38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
51 public $element =
'product';
56 public $table_element =
'product';
61 public $fk_element =
'fk_product';
66 protected $childtables = array(
67 'supplier_proposaldet' => array(
'name' =>
'SupplierProposal',
'parent' =>
'supplier_proposal',
'parentkey' =>
'fk_supplier_proposal'),
68 'propaldet' => array(
'name' =>
'Proposal',
'parent' =>
'propal',
'parentkey' =>
'fk_propal'),
69 'commandedet' => array(
'name' =>
'Order',
'parent' =>
'commande',
'parentkey' =>
'fk_commande'),
70 'facturedet' => array(
'name' =>
'Invoice',
'parent' =>
'facture',
'parentkey' =>
'fk_facture'),
71 'contratdet' => array(
'name' =>
'Contract',
'parent' =>
'contrat',
'parentkey' =>
'fk_contrat'),
72 'facture_fourn_det' => array(
'name' =>
'SupplierInvoice',
'parent' =>
'facture_fourn',
'parentkey' =>
'fk_facture_fourn'),
73 'commande_fournisseurdet' => array(
'name' =>
'SupplierOrder',
'parent' =>
'commande_fournisseur',
'parentkey' =>
'fk_commande')
81 public $ismultientitymanaged = 1;
86 public $picto =
'product';
93 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm';
136 public $price_formated;
145 public $price_ttc_formated;
159 public $price_min_ttc;
165 public $price_base_type;
169 public $multiprices_ttc = array();
170 public $multiprices_base_type = array();
171 public $multiprices_min = array();
172 public $multiprices_min_ttc = array();
173 public $multiprices_tva_tx = array();
174 public $multiprices_recuperableonly = array();
178 public $prices_by_qty = array();
179 public $prices_by_qty_id = array();
180 public $prices_by_qty_list = array();
199 public $localtax2_tx;
200 public $localtax1_type;
201 public $localtax2_type;
205 public $desc_supplier;
206 public $vatrate_supplier;
207 public $default_vat_code_supplier;
208 public $fourn_multicurrency_price;
209 public $fourn_multicurrency_unitprice;
210 public $fourn_multicurrency_tx;
211 public $fourn_multicurrency_id;
212 public $fourn_multicurrency_code;
218 public $qc_frequency;
225 public $stock_reel = 0;
232 public $stock_theorique;
249 public $seuil_stock_alerte = 0;
259 public $duration_value;
264 public $fk_default_workstation;
291 public $status_buy = 0;
313 public $fk_default_bom;
320 public $status_batch = 0;
327 public $batch_mask =
'';
345 public $weight_units;
347 public $length_units;
351 public $height_units;
353 public $surface_units;
355 public $volume_units;
358 public $net_measure_units;
360 public $accountancy_code_sell;
361 public $accountancy_code_sell_intra;
362 public $accountancy_code_sell_export;
363 public $accountancy_code_buy;
364 public $accountancy_code_buy_intra;
365 public $accountancy_code_buy_export;
379 public $barcode_type;
386 public $barcode_type_code;
388 public $stats_propale = array();
389 public $stats_commande = array();
390 public $stats_contrat = array();
391 public $stats_facture = array();
392 public $stats_commande_fournisseur = array();
393 public $stats_reception = array();
394 public $stats_mrptoconsume = array();
395 public $stats_mrptoproduce = array();
404 public $date_creation;
409 public $date_modification;
427 public $fk_default_warehouse;
431 public $fk_price_expression;
436 public $fourn_price_base_type;
448 public $ref_supplier;
462 public $price_autogen = 0;
469 public $supplierprices;
476 public $is_object_used;
484 public $mandatory_period;
514 public $fields = array(
515 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
516 'ref' =>array(
'type'=>
'varchar(128)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1,
'comment'=>
'Reference of object'),
517 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'notnull'=>1,
'index'=>1,
'position'=>5),
518 'label' =>array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>2,
'position'=>15),
519 'barcode' =>array(
'type'=>
'varchar(255)',
'label'=>
'Barcode',
'enabled'=>
'isModEnabled("barcode")',
'position'=>20,
'visible'=>-1,
'showoncombobox'=>3),
520 'fk_barcode_type' => array(
'type'=>
'integer',
'label'=>
'BarcodeType',
'enabled'=>
'1',
'position'=>21,
'notnull'=>0,
'visible'=>-1,),
521 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>61),
522 'note' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>62),
523 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
524 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
526 'fk_user_author'=>array(
'type'=>
'integer',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>510,
'foreignkey'=>
'llx_user.rowid'),
527 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511),
529 'localtax1_tx' => array(
'type'=>
'double(6,3)',
'label'=>
'Localtax1tx',
'enabled'=>
'1',
'position'=>150,
'notnull'=>0,
'visible'=>-1,),
530 'localtax1_type' => array(
'type'=>
'varchar(10)',
'label'=>
'Localtax1type',
'enabled'=>
'1',
'position'=>155,
'notnull'=>1,
'visible'=>-1,),
531 'localtax2_tx' => array(
'type'=>
'double(6,3)',
'label'=>
'Localtax2tx',
'enabled'=>
'1',
'position'=>160,
'notnull'=>0,
'visible'=>-1,),
532 'localtax2_type' => array(
'type'=>
'varchar(10)',
'label'=>
'Localtax2type',
'enabled'=>
'1',
'position'=>165,
'notnull'=>1,
'visible'=>-1,),
533 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000),
536 'mandatory_period' => array(
'type'=>
'integer',
'label'=>
'mandatory_period',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'default'=>0,
'index'=>1,
'position'=>1000),
600 public function create($user, $notrigger = 0)
602 global $conf, $langs;
608 $this->label = trim($this->label);
609 $this->price_ttc =
price2num($this->price_ttc);
611 $this->price_min_ttc =
price2num($this->price_min_ttc);
612 $this->price_min =
price2num($this->price_min);
613 if (empty($this->tva_tx)) {
616 if (empty($this->tva_npr)) {
620 if (empty($this->localtax1_tx)) {
621 $this->localtax1_tx = 0;
623 if (empty($this->localtax2_tx)) {
624 $this->localtax2_tx = 0;
626 if (empty($this->localtax1_type)) {
627 $this->localtax1_type =
'0';
629 if (empty($this->localtax2_type)) {
630 $this->localtax2_type =
'0';
632 if (empty($this->
price)) {
635 if (empty($this->price_min)) {
636 $this->price_min = 0;
639 if (empty($this->price_by_qty)) {
640 $this->price_by_qty = 0;
643 if (empty($this->status)) {
646 if (empty($this->status_buy)) {
647 $this->status_buy = 0;
656 if ($this->price_base_type ==
'TTC' && $this->price_ttc > 0) {
657 $price_ttc =
price2num($this->price_ttc,
'MU');
658 $price_ht =
price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),
'MU');
662 if ($this->price_base_type !=
'TTC' && $this->
price > 0) {
664 $price_ttc =
price2num($this->
price * (1 + ($this->tva_tx / 100)),
'MU');
668 if (($this->price_min_ttc > 0) && ($this->price_base_type ==
'TTC')) {
669 $price_min_ttc =
price2num($this->price_min_ttc,
'MU');
670 $price_min_ht =
price2num($this->price_min_ttc / (1 + ($this->tva_tx / 100)),
'MU');
674 if (($this->price_min > 0) && ($this->price_base_type !=
'TTC')) {
675 $price_min_ht =
price2num($this->price_min,
'MU');
676 $price_min_ttc =
price2num($this->price_min * (1 + ($this->tva_tx / 100)),
'MU');
679 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
680 $this->accountancy_code_buy_intra = trim($this->accountancy_code_buy_intra);
681 $this->accountancy_code_buy_export = trim($this->accountancy_code_buy_export);
682 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
683 $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra);
684 $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export);
687 $this->barcode = trim($this->barcode);
688 $this->mandatory_period = empty($this->mandatory_period) ? 0 : $this->mandatory_period;
690 if (empty($this->label)) {
691 $this->error =
'ErrorMandatoryParametersNotProvided';
695 if (empty($this->
ref) || $this->
ref ==
'auto') {
697 $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON :
'mod_codeproduct_leopard');
698 if ($module !=
'mod_codeproduct_leopard') {
699 if (substr($module, 0, 16) ==
'mod_codeproduct_' && substr($module, -3) ==
'php') {
700 $module = substr($module, 0,
dol_strlen($module) - 4);
703 $modCodeProduct =
new $module;
704 if (!empty($modCodeProduct->code_auto)) {
705 $this->
ref = $modCodeProduct->getNextValue($this, $this->
type);
707 unset($modCodeProduct);
710 if (empty($this->
ref)) {
711 $this->error =
'ProductModuleNotSetupForAutoRef';
716 dol_syslog(get_class($this).
"::create ref=".$this->
ref.
" price=".$this->price.
" price_ttc=".$this->price_ttc.
" tva_tx=".$this->tva_tx.
" price_base_type=".$this->price_base_type, LOG_DEBUG);
723 if ($this->barcode == -1) {
724 $this->barcode = $this->
get_barcode($this, $this->barcode_type_code);
729 $result = $this->
verify();
732 $sql =
"SELECT count(*) as nb";
733 $sql .=
" FROM ".$this->db->prefix().
"product";
734 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
735 $sql .=
" AND ref = '".$this->db->escape($this->
ref).
"'";
737 $result = $this->
db->query($sql);
739 $obj = $this->
db->fetch_object($result);
742 $sql =
"INSERT INTO ".$this->db->prefix().
"product (";
747 $sql .=
", price_min";
748 $sql .=
", price_min_ttc";
750 $sql .=
", fk_user_author";
751 $sql .=
", fk_product_type";
753 $sql .=
", price_ttc";
754 $sql .=
", price_base_type";
757 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
758 $sql .=
", accountancy_code_buy";
759 $sql .=
", accountancy_code_buy_intra";
760 $sql .=
", accountancy_code_buy_export";
761 $sql .=
", accountancy_code_sell";
762 $sql .=
", accountancy_code_sell_intra";
763 $sql .=
", accountancy_code_sell_export";
766 $sql .=
", finished";
768 $sql .=
", batch_mask";
770 $sql .=
", mandatory_period";
771 $sql .=
") VALUES (";
772 $sql .=
"'".$this->db->idate($now).
"'";
773 $sql .=
", ".((int) $conf->entity);
774 $sql .=
", '".$this->db->escape($this->
ref).
"'";
775 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
776 $sql .=
", ".price2num($price_min_ht);
777 $sql .=
", ".price2num($price_min_ttc);
778 $sql .=
", ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
779 $sql .=
", ".((int) $user->id);
780 $sql .=
", ".((int) $this->
type);
781 $sql .=
", ".price2num($price_ht,
'MT');
782 $sql .=
", ".price2num($price_ttc,
'MT');
783 $sql .=
", '".$this->db->escape($this->price_base_type).
"'";
784 $sql .=
", ".((int) $this->status);
785 $sql .=
", ".((int) $this->status_buy);
786 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
787 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
788 $sql .=
", '".$this->db->escape($this->accountancy_code_buy_intra).
"'";
789 $sql .=
", '".$this->db->escape($this->accountancy_code_buy_export).
"'";
790 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
791 $sql .=
", '".$this->db->escape($this->accountancy_code_sell_intra).
"'";
792 $sql .=
", '".$this->db->escape($this->accountancy_code_sell_export).
"'";
794 $sql .=
", '".$this->db->escape($this->canvas).
"'";
795 $sql .=
", ".((!isset($this->finished) || $this->finished < 0 || $this->finished ==
'') ?
'NULL' : (
int) $this->finished);
796 $sql .=
", ".((empty($this->status_batch) || $this->status_batch < 0) ?
'0' : ((
int) $this->status_batch));
797 $sql .=
", '".$this->db->escape($this->batch_mask).
"'";
798 $sql .=
", ".($this->fk_unit > 0 ? ((int) $this->fk_unit) :
'NULL');
799 $sql .=
", '".$this->db->escape($this->mandatory_period).
"'";
802 dol_syslog(get_class($this).
"::Create", LOG_DEBUG);
803 $result = $this->
db->query($sql);
805 $id = $this->
db->last_insert_id($this->
db->prefix().
"product");
809 $this->
price = $price_ht;
810 $this->price_ttc = $price_ttc;
811 $this->price_min = $price_min_ht;
812 $this->price_min_ttc = $price_min_ttc;
816 if ($this->
update($id, $user,
true,
'add') <= 0) {
821 $this->error = $this->
db->lasterror();
825 if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
826 $this->
db->query(
"DELETE FROM " . $this->
db->prefix() .
"product_perentity WHERE fk_product = " .((int) $this->id) .
" AND entity = " . ((
int) $conf->entity));
828 $sql =
"INSERT INTO " . $this->
db->prefix() .
"product_perentity (";
829 $sql .=
" fk_product";
831 $sql .=
", accountancy_code_buy";
832 $sql .=
", accountancy_code_buy_intra";
833 $sql .=
", accountancy_code_buy_export";
834 $sql .=
", accountancy_code_sell";
835 $sql .=
", accountancy_code_sell_intra";
836 $sql .=
", accountancy_code_sell_export";
837 $sql .=
") VALUES (";
839 $sql .=
", " . $conf->entity;
840 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy) .
"'";
841 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy_intra) .
"'";
842 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy_export) .
"'";
843 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell) .
"'";
844 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell_intra) .
"'";
845 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell_export) .
"'";
847 $result = $this->
db->query($sql);
850 $this->error =
'ErrorFailedToInsertAccountancyForEntity';
855 $this->error =
'ErrorFailedToGetInsertedId';
859 $this->error = $this->
db->lasterror();
863 $langs->load(
"products");
865 $this->error =
"ErrorProductAlreadyExists";
869 $this->error = $this->
db->lasterror();
872 if (!$error && !$notrigger) {
885 $this->
db->rollback();
889 $this->
db->rollback();
890 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
906 $this->errors = array();
909 $this->
ref = trim($this->
ref);
912 $this->errors[] =
'ErrorBadRef';
916 $arrayofnonnegativevalue = array(
'weight'=>
'Weight',
'width'=>
'Width',
'height'=>
'Height',
'length'=>
'Length',
'surface'=>
'Surface',
'volume'=>
'Volume');
917 foreach ($arrayofnonnegativevalue as $key => $value) {
918 if (property_exists($this, $key) && !empty($this->$key) && ($this->$key < 0)) {
919 $langs->loadLangs(array(
"main",
"other"));
920 $this->error = $langs->trans(
"FieldCannotBeNegative", $langs->transnoentitiesnoconv($value));
921 $this->errors[] = $this->error;
926 $rescode = $this->
check_barcode($this->barcode, $this->barcode_type_code);
928 if ($rescode == -1) {
929 $this->errors[] =
'ErrorBadBarCodeSyntax';
930 } elseif ($rescode == -2) {
931 $this->errors[] =
'ErrorBarCodeRequired';
932 } elseif ($rescode == -3) {
934 $this->errors[] =
'ErrorBarCodeAlreadyUsed';
958 if (
isModEnabled(
'barcode') && !empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
959 $module = strtolower($conf->global->BARCODE_PRODUCT_ADDON_NUM);
961 $dirsociete = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
962 foreach ($dirsociete as $dirroot) {
969 $mod =
new $module();
971 dol_syslog(get_class($this).
"::check_barcode value=".$valuetotest.
" type=".$typefortest.
" module=".$module);
972 $result = $mod->verif($this->
db, $valuetotest, $this, 0, $typefortest);
990 public function update($id, $user, $notrigger =
false, $action =
'update', $updatetype =
false)
992 global $langs, $conf, $hookmanager;
998 $this->label =
'MISSING LABEL';
1003 $this->label = trim($this->label);
1005 $this->note_private = (isset($this->note_private) ? trim($this->note_private) :
null);
1006 $this->note_public = (isset($this->note_public) ? trim($this->note_public) :
null);
1007 $this->net_measure =
price2num($this->net_measure);
1008 $this->net_measure_units = trim($this->net_measure_units);
1009 $this->weight =
price2num($this->weight);
1010 $this->weight_units = trim($this->weight_units);
1011 $this->length =
price2num($this->length);
1012 $this->length_units = trim($this->length_units);
1014 $this->width_units = trim($this->width_units);
1015 $this->height =
price2num($this->height);
1016 $this->height_units = trim($this->height_units);
1017 $this->surface =
price2num($this->surface);
1018 $this->surface_units = trim($this->surface_units);
1019 $this->volume =
price2num($this->volume);
1020 $this->volume_units = trim($this->volume_units);
1023 if (is_numeric($this->length_units)) {
1024 $this->width_units = $this->length_units;
1026 if (is_numeric($this->length_units)) {
1027 $this->height_units = $this->length_units;
1031 if (empty($this->surface) && !empty($this->length) && !empty($this->width) && $this->length_units == $this->width_units) {
1032 $this->surface = $this->length * $this->width;
1035 if (empty($this->volume) && !empty($this->surface) && !empty($this->height) && $this->length_units == $this->height_units) {
1036 $this->volume = $this->surface * $this->height;
1040 if (empty($this->tva_tx)) {
1043 if (empty($this->tva_npr)) {
1046 if (empty($this->localtax1_tx)) {
1047 $this->localtax1_tx = 0;
1049 if (empty($this->localtax2_tx)) {
1050 $this->localtax2_tx = 0;
1052 if (empty($this->localtax1_type)) {
1053 $this->localtax1_type =
'0';
1055 if (empty($this->localtax2_type)) {
1056 $this->localtax2_type =
'0';
1058 if (empty($this->status)) {
1061 if (empty($this->status_buy)) {
1062 $this->status_buy = 0;
1065 if (empty($this->country_id)) {
1066 $this->country_id = 0;
1069 if (empty($this->state_id)) {
1070 $this->state_id = 0;
1074 $this->barcode = trim($this->barcode);
1076 $this->accountancy_code_buy = trim($this->accountancy_code_buy);
1077 $this->accountancy_code_buy_intra = trim($this->accountancy_code_buy_intra);
1078 $this->accountancy_code_buy_export = trim($this->accountancy_code_buy_export);
1079 $this->accountancy_code_sell = trim($this->accountancy_code_sell);
1080 $this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra);
1081 $this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export);
1088 if ($action !=
'add') {
1089 $result = $this->
verify();
1097 if (empty($this->oldcopy)) {
1103 if ($this->
hasbatch() && !$this->oldcopy->hasbatch()) {
1105 $valueforundefinedlot =
'000000';
1106 if (!empty($conf->global->STOCK_DEFAULT_BATCH)) {
1107 $valueforundefinedlot = $conf->global->STOCK_DEFAULT_BATCH;
1110 dol_syslog(
"Flag batch of product id=".$this->
id.
" is set to ON, so we will create missing records into product_batch");
1113 foreach ($this->stock_warehouse as $idW => $ObjW) {
1115 foreach ($ObjW->detail_batch as $detail) {
1116 if ($detail->batch == $valueforundefinedlot || $detail->batch ==
'Undefined') {
1118 $sqlclean =
"DELETE FROM ".$this->db->prefix().
"product_batch WHERE batch in('Undefined', '".$this->
db->escape($valueforundefinedlot).
"') AND fk_product_stock = ".((int) $ObjW->id);
1119 $result = $this->
db->query($sqlclean);
1127 $qty_batch += $detail->qty;
1131 if ($ObjW->real <> $qty_batch) {
1133 $ObjBatch->batch = $valueforundefinedlot;
1134 $ObjBatch->qty = ($ObjW->real - $qty_batch);
1135 $ObjBatch->fk_product_stock = $ObjW->id;
1137 if ($ObjBatch->create($user, 1) < 0) {
1139 $this->errors = $ObjBatch->errors;
1146 if ($this->barcode == -1) {
1147 $this->barcode = $this->
get_barcode($this, $this->barcode_type_code);
1150 $sql =
"UPDATE ".$this->db->prefix().
"product";
1151 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
1154 $sql .=
", fk_product_type = ".((int) $this->
type);
1157 $sql .=
", ref = '".$this->db->escape($this->
ref).
"'";
1158 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1159 $sql .=
", default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null");
1160 $sql .=
", tva_tx = ".((float) $this->tva_tx);
1161 $sql .=
", recuperableonly = ".((int) $this->tva_npr);
1162 $sql .=
", localtax1_tx = ".((float) $this->localtax1_tx);
1163 $sql .=
", localtax2_tx = ".((float) $this->localtax2_tx);
1164 $sql .=
", localtax1_type = ".($this->localtax1_type !=
'' ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'");
1165 $sql .=
", localtax2_type = ".($this->localtax2_type !=
'' ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'");
1167 $sql .=
", barcode = ".(empty($this->barcode) ?
"null" :
"'".$this->db->escape($this->barcode).
"'");
1168 $sql .=
", fk_barcode_type = ".(empty($this->barcode_type) ?
"null" : $this->
db->escape($this->barcode_type));
1170 $sql .=
", tosell = ".(int) $this->status;
1171 $sql .=
", tobuy = ".(int) $this->status_buy;
1172 $sql .=
", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ?
'0' : (
int) $this->status_batch);
1173 $sql .=
", batch_mask = '".$this->db->escape($this->batch_mask).
"'";
1175 $sql .=
", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished ==
'') ?
"null" : (
int) $this->finished);
1176 $sql .=
", fk_default_bom = ".((!isset($this->fk_default_bom) || $this->fk_default_bom < 0 || $this->fk_default_bom ==
'') ?
"null" : (
int) $this->fk_default_bom);
1177 $sql .=
", net_measure = ".($this->net_measure !=
'' ?
"'".$this->db->escape($this->net_measure).
"'" :
'null');
1178 $sql .=
", net_measure_units = ".($this->net_measure_units !=
'' ?
"'".$this->db->escape($this->net_measure_units).
"'" :
'null');
1179 $sql .=
", weight = ".($this->weight !=
'' ?
"'".$this->db->escape($this->weight).
"'" :
'null');
1180 $sql .=
", weight_units = ".($this->weight_units !=
'' ?
"'".$this->db->escape($this->weight_units).
"'" :
'null');
1181 $sql .=
", length = ".($this->length !=
'' ?
"'".$this->db->escape($this->length).
"'" :
'null');
1182 $sql .=
", length_units = ".($this->length_units !=
'' ?
"'".$this->db->escape($this->length_units).
"'" :
'null');
1183 $sql .=
", width= ".($this->width !=
'' ?
"'".$this->db->escape($this->width).
"'" :
'null');
1184 $sql .=
", width_units = ".($this->width_units !=
'' ?
"'".$this->db->escape($this->width_units).
"'" :
'null');
1185 $sql .=
", height = ".($this->height !=
'' ?
"'".$this->db->escape($this->height).
"'" :
'null');
1186 $sql .=
", height_units = ".($this->height_units !=
'' ?
"'".$this->db->escape($this->height_units).
"'" :
'null');
1187 $sql .=
", surface = ".($this->surface !=
'' ?
"'".$this->db->escape($this->surface).
"'" :
'null');
1188 $sql .=
", surface_units = ".($this->surface_units !=
'' ?
"'".$this->db->escape($this->surface_units).
"'" :
'null');
1189 $sql .=
", volume = ".($this->volume !=
'' ?
"'".$this->db->escape($this->volume).
"'" :
'null');
1190 $sql .=
", volume_units = ".($this->volume_units !=
'' ?
"'".$this->db->escape($this->volume_units).
"'" :
'null');
1191 $sql .=
", fk_default_warehouse = ".($this->fk_default_warehouse > 0 ? $this->
db->escape($this->fk_default_warehouse) :
'null');
1192 $sql .=
", fk_default_workstation = ".($this->fk_default_workstation > 0 ? $this->
db->escape($this->fk_default_workstation) :
'null');
1193 $sql .=
", seuil_stock_alerte = ".((isset($this->seuil_stock_alerte) && is_numeric($this->seuil_stock_alerte)) ? (
float) $this->seuil_stock_alerte :
'null');
1194 $sql .=
", description = '".$this->db->escape($this->
description).
"'";
1195 $sql .=
", url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
'null');
1196 $sql .=
", customcode = '".$this->db->escape($this->customcode).
"'";
1197 $sql .=
", fk_country = ".($this->country_id > 0 ? (int) $this->country_id :
'null');
1198 $sql .=
", fk_state = ".($this->state_id > 0 ? (int) $this->state_id :
'null');
1199 $sql .=
", lifetime = ".($this->lifetime > 0 ? (int) $this->lifetime :
'null');
1200 $sql .=
", qc_frequency = ".($this->qc_frequency > 0 ? (int) $this->qc_frequency :
'null');
1201 $sql .=
", note = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
'null');
1202 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
'null');
1203 $sql .=
", duration = '".$this->db->escape($this->duration_value.$this->duration_unit).
"'";
1204 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
1205 $sql .=
", accountancy_code_buy = '" . $this->
db->escape($this->accountancy_code_buy) .
"'";
1206 $sql .=
", accountancy_code_buy_intra = '" . $this->
db->escape($this->accountancy_code_buy_intra) .
"'";
1207 $sql .=
", accountancy_code_buy_export = '" . $this->
db->escape($this->accountancy_code_buy_export) .
"'";
1208 $sql .=
", accountancy_code_sell= '" . $this->
db->escape($this->accountancy_code_sell) .
"'";
1209 $sql .=
", accountancy_code_sell_intra= '" . $this->
db->escape($this->accountancy_code_sell_intra) .
"'";
1210 $sql .=
", accountancy_code_sell_export= '" . $this->
db->escape($this->accountancy_code_sell_export) .
"'";
1212 $sql .=
", desiredstock = ".((isset($this->desiredstock) && is_numeric($this->desiredstock)) ? (
float) $this->desiredstock :
"null");
1213 $sql .=
", cost_price = ".($this->cost_price !=
'' ? $this->
db->escape($this->cost_price) :
'null');
1214 $sql .=
", fk_unit= ".(!$this->fk_unit ?
'NULL' : (int) $this->fk_unit);
1215 $sql .=
", price_autogen = ".(!$this->price_autogen ? 0 : 1);
1216 $sql .=
", fk_price_expression = ".($this->fk_price_expression != 0 ? (int) $this->fk_price_expression :
'NULL');
1217 $sql .=
", fk_user_modif = ".($user->id > 0 ? $user->id :
'NULL');
1218 $sql .=
", mandatory_period = ".($this->mandatory_period );
1220 $sql .=
" WHERE rowid = ".((int) $id);
1222 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1231 $this->error = $langs->trans(
"Error").
" : ".$this->
db->error().
" - ".$sql;
1239 if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
1240 $this->
db->query(
"DELETE FROM " . $this->
db->prefix() .
"product_perentity WHERE fk_product = " . ((
int) $this->id) .
" AND entity = " . ((
int) $conf->entity));
1242 $sql =
"INSERT INTO " . $this->
db->prefix() .
"product_perentity (";
1243 $sql .=
" fk_product";
1245 $sql .=
", accountancy_code_buy";
1246 $sql .=
", accountancy_code_buy_intra";
1247 $sql .=
", accountancy_code_buy_export";
1248 $sql .=
", accountancy_code_sell";
1249 $sql .=
", accountancy_code_sell_intra";
1250 $sql .=
", accountancy_code_sell_export";
1251 $sql .=
") VALUES (";
1253 $sql .=
", " . $conf->entity;
1254 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy) .
"'";
1255 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy_intra) .
"'";
1256 $sql .=
", '" . $this->
db->escape($this->accountancy_code_buy_export) .
"'";
1257 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell) .
"'";
1258 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell_intra) .
"'";
1259 $sql .=
", '" . $this->
db->escape($this->accountancy_code_sell_export) .
"'";
1261 $result = $this->
db->query($sql);
1264 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1276 if (!$error && !$notrigger) {
1278 $result = $this->
call_trigger(
'PRODUCT_MODIFY', $user);
1285 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
1287 if ($conf->product->dir_output) {
1290 if (file_exists($olddir)) {
1294 $res = @rename($olddir, $newdir);
1296 $langs->load(
"errors");
1297 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
1306 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
1310 foreach ($comb->fetchAllByFkProductParent($this->id) as $currcomb) {
1311 $currcomb->updateProperties($this, $user);
1315 $this->
db->commit();
1318 $this->
db->rollback();
1322 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1323 $langs->load(
"errors");
1324 if (empty($conf->barcode->enabled) || empty($this->barcode)) {
1325 $this->error = $langs->trans(
"Error").
" : ".$langs->trans(
"ErrorProductAlreadyExists", $this->
ref);
1327 $this->error = $langs->trans(
"Error").
" : ".$langs->trans(
"ErrorProductBarCodeAlreadyExists", $this->barcode);
1329 $this->errors[] = $this->error;
1330 $this->
db->rollback();
1333 $this->error = $langs->trans(
"Error").
" : ".$this->
db->error().
" - ".$sql;
1334 $this->errors[] = $this->error;
1335 $this->
db->rollback();
1340 $this->
db->rollback();
1341 dol_syslog(get_class($this).
"::Update fails verify ".join(
',', $this->errors), LOG_WARNING);
1353 public function delete(
User $user, $notrigger = 0)
1355 global $conf, $langs;
1356 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1361 if (empty($this->
id)) {
1362 $this->error =
"Object must be fetched before calling delete";
1366 $this->error =
"ErrorForbidden";
1371 if (empty($objectisused)) {
1374 if (!$error && empty($notrigger)) {
1376 $result = $this->
call_trigger(
'PRODUCT_DELETE', $user);
1385 $sql =
"DELETE FROM ".$this->db->prefix().
'product_batch';
1386 $sql .=
" WHERE fk_product_stock IN (";
1387 $sql .=
"SELECT rowid FROM ".$this->db->prefix().
'product_stock';
1388 $sql .=
" WHERE fk_product = ".((int) $this->
id).
")";
1390 $result = $this->
db->query($sql);
1393 $this->errors[] = $this->
db->lasterror();
1399 $elements = array(
'product_fournisseur_price',
'product_price',
'product_lang',
'categorie_product',
'product_stock',
'product_customer_price',
'product_lot');
1400 foreach ($elements as $table) {
1402 $sql =
"DELETE FROM ".$this->db->prefix().$table;
1403 $sql .=
" WHERE fk_product = ".(int) $this->
id;
1405 $result = $this->
db->query($sql);
1408 $this->errors[] = $this->
db->lasterror();
1415 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
1416 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination2ValuePair.class.php';
1421 if ($prodcomb->deleteByFkProductParent($user, $this->id) < 0) {
1423 $this->errors[] =
'Error deleting combinations';
1427 if (!$error && ($prodcomb->fetchByFkProductChild($this->id) > 0) && ($prodcomb->delete($user) < 0)) {
1429 $this->errors[] =
'Error deleting child combination';
1435 $sql =
"DELETE FROM ".$this->db->prefix().
"product_association";
1436 $sql .=
" WHERE fk_product_pere = ".(int) $this->
id.
" OR fk_product_fils = ".(
int) $this->id;
1438 $result = $this->
db->query($sql);
1441 $this->errors[] = $this->
db->lasterror();
1450 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
1456 $sqlz =
"DELETE FROM ".$this->db->prefix().
"product";
1457 $sqlz .=
" WHERE rowid = ".(int) $this->
id;
1459 $resultz = $this->
db->query($sqlz);
1462 $this->errors[] = $this->
db->lasterror();
1477 if ($conf->product->dir_output) {
1478 $dir = $conf->product->dir_output.
"/".$ref;
1479 if (file_exists($dir)) {
1482 $this->errors[] =
'ErrorFailToDeleteDir';
1490 $this->
db->commit();
1493 foreach ($this->errors as $errmsg) {
1494 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1495 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1497 $this->
db->rollback();
1501 $this->error =
"ErrorRecordIsUsedCantDelete";
1514 global $conf, $langs;
1516 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
1517 $current_lang = $langs->getDefaultLang();
1519 foreach ($langs_available as $key => $value) {
1520 if ($key == $current_lang) {
1521 $sql =
"SELECT rowid";
1522 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
1523 $sql .=
" WHERE fk_product = ".((int) $this->
id);
1524 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
1526 $result = $this->
db->query($sql);
1528 if ($this->
db->num_rows($result)) {
1529 $sql2 =
"UPDATE ".$this->db->prefix().
"product_lang";
1531 $sql2 .=
" label='".$this->db->escape($this->label).
"',";
1532 $sql2 .=
" description='".$this->db->escape($this->
description).
"'";
1533 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1534 $sql2 .=
", note='".$this->db->escape($this->other).
"'";
1536 $sql2 .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->
db->escape($key).
"'";
1538 $sql2 =
"INSERT INTO ".$this->db->prefix().
"product_lang (fk_product, lang, label, description";
1539 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1543 $sql2 .=
" VALUES(".$this->id.
",'".$this->
db->escape($key).
"','".$this->
db->escape($this->label).
"',";
1544 $sql2 .=
" '".$this->db->escape($this->
description).
"'";
1545 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1546 $sql2 .=
", '".$this->db->escape($this->other).
"'";
1550 dol_syslog(get_class($this).
'::setMultiLangs key = current_lang = '.$key);
1551 if (!$this->
db->query($sql2)) {
1552 $this->error = $this->
db->lasterror();
1555 } elseif (isset($this->multilangs[$key])) {
1556 if (empty($this->multilangs[
"$key"][
"label"])) {
1557 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label"));
1561 $sql =
"SELECT rowid";
1562 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
1563 $sql .=
" WHERE fk_product = ".((int) $this->
id);
1564 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
1566 $result = $this->
db->query($sql);
1568 if ($this->
db->num_rows($result)) {
1569 $sql2 =
"UPDATE ".$this->db->prefix().
"product_lang";
1571 $sql2 .=
" label = '".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
1572 $sql2 .=
" description = '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
1573 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1574 $sql2 .=
", note = '".$this->db->escape($this->multilangs[
"$key"][
"other"]).
"'";
1576 $sql2 .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->
db->escape($key).
"'";
1578 $sql2 =
"INSERT INTO ".$this->db->prefix().
"product_lang (fk_product, lang, label, description";
1579 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1583 $sql2 .=
" VALUES(".$this->id.
",'".$this->
db->escape($key).
"','".$this->
db->escape($this->multilangs[
"$key"][
"label"]).
"',";
1584 $sql2 .=
" '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
1585 if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) {
1586 $sql2 .=
", '".$this->db->escape($this->multilangs[
"$key"][
"other"]).
"'";
1592 if ($this->multilangs[
"$key"][
"label"] || $this->multilangs[
"$key"][
"description"]) {
1593 if (!$this->
db->query($sql2)) {
1594 $this->error = $this->
db->lasterror();
1604 $result = $this->
call_trigger(
'PRODUCT_SET_MULTILANGS', $user);
1606 $this->error = $this->
db->lasterror();
1624 $sql =
"DELETE FROM ".$this->db->prefix().
"product_lang";
1625 $sql .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->
db->escape($langtodelete).
"'";
1627 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
1628 $result = $this->
db->query($sql);
1631 $result = $this->
call_trigger(
'PRODUCT_DEL_MULTILANGS', $user);
1633 $this->error = $this->
db->lasterror();
1634 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
1640 $this->error = $this->
db->lasterror();
1641 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
1656 global $user, $langs, $conf;
1662 if ($type ==
'buy') {
1663 $field =
'accountancy_code_buy';
1664 } elseif ($type ==
'buy_intra') {
1665 $field =
'accountancy_code_buy_intra';
1666 } elseif ($type ==
'buy_export') {
1667 $field =
'accountancy_code_buy_export';
1668 } elseif ($type ==
'sell') {
1669 $field =
'accountancy_code_sell';
1670 } elseif ($type ==
'sell_intra') {
1671 $field =
'accountancy_code_sell_intra';
1672 } elseif ($type ==
'sell_export') {
1673 $field =
'accountancy_code_sell_export';
1678 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ";
1679 $sql .=
"$field = '".$this->db->escape($value).
"'";
1680 $sql .=
" WHERE rowid = ".((int) $this->
id);
1687 $result = $this->
call_trigger(
'PRODUCT_MODIFY', $user);
1694 $this->
db->rollback();
1698 $this->$field = $value;
1700 $this->
db->commit();
1703 $this->error = $this->
db->lasterror();
1704 $this->
db->rollback();
1718 $current_lang = $langs->getDefaultLang();
1720 $sql =
"SELECT lang, label, description, note as other";
1721 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
1722 $sql .=
" WHERE fk_product = ".((int) $this->
id);
1724 $result = $this->
db->query($sql);
1726 while ($obj = $this->
db->fetch_object($result)) {
1728 if ($obj->lang == $current_lang) {
1729 $this->label = $obj->label;
1731 $this->other = $obj->other;
1733 $this->multilangs[
"$obj->lang"][
"label"] = $obj->label;
1734 $this->multilangs[
"$obj->lang"][
"description"] = $obj->description;
1735 $this->multilangs[
"$obj->lang"][
"other"] = $obj->other;
1739 $this->error =
"Error: ".$this->db->lasterror().
" - ".$sql;
1753 $testExit = array(
'multiprices',
'multiprices_ttc',
'multiprices_base_type',
'multiprices_min',
'multiprices_min_ttc',
'multiprices_tva_tx',
'multiprices_recuperableonly');
1755 foreach ($testExit as $field) {
1756 if (!isset($this->$field)) {
1759 $tmparray = $this->$field;
1760 if (!isset($tmparray[$level])) {
1766 'level' => $level ? $level : 1,
1767 'multiprices' => doubleval($this->multiprices[$level]),
1768 'multiprices_ttc' => doubleval($this->multiprices_ttc[$level]),
1769 'multiprices_base_type' => $this->multiprices_base_type[$level],
1770 'multiprices_min' => doubleval($this->multiprices_min[$level]),
1771 'multiprices_min_ttc' => doubleval($this->multiprices_min_ttc[$level]),
1772 'multiprices_tva_tx' => doubleval($this->multiprices_tva_tx[$level]),
1773 'multiprices_recuperableonly' => doubleval($this->multiprices_recuperableonly[$level]),
1796 if (empty($this->price_by_qty)) {
1797 $this->price_by_qty = 0;
1801 $sql =
"INSERT INTO ".$this->db->prefix().
"product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
1802 $sql .=
" localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) ";
1803 $sql .=
" VALUES(".($level ? ((int) $level) : 1).
", '".$this->
db->idate($now).
"', ".((int) $this->
id).
", ".((int) $user->id).
", ".((
float)
price2num($this->
price)).
", ".((
float)
price2num($this->price_ttc)).
",'".$this->
db->escape($this->price_base_type).
"',".((int) $this->status).
", ".((
float)
price2num($this->tva_tx)).
", ".($this->default_vat_code ? (
"'".$this->
db->escape($this->default_vat_code).
"'") :
"null").
", ".((
int)
$this->tva_npr).
",";
1804 $sql .=
" ".price2num($this->localtax1_tx).
", ".
price2num($this->localtax2_tx).
", '".$this->
db->escape($this->localtax1_type).
"', '".$this->
db->escape($this->localtax2_type).
"', ".
price2num($this->price_min).
", ".
price2num($this->price_min_ttc).
", ".
price2num($this->price_by_qty).
", ".((int) $conf->entity).
",".($this->fk_price_expression > 0 ? ((int) $this->fk_price_expression) :
'null');
1807 dol_syslog(get_class($this).
"::_log_price", LOG_DEBUG);
1810 $this->error = $this->
db->lasterror();
1830 $sql =
"DELETE FROM ".$this->db->prefix().
"product_price_by_qty";
1831 $sql .=
" WHERE fk_product_price = ".((int) $rowid);
1834 $sql =
"DELETE FROM ".$this->db->prefix().
"product_price";
1835 $sql .=
" WHERE rowid=".((int) $rowid);
1840 $this->error = $this->
db->lasterror();
1855 public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0)
1857 global $conf, $db, $hookmanager, $action;
1860 if (is_object($hookmanager)) {
1861 $parameters = array(
'thirdparty_seller'=>$thirdparty_seller,
'thirdparty_buyer' => $thirdparty_buyer,
'pqp' => $pqp);
1863 $reshook = $hookmanager->executeHooks(
'getSellPrice', $parameters, $this, $action);
1865 return $hookmanager->resArray;
1876 $pu_ht = $this->price;
1877 $pu_ttc = $this->price_ttc;
1878 $price_min = $this->price_min;
1879 $price_base_type = $this->price_base_type;
1882 if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($thirdparty_buyer->price_level)) {
1883 $pu_ht = $this->multiprices[$thirdparty_buyer->price_level];
1884 $pu_ttc = $this->multiprices_ttc[$thirdparty_buyer->price_level];
1885 $price_min = $this->multiprices_min[$thirdparty_buyer->price_level];
1886 $price_base_type = $this->multiprices_base_type[$thirdparty_buyer->price_level];
1887 if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
1888 if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) {
1889 $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level];
1891 if (isset($this->multiprices_recuperableonly[$thirdparty_buyer->price_level])) {
1892 $tva_npr = $this->multiprices_recuperableonly[$thirdparty_buyer->price_level];
1898 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
1900 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
1904 $filter = array(
't.fk_product' => $this->
id,
't.fk_soc' => $thirdparty_buyer->id);
1906 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
1908 if (count($prodcustprice->lines) > 0) {
1909 $pu_ht =
price($prodcustprice->lines[0]->price);
1910 $price_min =
price($prodcustprice->lines[0]->price_min);
1911 $pu_ttc =
price($prodcustprice->lines[0]->price_ttc);
1912 $price_base_type = $prodcustprice->lines[0]->price_base_type;
1913 $tva_tx = $prodcustprice->lines[0]->tva_tx;
1914 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/',
$tva_tx)) {
1915 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
1917 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
1923 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
1925 if ($this->prices_by_qty[0]) {
1928 foreach ($this->prices_by_qty_list[0] as $priceforthequantityarray) {
1929 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1933 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1934 $pu_ht = $priceforthequantityarray[
'unitprice'];
1936 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1941 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
1943 if ($this->prices_by_qty[$thirdparty_buyer->price_level]) {
1946 foreach ($this->prices_by_qty_list[$thirdparty_buyer->price_level] as $priceforthequantityarray) {
1947 if ($priceforthequantityarray[
'rowid'] != $pqp) {
1951 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
1952 $pu_ht = $priceforthequantityarray[
'unitprice'];
1954 $pu_ttc = $priceforthequantityarray[
'unitprice'];
1961 return array(
'pu_ht'=>$pu_ht,
'pu_ttc'=>$pu_ttc,
'price_min'=>$price_min,
'price_base_type'=>$price_base_type,
'tva_tx'=>
$tva_tx,
'tva_npr'=>
$tva_npr);
1978 public function get_buyprice($prodfournprice, $qty, $product_id = 0, $fourn_ref =
'', $fk_soc = 0)
1985 $sql =
"SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
1986 $sql .=
" pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.desc_fourn as desc_supplier, pfp.tva_tx, pfp.default_vat_code, pfp.fk_supplier_price_expression,";
1987 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
1988 $sql .=
" pfp.packaging";
1989 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as pfp";
1990 $sql .=
" WHERE pfp.rowid = ".((int) $prodfournprice);
1992 $sql .=
" AND pfp.quantity <= ".((float) $qty);
1994 $sql .=
" ORDER BY pfp.quantity DESC";
1996 dol_syslog(get_class($this).
"::get_buyprice first search by prodfournprice/qty", LOG_DEBUG);
1999 $obj = $this->
db->fetch_object(
$resql);
2000 if ($obj && $obj->quantity > 0) {
2001 if (
isModEnabled(
'dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
2003 $prod_supplier->product_fourn_price_id = $obj->rowid;
2004 $prod_supplier->id = $obj->fk_product;
2005 $prod_supplier->fourn_qty = $obj->quantity;
2006 $prod_supplier->fourn_tva_tx = $obj->tva_tx;
2007 $prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
2009 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2011 $price_result = $priceparser->parseProductSupplier($prod_supplier);
2012 if ($price_result >= 0) {
2013 $obj->price = $price_result;
2016 $this->product_fourn_price_id = $obj->rowid;
2017 $this->buyprice = $obj->price;
2018 $this->fourn_pu = $obj->price / $obj->quantity;
2019 $this->fourn_price_base_type =
'HT';
2020 $this->fourn_socid = $obj->fk_soc;
2021 $this->ref_fourn = $obj->ref_supplier;
2022 $this->ref_supplier = $obj->ref_supplier;
2023 $this->desc_supplier = $obj->desc_supplier;
2024 $this->remise_percent = $obj->remise_percent;
2025 $this->vatrate_supplier = $obj->tva_tx;
2026 $this->default_vat_code_supplier = $obj->default_vat_code;
2027 $this->fourn_multicurrency_price = $obj->multicurrency_price;
2028 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
2029 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
2030 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
2031 $this->fourn_multicurrency_code = $obj->multicurrency_code;
2032 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
2033 $this->packaging = $obj->packaging;
2035 $result = $obj->fk_product;
2039 $sql =
"SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
2040 $sql .=
" pfp.fk_product, pfp.ref_fourn as ref_supplier, pfp.desc_fourn as desc_supplier, pfp.tva_tx, pfp.default_vat_code, pfp.fk_supplier_price_expression,";
2041 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
2042 $sql .=
" pfp.packaging";
2043 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as pfp";
2044 $sql .=
" WHERE 1 = 1";
2045 if ($product_id > 0) {
2046 $sql .=
" AND pfp.fk_product = ".((int) $product_id);
2048 if ($fourn_ref !=
'none') {
2049 $sql .=
" AND pfp.ref_fourn = '".$this->db->escape($fourn_ref).
"'";
2052 $sql .=
" AND pfp.fk_soc = ".((int) $fk_soc);
2055 $sql .=
" AND pfp.quantity <= ".((float) $qty);
2057 $sql .=
" ORDER BY pfp.quantity DESC";
2060 dol_syslog(get_class($this).
"::get_buyprice second search from qty/ref/product_id", LOG_DEBUG);
2063 $obj = $this->
db->fetch_object(
$resql);
2064 if ($obj && $obj->quantity > 0) {
2065 if (
isModEnabled(
'dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
2067 $prod_supplier->product_fourn_price_id = $obj->rowid;
2068 $prod_supplier->id = $obj->fk_product;
2069 $prod_supplier->fourn_qty = $obj->quantity;
2070 $prod_supplier->fourn_tva_tx = $obj->tva_tx;
2071 $prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
2073 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2075 $price_result = $priceparser->parseProductSupplier($prod_supplier);
2077 $obj->price = $price_result;
2080 $this->product_fourn_price_id = $obj->rowid;
2081 $this->buyprice = $obj->price;
2082 $this->fourn_qty = $obj->quantity;
2083 $this->fourn_pu = $obj->price / $obj->quantity;
2084 $this->fourn_price_base_type =
'HT';
2085 $this->fourn_socid = $obj->fk_soc;
2086 $this->ref_fourn = $obj->ref_supplier;
2087 $this->ref_supplier = $obj->ref_supplier;
2088 $this->desc_supplier = $obj->desc_supplier;
2089 $this->remise_percent = $obj->remise_percent;
2090 $this->vatrate_supplier = $obj->tva_tx;
2091 $this->default_vat_code_supplier = $obj->default_vat_code;
2092 $this->fourn_multicurrency_price = $obj->multicurrency_price;
2093 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
2094 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
2095 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
2096 $this->fourn_multicurrency_code = $obj->multicurrency_code;
2097 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
2098 $this->packaging = $obj->packaging;
2100 $result = $obj->fk_product;
2106 $this->error = $this->
db->lasterror();
2111 $this->error = $this->
db->lasterror();
2133 public function updatePrice($newprice, $newpricebase, $user, $newvat =
'', $newminprice = 0, $level = 0, $newnpr = 0, $newpbq = 0, $ignore_autogen = 0, $localtaxes_array = array(), $newdefaultvatcode =
'')
2135 global $conf, $langs;
2141 dol_syslog(get_class($this).
"::update_price id=".$id.
" newprice=".$newprice.
" newpricebase=".$newpricebase.
" newminprice=".$newminprice.
" level=".$level.
" npr=".$newnpr.
" newdefaultvatcode=".$newdefaultvatcode);
2144 if (empty($this->tva_tx)) {
2147 if (empty($newnpr)) {
2150 if (empty($newminprice)) {
2153 if (empty($newminprice)) {
2158 if ($newvat ==
'') {
2164 if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !$ignore_autogen && $this->price_autogen && ($level == 1)) {
2165 return $this->
generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpbq);
2168 if (!empty($newminprice) && ($newminprice > $newprice)) {
2169 $this->error =
'ErrorPriceCantBeLowerThanMinPrice';
2173 if ($newprice !==
'' || $newprice === 0) {
2174 if ($newpricebase ==
'TTC') {
2175 $price_ttc =
price2num($newprice,
'MU');
2176 $price =
price2num($newprice) / (1 + ($newvat / 100));
2179 if ($newminprice !=
'' || $newminprice == 0) {
2180 $price_min_ttc =
price2num($newminprice,
'MU');
2181 $price_min =
price2num($newminprice) / (1 + ($newvat / 100));
2182 $price_min =
price2num($price_min,
'MU');
2189 $price_ttc = ($newnpr != 1) ? (
float)
price2num($newprice) * (1 + ($newvat / 100)) : $price;
2190 $price_ttc =
price2num($price_ttc,
'MU');
2192 if ($newminprice !==
'' || $newminprice === 0) {
2193 $price_min =
price2num($newminprice,
'MU');
2194 $price_min_ttc =
price2num($newminprice) * (1 + ($newvat / 100));
2195 $price_min_ttc =
price2num($price_min_ttc,
'MU');
2204 if (count($localtaxes_array) > 0) {
2205 $localtaxtype1 = $localtaxes_array[
'0'];
2206 $localtax1 = $localtaxes_array[
'1'];
2207 $localtaxtype2 = $localtaxes_array[
'2'];
2208 $localtax2 = $localtaxes_array[
'3'];
2211 if (!empty($newdefaultvatcode)) {
2214 $sql =
"SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
2215 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
2216 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($mysoc->country_code).
"'";
2217 $sql .=
" AND t.taux = ".((float) $newdefaultvatcode).
" AND t.active = 1";
2218 $sql .=
" AND t.code = '".$this->db->escape($newdefaultvatcode).
"'";
2221 $obj = $this->
db->fetch_object(
$resql);
2223 $npr = $obj->recuperableonly;
2224 $localtax1 = $obj->localtax1;
2225 $localtax2 = $obj->localtax2;
2226 $localtaxtype1 = $obj->localtax1_type;
2227 $localtaxtype2 = $obj->localtax2_type;
2232 $localtaxtype1 =
'0';
2234 $localtaxtype2 =
'0';
2238 if (empty($localtax1)) {
2241 if (empty($localtax2)) {
2249 $sql =
"UPDATE ".$this->db->prefix().
"product SET";
2250 $sql .=
" price_base_type='".$this->db->escape($newpricebase).
"',";
2251 $sql .=
" price=".$price.
",";
2252 $sql .=
" price_ttc=".$price_ttc.
",";
2253 $sql .=
" price_min=".$price_min.
",";
2254 $sql .=
" price_min_ttc=".$price_min_ttc.
",";
2255 $sql .=
" localtax1_tx=".($localtax1 >= 0 ? $localtax1 :
'NULL').
",";
2256 $sql .=
" localtax2_tx=".($localtax2 >= 0 ? $localtax2 :
'NULL').
",";
2257 $sql .=
" localtax1_type=".($localtaxtype1 !=
'' ?
"'".$this->db->escape($localtaxtype1).
"'" :
"'0'").
",";
2258 $sql .=
" localtax2_type=".($localtaxtype2 !=
'' ?
"'".$this->db->escape($localtaxtype2).
"'" :
"'0'").
",";
2259 $sql .=
" default_vat_code=".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
2260 $sql .=
" tva_tx='".price2num($newvat).
"',";
2261 $sql .=
" recuperableonly='".$this->db->escape($newnpr).
"'";
2262 $sql .=
" WHERE rowid = ".((int) $id);
2264 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
2267 $this->multiprices[$level] = $price;
2268 $this->multiprices_ttc[$level] = $price_ttc;
2269 $this->multiprices_min[$level] = $price_min;
2270 $this->multiprices_min_ttc[$level] = $price_min_ttc;
2271 $this->multiprices_base_type[$level] = $newpricebase;
2272 $this->multiprices_default_vat_code[$level] = $newdefaultvatcode;
2273 $this->multiprices_tva_tx[$level] = $newvat;
2274 $this->multiprices_recuperableonly[$level] = $newnpr;
2276 $this->
price = $price;
2277 $this->price_ttc = $price_ttc;
2278 $this->price_min = $price_min;
2279 $this->price_min_ttc = $price_min_ttc;
2280 $this->price_base_type = $newpricebase;
2281 $this->default_vat_code = $newdefaultvatcode;
2282 $this->tva_tx = $newvat;
2283 $this->tva_npr = $newnpr;
2285 $this->localtax1_tx = $localtax1;
2286 $this->localtax2_tx = $localtax2;
2287 $this->localtax1_type = $localtaxtype1;
2288 $this->localtax2_type = $localtaxtype2;
2291 $this->price_by_qty = $newpbq;
2295 if (!empty(array_diff_assoc($newPriceData, $lastPriceData)) || empty($conf->global->PRODUIT_MULTIPRICES)) {
2299 $this->level = $level;
2302 $result = $this->
call_trigger(
'PRODUCT_PRICE_MODIFY', $user);
2304 $this->
db->rollback();
2309 $this->
db->commit();
2311 $this->
db->rollback();
2312 $this->error = $this->
db->lasterror();
2331 $this->fk_price_expression = $expression_id;
2333 return $this->
update($this->
id, $user);
2348 public function fetch($id =
'', $ref =
'', $ref_ext =
'', $barcode =
'', $ignore_expression = 0, $ignore_price_load = 0, $ignore_lang_load = 0)
2350 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
2352 global $langs, $conf;
2354 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
2357 if (!$id && !$ref && !$ref_ext && !$barcode) {
2358 $this->error =
'ErrorWrongParameters';
2359 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
2363 $sql =
"SELECT p.rowid, p.ref, p.ref_ext, p.label, p.description, p.url, p.note_public, p.note as note_private, p.customcode, p.fk_country, p.fk_state, p.lifetime, p.qc_frequency, p.price, p.price_ttc,";
2364 $sql .=
" p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly as tva_npr, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,";
2365 $sql .=
" p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.fk_default_workstation, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,";
2366 $sql .=
" p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
2367 $sql .=
" p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished, p.fk_default_bom, p.mandatory_period,";
2368 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
2369 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
2371 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export, ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
2376 $separatedEntityPMP =
false;
2377 $separatedStock =
false;
2378 $visibleWarehousesEntities = $conf->entity;
2379 if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) {
2380 if (!empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
2381 $checkPMPPerEntity = $this->
db->query(
"SELECT pmp FROM " . $this->
db->prefix() .
"product_perentity WHERE fk_product = ".((int) $id).
" AND entity = ".(
int) $conf->entity);
2382 if ($this->
db->num_rows($checkPMPPerEntity)>0) {
2383 $separatedEntityPMP =
true;
2387 $separatedStock =
true;
2388 if (isset($mc->sharings[
'stock']) && !empty($mc->sharings[
'stock'])) {
2389 $visibleWarehousesEntities .=
"," . implode(
",", $mc->sharings[
'stock']);
2392 if ($separatedEntityPMP) {
2393 $sql .=
" ppe.pmp,";
2397 $sql .=
" p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
2398 $sql .=
" p.fk_price_expression, p.price_autogen, p.model_pdf,";
2399 if ($separatedStock) {
2400 $sql .=
" SUM(sp.reel) as stock";
2404 $sql .=
" FROM ".$this->db->prefix().
"product as p";
2405 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) || $separatedEntityPMP) {
2406 $sql .=
" LEFT JOIN " . $this->
db->prefix() .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
2408 if ($separatedStock) {
2409 $sql .=
" LEFT JOIN " . $this->
db->prefix() .
"product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".$this->db->prefix().
"entrepot WHERE entity IN (".$this->
db->sanitize($visibleWarehousesEntities).
"))";
2413 $sql .=
" WHERE p.rowid = ".((int) $id);
2415 $sql .=
" WHERE p.entity IN (".getEntity($this->element).
")";
2417 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
2418 } elseif ($ref_ext) {
2419 $sql .=
" AND p.ref_ext = '".$this->db->escape($ref_ext).
"'";
2420 } elseif ($barcode) {
2421 $sql .=
" AND p.barcode = '".$this->db->escape($barcode).
"'";
2424 if ($separatedStock) {
2425 $sql .=
" GROUP BY p.rowid, p.ref, p.ref_ext, p.label, p.description, p.url, p.note_public, p.note, p.customcode, p.fk_country, p.fk_state, p.lifetime, p.qc_frequency, p.price, p.price_ttc,";
2426 $sql .=
" p.price_min, p.price_min_ttc, p.price_base_type, p.cost_price, p.default_vat_code, p.tva_tx, p.recuperableonly, p.localtax1_tx, p.localtax2_tx, p.localtax1_type, p.localtax2_type, p.tosell,";
2427 $sql .=
" p.tobuy, p.fk_product_type, p.duration, p.fk_default_warehouse, p.fk_default_workstation, p.seuil_stock_alerte, p.canvas, p.net_measure, p.net_measure_units, p.weight, p.weight_units,";
2428 $sql .=
" p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
2429 $sql .=
" p.surface, p.surface_units, p.volume, p.volume_units, p.barcode, p.fk_barcode_type, p.finished,";
2430 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
2431 $sql .=
" p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export, p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export,";
2433 $sql .=
" ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export, ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
2435 if ($separatedEntityPMP) {
2436 $sql .=
" ppe.pmp,";
2440 $sql .=
" p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
2441 $sql .=
" p.fk_price_expression, p.price_autogen, p.model_pdf";
2442 if (!$separatedStock) {
2443 $sql .=
", p.stock";
2449 unset($this->oldcopy);
2451 if ($this->
db->num_rows(
$resql) > 0) {
2452 $obj = $this->
db->fetch_object(
$resql);
2454 $this->
id = $obj->rowid;
2455 $this->
ref = $obj->ref;
2456 $this->ref_ext = $obj->ref_ext;
2457 $this->label = $obj->label;
2459 $this->url = $obj->url;
2460 $this->note_public = $obj->note_public;
2461 $this->note_private = $obj->note_private;
2462 $this->note = $obj->note_private;
2464 $this->
type = $obj->fk_product_type;
2465 $this->status = $obj->tosell;
2466 $this->status_buy = $obj->tobuy;
2467 $this->status_batch = $obj->tobatch;
2468 $this->batch_mask = $obj->batch_mask;
2470 $this->customcode = $obj->customcode;
2471 $this->country_id = $obj->fk_country;
2472 $this->country_code =
getCountry($this->country_id, 2, $this->
db);
2473 $this->state_id = $obj->fk_state;
2474 $this->lifetime = $obj->lifetime;
2475 $this->qc_frequency = $obj->qc_frequency;
2476 $this->
price = $obj->price;
2477 $this->price_ttc = $obj->price_ttc;
2478 $this->price_min = $obj->price_min;
2479 $this->price_min_ttc = $obj->price_min_ttc;
2480 $this->price_base_type = $obj->price_base_type;
2481 $this->cost_price = $obj->cost_price;
2482 $this->default_vat_code = $obj->default_vat_code;
2483 $this->tva_tx = $obj->tva_tx;
2485 $this->tva_npr = $obj->tva_npr;
2486 $this->recuperableonly = $obj->tva_npr;
2488 $this->localtax1_tx = $obj->localtax1_tx;
2489 $this->localtax2_tx = $obj->localtax2_tx;
2490 $this->localtax1_type = $obj->localtax1_type;
2491 $this->localtax2_type = $obj->localtax2_type;
2493 $this->finished = $obj->finished;
2494 $this->fk_default_bom = $obj->fk_default_bom;
2496 $this->duration = $obj->duration;
2497 $this->duration_value = substr($obj->duration, 0,
dol_strlen($obj->duration) - 1);
2498 $this->duration_unit = substr($obj->duration, -1);
2499 $this->canvas = $obj->canvas;
2500 $this->net_measure = $obj->net_measure;
2501 $this->net_measure_units = $obj->net_measure_units;
2502 $this->weight = $obj->weight;
2503 $this->weight_units = $obj->weight_units;
2504 $this->length = $obj->length;
2505 $this->length_units = $obj->length_units;
2506 $this->width = $obj->width;
2507 $this->width_units = $obj->width_units;
2508 $this->height = $obj->height;
2509 $this->height_units = $obj->height_units;
2511 $this->surface = $obj->surface;
2512 $this->surface_units = $obj->surface_units;
2513 $this->volume = $obj->volume;
2514 $this->volume_units = $obj->volume_units;
2515 $this->barcode = $obj->barcode;
2516 $this->barcode_type = $obj->fk_barcode_type;
2518 $this->accountancy_code_buy = $obj->accountancy_code_buy;
2519 $this->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra;
2520 $this->accountancy_code_buy_export = $obj->accountancy_code_buy_export;
2521 $this->accountancy_code_sell = $obj->accountancy_code_sell;
2522 $this->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra;
2523 $this->accountancy_code_sell_export = $obj->accountancy_code_sell_export;
2525 $this->fk_default_warehouse = $obj->fk_default_warehouse;
2526 $this->fk_default_workstation = $obj->fk_default_workstation;
2527 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
2528 $this->desiredstock = $obj->desiredstock;
2529 $this->stock_reel = $obj->stock;
2530 $this->pmp = $obj->pmp;
2532 $this->date_creation = $obj->datec;
2533 $this->date_modification = $obj->tms;
2534 $this->import_key = $obj->import_key;
2535 $this->entity = $obj->entity;
2537 $this->ref_ext = $obj->ref_ext;
2538 $this->fk_price_expression = $obj->fk_price_expression;
2539 $this->fk_unit = $obj->fk_unit;
2540 $this->price_autogen = $obj->price_autogen;
2541 $this->model_pdf = $obj->model_pdf;
2543 $this->mandatory_period = $obj->mandatory_period;
2556 if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($ignore_price_load)) {
2557 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
2558 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
2559 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
2560 $sql .=
" FROM ".$this->db->prefix().
"product_price";
2561 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
2562 $sql .=
" AND price_level=".((int) $i);
2563 $sql .=
" AND fk_product = ".((int) $this->
id);
2564 $sql .=
" ORDER BY date_price DESC, rowid DESC";
2568 $result = $this->
db->fetch_array(
$resql);
2570 $this->multiprices[$i] = $result ? $result[
"price"] :
null;
2571 $this->multiprices_ttc[$i] = $result ? $result[
"price_ttc"] :
null;
2572 $this->multiprices_min[$i] = $result ? $result[
"price_min"] :
null;
2573 $this->multiprices_min_ttc[$i] = $result ? $result[
"price_min_ttc"] :
null;
2574 $this->multiprices_base_type[$i] = $result ? $result[
"price_base_type"] :
null;
2576 $this->multiprices_tva_tx[$i] = $result ? $result[
"tva_tx"].($result ?
' ('.$result[
'default_vat_code'].
')' :
'') :
null;
2577 $this->multiprices_recuperableonly[$i] = $result ? $result[
"recuperableonly"] :
null;
2615 $this->error = $this->
db->lasterror;
2619 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && empty($ignore_price_load)) {
2621 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && empty($ignore_price_load)) {
2622 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
2623 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid";
2624 $sql .=
" FROM ".$this->db->prefix().
"product_price";
2625 $sql .=
" WHERE fk_product = ".((int) $this->
id);
2626 $sql .=
" ORDER BY date_price DESC, rowid DESC";
2630 $result = $this->
db->fetch_array(
$resql);
2633 $this->prices_by_qty[0] = $result[
"price_by_qty"];
2634 $this->prices_by_qty_id[0] = $result[
"rowid"];
2636 if ($this->prices_by_qty[0] == 1) {
2637 $sql =
"SELECT rowid,price, unitprice, quantity, remise_percent, remise, remise, price_base_type";
2638 $sql .=
" FROM ".$this->db->prefix().
"product_price_by_qty";
2639 $sql .=
" WHERE fk_product_price = ".((int) $this->prices_by_qty_id[0]);
2640 $sql .=
" ORDER BY quantity ASC";
2641 $resultat = array();
2645 while ($result = $this->
db->fetch_array(
$resql)) {
2646 $resultat[$ii] = array();
2647 $resultat[$ii][
"rowid"] = $result[
"rowid"];
2648 $resultat[$ii][
"price"] = $result[
"price"];
2649 $resultat[$ii][
"unitprice"] = $result[
"unitprice"];
2650 $resultat[$ii][
"quantity"] = $result[
"quantity"];
2651 $resultat[$ii][
"remise_percent"] = $result[
"remise_percent"];
2653 $resultat[$ii][
"price_base_type"] = $result[
"price_base_type"];
2656 $this->prices_by_qty_list[0] = $resultat;
2658 $this->error = $this->
db->lasterror;
2663 $this->error = $this->
db->lasterror;
2666 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES) && empty($ignore_price_load)) {
2667 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
2668 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
2669 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
2670 $sql .=
" FROM ".$this->db->prefix().
"product_price";
2671 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
2672 $sql .=
" AND price_level=".((int) $i);
2673 $sql .=
" AND fk_product = ".((int) $this->
id);
2674 $sql .=
" ORDER BY date_price DESC, rowid DESC";
2678 $result = $this->
db->fetch_array(
$resql);
2680 $this->multiprices[$i] = $result[
"price"];
2681 $this->multiprices_ttc[$i] = $result[
"price_ttc"];
2682 $this->multiprices_min[$i] = $result[
"price_min"];
2683 $this->multiprices_min_ttc[$i] = $result[
"price_min_ttc"];
2684 $this->multiprices_base_type[$i] = $result[
"price_base_type"];
2686 $this->multiprices_tva_tx[$i] = $result[
"tva_tx"];
2687 $this->multiprices_recuperableonly[$i] = $result[
"recuperableonly"];
2690 $this->prices_by_qty[$i] = $result[
"price_by_qty"];
2691 $this->prices_by_qty_id[$i] = $result[
"rowid"];
2693 if ($this->prices_by_qty[$i] == 1) {
2694 $sql =
"SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type";
2695 $sql .=
" FROM ".$this->db->prefix().
"product_price_by_qty";
2696 $sql .=
" WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]);
2697 $sql .=
" ORDER BY quantity ASC";
2698 $resultat = array();
2702 while ($result = $this->
db->fetch_array(
$resql)) {
2703 $resultat[$ii] = array();
2704 $resultat[$ii][
"rowid"] = $result[
"rowid"];
2705 $resultat[$ii][
"price"] = $result[
"price"];
2706 $resultat[$ii][
"unitprice"] = $result[
"unitprice"];
2707 $resultat[$ii][
"quantity"] = $result[
"quantity"];
2708 $resultat[$ii][
"remise_percent"] = $result[
"remise_percent"];
2709 $resultat[$ii][
"remise"] = $result[
"remise"];
2710 $resultat[$ii][
"price_base_type"] = $result[
"price_base_type"];
2713 $this->prices_by_qty_list[$i] = $resultat;
2715 $this->error = $this->
db->lasterror;
2720 $this->error = $this->
db->lasterror;
2726 if (
isModEnabled(
'dynamicprices') && !empty($this->fk_price_expression) && empty($ignore_expression)) {
2727 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2729 $price_result = $priceparser->parseProduct($this);
2730 if ($price_result >= 0) {
2731 $this->
price = $price_result;
2733 $this->price_ttc =
price2num($this->
price) * (1 + ($this->tva_tx / 100));
2734 $this->price_ttc =
price2num($this->price_ttc,
'MU');
2740 $this->stock_warehouse = array();
2747 $this->error = $this->
db->lasterror();
2762 global $user, $hookmanager, $action;
2766 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
2767 $this->stats_mo[
'customers_'.$role] = 0;
2768 $this->stats_mo[
'nb_'.$role] = 0;
2769 $this->stats_mo[
'qty_'.$role] = 0;
2771 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
2772 $sql .=
" SUM(mp.qty) as qty";
2773 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
2774 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
2775 if (empty($user->rights->societe->client->voir) && !$socid) {
2776 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
2779 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
2781 $sql .=
" AND mp.fk_product = ".((int) $this->
id);
2782 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
2784 $sql .=
" AND c.fk_soc = ".((int) $socid);
2787 $result = $this->
db->query($sql);
2789 $obj = $this->
db->fetch_object($result);
2790 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
2791 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
2792 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
2794 $this->error = $this->
db->error();
2799 if (!empty($error)) {
2803 $parameters = array(
'socid' => $socid);
2804 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
2806 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
2822 global $user, $hookmanager, $action;
2826 $this->stats_bom[
'nb_toproduce'] = 0;
2827 $this->stats_bom[
'nb_toconsume'] = 0;
2828 $this->stats_bom[
'qty_toproduce'] = 0;
2829 $this->stats_bom[
'qty_toconsume'] = 0;
2831 $sql =
"SELECT COUNT(DISTINCT b.rowid) as nb_toproduce,";
2832 $sql .=
" SUM(b.qty) as qty_toproduce";
2833 $sql .=
" FROM ".$this->db->prefix().
"bom_bom as b";
2834 $sql .=
" INNER JOIN ".$this->db->prefix().
"bom_bomline as bl ON bl.fk_bom=b.rowid";
2836 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
2837 $sql .=
" AND b.fk_product =".((int) $this->
id);
2838 $sql .=
" GROUP BY b.rowid";
2840 $result = $this->
db->query($sql);
2842 $obj = $this->
db->fetch_object($result);
2843 $this->stats_bom[
'nb_toproduce'] = !empty($obj->nb_toproduce) ? $obj->nb_toproduce : 0;
2844 $this->stats_bom[
'qty_toproduce'] = !empty($obj->qty_toproduce) ?
price2num($obj->qty_toproduce) : 0;
2846 $this->error = $this->
db->error();
2850 $sql =
"SELECT COUNT(DISTINCT bl.rowid) as nb_toconsume,";
2851 $sql .=
" SUM(bl.qty) as qty_toconsume";
2852 $sql .=
" FROM ".$this->db->prefix().
"bom_bom as b";
2853 $sql .=
" INNER JOIN ".$this->db->prefix().
"bom_bomline as bl ON bl.fk_bom=b.rowid";
2855 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
2856 $sql .=
" AND bl.fk_product =".((int) $this->
id);
2858 $result = $this->
db->query($sql);
2860 $obj = $this->
db->fetch_object($result);
2861 $this->stats_bom[
'nb_toconsume'] = !empty($obj->nb_toconsume) ? $obj->nb_toconsume : 0;
2862 $this->stats_bom[
'qty_toconsume'] = !empty($obj->qty_toconsume) ?
price2num($obj->qty_toconsume) : 0;
2864 $this->error = $this->
db->error();
2868 if (!empty($error)) {
2872 $parameters = array(
'socid' => $socid);
2873 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
2875 $this->stats_bom = $hookmanager->resArray[
'stats_bom'];
2891 global $conf, $user, $hookmanager, $action;
2893 $sql =
"SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,";
2894 $sql .=
" COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
2895 $sql .=
" FROM ".$this->db->prefix().
"propaldet as pd";
2896 $sql .=
", ".$this->db->prefix().
"propal as p";
2897 $sql .=
", ".$this->db->prefix().
"societe as s";
2898 if (empty($user->rights->societe->client->voir) && !$socid) {
2899 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
2901 $sql .=
" WHERE p.rowid = pd.fk_propal";
2902 $sql .=
" AND p.fk_soc = s.rowid";
2903 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
2904 $sql .=
" AND pd.fk_product = ".((int) $this->
id);
2905 if (empty($user->rights->societe->client->voir) && !$socid) {
2906 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2910 $sql .=
" AND p.fk_soc = ".((int) $socid);
2913 $result = $this->
db->query($sql);
2915 $obj = $this->
db->fetch_object($result);
2916 $this->stats_propale[
'customers'] = $obj->nb_customers;
2917 $this->stats_propale[
'nb'] = $obj->nb;
2918 $this->stats_propale[
'rows'] = $obj->nb_rows;
2919 $this->stats_propale[
'qty'] = $obj->qty ? $obj->qty : 0;
2922 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
2924 if (is_array($TFather) && !empty($TFather)) {
2925 foreach ($TFather as &$fatherData) {
2927 $pFather->id = $fatherData[
'id'];
2928 $qtyCoef = $fatherData[
'qty'];
2930 if ($fatherData[
'incdec']) {
2931 $pFather->load_stats_propale($socid);
2933 $this->stats_propale[
'customers'] += $pFather->stats_propale[
'customers'];
2934 $this->stats_propale[
'nb'] += $pFather->stats_propale[
'nb'];
2935 $this->stats_propale[
'rows'] += $pFather->stats_propale[
'rows'];
2936 $this->stats_propale[
'qty'] += $pFather->stats_propale[
'qty'] * $qtyCoef;
2942 $parameters = array(
'socid' => $socid);
2943 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerProposal', $parameters, $this, $action);
2945 $this->stats_propale = $hookmanager->resArray[
'stats_propale'];
2950 $this->error = $this->
db->error();
2966 global $conf, $user, $hookmanager, $action;
2968 $sql =
"SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,";
2969 $sql .=
" COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
2970 $sql .=
" FROM ".$this->db->prefix().
"supplier_proposaldet as pd";
2971 $sql .=
", ".$this->db->prefix().
"supplier_proposal as p";
2972 $sql .=
", ".$this->db->prefix().
"societe as s";
2973 if (empty($user->rights->societe->client->voir) && !$socid) {
2974 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
2976 $sql .=
" WHERE p.rowid = pd.fk_supplier_proposal";
2977 $sql .=
" AND p.fk_soc = s.rowid";
2978 $sql .=
" AND p.entity IN (".getEntity(
'supplier_proposal').
")";
2979 $sql .=
" AND pd.fk_product = ".((int) $this->
id);
2980 if (empty($user->rights->societe->client->voir) && !$socid) {
2981 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2985 $sql .=
" AND p.fk_soc = ".((int) $socid);
2988 $result = $this->
db->query($sql);
2990 $obj = $this->
db->fetch_object($result);
2991 $this->stats_proposal_supplier[
'suppliers'] = $obj->nb_suppliers;
2992 $this->stats_proposal_supplier[
'nb'] = $obj->nb;
2993 $this->stats_proposal_supplier[
'rows'] = $obj->nb_rows;
2994 $this->stats_proposal_supplier[
'qty'] = $obj->qty ? $obj->qty : 0;
2996 $parameters = array(
'socid' => $socid);
2997 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierProposal', $parameters, $this, $action);
2999 $this->stats_proposal_supplier = $hookmanager->resArray[
'stats_proposal_supplier'];
3004 $this->error = $this->
db->error();
3022 global $conf, $user, $hookmanager, $action;
3024 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
3025 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
3026 $sql .=
" FROM ".$this->db->prefix().
"commandedet as cd";
3027 $sql .=
", ".$this->db->prefix().
"commande as c";
3028 $sql .=
", ".$this->db->prefix().
"societe as s";
3029 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3030 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3032 $sql .=
" WHERE c.rowid = cd.fk_commande";
3033 $sql .=
" AND c.fk_soc = s.rowid";
3034 $sql .=
" AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'commande').
")";
3035 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
3036 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3037 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3040 $sql .=
" AND c.fk_soc = ".((int) $socid);
3042 if ($filtrestatut <>
'') {
3043 $sql .=
" AND c.fk_statut in (".$this->db->sanitize($filtrestatut).
")";
3046 $result = $this->
db->query($sql);
3048 $obj = $this->
db->fetch_object($result);
3049 $this->stats_commande[
'customers'] = $obj->nb_customers;
3050 $this->stats_commande[
'nb'] = $obj->nb;
3051 $this->stats_commande[
'rows'] = $obj->nb_rows;
3052 $this->stats_commande[
'qty'] = $obj->qty ? $obj->qty : 0;
3055 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
3057 if (is_array($TFather) && !empty($TFather)) {
3058 foreach ($TFather as &$fatherData) {
3060 $pFather->id = $fatherData[
'id'];
3061 $qtyCoef = $fatherData[
'qty'];
3063 if ($fatherData[
'incdec']) {
3064 $pFather->load_stats_commande($socid, $filtrestatut);
3066 $this->stats_commande[
'customers'] += $pFather->stats_commande[
'customers'];
3067 $this->stats_commande[
'nb'] += $pFather->stats_commande[
'nb'];
3068 $this->stats_commande[
'rows'] += $pFather->stats_commande[
'rows'];
3069 $this->stats_commande[
'qty'] += $pFather->stats_commande[
'qty'] * $qtyCoef;
3077 if ($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
3078 if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) {
3081 $sql =
"SELECT sum(fd.qty) as count FROM ".$this->db->prefix().
"facturedet as fd ";
3082 $sql .=
" JOIN ".$this->db->prefix().
"facture as f ON fd.fk_facture = f.rowid ";
3083 $sql .=
" JOIN ".$this->db->prefix().
"element_element as el ON ((el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande') OR (el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture'))";
3084 $sql .=
" JOIN ".$this->db->prefix().
"commande as c ON el.fk_source = c.rowid ";
3085 $sql .=
" WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).
") AND c.facture = 0 AND fd.fk_product = ".((int) $this->
id);
3086 dol_syslog(__METHOD__.
":: sql $sql", LOG_NOTICE);
3089 if ($this->
db->num_rows(
$resql) > 0) {
3090 $obj = $this->
db->fetch_object(
$resql);
3091 $adeduire += $obj->count;
3095 $this->stats_commande[
'qty'] -= $adeduire;
3098 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
3102 $sql =
'SELECT sum(fd.qty) as count FROM '.MAIN_DB_PREFIX.
'facturedet as fd ';
3103 $sql .=
' JOIN '.MAIN_DB_PREFIX.
'facture as f ON fd.fk_facture = f.rowid ';
3104 $sql .=
' JOIN '.MAIN_DB_PREFIX.
"element_element as el ON ((el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande') OR (el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture'))";
3105 $sql .=
' JOIN '.MAIN_DB_PREFIX.
'commande as c ON el.fk_source = c.rowid ';
3106 $sql .=
' WHERE c.fk_statut IN ('.$this->db->sanitize($filtrestatut).
') AND f.fk_statut > '.
Facture::STATUS_DRAFT.
' AND fd.fk_product = '.((int) $this->
id);
3107 dol_syslog(__METHOD__.
":: sql $sql", LOG_NOTICE);
3110 if ($this->
db->num_rows(
$resql) > 0) {
3111 $obj = $this->
db->fetch_object(
$resql);
3112 $adeduire += $obj->count;
3116 $this->stats_commande[
'qty'] -= $adeduire;
3120 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
3121 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerOrder', $parameters, $this, $action);
3123 $this->stats_commande = $hookmanager->resArray[
'stats_commande'];
3127 $this->error = $this->
db->error();
3145 global $conf, $user, $hookmanager, $action;
3147 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,";
3148 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
3149 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as cd";
3150 $sql .=
", ".$this->db->prefix().
"commande_fournisseur as c";
3151 $sql .=
", ".$this->db->prefix().
"societe as s";
3152 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3153 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3155 $sql .=
" WHERE c.rowid = cd.fk_commande";
3156 $sql .=
" AND c.fk_soc = s.rowid";
3157 $sql .=
" AND c.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'supplier_order').
")";
3158 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
3159 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3160 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3163 $sql .=
" AND c.fk_soc = ".((int) $socid);
3165 if ($filtrestatut !=
'') {
3166 $sql .=
" AND c.fk_statut in (".$this->db->sanitize($filtrestatut).
")";
3168 if (!empty($dateofvirtualstock)) {
3169 $sql .=
" AND c.date_livraison <= '".$this->db->idate($dateofvirtualstock).
"'";
3172 $result = $this->
db->query($sql);
3174 $obj = $this->
db->fetch_object($result);
3175 $this->stats_commande_fournisseur[
'suppliers'] = $obj->nb_suppliers;
3176 $this->stats_commande_fournisseur[
'nb'] = $obj->nb;
3177 $this->stats_commande_fournisseur[
'rows'] = $obj->nb_rows;
3178 $this->stats_commande_fournisseur[
'qty'] = $obj->qty ? $obj->qty : 0;
3180 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
3181 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierOrder', $parameters, $this, $action);
3183 $this->stats_commande_fournisseur = $hookmanager->resArray[
'stats_commande_fournisseur'];
3188 $this->error = $this->
db->error().
' sql='.$sql;
3203 public function load_stats_sending($socid = 0, $filtrestatut =
'', $forVirtualStock = 0, $filterShipmentStatus =
'')
3206 global $conf, $user, $hookmanager, $action;
3208 $sql =
"SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,";
3209 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
3210 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
3211 $sql .=
", ".$this->db->prefix().
"commandedet as cd";
3212 $sql .=
", ".$this->db->prefix().
"commande as c";
3213 $sql .=
", ".$this->db->prefix().
"expedition as e";
3214 $sql .=
", ".$this->db->prefix().
"societe as s";
3215 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3216 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3218 $sql .=
" WHERE e.rowid = ed.fk_expedition";
3219 $sql .=
" AND c.rowid = cd.fk_commande";
3220 $sql .=
" AND e.fk_soc = s.rowid";
3221 $sql .=
" AND e.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'expedition').
")";
3222 $sql .=
" AND ed.fk_origin_line = cd.rowid";
3223 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
3224 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3225 $sql .=
" AND e.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3228 $sql .=
" AND e.fk_soc = ".((int) $socid);
3230 if ($filtrestatut <>
'') {
3231 $sql .=
" AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).
")";
3233 if (!empty($filterShipmentStatus)) {
3234 $sql .=
" AND e.fk_statut IN (".$this->db->sanitize($filterShipmentStatus).
")";
3237 $result = $this->
db->query($sql);
3239 $obj = $this->
db->fetch_object($result);
3240 $this->stats_expedition[
'customers'] = $obj->nb_customers;
3241 $this->stats_expedition[
'nb'] = $obj->nb;
3242 $this->stats_expedition[
'rows'] = $obj->nb_rows;
3243 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
3246 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
3248 if (is_array($TFather) && !empty($TFather)) {
3249 foreach ($TFather as &$fatherData) {
3251 $pFather->id = $fatherData[
'id'];
3252 $qtyCoef = $fatherData[
'qty'];
3254 if ($fatherData[
'incdec']) {
3255 $pFather->load_stats_sending($socid, $filtrestatut, $forVirtualStock);
3257 $this->stats_expedition[
'customers'] += $pFather->stats_expedition[
'customers'];
3258 $this->stats_expedition[
'nb'] += $pFather->stats_expedition[
'nb'];
3259 $this->stats_expedition[
'rows'] += $pFather->stats_expedition[
'rows'];
3260 $this->stats_expedition[
'qty'] += $pFather->stats_expedition[
'qty'] * $qtyCoef;
3266 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock,
'filterShipmentStatus' => $filterShipmentStatus);
3267 $reshook = $hookmanager->executeHooks(
'loadStatsSending', $parameters, $this, $action);
3269 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
3274 $this->error = $this->
db->error();
3289 public function load_stats_reception($socid = 0, $filtrestatut =
'', $forVirtualStock = 0, $dateofvirtualstock =
null)
3292 global $conf, $user, $hookmanager, $action;
3294 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,";
3295 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
3296 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur_dispatch as fd";
3297 $sql .=
", ".$this->db->prefix().
"commande_fournisseur as cf";
3298 $sql .=
", ".$this->db->prefix().
"societe as s";
3299 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3300 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3302 $sql .=
" WHERE cf.rowid = fd.fk_commande";
3303 $sql .=
" AND cf.fk_soc = s.rowid";
3304 $sql .=
" AND cf.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'supplier_order').
")";
3305 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
3306 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3307 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3310 $sql .=
" AND cf.fk_soc = ".((int) $socid);
3312 if ($filtrestatut <>
'') {
3313 $sql .=
" AND cf.fk_statut IN (".$this->db->sanitize($filtrestatut).
")";
3315 if (!empty($dateofvirtualstock)) {
3316 $sql .=
" AND fd.datec <= '".$this->db->idate($dateofvirtualstock).
"'";
3319 $result = $this->
db->query($sql);
3321 $obj = $this->
db->fetch_object($result);
3322 $this->stats_reception[
'suppliers'] = $obj->nb_suppliers;
3323 $this->stats_reception[
'nb'] = $obj->nb;
3324 $this->stats_reception[
'rows'] = $obj->nb_rows;
3325 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
3327 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
3328 $reshook = $hookmanager->executeHooks(
'loadStatsReception', $parameters, $this, $action);
3330 $this->stats_reception = $hookmanager->resArray[
'stats_reception'];
3335 $this->error = $this->
db->error();
3353 global $conf, $user, $hookmanager, $action;
3355 $sql =
"SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,";
3356 $sql .=
" COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role";
3357 $sql .=
" FROM ".$this->db->prefix().
"mrp_production as mp";
3358 $sql .=
", ".$this->db->prefix().
"mrp_mo as m";
3359 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON s.rowid = m.fk_soc";
3360 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3361 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3363 $sql .=
" WHERE m.rowid = mp.fk_mo";
3364 $sql .=
" AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ?
'stock' :
'mrp').
")";
3365 $sql .=
" AND mp.fk_product = ".((int) $this->
id);
3366 if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) {
3367 $sql .=
" AND m.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3370 $sql .=
" AND m.fk_soc = ".((int) $socid);
3372 if ($filtrestatut <>
'') {
3373 $sql .=
" AND m.status IN (".$this->db->sanitize($filtrestatut).
")";
3375 if (!empty($dateofvirtualstock)) {
3376 $sql .=
" AND m.date_valid <= '".$this->db->idate($dateofvirtualstock).
"'";
3378 $sql .=
" GROUP BY role";
3380 $this->stats_mrptoconsume[
'customers'] = 0;
3381 $this->stats_mrptoconsume[
'nb'] = 0;
3382 $this->stats_mrptoconsume[
'rows'] = 0;
3383 $this->stats_mrptoconsume[
'qty'] = 0;
3384 $this->stats_mrptoproduce[
'customers'] = 0;
3385 $this->stats_mrptoproduce[
'nb'] = 0;
3386 $this->stats_mrptoproduce[
'rows'] = 0;
3387 $this->stats_mrptoproduce[
'qty'] = 0;
3389 $result = $this->
db->query($sql);
3391 while ($obj = $this->
db->fetch_object($result)) {
3392 if ($obj->role ==
'toconsume') {
3393 $this->stats_mrptoconsume[
'customers'] += $obj->nb_customers;
3394 $this->stats_mrptoconsume[
'nb'] += $obj->nb;
3395 $this->stats_mrptoconsume[
'rows'] += $obj->nb_rows;
3396 $this->stats_mrptoconsume[
'qty'] += ($obj->qty ? $obj->qty : 0);
3398 if ($obj->role ==
'consumed') {
3402 $this->stats_mrptoconsume[
'qty'] -= ($obj->qty ? $obj->qty : 0);
3404 if ($obj->role ==
'toproduce') {
3405 $this->stats_mrptoproduce[
'customers'] += $obj->nb_customers;
3406 $this->stats_mrptoproduce[
'nb'] += $obj->nb;
3407 $this->stats_mrptoproduce[
'rows'] += $obj->nb_rows;
3408 $this->stats_mrptoproduce[
'qty'] += ($obj->qty ? $obj->qty : 0);
3410 if ($obj->role ==
'produced') {
3414 $this->stats_mrptoproduce[
'qty'] -= ($obj->qty ? $obj->qty : 0);
3419 if ($this->stats_mrptoconsume[
'qty'] < 0) {
3420 $this->stats_mrptoconsume[
'qty'] = 0;
3422 if ($this->stats_mrptoproduce[
'qty'] < 0) {
3423 $this->stats_mrptoproduce[
'qty'] = 0;
3426 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
3427 $reshook = $hookmanager->executeHooks(
'loadStatsInProduction', $parameters, $this, $action);
3429 $this->stats_mrptoproduce = $hookmanager->resArray[
'stats_mrptoproduce'];
3434 $this->error = $this->
db->error();
3449 global $conf, $user, $hookmanager, $action;
3451 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
3452 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
3453 $sql .=
" FROM ".$this->db->prefix().
"contratdet as cd";
3454 $sql .=
", ".$this->db->prefix().
"contrat as c";
3455 $sql .=
", ".$this->db->prefix().
"societe as s";
3456 if (empty($user->rights->societe->client->voir) && !$socid) {
3457 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3459 $sql .=
" WHERE c.rowid = cd.fk_contrat";
3460 $sql .=
" AND c.fk_soc = s.rowid";
3461 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
3462 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
3463 if (empty($user->rights->societe->client->voir) && !$socid) {
3464 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3468 $sql .=
" AND c.fk_soc = ".((int) $socid);
3471 $result = $this->
db->query($sql);
3473 $obj = $this->
db->fetch_object($result);
3474 $this->stats_contrat[
'customers'] = $obj->nb_customers;
3475 $this->stats_contrat[
'nb'] = $obj->nb;
3476 $this->stats_contrat[
'rows'] = $obj->nb_rows;
3477 $this->stats_contrat[
'qty'] = $obj->qty ? $obj->qty : 0;
3480 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
3482 if (is_array($TFather) && !empty($TFather)) {
3483 foreach ($TFather as &$fatherData) {
3485 $pFather->id = $fatherData[
'id'];
3486 $qtyCoef = $fatherData[
'qty'];
3488 if ($fatherData[
'incdec']) {
3489 $pFather->load_stats_contrat($socid);
3491 $this->stats_contrat[
'customers'] += $pFather->stats_contrat[
'customers'];
3492 $this->stats_contrat[
'nb'] += $pFather->stats_contrat[
'nb'];
3493 $this->stats_contrat[
'rows'] += $pFather->stats_contrat[
'rows'];
3494 $this->stats_contrat[
'qty'] += $pFather->stats_contrat[
'qty'] * $qtyCoef;
3500 $parameters = array(
'socid' => $socid);
3501 $reshook = $hookmanager->executeHooks(
'loadStatsContract', $parameters, $this, $action);
3503 $this->stats_contrat = $hookmanager->resArray[
'stats_contrat'];
3508 $this->error = $this->
db->error().
' sql='.$sql;
3523 global $db, $conf, $user, $hookmanager, $action;
3525 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,";
3526 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(".$this->db->ifsql(
'f.type != 2',
'fd.qty',
'fd.qty * -1').
") as qty";
3527 $sql .=
" FROM ".$this->db->prefix().
"facturedet as fd";
3528 $sql .=
", ".$this->db->prefix().
"facture as f";
3529 $sql .=
", ".$this->db->prefix().
"societe as s";
3530 if (empty($user->rights->societe->client->voir) && !$socid) {
3531 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3533 $sql .=
" WHERE f.rowid = fd.fk_facture";
3534 $sql .=
" AND f.fk_soc = s.rowid";
3535 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
3536 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
3537 if (empty($user->rights->societe->client->voir) && !$socid) {
3538 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3542 $sql .=
" AND f.fk_soc = ".((int) $socid);
3545 $result = $this->
db->query($sql);
3547 $obj = $this->
db->fetch_object($result);
3548 $this->stats_facture[
'customers'] = $obj->nb_customers;
3549 $this->stats_facture[
'nb'] = $obj->nb;
3550 $this->stats_facture[
'rows'] = $obj->nb_rows;
3551 $this->stats_facture[
'qty'] = $obj->qty ? $obj->qty : 0;
3554 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
3556 if (is_array($TFather) && !empty($TFather)) {
3557 foreach ($TFather as &$fatherData) {
3559 $pFather->id = $fatherData[
'id'];
3560 $qtyCoef = $fatherData[
'qty'];
3562 if ($fatherData[
'incdec']) {
3563 $pFather->load_stats_facture($socid);
3565 $this->stats_facture[
'customers'] += $pFather->stats_facture[
'customers'];
3566 $this->stats_facture[
'nb'] += $pFather->stats_facture[
'nb'];
3567 $this->stats_facture[
'rows'] += $pFather->stats_facture[
'rows'];
3568 $this->stats_facture[
'qty'] += $pFather->stats_facture[
'qty'] * $qtyCoef;
3574 $parameters = array(
'socid' => $socid);
3575 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerInvoice', $parameters, $this, $action);
3577 $this->stats_facture = $hookmanager->resArray[
'stats_facture'];
3582 $this->error = $this->
db->error();
3598 global $db, $conf, $user, $hookmanager;
3600 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,";
3601 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
3602 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet_rec as fd";
3603 $sql .=
", ".MAIN_DB_PREFIX.
"facture_rec as f";
3604 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
3605 if (empty($user->rights->societe->client->voir) && !$socid) {
3606 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
3608 $sql .=
" WHERE f.rowid = fd.fk_facture";
3609 $sql .=
" AND f.fk_soc = s.rowid";
3610 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
3611 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
3612 if (empty($user->rights->societe->client->voir) && !$socid) {
3613 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3617 $sql .=
" AND f.fk_soc = ".((int) $socid);
3620 $result = $this->
db->query($sql);
3622 $obj = $this->
db->fetch_object($result);
3623 $this->stats_facturerec[
'customers'] = $obj->nb_customers;
3624 $this->stats_facturerec[
'nb'] = $obj->nb;
3625 $this->stats_facturerec[
'rows'] = $obj->nb_rows;
3626 $this->stats_facturerec[
'qty'] = $obj->qty ? $obj->qty : 0;
3629 if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
3631 if (is_array($TFather) && !empty($TFather)) {
3632 foreach ($TFather as &$fatherData) {
3634 $pFather->id = $fatherData[
'id'];
3635 $qtyCoef = $fatherData[
'qty'];
3637 if ($fatherData[
'incdec']) {
3638 $pFather->load_stats_facture($socid);
3640 $this->stats_facturerec[
'customers'] += $pFather->stats_facturerec[
'customers'];
3641 $this->stats_facturerec[
'nb'] += $pFather->stats_facturerec[
'nb'];
3642 $this->stats_facturerec[
'rows'] += $pFather->stats_facturerec[
'rows'];
3643 $this->stats_facturerec[
'qty'] += $pFather->stats_facturerec[
'qty'] * $qtyCoef;
3649 $parameters = array(
'socid' => $socid);
3650 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerInvoiceRec', $parameters, $this, $action);
3652 $this->stats_facturerec = $hookmanager->resArray[
'stats_facturerec'];
3657 $this->error = $this->
db->error();
3672 global $conf, $user, $hookmanager, $action;
3674 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,";
3675 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
3676 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn_det as fd";
3677 $sql .=
", ".$this->db->prefix().
"facture_fourn as f";
3678 $sql .=
", ".$this->db->prefix().
"societe as s";
3679 if (empty($user->rights->societe->client->voir) && !$socid) {
3680 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3682 $sql .=
" WHERE f.rowid = fd.fk_facture_fourn";
3683 $sql .=
" AND f.fk_soc = s.rowid";
3684 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
3685 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
3686 if (empty($user->rights->societe->client->voir) && !$socid) {
3687 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3691 $sql .=
" AND f.fk_soc = ".((int) $socid);
3694 $result = $this->
db->query($sql);
3696 $obj = $this->
db->fetch_object($result);
3697 $this->stats_facture_fournisseur[
'suppliers'] = $obj->nb_suppliers;
3698 $this->stats_facture_fournisseur[
'nb'] = $obj->nb;
3699 $this->stats_facture_fournisseur[
'rows'] = $obj->nb_rows;
3700 $this->stats_facture_fournisseur[
'qty'] = $obj->qty ? $obj->qty : 0;
3702 $parameters = array(
'socid' => $socid);
3703 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierInvoice', $parameters, $this, $action);
3705 $this->stats_facture_fournisseur = $hookmanager->resArray[
'stats_facture_fournisseur'];
3710 $this->error = $this->
db->error();
3731 $num = $this->
db->num_rows(
$resql);
3734 $arr = $this->
db->fetch_array(
$resql);
3735 $keyfortab = (string) $arr[1];
3737 $keyfortab = substr($keyfortab, -2);
3740 if ($mode ==
'byunit') {
3741 $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[0];
3742 } elseif ($mode ==
'bynumber') {
3743 $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[2];
3748 $this->error = $this->
db->error().
' sql='.$sql;
3753 $year = strftime(
'%Y', time());
3754 $month = strftime(
'%m', time());
3755 } elseif ($year == -1) {
3764 for ($j = 0; $j < 12; $j++) {
3766 $idx = ucfirst(
dol_trunc(
dol_print_date(
dol_mktime(12, 0, 0, $month, 1, 1970),
"%b"), 1,
'right',
'UTF-8', 1));
3769 $result[$j] = array($idx, isset($tab[$year.$month]) ? $tab[$year.$month] : 0);
3772 $month =
"0".($month - 1);
3774 $month = substr($month, 1);
3782 return array_reverse($result);
3797 public function get_nb_vente($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
3803 $sql =
"SELECT sum(d.qty), date_format(f.datef, '%Y%m')";
3804 if ($mode ==
'bynumber') {
3805 $sql .=
", count(DISTINCT f.rowid)";
3807 $sql .=
" FROM ".$this->db->prefix().
"facturedet as d, ".$this->
db->prefix().
"facture as f, ".$this->
db->prefix().
"societe as s";
3808 if ($filteronproducttype >= 0) {
3809 $sql .=
", ".$this->db->prefix().
"product as p";
3811 if (empty($user->rights->societe->client->voir) && !$socid) {
3812 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3814 $sql .=
" WHERE f.rowid = d.fk_facture";
3815 if ($this->
id > 0) {
3816 $sql .=
" AND d.fk_product = ".((int) $this->
id);
3818 $sql .=
" AND d.fk_product > 0";
3820 if ($filteronproducttype >= 0) {
3821 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
3823 $sql .=
" AND f.fk_soc = s.rowid";
3824 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
3825 if (empty($user->rights->societe->client->voir) && !$socid) {
3826 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3829 $sql .=
" AND f.fk_soc = $socid";
3831 $sql .= $morefilter;
3832 $sql .=
" GROUP BY date_format(f.datef,'%Y%m')";
3833 $sql .=
" ORDER BY date_format(f.datef,'%Y%m') DESC";
3835 return $this->
_get_stats($sql, $mode, $year);
3850 public function get_nb_achat($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
3856 $sql =
"SELECT sum(d.qty), date_format(f.datef, '%Y%m')";
3857 if ($mode ==
'bynumber') {
3858 $sql .=
", count(DISTINCT f.rowid)";
3860 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn_det as d, ".$this->
db->prefix().
"facture_fourn as f, ".$this->
db->prefix().
"societe as s";
3861 if ($filteronproducttype >= 0) {
3862 $sql .=
", ".$this->db->prefix().
"product as p";
3864 if (empty($user->rights->societe->client->voir) && !$socid) {
3865 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3867 $sql .=
" WHERE f.rowid = d.fk_facture_fourn";
3868 if ($this->
id > 0) {
3869 $sql .=
" AND d.fk_product = ".((int) $this->
id);
3871 $sql .=
" AND d.fk_product > 0";
3873 if ($filteronproducttype >= 0) {
3874 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
3876 $sql .=
" AND f.fk_soc = s.rowid";
3877 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
3878 if (empty($user->rights->societe->client->voir) && !$socid) {
3879 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3882 $sql .=
" AND f.fk_soc = $socid";
3884 $sql .= $morefilter;
3885 $sql .=
" GROUP BY date_format(f.datef,'%Y%m')";
3886 $sql .=
" ORDER BY date_format(f.datef,'%Y%m') DESC";
3888 return $this->
_get_stats($sql, $mode, $year);
3902 public function get_nb_propal($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
3905 global $conf, $user;
3907 $sql =
"SELECT sum(d.qty), date_format(p.datep, '%Y%m')";
3908 if ($mode ==
'bynumber') {
3909 $sql .=
", count(DISTINCT p.rowid)";
3911 $sql .=
" FROM ".$this->db->prefix().
"propaldet as d, ".$this->
db->prefix().
"propal as p, ".$this->
db->prefix().
"societe as s";
3912 if ($filteronproducttype >= 0) {
3913 $sql .=
", ".$this->db->prefix().
"product as prod";
3915 if (empty($user->rights->societe->client->voir) && !$socid) {
3916 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3918 $sql .=
" WHERE p.rowid = d.fk_propal";
3919 if ($this->
id > 0) {
3920 $sql .=
" AND d.fk_product = ".((int) $this->
id);
3922 $sql .=
" AND d.fk_product > 0";
3924 if ($filteronproducttype >= 0) {
3925 $sql .=
" AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype);
3927 $sql .=
" AND p.fk_soc = s.rowid";
3928 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
3929 if (empty($user->rights->societe->client->voir) && !$socid) {
3930 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3933 $sql .=
" AND p.fk_soc = ".((int) $socid);
3935 $sql .= $morefilter;
3936 $sql .=
" GROUP BY date_format(p.datep,'%Y%m')";
3937 $sql .=
" ORDER BY date_format(p.datep,'%Y%m') DESC";
3939 return $this->
_get_stats($sql, $mode, $year);
3959 $sql =
"SELECT sum(d.qty), date_format(p.date_valid, '%Y%m')";
3960 if ($mode ==
'bynumber') {
3961 $sql .=
", count(DISTINCT p.rowid)";
3963 $sql .=
" FROM ".$this->db->prefix().
"supplier_proposaldet as d, ".$this->
db->prefix().
"supplier_proposal as p, ".$this->
db->prefix().
"societe as s";
3964 if ($filteronproducttype >= 0) {
3965 $sql .=
", ".$this->db->prefix().
"product as prod";
3967 if (empty($user->rights->societe->client->voir) && !$socid) {
3968 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
3970 $sql .=
" WHERE p.rowid = d.fk_supplier_proposal";
3971 if ($this->
id > 0) {
3972 $sql .=
" AND d.fk_product = ".((int) $this->
id);
3974 $sql .=
" AND d.fk_product > 0";
3976 if ($filteronproducttype >= 0) {
3977 $sql .=
" AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype);
3979 $sql .=
" AND p.fk_soc = s.rowid";
3980 $sql .=
" AND p.entity IN (".getEntity(
'supplier_proposal').
")";
3981 if (empty($user->rights->societe->client->voir) && !$socid) {
3982 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3985 $sql .=
" AND p.fk_soc = ".((int) $socid);
3987 $sql .= $morefilter;
3988 $sql .=
" GROUP BY date_format(p.date_valid,'%Y%m')";
3989 $sql .=
" ORDER BY date_format(p.date_valid,'%Y%m') DESC";
3991 return $this->
_get_stats($sql, $mode, $year);
4005 public function get_nb_order($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4008 global $conf, $user;
4010 $sql =
"SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')";
4011 if ($mode ==
'bynumber') {
4012 $sql .=
", count(DISTINCT c.rowid)";
4014 $sql .=
" FROM ".$this->db->prefix().
"commandedet as d, ".$this->
db->prefix().
"commande as c, ".$this->
db->prefix().
"societe as s";
4015 if ($filteronproducttype >= 0) {
4016 $sql .=
", ".$this->db->prefix().
"product as p";
4018 if (empty($user->rights->societe->client->voir) && !$socid) {
4019 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4021 $sql .=
" WHERE c.rowid = d.fk_commande";
4022 if ($this->
id > 0) {
4023 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4025 $sql .=
" AND d.fk_product > 0";
4027 if ($filteronproducttype >= 0) {
4028 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4030 $sql .=
" AND c.fk_soc = s.rowid";
4031 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
4032 if (empty($user->rights->societe->client->voir) && !$socid) {
4033 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4036 $sql .=
" AND c.fk_soc = ".((int) $socid);
4038 $sql .= $morefilter;
4039 $sql .=
" GROUP BY date_format(c.date_commande,'%Y%m')";
4040 $sql .=
" ORDER BY date_format(c.date_commande,'%Y%m') DESC";
4042 return $this->
_get_stats($sql, $mode, $year);
4059 global $conf, $user;
4061 $sql =
"SELECT sum(d.qty), date_format(c.date_commande, '%Y%m')";
4062 if ($mode ==
'bynumber') {
4063 $sql .=
", count(DISTINCT c.rowid)";
4065 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as d, ".$this->
db->prefix().
"commande_fournisseur as c, ".$this->
db->prefix().
"societe as s";
4066 if ($filteronproducttype >= 0) {
4067 $sql .=
", ".$this->db->prefix().
"product as p";
4069 if (empty($user->rights->societe->client->voir) && !$socid) {
4070 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4072 $sql .=
" WHERE c.rowid = d.fk_commande";
4073 if ($this->
id > 0) {
4074 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4076 $sql .=
" AND d.fk_product > 0";
4078 if ($filteronproducttype >= 0) {
4079 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4081 $sql .=
" AND c.fk_soc = s.rowid";
4082 $sql .=
" AND c.entity IN (".getEntity(
'supplier_order').
")";
4083 if (empty($user->rights->societe->client->voir) && !$socid) {
4084 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4087 $sql .=
" AND c.fk_soc = ".((int) $socid);
4089 $sql .= $morefilter;
4090 $sql .=
" GROUP BY date_format(c.date_commande,'%Y%m')";
4091 $sql .=
" ORDER BY date_format(c.date_commande,'%Y%m') DESC";
4093 return $this->
_get_stats($sql, $mode, $year);
4107 public function get_nb_contract($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4110 global $conf, $user;
4112 $sql =
"SELECT sum(d.qty), date_format(c.date_contrat, '%Y%m')";
4113 if ($mode ==
'bynumber') {
4114 $sql .=
", count(DISTINCT c.rowid)";
4116 $sql .=
" FROM ".$this->db->prefix().
"contratdet as d, ".$this->
db->prefix().
"contrat as c, ".$this->
db->prefix().
"societe as s";
4117 if ($filteronproducttype >= 0) {
4118 $sql .=
", ".$this->db->prefix().
"product as p";
4120 if (empty($user->rights->societe->client->voir) && !$socid) {
4121 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4124 $sql .=
" WHERE c.entity IN (".getEntity(
'contract').
")";
4125 $sql .=
" AND c.rowid = d.fk_contrat";
4127 if ($this->
id > 0) {
4128 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4130 $sql .=
" AND d.fk_product > 0";
4132 if ($filteronproducttype >= 0) {
4133 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4135 $sql .=
" AND c.fk_soc = s.rowid";
4137 if (empty($user->rights->societe->client->voir) && !$socid) {
4138 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4141 $sql .=
" AND c.fk_soc = ".((int) $socid);
4143 $sql .= $morefilter;
4144 $sql .=
" GROUP BY date_format(c.date_contrat,'%Y%m')";
4145 $sql .=
" ORDER BY date_format(c.date_contrat,'%Y%m') DESC";
4147 return $this->
_get_stats($sql, $mode, $year);
4161 public function get_nb_mos($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4164 global $conf, $user;
4166 $sql =
"SELECT sum(d.qty), date_format(d.date_valid, '%Y%m')";
4167 if ($mode ==
'bynumber') {
4168 $sql .=
", count(DISTINCT d.rowid)";
4170 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as d LEFT JOIN ".$this->
db->prefix().
"societe as s ON d.fk_soc = s.rowid";
4171 if ($filteronproducttype >= 0) {
4172 $sql .=
", ".$this->db->prefix().
"product as p";
4174 if (empty($user->rights->societe->client->voir) && !$socid) {
4175 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4178 $sql .=
" WHERE d.entity IN (".getEntity(
'mo').
")";
4179 $sql .=
" AND d.status > 0";
4181 if ($this->
id > 0) {
4182 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4184 $sql .=
" AND d.fk_product > 0";
4186 if ($filteronproducttype >= 0) {
4187 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4190 if (empty($user->rights->societe->client->voir) && !$socid) {
4191 $sql .=
" AND d.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4194 $sql .=
" AND d.fk_soc = ".((int) $socid);
4196 $sql .= $morefilter;
4197 $sql .=
" GROUP BY date_format(d.date_valid,'%Y%m')";
4198 $sql .=
" ORDER BY date_format(d.date_valid,'%Y%m') DESC";
4200 return $this->
_get_stats($sql, $mode, $year);
4217 if (!is_numeric($id_pere)) {
4220 if (!is_numeric($id_fils)) {
4223 if (!is_numeric($incdec)) {
4233 $sql =
"SELECT fk_product_pere from ".$this->db->prefix().
"product_association";
4234 $sql .=
" WHERE fk_product_pere = ".((int) $id_fils).
" AND fk_product_fils = ".((int) $id_pere);
4235 if (!$this->
db->query($sql)) {
4240 $sql =
"SELECT MAX(rang) as max_rank FROM ".$this->db->prefix().
"product_association";
4241 $sql .=
" WHERE fk_product_pere = ".((int) $id_pere);
4244 $obj = $this->
db->fetch_object(
$resql);
4245 $rank = $obj->max_rank + 1;
4247 $sql =
"INSERT INTO ".$this->db->prefix().
"product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)";
4248 $sql .=
" VALUES (".((int) $id_pere).
", ".((int) $id_fils).
", ".
price2num($qty,
'MS').
", ".
price2num($incdec,
'MS').
", ".((int) $rank).
")";
4249 if (! $this->
db->query($sql)) {
4276 if (!is_numeric($id_pere)) {
4279 if (!is_numeric($id_fils)) {
4282 if (!is_numeric($incdec)) {
4285 if (!is_numeric($qty)) {
4289 $sql =
'UPDATE '.$this->db->prefix().
'product_association SET ';
4290 $sql .=
'qty = '.price2num($qty,
'MS');
4291 $sql .=
',incdec = '.price2num($incdec,
'MS');
4292 $sql .=
' WHERE fk_product_pere = '.((int) $id_pere).
' AND fk_product_fils = '.((int) $id_fils);
4294 if (!$this->
db->query($sql)) {
4313 if (!is_numeric($fk_parent)) {
4316 if (!is_numeric($fk_child)) {
4320 $sql =
"DELETE FROM ".$this->db->prefix().
"product_association";
4321 $sql .=
" WHERE fk_product_pere = ".((int) $fk_parent);
4322 $sql .=
" AND fk_product_fils = ".((int) $fk_child);
4324 dol_syslog(get_class($this).
'::del_sousproduit', LOG_DEBUG);
4325 if (!$this->
db->query($sql)) {
4331 $sqlrank =
"SELECT rowid, rang FROM ".$this->db->prefix().
"product_association";
4332 $sqlrank.=
" WHERE fk_product_pere = ".((int) $fk_parent);
4333 $sqlrank.=
" ORDER BY rang";
4334 $resqlrank = $this->
db->query($sqlrank);
4337 while ($objrank = $this->
db->fetch_object($resqlrank)) {
4339 $sql =
"UPDATE ".$this->db->prefix().
"product_association";
4340 $sql.=
" SET rang = ".((int) $cpt);
4341 $sql.=
" WHERE rowid = ".((int) $objrank->rowid);
4342 if (! $this->
db->query($sql)) {
4362 $sql =
"SELECT fk_product_pere, qty, incdec";
4363 $sql .=
" FROM ".$this->db->prefix().
"product_association";
4364 $sql .=
" WHERE fk_product_pere = ".((int) $fk_parent);
4365 $sql .=
" AND fk_product_fils = ".((int) $fk_child);
4367 $result = $this->
db->query($sql);
4369 $num = $this->
db->num_rows($result);
4372 $obj = $this->
db->fetch_object($result);
4374 $this->is_sousproduit_qty = $obj->qty;
4375 $this->is_sousproduit_incdec = $obj->incdec;
4406 dol_syslog(get_class($this).
"::add_fournisseur id_fourn = ".$id_fourn.
" ref_fourn=".
$ref_fourn.
" quantity=".$quantity, LOG_DEBUG);
4412 $sql =
"SELECT rowid, fk_product";
4413 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
4414 $sql .=
" WHERE fk_soc = ".((int) $id_fourn);
4415 $sql .=
" AND ref_fourn = '".$this->db->escape(
$ref_fourn).
"'";
4416 $sql .=
" AND fk_product <> ".((int) $this->
id);
4417 $sql .=
" AND entity IN (".getEntity(
'productsupplierprice').
")";
4421 $obj = $this->
db->fetch_object(
$resql);
4424 $this->product_id_already_linked = $obj->fk_product;
4431 $sql =
"SELECT rowid";
4432 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
4433 $sql .=
" WHERE fk_soc = ".((int) $id_fourn);
4435 $sql .=
" AND ref_fourn = '".$this->db->escape(
$ref_fourn).
"'";
4437 $sql .=
" AND (ref_fourn = '' OR ref_fourn IS NULL)";
4439 $sql .=
" AND quantity = ".((float) $quantity);
4440 $sql .=
" AND fk_product = ".((int) $this->
id);
4441 $sql .=
" AND entity IN (".getEntity(
'productsupplierprice').
")";
4445 $obj = $this->
db->fetch_object(
$resql);
4449 $sql =
"INSERT INTO ".$this->db->prefix().
"product_fournisseur_price(";
4452 $sql .=
", fk_product";
4454 $sql .=
", ref_fourn";
4455 $sql .=
", quantity";
4456 $sql .=
", fk_user";
4458 $sql .=
") VALUES (";
4459 $sql .=
"'".$this->db->idate($now).
"'";
4460 $sql .=
", ".$conf->entity;
4461 $sql .=
", ".$this->id;
4462 $sql .=
", ".$id_fourn;
4463 $sql .=
", '".$this->db->escape(
$ref_fourn).
"'";
4464 $sql .=
", ".$quantity;
4465 $sql .=
", ".$user->id;
4469 if ($this->
db->query($sql)) {
4470 $this->product_fourn_price_id = $this->
db->last_insert_id($this->
db->prefix().
"product_fournisseur_price");
4473 $this->error = $this->
db->lasterror();
4478 $this->product_fourn_price_id = $obj->rowid;
4482 $this->error = $this->
db->lasterror();
4501 $sql =
"SELECT DISTINCT p.fk_soc";
4502 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as p";
4503 $sql .=
" WHERE p.fk_product = ".((int) $this->
id);
4504 $sql .=
" AND p.entity = ".((int) $conf->entity);
4506 $result = $this->
db->query($sql);
4508 $num = $this->
db->num_rows($result);
4511 $obj = $this->
db->fetch_object($result);
4512 $list[$i] = $obj->fk_soc;
4530 global $conf, $user;
4537 $sql =
"INSERT INTO ".$this->db->prefix().
"product_price (";
4539 $sql .=
", fk_product";
4540 $sql .=
", date_price";
4541 $sql .=
", price_level";
4543 $sql .=
", price_ttc";
4544 $sql .=
", price_min";
4545 $sql .=
", price_min_ttc";
4546 $sql .=
", price_base_type";
4547 $sql .=
", default_vat_code";
4549 $sql .=
", recuperableonly";
4550 $sql .=
", localtax1_tx";
4551 $sql .=
", localtax1_type";
4552 $sql .=
", localtax2_tx";
4553 $sql .=
", localtax2_type";
4554 $sql .=
", fk_user_author";
4556 $sql .=
", price_by_qty";
4557 $sql .=
", fk_price_expression";
4558 $sql .=
", fk_multicurrency";
4559 $sql .=
", multicurrency_code";
4560 $sql .=
", multicurrency_tx";
4561 $sql .=
", multicurrency_price";
4562 $sql .=
", multicurrency_price_ttc";
4567 $sql .=
", '".$this->db->idate($now).
"'";
4568 $sql .=
", price_level";
4570 $sql .=
", price_ttc";
4571 $sql .=
", price_min";
4572 $sql .=
", price_min_ttc";
4573 $sql .=
", price_base_type";
4574 $sql .=
", default_vat_code";
4576 $sql .=
", recuperableonly";
4577 $sql .=
", localtax1_tx";
4578 $sql .=
", localtax1_type";
4579 $sql .=
", localtax2_tx";
4580 $sql .=
", localtax2_type";
4581 $sql .=
", ".$user->id;
4583 $sql .=
", price_by_qty";
4584 $sql .=
", fk_price_expression";
4585 $sql .=
", fk_multicurrency";
4586 $sql .=
", multicurrency_code";
4587 $sql .=
", multicurrency_tx";
4588 $sql .=
", multicurrency_price";
4589 $sql .=
", multicurrency_price_ttc";
4590 $sql .=
" FROM ".$this->db->prefix().
"product_price";
4591 $sql .=
" WHERE fk_product = ".((int) $fromId);
4592 $sql .=
" ORDER BY date_price DESC";
4593 if ($conf->global->PRODUIT_MULTIPRICES_LIMIT > 0) {
4594 $sql .=
" LIMIT ".$conf->global->PRODUIT_MULTIPRICES_LIMIT;
4600 $this->
db->rollback();
4604 $this->
db->commit();
4621 $sql =
'INSERT INTO '.$this->db->prefix().
'product_association (fk_product_pere, fk_product_fils, qty)';
4622 $sql .=
" SELECT ".$toId.
", fk_product_fils, qty FROM ".$this->
db->prefix().
"product_association";
4623 $sql .=
" WHERE fk_product_pere = ".((int) $fromId);
4625 dol_syslog(get_class($this).
'::clone_association', LOG_DEBUG);
4626 if (!$this->
db->query($sql)) {
4627 $this->
db->rollback();
4631 $this->
db->commit();
4664 $sql =
"INSERT ".$this->db->prefix().
"product_fournisseur_price (";
4665 $sql .=
" datec, fk_product, fk_soc, price, quantity, fk_user)";
4666 $sql .=
" SELECT '".$this->db->idate($now).
"', ".((int) $toId).
", fk_soc, price, quantity, fk_user";
4667 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
4668 $sql .=
" WHERE fk_product = ".((int) $fromId);
4670 dol_syslog(get_class($this).
'::clone_fournisseurs', LOG_DEBUG);
4673 $this->
db->rollback();
4676 $this->
db->commit();
4694 public function fetch_prod_arbo($prod, $compl_path =
'', $multiply = 1, $level = 1, $id_parent = 0, $ignore_stock_load = 0)
4697 global $conf, $langs;
4701 foreach ($prod as $id_product => $desc_pere) {
4702 if (is_array($desc_pere)) {
4703 $id = (!empty($desc_pere[0]) ? $desc_pere[0] :
'');
4704 $nb = (!empty($desc_pere[1]) ? $desc_pere[1] :
'');
4705 $type = (!empty($desc_pere[2]) ? $desc_pere[2] :
'');
4706 $label = (!empty($desc_pere[3]) ? $desc_pere[3] :
'');
4707 $incdec = (!empty($desc_pere[4]) ? $desc_pere[4] : 0);
4709 if ($multiply < 1) {
4714 if (is_null($tmpproduct)) {
4717 $tmpproduct->fetch($id);
4719 if (empty($ignore_stock_load) && ($tmpproduct->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES))) {
4720 $tmpproduct->load_stock(
'nobatch,novirtual');
4723 $this->res[] = array(
4725 'id_parent'=>$id_parent,
4726 'ref'=>$tmpproduct->ref,
4728 'nb_total'=>$nb * $multiply,
4729 'stock'=>$tmpproduct->stock_reel,
4730 'stock_alert'=>$tmpproduct->seuil_stock_alerte,
4732 'fullpath'=>$compl_path.$label,
4734 'desiredstock'=>$tmpproduct->desiredstock,
4737 'entity'=>$tmpproduct->entity
4741 if (isset($desc_pere[
'childs']) && is_array($desc_pere[
'childs'])) {
4743 $this->
fetch_prod_arbo($desc_pere[
'childs'], $compl_path.$desc_pere[3].
" -> ", $desc_pere[1] * $multiply, $level + 1, $id, $ignore_stock_load);
4761 $this->res = array();
4762 if (isset($this->sousprods) && is_array($this->sousprods)) {
4763 foreach ($this->sousprods as $prod_name => $desc_product) {
4764 if (is_array($desc_product)) {
4765 $this->
fetch_prod_arbo($desc_product,
"", $multiply, 1, $this->
id, $ignore_stock_load);
4784 $sql =
"SELECT COUNT(pa.rowid) as nb";
4785 $sql .=
" FROM ".$this->db->prefix().
"product_association as pa";
4787 $sql .=
" WHERE pa.fk_product_fils = ".((int) $this->
id).
" OR pa.fk_product_pere = ".((int) $this->
id);
4788 } elseif ($mode == -1) {
4789 $sql .=
" WHERE pa.fk_product_fils = ".((int) $this->
id);
4790 } elseif ($mode == 1) {
4791 $sql .=
" WHERE pa.fk_product_pere = ".((int) $this->
id);
4796 $obj = $this->
db->fetch_object(
$resql);
4815 $sql =
"SELECT count(rowid) as nb FROM ".$this->db->prefix().
"product_attribute_combination WHERE fk_product_parent = ".((int) $this->
id);
4816 $sql .=
" AND entity IN (".getEntity(
'product').
")";
4820 $obj = $this->
db->fetch_object(
$resql);
4839 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_combination WHERE fk_product_child = ".((int) $this->
id).
" AND entity IN (".
getEntity(
'product').
")";
4841 $query = $this->
db->query($sql);
4844 if (!$this->
db->num_rows($query)) {
4865 $sql =
"SELECT p.rowid, p.label as label, p.ref as ref, pa.fk_product_pere as id, p.fk_product_type, pa.qty, pa.incdec, p.entity";
4866 $sql .=
", p.tosell as status, p.tobuy as status_buy";
4867 $sql .=
" FROM ".$this->db->prefix().
"product_association as pa,";
4868 $sql .=
" ".$this->db->prefix().
"product as p";
4869 $sql .=
" WHERE p.rowid = pa.fk_product_pere";
4870 $sql .=
" AND pa.fk_product_fils = ".((int) $this->
id);
4872 $res = $this->
db->query($sql);
4875 while ($record = $this->
db->fetch_array($res)) {
4877 $prods[$record[
'id']][
'id'] = $record[
'rowid'];
4878 $prods[$record[
'id']][
'ref'] = $record[
'ref'];
4879 $prods[$record[
'id']][
'label'] = $record[
'label'];
4880 $prods[$record[
'id']][
'qty'] = $record[
'qty'];
4881 $prods[$record[
'id']][
'incdec'] = $record[
'incdec'];
4882 $prods[$record[
'id']][
'fk_product_type'] = $record[
'fk_product_type'];
4883 $prods[$record[
'id']][
'entity'] = $record[
'entity'];
4884 $prods[$record[
'id']][
'status'] = $record[
'status'];
4885 $prods[$record[
'id']][
'status_buy'] = $record[
'status_buy'];
4904 public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = array())
4906 global $alreadyfound;
4912 $sql =
"SELECT p.rowid, p.ref, p.label as label, p.fk_product_type,";
4913 $sql .=
" pa.qty as qty, pa.fk_product_fils as id, pa.incdec,";
4914 $sql .=
" pa.rowid as fk_association, pa.rang";
4915 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
4916 $sql .=
" ".$this->db->prefix().
"product_association as pa";
4917 $sql .=
" WHERE p.rowid = pa.fk_product_fils";
4918 $sql .=
" AND pa.fk_product_pere = ".((int) $id);
4919 $sql .=
" AND pa.fk_product_fils <> ".((int) $id);
4920 $sql.=
" ORDER BY pa.rang";
4922 dol_syslog(get_class($this).
'::getChildsArbo id='.$id.
' level='.$level.
' parents='.(is_array($parents)?implode(
',', $parents):$parents), LOG_DEBUG);
4925 $alreadyfound = array($id=>1);
4932 $res = $this->
db->query($sql);
4935 while ($rec = $this->
db->fetch_array($res)) {
4936 if (!empty($alreadyfound[$rec[
'rowid']])) {
4937 dol_syslog(get_class($this).
'::getChildsArbo the product id='.$rec[
'rowid'].
' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING);
4938 if (in_array($rec[
'id'], $parents)) {
4942 $alreadyfound[$rec[
'rowid']] = 1;
4943 $prods[$rec[
'rowid']] = array(
4946 2=>$rec[
'fk_product_type'],
4947 3=>$this->
db->escape($rec[
'label']),
4950 6=>$rec[
'fk_association'],
4955 if (empty($firstlevelonly)) {
4956 $listofchilds = $this->
getChildsArbo($rec[
'rowid'], 0, $level + 1, array_push($parents, $rec[
'rowid']));
4957 foreach ($listofchilds as $keyChild => $valueChild) {
4958 $prods[$rec[
'rowid']][
'childs'][$keyChild] = $valueChild;
4982 foreach ($this->
getChildsArbo($this->
id) as $keyChild => $valueChild) {
4983 $parent[$this->label][$keyChild] = $valueChild;
4985 foreach ($parent as $key => $value) {
4986 $this->sousprods[$key] = $value;
5003 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ')
5005 global $conf, $langs, $hookmanager;
5006 include_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
5008 $result =
''; $label =
'';
5010 $newref = $this->ref;
5012 $newref =
dol_trunc($newref, $maxlength,
'middle');
5015 if (!empty($this->entity)) {
5016 $tmpphoto = $this->
show_photos(
'product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80);
5017 if ($this->nbphoto > 0) {
5018 $label .=
'<div class="photointooltip floatright">';
5019 $label .= $tmpphoto;
5026 $label .=
img_picto(
'',
'product').
' <u class="paddingrightonly">'.$langs->trans(
"Product").
'</u>';
5028 $label .=
img_picto(
'',
'service').
' <u class="paddingrightonly">'.$langs->trans(
"Service").
'</u>';
5030 if (isset($this->status) && isset($this->status_buy)) {
5031 $label .=
' '.$this->getLibStatut(5, 0);
5032 $label .=
' '.$this->getLibStatut(5, 1);
5035 if (!empty($this->
ref)) {
5036 $label .=
'<br><b>'.$langs->trans(
'ProductRef').
':</b> '.$this->ref;
5038 if (!empty($this->label)) {
5039 $label .=
'<br><b>'.$langs->trans(
'ProductLabel').
':</b> '.$this->label;
5043 $langs->load(
"productbatch");
5044 $label .=
"<br><b>".$langs->trans(
"ManageLotSerial").
'</b>: '.$this->
getLibStatut(0, 2);
5048 $label .=
'<br><b>'.$langs->trans(
'BarCode').
':</b> '.$this->barcode;
5052 if ($this->weight) {
5053 $label .=
"<br><b>".$langs->trans(
"Weight").
'</b>: '.$this->weight.
' '.
measuringUnitString(0,
"weight", $this->weight_units);
5056 if ($this->length) {
5057 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Length").
'</b>: '.$this->length.
' '.
measuringUnitString(0,
'size', $this->length_units);
5060 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Width").
'</b>: '.$this->width.
' '.
measuringUnitString(0,
'size', $this->width_units);
5062 if ($this->height) {
5063 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Height").
'</b>: '.$this->height.
' '.
measuringUnitString(0,
'size', $this->height_units);
5066 $label .=
"<br>".$labelsize;
5069 $labelsurfacevolume =
"";
5070 if ($this->surface) {
5071 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Surface").
'</b>: '.$this->surface.
' '.
measuringUnitString(0,
'surface', $this->surface_units);
5073 if ($this->volume) {
5074 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Volume").
'</b>: '.$this->volume.
' '.
measuringUnitString(0,
'volume', $this->volume_units);
5076 if ($labelsurfacevolume) {
5077 $label .=
"<br>".$labelsurfacevolume;
5080 if (!empty($this->pmp) && $this->pmp) {
5081 $label .=
"<br><b>".$langs->trans(
"PMPValue").
'</b>: '.
price($this->pmp, 0,
'', 1, -1, -1, $conf->currency);
5085 if ($this->status && isset($this->accountancy_code_sell)) {
5086 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
5088 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellCode').
':</b> '.
length_accountg($this->accountancy_code_sell);
5089 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellIntraCode').
':</b> '.
length_accountg($this->accountancy_code_sell_intra);
5090 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancySellExportCode').
':</b> '.
length_accountg($this->accountancy_code_sell_export);
5092 if ($this->status_buy && isset($this->accountancy_code_buy)) {
5093 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
5094 if (empty($this->status)) {
5097 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyCode').
':</b> '.
length_accountg($this->accountancy_code_buy);
5098 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyIntraCode').
':</b> '.
length_accountg($this->accountancy_code_buy_intra);
5099 $label .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyExportCode').
':</b> '.
length_accountg($this->accountancy_code_buy_export);
5104 if (empty($notooltip)) {
5105 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
5106 $label = $langs->trans(
"ShowProduct");
5107 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
5110 $linkclose .=
' title="'.dol_escape_htmltag($label, 1, 1).
'"';
5111 $linkclose .=
' class="nowraponall classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
5113 $linkclose =
' class="nowraponall'.($morecss ?
' '.$morecss :
'').
'"';
5116 if ($option ==
'supplier' || $option ==
'category') {
5117 $url = DOL_URL_ROOT.
'/product/fournisseurs.php?id='.$this->id;
5118 } elseif ($option ==
'stock') {
5119 $url = DOL_URL_ROOT.
'/product/stock/product.php?id='.$this->id;
5120 } elseif ($option ==
'composition') {
5121 $url = DOL_URL_ROOT.
'/product/composition/card.php?id='.$this->id;
5123 $url = DOL_URL_ROOT.
'/product/card.php?id='.$this->id;
5126 if ($option !==
'nolink') {
5128 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
5129 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
5130 $add_save_lastsearch_values = 1;
5132 if ($add_save_lastsearch_values) {
5133 $url .=
'&save_lastsearch_values=1';
5137 $linkstart =
'<a href="'.$url.
'"';
5138 $linkstart .= $linkclose.
'>';
5141 $result .= $linkstart;
5144 $result .= (
img_object(($notooltip ?
'' : $label),
'product', ($notooltip ?
'class="paddingright"' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1));
5147 $result .= (
img_object(($notooltip ?
'' : $label),
'service', ($notooltip ?
'class="paddingright"' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1));
5151 $result .= $linkend;
5152 if ($withpicto != 2) {
5153 $result .= (($add_label && $this->label) ? $sep.dol_trunc($this->label, ($add_label > 1 ? $add_label : 0)) :
'');
5157 $hookmanager->initHooks(array(
'productdao'));
5158 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result,
'label' => &$label);
5159 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
5161 $result = $hookmanager->resPrint;
5163 $result .= $hookmanager->resPrint;
5180 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
5182 global $conf, $user, $langs;
5184 $langs->load(
"products");
5185 $outputlangs->load(
"products");
5192 $modelpath =
"core/modules/product/doc/";
5194 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
5208 return $this->
LibStatut($this->status, $mode, $type);
5210 return $this->
LibStatut($this->status_buy, $mode, $type);
5212 return $this->
LibStatut($this->status_batch, $mode, $type);
5215 return $this->
LibStatut($this->status_buy, $mode, $type);
5231 global $conf, $langs;
5233 $labelStatus = $labelStatusShort =
'';
5235 $langs->load(
'products');
5237 $langs->load(
"productbatch");
5243 $label = ($status == 0 ? $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch') : ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatch') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerial')));
5246 $label = ($status == 0 ? $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatchShort') : ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatchShort') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerialShort')));
5251 return dolGetStatus($langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch'),
'',
'', empty($status) ?
'status5' :
'status4', 3,
'dot');
5257 return dolGetStatus($langs->transnoentitiesnoconv(
'Unknown'));
5261 $statuttrans = empty($status) ?
'status5' :
'status4';
5266 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnSellShort');
5267 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnSell');
5268 } elseif ($type == 1) {
5269 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBuyShort');
5270 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBuy');
5271 } elseif ($type == 2) {
5272 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch');
5273 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatchShort');
5275 } elseif ($status == 1) {
5278 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnSellShort');
5279 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnSell');
5280 } elseif ($type == 1) {
5281 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnBuyShort');
5282 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnBuy');
5283 } elseif ($type == 2) {
5284 $labelStatus = ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatch') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerial'));
5285 $labelStatusShort = ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatchShort') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerialShort'));
5287 } elseif ( $type == 2 && $status == 2 ) {
5288 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnSerial');
5289 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnSerialShort');
5293 return dolGetStatus($langs->transnoentitiesnoconv(
'Unknown'),
'',
'',
'status0', 0);
5295 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statuttrans, $mode);
5308 $langs->load(
'products');
5310 if (isset($this->finished) && $this->finished >= 0) {
5311 $sql =
"SELECT label, code FROM ".$this->db->prefix().
"c_product_nature where code = ".((int) $this->finished).
" AND active=1";
5314 $res = $this->
db->fetch_array(
$resql);
5315 $label = $langs->trans($res[
'label']);
5319 $this->error = $this->
db->error().
' sql='.$sql;
5320 dol_syslog(__METHOD__.
' Error '.$this->error, LOG_ERR);
5346 public function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label =
'', $price = 0, $inventorycode =
'', $origin_element =
'', $origin_id =
null, $disablestockchangeforsubproduct = 0, $extrafields =
null)
5352 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
5358 $nbpiece = abs($nbpiece);
5361 $op[0] =
"+".trim($nbpiece);
5362 $op[1] =
"-".trim($nbpiece);
5365 $movementstock->setOrigin($origin_element, $origin_id);
5366 $result = $movementstock->_create($user, $this->
id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode,
'',
'',
'',
'',
false, 0, $disablestockchangeforsubproduct);
5370 $array_options = $extrafields->getOptionalsFromPost(
'stock_mouvement');
5371 $movementstock->array_options = $array_options;
5372 $movementstock->insertExtraFields();
5374 $this->
db->commit();
5377 $this->error = $movementstock->error;
5378 $this->errors = $movementstock->errors;
5380 $this->
db->rollback();
5406 public function correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label =
'', $price = 0, $dlc =
'', $dluo =
'', $lot =
'', $inventorycode =
'', $origin_element =
'', $origin_id =
null, $disablestockchangeforsubproduct = 0, $extrafields =
null)
5412 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
5418 $nbpiece = abs($nbpiece);
5421 $op[0] =
"+".trim($nbpiece);
5422 $op[1] =
"-".trim($nbpiece);
5425 $movementstock->setOrigin($origin_element, $origin_id);
5426 $result = $movementstock->_create($user, $this->
id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode,
'', $dlc, $dluo, $lot,
false, 0, $disablestockchangeforsubproduct);
5430 $array_options = $extrafields->getOptionalsFromPost(
'stock_mouvement');
5431 $movementstock->array_options = $array_options;
5432 $movementstock->insertExtraFields();
5434 $this->
db->commit();
5437 $this->error = $movementstock->error;
5438 $this->errors = $movementstock->errors;
5440 $this->
db->rollback();
5459 public function load_stock($option =
'', $includedraftpoforvirtual =
null, $dateofvirtualstock =
null)
5464 $this->stock_reel = 0;
5465 $this->stock_warehouse = array();
5466 $this->stock_theorique = 0;
5469 $warehouseStatus = array();
5470 if (preg_match(
'/warehouseclosed/', $option)) {
5473 if (preg_match(
'/warehouseopen/', $option)) {
5476 if (preg_match(
'/warehouseinternal/', $option)) {
5477 if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
5484 $sql =
"SELECT ps.rowid, ps.reel, ps.fk_entrepot";
5485 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
5486 $sql .=
", ".$this->db->prefix().
"entrepot as w";
5487 $sql .=
" WHERE w.entity IN (".getEntity(
'stock').
")";
5488 $sql .=
" AND w.rowid = ps.fk_entrepot";
5489 $sql .=
" AND ps.fk_product = ".((int) $this->
id);
5490 if (count($warehouseStatus)) {
5491 $sql .=
" AND w.statut IN (".$this->db->sanitize(implode(
',', $warehouseStatus)).
")";
5494 $sql .=
" ORDER BY ps.reel ".(!empty($conf->global->DO_NOT_TRY_TO_DEFRAGMENT_STOCKS_WAREHOUSE)?
'DESC':
'ASC');
5496 dol_syslog(get_class($this).
"::load_stock", LOG_DEBUG);
5497 $result = $this->
db->query($sql);
5499 $num = $this->
db->num_rows($result);
5503 $row = $this->
db->fetch_object($result);
5504 $this->stock_warehouse[$row->fk_entrepot] =
new stdClass();
5505 $this->stock_warehouse[$row->fk_entrepot]->real = $row->reel;
5506 $this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid;
5507 if ((!preg_match(
'/nobatch/', $option)) && $this->
hasbatch()) {
5508 $this->stock_warehouse[$row->fk_entrepot]->detail_batch =
Productbatch::findAll($this->
db, $row->rowid, 1, $this->id);
5510 $this->stock_reel += $row->reel;
5514 $this->
db->free($result);
5516 if (!preg_match(
'/novirtual/', $option)) {
5522 $this->error = $this->
db->lasterror();
5541 global $conf, $hookmanager, $action;
5543 $stock_commande_client = 0;
5544 $stock_commande_fournisseur = 0;
5545 $stock_sending_client = 0;
5546 $stock_reception_fournisseur = 0;
5547 $stock_inproduction = 0;
5556 $stock_commande_client = $this->stats_commande[
'qty'];
5559 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
5560 $filterShipmentStatus =
'';
5561 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) {
5563 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
5570 $stock_sending_client = $this->stats_expedition[
'qty'];
5572 if ((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order")) {
5573 $filterStatus = empty($conf->global->SUPPLIER_ORDER_STATUS_FOR_VIRTUAL_STOCK) ?
'3,4' : $conf->global->SUPPLIER_ORDER_STATUS_FOR_VIRTUAL_STOCK;
5574 if (isset($includedraftpoforvirtual)) {
5575 $filterStatus =
'0,1,2,'.$filterStatus;
5581 $stock_commande_fournisseur = $this->stats_commande_fournisseur[
'qty'];
5583 if (((
isModEnabled(
"fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) ||
isModEnabled(
"supplier_order") ||
isModEnabled(
"supplier_invoice")) && empty($conf->reception->enabled)) {
5585 $filterStatus =
'4';
5586 if (isset($includedraftpoforvirtual)) {
5587 $filterStatus =
'0,'.$filterStatus;
5593 $stock_reception_fournisseur = $this->stats_reception[
'qty'];
5597 $filterStatus =
'4';
5598 if (isset($includedraftpoforvirtual)) {
5599 $filterStatus =
'0,'.$filterStatus;
5605 $stock_reception_fournisseur = $this->stats_reception[
'qty'];
5612 $stock_inproduction = $this->stats_mrptoproduce[
'qty'] - $this->stats_mrptoconsume[
'qty'];
5615 $this->stock_theorique = $this->stock_reel + $stock_inproduction;
5618 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {
5619 $this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
5620 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)) {
5621 $this->stock_theorique += 0;
5622 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
5623 $this->stock_theorique -= $stock_commande_client;
5626 if (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)) {
5627 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
5628 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
5629 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
5630 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
5631 $this->stock_theorique -= $stock_reception_fournisseur;
5632 } elseif (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) {
5633 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
5636 if (!is_object($hookmanager)) {
5637 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
5640 $hookmanager->initHooks(array(
'productdao'));
5641 $parameters = array(
'id'=>$this->
id,
'includedraftpoforvirtual' => $includedraftpoforvirtual);
5643 $reshook = $hookmanager->executeHooks(
'loadvirtualstock', $parameters, $this, $action);
5645 $this->stock_theorique = $hookmanager->resArray[
'stock_theorique'];
5663 $sql =
"SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".$this->db->prefix().
"product_batch as pb, ".$this->
db->prefix().
"product_stock as ps";
5664 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND ps.fk_product = ".((int) $this->
id).
" AND pb.batch = '".$this->
db->escape($batch).
"'";
5665 $sql .=
" GROUP BY pb.batch, pb.eatby, pb.sellby";
5666 dol_syslog(get_class($this).
"::loadBatchInfo load first entry found for lot/serial = ".$batch, LOG_DEBUG);
5669 $num = $this->
db->num_rows(
$resql);
5672 $obj = $this->
db->fetch_object(
$resql);
5673 $result[] = array(
'batch'=>$batch,
'eatby'=>$this->
db->jdate($obj->eatby),
'sellby'=>$this->db->jdate($obj->sellby),
'qty'=>$obj->qty);
5679 $this->
db->rollback();
5697 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5703 $dir .=
'/'.get_exdir($this->
id, 2, 0, 0, $this,
'product').$this->id.
"/photos";
5705 $dir .=
'/'.get_exdir(0, 0, 0, 0, $this,
'product').dol_sanitizeFileName($this->
ref);
5710 $dir_osencoded = $dir;
5712 if (is_dir($dir_osencoded)) {
5713 $originImage = $dir.
'/'.$file[
'name'];
5724 if (is_numeric($result) && $result > 0) {
5741 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5742 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5748 $dir .=
'/'.get_exdir($this->
id, 2, 0, 0, $this,
'product').$this->id.
"/photos/";
5750 $dir .=
'/'.get_exdir(0, 0, 0, 0, $this,
'product');
5756 if (file_exists($dir_osencoded)) {
5757 $handle = opendir($dir_osencoded);
5758 if (is_resource($handle)) {
5759 while (($file = readdir($handle)) !==
false) {
5761 $file = utf8_encode($file);
5783 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5784 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5790 $handle = @opendir($dir_osencoded);
5791 if (is_resource($handle)) {
5792 while (($file = readdir($handle)) !==
false) {
5794 $file = utf8_encode($file);
5801 $photo_vignette =
'';
5803 if (preg_match(
'/('.$this->regeximgext.
')$/i', $photo, $regs)) {
5804 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
5807 $dirthumb = $dir.
'thumbs/';
5811 $obj[
'photo'] = $photo;
5812 if ($photo_vignette &&
dol_is_file($dirthumb.$photo_vignette)) {
5813 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
5815 $obj[
'photo_vignette'] =
"";
5818 $tabobj[$nbphoto - 1] = $obj;
5821 if ($nbmax && $nbphoto >= $nbmax) {
5843 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5844 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5846 $dir = dirname($file).
'/';
5847 $dirthumb = $dir.
'/thumbs/';
5848 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
5854 if (preg_match(
'/('.$this->regeximgext.
')$/i', $filename, $regs)) {
5855 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
5856 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
5860 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_mini'.$regs[0];
5861 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
5878 $infoImg = getimagesize($file_osencoded);
5879 $this->imgWidth = $infoImg[0];
5880 $this->imgHeight = $infoImg[1];
5892 global $hookmanager;
5894 $this->nb = array();
5896 $sql =
"SELECT count(p.rowid) as nb, fk_product_type";
5897 $sql .=
" FROM ".$this->db->prefix().
"product as p";
5898 $sql .=
' WHERE p.entity IN ('.getEntity($this->element, 1).
')';
5900 if (is_object($hookmanager)) {
5901 $parameters = array();
5902 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
5903 $sql .= $hookmanager->resPrint;
5905 $sql .=
' GROUP BY fk_product_type';
5909 while ($obj = $this->
db->fetch_object(
$resql)) {
5910 if ($obj->fk_product_type == 1) {
5911 $this->nb[
"services"] = $obj->nb;
5913 $this->nb[
"products"] = $obj->nb;
5920 $this->error = $this->
db->error();
5953 return ($this->mandatory_period == 1 ?
true :
false);
5970 if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
5971 $dirsociete = array_merge(array(
'/core/modules/barcode/'), $conf->modules_parts[
'barcode']);
5972 foreach ($dirsociete as $dirroot) {
5973 $res =
dol_include_once($dirroot.$conf->global->BARCODE_PRODUCT_ADDON_NUM.
'.php');
5978 $var = $conf->global->BARCODE_PRODUCT_ADDON_NUM;
5981 $result = $mod->getNextValue($object, $type);
5983 dol_syslog(get_class($this).
"::get_barcode barcode=".$result.
" module=".$var);
5997 global $user, $langs, $conf, $mysoc;
6002 $this->specimen = 1;
6004 $this->
ref =
'PRODUCT_SPEC';
6005 $this->label =
'PRODUCT SPECIMEN';
6006 $this->
description =
'This is description of this product specimen that was created the '.dol_print_date($now,
'dayhourlog').
'.';
6007 $this->specimen = 1;
6008 $this->country_id = 1;
6010 $this->status_buy = 1;
6012 $this->note_private =
'This is a comment (private)';
6013 $this->note_public =
'This is a comment (public)';
6014 $this->date_creation = $now;
6015 $this->date_modification = $now;
6018 $this->weight_units = 3;
6021 $this->length_units = 1;
6023 $this->width_units = 0;
6024 $this->height =
null;
6025 $this->height_units =
null;
6027 $this->surface = 30;
6028 $this->surface_units = 0;
6029 $this->volume = 300;
6030 $this->volume_units = 0;
6032 $this->barcode = -1;
6045 if (!$this->fk_unit) {
6049 $langs->load(
'products');
6051 $label_type =
'label';
6052 if ($type ==
'short') {
6053 $label_type =
'short_label';
6056 $sql =
"SELECT ".$label_type.
", code from ".$this->
db->prefix().
"c_units where rowid = ".((int) $this->fk_unit);
6060 $res = $this->
db->fetch_array(
$resql);
6061 $label = ($label_type ==
'short_label' ? $res[$label_type] :
'unit'.$res[
'code']);
6065 $this->error = $this->
db->error();
6066 dol_syslog(get_class($this).
"::getLabelOfUnit Error ".$this->error, LOG_ERR);
6078 return ($this->status_batch > 0 ?
true :
false);
6093 $maxpricesupplier = 0;
6095 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
6096 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
6098 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->
id,
'',
'');
6100 if (is_array($product_fourn_list) && count($product_fourn_list) > 0) {
6101 foreach ($product_fourn_list as $productfourn) {
6102 if ($productfourn->fourn_unitprice > $maxpricesupplier) {
6103 $maxpricesupplier = $productfourn->fourn_unitprice;
6107 $maxpricesupplier *= $conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE;
6111 return $maxpricesupplier;
6127 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
6128 return parent::setCategoriesCommon($categories, Categorie::TYPE_PRODUCT);
6142 'product_customer_price',
6143 'product_customer_price_log'
6164 $sql =
"SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".$this->db->prefix().
"product_pricerules";
6165 $query = $this->
db->query($sql);
6169 while ($result = $this->
db->fetch_object($query)) {
6170 $rules[$result->level] = $result;
6178 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
6179 $price = $baseprice;
6180 $price_min = $baseprice;
6184 if ($i > 1 && isset($rules[$i]->var_percent) && $rules[$i]->var_percent) {
6185 $price = $prices[$rules[$i]->fk_level] * (1 + ($rules[$i]->var_percent / 100));
6188 $prices[$i] = $price;
6191 if (isset($rules[$i]->var_min_percent) && $rules[$i]->var_min_percent) {
6192 $price_min = $price * (1 - ($rules[$i]->var_min_percent / 100));
6196 $check_amount = (($price == $this->multiprices[$i]) && ($price_min == $this->multiprices_min[$i]));
6197 $check_type = ($baseprice == $this->multiprices_base_type[$i]);
6199 if ($check_amount && $check_type) {
6203 if ($this->
updatePrice($price, $price_type, $user, $price_vat, $price_min, $i, $npr, $psq,
true) < 0) {
6221 return $user->rights->produit;
6223 return $user->rights->service;
6235 $sql =
"SELECT p.rowid, p.ref, p.datec as date_creation, p.tms as date_modification,";
6236 $sql .=
" p.fk_user_author, p.fk_user_modif";
6237 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as p";
6238 $sql .=
" WHERE p.rowid = ".((int) $id);
6240 $result = $this->
db->query($sql);
6242 if ($this->
db->num_rows($result)) {
6243 $obj = $this->
db->fetch_object($result);
6245 $this->
id = $obj->rowid;
6247 if ($obj->fk_user_author) {
6248 $cuser =
new User($this->
db);
6249 $cuser->fetch($obj->fk_user_author);
6250 $this->user_creation = $cuser;
6253 if ($obj->fk_user_modif) {
6254 $muser =
new User($this->
db);
6255 $muser->fetch($obj->fk_user_modif);
6256 $this->user_modification = $muser;
6259 $this->
ref = $obj->ref;
6260 $this->date_creation = $this->
db->jdate($obj->date_creation);
6261 $this->date_modification = $this->
db->jdate($obj->date_modification);
6264 $this->
db->free($result);
6279 if (empty($this->duration_value)) {
6280 $this->errors[]=
'ErrorDurationForServiceNotDefinedCantCalculateHourlyPrice';
6284 if ($this->duration_unit ==
'i') {
6285 $prodDurationHours = 1. / 60;
6287 if ($this->duration_unit ==
'h') {
6288 $prodDurationHours = 1.;
6290 if ($this->duration_unit ==
'd') {
6291 $prodDurationHours = 24.;
6293 if ($this->duration_unit ==
'w') {
6294 $prodDurationHours = 24. * 7;
6296 if ($this->duration_unit ==
'm') {
6297 $prodDurationHours = 24. * 30;
6299 if ($this->duration_unit ==
'y') {
6300 $prodDurationHours = 24. * 365;
6302 $prodDurationHours *= $this->duration_value;
6304 return $prodDurationHours;
6314 public $picto =
'service';
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others.
deleteExtraFields()
Delete all extra fields values for the current object.
addThumbs($file)
Build thumb.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0)
Show photos of an object (nbmax maximum), into several columns.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
const STATUS_CLOSED
Warehouse closed, inactive.
const STATUS_CLOSED
Closed status.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
Class to manage stock movements.
Class to parse product price expressions.
Class ProductCombination Used to represent a product combination.
Class to manage predefined suppliers products.
Class to manage products or services.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
get_nb_achat($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units or supplier invoices in which product is included.
getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp=0)
Return price of sell of a product for a seller/buyer/product.
__construct($db)
Constructor.
$price_by_qty
Price by quantity arrays.
is_sousproduit($fk_parent, $fk_child)
Check if it is a sub-product into a kit.
setPriceExpression($expression_id)
Sets the supplier price expression.
getArrayForPriceCompare($level=0)
used to check if price have really change to avoid log pollution
get_arbo_each_prod($multiply=1, $ignore_stock_load=0)
Build the tree of subproducts into an array ->res and return it.
check_barcode($valuetotest, $typefortest)
Check barcode.
correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='', $lot='', $inventorycode='', $origin_element='', $origin_id=null, $disablestockchangeforsubproduct=0, $extrafields=null)
Adjust stock in a warehouse for product with batch number.
list_suppliers()
Return list of suppliers providing the product or service.
load_stats_mo($socid=0)
Charge tableau des stats OF pour le produit/service.
isVariant()
Return if loaded product is a variant.
hasVariants()
Return if a product has variants or not.
delMultiLangs($langtodelete, $user)
Delete a language for this product.
getLabelOfUnit($type='long')
Returns the text label from units dictionary.
load_stats_proposal_supplier($socid=0)
Charge tableau des stats propale pour le produit/service.
getLibFinished()
Retour label of nature of product.
add_fournisseur($user, $id_fourn, $ref_fourn, $quantity)
Add a supplier price for the product.
hasFatherOrChild($mode=0)
Count all parent and children products for current product (first level only)
load_stats_facturerec($socid=0)
Charge tableau des stats facture recurrentes pour le produit/service.
$product_id_already_linked
Product ID already linked to a reference supplier.
get_nb_propalsupplier($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in proposals in which product is included.
get_nb_contract($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in orders in which product is included.
load_stats_facture_fournisseur($socid=0)
Charge tableau des stats facture pour le produit/service.
get_nb_ordersupplier($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in orders in which product is included.
getMultiLangs()
Load array this->multilangs.
get_nb_mos($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in orders in which product is included.
clone_associations($fromId, $toId)
Clone links between products.
create($user, $notrigger=0)
Insert product into database.
load_stats_contrat($socid=0)
Charge tableau des stats contrat pour le produit/service.
isService()
Return if object is a product.
getRights()
Returns the rights used for this class.
loadBatchInfo($batch)
Load existing information about a serial.
$pmp
Average price value for product entry into stock (PMP)
load_stock($option='', $includedraftpoforvirtual=null, $dateofvirtualstock=null)
Load information about stock of a product into ->stock_reel, ->stock_warehouse[] (including stock_war...
getProductDurationHours()
Return the duration in Hours of a service base on duration fields.
fetch($id='', $ref='', $ref_ext='', $barcode='', $ignore_expression=0, $ignore_price_load=0, $ignore_lang_load=0)
Load a product in memory from database.
$default_vat_code
Default VAT code for product (link to code into llx_c_tva but without foreign keys)
$duration_unit
Exoiration unit.
get_buyprice($prodfournprice, $qty, $product_id=0, $fourn_ref='', $fk_soc=0)
Read price used by a provider.
clone_fournisseurs($fromId, $toId)
Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre.
const TYPE_PRODUCT
Regular product.
$stock_warehouse
Contains detail of stock of product into each warehouse.
add_photo($sdir, $file)
Move an uploaded file described into $file array into target directory $sdir.
log_price_delete($user, $rowid)
Delete a price line.
update_sousproduit($id_pere, $id_fils, $qty, $incdec=1)
Modify composed product.
update($id, $user, $notrigger=false, $action='update', $updatetype=false)
Update a record into database.
info($id)
Load information for tab info.
const TYPE_STOCKKIT
Advanced feature: stock kit.
load_stats_inproduction($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null)
Charge tableau des stats production pour le produit/service.
correct_stock($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $inventorycode='', $origin_element='', $origin_id=null, $disablestockchangeforsubproduct=0, $extrafields=null)
Adjust stock in a warehouse for product.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
$multiprices
Arrays for multiprices.
$localtax1_tx
Other local taxes.
getChildsArbo($id, $firstlevelonly=0, $level=1, $parents=array())
Return childs of product $id.
load_virtual_stock($includedraftpoforvirtual=null, $dateofvirtualstock=null)
Load value ->stock_theorique of a product.
load_stats_propale($socid=0)
Charge tableau des stats propale pour le produit/service.
get_barcode($object, $type='')
Get a barcode from the module to generate barcode values.
setAccountancyCode($type, $value)
Sets an accountancy code for a product.
load_stats_facture($socid=0)
Charge tableau des stats facture pour le produit/service.
$remise_percent
Default discount percent.
setCategories($categories)
Sets object to supplied categories.
load_stats_reception($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null)
Charge tableau des stats réception fournisseur pour le produit/service.
get_nb_propal($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in proposals in which product is included.
setMultiLangs($user)
Update or add a translation for a product.
$tva_npr
French VAT NPR (0 or 1)
$tva_tx
Default VAT rate of product.
load_stats_bom($socid=0)
Charge tableau des stats OF pour le produit/service.
hasbatch()
Return if object has a sell-by date or eat-by date.
$weight
Metric of products.
load_stats_commande($socid=0, $filtrestatut='', $forVirtualStock=0)
Charge tableau des stats commande client pour le produit/service.
delete_photo($file)
Delete a photo and its thumbs.
fetch_prod_arbo($prod, $compl_path='', $multiply=1, $level=1, $id_parent=0, $ignore_stock_load=0)
Fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousprodu...
getLibStatut($mode=0, $type=0)
Return label of status of object.
load_stats_sending($socid=0, $filtrestatut='', $forVirtualStock=0, $filterShipmentStatus='')
Charge tableau des stats expedition client pour le produit/service.
clone_price($fromId, $toId)
Recopie les prix d'un produit/service sur un autre.
check()
Check that ref and label are ok.
updatePrice($newprice, $newpricebase, $user, $newvat='', $newminprice=0, $level=0, $newnpr=0, $newpbq=0, $ignore_autogen=0, $localtaxes_array=array(), $newdefaultvatcode='')
Modify customer price of a product/Service for a given level.
initAsSpecimen()
Initialise an instance with random values.
liste_photos($dir, $nbmax=0)
Return an array with all photos of product found on disk.
getFather()
Return all parent products for current product (first level only)
getNomUrl($withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='', $add_label=0, $sep=' - ')
Return clicable link of object (with eventually picto)
$product_fourn_id
Id du fournisseur.
$desiredstock
Ask for replenishment when $desiredstock < $stock_reel.
add_sousproduit($id_pere, $id_fils, $qty, $incdec=1)
Link a product/service to a parent product/service.
verify()
Check properties of product are ok (like name, barcode, ...).
get_nb_order($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in orders in which product is included.
del_sousproduit($fk_parent, $fk_child)
Remove a link between a subproduct and a parent product/service.
load_state_board()
Load indicators this->nb for the dashboard.
min_recommended_price()
Return minimum product recommended price.
_log_price($user, $level=0)
Insert a track that we changed a customer price.
_get_stats($sql, $mode, $year=0)
Return an array formated for showing graphs.
$multilangs
Array for multilangs.
load_stats_commande_fournisseur($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null)
Charge tableau des stats commande fournisseur pour le produit/service.
isMandatoryPeriod()
Return if object have a constraint on mandatory_period.
isProduct()
Return if object is a product.
generateMultiprices(User $user, $baseprice, $price_type, $price_vat, $npr, $psq)
Generates prices for a product based on product multiprice generation rules.
LibStatut($status, $mode=0, $type=0)
Return label of a given status.
const TYPE_SERVICE
Service.
is_photo_available($sdir)
Return if at least one photo is available.
get_image_size($file)
Load size of image file.
get_nb_vente($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units or customers invoices in which product is included.
const TYPE_ASSEMBLYKIT
Advanced feature: assembly kit.
Class to manage products or services.
Manage record for batch number management.
static findAll($dbs, $fk_product_stock, $with_qty=0, $fk_product=0)
Return all batch detail records for a given product and warehouse.
File of class to manage predefined price products or services by customer.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_is_file($pathoffile)
Return if path is a file.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='')
Clean a string from all punctuation characters to use it as a ref or login.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
div float
Buy price without taxes.
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
measuring_units_squared($unit)
Transform a given unit scale into the square of that unit, if known.
measuring_units_cubed($unit)
Transform a given unit scale into the cube of that unit, if known.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
$conf db
API class for accounts.