2
0
forked from Wavyzz/dolibarr

Merge pull request #24774 from noec764/17_FIX_Rework_on_warehouse_total

FIX: Warehouse total line
This commit is contained in:
Laurent Destailleur
2023-05-15 23:44:10 +02:00
committed by GitHub
2 changed files with 61 additions and 35 deletions

View File

@@ -13,13 +13,28 @@ if (isset($totalarray['pos'])) {
while ($i < $totalarray['nbfield']) {
$i++;
if (!empty($totalarray['pos'][$i])) {
print '<td class="right">';
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);
switch ($totalarray['type'][$i]) {
case 'duration';
print '<td class="right">';
print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0);
print '</td>';
break;
case 'string';
print '<td class="left">';
print (!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : '');
print '</td>';
break;
case 'stock';
print '<td class="right">';
print price2num(!empty($totalarray['val'][$totalarray['pos'][$i]]) ? $totalarray['val'][$totalarray['pos'][$i]] : 0, 'MS');
print '</td>';
break;
default;
print '<td class="right">';
print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0);
print '</td>';
break;
}
print '</td>';
} else {
if ($i == 1) {
if (is_null($limit) || $num < $limit) {

View File

@@ -595,35 +595,60 @@ if ($action == 'create') {
print '<br>';
$totalarray = array();
$totalarray['val'] = array ();
$totalarray['pos'] = array ();
$totalarray['type'] = array ();
$totalarray['nbfield'] = 0;
// TODO Create $arrayfields with all fields to show
print '<table class="noborder centpercent">';
print "<tr class=\"liste_titre\">";
$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", "&amp;id=".$id, "", "", $sortfield, $sortorder);
print_liste_field_titre("Label", "", "p.label", "&amp;id=".$id, "", "", $sortfield, $sortorder);
print_liste_field_titre("NumberOfUnit", "", "ps.reel", "&amp;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", "&amp;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", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
$totalarray['nbfield']++;
print_liste_field_titre("EstimatedStockValueShort", "", "", "&amp;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", "&amp;id=".$id, "", '', $sortfield, $sortorder, 'right ');
$totalarray['nbfield']++;
}
if (empty($conf->global->PRODUIT_MULTIPRICES)) {
print_liste_field_titre("EstimatedStockValueSellShort", "", "", "&amp;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 "</tr>\n";
@@ -708,7 +733,7 @@ if ($action == 'create') {
//print '<td>'.dol_print_date($objp->datem).'</td>';
print '<tr class="oddeven">';
$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,20 @@ if ($action == 'create') {
}
$db->free($resql);
// Total
print '<tr class="liste_total"><td class="liste_total" colspan="2">'.$langs->trans("Total").'</td>';
print '<td class="liste_total right">';
$valtoshow = price2num($totalunit, 'MS');
if (empty($conf->global->PRODUCT_USE_UNITS) || $sameunits) {
print empty($valtoshow) ? '0' : $valtoshow;
}
print '</td>';
print '<td class="liste_total">';
if (empty($conf->global->PRODUCT_USE_UNITS) && $sameunits) {
print $langs->trans($productstatic->getLabelOfUnit());
}
print '</td>';
print '<td class="liste_total right">'.price(price2num($totalvalue, 'MT')).'</td>';
if (empty($conf->global->PRODUIT_MULTIPRICES)) {
print '<td class="liste_total">&nbsp;</td>';
print '<td class="liste_total right">'.price(price2num($totalvaluesell, 'MT')).'</td>';
$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);
}
if ($user->rights->stock->mouvement->creer) {
print '<td class="liste_total">&nbsp;</td>';
}
if ($user->rights->stock->creer) {
print '<td class="liste_total">&nbsp;</td>';
}
print '</tr>';
// Show total line
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
} else {
dol_print_error($db);
}