169 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
171 global
$conf, $langs;
176 if (isset($this->entity)) {
177 $this->entity = (int) $this->entity;
179 if (isset($this->fk_product)) {
180 $this->fk_product = (int) $this->fk_product;
182 if (isset($this->fk_soc)) {
183 $this->fk_soc = (int) $this->fk_soc;
185 if (isset($this->ref_customer)) {
186 $this->ref_customer = trim($this->ref_customer);
188 if (isset($this->
price)) {
191 if (isset($this->price_ttc)) {
192 $this->price_ttc = trim($this->price_ttc);
194 if (isset($this->price_min)) {
195 $this->price_min = trim($this->price_min);
197 if (isset($this->price_min_ttc)) {
198 $this->price_min_ttc = trim($this->price_min_ttc);
200 if (isset($this->price_base_type)) {
201 $this->price_base_type = trim($this->price_base_type);
203 if (isset($this->tva_tx)) {
204 $this->tva_tx = trim($this->tva_tx);
206 if (isset($this->recuperableonly)) {
207 $this->recuperableonly = trim($this->recuperableonly);
209 if (isset($this->localtax1_tx)) {
210 $this->localtax1_tx = trim($this->localtax1_tx);
212 if (isset($this->localtax2_tx)) {
213 $this->localtax2_tx = trim($this->localtax2_tx);
215 if (isset($this->fk_user)) {
216 $this->fk_user = (int) $this->fk_user;
218 if (isset($this->price_label)) {
219 $this->price_label = trim($this->price_label);
221 if (isset($this->import_key)) {
222 $this->import_key = trim($this->import_key);
228 if ($this->
price !=
'' || $this->
price == 0) {
229 $vatRate = (float) $this->tva_tx;
230 if ($this->price_base_type ==
'TTC') {
235 if ($this->price_min !=
'' || $this->price_min == 0) {
236 $this->price_min_ttc =
price2num($this->price_min,
'MU');
237 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
238 $this->price_min =
price2num($this->price_min,
'MU');
240 $this->price_min = 0;
241 $this->price_min_ttc = 0;
245 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
246 $this->price_ttc =
price2num($this->price_ttc,
'MU');
248 if ($this->price_min !=
'' || $this->price_min == 0) {
249 $this->price_min =
price2num($this->price_min,
'MU');
250 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
251 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
254 $this->price_min = 0;
255 $this->price_min_ttc = 0;
261 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
264 $sql .=
"fk_product,";
266 $sql .=
'ref_customer,';
268 $sql .=
"price_ttc,";
269 $sql .=
"price_min,";
270 $sql .=
"price_min_ttc,";
271 $sql .=
"price_base_type,";
272 $sql .=
"default_vat_code,";
274 $sql .=
"recuperableonly,";
275 $sql .=
"localtax1_type,";
276 $sql .=
"localtax1_tx,";
277 $sql .=
"localtax2_type,";
278 $sql .=
"localtax2_tx,";
280 $sql .=
"price_label,";
281 $sql .=
"import_key";
282 $sql .=
") VALUES (";
283 $sql .=
" ".((int)
$conf->entity).
",";
284 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
285 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
286 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' :
"'".$this->db->escape($this->fk_soc).
"'").
",";
287 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
288 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
289 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
290 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
291 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
292 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
293 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
294 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
295 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
296 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
297 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).
",";
298 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
299 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).
",";
300 $sql .=
" ".((int) $user->id).
",";
301 $sql .=
" ".(!isset($this->price_label) ?
'NULL' :
"'".$this->db->escape($this->price_label).
"'").
",";
302 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
307 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
308 $resql = $this->db->query($sql);
311 $this->errors [] =
"Error ".$this->db->lasterror();
315 $this->
id = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
318 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
334 foreach ($this->errors as $errmsg) {
335 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
336 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
338 $this->db->rollback();
358 $sql .=
" t.entity,";
361 $sql .=
" t.fk_product,";
362 $sql .=
" t.fk_soc,";
363 $sql .=
" t.ref_customer,";
365 $sql .=
" t.price_ttc,";
366 $sql .=
" t.price_min,";
367 $sql .=
" t.price_min_ttc,";
368 $sql .=
" t.price_base_type,";
369 $sql .=
" t.default_vat_code,";
370 $sql .=
" t.tva_tx,";
371 $sql .=
" t.recuperableonly,";
372 $sql .=
" t.localtax1_tx,";
373 $sql .=
" t.localtax2_tx,";
374 $sql .=
" t.fk_user,";
375 $sql .=
" t.price_label,";
376 $sql .=
" t.import_key";
377 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
378 $sql .=
" WHERE t.rowid = ".((int) $id);
380 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
381 $resql = $this->db->query($sql);
383 if ($this->db->num_rows($resql)) {
384 $obj = $this->db->fetch_object($resql);
386 $this->
id = $obj->rowid;
388 $this->entity = $obj->entity;
389 $this->datec = $this->db->jdate($obj->datec);
390 $this->tms = $this->db->jdate($obj->tms);
391 $this->fk_product = $obj->fk_product;
392 $this->fk_soc = $obj->fk_soc;
393 $this->ref_customer = $obj->ref_customer;
394 $this->
price = $obj->price;
395 $this->price_ttc = $obj->price_ttc;
396 $this->price_min = $obj->price_min;
397 $this->price_min_ttc = $obj->price_min_ttc;
398 $this->price_base_type = $obj->price_base_type;
399 $this->default_vat_code = $obj->default_vat_code;
400 $this->tva_tx = $obj->tva_tx;
401 $this->recuperableonly = $obj->recuperableonly;
402 $this->localtax1_tx = $obj->localtax1_tx;
403 $this->localtax2_tx = $obj->localtax2_tx;
404 $this->fk_user = $obj->fk_user;
405 $this->price_label = $obj->price_label;
406 $this->import_key = $obj->import_key;
408 $this->db->free($resql);
412 $this->db->free($resql);
417 $this->error =
"Error ".$this->db->lasterror();
433 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'')
435 if (empty($sortfield)) {
436 $sortfield =
"t.rowid";
438 if (empty($sortorder)) {
444 $sql .=
" t.entity,";
447 $sql .=
" t.fk_product,";
448 $sql .=
" t.fk_soc,";
449 $sql .=
" t.ref_customer,";
451 $sql .=
" t.price_ttc,";
452 $sql .=
" t.price_min,";
453 $sql .=
" t.price_min_ttc,";
454 $sql .=
" t.price_base_type,";
455 $sql .=
" t.default_vat_code,";
456 $sql .=
" t.tva_tx,";
457 $sql .=
" t.recuperableonly,";
458 $sql .=
" t.localtax1_tx,";
459 $sql .=
" t.localtax2_tx,";
460 $sql .=
" t.localtax1_type,";
461 $sql .=
" t.localtax2_type,";
462 $sql .=
" t.fk_user,";
463 $sql .=
" t.price_label,";
464 $sql .=
" t.import_key,";
465 $sql .=
" soc.nom as socname,";
466 $sql .=
" prod.ref as prodref";
467 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
468 $sql .=
" ".$this->db->prefix().
"product as prod,";
469 $sql .=
" ".$this->db->prefix().
"societe as soc";
470 $sql .=
" WHERE soc.rowid=t.fk_soc ";
471 $sql .=
" AND prod.rowid=t.fk_product ";
472 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
473 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
476 if (is_array($filter)) {
477 if (count($filter) > 0) {
478 foreach ($filter as $key => $value) {
479 if (strpos($key,
'date')) {
480 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape($value).
"'";
481 } elseif ($key ==
'soc.nom') {
482 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
483 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
484 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike($value)).
"%'";
485 } elseif ($key ==
't.price' || $key ==
't.price_ttc') {
486 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((float)
price2num($value));
488 $sql .=
" AND ".$this->db->sanitize($key).
" = ".((int) $value);
500 $this->errors[] = $errormessage;
501 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
505 $sql .= $this->db->order($sortfield, $sortorder);
506 if (!empty($limit)) {
507 $sql .= $this->db->plimit($limit + 1, $offset);
510 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
511 $resql = $this->db->query($sql);
513 $this->lines = array();
514 $num = $this->db->num_rows($resql);
516 while ($obj = $this->db->fetch_object($resql)) {
519 $line->id = $obj->rowid;
521 $line->entity = $obj->entity;
522 $line->datec = $this->db->jdate($obj->datec);
523 $line->tms = $this->db->jdate($obj->tms);
524 $line->fk_product = $obj->fk_product;
525 $line->fk_soc = $obj->fk_soc;
526 $line->ref_customer = $obj->ref_customer;
527 $line->price = $obj->price;
528 $line->price_ttc = $obj->price_ttc;
529 $line->price_min = $obj->price_min;
530 $line->price_min_ttc = $obj->price_min_ttc;
531 $line->price_base_type = $obj->price_base_type;
532 $line->default_vat_code = $obj->default_vat_code;
533 $line->tva_tx = $obj->tva_tx;
534 $line->recuperableonly = $obj->recuperableonly;
535 $line->localtax1_tx = $obj->localtax1_tx;
536 $line->localtax2_tx = $obj->localtax2_tx;
537 $line->localtax1_type = $obj->localtax1_type;
538 $line->localtax2_type = $obj->localtax2_type;
539 $line->fk_user = $obj->fk_user;
540 $line->price_label = $obj->price_label;
541 $line->import_key = $obj->import_key;
542 $line->socname = $obj->socname;
543 $line->prodref = $obj->prodref;
545 $this->lines[] = $line;
547 $this->db->free($resql);
551 $this->error =
"Error ".$this->db->lasterror();
566 public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array())
568 if (!empty($sortfield)) {
569 $sortfield =
"t.rowid";
571 if (!empty($sortorder)) {
577 $sql .=
" t.entity,";
579 $sql .=
" t.fk_product,";
580 $sql .=
" t.fk_soc,";
581 $sql .=
" t.ref_customer,";
583 $sql .=
" t.price_ttc,";
584 $sql .=
" t.price_min,";
585 $sql .=
" t.price_min_ttc,";
586 $sql .=
" t.price_base_type,";
587 $sql .=
" t.default_vat_code,";
588 $sql .=
" t.tva_tx,";
589 $sql .=
" t.recuperableonly,";
590 $sql .=
" t.localtax1_tx,";
591 $sql .=
" t.localtax2_tx,";
592 $sql .=
" t.fk_user,";
593 $sql .=
" t.price_label,";
594 $sql .=
" t.import_key,";
595 $sql .=
" soc.nom as socname,";
596 $sql .=
" prod.ref as prodref";
597 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
598 $sql .=
" ,".$this->db->prefix().
"product as prod";
599 $sql .=
" ,".$this->db->prefix().
"societe as soc";
600 $sql .=
" WHERE soc.rowid=t.fk_soc";
601 $sql .=
" AND prod.rowid=t.fk_product ";
602 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
603 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
605 if (count($filter) > 0) {
606 foreach ($filter as $key => $value) {
607 if (strpos($key,
'date')) {
608 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
609 } elseif ($key ==
'soc.nom') {
610 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
612 $sql .=
" AND ".$key.
" = ".((int) $value);
616 $sql .= $this->db->order($sortfield, $sortorder);
617 if (!empty($limit)) {
618 $sql .= $this->db->plimit($limit + 1, $offset);
621 dol_syslog(get_class($this).
"::fetchAllLog", LOG_DEBUG);
622 $resql = $this->db->query($sql);
624 $this->lines = array();
625 $num = $this->db->num_rows($resql);
627 while ($obj = $this->db->fetch_object($resql)) {
630 $line->id = $obj->rowid;
632 $line->entity = $obj->entity;
633 $line->datec = $this->db->jdate($obj->datec);
634 $line->tms = $this->db->jdate($obj->tms);
635 $line->fk_product = $obj->fk_product;
636 $line->fk_soc = $obj->fk_soc;
637 $line->ref_customer = $obj->ref_customer;
638 $line->price = $obj->price;
639 $line->price_ttc = $obj->price_ttc;
640 $line->price_min = $obj->price_min;
641 $line->price_min_ttc = $obj->price_min_ttc;
642 $line->price_base_type = $obj->price_base_type;
643 $line->default_vat_code = $obj->default_vat_code;
644 $line->tva_tx = $obj->tva_tx;
645 $line->recuperableonly = $obj->recuperableonly;
646 $line->localtax1_tx = $obj->localtax1_tx;
647 $line->localtax2_tx = $obj->localtax2_tx;
648 $line->fk_user = $obj->fk_user;
649 $line->price_label = $obj->price_label;
650 $line->import_key = $obj->import_key;
651 $line->socname = $obj->socname;
652 $line->prodref = $obj->prodref;
654 $this->lines [] = $line;
656 $this->db->free($resql);
660 $this->error =
"Error ".$this->db->lasterror();
673 public function update(
User $user, $notrigger = 0, $forceupdateaffiliate = 0)
675 global
$conf, $langs;
680 if (isset($this->entity)) {
681 $this->entity = (int) $this->entity;
683 if (isset($this->fk_product)) {
684 $this->fk_product = (int) $this->fk_product;
686 if (isset($this->fk_soc)) {
687 $this->fk_soc = (int) $this->fk_soc;
689 if (isset($this->ref_customer)) {
690 $this->ref_customer = trim($this->ref_customer);
692 if (isset($this->
price)) {
695 if (isset($this->price_ttc)) {
696 $this->price_ttc = trim((
string) $this->price_ttc);
698 if (isset($this->price_min)) {
699 $this->price_min = trim((
string) $this->price_min);
701 if (isset($this->price_min_ttc)) {
702 $this->price_min_ttc = trim((
string) $this->price_min_ttc);
704 if (isset($this->price_base_type)) {
705 $this->price_base_type = trim($this->price_base_type);
707 if (isset($this->tva_tx)) {
708 $this->tva_tx = trim($this->tva_tx);
710 if (isset($this->recuperableonly)) {
711 $this->recuperableonly = trim((
string) $this->recuperableonly);
713 if (isset($this->localtax1_tx)) {
714 $this->localtax1_tx = trim((
string) $this->localtax1_tx);
716 if (isset($this->localtax2_tx)) {
717 $this->localtax2_tx = trim((
string) $this->localtax2_tx);
719 if (isset($this->fk_user)) {
720 $this->fk_user = (int) $this->fk_user;
722 if (isset($this->price_label)) {
723 $this->price_label = trim($this->price_label);
725 if (isset($this->import_key)) {
726 $this->import_key = trim($this->import_key);
732 if ($this->
price !=
'' || $this->
price == 0) {
733 $vatRate = (float) $this->tva_tx;
734 if ($this->price_base_type ==
'TTC') {
739 if ($this->price_min !=
'' || $this->price_min == 0) {
740 $this->price_min_ttc =
price2num($this->price_min,
'MU');
741 $this->price_min = (float)
price2num($this->price_min) / (1 + ($vatRate / 100));
742 $this->price_min =
price2num($this->price_min,
'MU');
744 $this->price_min = 0;
745 $this->price_min_ttc = 0;
749 $this->price_ttc = ($this->recuperableonly != 1) ? (
float)
price2num($this->
price) * (1 + ($vatRate / 100)) : $this->price;
750 $this->price_ttc =
price2num($this->price_ttc,
'MU');
752 if ($this->price_min !=
'' || $this->price_min == 0) {
753 $this->price_min =
price2num($this->price_min,
'MU');
754 $this->price_min_ttc = (float)
price2num($this->price_min) * (1 + ($vatRate / 100));
755 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
758 $this->price_min = 0;
759 $this->price_min_ttc = 0;
766 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
770 $sql .=
"fk_product,";
772 $sql .=
"ref_customer,";
774 $sql .=
"price_ttc,";
775 $sql .=
"price_min,";
776 $sql .=
"price_min_ttc,";
777 $sql .=
"price_base_type,";
778 $sql .=
"default_vat_code,";
780 $sql .=
"recuperableonly,";
781 $sql .=
"localtax1_tx,";
782 $sql .=
"localtax2_tx,";
783 $sql .=
"localtax1_type,";
784 $sql .=
"localtax2_type,";
786 $sql .=
"price_label,";
787 $sql .=
"import_key";
792 $sql .=
" t.entity,";
794 $sql .=
" t.fk_product,";
795 $sql .=
" t.fk_soc,";
796 $sql .=
" t.ref_customer,";
798 $sql .=
" t.price_ttc,";
799 $sql .=
" t.price_min,";
800 $sql .=
" t.price_min_ttc,";
801 $sql .=
" t.price_base_type,";
802 $sql .=
" t.default_vat_code,";
803 $sql .=
" t.tva_tx,";
804 $sql .=
" t.recuperableonly,";
805 $sql .=
" t.localtax1_tx,";
806 $sql .=
" t.localtax2_tx,";
807 $sql .=
" t.localtax1_type,";
808 $sql .=
" t.localtax2_type,";
809 $sql .=
" t.fk_user,";
810 $sql .=
" t.price_label,";
811 $sql .=
" t.import_key";
813 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
814 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
817 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
818 $resql = $this->db->query($sql);
821 $this->errors [] =
"Error ".$this->db->lasterror();
825 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
827 $sql .=
" entity=".((int)
$conf->entity).
",";
828 $sql .=
" datec='".$this->db->idate(
dol_now()).
"',";
829 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
830 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
831 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
832 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
833 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
834 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
835 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
836 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
837 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
838 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
839 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
840 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
841 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
842 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
843 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
844 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
845 $sql .=
" fk_user=".((int) $user->id).
",";
846 $sql .=
" price_label=".(isset($this->price_label) ?
"'".$this->db->escape($this->price_label).
"'" :
"null").
",";
847 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
849 $sql .=
" WHERE rowid=".((int) $this->
id);
851 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
852 $resql = $this->db->query($sql);
855 $this->errors [] =
"Error ".$this->db->lasterror();
858 if (!$error && !$notrigger) {
860 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
876 foreach ($this->errors as $errmsg) {
877 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
878 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
880 $this->db->rollback();
897 if (
getDolGlobalString(
'PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES')) {
904 $sql =
"SELECT s.rowid";
905 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
906 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
907 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
909 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
910 $resql = $this->db->query($sql);
913 $this->lines = array();
914 $num = $this->db->num_rows($resql);
916 while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
921 't.fk_product' => $this->fk_product,
't.fk_soc' => $obj->rowid
924 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
927 $this->error = $prodsocprice->error;
930 if (count($prodsocprice->lines) > 0) {
932 if (!empty($forceupdateaffiliate)) {
934 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
936 $prodsocpriceupd->price = $this->price;
937 $prodsocpriceupd->price_min = $this->price_min;
938 $prodsocpriceupd->price_base_type = $this->price_base_type;
939 $prodsocpriceupd->tva_tx = $this->tva_tx;
940 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
941 $prodsocpriceupd->price_label = $this->price_label;
943 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
944 if ($resultupd < 0) {
946 $this->error = $prodsocpriceupd->error;
952 $prodsocpricenew->fk_soc = $obj->rowid;
953 $prodsocpricenew->ref_customer = $obj->ref_customer;
954 $prodsocpricenew->fk_product = $this->fk_product;
955 $prodsocpricenew->price = $this->price;
956 $prodsocpricenew->price_min = $this->price_min;
957 $prodsocpricenew->price_base_type = $this->price_base_type;
958 $prodsocpricenew->tva_tx = $this->tva_tx;
959 $prodsocpricenew->recuperableonly = $this->recuperableonly;
960 $prodsocpricenew->price_label = $this->price_label;
962 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
963 if ($resultupd < 0) {
965 $this->error = $prodsocpricenew->error;
970 $this->db->free($resql);
978 $this->error =
"Error ".$this->db->lasterror();