224 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
232 if (isset($this->entity)) {
233 $this->entity = (int) $this->entity;
235 if (isset($this->fk_product)) {
236 $this->fk_product = (int) $this->fk_product;
238 if (isset($this->fk_soc)) {
239 $this->fk_soc = (int) $this->fk_soc;
241 if (isset($this->ref_customer)) {
242 $this->ref_customer = trim($this->ref_customer);
244 if (isset($this->
price)) {
247 if (isset($this->price_ttc)) {
248 $this->price_ttc = trim($this->price_ttc);
250 if (isset($this->price_min)) {
251 $this->price_min = trim($this->price_min);
253 if (isset($this->price_min_ttc)) {
254 $this->price_min_ttc = trim($this->price_min_ttc);
256 if (isset($this->price_base_type)) {
257 $this->price_base_type = trim($this->price_base_type);
259 if (isset($this->tva_tx)) {
260 $this->tva_tx = trim($this->tva_tx);
262 if (isset($this->recuperableonly)) {
263 $this->recuperableonly = trim($this->recuperableonly);
265 if (isset($this->localtax1_tx)) {
266 $this->localtax1_tx = trim($this->localtax1_tx);
268 if (isset($this->localtax2_tx)) {
269 $this->localtax2_tx = trim($this->localtax2_tx);
271 if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) {
272 $this->discount_percent = 0;
274 if (empty($this->date_begin)) {
275 $this->date_begin = $now;
277 if (isset($this->fk_user)) {
278 $this->fk_user = (int) $this->fk_user;
280 if (isset($this->price_label)) {
281 $this->price_label = trim($this->price_label);
283 if (isset($this->import_key)) {
284 $this->import_key = trim($this->import_key);
294 if ($this->
price !=
'' || $this->
price == 0) {
295 $vatRate = (float) $this->tva_tx;
296 if ($this->price_base_type ==
'TTC') {
301 if ($this->price_min !=
'' || $this->price_min == 0) {
302 $this->price_min_ttc =
price2num($this->price_min,
'MU');
303 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
304 $this->price_min =
price2num($this->price_min,
'MU');
306 $this->price_min = 0;
307 $this->price_min_ttc = 0;
311 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
312 $this->price_ttc =
price2num($this->price_ttc,
'MU');
314 if ($this->price_min !=
'' || $this->price_min == 0) {
315 $this->price_min =
price2num($this->price_min,
'MU');
316 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
317 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
320 $this->price_min = 0;
321 $this->price_min_ttc = 0;
327 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
330 $sql .=
"fk_product,";
332 $sql .=
'ref_customer,';
334 $sql .=
"price_ttc,";
335 $sql .=
"price_min,";
336 $sql .=
"price_min_ttc,";
337 $sql .=
"price_base_type,";
338 $sql .=
"default_vat_code,";
340 $sql .=
"recuperableonly,";
341 $sql .=
"localtax1_type,";
342 $sql .=
"localtax1_tx,";
343 $sql .=
"localtax2_type,";
344 $sql .=
"localtax2_tx,";
345 $sql .=
"discount_percent,";
346 $sql .=
"date_begin,";
349 $sql .=
"price_label,";
350 $sql .=
"import_key";
351 $sql .=
") VALUES (";
352 $sql .=
" ".((int)
$conf->entity).
",";
353 $sql .=
" '".$this->db->idate($now).
"',";
354 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' : ((int) $this->fk_product)).
",";
355 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' : ((int) $this->fk_soc)).
",";
356 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
357 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
358 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
359 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
360 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
361 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
362 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
363 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
364 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
365 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
366 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ?
"'0'" :
"'".$this->db->escape($this->localtax1_tx).
"'")).
",";
367 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
368 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ?
"'0'" :
"'".$this->db->escape($this->localtax2_tx).
"'")).
",";
369 $sql .=
" ".(empty($this->discount_percent) ?
'0' :
"'".$this->db->escape(
price2num($this->discount_percent)).
"'").
",";
370 $sql .=
" '".$this->db->idate($this->date_begin).
"',";
371 $sql .=
" ".(empty($this->date_end) ?
'NULL' :
"'".$this->db->idate($this->date_end).
"'").
",";
372 $sql .=
" ".((int) $user->id).
",";
373 $sql .=
" ".(!isset($this->price_label) ?
'NULL' :
"'".$this->db->escape($this->price_label).
"'").
",";
374 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
379 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
380 $resql = $this->db->query($sql);
383 $this->errors [] =
"Error ".$this->db->lasterror();
387 $this->
id = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
390 $result = $this->call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
406 foreach ($this->errors as $errmsg) {
407 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
408 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
410 $this->db->rollback();
428 $sql .=
" t.entity,";
431 $sql .=
" t.fk_product,";
432 $sql .=
" t.fk_soc,";
433 $sql .=
" t.ref_customer,";
435 $sql .=
" t.price_ttc,";
436 $sql .=
" t.price_min,";
437 $sql .=
" t.price_min_ttc,";
438 $sql .=
" t.price_base_type,";
439 $sql .=
" t.default_vat_code,";
440 $sql .=
" t.tva_tx,";
441 $sql .=
" t.recuperableonly,";
442 $sql .=
" t.localtax1_tx,";
443 $sql .=
" t.localtax2_tx,";
444 $sql .=
" t.discount_percent,";
445 $sql .=
" t.date_begin,";
446 $sql .=
" t.date_end,";
447 $sql .=
" t.fk_user,";
448 $sql .=
" t.price_label,";
449 $sql .=
" t.import_key";
450 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
451 $sql .=
" WHERE t.rowid = ".((int) $id);
453 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
454 $resql = $this->db->query($sql);
456 if ($this->db->num_rows($resql)) {
457 $obj = $this->db->fetch_object($resql);
459 $this->
id = $obj->rowid;
461 $this->entity = $obj->entity;
462 $this->datec = $this->db->jdate($obj->datec);
463 $this->tms = $this->db->jdate($obj->tms);
464 $this->date_modification = $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);
578 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
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->date_modification = $this->db->jdate($obj->tms);
605 $line->fk_product = $obj->fk_product;
606 $line->fk_soc = $obj->fk_soc;
607 $line->ref_customer = $obj->ref_customer;
608 $line->price = $obj->price;
609 $line->price_ttc = $obj->price_ttc;
610 $line->price_min = $obj->price_min;
611 $line->price_min_ttc = $obj->price_min_ttc;
612 $line->price_base_type = $obj->price_base_type;
613 $line->default_vat_code = $obj->default_vat_code;
614 $line->tva_tx = $obj->tva_tx;
615 $line->recuperableonly = $obj->recuperableonly;
616 $line->localtax1_tx = $obj->localtax1_tx;
617 $line->localtax2_tx = $obj->localtax2_tx;
618 $line->localtax1_type = $obj->localtax1_type;
619 $line->localtax2_type = $obj->localtax2_type;
620 $line->discount_percent = $obj->discount_percent;
621 $line->date_begin = $this->db->jdate($obj->date_begin);
622 $line->date_end = $this->db->jdate($obj->date_end);
623 $line->fk_user = $obj->fk_user;
624 $line->price_label = $obj->price_label;
625 $line->import_key = $obj->import_key;
626 $line->socname = $obj->socname;
627 $line->prodref = $obj->prodref;
629 $this->lines[] = $line;
631 $this->db->free($resql);
635 $this->error =
"Error ".$this->db->lasterror();
650 public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array())
652 if (empty($sortfield)) {
653 $sortfield =
"t.date_begin";
655 if (empty($sortorder)) {
661 $sql .=
" t.entity,";
663 $sql .=
" t.fk_product,";
664 $sql .=
" t.fk_soc,";
665 $sql .=
" t.ref_customer,";
667 $sql .=
" t.price_ttc,";
668 $sql .=
" t.price_min,";
669 $sql .=
" t.price_min_ttc,";
670 $sql .=
" t.price_base_type,";
671 $sql .=
" t.default_vat_code,";
672 $sql .=
" t.tva_tx,";
673 $sql .=
" t.recuperableonly,";
674 $sql .=
" t.localtax1_tx,";
675 $sql .=
" t.localtax2_tx,";
676 $sql .=
" t.discount_percent,";
677 $sql .=
" t.date_begin,";
678 $sql .=
" t.date_end,";
679 $sql .=
" t.fk_user,";
680 $sql .=
" t.price_label,";
681 $sql .=
" t.import_key,";
682 $sql .=
" soc.nom as socname,";
683 $sql .=
" prod.ref as prodref";
684 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
685 $sql .=
" ,".$this->db->prefix().
"product as prod";
686 $sql .=
" ,".$this->db->prefix().
"societe as soc";
687 $sql .=
" WHERE soc.rowid=t.fk_soc";
688 $sql .=
" AND prod.rowid=t.fk_product ";
689 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
690 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
692 if (count($filter) > 0) {
693 foreach ($filter as $key => $value) {
694 if (strpos($key,
'date')) {
695 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
696 } elseif ($key ==
'soc.nom') {
697 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($value).
"%'";
699 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((int) $value);
703 $sql .= $this->db->order($sortfield, $sortorder);
704 if (!empty($limit)) {
705 $sql .= $this->db->plimit($limit + 1, $offset);
708 dol_syslog(get_class($this).
"::fetchAllLog", LOG_DEBUG);
709 $resql = $this->db->query($sql);
711 $this->lines = array();
712 $num = $this->db->num_rows($resql);
714 while ($obj = $this->db->fetch_object($resql)) {
717 $line->id = $obj->rowid;
719 $line->entity = $obj->entity;
720 $line->datec = $this->db->jdate($obj->datec);
721 $line->tms = $this->db->jdate($obj->tms);
722 $line->date_modification = $this->db->jdate($obj->tms);
723 $line->fk_product = $obj->fk_product;
724 $line->fk_soc = $obj->fk_soc;
725 $line->ref_customer = $obj->ref_customer;
726 $line->price = $obj->price;
727 $line->price_ttc = $obj->price_ttc;
728 $line->price_min = $obj->price_min;
729 $line->price_min_ttc = $obj->price_min_ttc;
730 $line->price_base_type = $obj->price_base_type;
731 $line->default_vat_code = $obj->default_vat_code;
732 $line->tva_tx = $obj->tva_tx;
733 $line->recuperableonly = $obj->recuperableonly;
734 $line->localtax1_tx = $obj->localtax1_tx;
735 $line->localtax2_tx = $obj->localtax2_tx;
736 $line->discount_percent = $obj->discount_percent;
737 $line->date_begin = $this->db->jdate($obj->date_begin);
738 $line->date_end = $this->db->jdate($obj->date_end);
739 $line->fk_user = $obj->fk_user;
740 $line->price_label = $obj->price_label;
741 $line->import_key = $obj->import_key;
742 $line->socname = $obj->socname;
743 $line->prodref = $obj->prodref;
745 $this->lines [] = $line;
747 $this->db->free($resql);
751 $this->error =
"Error ".$this->db->lasterror();
764 public function update(
User $user, $notrigger = 0, $forceupdateaffiliate = 0)
772 if (isset($this->entity)) {
773 $this->entity = (int) $this->entity;
775 if (isset($this->fk_product)) {
776 $this->fk_product = (int) $this->fk_product;
778 if (isset($this->fk_soc)) {
779 $this->fk_soc = (int) $this->fk_soc;
781 if (isset($this->ref_customer)) {
782 $this->ref_customer = trim($this->ref_customer);
784 if (isset($this->
price)) {
787 if (isset($this->price_ttc)) {
788 $this->price_ttc = trim((
string) $this->price_ttc);
790 if (isset($this->price_min)) {
791 $this->price_min = trim((
string) $this->price_min);
793 if (isset($this->price_min_ttc)) {
794 $this->price_min_ttc = trim((
string) $this->price_min_ttc);
796 if (isset($this->price_base_type)) {
797 $this->price_base_type = trim($this->price_base_type);
799 if (isset($this->tva_tx)) {
800 $this->tva_tx = trim($this->tva_tx);
802 if (isset($this->recuperableonly)) {
803 $this->recuperableonly = trim((
string) $this->recuperableonly);
805 if (isset($this->localtax1_tx)) {
806 $this->localtax1_tx = trim((
string) $this->localtax1_tx);
808 if (isset($this->localtax2_tx)) {
809 $this->localtax2_tx = trim((
string) $this->localtax2_tx);
811 if (empty($this->discount_percent) || !is_numeric($this->discount_percent)) {
812 $this->discount_percent = 0;
814 if (empty($this->date_begin)) {
815 $this->date_begin = $now;
817 if (isset($this->fk_user)) {
818 $this->fk_user = (int) $this->fk_user;
820 if (isset($this->price_label)) {
821 $this->price_label = trim($this->price_label);
823 if (isset($this->import_key)) {
824 $this->import_key = trim($this->import_key);
834 if ($this->
price !=
'' || $this->
price == 0) {
835 $vatRate = (float) $this->tva_tx;
836 if ($this->price_base_type ==
'TTC') {
841 if ($this->price_min !=
'' || $this->price_min == 0) {
842 $this->price_min_ttc =
price2num($this->price_min,
'MU');
843 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
844 $this->price_min =
price2num($this->price_min,
'MU');
846 $this->price_min = 0;
847 $this->price_min_ttc = 0;
851 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
852 $this->price_ttc =
price2num($this->price_ttc,
'MU');
854 if ($this->price_min !=
'' || $this->price_min == 0) {
855 $this->price_min =
price2num($this->price_min,
'MU');
856 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
857 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
860 $this->price_min = 0;
861 $this->price_min_ttc = 0;
868 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
871 $sql .=
"fk_product,";
873 $sql .=
"ref_customer,";
875 $sql .=
"price_ttc,";
876 $sql .=
"price_min,";
877 $sql .=
"price_min_ttc,";
878 $sql .=
"price_base_type,";
879 $sql .=
"default_vat_code,";
881 $sql .=
"recuperableonly,";
882 $sql .=
"localtax1_tx,";
883 $sql .=
"localtax2_tx,";
884 $sql .=
"localtax1_type,";
885 $sql .=
"localtax2_type,";
886 $sql .=
"discount_percent,";
887 $sql .=
"date_begin,";
890 $sql .=
"price_label,";
891 $sql .=
"import_key";
894 $sql .=
" t.entity,";
896 $sql .=
" t.fk_product,";
897 $sql .=
" t.fk_soc,";
898 $sql .=
" t.ref_customer,";
900 $sql .=
" t.price_ttc,";
901 $sql .=
" t.price_min,";
902 $sql .=
" t.price_min_ttc,";
903 $sql .=
" t.price_base_type,";
904 $sql .=
" t.default_vat_code,";
905 $sql .=
" t.tva_tx,";
906 $sql .=
" t.recuperableonly,";
907 $sql .=
" t.localtax1_tx,";
908 $sql .=
" t.localtax2_tx,";
909 $sql .=
" t.localtax1_type,";
910 $sql .=
" t.localtax2_type,";
911 $sql .=
" t.discount_percent,";
912 $sql .=
" t.date_begin,";
913 $sql .=
" t.date_end,";
914 $sql .=
" t.fk_user,";
915 $sql .=
" t.price_label,";
916 $sql .=
" t.import_key";
917 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
918 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
921 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
922 $resql = $this->db->query($sql);
925 $this->errors [] =
"Error ".$this->db->lasterror();
929 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
930 $sql .=
" entity=".((int)
$conf->entity).
",";
931 $sql .=
" datec='".$this->db->idate($now).
"',";
932 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
933 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
934 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
935 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
936 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
937 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
938 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
939 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
940 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
941 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
942 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
943 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
944 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ?
"'0'" :
"'".$this->db->escape($this->localtax1_tx).
"'") :
"null").
",";
945 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ?
"'0'" :
"'".$this->db->escape($this->localtax2_tx).
"'") :
"null").
",";
946 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
947 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
948 $sql .=
" discount_percent=".(!empty($this->discount_percent) ?
"'".price2num($this->discount_percent).
"'" :
"0").
",";
949 $sql .=
" date_begin='".$this->db->idate($this->date_begin).
"',";
950 $sql .=
" date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
951 $sql .=
" fk_user=".((int) $user->id).
",";
952 $sql .=
" price_label=".(isset($this->price_label) ?
"'".$this->db->escape($this->price_label).
"'" :
"null").
",";
953 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
955 $sql .=
" WHERE rowid=".((int) $this->
id);
957 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
958 $resql = $this->db->query($sql);
961 $this->errors [] =
"Error ".$this->db->lasterror();
964 if (!$error && !$notrigger) {
966 $result = $this->call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
982 foreach ($this->errors as $errmsg) {
983 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
984 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
986 $this->db->rollback();
1003 if (
getDolGlobalString(
'PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES')) {
1010 $sql =
"SELECT s.rowid";
1011 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
1012 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
1013 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
1015 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
1016 $resql = $this->db->query($sql);
1019 $this->lines = array();
1020 $num = $this->db->num_rows($resql);
1022 while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
1027 't.fk_product' => (
string) $this->fk_product,
't.fk_soc' => (
string) $obj->rowid
1030 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
1033 $this->error = $prodsocprice->error;
1036 if (count($prodsocprice->lines) > 0) {
1038 if (!empty($forceupdateaffiliate)) {
1040 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
1042 $prodsocpriceupd->price = $this->price;
1043 $prodsocpriceupd->price_min = $this->price_min;
1044 $prodsocpriceupd->price_base_type = $this->price_base_type;
1045 $prodsocpriceupd->tva_tx = $this->tva_tx;
1046 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
1047 $prodsocpriceupd->price_label = $this->price_label;
1048 $prodsocpriceupd->discount_percent = $this->discount_percent;
1049 $prodsocpriceupd->date_begin = $this->date_begin;
1050 $prodsocpriceupd->date_end = $this->date_end;
1052 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
1053 if ($resultupd < 0) {
1055 $this->error = $prodsocpriceupd->error;
1061 $prodsocpricenew->fk_soc = $obj->rowid;
1062 $prodsocpricenew->ref_customer = $obj->ref_customer;
1063 $prodsocpricenew->fk_product = $this->fk_product;
1064 $prodsocpricenew->price = $this->price;
1065 $prodsocpricenew->price_min = $this->price_min;
1066 $prodsocpricenew->price_base_type = $this->price_base_type;
1067 $prodsocpricenew->tva_tx = $this->tva_tx;
1068 $prodsocpricenew->recuperableonly = $this->recuperableonly;
1069 $prodsocpricenew->price_label = $this->price_label;
1070 $prodsocpricenew->discount_percent = $this->discount_percent;
1071 $prodsocpricenew->date_begin = $this->date_begin;
1072 $prodsocpricenew->date_end = $this->date_end;
1074 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
1075 if ($resultupd < 0) {
1077 $this->error = $prodsocpricenew->error;
1082 $this->db->free($resql);
1084 if (empty($error)) {
1090 $this->error =
"Error ".$this->db->lasterror();