Merge pull request #14659 from Tim-Otte/feature-filterable-purchase-price-table-columns

NEW Purchase price table: Added filterable table columns
This commit is contained in:
Laurent Destailleur 2020-09-09 18:55:55 +02:00 committed by GitHub
commit c761b829b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -858,6 +858,52 @@ SCRIPT;
print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1); print_barre_liste($langs->trans('SupplierPrices'), $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit, 1);
// Definition of fields for lists
// Some fields are missing because they are not included in the database query
$arrayfields = array(
'pfp.datec'=>array('label'=>$langs->trans("AppliedPricesFrom"), 'checked'=>1, 'position'=>1),
's.nom'=>array('label'=>$langs->trans("Suppliers"), 'checked'=>1, 'position'=>2),
'pfp.fk_availability'=>array('label'=>$langs->trans("Availability"), 'enabled' => !empty($conf->global->FOURN_PRODUCT_AVAILABILITY), 'checked'=>0, 'position'=>4),
'pfp.quantity'=>array('label'=>$langs->trans("QtyMin"), 'checked'=>1, 'position'=>5),
'pfp.unitprice'=>array('label'=>$langs->trans("UnitPriceHT"), 'checked'=>1, 'position'=>9),
'pfp.multicurrency_unitprice'=>array('label'=>$langs->trans("UnitPriceHTCurrency"), 'enabled' => $conf->multicurrency->enabled, 'checked'=>0, 'position'=>10),
'pfp.delivery_time_days'=>array('label'=>$langs->trans("NbDaysToDelivery"), 'checked'=>1, 'position'=>13),
'pfp.supplier_reputation'=>array('label'=>$langs->trans("ReputationForThisProduct"), 'checked'=>1, 'position'=>14),
'pfp.barcode'=>array('label'=>$langs->trans("BarcodeValue"), 'enabled' => $conf->barcode->enabled, 'checked'=>0, 'position'=>15),
'pfp.fk_barcode_type'=>array('label'=>$langs->trans("BarcodeType"), 'enabled' => $conf->barcode->enabled, 'checked'=>0, 'position'=>16),
'pfp.packaging'=>array('label'=>$langs->trans("PackagingForThisProduct"), 'enabled' => !empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING), 'checked'=>0, 'position'=>17),
'pfp.tms'=>array('label'=>$langs->trans("DateModification"), 'enabled' => $conf->barcode->enabled, 'checked'=>1, 'position'=>18),
);
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
if (!empty($extralabels)) {
foreach ($extralabels as $key => $value) {
// Show field if not hidden
if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]);
if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key]));
else $extratitle = $langs->trans($value);
$arrayfields['ef.'.$key] = array('label'=>$extratitle, 'checked'=>0, 'position'=>(end($arrayfields)['position']+1));
}
}
}
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post" name="formulaire">';
print '<input type="hidden" name="token" value="'. newToken() . '">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
// Suppliers list title // Suppliers list title
print '<div class="div-table-responsive">'; print '<div class="div-table-responsive">';
print '<table class="liste centpercent">'; print '<table class="liste centpercent">';
@ -865,42 +911,37 @@ SCRIPT;
$param = "&id=".$object->id; $param = "&id=".$object->id;
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder); if (!empty($arrayfields['pfp.datec']['checked'])) print_liste_field_titre("AppliedPricesFrom", $_SERVER["PHP_SELF"], "pfp.datec", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("Suppliers", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder); if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre("Suppliers", $_SERVER["PHP_SELF"], "s.nom", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("SupplierRef", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("SupplierRef", $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder);
if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre("Availability", $_SERVER["PHP_SELF"], "pfp.fk_availability", "", $param, "", $sortfield, $sortorder); if (!empty($arrayfields['pfp.fk_availability']['checked'])) print_liste_field_titre("Availability", $_SERVER["PHP_SELF"], "pfp.fk_availability", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['pfp.quantity']['checked'])) print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("VATRate", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("PriceQtyMinHT", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("PriceQtyMinHT", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
if ($conf->multicurrency->enabled) { if ($conf->multicurrency->enabled) print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("PriceQtyMinHTCurrency", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['pfp.unitprice']['checked'])) print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, '', $sortfield, $sortorder, 'right ');
} if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("UnitPriceHT", $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, '', $sortfield, $sortorder, 'right '); if ($conf->multicurrency->enabled) print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
if ($conf->multicurrency->enabled) {
print_liste_field_titre("UnitPriceHTCurrency", $_SERVER["PHP_SELF"], "pfp.multicurrency_unitprice", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("Currency", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
}
print_liste_field_titre("DiscountQtyMin", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("DiscountQtyMin", $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center ');
if ($conf->barcode->enabled) { if (!empty($arrayfields['pfp.barcode']['checked'])) print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['pfp.packaging']['checked'])) print_liste_field_titre("PackagingForThisProduct", $_SERVER["PHP_SELF"], "pfp.packaging", "", $param, 'align="center"', $sortfield, $sortorder);
} if (!empty($arrayfields['pfp.tms']['checked'])) print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ');
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) print_liste_field_titre("PackagingForThisProduct", $_SERVER["PHP_SELF"], "pfp.packaging", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ');
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label("product_fournisseur_price"); $extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extralabels = $extrafields->attributes["product_fournisseur_price"]['label']; $extralabels = $extrafields->attributes["product_fournisseur_price"]['label'];
if (!empty($extralabels)) { if (!empty($extralabels)) {
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
// Show field if not hidden // Show field if not hidden
if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]); if (!empty($extrafields->attributes["product_fournisseur_price"]['langfile'][$key])) $langs->load($extrafields->attributes["product_fournisseur_price"]['langfile'][$key]);
if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key])); if (!empty($extrafields->attributes["product_fournisseur_price"]['help'][$key])) $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product_fournisseur_price"]['help'][$key]));
else $extratitle = $langs->trans($value); else $extratitle = $langs->trans($value);
print_liste_field_titre($extratitle, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['ef.'.$key]['checked'])) print_liste_field_titre($extratitle, $_SERVER["PHP_SELF"], 'ef.'.$key, '', $param, '', $sortfield, $sortorder, 'right ');
} }
} }
} }
@ -910,7 +951,7 @@ SCRIPT;
$parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id); $parameters = array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
} }
print_liste_field_titre(''); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
print "</tr>\n"; print "</tr>\n";
if (is_array($product_fourn_list)) if (is_array($product_fourn_list))
@ -920,10 +961,14 @@ SCRIPT;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Date from // Date from
print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation : $productfourn->date_creation), 'dayhour').'</td>'; if (!empty($arrayfields['pfp.datec']['checked'])) {
print '<td>'.dol_print_date(($productfourn->fourn_date_creation ? $productfourn->fourn_date_creation : $productfourn->date_creation), 'dayhour').'</td>';
}
// Supplier // Supplier
print '<td>'.$productfourn->getSocNomUrl(1, 'supplier').'</td>'; if (!empty($arrayfields['s.nom']['checked'])) {
print '<td>'.$productfourn->getSocNomUrl(1, 'supplier').'</td>';
}
// Supplier ref // Supplier ref
if ($usercancreate) // change required right here if ($usercancreate) // change required right here
@ -934,7 +979,7 @@ SCRIPT;
} }
// Availability // Availability
if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) if (!empty($arrayfields['pfp.fk_availability']['checked']))
{ {
$form->load_cache_availability(); $form->load_cache_availability();
$availability = $form->cache_availability[$productfourn->fk_availability]['label']; $availability = $form->cache_availability[$productfourn->fk_availability]['label'];
@ -942,16 +987,18 @@ SCRIPT;
} }
// Quantity // Quantity
print '<td class="right">'; if (!empty($arrayfields['pfp.quantity']['checked'])) {
print $productfourn->fourn_qty; print '<td class="right">';
// Units print $productfourn->fourn_qty;
if ($conf->global->PRODUCT_USE_UNITS) { // Units
$unit = $object->getLabelOfUnit(); if ($conf->global->PRODUCT_USE_UNITS) {
if ($unit !== '') { $unit = $object->getLabelOfUnit();
print '&nbsp;&nbsp;'.$langs->trans($unit); if ($unit !== '') {
} print '&nbsp;&nbsp;'.$langs->trans($unit);
} }
print '</td>'; }
print '</td>';
}
// VAT rate // VAT rate
print '<td class="right">'; print '<td class="right">';
@ -971,18 +1018,21 @@ SCRIPT;
} }
// Unit price // Unit price
print '<td class="right">'; if (!empty($arrayfields['pfp.unitprice']['checked'])) {
print price($productfourn->fourn_unitprice); print '<td class="right">';
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):"&nbsp;"); print price($productfourn->fourn_unitprice);
print '</td>'; //print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):"&nbsp;");
print '</td>';
}
if ($conf->multicurrency->enabled) { // Unit price in currency
// Unit price in currency if (!empty($arrayfields['pfp.multicurrency_unitprice']['checked'])) {
print '<td class="right">'; print '<td class="right">';
print price($productfourn->fourn_multicurrency_unitprice); print price($productfourn->fourn_multicurrency_unitprice);
print '</td>'; print '</td>';}
// Currency // Currency
if ($conf->multicurrency->enabled) {
print '<td class="right">'; print '<td class="right">';
print $productfourn->fourn_multicurrency_code ? currency_name($productfourn->fourn_multicurrency_code) : ''; print $productfourn->fourn_multicurrency_code ? currency_name($productfourn->fourn_multicurrency_code) : '';
print '</td>'; print '</td>';
@ -994,24 +1044,30 @@ SCRIPT;
print '</td>'; print '</td>';
// Delivery delay // Delivery delay
print '<td class="right">'; if (!empty($arrayfields['pfp.delivery_time_days']['checked'])) {
print $productfourn->delivery_time_days; print '<td class="right">';
print '</td>'; print $productfourn->delivery_time_days;
print '</td>';
}
// Reputation // Reputation
print '<td class="center">'; if (!empty($arrayfields['pfp.supplier_reputation']['checked'])) {
if (!empty($productfourn->supplier_reputation) && !empty($object->reputations[$productfourn->supplier_reputation])) { print '<td class="center">';
print $object->reputations[$productfourn->supplier_reputation]; if (!empty($productfourn->supplier_reputation) && !empty($object->reputations[$productfourn->supplier_reputation])) {
print $object->reputations[$productfourn->supplier_reputation];
}
print'</td>';
} }
print'</td>';
if ($conf->barcode->enabled) { // Barcode
// Barcode if (!empty($arrayfields['pfp.barcode']['checked'])) {
print '<td align="right">'; print '<td align="right">';
print $productfourn->barcode; print $productfourn->barcode;
print '</td>'; print '</td>';
}
// Barcode type // Barcode type
if (!empty($arrayfields['pfp.fk_barcode_type']['checked'])) {
print '<td class="center">'; print '<td class="center">';
$productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type : 0; $productfourn->barcode_type = !empty($productfourn->fk_barcode_type) ? $productfourn->fk_barcode_type : 0;
$productfourn->fetch_barcode(); $productfourn->fetch_barcode();
@ -1020,17 +1076,18 @@ SCRIPT;
} }
// Packaging // Packaging
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) if (!empty($arrayfields['pfp.packaging']['checked'])) {
{
print '<td align="center">'; print '<td align="center">';
print price2num($productfourn->packaging); print price2num($productfourn->packaging);
print '</td>'; print '</td>';
} }
// Date // Date
print '<td align="right">'; if (!empty($arrayfields['pfp.tms']['checked'])) {
print dol_print_date(($productfourn->fourn_date_modification ? $productfourn->fourn_date_modification : $productfourn->date_modification), "dayhour"); print '<td align="right">';
print '</td>'; print dol_print_date(($productfourn->fourn_date_modification ? $productfourn->fourn_date_modification : $productfourn->date_modification), "dayhour");
print '</td>';
}
// Extrafields // Extrafields
if (!empty($extralabels)) { if (!empty($extralabels)) {
@ -1045,14 +1102,14 @@ SCRIPT;
if ($resql) { if ($resql) {
if ($db->num_rows($resql) != 1) { if ($db->num_rows($resql) != 1) {
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($arrayfields['ef.'.$key]['checked']) && !empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
print "<td></td>"; print "<td></td>";
} }
} }
} else { } else {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
foreach ($extralabels as $key => $value) { foreach ($extralabels as $key => $value) {
if (!empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { if (!empty($arrayfields['ef.'.$key]['checked']) && !empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {
print '<td align="right">'.$extrafields->showOutputField($key, $obj->{$key})."</td>"; print '<td align="right">'.$extrafields->showOutputField($key, $obj->{$key})."</td>";
} }
} }
@ -1087,6 +1144,7 @@ SCRIPT;
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '</form>';
} }
} }
} }