24 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
34 public $element =
'product_customer_price';
39 public $table_element =
'product_customer_price';
67 public $price_min_ttc;
68 public $price_base_type;
70 public $recuperableonly;
71 public $localtax1_type;
73 public $localtax2_type;
81 public $lines = array();
102 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
105 global $conf, $langs;
110 if (isset($this->entity)) {
111 $this->entity = trim($this->entity);
113 if (isset($this->fk_product)) {
114 $this->fk_product = trim($this->fk_product);
116 if (isset($this->fk_soc)) {
117 $this->fk_soc = trim($this->fk_soc);
119 if (isset($this->ref_customer)) {
120 $this->ref_customer = trim($this->ref_customer);
122 if (isset($this->
price)) {
125 if (isset($this->price_ttc)) {
126 $this->price_ttc = trim($this->price_ttc);
128 if (isset($this->price_min)) {
129 $this->price_min = trim($this->price_min);
131 if (isset($this->price_min_ttc)) {
132 $this->price_min_ttc = trim($this->price_min_ttc);
134 if (isset($this->price_base_type)) {
135 $this->price_base_type = trim($this->price_base_type);
137 if (isset($this->tva_tx)) {
138 $this->tva_tx = (
float) $this->tva_tx;
140 if (isset($this->recuperableonly)) {
141 $this->recuperableonly = trim($this->recuperableonly);
143 if (isset($this->localtax1_tx)) {
144 $this->localtax1_tx = trim($this->localtax1_tx);
146 if (isset($this->localtax2_tx)) {
147 $this->localtax2_tx = trim($this->localtax2_tx);
149 if (isset($this->fk_user)) {
150 $this->fk_user = trim($this->fk_user);
152 if (isset($this->import_key)) {
153 $this->import_key = trim($this->import_key);
159 if ($this->
price !=
'' || $this->
price == 0) {
160 if ($this->price_base_type ==
'TTC') {
165 if ($this->price_min !=
'' || $this->price_min == 0) {
166 $this->price_min_ttc =
price2num($this->price_min,
'MU');
167 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
168 $this->price_min =
price2num($this->price_min,
'MU');
170 $this->price_min = 0;
171 $this->price_min_ttc = 0;
175 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
176 $this->price_ttc =
price2num($this->price_ttc,
'MU');
178 if ($this->price_min !=
'' || $this->price_min == 0) {
179 $this->price_min =
price2num($this->price_min,
'MU');
180 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
181 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
184 $this->price_min = 0;
185 $this->price_min_ttc = 0;
191 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
194 $sql .=
"fk_product,";
196 $sql .=
'ref_customer,';
198 $sql .=
"price_ttc,";
199 $sql .=
"price_min,";
200 $sql .=
"price_min_ttc,";
201 $sql .=
"price_base_type,";
202 $sql .=
"default_vat_code,";
204 $sql .=
"recuperableonly,";
205 $sql .=
"localtax1_type,";
206 $sql .=
"localtax1_tx,";
207 $sql .=
"localtax2_type,";
208 $sql .=
"localtax2_tx,";
210 $sql .=
"import_key";
211 $sql .=
") VALUES (";
212 $sql .=
" ".((int) $conf->entity).
",";
213 $sql .=
" '".$this->db->idate(
dol_now()).
"',";
214 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
215 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' :
"'".$this->db->escape($this->fk_soc).
"'").
",";
216 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
217 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
218 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
219 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
220 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
221 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
222 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
223 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
224 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
225 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
226 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).
",";
227 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
228 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).
",";
229 $sql .=
" ".((int) $user->id).
",";
230 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
235 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
239 $this->errors [] =
"Error ".$this->db->lasterror();
243 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"product_customer_price");
246 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
262 foreach ($this->errors as $errmsg) {
263 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
264 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
266 $this->
db->rollback();
286 $sql .=
" t.entity,";
289 $sql .=
" t.fk_product,";
290 $sql .=
" t.fk_soc,";
291 $sql .=
" t.ref_customer,";
293 $sql .=
" t.price_ttc,";
294 $sql .=
" t.price_min,";
295 $sql .=
" t.price_min_ttc,";
296 $sql .=
" t.price_base_type,";
297 $sql .=
" t.default_vat_code,";
298 $sql .=
" t.tva_tx,";
299 $sql .=
" t.recuperableonly,";
300 $sql .=
" t.localtax1_tx,";
301 $sql .=
" t.localtax2_tx,";
302 $sql .=
" t.fk_user,";
303 $sql .=
" t.import_key";
304 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
305 $sql .=
" WHERE t.rowid = ".((int) $id);
307 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
311 $obj = $this->
db->fetch_object(
$resql);
313 $this->
id = $obj->rowid;
315 $this->entity = $obj->entity;
316 $this->datec = $this->
db->jdate($obj->datec);
317 $this->tms = $this->
db->jdate($obj->tms);
318 $this->fk_product = $obj->fk_product;
319 $this->fk_soc = $obj->fk_soc;
320 $this->ref_customer = $obj->ref_customer;
321 $this->
price = $obj->price;
322 $this->price_ttc = $obj->price_ttc;
323 $this->price_min = $obj->price_min;
324 $this->price_min_ttc = $obj->price_min_ttc;
325 $this->price_base_type = $obj->price_base_type;
326 $this->default_vat_code = $obj->default_vat_code;
327 $this->tva_tx = $obj->tva_tx;
328 $this->recuperableonly = $obj->recuperableonly;
329 $this->localtax1_tx = $obj->localtax1_tx;
330 $this->localtax2_tx = $obj->localtax2_tx;
331 $this->fk_user = $obj->fk_user;
332 $this->import_key = $obj->import_key;
343 $this->error =
"Error ".$this->db->lasterror();
360 public function fetch_all($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array())
364 dol_syslog(get_class($this).
"::fetch_all is deprecated, use fetchAll instead", LOG_NOTICE);
366 return $this->
fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
380 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array())
384 if (empty($sortfield)) {
385 $sortfield =
"t.rowid";
387 if (empty($sortorder)) {
393 $sql .=
" t.entity,";
396 $sql .=
" t.fk_product,";
397 $sql .=
" t.fk_soc,";
398 $sql .=
" t.ref_customer,";
400 $sql .=
" t.price_ttc,";
401 $sql .=
" t.price_min,";
402 $sql .=
" t.price_min_ttc,";
403 $sql .=
" t.price_base_type,";
404 $sql .=
" t.default_vat_code,";
405 $sql .=
" t.tva_tx,";
406 $sql .=
" t.recuperableonly,";
407 $sql .=
" t.localtax1_tx,";
408 $sql .=
" t.localtax2_tx,";
409 $sql .=
" t.localtax1_type,";
410 $sql .=
" t.localtax2_type,";
411 $sql .=
" t.fk_user,";
412 $sql .=
" t.import_key,";
413 $sql .=
" soc.nom as socname,";
414 $sql .=
" prod.ref as prodref";
415 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
416 $sql .=
" ".$this->db->prefix().
"product as prod,";
417 $sql .=
" ".$this->db->prefix().
"societe as soc";
418 $sql .=
" WHERE soc.rowid=t.fk_soc ";
419 $sql .=
" AND prod.rowid=t.fk_product ";
420 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
421 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
424 if (count($filter) > 0) {
425 foreach ($filter as $key => $value) {
426 if (strpos($key,
'date')) {
427 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
428 } elseif ($key ==
'soc.nom') {
429 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
430 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
431 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
432 } elseif ($key ==
't.price' || $key ==
't.price_ttc') {
433 $sql .=
" AND ".$key.
" LIKE '%".
price2num($value).
"%'";
435 $sql .=
" AND ".$key.
" = ".((int) $value);
439 $sql .= $this->
db->order($sortfield, $sortorder);
440 if (!empty($limit)) {
441 $sql .= $this->
db->plimit($limit + 1, $offset);
444 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
447 $this->lines = array();
450 while ($obj = $this->
db->fetch_object(
$resql)) {
453 $line->id = $obj->rowid;
455 $line->entity = $obj->entity;
456 $line->datec = $this->
db->jdate($obj->datec);
457 $line->tms = $this->
db->jdate($obj->tms);
458 $line->fk_product = $obj->fk_product;
459 $line->fk_soc = $obj->fk_soc;
460 $line->ref_customer = $obj->ref_customer;
461 $line->price = $obj->price;
462 $line->price_ttc = $obj->price_ttc;
463 $line->price_min = $obj->price_min;
464 $line->price_min_ttc = $obj->price_min_ttc;
465 $line->price_base_type = $obj->price_base_type;
466 $line->default_vat_code = $obj->default_vat_code;
467 $line->tva_tx = $obj->tva_tx;
468 $line->recuperableonly = $obj->recuperableonly;
469 $line->localtax1_tx = $obj->localtax1_tx;
470 $line->localtax2_tx = $obj->localtax2_tx;
471 $line->localtax1_type = $obj->localtax1_type;
472 $line->localtax2_type = $obj->localtax2_type;
473 $line->fk_user = $obj->fk_user;
474 $line->import_key = $obj->import_key;
475 $line->socname = $obj->socname;
476 $line->prodref = $obj->prodref;
478 $this->lines[] = $line;
484 $this->error =
"Error ".$this->db->lasterror();
500 public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = array())
505 if (!empty($sortfield)) {
506 $sortfield =
"t.rowid";
508 if (!empty($sortorder)) {
514 $sql .=
" t.entity,";
516 $sql .=
" t.fk_product,";
517 $sql .=
" t.fk_soc,";
518 $sql .=
" t.ref_customer,";
520 $sql .=
" t.price_ttc,";
521 $sql .=
" t.price_min,";
522 $sql .=
" t.price_min_ttc,";
523 $sql .=
" t.price_base_type,";
524 $sql .=
" t.default_vat_code,";
525 $sql .=
" t.tva_tx,";
526 $sql .=
" t.recuperableonly,";
527 $sql .=
" t.localtax1_tx,";
528 $sql .=
" t.localtax2_tx,";
529 $sql .=
" t.fk_user,";
530 $sql .=
" t.import_key,";
531 $sql .=
" soc.nom as socname,";
532 $sql .=
" prod.ref as prodref";
533 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
534 $sql .=
" ,".$this->db->prefix().
"product as prod";
535 $sql .=
" ,".$this->db->prefix().
"societe as soc";
536 $sql .=
" WHERE soc.rowid=t.fk_soc";
537 $sql .=
" AND prod.rowid=t.fk_product ";
538 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
539 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
541 if (count($filter) > 0) {
542 foreach ($filter as $key => $value) {
543 if (strpos($key,
'date')) {
544 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
545 } elseif ($key ==
'soc.nom') {
546 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
548 $sql .=
" AND ".$key.
" = ".((int) $value);
552 $sql .= $this->
db->order($sortfield, $sortorder);
553 if (!empty($limit)) {
554 $sql .= $this->
db->plimit($limit + 1, $offset);
557 dol_syslog(get_class($this).
"::fetch_all_log", LOG_DEBUG);
560 $this->lines = array();
563 while ($obj = $this->
db->fetch_object(
$resql)) {
566 $line->id = $obj->rowid;
568 $line->entity = $obj->entity;
569 $line->datec = $this->
db->jdate($obj->datec);
570 $line->tms = $this->
db->jdate($obj->tms);
571 $line->fk_product = $obj->fk_product;
572 $line->fk_soc = $obj->fk_soc;
573 $line->ref_customer = $obj->ref_customer;
574 $line->price = $obj->price;
575 $line->price_ttc = $obj->price_ttc;
576 $line->price_min = $obj->price_min;
577 $line->price_min_ttc = $obj->price_min_ttc;
578 $line->price_base_type = $obj->price_base_type;
579 $line->default_vat_code = $obj->default_vat_code;
580 $line->tva_tx = $obj->tva_tx;
581 $line->recuperableonly = $obj->recuperableonly;
582 $line->localtax1_tx = $obj->localtax1_tx;
583 $line->localtax2_tx = $obj->localtax2_tx;
584 $line->fk_user = $obj->fk_user;
585 $line->import_key = $obj->import_key;
586 $line->socname = $obj->socname;
587 $line->prodref = $obj->prodref;
589 $this->lines [] = $line;
595 $this->error =
"Error ".$this->db->lasterror();
608 public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0)
611 global $conf, $langs;
616 if (isset($this->entity)) {
617 $this->entity = trim($this->entity);
619 if (isset($this->fk_product)) {
620 $this->fk_product = trim($this->fk_product);
622 if (isset($this->fk_soc)) {
623 $this->fk_soc = trim($this->fk_soc);
625 if (isset($this->ref_customer)) {
626 $this->ref_customer = trim($this->ref_customer);
628 if (isset($this->
price)) {
631 if (isset($this->price_ttc)) {
632 $this->price_ttc = trim($this->price_ttc);
634 if (isset($this->price_min)) {
635 $this->price_min = trim($this->price_min);
637 if (isset($this->price_min_ttc)) {
638 $this->price_min_ttc = trim($this->price_min_ttc);
640 if (isset($this->price_base_type)) {
641 $this->price_base_type = trim($this->price_base_type);
643 if (isset($this->tva_tx)) {
644 $this->tva_tx = (
float) $this->tva_tx;
646 if (isset($this->recuperableonly)) {
647 $this->recuperableonly = trim($this->recuperableonly);
649 if (isset($this->localtax1_tx)) {
650 $this->localtax1_tx = trim($this->localtax1_tx);
652 if (isset($this->localtax2_tx)) {
653 $this->localtax2_tx = trim($this->localtax2_tx);
655 if (isset($this->fk_user)) {
656 $this->fk_user = trim($this->fk_user);
658 if (isset($this->import_key)) {
659 $this->import_key = trim($this->import_key);
665 if ($this->
price !=
'' || $this->
price == 0) {
666 if ($this->price_base_type ==
'TTC') {
671 if ($this->price_min !=
'' || $this->price_min == 0) {
672 $this->price_min_ttc =
price2num($this->price_min,
'MU');
673 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
674 $this->price_min =
price2num($this->price_min,
'MU');
676 $this->price_min = 0;
677 $this->price_min_ttc = 0;
681 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
682 $this->price_ttc =
price2num($this->price_ttc,
'MU');
684 if ($this->price_min !=
'' || $this->price_min == 0) {
685 $this->price_min =
price2num($this->price_min,
'MU');
686 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
687 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
690 $this->price_min = 0;
691 $this->price_min_ttc = 0;
698 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
702 $sql .=
"fk_product,";
704 $sql .=
"ref_customer,";
706 $sql .=
"price_ttc,";
707 $sql .=
"price_min,";
708 $sql .=
"price_min_ttc,";
709 $sql .=
"price_base_type,";
710 $sql .=
"default_vat_code,";
712 $sql .=
"recuperableonly,";
713 $sql .=
"localtax1_tx,";
714 $sql .=
"localtax2_tx,";
715 $sql .=
"localtax1_type,";
716 $sql .=
"localtax2_type,";
718 $sql .=
"import_key";
723 $sql .=
" t.entity,";
725 $sql .=
" t.fk_product,";
726 $sql .=
" t.fk_soc,";
727 $sql .=
" t.ref_customer,";
729 $sql .=
" t.price_ttc,";
730 $sql .=
" t.price_min,";
731 $sql .=
" t.price_min_ttc,";
732 $sql .=
" t.price_base_type,";
733 $sql .=
" t.default_vat_code,";
734 $sql .=
" t.tva_tx,";
735 $sql .=
" t.recuperableonly,";
736 $sql .=
" t.localtax1_tx,";
737 $sql .=
" t.localtax2_tx,";
738 $sql .=
" t.localtax1_type,";
739 $sql .=
" t.localtax2_type,";
740 $sql .=
" t.fk_user,";
741 $sql .=
" t.import_key";
743 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
744 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
747 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
751 $this->errors [] =
"Error ".$this->db->lasterror();
755 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
757 $sql .=
" entity=".$conf->entity.
",";
758 $sql .=
" datec='".$this->db->idate(
dol_now()).
"',";
759 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
760 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
761 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
762 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
763 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
764 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
765 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
766 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
767 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
768 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
769 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
770 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
771 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
772 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
773 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
774 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
775 $sql .=
" fk_user=".$user->id.
",";
776 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
778 $sql .=
" WHERE rowid=".((int) $this->
id);
780 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
784 $this->errors [] =
"Error ".$this->db->lasterror();
787 if (!$error && !$notrigger) {
789 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
805 foreach ($this->errors as $errmsg) {
806 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
807 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
809 $this->
db->rollback();
828 if (!empty($conf->global->PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES)) {
835 $sql =
"SELECT s.rowid";
836 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
837 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
838 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
840 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
844 $this->lines = array();
847 while (($obj = $this->
db->fetch_object(
$resql)) && (empty($error))) {
852 't.fk_product' => $this->fk_product,
't.fk_soc' => $obj->rowid
855 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
858 $this->error = $prodsocprice->error;
861 if (count($prodsocprice->lines) > 0) {
863 if (!empty($forceupdateaffiliate)) {
865 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
867 $prodsocpriceupd->price = $this->price;
868 $prodsocpriceupd->price_min = $this->price_min;
869 $prodsocpriceupd->price_base_type = $this->price_base_type;
870 $prodsocpriceupd->tva_tx = $this->tva_tx;
871 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
873 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
876 $this->error = $prodsocpriceupd->error;
882 $prodsocpricenew->fk_soc = $obj->rowid;
883 $prodsocpricenew->ref_customer = $obj->ref_customer;
884 $prodsocpricenew->fk_product = $this->fk_product;
885 $prodsocpricenew->price = $this->price;
886 $prodsocpricenew->price_min = $this->price_min;
887 $prodsocpricenew->price_base_type = $this->price_base_type;
888 $prodsocpricenew->tva_tx = $this->tva_tx;
889 $prodsocpricenew->recuperableonly = $this->recuperableonly;
891 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
894 $this->error = $prodsocpricenew->error;
907 $this->error =
"Error ".$this->db->lasterror();
919 public function delete($user, $notrigger = 0)
921 global $conf, $langs;
926 if (!$error && !$notrigger) {
927 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_DELETE', $user);
934 $sql =
"DELETE FROM ".$this->db->prefix().
"product_customer_price";
935 $sql .=
" WHERE rowid=".((int) $this->
id);
937 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
941 $this->errors [] =
"Error ".$this->db->lasterror();
947 foreach ($this->errors as $errmsg) {
948 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
949 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
951 $this->
db->rollback();
975 $object->fetch($fromid);
983 $object->context[
'createfromclone'] =
'createfromclone';
984 $result = $object->create($user);
988 $this->error = $object->error;
989 $this->errors = array_merge($this->errors, $object->errors);
996 unset($object->context[
'createfromclone']);
1000 $this->
db->commit();
1003 $this->
db->rollback();
1022 $this->fk_product =
'';
1024 $this->ref_customer =
'';
1026 $this->price_ttc =
'';
1027 $this->price_min =
'';
1028 $this->price_min_ttc =
'';
1029 $this->price_base_type =
'';
1030 $this->default_vat_code =
'';
1032 $this->recuperableonly =
'';
1033 $this->localtax1_tx =
'';
1034 $this->localtax2_tx =
'';
1035 $this->fk_user =
'';
1036 $this->import_key =
'';
1066 public $ref_customer;
1076 public $price_min_ttc;
1077 public $price_base_type;
1078 public $default_vat_code;
1080 public $recuperableonly;
1081 public $localtax1_tx;
1082 public $localtax2_tx;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
File of class to manage predefined price products or services by customer lines.
File of class to manage predefined price products or services by customer.
fetch_all($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array())
Load all customer prices in memory from database.
fetch($id)
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update($user=0, $notrigger=0, $forceupdateaffiliate=0)
Update object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array())
Load all customer prices in memory from database.
setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
Force update price on child companies so child company has same prices than parent.
create($user, $notrigger=0, $forceupdateaffiliate=0)
Create object into database.
__construct($db)
Constructor.
fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter=array())
Load all objects in memory from database.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div float
Buy price without taxes.
$conf db
API class for accounts.