127 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
129 global $conf, $langs;
134 if (isset($this->entity)) {
135 $this->entity = (int) $this->entity;
137 if (isset($this->fk_product)) {
138 $this->fk_product = (int) $this->fk_product;
140 if (isset($this->fk_soc)) {
141 $this->fk_soc = (int) $this->fk_soc;
143 if (isset($this->ref_customer)) {
144 $this->ref_customer = trim($this->ref_customer);
146 if (isset($this->
price)) {
149 if (isset($this->price_ttc)) {
150 $this->price_ttc = trim($this->price_ttc);
152 if (isset($this->price_min)) {
153 $this->price_min = trim($this->price_min);
155 if (isset($this->price_min_ttc)) {
156 $this->price_min_ttc = trim($this->price_min_ttc);
158 if (isset($this->price_base_type)) {
159 $this->price_base_type = trim($this->price_base_type);
161 if (isset($this->tva_tx)) {
162 $this->tva_tx = (float) $this->tva_tx;
164 if (isset($this->recuperableonly)) {
165 $this->recuperableonly = trim($this->recuperableonly);
167 if (isset($this->localtax1_tx)) {
168 $this->localtax1_tx = trim($this->localtax1_tx);
170 if (isset($this->localtax2_tx)) {
171 $this->localtax2_tx = trim($this->localtax2_tx);
173 if (isset($this->fk_user)) {
174 $this->fk_user = (int) $this->fk_user;
176 if (isset($this->price_label)) {
177 $this->price_label = trim($this->price_label);
179 if (isset($this->import_key)) {
180 $this->import_key = trim($this->import_key);
186 if ($this->
price !=
'' || $this->
price == 0) {
187 if ($this->price_base_type ==
'TTC') {
192 if ($this->price_min !=
'' || $this->price_min == 0) {
193 $this->price_min_ttc =
price2num($this->price_min,
'MU');
194 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
195 $this->price_min =
price2num($this->price_min,
'MU');
197 $this->price_min = 0;
198 $this->price_min_ttc = 0;
202 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
203 $this->price_ttc =
price2num($this->price_ttc,
'MU');
205 if ($this->price_min !=
'' || $this->price_min == 0) {
206 $this->price_min =
price2num($this->price_min,
'MU');
207 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
208 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
211 $this->price_min = 0;
212 $this->price_min_ttc = 0;
218 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
221 $sql .=
"fk_product,";
223 $sql .=
'ref_customer,';
225 $sql .=
"price_ttc,";
226 $sql .=
"price_min,";
227 $sql .=
"price_min_ttc,";
228 $sql .=
"price_base_type,";
229 $sql .=
"default_vat_code,";
231 $sql .=
"recuperableonly,";
232 $sql .=
"localtax1_type,";
233 $sql .=
"localtax1_tx,";
234 $sql .=
"localtax2_type,";
235 $sql .=
"localtax2_tx,";
237 $sql .=
"price_label,";
238 $sql .=
"import_key";
239 $sql .=
") VALUES (";
240 $sql .=
" ".((int) $conf->entity).
",";
241 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
242 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
243 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' :
"'".$this->db->escape($this->fk_soc).
"'").
",";
244 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
245 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
246 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
247 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
248 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
249 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
250 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
251 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
252 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
253 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
254 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).
",";
255 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
256 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).
",";
257 $sql .=
" ".((int) $user->id).
",";
258 $sql .=
" ".(!isset($this->price_label) ?
'NULL' :
"'".$this->db->escape($this->price_label).
"'").
",";
259 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
264 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
265 $resql = $this->db->query($sql);
268 $this->errors [] =
"Error ".$this->db->lasterror();
272 $this->
id = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
275 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
291 foreach ($this->errors as $errmsg) {
292 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
293 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
295 $this->db->rollback();
315 $sql .=
" t.entity,";
318 $sql .=
" t.fk_product,";
319 $sql .=
" t.fk_soc,";
320 $sql .=
" t.ref_customer,";
322 $sql .=
" t.price_ttc,";
323 $sql .=
" t.price_min,";
324 $sql .=
" t.price_min_ttc,";
325 $sql .=
" t.price_base_type,";
326 $sql .=
" t.default_vat_code,";
327 $sql .=
" t.tva_tx,";
328 $sql .=
" t.recuperableonly,";
329 $sql .=
" t.localtax1_tx,";
330 $sql .=
" t.localtax2_tx,";
331 $sql .=
" t.fk_user,";
332 $sql .=
" t.price_label,";
333 $sql .=
" t.import_key";
334 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
335 $sql .=
" WHERE t.rowid = ".((int) $id);
337 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
338 $resql = $this->db->query($sql);
340 if ($this->db->num_rows($resql)) {
341 $obj = $this->db->fetch_object($resql);
343 $this->
id = $obj->rowid;
345 $this->entity = $obj->entity;
346 $this->datec = $this->db->jdate($obj->datec);
347 $this->tms = $this->db->jdate($obj->tms);
348 $this->fk_product = $obj->fk_product;
349 $this->fk_soc = $obj->fk_soc;
350 $this->ref_customer = $obj->ref_customer;
351 $this->
price = $obj->price;
352 $this->price_ttc = $obj->price_ttc;
353 $this->price_min = $obj->price_min;
354 $this->price_min_ttc = $obj->price_min_ttc;
355 $this->price_base_type = $obj->price_base_type;
356 $this->default_vat_code = $obj->default_vat_code;
357 $this->tva_tx = $obj->tva_tx;
358 $this->recuperableonly = $obj->recuperableonly;
359 $this->localtax1_tx = $obj->localtax1_tx;
360 $this->localtax2_tx = $obj->localtax2_tx;
361 $this->fk_user = $obj->fk_user;
362 $this->price_label = $obj->price_label;
363 $this->import_key = $obj->import_key;
365 $this->db->free($resql);
369 $this->db->free($resql);
374 $this->error =
"Error ".$this->db->lasterror();
390 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'')
392 if (empty($sortfield)) {
393 $sortfield =
"t.rowid";
395 if (empty($sortorder)) {
401 $sql .=
" t.entity,";
404 $sql .=
" t.fk_product,";
405 $sql .=
" t.fk_soc,";
406 $sql .=
" t.ref_customer,";
408 $sql .=
" t.price_ttc,";
409 $sql .=
" t.price_min,";
410 $sql .=
" t.price_min_ttc,";
411 $sql .=
" t.price_base_type,";
412 $sql .=
" t.default_vat_code,";
413 $sql .=
" t.tva_tx,";
414 $sql .=
" t.recuperableonly,";
415 $sql .=
" t.localtax1_tx,";
416 $sql .=
" t.localtax2_tx,";
417 $sql .=
" t.localtax1_type,";
418 $sql .=
" t.localtax2_type,";
419 $sql .=
" t.fk_user,";
420 $sql .=
" t.price_label,";
421 $sql .=
" t.import_key,";
422 $sql .=
" soc.nom as socname,";
423 $sql .=
" prod.ref as prodref";
424 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
425 $sql .=
" ".$this->db->prefix().
"product as prod,";
426 $sql .=
" ".$this->db->prefix().
"societe as soc";
427 $sql .=
" WHERE soc.rowid=t.fk_soc ";
428 $sql .=
" AND prod.rowid=t.fk_product ";
429 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
430 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
433 if (is_array($filter)) {
434 if (count($filter) > 0) {
435 foreach ($filter as $key => $value) {
436 if (strpos($key,
'date')) {
437 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
438 } elseif ($key ==
'soc.nom') {
439 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
440 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
441 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
442 } elseif ($key ==
't.price' || $key ==
't.price_ttc') {
443 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((float)
price2num($value));
445 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((int) $value);
457 $this->errors[] = $errormessage;
458 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
462 $sql .= $this->db->order($sortfield, $sortorder);
463 if (!empty($limit)) {
464 $sql .= $this->db->plimit($limit + 1, $offset);
467 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
468 $resql = $this->db->query($sql);
470 $this->lines = array();
471 $num = $this->db->num_rows($resql);
473 while ($obj = $this->db->fetch_object($resql)) {
476 $line->id = $obj->rowid;
478 $line->entity = $obj->entity;
479 $line->datec = $this->db->jdate($obj->datec);
480 $line->tms = $this->db->jdate($obj->tms);
481 $line->fk_product = $obj->fk_product;
482 $line->fk_soc = $obj->fk_soc;
483 $line->ref_customer = $obj->ref_customer;
484 $line->price = $obj->price;
485 $line->price_ttc = $obj->price_ttc;
486 $line->price_min = $obj->price_min;
487 $line->price_min_ttc = $obj->price_min_ttc;
488 $line->price_base_type = $obj->price_base_type;
489 $line->default_vat_code = $obj->default_vat_code;
490 $line->tva_tx = $obj->tva_tx;
491 $line->recuperableonly = $obj->recuperableonly;
492 $line->localtax1_tx = $obj->localtax1_tx;
493 $line->localtax2_tx = $obj->localtax2_tx;
494 $line->localtax1_type = $obj->localtax1_type;
495 $line->localtax2_type = $obj->localtax2_type;
496 $line->fk_user = $obj->fk_user;
497 $line->price_label = $obj->price_label;
498 $line->import_key = $obj->import_key;
499 $line->socname = $obj->socname;
500 $line->prodref = $obj->prodref;
502 $this->lines[] = $line;
504 $this->db->free($resql);
508 $this->error =
"Error ".$this->db->lasterror();
523 public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array())
525 if (!empty($sortfield)) {
526 $sortfield =
"t.rowid";
528 if (!empty($sortorder)) {
534 $sql .=
" t.entity,";
536 $sql .=
" t.fk_product,";
537 $sql .=
" t.fk_soc,";
538 $sql .=
" t.ref_customer,";
540 $sql .=
" t.price_ttc,";
541 $sql .=
" t.price_min,";
542 $sql .=
" t.price_min_ttc,";
543 $sql .=
" t.price_base_type,";
544 $sql .=
" t.default_vat_code,";
545 $sql .=
" t.tva_tx,";
546 $sql .=
" t.recuperableonly,";
547 $sql .=
" t.localtax1_tx,";
548 $sql .=
" t.localtax2_tx,";
549 $sql .=
" t.fk_user,";
550 $sql .=
" t.price_label,";
551 $sql .=
" t.import_key,";
552 $sql .=
" soc.nom as socname,";
553 $sql .=
" prod.ref as prodref";
554 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
555 $sql .=
" ,".$this->db->prefix().
"product as prod";
556 $sql .=
" ,".$this->db->prefix().
"societe as soc";
557 $sql .=
" WHERE soc.rowid=t.fk_soc";
558 $sql .=
" AND prod.rowid=t.fk_product ";
559 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
560 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
562 if (count($filter) > 0) {
563 foreach ($filter as $key => $value) {
564 if (strpos($key,
'date')) {
565 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
566 } elseif ($key ==
'soc.nom') {
567 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
569 $sql .=
" AND ".$key.
" = ".((int) $value);
573 $sql .= $this->db->order($sortfield, $sortorder);
574 if (!empty($limit)) {
575 $sql .= $this->db->plimit($limit + 1, $offset);
578 dol_syslog(get_class($this).
"::fetchAllLog", LOG_DEBUG);
579 $resql = $this->db->query($sql);
581 $this->lines = array();
582 $num = $this->db->num_rows($resql);
584 while ($obj = $this->db->fetch_object($resql)) {
587 $line->id = $obj->rowid;
589 $line->entity = $obj->entity;
590 $line->datec = $this->db->jdate($obj->datec);
591 $line->tms = $this->db->jdate($obj->tms);
592 $line->fk_product = $obj->fk_product;
593 $line->fk_soc = $obj->fk_soc;
594 $line->ref_customer = $obj->ref_customer;
595 $line->price = $obj->price;
596 $line->price_ttc = $obj->price_ttc;
597 $line->price_min = $obj->price_min;
598 $line->price_min_ttc = $obj->price_min_ttc;
599 $line->price_base_type = $obj->price_base_type;
600 $line->default_vat_code = $obj->default_vat_code;
601 $line->tva_tx = $obj->tva_tx;
602 $line->recuperableonly = $obj->recuperableonly;
603 $line->localtax1_tx = $obj->localtax1_tx;
604 $line->localtax2_tx = $obj->localtax2_tx;
605 $line->fk_user = $obj->fk_user;
606 $line->price_label = $obj->price_label;
607 $line->import_key = $obj->import_key;
608 $line->socname = $obj->socname;
609 $line->prodref = $obj->prodref;
611 $this->lines [] = $line;
613 $this->db->free($resql);
617 $this->error =
"Error ".$this->db->lasterror();
630 public function update(
User $user, $notrigger = 0, $forceupdateaffiliate = 0)
632 global $conf, $langs;
637 if (isset($this->entity)) {
638 $this->entity = (int) $this->entity;
640 if (isset($this->fk_product)) {
641 $this->fk_product = (int) $this->fk_product;
643 if (isset($this->fk_soc)) {
644 $this->fk_soc = (int) $this->fk_soc;
646 if (isset($this->ref_customer)) {
647 $this->ref_customer = trim($this->ref_customer);
649 if (isset($this->
price)) {
652 if (isset($this->price_ttc)) {
653 $this->price_ttc = trim($this->price_ttc);
655 if (isset($this->price_min)) {
656 $this->price_min = trim($this->price_min);
658 if (isset($this->price_min_ttc)) {
659 $this->price_min_ttc = trim($this->price_min_ttc);
661 if (isset($this->price_base_type)) {
662 $this->price_base_type = trim($this->price_base_type);
664 if (isset($this->tva_tx)) {
665 $this->tva_tx = (float) $this->tva_tx;
667 if (isset($this->recuperableonly)) {
668 $this->recuperableonly = trim($this->recuperableonly);
670 if (isset($this->localtax1_tx)) {
671 $this->localtax1_tx = trim($this->localtax1_tx);
673 if (isset($this->localtax2_tx)) {
674 $this->localtax2_tx = trim($this->localtax2_tx);
676 if (isset($this->fk_user)) {
677 $this->fk_user = (int) $this->fk_user;
679 if (isset($this->price_label)) {
680 $this->price_label = trim($this->price_label);
682 if (isset($this->import_key)) {
683 $this->import_key = trim($this->import_key);
689 if ($this->
price !=
'' || $this->
price == 0) {
690 if ($this->price_base_type ==
'TTC') {
695 if ($this->price_min !=
'' || $this->price_min == 0) {
696 $this->price_min_ttc =
price2num($this->price_min,
'MU');
697 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
698 $this->price_min =
price2num($this->price_min,
'MU');
700 $this->price_min = 0;
701 $this->price_min_ttc = 0;
705 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
706 $this->price_ttc =
price2num($this->price_ttc,
'MU');
708 if ($this->price_min !=
'' || $this->price_min == 0) {
709 $this->price_min =
price2num($this->price_min,
'MU');
710 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
711 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
714 $this->price_min = 0;
715 $this->price_min_ttc = 0;
722 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
726 $sql .=
"fk_product,";
728 $sql .=
"ref_customer,";
730 $sql .=
"price_ttc,";
731 $sql .=
"price_min,";
732 $sql .=
"price_min_ttc,";
733 $sql .=
"price_base_type,";
734 $sql .=
"default_vat_code,";
736 $sql .=
"recuperableonly,";
737 $sql .=
"localtax1_tx,";
738 $sql .=
"localtax2_tx,";
739 $sql .=
"localtax1_type,";
740 $sql .=
"localtax2_type,";
742 $sql .=
"price_label,";
743 $sql .=
"import_key";
748 $sql .=
" t.entity,";
750 $sql .=
" t.fk_product,";
751 $sql .=
" t.fk_soc,";
752 $sql .=
" t.ref_customer,";
754 $sql .=
" t.price_ttc,";
755 $sql .=
" t.price_min,";
756 $sql .=
" t.price_min_ttc,";
757 $sql .=
" t.price_base_type,";
758 $sql .=
" t.default_vat_code,";
759 $sql .=
" t.tva_tx,";
760 $sql .=
" t.recuperableonly,";
761 $sql .=
" t.localtax1_tx,";
762 $sql .=
" t.localtax2_tx,";
763 $sql .=
" t.localtax1_type,";
764 $sql .=
" t.localtax2_type,";
765 $sql .=
" t.fk_user,";
766 $sql .=
" t.price_label,";
767 $sql .=
" t.import_key";
769 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
770 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
773 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
774 $resql = $this->db->query($sql);
777 $this->errors [] =
"Error ".$this->db->lasterror();
781 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
783 $sql .=
" entity=".$conf->entity.
",";
784 $sql .=
" datec='".$this->db->idate(
dol_now()).
"',";
785 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
786 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
787 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
788 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
789 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
790 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
791 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
792 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
793 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
794 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
795 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
796 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
797 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
798 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
799 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
800 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
801 $sql .=
" fk_user=".$user->id.
",";
802 $sql .=
" price_label=".(isset($this->price_label) ?
"'".$this->db->escape($this->price_label).
"'" :
"null").
",";
803 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
805 $sql .=
" WHERE rowid=".((int) $this->
id);
807 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
808 $resql = $this->db->query($sql);
811 $this->errors [] =
"Error ".$this->db->lasterror();
814 if (!$error && !$notrigger) {
816 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
832 foreach ($this->errors as $errmsg) {
833 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
834 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
836 $this->db->rollback();
855 if (
getDolGlobalString(
'PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES')) {
862 $sql =
"SELECT s.rowid";
863 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
864 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
865 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
867 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
868 $resql = $this->db->query($sql);
871 $this->lines = array();
872 $num = $this->db->num_rows($resql);
874 while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
879 't.fk_product' => $this->fk_product,
't.fk_soc' => $obj->rowid
882 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
885 $this->error = $prodsocprice->error;
888 if (count($prodsocprice->lines) > 0) {
890 if (!empty($forceupdateaffiliate)) {
892 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
894 $prodsocpriceupd->price = $this->price;
895 $prodsocpriceupd->price_min = $this->price_min;
896 $prodsocpriceupd->price_base_type = $this->price_base_type;
897 $prodsocpriceupd->tva_tx = $this->tva_tx;
898 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
899 $prodsocpriceupd->price_label = $this->price_label;
901 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
902 if ($resultupd < 0) {
904 $this->error = $prodsocpriceupd->error;
910 $prodsocpricenew->fk_soc = $obj->rowid;
911 $prodsocpricenew->ref_customer = $obj->ref_customer;
912 $prodsocpricenew->fk_product = $this->fk_product;
913 $prodsocpricenew->price = $this->price;
914 $prodsocpricenew->price_min = $this->price_min;
915 $prodsocpricenew->price_base_type = $this->price_base_type;
916 $prodsocpricenew->tva_tx = $this->tva_tx;
917 $prodsocpricenew->recuperableonly = $this->recuperableonly;
918 $prodsocpricenew->price_label = $this->price_label;
920 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
921 if ($resultupd < 0) {
923 $this->error = $prodsocpricenew->error;
928 $this->db->free($resql);
936 $this->error =
"Error ".$this->db->lasterror();