fix movement stock list (#28192)

* fix movement stock list

* fix

* fix
This commit is contained in:
Frédéric FRANCE
2024-02-16 02:30:06 +01:00
committed by GitHub
parent 399f5d6cbe
commit ff29e2e2db
2 changed files with 61 additions and 50 deletions

View File

@@ -1135,10 +1135,12 @@ class MouvementStock extends CommonObject
$result = '';
$label = img_picto('', 'stock', 'class="pictofixedwidth"').'<u>'.$langs->trans("Movement").' '.$this->id.'</u>';
$label = img_picto('', 'stock', 'class="pictofixedwidth"').'<u>'.$langs->trans("StockMovement").'</u>';
$label .= '<div width="100%">';
$label .= '<b>'.$langs->trans('Label').':</b> '.$this->label;
$label .= '<br><b>'.$langs->trans('Qty').':</b> '.($this->qty > 0 ? '+' : '').$this->qty;
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->id;
$label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
$qtylabel = (($this->qty > 0) ? '<span class="stockmovemententry">+' : '<span class="stockmovementexit">') . $this->qty . '</span>';
$label .= '<br><b>'.$langs->trans('Qty').':</b> ' . $qtylabel;
if ($this->batch) {
$label .= '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
}

View File

@@ -65,6 +65,7 @@ $ref = GETPOST('ref', 'alpha');
$msid = GETPOST('msid', 'int');
$idproduct = GETPOST('idproduct', 'int');
$product_id = GETPOST("product_id", 'int');
$show_files = GETPOST('show_files', 'int');
$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
$search_date_startday = GETPOST('search_date_startday', 'int');
@@ -250,10 +251,10 @@ if (empty($reshook)) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$objecttmp = new $objectclass($db);
$objecttmp = new MouvementStock($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
$objecttmp = new MouvementStock($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;
@@ -310,7 +311,8 @@ if (empty($reshook)) {
if (!$error) {
$langs->load("exports");
setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
setEventMessage($langs->trans('FeatureNotYetAvailable'));
//setEventMessages($langs->trans('FileSuccessfullyBuilt', $filename.'_'.dol_print_date($now, 'dayhourlog')), null, 'mesgs');
}
$massaction = '';
@@ -465,8 +467,8 @@ if ($action == "transfert_stock" && !$cancel) {
if (!$error) {
if ($id) {
$object = new Entrepot($db);
$result = $object->fetch($id);
$warehouse = new Entrepot($db);
$result = $warehouse->fetch($id);
$db->begin();
@@ -574,7 +576,7 @@ if ($action == "transfert_stock" && !$cancel) {
header("Location: ".$backtopage);
exit;
} else {
header("Location: movement_list.php?id=".$object->id);
header("Location: movement_list.php?id=".$warehouse->id);
exit;
}
} else {
@@ -638,7 +640,7 @@ if (isModEnabled('project')) {
$productlot = new Productlot($db);
$productstatic = new Product($db);
$warehousestatic = new Entrepot($db);
$movement = new MouvementStock($db);
$userstatic = new User($db);
$now = dol_now();
@@ -782,13 +784,13 @@ $num = $db->num_rows($resql);
$product = new Product($db);
$object = new Entrepot($db);
$warehouse = new Entrepot($db);
if ($idproduct > 0) {
$product->fetch($idproduct);
}
if ($id > 0 || $ref) {
$result = $object->fetch($id, $ref);
$result = $warehouse->fetch($id, $ref);
if ($result < 0) {
dol_print_error($db);
}
@@ -805,8 +807,8 @@ if ($msid) {
} else {
$title = $langs->trans("ListOfStockMovements");
if ($id) {
if (!empty($object->ref)) {
$title .= ' ('.$object->ref.')';
if (!empty($warehouse->ref)) {
$title .= ' ('.$warehouse->ref.')';
} else {
$title .= ' ('.$langs->trans("ForThisWarehouse").')';
}
@@ -822,8 +824,8 @@ llxHeader('', $title, $help_url);
/*
* Show tab only if we ask a particular warehouse
*/
if ($object->id > 0) {
$head = stock_prepare_head($object);
if ($warehouse->id > 0) {
$head = stock_prepare_head($warehouse);
print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock');
@@ -831,7 +833,7 @@ if ($object->id > 0) {
$linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
$morehtmlref = '<div class="refidno">';
$morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu;
$morehtmlref .= $langs->trans("LocationSummary").' : '.$warehouse->lieu;
// Project
if (isModEnabled('project')) {
@@ -839,23 +841,23 @@ if ($object->id > 0) {
$morehtmlref .= '<br>'.img_picto('', 'project').' '.$langs->trans('Project').' ';
if ($usercancreate && 1 == 2) {
if ($action != 'classify') {
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$warehouse->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
}
if ($action == 'classify') {
$projectid = $object->fk_project;
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$projectid = $warehouse->fk_project;
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$warehouse->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500');
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} else {
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$warehouse->id, $warehouse->socid, $warehouse->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
}
} else {
if (!empty($object->fk_project)) {
if (!empty($warehouse->fk_project)) {
$proj = new Project($db);
$proj->fetch($object->fk_project);
$proj->fetch($warehouse->fk_project);
$morehtmlref .= ' : '.$proj->getNomUrl(1);
if ($proj->title) {
$morehtmlref .= ' - '.$proj->title;
@@ -872,7 +874,7 @@ if ($object->id > 0) {
$shownav = 0;
}
dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
dol_banner_tab($warehouse, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
@@ -884,10 +886,10 @@ if ($object->id > 0) {
print '<tr>';
// Description
print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($object->description).'</td></tr>';
print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>'.dol_htmlentitiesbr($warehouse->description).'</td></tr>';
$calcproductsunique = $object->nb_different_products();
$calcproducts = $object->nb_products();
$calcproductsunique = $warehouse->nb_different_products();
$calcproducts = $warehouse->nb_products();
// Total nb of different products
print '<tr><td>'.$langs->trans("NumberOfDifferentProducts").'</td><td>';
@@ -916,7 +918,7 @@ if ($object->id > 0) {
// Last movement
$sql = "SELECT MAX(m.datem) as datem";
$sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
$sql .= " WHERE m.fk_entrepot = ".((int) $object->id);
$sql .= " WHERE m.fk_entrepot = ".((int) $warehouse->id);
$resqlbis = $db->query($sql);
if ($resqlbis) {
$objbis = $db->fetch_object($resqlbis);
@@ -939,7 +941,7 @@ if ($object->id > 0) {
// Categories
if (isModEnabled('categorie')) {
print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1);
print $form->showCategories($warehouse->id, Categorie::TYPE_WAREHOUSE, 1);
print "</td></tr>";
}
@@ -972,7 +974,7 @@ if ((empty($action) || $action == 'list') && $id > 0) {
print "<div class=\"tabsAction\">\n";
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $warehouse, $action); // Note that $action and $warehouse may have been
// modified by hook
if (empty($reshook)) {
if ($user->hasRight('stock', 'mouvement', 'creer')) {
@@ -1002,6 +1004,9 @@ if ($limit > 0 && $limit != $conf->liste_limit) {
if ($id > 0) {
$param .= '&id='.urlencode($id);
}
if ($show_files) {
$param .= '&show_files='.urlencode($show_files);
}
if ($search_date_startday) {
$param .= '&search_date_startday='.urlencode($search_date_startday);
}
@@ -1054,7 +1059,7 @@ if ($search_fk_project != '' && $search_fk_project != '-1') {
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
// Add $param from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $warehouse, $action); // Note that $action and $warehouse may have been modified by hook
$param .= $hookmanager->resPrint;
// List of mass actions available
@@ -1106,7 +1111,7 @@ if ($id > 0) {
$topicmail = "SendStockMovement";
$modelmail = "movementstock";
$objecttmp = new MouvementStock($db);
$trackid = 'mov'.$object->id;
$trackid = 'mov'.$warehouse->id;
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
if ($massaction == 'prereverse') {
print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassReverse"), $langs->trans("ConfirmMassReverseQuestion", count($toselect)), "confirm_reverse", null, '', 0, 200, 500, 1, 'Yes');
@@ -1126,7 +1131,7 @@ if ($search_all) {
$moreforfilter = '';
$parameters = array('arrayfields'=>&$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $warehouse, $action); // Note that $action and $warehouse may have been modified by hook
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
@@ -1231,7 +1236,7 @@ if (!empty($arrayfields['origin']['checked'])) {
if (!empty($arrayfields['m.fk_projet']['checked'])) {
// fk_project
print '<td class="liste_titre" align="left">';
print $object->showInputField($object->fields['fk_project'], 'fk_project', $search_fk_project, '', '', 'search_', 'maxwidth125', 1);
print $warehouse->showInputField($warehouse->fields['fk_project'], 'fk_project', $search_fk_project, '', '', 'search_', 'maxwidth125', 1);
print '</td>';
}
if (!empty($arrayfields['m.type_mouvement']['checked'])) {
@@ -1268,7 +1273,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $warehouse, $action); // Note that $action and $warehouse may have been modified by hook
print $hookmanager->resPrint;
// Date creation
if (!empty($arrayfields['m.datec']['checked'])) {
@@ -1355,7 +1360,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $warehouse, $action); // Note that $action and $warehouse may have been modified by hook
print $hookmanager->resPrint;
if (!empty($arrayfields['m.datec']['checked'])) {
print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
@@ -1393,7 +1398,7 @@ while ($i < $imaxinloop) {
$userstatic->firstname = $obj->firstname;
$userstatic->photo = $obj->photo;
$userstatic->email = $obj->user_email;
$userstatic->statut = $obj->user_status;
$userstatic->status = $obj->user_status;
// Multilangs
if (getDolGlobalInt('MAIN_MULTILANGS')) { // If multilang is enabled
@@ -1434,11 +1439,16 @@ while ($i < $imaxinloop) {
$warehousestatic->fk_parent = $obj->fk_parent;
$warehousestatic->statut = $obj->statut;
$movement->type = $obj->type_mouvement;
$object->id = $obj->mid;
$object->qty = $obj->qty;
$object->label = $obj->label;
$object->batch = $obj->batch;
$object->warehouse_id = $obj->entrepot_id;
$object->type = $obj->type_mouvement;
$arrayofuniqueproduct[$obj->rowid] = $obj->produit;
if (!empty($obj->fk_origin)) {
$origin = $movement->get_origin($obj->fk_origin, $obj->origintype);
$origin = $object->get_origin($obj->fk_origin, $obj->origintype);
} else {
$origin = '';
}
@@ -1452,11 +1462,11 @@ while ($i < $imaxinloop) {
$selected = -1;
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($object->id, $arrayofselected)) {
if (in_array($warehouse->id, $arrayofselected)) {
$selected = 1;
}
}
print $object->getKanbanView('', array('selected' => $selected));
print $warehouse->getKanbanView('', array('selected' => $selected));
if ($i == ($imaxinloop - 1)) {
print '</div>';
print '</td></tr>';
@@ -1464,7 +1474,7 @@ while ($i < $imaxinloop) {
} else {
// Show here line of result
$j = 0;
print '<tr data-rowid="'.$object->id.'" class="oddeven">';
print '<tr data-rowid="'.$warehouse->id.'" class="oddeven">';
// Action column
if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
print '<td class="nowrap center">';
@@ -1483,8 +1493,8 @@ while ($i < $imaxinloop) {
// Id movement
if (!empty($arrayfields['m.rowid']['checked'])) {
print '<td class="nowraponall">';
print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
print $obj->mid;
//print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"');
print $object->getNomUrl(1);;
print '</td>'; // This is primary not movement id
}
if (!empty($arrayfields['m.datem']['checked'])) {
@@ -1546,14 +1556,14 @@ while ($i < $imaxinloop) {
// fk_project
print '<td>';
if ($obj->fk_project != 0) {
print $movement->get_origin($obj->fk_project, 'project');
print $object->get_origin($obj->fk_project, 'project');
}
print '</td>';
}
if (!empty($arrayfields['m.type_mouvement']['checked'])) {
// Type of movement
print '<td class="center">';
print $movement->getTypeMovement();
print $object->getTypeMovement();
print '</td>';
}
if (!empty($arrayfields['m.value']['checked'])) {
@@ -1581,7 +1591,6 @@ while ($i < $imaxinloop) {
}
// Extra fields
$object = $movement;
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
@@ -1643,8 +1652,8 @@ if (count($arrayofuniqueproduct) == 1 && !empty($year) && is_numeric($year)) {
}
$datebefore = dol_get_first_day($year ? $year : dol_print_date(time(), "%Y"), $month ? $month : 1, true);
$dateafter = dol_get_last_day($year ? $year : dol_print_date(time(), "%Y"), $month ? $month : 12, true);
$balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore);
$balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter);
$balancebefore = $object->calculateBalanceForProductBefore($productidselected, $datebefore);
$balanceafter = $object->calculateBalanceForProductBefore($productidselected, $dateafter);
//print '<tr class="total"><td class="liste_total">';
print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt'));
@@ -1679,7 +1688,7 @@ if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords
$genallowed = $permissiontoread;
$delallowed = $permissiontoadd;
print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
print $formfile->showdocuments('massfilesarea_stock', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
}
// End of page