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';
56$langs->loadLangs(array(
'products',
'bills',
'companies',
'other'));
63$action =
GETPOST(
'action',
'aZ09');
64$cancel =
GETPOST(
'cancel',
'alpha');
67$search_soc =
GETPOST(
'search_soc');
70$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
71$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
73 $socid = $user->socid;
77if ($id > 0 || !empty($ref)) {
85 $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
89$hookmanager->initHooks(array(
'productpricecard',
'globalcard'));
92 if (
$object->type == $object::TYPE_PRODUCT) {
95 if (
$object->type == $object::TYPE_SERVICE) {
99 restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
111$parameters = array(
'id' => $id,
'ref' => $ref);
112$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
117if (empty($reshook)) {
118 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
122 if ($action ==
'setlabelsellingprice' && $user->admin) {
123 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
124 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.GETPOST(
'pricelevel');
129 if (($action ==
'update_vat') && !$cancel && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
130 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
132 $price_label =
GETPOST(
'price_label',
'alpha');
135 $tva_tx = $tva_tx_txt;
138 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
139 $vatratecode = $reg[1];
140 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
143 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
144 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
147 $localtax1_type =
'0';
148 $localtax2_type =
'0';
151 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
153 $vatratecode = $reg[1];
155 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
157 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
158 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
159 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
160 $sql .=
" AND t.type_vat IN (0, 1)";
161 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
162 $resql = $db->query($sql);
164 $obj = $db->fetch_object($resql);
166 $npr = $obj->recuperableonly;
167 $localtax1 = $obj->localtax1;
168 $localtax2 = $obj->localtax2;
169 $localtax1_type = $obj->localtax1_type;
170 $localtax2_type = $obj->localtax2_type;
175 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
176 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
177 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
178 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
179 $sql .=
" AND t.code = ''";
180 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
181 $resql = $db->query($sql);
183 $obj = $db->fetch_object($resql);
185 $npr = $obj->recuperableonly;
186 $localtax1 = $obj->localtax1;
187 $localtax2 = $obj->localtax2;
188 $localtax1_type = $obj->localtax1_type;
189 $localtax2_type = $obj->localtax2_type;
194 $object->default_vat_code = $vatratecode;
197 $object->localtax1_tx = $localtax1;
198 $object->localtax2_tx = $localtax2;
199 $object->localtax1_type = $localtax1_type;
200 $object->localtax2_type = $localtax2_type;
201 $object->price_label = $price_label;
213 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
214 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
216 if (
$object->multiprices_base_type[$i] ==
'HT') {
217 $oldprice =
$object->multiprices[$i];
218 $oldminprice =
$object->multiprices_min[$i];
220 $oldprice =
$object->multiprices_ttc[$i];
221 $oldminprice =
$object->multiprices_min_ttc[$i];
223 $oldpricebasetype =
$object->multiprices_base_type[$i];
224 $oldnpr =
$object->multiprices_recuperableonly[$i];
227 $localtaxarray = array();
229 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
238 if (
$object->price_base_type ==
'HT') {
240 $oldminprice =
$object->price_min;
242 $oldprice =
$object->price_ttc;
243 $oldminprice =
$object->price_min_ttc;
245 $oldpricebasetype =
$object->price_base_type;
249 $localtaxarray = array();
251 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
269 if (($action ==
'update_price' || $action ==
'update_level_price') && !$cancel &&
$object->getRights()->creer) {
271 $pricestoupdate = array();
274 $psq = empty($newpsq) ? 0 : $newpsq;
275 $maxpricesupplier =
$object->min_recommended_price();
277 if (isModEnabled(
'dynamicprices')) {
278 $object->fk_price_expression = empty($eid) ? 0 : $eid;
280 if (
$object->fk_price_expression != 0) {
282 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
285 if ($priceparser->parseProduct($object) < 0) {
294 $newprice =
GETPOST(
'price',
'array');
295 $newprice_min =
GETPOST(
'price_min',
'array');
296 $newpricebase =
GETPOST(
'multiprices_base_type',
'array');
297 $newvattx =
GETPOST(
'tva_tx',
'array');
298 $newvatnpr =
GETPOST(
'tva_npr',
'array');
299 $newlocaltax1_tx =
GETPOST(
'localtax1_tx',
'array');
300 $newlocaltax1_type =
GETPOST(
'localtax1_type',
'array');
301 $newlocaltax2_tx =
GETPOST(
'localtax2_tx',
'array');
302 $newlocaltax2_type =
GETPOST(
'localtax2_type',
'array');
305 $object->price_autogen = (int) (
GETPOST(
'usePriceRules') ==
'on');
307 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
308 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
309 if (!isset($newprice[$i])) {
313 $tva_tx_txt = $newvattx[$i];
315 $tva_tx = $tva_tx_txt;
318 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
319 $vat_src_code = $reg[1];
320 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
322 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
324 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
325 $localtax1 = $newlocaltax1_tx[$i];
326 $localtax1_type = $newlocaltax1_type[$i];
327 $localtax2 = $newlocaltax2_tx[$i];
328 $localtax2_type = $newlocaltax2_type[$i];
329 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
331 $vatratecode = $reg[1];
333 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
335 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
336 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
337 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
338 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
339 $resql = $db->query($sql);
341 $obj = $db->fetch_object($resql);
343 $npr = $obj->recuperableonly;
344 $localtax1 = $obj->localtax1;
345 $localtax2 = $obj->localtax2;
346 $localtax1_type = $obj->localtax1_type;
347 $localtax2_type = $obj->localtax2_type;
351 if (in_array($mysoc->country_code, array(
'ES'))) {
358 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
360 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
361 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
362 $sql .=
" AND t.code = ''";
363 $resql = $db->query($sql);
365 $obj = $db->fetch_object($resql);
367 $npr = $obj->recuperableonly;
368 $localtax1 = $obj->localtax1;
369 $localtax2 = $obj->localtax2;
370 $localtax1_type = $obj->localtax1_type;
371 $localtax2_type = $obj->localtax2_type;
376 $pricestoupdate[$i] = array(
377 'price' =>
price2num($newprice[$i],
'', 2),
378 'price_min' =>
price2num($newprice_min[$i],
'', 2),
379 'price_base_type' => $newpricebase[$i],
380 'default_vat_code' => $vatratecode,
383 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
394 $newpricebase =
GETPOST(
'price_base_type',
'alpha');
395 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
396 $price_label =
GETPOST(
'price_label',
'alpha');
398 $tva_tx = $tva_tx_txt;
401 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
402 $vat_src_code = $reg[1];
403 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
405 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
407 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
410 $localtax1_type =
'0';
411 $localtax2_type =
'0';
413 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
415 $vatratecode = $reg[1];
417 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
418 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
419 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
420 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
421 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
422 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
423 $resql = $db->query($sql);
425 $obj = $db->fetch_object($resql);
427 $npr = $obj->recuperableonly;
428 $localtax1 = $obj->localtax1;
429 $localtax2 = $obj->localtax2;
430 $localtax1_type = $obj->localtax1_type;
431 $localtax2_type = $obj->localtax2_type;
435 if (in_array($mysoc->country_code, array(
'ES'))) {
442 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
444 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
445 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
446 $sql .=
" AND t.code = ''";
447 $resql = $db->query($sql);
449 $obj = $db->fetch_object($resql);
451 $npr = $obj->recuperableonly;
452 $localtax1 = $obj->localtax1;
453 $localtax2 = $obj->localtax2;
454 $localtax1_type = $obj->localtax1_type;
455 $localtax2_type = $obj->localtax2_type;
460 $pricestoupdate[0] = array(
461 'price' => $newprice,
462 'price_label' => $price_label,
463 'price_min' => $newprice_min,
464 'price_base_type' => $newpricebase,
465 'default_vat_code' => $vatratecode,
468 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
475 foreach ($pricestoupdate as $key => $val) {
476 $newprice = $val[
'price'];
478 if ($val[
'price'] < $val[
'price_min'] && !empty(
$object->fk_price_expression)) {
479 $newprice = $val[
'price_min'];
483 $newprice_min =
price2num($val[
'price_min'],
'MU');
486 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $newprice_min < $maxpricesupplier) {
487 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, - 1, - 1,
'auto')),
null,
'errors');
492 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) {
493 $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']);
495 $extralabels = $extrafields->fetch_name_optionals_label(
"product");
498 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
499 foreach ($extrafield_values as $efkey => $value) {
500 $object->array_options[$efkey] = $value;
502 $result =
$object->insertExtraFields();
507 $price_extralabels = $extrafields->fetch_name_optionals_label(
"product_price");
508 $sql =
"SELECT rowid";
509 $sql .=
" FROM ".$object->db->prefix().
"product_price";
510 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
511 $sql .=
" AND price_level=".((int) $key);
512 $sql .=
" AND fk_product = ".((int)
$object->id);
513 $sql .=
" ORDER BY date_price DESC, rowid DESC";
515 $resql =
$object->db->query($sql);
517 $lineid =
$object->db->fetch_object($resql);
520 if (!empty($lineid->rowid)) {
521 if (!empty($price_extralabels) && is_array($price_extralabels)) {
522 foreach ($price_extralabels as $code => $label) {
523 $code_array =
GETPOST($code,
'array');
524 $object->array_options[
'options_'.$code] = $code_array[$key];
528 $object->table_element =
'product_price';
529 $result =
$object->insertExtraFields();
533 $object->table_element =
'product';
562 $action =
'edit_price';
568 if ($action ==
'delete' && $user->hasRight(
'produit',
'supprimer')) {
576 if ($action ==
'activate_price_by_qty') {
588 if ($action ==
'disable_price_by_qty') {
600 if ($action ==
'edit_price_by_qty') {
605 if ($action ==
'update_price_by_qty') {
615 if (empty($quantity)) {
617 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Qty")),
null,
'errors');
619 if (empty($newprice)) {
621 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Price")),
null,
'errors');
625 if (
$object->price_base_type ==
'TTC') {
630 $unitPrice =
price2num((
float) $price / (
float) $quantity,
'MU');
634 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_price_by_qty SET";
635 $sql .=
" price=".((float) $price).
",";
636 $sql .=
" unitprice=".((float) $unitPrice).
",";
637 $sql .=
" quantity=".((float) $quantity).
",";
638 $sql .=
" remise_percent=".((float) $remise_percent).
",";
639 $sql .=
" remise=".((float) $remise);
640 $sql .=
" WHERE rowid = ".((int) $rowid);
642 $result = $db->query($sql);
647 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
648 $sql .= ((int) $priceid).
','.((float) $price).
','.((float) $unitPrice).
','.((float) $quantity).
','.((float) $remise_percent).
','.((float) $remise).
')';
650 $result = $db->query($sql);
652 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
662 if ($action ==
'delete_price_by_qty') {
664 if (!empty($rowid)) {
665 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
666 $sql .=
" WHERE rowid = ".((int) $rowid);
668 $result = $db->query($sql);
670 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
674 if ($action ==
'delete_all_price_by_qty') {
676 if (!empty($rowid)) {
677 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
678 $sql .=
" WHERE fk_product_price = ".((int) $priceid);
680 $result = $db->query($sql);
682 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
691 if ($action ==
'add_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
692 $maxpricesupplier =
$object->min_recommended_price();
694 $update_child_soc =
GETPOSTINT(
'updatechildprice');
698 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
699 $prodcustprice->fk_product =
$object->id;
702 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
703 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
705 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
706 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
708 $tva_tx_txt =
GETPOST(
"tva_tx",
'alpha');
710 $tva_tx = $tva_tx_txt;
712 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
713 $vat_src_code = $reg[1];
714 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
716 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
718 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
721 $localtax1_type =
'0';
722 $localtax2_type =
'0';
724 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
726 $vatratecode = $reg[1];
728 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
729 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
730 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
731 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
732 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
733 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
734 $resql = $db->query($sql);
736 $obj = $db->fetch_object($resql);
738 $npr = $obj->recuperableonly;
739 $localtax1 = $obj->localtax1;
740 $localtax2 = $obj->localtax2;
741 $localtax1_type = $obj->localtax1_type;
742 $localtax2_type = $obj->localtax2_type;
746 if (in_array($mysoc->country_code, array(
'ES'))) {
753 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
754 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
755 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
756 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
757 $sql .=
" AND t.code = ''";
758 $resql = $db->query($sql);
760 $obj = $db->fetch_object($resql);
762 $npr = $obj->recuperableonly;
763 $localtax1 = $obj->localtax1;
764 $localtax2 = $obj->localtax2;
765 $localtax1_type = $obj->localtax1_type;
766 $localtax2_type = $obj->localtax2_type;
771 $prodcustprice->default_vat_code = $vatratecode;
772 $prodcustprice->tva_tx = $tva_tx;
773 $prodcustprice->recuperableonly = $npr;
774 $prodcustprice->localtax1_tx = $localtax1;
775 $prodcustprice->localtax2_tx = $localtax2;
776 $prodcustprice->localtax1_type = $localtax1_type;
777 $prodcustprice->localtax2_type = $localtax2_type;
779 if (!($prodcustprice->fk_soc > 0)) {
780 $langs->load(
"errors");
781 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
783 $action =
'add_customer_price';
785 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $prodcustprice->price_min < $maxpricesupplier) {
786 $langs->load(
"errors");
787 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
789 $action =
'add_customer_price';
793 $result = $prodcustprice->create($user, 0, $update_child_soc);
795 if (!empty($extrafield_values) && is_array($extrafield_values)) {
797 $res = $productcustomerprice->fetch($prodcustprice->id);
799 foreach ($extrafield_values as $key => $value) {
800 $productcustomerprice->array_options[$key] = $value;
802 $result2 = $productcustomerprice->insertExtraFields();
804 $prodcustprice->error = $productcustomerprice->error;
805 $prodcustprice->errors = $productcustomerprice->errors;
822 if ($action ==
'delete_customer_price' && $prodcustprice !==
null && ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer'))) {
825 $result = $prodcustprice->delete($user);
828 $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields WHERE fk_object = ".((
int) $prodcustprice->id));
843 if ($action ==
'update_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
844 $maxpricesupplier =
$object->min_recommended_price();
846 $update_child_soc =
GETPOSTINT(
'updatechildprice');
851 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
854 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
855 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
857 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
858 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
860 $tva_tx_txt =
GETPOST(
"tva_tx");
862 $tva_tx = $tva_tx_txt;
864 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
865 $vat_src_code = $reg[1];
866 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
868 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
870 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
873 $localtax1_type =
'0';
874 $localtax2_type =
'0';
876 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
878 $vatratecode = $reg[1];
880 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
881 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
882 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
883 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
884 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
885 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
886 $resql = $db->query($sql);
888 $obj = $db->fetch_object($resql);
890 $npr = $obj->recuperableonly;
891 $localtax1 = $obj->localtax1;
892 $localtax2 = $obj->localtax2;
893 $localtax1_type = $obj->localtax1_type;
894 $localtax2_type = $obj->localtax2_type;
898 if (in_array($mysoc->country_code, array(
'ES'))) {
905 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
906 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
907 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
908 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
909 $sql .=
" AND t.code = ''";
910 $resql = $db->query($sql);
912 $obj = $db->fetch_object($resql);
914 $npr = $obj->recuperableonly;
915 $localtax1 = $obj->localtax1;
916 $localtax2 = $obj->localtax2;
917 $localtax1_type = $obj->localtax1_type;
918 $localtax2_type = $obj->localtax2_type;
923 $prodcustprice->default_vat_code = $vatratecode;
924 $prodcustprice->tva_tx = $tva_tx;
925 $prodcustprice->recuperableonly = $npr;
926 $prodcustprice->localtax1_tx = $localtax1;
927 $prodcustprice->localtax2_tx = $localtax2;
928 $prodcustprice->localtax1_type = $localtax1_type;
929 $prodcustprice->localtax2_type = $localtax2_type;
931 if ($prodcustprice->price_min < $maxpricesupplier &&
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
932 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
934 $action =
'update_customer_price';
938 $result = $prodcustprice->update($user, 0, $update_child_soc);
940 if (!empty($extrafield_values) && is_array($extrafield_values)) {
942 $res = $productcustomerprice->fetch($prodcustprice->id);
944 foreach ($extrafield_values as $key => $value) {
945 $productcustomerprice->array_options[$key] = $value;
947 $result2 = $productcustomerprice->insertExtraFields();
949 $prodcustprice->error = $productcustomerprice->error;
950 $prodcustprice->errors = $productcustomerprice->errors;
973$form =
new Form($db);
975if (!empty($id) || !empty($ref)) {
980$title = $langs->trans(
'ProductServiceCard');
984 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
985 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
988 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
989 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
992llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'classforhorizontalscrolloftabs mod-product page-price');
995$titre = $langs->trans(
"CardProduct".
$object->type);
1000$linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
1001$object->next_prev_filter =
"fk_product_type = ".((int)
$object->type);
1004if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
1008dol_banner_tab($object,
'ref', $linkback, $shownav,
'ref');
1011print
'<div class="fichecenter">';
1013print
'<div class="underbanner clearboth"></div>';
1014print
'<table class="border tableforfield centpercent">';
1020 if (!empty($socid)) {
1023 $soc->fetch($socid);
1026 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1027 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1028 print
'<tr><td class="">';
1029 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1031 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1036 print
'<tr><td class="titlefieldcreate">';
1037 print $langs->trans(
"SellingPrice");
1039 print
'<td colspan="2">';
1040 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1041 print
'<span class="amount">'.price(
$object->multiprices_ttc[$soc->price_level]).
'</span>';
1043 print
'<span class="amount">'.price(
$object->multiprices[$soc->price_level]).
'</span>';
1045 if (
$object->multiprices_base_type[$soc->price_level]) {
1046 print
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1048 print
' '.$langs->trans(
$object->price_base_type);
1053 print
'<tr><td>'.$langs->trans(
"MinPrice").
'</td><td colspan="2">';
1054 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1055 print
price(
$object->multiprices_min_ttc[$soc->price_level]).
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1057 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]);
1063 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td colspan="2">';
1065 $positiverates =
'';
1067 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_tva_tx[$soc->price_level]);
1070 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax1_tx[$soc->price_level]);
1073 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax2_tx[$soc->price_level]);
1075 if (empty($positiverates)) {
1076 $positiverates =
'0';
1078 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1083 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1085 $positiverates =
'';
1090 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1093 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1095 if (empty($positiverates)) {
1096 $positiverates =
'0';
1098 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1110 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1111 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1112 print
'<tr><td class="">';
1113 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1115 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1120 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1121 print
'<td colspan="2">'.vatrate(
$object->multiprices_tva_tx[1],
true).
'</td>';
1125 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1126 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1127 print
'<tr><td class="">';
1128 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1130 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1135 print
'<!-- Default VAT Rate -->';
1136 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1139 $positiverates =
'';
1141 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->tva_tx);
1144 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax1_tx);
1147 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax2_tx);
1149 if (empty($positiverates)) {
1150 $positiverates =
'0';
1153 print
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 1);
1166 print
'<table class="liste centpercent">';
1167 print
'<tr class="liste_titre"><td>';
1168 print $langs->trans(
"PriceLevel");
1170 print
' <a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editlabelsellingprice&token='.
newToken().
'&pricelevel='.$i.
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'EditSellingPriceLabel'), 0).
'</a>';
1173 print
'<td style="text-align: right">'.$langs->trans(
"SellingPrice").
'</td>';
1174 print
'<td style="text-align: right">'.$langs->trans(
"MinPrice").
'</td>';
1176 $extrafields->fetch_name_optionals_label(
"product_price");
1177 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1178 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1179 if (!empty($extralabels)) {
1180 foreach ($extralabels as $key => $value) {
1182 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1183 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1184 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1186 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1187 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1189 $extratitle = $langs->trans($value);
1191 $field =
'ef.' . $key;
1192 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1199 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1200 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1201 print
'<tr class="oddeven">';
1205 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1206 if (preg_match(
'/editlabelsellingprice/', $action)) {
1207 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
1208 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1209 print
'<input type="hidden" name="action" value="setlabelsellingprice">';
1210 print
'<input type="hidden" name="pricelevel" value="'.$i.
'">';
1211 print $langs->trans(
"SellingPrice").
' '.$i.
' - ';
1212 print
'<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' .
getDolGlobalString($keyforlabel).
'">';
1213 print
' <input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
1216 print $langs->trans(
"SellingPrice").
' '.$i;
1223 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1224 print
'<td class="right"><span class="amount">'.price(
$object->multiprices_ttc[$i]);
1226 print
'<td class="right"><span class="amount">'.price(
$object->multiprices[$i]);
1229 if (
$object->multiprices_base_type[$i]) {
1230 print
' '.$langs->trans(
$object->multiprices_base_type [$i]).
'</span></td>';
1232 print
' '.$langs->trans(
$object->price_base_type).
'</span></td>';
1236 print
'<td style="text-align: right">';
1237 if (empty(
$object->multiprices_base_type[$i])) {
1238 $object->multiprices_base_type[$i] =
"HT";
1240 if (
$object->multiprices_base_type[$i] ==
'TTC') {
1241 print
price(
$object->multiprices_min_ttc[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1243 print
price(
$object->multiprices_min[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1246 if (!empty($extralabels)) {
1247 $sql1 =
"SELECT rowid";
1248 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1249 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1250 $sql1 .=
" AND price_level=".((int) $i);
1251 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1252 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1253 $sql1 .=
" LIMIT 1";
1254 $resql1 =
$object->db->query($sql1);
1256 $lineid =
$object->db->fetch_object($resql1);
1259 $sql2 .=
" fk_object";
1260 foreach ($extralabels as $key => $value) {
1263 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1264 $sql2 .=
" WHERE fk_object = ".((int) $lineid->rowid);
1265 $resql2 = $db->query($sql2);
1267 if ($db->num_rows($resql2) != 1) {
1268 foreach ($extralabels as $key => $value) {
1269 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1270 print
'<td align="right"></td>';
1274 $obj = $db->fetch_object($resql2);
1275 foreach ($extralabels as $key => $value) {
1276 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1277 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_price').
"</td>";
1289 print
'<tr><td>'.$langs->trans(
"PriceByQuantity").
' '.$i;
1293 print
'</td><td colspan="2">';
1295 if (
$object->prices_by_qty[$i] == 1) {
1296 print
'<table width="50%" class="border" summary="List of quantities">';
1298 print
'<tr class="liste_titre">';
1299 print
'<td>'.$langs->trans(
"PriceByQuantityRange").
' '.$i.
'</td>';
1300 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
1301 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1302 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1303 print
'<td> </td>';
1305 foreach (
$object->prices_by_qty_list[$i] as $ii => $prices) {
1306 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1307 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1308 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1309 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1310 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1311 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1312 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1313 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1314 print
'<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"> '.
$object->price_base_type.
'</td>';
1315 print
'<td class="right nowraponall"><input size="5" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1316 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1320 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1321 print
'<td>'.$prices[
'quantity'].
'</td>';
1322 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1323 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1324 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1325 print
'<td class="center">';
1326 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1327 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1329 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1338 if ($action !=
'edit_price_by_qty' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1339 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1340 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1341 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1342 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1343 print
'<input type="hidden" value="0" name="rowid">';
1344 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1345 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1346 print
'<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.
'</td>';
1347 print
'<td class="right"> </td>';
1348 print
'<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
1349 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1355 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>';
1357 print $langs->trans(
"No");
1358 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>';
1366 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1368 $positiverates =
'';
1373 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1376 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1378 if (empty($positiverates)) {
1379 $positiverates =
'0';
1381 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 0, 1);
1391 print
'<tr class="field_selling_price"><td>'.$langs->trans(
"SellingPrice").
'</td><td>';
1392 if (
$object->price_base_type ==
'TTC') {
1397 print
'<i class="opacitymedium"> - ' .
price(
$object->price_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1404 print
'<tr class="field_min_price"><td>'.$langs->trans(
"MinPrice").
'</td><td>';
1405 if (
$object->price_base_type ==
'TTC') {
1410 print
'<i class="opacitymedium"> - ' .
price(
$object->price_min_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1416 print
'<tr class="field_price_label"><td>'.$langs->trans(
"PriceLabel").
'</td><td>';
1422 print
'<tr><td>'.$langs->trans(
"PriceByQuantity");
1423 if (
$object->prices_by_qty[0] == 0) {
1424 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=activate_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"Activate").
')';
1426 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=disable_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"DisablePriceByQty").
')';
1430 if (
$object->prices_by_qty[0] == 1) {
1431 print
'<table width="50%" class="border" summary="List of quantities">';
1432 print
'<tr class="liste_titre">';
1434 print
'<td>'.$langs->trans(
"Quantity").
'</td>';
1435 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
1436 print
'<td class="right"></td>';
1437 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1438 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1439 print
'<td> </td>';
1441 if ($action !=
'edit_price_by_qty') {
1442 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1443 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1444 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1445 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1446 print
'<input type="hidden" value="0" name="rowid">';
1448 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1449 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1450 print
'<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
1454 print
'<td class="right"> </td>';
1455 print
'<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
1456 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1461 foreach (
$object->prices_by_qty_list[0] as $ii => $prices) {
1462 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1463 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1464 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1465 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1466 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1467 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1468 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1469 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1470 print
'<td class="right"><input class="width50 right" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"></td>';
1471 print
'<td class="right">';
1473 print $prices[
'price_base_type'];
1475 print
'<td class="right"> </td>';
1476 print
'<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1477 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1481 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1482 print
'<td>'.$prices[
'quantity'].
'</td>';
1483 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1484 print
'<td class="right">';
1486 print $prices[
'price_base_type'];
1488 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1489 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1490 print
'<td class="center">';
1491 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1492 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1494 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1505 print $langs->trans(
"No");
1511 $extrafields->fetch_name_optionals_label(
"product");
1512 $extralabels = !empty($extrafields->attributes[
"product"][
'label']) ? $extrafields->attributes[
"product"][
'label'] :
'';
1513 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
1515 $sql .=
" fk_object";
1516 foreach ($extralabels as $key => $value) {
1519 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_extrafields";
1520 $sql .=
" WHERE fk_object = ".((int)
$object->id);
1521 $resql = $db->query($sql);
1523 $obj = $db->fetch_object($resql);
1524 foreach ($extralabels as $key => $value) {
1525 if (!empty($extrafields->attributes[
"product"][
'list'][$key]) && ($extrafields->attributes[
"product"][
'list'][$key] == 1 || $extrafields->attributes[
"product"][
'list'][$key] == 3 || ($action ==
"edit_price" && $extrafields->attributes[
"product"][
'list'][$key] == 4))) {
1526 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1527 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1530 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1531 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1532 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1534 print $langs->trans($value);
1537 print
'<td align="left">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product').
"</td></tr>";
1547print
'<div class="clearboth"></div>';
1559if (!$action || $action ==
'delete' || $action ==
'showlog_customer_price' || $action ==
'showlog_default_price' || $action ==
'add_customer_price'
1560 || $action ==
'activate_price_by_qty' || $action ==
'disable_price_by_qty') {
1561 print
"\n".
'<div class="tabsAction">'.
"\n";
1564 $parameters = array();
1565 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1566 if (empty($reshook)) {
1568 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1569 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"NoEditVariants")) .
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</a></div>';
1573 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1574 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>';
1576 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</span></div>';
1581 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1582 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>';
1584 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"AddCustomerPrice") .
'</span></div>';
1589 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1590 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>';
1592 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateVAT") .
'</span></div>';
1595 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1596 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>';
1598 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateLevelPrices") .
'</span></div>';
1613if ($action ==
'edit_vat' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1616 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1617 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1618 print
'<input type="hidden" name="action" value="update_vat">';
1619 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1623 print
'<table class="border centpercent">';
1626 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1634 print $form->buttonsSaveCancel();
1636 print
'<br></form><br>';
1639if (($action ==
'edit_price' || $action ==
'edit_level_price') &&
$object->getRights()->creer) {
1644 print
'<!-- Edit price -->'.
"\n";
1645 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1646 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1647 print
'<input type="hidden" name="action" value="update_price">';
1648 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1652 print
'<div class="div-table-responsive-no-min">';
1653 print
'<table class="border centpercent">';
1656 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1662 print $langs->trans(
'PriceBase');
1665 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
1670 if (isModEnabled(
'dynamicprices')) {
1672 print
'<!-- Show price mode of dynamicprices editor -->'.
"\n";
1673 print
'<tr><td>'.$langs->trans(
"PriceMode").
'</td><td>';
1674 print
img_picto(
'',
'dynamicprice',
'class="pictofixedwidth"');
1676 $price_expression_list = array(0 => $langs->trans(
"Numeric").
' <span class="opacitymedium">('.$langs->trans(
"NoDynamicPrice").
')</span>');
1677 foreach ($price_expression->list_price_expression() as $entry) {
1678 $price_expression_list[$entry->id] = $entry->title;
1680 $price_expression_preselection =
GETPOST(
'eid') ?
GETPOST(
'eid') : (
$object->fk_price_expression ?
$object->fk_price_expression :
'0');
1681 print $form->selectarray(
'eid', $price_expression_list, $price_expression_preselection);
1682 print
' <a id="expression_editor" class="classlink">'.$langs->trans(
"PriceExpressionEditor").
'</a>';
1688 <script
type=
"text/javascript">
1689 jQuery(document).ready(
function() {
1690 jQuery(
"#expression_editor").click(
function() {
1691 window.location =
"<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $(
"#eid").val();
1693 jQuery(
"#eid").change(on_change);
1696 function on_change() {
1697 if ($(
"#eid").val() == 0) {
1698 jQuery(
"#price_numeric").show();
1700 jQuery(
"#price_numeric").hide();
1709 $product->fetch($id, $ref,
'', 1);
1710 print
'<tr id="price_numeric"><td>';
1711 $text = $langs->trans(
'SellingPrice');
1712 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1714 if (
$object->price_base_type ==
'TTC') {
1715 print
'<input name="price" size="10" value="'.price($product->price_ttc).
'">';
1717 print
'<input name="price" size="10" value="'.price($product->price).
'">';
1723 $text = $langs->trans(
'MinPrice');
1724 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1726 if (
$object->price_base_type ==
'TTC') {
1727 print
'<input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
1729 print
'<input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
1732 print
' '.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1739 print $langs->trans(
'PriceLabel');
1741 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
1746 $extrafields->fetch_name_optionals_label(
"product");
1747 $extralabels = !empty($extrafields->attributes[
"product"][
'label']) ? $extrafields->attributes[
"product"][
'label'] :
'';
1748 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
1749 if (!empty($extralabels)) {
1751 foreach ($extralabels as $key => $value) {
1752 if (!empty($extrafields->attributes[
"product"][
'list'][$key]) && ($extrafields->attributes[
"product"][
'list'][$key] == 1 || $extrafields->attributes[
"product"][
'list'][$key] == 3 || ($action ==
"edit_price" && $extrafields->attributes[
"product"][
'list'][$key] == 4))) {
1753 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1754 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1757 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1758 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1759 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1761 print $langs->trans($value);
1763 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product').
'</td></tr>';
1768 $sql .=
" fk_object";
1769 foreach ($extralabels as $key => $value) {
1772 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_extrafields";
1773 $sql .=
" WHERE fk_object = ".((int)
$object->id);
1774 $resql = $db->query($sql);
1776 $obj = $db->fetch_object($resql);
1777 foreach ($extralabels as $key => $value) {
1778 if (!empty($extrafields->attributes[
"product"][
'list'][$key]) && ($extrafields->attributes[
"product"][
'list'][$key] == 1 || $extrafields->attributes[
"product"][
'list'][$key] == 3 || ($action ==
"edit_price" && $extrafields->attributes[
"product"][
'list'][$key] == 4))) {
1779 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1780 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1783 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1784 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1785 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1787 print $langs->trans($value);
1789 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product');
1798 $parameters = array();
1799 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1806 print $form->buttonsSaveCancel();
1809 } elseif ($action ==
'edit_level_price' &&
$object->getRights()->creer) {
1810 print
'<!-- Edit price per level -->'.
"\n"; ?>
1813 var showHidePriceRules =
function () {
1814 var otherPrices = $(
'div.fiche form table tbody tr:not(:first)');
1815 var minPrice1 = $(
'div.fiche form input[name="price_min[1]"]');
1817 if (jQuery(
'input#usePriceRules').prop(
'checked')) {
1826 jQuery(document).ready(
function () {
1827 showHidePriceRules();
1829 jQuery(
'input#usePriceRules').click(showHidePriceRules);
1834 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1835 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1836 print
'<input type="hidden" name="action" value="update_level_price">';
1837 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1842 print $langs->trans(
'UseMultipriceRules').
' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.(
$object->price_autogen ?
'checked' :
'').
'><br><br>';
1845 print
'<div class="div-table-responsive-no-min">';
1846 print
'<table class="noborder">';
1847 print
'<thead><tr class="liste_titre">';
1849 print
'<td>'.$langs->trans(
"PriceLevel").
'</td>';
1852 print
'<td style="text-align: center">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1857 print
'<td class="center">'.$langs->trans(
"SellingPrice").
'</td>';
1859 print
'<td class="center">'.$langs->trans(
"MinPrice").
'</td>';
1866 $extrafields->fetch_name_optionals_label(
"product_price");
1867 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1868 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1869 if (!empty($extralabels)) {
1870 foreach ($extralabels as $key => $value) {
1872 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1873 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1874 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1876 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1877 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1879 $extratitle = $langs->trans($value);
1881 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1886 print
'</tr></thead>';
1890 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1891 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1892 print
'<tr class="oddeven">';
1894 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1896 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1902 print
'<input type="hidden" name="tva_tx['.$i.
']" value="'.(
$object->default_vat_code ?
$object->tva_tx.
' ('.
$object->default_vat_code.
')' :
$object->tva_tx).
'">';
1903 print
'<input type="hidden" name="tva_npr['.$i.
']" value="'.
$object->tva_npr.
'">';
1904 print
'<input type="hidden" name="localtax1_tx['.$i.
']" value="'.
$object->localtax1_tx.
'">';
1905 print
'<input type="hidden" name="localtax1_type['.$i.
']" value="'.
$object->localtax1_type.
'">';
1906 print
'<input type="hidden" name="localtax2_tx['.$i.
']" value="'.
$object->localtax2_tx.
'">';
1907 print
'<input type="hidden" name="localtax2_type['.$i.
']" value="'.
$object->localtax2_type.
'">';
1911 print
'<td style="text-align: center">';
1912 print $form->load_tva(
"tva_tx[".$i.
']',
$object->multiprices_tva_tx[$i], $mysoc,
'',
$object->id,
false,
$object->type,
false, 1);
1917 print
'<td style="text-align: center">';
1918 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1919 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices_ttc [$i]).
'">';
1921 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices [$i]).
'">';
1923 print
' '.$form->selectPriceBaseType(
$object->multiprices_base_type [$i],
"multiprices_base_type[".$i.
"]");
1927 print
'<td style="text-align: center">';
1928 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1929 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min_ttc [$i]).
'">';
1931 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min [$i]).
'">';
1934 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1938 if (!empty($extralabels)) {
1939 $sql1 =
"SELECT rowid";
1940 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1941 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1942 $sql1 .=
" AND price_level=".((int) $i);
1943 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1944 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1945 $sql1 .=
" LIMIT 1";
1946 $resql1 =
$object->db->query($sql1);
1948 $lineid =
$object->db->fetch_object($resql1);
1950 if (empty($lineid->rowid)) {
1951 foreach ($extralabels as $key => $value) {
1952 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))) {
1953 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1954 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1957 $extravalue = GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key};
1958 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
1963 $sql .=
" fk_object";
1964 foreach ($extralabels as $key => $value) {
1967 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1968 $sql .=
" WHERE fk_object = ".((int) $lineid->rowid);
1969 $resql = $db->query($sql);
1971 $obj = $db->fetch_object($resql);
1972 foreach ($extralabels as $key => $value) {
1973 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))) {
1974 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1975 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1978 $extravalue = (GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key} ??
'');
1979 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
1996 print $form->buttonsSaveCancel();
2007 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
2008 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
2010 if (empty($page) || $page == -1) {
2013 $offset = $limit * $page;
2014 $pageprev = $page - 1;
2015 $pagenext = $page + 1;
2020 $sortfield =
"soc.nom";
2024 $filter = array(
't.fk_product' =>
$object->id);
2026 if (!empty($search_soc)) {
2027 $filter[
'soc.nom'] = $search_soc;
2030 if ($action ==
'add_customer_price') {
2032 $maxpricesupplier =
$object->min_recommended_price();
2034 print
'<!-- add_customer_price -->';
2037 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2038 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2039 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
2040 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2042 print
'<div class="tabBar tabBarWithBottom">';
2044 print
'<table class="border centpercent">';
2046 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2048 $filter =
'(s.client:IN:1,2,3)';
2049 print
img_picto(
'',
'company').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
2054 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2055 print
'<td><input name="ref_customer" size="12"></td></tr>';
2058 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2063 print
'<tr><td class="fieldrequired">';
2064 print $langs->trans(
'PriceBase');
2067 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
2072 print
'<tr><td class="fieldrequired">';
2073 $text = $langs->trans(
'SellingPrice');
2074 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2076 if (
$object->price_base_type ==
'TTC') {
2077 print
'<input name="price" size="10" value="'.price(
$object->price_ttc).
'">';
2079 print
'<input name="price" size="10" value="'.price(
$object->price).
'">';
2085 $text = $langs->trans(
'MinPrice');
2086 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2087 if (
$object->price_base_type ==
'TTC') {
2088 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
2090 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
2093 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2099 print $langs->trans(
'PriceLabel');
2101 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
2106 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2107 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2108 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2109 if (!empty($extralabels)) {
2110 if (empty($prodcustprice->id)) {
2111 foreach ($extralabels as $key => $value) {
2112 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))) {
2113 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2114 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2117 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2118 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2119 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2121 print $langs->trans($value);
2123 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2134 print
'<div class="center">';
2137 print
'<div class="marginbottomonly">';
2138 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2139 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2142 print $form->buttonsSaveCancel();
2145 } elseif ($action ==
'edit_customer_price') {
2147 $maxpricesupplier =
$object->min_recommended_price();
2149 print
'<!-- edit_customer_price -->';
2152 $result = $prodcustprice->fetch(
GETPOSTINT(
'lineid'));
2157 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2158 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2159 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
2160 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
2162 print
'<table class="liste centpercent">';
2164 print
'<td class="titlefield fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2165 $staticsoc =
new Societe($db);
2166 $staticsoc->fetch($prodcustprice->fk_soc);
2167 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2171 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2172 print
'<td><input name="ref_customer" size="12" value="' .
dol_escape_htmltag($prodcustprice->ref_customer) .
'"></td></tr>';
2175 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2176 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);
2180 print
'<tr><td class="fieldrequired">';
2181 print $langs->trans(
'PriceBase');
2184 print $form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
2189 print
'<tr><td class="fieldrequired">';
2190 $text = $langs->trans(
'SellingPrice');
2191 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2193 if ($prodcustprice->price_base_type ==
'TTC') {
2194 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
2196 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
2202 $text = $langs->trans(
'MinPrice');
2203 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2205 if ($prodcustprice->price_base_type ==
'TTC') {
2206 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
2208 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
2212 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2220 print $langs->trans(
'PriceLabel');
2222 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$prodcustprice->price_label.
'">';
2227 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2228 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2229 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2230 if (!empty($extralabels)) {
2232 foreach ($extralabels as $key => $value) {
2233 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))) {
2234 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2235 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2238 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2239 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2240 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2242 print $langs->trans($value);
2244 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2249 $sql .=
" fk_object";
2250 foreach ($extralabels as $key => $value) {
2253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2254 $sql .=
" WHERE fk_object = ".((int) $prodcustprice->id);
2255 $resql = $db->query($sql);
2257 $obj = $db->fetch_object($resql);
2258 foreach ($extralabels as $key => $value) {
2259 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))) {
2260 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2261 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2264 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2265 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2266 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2268 print $langs->trans($value);
2270 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product_customer_price');
2282 print
'<div class="center">';
2283 print
'<div class="marginbottomonly">';
2284 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2285 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2288 print $form->buttonsSaveCancel();
2290 print
'<br></form>';
2291 } elseif ($action ==
'showlog_customer_price') {
2293 print
'<!-- list of all log of prices per customer -->'.
"\n";
2295 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' =>
GETPOSTINT(
'socid'));
2298 $nbtotalofrecords =
'';
2300 $nbtotalofrecords = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2303 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2308 $option =
'&socid='.GETPOSTINT(
'socid').
'&id='.
$object->id;
2310 $staticsoc =
new Societe($db);
2313 $title = $langs->trans(
'PriceByCustomerLog');
2314 $title .=
' - '.$staticsoc->getNomUrl(1);
2316 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2319 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2321 if (count($prodcustprice->lines) > 0) {
2322 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2323 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2324 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2326 print
'<div class="div-table-responsive-no-min">';
2327 print
'<table class="liste centpercent">';
2329 print
'<tr class="liste_titre">';
2330 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2331 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2332 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2333 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2334 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2335 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2336 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2337 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2338 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2340 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2341 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2342 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2343 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
2344 print
'<td> </td>';
2347 foreach ($prodcustprice->lines as $line) {
2349 $staticsoc =
new Societe($db);
2350 $staticsoc->fetch($line->fk_soc);
2352 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2355 if ($line->price_base_type ==
'HT') {
2358 $pu = $line->price_ttc;
2362 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2364 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2366 $total_ht = $resultarray[0];
2367 $total_vat = $resultarray[1];
2368 $total_localtax1 = $resultarray[9];
2369 $total_localtax2 = $resultarray[10];
2370 $total_ttc = $resultarray[2];
2372 print
'<tr class="oddeven">';
2374 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2375 print
'<td>'.$line->ref_customer.
'</td>';
2376 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2377 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2378 print
'<td class="right">';
2380 $positiverates =
'';
2382 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2385 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2388 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2390 if (empty($positiverates)) {
2391 $positiverates =
'0';
2394 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2398 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2400 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2401 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2402 print
'<td class="right">'.price($resultarray[2]).
'</td>';
2405 print
'<td class="right">'.price($line->price_min).
'</td>';
2406 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2407 print
'<td class="right">'.$line->price_label.
'</td>';
2410 $userstatic =
new User($db);
2411 $userstatic->fetch($line->fk_user);
2412 print
'<td class="right">';
2413 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
2421 print $langs->trans(
'None');
2423 } elseif ($action !=
'showlog_default_price' && $action !=
'edit_price' && $action !=
'edit_level_price') {
2425 print
'<!-- list of all prices per customer -->'.
"\n";
2428 $nbtotalofrecords =
'';
2430 $nbtotalofrecords = $prodcustprice->fetchAll($sortorder, $sortfield, 0, 0, $filter);
2433 $result = $prodcustprice->fetchAll($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2438 $option =
'&search_soc='.$search_soc.
'&id='.
$object->id;
2441 print_barre_liste($langs->trans(
'PriceByCustomer'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2443 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2444 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2445 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2447 print
'<!-- List of prices per customer -->'.
"\n";
2448 print
'<div class="div-table-responsive-no-min">'.
"\n";
2449 print
'<table class="liste centpercent">'.
"\n";
2451 if (count($prodcustprice->lines) > 0 || $search_soc) {
2457 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2460 if (!empty($price_extralabels) && is_array($price_extralabels)) {
2461 $colspan += count($price_extralabels);
2464 print
'<tr class="liste_titre">';
2465 print
'<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.
'"></td>';
2466 print
'<td class="liste_titre" colspan="'.$colspan.
'"> </td>';
2468 print
'<td class="liste_titre maxwidthsearch">';
2469 $searchpicto = $form->showFilterAndCheckAddButtons(0);
2475 print
'<tr class="liste_titre">';
2476 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2477 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2478 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2479 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2480 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2481 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2482 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2483 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2484 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2486 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2487 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2488 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2490 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2491 if ($extrafields->attributes[
"product_customer_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_customer_price"])) {
2492 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
2493 if (!empty($extralabels)) {
2494 foreach ($extralabels as $key => $value) {
2496 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2497 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2498 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2500 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2501 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2503 $extratitle = $langs->trans($value);
2505 print
'<td style="text-align: right">'.$extratitle.
'</td>';
2510 print
'<td>'.$langs->trans(
"ChangedBy").
'</td>';
2515 if (
$object->price_base_type ==
'HT') {
2522 $localtaxarray =
getLocalTaxesFromRate(
$object->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2524 $resultarray =
calcul_price_total(1, $pu, 0,
$object->tva_tx, 1, 1, 0,
$object->price_base_type, 0,
$object->type, $mysoc, $localtaxarray);
2526 $total_ht = $resultarray[0];
2527 $total_vat = $resultarray[1];
2528 $total_localtax1 = $resultarray[9];
2529 $total_localtax2 = $resultarray[10];
2530 $total_ttc = $resultarray[2];
2533 print
'<tr class="oddeven">';
2534 print
'<td colspan="3">' . $langs->trans(
'Default') .
'</td>';
2536 print
'<td class="center">'.$langs->trans(
$object->price_base_type).
"</td>";
2539 print
'<td class="right">';
2541 $positiverates =
'';
2546 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
2549 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
2551 if (empty($positiverates)) {
2552 $positiverates =
'0';
2554 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
2560 print
'<td class="right"><span class="amount">'.price(
$object->price).
"</span></td>";
2562 print
'<td class="right"><span class="amount">'.price(
$object->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(
$object->price_min).
'</td>';
2569 print
'<td class="right">'.price(
$object->price_min_ttc).
'</td>';
2570 print
'<td class="right">'.$object->price_label.
'</td>';
2571 print
'<td class="right"></td>';
2572 if (!empty($extralabels)) {
2573 foreach ($extralabels as $key) {
2574 print
'<td class="right"></td>';
2577 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2578 print
'<td class="nowraponall">';
2579 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_default_price&token='.
newToken().
'&id='.
$object->id.
'">';
2580 print
img_info($langs->trans(
'PriceByCustomerLog'));
2583 print
'<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_price&token='.
newToken().
'&id='.
$object->id.
'">';
2584 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2591 if (count($prodcustprice->lines) > 0) {
2592 foreach ($prodcustprice->lines as $line) {
2594 $staticsoc =
new Societe($db);
2595 $staticsoc->fetch($line->fk_soc);
2597 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2600 if ($line->price_base_type ==
'HT') {
2603 $pu = $line->price_ttc;
2607 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2609 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2611 $total_ht = $resultarray[0];
2612 $total_vat = $resultarray[1];
2613 $total_localtax1 = $resultarray[9];
2614 $total_localtax2 = $resultarray[10];
2615 $total_ttc = $resultarray[2];
2617 print
'<tr class="oddeven">';
2619 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2620 print
'<td>'.dol_escape_htmltag($line->ref_customer).
'</td>';
2621 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2622 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2624 print
'<td class="right">';
2626 $positiverates =
'';
2628 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2631 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2634 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2636 if (empty($positiverates)) {
2637 $positiverates =
'0';
2640 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, (!empty($line->tva_npr) ? $line->tva_npr : $line->recuperableonly));
2644 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2646 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2647 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2649 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2652 print
'<td class="right">'.price($line->price_min).
'</td>';
2653 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2654 print
'<td class="right">'.$line->price_label.
'</td>';
2657 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2658 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'] ?? array();
2659 if (!empty($extralabels)) {
2661 $sql .=
" fk_object";
2662 foreach ($extralabels as $key => $value) {
2665 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2666 $sql .=
" WHERE fk_object = ".((int) $line->id);
2667 $resql = $db->query($sql);
2669 if ($db->num_rows($resql) != 1) {
2670 foreach ($extralabels as $key => $value) {
2671 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2676 $obj = $db->fetch_object($resql);
2677 foreach ($extralabels as $key => $value) {
2678 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2679 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_customer_price').
"</td>";
2688 $userstatic =
new User($db);
2689 $userstatic->fetch($line->fk_user);
2692 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2697 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2698 print
'<td class="right nowraponall">';
2699 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&id='.
$object->id.
'&socid='.$line->fk_soc.
'">';
2700 print
img_info($langs->trans(
'PriceByCustomerLog'));
2703 print
'<a class="marginleftonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2704 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2707 print
'<a class="marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2708 print
img_delete(
'default',
'style="vertical-align: middle;"');
2726if ((!
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES') || $action ==
'showlog_default_price') && !in_array($action, array(
'edit_price',
'edit_level_price',
'edit_vat'))) {
2727 $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,";
2728 $sql .=
" p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
2729 $sql .=
" p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
2730 $sql .=
" ,p.price_label";
2731 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price as p,";
2732 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
2733 $sql .=
" WHERE fk_product = ".((int)
$object->id);
2734 $sql .=
" AND p.entity IN (".getEntity(
'productprice').
")";
2735 $sql .=
" AND p.fk_user_author = u.rowid";
2737 $sql .=
" AND p.price_level = ".((int) $soc->price_level);
2739 $sql .=
" ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
2743 $result = $db->query($sql);
2745 print
'<div class="divlogofpreviouscustomerprice">';
2747 $num = $db->num_rows($result);
2756 $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);
2764 $result = $db->query($sql);
2765 $num = $db->num_rows($result);
2772 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2776 print_barre_liste($langs->trans(
"DefaultPriceLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'', $backbutton, 0, $num,
'title_accountancy.png');
2779 print_barre_liste($langs->trans(
"PriceByCustomerLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', 0, $num,
'title_accountancy.png');
2782 print
'<!-- List of log prices -->'.
"\n";
2783 print
'<div class="div-table-responsive">'.
"\n";
2784 print
'<table class="liste centpercent noborder">'.
"\n";
2786 print
'<tr class="liste_titre">';
2787 print
'<th>'.$langs->trans(
"AppliedPricesFrom").
'</tg>';
2790 print
'<th class="center">'.$langs->trans(
"PriceLevel").
'</th>';
2793 print
'<th class="center">'.$langs->trans(
"Type").
'</th>';
2796 print
'<th class="center">'.$langs->trans(
"PriceBase").
'</th>';
2798 print
'<th class="right">'.$langs->trans(
"DefaultTaxRate").
'</th>';
2800 print
'<th class="right">'.$langs->trans(
"HT").
'</th>';
2801 print
'<th class="right">'.$langs->trans(
"TTC").
'</th>';
2802 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2803 print
'<th class="right">'.$langs->trans(
"INCT").
'</th>';
2805 if (isModEnabled(
'dynamicprices')) {
2806 print
'<th class="right">'.$langs->trans(
"PriceExpressionSelected").
'</th>';
2808 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</th>';
2809 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</th>';
2810 print
'<th class="right">'.$langs->trans(
"Label").
'</th>';
2811 print
'<th>'.$langs->trans(
"ChangedBy").
'</th>';
2812 if ($user->hasRight(
'produit',
'supprimer')) {
2813 print
'<th class="right"> </th>';
2817 $notfirstlineforlevel = array();
2821 $objp = $db->fetch_object($result);
2823 print
'<tr class="oddeven">';
2825 print
"<td>".dol_print_date($db->jdate($objp->dp),
"dayhour",
'tzuserrel').
"</td>";
2829 print
'<td class="center">'.$objp->price_level.
"</td>";
2833 $type = ($objp->price_by_qty == 1) ?
'PriceByQuantity' :
'Standard';
2834 print
'<td class="center">'.$langs->trans($type).
"</td>";
2837 print
'<td class="center">';
2838 if (empty($objp->price_by_qty)) {
2839 print $langs->trans($objp->price_base_type);
2844 print
'<td class="right">';
2846 if (empty($objp->price_by_qty)) {
2847 $positiverates =
'';
2849 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->tva_tx);
2852 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax1_tx);
2855 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax2_tx);
2857 if (empty($positiverates)) {
2858 $positiverates =
'0';
2860 echo
vatrate($positiverates.($objp->default_vat_code ?
' ('.$objp->default_vat_code.
')' :
''), true, !empty($objp->tva_npr) ? $objp->tva_npr : 0);
2873 if ($objp->price_base_type ==
'HT') {
2876 $pu = $objp->price_ttc;
2880 $localtaxarray =
getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2882 $resultarray =
calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2884 $total_ht = $resultarray[0];
2885 $total_vat = $resultarray[1];
2886 $total_localtax1 = $resultarray[9];
2887 $total_localtax2 = $resultarray[10];
2888 $total_ttc = $resultarray[2];
2891 if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) {
2893 $res = $price_expression->fetch($objp->fk_price_expression);
2894 $title = $price_expression->title;
2895 print
'<td class="right"></td>';
2896 print
'<td class="right"></td>';
2897 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2898 print
'<td class="right"></td>';
2900 print
'<td class="right">'.$title.
"</td>";
2903 print
'<td class="right">';
2904 if (empty($objp->price_by_qty)) {
2905 print
'<span class="amount">'.price($objp->price).
'</span>';
2909 print
'<td class="right">';
2910 if (empty($objp->price_by_qty)) {
2911 $price_ttc = $objp->price_ttc;
2912 print
'<span class="amount">'.price($price_ttc).
'<span>';
2915 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2916 print
'<td class="right">';
2917 print $resultarray[2];
2920 if (isModEnabled(
'dynamicprices')) {
2921 print
'<td class="right"></td>';
2926 print
'<td class="right">';
2927 if (empty($objp->price_by_qty)) {
2928 print
price($objp->price_min);
2933 print
'<td class="right">';
2934 if (empty($objp->price_by_qty)) {
2935 $price_min_ttc = $objp->price_min_ttc;
2936 print
price($price_min_ttc);
2941 print
'<td class="right">';
2942 print $objp->price_label;
2947 if ($objp->user_id > 0) {
2948 $userstatic =
new User($db);
2949 $userstatic->fetch($objp->user_id);
2950 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2956 if ($user->hasRight(
'produit',
'supprimer')) {
2959 if (empty($notfirstlineforlevel[$objp->price_level])) {
2960 $notfirstlineforlevel[$objp->price_level] = 1;
2968 print
'<td class="right">';
2969 if ($candelete || ($db->jdate($objp->dp) >=
dol_now())) {
2970 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).
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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...
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.