Merge pull request #14870 from atm-john/12.0_add_filters_on_tab_soc_price

ADD : Filters more filters on customer price tab
This commit is contained in:
Laurent Destailleur 2020-10-02 15:40:52 +02:00 committed by GitHub
commit b15d862f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 13 deletions

View File

@ -252,7 +252,6 @@ class Productcustomerprice extends CommonObject
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.tms,";
@ -330,7 +329,6 @@ class Productcustomerprice extends CommonObject
$sql = "SELECT";
$sql .= " t.rowid,";
$sql .= " t.entity,";
$sql .= " t.datec,";
$sql .= " t.tms,";
@ -363,15 +361,16 @@ class Productcustomerprice extends CommonObject
// Manage filter
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if (strpos($key, 'date')) // To allow $filter['YEAR(s.dated)']=>$year
{
$sql .= ' AND '.$key.' = \''.$value.'\'';
if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
$sql .= ' AND '.$key.' = \''.$this->db->escape($value).'\'';
} elseif ($key == 'soc.nom') {
$sql .= ' AND '.$key.' LIKE \'%'.$value.'%\'';
} elseif ($key == 'prod.ref') {
$sql .= ' AND '.$key.' LIKE \'%'.$value.'%\'';
$sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
} elseif ($key == 'prod.ref' || $key == 'prod.label') {
$sql .= ' AND '.$key.' LIKE \'%'.$this->db->escape($value).'%\'';
} elseif ($key == 't.price' || $key == 't.price_ttc') {
$sql .= ' AND ' . $key . ' LIKE \'%' . price2num($value) . '%\'';
} else {
$sql .= ' AND '.$key.' = '.$value;
$sql .= ' AND '.$key.' = '.((int) $value);
}
}
}

View File

@ -43,6 +43,9 @@ $langs->loadLangs(array("products", "companies", "bills"));
$action = GETPOST('action', 'aZ09');
$search_prod = GETPOST('search_prod', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$search_label = GETPOST('search_label', 'alpha');
$search_price = GETPOST('search_price');
$search_price_ttc = GETPOST('search_price_ttc');
// Security check
$socid = GETPOST('socid', 'int') ?GETPOST('socid', 'int') : GETPOST('id', 'int');
@ -70,7 +73,7 @@ if (empty($reshook))
{
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_prod = '';
$search_prod = $search_label = $search_price = $search_price_ttc = '';
}
if ($action == 'add_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
@ -259,6 +262,18 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
$filter ['prod.ref'] = $search_prod;
}
if (! empty($search_label)) {
$filter ['prod.label'] = $search_label;
}
if (! empty($search_price)) {
$filter ['t.price'] = $search_price;
}
if (! empty($search_price_ttc)) {
$filter ['t.price_ttc'] = $search_price_ttc;
}
if ($action == 'add_customer_price') {
// Create mode
@ -517,7 +532,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
}
$option = '&search_prod='.$search_prod.'&id='.$object->id;
$option = '&search_prod=' . $search_prod . '&id=' . $object->id . '&label=' . $search_label .'&price=' . $search_price . '&price_ttc=' . $search_price_ttc;
print '<!-- view specific price for each product -->'."\n";
@ -530,7 +545,8 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Product").'</td>';
print '<td>' . $langs->trans("Ref") . '</td>';
print '<td>' . $langs->trans("Product") . '</td>';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
print '<td class="center">'.$langs->trans("PriceBase").'</td>';
print '<td class="right">'.$langs->trans("VAT").'</td>';
@ -546,7 +562,11 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
{
print '<tr class="liste_titre">';
print '<td class="liste_titre"><input type="text" class="flat" name="search_prod" value="'.$search_prod.'" size="20"></td>';
print '<td class="liste_titre" colspan="8">&nbsp;</td>';
print '<td class="liste_titre" ><input type="text" class="flat" name="search_label" value="' . $search_label . '" size="20"></td>';
print '<td class="liste_titre" colspan="3">&nbsp;</td>';
print '<td class="liste_titre" align="right"><input type="text" class="flat" name="search_price" value="' . $search_price . '" size="10"></td>';
print '<td class="liste_titre" align="right"><input type="text" class="flat" name="search_price_ttc" value="' . $search_price_ttc . '" size="10"></td>';
print '<td class="liste_titre" colspan="3">&nbsp;</td>';
// Print the search button
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
@ -565,6 +585,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
$staticprod->fetch($line->fk_product);
print "<td>".$staticprod->getNomUrl(1)."</td>";
print "<td>" . $staticprod->label ."</td>";
print "<td>".dol_print_date($line->datec, "dayhour")."</td>";
print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";