40require
'../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
65$langs->loadLangs(array(
'products',
'bills',
'companies',
'other'));
72$action =
GETPOST(
'action',
'aZ09');
73$cancel =
GETPOST(
'cancel',
'alpha');
76$search_soc =
GETPOST(
'search_soc');
79$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
80$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
82 $socid = $user->socid;
86if ($id > 0 || !empty($ref)) {
94 $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
98$hookmanager->initHooks(array(
'productpricecard',
'globalcard'));
101 if (
$object->type == $object::TYPE_PRODUCT) {
104 if (
$object->type == $object::TYPE_SERVICE) {
108 restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
120$parameters = array(
'id' => $id,
'ref' => $ref);
121$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
126if (empty($reshook)) {
127 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
131 if ($action ==
'setlabelsellingprice' && $user->admin) {
132 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
133 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.GETPOST(
'pricelevel');
138 if (($action ==
'update_vat') && !$cancel && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
139 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
141 $price_label =
GETPOST(
'price_label',
'alpha');
144 $tva_tx = $tva_tx_txt;
147 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
148 $vatratecode = $reg[1];
149 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
152 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
153 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
156 $localtax1_type =
'0';
157 $localtax2_type =
'0';
160 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
162 $vatratecode = $reg[1];
164 $sql =
"SELECT t.rowid, t.type_vat, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
166 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
167 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
168 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
169 $sql .=
" AND t.type_vat IN (0, 1)";
170 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
171 $resql = $db->query($sql);
173 $obj = $db->fetch_object($resql);
175 $npr = $obj->recuperableonly;
176 $localtax1 = $obj->localtax1;
177 $localtax2 = $obj->localtax2;
178 $localtax1_type = $obj->localtax1_type;
179 $localtax2_type = $obj->localtax2_type;
184 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
185 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
186 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
187 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
188 $sql .=
" AND t.code = ''";
189 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
190 $resql = $db->query($sql);
192 $obj = $db->fetch_object($resql);
194 $npr = $obj->recuperableonly;
195 $localtax1 = $obj->localtax1;
196 $localtax2 = $obj->localtax2;
197 $localtax1_type = $obj->localtax1_type;
198 $localtax2_type = $obj->localtax2_type;
203 $object->default_vat_code = $vatratecode;
206 $object->localtax1_tx = $localtax1;
207 $object->localtax2_tx = $localtax2;
208 $object->localtax1_type = $localtax1_type;
209 $object->localtax2_type = $localtax2_type;
210 $object->price_label = $price_label;
222 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
223 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
225 if (
$object->multiprices_base_type[$i] ==
'HT') {
226 $oldprice =
$object->multiprices[$i];
227 $oldminprice =
$object->multiprices_min[$i];
229 $oldprice =
$object->multiprices_ttc[$i];
230 $oldminprice =
$object->multiprices_min_ttc[$i];
232 $oldpricebasetype =
$object->multiprices_base_type[$i];
233 $oldnpr =
$object->multiprices_recuperableonly[$i];
236 $localtaxarray = array();
238 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
247 if (
$object->price_base_type ==
'HT') {
249 $oldminprice =
$object->price_min;
251 $oldprice =
$object->price_ttc;
252 $oldminprice =
$object->price_min_ttc;
254 $oldpricebasetype =
$object->price_base_type;
258 $localtaxarray = array();
260 $ret =
$object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode, $price_label);
278 if (($action ==
'update_price' || $action ==
'update_level_price') && !$cancel &&
$object->getRights()->creer) {
280 $pricestoupdate = array();
283 $psq = empty($newpsq) ? 0 : $newpsq;
284 $maxpricesupplier =
$object->min_recommended_price();
286 if (isModEnabled(
'dynamicprices')) {
287 $object->fk_price_expression = empty($eid) ? 0 : $eid;
289 if (
$object->fk_price_expression != 0) {
291 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
294 if ($priceparser->parseProduct($object) < 0) {
303 $newprice =
GETPOST(
'price',
'array');
304 $newprice_min =
GETPOST(
'price_min',
'array');
305 $newpricebase =
GETPOST(
'multiprices_base_type',
'array');
306 $newvattx =
GETPOST(
'tva_tx',
'array');
307 $newvatnpr =
GETPOST(
'tva_npr',
'array');
308 $newlocaltax1_tx =
GETPOST(
'localtax1_tx',
'array');
309 $newlocaltax1_type =
GETPOST(
'localtax1_type',
'array');
310 $newlocaltax2_tx =
GETPOST(
'localtax2_tx',
'array');
311 $newlocaltax2_type =
GETPOST(
'localtax2_type',
'array');
314 $object->price_autogen = (int) (
GETPOST(
'usePriceRules') ==
'on');
316 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
317 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
318 if (!isset($newprice[$i])) {
322 $tva_tx_txt = $newvattx[$i];
324 $tva_tx = $tva_tx_txt;
327 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
328 $vat_src_code = $reg[1];
329 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
331 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
333 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
334 $localtax1 = $newlocaltax1_tx[$i];
335 $localtax1_type = $newlocaltax1_type[$i];
336 $localtax2 = $newlocaltax2_tx[$i];
337 $localtax2_type = $newlocaltax2_type[$i];
338 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
340 $vatratecode = $reg[1];
342 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
344 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
345 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
346 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
347 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
348 $resql = $db->query($sql);
350 $obj = $db->fetch_object($resql);
352 $npr = $obj->recuperableonly;
353 $localtax1 = $obj->localtax1;
354 $localtax2 = $obj->localtax2;
355 $localtax1_type = $obj->localtax1_type;
356 $localtax2_type = $obj->localtax2_type;
360 if (in_array($mysoc->country_code, array(
'ES'))) {
367 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
369 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
370 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
371 $sql .=
" AND t.code = ''";
372 $resql = $db->query($sql);
374 $obj = $db->fetch_object($resql);
376 $npr = $obj->recuperableonly;
377 $localtax1 = $obj->localtax1;
378 $localtax2 = $obj->localtax2;
379 $localtax1_type = $obj->localtax1_type;
380 $localtax2_type = $obj->localtax2_type;
385 $pricestoupdate[$i] = array(
386 'price' =>
price2num($newprice[$i],
'', 2),
387 'price_min' =>
price2num($newprice_min[$i],
'', 2),
388 'price_base_type' => $newpricebase[$i],
389 'default_vat_code' => $vatratecode,
392 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
403 $newpricebase =
GETPOST(
'price_base_type',
'alpha');
404 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
405 $price_label =
GETPOST(
'price_label',
'alpha');
407 $tva_tx = $tva_tx_txt;
410 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
411 $vat_src_code = $reg[1];
412 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
414 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
416 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
419 $localtax1_type =
'0';
420 $localtax2_type =
'0';
422 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
424 $vatratecode = $reg[1];
426 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
427 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
428 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
429 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
430 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
431 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
432 $resql = $db->query($sql);
434 $obj = $db->fetch_object($resql);
436 $npr = $obj->recuperableonly;
437 $localtax1 = $obj->localtax1;
438 $localtax2 = $obj->localtax2;
439 $localtax1_type = $obj->localtax1_type;
440 $localtax2_type = $obj->localtax2_type;
444 if (in_array($mysoc->country_code, array(
'ES'))) {
451 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
452 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
453 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
454 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
455 $sql .=
" AND t.code = ''";
456 $resql = $db->query($sql);
458 $obj = $db->fetch_object($resql);
460 $npr = $obj->recuperableonly;
461 $localtax1 = $obj->localtax1;
462 $localtax2 = $obj->localtax2;
463 $localtax1_type = $obj->localtax1_type;
464 $localtax2_type = $obj->localtax2_type;
469 $pricestoupdate[0] = array(
470 'price' => $newprice,
471 'price_label' => $price_label,
472 'price_min' => $newprice_min,
473 'price_base_type' => $newpricebase,
474 'default_vat_code' => $vatratecode,
477 'localtaxes_array' => array(
'0' => $localtax1_type,
'1' => $localtax1,
'2' => $localtax2_type,
'3' => $localtax2)
484 foreach ($pricestoupdate as $key => $val) {
485 $newprice = $val[
'price'];
487 if ($val[
'price'] < $val[
'price_min'] && !empty(
$object->fk_price_expression)) {
488 $newprice = $val[
'price_min'];
492 $newprice_min =
price2num($val[
'price_min'],
'MU');
495 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $newprice_min < $maxpricesupplier) {
496 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, - 1, - 1,
'auto')),
null,
'errors');
501 if (!array_key_exists($key,
$object->multiprices) ||
$object->multiprices[$key] != $newprice ||
$object->multiprices_min[$key] != $newprice_min ||
$object->multiprices_base_type[$key] != $val[
'price_base_type'] ||
$object->multiprices_tva_tx[$key] != $newvattx) {
502 $res =
$object->updatePrice($newprice, $val[
'price_base_type'], $user, $val[
'vat_tx'], $newprice_min, $key, $val[
'npr'], $psq, 0, $val[
'localtaxes_array'], $val[
'default_vat_code'], $val[
'price_label']);
504 $extralabels = $extrafields->fetch_name_optionals_label(
"product");
507 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
508 foreach ($extrafield_values as $efkey => $value) {
509 $object->array_options[$efkey] = $value;
511 $result =
$object->insertExtraFields();
516 $price_extralabels = $extrafields->fetch_name_optionals_label(
"product_price");
517 $sql =
"SELECT rowid";
518 $sql .=
" FROM ".$object->db->prefix().
"product_price";
519 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
520 $sql .=
" AND price_level=".((int) $key);
521 $sql .=
" AND fk_product = ".((int)
$object->id);
522 $sql .=
" ORDER BY date_price DESC, rowid DESC";
524 $resql =
$object->db->query($sql);
526 $lineid =
$object->db->fetch_object($resql);
529 if (!empty($lineid->rowid)) {
530 if (!empty($price_extralabels) && is_array($price_extralabels)) {
531 foreach ($price_extralabels as $code => $label) {
532 $code_array =
GETPOST($code,
'array');
533 $object->array_options[
'options_'.$code] = $code_array[$key];
537 $object->table_element =
'product_price';
538 $result =
$object->insertExtraFields();
542 $object->table_element =
'product';
571 $action =
'edit_price';
577 if ($action ==
'delete' && $user->hasRight(
'produit',
'supprimer')) {
585 if ($action ==
'activate_price_by_qty') {
597 if ($action ==
'disable_price_by_qty') {
609 if ($action ==
'edit_price_by_qty') {
614 if ($action ==
'update_price_by_qty') {
624 if (empty($quantity)) {
626 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Qty")),
null,
'errors');
628 if (empty($newprice)) {
630 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Price")),
null,
'errors');
634 if (
$object->price_base_type ==
'TTC') {
639 $unitPrice =
price2num((
float) $price / (
float) $quantity,
'MU');
643 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_price_by_qty SET";
644 $sql .=
" price=".((float) $price).
",";
645 $sql .=
" unitprice=".((float) $unitPrice).
",";
646 $sql .=
" quantity=".((float) $quantity).
",";
647 $sql .=
" remise_percent=".((float) $remise_percent).
",";
648 $sql .=
" remise=".((float) $remise);
649 $sql .=
" WHERE rowid = ".((int) $rowid);
651 $result = $db->query($sql);
656 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
657 $sql .= ((int) $priceid).
','.((float) $price).
','.((float) $unitPrice).
','.((float) $quantity).
','.((float) $remise_percent).
','.((float) $remise).
')';
659 $result = $db->query($sql);
661 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
671 if ($action ==
'delete_price_by_qty') {
673 if (!empty($rowid)) {
674 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
675 $sql .=
" WHERE rowid = ".((int) $rowid);
677 $result = $db->query($sql);
679 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
683 if ($action ==
'delete_all_price_by_qty') {
685 if (!empty($rowid)) {
686 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
687 $sql .=
" WHERE fk_product_price = ".((int) $priceid);
689 $result = $db->query($sql);
691 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
700 if ($action ==
'add_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
701 $maxpricesupplier =
$object->min_recommended_price();
703 $update_child_soc =
GETPOSTINT(
'updatechildprice');
707 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
708 $prodcustprice->fk_product =
$object->id;
711 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
712 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
714 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
715 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
717 $tva_tx_txt =
GETPOST(
"tva_tx",
'alpha');
719 $tva_tx = $tva_tx_txt;
721 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
722 $vat_src_code = $reg[1];
723 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
725 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
727 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
730 $localtax1_type =
'0';
731 $localtax2_type =
'0';
733 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
735 $vatratecode = $reg[1];
737 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
739 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
740 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
741 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
742 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
743 $resql = $db->query($sql);
745 $obj = $db->fetch_object($resql);
747 $npr = $obj->recuperableonly;
748 $localtax1 = $obj->localtax1;
749 $localtax2 = $obj->localtax2;
750 $localtax1_type = $obj->localtax1_type;
751 $localtax2_type = $obj->localtax2_type;
755 if (in_array($mysoc->country_code, array(
'ES'))) {
762 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
763 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
764 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
765 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
766 $sql .=
" AND t.code = ''";
767 $resql = $db->query($sql);
769 $obj = $db->fetch_object($resql);
771 $npr = $obj->recuperableonly;
772 $localtax1 = $obj->localtax1;
773 $localtax2 = $obj->localtax2;
774 $localtax1_type = $obj->localtax1_type;
775 $localtax2_type = $obj->localtax2_type;
780 $prodcustprice->default_vat_code = $vatratecode;
781 $prodcustprice->tva_tx = $tva_tx;
782 $prodcustprice->recuperableonly = $npr;
783 $prodcustprice->localtax1_tx = $localtax1;
784 $prodcustprice->localtax2_tx = $localtax2;
785 $prodcustprice->localtax1_type = $localtax1_type;
786 $prodcustprice->localtax2_type = $localtax2_type;
788 if (!($prodcustprice->fk_soc > 0)) {
789 $langs->load(
"errors");
790 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
792 $action =
'add_customer_price';
794 if (
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $prodcustprice->price_min < $maxpricesupplier) {
795 $langs->load(
"errors");
796 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
798 $action =
'add_customer_price';
802 $result = $prodcustprice->create($user, 0, $update_child_soc);
804 if (!empty($extrafield_values) && is_array($extrafield_values)) {
806 $res = $productcustomerprice->fetch($prodcustprice->id);
808 foreach ($extrafield_values as $key => $value) {
809 $productcustomerprice->array_options[$key] = $value;
811 $result2 = $productcustomerprice->insertExtraFields();
813 $prodcustprice->error = $productcustomerprice->error;
814 $prodcustprice->errors = $productcustomerprice->errors;
831 if ($action ==
'delete_customer_price' && $prodcustprice !==
null && ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer'))) {
834 $result = $prodcustprice->delete($user);
837 $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields WHERE fk_object = ".((
int) $prodcustprice->id));
852 if ($action ==
'update_customer_price_confirm' && !$cancel && $prodcustprice !==
null && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
853 $maxpricesupplier =
$object->min_recommended_price();
855 $update_child_soc =
GETPOSTINT(
'updatechildprice');
860 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
863 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
864 $prodcustprice->price_label =
GETPOST(
"price_label",
'alpha');
866 $extralabels = $extrafields->fetch_name_optionals_label(
"product_customer_price");
867 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
869 $tva_tx_txt =
GETPOST(
"tva_tx");
871 $tva_tx = $tva_tx_txt;
873 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
874 $vat_src_code = $reg[1];
875 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
877 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
879 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
882 $localtax1_type =
'0';
883 $localtax2_type =
'0';
885 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
887 $vatratecode = $reg[1];
889 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
890 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
891 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
892 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
893 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
894 $sql .=
" AND t.entity IN (".getEntity(
'c_tva').
")";
895 $resql = $db->query($sql);
897 $obj = $db->fetch_object($resql);
899 $npr = $obj->recuperableonly;
900 $localtax1 = $obj->localtax1;
901 $localtax2 = $obj->localtax2;
902 $localtax1_type = $obj->localtax1_type;
903 $localtax2_type = $obj->localtax2_type;
907 if (in_array($mysoc->country_code, array(
'ES'))) {
914 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
915 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
916 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
917 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
918 $sql .=
" AND t.code = ''";
919 $resql = $db->query($sql);
921 $obj = $db->fetch_object($resql);
923 $npr = $obj->recuperableonly;
924 $localtax1 = $obj->localtax1;
925 $localtax2 = $obj->localtax2;
926 $localtax1_type = $obj->localtax1_type;
927 $localtax2_type = $obj->localtax2_type;
932 $prodcustprice->default_vat_code = $vatratecode;
933 $prodcustprice->tva_tx = $tva_tx;
934 $prodcustprice->recuperableonly = $npr;
935 $prodcustprice->localtax1_tx = $localtax1;
936 $prodcustprice->localtax2_tx = $localtax2;
937 $prodcustprice->localtax1_type = $localtax1_type;
938 $prodcustprice->localtax2_type = $localtax2_type;
940 if ($prodcustprice->price_min < $maxpricesupplier &&
getDolGlobalString(
'PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
941 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
943 $action =
'update_customer_price';
947 $result = $prodcustprice->update($user, 0, $update_child_soc);
949 if (!empty($extrafield_values) && is_array($extrafield_values)) {
951 $res = $productcustomerprice->fetch($prodcustprice->id);
953 foreach ($extrafield_values as $key => $value) {
954 $productcustomerprice->array_options[$key] = $value;
956 $result2 = $productcustomerprice->insertExtraFields();
958 $prodcustprice->error = $productcustomerprice->error;
959 $prodcustprice->errors = $productcustomerprice->errors;
982$form =
new Form($db);
984if (!empty($id) || !empty($ref)) {
989$title = $langs->trans(
'ProductServiceCard');
993 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
994 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
997 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
998 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
1001llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'classforhorizontalscrolloftabs mod-product page-price');
1004$titre = $langs->trans(
"CardProduct".
$object->type);
1009$linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1&type='.
$object->type.
'">'.$langs->trans(
"BackToList").
'</a>';
1010$object->next_prev_filter =
"fk_product_type:=:".((int)
$object->type);
1013if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
1017dol_banner_tab($object,
'ref', $linkback, $shownav,
'ref');
1020print
'<div class="fichecenter">';
1022print
'<div class="underbanner clearboth"></div>';
1023print
'<table class="border tableforfield centpercent">';
1029 if (!empty($socid)) {
1032 $soc->fetch($socid);
1035 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1036 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1037 print
'<tr><td class="">';
1038 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1040 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1045 print
'<tr><td class="titlefieldcreate">';
1046 print $langs->trans(
"SellingPrice");
1048 print
'<td colspan="2">';
1049 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1050 print
'<span class="amount">'.price(
$object->multiprices_ttc[$soc->price_level]).
'</span>';
1052 print
'<span class="amount">'.price(
$object->multiprices[$soc->price_level]).
'</span>';
1054 if (
$object->multiprices_base_type[$soc->price_level]) {
1055 print
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1057 print
' '.$langs->trans(
$object->price_base_type);
1062 print
'<tr><td>'.$langs->trans(
"MinPrice").
'</td><td colspan="2">';
1063 if (
$object->multiprices_base_type[$soc->price_level] ==
'TTC') {
1064 print
price(
$object->multiprices_min_ttc[$soc->price_level]).
' '.$langs->trans(
$object->multiprices_base_type[$soc->price_level]);
1066 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]);
1072 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td colspan="2">';
1074 $positiverates =
'';
1076 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_tva_tx[$soc->price_level]);
1079 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax1_tx[$soc->price_level]);
1082 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->multiprices_localtax2_tx[$soc->price_level]);
1084 if (empty($positiverates)) {
1085 $positiverates =
'0';
1087 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1092 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1094 $positiverates =
'';
1099 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1102 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1104 if (empty($positiverates)) {
1105 $positiverates =
'0';
1107 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
1119 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1120 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1121 print
'<tr><td class="">';
1122 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1124 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1129 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1130 print
'<td colspan="2">'.vatrate(
$object->multiprices_tva_tx[1],
true).
'</td>';
1134 if (isModEnabled(
"product") && isModEnabled(
"service")) {
1135 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
1136 print
'<tr><td class="">';
1137 print (!
getDolGlobalString(
'PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
1139 print $form->editfieldval(
"Type",
'fk_product_type',
$object->type, $object, 0, $typeformat);
1144 print
'<!-- Default VAT Rate -->';
1145 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1148 $positiverates =
'';
1150 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->tva_tx);
1153 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax1_tx);
1156 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num(
$object->localtax2_tx);
1158 if (empty($positiverates)) {
1159 $positiverates =
'0';
1162 print
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 1);
1175 print
'<table class="liste centpercent">';
1176 print
'<tr class="liste_titre"><td>';
1177 print $langs->trans(
"PriceLevel");
1179 print
' <a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editlabelsellingprice&token='.
newToken().
'&pricelevel='.$i.
'&id='.
$object->id.
'">'.
img_edit($langs->trans(
'EditSellingPriceLabel'), 0).
'</a>';
1182 print
'<td style="text-align: right">'.$langs->trans(
"SellingPrice").
'</td>';
1183 print
'<td style="text-align: right">'.$langs->trans(
"MinPrice").
'</td>';
1185 $extrafields->fetch_name_optionals_label(
"product_price");
1186 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1187 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1188 if (!empty($extralabels)) {
1189 foreach ($extralabels as $key => $value) {
1191 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1192 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1193 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1195 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1196 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1198 $extratitle = $langs->trans($value);
1200 $field =
'ef.' . $key;
1201 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1208 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1209 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1210 print
'<tr class="oddeven">';
1214 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1215 if (preg_match(
'/editlabelsellingprice/', $action)) {
1216 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
1217 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1218 print
'<input type="hidden" name="action" value="setlabelsellingprice">';
1219 print
'<input type="hidden" name="pricelevel" value="'.$i.
'">';
1220 print $langs->trans(
"SellingPrice").
' '.$i.
' - ';
1221 print
'<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' .
getDolGlobalString($keyforlabel).
'">';
1222 print
' <input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
1225 print $langs->trans(
"SellingPrice").
' '.$i;
1232 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1233 print
'<td class="right"><span class="amount">'.price(
$object->multiprices_ttc[$i]);
1235 print
'<td class="right"><span class="amount">'.price(
$object->multiprices[$i]);
1238 if (
$object->multiprices_base_type[$i]) {
1239 print
' '.$langs->trans(
$object->multiprices_base_type [$i]).
'</span></td>';
1241 print
' '.$langs->trans(
$object->price_base_type).
'</span></td>';
1245 print
'<td style="text-align: right">';
1246 if (empty(
$object->multiprices_base_type[$i])) {
1247 $object->multiprices_base_type[$i] =
"HT";
1249 if (
$object->multiprices_base_type[$i] ==
'TTC') {
1250 print
price(
$object->multiprices_min_ttc[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1252 print
price(
$object->multiprices_min[$i]).
' '.$langs->trans(
$object->multiprices_base_type[$i]);
1255 if (!empty($extralabels)) {
1256 $sql1 =
"SELECT rowid";
1257 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1258 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1259 $sql1 .=
" AND price_level=".((int) $i);
1260 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1261 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1262 $sql1 .=
" LIMIT 1";
1263 $resql1 =
$object->db->query($sql1);
1265 $lineid =
$object->db->fetch_object($resql1);
1268 $sql2 .=
" fk_object";
1269 foreach ($extralabels as $key => $value) {
1272 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1273 $sql2 .=
" WHERE fk_object = ".((int) $lineid->rowid);
1274 $resql2 = $db->query($sql2);
1276 if ($db->num_rows($resql2) != 1) {
1277 foreach ($extralabels as $key => $value) {
1278 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1279 print
'<td align="right"></td>';
1283 $obj = $db->fetch_object($resql2);
1284 foreach ($extralabels as $key => $value) {
1285 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1286 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_price').
"</td>";
1298 print
'<tr><td>'.$langs->trans(
"PriceByQuantity").
' '.$i;
1302 print
'</td><td colspan="2">';
1304 if (
$object->prices_by_qty[$i] == 1) {
1305 print
'<table width="50%" class="border" summary="List of quantities">';
1307 print
'<tr class="liste_titre">';
1308 print
'<td>'.$langs->trans(
"PriceByQuantityRange").
' '.$i.
'</td>';
1309 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
1310 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1311 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1312 print
'<td> </td>';
1314 foreach (
$object->prices_by_qty_list[$i] as $ii => $prices) {
1315 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1316 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1317 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1318 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1319 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1320 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1321 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1322 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1323 print
'<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"> '.
$object->price_base_type.
'</td>';
1324 print
'<td class="right nowraponall"><input size="5" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1325 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1329 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1330 print
'<td>'.$prices[
'quantity'].
'</td>';
1331 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1332 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1333 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1334 print
'<td class="center">';
1335 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1336 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1338 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1347 if ($action !=
'edit_price_by_qty' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1348 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1349 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1350 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1351 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1352 print
'<input type="hidden" value="0" name="rowid">';
1353 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1354 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1355 print
'<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.
'</td>';
1356 print
'<td class="right"> </td>';
1357 print
'<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
1358 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1364 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>';
1366 print $langs->trans(
"No");
1367 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>';
1375 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1377 $positiverates =
'';
1382 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
1385 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
1387 if (empty($positiverates)) {
1388 $positiverates =
'0';
1390 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr, 0, 1);
1400 print
'<tr class="field_selling_price"><td>'.$langs->trans(
"SellingPrice").
'</td><td>';
1401 if (
$object->price_base_type ==
'TTC') {
1406 print
'<i class="opacitymedium"> - ' .
price(
$object->price_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1413 print
'<tr class="field_min_price"><td>'.$langs->trans(
"MinPrice").
'</td><td>';
1414 if (
$object->price_base_type ==
'TTC') {
1419 print
'<i class="opacitymedium"> - ' .
price(
$object->price_min_ttc).
' '.$langs->trans(
'TTC') .
'</i>';
1425 print
'<tr class="field_price_label"><td>'.$langs->trans(
"PriceLabel").
'</td><td>';
1431 print
'<tr><td>'.$langs->trans(
"PriceByQuantity");
1432 if (
$object->prices_by_qty[0] == 0) {
1433 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=activate_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"Activate").
')';
1435 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=disable_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"DisablePriceByQty").
')';
1439 if (
$object->prices_by_qty[0] == 1) {
1440 print
'<table width="50%" class="border" summary="List of quantities">';
1441 print
'<tr class="liste_titre">';
1443 print
'<td>'.$langs->trans(
"Quantity").
'</td>';
1444 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
1445 print
'<td class="right"></td>';
1446 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1447 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1448 print
'<td> </td>';
1450 if ($action !=
'edit_price_by_qty') {
1451 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1452 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1453 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1454 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1455 print
'<input type="hidden" value="0" name="rowid">';
1457 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1458 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1459 print
'<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
1463 print
'<td class="right"> </td>';
1464 print
'<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
1465 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1470 foreach (
$object->prices_by_qty_list[0] as $ii => $prices) {
1471 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1472 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1473 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1474 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1475 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1476 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1477 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1478 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1479 print
'<td class="right"><input class="width50 right" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"></td>';
1480 print
'<td class="right">';
1482 print $prices[
'price_base_type'];
1484 print
'<td class="right"> </td>';
1485 print
'<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1486 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1490 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1491 print
'<td>'.$prices[
'quantity'].
'</td>';
1492 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1493 print
'<td class="right">';
1495 print $prices[
'price_base_type'];
1497 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1498 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1499 print
'<td class="center">';
1500 if (($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1501 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1503 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1514 print $langs->trans(
"No");
1520 $extrafields->fetch_name_optionals_label(
"product");
1521 $extralabels = !empty($extrafields->attributes[
"product"][
'label']) ? $extrafields->attributes[
"product"][
'label'] :
'';
1522 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
1524 $sql .=
" fk_object";
1525 foreach ($extralabels as $key => $value) {
1528 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_extrafields";
1529 $sql .=
" WHERE fk_object = ".((int)
$object->id);
1530 $resql = $db->query($sql);
1532 $obj = $db->fetch_object($resql);
1533 foreach ($extralabels as $key => $value) {
1534 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))) {
1535 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1536 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1539 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1540 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1541 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1543 print $langs->trans($value);
1546 print
'<td align="left">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product').
"</td></tr>";
1556print
'<div class="clearboth"></div>';
1568if (!$action || $action ==
'delete' || $action ==
'showlog_customer_price' || $action ==
'showlog_default_price' || $action ==
'add_customer_price'
1569 || $action ==
'activate_price_by_qty' || $action ==
'disable_price_by_qty') {
1570 print
"\n".
'<div class="tabsAction">'.
"\n";
1573 $parameters = array();
1574 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1575 if (empty($reshook)) {
1577 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1578 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"NoEditVariants")) .
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</a></div>';
1582 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1583 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>';
1585 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</span></div>';
1590 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1591 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>';
1593 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"AddCustomerPrice") .
'</span></div>';
1598 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1599 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>';
1601 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateVAT") .
'</span></div>';
1604 if ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer')) {
1605 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>';
1607 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateLevelPrices") .
'</span></div>';
1622if ($action ==
'edit_vat' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
1625 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1626 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1627 print
'<input type="hidden" name="action" value="update_vat">';
1628 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1632 print
'<table class="border centpercent">';
1635 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1643 print $form->buttonsSaveCancel();
1645 print
'<br></form><br>';
1648if (($action ==
'edit_price' || $action ==
'edit_level_price') &&
$object->getRights()->creer) {
1653 print
'<!-- Edit price -->'.
"\n";
1654 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1655 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1656 print
'<input type="hidden" name="action" value="update_price">';
1657 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1661 print
'<div class="div-table-responsive-no-min">';
1662 print
'<table class="border centpercent">';
1665 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1671 print $langs->trans(
'PriceBase');
1674 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
1679 if (isModEnabled(
'dynamicprices')) {
1681 print
'<!-- Show price mode of dynamicprices editor -->'.
"\n";
1682 print
'<tr><td>'.$langs->trans(
"PriceMode").
'</td><td>';
1683 print
img_picto(
'',
'dynamicprice',
'class="pictofixedwidth"');
1685 $price_expression_list = array(0 => $langs->trans(
"Numeric").
' <span class="opacitymedium">('.$langs->trans(
"NoDynamicPrice").
')</span>');
1686 foreach ($price_expression->list_price_expression() as $entry) {
1687 $price_expression_list[$entry->id] = $entry->title;
1689 $price_expression_preselection =
GETPOST(
'eid') ?
GETPOST(
'eid') : (
$object->fk_price_expression ?
$object->fk_price_expression :
'0');
1690 print $form->selectarray(
'eid', $price_expression_list, $price_expression_preselection);
1691 print
' <a id="expression_editor" class="classlink">'.$langs->trans(
"PriceExpressionEditor").
'</a>';
1697 <script
type=
"text/javascript">
1698 jQuery(document).ready(
function() {
1699 jQuery(
"#expression_editor").click(
function() {
1700 window.location =
"<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $(
"#eid").val();
1702 jQuery(
"#eid").change(on_change);
1705 function on_change() {
1706 if ($(
"#eid").val() == 0) {
1707 jQuery(
"#price_numeric").show();
1709 jQuery(
"#price_numeric").hide();
1718 $product->fetch($id, $ref,
'', 1);
1719 print
'<tr id="price_numeric"><td>';
1720 $text = $langs->trans(
'SellingPrice');
1721 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1723 if (
$object->price_base_type ==
'TTC') {
1724 print
'<input name="price" size="10" value="'.price($product->price_ttc).
'">';
1726 print
'<input name="price" size="10" value="'.price($product->price).
'">';
1732 $text = $langs->trans(
'MinPrice');
1733 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1735 if (
$object->price_base_type ==
'TTC') {
1736 print
'<input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
1738 print
'<input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
1741 print
' '.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1748 print $langs->trans(
'PriceLabel');
1750 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
1755 $extrafields->fetch_name_optionals_label(
"product");
1756 $extralabels = !empty($extrafields->attributes[
"product"][
'label']) ? $extrafields->attributes[
"product"][
'label'] :
'';
1757 $extrafield_values = $extrafields->getOptionalsFromPost(
"product");
1758 if (!empty($extralabels)) {
1760 foreach ($extralabels as $key => $value) {
1761 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))) {
1762 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1763 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1766 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1767 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1768 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1770 print $langs->trans($value);
1772 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product').
'</td></tr>';
1777 $sql .=
" fk_object";
1778 foreach ($extralabels as $key => $value) {
1781 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_extrafields";
1782 $sql .=
" WHERE fk_object = ".((int)
$object->id);
1783 $resql = $db->query($sql);
1785 $obj = $db->fetch_object($resql);
1786 foreach ($extralabels as $key => $value) {
1787 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))) {
1788 if (!empty($extrafields->attributes[
"product"][
'langfile'][$key])) {
1789 $langs->load($extrafields->attributes[
"product"][
'langfile'][$key]);
1792 print
'<tr><td'.($extrafields->attributes[
"product"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
1793 if (!empty($extrafields->attributes[
"product"][
'help'][$key])) {
1794 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product"][
'help'][$key]));
1796 print $langs->trans($value);
1798 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product');
1807 $parameters = array();
1808 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1815 print $form->buttonsSaveCancel();
1818 } elseif ($action ==
'edit_level_price' &&
$object->getRights()->creer) {
1819 print
'<!-- Edit price per level -->'.
"\n"; ?>
1822 var showHidePriceRules =
function () {
1823 var otherPrices = $(
'div.fiche form table tbody tr:not(:first)');
1824 var minPrice1 = $(
'div.fiche form input[name="price_min[1]"]');
1826 if (jQuery(
'input#usePriceRules').prop(
'checked')) {
1835 jQuery(document).ready(
function () {
1836 showHidePriceRules();
1838 jQuery(
'input#usePriceRules').click(showHidePriceRules);
1843 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
1844 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1845 print
'<input type="hidden" name="action" value="update_level_price">';
1846 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1851 print $langs->trans(
'UseMultipriceRules').
' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.(
$object->price_autogen ?
'checked' :
'').
'><br><br>';
1854 print
'<div class="div-table-responsive-no-min">';
1855 print
'<table class="noborder">';
1856 print
'<thead><tr class="liste_titre">';
1858 print
'<td>'.$langs->trans(
"PriceLevel").
'</td>';
1861 print
'<td style="text-align: center">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1866 print
'<td class="center">'.$langs->trans(
"SellingPrice").
'</td>';
1868 print
'<td class="center">'.$langs->trans(
"MinPrice").
'</td>';
1875 $extrafields->fetch_name_optionals_label(
"product_price");
1876 if ($extrafields->attributes[
"product_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_price"])) {
1877 $extralabels = $extrafields->attributes[
"product_price"][
'label'];
1878 if (!empty($extralabels)) {
1879 foreach ($extralabels as $key => $value) {
1881 if (!empty($extrafields->attributes[
"product_price"][
'list'][$key]) && $extrafields->attributes[
"product_price"][
'list'][$key] != 3) {
1882 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1883 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1885 if (!empty($extrafields->attributes[
"product_price"][
'help'][$key])) {
1886 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_price"][
'help'][$key]));
1888 $extratitle = $langs->trans($value);
1890 print
'<td style="text-align: right">'.$extratitle.
'</td>';
1895 print
'</tr></thead>';
1899 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
1900 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
1901 print
'<tr class="oddeven">';
1903 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1905 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
1911 print
'<input type="hidden" name="tva_tx['.$i.
']" value="'.(
$object->default_vat_code ?
$object->tva_tx.
' ('.
$object->default_vat_code.
')' :
$object->tva_tx).
'">';
1912 print
'<input type="hidden" name="tva_npr['.$i.
']" value="'.
$object->tva_npr.
'">';
1913 print
'<input type="hidden" name="localtax1_tx['.$i.
']" value="'.
$object->localtax1_tx.
'">';
1914 print
'<input type="hidden" name="localtax1_type['.$i.
']" value="'.
$object->localtax1_type.
'">';
1915 print
'<input type="hidden" name="localtax2_tx['.$i.
']" value="'.
$object->localtax2_tx.
'">';
1916 print
'<input type="hidden" name="localtax2_type['.$i.
']" value="'.
$object->localtax2_type.
'">';
1920 print
'<td style="text-align: center">';
1921 print $form->load_tva(
"tva_tx[".$i.
']',
$object->multiprices_tva_tx[$i], $mysoc,
'',
$object->id,
false,
$object->type,
false, 1);
1926 print
'<td style="text-align: center">';
1927 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1928 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices_ttc [$i]).
'">';
1930 print
'<input name="price['.$i.
']" size="10" value="'.
price(
$object->multiprices [$i]).
'">';
1932 print
' '.$form->selectPriceBaseType(
$object->multiprices_base_type [$i],
"multiprices_base_type[".$i.
"]");
1936 print
'<td style="text-align: center">';
1937 if (
$object->multiprices_base_type [$i] ==
'TTC') {
1938 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min_ttc [$i]).
'">';
1940 print
'<input name="price_min['.$i.
']" size="10" value="'.
price(
$object->multiprices_min [$i]).
'">';
1943 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1947 if (!empty($extralabels)) {
1948 $sql1 =
"SELECT rowid";
1949 $sql1 .=
" FROM ".$object->db->prefix().
"product_price";
1950 $sql1 .=
" WHERE entity IN (".getEntity(
'productprice').
")";
1951 $sql1 .=
" AND price_level=".((int) $i);
1952 $sql1 .=
" AND fk_product = ".((int)
$object->id);
1953 $sql1 .=
" ORDER BY date_price DESC, rowid DESC";
1954 $sql1 .=
" LIMIT 1";
1955 $resql1 =
$object->db->query($sql1);
1957 $lineid =
$object->db->fetch_object($resql1);
1959 if (empty($lineid->rowid)) {
1960 foreach ($extralabels as $key => $value) {
1961 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))) {
1962 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1963 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1966 $extravalue = GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key};
1967 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
1972 $sql .=
" fk_object";
1973 foreach ($extralabels as $key => $value) {
1976 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
1977 $sql .=
" WHERE fk_object = ".((int) $lineid->rowid);
1978 $resql = $db->query($sql);
1980 $obj = $db->fetch_object($resql);
1981 foreach ($extralabels as $key => $value) {
1982 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))) {
1983 if (!empty($extrafields->attributes[
"product_price"][
'langfile'][$key])) {
1984 $langs->load($extrafields->attributes[
"product_price"][
'langfile'][$key]);
1987 $extravalue = (GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key} ??
'');
1988 print
'<td align="center"><input name="'.$key.
'['.$i.
']" size="10" value="'.$extravalue.
'"></td>';
2005 print $form->buttonsSaveCancel();
2016 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
2017 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
2019 if (empty($page) || $page == -1) {
2022 $offset = $limit * $page;
2023 $pageprev = $page - 1;
2024 $pagenext = $page + 1;
2029 $sortfield =
"soc.nom";
2033 $filter = array(
't.fk_product' =>
$object->id);
2035 if (!empty($search_soc)) {
2036 $filter[
'soc.nom'] = $search_soc;
2039 if ($action ==
'add_customer_price') {
2041 $maxpricesupplier =
$object->min_recommended_price();
2043 print
'<!-- add_customer_price -->';
2046 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2047 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2048 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
2049 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2051 print
'<div class="tabBar tabBarWithBottom">';
2053 print
'<table class="border centpercent">';
2055 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2057 $filter =
'(s.client:IN:1,2,3)';
2058 print
img_picto(
'',
'company').$form->select_company(
'',
'socid', $filter,
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
2063 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2064 print
'<td><input name="ref_customer" size="12"></td></tr>';
2067 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2072 print
'<tr><td class="fieldrequired">';
2073 print $langs->trans(
'PriceBase');
2076 print $form->selectPriceBaseType(
$object->price_base_type,
"price_base_type");
2081 print
'<tr><td class="fieldrequired">';
2082 $text = $langs->trans(
'SellingPrice');
2083 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2085 if (
$object->price_base_type ==
'TTC') {
2086 print
'<input name="price" size="10" value="'.price(
$object->price_ttc).
'">';
2088 print
'<input name="price" size="10" value="'.price(
$object->price).
'">';
2094 $text = $langs->trans(
'MinPrice');
2095 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2096 if (
$object->price_base_type ==
'TTC') {
2097 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min_ttc).
'">';
2099 print
'<td><input name="price_min" size="10" value="'.price(
$object->price_min).
'">';
2102 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2108 print $langs->trans(
'PriceLabel');
2110 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$object->price_label.
'">';
2115 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2116 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2117 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2118 if (!empty($extralabels)) {
2119 if (empty($prodcustprice->id)) {
2120 foreach ($extralabels as $key => $value) {
2121 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))) {
2122 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2123 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2126 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2127 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2128 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2130 print $langs->trans($value);
2132 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2143 print
'<div class="center">';
2146 print
'<div class="marginbottomonly">';
2147 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2148 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2151 print $form->buttonsSaveCancel();
2154 } elseif ($action ==
'edit_customer_price') {
2156 $maxpricesupplier =
$object->min_recommended_price();
2158 print
'<!-- edit_customer_price -->';
2161 $result = $prodcustprice->fetch(
GETPOSTINT(
'lineid'));
2166 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2167 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2168 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
2169 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
2171 print
'<table class="liste centpercent">';
2173 print
'<td class="titlefield fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2174 $staticsoc =
new Societe($db);
2175 $staticsoc->fetch($prodcustprice->fk_soc);
2176 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2180 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2181 print
'<td><input name="ref_customer" size="12" value="' .
dol_escape_htmltag($prodcustprice->ref_customer) .
'"></td></tr>';
2184 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2185 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);
2189 print
'<tr><td class="fieldrequired">';
2190 print $langs->trans(
'PriceBase');
2193 print $form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
2198 print
'<tr><td class="fieldrequired">';
2199 $text = $langs->trans(
'SellingPrice');
2200 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2202 if ($prodcustprice->price_base_type ==
'TTC') {
2203 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
2205 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
2211 $text = $langs->trans(
'MinPrice');
2212 print $form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals",
getDolGlobalString(
'MAIN_MAX_DECIMALS_UNIT')), 1, 1);
2214 if ($prodcustprice->price_base_type ==
'TTC') {
2215 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
2217 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
2221 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2229 print $langs->trans(
'PriceLabel');
2231 print
'<input name="price_label" maxlength="255" class="minwidth300 maxwidth400onsmartphone" value="'.$prodcustprice->price_label.
'">';
2236 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2237 $extralabels = !empty($extrafields->attributes[
"product_customer_price"][
'label']) ? $extrafields->attributes[
"product_customer_price"][
'label'] :
'';
2238 $extrafield_values = $extrafields->getOptionalsFromPost(
"product_customer_price");
2239 if (!empty($extralabels)) {
2241 foreach ($extralabels as $key => $value) {
2242 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))) {
2243 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2244 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2247 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2248 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2249 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2251 print $langs->trans($value);
2253 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] :
'',
'',
'',
'',
'', 0,
'product_customer_price').
'</td></tr>';
2258 $sql .=
" fk_object";
2259 foreach ($extralabels as $key => $value) {
2262 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2263 $sql .=
" WHERE fk_object = ".((int) $prodcustprice->id);
2264 $resql = $db->query($sql);
2266 $obj = $db->fetch_object($resql);
2267 foreach ($extralabels as $key => $value) {
2268 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))) {
2269 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2270 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2273 print
'<tr><td'.($extrafields->attributes[
"product_customer_price"][
'required'][$key] ?
' class="fieldrequired"' :
'').
'>';
2274 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2275 print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2277 print $langs->trans($value);
2279 print
'</td><td>'.$extrafields->showInputField($key, GETPOSTISSET(
'options_'.$key) ? $extrafield_values[
'options_'.$key] : $obj->{$key},
'',
'',
'',
'', 0,
'product_customer_price');
2291 print
'<div class="center">';
2292 print
'<div class="marginbottomonly">';
2293 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2294 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2297 print $form->buttonsSaveCancel();
2299 print
'<br></form>';
2300 } elseif ($action ==
'showlog_customer_price') {
2302 print
'<!-- list of all log of prices per customer -->'.
"\n";
2304 $filter = array(
't.fk_product' =>
$object->id,
't.fk_soc' =>
GETPOSTINT(
'socid'));
2307 $nbtotalofrecords =
'';
2309 $nbtotalofrecords = $prodcustprice->fetchAllLog($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2312 $result = $prodcustprice->fetchAllLog($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2317 $option =
'&socid='.GETPOSTINT(
'socid').
'&id='.
$object->id;
2319 $staticsoc =
new Societe($db);
2322 $title = $langs->trans(
'PriceByCustomerLog');
2323 $title .=
' - '.$staticsoc->getNomUrl(1);
2325 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2328 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2330 if (count($prodcustprice->lines) > 0) {
2331 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2332 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2333 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2335 print
'<div class="div-table-responsive-no-min">';
2336 print
'<table class="liste centpercent">';
2338 print
'<tr class="liste_titre">';
2339 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2340 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2341 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2342 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2343 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2344 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2345 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2346 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2347 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2349 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2350 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2351 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2352 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
2353 print
'<td> </td>';
2356 foreach ($prodcustprice->lines as $line) {
2358 $staticsoc =
new Societe($db);
2359 $staticsoc->fetch($line->fk_soc);
2361 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2364 if ($line->price_base_type ==
'HT') {
2367 $pu = $line->price_ttc;
2371 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2373 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2375 $total_ht = $resultarray[0];
2376 $total_vat = $resultarray[1];
2377 $total_localtax1 = $resultarray[9];
2378 $total_localtax2 = $resultarray[10];
2379 $total_ttc = $resultarray[2];
2381 print
'<tr class="oddeven">';
2383 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2384 print
'<td>'.$line->ref_customer.
'</td>';
2385 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2386 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2387 print
'<td class="right">';
2389 $positiverates =
'';
2391 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2394 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2397 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2399 if (empty($positiverates)) {
2400 $positiverates =
'0';
2403 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2407 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2409 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2410 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2411 print
'<td class="right">'.price($resultarray[2]).
'</td>';
2414 print
'<td class="right">'.price($line->price_min).
'</td>';
2415 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2416 print
'<td class="right">'.$line->price_label.
'</td>';
2419 $userstatic =
new User($db);
2420 $userstatic->fetch($line->fk_user);
2421 print
'<td class="right">';
2422 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
2430 print $langs->trans(
'None');
2432 } elseif ($action !=
'showlog_default_price' && $action !=
'edit_price' && $action !=
'edit_level_price') {
2434 print
'<!-- list of all prices per customer -->'.
"\n";
2437 $nbtotalofrecords =
'';
2439 $nbtotalofrecords = $prodcustprice->fetchAll($sortorder, $sortfield, 0, 0, $filter);
2442 $result = $prodcustprice->fetchAll($sortorder, $sortfield,
$conf->liste_limit, $offset, $filter);
2447 $option =
'&search_soc='.$search_soc.
'&id='.
$object->id;
2450 print_barre_liste($langs->trans(
'PriceByCustomer'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2452 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'" method="POST">';
2453 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2454 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2456 print
'<!-- List of prices per customer -->'.
"\n";
2457 print
'<div class="div-table-responsive-no-min">'.
"\n";
2458 print
'<table class="liste centpercent">'.
"\n";
2460 if (count($prodcustprice->lines) > 0 || $search_soc) {
2466 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2469 if (!empty($price_extralabels) && is_array($price_extralabels)) {
2470 $colspan += count($price_extralabels);
2473 print
'<tr class="liste_titre">';
2474 print
'<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.
'"></td>';
2475 print
'<td class="liste_titre" colspan="'.$colspan.
'"> </td>';
2477 print
'<td class="liste_titre maxwidthsearch">';
2478 $searchpicto = $form->showFilterAndCheckAddButtons(0);
2484 print
'<tr class="liste_titre">';
2485 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2486 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2487 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2488 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2489 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2490 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2491 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2492 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2493 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2495 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2496 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2497 print
'<td class="right">'.$langs->trans(
"PriceLabel").
'</td>';
2499 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2500 if ($extrafields->attributes[
"product_customer_price"] && array_key_exists(
'label', $extrafields->attributes[
"product_customer_price"])) {
2501 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'];
2502 if (!empty($extralabels)) {
2503 foreach ($extralabels as $key => $value) {
2505 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2506 if (!empty($extrafields->attributes[
"product_customer_price"][
'langfile'][$key])) {
2507 $langs->load($extrafields->attributes[
"product_customer_price"][
'langfile'][$key]);
2509 if (!empty($extrafields->attributes[
"product_customer_price"][
'help'][$key])) {
2510 $extratitle = $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes[
"product_customer_price"][
'help'][$key]));
2512 $extratitle = $langs->trans($value);
2514 print
'<td style="text-align: right">'.$extratitle.
'</td>';
2519 print
'<td>'.$langs->trans(
"ChangedBy").
'</td>';
2524 if (
$object->price_base_type ==
'HT') {
2531 $localtaxarray =
getLocalTaxesFromRate(
$object->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2533 $resultarray =
calcul_price_total(1, $pu, 0,
$object->tva_tx, 1, 1, 0,
$object->price_base_type, 0,
$object->type, $mysoc, $localtaxarray);
2535 $total_ht = $resultarray[0];
2536 $total_vat = $resultarray[1];
2537 $total_localtax1 = $resultarray[9];
2538 $total_localtax2 = $resultarray[10];
2539 $total_ttc = $resultarray[2];
2542 print
'<!-- PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES -->'.
"\n";
2543 print
'<tr class="oddeven">';
2544 print
'<td colspan="3">' . $langs->trans(
'Default') .
'</td>';
2546 print
'<td class="center">'.$langs->trans(
$object->price_base_type).
"</td>";
2549 print
'<td class="right">';
2551 $positiverates =
'';
2556 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax1_tx);
2559 $positiverates .= ($positiverates ?
'/' :
'').
price2num(
$object->localtax2_tx);
2561 if (empty($positiverates)) {
2562 $positiverates =
'0';
2564 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), true,
$object->tva_npr);
2570 print
'<td class="right"><span class="amount">'.price(
$object->price).
"</span></td>";
2572 print
'<td class="right"><span class="amount">'.price(
$object->price_ttc).
"</span></td>";
2573 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2575 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2578 print
'<td class="right">'.price(
$object->price_min).
'</td>';
2579 print
'<td class="right">'.price(
$object->price_min_ttc).
'</td>';
2580 print
'<td class="right">'.$object->price_label.
'</td>';
2581 print
'<td class="right"></td>';
2582 if (!empty($extralabels)) {
2583 foreach ($extralabels as $key) {
2585 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2586 print
'<td class="right"></td>';
2590 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2591 print
'<td class="nowraponall">';
2592 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_default_price&token='.
newToken().
'&id='.
$object->id.
'">';
2593 print
img_info($langs->trans(
'PriceByCustomerLog'));
2596 print
'<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_price&token='.
newToken().
'&id='.
$object->id.
'">';
2597 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2604 if (count($prodcustprice->lines) > 0) {
2605 foreach ($prodcustprice->lines as $line) {
2607 $staticsoc =
new Societe($db);
2608 $staticsoc->fetch($line->fk_soc);
2610 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2613 if ($line->price_base_type ==
'HT') {
2616 $pu = $line->price_ttc;
2620 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2622 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2624 $total_ht = $resultarray[0];
2625 $total_vat = $resultarray[1];
2626 $total_localtax1 = $resultarray[9];
2627 $total_localtax2 = $resultarray[10];
2628 $total_ttc = $resultarray[2];
2630 print
'<tr class="oddeven">';
2632 print
'<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1).
"</td>";
2633 print
'<td>'.dol_escape_htmltag($line->ref_customer).
'</td>';
2634 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2635 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2637 print
'<td class="right">';
2639 $positiverates =
'';
2641 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2644 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2647 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2649 if (empty($positiverates)) {
2650 $positiverates =
'0';
2653 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), true, (!empty($line->tva_npr) ? $line->tva_npr : $line->recuperableonly));
2657 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2659 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2660 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2662 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2665 print
'<td class="right">'.price($line->price_min).
'</td>';
2666 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2667 print
'<td class="right">'.$line->price_label.
'</td>';
2670 $extrafields->fetch_name_optionals_label(
"product_customer_price");
2671 $extralabels = $extrafields->attributes[
"product_customer_price"][
'label'] ?? array();
2672 if (!empty($extralabels)) {
2674 $sql .=
" fk_object";
2675 foreach ($extralabels as $key => $value) {
2678 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_customer_price_extrafields";
2679 $sql .=
" WHERE fk_object = ".((int) $line->id);
2680 $resql = $db->query($sql);
2682 if ($db->num_rows($resql) != 1) {
2683 foreach ($extralabels as $key => $value) {
2684 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2689 $obj = $db->fetch_object($resql);
2690 foreach ($extralabels as $key => $value) {
2691 if (!empty($extrafields->attributes[
"product_customer_price"][
'list'][$key]) && $extrafields->attributes[
"product_customer_price"][
'list'][$key] != 3) {
2692 print
'<td align="right">'.$extrafields->showOutputField($key, $obj->{$key},
'',
'product_customer_price').
"</td>";
2701 $userstatic =
new User($db);
2702 $userstatic->fetch($line->fk_user);
2705 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2710 if ($user->hasRight(
'produit',
'supprimer') || $user->hasRight(
'service',
'supprimer')) {
2711 print
'<td class="right nowraponall">';
2712 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&id='.
$object->id.
'&socid='.$line->fk_soc.
'">';
2713 print
img_info($langs->trans(
'PriceByCustomerLog'));
2716 print
'<a class="marginleftonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2717 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2720 print
'<a class="marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&id='.
$object->id.
'&lineid='.$line->id.
'">';
2721 print
img_delete(
'default',
'style="vertical-align: middle;"');
2739if ((!
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES') || $action ==
'showlog_default_price') && !in_array($action, array(
'edit_price',
'edit_level_price',
'edit_vat'))) {
2740 $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,";
2741 $sql .=
" p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
2742 $sql .=
" p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
2743 $sql .=
" ,p.price_label";
2744 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price as p,";
2745 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
2746 $sql .=
" WHERE fk_product = ".((int)
$object->id);
2747 $sql .=
" AND p.entity IN (".getEntity(
'productprice').
")";
2748 $sql .=
" AND p.fk_user_author = u.rowid";
2750 $sql .=
" AND p.price_level = ".((int) $soc->price_level);
2752 $sql .=
" ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
2756 $result = $db->query($sql);
2758 print
'<div class="divlogofpreviouscustomerprice">';
2760 $num = $db->num_rows($result);
2769 $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);
2777 $result = $db->query($sql);
2778 $num = $db->num_rows($result);
2785 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2789 print_barre_liste($langs->trans(
"DefaultPriceLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'', $backbutton, 0, $num,
'title_accountancy.png');
2792 print_barre_liste($langs->trans(
"PriceByCustomerLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', 0, $num,
'title_accountancy.png');
2795 print
'<!-- List of log prices -->'.
"\n";
2796 print
'<div class="div-table-responsive">'.
"\n";
2797 print
'<table class="liste centpercent noborder">'.
"\n";
2799 print
'<tr class="liste_titre">';
2800 print
'<th>'.$langs->trans(
"AppliedPricesFrom").
'</tg>';
2803 print
'<th class="center">'.$langs->trans(
"PriceLevel").
'</th>';
2806 print
'<th class="center">'.$langs->trans(
"Type").
'</th>';
2809 print
'<th class="center">'.$langs->trans(
"PriceBase").
'</th>';
2811 print
'<th class="right">'.$langs->trans(
"DefaultTaxRate").
'</th>';
2813 print
'<th class="right">'.$langs->trans(
"HT").
'</th>';
2814 print
'<th class="right">'.$langs->trans(
"TTC").
'</th>';
2815 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2816 print
'<th class="right">'.$langs->trans(
"INCT").
'</th>';
2818 if (isModEnabled(
'dynamicprices')) {
2819 print
'<th class="right">'.$langs->trans(
"PriceExpressionSelected").
'</th>';
2821 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</th>';
2822 print
'<th class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</th>';
2823 print
'<th class="right">'.$langs->trans(
"Label").
'</th>';
2824 print
'<th>'.$langs->trans(
"ChangedBy").
'</th>';
2825 if ($user->hasRight(
'produit',
'supprimer')) {
2826 print
'<th class="right"> </th>';
2830 $notfirstlineforlevel = array();
2834 $objp = $db->fetch_object($result);
2836 print
'<tr class="oddeven">';
2838 print
"<td>".dol_print_date($db->jdate($objp->dp),
"dayhour",
'tzuserrel').
"</td>";
2842 print
'<td class="center">'.$objp->price_level.
"</td>";
2846 $type = ($objp->price_by_qty == 1) ?
'PriceByQuantity' :
'Standard';
2847 print
'<td class="center">'.$langs->trans($type).
"</td>";
2850 print
'<td class="center">';
2851 if (empty($objp->price_by_qty)) {
2852 print $langs->trans($objp->price_base_type);
2857 print
'<td class="right">';
2859 if (empty($objp->price_by_qty)) {
2860 $positiverates =
'';
2862 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->tva_tx);
2865 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax1_tx);
2868 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax2_tx);
2870 if (empty($positiverates)) {
2871 $positiverates =
'0';
2873 echo
vatrate($positiverates.($objp->default_vat_code ?
' ('.$objp->default_vat_code.
')' :
''), true, !empty($objp->tva_npr) ? $objp->tva_npr : 0);
2886 if ($objp->price_base_type ==
'HT') {
2889 $pu = $objp->price_ttc;
2893 $localtaxarray =
getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2895 $resultarray =
calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly,
$object->type, $mysoc, $localtaxarray);
2897 $total_ht = $resultarray[0];
2898 $total_vat = $resultarray[1];
2899 $total_localtax1 = $resultarray[9];
2900 $total_localtax2 = $resultarray[10];
2901 $total_ttc = $resultarray[2];
2904 if (!empty($objp->fk_price_expression) && !empty(
$conf->dynamicprices->enabled)) {
2906 $res = $price_expression->fetch($objp->fk_price_expression);
2907 $title = $price_expression->title;
2908 print
'<td class="right"></td>';
2909 print
'<td class="right"></td>';
2910 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2911 print
'<td class="right"></td>';
2913 print
'<td class="right">'.$title.
"</td>";
2916 print
'<td class="right">';
2917 if (empty($objp->price_by_qty)) {
2918 print
'<span class="amount">'.price($objp->price).
'</span>';
2922 print
'<td class="right">';
2923 if (empty($objp->price_by_qty)) {
2924 $price_ttc = $objp->price_ttc;
2925 print
'<span class="amount">'.price($price_ttc).
'<span>';
2928 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2929 print
'<td class="right">';
2930 print $resultarray[2];
2933 if (isModEnabled(
'dynamicprices')) {
2934 print
'<td class="right"></td>';
2939 print
'<td class="right">';
2940 if (empty($objp->price_by_qty)) {
2941 print
price($objp->price_min);
2946 print
'<td class="right">';
2947 if (empty($objp->price_by_qty)) {
2948 $price_min_ttc = $objp->price_min_ttc;
2949 print
price($price_min_ttc);
2954 print
'<td class="right">';
2955 print $objp->price_label;
2960 if ($objp->user_id > 0) {
2961 $userstatic =
new User($db);
2962 $userstatic->fetch($objp->user_id);
2963 print $userstatic->getNomUrl(-1,
'', 0, 0, 24, 0,
'login');
2969 if ($user->hasRight(
'produit',
'supprimer')) {
2972 if (empty($notfirstlineforlevel[$objp->price_level])) {
2973 $notfirstlineforlevel[$objp->price_level] = 1;
2981 print
'<td class="right">';
2982 if ($candelete || ($db->jdate($objp->dp) >=
dol_now())) {
2983 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
product_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.