From c9eacc4928c71def0b07e4ab168c7c0505d68406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Courtier?= Date: Mon, 15 May 2023 15:19:30 +0200 Subject: [PATCH 1/2] FIX: Warehouse total line --- htdocs/core/tpl/list_print_total.tpl.php | 29 +++++++--- htdocs/product/stock/card.php | 72 ++++++++++++++---------- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/htdocs/core/tpl/list_print_total.tpl.php b/htdocs/core/tpl/list_print_total.tpl.php index 288f3b8f72e..44c1c9e34dc 100644 --- a/htdocs/core/tpl/list_print_total.tpl.php +++ b/htdocs/core/tpl/list_print_total.tpl.php @@ -13,13 +13,28 @@ if (isset($totalarray['pos'])) { while ($i < $totalarray['nbfield']) { $i++; if (!empty($totalarray['pos'][$i])) { - print ''; - if (isset($totalarray['type']) && $totalarray['type'][$i] == 'duration') { - print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0); - } else { - print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0); - } - print ''; + switch ($totalarray['type'][$i]) { + case 'duration'; + print ''; + print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0); + print ''; + break; + case 'string'; + print ''; + print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : ''); + print ''; + break; + case 'stock'; + print ''; + print price2num(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0, 'MS'); + print ''; + break; + default; + print ''; + print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0); + print ''; + break; + } } else { if ($i == 1) { if (is_null($limit) || $num < $limit) { diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index ac740974d88..591d41c0ca3 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -595,35 +595,60 @@ if ($action == 'create') { print '
'; + $totalarray = array(); + $totalarray['val'] = array (); + $totalarray['pos'] = array (); + $totalarray['type'] = array (); + $totalarray['nbfield'] = 0; + // TODO Create $arrayfields with all fields to show print ''; print ""; - $parameters = array(); + $parameters = array('totalarray' => &$totalarray); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; + print_liste_field_titre("Product", "", "p.ref", "&id=".$id, "", "", $sortfield, $sortorder); print_liste_field_titre("Label", "", "p.label", "&id=".$id, "", "", $sortfield, $sortorder); print_liste_field_titre("NumberOfUnit", "", "ps.reel", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); + $totalarray['nbfield'] += 3; + $totalarray['pos'][$totalarray['nbfield']] = 'totalunit'; + $totalarray['type'][$totalarray['nbfield']] = 'stock'; + if (!empty($conf->global->PRODUCT_USE_UNITS)) { print_liste_field_titre("Unit", "", "p.fk_unit", "&id=".$id, "", 'align="left"', $sortfield, $sortorder); - } + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'units'; + $totalarray['type'][$totalarray['nbfield']] = 'string'; + } + print_liste_field_titre($form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")), "", "p.pmp", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); + $totalarray['nbfield']++; + print_liste_field_titre("EstimatedStockValueShort", "", "", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'totalvalue'; + if (empty($conf->global->PRODUIT_MULTIPRICES)) { print_liste_field_titre("SellPriceMin", "", "p.price", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); + $totalarray['nbfield']++; } if (empty($conf->global->PRODUIT_MULTIPRICES)) { print_liste_field_titre("EstimatedStockValueSellShort", "", "", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - } + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'totalvaluesell'; + } if ($user->rights->stock->mouvement->creer) { print_liste_field_titre(''); + $totalarray['nbfield']++; } if ($user->rights->stock->creer) { print_liste_field_titre(''); + $totalarray['nbfield']++; } // Hook fields - $parameters = array('sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $parameters = array('sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray' => &$totalarray); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; print "\n"; @@ -708,7 +733,7 @@ if ($action == 'create') { //print ''; print ''; - $parameters = array('obj'=>$objp); + $parameters = array('obj'=>$objp, 'totalarray' => &$totalarray); $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; @@ -807,34 +832,21 @@ if ($action == 'create') { } $db->free($resql); - // Total - print ''; - print ''; - print ''; - print ''; - if (empty($conf->global->PRODUIT_MULTIPRICES)) { - print ''; - print ''; - } + $totalarray['val']['totalunit'] = $totalunit; + $totalarray['val']['totalvalue'] = price2num($totalvalue, 'MT'); + $totalarray['val']['totalvaluesell'] = price2num($totalvaluesell, 'MT'); + $totalarray['val']['units'] = $langs->trans($productstatic->getLabelOfUnit()); - if ($user->rights->stock->mouvement->creer) { - print ''; - } + $parameters = array('totalarray' => &$totalarray); + // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors); + } - if ($user->rights->stock->creer) { - print ''; - } + // Show total line + include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; - print ''; } else { dol_print_error($db); } From fd108f67a742e2b93e0f557ae736d83185c85edd Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 15 May 2023 13:27:01 +0000 Subject: [PATCH 2/2] Fixing style errors. --- htdocs/core/tpl/list_print_total.tpl.php | 44 +++++++++--------- htdocs/product/stock/card.php | 59 ++++++++++++------------ 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/htdocs/core/tpl/list_print_total.tpl.php b/htdocs/core/tpl/list_print_total.tpl.php index 44c1c9e34dc..9b4fa75c751 100644 --- a/htdocs/core/tpl/list_print_total.tpl.php +++ b/htdocs/core/tpl/list_print_total.tpl.php @@ -13,28 +13,28 @@ if (isset($totalarray['pos'])) { while ($i < $totalarray['nbfield']) { $i++; if (!empty($totalarray['pos'][$i])) { - switch ($totalarray['type'][$i]) { - case 'duration'; - print ''; - break; - case 'string'; - print ''; - break; - case 'stock'; - print ''; - break; - default; - print ''; - break; - } + switch ($totalarray['type'][$i]) { + case 'duration'; + print ''; + break; + case 'string'; + print ''; + break; + case 'stock'; + print ''; + break; + default; + print ''; + break; + } } else { if ($i == 1) { if (is_null($limit) || $num < $limit) { diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 591d41c0ca3..1412ea2fcf5 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -595,12 +595,12 @@ if ($action == 'create') { print '
'; - $totalarray = array(); - $totalarray['val'] = array (); - $totalarray['pos'] = array (); - $totalarray['type'] = array (); - $totalarray['nbfield'] = 0; - + $totalarray = array(); + $totalarray['val'] = array (); + $totalarray['pos'] = array (); + $totalarray['type'] = array (); + $totalarray['nbfield'] = 0; + // TODO Create $arrayfields with all fields to show print '
'.dol_print_date($objp->datem).'
'.$langs->trans("Total").''; - $valtoshow = price2num($totalunit, 'MS'); - if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) { - print empty($valtoshow) ? '0' : $valtoshow; - } - print ''; - if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) { - print $langs->trans($productstatic->getLabelOfUnit()); - } - print ''.price(price2num($totalvalue, 'MT')).' '.price(price2num($totalvaluesell, 'MT')).'  
'; - print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0); - print ''; - print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : ''); - print ''; - print price2num(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0, 'MS'); - print ''; - print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0); - print ''; + print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0); + print ''; + print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : ''); + print ''; + print price2num(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0, 'MS'); + print ''; + print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0); + print '
'; @@ -612,40 +612,40 @@ if ($action == 'create') { print_liste_field_titre("Product", "", "p.ref", "&id=".$id, "", "", $sortfield, $sortorder); print_liste_field_titre("Label", "", "p.label", "&id=".$id, "", "", $sortfield, $sortorder); print_liste_field_titre("NumberOfUnit", "", "ps.reel", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield'] += 3; - $totalarray['pos'][$totalarray['nbfield']] = 'totalunit'; - $totalarray['type'][$totalarray['nbfield']] = 'stock'; + $totalarray['nbfield'] += 3; + $totalarray['pos'][$totalarray['nbfield']] = 'totalunit'; + $totalarray['type'][$totalarray['nbfield']] = 'stock'; if (!empty($conf->global->PRODUCT_USE_UNITS)) { print_liste_field_titre("Unit", "", "p.fk_unit", "&id=".$id, "", 'align="left"', $sortfield, $sortorder); - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'units'; - $totalarray['type'][$totalarray['nbfield']] = 'string'; - } + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'units'; + $totalarray['type'][$totalarray['nbfield']] = 'string'; + } print_liste_field_titre($form->textwithpicto($langs->trans("AverageUnitPricePMPShort"), $langs->trans("AverageUnitPricePMPDesc")), "", "p.pmp", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; + $totalarray['nbfield']++; print_liste_field_titre("EstimatedStockValueShort", "", "", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'totalvalue'; + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'totalvalue'; if (empty($conf->global->PRODUIT_MULTIPRICES)) { print_liste_field_titre("SellPriceMin", "", "p.price", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; + $totalarray['nbfield']++; } if (empty($conf->global->PRODUIT_MULTIPRICES)) { print_liste_field_titre("EstimatedStockValueSellShort", "", "", "&id=".$id, "", '', $sortfield, $sortorder, 'right '); - $totalarray['nbfield']++; - $totalarray['pos'][$totalarray['nbfield']] = 'totalvaluesell'; - } + $totalarray['nbfield']++; + $totalarray['pos'][$totalarray['nbfield']] = 'totalvaluesell'; + } if ($user->rights->stock->mouvement->creer) { print_liste_field_titre(''); - $totalarray['nbfield']++; + $totalarray['nbfield']++; } if ($user->rights->stock->creer) { print_liste_field_titre(''); - $totalarray['nbfield']++; + $totalarray['nbfield']++; } // Hook fields $parameters = array('sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray' => &$totalarray); @@ -832,21 +832,20 @@ if ($action == 'create') { } $db->free($resql); - $totalarray['val']['totalunit'] = $totalunit; - $totalarray['val']['totalvalue'] = price2num($totalvalue, 'MT'); - $totalarray['val']['totalvaluesell'] = price2num($totalvaluesell, 'MT'); - $totalarray['val']['units'] = $langs->trans($productstatic->getLabelOfUnit()); + $totalarray['val']['totalunit'] = $totalunit; + $totalarray['val']['totalvalue'] = price2num($totalvalue, 'MT'); + $totalarray['val']['totalvaluesell'] = price2num($totalvaluesell, 'MT'); + $totalarray['val']['units'] = $langs->trans($productstatic->getLabelOfUnit()); $parameters = array('totalarray' => &$totalarray); // Note that $action and $object may have been modified by hook $reshook = $hookmanager->executeHooks('printFieldListTotal', $parameters, $object); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors); - } - - // Show total line - include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; + } + // Show total line + include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; } else { dol_print_error($db); }