diff --git a/htdocs/core/modules/stock/doc/pdf_standard.modules.php b/htdocs/core/modules/stock/doc/pdf_standard.modules.php
index 17e2c6b532b..f66e7e6e5d1 100644
--- a/htdocs/core/modules/stock/doc/pdf_standard.modules.php
+++ b/htdocs/core/modules/stock/doc/pdf_standard.modules.php
@@ -853,6 +853,9 @@ class pdf_standard extends ModelePDFStock
$pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("EstimatedStockValueShort").' : '.price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
$nexY = $pdf->GetY();
+ // Value
+ $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, ''.$outputlangs->transnoentities("Date").' : '.dol_print_date(dol_now(), 'dayhour'), 0, 1);
+ $nexY = $pdf->GetY();
// Last movement
$sql = "SELECT max(m.datem) as datem";
diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php
index f5d74c47c8e..405528a3480 100644
--- a/htdocs/product/stock/movement_list.php
+++ b/htdocs/product/stock/movement_list.php
@@ -84,14 +84,19 @@ $search_fk_projet=GETPOST("search_fk_projet", 'int');
$optioncss = GETPOST('optioncss', 'alpha');
$type = GETPOST("type", "int");
+// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
-$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
-if (empty($page) || $page == -1) {
+$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
+if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
+ // If $page is not defined, or '' or -1 or if we click on clear filters
$page = 0;
-} // If $page is not defined, or '' or -1
+}
$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+
if (!$sortfield) {
$sortfield = "m.datem";
}
@@ -103,8 +108,10 @@ $pdluoid = GETPOST('pdluoid', 'int');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new MouvementStock($db);
-$hookmanager->initHooks(array('movementlist'));
$extrafields = new ExtraFields($db);
+$diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id;
+$hookmanager->initHooks(array('movementlist'));
+
$formfile = new FormFile($db);
// fetch optionals attributes and labels
@@ -156,6 +163,8 @@ if (!$user->rights->stock->mouvement->lire) {
accessforbidden();
}
+$uploaddir = $conf->stock->dir_output.'/movements';
+
$permissiontoread = $user->rights->stock->mouvement->lire;
$permissiontoadd = $user->rights->stock->mouvement->creer;
$permissiontodelete = $user->rights->stock->mouvement->creer; // There is no deletion permission for stock movement as we shoul dnever delete
@@ -172,7 +181,8 @@ $error = 0;
*/
if (GETPOST('cancel', 'alpha')) {
- $action = 'list'; $massaction = '';
+ $action = 'list';
+ $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
@@ -185,9 +195,10 @@ if ($reshook < 0) {
}
if (empty($reshook)) {
+ // Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
- // Do we click on purge search criteria ?
+ // Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // Both test are required to be compatible with all browsers
$search_date_startday = '';
$search_date_startmonth = '';
@@ -212,11 +223,92 @@ if (empty($reshook)) {
$toselect = '';
$search_array_options = array();
}
+ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
+ || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
+ $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
+ }
// Mass actions
$objectclass = 'MouvementStock';
$objectlabel = 'MouvementStock';
- $uploaddir = $conf->stock->dir_output;
+
+ if (!$error && $massaction == "builddoc" && $permissiontoread && !GETPOST('button_search')) {
+ if (empty($diroutputmassaction)) {
+ dol_print_error(null, 'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
+ exit;
+ }
+
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
+
+ $objecttmp = new $objectclass($db);
+ $listofobjectid = array();
+ foreach ($toselect as $toselectid) {
+ $objecttmp = new $objectclass($db); // must create new instance because instance is saved into $listofobjectref array for future use
+ $result = $objecttmp->fetch($toselectid);
+ if ($result > 0) {
+ $listofobjectid[$toselectid] = $toselectid;
+ }
+ }
+
+ $arrayofinclusion = array();
+ foreach ($listofobjectref as $tmppdf) {
+ $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'\.pdf$';
+ }
+ foreach ($listofobjectref as $tmppdf) {
+ $arrayofinclusion[] = '^'.preg_quote(dol_sanitizeFileName($tmppdf), '/').'_[a-zA-Z0-9-_]+\.pdf$'; // To include PDF generated from ODX files
+ }
+ $listoffiles = dol_dir_list($uploaddir, 'all', 1, implode('|', $arrayofinclusion), '\.meta$|\.png', 'date', SORT_DESC, 0, true);
+
+ // Define output language (Here it is not used because we do only merging existing PDF)
+ $outputlangs = $langs;
+ $newlang = '';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
+ $newlang = GETPOST('lang_id', 'aZ09');
+ }
+ //elseif ($conf->global->MAIN_MULTILANGS && empty($newlang) && is_object($objecttmp->thirdparty)) { // On massaction, we can have several values for $objecttmp->thirdparty
+ // $newlang = $objecttmp->thirdparty->default_lang;
+ //}
+ if (!empty($newlang)) {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+
+ // Create output dir if not exists
+ dol_mkdir($diroutputmassaction);
+
+ // Defined name of merged file
+ $filename = strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel)));
+ $filename = preg_replace('/\s/', '_', $filename);
+
+ // Save merged file
+ /*
+ if ($year) {
+ $filename .= '_'.$year;
+ }
+ if ($month) {
+ $filename .= '_'.$month;
+ }
+ */
+ $now = dol_now();
+ $file = $diroutputmassaction.'/'.$filename.'_'.dol_print_date($now, 'dayhourlog').'.pdf';
+
+
+ // Create PDF
+ // TODO Create the pdf including list of movement ids found into $listofobjectid
+ // ...
+
+
+ if (!$error) {
+ $langs->load("exports");
+ setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
+ }
+
+ $massaction = '';
+ $action = '';
+ }
+
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
}
@@ -482,6 +574,8 @@ if (!empty($conf->projet->enabled)) {
$formproject = new FormProjets($db);
}
+// Build and execute select
+// --------------------------------------------------------------------
$sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tosell, p.tobuy, p.tobatch, p.fk_product_type as type, p.entity,";
$sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu, e.fk_parent, e.statut,";
$sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,";
@@ -499,7 +593,8 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
-$sql .= $hookmanager->resPrint;
+$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
+$sql = preg_replace('/,\s*$/', '', $sql);
$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,";
$sql .= " ".MAIN_DB_PREFIX."product as p,";
$sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m";
@@ -572,6 +667,31 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
+/* If a group by is required
+ $sql .= " GROUP BY ";
+ foreach($object->fields as $key => $val) {
+ $sql .= "t.".$key.", ";
+ }
+ // Add fields from extrafields
+ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
+ foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
+ $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
+ }
+ }
+ // Add where from hooks
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= $hookmanager->resPrint;
+ $sql = preg_replace('/,\s*$/', '', $sql);
+ */
+
+// Add HAVING from hooks
+/*
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
+ $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
+ */
+
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
@@ -589,20 +709,19 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
$resql = $db->query($sqlforcount);
$objforcount = $db->fetch_object($resql);
$nbtotalofrecords = $objforcount->nbtotalofrecords;
- if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
+ if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
$page = 0;
$offset = 0;
}
$db->free($resql);
}
+// Complete request and execute it with limit
$sql .= $db->order($sortfield, $sortorder);
if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
-//print $sql;
-
$resql = $db->query($sql);
if (!$resql) {
dol_print_error($db);
@@ -624,20 +743,24 @@ if ($id > 0 || $ref) {
$num = $db->num_rows($resql);
-$arrayofselected = is_array($toselect) ? $toselect : array();
+// Output page
+// --------------------------------------------------------------------
$i = 0;
$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
if ($msid) {
- $texte = $langs->trans('StockMovementForId', $msid);
+ $title = $langs->trans('StockMovementForId', $msid);
} else {
- $texte = $langs->trans("ListOfStockMovements");
+ $title = $langs->trans("ListOfStockMovements");
if ($id) {
- $texte .= ' ('.$langs->trans("ForThisWarehouse").')';
+ $title .= ' ('.$langs->trans("ForThisWarehouse").')';
}
}
-llxHeader("", $texte, $help_url);
+
+llxHeader('', $title, $help_url);
+
+$arrayofselected = is_array($toselect) ? $toselect : array();
/*
* Show tab only if we ask a particular warehouse
@@ -774,26 +897,20 @@ if ($object->id > 0) {
}
-/*
- * Correct stock
- */
+// Correct stock
if ($action == "correction") {
include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php';
print '
';
}
-/*
- * Transfer of units
- */
+// Transfer of units
if ($action == "transfert") {
include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php';
print '
';
}
-/*
- * Action bar
- */
+// Action bar
if ((empty($action) || $action == 'list') && $id > 0) {
print "