184 $sql =
"SELECT COUNT(*) AS nb";
185 $sql .=
" FROM " . $this->db->prefix() .
"product_customer_price as t";
186 $sql .=
" WHERE (t.date_begin = '" . $this->db->idate($this->date_begin) .
"' OR t.date_end = '" . $this->db->idate($this->date_begin) .
"'";
187 $sql .=
" OR t.date_begin = '" . $this->db->idate($this->date_end) .
"' OR t.date_end = '" . $this->db->idate($this->date_end) .
"'";
188 $sql .=
" OR (t.date_begin <= '" . $this->db->idate($this->date_begin) .
"' AND '" . $this->db->idate($this->date_begin) .
"' <= t.date_end)";
189 $sql .=
" OR (t.date_begin <= '" . $this->db->idate($this->date_end) .
"' AND '" . $this->db->idate($this->date_end) .
"' <= t.date_end))";
190 if ($this->fk_product > 0) $sql .=
" AND t.fk_product = " . ((int) $this->fk_product);
191 if ($this->fk_soc > 0) $sql .=
" AND t.fk_soc = " . ((int) $this->fk_soc);
192 if ($this->
id > 0) $sql .=
" AND t.rowid != " . ((int) $this->
id);
194 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
195 $resql = $this->db->query($sql);
197 $this->errors[] =
"Error " . $this->db->lasterror();
202 if ($obj = $this->db->fetch_object($resql)) {
203 $nb = (int) $obj->nb;
205 $this->db->free($resql);
208 $this->errors[] = $langs->trans(
'ErrorAppliedPricesIntersectAnotherPeriod');
223 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
225 global
$conf, $langs;
231 if (isset($this->entity)) {
232 $this->entity = (int) $this->entity;
234 if (isset($this->fk_product)) {
235 $this->fk_product = (int) $this->fk_product;
237 if (isset($this->fk_soc)) {
238 $this->fk_soc = (int) $this->fk_soc;
240 if (isset($this->ref_customer)) {
241 $this->ref_customer = trim($this->ref_customer);
243 if (isset($this->
price)) {
246 if (isset($this->price_ttc)) {
247 $this->price_ttc = trim($this->price_ttc);
249 if (isset($this->price_min)) {
250 $this->price_min = trim($this->price_min);
252 if (isset($this->price_min_ttc)) {
253 $this->price_min_ttc = trim($this->price_min_ttc);
255 if (isset($this->price_base_type)) {
256 $this->price_base_type = trim($this->price_base_type);
258 if (isset($this->tva_tx)) {
259 $this->tva_tx = trim($this->tva_tx);
261 if (isset($this->recuperableonly)) {
262 $this->recuperableonly = trim($this->recuperableonly);
264 if (isset($this->localtax1_tx)) {
265 $this->localtax1_tx = trim($this->localtax1_tx);
267 if (isset($this->localtax2_tx)) {
268 $this->localtax2_tx = trim($this->localtax2_tx);
270 if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) {
271 $this->discount_percent = 0;
273 if (empty($this->date_begin)) {
274 $this->date_begin = $now;
276 if (isset($this->fk_user)) {
277 $this->fk_user = (int) $this->fk_user;
279 if (isset($this->price_label)) {
280 $this->price_label = trim($this->price_label);
282 if (isset($this->import_key)) {
283 $this->import_key = trim($this->import_key);
293 if ($this->
price !=
'' || $this->
price == 0) {
294 $vatRate = (float) $this->tva_tx;
295 if ($this->price_base_type ==
'TTC') {
300 if ($this->price_min !=
'' || $this->price_min == 0) {
301 $this->price_min_ttc =
price2num($this->price_min,
'MU');
302 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
303 $this->price_min =
price2num($this->price_min,
'MU');
305 $this->price_min = 0;
306 $this->price_min_ttc = 0;
310 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
311 $this->price_ttc =
price2num($this->price_ttc,
'MU');
313 if ($this->price_min !=
'' || $this->price_min == 0) {
314 $this->price_min =
price2num($this->price_min,
'MU');
315 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
316 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
319 $this->price_min = 0;
320 $this->price_min_ttc = 0;
326 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
329 $sql .=
"fk_product,";
331 $sql .=
'ref_customer,';
333 $sql .=
"price_ttc,";
334 $sql .=
"price_min,";
335 $sql .=
"price_min_ttc,";
336 $sql .=
"price_base_type,";
337 $sql .=
"default_vat_code,";
339 $sql .=
"recuperableonly,";
340 $sql .=
"localtax1_type,";
341 $sql .=
"localtax1_tx,";
342 $sql .=
"localtax2_type,";
343 $sql .=
"localtax2_tx,";
344 $sql .=
"discount_percent,";
345 $sql .=
"date_begin,";
348 $sql .=
"price_label,";
349 $sql .=
"import_key";
350 $sql .=
") VALUES (";
351 $sql .=
" ".((int)
$conf->entity).
",";
352 $sql .=
" '".$this->db->idate($now).
"',";
353 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : ((int) $this->fk_product)).
",";
354 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' : ((int) $this->fk_soc)).
",";
355 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
356 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
357 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
358 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
359 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
360 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
361 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
362 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
363 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
364 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
365 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).
",";
366 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
367 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).
",";
368 $sql .=
" ".(empty($this->discount_percent) ?
'0' :
"'".$this->db->escape(
price2num($this->discount_percent)).
"'").
",";
369 $sql .=
" '".$this->db->idate($this->date_begin).
"',";
370 $sql .=
" ".(empty($this->date_end) ?
'NULL' :
"'".$this->db->idate($this->date_end).
"'").
",";
371 $sql .=
" ".((int) $user->id).
",";
372 $sql .=
" ".(!isset($this->price_label) ?
'NULL' :
"'".$this->db->escape($this->price_label).
"'").
",";
373 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
378 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
379 $resql = $this->db->query($sql);
382 $this->errors [] =
"Error ".$this->db->lasterror();
386 $this->
id = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
389 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
405 foreach ($this->errors as $errmsg) {
406 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
407 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
409 $this->db->rollback();
429 $sql .=
" t.entity,";
432 $sql .=
" t.fk_product,";
433 $sql .=
" t.fk_soc,";
434 $sql .=
" t.ref_customer,";
436 $sql .=
" t.price_ttc,";
437 $sql .=
" t.price_min,";
438 $sql .=
" t.price_min_ttc,";
439 $sql .=
" t.price_base_type,";
440 $sql .=
" t.default_vat_code,";
441 $sql .=
" t.tva_tx,";
442 $sql .=
" t.recuperableonly,";
443 $sql .=
" t.localtax1_tx,";
444 $sql .=
" t.localtax2_tx,";
445 $sql .=
" t.discount_percent,";
446 $sql .=
" t.date_begin,";
447 $sql .=
" t.date_end,";
448 $sql .=
" t.fk_user,";
449 $sql .=
" t.price_label,";
450 $sql .=
" t.import_key";
451 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
452 $sql .=
" WHERE t.rowid = ".((int) $id);
454 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
455 $resql = $this->db->query($sql);
457 if ($this->db->num_rows($resql)) {
458 $obj = $this->db->fetch_object($resql);
460 $this->
id = $obj->rowid;
462 $this->entity = $obj->entity;
463 $this->datec = $this->db->jdate($obj->datec);
464 $this->tms = $this->db->jdate($obj->tms);
465 $this->fk_product = $obj->fk_product;
466 $this->fk_soc = $obj->fk_soc;
467 $this->ref_customer = $obj->ref_customer;
468 $this->
price = $obj->price;
469 $this->price_ttc = $obj->price_ttc;
470 $this->price_min = $obj->price_min;
471 $this->price_min_ttc = $obj->price_min_ttc;
472 $this->price_base_type = $obj->price_base_type;
473 $this->default_vat_code = $obj->default_vat_code;
474 $this->tva_tx = $obj->tva_tx;
475 $this->recuperableonly = $obj->recuperableonly;
476 $this->localtax1_tx = $obj->localtax1_tx;
477 $this->localtax2_tx = $obj->localtax2_tx;
478 $this->discount_percent = $obj->discount_percent;
479 $this->date_begin = $this->db->jdate($obj->date_begin);
480 $this->date_end = $this->db->jdate($obj->date_end);
481 $this->fk_user = $obj->fk_user;
482 $this->price_label = $obj->price_label;
483 $this->import_key = $obj->import_key;
485 $this->db->free($resql);
489 $this->db->free($resql);
494 $this->error =
"Error ".$this->db->lasterror();
510 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'')
512 if (empty($sortfield)) {
513 $sortfield =
"t.date_begin";
515 if (empty($sortorder)) {
521 $sql .=
" t.entity,";
524 $sql .=
" t.fk_product,";
525 $sql .=
" t.fk_soc,";
526 $sql .=
" t.ref_customer,";
528 $sql .=
" t.price_ttc,";
529 $sql .=
" t.price_min,";
530 $sql .=
" t.price_min_ttc,";
531 $sql .=
" t.price_base_type,";
532 $sql .=
" t.default_vat_code,";
533 $sql .=
" t.tva_tx,";
534 $sql .=
" t.recuperableonly,";
535 $sql .=
" t.localtax1_tx,";
536 $sql .=
" t.localtax2_tx,";
537 $sql .=
" t.localtax1_type,";
538 $sql .=
" t.localtax2_type,";
539 $sql .=
" t.discount_percent,";
540 $sql .=
" t.date_begin,";
541 $sql .=
" t.date_end,";
542 $sql .=
" t.fk_user,";
543 $sql .=
" t.price_label,";
544 $sql .=
" t.import_key,";
545 $sql .=
" soc.nom as socname,";
546 $sql .=
" prod.ref as prodref";
547 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
548 $sql .=
" ".$this->db->prefix().
"product as prod,";
549 $sql .=
" ".$this->db->prefix().
"societe as soc";
550 $sql .=
" WHERE soc.rowid=t.fk_soc ";
551 $sql .=
" AND prod.rowid=t.fk_product ";
552 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
553 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
556 if (is_array($filter)) {
557 if (count($filter) > 0) {
558 foreach ($filter as $key => $value) {
559 if (strpos($key,
'date')) {
560 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
561 } elseif ($key ==
'soc.nom') {
562 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
563 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
564 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
565 } elseif ($key ==
't.price' || $key ==
't.price_ttc' || $key ==
't.discount_percent') {
566 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((float)
price2num($value));
568 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((int) $value);
580 $this->errors[] = $errormessage;
581 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
585 $sql .= $this->db->order($sortfield, $sortorder);
586 if (!empty($limit)) {
587 $sql .= $this->db->plimit($limit + 1, $offset);
590 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
591 $resql = $this->db->query($sql);
593 $this->lines = array();
594 $num = $this->db->num_rows($resql);
596 while ($obj = $this->db->fetch_object($resql)) {
599 $line->id = $obj->rowid;
601 $line->entity = $obj->entity;
602 $line->datec = $this->db->jdate($obj->datec);
603 $line->tms = $this->db->jdate($obj->tms);
604 $line->fk_product = $obj->fk_product;
605 $line->fk_soc = $obj->fk_soc;
606 $line->ref_customer = $obj->ref_customer;
607 $line->price = $obj->price;
608 $line->price_ttc = $obj->price_ttc;
609 $line->price_min = $obj->price_min;
610 $line->price_min_ttc = $obj->price_min_ttc;
611 $line->price_base_type = $obj->price_base_type;
612 $line->default_vat_code = $obj->default_vat_code;
613 $line->tva_tx = $obj->tva_tx;
614 $line->recuperableonly = $obj->recuperableonly;
615 $line->localtax1_tx = $obj->localtax1_tx;
616 $line->localtax2_tx = $obj->localtax2_tx;
617 $line->localtax1_type = $obj->localtax1_type;
618 $line->localtax2_type = $obj->localtax2_type;
619 $line->discount_percent = $obj->discount_percent;
620 $line->date_begin = $this->db->jdate($obj->date_begin);
621 $line->date_end = $this->db->jdate($obj->date_end);
622 $line->fk_user = $obj->fk_user;
623 $line->price_label = $obj->price_label;
624 $line->import_key = $obj->import_key;
625 $line->socname = $obj->socname;
626 $line->prodref = $obj->prodref;
628 $this->lines[] = $line;
630 $this->db->free($resql);
634 $this->error =
"Error ".$this->db->lasterror();
649 public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array())
651 if (empty($sortfield)) {
652 $sortfield =
"t.date_begin";
654 if (empty($sortorder)) {
660 $sql .=
" t.entity,";
662 $sql .=
" t.fk_product,";
663 $sql .=
" t.fk_soc,";
664 $sql .=
" t.ref_customer,";
666 $sql .=
" t.price_ttc,";
667 $sql .=
" t.price_min,";
668 $sql .=
" t.price_min_ttc,";
669 $sql .=
" t.price_base_type,";
670 $sql .=
" t.default_vat_code,";
671 $sql .=
" t.tva_tx,";
672 $sql .=
" t.recuperableonly,";
673 $sql .=
" t.localtax1_tx,";
674 $sql .=
" t.localtax2_tx,";
675 $sql .=
" t.discount_percent,";
676 $sql .=
" t.date_begin,";
677 $sql .=
" t.date_end,";
678 $sql .=
" t.fk_user,";
679 $sql .=
" t.price_label,";
680 $sql .=
" t.import_key,";
681 $sql .=
" soc.nom as socname,";
682 $sql .=
" prod.ref as prodref";
683 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
684 $sql .=
" ,".$this->db->prefix().
"product as prod";
685 $sql .=
" ,".$this->db->prefix().
"societe as soc";
686 $sql .=
" WHERE soc.rowid=t.fk_soc";
687 $sql .=
" AND prod.rowid=t.fk_product ";
688 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
689 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
691 if (count($filter) > 0) {
692 foreach ($filter as $key => $value) {
693 if (strpos($key,
'date')) {
694 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
695 } elseif ($key ==
'soc.nom') {
696 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($value).
"%'";
698 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((int) $value);
702 $sql .= $this->db->order($sortfield, $sortorder);
703 if (!empty($limit)) {
704 $sql .= $this->db->plimit($limit + 1, $offset);
707 dol_syslog(get_class($this).
"::fetchAllLog", LOG_DEBUG);
708 $resql = $this->db->query($sql);
710 $this->lines = array();
711 $num = $this->db->num_rows($resql);
713 while ($obj = $this->db->fetch_object($resql)) {
716 $line->id = $obj->rowid;
718 $line->entity = $obj->entity;
719 $line->datec = $this->db->jdate($obj->datec);
720 $line->tms = $this->db->jdate($obj->tms);
721 $line->fk_product = $obj->fk_product;
722 $line->fk_soc = $obj->fk_soc;
723 $line->ref_customer = $obj->ref_customer;
724 $line->price = $obj->price;
725 $line->price_ttc = $obj->price_ttc;
726 $line->price_min = $obj->price_min;
727 $line->price_min_ttc = $obj->price_min_ttc;
728 $line->price_base_type = $obj->price_base_type;
729 $line->default_vat_code = $obj->default_vat_code;
730 $line->tva_tx = $obj->tva_tx;
731 $line->recuperableonly = $obj->recuperableonly;
732 $line->localtax1_tx = $obj->localtax1_tx;
733 $line->localtax2_tx = $obj->localtax2_tx;
734 $line->discount_percent = $obj->discount_percent;
735 $line->date_begin = $this->db->jdate($obj->date_begin);
736 $line->date_end = $this->db->jdate($obj->date_end);
737 $line->fk_user = $obj->fk_user;
738 $line->price_label = $obj->price_label;
739 $line->import_key = $obj->import_key;
740 $line->socname = $obj->socname;
741 $line->prodref = $obj->prodref;
743 $this->lines [] = $line;
745 $this->db->free($resql);
749 $this->error =
"Error ".$this->db->lasterror();
762 public function update(
User $user, $notrigger = 0, $forceupdateaffiliate = 0)
764 global
$conf, $langs;
770 if (isset($this->entity)) {
771 $this->entity = (int) $this->entity;
773 if (isset($this->fk_product)) {
774 $this->fk_product = (int) $this->fk_product;
776 if (isset($this->fk_soc)) {
777 $this->fk_soc = (int) $this->fk_soc;
779 if (isset($this->ref_customer)) {
780 $this->ref_customer = trim($this->ref_customer);
782 if (isset($this->
price)) {
785 if (isset($this->price_ttc)) {
786 $this->price_ttc = trim((
string) $this->price_ttc);
788 if (isset($this->price_min)) {
789 $this->price_min = trim((
string) $this->price_min);
791 if (isset($this->price_min_ttc)) {
792 $this->price_min_ttc = trim((
string) $this->price_min_ttc);
794 if (isset($this->price_base_type)) {
795 $this->price_base_type = trim($this->price_base_type);
797 if (isset($this->tva_tx)) {
798 $this->tva_tx = trim($this->tva_tx);
800 if (isset($this->recuperableonly)) {
801 $this->recuperableonly = trim((
string) $this->recuperableonly);
803 if (isset($this->localtax1_tx)) {
804 $this->localtax1_tx = trim((
string) $this->localtax1_tx);
806 if (isset($this->localtax2_tx)) {
807 $this->localtax2_tx = trim((
string) $this->localtax2_tx);
809 if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) {
810 $this->discount_percent = 0;
812 if (empty($this->date_begin)) {
813 $this->date_begin = $now;
815 if (isset($this->fk_user)) {
816 $this->fk_user = (int) $this->fk_user;
818 if (isset($this->price_label)) {
819 $this->price_label = trim($this->price_label);
821 if (isset($this->import_key)) {
822 $this->import_key = trim($this->import_key);
832 if ($this->
price !=
'' || $this->
price == 0) {
833 $vatRate = (float) $this->tva_tx;
834 if ($this->price_base_type ==
'TTC') {
839 if ($this->price_min !=
'' || $this->price_min == 0) {
840 $this->price_min_ttc =
price2num($this->price_min,
'MU');
841 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
842 $this->price_min =
price2num($this->price_min,
'MU');
844 $this->price_min = 0;
845 $this->price_min_ttc = 0;
849 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
850 $this->price_ttc =
price2num($this->price_ttc,
'MU');
852 if ($this->price_min !=
'' || $this->price_min == 0) {
853 $this->price_min =
price2num($this->price_min,
'MU');
854 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
855 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
858 $this->price_min = 0;
859 $this->price_min_ttc = 0;
866 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
870 $sql .=
"fk_product,";
872 $sql .=
"ref_customer,";
874 $sql .=
"price_ttc,";
875 $sql .=
"price_min,";
876 $sql .=
"price_min_ttc,";
877 $sql .=
"price_base_type,";
878 $sql .=
"default_vat_code,";
880 $sql .=
"recuperableonly,";
881 $sql .=
"localtax1_tx,";
882 $sql .=
"localtax2_tx,";
883 $sql .=
"localtax1_type,";
884 $sql .=
"localtax2_type,";
885 $sql .=
"discount_percent,";
886 $sql .=
"date_begin,";
889 $sql .=
"price_label,";
890 $sql .=
"import_key";
895 $sql .=
" t.entity,";
897 $sql .=
" t.fk_product,";
898 $sql .=
" t.fk_soc,";
899 $sql .=
" t.ref_customer,";
901 $sql .=
" t.price_ttc,";
902 $sql .=
" t.price_min,";
903 $sql .=
" t.price_min_ttc,";
904 $sql .=
" t.price_base_type,";
905 $sql .=
" t.default_vat_code,";
906 $sql .=
" t.tva_tx,";
907 $sql .=
" t.recuperableonly,";
908 $sql .=
" t.localtax1_tx,";
909 $sql .=
" t.localtax2_tx,";
910 $sql .=
" t.localtax1_type,";
911 $sql .=
" t.localtax2_type,";
912 $sql .=
" t.discount_percent,";
913 $sql .=
" t.date_begin,";
914 $sql .=
" t.date_end,";
915 $sql .=
" t.fk_user,";
916 $sql .=
" t.price_label,";
917 $sql .=
" t.import_key";
919 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
920 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
923 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
924 $resql = $this->db->query($sql);
927 $this->errors [] =
"Error ".$this->db->lasterror();
931 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
933 $sql .=
" entity=".((int)
$conf->entity).
",";
934 $sql .=
" datec='".$this->db->idate($now).
"',";
935 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
936 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
937 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
938 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
939 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
940 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
941 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
942 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
943 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
944 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
945 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
946 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
947 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
948 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
949 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
950 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
951 $sql .=
" discount_percent=".(!empty($this->discount_percent) ?
"'".price2num($this->discount_percent).
"'" :
"0").
",";
952 $sql .=
" date_begin='".$this->db->idate($this->date_begin).
"',";
953 $sql .=
" date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
954 $sql .=
" fk_user=".((int) $user->id).
",";
955 $sql .=
" price_label=".(isset($this->price_label) ?
"'".$this->db->escape($this->price_label).
"'" :
"null").
",";
956 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
958 $sql .=
" WHERE rowid=".((int) $this->
id);
960 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
961 $resql = $this->db->query($sql);
964 $this->errors [] =
"Error ".$this->db->lasterror();
967 if (!$error && !$notrigger) {
969 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
985 foreach ($this->errors as $errmsg) {
986 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
987 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
989 $this->db->rollback();
1006 if (
getDolGlobalString(
'PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES')) {
1013 $sql =
"SELECT s.rowid";
1014 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
1015 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
1016 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
1018 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
1019 $resql = $this->db->query($sql);
1022 $this->lines = array();
1023 $num = $this->db->num_rows($resql);
1025 while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
1030 't.fk_product' => (
string) $this->fk_product,
't.fk_soc' => (
string) $obj->rowid
1033 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
1036 $this->error = $prodsocprice->error;
1039 if (count($prodsocprice->lines) > 0) {
1041 if (!empty($forceupdateaffiliate)) {
1043 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
1045 $prodsocpriceupd->price = $this->price;
1046 $prodsocpriceupd->price_min = $this->price_min;
1047 $prodsocpriceupd->price_base_type = $this->price_base_type;
1048 $prodsocpriceupd->tva_tx = $this->tva_tx;
1049 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
1050 $prodsocpriceupd->price_label = $this->price_label;
1051 $prodsocpriceupd->discount_percent = $this->discount_percent;
1052 $prodsocpriceupd->date_begin = $this->date_begin;
1053 $prodsocpriceupd->date_end = $this->date_end;
1055 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
1056 if ($resultupd < 0) {
1058 $this->error = $prodsocpriceupd->error;
1064 $prodsocpricenew->fk_soc = $obj->rowid;
1065 $prodsocpricenew->ref_customer = $obj->ref_customer;
1066 $prodsocpricenew->fk_product = $this->fk_product;
1067 $prodsocpricenew->price = $this->price;
1068 $prodsocpricenew->price_min = $this->price_min;
1069 $prodsocpricenew->price_base_type = $this->price_base_type;
1070 $prodsocpricenew->tva_tx = $this->tva_tx;
1071 $prodsocpricenew->recuperableonly = $this->recuperableonly;
1072 $prodsocpricenew->price_label = $this->price_label;
1073 $prodsocpricenew->discount_percent = $this->discount_percent;
1074 $prodsocpricenew->date_begin = $this->date_begin;
1075 $prodsocpricenew->date_end = $this->date_end;
1077 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
1078 if ($resultupd < 0) {
1080 $this->error = $prodsocpricenew->error;
1085 $this->db->free($resql);
1087 if (empty($error)) {
1093 $this->error =
"Error ".$this->db->lasterror();