From b3c1ebf30ad99684b5298f6ef19c319d6ddf2bc0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Fri, 19 Jun 2015 12:13:05 +0200 Subject: [PATCH] Debug price per customer --- htdocs/core/class/html.form.class.php | 12 ++-- htdocs/product/price.php | 91 ++++++++++++++++----------- 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c236df18199..51582886af2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -818,15 +818,16 @@ class Form * * @param string $selected Preselected type * @param string $htmlname Name of field in form - * @param string $filter optional filters criteras (example: 's.rowid <> x') + * @param string $filter optional filters criteras (example: 's.rowid <> x', 's.client IN (1,3)') * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param int $limit Maximum number of elements + * @param string $morecss Add more css styles to the SELECT component * @return string HTML string with select box for thirdparty. */ - function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) + function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0, $morecss='minwidth100') { $out=''; @@ -860,7 +861,7 @@ class Form } else {*/ - $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); + $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit, $morecss); //} return $out; @@ -879,9 +880,10 @@ class Form * @param string $filterkey Filter on key value * @param int $outputmode 0=HTML select string, 1=Array * @param int $limit Limit number of answers + * @param string $morecss Add more css styles to the SELECT component * @return string HTML string with */ - function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=0) + function select_thirdparty_list($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0, $events=array(), $filterkey='', $outputmode=0, $limit=0, $morecss='minwidth100') { global $conf,$user,$langs; @@ -935,7 +937,7 @@ class Form } // Construct $out and $outarray - $out.= '<select id="'.$htmlname.'" class="flat minwidth100" name="'.$htmlname.'"'.$nodatarole.'>'."\n"; + $out.= '<select id="'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'"'.$nodatarole.'>'."\n"; $textifempty=''; // Do not use textempty = ' ' or ' ' here, or search on key will search on ' key'. diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 1e454ca724b..915f1988843 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -110,7 +110,9 @@ if (empty($reshook)) break; // We found submited price } } - } else { + } + else + { $level = 0; $newprice = price2num($_POST ["price"], 'MU'); $newprice_min = price2num($_POST ["price_min"], 'MU'); @@ -128,7 +130,8 @@ if (empty($reshook)) $action='edit_price'; } - if ($newprice < $newprice_min && ! empty($object->fk_price_expression)) { + if ($newprice < $newprice_min && ! empty($object->fk_price_expression)) + { $newprice = $newprice_min; //Set price same as min, the user will not see the } @@ -185,11 +188,13 @@ if (empty($reshook)) $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1); } - if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité + if ($action == 'edit_price_by_qty') + { // Edition d'un prix par quantité $rowid = GETPOST('rowid'); } - if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par quantité + if ($action == 'update_price_by_qty') + { // Ajout / Mise à jour d'un prix par quantité // Récupération des variables $rowid = GETPOST('rowid'); @@ -237,7 +242,8 @@ if (empty($reshook)) } } - if ($action == 'delete_price_by_qty') { + if ($action == 'delete_price_by_qty') + { $rowid = GETPOST('rowid'); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_price_by_qty"; @@ -246,7 +252,8 @@ if (empty($reshook)) $result = $db->query($sql); } - if ($action == 'delete_all_price_by_qty') { + if ($action == 'delete_all_price_by_qty') + { $priceid = GETPOST('priceid'); $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_price_by_qty"; @@ -289,14 +296,15 @@ if (empty($reshook)) if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } else { - setEventMessage($langs->trans('Save'), 'mesgs'); + setEventMessage($langs->trans('RecordSaved'), 'mesgs'); } $action = ''; } } - if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) { + if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) + { // Delete price by customer $prodcustprice->id = GETPOST('lineid'); $result = $prodcustprice->delete($user); @@ -304,13 +312,13 @@ if (empty($reshook)) if ($result < 0) { setEventMessage($prodcustprice->error, 'mesgs'); } else { - setEventMessage($langs->trans('Delete'), 'errors'); + setEventMessage($langs->trans('RecordDeleted'), 'errors'); } $action = ''; } - if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { - + if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) + { $maxpricesupplier = $object->min_recommended_price(); $update_child_soc = GETPOST('updatechildprice'); @@ -644,7 +652,7 @@ print '</td></tr>'; print "</table>\n"; -print "</div>\n"; +dol_fiche_end(); /* ************************************************************************** */ @@ -653,7 +661,7 @@ print "</div>\n"; /* */ /* ************************************************************************** */ -if (! $action || $action == 'delete') +if (! $action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'add_customer_price') { print "\n" . '<div class="tabsAction">' . "\n"; @@ -669,7 +677,7 @@ if (! $action || $action == 'delete') */ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->service->creer)) { - print_fiche_titre($langs->trans("NewPrice"), '', ''); + print_fiche_titre($langs->trans("NewPrice"), ''); if (empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -853,8 +861,6 @@ if ($result) if ($num > 0) { - print '<br>'; - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print_fiche_titre($langs->trans("DefaultPrice"),'',''); print '<table class="noborder" width="100%">'; @@ -932,7 +938,8 @@ if ($result) print '<td align="right"><a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $objp->user_id . '">' . img_object($langs->trans("ShowUser"), 'user') . ' ' . $objp->login . '</a></td>'; // Action - if ($user->rights->produit->supprimer) { + if ($user->rights->produit->supprimer) + { print '<td align="right">'; if ($i > 0) { print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete&id=' . $object->id . '&lineid=' . $objp->rowid . '">'; @@ -955,9 +962,9 @@ if ($result) } +// Add area to show/add/edit a price for a dedicated customer if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { - $prodcustprice = new Productcustomerprice($db); $sortfield = GETPOST("sortfield", 'alpha'); @@ -979,7 +986,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $search_soc = GETPOST('search_soc'); if (! empty($search_soc)) { - $filter ['soc.nom'] = $search_soc; + $filter['soc.nom'] = $search_soc; } if ($action == 'add_customer_price') @@ -997,7 +1004,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '<tr>'; print '<td>' . $langs->trans('ThirdParty') . '</td>'; print '<td>'; - print $form->select_company('', 'socid', 's.rowid NOT IN (SELECT fk_soc FROM ' . MAIN_DB_PREFIX . 'product_customer_price WHERE fk_product='.$object->id.')', 1); + print $form->select_company('', 'socid', 's.client in (1,2,3) AND s.rowid NOT IN (SELECT fk_soc FROM ' . MAIN_DB_PREFIX . 'product_customer_price WHERE fk_product='.$object->id.')', 1, 0, 0, array(), 0, 'minwidth300'); print '</td>'; print '</tr>'; @@ -1165,9 +1172,10 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $option = '&socid=' . GETPOST('socid', 'int') . '&id=' . $object->id; - print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVEUR ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords); + print_barre_liste($langs->trans('PriceByCustomerLog'), $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, ''); - if (count($prodcustprice->lines) > 0) { + if (count($prodcustprice->lines) > 0) + { print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">'; print '<input type="hidden" name="id" value="' . $object->id . '">'; @@ -1189,9 +1197,9 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $var = True; - foreach ($prodcustprice->lines as $line) { - - print "<tr $bc[$var]>"; + foreach ($prodcustprice->lines as $line) + { + print "<tr ".$bc[$var].">"; // Date $staticsoc = new Societe($db); $staticsoc->fetch($line->fk_soc); @@ -1219,7 +1227,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } print "\n" . '<div class="tabsAction">' . "\n"; - print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">' . $langs->trans("Ok") . '</a></div>'; + print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '">' . $langs->trans("Back") . '</a></div>'; print "\n</div><br>\n"; } else @@ -1268,12 +1276,12 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '</td>'; print '</tr>'; - if (count($prodcustprice->lines) > 0) { - - $var = True; - - foreach ($prodcustprice->lines as $line) { + if (count($prodcustprice->lines) > 0) + { + $var = False; + foreach ($prodcustprice->lines as $line) + { print "<tr ".$bc[$var].">"; // Date $staticsoc = new Societe($db); @@ -1298,26 +1306,33 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) // Todo Edit or delete button // Action - if ($user->rights->produit->supprimer || $user->rights->service->supprimer) { + if ($user->rights->produit->supprimer || $user->rights->service->supprimer) + { print '<td align="right">'; - print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete_customer_price&id=' . $object->id . '&lineid=' . $line->id . '">'; - print img_delete(); + print '<a href="' . $_SERVER["PHP_SELF"] . '?action=showlog_customer_price&id=' . $object->id . '&socid=' . $line->fk_soc . '">'; + print img_info(); print '</a>'; + print ' '; print '<a href="' . $_SERVER["PHP_SELF"] . '?action=edit_customer_price&id=' . $object->id . '&lineid=' . $line->id . '">'; - print img_edit(); + print img_edit('default', 0, 'style="vertical-align: middle;"'); print '</a>'; - print '<a href="' . $_SERVER["PHP_SELF"] . '?action=showlog_customer_price&id=' . $object->id . '&socid=' . $line->fk_soc . '">'; - print img_info(); + print ' '; + print '<a href="' . $_SERVER["PHP_SELF"] . '?action=delete_customer_price&id=' . $object->id . '&lineid=' . $line->id . '">'; + print img_delete('default', 'style="vertical-align: middle;"'); print '</a>'; print '</td>'; } print "</tr>\n"; } - } else { + } + else + { $colspan=9; if ($user->rights->produit->supprimer || $user->rights->service->supprimer) $colspan+=1; + print "<tr ".$bc[false].">"; print '<td colspan="'.$colspan.'">'.$langs->trans('None').'</td>'; + print "</tr>"; } print "</table>"; -- GitLab