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();
359 public function fetch_all($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array())
364 if (empty($sortfield)) {
365 $sortfield =
"t.rowid";
367 if (empty($sortorder)) {
373 $sql .=
" t.entity,";
376 $sql .=
" t.fk_product,";
377 $sql .=
" t.fk_soc,";
378 $sql .=
" t.ref_customer,";
380 $sql .=
" t.price_ttc,";
381 $sql .=
" t.price_min,";
382 $sql .=
" t.price_min_ttc,";
383 $sql .=
" t.price_base_type,";
384 $sql .=
" t.default_vat_code,";
385 $sql .=
" t.tva_tx,";
386 $sql .=
" t.recuperableonly,";
387 $sql .=
" t.localtax1_tx,";
388 $sql .=
" t.localtax2_tx,";
389 $sql .=
" t.localtax1_type,";
390 $sql .=
" t.localtax2_type,";
391 $sql .=
" t.fk_user,";
392 $sql .=
" t.import_key,";
393 $sql .=
" soc.nom as socname,";
394 $sql .=
" prod.ref as prodref";
395 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t,";
396 $sql .=
" ".$this->db->prefix().
"product as prod,";
397 $sql .=
" ".$this->db->prefix().
"societe as soc";
398 $sql .=
" WHERE soc.rowid=t.fk_soc ";
399 $sql .=
" AND prod.rowid=t.fk_product ";
400 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
401 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
404 if (count($filter) > 0) {
405 foreach ($filter as $key => $value) {
406 if (strpos($key,
'date')) {
407 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
408 } elseif ($key ==
'soc.nom') {
409 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
410 } elseif ($key ==
'prod.ref' || $key ==
'prod.label') {
411 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
412 } elseif ($key ==
't.price' || $key ==
't.price_ttc') {
413 $sql .=
" AND ".$key.
" LIKE '%".
price2num($value).
"%'";
415 $sql .=
" AND ".$key.
" = ".((int) $value);
419 $sql .= $this->
db->order($sortfield, $sortorder);
420 if (!empty($limit)) {
421 $sql .= $this->
db->plimit($limit + 1, $offset);
424 dol_syslog(get_class($this).
"::fetch_all", LOG_DEBUG);
427 $this->lines = array();
430 while ($obj = $this->
db->fetch_object(
$resql)) {
433 $line->id = $obj->rowid;
435 $line->entity = $obj->entity;
436 $line->datec = $this->
db->jdate($obj->datec);
437 $line->tms = $this->
db->jdate($obj->tms);
438 $line->fk_product = $obj->fk_product;
439 $line->fk_soc = $obj->fk_soc;
440 $line->ref_customer = $obj->ref_customer;
441 $line->price = $obj->price;
442 $line->price_ttc = $obj->price_ttc;
443 $line->price_min = $obj->price_min;
444 $line->price_min_ttc = $obj->price_min_ttc;
445 $line->price_base_type = $obj->price_base_type;
446 $line->default_vat_code = $obj->default_vat_code;
447 $line->tva_tx = $obj->tva_tx;
448 $line->recuperableonly = $obj->recuperableonly;
449 $line->localtax1_tx = $obj->localtax1_tx;
450 $line->localtax2_tx = $obj->localtax2_tx;
451 $line->localtax1_type = $obj->localtax1_type;
452 $line->localtax2_type = $obj->localtax2_type;
453 $line->fk_user = $obj->fk_user;
454 $line->import_key = $obj->import_key;
455 $line->socname = $obj->socname;
456 $line->prodref = $obj->prodref;
458 $this->lines[] = $line;
464 $this->error =
"Error ".$this->db->lasterror();
480 public function fetch_all_log($sortorder, $sortfield, $limit, $offset, $filter = array())
485 if (!empty($sortfield)) {
486 $sortfield =
"t.rowid";
488 if (!empty($sortorder)) {
494 $sql .=
" t.entity,";
496 $sql .=
" t.fk_product,";
497 $sql .=
" t.fk_soc,";
498 $sql .=
" t.ref_customer,";
500 $sql .=
" t.price_ttc,";
501 $sql .=
" t.price_min,";
502 $sql .=
" t.price_min_ttc,";
503 $sql .=
" t.price_base_type,";
504 $sql .=
" t.default_vat_code,";
505 $sql .=
" t.tva_tx,";
506 $sql .=
" t.recuperableonly,";
507 $sql .=
" t.localtax1_tx,";
508 $sql .=
" t.localtax2_tx,";
509 $sql .=
" t.fk_user,";
510 $sql .=
" t.import_key,";
511 $sql .=
" soc.nom as socname,";
512 $sql .=
" prod.ref as prodref";
513 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price_log as t";
514 $sql .=
" ,".$this->db->prefix().
"product as prod";
515 $sql .=
" ,".$this->db->prefix().
"societe as soc";
516 $sql .=
" WHERE soc.rowid=t.fk_soc";
517 $sql .=
" AND prod.rowid=t.fk_product ";
518 $sql .=
" AND prod.entity IN (".getEntity(
'product').
")";
519 $sql .=
" AND t.entity IN (".getEntity(
'productprice').
")";
521 if (count($filter) > 0) {
522 foreach ($filter as $key => $value) {
523 if (strpos($key,
'date')) {
524 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
525 } elseif ($key ==
'soc.nom') {
526 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
528 $sql .=
" AND ".$key.
" = ".((int) $value);
532 $sql .= $this->
db->order($sortfield, $sortorder);
533 if (!empty($limit)) {
534 $sql .= $this->
db->plimit($limit + 1, $offset);
537 dol_syslog(get_class($this).
"::fetch_all_log", LOG_DEBUG);
540 $this->lines = array();
543 while ($obj = $this->
db->fetch_object(
$resql)) {
546 $line->id = $obj->rowid;
548 $line->entity = $obj->entity;
549 $line->datec = $this->
db->jdate($obj->datec);
550 $line->tms = $this->
db->jdate($obj->tms);
551 $line->fk_product = $obj->fk_product;
552 $line->fk_soc = $obj->fk_soc;
553 $line->ref_customer = $obj->ref_customer;
554 $line->price = $obj->price;
555 $line->price_ttc = $obj->price_ttc;
556 $line->price_min = $obj->price_min;
557 $line->price_min_ttc = $obj->price_min_ttc;
558 $line->price_base_type = $obj->price_base_type;
559 $line->default_vat_code = $obj->default_vat_code;
560 $line->tva_tx = $obj->tva_tx;
561 $line->recuperableonly = $obj->recuperableonly;
562 $line->localtax1_tx = $obj->localtax1_tx;
563 $line->localtax2_tx = $obj->localtax2_tx;
564 $line->fk_user = $obj->fk_user;
565 $line->import_key = $obj->import_key;
566 $line->socname = $obj->socname;
567 $line->prodref = $obj->prodref;
569 $this->lines [] = $line;
575 $this->error =
"Error ".$this->db->lasterror();
588 public function update($user = 0, $notrigger = 0, $forceupdateaffiliate = 0)
591 global $conf, $langs;
596 if (isset($this->entity)) {
597 $this->entity = trim($this->entity);
599 if (isset($this->fk_product)) {
600 $this->fk_product = trim($this->fk_product);
602 if (isset($this->fk_soc)) {
603 $this->fk_soc = trim($this->fk_soc);
605 if (isset($this->ref_customer)) {
606 $this->ref_customer = trim($this->ref_customer);
608 if (isset($this->
price)) {
611 if (isset($this->price_ttc)) {
612 $this->price_ttc = trim($this->price_ttc);
614 if (isset($this->price_min)) {
615 $this->price_min = trim($this->price_min);
617 if (isset($this->price_min_ttc)) {
618 $this->price_min_ttc = trim($this->price_min_ttc);
620 if (isset($this->price_base_type)) {
621 $this->price_base_type = trim($this->price_base_type);
623 if (isset($this->tva_tx)) {
624 $this->tva_tx = (
float) $this->tva_tx;
626 if (isset($this->recuperableonly)) {
627 $this->recuperableonly = trim($this->recuperableonly);
629 if (isset($this->localtax1_tx)) {
630 $this->localtax1_tx = trim($this->localtax1_tx);
632 if (isset($this->localtax2_tx)) {
633 $this->localtax2_tx = trim($this->localtax2_tx);
635 if (isset($this->fk_user)) {
636 $this->fk_user = trim($this->fk_user);
638 if (isset($this->import_key)) {
639 $this->import_key = trim($this->import_key);
645 if ($this->
price !=
'' || $this->
price == 0) {
646 if ($this->price_base_type ==
'TTC') {
651 if ($this->price_min !=
'' || $this->price_min == 0) {
652 $this->price_min_ttc =
price2num($this->price_min,
'MU');
653 $this->price_min =
price2num($this->price_min) / (1 + ($this->tva_tx / 100));
654 $this->price_min =
price2num($this->price_min,
'MU');
656 $this->price_min = 0;
657 $this->price_min_ttc = 0;
661 $this->price_ttc = ($this->recuperableonly != 1) ?
price2num($this->
price) * (1 + ($this->tva_tx / 100)) : $this->price;
662 $this->price_ttc =
price2num($this->price_ttc,
'MU');
664 if ($this->price_min !=
'' || $this->price_min == 0) {
665 $this->price_min =
price2num($this->price_min,
'MU');
666 $this->price_min_ttc =
price2num($this->price_min) * (1 + ($this->tva_tx / 100));
667 $this->price_min_ttc =
price2num($this->price_min_ttc,
'MU');
670 $this->price_min = 0;
671 $this->price_min_ttc = 0;
678 $sql =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_log(";
682 $sql .=
"fk_product,";
684 $sql .=
"ref_customer,";
686 $sql .=
"price_ttc,";
687 $sql .=
"price_min,";
688 $sql .=
"price_min_ttc,";
689 $sql .=
"price_base_type,";
690 $sql .=
"default_vat_code,";
692 $sql .=
"recuperableonly,";
693 $sql .=
"localtax1_tx,";
694 $sql .=
"localtax2_tx,";
695 $sql .=
"localtax1_type,";
696 $sql .=
"localtax2_type,";
698 $sql .=
"import_key";
703 $sql .=
" t.entity,";
705 $sql .=
" t.fk_product,";
706 $sql .=
" t.fk_soc,";
707 $sql .=
" t.ref_customer,";
709 $sql .=
" t.price_ttc,";
710 $sql .=
" t.price_min,";
711 $sql .=
" t.price_min_ttc,";
712 $sql .=
" t.price_base_type,";
713 $sql .=
" t.default_vat_code,";
714 $sql .=
" t.tva_tx,";
715 $sql .=
" t.recuperableonly,";
716 $sql .=
" t.localtax1_tx,";
717 $sql .=
" t.localtax2_tx,";
718 $sql .=
" t.localtax1_type,";
719 $sql .=
" t.localtax2_type,";
720 $sql .=
" t.fk_user,";
721 $sql .=
" t.import_key";
723 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price as t";
724 $sql .=
" WHERE t.rowid = ".((int) $this->
id);
727 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
731 $this->errors [] =
"Error ".$this->db->lasterror();
735 $sql =
"UPDATE ".$this->db->prefix().
"product_customer_price SET";
737 $sql .=
" entity=".$conf->entity.
",";
738 $sql .=
" datec='".$this->db->idate(
dol_now()).
"',";
739 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
740 $sql .=
" fk_product=".(isset($this->fk_product) ? $this->fk_product :
"null").
",";
741 $sql .=
" fk_soc=".(isset($this->fk_soc) ? $this->fk_soc :
"null").
",";
742 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
743 $sql .=
" price=".(isset($this->
price) ? $this->
price :
"null").
",";
744 $sql .=
" price_ttc=".(isset($this->price_ttc) ? $this->price_ttc :
"null").
",";
745 $sql .=
" price_min=".(isset($this->price_min) ? $this->price_min :
"null").
",";
746 $sql .=
" price_min_ttc=".(isset($this->price_min_ttc) ? $this->price_min_ttc :
"null").
",";
747 $sql .=
" price_base_type=".(isset($this->price_base_type) ?
"'".$this->db->escape($this->price_base_type).
"'" :
"null").
",";
748 $sql .=
" default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null").
",";
749 $sql .=
" tva_tx=".(isset($this->tva_tx) ? (empty($this->tva_tx) ? 0 : $this->tva_tx) :
"null").
",";
750 $sql .=
" recuperableonly=".(isset($this->recuperableonly) ? $this->recuperableonly :
"null").
",";
751 $sql .=
" localtax1_tx=".(isset($this->localtax1_tx) ? (empty($this->localtax1_tx) ? 0 : $this->localtax1_tx) :
"null").
",";
752 $sql .=
" localtax2_tx=".(isset($this->localtax2_tx) ? (empty($this->localtax2_tx) ? 0 : $this->localtax2_tx) :
"null").
",";
753 $sql .=
" localtax1_type=".(!empty($this->localtax1_type) ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'").
",";
754 $sql .=
" localtax2_type=".(!empty($this->localtax2_type) ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'").
",";
755 $sql .=
" fk_user=".$user->id.
",";
756 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
"";
758 $sql .=
" WHERE rowid=".((int) $this->
id);
760 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
764 $this->errors [] =
"Error ".$this->db->lasterror();
767 if (!$error && !$notrigger) {
769 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_MODIFY', $user);
785 foreach ($this->errors as $errmsg) {
786 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
787 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
789 $this->
db->rollback();
808 if (!empty($conf->global->PRODUCT_DISABLE_PROPAGATE_CUSTOMER_PRICES_ON_CHILD_COMPANIES)) {
815 $sql =
"SELECT s.rowid";
816 $sql .=
" FROM ".$this->db->prefix().
"societe as s";
817 $sql .=
" WHERE s.parent = ".((int) $this->fk_soc);
818 $sql .=
" AND s.entity IN (".getEntity(
'societe').
")";
820 dol_syslog(get_class($this).
"::setPriceOnAffiliateThirdparty", LOG_DEBUG);
824 $this->lines = array();
827 while (($obj = $this->
db->fetch_object(
$resql)) && (empty($error))) {
832 't.fk_product' => $this->fk_product,
't.fk_soc' => $obj->rowid
835 $result = $prodsocprice->fetch_all(
'',
'', 0, 0, $filter);
838 $this->error = $prodsocprice->error;
841 if (count($prodsocprice->lines) > 0) {
843 if (!empty($forceupdateaffiliate)) {
845 $prodsocpriceupd->fetch($prodsocprice->lines [0]->id);
847 $prodsocpriceupd->price = $this->price;
848 $prodsocpriceupd->price_min = $this->price_min;
849 $prodsocpriceupd->price_base_type = $this->price_base_type;
850 $prodsocpriceupd->tva_tx = $this->tva_tx;
851 $prodsocpriceupd->recuperableonly = $this->recuperableonly;
853 $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
856 $this->error = $prodsocpriceupd->error;
862 $prodsocpricenew->fk_soc = $obj->rowid;
863 $prodsocpricenew->ref_customer = $obj->ref_customer;
864 $prodsocpricenew->fk_product = $this->fk_product;
865 $prodsocpricenew->price = $this->price;
866 $prodsocpricenew->price_min = $this->price_min;
867 $prodsocpricenew->price_base_type = $this->price_base_type;
868 $prodsocpricenew->tva_tx = $this->tva_tx;
869 $prodsocpricenew->recuperableonly = $this->recuperableonly;
871 $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
874 $this->error = $prodsocpricenew->error;
887 $this->error =
"Error ".$this->db->lasterror();
899 public function delete($user, $notrigger = 0)
901 global $conf, $langs;
906 if (!$error && !$notrigger) {
907 $result = $this->
call_trigger(
'PRODUCT_CUSTOMER_PRICE_DELETE', $user);
914 $sql =
"DELETE FROM ".$this->db->prefix().
"product_customer_price";
915 $sql .=
" WHERE rowid=".((int) $this->
id);
917 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
921 $this->errors [] =
"Error ".$this->db->lasterror();
927 foreach ($this->errors as $errmsg) {
928 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
929 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
931 $this->
db->rollback();
955 $object->fetch($fromid);
963 $object->context[
'createfromclone'] =
'createfromclone';
964 $result = $object->create($user);
968 $this->error = $object->error;
969 $this->errors = array_merge($this->errors, $object->errors);
976 unset($object->context[
'createfromclone']);
983 $this->
db->rollback();
1002 $this->fk_product =
'';
1004 $this->ref_customer =
'';
1006 $this->price_ttc =
'';
1007 $this->price_min =
'';
1008 $this->price_min_ttc =
'';
1009 $this->price_base_type =
'';
1010 $this->default_vat_code =
'';
1012 $this->recuperableonly =
'';
1013 $this->localtax1_tx =
'';
1014 $this->localtax2_tx =
'';
1015 $this->fk_user =
'';
1016 $this->import_key =
'';
1046 public $ref_customer;
1056 public $price_min_ttc;
1057 public $price_base_type;
1058 public $default_vat_code;
1060 public $recuperableonly;
1061 public $localtax1_tx;
1062 public $localtax2_tx;