40require
'../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
65$langs->loadLangs(array(
'products',
'bills',
'companies',
'other'));
72$action =
GETPOST(
'action',
'aZ09');
73$cancel =
GETPOST(
'cancel',
'alpha');
76$search_soc =
GETPOST(
'search_soc');
79$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
80$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
82 $socid = $user->socid;
86if ($id > 0 || !empty($ref)) {
94 $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
98$hookmanager->initHooks(array(
'productpricecard',
'globalcard'));
101 if (
$object->type == $object::TYPE_PRODUCT) {
104 if (
$object->type == $object::TYPE_SERVICE) {
108 restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
120$parameters = array(
'id' => $id,
'ref' => $ref);
121$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
126if (empty($reshook)) {
127 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
131 if ($action ==
'setlabelsellingprice' && $user->admin) {
132 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
133 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.GETPOST(
'pricelevel');
138 if (($action ==
'update_vat') && !$cancel && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
139 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
141 $price_label =
GETPOST(
'price_label',
'alpha');
144 $tva_tx = $tva_tx_txt;
147 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
148 $vatratecode = $reg[1];
149 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
152 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
153 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
156 $localtax1_type =
'0';
157 $localtax2_type =
'0';
160 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
162 $vatratecode = $reg[1];
164 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
166 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
167 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
168 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
169 $sql .=
" AND t.type_vat IN (0, 1)";
170 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
171 $resql = $db->query($sql);
173 $obj = $db->fetch_object($resql);
175 $npr = $obj->recuperableonly;
176 $localtax1 = $obj->localtax1;
177 $localtax2 = $obj->localtax2;
178 $localtax1_type = $obj->localtax1_type;
179 $localtax2_type = $obj->localtax2_type;
184 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
185 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
186 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
187 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
188 $sql .=
" AND t.code = ''";
189 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
190 $resql = $db->query($sql);
192 $obj = $db->fetch_object($resql);
194 $npr = $obj->recuperableonly;
195 $localtax1 = $obj->localtax1;
196 $localtax2 = $obj->localtax2;
197 $localtax1_type = $obj->localtax1_type;
198 $localtax2_type = $obj->localtax2_type;
203 $object->default_vat_code = $vatratecode;
206 $object->localtax1_tx = $localtax1;
207 $object->localtax2_tx = $localtax2;
208 $object->localtax1_type = $localtax1_type;
209 $object->localtax2_type = $localtax2_type;
210 $object->price_label = $price_label;
222 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
223 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
225 if (
$object->multiprices_base_type[$i] ==
'HT') {
226 $oldprice =
$object->multiprices[$i];
227 $oldminprice =
$object->multiprices_min[$i];
229 $oldprice =
$object->multiprices_ttc[$i];
230 $oldminprice =
$object->multiprices_min_ttc[$i];
232 $oldpricebasetype =
$object->multiprices_base_type[$i];
233 $oldnpr =
$object->multiprices_recuperableonly[$i];
236 $localtaxarray = array();
238 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
247 if (
$object->price_base_type ==
'HT') {
249 $oldminprice =
$object->price_min;
251 $oldprice =
$object->price_ttc;
252 $oldminprice =
$object->price_min_ttc;
254 $oldpricebasetype =
$object->price_base_type;
258 $localtaxarray = array();
260 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
278 if (($action ==
'update_price' || $action ==
'update_level_price') && !$cancel &&
$object->getRights()->creer) {
280 $pricestoupdate = array();
283 $psq = empty($newpsq) ? 0 : $newpsq;
284 $maxpricesupplier =
$object->min_recommended_price();
286 if (isModEnabled(
'dynamicprices')) {
287 $object->fk_price_expression = empty($eid) ? 0 : $eid;
289 if (
$object->fk_price_expression != 0) {
291 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
294 if ($priceparser->parseProduct($object) < 0) {
303 $newprice =
GETPOST(
'price',
'array');
304 $newprice_min =
GETPOST(
'price_min',
'array');
305 $newpricebase =
GETPOST(
'multiprices_base_type',
'array');
306 $newvattx =
GETPOST(
'tva_tx',
'array');
307 $newvatnpr =
GETPOST(
'tva_npr',
'array');
308 $newlocaltax1_tx =
GETPOST(
'localtax1_tx',
'array');
309 $newlocaltax1_type =
GETPOST(
'localtax1_type',
'array');
310 $newlocaltax2_tx =
GETPOST(
'localtax2_tx',
'array');
311 $newlocaltax2_type =
GETPOST(
'localtax2_type',
'array');
314 $object->price_autogen = (int) (
GETPOST(
'usePriceRules') ==
'on');
316 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
317 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
318 if (!isset($newprice[$i])) {
322 $tva_tx_txt = $newvattx[$i];
324 $tva_tx = $tva_tx_txt;
327 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
328 $vat_src_code = $reg[1];
329 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
331 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
333 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
334 $localtax1 = $newlocaltax1_tx[$i];
335 $localtax1_type = $newlocaltax1_type[$i];
336 $localtax2 = $newlocaltax2_tx[$i];
337 $localtax2_type = $newlocaltax2_type[$i];
338 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
340 $vatratecode = $reg[1];
342 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
344 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
345 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
346 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
347 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
348 $resql = $db->query($sql);
350 $obj = $db->fetch_object($resql);
352 $npr = $obj->recuperableonly;
353 $localtax1 = $obj->localtax1;
354 $localtax2 = $obj->localtax2;
355 $localtax1_type = $obj->localtax1_type;
356 $localtax2_type = $obj->localtax2_type;
360 if (in_array($mysoc->country_code, array(
'ES'))) {
367 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
369 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
370 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
371 $sql .=
" AND t.code = ''";
372 $resql = $db->query($sql);
374 $obj = $db->fetch_object($resql);
376 $npr = $obj->recuperableonly;
377 $localtax1 = $obj->localtax1;
378 $localtax2 = $obj->localtax2;
379 $localtax1_type = $obj->localtax1_type;
380 $localtax2_type = $obj->localtax2_type;
385 $pricestoupdate[$i] = array(
386 'price' =>
price2num($newprice[$i],
'', 2),
387 'price_min' =>
price2num($newprice_min[$i],
'', 2),
388 'price_base_type' => $newpricebase[$i],
389 'default_vat_code' => $vatratecode,
392 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
403 $newpricebase =
GETPOST(
'price_base_type',
'alpha');
404 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
405 $price_label =
GETPOST(
'price_label',
'alpha');
407 $tva_tx = $tva_tx_txt;
410 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
411 $vat_src_code = $reg[1];
412 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
414 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
416 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
419 $localtax1_type =
'0';
420 $localtax2_type =
'0';
422 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
424 $vatratecode = $reg[1];
426 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
427 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
428 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
429 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
430 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
431 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
432 $resql = $db->query($sql);
434 $obj = $db->fetch_object($resql);
436 $npr = $obj->recuperableonly;
437 $localtax1 = $obj->localtax1;
438 $localtax2 = $obj->localtax2;
439 $localtax1_type = $obj->localtax1_type;
440 $localtax2_type = $obj->localtax2_type;
444 if (in_array($mysoc->country_code, array(
'ES'))) {
451 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
452 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
453 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
454 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
455 $sql .=
" AND t.code = ''";
456 $resql = $db->query($sql);
458 $obj = $db->fetch_object($resql);
460 $npr = $obj->recuperableonly;
461 $localtax1 = $obj->localtax1;
462 $localtax2 = $obj->localtax2;
463 $localtax1_type = $obj->localtax1_type;
464 $localtax2_type = $obj->localtax2_type;
469 $pricestoupdate[0] = array(
470 'price' => $newprice,
471 'price_label' => $price_label,
472 'price_min' => $newprice_min,
473 'price_base_type' => $newpricebase,
474 'default_vat_code' => $vatratecode,
477 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
484 foreach ($pricestoupdate as $key => $val) {
485 $newprice = $val[
'price'];
487 if ($val[
'price'] < $val[
'price_min'] && !empty(
$object->fk_price_expression)) {
488 $newprice = $val[
'price_min'];
492 $newprice_min =
price2num($val[
'price_min'],
'MU');
495 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $newprice_min < $maxpricesupplier) {
496 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, - 1, - 1,
'auto')),
null,
'errors');
501 if (!array_key_exists($key,
$object->multiprices) ||
$object->multiprices[$key] != $newprice ||
$object->multiprices_min[$key] != $newprice_min ||
$object->multiprices_base_type[$key] != $val[
'price_base_type'] ||
$object->multiprices_tva_tx[$key] != $newvattx) {
502 $res =
$object->updatePrice($newprice, $val[
'price_base_type'], $user, $val[
'vat_tx'], $newprice_min, $key, $val[
'npr'], $psq, 0, $val[
'localtaxes_array'], $val[
'default_vat_code'], $val[
'price_label']);
514 $price_extralabels = $extrafields->fetch_name_optionals_label(
"product_price");
516 $sql =
"SELECT rowid";
517 $sql .=
" FROM ".$object->db->prefix().
"product_price";
518 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
519 $sql .=
" AND price_level=".((int) $key);
520 $sql .=
" AND fk_product = ".((int)
$object->id);
521 $sql .=
" ORDER BY date_price DESC, rowid DESC";
523 $resql =
$object->db->query($sql);
525 $lineid =
$object->db->fetch_object($resql);
528 if (!empty($lineid->rowid)) {
529 foreach ($price_extralabels as $code => $label) {
530 $code_array =
GETPOST($code,
'array');
531 $object->array_options[
'options_'.$code] = $code_array[$key];
535 $object->table_element =
'product_price';
536 $result =
$object->insertExtraFields();
539 $object->table_element =
'product';
558 $action =
'edit_price';
564 if ($action ==
'delete' && $user->hasRight(
'produit',
'supprimer')) {
572 if ($action ==
'activate_price_by_qty') {
584 if ($action ==
'disable_price_by_qty') {
596 if ($action ==
'edit_price_by_qty') {
601 if ($action ==
'update_price_by_qty') {
611 if (empty($quantity)) {
613 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Qty")),
null,
'errors');
615 if (empty($newprice)) {
617 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Price")),
null,
'errors');
621 if (
$object->price_base_type ==
'TTC') {
626 $unitPrice =
price2num((
float) $price / (
float) $quantity,
'MU');
630 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_price_by_qty SET";
631 $sql .=
" price=".((float) $price).
",";
632 $sql .=
" unitprice=".((float) $unitPrice).
",";
633 $sql .=
" quantity=".((float) $quantity).
",";
634 $sql .=
" remise_percent=".((float) $remise_percent).
",";
635 $sql .=
" remise=".((float) $remise);
636 $sql .=
" WHERE rowid = ".((int) $rowid);
638 $result = $db->query($sql);
643 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
644 $sql .= ((int) $priceid).
','.((float) $price).
','.((float) $unitPrice).
','.((float) $quantity).
','.((float) $remise_percent).
','.((float) $remise).
')';
646 $result = $db->query($sql);
648 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
658 if ($action ==
'delete_price_by_qty') {
660 if (!empty($rowid)) {
661 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
662 $sql .=
" WHERE rowid = ".((int) $rowid);
664 $result = $db->query($sql);
666 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
670 if ($action ==
'delete_all_price_by_qty') {
672 if (!empty($rowid)) {
673 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
674 $sql .=
" WHERE fk_product_price = ".((int) $priceid);
676 $result = $db->query($sql);
678 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
687 if ($action ==
'add_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
688 $maxpricesupplier =
$object->min_recommended_price();
690 $update_child_soc =
GETPOSTINT(
'updatechildprice');
694 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
695 $prodcustprice->fk_product =
$object->id;
698 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
699 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
701 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
702 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
704 $tva_tx_txt =
GETPOST(
"tva_tx",
'alpha');
706 $tva_tx = $tva_tx_txt;
708 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
709 $vat_src_code = $reg[1];
710 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
712 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
714 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
717 $localtax1_type =
'0';
718 $localtax2_type =
'0';
720 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
722 $vatratecode = $reg[1];
724 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
725 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
726 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
727 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
728 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
729 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
730 $resql = $db->query($sql);
732 $obj = $db->fetch_object($resql);
734 $npr = $obj->recuperableonly;
735 $localtax1 = $obj->localtax1;
736 $localtax2 = $obj->localtax2;
737 $localtax1_type = $obj->localtax1_type;
738 $localtax2_type = $obj->localtax2_type;
742 if (in_array($mysoc->country_code, array(
'ES'))) {
749 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
750 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
751 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
752 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
753 $sql .=
" AND t.code = ''";
754 $resql = $db->query($sql);
756 $obj = $db->fetch_object($resql);
758 $npr = $obj->recuperableonly;
759 $localtax1 = $obj->localtax1;
760 $localtax2 = $obj->localtax2;
761 $localtax1_type = $obj->localtax1_type;
762 $localtax2_type = $obj->localtax2_type;
767 $prodcustprice->default_vat_code = $vatratecode;
768 $prodcustprice->tva_tx = $tva_tx;
769 $prodcustprice->recuperableonly = $npr;
770 $prodcustprice->localtax1_tx = $localtax1;
771 $prodcustprice->localtax2_tx = $localtax2;
772 $prodcustprice->localtax1_type = $localtax1_type;
773 $prodcustprice->localtax2_type = $localtax2_type;
775 if (!($prodcustprice->fk_soc > 0)) {
776 $langs->load(
"errors");
777 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
779 $action =
'add_customer_price';
781 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $prodcustprice->price_min < $maxpricesupplier) {
782 $langs->load(
"errors");
783 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
785 $action =
'add_customer_price';
789 $result = $prodcustprice->create($user, 0, $update_child_soc);
791 if (!empty($extrafield_values) && is_array($extrafield_values)) {
793 $res = $productcustomerprice->fetch($prodcustprice->id);
795 foreach ($extrafield_values as $key => $value) {
796 $productcustomerprice->array_options[$key] = $value;
798 $result2 = $productcustomerprice->insertExtraFields();
800 $prodcustprice->error = $productcustomerprice->error;
801 $prodcustprice->errors = $productcustomerprice->errors;
818 if ($action ==
'delete_customer_price' && $prodcustprice !==
null && ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer'))) {
821 $result = $prodcustprice->delete($user);
824 $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields WHERE fk_object = ".((
int) $prodcustprice->id));
839 if ($action ==
'update_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
840 $maxpricesupplier =
$object->min_recommended_price();
842 $update_child_soc =
GETPOSTINT(
'updatechildprice');
847 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
850 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
851 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
853 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
854 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
856 $tva_tx_txt =
GETPOST(
"tva_tx");
858 $tva_tx = $tva_tx_txt;
860 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
861 $vat_src_code = $reg[1];
862 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
864 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
866 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
869 $localtax1_type =
'0';
870 $localtax2_type =
'0';
872 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
874 $vatratecode = $reg[1];
876 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
877 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
878 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
879 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
880 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
881 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
882 $resql = $db->query($sql);
884 $obj = $db->fetch_object($resql);
886 $npr = $obj->recuperableonly;
887 $localtax1 = $obj->localtax1;
888 $localtax2 = $obj->localtax2;
889 $localtax1_type = $obj->localtax1_type;
890 $localtax2_type = $obj->localtax2_type;
894 if (in_array($mysoc->country_code, array(
'ES'))) {
901 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
902 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
903 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
904 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
905 $sql .=
" AND t.code = ''";
906 $resql = $db->query($sql);
908 $obj = $db->fetch_object($resql);
910 $npr = $obj->recuperableonly;
911 $localtax1 = $obj->localtax1;
912 $localtax2 = $obj->localtax2;
913 $localtax1_type = $obj->localtax1_type;
914 $localtax2_type = $obj->localtax2_type;
919 $prodcustprice->default_vat_code = $vatratecode;
920 $prodcustprice->tva_tx = $tva_tx;
921 $prodcustprice->recuperableonly = $npr;
922 $prodcustprice->localtax1_tx = $localtax1;
923 $prodcustprice->localtax2_tx = $localtax2;
924 $prodcustprice->localtax1_type = $localtax1_type;
925 $prodcustprice->localtax2_type = $localtax2_type;
927 if ($prodcustprice->price_min < $maxpricesupplier &&
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
928 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
930 $action =
'update_customer_price';
934 $result = $prodcustprice->update($user, 0, $update_child_soc);
936 if (!empty($extrafield_values) && is_array($extrafield_values)) {
938 $res = $productcustomerprice->fetch($prodcustprice->id);
940 foreach ($extrafield_values as $key => $value) {
941 $productcustomerprice->array_options[$key] = $value;
943 $result2 = $productcustomerprice->insertExtraFields();
945 $prodcustprice->error = $productcustomerprice->error;
946 $prodcustprice->errors = $productcustomerprice->errors;
969$form =
new Form($db);
971if (!empty($id) || !empty($ref)) {
976$title = $langs->trans(
'ProductServiceCard');
980 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
981 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
984 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
985 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
988llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'classforhorizontalscrolloftabs mod-product page-price');
991$titre = $langs->trans(
"CardProduct".
$object->type);
996$linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
997$object->next_prev_filter =
"(te.fk_product_type:=:".((int)
$object->type).
")";
1000if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
1004dol_banner_tab($object,
'ref', $linkback, $shownav,
'ref');
1007print
'<div class="fichecenter">';
1009print
'<div class="underbanner clearboth"></div>';
1010print
'<table class="border tableforfield centpercent">';
1016 if (!empty($socid)) {
1019 $soc->fetch($socid);
1022 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1023 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1024 print
'<tr><td class="">';
1025 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1027 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1032 print
'<tr><td class="titlefieldcreate">';
1033 print $langs->trans(
"SellingPrice");
1035 print
'<td colspan="2">';
1036 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1037 print
'<span class="amount">'.price(
$object->multiprices_ttc[$soc->price_level]).
'</span>';
1039 print
'<span class="amount">'.price(
$object->multiprices[$soc->price_level]).
'</span>';
1041 if (
$object->multiprices_base_type[$soc->price_level]) {
1042 print
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1044 print
' '.$langs->trans(
$object->price_base_type);
1049 print
'<tr><td>'.$langs->trans(
"MinPrice").
'</td><td colspan="2">';
1050 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1051 print
price(
$object->multiprices_min_ttc[$soc->price_level]).
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1053 print
price(
$object->multiprices_min[$soc->price_level]).
' '.$langs->trans(empty(
$object->multiprices_base_type[$soc->price_level]) ?
'HT' :
$object->multiprices_base_type[$soc->price_level]);
1059 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td colspan="2">';
1061 $positiverates =
'';
1063 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_tva_tx[$soc->price_level]);
1066 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax1_tx[$soc->price_level]);
1069 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax2_tx[$soc->price_level]);
1071 if (empty($positiverates)) {
1072 $positiverates =
'0';
1074 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1079 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1081 $positiverates =
'';
1086 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1089 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1091 if (empty($positiverates)) {
1092 $positiverates =
'0';
1094 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1106 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1107 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1108 print
'<tr><td class="">';
1109 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1111 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1116 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1117 print
'<td colspan="2">'.vatrate(
$object->multiprices_tva_tx[1],
true).
'</td>';
1121 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1122 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1123 print
'<tr><td class="">';
1124 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1126 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1131 print
'<!-- Default VAT Rate -->';
1132 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1135 $positiverates =
'';
1137 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->tva_tx);
1140 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax1_tx);
1143 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax2_tx);
1145 if (empty($positiverates)) {
1146 $positiverates =
'0';
1149 print
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 1);
1162 print
'<table class="liste centpercent">';
1163 print
'<tr class="liste_titre"><td>';
1164 print $langs->trans(
"PriceLevel");
1166 print
' <a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editlabelsellingprice&token='.
newToken().
'&pricelevel='.$i.
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'EditSellingPriceLabel'), 0).
'</a>';
1169 print
'<td style="text-align: right">'.$langs->trans(
"SellingPrice").
'</td>';
1170 print
'<td style="text-align: right">'.$langs->trans(
"MinPrice").
'</td>';
1172 $extrafields->fetch_name_optionals_label(
"product_price");
1173 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1174 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1175 if (!empty($extralabels)) {
1176 foreach ($extralabels as $key => $value) {
1178 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1179 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1180 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1182 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1183 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1185 $extratitle = $langs->trans($value);
1187 $field =
'ef.' . $key;
1188 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1195 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1196 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1197 print
'<tr class="oddeven">';
1201 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1202 if (preg_match(
'/editlabelsellingprice/', $action)) {
1203 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
1204 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1205 print
'<input type="hidden" name="action" value="setlabelsellingprice">';
1206 print
'<input type="hidden" name="pricelevel" value="'.$i.
'">';
1207 print $langs->trans(
"SellingPrice").
' '.$i.
' - ';
1208 print
'<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' .
getDolGlobalString($keyforlabel).
'">';
1209 print
' <input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
1212 print $langs->trans(
"SellingPrice").
' '.$i;
1219 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1220 print
'<td class="right"><span class="amount">'.price(
$object->multiprices_ttc[$i]);
1222 print
'<td class="right"><span class="amount">'.price(
$object->multiprices[$i]);
1225 if (
$object->multiprices_base_type[$i]) {
1226 print
' '.$langs->trans(
$object->multiprices_base_type [$i]).
'</span></td>';
1228 print
' '.$langs->trans(
$object->price_base_type).
'</span></td>';
1232 print
'<td style="text-align: right">';
1233 if (empty(
$object->multiprices_base_type[$i])) {
1234 $object->multiprices_base_type[$i] =
"HT";
1236 if (
$object->multiprices_base_type[$i] ==
'TTC') {
1237 print
price(
$object->multiprices_min_ttc[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1239 print
price(
$object->multiprices_min[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1242 if (!empty($extralabels)) {
1243 $sql1 =
"SELECT rowid";
1244 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1245 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1246 $sql1 .=
" AND price_level=".((int) $i);
1247 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1248 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1249 $sql1 .=
" LIMIT 1";
1250 $resql1 =
$object->db->query($sql1);
1252 $lineid =
$object->db->fetch_object($resql1);
1255 $sql2 .=
" fk_object";
1256 foreach ($extralabels as $key => $value) {
1259 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1260 $sql2 .=
" WHERE fk_object = ".((int) $lineid->rowid);
1261 $resql2 = $db->query($sql2);
1263 if ($db->num_rows($resql2) != 1) {
1264 foreach ($extralabels as $key => $value) {
1265 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1266 print
'<td align="right"></td>';
1270 $obj = $db->fetch_object($resql2);
1271 foreach ($extralabels as $key => $value) {
1272 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1273 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_price').
"</td>";
1285 print
'<tr><td>'.$langs->trans(
"PriceByQuantity").
' '.$i;
1289 print
'</td><td colspan="2">';
1291 if (
$object->prices_by_qty[$i] == 1) {
1292 print
'<table width="50%" class="border" summary="List of quantities">';
1294 print
'<tr class="liste_titre">';
1295 print
'<td>'.$langs->trans(
"PriceByQuantityRange").
' '.$i.
'</td>';
1296 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
1297 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1298 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1299 print
'<td> </td>';
1301 foreach (
$object->prices_by_qty_list[$i] as $ii => $prices) {
1302 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1303 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1304 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1305 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1306 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1307 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1308 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1309 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1310 print
'<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"> '.
$object->price_base_type.
'</td>';
1311 print
'<td class="right nowraponall"><input size="5" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1312 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1316 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1317 print
'<td>'.$prices[
'quantity'].
'</td>';
1318 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1319 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1320 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1321 print
'<td class="center">';
1322 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1323 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1325 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1334 if ($action !=
'edit_price_by_qty' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1335 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1336 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1337 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1338 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1339 print
'<input type="hidden" value="0" name="rowid">';
1340 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1341 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1342 print
'<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.
'</td>';
1343 print
'<td class="right"> </td>';
1344 print
'<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
1345 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1351 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=disable_price_by_qty&level='.$i.
'&token='.
newToken().
'">('.$langs->trans(
"DisablePriceByQty").
')</a>';
1353 print $langs->trans(
"No");
1354 print
' <a class="marginleftonly marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=activate_price_by_qty&level='.$i.
'&token='.
newToken().
'">('.$langs->trans(
"Activate").
')</a>';
1362 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1364 $positiverates =
'';
1369 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1372 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1374 if (empty($positiverates)) {
1375 $positiverates =
'0';
1377 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 0, 1);
1387 print
'<tr class="field_selling_price"><td>'.$langs->trans(
"SellingPrice").
'</td><td>';
1388 if (
$object->price_base_type ==
'TTC') {
1393 print
'<i class="opacitymedium"> - ' .
price(
$object->price_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1400 print
'<tr class="field_min_price"><td>'.$langs->trans(
"MinPrice").
'</td><td>';
1401 if (
$object->price_base_type ==
'TTC') {
1406 print
'<i class="opacitymedium"> - ' .
price(
$object->price_min_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1412 print
'<tr class="field_price_label"><td>'.$langs->trans(
"PriceLabel").
'</td><td>';
1418 print
'<tr><td>'.$langs->trans(
"PriceByQuantity");
1419 if (
$object->prices_by_qty[0] == 0) {
1420 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=activate_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"Activate").
')';
1422 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=disable_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"DisablePriceByQty").
')';
1426 if (
$object->prices_by_qty[0] == 1) {
1427 print
'<table width="50%" class="border" summary="List of quantities">';
1428 print
'<tr class="liste_titre">';
1430 print
'<td>'.$langs->trans(
"Quantity").
'</td>';
1431 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
1432 print
'<td class="right"></td>';
1433 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1434 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1435 print
'<td> </td>';
1437 if ($action !=
'edit_price_by_qty') {
1438 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1439 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1440 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1441 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1442 print
'<input type="hidden" value="0" name="rowid">';
1444 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1445 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1446 print
'<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
1450 print
'<td class="right"> </td>';
1451 print
'<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
1452 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1457 foreach (
$object->prices_by_qty_list[0] as $ii => $prices) {
1458 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1459 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1460 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1461 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1462 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1463 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1464 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1465 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1466 print
'<td class="right"><input class="width50 right" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"></td>';
1467 print
'<td class="right">';
1469 print $prices[
'price_base_type'];
1471 print
'<td class="right"> </td>';
1472 print
'<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1473 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1477 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1478 print
'<td>'.$prices[
'quantity'].
'</td>';
1479 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1480 print
'<td class="right">';
1482 print $prices[
'price_base_type'];
1484 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1485 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1486 print
'<td class="center">';
1487 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1488 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1490 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1501 print $langs->trans(
"No");
1510print
'<div class="clearboth"></div>';
1522if (!$action || $action ==
'delete' || $action ==
'showlog_customer_price' || $action ==
'showlog_default_price' || $action ==
'add_customer_price'
1523 || $action ==
'activate_price_by_qty' || $action ==
'disable_price_by_qty') {
1524 print
"\n".
'<div class="tabsAction">'.
"\n";
1527 $parameters = array();
1528 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1529 if (empty($reshook)) {
1531 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1532 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"NoEditVariants")) .
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</a></div>';
1536 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1537 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit_price&token='.newToken().
'&id=' .
$object->id .
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</a></div>';
1539 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</span></div>';
1544 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1545 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?action=add_customer_price&token='.newToken().
'&id=' .
$object->id .
'">' . $langs->trans(
"AddCustomerPrice") .
'</a></div>';
1547 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"AddCustomerPrice") .
'</span></div>';
1552 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1553 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit_vat&token='.newToken().
'&id=' .
$object->id .
'">' . $langs->trans(
"UpdateVAT") .
'</a></div>';
1555 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateVAT") .
'</span></div>';
1558 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1559 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit_level_price&token='.newToken().
'&id=' .
$object->id .
'">' . $langs->trans(
"UpdateLevelPrices") .
'</a></div>';
1561 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateLevelPrices") .
'</span></div>';
1576if ($action ==
'edit_vat' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1579 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1580 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1581 print
'<input type="hidden" name="action" value="update_vat">';
1582 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1586 print
'<table class="border centpercent">';
1589 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1597 print $form->buttonsSaveCancel();
1599 print
'<br></form><br>';
1602if (($action ==
'edit_price' || $action ==
'edit_level_price') &&
$object->getRights()->creer) {
1607 print
'<!-- Edit price -->'.
"\n";
1608 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1609 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1610 print
'<input type="hidden" name="action" value="update_price">';
1611 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1615 print
'<div class="div-table-responsive-no-min">';
1616 print
'<table class="border centpercent">';
1619 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1625 print $langs->trans(
'PriceBase');
1628 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
1633 if (isModEnabled(
'dynamicprices')) {
1635 print
'<!-- Show price mode of dynamicprices editor -->'.
"\n";
1636 print
'<tr><td>'.$langs->trans(
"PriceMode").
'</td><td>';
1637 print
img_picto(
'',
'dynamicprice',
'class="pictofixedwidth"');
1639 $price_expression_list = array(0 => $langs->trans(
"Numeric").
' <span class="opacitymedium">('.$langs->trans(
"NoDynamicPrice").
')</span>');
1640 foreach ($price_expression->list_price_expression() as $entry) {
1641 $price_expression_list[$entry->id] = $entry->title;
1643 $price_expression_preselection =
GETPOST(
'eid') ?
GETPOST(
'eid') : (
$object->fk_price_expression ?
$object->fk_price_expression :
'0');
1644 print $form->selectarray(
'eid', $price_expression_list, $price_expression_preselection);
1645 print
' <a id="expression_editor" class="classlink">'.$langs->trans(
"PriceExpressionEditor").
'</a>';
1651 <script
type=
"text/javascript">
1652 jQuery(document).ready(
function() {
1653 jQuery(
"#expression_editor").click(
function() {
1654 window.location =
"<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $(
"#eid").val();
1656 jQuery(
"#eid").change(on_change);
1659 function on_change() {
1660 if ($(
"#eid").val() == 0) {
1661 jQuery(
"#price_numeric").show();
1663 jQuery(
"#price_numeric").hide();
1672 $product->fetch($id, $ref,
'', 1);
1673 print
'<tr id="price_numeric"><td>';
1674 $text = $langs->trans(
'SellingPrice');
1675 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1677 if (
$object->price_base_type ==
'TTC') {
1678 print
'<input name="price" size="10" value="'.price($product->price_ttc).
'">';
1680 print
'<input name="price" size="10" value="'.price($product->price).
'">';
1686 $text = $langs->trans(
'MinPrice');
1687 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1689 if (
$object->price_base_type ==
'TTC') {
1690 print
'<input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
1692 print
'<input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
1695 print
' '.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1702 print $langs->trans(
'PriceLabel');
1704 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
1708 $parameters = array();
1709 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1716 print $form->buttonsSaveCancel();
1719 } elseif ($action ==
'edit_level_price' &&
$object->getRights()->creer) {
1720 print
'<!-- Edit price per level -->'.
"\n"; ?>
1723 var showHidePriceRules =
function () {
1724 var otherPrices = $(
'div.fiche form table tbody tr:not(:first)');
1725 var minPrice1 = $(
'div.fiche form input[name="price_min[1]"]');
1727 if (jQuery(
'input#usePriceRules').prop(
'checked')) {
1736 jQuery(document).ready(
function () {
1737 showHidePriceRules();
1739 jQuery(
'input#usePriceRules').click(showHidePriceRules);
1744 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1745 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1746 print
'<input type="hidden" name="action" value="update_level_price">';
1747 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1752 print $langs->trans(
'UseMultipriceRules').
' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.(
$object->price_autogen ?
'checked' :
'').
'><br><br>';
1755 print
'<div class="div-table-responsive-no-min">';
1756 print
'<table class="noborder">';
1757 print
'<thead><tr class="liste_titre">';
1759 print
'<td>'.$langs->trans(
"PriceLevel").
'</td>';
1762 print
'<td style="text-align: center">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1767 print
'<td class="center">'.$langs->trans(
"SellingPrice").
'</td>';
1769 print
'<td class="center">'.$langs->trans(
"MinPrice").
'</td>';
1776 $extrafields->fetch_name_optionals_label(
"product_price");
1777 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1778 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1779 if (!empty($extralabels)) {
1780 foreach ($extralabels as $key => $value) {
1782 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1783 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1784 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1786 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1787 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1789 $extratitle = $langs->trans($value);
1791 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1796 print
'</tr></thead>';
1800 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1801 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1802 print
'<tr class="oddeven">';
1804 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1806 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1812 print
'<input type="hidden" name="tva_tx['.$i.
']" value="'.(
$object->default_vat_code ?
$object->tva_tx.
' ('.
$object->default_vat_code.
')' :
$object->tva_tx).
'">';
1813 print
'<input type="hidden" name="tva_npr['.$i.
']" value="'.
$object->tva_npr.
'">';
1814 print
'<input type="hidden" name="localtax1_tx['.$i.
']" value="'.
$object->localtax1_tx.
'">';
1815 print
'<input type="hidden" name="localtax1_type['.$i.
']" value="'.
$object->localtax1_type.
'">';
1816 print
'<input type="hidden" name="localtax2_tx['.$i.
']" value="'.
$object->localtax2_tx.
'">';
1817 print
'<input type="hidden" name="localtax2_type['.$i.
']" value="'.
$object->localtax2_type.
'">';
1821 print
'<td style="text-align: center">';
1822 print $form->load_tva(
"tva_tx[".$i.
']',
$object->multiprices_tva_tx[$i], $mysoc,
'',
$object->id,
false,
$object->type,
false, 1);
1827 print
'<td style="text-align: center">';
1828 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1829 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices_ttc [$i]).
'">';
1831 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices [$i]).
'">';
1833 print
' '.$form->selectPriceBaseType(
$object->multiprices_base_type [$i],
"multiprices_base_type[".$i.
"]");
1837 print
'<td style="text-align: center">';
1838 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1839 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min_ttc [$i]).
'">';
1841 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min [$i]).
'">';
1844 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1848 if (!empty($extralabels)) {
1849 $sql1 =
"SELECT rowid";
1850 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1851 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1852 $sql1 .=
" AND price_level=".((int) $i);
1853 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1854 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1855 $sql1 .=
" LIMIT 1";
1856 $resql1 =
$object->db->query($sql1);
1858 $lineid =
$object->db->fetch_object($resql1);
1860 if (empty($lineid->rowid)) {
1861 foreach ($extralabels as $key => $value) {
1862 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && ($extrafields->attributes[
"product_price"][
'list'][$key] == 1 || $extrafields->attributes[
"product_price"][
'list'][$key] == 3 || ($action ==
"edit_level_price" && $extrafields->attributes[
"product_price"][
'list'][$key] == 4))) {
1863 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1864 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1867 $extravalue = GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key};
1868 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
1873 $sql .=
" fk_object";
1874 foreach ($extralabels as $key => $value) {
1877 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1878 $sql .=
" WHERE fk_object = ".((int) $lineid->rowid);
1879 $resql = $db->query($sql);
1881 $obj = $db->fetch_object($resql);
1882 foreach ($extralabels as $key => $value) {
1883 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && ($extrafields->attributes[
"product_price"][
'list'][$key] == 1 || $extrafields->attributes[
"product_price"][
'list'][$key] == 3 || ($action ==
"edit_level_price" && $extrafields->attributes[
"product_price"][
'list'][$key] == 4))) {
1884 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1885 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1888 $extravalue = (GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key} ??
'');
1889 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
1906 print $form->buttonsSaveCancel();
1917 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
1918 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
1920 if (empty($page) || $page == -1) {
1923 $offset = $limit * $page;
1924 $pageprev = $page - 1;
1925 $pagenext = $page + 1;
1930 $sortfield =
"soc.nom";
1934 $filter = array(
't.fk_product' =>
$object->id);
1936 if (!empty($search_soc)) {
1937 $filter[
'soc.nom'] = $search_soc;
1940 if ($action ==
'add_customer_price') {
1942 $maxpricesupplier =
$object->min_recommended_price();
1944 print
'<!-- add_customer_price -->';
1947 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1948 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1949 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
1950 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1952 print
'<div class="tabBar tabBarWithBottom">';
1954 print
'<table class="border centpercent">';
1956 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1958 $filter =
'(s.client:IN:1,2,3)';
1959 print
img_picto(
'',
'company').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
1964 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
1965 print
'<td><input name="ref_customer" size="12"></td></tr>';
1968 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1973 print
'<tr><td class="fieldrequired">';
1974 print $langs->trans(
'PriceBase');
1977 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
1982 print
'<tr><td class="fieldrequired">';
1983 $text = $langs->trans(
'SellingPrice');
1984 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1986 if (
$object->price_base_type ==
'TTC') {
1987 print
'<input name="price" size="10" value="'.price(
$object->price_ttc).
'">';
1989 print
'<input name="price" size="10" value="'.price(
$object->price).
'">';
1995 $text = $langs->trans(
'MinPrice');
1996 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1997 if (
$object->price_base_type ==
'TTC') {
1998 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
2000 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
2003 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2009 print $langs->trans(
'PriceLabel');
2011 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
2016 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2017 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2018 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2019 if (!empty($extralabels)) {
2020 if (empty($prodcustprice->id)) {
2021 foreach ($extralabels as $key => $value) {
2022 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))) {
2023 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2024 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2027 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2028 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2029 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2031 print $langs->trans($value);
2033 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2044 print
'<div class="center">';
2047 print
'<div class="marginbottomonly">';
2048 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2049 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2052 print $form->buttonsSaveCancel();
2055 } elseif ($action ==
'edit_customer_price') {
2057 $maxpricesupplier =
$object->min_recommended_price();
2059 print
'<!-- edit_customer_price -->';
2062 $result = $prodcustprice->fetch(
GETPOSTINT(
'lineid'));
2067 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2068 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2069 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
2070 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
2072 print
'<table class="liste centpercent">';
2074 print
'<td class="titlefield fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2075 $staticsoc =
new Societe($db);
2076 $staticsoc->fetch($prodcustprice->fk_soc);
2077 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2081 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2082 print
'<td><input name="ref_customer" size="12" value="' .
dol_escape_htmltag($prodcustprice->ref_customer) .
'"></td></tr>';
2085 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2086 print $form->load_tva(
"tva_tx", $prodcustprice->default_vat_code ? $prodcustprice->tva_tx.
' ('.$prodcustprice->default_vat_code.
')' : $prodcustprice->tva_tx, $mysoc, null,
$object->id, $prodcustprice->recuperableonly,
$object->
type, false, 1);
2090 print
'<tr><td class="fieldrequired">';
2091 print $langs->trans(
'PriceBase');
2094 print $form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
2099 print
'<tr><td class="fieldrequired">';
2100 $text = $langs->trans(
'SellingPrice');
2101 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2103 if ($prodcustprice->price_base_type ==
'TTC') {
2104 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
2106 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
2112 $text = $langs->trans(
'MinPrice');
2113 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2115 if ($prodcustprice->price_base_type ==
'TTC') {
2116 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
2118 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
2122 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2130 print $langs->trans(
'PriceLabel');
2132 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$prodcustprice->price_label.
'">';
2137 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2138 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2139 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2140 if (!empty($extralabels)) {
2142 foreach ($extralabels as $key => $value) {
2143 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))) {
2144 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2145 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2148 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2149 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2150 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2152 print $langs->trans($value);
2154 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2159 $sql .=
" fk_object";
2160 foreach ($extralabels as $key => $value) {
2163 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2164 $sql .=
" WHERE fk_object = ".((int) $prodcustprice->id);
2165 $resql = $db->query($sql);
2167 $obj = $db->fetch_object($resql);
2168 foreach ($extralabels as $key => $value) {
2169 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))) {
2170 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2171 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2174 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2175 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2176 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2178 print $langs->trans($value);
2180 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product_customer_price');
2192 print
'<div class="center">';
2193 print
'<div class="marginbottomonly">';
2194 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2195 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2198 print $form->buttonsSaveCancel();
2200 print
'<br></form>';
2201 } elseif ($action ==
'showlog_customer_price') {
2203 print
'<!-- list of all log of prices per customer -->'.
"\n";
2205 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' =>
GETPOSTINT(
'socid'));
2208 $nbtotalofrecords =
'';
2210 $nbtotalofrecords = $prodcustprice->fetchAllLog($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2213 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2218 $option =
'&socid='.GETPOSTINT(
'socid').
'&id='.
$object->id;
2220 $staticsoc =
new Societe($db);
2223 $title = $langs->trans(
'PriceByCustomerLog');
2224 $title .=
' - '.$staticsoc->getNomUrl(1);
2226 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2229 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2231 if (count($prodcustprice->lines) > 0) {
2232 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2233 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2234 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2236 print
'<div class="div-table-responsive-no-min">';
2237 print
'<table class="liste centpercent">';
2239 print
'<tr class="liste_titre">';
2240 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2241 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2242 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2243 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2244 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2245 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2246 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2247 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2248 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2250 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2251 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2252 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2253 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
2254 print
'<td> </td>';
2257 foreach ($prodcustprice->lines as $line) {
2259 $staticsoc =
new Societe($db);
2260 $staticsoc->fetch($line->fk_soc);
2262 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2265 if ($line->price_base_type ==
'HT') {
2268 $pu = $line->price_ttc;
2272 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2274 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2276 $total_ht = $resultarray[0];
2277 $total_vat = $resultarray[1];
2278 $total_localtax1 = $resultarray[9];
2279 $total_localtax2 = $resultarray[10];
2280 $total_ttc = $resultarray[2];
2282 print
'<tr class="oddeven">';
2284 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2285 print
'<td>'.$line->ref_customer.
'</td>';
2286 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2287 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2288 print
'<td class="right">';
2290 $positiverates =
'';
2292 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2295 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2298 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2300 if (empty($positiverates)) {
2301 $positiverates =
'0';
2304 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2308 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2310 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2311 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2312 print
'<td class="right">'.price($resultarray[2]).
'</td>';
2315 print
'<td class="right">'.price($line->price_min).
'</td>';
2316 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2317 print
'<td class="right">'.$line->price_label.
'</td>';
2320 $userstatic =
new User($db);
2321 $userstatic->fetch($line->fk_user);
2322 print
'<td class="right">';
2323 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
2331 print $langs->trans(
'None');
2333 } elseif ($action !=
'showlog_default_price' && $action !=
'edit_price' && $action !=
'edit_level_price') {
2335 print
'<!-- list of all prices per customer -->'.
"\n";
2338 $nbtotalofrecords =
'';
2340 $nbtotalofrecords = $prodcustprice->fetchAll($sortorder, $sortfield, 0, 0, $filter);
2343 $result = $prodcustprice->fetchAll($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2348 $option =
'&search_soc='.$search_soc.
'&id='.
$object->id;
2351 print_barre_liste($langs->trans(
'PriceByCustomer'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2353 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2354 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2355 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2357 print
'<!-- List of prices per customer -->'.
"\n";
2358 print
'<div class="div-table-responsive-no-min">'.
"\n";
2359 print
'<table class="liste centpercent">'.
"\n";
2361 if (count($prodcustprice->lines) > 0 || $search_soc) {
2362 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2363 $custom_price_extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2369 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2372 if (!empty($custom_price_extralabels) && is_array($custom_price_extralabels)) {
2373 $colspan += count($custom_price_extralabels);
2376 print
'<tr class="liste_titre">';
2377 print
'<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.
'"></td>';
2378 print
'<td class="liste_titre" colspan="'.$colspan.
'"> </td>';
2380 print
'<td class="liste_titre maxwidthsearch">';
2381 $searchpicto = $form->showFilterAndCheckAddButtons(0);
2387 print
'<tr class="liste_titre">';
2388 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2389 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2390 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2391 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2392 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2393 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2394 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2395 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2396 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2398 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2399 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2400 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2402 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2403 if ($extrafields->attributes[
"product_customer_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_customer_price"])) {
2404 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
2405 if (!empty($extralabels)) {
2406 foreach ($extralabels as $key => $value) {
2408 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2409 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2410 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2412 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2413 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2415 $extratitle = $langs->trans($value);
2417 print
'<td style="text-align: right">'.$extratitle.
'</td>';
2422 print
'<td>'.$langs->trans(
"ChangedBy").
'</td>';
2427 if (
$object->price_base_type ==
'HT') {
2434 $localtaxarray =
getLocalTaxesFromRate(
$object->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2436 $resultarray =
calcul_price_total(1, $pu, 0,
$object->tva_tx, 1, 1, 0,
$object->price_base_type, 0,
$object->type, $mysoc, $localtaxarray);
2438 $total_ht = $resultarray[0];
2439 $total_vat = $resultarray[1];
2440 $total_localtax1 = $resultarray[9];
2441 $total_localtax2 = $resultarray[10];
2442 $total_ttc = $resultarray[2];
2445 print
'<!-- PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES -->'.
"\n";
2446 print
'<tr class="oddeven">';
2447 print
'<td colspan="3">' . $langs->trans(
'Default') .
'</td>';
2449 print
'<td class="center">'.$langs->trans(
$object->price_base_type).
"</td>";
2452 print
'<td class="right">';
2454 $positiverates =
'';
2459 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
2462 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
2464 if (empty($positiverates)) {
2465 $positiverates =
'0';
2467 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
2473 print
'<td class="right"><span class="amount">'.price(
$object->price).
"</span></td>";
2475 print
'<td class="right"><span class="amount">'.price(
$object->price_ttc).
"</span></td>";
2476 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2478 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2481 print
'<td class="right">'.price(
$object->price_min).
'</td>';
2482 print
'<td class="right">'.price(
$object->price_min_ttc).
'</td>';
2483 print
'<td class="right">'.$object->price_label.
'</td>';
2484 print
'<td class="right"></td>';
2485 if (!empty($extralabels)) {
2486 foreach ($extralabels as $key) {
2488 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2489 print
'<td class="right"></td>';
2493 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2494 print
'<td class="nowraponall">';
2495 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_default_price&token='.
newToken().
'&id='.
$object->id.
'">';
2496 print
img_info($langs->trans(
'PriceByCustomerLog'));
2499 print
'<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_price&token='.
newToken().
'&id='.
$object->id.
'">';
2500 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2507 if (count($prodcustprice->lines) > 0) {
2508 foreach ($prodcustprice->lines as $line) {
2510 $staticsoc =
new Societe($db);
2511 $staticsoc->fetch($line->fk_soc);
2513 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2516 if ($line->price_base_type ==
'HT') {
2519 $pu = $line->price_ttc;
2523 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2525 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2527 $total_ht = $resultarray[0];
2528 $total_vat = $resultarray[1];
2529 $total_localtax1 = $resultarray[9];
2530 $total_localtax2 = $resultarray[10];
2531 $total_ttc = $resultarray[2];
2533 print
'<tr class="oddeven">';
2535 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2536 print
'<td>'.dol_escape_htmltag($line->ref_customer).
'</td>';
2537 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2538 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2540 print
'<td class="right">';
2542 $positiverates =
'';
2544 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2547 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2550 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2552 if (empty($positiverates)) {
2553 $positiverates =
'0';
2556 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, (!empty($line->tva_npr) ? $line->tva_npr : $line->recuperableonly));
2560 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2562 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2563 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2565 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2568 print
'<td class="right">'.price($line->price_min).
'</td>';
2569 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2570 print
'<td class="right">'.$line->price_label.
'</td>';
2573 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2574 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'] ?? array();
2575 if (!empty($extralabels)) {
2577 $sql .=
" fk_object";
2578 foreach ($extralabels as $key => $value) {
2581 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2582 $sql .=
" WHERE fk_object = ".((int) $line->id);
2583 $resql = $db->query($sql);
2585 if ($db->num_rows($resql) != 1) {
2586 foreach ($extralabels as $key => $value) {
2587 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2592 $obj = $db->fetch_object($resql);
2593 foreach ($extralabels as $key => $value) {
2594 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2595 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_customer_price').
"</td>";
2604 $userstatic =
new User($db);
2605 $userstatic->fetch($line->fk_user);
2608 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2613 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2614 print
'<td class="right nowraponall">';
2615 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&id='.
$object->id.
'&socid='.$line->fk_soc.
'">';
2616 print
img_info($langs->trans(
'PriceByCustomerLog'));
2619 print
'<a class="marginleftonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2620 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2623 print
'<a class="marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2624 print
img_delete(
'default',
'style="vertical-align: middle;"');
2642if ((!
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES') || $action ==
'showlog_default_price') && !in_array($action, array(
'edit_price',
'edit_level_price',
'edit_vat'))) {
2643 $sql =
"SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type,";
2644 $sql .=
" p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
2645 $sql .=
" p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
2646 $sql .=
" ,p.price_label";
2647 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price as p,";
2648 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
2649 $sql .=
" WHERE fk_product = ".((int)
$object->id);
2650 $sql .=
" AND p.entity IN (".getEntity(
'productprice').
")";
2651 $sql .=
" AND p.fk_user_author = u.rowid";
2653 $sql .=
" AND p.price_level = ".((int) $soc->price_level);
2655 $sql .=
" ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
2659 $result = $db->query($sql);
2661 print
'<div class="divlogofpreviouscustomerprice">';
2663 $num = $db->num_rows($result);
2672 $ret =
$object->updatePrice((
$object->multiprices_base_type[1] ==
'TTC' ?
$object->multiprices_ttc[1] :
$object->multiprices[1]),
$object->multiprices_base_type[1], $user, (empty(
$object->multiprices_tva_tx[1]) ? 0 :
$object->multiprices_tva_tx[1]), (
$object->multiprices_base_type[1] ==
'TTC' ?
$object->multiprices_min_ttc[1] :
$object->multiprices_min[1]), 1);
2680 $result = $db->query($sql);
2681 $num = $db->num_rows($result);
2688 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2692 print_barre_liste($langs->trans(
"DefaultPriceLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'', $backbutton, 0, $num,
'title_accountancy.png');
2695 print_barre_liste($langs->trans(
"PriceByCustomerLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', 0, $num,
'title_accountancy.png');
2698 print
'<!-- List of log prices -->'.
"\n";
2699 print
'<div class="div-table-responsive">'.
"\n";
2700 print
'<table class="liste centpercent noborder">'.
"\n";
2702 print
'<tr class="liste_titre">';
2703 print
'<th>'.$langs->trans(
"AppliedPricesFrom").
'</tg>';
2706 print
'<th class="center">'.$langs->trans(
"PriceLevel").
'</th>';
2709 print
'<th class="center">'.$langs->trans(
"Type").
'</th>';
2712 print
'<th class="center">'.$langs->trans(
"PriceBase").
'</th>';
2714 print
'<th class="right">'.$langs->trans(
"DefaultTaxRate").
'</th>';
2716 print
'<th class="right">'.$langs->trans(
"HT").
'</th>';
2717 print
'<th class="right">'.$langs->trans(
"TTC").
'</th>';
2718 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2719 print
'<th class="right">'.$langs->trans(
"INCT").
'</th>';
2721 if (isModEnabled(
'dynamicprices')) {
2722 print
'<th class="right">'.$langs->trans(
"PriceExpressionSelected").
'</th>';
2724 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</th>';
2725 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</th>';
2726 print
'<th class="right">'.$langs->trans(
"Label").
'</th>';
2727 print
'<th>'.$langs->trans(
"ChangedBy").
'</th>';
2728 if ($user->hasRight(
'produit',
'supprimer')) {
2729 print
'<th class="right"> </th>';
2733 $notfirstlineforlevel = array();
2737 $objp = $db->fetch_object($result);
2739 print
'<tr class="oddeven">';
2741 print
"<td>".dol_print_date($db->jdate($objp->dp),
"dayhour",
'tzuserrel').
"</td>";
2745 print
'<td class="center">'.$objp->price_level.
"</td>";
2749 $type = ($objp->price_by_qty == 1) ?
'PriceByQuantity' :
'Standard';
2750 print
'<td class="center">'.$langs->trans($type).
"</td>";
2753 print
'<td class="center">';
2754 if (empty($objp->price_by_qty)) {
2755 print $langs->trans($objp->price_base_type);
2760 print
'<td class="right">';
2762 if (empty($objp->price_by_qty)) {
2763 $positiverates =
'';
2765 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->tva_tx);
2768 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax1_tx);
2771 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax2_tx);
2773 if (empty($positiverates)) {
2774 $positiverates =
'0';
2776 echo
vatrate($positiverates.($objp->default_vat_code ?
' ('.$objp->default_vat_code.
')' :
''), true, !empty($objp->tva_npr) ? $objp->tva_npr : 0);
2789 if ($objp->price_base_type ==
'HT') {
2792 $pu = $objp->price_ttc;
2796 $localtaxarray =
getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2798 $resultarray =
calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2800 $total_ht = $resultarray[0];
2801 $total_vat = $resultarray[1];
2802 $total_localtax1 = $resultarray[9];
2803 $total_localtax2 = $resultarray[10];
2804 $total_ttc = $resultarray[2];
2807 if (!empty($objp->fk_price_expression) && !empty(
$conf->dynamicprices->enabled)) {
2809 $res = $price_expression->fetch($objp->fk_price_expression);
2810 $title = $price_expression->title;
2811 print
'<td class="right"></td>';
2812 print
'<td class="right"></td>';
2813 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2814 print
'<td class="right"></td>';
2816 print
'<td class="right">'.$title.
"</td>";
2819 print
'<td class="right">';
2820 if (empty($objp->price_by_qty)) {
2821 print
'<span class="amount">'.price($objp->price).
'</span>';
2825 print
'<td class="right">';
2826 if (empty($objp->price_by_qty)) {
2827 $price_ttc = $objp->price_ttc;
2828 print
'<span class="amount">'.price($price_ttc).
'<span>';
2831 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2832 print
'<td class="right">';
2833 print $resultarray[2];
2836 if (isModEnabled(
'dynamicprices')) {
2837 print
'<td class="right"></td>';
2842 print
'<td class="right">';
2843 if (empty($objp->price_by_qty)) {
2844 print
price($objp->price_min);
2849 print
'<td class="right">';
2850 if (empty($objp->price_by_qty)) {
2851 $price_min_ttc = $objp->price_min_ttc;
2852 print
price($price_min_ttc);
2857 print
'<td class="right">';
2858 print $objp->price_label;
2863 if ($objp->user_id > 0) {
2864 $userstatic =
new User($db);
2865 $userstatic->fetch($objp->user_id);
2866 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2872 if ($user->hasRight(
'produit',
'supprimer')) {
2875 if (empty($notfirstlineforlevel[$objp->price_level])) {
2876 $notfirstlineforlevel[$objp->price_level] = 1;
2884 print
'<td class="right">';
2885 if ($candelete || ($db->jdate($objp->dp) >=
dol_now())) {
2886 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$objp->rowid.
'">';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
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.
Class for accessing price expression table.
Class to parse product price expressions.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
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)
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
img_info($titlealt='default')
Show info logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
product_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.