35require
'../main.inc.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
46require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
48require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
58$langs->loadLangs(array(
"products",
"companies",
"bills"));
62$action =
GETPOST(
'action',
'aZ09');
63$search_prod =
GETPOST(
'search_prod',
'alpha');
64$cancel =
GETPOST(
'cancel',
'alpha');
65$search_label =
GETPOST(
'search_label',
'alpha');
66$search_price =
GETPOST(
'search_price');
67$search_price_ttc =
GETPOST(
'search_price_ttc');
72 $socid = $user->socid;
76$hookmanager->initHooks(array(
'thirdpartycustomerprice',
'globalcard'));
90$parameters = array(
'id' => $socid);
91$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
97 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
98 $search_prod = $search_label = $search_price = $search_price_ttc =
'';
101 if ($action ==
'add_customer_price_confirm' && $prodcustprice !==
null && !$cancel && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->trans(
"Product")),
null,
'errors');
105 $action =
'add_customer_price';
109 $update_child_soc =
GETPOSTINT(
'updatechildprice');
112 $prodcustprice->fk_soc = $socid;
113 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
114 $prodcustprice->fk_product =
GETPOSTINT(
'prodid');
117 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
122 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
126 $tva_tx = preg_replace(
'/[^0-9\.].*$/',
'', $tva_tx_txt);
127 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
130 $localtax1_type =
'0';
131 $localtax2_type =
'0';
133 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
135 $vatratecode = $reg[1];
137 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
139 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
140 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
141 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
142 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
143 $resql = $db->query($sql);
145 $obj = $db->fetch_object($resql);
146 $npr = $obj->recuperableonly;
147 $localtax1 = $obj->localtax1;
148 $localtax2 = $obj->localtax2;
149 $localtax1_type = $obj->localtax1_type;
150 $localtax2_type = $obj->localtax2_type;
154 $prodcustprice->default_vat_code = $vatratecode;
155 $prodcustprice->tva_tx = $tva_tx;
156 $prodcustprice->recuperableonly = $npr;
157 $prodcustprice->localtax1_tx = $localtax1;
158 $prodcustprice->localtax2_tx = $localtax2;
159 $prodcustprice->localtax1_type = $localtax1_type;
160 $prodcustprice->localtax2_type = $localtax2_type;
162 $result = $prodcustprice->create($user, 0, $update_child_soc);
164 $extrafields->fetch_name_optionals_label(
"product_customer_price");
165 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
166 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
167 if (!empty($extralabels) && is_array($extralabels)) {
169 $res = $productcustomerprice->fetch($prodcustprice->id);
171 foreach ($extrafield_values as $key => $value) {
172 $productcustomerprice->array_options[$key] = $value;
174 $result2 = $productcustomerprice->insertExtraFields();
176 $prodcustprice->error = $productcustomerprice->error;
177 $prodcustprice->errors = $productcustomerprice->errors;
186 $action =
'add_customer_price';
194 if ($action ==
'delete_customer_price' && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
197 $result = $prodcustprice->delete($user);
207 if ($action ==
'update_customer_price_confirm' && $prodcustprice !==
null && !$cancel && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
210 $update_child_soc =
GETPOSTINT(
'updatechildprice');
213 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
216 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
217 $prodcustprice->tva_tx = str_replace(
'*',
'',
GETPOST(
"tva_tx"));
218 $prodcustprice->recuperableonly = (preg_match(
'/\*/',
GETPOST(
"tva_tx")) ? 1 : 0);
223 $result = $prodcustprice->update($user, 0, $update_child_soc);
225 $extrafields->fetch_name_optionals_label(
"product_customer_price");
226 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
227 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
228 if (!empty($extralabels) && is_array($extralabels)) {
230 $res = $productcustomerprice->fetch($prodcustprice->id);
232 foreach ($extrafield_values as $key => $value) {
233 $productcustomerprice->array_options[$key] = $value;
235 $result2 = $productcustomerprice->insertExtraFields();
237 $prodcustprice->error = $productcustomerprice->error;
238 $prodcustprice->errors = $productcustomerprice->errors;
246 $action =
'edit_customer_price';
259$form =
new Form($db);
263$result =
$object->fetch($socid);
264llxHeader(
"", $langs->trans(
"ThirdParty").
'-'.$langs->trans(
'PriceByCustomer'));
270$linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
272dol_banner_tab($object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
274print
'<div class="fichecenter">';
276print
'<div class="underbanner clearboth"></div>';
277print
'<table class="border centpercent tableforfield">';
280print
'<tr><td class="titlefield">'.$langs->trans(
'NatureOfThirdParty').
'</td><td>';
285 print
'<tr><td class="titlefield">'.$langs->trans(
'Prefix').
'</td><td colspan="3">'.
$object->prefix_comm.
'</td></tr>';
289 print
'<tr><td class="titlefield">';
290 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
292 $tmpcheck =
$object->check_codeclient();
293 if ($tmpcheck != 0 && $tmpcheck != -5) {
294 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
300 print
'<tr><td class="titlefield">';
301 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
302 print
$object->code_fournisseur;
303 $tmpcheck =
$object->check_codefournisseur();
304 if ($tmpcheck != 0 && $tmpcheck != -5) {
305 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
321 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
322 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
325 if (empty($page) || $page == -1) {
328 $offset = $limit * $page;
329 $pageprev = $page - 1;
330 $pagenext = $page + 1;
332 $sortorder =
"ASC,ASC";
335 $sortfield =
"soc.nom,t.date_begin";
340 't.fk_soc' => (
string)
$object->id
343 if (!empty($search_prod)) {
344 $filter [
'prod.ref'] = (string) $search_prod;
347 if (!empty($search_label)) {
348 $filter [
'prod.label'] = (string) $search_label;
351 if (!empty($search_price)) {
352 $filter [
't.price'] = (string) $search_price;
355 if (!empty($search_price_ttc)) {
356 $filter [
't.price_ttc'] = (string) $search_price_ttc;
359 if ($action ==
'add_customer_price') {
363 print
'<!-- Price by customer -->'.
"\n";
367 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'" method="POST">';
368 print
'<input type="hidden" name="token" value="'.newToken().
'">';
369 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
370 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
371 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
372 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
373 print
'<table class="border centpercent">';
375 print
'<td>'.$langs->trans(
'Product').
'</td>';
377 $form->select_produits(
GETPOSTINT(
'prodid'),
'prodid',
'', 0);
382 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
383 print
'<td><input name="ref_customer" size="12"></td></tr>';
387 print
'<tr><td>'.$langs->trans(
"AppliedPricesFrom").
'</td><td>';
388 print $form->selectDate(!empty($date_begin) ? $date_begin :
dol_now(),
"date_begin", 0, 0, 1,
"date_begin");
393 print
'<tr><td>'.$langs->trans(
"AppliedPricesTo").
'</td><td>';
394 print $form->selectDate($date_end,
"date_end", 0, 0, 1,
"date_end");
398 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
399 print $form->load_tva(
"tva_tx",
GETPOST(
"tva_tx",
"alpha"), $mysoc,
null,
$object->id, 0,
'',
false, 1);
403 print
'<tr><td width="15%">';
404 print $langs->trans(
'PriceBase');
407 print $form->selectPriceBaseType(
GETPOST(
"price_base_type",
"aZ09"),
"price_base_type");
412 print
'<tr><td width="20%">';
413 $text = $langs->trans(
'SellingPrice');
414 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
416 print
'<input name="price" size="10" value="'.GETPOSTINT(
'price').
'">';
421 $text = $langs->trans(
'MinPrice');
422 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
423 print
'<td><input name="price_min" size="10" value="'.GETPOSTINT(
'price_min').
'">';
428 print
'<tr><td>'.$langs->trans(
"Discount").
'</td><td>';
429 print
'<input name="discount_percent" size="10" value="'.price($discount_percent).
'">';
433 print
'<tr><td width="15%">';
434 print $langs->trans(
'ForceUpdateChildPriceSoc');
437 print
'<input type="checkbox" name="updatechildprice" value="1"/>';
442 $extrafields->fetch_name_optionals_label(
"product_customer_price");
443 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
444 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
445 if (!empty($extralabels)) {
446 if (empty($prodcustprice->id)) {
447 foreach ($extralabels as $key => $value) {
448 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && ($extrafields->attributes[
"product_customer_price"][
'list'][$key] == 1 || $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 3 || ($action ==
"add_customer_price" && $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 4))) {
449 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
450 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
453 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
454 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
455 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
457 print $langs->trans($value);
459 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
467 print $form->buttonsSaveCancel();
470 } elseif ($action ==
'edit_customer_price') {
475 $result = $prodcustprice->fetch(
GETPOSTINT(
'lineid'));
480 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'" method="POST">';
481 print
'<input type="hidden" name="token" value="'.newToken().
'">';
482 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
483 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
484 print
'<table class="border centpercent">';
486 print
'<td>'.$langs->trans(
'Product').
'</td>';
487 $staticprod =
new Product($db);
488 $staticprod->fetch($prodcustprice->fk_product);
489 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
493 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
494 print
'<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).
'"></td></tr>';
497 print
'<tr><td>'.$langs->trans(
"AppliedPricesFrom").
'</td><td>';
498 print $form->selectDate($prodcustprice->date_begin,
"date_begin", 0, 0, 1,
"date_begin");
502 print
'<tr><td>'.$langs->trans(
"AppliedPricesTo").
'</td><td>';
503 print $form->selectDate($prodcustprice->date_end,
"date_end", 0, 0, 1,
"date_end");
507 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
508 print $form->load_tva(
"tva_tx", $prodcustprice->tva_tx, $mysoc,
null, $staticprod->id, $prodcustprice->recuperableonly);
512 print
'<tr><td width="15%">';
513 print $langs->trans(
'PriceBase');
516 print $form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
522 $text = $langs->trans(
'SellingPrice');
523 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
525 if ($prodcustprice->price_base_type ==
'TTC') {
526 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
528 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
534 $text = $langs->trans(
'MinPrice');
535 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
537 if ($prodcustprice->price_base_type ==
'TTC') {
538 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
540 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
545 print
'<tr><td>'.$langs->trans(
"Discount").
'</td><td>';
546 print
'<input name="discount_percent" size="10" value="'.price($prodcustprice->discount_percent).
'">';
550 $extrafields->fetch_name_optionals_label(
"product_customer_price");
551 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
552 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
553 if (!empty($extralabels)) {
555 foreach ($extralabels as $key => $value) {
556 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && ($extrafields->attributes[
"product_customer_price"][
'list'][$key] == 1 || $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 3 || ($action ==
"edit_price" && $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 4))) {
557 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
558 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
561 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
562 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
563 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
565 print $langs->trans($value);
567 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
572 $sql .=
" fk_object";
573 foreach ($extralabels as $key => $value) {
574 $sql .=
", ".$db->sanitize($key);
576 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
577 $sql .=
" WHERE fk_object = ".((int) $prodcustprice->id);
578 $resql = $db->query($sql);
580 $obj = $db->fetch_object($resql);
581 foreach ($extralabels as $key => $value) {
582 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && ($extrafields->attributes[
"product_customer_price"][
'list'][$key] == 1 || $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 3 || ($action ==
"edit_price" && $extrafields->attributes[
"product_customer_price"][
'list'][$key] == 4))) {
583 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
584 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
587 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
588 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
589 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
591 print $langs->trans($value);
593 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product_customer_price');
607 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
608 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
611 print $form->buttonsSaveCancel();
615 } elseif ($action ==
'showlog_customer_price') {
617 print
'<!-- showlog_customer_price -->'.
"\n";
619 $sortfield =
't.datec';
621 't.fk_product' => (
string)
GETPOSTINT(
'prodid'),
622 't.fk_soc' => (
string) $socid
626 $nbtotalofrecords =
'';
627 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
632 $nbtotalofrecords = $result;
636 $option =
'&socid='.GETPOSTINT(
'socid').
'&prodid='.
GETPOSTINT(
'prodid');
639 print_barre_liste($langs->trans(
'PriceByCustomerLog'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords);
641 if (count($prodcustprice->lines) > 0) {
642 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
643 print
'<input type="hidden" name="token" value="'.newToken().
'">';
644 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
646 print
'<table class="noborder centpercent">';
648 print
'<tr class="liste_titre">';
649 print
'<td>'.$langs->trans(
"Product").
'</td>';
650 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
651 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
652 print
'<td>'.$langs->trans(
"AppliedPricesTo").
'</td>';
653 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
654 print
'<td class="right">'.$langs->trans(
"VAT").
'</td>';
655 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
656 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
657 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
658 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
659 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
660 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
661 print
'<td>'.$langs->trans(
"DateCreation").
'</td>';
664 foreach ($prodcustprice->lines as $line) {
665 $staticprod =
new Product($db);
666 $staticprod->fetch($line->fk_product);
668 $userstatic =
new User($db);
669 $userstatic->fetch($line->fk_user);
671 print
'<tr class="oddeven">';
673 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
674 print
'<td>'.$line->ref_customer.
'</td>';
675 print
"<td>".dol_print_date($line->date_begin,
"day",
'tzuserrel').
"</td>";
676 print
"<td>".dol_print_date($line->date_end,
"day",
'tzuserrel').
"</td>";
678 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
679 print
'<td class="right">'.vatrate($line->tva_tx,
true, $line->recuperableonly).
"</td>";
680 print
'<td class="right">'.price($line->price).
"</td>";
681 print
'<td class="right">'.price($line->price_ttc).
"</td>";
682 print
'<td class="right">'.price($line->price_min).
'</td>';
683 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
684 print
'<td class="right">'.price($line->discount_percent).
'</td>';
687 print
'<td class="right">';
688 print $userstatic->getNomUrl(-1);
690 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
694 print $langs->trans(
'None');
697 print
"\n".
'<div class="tabsAction">'.
"\n";
698 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'">'.$langs->trans(
"Ok").
'</a></div>';
699 print
"\n</div><br>\n";
706 print
"\n".
'<div class="tabsAction">'.
"\n";
708 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
709 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>';
714 $arrayfields = array();
715 foreach ($prodcustprice->fields as $key => $val) {
717 if (!empty($val[
'visible'])) {
718 $visible = (int)
dol_eval((
string) $val[
'visible'], 1, 1,
'1');
719 $arrayfields[
't.'.$key] = array(
720 'label' => $val[
'label'],
721 'checked' => (($visible < 0) ? 0 : 1),
722 'enabled' => (abs($visible) != 3 && (bool)
dol_eval((string) $val[
'enabled'], 1)),
723 'position' => $val[
'position'],
724 'help' => isset($val[
'help']) ? $val[
'help'] :
''
729 $extrafields->fetch_name_optionals_label(
"product_customer_price");
730 if ($extrafields->attributes[
"product_customer_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_customer_price"])) {
731 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
733 if (!empty($extralabels)) {
734 foreach ($extralabels as $key => $value) {
736 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
737 $extratitle = $langs->trans($value);
738 if (!empty($val[
'visible'])) {
739 $visible = (int)
dol_eval((
string) $val[
'visible'], 1, 1,
'1');
740 $arrayfields[
'ef.' . $key] = array(
741 'label' => $extratitle,
742 'checked' => (($visible < 0) ? 0 : 1),
743 'position' => (int) $extrafields->attributes[
'product_customer_price'][
'pos'][$key],
744 'langfile' => $extrafields->attributes[
"product_customer_price"][
'langfile'][$key],
745 'help' => $extrafields->attributes[
"product_customer_price"][
'help'][$key]
756 $nbtotalofrecords =
'';
758 $nbtotalofrecords = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
761 $result = $prodcustprice->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
766 $option =
'&search_prod='.$search_prod.
'&id='.
$object->id.
'&label='.$search_label.
'&price='.$search_price.
'&price_ttc='.$search_price_ttc;
768 print
'<!-- view specific price for each product -->'.
"\n";
771 print_barre_liste($langs->trans(
'PriceForEachProduct'), $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'');
773 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
774 print
'<input type="hidden" name="token" value="'.newToken().
'">';
775 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
776 if (!empty($sortfield)) {
777 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
779 if (!empty($sortorder)) {
780 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
782 print
'<div class="div-table-responsive-no-min">';
783 print
'<table class="noborder centpercent liste">';
785 $param =
'socid='.$object->id.
'&';
787 $param .=
'&search_prod='.urlencode($search_prod);
790 $param .=
'&search_label='.urlencode($search_label);
793 $param .=
'&search_price='.urlencode($search_price);
796 $param .=
'&search_price='.urlencode($search_price);
798 if ($search_price_ttc) {
799 $param .=
'&search_price_ttc='.urlencode($search_price_ttc);
802 print
'<tr class="liste_titre">';
806 foreach ($prodcustprice->fields as $key => $val) {
807 if (!empty($arrayfields[
't.'.$key][
'checked'])) {
808 print
getTitleFieldOfList($arrayfields[
't.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'], $key,
'', $param,
'', $sortfield, $sortorder).
"\n";
812 if (!empty($extralabels) && is_array($extralabels)) {
813 foreach ($extralabels as $key => $val) {
814 if (!empty($arrayfields[
'ef.'.$key][
'checked'])) {
815 print
getTitleFieldOfList($arrayfields[
'ef.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'], $key,
'', $param,
'', $sortfield, $sortorder).
"\n";
825 if (count($prodcustprice->lines) > 0 || $search_prod) {
826 print
'<tr class="liste_titre">';
827 print
'<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="'.$search_prod.
'"></td>';
828 print
'<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="'.$search_label.
'"></td>';
829 print
'<td class="liste_titre"></td>';
830 print
'<td class="liste_titre"></td>';
831 print
'<td class="liste_titre"></td>';
832 print
'<td class="liste_titre"></td>';
833 print
'<td class="liste_titre"></td>';
834 print
'<td class="liste_titre left"><input type="text" class="flat width75" name="search_price" value="'.$search_price.
'"></td>';
835 print
'<td class="liste_titre left"><input type="text" class="flat width75" name="search_price_ttc" value="'.$search_price_ttc.
'"></td>';
836 print
'<td class="liste_titre"></td>';
837 print
'<td class="liste_titre"></td>';
838 print
'<td class="liste_titre"></td>';
839 print
'<td class="liste_titre"></td>';
840 print
'<td class="liste_titre"></td>';
841 if (!empty($extralabels)) {
842 foreach ($extralabels as $key) {
843 print
'<td class="right"></td>';
847 print
'<td class="liste_titre maxwidthsearch">';
848 $searchpicto = $form->showFilterAndCheckAddButtons(0);
854 if (count($prodcustprice->lines) > 0) {
855 foreach ($prodcustprice->lines as $line) {
856 $staticprod =
new Product($db);
857 $staticprod->fetch($line->fk_product);
859 $userstatic =
new User($db);
860 $userstatic->fetch($line->fk_user);
862 print
'<tr class="oddeven">';
864 print
'<td class="left">'.$staticprod->getNomUrl(1).
"</td>";
865 print
'<td class="left">'.$staticprod->label.
"</td>";
866 print
'<td class="left">'.$line->ref_customer.
'</td>';
867 print
'<td class="left">'.dol_print_date($line->date_begin,
"day",
'tzuserrel').
"</td>";
868 print
'<td class="left">'.dol_print_date($line->date_end,
"day",
'tzuserrel').
"</td>";
869 print
'<td class="left">'.$langs->trans($line->price_base_type).
"</td>";
870 print
'<td class="left">'.vatrate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, $line->recuperableonly).
"</td>";
871 print
'<td class="left">'.price($line->price).
"</td>";
872 print
'<td class="left">'.price($line->price_ttc).
"</td>";
873 print
'<td class="left">'.price($line->price_min).
'</td>';
874 print
'<td class="left">'.price($line->price_min_ttc).
'</td>';
875 print
'<td class="left">'.$line->price_label.
'</td>';
876 print
'<td class="left">'.price($line->discount_percent).
'</td>';
878 print
'<td class="left">';
879 print $userstatic->getNomUrl(-1);
883 $extrafields->fetch_name_optionals_label(
"product_customer_price");
884 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
885 if (!empty($extralabels)) {
887 $sql .=
" fk_object";
888 foreach ($extralabels as $key => $value) {
889 $sql .=
", ".$db->sanitize($key);
891 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
892 $sql .=
" WHERE fk_object = ".((int) $line->id);
893 $resql = $db->query($sql);
895 if ($db->num_rows($resql) != 1) {
896 foreach ($extralabels as $key => $value) {
897 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
902 $obj = $db->fetch_object($resql);
903 foreach ($extralabels as $key => $value) {
904 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
905 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_customer_price').
"</td>";
913 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
914 print
'<td class="right nowraponall">';
915 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&prodid='.$line->fk_product.
'">';
919 print
'<a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&lineid='.$line->id.
'">';
920 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
923 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&lineid='.$line->id.
'">';
924 print
img_delete(
'default',
'style="vertical-align: middle;"');
932 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
935 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
'None').
'</span></td></tr>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_info($titlealt='default')
Show info logo.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.