37 require
'../main.inc.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_expression.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
44 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
45 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
51 $langs->loadLangs(array(
'products',
'bills',
'companies',
'other'));
58 $action =
GETPOST(
'action',
'aZ09');
59 $cancel =
GETPOST(
'cancel',
'alpha');
62 $search_soc =
GETPOST(
'search_soc');
65 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
66 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
68 $socid = $user->socid;
71 if ($id > 0 || !empty($ref)) {
73 $object->fetch($id, $ref);
77 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) {
78 $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
82 $hookmanager->initHooks(array(
'productpricecard',
'globalcard'));
84 if ($object->id > 0) {
85 if ($object->type == $object::TYPE_PRODUCT) {
86 restrictedArea($user,
'produit', $object->id,
'product&product',
'',
'');
88 if ($object->type == $object::TYPE_SERVICE) {
89 restrictedArea($user,
'service', $object->id,
'product&product',
'',
'');
92 restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
104 $parameters = array(
'id'=>$id,
'ref'=>$ref);
105 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
110 if (empty($reshook)) {
111 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
115 if ($action ==
'setlabelsellingprice' && $user->admin) {
116 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
117 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.GETPOST(
'pricelevel');
122 if (($action ==
'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
123 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
126 $tva_tx = $tva_tx_txt;
129 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
130 $vatratecode = $reg[1];
131 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
134 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
135 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
136 $localtax1 = 0; $localtax2 = 0; $localtax1_type =
'0'; $localtax2_type =
'0';
138 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
140 $vatratecode = $reg[1];
142 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
143 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
144 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
145 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
146 $sql .=
" AND t.code = '".$db->escape($vatratecode).
"'";
147 $resql = $db->query($sql);
149 $obj = $db->fetch_object(
$resql);
151 $npr = $obj->recuperableonly;
152 $localtax1 = $obj->localtax1;
153 $localtax2 = $obj->localtax2;
154 $localtax1_type = $obj->localtax1_type;
155 $localtax2_type = $obj->localtax2_type;
160 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
162 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
163 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
164 $sql .=
" AND t.code = ''";
165 $resql = $db->query($sql);
167 $obj = $db->fetch_object(
$resql);
169 $npr = $obj->recuperableonly;
170 $localtax1 = $obj->localtax1;
171 $localtax2 = $obj->localtax2;
172 $localtax1_type = $obj->localtax1_type;
173 $localtax2_type = $obj->localtax2_type;
178 $object->default_vat_code = $vatratecode;
179 $object->tva_tx = $tva_tx;
180 $object->tva_npr = $npr;
181 $object->localtax1_tx = $localtax1;
182 $object->localtax2_tx = $localtax2;
183 $object->localtax1_type = $localtax1_type;
184 $object->localtax2_type = $localtax2_type;
188 $resql = $object->update($object->id, $user);
195 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
196 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
198 if ($object->multiprices_base_type[$i] ==
'HT') {
199 $oldprice = $object->multiprices[$i];
200 $oldminprice = $object->multiprices_min[$i];
202 $oldprice = $object->multiprices_ttc[$i];
203 $oldminprice = $object->multiprices_min_ttc[$i];
205 $oldpricebasetype = $object->multiprices_base_type[$i];
206 $oldnpr = $object->multiprices_recuperableonly[$i];
209 $localtaxarray = array();
211 $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
220 if ($object->price_base_type ==
'HT') {
221 $oldprice = $object->price;
222 $oldminprice = $object->price_min;
224 $oldprice = $object->price_ttc;
225 $oldminprice = $object->price_min_ttc;
227 $oldpricebasetype = $object->price_base_type;
228 $oldnpr = $object->tva_npr;
231 $localtaxarray = array();
233 $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
251 if (($action ==
'update_price') && !$cancel && $object->getRights()->creer) {
253 $pricestoupdate = array();
256 $psq = empty($newpsq) ? 0 : $newpsq;
257 $maxpricesupplier = $object->min_recommended_price();
259 if (!empty($conf->dynamicprices->enabled)) {
260 $object->fk_price_expression = empty($eid) ? 0 : $eid;
262 if ($object->fk_price_expression != 0) {
266 if ($priceparser->parseProduct($object) < 0) {
274 if (!$error && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
275 $newprice =
GETPOST(
'price',
'array');
276 $newprice_min =
GETPOST(
'price_min',
'array');
277 $newpricebase =
GETPOST(
'multiprices_base_type',
'array');
278 $newvattx =
GETPOST(
'tva_tx',
'array');
279 $newvatnpr =
GETPOST(
'tva_npr',
'array');
280 $newlocaltax1_tx =
GETPOST(
'localtax1_tx',
'array');
281 $newlocaltax1_type =
GETPOST(
'localtax1_type',
'array');
282 $newlocaltax2_tx =
GETPOST(
'localtax2_tx',
'array');
283 $newlocaltax2_type =
GETPOST(
'localtax2_type',
'array');
286 $object->price_autogen =
GETPOST(
'usePriceRules') ==
'on';
288 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
289 if (!isset($newprice[$i])) {
293 $tva_tx_txt = $newvattx[$i];
295 $tva_tx = $tva_tx_txt;
298 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
299 $vat_src_code = $reg[1];
300 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
302 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
304 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
305 $localtax1 = $newlocaltax1_tx[$i];
306 $localtax1_type = $newlocaltax1_type[$i];
307 $localtax2 = $newlocaltax2_tx[$i];
308 $localtax2_type = $newlocaltax2_type[$i];
309 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
311 $vatratecode = $reg[1];
313 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
315 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
316 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
317 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
318 $resql = $db->query($sql);
320 $obj = $db->fetch_object(
$resql);
322 $npr = $obj->recuperableonly;
323 $localtax1 = $obj->localtax1;
324 $localtax2 = $obj->localtax2;
325 $localtax1_type = $obj->localtax1_type;
326 $localtax2_type = $obj->localtax2_type;
330 if (in_array($mysoc->country_code, array(
'ES'))) {
337 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
338 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
339 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
340 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
341 $sql .=
" AND t.code = ''";
342 $resql = $db->query($sql);
344 $obj = $db->fetch_object(
$resql);
346 $npr = $obj->recuperableonly;
347 $localtax1 = $obj->localtax1;
348 $localtax2 = $obj->localtax2;
349 $localtax1_type = $obj->localtax1_type;
350 $localtax2_type = $obj->localtax2_type;
355 $pricestoupdate[$i] = array(
356 'price' =>
price2num($newprice[$i],
'', 2),
357 'price_min' =>
price2num($newprice_min[$i],
'', 2),
358 'price_base_type' => $newpricebase[$i],
359 'default_vat_code' => $vatratecode,
362 'localtaxes_array' => array(
'0'=>$localtax1_type,
'1'=>$localtax1,
'2'=>$localtax2_type,
'3'=>$localtax2)
366 if ($object->price_autogen) {
373 $newpricebase =
GETPOST(
'price_base_type',
'alpha');
374 $tva_tx_txt =
GETPOST(
'tva_tx',
'alpha');
376 $tva_tx = $tva_tx_txt;
379 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
380 $vat_src_code = $reg[1];
381 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
383 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
385 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
386 $localtax1 = 0; $localtax2 = 0; $localtax1_type =
'0'; $localtax2_type =
'0';
388 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
390 $vatratecode = $reg[1];
392 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
393 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
394 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
395 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
396 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
397 $resql = $db->query($sql);
399 $obj = $db->fetch_object(
$resql);
401 $npr = $obj->recuperableonly;
402 $localtax1 = $obj->localtax1;
403 $localtax2 = $obj->localtax2;
404 $localtax1_type = $obj->localtax1_type;
405 $localtax2_type = $obj->localtax2_type;
409 if (in_array($mysoc->country_code, array(
'ES'))) {
416 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
417 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
418 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
419 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
420 $sql .=
" AND t.code = ''";
421 $resql = $db->query($sql);
423 $obj = $db->fetch_object(
$resql);
425 $npr = $obj->recuperableonly;
426 $localtax1 = $obj->localtax1;
427 $localtax2 = $obj->localtax2;
428 $localtax1_type = $obj->localtax1_type;
429 $localtax2_type = $obj->localtax2_type;
434 $pricestoupdate[0] = array(
435 'price' => $newprice,
436 'price_min' => $newprice_min,
437 'price_base_type' => $newpricebase,
438 'default_vat_code' => $vatratecode,
441 'localtaxes_array' => array(
'0'=>$localtax1_type,
'1'=>$localtax1,
'2'=>$localtax2_type,
'3'=>$localtax2)
448 foreach ($pricestoupdate as $key => $val) {
449 $newprice = $val[
'price'];
451 if ($val[
'price'] < $val[
'price_min'] && !empty($object->fk_price_expression)) {
452 $newprice = $val[
'price_min'];
456 $newprice_min =
price2num($val[
'price_min'],
'MU');
459 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $newprice_min < $maxpricesupplier) {
460 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, - 1, - 1,
'auto')),
null,
'errors');
465 if ($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) {
466 $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']);
479 if (!$error && $object->update($object->id, $user) < 0) {
489 $action =
'edit_price';
495 if ($action ==
'delete' && $user->rights->produit->supprimer) {
496 $result = $object->log_price_delete($user,
GETPOST(
'lineid',
'int'));
503 if ($action ==
'activate_price_by_qty') {
505 $level =
GETPOST(
'level',
'int');
506 $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
513 if ($action ==
'disable_price_by_qty') {
515 $level =
GETPOST(
'level',
'int');
516 $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0);
523 if ($action ==
'edit_price_by_qty') {
524 $rowid =
GETPOST(
'rowid',
'int');
528 if ($action ==
'update_price_by_qty') {
530 $rowid =
GETPOST(
'rowid',
'int');
531 $priceid =
GETPOST(
'priceid',
'int');
538 if (empty($quantity)) {
540 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Qty")),
null,
'errors');
542 if (empty($newprice)) {
544 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Price")),
null,
'errors');
548 if ($object->price_base_type ==
'TTC') {
549 $price =
price2num($newprice) / (1 + ($object->tva_tx / 100));
553 $unitPrice =
price2num($price / $quantity,
'MU');
557 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product_price_by_qty SET";
558 $sql .=
" price=".((float) $price).
"',";
559 $sql .=
" unitprice=".((float) $unitPrice).
",";
560 $sql .=
" quantity=".((float) $quantity).
",";
561 $sql .=
" remise_percent=".((float) $remise_percent).
",";
562 $sql .=
" remise=".((float) $remise);
563 $sql .=
" WHERE rowid = ".((int) $rowid);
565 $result = $db->query($sql);
570 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
571 $sql .= ((int) $priceid).
','.((
float) $price).
','.((
float) $unitPrice).
','.((
float) $quantity).
','.((
float) $remise_percent).
','.((
float) $remise).
')';
573 $result = $db->query($sql);
575 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
585 if ($action ==
'delete_price_by_qty') {
586 $rowid =
GETPOST(
'rowid',
'int');
587 if (!empty($rowid)) {
588 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
589 $sql .=
" WHERE rowid = ".((int) $rowid);
591 $result = $db->query($sql);
593 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
597 if ($action ==
'delete_all_price_by_qty') {
598 $priceid =
GETPOST(
'priceid',
'int');
599 if (!empty($rowid)) {
600 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_price_by_qty";
601 $sql .=
" WHERE fk_product_price = ".((int) $priceid);
603 $result = $db->query($sql);
605 setEventMessages((
'delete_price_by_qty'.$langs->transnoentities(
'MissingIds')),
null,
'errors');
614 if ($action ==
'add_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
615 $maxpricesupplier = $object->min_recommended_price();
617 $update_child_soc =
GETPOST(
'updatechildprice',
'int');
620 $prodcustprice->fk_soc =
GETPOST(
'socid',
'int');
621 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
622 $prodcustprice->fk_product = $object->id;
625 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
627 $tva_tx_txt =
GETPOST(
"tva_tx",
'alpha');
629 $tva_tx = $tva_tx_txt;
631 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
632 $vat_src_code = $reg[1];
633 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
635 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
637 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
638 $localtax1 = 0; $localtax2 = 0; $localtax1_type =
'0'; $localtax2_type =
'0';
640 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
642 $vatratecode = $reg[1];
644 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
645 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
646 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
647 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
648 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
649 $resql = $db->query($sql);
651 $obj = $db->fetch_object(
$resql);
653 $npr = $obj->recuperableonly;
654 $localtax1 = $obj->localtax1;
655 $localtax2 = $obj->localtax2;
656 $localtax1_type = $obj->localtax1_type;
657 $localtax2_type = $obj->localtax2_type;
661 if (in_array($mysoc->country_code, array(
'ES'))) {
668 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
669 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
670 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
671 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
672 $sql .=
" AND t.code = ''";
673 $resql = $db->query($sql);
675 $obj = $db->fetch_object(
$resql);
677 $npr = $obj->recuperableonly;
678 $localtax1 = $obj->localtax1;
679 $localtax2 = $obj->localtax2;
680 $localtax1_type = $obj->localtax1_type;
681 $localtax2_type = $obj->localtax2_type;
686 $prodcustprice->default_vat_code = $vatratecode;
687 $prodcustprice->tva_tx = $tva_tx;
688 $prodcustprice->recuperableonly = $npr;
689 $prodcustprice->localtax1_tx = $localtax1;
690 $prodcustprice->localtax2_tx = $localtax2;
691 $prodcustprice->localtax1_type = $localtax1_type;
692 $prodcustprice->localtax2_type = $localtax2_type;
694 if (!($prodcustprice->fk_soc > 0)) {
695 $langs->load(
"errors");
696 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
698 $action =
'add_customer_price';
700 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $prodcustprice->price_min < $maxpricesupplier) {
701 $langs->load(
"errors");
702 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
704 $action =
'add_customer_price';
708 $result = $prodcustprice->create($user, 0, $update_child_soc);
720 if ($action ==
'delete_customer_price' && ($user->rights->produit->supprimer || $user->rights->service->supprimer)) {
722 $prodcustprice->id =
GETPOST(
'lineid',
'int');
723 $result = $prodcustprice->delete($user);
733 if ($action ==
'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
734 $maxpricesupplier = $object->min_recommended_price();
736 $update_child_soc =
GETPOST(
'updatechildprice',
'int');
738 $prodcustprice->fetch(
GETPOST(
'lineid',
'int'));
741 $prodcustprice->ref_customer =
GETPOST(
'ref_customer',
'alpha');
744 $prodcustprice->price_base_type =
GETPOST(
"price_base_type",
'alpha');
746 $tva_tx_txt =
GETPOST(
"tva_tx");
748 $tva_tx = $tva_tx_txt;
750 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
751 $vat_src_code = $reg[1];
752 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx_txt);
754 $tva_tx =
price2num(preg_replace(
'/\*/',
'', $tva_tx));
756 $npr = preg_match(
'/\*/', $tva_tx_txt) ? 1 : 0;
757 $localtax1 = 0; $localtax2 = 0; $localtax1_type =
'0'; $localtax2_type =
'0';
759 if (preg_match(
'/\((.*)\)/', $tva_tx_txt, $reg)) {
761 $vatratecode = $reg[1];
763 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
764 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
765 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
766 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
767 $sql .=
" AND t.code ='".$db->escape($vatratecode).
"'";
768 $resql = $db->query($sql);
770 $obj = $db->fetch_object(
$resql);
772 $npr = $obj->recuperableonly;
773 $localtax1 = $obj->localtax1;
774 $localtax2 = $obj->localtax2;
775 $localtax1_type = $obj->localtax1_type;
776 $localtax2_type = $obj->localtax2_type;
780 if (in_array($mysoc->country_code, array(
'ES'))) {
787 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
788 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
789 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code).
"'";
790 $sql .=
" AND t.taux = ".((float) $tva_tx).
" AND t.active = 1";
791 $sql .=
" AND t.code = ''";
792 $resql = $db->query($sql);
794 $obj = $db->fetch_object(
$resql);
796 $npr = $obj->recuperableonly;
797 $localtax1 = $obj->localtax1;
798 $localtax2 = $obj->localtax2;
799 $localtax1_type = $obj->localtax1_type;
800 $localtax2_type = $obj->localtax2_type;
805 $prodcustprice->default_vat_code = $vatratecode;
806 $prodcustprice->tva_tx = $tva_tx;
807 $prodcustprice->recuperableonly = $npr;
808 $prodcustprice->localtax1_tx = $localtax1;
809 $prodcustprice->localtax2_tx = $localtax2;
810 $prodcustprice->localtax1_type = $localtax1_type;
811 $prodcustprice->localtax2_type = $localtax2_type;
813 if ($prodcustprice->price_min < $maxpricesupplier && !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
814 setEventMessages($langs->trans(
"MinimumPriceLimit",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')),
null,
'errors');
816 $action =
'update_customer_price';
820 $result = $prodcustprice->update($user, 0, $update_child_soc);
840 if (!empty($id) || !empty($ref)) {
842 $object->fetch($id, $ref);
845 $title = $langs->trans(
'ProductServiceCard');
847 $shortlabel =
dol_trunc($object->label, 16);
849 $title = $langs->trans(
'Product').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
850 $helpurl =
'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos';
853 $title = $langs->trans(
'Service').
" ".$shortlabel.
" - ".$langs->trans(
'SellingPrices');
854 $helpurl =
'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios';
857 llxHeader(
'', $title, $helpurl,
'', 0, 0,
'',
'',
'',
'classforhorizontalscrolloftabs');
860 $titre = $langs->trans(
"CardProduct".$object->type);
865 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
866 $object->next_prev_filter =
" fk_product_type = ".$object->type;
869 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
876 print
'<div class="fichecenter">';
878 print
'<div class="underbanner clearboth"></div>';
879 print
'<table class="border tableforfield" width="100%">';
882 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
884 if (!empty($socid)) {
890 if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
891 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
892 print
'<tr><td class="">';
893 print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ?
$form->editfieldkey(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
895 print
$form->editfieldval(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat);
900 print
'<tr><td class="titlefieldcreate">';
901 print $langs->trans(
"SellingPrice");
903 print
'<td colspan="2">';
904 if ($object->multiprices_base_type[$soc->price_level] ==
'TTC') {
905 print
'<span class="amount">'.price($object->multiprices_ttc[$soc->price_level]).
'</span>';
907 print
'<span class="amount">'.price($object->multiprices[$soc->price_level]).
'</span>';
909 if ($object->multiprices_base_type[$soc->price_level]) {
910 print
' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
912 print
' '.$langs->trans($object->price_base_type);
917 print
'<tr><td>'.$langs->trans(
"MinPrice").
'</td><td colspan="2">';
918 if ($object->multiprices_base_type[$soc->price_level] ==
'TTC') {
919 print
price($object->multiprices_min_ttc[$soc->price_level]).
' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
921 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]);
925 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
927 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td colspan="2">';
930 if (
price2num($object->multiprices_tva_tx[$soc->price_level])) {
931 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->multiprices_tva_tx[$soc->price_level]);
933 if (
price2num($object->multiprices_localtax1_type[$soc->price_level])) {
934 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->multiprices_localtax1_tx[$soc->price_level]);
936 if (
price2num($object->multiprices_localtax2_type[$soc->price_level])) {
937 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->multiprices_localtax2_tx[$soc->price_level]);
939 if (empty($positiverates)) {
940 $positiverates =
'0';
942 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''),
'%', $object->tva_npr);
947 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
951 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->tva_tx);
953 if (
price2num($object->localtax1_type)) {
954 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax1_tx);
956 if (
price2num($object->localtax2_type)) {
957 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax2_tx);
959 if (empty($positiverates)) {
960 $positiverates =
'0';
962 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''),
'%', $object->tva_npr);
972 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
974 if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
975 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
976 print
'<tr><td class="">';
977 print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ?
$form->editfieldkey(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
979 print
$form->editfieldval(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat);
984 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td>';
985 print
'<td colspan="2">'.vatrate($object->multiprices_tva_tx[1],
true).
'</td>';
989 if (!empty($conf->product->enabled) && !empty($conf->service->enabled)) {
990 $typeformat =
'select;0:'.$langs->trans(
"Product").
',1:'.$langs->trans(
"Service");
991 print
'<tr><td class="">';
992 print (empty($conf->global->PRODUCT_DENY_CHANGE_PRODUCT_TYPE)) ?
$form->editfieldkey(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans(
'Type');
994 print
$form->editfieldval(
"Type",
'fk_product_type', $object->type, $object, 0, $typeformat);
999 print
'<!-- Default VAT Rate -->';
1000 print
'<tr><td class="titlefieldcreate">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1002 $positiverates =
'';
1004 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num($object->tva_tx);
1006 if (
price2num($object->localtax1_type)) {
1007 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num($object->localtax1_tx);
1009 if (
price2num($object->localtax2_type)) {
1010 $positiverates .= ($positiverates ?
'<span class="opacitymedium">/</span>' :
'').
price2num($object->localtax2_tx);
1012 if (empty($positiverates)) {
1013 $positiverates =
'0';
1015 print
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''),
true, $object->tva_npr, 1);
1028 print
'<table class="noborder tableforfield" width="100%">';
1029 print
'<tr class="liste_titre"><td>';
1030 print $langs->trans(
"PriceLevel");
1032 print
' <a class="editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=editlabelsellingprice&token='.
newToken().
'&pricelevel='.$i.
'&id='.$object->id.
'">'.
img_edit($langs->trans(
'EditSellingPriceLabel'), 0).
'</a>';
1035 print
'<td style="text-align: right">'.$langs->trans(
"SellingPrice").
'</td>';
1036 print
'<td style="text-align: right">'.$langs->trans(
"MinPrice").
'</td>';
1039 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
1040 print
'<tr class="oddeven">';
1044 $keyforlabel =
'PRODUIT_MULTIPRICES_LABEL'.$i;
1045 if (preg_match(
'/editlabelsellingprice/', $action)) {
1046 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'">';
1047 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1048 print
'<input type="hidden" name="action" value="setlabelsellingprice">';
1049 print
'<input type="hidden" name="pricelevel" value="'.$i.
'">';
1050 print $langs->trans(
"SellingPrice").
' '.$i.
' - ';
1051 print
'<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="'.$conf->global->$keyforlabel.
'">';
1052 print
' <input type="submit" class="button smallpaddingimp" value="'.$langs->trans(
"Modify").
'">';
1055 print $langs->trans(
"SellingPrice").
' '.$i;
1056 if (!empty($conf->global->$keyforlabel)) {
1057 print
' - '.$langs->trans($conf->global->$keyforlabel);
1062 if ($object->multiprices_base_type [$i] ==
'TTC') {
1063 print
'<td class="right"><span class="amount">'.price($object->multiprices_ttc[$i]);
1065 print
'<td class="right"><span class="amount">'.price($object->multiprices[$i]);
1068 if ($object->multiprices_base_type[$i]) {
1069 print
' '.$langs->trans($object->multiprices_base_type [$i]).
'</span></td>';
1071 print
' '.$langs->trans($object->price_base_type).
'</span></td>';
1075 print
'<td style="text-align: right">';
1076 if (empty($object->multiprices_base_type[$i])) {
1077 $object->multiprices_base_type[$i] =
"HT";
1079 if ($object->multiprices_base_type[$i] ==
'TTC') {
1080 print
price($object->multiprices_min_ttc[$i]).
' '.$langs->trans($object->multiprices_base_type[$i]);
1082 print
price($object->multiprices_min[$i]).
' '.$langs->trans($object->multiprices_base_type[$i]);
1087 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1088 print
'<tr><td>'.$langs->trans(
"PriceByQuantity").
' '.$i;
1089 if (!empty($conf->global->$keyforlabel)) {
1090 print
' - '.$langs->trans($conf->global->$keyforlabel);
1092 print
'</td><td colspan="2">';
1094 if ($object->prices_by_qty[$i] == 1) {
1095 print
'<table width="50%" class="border" summary="List of quantities">';
1097 print
'<tr class="liste_titre">';
1098 print
'<td>'.$langs->trans(
"PriceByQuantityRange").
' '.$i.
'</td>';
1099 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
1100 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1101 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1102 print
'<td> </td>';
1104 foreach ($object->prices_by_qty_list[$i] as $ii => $prices) {
1105 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
1106 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1107 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1108 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1109 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1110 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1111 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1112 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1113 print
'<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"> '.$object->price_base_type.
'</td>';
1114 print
'<td class="right nowraponall"><input size="5" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1115 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1119 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1120 print
'<td>'.$prices[
'quantity'].
'</td>';
1121 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1122 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1123 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1124 print
'<td class="center">';
1125 if (($user->rights->produit->creer || $user->rights->service->creer)) {
1126 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1128 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1137 if ($action !=
'edit_price_by_qty' && ($user->rights->produit->creer || $user->rights->service->creer)) {
1138 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1139 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1140 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1141 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].
'">';
1142 print
'<input type="hidden" value="0" name="rowid">';
1143 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1144 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1145 print
'<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.
'</td>';
1146 print
'<td class="right"> </td>';
1147 print
'<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
1148 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1154 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>';
1156 print $langs->trans(
"No");
1157 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>';
1165 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1167 $positiverates =
'';
1169 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->tva_tx);
1171 if (
price2num($object->localtax1_type)) {
1172 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax1_tx);
1174 if (
price2num($object->localtax2_type)) {
1175 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax2_tx);
1177 if (empty($positiverates)) {
1178 $positiverates =
'0';
1180 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''),
'%', $object->tva_npr, 0, 1);
1190 print
'<tr><td>'.$langs->trans(
"SellingPrice").
'</td><td>';
1191 if ($object->price_base_type ==
'TTC') {
1192 print
price($object->price_ttc).
' '.$langs->trans($object->price_base_type);
1194 print
price($object->price).
' '.$langs->trans($object->price_base_type);
1199 print
'<tr><td>'.$langs->trans(
"MinPrice").
'</td><td>';
1200 if ($object->price_base_type ==
'TTC') {
1201 print
price($object->price_min_ttc).
' '.$langs->trans($object->price_base_type);
1203 print
price($object->price_min).
' '.$langs->trans($object->price_base_type);
1208 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1209 print
'<tr><td>'.$langs->trans(
"PriceByQuantity");
1210 if ($object->prices_by_qty[0] == 0) {
1211 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=activate_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"Activate").
')';
1213 print
' <a href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=disable_price_by_qty&level=1&token='.
newToken().
'">('.$langs->trans(
"DisablePriceByQty").
')';
1217 if ($object->prices_by_qty[0] == 1) {
1218 print
'<table width="50%" class="border" summary="List of quantities">';
1219 print
'<tr class="liste_titre">';
1221 print
'<td>'.$langs->trans(
"Quantity").
'</td>';
1222 print
'<td class="right">'.$langs->trans(
"Price").
'</td>';
1223 print
'<td class="right"></td>';
1224 print
'<td class="right">'.$langs->trans(
"UnitPrice").
'</td>';
1225 print
'<td class="right">'.$langs->trans(
"Discount").
'</td>';
1226 print
'<td> </td>';
1228 if ($action !=
'edit_price_by_qty') {
1229 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1230 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1231 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1232 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1233 print
'<input type="hidden" value="0" name="rowid">';
1235 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1236 print
'<td><input size="5" type="text" value="1" name="quantity"></td>';
1237 print
'<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
1241 print
'<td class="right"> </td>';
1242 print
'<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
1243 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Add").
'" class="button"></td>';
1248 foreach ($object->prices_by_qty_list[0] as $ii => $prices) {
1249 if ($action ==
'edit_price_by_qty' && $rowid == $prices[
'rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
1250 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1251 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1252 print
'<input type="hidden" name="action" value="update_price_by_qty">';
1253 print
'<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].
'">';
1254 print
'<input type="hidden" value="'.$prices[
'rowid'].
'" name="rowid">';
1255 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1256 print
'<td><input size="5" type="text" value="'.$prices[
'quantity'].
'" name="quantity"></td>';
1257 print
'<td class="right"><input class="width50 right" type="text" value="'.price2num($prices[
'price'],
'MU').
'" name="price"></td>';
1258 print
'<td class="right">';
1260 print $prices[
'price_base_type'];
1262 print
'<td class="right"> </td>';
1263 print
'<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices[
'remise_percent'].
'" name="remise_percent"> %</td>';
1264 print
'<td class="center"><input type="submit" value="'.$langs->trans(
"Modify").
'" class="button"></td>';
1268 print
'<tr class="'.($ii % 2 == 0 ?
'pair' :
'impair').
'">';
1269 print
'<td>'.$prices[
'quantity'].
'</td>';
1270 print
'<td class="right">'.price($prices[
'price']).
'</td>';
1271 print
'<td class="right">';
1273 print $prices[
'price_base_type'];
1275 print
'<td class="right">'.price($prices[
'unitprice']).
'</td>';
1276 print
'<td class="right">'.price($prices[
'remise_percent']).
' %</td>';
1277 print
'<td class="center">';
1278 if (($user->rights->produit->creer || $user->rights->service->creer)) {
1279 print
'<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1281 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete_price_by_qty&token='.
newToken().
'&rowid='.$prices[
"rowid"].
'">';
1292 print $langs->trans(
"No");
1301 print
'<div style="clear:both"></div>';
1313 if (!$action || $action ==
'delete' || $action ==
'showlog_customer_price' || $action ==
'showlog_default_price' || $action ==
'add_customer_price'
1314 || $action ==
'activate_price_by_qty' || $action ==
'disable_price_by_qty') {
1315 print
"\n".
'<div class="tabsAction">'.
"\n";
1318 $parameters = array();
1319 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
1320 if (empty($reshook)) {
1321 if ($object->isVariant()) {
1322 if ($user->rights->produit->creer || $user->rights->service->creer) {
1323 print
'<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' .
dol_escape_htmltag($langs->trans(
"NoEditVariants")) .
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</a></div>';
1326 if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1327 if ($user->rights->produit->creer || $user->rights->service->creer) {
1328 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>';
1330 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateDefaultPrice") .
'</span></div>';
1334 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1335 if ($user->rights->produit->creer || $user->rights->service->creer) {
1336 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>';
1338 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"AddCustomerPrice") .
'</span></div>';
1342 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1343 if ($user->rights->produit->creer || $user->rights->service->creer) {
1344 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>';
1346 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateVAT") .
'</span></div>';
1349 if ($user->rights->produit->creer || $user->rights->service->creer) {
1350 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit_price&token='.newToken().
'&id=' . $object->id .
'">' . $langs->trans(
"UpdateLevelPrices") .
'</a></div>';
1352 print
'<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">' . $langs->trans(
"UpdateLevelPrices") .
'</span></div>';
1367 if ($action ==
'edit_vat' && ($user->rights->produit->creer || $user->rights->service->creer)) {
1370 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1371 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1372 print
'<input type="hidden" name="action" value="update_vat">';
1373 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1377 print
'<table class="border centpercent">';
1380 print
'<tr><td>'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1381 print
$form->load_tva(
"tva_tx", $object->default_vat_code ? $object->tva_tx.
' ('.$object->default_vat_code.
')' : $object->tva_tx, $mysoc,
'', $object->id, $object->tva_npr, $object->type,
false, 1);
1388 print
$form->buttonsSaveCancel();
1390 print
'<br></form><br>';
1393 if ($action ==
'edit_price' && $object->getRights()->creer) {
1397 if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1398 print
'<!-- Edit price -->'.
"\n";
1399 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1400 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1401 print
'<input type="hidden" name="action" value="update_price">';
1402 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1406 print
'<div class="div-table-responsive-no-min">';
1407 print
'<table class="border centpercent">';
1410 print
'<tr><td class="titlefield">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1411 print
$form->load_tva(
"tva_tx", $object->default_vat_code ? $object->tva_tx.
' ('.$object->default_vat_code.
')' : $object->tva_tx, $mysoc,
'', $object->id, $object->tva_npr, $object->type,
false, 1);
1416 print $langs->trans(
'PriceBase');
1419 print
$form->selectPriceBaseType($object->price_base_type,
"price_base_type");
1424 if (!empty($conf->dynamicprices->enabled)) {
1426 print
'<!-- Show price mode of dynamicprices editor -->'.
"\n";
1427 print
'<tr><td>'.$langs->trans(
"PriceMode").
'</td><td>';
1428 print
img_picto(
'',
'dynamicprice',
'class="pictofixedwidth"');
1430 $price_expression_list = array(0 => $langs->trans(
"Numeric").
' <span class="opacitymedium">('.$langs->trans(
"NoDynamicPrice").
')</span>');
1431 foreach ($price_expression->list_price_expression() as $entry) {
1432 $price_expression_list[$entry->id] = $entry->title;
1434 $price_expression_preselection =
GETPOST(
'eid') ?
GETPOST(
'eid') : ($object->fk_price_expression ? $object->fk_price_expression :
'0');
1435 print
$form->selectarray(
'eid', $price_expression_list, $price_expression_preselection);
1436 print
' <a id="expression_editor" class="classlink">'.$langs->trans(
"PriceExpressionEditor").
'</a>';
1442 <script
type=
"text/javascript">
1443 jQuery(document).ready(
function() {
1444 jQuery(
"#expression_editor").click(
function() {
1445 window.location =
"<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $(
"#eid").val();
1447 jQuery(
"#eid").change(on_change);
1450 function on_change() {
1451 if ($(
"#eid").val() == 0) {
1452 jQuery(
"#price_numeric").show();
1454 jQuery(
"#price_numeric").hide();
1463 $product->fetch($id, $ref,
'', 1);
1464 print
'<tr id="price_numeric"><td>';
1465 $text = $langs->trans(
'SellingPrice');
1466 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1468 if ($object->price_base_type ==
'TTC') {
1469 print
'<input name="price" size="10" value="'.price($product->price_ttc).
'">';
1471 print
'<input name="price" size="10" value="'.price($product->price).
'">';
1477 $text = $langs->trans(
'MinPrice');
1478 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1480 if ($object->price_base_type ==
'TTC') {
1481 print
'<input name="price_min" size="10" value="'.price($object->price_min_ttc).
'">';
1483 print
'<input name="price_min" size="10" value="'.price($object->price_min).
'">';
1485 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1486 print
' '.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1491 $parameters = array();
1492 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1499 print
$form->buttonsSaveCancel();
1503 print
'<!-- Edit price per level -->'.
"\n";
1507 var showHidePriceRules =
function () {
1508 var otherPrices = $(
'div.fiche form table tbody tr:not(:first)');
1509 var minPrice1 = $(
'div.fiche form input[name="price_min[1]"]');
1511 if (jQuery(
'input#usePriceRules').prop(
'checked')) {
1520 jQuery(document).ready(
function () {
1521 showHidePriceRules();
1523 jQuery(
'input#usePriceRules').click(showHidePriceRules);
1528 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1529 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1530 print
'<input type="hidden" name="action" value="update_price">';
1531 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1535 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL)) {
1536 print $langs->trans(
'UseMultipriceRules').
' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.($object->price_autogen ?
'checked' :
'').
'><br><br>';
1539 print
'<div class="div-table-responsive-no-min">';
1540 print
'<table class="noborder">';
1541 print
'<thead><tr class="liste_titre">';
1543 print
'<td>'.$langs->trans(
"PriceLevel").
'</td>';
1545 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1546 print
'<td style="text-align: center">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1551 print
'<td class="center">'.$langs->trans(
"SellingPrice").
'</td>';
1553 print
'<td class="center">'.$langs->trans(
"MinPrice").
'</td>';
1555 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1558 print
'</tr></thead>';
1562 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
1563 print
'<tr class="oddeven">';
1565 $text = $langs->trans(
'SellingPrice').
' '.$i;
1566 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1570 if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1572 print
'<input type="hidden" name="tva_tx['.$i.
']" value="'.($object->default_vat_code ? $object->tva_tx.
' ('.$object->default_vat_code.
')' : $object->tva_tx).
'">';
1573 print
'<input type="hidden" name="tva_npr['.$i.
']" value="'.$object->tva_npr.
'">';
1574 print
'<input type="hidden" name="localtax1_tx['.$i.
']" value="'.$object->localtax1_tx.
'">';
1575 print
'<input type="hidden" name="localtax1_type['.$i.
']" value="'.$object->localtax1_type.
'">';
1576 print
'<input type="hidden" name="localtax2_tx['.$i.
']" value="'.$object->localtax2_tx.
'">';
1577 print
'<input type="hidden" name="localtax2_type['.$i.
']" value="'.$object->localtax2_type.
'">';
1581 print
'<td style="text-align: center">';
1582 print
$form->load_tva(
"tva_tx[".$i.
']', $object->multiprices_tva_tx[$i], $mysoc,
'', $object->id,
false, $object->type,
false, 1);
1587 print
'<td style="text-align: center">';
1588 if ($object->multiprices_base_type [$i] ==
'TTC') {
1589 print
'<input name="price['.$i.
']" size="10" value="'.
price($object->multiprices_ttc [$i]).
'">';
1591 print
'<input name="price['.$i.
']" size="10" value="'.
price($object->multiprices [$i]).
'">';
1593 print
' '.$form->selectPriceBaseType($object->multiprices_base_type [$i],
"multiprices_base_type[".$i.
"]");
1597 print
'<td style="text-align: center">';
1598 if ($object->multiprices_base_type [$i] ==
'TTC') {
1599 print
'<input name="price_min['.$i.
']" size="10" value="'.
price($object->multiprices_min_ttc [$i]).
'">';
1601 print
'<input name="price_min['.$i.
']" size="10" value="'.
price($object->multiprices_min [$i]).
'">';
1603 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1604 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1618 print
$form->buttonsSaveCancel();
1627 if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action ==
'showlog_default_price') && !in_array($action, array(
'edit_price',
'edit_vat'))) {
1628 $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,";
1629 $sql .=
" p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
1630 $sql .=
" p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
1631 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_price as p,";
1632 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
1633 $sql .=
" WHERE fk_product = ".((int) $object->id);
1634 $sql .=
" AND p.entity IN (".getEntity(
'productprice').
")";
1635 $sql .=
" AND p.fk_user_author = u.rowid";
1636 if (!empty($socid) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
1637 $sql .=
" AND p.price_level = ".((int) $soc->price_level);
1639 $sql .=
" ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
1643 $result = $db->query($sql);
1645 print
'<div class="divlogofpreviouscustomerprice">';
1647 $num = $db->num_rows($result);
1655 if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
1656 $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);
1658 $ret = $object->updatePrice(($object->price_base_type ==
'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type ==
'TTC' ? $object->price_min_ttc : $object->price_min));
1664 $result = $db->query($sql);
1665 $num = $db->num_rows($result);
1672 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'">'.$langs->trans(
"Back").
'</a>';
1674 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1675 print_barre_liste($langs->trans(
"DefaultPriceLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'', $backbutton, 0, $num,
'title_accountancy.png');
1677 print_barre_liste($langs->trans(
"PriceByCustomerLog"), 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', 0, $num,
'title_accountancy.png');
1680 print
'<!-- List of log prices -->'.
"\n";
1681 print
'<div class="div-table-responsive">'.
"\n";
1682 print
'<table class="liste centpercent">'.
"\n";
1684 print
'<tr class="liste_titre">';
1685 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
1687 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1688 print
'<td class="center">'.$langs->trans(
"PriceLevel").
'</td>';
1690 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1691 print
'<td class="center">'.$langs->trans(
"Type").
'</td>';
1694 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
1695 if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1696 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
1698 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
1699 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
1700 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
1701 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
1703 if (!empty($conf->dynamicprices->enabled)) {
1704 print
'<td class="right">'.$langs->trans(
"PriceExpressionSelected").
'</td>';
1706 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
1707 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
1708 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
1709 if ($user->rights->produit->supprimer) {
1710 print
'<td class="right"> </td>';
1714 $notfirstlineforlevel = array();
1718 $objp = $db->fetch_object($result);
1720 print
'<tr class="oddeven">';
1722 print
"<td>".dol_print_date($db->jdate($objp->dp),
"dayhour",
'tzuserrel').
"</td>";
1725 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1726 print
'<td class="center">'.$objp->price_level.
"</td>";
1729 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1730 $type = ($objp->price_by_qty == 1) ?
'PriceByQuantity' :
'Standard';
1731 print
'<td class="center">'.$langs->trans($type).
"</td>";
1734 print
'<td class="center">';
1735 if (empty($objp->price_by_qty)) {
1736 print $langs->trans($objp->price_base_type);
1740 if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1741 print
'<td class="right">';
1743 if (empty($objp->price_by_qty)) {
1744 $positiverates =
'';
1746 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->tva_tx);
1749 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax1_tx);
1752 $positiverates .= ($positiverates ?
'/' :
'').
price2num($objp->localtax2_tx);
1754 if (empty($positiverates)) {
1755 $positiverates =
'0';
1757 echo
vatrate($positiverates.($objp->default_vat_code ?
' ('.$objp->default_vat_code.
')' :
''),
'%', !empty($objp->tva_npr) ? $objp->tva_npr : 0);
1770 if ($objp->price_base_type ==
'HT') {
1773 $pu = $objp->price_ttc;
1777 $localtaxarray =
getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
1779 $resultarray =
calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly, $object->type, $mysoc, $localtaxarray);
1781 $total_ht = $resultarray[0];
1782 $total_vat = $resultarray[1];
1783 $total_localtax1 = $resultarray[9];
1784 $total_localtax2 = $resultarray[10];
1785 $total_ttc = $resultarray[2];
1788 if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) {
1790 $res = $price_expression->fetch($objp->fk_price_expression);
1791 $title = $price_expression->title;
1792 print
'<td class="right"></td>';
1793 print
'<td class="right"></td>';
1794 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
1795 print
'<td class="right"></td>';
1797 print
'<td class="right">'.$title.
"</td>";
1800 print
'<td class="right">';
1801 if (empty($objp->price_by_qty)) {
1802 print
'<span class="amount">'.price($objp->price).
'</span>';
1806 print
'<td class="right">';
1807 if (empty($objp->price_by_qty)) {
1808 $price_ttc = $objp->price_ttc;
1809 print
'<span class="amount">'.price($price_ttc).
'<span>';
1812 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
1813 print
'<td class="right">';
1814 print $resultarray[2];
1817 if (!empty($conf->dynamicprices->enabled)) {
1818 print
'<td class="right"></td>';
1823 print
'<td class="right">';
1824 if (empty($objp->price_by_qty)) {
1825 print
price($objp->price_min);
1830 print
'<td class="right">';
1831 if (empty($objp->price_by_qty)) {
1832 $price_min_ttc = $objp->price_min_ttc;
1833 print
price($price_min_ttc);
1838 print
'<td class="right">';
1839 if ($objp->user_id > 0) {
1840 $userstatic =
new User($db);
1841 $userstatic->fetch($objp->user_id);
1842 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
1847 if ($user->rights->produit->supprimer) {
1849 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1850 if (empty($notfirstlineforlevel[$objp->price_level])) {
1851 $notfirstlineforlevel[$objp->price_level] = 1;
1859 print
'<td class="right">';
1860 if ($candelete || ($db->jdate($objp->dp) >=
dol_now())) {
1861 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=delete&token='.
newToken().
'&id='.$object->id.
'&lineid='.$objp->rowid.
'">';
1888 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1891 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
1892 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
1893 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
1895 if (empty($page) || $page == -1) {
1898 $offset = $limit * $page;
1899 $pageprev = $page - 1;
1900 $pagenext = $page + 1;
1905 $sortfield =
"soc.nom";
1909 $filter = array(
't.fk_product' => $object->id);
1911 if (!empty($search_soc)) {
1912 $filter[
'soc.nom'] = $search_soc;
1915 if ($action ==
'add_customer_price') {
1917 $maxpricesupplier = $object->min_recommended_price();
1919 print
'<!-- add_customer_price -->';
1922 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
1923 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1924 print
'<input type="hidden" name="action" value="add_customer_price_confirm">';
1925 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1927 print
'<div class="tabBar tabBarWithBottom">';
1929 print
'<table class="border centpercent">';
1931 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1933 print
img_picto(
'',
'company').$form->select_company(
'',
'socid',
's.client IN (1,2,3)',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
1938 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
1939 print
'<td><input name="ref_customer" size="12"></td></tr>';
1942 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
1943 print
$form->load_tva(
"tva_tx", $object->default_vat_code ? $object->tva_tx.
' ('.$object->default_vat_code.
')' : $object->tva_tx, $mysoc,
'', $object->id, $object->tva_npr, $object->type,
false, 1);
1947 print
'<tr><td class="fieldrequired">';
1948 print $langs->trans(
'PriceBase');
1951 print
$form->selectPriceBaseType($object->price_base_type,
"price_base_type");
1956 print
'<tr><td class="fieldrequired">';
1957 $text = $langs->trans(
'SellingPrice');
1958 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1960 if ($object->price_base_type ==
'TTC') {
1961 print
'<input name="price" size="10" value="'.price($object->price_ttc).
'">';
1963 print
'<input name="price" size="10" value="'.price($object->price).
'">';
1969 $text = $langs->trans(
'MinPrice');
1970 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
1971 if ($object->price_base_type ==
'TTC') {
1972 print
'<td><input name="price_min" size="10" value="'.price($object->price_min_ttc).
'">';
1974 print
'<td><input name="price_min" size="10" value="'.price($object->price_min).
'">';
1976 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
1977 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
1986 print
'<div class="center">';
1989 print
'<div class="marginbottomonly">';
1990 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
1991 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
1994 print
$form->buttonsSaveCancel();
1997 } elseif ($action ==
'edit_customer_price') {
1999 $maxpricesupplier = $object->min_recommended_price();
2001 print
'<!-- edit_customer_price -->';
2004 $result = $prodcustprice->fetch(
GETPOST(
'lineid',
'int'));
2009 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
2010 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2011 print
'<input type="hidden" name="action" value="update_customer_price_confirm">';
2012 print
'<input type="hidden" name="lineid" value="'.$prodcustprice->id.
'">';
2014 print
'<table class="liste centpercent">';
2016 print
'<td class="titlefield fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
2017 $staticsoc =
new Societe($db);
2018 $staticsoc->fetch($prodcustprice->fk_soc);
2019 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2023 print
'<tr><td>' . $langs->trans(
'RefCustomer') .
'</td>';
2024 print
'<td><input name="ref_customer" size="12" value="' .
dol_escape_htmltag($prodcustprice->ref_customer) .
'"></td></tr>';
2027 print
'<tr><td class="fieldrequired">'.$langs->trans(
"DefaultTaxRate").
'</td><td>';
2028 print
$form->load_tva(
"tva_tx", $prodcustprice->default_vat_code ? $prodcustprice->tva_tx.
' ('.$prodcustprice->default_vat_code.
')' : $prodcustprice->tva_tx, $mysoc,
'', $object->id, $prodcustprice->recuperableonly, $object->type,
false, 1);
2032 print
'<tr><td class="fieldrequired">';
2033 print $langs->trans(
'PriceBase');
2036 print
$form->selectPriceBaseType($prodcustprice->price_base_type,
"price_base_type");
2041 print
'<tr><td class="fieldrequired">';
2042 $text = $langs->trans(
'SellingPrice');
2043 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
2045 if ($prodcustprice->price_base_type ==
'TTC') {
2046 print
'<input name="price" size="10" value="'.price($prodcustprice->price_ttc).
'">';
2048 print
'<input name="price" size="10" value="'.price($prodcustprice->price).
'">';
2054 $text = $langs->trans(
'MinPrice');
2055 print
$form->textwithpicto($text, $langs->trans(
"PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
2057 if ($prodcustprice->price_base_type ==
'TTC') {
2058 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).
'">';
2060 print
'<input name="price_min" size="10" value="'.price($prodcustprice->price_min).
'">';
2063 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
2064 print
'<td class="left">'.$langs->trans(
"MinimumRecommendedPrice",
price($maxpricesupplier, 0,
'', 1, -1, -1,
'auto')).
' '.
img_warning().
'</td>';
2071 print
'<div class="center">';
2072 print
'<div class="marginbottomonly">';
2073 print
'<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
2074 print
'<label for="updatechildprice">'.$langs->trans(
'ForceUpdateChildPriceSoc').
'</label>';
2077 print
$form->buttonsSaveCancel();
2079 print
'<br></form>';
2080 } elseif ($action ==
'showlog_customer_price') {
2082 print
'<!-- list of all log of prices per customer -->'.
"\n";
2084 $filter = array(
't.fk_product' => $object->id,
't.fk_soc' =>
GETPOST(
'socid',
'int'));
2087 $nbtotalofrecords =
'';
2088 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2089 $nbtotalofrecords = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2092 $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2097 $option =
'&socid='.GETPOST(
'socid',
'int').
'&id='.$object->id;
2099 $staticsoc =
new Societe($db);
2100 $staticsoc->fetch(
GETPOST(
'socid',
'int'));
2102 $title = $langs->trans(
'PriceByCustomerLog');
2103 $title .=
' - '.$staticsoc->getNomUrl(1);
2105 $backbutton =
'<a class="justalink" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'">'.$langs->trans(
"Back").
'</a>';
2107 print_barre_liste($title, $page, $_SERVER[
'PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2109 if (count($prodcustprice->lines) > 0) {
2110 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
2111 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2112 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2114 print
'<div class="div-table-responsive-no-min">';
2115 print
'<table class="liste centpercent">';
2117 print
'<tr class="liste_titre">';
2118 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2119 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2120 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2121 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2122 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2123 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2124 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2125 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2126 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2128 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2129 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2130 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
2131 print
'<td> </td>';
2134 foreach ($prodcustprice->lines as $line) {
2136 $staticsoc =
new Societe($db);
2137 $staticsoc->fetch($line->fk_soc);
2139 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2142 if ($line->price_base_type ==
'HT') {
2145 $pu = $line->price_ttc;
2149 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2151 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
2153 $total_ht = $resultarray[0];
2154 $total_vat = $resultarray[1];
2155 $total_localtax1 = $resultarray[9];
2156 $total_localtax2 = $resultarray[10];
2157 $total_ttc = $resultarray[2];
2159 print
'<tr class="oddeven">';
2161 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2162 print
'<td>'.$line->ref_customer.
'</td>';
2163 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2164 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2165 print
'<td class="right">';
2167 $positiverates =
'';
2169 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2172 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2175 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2177 if (empty($positiverates)) {
2178 $positiverates =
'0';
2181 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''),
'%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2185 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2187 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2188 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2189 print
'<td class="right">'.price($resultarray[2]).
'</td>';
2192 print
'<td class="right">'.price($line->price_min).
'</td>';
2193 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2196 $userstatic =
new User($db);
2197 $userstatic->fetch($line->fk_user);
2198 print
'<td class="right">';
2199 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
2207 print $langs->trans(
'None');
2209 } elseif ($action !=
'showlog_default_price' && $action !=
'edit_price') {
2211 print
'<!-- list of all prices per customer -->'.
"\n";
2214 $nbtotalofrecords =
'';
2215 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2216 $nbtotalofrecords = $prodcustprice->fetch_all($sortorder, $sortfield, 0, 0, $filter);
2219 $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
2224 $option =
'&search_soc='.$search_soc.
'&id='.$object->id;
2226 print_barre_liste($langs->trans(
'PriceByCustomer'), $page, $_SERVER [
'PHP_SELF'], $option, $sortfield, $sortorder,
'', count($prodcustprice->lines), $nbtotalofrecords,
'title_accountancy.png');
2228 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'" method="POST">';
2229 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2230 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2232 print
'<!-- List of prices per customer -->'.
"\n";
2233 print
'<div class="div-table-responsive-no-min">'.
"\n";
2234 print
'<table class="liste centpercent">'.
"\n";
2236 if (count($prodcustprice->lines) > 0 || $search_soc) {
2238 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2242 print
'<tr class="liste_titre">';
2243 print
'<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.
'"></td>';
2244 print
'<td class="liste_titre" colspan="'.$colspan.
'"> </td>';
2246 print
'<td class="liste_titre maxwidthsearch">';
2247 $searchpicto =
$form->showFilterAndCheckAddButtons(0);
2253 print
'<tr class="liste_titre">';
2254 print
'<td>'.$langs->trans(
"ThirdParty").
'</td>';
2255 print
'<td>'.$langs->trans(
'RefCustomer').
'</td>';
2256 print
'<td>'.$langs->trans(
"AppliedPricesFrom").
'</td>';
2257 print
'<td class="center">'.$langs->trans(
"PriceBase").
'</td>';
2258 print
'<td class="right">'.$langs->trans(
"DefaultTaxRate").
'</td>';
2259 print
'<td class="right">'.$langs->trans(
"HT").
'</td>';
2260 print
'<td class="right">'.$langs->trans(
"TTC").
'</td>';
2261 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2262 print
'<td class="right">'.$langs->trans(
"INCT").
'</td>';
2264 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"HT").
'</td>';
2265 print
'<td class="right">'.$langs->trans(
"MinPrice").
' '.$langs->trans(
"TTC").
'</td>';
2266 print
'<td class="right">'.$langs->trans(
"ChangedBy").
'</td>';
2271 if ($object->price_base_type ==
'HT') {
2272 $pu = $object->price;
2274 $pu = $object->price_ttc;
2278 $localtaxarray =
getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''), 0, $mysoc, $mysoc);
2280 $resultarray =
calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray);
2282 $total_ht = $resultarray[0];
2283 $total_vat = $resultarray[1];
2284 $total_localtax1 = $resultarray[9];
2285 $total_localtax2 = $resultarray[10];
2286 $total_ttc = $resultarray[2];
2288 print
'<tr class="oddeven">';
2289 print
'<td colspan="3">' . $langs->trans(
'Default') .
'</td>';
2291 print
'<td class="center">'.$langs->trans($object->price_base_type).
"</td>";
2294 print
'<td class="right">';
2296 $positiverates =
'';
2298 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->tva_tx);
2300 if (
price2num($object->localtax1_type)) {
2301 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax1_tx);
2303 if (
price2num($object->localtax2_type)) {
2304 $positiverates .= ($positiverates ?
'/' :
'').
price2num($object->localtax2_tx);
2306 if (empty($positiverates)) {
2307 $positiverates =
'0';
2309 echo
vatrate($positiverates.($object->default_vat_code ?
' ('.$object->default_vat_code.
')' :
''),
'%', $object->tva_npr);
2315 print
'<td class="right"><span class="amount">'.price($object->price).
"</span></td>";
2317 print
'<td class="right"><span class="amount">'.price($object->price_ttc).
"</span></td>";
2318 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2320 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2323 print
'<td class="right">'.price($object->price_min).
'</td>';
2324 print
'<td class="right">'.price($object->price_min_ttc).
'</td>';
2325 print
'<td class="right">';
2327 if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
2328 print
'<td class="nowraponall">';
2329 print
'<a class="marginleftonly marginrightonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_default_price&token='.
newToken().
'&id='.$object->id.
'">';
2330 print
img_info($langs->trans(
'PriceByCustomerLog'));
2333 print
'<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_price&token='.
newToken().
'&id='.$object->id.
'">';
2334 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2340 if (count($prodcustprice->lines) > 0) {
2341 foreach ($prodcustprice->lines as $line) {
2343 $staticsoc =
new Societe($db);
2344 $staticsoc->fetch($line->fk_soc);
2346 $tva_tx = $line->default_vat_code ? $line->tva_tx.
' ('.$line->default_vat_code.
')' : $line->tva_tx;
2349 if ($line->price_base_type ==
'HT') {
2352 $pu = $line->price_ttc;
2356 $localtaxarray =
getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''), 0, $staticsoc, $mysoc);
2358 $resultarray =
calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
2360 $total_ht = $resultarray[0];
2361 $total_vat = $resultarray[1];
2362 $total_localtax1 = $resultarray[9];
2363 $total_localtax2 = $resultarray[10];
2364 $total_ttc = $resultarray[2];
2366 print
'<tr class="oddeven">';
2368 print
"<td>".$staticsoc->getNomUrl(1).
"</td>";
2369 print
'<td>'.dol_escape_htmltag($line->ref_customer).
'</td>';
2370 print
"<td>".dol_print_date($line->datec,
"dayhour",
'tzuserrel').
"</td>";
2371 print
'<td class="center">'.$langs->trans($line->price_base_type).
"</td>";
2373 print
'<td class="right">';
2375 $positiverates =
'';
2377 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->tva_tx);
2380 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax1_tx);
2383 $positiverates .= ($positiverates ?
'/' :
'').
price2num($line->localtax2_tx);
2385 if (empty($positiverates)) {
2386 $positiverates =
'0';
2389 echo
vatrate($positiverates.($line->default_vat_code ?
' ('.$line->default_vat_code.
')' :
''),
'%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
2393 print
'<td class="right"><span class="amount">'.price($line->price).
"</span></td>";
2395 print
'<td class="right"><span class="amount">'.price($line->price_ttc).
"</span></td>";
2396 if ($mysoc->localtax1_assuj ==
"1" || $mysoc->localtax2_assuj ==
"1") {
2398 print
'<td class="right"><span class="amount">'.price($resultarray[2]).
'</span></td>';
2401 print
'<td class="right">'.price($line->price_min).
'</td>';
2402 print
'<td class="right">'.price($line->price_min_ttc).
'</td>';
2405 $userstatic =
new User($db);
2406 $userstatic->fetch($line->fk_user);
2407 print
'<td class="right">';
2408 print $userstatic->getNomUrl(1,
'', 0, 0, 24, 0,
'login');
2413 if ($user->rights->produit->supprimer || $user->rights->service->supprimer) {
2414 print
'<td class="right nowraponall">';
2415 print
'<a href="'.$_SERVER[
"PHP_SELF"].
'?action=showlog_customer_price&token='.
newToken().
'&id='.$object->id.
'&socid='.$line->fk_soc.
'">';
2416 print
img_info($langs->trans(
'PriceByCustomerLog'));
2419 print
'<a class="marginleftonly editfielda" href="'.$_SERVER[
"PHP_SELF"].
'?action=edit_customer_price&token='.
newToken().
'&id='.$object->id.
'&lineid='.$line->id.
'">';
2420 print
img_edit(
'default', 0,
'style="vertical-align: middle;"');
2423 print
'<a class="marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?action=delete_customer_price&token='.
newToken().
'&id='.$object->id.
'&lineid='.$line->id.
'">';
2424 print
img_delete(
'default',
'style="vertical-align: middle;"');