29 require
'../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
36 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
41 $langs->loadLangs(array(
"products",
"companies",
"bills"));
43 $action =
GETPOST(
'action',
'aZ09');
44 $search_prod =
GETPOST(
'search_prod',
'alpha');
45 $cancel =
GETPOST(
'cancel',
'alpha');
46 $search_label =
GETPOST(
'search_label',
'alpha');
47 $search_price =
GETPOST(
'search_price');
48 $search_price_ttc =
GETPOST(
'search_price_ttc');
53 $socid = $user->socid;
60 $hookmanager->initHooks(array(
'thirdpartycustomerprice',
'globalcard'));
69 $parameters = array(
'id'=>$socid);
70 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
75 if (empty($reshook)) {
76 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
77 $search_prod = $search_label = $search_price = $search_price_ttc =
'';
80 if ($action ==
'add_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
81 if (!(
GETPOST(
'prodid',
'int') > 0)) {
83 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->trans(
"Product")),
null,
'errors');
84 $action =
'add_customer_price';
88 $update_child_soc =
GETPOST(
'updatechildprice');
91 $prodcustprice->fk_soc = $socid;
92 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
93 $prodcustprice->fk_product =
GETPOST(
'prodid',
'int');
96 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
98 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
102 $tva_tx = preg_replace(
'/[^0-9\.].*$/',
'', $tva_tx_txt);
103 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
104 $localtax1 = 0; $localtax2 = 0; $localtax1_type =
'0'; $localtax2_type =
'0';
106 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
108 $vatratecode = $reg[1];
110 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
111 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
112 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
113 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
114 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
115 $resql = $db->query($sql);
117 $obj = $db->fetch_object(
$resql);
118 $npr = $obj->recuperableonly;
119 $localtax1 = $obj->localtax1;
120 $localtax2 = $obj->localtax2;
121 $localtax1_type = $obj->localtax1_type;
122 $localtax2_type = $obj->localtax2_type;
126 $prodcustprice->default_vat_code = $vatratecode;
127 $prodcustprice->tva_tx = $tva_tx;
128 $prodcustprice->recuperableonly = $npr;
129 $prodcustprice->localtax1_tx = $localtax1;
130 $prodcustprice->localtax2_tx = $localtax2;
131 $prodcustprice->localtax1_type = $localtax1_type;
132 $prodcustprice->localtax2_type = $localtax2_type;
134 $result = $prodcustprice->create($user, 0, $update_child_soc);
146 if ($action ==
'delete_customer_price' && ($user->rights->produit->creer || $user->rights->service->creer)) {
148 $prodcustprice->id =
GETPOST(
'lineid',
'int');
149 $result = $prodcustprice->delete($user);
159 if ($action ==
'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
160 $prodcustprice->fetch(
GETPOST(
'lineid',
'int'));
162 $update_child_soc =
GETPOST(
'updatechildprice');
165 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
168 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
169 $prodcustprice->tva_tx = str_replace(
'*',
'',
GETPOST(
"tva_tx"));
170 $prodcustprice->recuperableonly = (preg_match(
'/\*/',
GETPOST(
"tva_tx")) ? 1 : 0);
172 $result = $prodcustprice->update($user, 0, $update_child_soc);
192 $result = $object->fetch($socid);
193 llxHeader(
"", $langs->trans(
"ThirdParty").
'-'.$langs->trans(
'PriceByCustomer'));
195 if (!empty($conf->notification->enabled)) {
196 $langs->load(
"mails");
202 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
204 dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
206 print
'<div class="fichecenter">';
208 print
'<div class="underbanner clearboth"></div>';
209 print
'<table class="border centpercent tableforfield">';
211 if (!empty($conf->global->SOCIETE_USEPREFIX)) {
212 print
'<tr><td class="titlefield">'.$langs->trans(
'Prefix').
'</td><td colspan="3">'.$object->prefix_comm.
'</td></tr>';
215 if ($object->client) {
216 print
'<tr><td class="titlefield">';
217 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
218 print $object->code_client;
219 $tmpcheck = $object->check_codeclient();
220 if ($tmpcheck != 0 && $tmpcheck != -5) {
221 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
226 if ($object->fournisseur) {
227 print
'<tr><td class="titlefield">';
228 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
229 print $object->code_fournisseur;
230 $tmpcheck = $object->check_codefournisseur();
231 if ($tmpcheck != 0 && $tmpcheck != -5) {
232 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
245 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
248 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
249 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
250 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
252 if (empty($page) || $page == -1) {
255 $offset = $limit * $page;
256 $pageprev = $page - 1;
257 $pagenext = $page + 1;
262 $sortfield =
"soc.nom";
267 't.fk_soc' => $object->id
270 if (!empty($search_prod)) {
271 $filter [
'prod.ref'] = $search_prod;
274 if (!empty($search_label)) {
275 $filter [
'prod.label'] = $search_label;
278 if (!empty($search_price)) {
279 $filter [
't.price'] = $search_price;
282 if (!empty($search_price_ttc)) {
283 $filter [
't.price_ttc'] = $search_price_ttc;
286 if ($action ==
'add_customer_price') {
290 print
'<!-- Price by customer -->'.
"\n";
294 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'" method="POST">';
295 print
'<input type="hidden" name="token" value="'.newToken().
'">';
296 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
297 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
298 print
'<table class="border centpercent">';
300 print
'<td>'.$langs->trans(
'Product').
'</td>';
302 $form->select_produits(
'',
'prodid',
'', 0);
307 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
308 print
'<td><input name="ref_customer" size="12"></td></tr>';
311 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
312 print
$form->load_tva(
"tva_tx", $object->tva_tx, $mysoc,
'', $object->id, $object->tva_npr,
'',
false, 1);
316 print
'<tr><td width="15%">';
317 print $langs->trans(
'PriceBase');
320 print
$form->selectPriceBaseType($object->price_base_type,
"price_base_type");
325 print
'<tr><td width="20%">';
326 $text = $langs->trans(
'SellingPrice');
327 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
329 print
'<input name="price" size="10" value="'.GETPOST(
'price',
'int').
'">';
334 $text = $langs->trans(
'MinPrice');
335 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
336 print
'<td><input name="price_min" size="10" value="'.GETPOST(
'price_min',
'int').
'">';
340 print
'<tr><td width="15%">';
341 print $langs->trans(
'ForceUpdateChildPriceSoc');
344 print
'<input type="checkbox" name="updatechildprice" value="1"/>';
350 print
$form->buttonsSaveCancel();
353 } elseif ($action ==
'edit_customer_price') {
358 $result = $prodcustprice->fetch(
GETPOST(
'lineid',
'int'));
363 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'" method="POST">';
364 print
'<input type="hidden" name="token" value="'.newToken().
'">';
365 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
366 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
367 print
'<table class="border centpercent">';
369 print
'<td>'.$langs->trans(
'Product').
'</td>';
370 $staticprod =
new Product($db);
371 $staticprod->fetch($prodcustprice->fk_product);
372 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
376 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
377 print
'<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).
'"></td></tr>';
380 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
381 print
$form->load_tva(
"tva_tx", $prodcustprice->tva_tx, $mysoc,
'', $staticprod->id, $prodcustprice->recuperableonly);
385 print
'<tr><td width="15%">';
386 print $langs->trans(
'PriceBase');
389 print
$form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
395 $text = $langs->trans(
'SellingPrice');
396 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
398 if ($prodcustprice->price_base_type ==
'TTC') {
399 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
401 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
407 $text = $langs->trans(
'MinPrice');
408 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
410 if ($prodcustprice->price_base_type ==
'TTC') {
411 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
413 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
419 print $langs->trans(
'ForceUpdateChildPriceSoc');
422 print
'<input type="checkbox" name="updatechildprice" value="1">';
428 print
$form->buttonsSaveCancel();
432 } elseif ($action ==
'showlog_customer_price') {
434 print
'<!-- showlog_customer_price -->'.
"\n";
437 't.fk_product' =>
GETPOST(
'prodid',
'int'),
442 $nbtotalofrecords =
'';
443 $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
447 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
448 $nbtotalofrecords = $result;
452 $option =
'&socid='.GETPOST(
'socid',
'int').
'&prodid='.
GETPOST(
'prodid',
'int');
454 print_barre_liste($langs->trans(
'PriceByCustomerLog'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords);
456 if (count($prodcustprice->lines) > 0) {
457 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
458 print
'<input type="hidden" name="token" value="'.newToken().
'">';
459 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
461 print
'<table class="noborder centpercent">';
463 print
'<tr class="liste_titre">';
464 print
'<td>'.$langs->trans(
"Product").
'</td>';
465 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
466 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
467 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
468 print
'<td class="right">'.$langs->trans(
"VAT").
'</td>';
469 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
470 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
471 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
472 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
473 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
477 foreach ($prodcustprice->lines as $line) {
478 $staticprod =
new Product($db);
479 $staticprod->fetch($line->fk_product);
481 $userstatic =
new User($db);
482 $userstatic->fetch($line->fk_user);
484 print
'<tr class="oddeven">';
486 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
487 print
'<td>'.$line->ref_customer.
'</td>';
488 print
"<td>".dol_print_date($line->datec,
"dayhour").
"</td>";
490 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
491 print
'<td class="right">'.vatrate($line->tva_tx,
true, $line->recuperableonly).
"</td>";
492 print
'<td class="right">'.price($line->price).
"</td>";
493 print
'<td class="right">'.price($line->price_ttc).
"</td>";
494 print
'<td class="right">'.price($line->price_min).
'</td>';
495 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
498 print
'<td class="right">';
499 print $userstatic->getNomUrl(-1);
505 print $langs->trans(
'None');
508 print
"\n".
'<div class="tabsAction">'.
"\n";
509 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?socid='.$object->id.
'">'.$langs->trans(
"Ok").
'</a></div>';
510 print
"\n</div><br>\n";
517 print
"\n".
'<div class="tabsAction">'.
"\n";
519 if ($user->rights->produit->creer || $user->rights->service->creer) {
520 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=add_customer_price&token='.
newToken().
'&socid='.$object->id.
'">'.$langs->trans(
"AddCustomerPrice").
'</a></div>';
526 $nbtotalofrecords =
'';
527 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
528 $nbtotalofrecords = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
531 $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
536 $option =
'&search_prod='.$search_prod.
'&id='.$object->id.
'&label='.$search_label.
'&price='.$search_price.
'&price_ttc='.$search_price_ttc;
538 print
'<!-- view specific price for each product -->'.
"\n";
540 print_barre_liste($langs->trans(
'PriceForEachProduct'), $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'');
542 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
543 print
'<input type="hidden" name="token" value="'.newToken().
'">';
544 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
546 print
'<div class="div-table-responsive-no-min">';
547 print
'<table class="noborder centpercent">';
549 print
'<tr class="liste_titre">';
550 print
'<td>'.$langs->trans(
"Ref").
'</td>';
551 print
'<td>'.$langs->trans(
"Product").
'</td>';
552 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
553 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
554 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
555 print
'<td class="right">'.$langs->trans(
"VAT").
'</td>';
556 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
557 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
558 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
559 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
560 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
564 if (count($prodcustprice->lines) > 0 || $search_prod) {
565 print
'<tr class="liste_titre">';
566 print
'<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="'.$search_prod.
'"></td>';
567 print
'<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="'.$search_label.
'"></td>';
568 print
'<td class="liste_titre"></td>';
569 print
'<td class="liste_titre"></td>';
570 print
'<td class="liste_titre"></td>';
571 print
'<td class="liste_titre"></td>';
572 print
'<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price" value="'.$search_price.
'"></td>';
573 print
'<td class="liste_titre right"><input type="text" class="flat width75 right" name="search_price_ttc" value="'.$search_price_ttc.
'"></td>';
574 print
'<td class="liste_titre"></td>';
575 print
'<td class="liste_titre"></td>';
576 print
'<td class="liste_titre"></td>';
578 print
'<td class="liste_titre maxwidthsearch">';
579 $searchpicto =
$form->showFilterAndCheckAddButtons(0);
585 if (count($prodcustprice->lines) > 0) {
586 foreach ($prodcustprice->lines as $line) {
587 $staticprod =
new Product($db);
588 $staticprod->fetch($line->fk_product);
590 $userstatic =
new User($db);
591 $userstatic->fetch($line->fk_user);
593 print
'<tr class="oddeven">';
595 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
596 print
"<td>".$staticprod->label.
"</td>";
597 print
'<td>'.$line->ref_customer.
'</td>';
598 print
"<td>".dol_print_date($line->datec,
"dayhour").
"</td>";
599 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
600 print
'<td class="right">'.vatrate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''),
true, $line->recuperableonly).
"</td>";
601 print
'<td class="right">'.price($line->price).
"</td>";
602 print
'<td class="right">'.price($line->price_ttc).
"</td>";
603 print
'<td class="right">'.price($line->price_min).
'</td>';
604 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
606 print
'<td class="right">';
607 print $userstatic->getNomUrl(-1);
610 if ($user->rights->produit->creer || $user->rights->service->creer) {
611 print
'<td class="right nowraponall">';
612 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&socid='.$object->id.
'&prodid='.$line->fk_product.
'">';
616 print
'<a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&socid='.$object->id.
'&lineid='.$line->id.
'">';
617 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
620 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&socid='.$object->id.
'&lineid='.$line->id.
'">';
621 print
img_delete(
'default',
'style="vertical-align: middle;"');
630 if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
633 print
'<tr class="oddeven"><td colspan="'.$colspan.
'">'.$langs->trans(
'None').
'</td></tr>';