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;
69 public $default_vat_code;
71 public $recuperableonly;
72 public $localtax1_type;
74 public $localtax2_type;
85 public $lines = array();
106 public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
109 global $conf, $langs;
114 if (isset($this->entity)) {
115 $this->entity = trim($this->entity);
117 if (isset($this->fk_product)) {
118 $this->fk_product = trim($this->fk_product);
120 if (isset($this->fk_soc)) {
121 $this->fk_soc = trim($this->fk_soc);
123 if (isset($this->ref_customer)) {
124 $this->ref_customer = trim($this->ref_customer);
126 if (isset($this->
price)) {
129 if (isset($this->price_ttc)) {
130 $this->price_ttc = trim($this->price_ttc);
132 if (isset($this->price_min)) {
133 $this->price_min = trim($this->price_min);
135 if (isset($this->price_min_ttc)) {
136 $this->price_min_ttc = trim($this->price_min_ttc);
138 if (isset($this->price_base_type)) {
139 $this->price_base_type = trim($this->price_base_type);
141 if (isset($this->tva_tx)) {
142 $this->tva_tx = (
float) $this->tva_tx;
144 if (isset($this->recuperableonly)) {
145 $this->recuperableonly = trim($this->recuperableonly);
147 if (isset($this->localtax1_tx)) {
148 $this->localtax1_tx = trim($this->localtax1_tx);
150 if (isset($this->localtax2_tx)) {
151 $this->localtax2_tx = trim($this->localtax2_tx);
153 if (isset($this->fk_user)) {
154 $this->fk_user = trim($this->fk_user);
156 if (isset($this->import_key)) {
157 $this->import_key = trim($this->import_key);
163 if ($this->
price !=
'' || $this->
price == 0) {
164 if ($this->price_base_type ==
'TTC') {
169 if ($this->price_min !=
'' || $this->price_min == 0) {
170 $this->price_min_ttc =
price2num($this->price_min,
'MU');
171 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
172 $this->price_min =
price2num($this->price_min,
'MU');
174 $this->price_min = 0;
175 $this->price_min_ttc = 0;
179 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
180 $this->price_ttc =
price2num($this->price_ttc,
'MU');
182 if ($this->price_min !=
'' || $this->price_min == 0) {
183 $this->price_min =
price2num($this->price_min,
'MU');
184 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
185 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
188 $this->price_min = 0;
189 $this->price_min_ttc = 0;
195 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price(";
198 $sql .=
"fk_product,";
200 $sql .=
'ref_customer,';
202 $sql .=
"price_ttc,";
203 $sql .=
"price_min,";
204 $sql .=
"price_min_ttc,";
205 $sql .=
"price_base_type,";
206 $sql .=
"default_vat_code,";
208 $sql .=
"recuperableonly,";
209 $sql .=
"localtax1_type,";
210 $sql .=
"localtax1_tx,";
211 $sql .=
"localtax2_type,";
212 $sql .=
"localtax2_tx,";
214 $sql .=
"import_key";
215 $sql .=
") VALUES (";
216 $sql .=
" ".((int) $conf->entity).
",";
218 $sql .=
" ".(!isset($this->fk_product) ?
'NULL' :
"'".$this->db->escape($this->fk_product).
"'").
",";
219 $sql .=
" ".(!isset($this->fk_soc) ?
'NULL' :
"'".$this->db->escape($this->fk_soc).
"'").
",";
220 $sql .=
" ".(!isset($this->ref_customer) ?
'NULL' :
"'".$this->db->escape($this->ref_customer).
"'").
",";
221 $sql .=
" ".(empty($this->
price) ?
'0' :
"'".$this->db->escape($this->
price).
"'").
",";
222 $sql .=
" ".(empty($this->price_ttc) ?
'0' :
"'".$this->db->escape($this->price_ttc).
"'").
",";
223 $sql .=
" ".(empty($this->price_min) ?
'0' :
"'".$this->db->escape($this->price_min).
"'").
",";
224 $sql .=
" ".(empty($this->price_min_ttc) ?
'0' :
"'".$this->db->escape($this->price_min_ttc).
"'").
",";
225 $sql .=
" ".(!isset($this->price_base_type) ?
'NULL' :
"'".$this->db->escape($this->price_base_type).
"'").
",";
226 $sql .=
" ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
227 $sql .=
" ".(!isset($this->tva_tx) ?
'NULL' : (empty($this->tva_tx) ? 0 : $this->tva_tx)).
",";
228 $sql .=
" ".(!isset($this->recuperableonly) ?
'NULL' :
"'".$this->db->escape($this->recuperableonly).
"'").
",";
229 $sql .=
" ".(empty($this->localtax1_type) ?
"'0'" :
"'".$this->db->escape($this->localtax1_type).
"'").
",";
230 $sql .=
" ".(!isset($this->localtax1_tx) ?
'NULL' : (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx)).
",";
231 $sql .=
" ".(empty($this->localtax2_type) ?
"'0'" :
"'".$this->db->escape($this->localtax2_type).
"'").
",";
232 $sql .=
" ".(!isset($this->localtax2_tx) ?
'NULL' : (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx)).
",";
233 $sql .=
" ".((int) $user->id).
",";
234 $sql .=
" ".(!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
239 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
240 $resql = $this->db->query(
$sql);
243 $this->errors [] =
"Error ".$this->db->lasterror();
247 $this->
id = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
250 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_CREATE', $user);
266 foreach ($this->errors as $errmsg) {
267 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
268 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
270 $this->db->rollback();
290 $sql .=
" t.entity,";
293 $sql .=
" t.fk_product,";
294 $sql .=
" t.fk_soc,";
295 $sql .=
" t.ref_customer,";
297 $sql .=
" t.price_ttc,";
298 $sql .=
" t.price_min,";
299 $sql .=
" t.price_min_ttc,";
300 $sql .=
" t.price_base_type,";
301 $sql .=
" t.default_vat_code,";
302 $sql .=
" t.tva_tx,";
303 $sql .=
" t.recuperableonly,";
304 $sql .=
" t.localtax1_tx,";
305 $sql .=
" t.localtax2_tx,";
306 $sql .=
" t.fk_user,";
307 $sql .=
" t.import_key";
308 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
309 $sql .=
" WHERE t.rowid = ".((int) $id);
311 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
312 $resql = $this->db->query(
$sql);
314 if ($this->db->num_rows($resql)) {
315 $obj = $this->db->fetch_object($resql);
317 $this->
id = $obj->rowid;
319 $this->entity = $obj->entity;
320 $this->datec = $this->db->jdate($obj->datec);
321 $this->tms = $this->db->jdate($obj->tms);
322 $this->fk_product = $obj->fk_product;
323 $this->fk_soc = $obj->fk_soc;
324 $this->ref_customer = $obj->ref_customer;
325 $this->
price = $obj->price;
326 $this->price_ttc = $obj->price_ttc;
327 $this->price_min = $obj->price_min;
328 $this->price_min_ttc = $obj->price_min_ttc;
329 $this->price_base_type = $obj->price_base_type;
330 $this->default_vat_code = $obj->default_vat_code;
331 $this->tva_tx = $obj->tva_tx;
332 $this->recuperableonly = $obj->recuperableonly;
333 $this->localtax1_tx = $obj->localtax1_tx;
334 $this->localtax2_tx = $obj->localtax2_tx;
335 $this->fk_user = $obj->fk_user;
336 $this->import_key = $obj->import_key;
338 $this->db->free($resql);
342 $this->db->free($resql);
347 $this->error =
"Error ".$this->db->lasterror();
364 public function fetch_all($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array())
368 dol_syslog(get_class($this).
"::fetch_all is deprecated, use fetchAll instead", LOG_NOTICE);
370 return $this->
fetchAll($sortorder, $sortfield, $limit, $offset, $filter);
384 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array())
388 if (empty($sortfield)) {
389 $sortfield =
"t.rowid";
391 if (empty($sortorder)) {
397 $sql .=
" t.entity,";
400 $sql .=
" t.fk_product,";
401 $sql .=
" t.fk_soc,";
402 $sql .=
" t.ref_customer,";
404 $sql .=
" t.price_ttc,";
405 $sql .=
" t.price_min,";
406 $sql .=
" t.price_min_ttc,";
407 $sql .=
" t.price_base_type,";
408 $sql .=
" t.default_vat_code,";
409 $sql .=
" t.tva_tx,";
410 $sql .=
" t.recuperableonly,";
411 $sql .=
" t.localtax1_tx,";
412 $sql .=
" t.localtax2_tx,";
413 $sql .=
" t.localtax1_type,";
414 $sql .=
" t.localtax2_type,";
415 $sql .=
" t.fk_user,";
416 $sql .=
" t.import_key,";
417 $sql .=
" soc.nom as socname,";
418 $sql .=
" prod.ref as prodref";
419 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
420 $sql .=
" ".$this->db->prefix().
"product as prod,";
421 $sql .=
" ".$this->db->prefix().
"societe as soc";
422 $sql .=
" WHERE soc.rowid=t.fk_soc ";
423 $sql .=
" AND prod.rowid=t.fk_product ";
424 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
425 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
428 if (count($filter) > 0) {
429 foreach ($filter as $key => $value) {
430 if (strpos($key,
'date')) {
431 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
432 } elseif ($key ==
'soc.nom') {
433 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
434 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
435 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
436 } elseif ($key ==
't.price' || $key ==
't.price_ttc') {
439 $sql .=
" AND ".$key.
" = ".((int) $value);
443 $sql .= $this->db->order($sortfield, $sortorder);
444 if (!empty($limit)) {
445 $sql .= $this->db->plimit($limit + 1, $offset);
448 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
449 $resql = $this->db->query(
$sql);
451 $this->lines = array();
452 $num = $this->db->num_rows($resql);
454 while ($obj = $this->db->fetch_object($resql)) {
457 $line->id = $obj->rowid;
459 $line->entity = $obj->entity;
460 $line->datec = $this->db->jdate($obj->datec);
461 $line->tms = $this->db->jdate($obj->tms);
462 $line->fk_product = $obj->fk_product;
463 $line->fk_soc = $obj->fk_soc;
464 $line->ref_customer = $obj->ref_customer;
465 $line->price = $obj->price;
466 $line->price_ttc = $obj->price_ttc;
467 $line->price_min = $obj->price_min;
468 $line->price_min_ttc = $obj->price_min_ttc;
469 $line->price_base_type = $obj->price_base_type;
470 $line->default_vat_code = $obj->default_vat_code;
471 $line->tva_tx = $obj->tva_tx;
472 $line->recuperableonly = $obj->recuperableonly;
473 $line->localtax1_tx = $obj->localtax1_tx;
474 $line->localtax2_tx = $obj->localtax2_tx;
475 $line->localtax1_type = $obj->localtax1_type;
476 $line->localtax2_type = $obj->localtax2_type;
477 $line->fk_user = $obj->fk_user;
478 $line->import_key = $obj->import_key;
479 $line->socname = $obj->socname;
480 $line->prodref = $obj->prodref;
482 $this->lines[] = $line;
484 $this->db->free($resql);
488 $this->error =
"Error ".$this->db->lasterror();
504 public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = array())
509 if (!empty($sortfield)) {
510 $sortfield =
"t.rowid";
512 if (!empty($sortorder)) {
518 $sql .=
" t.entity,";
520 $sql .=
" t.fk_product,";
521 $sql .=
" t.fk_soc,";
522 $sql .=
" t.ref_customer,";
524 $sql .=
" t.price_ttc,";
525 $sql .=
" t.price_min,";
526 $sql .=
" t.price_min_ttc,";
527 $sql .=
" t.price_base_type,";
528 $sql .=
" t.default_vat_code,";
529 $sql .=
" t.tva_tx,";
530 $sql .=
" t.recuperableonly,";
531 $sql .=
" t.localtax1_tx,";
532 $sql .=
" t.localtax2_tx,";
533 $sql .=
" t.fk_user,";
534 $sql .=
" t.import_key,";
535 $sql .=
" soc.nom as socname,";
536 $sql .=
" prod.ref as prodref";
537 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
538 $sql .=
" ,".$this->db->prefix().
"product as prod";
539 $sql .=
" ,".$this->db->prefix().
"societe as soc";
540 $sql .=
" WHERE soc.rowid=t.fk_soc";
541 $sql .=
" AND prod.rowid=t.fk_product ";
542 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
543 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
545 if (count($filter) > 0) {
546 foreach ($filter as $key => $value) {
547 if (strpos($key,
'date')) {
548 $sql .=
" AND ".$key.
" = '".$this->db->escape($value).
"'";
549 } elseif ($key ==
'soc.nom') {
550 $sql .=
" AND ".$key.
" LIKE '%".$this->db->escape($value).
"%'";
552 $sql .=
" AND ".$key.
" = ".((int) $value);
556 $sql .= $this->db->order($sortfield, $sortorder);
557 if (!empty($limit)) {
558 $sql .= $this->db->plimit($limit + 1, $offset);
561 dol_syslog(get_class($this).
"::fetch_all_log", LOG_DEBUG);
562 $resql = $this->db->query(
$sql);
564 $this->lines = array();
565 $num = $this->db->num_rows($resql);
567 while ($obj = $this->db->fetch_object($resql)) {
570 $line->id = $obj->rowid;
572 $line->entity = $obj->entity;
573 $line->datec = $this->db->jdate($obj->datec);
574 $line->tms = $this->db->jdate($obj->tms);
575 $line->fk_product = $obj->fk_product;
576 $line->fk_soc = $obj->fk_soc;
577 $line->ref_customer = $obj->ref_customer;
578 $line->price = $obj->price;
579 $line->price_ttc = $obj->price_ttc;
580 $line->price_min = $obj->price_min;
581 $line->price_min_ttc = $obj->price_min_ttc;
582 $line->price_base_type = $obj->price_base_type;
583 $line->default_vat_code = $obj->default_vat_code;
584 $line->tva_tx = $obj->tva_tx;
585 $line->recuperableonly = $obj->recuperableonly;
586 $line->localtax1_tx = $obj->localtax1_tx;
587 $line->localtax2_tx = $obj->localtax2_tx;
588 $line->fk_user = $obj->fk_user;
589 $line->import_key = $obj->import_key;
590 $line->socname = $obj->socname;
591 $line->prodref = $obj->prodref;
593 $this->lines [] = $line;
595 $this->db->free($resql);
599 $this->error =
"Error ".$this->db->lasterror();
612 public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0)
615 global $conf, $langs;
620 if (isset($this->entity)) {
621 $this->entity = trim($this->entity);
623 if (isset($this->fk_product)) {
624 $this->fk_product = trim($this->fk_product);
626 if (isset($this->fk_soc)) {
627 $this->fk_soc = trim($this->fk_soc);
629 if (isset($this->ref_customer)) {
630 $this->ref_customer = trim($this->ref_customer);
632 if (isset($this->
price)) {
635 if (isset($this->price_ttc)) {
636 $this->price_ttc = trim($this->price_ttc);
638 if (isset($this->price_min)) {
639 $this->price_min = trim($this->price_min);
641 if (isset($this->price_min_ttc)) {
642 $this->price_min_ttc = trim($this->price_min_ttc);
644 if (isset($this->price_base_type)) {
645 $this->price_base_type = trim($this->price_base_type);
647 if (isset($this->tva_tx)) {
648 $this->tva_tx = (
float) $this->tva_tx;
650 if (isset($this->recuperableonly)) {
651 $this->recuperableonly = trim($this->recuperableonly);
653 if (isset($this->localtax1_tx)) {
654 $this->localtax1_tx = trim($this->localtax1_tx);
656 if (isset($this->localtax2_tx)) {
657 $this->localtax2_tx = trim($this->localtax2_tx);
659 if (isset($this->fk_user)) {
660 $this->fk_user = trim($this->fk_user);
662 if (isset($this->import_key)) {
663 $this->import_key = trim($this->import_key);
669 if ($this->
price !=
'' || $this->
price == 0) {
670 if ($this->price_base_type ==
'TTC') {
675 if ($this->price_min !=
'' || $this->price_min == 0) {
676 $this->price_min_ttc =
price2num($this->price_min,
'MU');
677 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
678 $this->price_min =
price2num($this->price_min,
'MU');
680 $this->price_min = 0;
681 $this->price_min_ttc = 0;
685 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
686 $this->price_ttc =
price2num($this->price_ttc,
'MU');
688 if ($this->price_min !=
'' || $this->price_min == 0) {
689 $this->price_min =
price2num($this->price_min,
'MU');
690 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
691 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
694 $this->price_min = 0;
695 $this->price_min_ttc = 0;
702 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
706 $sql .=
"fk_product,";
708 $sql .=
"ref_customer,";
710 $sql .=
"price_ttc,";
711 $sql .=
"price_min,";
712 $sql .=
"price_min_ttc,";
713 $sql .=
"price_base_type,";
714 $sql .=
"default_vat_code,";
716 $sql .=
"recuperableonly,";
717 $sql .=
"localtax1_tx,";
718 $sql .=
"localtax2_tx,";
719 $sql .=
"localtax1_type,";
720 $sql .=
"localtax2_type,";
722 $sql .=
"import_key";
727 $sql .=
" t.entity,";
729 $sql .=
" t.fk_product,";
730 $sql .=
" t.fk_soc,";
731 $sql .=
" t.ref_customer,";
733 $sql .=
" t.price_ttc,";
734 $sql .=
" t.price_min,";
735 $sql .=
" t.price_min_ttc,";
736 $sql .=
" t.price_base_type,";
737 $sql .=
" t.default_vat_code,";
738 $sql .=
" t.tva_tx,";
739 $sql .=
" t.recuperableonly,";
740 $sql .=
" t.localtax1_tx,";
741 $sql .=
" t.localtax2_tx,";
742 $sql .=
" t.localtax1_type,";
743 $sql .=
" t.localtax2_type,";
744 $sql .=
" t.fk_user,";
745 $sql .=
" t.import_key";
747 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
748 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
751 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
752 $resql = $this->db->query(
$sql);
755 $this->errors [] =
"Error ".$this->db->lasterror();
759 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
761 $sql .=
" entity=".$conf->entity.
",";
762 $sql .=
" datec='".$this->db->idate(
dol_now()).
"',";
763 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
764 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
765 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
766 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
767 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
768 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
769 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
770 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
771 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
772 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
773 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
774 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
775 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
776 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
777 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
778 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
779 $sql .=
" fk_user=".$user->id.
",";
780 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
782 $sql .=
" WHERE rowid=".((int) $this->
id);
784 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
785 $resql = $this->db->query(
$sql);
788 $this->errors [] =
"Error ".$this->db->lasterror();
791 if (!$error && !$notrigger) {
793 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
809 foreach ($this->errors as $errmsg) {
810 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
811 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
813 $this->db->rollback();
832 if (!empty($conf->global->PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES)) {
839 $sql =
"SELECT s.rowid";
840 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
841 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
842 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
844 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
845 $resql = $this->db->query(
$sql);
848 $this->lines = array();
849 $num = $this->db->num_rows($resql);
851 while (($obj = $this->db->fetch_object($resql)) && (empty($error))) {
856 't.fk_product' => $this->fk_product,
't.fk_soc' => $obj->rowid
859 $result = $prodsocprice->fetchAll(
'',
'', 0, 0, $filter);
862 $this->error = $prodsocprice->error;
865 if (count($prodsocprice->lines) > 0) {
867 if (!empty($forceupdateaffiliate)) {
869 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
871 $prodsocpriceupd->price = $this->price;
872 $prodsocpriceupd->price_min = $this->price_min;
873 $prodsocpriceupd->price_base_type = $this->price_base_type;
874 $prodsocpriceupd->tva_tx = $this->tva_tx;
875 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
877 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
878 if ($resultupd < 0) {
880 $this->error = $prodsocpriceupd->error;
886 $prodsocpricenew->fk_soc = $obj->rowid;
887 $prodsocpricenew->ref_customer = $obj->ref_customer;
888 $prodsocpricenew->fk_product = $this->fk_product;
889 $prodsocpricenew->price = $this->price;
890 $prodsocpricenew->price_min = $this->price_min;
891 $prodsocpricenew->price_base_type = $this->price_base_type;
892 $prodsocpricenew->tva_tx = $this->tva_tx;
893 $prodsocpricenew->recuperableonly = $this->recuperableonly;
895 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
896 if ($resultupd < 0) {
898 $this->error = $prodsocpricenew->error;
903 $this->db->free($resql);
911 $this->error =
"Error ".$this->db->lasterror();
923 public function delete($user, $notrigger = 0)
925 global $conf, $langs;
931 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_DELETE', $user);
938 $sql =
"DELETE FROM ".$this->db->prefix().
"product_customer_price";
939 $sql .=
" WHERE rowid=".((int) $this->
id);
941 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
942 $resql = $this->db->query(
$sql);
945 $this->errors [] =
"Error ".$this->db->lasterror();
951 foreach ($this->errors as $errmsg) {
952 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
953 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
955 $this->db->rollback();
979 $object->fetch($fromid);
987 $object->context[
'createfromclone'] =
'createfromclone';
988 $result = $object->create($user);
992 $this->error = $object->error;
993 $this->errors = array_merge($this->errors, $object->errors);
1000 unset($object->context[
'createfromclone']);
1004 $this->db->commit();
1007 $this->db->rollback();
1026 $this->fk_product =
'';
1028 $this->ref_customer =
'';
1030 $this->price_ttc =
'';
1031 $this->price_min =
'';
1032 $this->price_min_ttc =
'';
1033 $this->price_base_type =
'';
1034 $this->default_vat_code =
'';
1036 $this->recuperableonly =
'';
1037 $this->localtax1_tx =
'';
1038 $this->localtax2_tx =
'';
1039 $this->fk_user =
'';
1040 $this->import_key =
'';
1070 public $ref_customer;
1080 public $price_min_ttc;
1081 public $price_base_type;
1082 public $default_vat_code;
1084 public $recuperableonly;
1085 public $localtax1_tx;
1086 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') && $user->hasRight('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') && $user->hasRight('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)) $sql
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.