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">';
286 print $langs->trans(
'CustomerCode').
'</td><td colspan="3">';
288 $tmpcheck =
$object->check_codeclient();
289 if ($tmpcheck != 0 && $tmpcheck != -5) {
290 print
' <span class="error">('.$langs->trans(
"WrongCustomerCode").
')</span>';
296 print
'<tr><td class="titlefield">';
297 print $langs->trans(
'SupplierCode').
'</td><td colspan="3">';
298 print
$object->code_fournisseur;
299 $tmpcheck =
$object->check_codefournisseur();
300 if ($tmpcheck != 0 && $tmpcheck != -5) {
301 print
' <span class="error">('.$langs->trans(
"WrongSupplierCode").
')</span>';
317 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
318 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
321 if (empty($page) || $page == -1) {
324 $offset = $limit * $page;
325 $pageprev = $page - 1;
326 $pagenext = $page + 1;
328 $sortorder =
"ASC,ASC";
331 $sortfield =
"soc.nom,t.date_begin";
336 't.fk_soc' => (
string)
$object->id
339 if (!empty($search_prod)) {
340 $filter [
'prod.ref'] = (string) $search_prod;
343 if (!empty($search_label)) {
344 $filter [
'prod.label'] = (string) $search_label;
347 if (!empty($search_price)) {
348 $filter [
't.price'] = (string) $search_price;
351 if (!empty($search_price_ttc)) {
352 $filter [
't.price_ttc'] = (string) $search_price_ttc;
355 if ($action ==
'add_customer_price') {
359 print
'<!-- Price by customer -->'.
"\n";
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="add_customer_price_confirm">';
366 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
367 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
368 print
'<input type="hidden" name="socid" value="'.$object->id.
'">';
369 print
'<table class="border centpercent">';
371 print
'<td>'.$langs->trans(
'Product').
'</td>';
373 $form->select_produits(
GETPOSTINT(
'prodid'),
'prodid',
'', 0);
378 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
379 print
'<td><input name="ref_customer" size="12"></td></tr>';
383 print
'<tr><td>'.$langs->trans(
"AppliedPricesFrom").
'</td><td>';
384 print $form->selectDate(!empty($date_begin) ? $date_begin :
dol_now(),
"date_begin", 0, 0, 1,
"date_begin");
389 print
'<tr><td>'.$langs->trans(
"AppliedPricesTo").
'</td><td>';
390 print $form->selectDate($date_end,
"date_end", 0, 0, 1,
"date_end");
394 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
395 print $form->load_tva(
"tva_tx",
GETPOST(
"tva_tx",
"alpha"),
$mysoc,
null,
$object->id, 0,
'',
false, 1);
399 print
'<tr><td width="15%">';
400 print $langs->trans(
'PriceBase');
403 print $form->selectPriceBaseType(
GETPOST(
"price_base_type",
"aZ09"),
"price_base_type");
408 print
'<tr><td width="20%">';
409 $text = $langs->trans(
'SellingPrice');
410 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
412 print
'<input name="price" size="10" value="'.GETPOSTINT(
'price').
'">';
417 $text = $langs->trans(
'MinPrice');
418 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
419 print
'<td><input name="price_min" size="10" value="'.GETPOSTINT(
'price_min').
'">';
424 print
'<tr><td>'.$langs->trans(
"Discount").
'</td><td>';
425 print
'<input name="discount_percent" size="10" value="'.price($discount_percent).
'">';
429 print
'<tr><td width="15%">';
430 print $langs->trans(
'ForceUpdateChildPriceSoc');
433 print
'<input type="checkbox" name="updatechildprice" value="1"/>';
438 $extrafields->fetch_name_optionals_label(
"product_customer_price");
439 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
440 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
441 if (!empty($extralabels)) {
442 if (empty($prodcustprice->id)) {
443 foreach ($extralabels as $key => $value) {
444 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))) {
445 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
446 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
449 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
450 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
451 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
453 print $langs->trans($value);
455 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
463 print $form->buttonsSaveCancel();
466 } elseif ($action ==
'edit_customer_price') {
471 $result = $prodcustprice->fetch(
GETPOSTINT(
'lineid'));
476 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'" method="POST">';
477 print
'<input type="hidden" name="token" value="'.newToken().
'">';
478 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
479 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
480 print
'<table class="border centpercent">';
482 print
'<td>'.$langs->trans(
'Product').
'</td>';
483 $staticprod =
new Product($db);
484 $staticprod->fetch($prodcustprice->fk_product);
485 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
489 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
490 print
'<td><input name="ref_customer" size="12" value="'.dol_escape_htmltag($prodcustprice->ref_customer).
'"></td></tr>';
493 print
'<tr><td>'.$langs->trans(
"AppliedPricesFrom").
'</td><td>';
494 print $form->selectDate($prodcustprice->date_begin,
"date_begin", 0, 0, 1,
"date_begin");
498 print
'<tr><td>'.$langs->trans(
"AppliedPricesTo").
'</td><td>';
499 print $form->selectDate($prodcustprice->date_end,
"date_end", 0, 0, 1,
"date_end");
503 print
'<tr><td>'.$langs->trans(
"VATRate").
'</td><td>';
504 print $form->load_tva(
"tva_tx", $prodcustprice->tva_tx,
$mysoc,
null, $staticprod->id, $prodcustprice->recuperableonly);
508 print
'<tr><td width="15%">';
509 print $langs->trans(
'PriceBase');
512 print $form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
518 $text = $langs->trans(
'SellingPrice');
519 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
521 if ($prodcustprice->price_base_type ==
'TTC') {
522 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
524 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
530 $text = $langs->trans(
'MinPrice');
531 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1,
'help');
533 if ($prodcustprice->price_base_type ==
'TTC') {
534 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
536 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
541 print
'<tr><td>'.$langs->trans(
"Discount").
'</td><td>';
542 print
'<input name="discount_percent" size="10" value="'.price($prodcustprice->discount_percent).
'">';
546 $extrafields->fetch_name_optionals_label(
"product_customer_price");
547 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
548 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
549 if (!empty($extralabels)) {
551 foreach ($extralabels as $key => $value) {
552 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))) {
553 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
554 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
557 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
558 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
559 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
561 print $langs->trans($value);
563 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
568 $sql .=
" fk_object";
569 foreach ($extralabels as $key => $value) {
570 $sql .=
", ".$db->sanitize($key);
572 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
573 $sql .=
" WHERE fk_object = ".((int) $prodcustprice->id);
574 $resql = $db->query($sql);
576 $obj = $db->fetch_object($resql);
577 foreach ($extralabels as $key => $value) {
578 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))) {
579 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
580 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
583 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
584 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
585 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
587 print $langs->trans($value);
589 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product_customer_price');
603 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
604 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
607 print $form->buttonsSaveCancel();
611 } elseif ($action ==
'showlog_customer_price') {
613 print
'<!-- showlog_customer_price -->'.
"\n";
615 $sortfield =
't.datec';
617 't.fk_product' => (
string)
GETPOSTINT(
'prodid'),
618 't.fk_soc' => (
string) $socid
622 $nbtotalofrecords =
'';
623 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
628 $nbtotalofrecords = $result;
632 $option =
'&socid='.GETPOSTINT(
'socid').
'&prodid='.
GETPOSTINT(
'prodid');
635 print_barre_liste($langs->trans(
'PriceByCustomerLog'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords);
637 if (count($prodcustprice->lines) > 0) {
638 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
639 print
'<input type="hidden" name="token" value="'.newToken().
'">';
640 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
642 print
'<table class="noborder centpercent">';
644 print
'<tr class="liste_titre">';
645 print
'<td>'.$langs->trans(
"Product").
'</td>';
646 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
647 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
648 print
'<td>'.$langs->trans(
"AppliedPricesTo").
'</td>';
649 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
650 print
'<td class="right">'.$langs->trans(
"VAT").
'</td>';
651 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
652 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
653 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
654 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
655 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
656 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
657 print
'<td>'.$langs->trans(
"DateCreation").
'</td>';
660 foreach ($prodcustprice->lines as $line) {
661 $staticprod =
new Product($db);
662 $staticprod->fetch($line->fk_product);
664 $userstatic =
new User($db);
665 $userstatic->fetch($line->fk_user);
667 print
'<tr class="oddeven">';
669 print
"<td>".$staticprod->getNomUrl(1).
"</td>";
670 print
'<td>'.$line->ref_customer.
'</td>';
671 print
"<td>".dol_print_date($line->date_begin,
"day",
'tzuserrel').
"</td>";
672 print
"<td>".dol_print_date($line->date_end,
"day",
'tzuserrel').
"</td>";
674 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
675 print
'<td class="right">'.vatrate($line->tva_tx,
true, $line->recuperableonly).
"</td>";
676 print
'<td class="right">'.price($line->price).
"</td>";
677 print
'<td class="right">'.price($line->price_ttc).
"</td>";
678 print
'<td class="right">'.price($line->price_min).
'</td>';
679 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
680 print
'<td class="right">'.price($line->discount_percent).
'</td>';
683 print
'<td class="right">';
684 print $userstatic->getNomUrl(-1);
686 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
690 print $langs->trans(
'None');
693 print
"\n".
'<div class="tabsAction">'.
"\n";
694 print
'<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?socid='.
$object->id.
'">'.$langs->trans(
"Ok").
'</a></div>';
695 print
"\n</div><br>\n";
702 print
"\n".
'<div class="tabsAction">'.
"\n";
704 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
705 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>';
710 $arrayfields = array();
711 foreach ($prodcustprice->fields as $key => $val) {
713 if (!empty($val[
'visible'])) {
714 $visible = (int)
dol_eval((
string) $val[
'visible'], 1, 1,
'1');
715 $arrayfields[
't.'.$key] = array(
716 'label' => $val[
'label'],
717 'checked' => (($visible < 0) ? 0 : 1),
718 'enabled' => (abs($visible) != 3 && (bool)
dol_eval((string) $val[
'enabled'], 1)),
719 'position' => $val[
'position'],
720 'help' => isset($val[
'help']) ? $val[
'help'] :
''
725 $extrafields->fetch_name_optionals_label(
"product_customer_price");
726 if ($extrafields->attributes[
"product_customer_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_customer_price"])) {
727 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
729 if (!empty($extralabels)) {
730 foreach ($extralabels as $key => $value) {
732 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
733 $extratitle = $langs->trans($value);
734 if (!empty($val[
'visible'])) {
735 $visible = (int)
dol_eval((
string) $val[
'visible'], 1, 1,
'1');
736 $arrayfields[
'ef.' . $key] = array(
737 'label' => $extratitle,
738 'checked' => (($visible < 0) ? 0 : 1),
739 'position' => (int) $extrafields->attributes[
'product_customer_price'][
'pos'][$key],
740 'langfile' => $extrafields->attributes[
"product_customer_price"][
'langfile'][$key],
741 'help' => $extrafields->attributes[
"product_customer_price"][
'help'][$key]
752 $nbtotalofrecords =
'';
754 $nbtotalofrecords = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
757 $result = $prodcustprice->fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
762 $option =
'&search_prod='.$search_prod.
'&id='.
$object->id.
'&label='.$search_label.
'&price='.$search_price.
'&price_ttc='.$search_price_ttc;
764 print
'<!-- view specific price for each product -->'.
"\n";
767 print_barre_liste($langs->trans(
'PriceForEachProduct'), $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'');
769 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
770 print
'<input type="hidden" name="token" value="'.newToken().
'">';
771 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
772 if (!empty($sortfield)) {
773 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
775 if (!empty($sortorder)) {
776 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
778 print
'<div class="div-table-responsive-no-min">';
779 print
'<table class="noborder centpercent liste">';
781 $param =
'socid='.$object->id.
'&';
783 $param .=
'&search_prod='.urlencode($search_prod);
786 $param .=
'&search_label='.urlencode($search_label);
789 $param .=
'&search_price='.urlencode($search_price);
792 $param .=
'&search_price='.urlencode($search_price);
794 if ($search_price_ttc) {
795 $param .=
'&search_price_ttc='.urlencode($search_price_ttc);
798 print
'<tr class="liste_titre">';
802 foreach ($prodcustprice->fields as $key => $val) {
803 if (!empty($arrayfields[
't.'.$key][
'checked'])) {
804 print
getTitleFieldOfList($arrayfields[
't.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'], $key,
'', $param,
'', $sortfield, $sortorder).
"\n";
808 if (!empty($extralabels) && is_array($extralabels)) {
809 foreach ($extralabels as $key => $val) {
810 if (!empty($arrayfields[
'ef.'.$key][
'checked'])) {
811 print
getTitleFieldOfList($arrayfields[
'ef.'.$key][
'label'], 0, $_SERVER[
'PHP_SELF'], $key,
'', $param,
'', $sortfield, $sortorder).
"\n";
821 if (count($prodcustprice->lines) > 0 || $search_prod) {
822 print
'<tr class="liste_titre">';
823 print
'<td class="liste_titre"><input type="text" class="flat width75" name="search_prod" value="'.$search_prod.
'"></td>';
824 print
'<td class="liste_titre" ><input type="text" class="flat width75" name="search_label" value="'.$search_label.
'"></td>';
825 print
'<td class="liste_titre"></td>';
826 print
'<td class="liste_titre"></td>';
827 print
'<td class="liste_titre"></td>';
828 print
'<td class="liste_titre"></td>';
829 print
'<td class="liste_titre"></td>';
830 print
'<td class="liste_titre left"><input type="text" class="flat width75" name="search_price" value="'.$search_price.
'"></td>';
831 print
'<td class="liste_titre left"><input type="text" class="flat width75" name="search_price_ttc" value="'.$search_price_ttc.
'"></td>';
832 print
'<td class="liste_titre"></td>';
833 print
'<td class="liste_titre"></td>';
834 print
'<td class="liste_titre"></td>';
835 print
'<td class="liste_titre"></td>';
836 print
'<td class="liste_titre"></td>';
837 if (!empty($extralabels)) {
838 foreach ($extralabels as $key) {
839 print
'<td class="right"></td>';
843 print
'<td class="liste_titre maxwidthsearch">';
844 $searchpicto = $form->showFilterAndCheckAddButtons(0);
850 if (count($prodcustprice->lines) > 0) {
851 foreach ($prodcustprice->lines as $line) {
852 $staticprod =
new Product($db);
853 $staticprod->fetch($line->fk_product);
855 $userstatic =
new User($db);
856 $userstatic->fetch($line->fk_user);
858 print
'<tr class="oddeven">';
860 print
'<td class="left">'.$staticprod->getNomUrl(1).
"</td>";
861 print
'<td class="left">'.$staticprod->label.
"</td>";
862 print
'<td class="left">'.$line->ref_customer.
'</td>';
863 print
'<td class="left">'.dol_print_date($line->date_begin,
"day",
'tzuserrel').
"</td>";
864 print
'<td class="left">'.dol_print_date($line->date_end,
"day",
'tzuserrel').
"</td>";
865 print
'<td class="left">'.$langs->trans($line->price_base_type).
"</td>";
866 print
'<td class="left">'.vatrate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, $line->recuperableonly).
"</td>";
867 print
'<td class="left">'.price($line->price).
"</td>";
868 print
'<td class="left">'.price($line->price_ttc).
"</td>";
869 print
'<td class="left">'.price($line->price_min).
'</td>';
870 print
'<td class="left">'.price($line->price_min_ttc).
'</td>';
871 print
'<td class="left">'.$line->price_label.
'</td>';
872 print
'<td class="left">'.price($line->discount_percent).
'</td>';
874 print
'<td class="left">';
875 print $userstatic->getNomUrl(-1);
879 $extrafields->fetch_name_optionals_label(
"product_customer_price");
880 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
881 if (!empty($extralabels)) {
883 $sql .=
" fk_object";
884 foreach ($extralabels as $key => $value) {
885 $sql .=
", ".$db->sanitize($key);
887 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
888 $sql .=
" WHERE fk_object = ".((int) $line->id);
889 $resql = $db->query($sql);
891 if ($db->num_rows($resql) != 1) {
892 foreach ($extralabels as $key => $value) {
893 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
898 $obj = $db->fetch_object($resql);
899 foreach ($extralabels as $key => $value) {
900 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
901 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_customer_price').
"</td>";
909 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
910 print
'<td class="right nowraponall">';
911 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&prodid='.$line->fk_product.
'">';
915 print
'<a class="editfielda paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&lineid='.$line->id.
'">';
916 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
919 print
'<a class="paddingleftonly paddingrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&socid='.
$object->id.
'&lineid='.$line->id.
'">';
920 print
img_delete(
'default',
'style="vertical-align: middle;"');
928 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
931 print
'<tr class="oddeven"><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
'None').
'</span></td></tr>';
if(! $sortfield) if(! $sortorder) $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_now($mode='gmt')
Return date for now.
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...
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.
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
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.