44require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/product/class/productlang.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/productlot.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
60 const SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY = 1;
61 const SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY = 2;
62 const SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT = 3;
68 public $TRIGGER_PREFIX =
'PRODUCT';
73 public $element =
'product';
78 public $table_element =
'product';
83 public $fk_element =
'fk_product';
88 protected $childtables = array(
89 'supplier_proposaldet' => array(
'name' =>
'SupplierProposal',
'parent' =>
'supplier_proposal',
'parentkey' =>
'fk_supplier_proposal'),
90 'propaldet' => array(
'name' =>
'Proposal',
'parent' =>
'propal',
'parentkey' =>
'fk_propal'),
91 'commandedet' => array(
'name' =>
'Order',
'parent' =>
'commande',
'parentkey' =>
'fk_commande'),
92 'facturedet' => array(
'name' =>
'Invoice',
'parent' =>
'facture',
'parentkey' =>
'fk_facture'),
93 'contratdet' => array(
'name' =>
'Contract',
'parent' =>
'contrat',
'parentkey' =>
'fk_contrat'),
94 'facture_fourn_det' => array(
'name' =>
'SupplierInvoice',
'parent' =>
'facture_fourn',
'parentkey' =>
'fk_facture_fourn'),
95 'commande_fournisseurdet' => array(
'name' =>
'SupplierOrder',
'parent' =>
'commande_fournisseur',
'parentkey' =>
'fk_commande'),
96 'mrp_production' => array(
'name' =>
'Mo',
'parent' =>
'mrp_mo',
'parentkey' =>
'fk_mo',
'enabled' =>
'isModEnabled("mrp")'),
97 'bom_bom' => array(
'name' =>
'BOM',
'enabled' =>
'isModEnabled("bom")'),
98 'bom_bomline' => array(
'name' =>
'BOMLine',
'parent' =>
'bom_bom',
'parentkey' =>
'fk_bom',
'enabled' =>
'isModEnabled("bom")'),
106 public $picto =
'product';
117 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm|\.avif';
171 public $price_formated;
183 public $price_ttc_formated;
197 public $price_min_ttc;
203 public $price_base_type;
213 public $multiprices = array();
217 public $multiprices_ttc = array();
221 public $multiprices_base_type = array();
225 public $multiprices_default_vat_code = array();
229 public $multiprices_min = array();
233 public $multiprices_min_ttc = array();
237 public $multiprices_tva_tx = array();
241 public $multiprices_recuperableonly = array();
247 public $price_by_qty;
251 public $prices_by_qty = array();
255 public $prices_by_qty_id = array();
259 public $prices_by_qty_list = array();
269 public $multilangs = array();
274 public $default_vat_code;
289 public $remise_percent;
294 public $localtax1_tx;
298 public $localtax2_tx;
302 public $localtax1_type;
306 public $localtax2_type;
313 public $desc_supplier;
317 public $vatrate_supplier;
321 public $default_vat_code_supplier;
326 public $fourn_multicurrency_price;
331 public $fourn_multicurrency_unitprice;
335 public $fourn_multicurrency_tx;
339 public $fourn_multicurrency_id;
343 public $fourn_multicurrency_code;
365 public $qc_frequency;
372 public $stock_reel = 0;
379 public $stock_theorique;
400 public $seuil_stock_alerte = 0;
405 public $desiredstock = 0;
410 public $duration_value;
414 public $duration_unit;
423 public $fk_default_workstation;
445 public $status_buy = 0;
467 public $fk_default_bom;
474 public $product_fourn_price_id;
496 public $status_batch = 0;
503 public $sell_or_eat_by_mandatory = 0;
510 public $batch_mask =
'';
535 public $weight_units;
543 public $length_units;
559 public $height_units;
567 public $surface_units;
575 public $volume_units;
584 public $net_measure_units;
589 public $accountancy_code_sell;
593 public $accountancy_code_sell_intra;
597 public $accountancy_code_sell_export;
601 public $accountancy_code_buy;
605 public $accountancy_code_buy_intra;
609 public $accountancy_code_buy_export;
619 public $barcode_type;
624 public $barcode_type_code;
629 public $stats_propale = array();
634 public $stats_commande = array();
639 public $stats_contrat = array();
644 public $stats_facture = array();
649 public $stats_proposal_supplier = array();
654 public $stats_commande_fournisseur = array();
659 public $stats_expedition = array();
664 public $stats_reception = array();
669 public $stats_mo = array();
674 public $stats_bom = array();
679 public $stats_mrptoconsume = array();
684 public $stats_mrptoproduce = array();
689 public $stats_facturerec = array();
694 public $stats_facture_fournisseur = array();
699 public $stats_facturefournrec = array();
714 public $product_fourn_id;
720 public $product_id_already_linked;
731 public $stock_warehouse = array();
736 public $fk_default_warehouse;
741 public $fk_price_expression;
759 public $fourn_price_base_type;
776 public $ref_supplier;
790 public $price_autogen = 0;
797 public $sousprods = array();
810 public $is_object_used;
821 public $is_sousproduit_qty;
833 public $is_sousproduit_incdec;
838 public $mandatory_period;
845 public $stockable_product = 1;
875 public $fields = array(
876 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
877 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 5),
878 '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'),
879 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 2,
'position' => 11,
'csslist' =>
'tdoverflowmax250'),
880 'barcode' => array(
'type' =>
'varchar(255)',
'label' =>
'Barcode',
'enabled' =>
'isModEnabled("barcode")',
'position' => 20,
'visible' => -1,
'showoncombobox' => 3,
'cssview' =>
'tdwordbreak',
'csslist' =>
'tdoverflowmax125'),
881 'fk_barcode_type' => array(
'type' =>
'integer',
'label' =>
'BarcodeType',
'enabled' => 1,
'position' => 21,
'notnull' => 0,
'visible' => -1,),
882 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 61,
'uieditable' => 1),
883 'note' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 62),
884 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 500),
885 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
887 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 510,
'foreignkey' =>
'llx_user.rowid'),
888 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
890 'localtax1_tx' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax1tx',
'enabled' => 1,
'position' => 150,
'notnull' => 0,
'visible' => -1,),
891 'localtax1_type' => array(
'type' =>
'varchar(10)',
'label' =>
'Localtax1type',
'enabled' => 1,
'position' => 155,
'notnull' => 1,
'visible' => -1,),
892 'localtax2_tx' => array(
'type' =>
'double(6,3)',
'label' =>
'Localtax2tx',
'enabled' => 1,
'position' => 160,
'notnull' => 0,
'visible' => -1,),
893 'localtax2_type' => array(
'type' =>
'varchar(10)',
'label' =>
'Localtax2type',
'enabled' => 1,
'position' => 165,
'notnull' => 1,
'visible' => -1,),
894 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 170),
895 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000),
898 'mandatory_period' => array(
'type' =>
'integer',
'label' =>
'mandatoryperiod',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'default' =>
'0',
'index' => 1,
'position' => 1000),
899 'stockable_product' => array(
'type' =>
'integer',
'label' =>
'stockable_product',
'enabled' => 1,
'visible' => 1,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 502),
915 const ENABLED_STOCK = 1;
926 $this->ismultientitymanaged = 1;
927 $this->isextrafieldmanaged = 1;
940 $this->
ref = trim((
string) $this->
ref);
950 if (
dol_strlen(trim((
string) $this->label)) == 0) {
968 public function create($user, $notrigger = 0)
970 global
$conf, $langs;
976 $this->
ref = trim((
string) $this->
ref);
980 $this->label = trim((
string) $this->label);
981 $this->price_ttc = (float)
price2num($this->price_ttc);
983 $this->price_min_ttc = (float)
price2num($this->price_min_ttc);
984 $this->price_min = (float)
price2num($this->price_min);
985 $this->price_label = trim((
string) $this->price_label);
986 if (empty($this->tva_tx)) {
989 if (empty($this->tva_npr)) {
993 if (empty($this->localtax1_tx)) {
994 $this->localtax1_tx = 0;
996 if (empty($this->localtax2_tx)) {
997 $this->localtax2_tx = 0;
999 if (empty($this->localtax1_type)) {
1000 $this->localtax1_type =
'0';
1002 if (empty($this->localtax2_type)) {
1003 $this->localtax2_type =
'0';
1006 if (empty($this->price_base_type) &&
getDolGlobalString(
'PRODUCT_PRICE_BASE_TYPE')) {
1009 if (empty($this->
price)) {
1012 if (empty($this->price_min)) {
1013 $this->price_min = 0;
1016 if (empty($this->price_by_qty)) {
1017 $this->price_by_qty = 0;
1020 if (empty($this->
status)) {
1023 if (empty($this->status_buy)) {
1024 $this->status_buy = 0;
1026 if (empty($this->stockable_product)) {
1027 $this->stockable_product = 0;
1036 if ($this->price_base_type ==
'TTC' && $this->price_ttc > 0) {
1037 $price_ttc =
price2num($this->price_ttc,
'MU');
1038 $price_ht =
price2num($this->price_ttc / (1 + ($this->tva_tx / 100)),
'MU');
1042 if ($this->price_base_type !=
'TTC' && $this->
price > 0) {
1044 $price_ttc =
price2num($this->
price * (1 + ($this->tva_tx / 100)),
'MU');
1048 if (($this->price_min_ttc > 0) && ($this->price_base_type ==
'TTC')) {
1049 $price_min_ttc =
price2num($this->price_min_ttc,
'MU');
1050 $price_min_ht =
price2num($this->price_min_ttc / (1 + ($this->tva_tx / 100)),
'MU');
1054 if (($this->price_min > 0) && ($this->price_base_type !=
'TTC')) {
1055 $price_min_ht =
price2num($this->price_min,
'MU');
1056 $price_min_ttc =
price2num($this->price_min * (1 + ($this->tva_tx / 100)),
'MU');
1059 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
1060 $this->accountancy_code_buy_intra = trim((
string) $this->accountancy_code_buy_intra);
1061 $this->accountancy_code_buy_export = trim((
string) $this->accountancy_code_buy_export);
1062 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
1063 $this->accountancy_code_sell_intra = trim((
string) $this->accountancy_code_sell_intra);
1064 $this->accountancy_code_sell_export = trim((
string) $this->accountancy_code_sell_export);
1070 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1071 $this->accountancy_code_buy =
clean_account($this->accountancy_code_buy);
1072 $this->accountancy_code_buy_intra =
clean_account($this->accountancy_code_buy_intra);
1073 $this->accountancy_code_buy_export =
clean_account($this->accountancy_code_buy_export);
1074 $this->accountancy_code_sell =
clean_account($this->accountancy_code_sell);
1075 $this->accountancy_code_sell_intra =
clean_account($this->accountancy_code_sell_intra);
1076 $this->accountancy_code_sell_export =
clean_account($this->accountancy_code_sell_export);
1080 $this->barcode = trim((
string) $this->barcode);
1081 $this->mandatory_period = empty($this->mandatory_period) ? 0 : $this->mandatory_period;
1083 if (empty($this->label)) {
1084 $langs->load(
'errors');
1085 $this->errors[] = $langs->trans(
'ErrorMandatoryParametersNotProvided');
1089 if (empty($this->
ref) || $this->
ref ==
'auto') {
1091 $module =
getDolGlobalString(
'PRODUCT_CODEPRODUCT_ADDON',
'mod_codeproduct_leopard');
1092 if ($module !=
'mod_codeproduct_leopard') {
1093 if (substr($module, 0, 16) ==
'mod_codeproduct_' && substr($module, -3) ==
'php') {
1094 $module = substr($module, 0,
dol_strlen($module) - 4);
1097 $modCodeProduct =
new $module();
1098 '@phan-var-force ModeleProductCode $modCodeProduct';
1099 if (!empty($modCodeProduct->code_auto)) {
1100 $this->
ref = $modCodeProduct->getNextValue($this, $this->
type);
1102 unset($modCodeProduct);
1105 if (empty($this->
ref)) {
1106 $this->error =
'ProductModuleNotSetupForAutoRef';
1111 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);
1115 if (empty($this->date_creation)) {
1116 $this->date_creation = $now;
1122 if ($this->barcode ==
'-1' || $this->barcode ==
'auto') {
1123 $this->barcode = $this->
get_barcode($this, $this->barcode_type_code);
1128 $result = $this->
verify();
1131 $sql =
"SELECT count(*) as nb";
1132 $sql .=
" FROM ".$this->db->prefix().
"product";
1133 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
1134 $sql .=
" AND ref = '".$this->db->escape($this->
ref).
"'";
1136 $result = $this->db->query($sql);
1138 $obj = $this->db->fetch_object($result);
1139 if ($obj->nb == 0) {
1141 $sql =
"INSERT INTO ".$this->db->prefix().
"product (";
1145 $sql .=
", ref_ext";
1146 $sql .=
", price_min";
1147 $sql .=
", price_min_ttc";
1149 $sql .=
", fk_user_author";
1150 $sql .=
", fk_product_type";
1152 $sql .=
", price_ttc";
1153 $sql .=
", price_base_type";
1154 $sql .=
", price_label";
1158 $sql .=
", accountancy_code_buy";
1159 $sql .=
", accountancy_code_buy_intra";
1160 $sql .=
", accountancy_code_buy_export";
1161 $sql .=
", accountancy_code_sell";
1162 $sql .=
", accountancy_code_sell_intra";
1163 $sql .=
", accountancy_code_sell_export";
1166 $sql .=
", finished";
1167 $sql .=
", tobatch";
1168 $sql .=
", sell_or_eat_by_mandatory";
1169 $sql .=
", batch_mask";
1170 $sql .=
", fk_unit";
1171 $sql .=
", mandatory_period";
1172 $sql .=
", stockable_product";
1173 if (!empty($this->default_vat_code)) {
1174 $sql .=
", default_vat_code";
1176 $sql .=
") VALUES (";
1177 $sql .=
"'".$this->db->idate($this->date_creation).
"'";
1178 $sql .=
", ".(!empty($this->entity) ? (int) $this->entity : (int)
$conf->entity);
1179 $sql .=
", '".$this->db->escape($this->
ref).
"'";
1180 $sql .=
", ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1181 $sql .=
", ".price2num($price_min_ht);
1182 $sql .=
", ".price2num($price_min_ttc);
1183 $sql .=
", ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
1184 $sql .=
", ".((int) $user->id);
1185 $sql .=
", ".((int) $this->
type);
1186 $sql .=
", ".price2num($price_ht,
'MT');
1187 $sql .=
", ".price2num($price_ttc,
'MT');
1188 $sql .=
", '".$this->db->escape($this->price_base_type).
"'";
1189 $sql .=
", ".(!empty($this->price_label) ?
"'".$this->db->escape($this->price_label).
"'" :
"null");
1190 $sql .=
", ".((int) $this->
status);
1191 $sql .=
", ".((int) $this->status_buy);
1193 $sql .=
", '".$this->db->escape($this->accountancy_code_buy).
"'";
1194 $sql .=
", '".$this->db->escape($this->accountancy_code_buy_intra).
"'";
1195 $sql .=
", '".$this->db->escape($this->accountancy_code_buy_export).
"'";
1196 $sql .=
", '".$this->db->escape($this->accountancy_code_sell).
"'";
1197 $sql .=
", '".$this->db->escape($this->accountancy_code_sell_intra).
"'";
1198 $sql .=
", '".$this->db->escape($this->accountancy_code_sell_export).
"'";
1200 $sql .=
", '".$this->db->escape($this->canvas).
"'";
1201 $sql .=
", ".((!isset($this->finished) || $this->finished < 0 || $this->finished ==
'') ?
'NULL' : (int) $this->finished);
1202 $sql .=
", ".((empty($this->status_batch) || $this->status_batch < 0) ?
'0' : ((int) $this->status_batch));
1203 $sql .=
", ".((empty($this->sell_or_eat_by_mandatory) || $this->sell_or_eat_by_mandatory < 0) ? 0 : ((int) $this->sell_or_eat_by_mandatory));
1204 $sql .=
", '".$this->db->escape($this->batch_mask).
"'";
1205 $sql .=
", ".($this->fk_unit > 0 ? ((int) $this->fk_unit) :
'NULL');
1206 $sql .=
", '".$this->db->escape((
string) $this->mandatory_period).
"'";
1207 $sql .=
", ".((int) $this->stockable_product);
1208 if (!empty($this->default_vat_code)) {
1209 $sql .=
", '".$this->db->escape($this->default_vat_code).
"'";
1212 dol_syslog(get_class($this).
"::Create", LOG_DEBUG);
1214 $result = $this->db->query($sql);
1216 $id = $this->db->last_insert_id($this->db->prefix().
"product");
1220 $this->
price = $price_ht;
1221 $this->price_ttc = $price_ttc;
1222 $this->price_min = $price_min_ht;
1223 $this->price_min_ttc = $price_min_ttc;
1227 if ($this->
update($id, $user, 1,
'add') <= 0) {
1232 $this->error = $this->db->lasterror();
1237 $this->db->query(
"DELETE FROM " . $this->db->prefix() .
"product_perentity WHERE fk_product = " .((int) $this->id) .
" AND entity = " . ((
int)
$conf->entity));
1239 $sql =
"INSERT INTO " . $this->db->prefix() .
"product_perentity (";
1240 $sql .=
" fk_product";
1242 $sql .=
", accountancy_code_buy";
1243 $sql .=
", accountancy_code_buy_intra";
1244 $sql .=
", accountancy_code_buy_export";
1245 $sql .=
", accountancy_code_sell";
1246 $sql .=
", accountancy_code_sell_intra";
1247 $sql .=
", accountancy_code_sell_export";
1248 $sql .=
") VALUES (";
1249 $sql .= ((int) $this->
id);
1250 $sql .=
", " . ((int)
$conf->entity);
1251 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1252 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy_intra) .
"'";
1253 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy_export) .
"'";
1254 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1255 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell_intra) .
"'";
1256 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell_export) .
"'";
1258 $result = $this->db->query($sql);
1261 $this->error =
'ErrorFailedToInsertAccountancyForEntity';
1266 $this->error =
'ErrorFailedToGetInsertedId';
1270 $this->error = $this->db->lasterror();
1274 $langs->load(
"products");
1276 $this->error =
"ErrorProductAlreadyExists";
1277 dol_syslog(get_class($this).
"::Create fails, ref ".$this->
ref.
" already exists");
1281 $this->error = $this->db->lasterror();
1284 if (!$error && !$notrigger) {
1286 $result = $this->call_trigger(
'PRODUCT_CREATE', $user);
1294 $this->db->commit();
1297 $this->db->rollback();
1301 $this->db->rollback();
1302 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
1318 $this->errors = array();
1321 $this->
ref = trim((
string) $this->
ref);
1324 $this->errors[] =
'ErrorBadRef';
1328 $arrayofnonnegativevalue = array(
'weight' =>
'Weight',
'width' =>
'Width',
'height' =>
'Height',
'length' =>
'Length',
'surface' =>
'Surface',
'volume' =>
'Volume');
1329 foreach ($arrayofnonnegativevalue as $key => $value) {
1330 if (property_exists($this, $key) && !empty($this->$key) && ($this->$key < 0)) {
1331 $langs->loadLangs(array(
"main",
"other"));
1332 $this->error = $langs->trans(
"FieldCannotBeNegative", $langs->transnoentitiesnoconv($value));
1333 $this->errors[] = $this->error;
1338 $rescode = $this->check_barcode($this->barcode, $this->barcode_type_code);
1340 if ($rescode == -1) {
1341 $this->errors[] =
'ErrorBadBarCodeSyntax';
1342 } elseif ($rescode == -2) {
1343 $this->errors[] =
'ErrorBarCodeRequired';
1344 } elseif ($rescode == -3) {
1346 $this->errors[] =
'ErrorBarCodeAlreadyUsed';
1366 public function check_barcode($valuetotest, $typefortest)
1374 $dirsociete = array_merge(array(
'/core/modules/barcode/'),
$conf->modules_parts[
'barcode']);
1375 foreach ($dirsociete as $dirroot) {
1382 $mod =
new $module();
1383 '@phan-var-force ModeleNumRefBarCode $mod';
1386 dol_syslog(get_class($this).
"::check_barcode value=".$valuetotest.
" type=".$typefortest.
" module=".$module);
1387 $result = $mod->verif($this->db, $valuetotest, $this, 0, $typefortest);
1405 public function update($id, $user, $notrigger = 0, $action =
'update', $updatetype =
false)
1407 global $langs,
$conf, $hookmanager;
1412 if (!$this->label) {
1413 $this->label =
'MISSING LABEL';
1418 $this->
ref = trim((
string) $this->
ref);
1422 $this->label = trim((
string) $this->label);
1424 $this->note_private = (isset($this->note_private) ? trim($this->note_private) :
null);
1425 $this->note_public = (isset($this->note_public) ? trim($this->note_public) :
null);
1426 $this->net_measure =
price2num($this->net_measure);
1427 $this->net_measure_units = (!is_numeric($this->net_measure_units) ? null : (int) $this->net_measure_units);
1428 $this->weight =
price2num($this->weight);
1429 $this->weight_units = (!is_numeric($this->weight_units) ? null : (int) $this->weight_units);
1430 $this->length =
price2num($this->length);
1431 $this->length_units = (!is_numeric($this->length_units) ? null : (int) $this->length_units);
1433 $this->width_units = (!is_numeric($this->width_units) ? null : (int) $this->width_units);
1434 $this->height =
price2num($this->height);
1435 $this->height_units = (!is_numeric($this->height_units) ? null : (int) $this->height_units);
1436 $this->surface =
price2num($this->surface);
1437 $this->surface_units = (!is_numeric($this->surface_units) ? null : (int) $this->surface_units);
1438 $this->volume =
price2num($this->volume);
1439 $this->volume_units = (!is_numeric($this->volume_units) ? null : (int) $this->volume_units);
1442 if (is_numeric($this->length_units)) {
1443 $this->width_units = $this->length_units;
1445 if (is_numeric($this->length_units)) {
1446 $this->height_units = $this->length_units;
1450 if (empty($this->surface) && !empty($this->length) && !empty($this->width) && $this->length_units == $this->width_units) {
1451 $this->surface = (float) $this->length * (
float) $this->width;
1454 if (empty($this->volume) && !empty($this->surface) && !empty($this->height) && $this->length_units == $this->height_units) {
1455 $this->volume = $this->surface * (float) $this->height;
1459 if (empty($this->tva_tx)) {
1462 if (empty($this->tva_npr)) {
1465 if (empty($this->localtax1_tx)) {
1466 $this->localtax1_tx = 0;
1468 if (empty($this->localtax2_tx)) {
1469 $this->localtax2_tx = 0;
1471 if (empty($this->localtax1_type)) {
1472 $this->localtax1_type =
'0';
1474 if (empty($this->localtax2_type)) {
1475 $this->localtax2_type =
'0';
1477 if (empty($this->
status)) {
1480 if (empty($this->status_buy)) {
1481 $this->status_buy = 0;
1484 if (empty($this->country_id)) {
1485 $this->country_id = 0;
1487 if (empty($this->country_id) && !empty($this->country_code)) {
1488 $country_id =
getCountry($this->country_code,
'3');
1489 $this->country_id = is_int($country_id) ? $country_id : 0;
1492 if (empty($this->state_id)) {
1493 $this->state_id = 0;
1496 if (empty($this->stockable_product)) {
1497 $this->stockable_product = 0;
1501 if ($this->barcode ==
'-1' || $this->barcode ==
'auto') {
1502 $this->barcode = $this->
get_barcode($this, $this->barcode_type_code);
1506 $this->barcode = (empty($this->barcode) ?
'' : trim($this->barcode));
1508 $this->accountancy_code_buy = trim((
string) $this->accountancy_code_buy);
1509 $this->accountancy_code_buy_intra = (!empty($this->accountancy_code_buy_intra) ? trim($this->accountancy_code_buy_intra) :
'');
1510 $this->accountancy_code_buy_export = trim((
string) $this->accountancy_code_buy_export);
1511 $this->accountancy_code_sell = trim((
string) $this->accountancy_code_sell);
1512 $this->accountancy_code_sell_intra = trim((
string) $this->accountancy_code_sell_intra);
1513 $this->accountancy_code_sell_export = trim((
string) $this->accountancy_code_sell_export);
1519 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
1520 $this->accountancy_code_buy =
clean_account($this->accountancy_code_buy);
1521 $this->accountancy_code_buy_intra =
clean_account($this->accountancy_code_buy_intra);
1522 $this->accountancy_code_buy_export =
clean_account($this->accountancy_code_buy_export);
1523 $this->accountancy_code_sell =
clean_account($this->accountancy_code_sell);
1524 $this->accountancy_code_sell_intra =
clean_account($this->accountancy_code_sell_intra);
1525 $this->accountancy_code_sell_export =
clean_account($this->accountancy_code_sell_export);
1532 if ($action !=
'add') {
1533 $result = $this->
verify();
1545 if (is_null($this->oldcopy) || (is_object($this->oldcopy) && empty($this->oldcopy->id)) || !($this->oldcopy instanceof
Product)) {
1550 if ($this->
hasbatch() && !$this->oldcopy->hasbatch()) {
1552 $valueforundefinedlot =
'000000';
1557 dol_syslog(
"Flag batch of product id=".$this->
id.
" is set to ON, so we will create missing records into product_batch");
1560 foreach ($this->stock_warehouse as $idW => $ObjW) {
1562 foreach ($ObjW->detail_batch as $detail) {
1563 if ($detail->batch == $valueforundefinedlot || $detail->batch ==
'Undefined') {
1565 $sqlclean =
"DELETE FROM ".$this->db->prefix().
"product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot).
"') AND fk_product_stock = ".((int) $ObjW->id);
1566 $result = $this->db->query($sqlclean);
1568 dol_print_error($this->db);
1574 $qty_batch += $detail->qty;
1578 if ($ObjW->real != $qty_batch) {
1580 $ObjBatch->batch = $valueforundefinedlot;
1581 $ObjBatch->qty = ($ObjW->real - $qty_batch);
1582 $ObjBatch->fk_product_stock = (int) $ObjW->id;
1584 if ($ObjBatch->create($user, 1) < 0) {
1586 $this->errors = $ObjBatch->errors;
1591 if ($ObjLot->fetch(0, $this->id, $valueforundefinedlot) == 0) {
1592 $ObjLot->fk_product = $this->id;
1593 $ObjLot->entity = (int) $this->entity;
1594 $ObjLot->fk_user_creat = $user->id;
1595 $ObjLot->batch = $valueforundefinedlot;
1596 if ($ObjLot->create($user, 1) < 0) {
1598 $this->errors = $ObjLot->errors;
1606 $sql =
"UPDATE ".$this->db->prefix().
"product";
1607 $sql .=
" SET label = '".$this->db->escape($this->label).
"'";
1610 $sql .=
", fk_product_type = ".((int) $this->
type);
1613 $sql .=
", ref = '".$this->db->escape($this->
ref).
"'";
1614 $sql .=
", ref_ext = ".(!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1615 $sql .=
", default_vat_code = ".($this->default_vat_code ?
"'".$this->db->escape($this->default_vat_code).
"'" :
"null");
1616 $sql .=
", tva_tx = ".((float) $this->tva_tx);
1617 $sql .=
", recuperableonly = ".((int) $this->tva_npr);
1618 $sql .=
", localtax1_tx = ".((float) $this->localtax1_tx);
1619 $sql .=
", localtax2_tx = ".((float) $this->localtax2_tx);
1620 $sql .=
", localtax1_type = ".($this->localtax1_type !=
'' ?
"'".$this->db->escape($this->localtax1_type).
"'" :
"'0'");
1621 $sql .=
", localtax2_type = ".($this->localtax2_type !=
'' ?
"'".$this->db->escape($this->localtax2_type).
"'" :
"'0'");
1623 $sql .=
", barcode = ".(empty($this->barcode) ?
"null" :
"'".$this->db->escape($this->barcode).
"'");
1624 $sql .=
", fk_barcode_type = ".(empty($this->barcode_type) ?
"null" : ((int) $this->barcode_type));
1626 $sql .=
", tosell = ".(int) $this->
status;
1627 $sql .=
", tobuy = ".(int) $this->status_buy;
1628 $sql .=
", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ?
'0' : (int) $this->status_batch);
1629 $sql .=
", sell_or_eat_by_mandatory = ".((empty($this->sell_or_eat_by_mandatory) || $this->sell_or_eat_by_mandatory < 0) ? 0 : (int) $this->sell_or_eat_by_mandatory);
1630 $sql .=
", batch_mask = '".$this->db->escape($this->batch_mask).
"'";
1632 $sql .=
", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished ===
'') ?
"null" : (int) $this->finished);
1633 $sql .=
", fk_default_bom = ".((!isset($this->fk_default_bom) || $this->fk_default_bom < 0 || $this->fk_default_bom ==
'') ?
"null" : (int) $this->fk_default_bom);
1634 $sql .=
", net_measure = ".($this->net_measure !=
'' ?
"'".$this->db->escape($this->net_measure).
"'" :
'null');
1635 $sql .=
", net_measure_units = ".((string) $this->net_measure_units !=
'' ? ((
int) $this->net_measure_units) :
'null');
1636 $sql .=
", weight = ".($this->weight !=
'' ?
"'".$this->db->escape($this->weight).
"'" :
'null');
1637 $sql .=
", weight_units = ".((string) $this->weight_units !=
'' ? ((
int) $this->weight_units) :
'null');
1638 $sql .=
", length = ".($this->length !=
'' ?
"'".$this->db->escape($this->length).
"'" :
'null');
1639 $sql .=
", length_units = ".((string) $this->length_units !=
'' ? ((
int) $this->length_units) :
'null');
1640 $sql .=
", width= ".($this->width !=
'' ?
"'".$this->db->escape($this->width).
"'" :
'null');
1641 $sql .=
", width_units = ".((string) $this->width_units !=
'' ? ((
int) $this->width_units) :
'null');
1642 $sql .=
", height = ".($this->height !=
'' ?
"'".$this->db->escape($this->height).
"'" :
'null');
1643 $sql .=
", height_units = ".((string) $this->height_units !=
'' ? ((
int) $this->height_units) :
'null');
1644 $sql .=
", surface = ".($this->surface !=
'' ?
"'".$this->db->escape($this->surface).
"'" :
'null');
1645 $sql .=
", surface_units = ".((string) $this->surface_units !=
'' ? ((
int) $this->surface_units) :
'null');
1646 $sql .=
", volume = ".($this->volume !=
'' ?
"'".$this->db->escape($this->volume).
"'" :
'null');
1647 $sql .=
", volume_units = ".((string) $this->volume_units !=
'' ? ((
int) $this->volume_units) :
'null');
1648 $sql .=
", fk_default_warehouse = ".($this->fk_default_warehouse > 0 ? ((int) $this->fk_default_warehouse) :
'null');
1649 $sql .=
", fk_default_workstation = ".($this->fk_default_workstation > 0 ? ((int) $this->fk_default_workstation) :
'null');
1650 $sql .=
", seuil_stock_alerte = ".((isset($this->seuil_stock_alerte) && is_numeric($this->seuil_stock_alerte)) ? (
float) $this->seuil_stock_alerte :
'null');
1651 $sql .=
", description = '".$this->db->escape($this->description).
"'";
1652 $sql .=
", url = ".($this->url ?
"'".$this->db->escape($this->url).
"'" :
'null');
1653 $sql .=
", customcode = '".$this->db->escape($this->customcode).
"'";
1654 $sql .=
", fk_country = ".($this->country_id > 0 ? (int) $this->country_id :
'null');
1655 $sql .=
", fk_state = ".($this->state_id > 0 ? (int) $this->state_id :
'null');
1656 $sql .=
", lifetime = ".($this->lifetime > 0 ? (int) $this->lifetime :
'null');
1657 $sql .=
", qc_frequency = ".($this->qc_frequency > 0 ? (int) $this->qc_frequency :
'null');
1658 $sql .=
", note = ".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
'null');
1659 $sql .=
", note_public = ".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
'null');
1660 $sql .=
", duration = '".$this->db->escape($this->duration_value.$this->duration_unit).
"'";
1662 $sql .=
", accountancy_code_buy = '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1663 $sql .=
", accountancy_code_buy_intra = '" . $this->db->escape($this->accountancy_code_buy_intra) .
"'";
1664 $sql .=
", accountancy_code_buy_export = '" . $this->db->escape($this->accountancy_code_buy_export) .
"'";
1665 $sql .=
", accountancy_code_sell= '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1666 $sql .=
", accountancy_code_sell_intra= '" . $this->db->escape($this->accountancy_code_sell_intra) .
"'";
1667 $sql .=
", accountancy_code_sell_export= '" . $this->db->escape($this->accountancy_code_sell_export) .
"'";
1669 $sql .=
", desiredstock = ".((isset($this->desiredstock) && is_numeric($this->desiredstock)) ? (
float) $this->desiredstock :
"null");
1670 $sql .=
", cost_price = ".($this->cost_price !=
'' ? ((float) $this->cost_price) :
'null');
1671 $sql .=
", fk_unit= ".(!$this->fk_unit ?
'NULL' : (int) $this->fk_unit);
1672 $sql .=
", price_autogen = ".(!$this->price_autogen ? 0 : 1);
1673 $sql .=
", fk_price_expression = ".($this->fk_price_expression != 0 ? (int) $this->fk_price_expression :
'NULL');
1674 $sql .=
", fk_user_modif = ".($user->id > 0 ? (int) $user->id :
'NULL');
1675 $sql .=
", mandatory_period = ".((int) $this->mandatory_period);
1676 $sql .=
", stockable_product = ".(int) $this->stockable_product;
1678 $sql .=
", packaging = ".(float) $this->packaging;
1682 $sql .=
" WHERE rowid = ".((int) $id);
1684 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1686 $resql = $this->db->query($sql);
1693 $this->db->rollback();
1702 $this->db->query(
"DELETE FROM " . $this->db->prefix() .
"product_perentity WHERE fk_product = " . ((
int) $this->id) .
" AND entity = " . ((
int)
$conf->entity));
1704 $sql =
"INSERT INTO " . $this->db->prefix() .
"product_perentity (";
1705 $sql .=
" fk_product";
1707 $sql .=
", accountancy_code_buy";
1708 $sql .=
", accountancy_code_buy_intra";
1709 $sql .=
", accountancy_code_buy_export";
1710 $sql .=
", accountancy_code_sell";
1711 $sql .=
", accountancy_code_sell_intra";
1712 $sql .=
", accountancy_code_sell_export";
1713 $sql .=
") VALUES (";
1714 $sql .= ((int) $this->
id);
1715 $sql .=
", " . ((int)
$conf->entity);
1716 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy) .
"'";
1717 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy_intra) .
"'";
1718 $sql .=
", '" . $this->db->escape($this->accountancy_code_buy_export) .
"'";
1719 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell) .
"'";
1720 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell_intra) .
"'";
1721 $sql .=
", '" . $this->db->escape($this->accountancy_code_sell_export) .
"'";
1723 $result = $this->db->query($sql);
1726 $this->error =
'ErrorFailedToUpdateAccountancyForEntity';
1730 if (!$this->
hasbatch() && $this->oldcopy->hasbatch()) {
1732 $sql =
'SELECT pb.qty, ps.fk_entrepot, pb.batch FROM '.MAIN_DB_PREFIX.
'product_batch as pb';
1733 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'product_stock as ps ON (ps.rowid = pb.fk_product_stock)';
1734 $sql .=
' WHERE ps.fk_product = '.(int) $this->
id;
1736 $resql = $this->db->query($sql);
1740 while ($obj = $this->db->fetch_object($resql)) {
1742 $fk_entrepot = $obj->fk_entrepot;
1746 $batch = $obj->batch;
1749 $addOremove = $value > 0 ? 1 : 0;
1750 $label = $langs->trans(
'BatchStockMouvementAddInGlobal');
1751 $res = $this->
correct_stock_batch($user, $fk_entrepot, abs($value), $addOremove, $label, $price, $dlc, $dluo, $batch, $inventorycode,
'',
null, 0,
null,
true);
1754 $label = $langs->trans(
'BatchStockMouvementAddInGlobal');
1755 $res = $this->
correct_stock($user, $fk_entrepot, abs($value), (
int) empty($addOremove), $label, $price, $inventorycode,
'',
null, 0);
1774 if (!$error && !$notrigger) {
1776 $result = $this->call_trigger(
'PRODUCT_MODIFY', $user);
1783 if (!$error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref)) {
1785 if (
$conf->product->dir_output) {
1788 if (file_exists($olddir)) {
1792 $res = @rename($olddir, $newdir);
1794 $langs->load(
"errors");
1795 $this->error = $langs->trans(
'ErrorFailToRenameDir', $olddir, $newdir);
1799 require_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
1800 $ecmfiles =
new EcmFiles($this->db);
1801 $ecmfiles->updateAfterRename(
"produit/".
dol_sanitizeFileName($this->oldcopy->ref),
"produit/".dol_sanitizeFileName($this->ref));
1809 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
1813 foreach ($comb->fetchAllByFkProductParent($this->id) as $currcomb) {
1814 $currcomb->updateProperties($this, $user);
1818 $this->db->commit();
1821 $this->db->rollback();
1825 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1826 $langs->load(
"errors");
1827 if (empty(
$conf->barcode->enabled) || empty($this->barcode)) {
1828 $this->error = $langs->trans(
"Error").
" : ".$langs->trans(
"ErrorProductAlreadyExists", $this->
ref);
1830 $this->error = $langs->trans(
"Error").
" : ".$langs->trans(
"ErrorProductBarCodeAlreadyExists", $this->barcode);
1832 $this->errors[] = $this->error;
1833 $this->db->rollback();
1836 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
1837 $this->errors[] = $this->error;
1838 $this->db->rollback();
1843 $this->db->rollback();
1844 dol_syslog(get_class($this).
"::Update fails verify ".implode(
',', $this->errors), LOG_WARNING);
1856 public function delete(
User $user, $notrigger = 0)
1859 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1864 if (empty($this->
id)) {
1865 $this->error =
"Object must be fetched before calling delete";
1868 if (($this->
isProduct() && !$user->
hasRight(
'produit',
'supprimer')) || ($this->isService() && !$user->hasRight(
'service',
'supprimer'))) {
1869 $this->error =
"ErrorForbidden";
1874 if (empty($objectisused)) {
1877 if (empty($notrigger)) {
1879 $result = $this->call_trigger(
'PRODUCT_DELETE', $user);
1888 $sql =
"DELETE FROM ".$this->db->prefix().
'product_batch';
1889 $sql .=
" WHERE fk_product_stock IN (";
1890 $sql .=
"SELECT rowid FROM ".$this->db->prefix().
'product_stock';
1891 $sql .=
" WHERE fk_product = ".((int) $this->
id).
")";
1893 $result = $this->db->query($sql);
1896 $this->errors[] = $this->db->lasterror();
1902 $sql =
"DELETE FROM " . $this->db->prefix() .
"product_fournisseur_price_log";
1903 $sql .=
" WHERE fk_product_fournisseur IN (";
1904 $sql .=
" SELECT rowid FROM " . $this->db->prefix() .
"product_fournisseur_price";
1905 $sql .=
" WHERE fk_product = " . ((int) $this->
id);
1908 $resql = $this->db->query($sql);
1911 $this->errors[] = $this->db->lasterror();
1917 $sql =
"DELETE FROM ".$this->db->prefix().
"product_lang_extrafields";
1918 $sql .=
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix().
"product_lang WHERE fk_product = ".((int) $this->
id).
")";
1919 $result = $this->db->query($sql);
1922 $this->errors[] = $this->db->lasterror();
1928 $elements = array(
'product_fournisseur_price',
'product_price',
'product_lang',
'categorie_product',
'product_stock',
'product_customer_price',
'product_lot');
1929 foreach ($elements as $table) {
1931 $sql =
"DELETE FROM ".$this->db->prefix().$table;
1932 $sql .=
" WHERE fk_product = ".(int) $this->
id;
1934 $result = $this->db->query($sql);
1937 $this->errors[] = $this->db->lasterror();
1944 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
1945 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination2ValuePair.class.php';
1950 if ($prodcomb->deleteByFkProductParent($user, $this->id) < 0) {
1952 $this->errors[] =
'Error deleting combinations';
1956 if (!$error && ($prodcomb->fetchByFkProductChild($this->id) > 0) && ($prodcomb->delete($user) < 0)) {
1958 $this->errors[] =
'Error deleting child combination';
1968 include_once DOL_DOCUMENT_ROOT.
'/variants/class/ProductCombination.class.php';
1971 if ($prodcomb->deleteLinksByProduct($this->id) < 0) {
1973 $this->errors[] = $prodcomb->error;
1979 $sql =
"DELETE FROM ".$this->db->prefix().
"product_association";
1980 $sql .=
" WHERE fk_product_pere = ".(int) $this->
id.
" OR fk_product_fils = ".(
int) $this->id;
1982 $result = $this->db->query($sql);
1985 $this->errors[] = $this->db->lasterror();
1994 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2000 $sqlz =
"DELETE FROM ".$this->db->prefix().
"product";
2001 $sqlz .=
" WHERE rowid = ".(int) $this->
id;
2003 $resultz = $this->db->query($sqlz);
2006 $this->errors[] = $this->db->lasterror();
2022 if ($conf->product->dir_output) {
2023 $dir =
$conf->product->dir_output.
"/".$ref;
2024 if (file_exists($dir)) {
2027 $this->errors[] =
'ErrorFailToDeleteDir';
2035 $this->db->commit();
2038 foreach ($this->errors as $errmsg) {
2039 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
2040 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2042 $this->db->rollback();
2046 $this->error =
"ErrorRecordIsUsedCantDelete";
2060 $sellByLabel = $langs->trans(
'SellByDate');
2061 $eatByLabel = $langs->trans(
'EatByDate');
2063 self::SELL_OR_EAT_BY_MANDATORY_ID_NONE => $langs->trans(
'BatchSellOrEatByMandatoryNone'),
2064 self::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY => $sellByLabel,
2065 self::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY => $eatByLabel,
2066 self::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT => $langs->trans(
'BatchSellOrEatByMandatoryAll', $sellByLabel, $eatByLabel),
2077 $sellOrEatByMandatoryLabel =
'';
2080 if (isset($sellOrEatByMandatoryList[$this->sell_or_eat_by_mandatory])) {
2081 $sellOrEatByMandatoryLabel = $sellOrEatByMandatoryList[$this->sell_or_eat_by_mandatory];
2084 return $sellOrEatByMandatoryLabel;
2098 $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2);
2099 $current_lang = $langs->getDefaultLang();
2101 foreach ($langs_available as $key => $value) {
2102 if ($key == $current_lang) {
2103 $sql =
"SELECT rowid";
2104 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
2105 $sql .=
" WHERE fk_product = ".((int) $this->
id);
2106 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
2108 $result = $this->db->query($sql);
2109 $objlang = ($result ? $this->db->fetch_object($result) :
null);
2110 $rowidlang = ($objlang ? (int) $objlang->rowid : 0);
2113 $sql2 =
"UPDATE ".$this->db->prefix().
"product_lang";
2115 $sql2 .=
" label='".$this->db->escape($this->label).
"',";
2116 $sql2 .=
" description='".$this->db->escape($this->
description).
"'";
2118 $sql2 .=
", note='".$this->db->escape($this->other).
"'";
2120 $sql2 .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
2122 $sql2 =
"INSERT INTO ".$this->db->prefix().
"product_lang (fk_product, lang, label, description";
2127 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->db->escape($key).
"','".$this->db->escape($this->label).
"',";
2128 $sql2 .=
" '".$this->db->escape($this->
description).
"'";
2130 $sql2 .=
", '".$this->db->escape($this->other).
"'";
2134 dol_syslog(get_class($this).
'::setMultiLangs key = current_lang = '.$key);
2135 if (!$this->db->query($sql2)) {
2136 $this->error = $this->db->lasterror();
2139 if (empty($rowidlang)) {
2140 $rowidlang = (int) $this->db->last_insert_id($this->db->prefix().
"product_lang");
2145 } elseif (isset($this->multilangs[$key])) {
2146 if (empty($this->multilangs[$key][
"label"])) {
2147 $this->errors[] = $key .
' : ' . $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label"));
2151 $sql =
"SELECT rowid";
2152 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
2153 $sql .=
" WHERE fk_product = ".((int) $this->
id);
2154 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
2156 $result = $this->db->query($sql);
2157 $objlang = ($result ? $this->db->fetch_object($result) :
null);
2158 $rowidlang = ($objlang ? (int) $objlang->rowid : 0);
2161 $sql2 =
"UPDATE ".$this->db->prefix().
"product_lang";
2163 $sql2 .=
" label = '".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
2164 $sql2 .=
" description = '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
2167 $sql2 .=
", note = '".$this->db->escape($this->multilangs[
"$key"][
"other"]).
"'";
2169 $sql2 .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
2171 $sql2 =
"INSERT INTO ".$this->db->prefix().
"product_lang (fk_product, lang, label, description";
2176 $sql2 .=
" VALUES(".((int) $this->
id).
",'".$this->db->escape($key).
"','".$this->db->escape($this->multilangs[
"$key"][
"label"]).
"',";
2177 $sql2 .=
" '".$this->db->escape($this->multilangs[
"$key"][
"description"]).
"'";
2180 $sql2 .=
", '".$this->db->escape($this->multilangs[
"$key"][
"other"]).
"'";
2186 if ($this->multilangs[
"$key"][
"label"] || $this->multilangs[
"$key"][
"description"]) {
2187 if (!$this->db->query($sql2)) {
2188 $this->error = $this->db->lasterror();
2191 if (empty($rowidlang)) {
2192 $rowidlang = (int) $this->db->last_insert_id($this->db->prefix().
"product_lang");
2203 if (empty($notrigger)) {
2205 $result = $this->call_trigger(
'PRODUCT_SET_MULTILANGS', $user);
2207 $this->error = $this->db->lasterror();
2226 if (empty($rowidlang) || !isset($this->multilangs[$langcode][
'array_options']) || !is_array($this->multilangs[$langcode][
'array_options'])) {
2231 $productlang->id = $rowidlang;
2232 $productlang->array_options = $this->multilangs[$langcode][
'array_options'];
2233 $result = $productlang->insertExtraFields();
2235 $this->error = $productlang->error;
2236 $this->errors = array_merge($this->errors, $productlang->errors);
2237 dol_syslog(get_class($this).
'::setMultiLangsExtrafields error='.$this->error, LOG_ERR);
2255 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
2258 $sql =
"DELETE FROM ".$this->db->prefix().
"product_lang_extrafields";
2259 $sql .=
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix().
"product_lang";
2260 $sql .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"')";
2261 $result = $this->db->query($sql);
2263 $this->error = $this->db->lasterror();
2264 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2268 $sql =
"DELETE FROM ".$this->db->prefix().
"product_lang";
2269 $sql .=
" WHERE fk_product = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
2271 $result = $this->db->query($sql);
2273 if (empty($notrigger)) {
2275 $result = $this->call_trigger(
'PRODUCT_DEL_MULTILANGS', $user);
2277 $this->error = $this->db->lasterror();
2278 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2283 unset($this->multilangs[$langtodelete]);
2286 $this->error = $this->db->lasterror();
2287 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2308 if ($type ==
'buy') {
2309 $field =
'accountancy_code_buy';
2310 } elseif ($type ==
'buy_intra') {
2311 $field =
'accountancy_code_buy_intra';
2312 } elseif ($type ==
'buy_export') {
2313 $field =
'accountancy_code_buy_export';
2314 } elseif ($type ==
'sell') {
2315 $field =
'accountancy_code_sell';
2316 } elseif ($type ==
'sell_intra') {
2317 $field =
'accountancy_code_sell_intra';
2318 } elseif ($type ==
'sell_export') {
2319 $field =
'accountancy_code_sell_export';
2324 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ";
2325 $sql .=
"$field = '".$this->db->escape($value).
"'";
2326 $sql .=
" WHERE rowid = ".((int) $this->
id);
2329 $resql = $this->db->query($sql);
2333 $result = $this->call_trigger(
'PRODUCT_MODIFY', $user);
2340 $this->db->rollback();
2344 $this->$field = $value;
2346 $this->db->commit();
2349 $this->error = $this->db->lasterror();
2350 $this->db->rollback();
2367 $current_lang = $langs->getDefaultLang();
2370 $sql =
"SELECT rowid, lang, label, description, note as other";
2371 $sql .=
" FROM ".$this->db->prefix().
"product_lang";
2372 $sql .=
" WHERE fk_product = ".((int) $this->
id);
2374 $result = $this->db->query($sql);
2376 while ($obj = $this->db->fetch_object($result)) {
2378 if ($obj->lang == $current_lang) {
2379 $this->label = $obj->label;
2381 $this->other = $obj->other;
2383 $this->multilangs[(string) $obj->lang][
"rowid"] = (
int) $obj->rowid;
2384 $this->multilangs[(string) $obj->lang][
"label"] = $obj->label;
2385 $this->multilangs[(string) $obj->lang][
"description"] = $obj->description;
2386 $this->multilangs[(string) $obj->lang][
"other"] = $obj->other;
2390 if ($loadextrafields && !empty($this->multilangs)) {
2392 $extrafields->fetch_name_optionals_label(
'product_lang');
2393 if (!empty($extrafields->attributes[
'product_lang'][
'count'])) {
2395 foreach ($this->multilangs as $langcode => $value) {
2396 $productlang->id = $value[
'rowid'];
2397 $productlang->array_options = array();
2398 $productlang->fetch_optionals();
2399 $this->multilangs[$langcode][
'array_options'] = $productlang->array_options;
2406 $this->error =
"Error: ".$this->db->lasterror().
" - ".$sql;
2419 $testExit = array(
'multiprices',
'multiprices_ttc',
'multiprices_base_type',
'multiprices_min',
'multiprices_min_ttc',
'multiprices_tva_tx',
'multiprices_recuperableonly');
2421 foreach ($testExit as $field) {
2422 if (!isset($this->$field)) {
2425 $tmparray = $this->$field;
2426 if (!isset($tmparray[$level])) {
2432 'level' => $level ? $level : 1,
2433 'multiprices' => (float) $this->multiprices[$level],
2434 'multiprices_ttc' => (
float) $this->multiprices_ttc[$level],
2435 'multiprices_base_type' => $this->multiprices_base_type[$level],
2436 'multiprices_min' => (float) $this->multiprices_min[$level],
2437 'multiprices_min_ttc' => (
float) $this->multiprices_min_ttc[$level],
2438 'multiprices_tva_tx' => (float) $this->multiprices_tva_tx[$level],
2439 'multiprices_recuperableonly' => (
float) $this->multiprices_recuperableonly[$level],
2462 if (empty($this->price_by_qty)) {
2463 $this->price_by_qty = 0;
2467 $sql =
"INSERT INTO ".$this->db->prefix().
"product_price(price_level,date_price, fk_product, fk_user_author, price_label, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,";
2468 $sql .=
" localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) ";
2469 $sql .=
" VALUES(".($level ? ((int) $level) : 1).
", '".$this->db->idate($now).
"', ".((int) $this->
id).
", ".((int) $user->id).
", ".(empty($this->price_label) ?
"null" :
"'".$this->db->escape($this->price_label).
"'").
",";
2470 $sql .=
" ".((float)
price2num($this->
price)).
", ".((
float)
price2num($this->price_ttc)).
",'".$this->db->escape($this->price_base_type).
"',".((int) $this->
status).
", ".((float)
price2num($this->tva_tx)).
",";
2471 $sql .=
" ".($this->default_vat_code ? (
"'".$this->db->escape($this->default_vat_code).
"'") :
"null").
", ".((
int) $this->tva_npr).
",";
2472 $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');
2475 dol_syslog(get_class($this).
"::_log_price", LOG_DEBUG);
2476 $resql = $this->db->query($sql);
2478 $this->error = $this->db->lasterror();
2479 dol_print_error($this->db);
2498 $sql =
"DELETE FROM ".$this->db->prefix().
"product_price_by_qty";
2499 $sql .=
" WHERE fk_product_price = ".((int) $rowid);
2500 $sql .=
" AND fk_product_price IN (SELECT pp.rowid FROM ".$this->db->prefix().
"product_price as pp WHERE pp.fk_product = ".((int) $this->
id).
")";
2501 $resql = $this->db->query($sql);
2503 $sql =
"DELETE FROM ".$this->db->prefix().
"product_price_extrafields";
2504 $sql .=
" WHERE fk_object = ".((int) $rowid);
2505 $resql = $this->db->query($sql);
2507 $sql =
"DELETE FROM ".$this->db->prefix().
"product_price";
2508 $sql .=
" WHERE rowid = ".((int) $rowid);
2509 $sql .=
" AND fk_product = ".((int) $this->
id);
2510 $resql = $this->db->query($sql);
2514 $this->error = $this->db->lasterror();
2534 $sql .=
" pl.rowid as log_rowid,";
2535 $sql .=
" pl.datec,";
2536 $sql .=
" pl.price,";
2537 $sql .=
" pl.quantity,";
2538 $sql .=
" pl.fk_user,";
2539 $sql .=
" pl.multicurrency_code,";
2540 $sql .=
" pl.multicurrency_price,";
2542 $sql .=
" pp.fk_soc as supplier_id,";
2543 $sql .=
" pp.ref_fourn as supplier_ref,";
2544 $sql .=
" pp.entity as entity";
2546 $sql .=
" FROM " . $this->db->prefix() .
"product_fournisseur_price_log as pl";
2547 $sql .=
" INNER JOIN " . $this->db->prefix() .
"product_fournisseur_price as pp ON pl.fk_product_fournisseur = pp.rowid";
2549 $sql .=
" WHERE pp.fk_product = " . ((int) $id);
2550 $sql .=
" AND pp.entity IN (" .
getEntity(
'product') .
")";
2551 $sql .=
" ORDER BY pl.datec DESC";
2553 $resql = $this->db->query($sql);
2555 while ($obj = $this->db->fetch_object($resql)) {
2556 if (is_string($obj->datec)) {
2557 $obj->datec = strtotime($obj->datec);
2561 $this->db->free($resql);
2563 $this->error = $this->db->lasterror();
2578 public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0)
2580 global $hookmanager, $action;
2583 if (is_object($hookmanager)) {
2584 $parameters = array(
'thirdparty_seller' => $thirdparty_seller,
'thirdparty_buyer' => $thirdparty_buyer,
'pqp' => $pqp);
2586 $reshook = $hookmanager->executeHooks(
'getSellPrice', $parameters, $this, $action);
2588 return $hookmanager->resArray;
2593 $tva_tx =
get_default_tva($thirdparty_seller, $thirdparty_buyer, $this->
id);
2594 $tva_npr =
get_default_npr($thirdparty_seller, $thirdparty_buyer, $this->
id);
2595 if (empty($tva_tx)) {
2599 $pu_ht = $this->price;
2600 $pu_ttc = $this->price_ttc;
2601 $price_min = $this->price_min;
2602 $price_min_ttc = $this->price_min_ttc;
2603 $price_base_type = (empty($this->price_base_type) ?
'HT' : $this->price_base_type);
2607 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
2611 $filter = array(
't.fk_product' => (
string) $this->
id,
't.fk_soc' => (
string) $thirdparty_buyer->id);
2614 $pricebycustomerexist =
false;
2615 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
2617 if (count($prodcustprice->lines) > 0) {
2618 $date_now = (int) floor(
dol_now() / 86400) * 86400;
2619 foreach ($prodcustprice->lines as $k => $custprice_line) {
2620 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
2621 $pricebycustomerexist =
true;
2622 $pu_ht =
price($custprice_line->price);
2623 $price_min =
price($custprice_line->price_min);
2624 $price_min_ttc =
price($custprice_line->price_min_ttc);
2625 $pu_ttc =
price($custprice_line->price_ttc);
2626 $price_base_type = $custprice_line->price_base_type;
2627 $tva_tx = $custprice_line->tva_tx;
2628 if ($custprice_line->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
2629 $tva_tx .=
' (' . $custprice_line->default_vat_code .
')';
2631 $tva_npr = $custprice_line->recuperableonly;
2632 if (empty($tva_tx)) {
2641 if (!$pricebycustomerexist && !empty($thirdparty_buyer->price_level)) {
2642 $pu_ht = isset($this->multiprices[$thirdparty_buyer->price_level]) ? $this->multiprices[$thirdparty_buyer->price_level] : 0;
2643 $pu_ttc = isset($this->multiprices_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_ttc[$thirdparty_buyer->price_level] : 0;
2644 $price_min = isset($this->multiprices_min[$thirdparty_buyer->price_level]) ? $this->multiprices_min[$thirdparty_buyer->price_level] : 0;
2645 $price_min_ttc = isset($this->multiprices_min_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_min_ttc[$thirdparty_buyer->price_level] : 0;
2646 $price_base_type = isset($this->multiprices_base_type[$thirdparty_buyer->price_level]) ? $this->multiprices_base_type[$thirdparty_buyer->price_level] :
'HT';
2649 if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) {
2650 $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level];
2652 if (isset($this->multiprices_recuperableonly[$thirdparty_buyer->price_level])) {
2653 $tva_npr = $this->multiprices_recuperableonly[$thirdparty_buyer->price_level];
2655 if (empty($tva_tx)) {
2660 } elseif (
getDolGlobalString(
'PRODUIT_MULTIPRICES') && !empty($thirdparty_buyer->price_level)) {
2661 $pu_ht = isset($this->multiprices[$thirdparty_buyer->price_level]) ? $this->multiprices[$thirdparty_buyer->price_level] : 0;
2662 $pu_ttc = isset($this->multiprices_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_ttc[$thirdparty_buyer->price_level] : 0;
2663 $price_min = isset($this->multiprices_min[$thirdparty_buyer->price_level]) ? $this->multiprices_min[$thirdparty_buyer->price_level] : 0;
2664 $price_min_ttc = isset($this->multiprices_min_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_min_ttc[$thirdparty_buyer->price_level] : 0;
2665 $price_base_type = isset($this->multiprices_base_type[$thirdparty_buyer->price_level]) ? $this->multiprices_base_type[$thirdparty_buyer->price_level] :
'HT';
2668 if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) {
2669 $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level];
2671 if (isset($this->multiprices_recuperableonly[$thirdparty_buyer->price_level])) {
2672 $tva_npr = $this->multiprices_recuperableonly[$thirdparty_buyer->price_level];
2674 if (empty($tva_tx)) {
2680 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
2684 $filter = array(
't.fk_product' => (
string) $this->
id,
't.fk_soc' => (
string) $thirdparty_buyer->id);
2686 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
2688 if (count($prodcustprice->lines) > 0) {
2689 $date_now = (int) floor(
dol_now() / 86400) * 86400;
2690 foreach ($prodcustprice->lines as $k => $custprice_line) {
2691 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
2692 $pu_ht =
price($custprice_line->price);
2693 $price_min =
price($custprice_line->price_min);
2694 $price_min_ttc =
price($custprice_line->price_min_ttc);
2695 $pu_ttc =
price($custprice_line->price_ttc);
2696 $price_base_type = $custprice_line->price_base_type;
2697 $tva_tx = $custprice_line->tva_tx;
2698 if ($custprice_line->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
2699 $tva_tx .=
' (' . $custprice_line->default_vat_code .
')';
2701 $tva_npr = $custprice_line->recuperableonly;
2702 if (empty($tva_tx)) {
2712 if (!empty($this->prices_by_qty[0])) {
2715 foreach ($this->prices_by_qty_list[0] as $priceforthequantityarray) {
2716 if ($priceforthequantityarray[
'rowid'] != $pqp) {
2720 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
2721 $pu_ht = $priceforthequantityarray[
'unitprice'];
2723 $pu_ttc = $priceforthequantityarray[
'unitprice'];
2730 if (!empty($thirdparty_buyer->price_level)) {
2732 $pu_ht = isset($this->multiprices[$thirdparty_buyer->price_level]) ? $this->multiprices[$thirdparty_buyer->price_level] : 0;
2733 $pu_ttc = isset($this->multiprices_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_ttc[$thirdparty_buyer->price_level] : 0;
2734 $price_min = isset($this->multiprices_min[$thirdparty_buyer->price_level]) ? $this->multiprices_min[$thirdparty_buyer->price_level] : 0;
2735 $price_min_ttc = isset($this->multiprices_min_ttc[$thirdparty_buyer->price_level]) ? $this->multiprices_min_ttc[$thirdparty_buyer->price_level] : 0;
2736 $price_base_type = empty($this->multiprices_base_type[$thirdparty_buyer->price_level]) ?
'HT' : $this->multiprices_base_type[$thirdparty_buyer->price_level];
2739 if (isset($this->multiprices_tva_tx[$thirdparty_buyer->price_level])) {
2740 $tva_tx = $this->multiprices_tva_tx[$thirdparty_buyer->price_level];
2742 if (isset($this->multiprices_recuperableonly[$thirdparty_buyer->price_level])) {
2743 $tva_npr = $this->multiprices_recuperableonly[$thirdparty_buyer->price_level];
2745 if (empty($tva_tx)) {
2750 if (!empty($thirdparty_buyer->price_level) && !empty($this->prices_by_qty[$thirdparty_buyer->price_level])) {
2753 foreach ($this->prices_by_qty_list[$thirdparty_buyer->price_level] as $priceforthequantityarray) {
2754 if ($priceforthequantityarray[
'rowid'] != $pqp) {
2758 if ($priceforthequantityarray[
'price_base_type'] ==
'HT') {
2759 $pu_ht = $priceforthequantityarray[
'unitprice'];
2761 $pu_ttc = $priceforthequantityarray[
'unitprice'];
2768 $localtax1 =
get_localtax((
string) $tva_tx, 1, $thirdparty_buyer, $thirdparty_seller, $tva_npr);
2769 $localtax2 =
get_localtax((
string) $tva_tx, 2, $thirdparty_buyer, $thirdparty_seller, $tva_npr);
2771 return array(
'pu_ht' => $pu_ht,
'pu_ttc' => $pu_ttc,
'price_min' => $price_min,
'price_min_ttc' => $price_min_ttc,
'price_base_type' => $price_base_type,
'tva_tx' => $tva_tx,
'tva_npr' => $tva_npr,
'localtax1' => $localtax1,
'localtax2' => $localtax2);
2788 public function get_buyprice($prodfournprice, $qty, $product_id = 0, $fourn_ref =
'', $fk_soc = 0)
2791 global $action, $hookmanager;
2794 if (is_object($hookmanager)) {
2795 $parameters = array(
2796 'prodfournprice' => $prodfournprice,
2798 'product_id' => $product_id,
2799 'fourn_ref' => $fourn_ref,
2800 'fk_soc' => $fk_soc,
2803 $reshook = $hookmanager->executeHooks(
'getBuyPrice', $parameters, $this, $action);
2805 return $hookmanager->resArray;
2812 $sql =
"SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
2813 $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,";
2814 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
2815 $sql .=
" pfp.packaging";
2816 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as pfp";
2817 $sql .=
" WHERE pfp.rowid = ".((int) $prodfournprice);
2819 $sql .=
" AND pfp.quantity <= ".((float) $qty);
2821 $sql .=
" ORDER BY pfp.quantity DESC";
2823 dol_syslog(get_class($this).
"::get_buyprice first search by prodfournprice/qty", LOG_DEBUG);
2824 $resql = $this->db->query($sql);
2826 $obj = $this->db->fetch_object($resql);
2827 if ($obj && $obj->quantity > 0) {
2828 if (
isModEnabled(
'dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
2830 $prod_supplier->product_fourn_price_id = $obj->rowid;
2831 $prod_supplier->id = $obj->fk_product;
2832 $prod_supplier->fourn_qty = $obj->quantity;
2833 $prod_supplier->fourn_tva_tx = $obj->tva_tx;
2834 $prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
2836 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2838 $price_result = $priceparser->parseProductSupplier($prod_supplier);
2839 if ($price_result >= 0) {
2840 $obj->price = $price_result;
2843 $this->product_fourn_price_id = $obj->rowid;
2844 $this->buyprice = $obj->price;
2845 $this->fourn_pu = $obj->price / $obj->quantity;
2846 $this->fourn_price_base_type =
'HT';
2847 $this->fourn_socid = $obj->fk_soc;
2848 $this->ref_fourn = $obj->ref_supplier;
2849 $this->ref_supplier = $obj->ref_supplier;
2850 $this->desc_supplier = $obj->desc_supplier;
2851 $this->remise_percent = $obj->remise_percent;
2852 $this->vatrate_supplier = $obj->tva_tx;
2853 $this->default_vat_code_supplier = $obj->default_vat_code;
2854 $this->fourn_multicurrency_price = $obj->multicurrency_price;
2855 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
2856 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
2857 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
2858 $this->fourn_multicurrency_code = $obj->multicurrency_code;
2860 $this->packaging = (float) $obj->packaging;
2866 $this->fourn_qty = $obj->quantity;
2867 $result = $obj->fk_product;
2871 $sql =
"SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pfp.remise_percent, pfp.fk_soc,";
2872 $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,";
2873 $sql .=
" pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,";
2874 $sql .=
" pfp.packaging";
2875 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as pfp";
2876 $sql .=
" WHERE 1 = 1";
2877 if ($product_id > 0) {
2878 $sql .=
" AND pfp.fk_product = ".((int) $product_id);
2880 if ($fourn_ref !=
'none') {
2881 $sql .=
" AND pfp.ref_fourn = '".$this->db->escape($fourn_ref).
"'";
2884 $sql .=
" AND pfp.fk_soc = ".((int) $fk_soc);
2887 $sql .=
" AND pfp.quantity <= ".((float) $qty);
2889 $sql .=
" ORDER BY pfp.quantity DESC";
2892 dol_syslog(get_class($this).
"::get_buyprice second search from qty/ref/product_id", LOG_DEBUG);
2893 $resql = $this->db->query($sql);
2895 $obj = $this->db->fetch_object($resql);
2896 if ($obj && $obj->quantity > 0) {
2897 if (
isModEnabled(
'dynamicprices') && !empty($obj->fk_supplier_price_expression)) {
2899 $prod_supplier->product_fourn_price_id = $obj->rowid;
2900 $prod_supplier->id = $obj->fk_product;
2901 $prod_supplier->fourn_qty = $obj->quantity;
2902 $prod_supplier->fourn_tva_tx = $obj->tva_tx;
2903 $prod_supplier->fk_supplier_price_expression = $obj->fk_supplier_price_expression;
2905 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
2907 $price_result = $priceparser->parseProductSupplier($prod_supplier);
2908 if ($price_result >= 0) {
2909 $obj->price = $price_result;
2912 $this->product_fourn_price_id = $obj->rowid;
2913 $this->buyprice = $obj->price;
2914 $this->fourn_qty = $obj->quantity;
2915 $this->fourn_pu = $obj->price / $obj->quantity;
2916 $this->fourn_price_base_type =
'HT';
2917 $this->fourn_socid = $obj->fk_soc;
2918 $this->ref_fourn = $obj->ref_supplier;
2919 $this->ref_supplier = $obj->ref_supplier;
2920 $this->desc_supplier = $obj->desc_supplier;
2921 $this->remise_percent = $obj->remise_percent;
2922 $this->vatrate_supplier = $obj->tva_tx;
2923 $this->default_vat_code_supplier = $obj->default_vat_code;
2924 $this->fourn_multicurrency_price = $obj->multicurrency_price;
2925 $this->fourn_multicurrency_unitprice = $obj->multicurrency_unitprice;
2926 $this->fourn_multicurrency_tx = $obj->multicurrency_tx;
2927 $this->fourn_multicurrency_id = $obj->fk_multicurrency;
2928 $this->fourn_multicurrency_code = $obj->multicurrency_code;
2930 $this->packaging = (float) $obj->packaging;
2934 $this->fourn_qty = $obj->quantity;
2935 $result = $obj->fk_product;
2941 $this->error = $this->db->lasterror();
2946 $this->error = $this->db->lasterror();
2970 public function updatePrice($newprice, $newpricebase, $user, $newvat =
null, $newminprice = 0, $level = 0, $newnpr = 0, $newpbq = 0, $ignore_autogen = 0, $localtaxes_array = array(), $newdefaultvatcode =
'', $price_label =
'', $notrigger = 0)
2976 dol_syslog(get_class($this).
"::update_price id=".$id.
" newprice=".$newprice.
" newpricebase=".$newpricebase.
" newminprice=".$newminprice.
" level=".$level.
" npr=".$newnpr.
" newdefaultvatcode=".$newdefaultvatcode);
2979 if (empty($this->tva_tx)) {
2980 $this->tva_tx = 0.0;
2982 if (empty($newnpr)) {
2985 if (empty($newminprice)) {
2990 if ($newvat ===
null || $newvat ==
'') {
2991 $newvat = (float) $this->tva_tx;
2994 $localtaxtype1 =
'';
2995 $localtaxtype2 =
'';
3000 return $this->
generateMultiprices($user, $newprice, $newpricebase, $newvat, $newnpr, $newpbq);
3003 if (!empty($newminprice) && ($newminprice > $newprice)) {
3004 $this->error =
'ErrorPriceCantBeLowerThanMinPrice';
3008 if ($newprice === 0 || $newprice !==
'') {
3009 if ($newpricebase ==
'TTC') {
3010 $price_ttc = (float)
price2num($newprice,
'MU');
3011 $price = (float)
price2num($newprice) / (1 + ((float) $newvat / 100));
3012 $price = (float)
price2num($price,
'MU');
3014 if ((
string) $newminprice !=
'0') {
3015 $price_min_ttc = (float)
price2num($newminprice,
'MU');
3016 $price_min = (float)
price2num($newminprice) / (1 + ($newvat / 100));
3017 $price_min = (float)
price2num($price_min,
'MU');
3020 $price_min_ttc = 0.0;
3023 $price = (float)
price2num($newprice,
'MU');
3024 $price_ttc = ($newnpr != 1) ? (
float)
price2num($newprice) * (1 + ($newvat / 100)) : $price;
3025 $price_ttc = (float)
price2num($price_ttc,
'MU');
3027 if ((
string) $newminprice !=
'0') {
3028 $price_min = (float)
price2num($newminprice,
'MU');
3029 $price_min_ttc = (float)
price2num($newminprice) * (1 + ($newvat / 100));
3030 $price_min_ttc = (float)
price2num($price_min_ttc,
'MU');
3034 $price_min_ttc = 0.0;
3038 if (count($localtaxes_array) > 0) {
3039 $localtaxtype1 = $localtaxes_array[
'0'];
3040 $localtax1 = $localtaxes_array[
'1'];
3041 $localtaxtype2 = $localtaxes_array[
'2'];
3042 $localtax2 = $localtaxes_array[
'3'];
3045 if (!empty($newdefaultvatcode)) {
3048 $sql =
"SELECT t.rowid, t.code, t.recuperableonly as tva_npr, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
3049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t, ".MAIN_DB_PREFIX.
"c_country as c";
3050 $sql .=
" WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape(
$mysoc->country_code).
"'";
3051 $sql .=
" AND t.taux = ".((float) $newdefaultvatcode).
" AND t.active = 1";
3052 $sql .=
" AND t.code = '".$this->db->escape($newdefaultvatcode).
"'";
3053 $resql = $this->db->query($sql);
3055 $obj = $this->db->fetch_object($resql);
3057 $npr = $obj->tva_npr;
3058 $localtax1 = $obj->localtax1;
3059 $localtax2 = $obj->localtax2;
3060 $localtaxtype1 = $obj->localtax1_type;
3061 $localtaxtype2 = $obj->localtax2_type;
3066 $localtaxtype1 =
'0';
3068 $localtaxtype2 =
'0';
3072 if (empty($localtax1)) {
3075 if (empty($localtax2)) {
3084 $updatedefaultprice = (empty($level) || $level == 1);
3088 $sql =
"UPDATE ".$this->db->prefix().
"product SET";
3089 if ($updatedefaultprice) {
3090 $sql .=
" price_base_type = '".$this->db->escape($newpricebase).
"',";
3091 $sql .=
" price = ".(float) $price.
",";
3092 $sql .=
" price_ttc = ".(float) $price_ttc.
",";
3093 $sql .=
" price_min = ".(float) $price_min.
",";
3094 $sql .=
" price_min_ttc = ".(float) $price_min_ttc.
",";
3095 $sql .=
" price_label = ".(!empty($price_label) ?
"'".$this->db->escape($price_label).
"'" :
"null").
",";
3097 $sql .=
" localtax1_tx = ".($localtax1 >= 0 ? (float) $localtax1 :
'NULL').
",";
3098 $sql .=
" localtax2_tx = ".($localtax2 >= 0 ? (float) $localtax2 :
'NULL').
",";
3099 $sql .=
" localtax1_type = ".($localtaxtype1 !=
'' ?
"'".$this->db->escape($localtaxtype1).
"'" :
"'0'").
",";
3100 $sql .=
" localtax2_type = ".($localtaxtype2 !=
'' ?
"'".$this->db->escape($localtaxtype2).
"'" :
"'0'").
",";
3101 $sql .=
" default_vat_code = ".($newdefaultvatcode ?
"'".$this->db->escape($newdefaultvatcode).
"'" :
"null").
",";
3102 $sql .=
" tva_tx = ".(float)
price2num($newvat).
",";
3103 $sql .=
" recuperableonly = '".$this->db->escape((
string) $newnpr).
"'";
3104 $sql .=
" WHERE rowid = ".((int) $id);
3106 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3107 $resql = $this->db->query($sql);
3109 $this->multiprices[$level] = $price;
3110 $this->multiprices_ttc[$level] = $price_ttc;
3111 $this->multiprices_min[$level] = $price_min;
3112 $this->multiprices_min_ttc[$level] = $price_min_ttc;
3113 $this->multiprices_base_type[$level] = $newpricebase;
3114 $this->multiprices_default_vat_code[$level] = $newdefaultvatcode;
3115 $this->multiprices_tva_tx[$level] = $newvat;
3116 $this->multiprices_recuperableonly[$level] = $newnpr;
3120 $savdefaultprice = array($this->
price, $this->price_label, $this->price_ttc, $this->price_min, $this->price_min_ttc, $this->price_base_type);
3122 $this->
price = $price;
3123 $this->price_label = $price_label;
3124 $this->price_ttc = $price_ttc;
3125 $this->price_min = $price_min;
3126 $this->price_min_ttc = $price_min_ttc;
3127 $this->price_base_type = $newpricebase;
3128 $this->default_vat_code = $newdefaultvatcode;
3129 $this->tva_tx = $newvat;
3130 $this->tva_npr = $newnpr;
3133 $this->localtax1_tx = $localtax1;
3134 $this->localtax2_tx = $localtax2;
3135 $this->localtax1_type = $localtaxtype1;
3136 $this->localtax2_type = $localtaxtype2;
3144 $sqlpbq =
"SELECT rowid, price_by_qty FROM ".$this->db->prefix().
"product_price";
3145 $sqlpbq .=
" WHERE fk_product = ".((int) $id);
3147 $sqlpbq .=
" AND entity IN (".getEntity(
'productprice').
")";
3148 $sqlpbq .=
" AND price_level = ".((int) ($level ? $level : 1));
3150 $sqlpbq .=
" ORDER BY date_price DESC, rowid DESC";
3151 $sqlpbq .=
" LIMIT 1";
3152 $resqlpbq = $this->db->query($sqlpbq);
3154 $objpbq = $this->db->fetch_object($resqlpbq);
3156 $oldpriceid = (int) $objpbq->rowid;
3157 if (empty($newpbq)) {
3158 $newpbq = (int) $objpbq->price_by_qty;
3166 $this->price_by_qty = $newpbq;
3170 if (!empty(array_diff_assoc($newPriceData, $lastPriceData)) || (!
getDolGlobalString(
'PRODUIT_MULTIPRICES') && !
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES'))) {
3174 if ($newpbq == 1 && $oldpriceid > 0) {
3175 $newpriceid = (int) $this->db->last_insert_id($this->db->prefix().
"product_price");
3176 if ($newpriceid > 0 && $newpriceid != $oldpriceid) {
3177 $sqlpbq =
"UPDATE ".$this->db->prefix().
"product_price_by_qty";
3178 $sqlpbq .=
" SET fk_product_price = ".((int) $newpriceid);
3179 $sqlpbq .=
" WHERE fk_product_price = ".((int) $oldpriceid);
3180 if (!$this->db->query($sqlpbq)) {
3181 $this->error = $this->db->lasterror();
3182 $this->db->rollback();
3189 if (!$updatedefaultprice) {
3191 list($this->
price, $this->price_label, $this->price_ttc, $this->price_min, $this->price_min_ttc, $this->price_base_type) = $savdefaultprice;
3194 $this->level = $level;
3198 $result = $this->call_trigger(
'PRODUCT_PRICE_MODIFY', $user);
3200 $this->db->rollback();
3206 $this->db->commit();
3208 $this->db->rollback();
3209 $this->error = $this->db->lasterror();
3228 $this->fk_price_expression = $expression_id;
3230 return $this->
update($this->
id, $user);
3245 public function fetch($id = 0, $ref =
'', $ref_ext =
'', $barcode =
'', $ignore_expression = 0, $ignore_price_load = 0, $ignore_lang_load = 0)
3247 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
3251 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
3254 if (!$id && !$ref && !$ref_ext && !$barcode) {
3255 $this->error =
'ErrorWrongParameters';
3256 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
3260 $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,";
3261 $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,";
3262 $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,";
3263 $sql .=
" p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.last_main_doc,";
3264 $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, p.packaging,";
3266 $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,";
3268 $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,";
3273 $separatedEntityPMP =
false;
3274 $separatedStock =
false;
3275 $visibleWarehousesEntities =
$conf->entity;
3278 $checkPMPPerEntity = $this->db->query(
"SELECT pmp FROM " . $this->db->prefix() .
"product_perentity WHERE fk_product = ".((int) $id).
" AND entity = ".(
int)
$conf->entity);
3279 if ($this->db->num_rows($checkPMPPerEntity) > 0) {
3280 $separatedEntityPMP =
true;
3284 $separatedStock =
true;
3285 if (isset($mc->sharings[
'stock']) && !empty($mc->sharings[
'stock'])) {
3286 $visibleWarehousesEntities .=
"," . implode(
",", $mc->sharings[
'stock']);
3289 if ($separatedEntityPMP) {
3290 $sql .=
" ppe.pmp,";
3294 $sql .=
" p.datec, GREATEST(p.tms, COALESCE(pef.tms, p.tms)) AS tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,";
3295 $sql .=
" p.fk_price_expression, p.price_autogen, p.stockable_product, p.model_pdf,";
3296 $sql .=
" p.price_label,";
3297 if ($separatedStock) {
3298 $sql .=
" SUM(sp.reel) as stock";
3302 $sql .=
" FROM ".$this->db->prefix().
"product as p";
3303 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_extrafields as pef ON pef.fk_object=p.rowid";
3305 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int)
$conf->entity);
3307 if ($separatedStock) {
3308 $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).
"))";
3312 $sql .=
" WHERE p.rowid = ".((int) $id);
3314 $sql .=
" WHERE p.entity IN (".getEntity($this->element).
")";
3316 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
3317 } elseif ($ref_ext) {
3318 $sql .=
" AND p.ref_ext = '".$this->db->escape($ref_ext).
"'";
3319 } elseif ($barcode) {
3320 $sql .=
" AND p.barcode = '".$this->db->escape($barcode).
"'";
3323 if ($separatedStock) {
3324 $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,";
3325 $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,";
3326 $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,";
3327 $sql .=
" p.length, p.length_units, p.width, p.width_units, p.height, p.height_units,";
3328 $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, p.packaging,";
3330 $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,";
3332 $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,";
3334 if ($separatedEntityPMP) {
3335 $sql .=
" ppe.pmp,";
3339 $sql .=
" p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.sell_or_eat_by_mandatory, p.batch_mask, p.fk_unit,";
3340 $sql .=
" p.fk_price_expression, p.price_autogen, p.stockable_product, p.model_pdf,";
3341 $sql .=
" p.price_label";
3348 $resql = $this->db->query($sql);
3350 unset($this->oldcopy);
3352 if ($this->db->num_rows($resql) > 0) {
3353 $obj = $this->db->fetch_object($resql);
3355 $this->
id = $obj->rowid;
3356 $this->
ref = $obj->ref;
3357 $this->ref_ext = $obj->ref_ext;
3358 $this->label = $obj->label;
3360 $this->url = $obj->url;
3361 $this->note_public = $obj->note_public;
3362 $this->note_private = $obj->note_private;
3363 $this->note = $obj->note_private;
3365 $this->
type = $obj->fk_product_type;
3366 $this->price_label = $obj->price_label;
3367 $this->
status = $obj->tosell;
3368 $this->status_buy = $obj->tobuy;
3369 $this->status_batch = $obj->tobatch;
3370 $this->sell_or_eat_by_mandatory = $obj->sell_or_eat_by_mandatory;
3371 $this->batch_mask = $obj->batch_mask;
3373 $this->customcode = $obj->customcode;
3374 $this->country_id = $obj->fk_country;
3375 $this->country_code =
getCountry($this->country_id,
'2', $this->db);
3376 $this->state_id = $obj->fk_state;
3377 $this->lifetime = $obj->lifetime;
3378 $this->qc_frequency = $obj->qc_frequency;
3379 $this->
price = $obj->price;
3380 $this->price_ttc = $obj->price_ttc;
3381 $this->price_min = $obj->price_min;
3382 $this->price_min_ttc = $obj->price_min_ttc;
3383 $this->price_base_type = (empty($obj->price_base_type) ?
'HT' : $obj->price_base_type);
3384 $this->cost_price = isset($obj->cost_price) ? (float) $obj->cost_price :
null;
3385 $this->default_vat_code = $obj->default_vat_code;
3386 $this->tva_tx = $obj->tva_tx;
3388 $this->tva_npr = $obj->tva_npr;
3390 $this->localtax1_tx = $obj->localtax1_tx;
3391 $this->localtax2_tx = $obj->localtax2_tx;
3392 $this->localtax1_type = $obj->localtax1_type;
3393 $this->localtax2_type = $obj->localtax2_type;
3395 $this->finished = $obj->finished;
3396 $this->fk_default_bom = $obj->fk_default_bom;
3398 $this->duration = $obj->duration;
3400 preg_match(
'/([\d.]+)(\w+)/', $obj->duration, $matches);
3401 $this->duration_value = !empty($matches[1]) ? (float) $matches[1] : 0;
3402 $this->duration_unit = !empty($matches[2]) ? (string) $matches[2] :
null;
3403 $this->canvas = $obj->canvas;
3404 $this->net_measure = $obj->net_measure;
3405 $this->net_measure_units = $obj->net_measure_units;
3406 $this->weight = $obj->weight;
3407 $this->weight_units = (is_null($obj->weight_units) ? 0 : $obj->weight_units);
3408 $this->length = $obj->length;
3409 $this->length_units = (is_null($obj->length_units) ? 0 : $obj->length_units);
3410 $this->width = $obj->width;
3411 $this->width_units = (is_null($obj->width_units) ? 0 : $obj->width_units);
3412 $this->height = $obj->height;
3413 $this->height_units = (is_null($obj->height_units) ? 0 : $obj->height_units);
3415 $this->surface = $obj->surface;
3416 $this->surface_units = (is_null($obj->surface_units) ? 0 : $obj->surface_units);
3417 $this->volume = $obj->volume;
3418 $this->volume_units = (is_null($obj->volume_units) ? 0 : $obj->volume_units);
3419 $this->barcode = $obj->barcode;
3420 $this->barcode_type = $obj->fk_barcode_type;
3422 $this->accountancy_code_buy = $obj->accountancy_code_buy;
3423 $this->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra;
3424 $this->accountancy_code_buy_export = $obj->accountancy_code_buy_export;
3425 $this->accountancy_code_sell = $obj->accountancy_code_sell;
3426 $this->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra;
3427 $this->accountancy_code_sell_export = $obj->accountancy_code_sell_export;
3429 $this->fk_default_warehouse = $obj->fk_default_warehouse;
3430 $this->fk_default_workstation = $obj->fk_default_workstation;
3431 $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
3432 $this->desiredstock = $obj->desiredstock;
3433 $this->stock_reel = $obj->stock;
3434 $this->stockable_product = $obj->stockable_product;
3435 $this->pmp = $obj->pmp;
3437 $this->date_creation = $this->db->jdate($obj->datec);
3438 $this->date_modification = $this->db->jdate($obj->tms);
3440 $this->import_key = $obj->import_key;
3441 $this->entity = $obj->entity;
3443 $this->ref_ext = $obj->ref_ext;
3444 $this->fk_price_expression = $obj->fk_price_expression;
3445 $this->fk_unit = $obj->fk_unit;
3446 $this->price_autogen = $obj->price_autogen;
3447 $this->model_pdf = $obj->model_pdf;
3448 $this->last_main_doc = $obj->last_main_doc;
3450 $this->mandatory_period = $obj->mandatory_period;
3453 $this->packaging = (float) $obj->packaging;
3456 $this->db->free($resql);
3468 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
3469 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
3470 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
3471 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
3472 $sql .=
" ,price_label";
3473 $sql .=
" FROM ".$this->db->prefix().
"product_price";
3474 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
3475 $sql .=
" AND price_level=".((int) $i);
3476 $sql .=
" AND fk_product = ".((int) $this->
id);
3477 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3479 $resql = $this->db->query($sql);
3481 $result = $this->db->fetch_array($resql);
3483 $this->multiprices[$i] = $result ? $result[
"price"] :
null;
3484 $this->multiprices_ttc[$i] = $result ? $result[
"price_ttc"] :
null;
3485 $this->multiprices_min[$i] = $result ? $result[
"price_min"] :
null;
3486 $this->multiprices_min_ttc[$i] = $result ? $result[
"price_min_ttc"] :
null;
3487 $this->multiprices_base_type[$i] = $result ? $result[
"price_base_type"] :
null;
3489 $this->multiprices_tva_tx[$i] = $result ? $result[
"tva_tx"].(!empty($result[
'default_vat_code']) ?
' ('.$result[
'default_vat_code'].
')' :
'') :
null;
3490 $this->multiprices_recuperableonly[$i] = $result ? $result[
"recuperableonly"] :
null;
3529 $this->error = $this->db->lasterror;
3535 } elseif (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY') && empty($ignore_price_load)) {
3536 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
3537 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid";
3538 $sql .=
" FROM ".$this->db->prefix().
"product_price";
3539 $sql .=
" WHERE fk_product = ".((int) $this->
id);
3540 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3543 $resql = $this->db->query($sql);
3545 $result = $this->db->fetch_array($resql);
3549 $this->prices_by_qty[0] = $result[
"price_by_qty"];
3550 $this->prices_by_qty_id[0] = $result[
"rowid"];
3552 if ($this->prices_by_qty[0] == 1) {
3553 $sql =
"SELECT rowid,price, unitprice, quantity, remise_percent, remise, remise, price_base_type";
3554 $sql .=
" FROM ".$this->db->prefix().
"product_price_by_qty";
3555 $sql .=
" WHERE fk_product_price = ".((int) $this->prices_by_qty_id[0]);
3556 $sql .=
" ORDER BY quantity ASC";
3558 $resql = $this->db->query($sql);
3560 $resultat = array();
3562 while ($result = $this->db->fetch_array($resql)) {
3563 $resultat[$ii] = array();
3564 $resultat[$ii][
"rowid"] = $result[
"rowid"];
3565 $resultat[$ii][
"price"] = $result[
"price"];
3566 $resultat[$ii][
"unitprice"] = $result[
"unitprice"];
3567 $resultat[$ii][
"quantity"] = $result[
"quantity"];
3568 $resultat[$ii][
"remise_percent"] = $result[
"remise_percent"];
3570 $resultat[$ii][
"price_base_type"] = $result[
"price_base_type"];
3573 $this->prices_by_qty_list[0] = $resultat;
3575 $this->error = $this->db->lasterror;
3581 $this->error = $this->db->lasterror;
3584 } elseif (
getDolGlobalString(
'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES') && empty($ignore_price_load)) {
3585 $produit_multiprices_limit =
getDolGlobalInt(
'PRODUIT_MULTIPRICES_LIMIT');
3586 for ($i = 1; $i <= $produit_multiprices_limit; $i++) {
3587 $sql =
"SELECT price, price_ttc, price_min, price_min_ttc,";
3588 $sql .=
" price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly";
3589 $sql .=
" FROM ".$this->db->prefix().
"product_price";
3590 $sql .=
" WHERE entity IN (".getEntity(
'productprice').
")";
3591 $sql .=
" AND price_level=".((int) $i);
3592 $sql .=
" AND fk_product = ".((int) $this->
id);
3593 $sql .=
" ORDER BY date_price DESC, rowid DESC";
3595 $resql = $this->db->query($sql);
3597 $this->error = $this->db->lasterror;
3600 $result = $this->db->fetch_array($resql);
3601 $this->multiprices[$i] = (!empty($result[
"price"]) ? $result[
"price"] : 0);
3602 $this->multiprices_ttc[$i] = (!empty($result[
"price_ttc"]) ? $result[
"price_ttc"] : 0);
3603 $this->multiprices_min[$i] = (!empty($result[
"price_min"]) ? $result[
"price_min"] : 0);
3604 $this->multiprices_min_ttc[$i] = (!empty($result[
"price_min_ttc"]) ? $result[
"price_min_ttc"] : 0);
3605 $this->multiprices_base_type[$i] = (!empty($result[
"price_base_type"]) ? $result[
"price_base_type"] :
'');
3607 $this->multiprices_tva_tx[$i] = (!empty($result[
"tva_tx"]) ? $result[
"tva_tx"] : 0);
3608 $this->multiprices_recuperableonly[$i] = (!empty($result[
"recuperableonly"]) ? $result[
"recuperableonly"] : 0);
3611 $this->prices_by_qty[$i] = (!empty($result[
"price_by_qty"]) ? $result[
"price_by_qty"] : 0);
3612 $this->prices_by_qty_id[$i] = (!empty($result[
"rowid"]) ? $result[
"rowid"] : 0);
3614 if ($this->prices_by_qty[$i] == 1) {
3615 $sql =
"SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type";
3616 $sql .=
" FROM ".$this->db->prefix().
"product_price_by_qty";
3617 $sql .=
" WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]);
3618 $sql .=
" ORDER BY quantity ASC";
3620 $resql = $this->db->query($sql);
3622 $resultat = array();
3624 while ($result = $this->db->fetch_array($resql)) {
3625 $resultat[$ii] = array();
3626 $resultat[$ii][
"rowid"] = $result[
"rowid"];
3627 $resultat[$ii][
"price"] = $result[
"price"];
3628 $resultat[$ii][
"unitprice"] = $result[
"unitprice"];
3629 $resultat[$ii][
"quantity"] = $result[
"quantity"];
3630 $resultat[$ii][
"remise_percent"] = $result[
"remise_percent"];
3631 $resultat[$ii][
"remise"] = $result[
"remise"];
3632 $resultat[$ii][
"price_base_type"] = $result[
"price_base_type"];
3635 $this->prices_by_qty_list[$i] = $resultat;
3637 $this->error = $this->db->lasterror;
3645 if (
isModEnabled(
'dynamicprices') && !empty($this->fk_price_expression) && empty($ignore_expression)) {
3646 include_once DOL_DOCUMENT_ROOT.
'/product/dynamic_price/class/price_parser.class.php';
3648 $price_result = $priceparser->parseProduct($this);
3649 if ($price_result >= 0) {
3650 $this->
price = $price_result;
3652 $this->price_ttc = (float)
price2num($this->
price) * (1 + ($this->tva_tx / 100));
3653 $this->price_ttc = (float)
price2num($this->price_ttc,
'MU');
3659 $this->stock_warehouse = array();
3666 $this->error = $this->db->lasterror();
3681 global $user, $hookmanager, $action;
3685 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
3686 $this->stats_mo[
'customers_'.$role] = 0;
3687 $this->stats_mo[
'nb_'.$role] = 0;
3688 $this->stats_mo[
'qty_'.$role] = 0;
3690 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
3691 $sql .=
" SUM(mp.qty) as qty";
3692 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
3693 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
3694 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
3695 $sql .=
" INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id);
3698 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
3700 $sql .=
" AND mp.fk_product = ".((int) $this->
id);
3701 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
3703 $sql .=
" AND c.fk_soc = ".((int) $socid);
3706 $result = $this->db->query($sql);
3708 $obj = $this->db->fetch_object($result);
3709 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
3710 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
3711 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
3713 $this->error = $this->db->error();
3718 if (!empty($error)) {
3722 $parameters = array(
'socid' => $socid);
3723 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
3725 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
3741 global $hookmanager, $action;
3745 $this->stats_bom[
'nb_toproduce'] = 0;
3746 $this->stats_bom[
'nb_toconsume'] = 0;
3747 $this->stats_bom[
'qty_toproduce'] = 0;
3748 $this->stats_bom[
'qty_toconsume'] = 0;
3750 $sql =
"SELECT COUNT(DISTINCT b.rowid) as nb_toproduce,";
3751 $sql .=
" SUM(b.qty) as qty_toproduce";
3752 $sql .=
" FROM ".$this->db->prefix().
"bom_bom as b";
3753 $sql .=
" INNER JOIN ".$this->db->prefix().
"bom_bomline as bl ON bl.fk_bom = b.rowid";
3755 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
3756 $sql .=
" AND b.fk_product =".((int) $this->
id);
3757 $sql .=
" GROUP BY b.rowid";
3759 $result = $this->db->query($sql);
3761 $obj = $this->db->fetch_object($result);
3762 $this->stats_bom[
'nb_toproduce'] = !empty($obj->nb_toproduce) ? $obj->nb_toproduce : 0;
3763 $this->stats_bom[
'qty_toproduce'] = !empty($obj->qty_toproduce) ?
price2num($obj->qty_toproduce) : 0;
3765 $this->error = $this->db->error();
3769 $sql =
"SELECT COUNT(DISTINCT bl.rowid) as nb_toconsume,";
3770 $sql .=
" SUM(bl.qty) as qty_toconsume";
3771 $sql .=
" FROM ".$this->db->prefix().
"bom_bom as b";
3772 $sql .=
" INNER JOIN ".$this->db->prefix().
"bom_bomline as bl ON bl.fk_bom=b.rowid";
3774 $sql .=
" b.entity IN (".getEntity(
'bom').
")";
3775 $sql .=
" AND bl.fk_product =".((int) $this->
id);
3777 $result = $this->db->query($sql);
3779 $obj = $this->db->fetch_object($result);
3780 $this->stats_bom[
'nb_toconsume'] = !empty($obj->nb_toconsume) ? $obj->nb_toconsume : 0;
3781 $this->stats_bom[
'qty_toconsume'] = !empty($obj->qty_toconsume) ?
price2num($obj->qty_toconsume) : 0;
3783 $this->error = $this->db->error();
3787 if (!empty($error)) {
3791 $parameters = array(
'socid' => $socid);
3792 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
3794 $this->stats_bom = $hookmanager->resArray[
'stats_bom'];
3810 global $user, $hookmanager, $action;
3812 $sql =
"SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,";
3813 $sql .=
" COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
3814 $sql .=
" FROM ".$this->db->prefix().
"propaldet as pd";
3815 $sql .=
", ".$this->db->prefix().
"propal as p";
3816 $sql .=
", ".$this->db->prefix().
"societe as s";
3817 $sql .=
" WHERE p.rowid = pd.fk_propal";
3818 $sql .=
" AND p.fk_soc = s.rowid";
3819 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
3820 $sql .=
" AND pd.fk_product = ".((int) $this->
id);
3821 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
3822 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
3826 $sql .=
" AND p.fk_soc = ".((int) $socid);
3829 $parameters = array(
'socid' => $socid,
'type_element' =>
'propal');
3830 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3831 $sql .= $hookmanager->resPrint;
3832 $result = $this->db->query($sql);
3834 $obj = $this->db->fetch_object($result);
3835 $this->stats_propale[
'customers'] = (int) $obj->nb_customers;
3836 $this->stats_propale[
'nb'] = (int) $obj->nb;
3837 $this->stats_propale[
'rows'] = (int) $obj->nb_rows;
3838 $this->stats_propale[
'qty'] = $obj->qty ? (float) $obj->qty : 0;
3843 if (is_array($TFather) && !empty($TFather)) {
3844 foreach ($TFather as &$fatherData) {
3845 $pFather =
new Product($this->db);
3846 $pFather->id = (int) $fatherData[
'id'];
3847 $qtyCoef = $fatherData[
'qty'];
3849 if ($fatherData[
'incdec']) {
3850 $pFather->load_stats_propale($socid);
3852 if (!empty($pFather->stats_propale)) {
3853 $this->stats_propale[
'customers'] += $pFather->stats_propale[
'customers'];
3854 $this->stats_propale[
'nb'] += $pFather->stats_propale[
'nb'];
3855 $this->stats_propale[
'rows'] += $pFather->stats_propale[
'rows'];
3856 $this->stats_propale[
'qty'] += $pFather->stats_propale[
'qty'] * $qtyCoef;
3863 $parameters = array(
'socid' => $socid);
3864 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerProposal', $parameters, $this, $action);
3866 $this->stats_propale = $hookmanager->resArray[
'stats_propale'];
3871 $this->error = $this->db->error();
3887 global $user, $hookmanager, $action;
3889 $sql =
"SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,";
3890 $sql .=
" COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty";
3891 $sql .=
" FROM ".$this->db->prefix().
"supplier_proposaldet as pd";
3892 $sql .=
", ".$this->db->prefix().
"supplier_proposal as p";
3893 $sql .=
", ".$this->db->prefix().
"societe as s";
3894 $sql .=
" WHERE p.rowid = pd.fk_supplier_proposal";
3895 $sql .=
" AND p.fk_soc = s.rowid";
3896 $sql .=
" AND p.entity IN (".getEntity(
'supplier_proposal').
")";
3897 $sql .=
" AND pd.fk_product = ".((int) $this->
id);
3898 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
3899 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
3903 $sql .=
" AND p.fk_soc = ".((int) $socid);
3906 $result = $this->db->query($sql);
3908 $obj = $this->db->fetch_object($result);
3909 $this->stats_proposal_supplier[
'suppliers'] = $obj->nb_suppliers;
3910 $this->stats_proposal_supplier[
'nb'] = $obj->nb;
3911 $this->stats_proposal_supplier[
'rows'] = $obj->nb_rows;
3912 $this->stats_proposal_supplier[
'qty'] = $obj->qty ? $obj->qty : 0;
3914 $parameters = array(
'socid' => $socid);
3915 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierProposal', $parameters, $this, $action);
3917 $this->stats_proposal_supplier = $hookmanager->resArray[
'stats_proposal_supplier'];
3922 $this->error = $this->db->error();
3940 global $user, $hookmanager, $action;
3943 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
3944 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
3945 $sql .=
" FROM ".$this->db->prefix().
"commandedet as cd";
3946 $sql .=
", ".$this->db->prefix().
"commande as c";
3947 $sql .=
", ".$this->db->prefix().
"societe as s";
3948 $sql .=
" WHERE c.rowid = cd.fk_commande";
3949 $sql .=
" AND c.fk_soc = s.rowid";
3950 $sql .=
" AND c.entity IN (".getEntity($forVirtualStock &&
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'commande').
")";
3951 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
3952 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir') && !$forVirtualStock) {
3953 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
3956 $sql .=
" AND c.fk_soc = ".((int) $socid);
3958 if ($filtrestatut !=
'') {
3959 $sql .=
" AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).
")";
3962 $parameters = array(
'socid' => $socid,
'type_element' =>
'order');
3963 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3964 $sql .= $hookmanager->resPrint;
3965 $result = $this->db->query($sql);
3967 $obj = $this->db->fetch_object($result);
3968 $this->stats_commande[
'customers'] = (int) $obj->nb_customers;
3969 $this->stats_commande[
'nb'] = (int) $obj->nb;
3970 $this->stats_commande[
'rows'] = (int) $obj->nb_rows;
3971 $this->stats_commande[
'qty'] = $obj->qty ? (float) $obj->qty : 0;
3976 if (is_array($TFather) && !empty($TFather)) {
3977 foreach ($TFather as &$fatherData) {
3978 $pFather =
new Product($this->db);
3979 $pFather->id = $fatherData[
'id'];
3980 $qtyCoef = $fatherData[
'qty'];
3982 if ($fatherData[
'incdec']) {
3983 $pFather->load_stats_commande($socid, $filtrestatut);
3985 $this->stats_commande[
'customers'] += $pFather->stats_commande[
'customers'];
3986 $this->stats_commande[
'nb'] += $pFather->stats_commande[
'nb'];
3987 $this->stats_commande[
'rows'] += $pFather->stats_commande[
'rows'];
3988 $this->stats_commande[
'qty'] += $pFather->stats_commande[
'qty'] * $qtyCoef;
4001 $sql =
"SELECT SUM(".$this->db->ifsql(
'f.type=2',
'-1',
'1').
" * fd.qty) as count FROM ".$this->db->prefix().
"facturedet as fd ";
4002 $sql .=
" JOIN ".$this->db->prefix().
"facture as f ON fd.fk_facture = f.rowid";
4004 $sql .=
" JOIN ".$this->db->prefix().
"element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande' ";
4005 $sql .=
" JOIN ".$this->db->prefix().
"commande as c ON el.fk_source = c.rowid";
4006 $sql .=
" WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).
") AND c.facture = 0 AND fd.fk_product = ".((int) $this->
id);
4007 $sql .=
" AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix().
"commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)";
4011 $sql .=
"SELECT SUM(".$this->db->ifsql(
'f.type=2',
'-1',
'1').
" * fd.qty) as count FROM ".$this->db->prefix().
"facturedet as fd ";
4012 $sql .=
" JOIN ".$this->db->prefix().
"facture as f ON fd.fk_facture = f.rowid";
4013 $sql .=
" JOIN ".$this->db->prefix().
"element_element as el ON el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture' ";
4014 $sql .=
" JOIN ".$this->db->prefix().
"commande as c ON el.fk_target = c.rowid";
4015 $sql .=
" WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).
") AND c.facture = 0 AND fd.fk_product = ".((int) $this->
id);
4016 $sql .=
" AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix().
"commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)";
4018 $parameters = array(
'socid' => $socid,
'type_element' =>
'order');
4019 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
4020 $sql .= $hookmanager->resPrint;
4021 $resql = $this->db->query($sql);
4023 while ($obj = $this->db->fetch_object($resql)) {
4024 $adeduire += (float) $obj->count;
4028 $this->stats_commande[
'qty'] -= $adeduire;
4031 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4035 $sql =
"SELECT sum(".$this->db->ifsql(
'f.type=2',
'-1',
'1').
" * fd.qty) as count FROM ".$this->db->prefix().
"facturedet as fd ";
4036 $sql .=
" JOIN ".$this->db->prefix().
"facture as f ON fd.fk_facture = f.rowid";
4038 $sql .=
" JOIN ".$this->db->prefix().
"element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture' AND sourcetype = 'commande' ";
4039 $sql .=
" JOIN ".$this->db->prefix().
"commande as c ON el.fk_source = c.rowid";
4040 $sql .=
" WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).
") AND f.fk_statut > ".
Facture::STATUS_DRAFT.
" AND fd.fk_product = ".((int) $this->
id);
4041 $sql .=
" AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix().
"commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)";
4043 $sql .=
" UNION ALL ";
4045 $sql .=
"SELECT sum(".$this->db->ifsql(
'f.type=2',
'-1',
'1').
" * fd.qty) as count FROM ".$this->db->prefix().
"facturedet as fd ";
4046 $sql .=
" JOIN ".$this->db->prefix().
"facture as f ON fd.fk_facture = f.rowid";
4047 $sql .=
" JOIN ".$this->db->prefix().
"element_element as el ON el.fk_source = f.rowid AND el.targettype = 'commande' AND sourcetype = 'facture' ";
4048 $sql .=
" JOIN ".$this->db->prefix().
"commande as c ON el.fk_target = c.rowid";
4049 $sql .=
" WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).
") AND f.fk_statut > ".
Facture::STATUS_DRAFT.
" AND fd.fk_product = ".((int) $this->
id);
4050 $sql .=
" AND EXISTS (SELECT cd.fk_product FROM ".$this->db->prefix().
"commandedet as cd WHERE cd.fk_product = fd.fk_product AND cd.fk_commande = c.rowid)";
4052 dol_syslog(__METHOD__.
":: sql $sql", LOG_NOTICE);
4054 $parameters = array(
'socid' => $socid,
'type_element' =>
'order');
4055 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
4056 $sql .= $hookmanager->resPrint;
4057 $resql = $this->db->query($sql);
4059 while ($obj = $this->db->fetch_object($resql)) {
4060 $adeduire += (float) $obj->count;
4063 $this->error = $this->db->error();
4067 $this->stats_commande[
'qty'] -= $adeduire;
4071 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
4072 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerOrder', $parameters, $this, $action);
4074 $this->stats_commande = $hookmanager->resArray[
'stats_commande'];
4078 $this->error = $this->db->error();
4097 global $user, $hookmanager, $action;
4099 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,";
4100 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
4101 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as cd";
4102 $sql .=
", ".$this->db->prefix().
"commande_fournisseur as c";
4103 $sql .=
", ".$this->db->prefix().
"societe as s";
4104 $sql .=
" WHERE c.rowid = cd.fk_commande";
4105 $sql .=
" AND c.fk_soc = s.rowid";
4106 $sql .=
" AND c.entity IN (".getEntity($forVirtualStock &&
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'supplier_order').
")";
4107 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
4108 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir') && !$forVirtualStock) {
4109 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4112 $sql .=
" AND c.fk_soc = ".((int) $socid);
4114 if ($filtrestatut !=
'') {
4115 $sql .=
" AND c.fk_statut in (".$this->db->sanitize($filtrestatut).
")";
4117 if (!empty($dateofvirtualstock)) {
4121 $sqlwindow =
"c.date_livraison <= '".$this->db->idate($dateofvirtualstock).
"'";
4122 if (!empty($dateofvirtualstockmin)) {
4123 $sqlwindow =
"c.date_livraison >= '".$this->db->idate($dateofvirtualstockmin).
"' AND ".$sqlwindow;
4125 if (
getDolGlobalInt(
'STOCK_VIRTUAL_HORIZON_INCLUDE_UNDATED_ORDERS')) {
4126 $sqlwindow .=
" OR c.date_livraison IS NULL";
4128 $sql .=
" AND (".$sqlwindow.
")";
4131 $result = $this->db->query($sql);
4133 $obj = $this->db->fetch_object($result);
4134 $this->stats_commande_fournisseur[
'suppliers'] = $obj->nb_suppliers;
4135 $this->stats_commande_fournisseur[
'nb'] = $obj->nb;
4136 $this->stats_commande_fournisseur[
'rows'] = $obj->nb_rows;
4137 $this->stats_commande_fournisseur[
'qty'] = $obj->qty ? $obj->qty : 0;
4139 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
4140 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierOrder', $parameters, $this, $action);
4142 $this->stats_commande_fournisseur = $hookmanager->resArray[
'stats_commande_fournisseur'];
4147 $this->error = $this->db->error().
' sql='.$sql;
4162 public function load_stats_sending($socid = 0, $filtrestatut =
'', $forVirtualStock = 0, $filterShipmentStatus =
'')
4165 global $user, $hookmanager, $action;
4167 $sql =
"SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,";
4168 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty";
4169 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet as ed";
4170 $sql .=
", ".$this->db->prefix().
"commandedet as cd";
4171 $sql .=
", ".$this->db->prefix().
"commande as c";
4172 $sql .=
", ".$this->db->prefix().
"expedition as e";
4173 $sql .=
", ".$this->db->prefix().
"societe as s";
4174 $sql .=
" WHERE e.rowid = ed.fk_expedition";
4175 $sql .=
" AND c.rowid = cd.fk_commande";
4176 $sql .=
" AND e.fk_soc = s.rowid";
4177 $sql .=
" AND e.entity IN (".getEntity($forVirtualStock &&
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'expedition').
")";
4178 $sql .=
" AND ed.fk_elementdet = cd.rowid";
4179 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
4180 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir') && !$forVirtualStock) {
4181 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4184 $sql .=
" AND e.fk_soc = ".((int) $socid);
4186 if ($filtrestatut !=
'') {
4187 $sql .=
" AND c.fk_statut IN (".$this->db->sanitize($filtrestatut).
")";
4189 if (!empty($filterShipmentStatus)) {
4190 $sql .=
" AND e.fk_statut IN (".$this->db->sanitize($filterShipmentStatus).
")";
4193 $result = $this->db->query($sql);
4195 $obj = $this->db->fetch_object($result);
4196 $this->stats_expedition[
'customers'] = (int) $obj->nb_customers;
4197 $this->stats_expedition[
'nb'] = (int) $obj->nb;
4198 $this->stats_expedition[
'rows'] = (int) $obj->nb_rows;
4199 $this->stats_expedition[
'qty'] = $obj->qty ? (float) $obj->qty : 0;
4204 if (is_array($TFather) && !empty($TFather)) {
4205 foreach ($TFather as &$fatherData) {
4206 $pFather =
new Product($this->db);
4207 $pFather->id = $fatherData[
'id'];
4208 $qtyCoef = $fatherData[
'qty'];
4210 if ($fatherData[
'incdec']) {
4211 $pFather->load_stats_sending($socid, $filtrestatut, $forVirtualStock);
4213 if (!empty($pFather->stats_expedition)) {
4214 $this->stats_expedition[
'customers'] += $pFather->stats_expedition[
'customers'];
4215 $this->stats_expedition[
'nb'] += $pFather->stats_expedition[
'nb'];
4216 $this->stats_expedition[
'rows'] += $pFather->stats_expedition[
'rows'];
4217 $this->stats_expedition[
'qty'] += $pFather->stats_expedition[
'qty'] * $qtyCoef;
4224 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock,
'filterShipmentStatus' => $filterShipmentStatus);
4225 $reshook = $hookmanager->executeHooks(
'loadStatsSending', $parameters, $this, $action);
4227 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
4232 $this->error = $this->db->error();
4248 public function load_stats_reception($socid = 0, $filtrestatut =
'', $forVirtualStock = 0, $dateofvirtualstock =
null, $dateofvirtualstockmin =
null)
4251 global $user, $hookmanager, $action;
4253 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,";
4254 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
4255 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as fd";
4256 $sql .=
", ".$this->db->prefix().
"commande_fournisseur as cf";
4257 $sql .=
", ".$this->db->prefix().
"societe as s";
4258 $sql .=
" WHERE cf.rowid = fd.fk_element";
4259 $sql .=
" AND cf.fk_soc = s.rowid";
4260 $sql .=
" AND cf.entity IN (".getEntity($forVirtualStock &&
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE') ?
'stock' :
'supplier_order').
")";
4261 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
4262 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir') && !$forVirtualStock) {
4263 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = cf.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4266 $sql .=
" AND cf.fk_soc = ".((int) $socid);
4268 if ($filtrestatut !=
'') {
4269 $sql .=
" AND cf.fk_statut IN (".$this->db->sanitize($filtrestatut).
")";
4271 if (!empty($dateofvirtualstock)) {
4272 $sql .=
" AND fd.datec <= '".$this->db->idate($dateofvirtualstock).
"'";
4274 if (!empty($dateofvirtualstockmin)) {
4278 $sqlwindow =
"cf.date_livraison >= '".$this->db->idate($dateofvirtualstockmin).
"' AND cf.date_livraison <= '".$this->db->idate($dateofvirtualstock).
"'";
4279 if (
getDolGlobalInt(
'STOCK_VIRTUAL_HORIZON_INCLUDE_UNDATED_ORDERS')) {
4280 $sqlwindow .=
" OR cf.date_livraison IS NULL";
4282 $sql .=
" AND (".$sqlwindow.
")";
4285 $result = $this->db->query($sql);
4287 $obj = $this->db->fetch_object($result);
4288 $this->stats_reception[
'suppliers'] = $obj->nb_suppliers;
4289 $this->stats_reception[
'nb'] = $obj->nb;
4290 $this->stats_reception[
'rows'] = $obj->nb_rows;
4291 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
4293 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
4294 $reshook = $hookmanager->executeHooks(
'loadStatsReception', $parameters, $this, $action);
4296 $this->stats_reception = $hookmanager->resArray[
'stats_reception'];
4301 $this->error = $this->db->error();
4318 public function load_stats_inproduction($socid = 0, $filtrestatut =
'', $forVirtualStock = 0, $dateofvirtualstock =
null, $warehouseid = 0, $dateofvirtualstockmin =
null)
4321 global $user, $hookmanager, $action;
4325 $sql =
"SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,";
4326 $sql .=
" COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role";
4327 $sql .=
" FROM ".$this->db->prefix().
"mrp_production as mp";
4328 $sql .=
", ".$this->db->prefix().
"mrp_mo as m";
4329 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON s.rowid = m.fk_soc";
4330 $sql .=
" WHERE m.rowid = mp.fk_mo";
4331 $sql .=
" AND m.entity IN (".getEntity(($forVirtualStock &&
getDolGlobalString(
'STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE')) ?
'stock' :
'mrp').
")";
4332 $sql .=
" AND mp.fk_product = ".((int) $this->
id);
4333 $sql .=
" AND (mp.disable_stock_change IN (0) OR mp.disable_stock_change IS NULL)";
4334 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir') && !$forVirtualStock) {
4335 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = m.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4338 $sql .=
" AND m.fk_soc = ".((int) $socid);
4340 if ($filtrestatut !=
'') {
4341 $sql .=
" AND m.status IN (".$this->db->sanitize($filtrestatut).
")";
4343 if (!empty($dateofvirtualstockmin)) {
4348 $sql .=
" AND COALESCE(m.date_end_planned, m.date_valid) >= '".$this->db->idate($dateofvirtualstockmin).
"'";
4349 $sql .=
" AND COALESCE(m.date_end_planned, m.date_valid) <= '".$this->db->idate($dateofvirtualstock).
"'";
4350 } elseif (!empty($dateofvirtualstock)) {
4351 $sql .=
" AND m.date_valid <= '".$this->db->idate($dateofvirtualstock).
"'";
4353 if (!$serviceStockIsEnabled) {
4354 $sql .=
"AND EXISTS (SELECT p.rowid FROM ".$this->db->prefix().
"product AS p WHERE p.rowid = ".((int) $this->
id).
" AND p.fk_product_type IN (0))";
4356 if (!empty($warehouseid)) {
4357 $sql .=
" AND m.fk_warehouse = ".((int) $warehouseid);
4359 $sql .=
" GROUP BY role";
4362 $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] = 0;
4364 $this->stats_mrptoconsume[
'customers'] = 0;
4365 $this->stats_mrptoconsume[
'nb'] = 0;
4366 $this->stats_mrptoconsume[
'rows'] = 0;
4367 $this->stats_mrptoconsume[
'qty'] = 0.0;
4368 $this->stats_mrptoproduce[
'customers'] = 0;
4369 $this->stats_mrptoproduce[
'nb'] = 0;
4370 $this->stats_mrptoproduce[
'rows'] = 0;
4371 $this->stats_mrptoproduce[
'qty'] = 0.0;
4374 $result = $this->db->query($sql);
4376 while ($obj = $this->db->fetch_object($result)) {
4377 if ($obj->role ==
'toconsume' && empty($warehouseid)) {
4378 $this->stats_mrptoconsume[
'customers'] += (int) $obj->nb_customers;
4379 $this->stats_mrptoconsume[
'nb'] += (int) $obj->nb;
4380 $this->stats_mrptoconsume[
'rows'] += (int) $obj->nb_rows;
4381 $this->stats_mrptoconsume[
'qty'] += ($obj->qty ? (float) $obj->qty : 0.0);
4383 if ($obj->role ==
'consumed' && empty($warehouseid)) {
4387 $this->stats_mrptoconsume[
'qty'] -= ($obj->qty ? (float) $obj->qty : 0.0);
4389 if ($obj->role ==
'toproduce') {
4391 $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] += ($obj->qty ? (float) $obj->qty : 0.0);
4393 $this->stats_mrptoproduce[
'customers'] += (int) $obj->nb_customers;
4394 $this->stats_mrptoproduce[
'nb'] += (int) $obj->nb;
4395 $this->stats_mrptoproduce[
'rows'] += (int) $obj->nb_rows;
4396 $this->stats_mrptoproduce[
'qty'] += ($obj->qty ? (float) $obj->qty : 0.0);
4399 if ($obj->role ==
'produced') {
4404 $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] -= ($obj->qty ? $obj->qty : 0);
4406 $this->stats_mrptoproduce[
'qty'] -= ($obj->qty ? $obj->qty : 0);
4413 if ($this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] < 0) {
4414 $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] = 0;
4417 if ($this->stats_mrptoconsume[
'qty'] < 0) {
4418 $this->stats_mrptoconsume[
'qty'] = 0;
4420 if ($this->stats_mrptoproduce[
'qty'] < 0) {
4421 $this->stats_mrptoproduce[
'qty'] = 0;
4425 $parameters = array(
'socid' => $socid,
'filtrestatut' => $filtrestatut,
'forVirtualStock' => $forVirtualStock);
4426 $reshook = $hookmanager->executeHooks(
'loadStatsInProduction', $parameters, $this, $action);
4428 $this->stats_mrptoproduce = $hookmanager->resArray[
'stats_mrptoproduce'];
4433 $this->error = $this->db->error();
4448 global $user, $hookmanager, $action;
4450 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
4451 $sql .=
" COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
4452 $sql .=
" FROM ".$this->db->prefix().
"contratdet as cd";
4453 $sql .=
", ".$this->db->prefix().
"contrat as c";
4454 $sql .=
", ".$this->db->prefix().
"societe as s";
4455 $sql .=
" WHERE c.rowid = cd.fk_contrat";
4456 $sql .=
" AND c.fk_soc = s.rowid";
4457 $sql .=
" AND c.entity IN (".getEntity(
'contract').
")";
4458 $sql .=
" AND cd.fk_product = ".((int) $this->
id);
4459 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
4460 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4464 $sql .=
" AND c.fk_soc = ".((int) $socid);
4467 $result = $this->db->query($sql);
4469 $obj = $this->db->fetch_object($result);
4470 $this->stats_contrat[
'customers'] = (int) $obj->nb_customers;
4471 $this->stats_contrat[
'nb'] = (int) $obj->nb;
4472 $this->stats_contrat[
'rows'] = (int) $obj->nb_rows;
4473 $this->stats_contrat[
'qty'] = $obj->qty ? (float) $obj->qty : 0;
4478 if (is_array($TFather) && !empty($TFather)) {
4479 foreach ($TFather as &$fatherData) {
4480 $pFather =
new Product($this->db);
4481 $pFather->id = $fatherData[
'id'];
4482 $qtyCoef = $fatherData[
'qty'];
4484 if ($fatherData[
'incdec']) {
4485 $pFather->load_stats_contrat($socid);
4487 if (!empty($pFather->stats_contrat)) {
4488 $this->stats_contrat[
'customers'] += $pFather->stats_contrat[
'customers'];
4489 $this->stats_contrat[
'nb'] += $pFather->stats_contrat[
'nb'];
4490 $this->stats_contrat[
'rows'] += $pFather->stats_contrat[
'rows'];
4491 $this->stats_contrat[
'qty'] += $pFather->stats_contrat[
'qty'] * $qtyCoef;
4498 $parameters = array(
'socid' => $socid);
4499 $reshook = $hookmanager->executeHooks(
'loadStatsContract', $parameters, $this, $action);
4501 $this->stats_contrat = $hookmanager->resArray[
'stats_contrat'];
4506 $this->error = $this->db->error().
' sql='.$sql;
4521 global $user, $hookmanager, $action;
4523 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,";
4524 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(".$this->db->ifsql(
'f.type != 2',
'fd.qty',
'fd.qty * -1').
") as qty";
4525 $sql .=
" FROM ".$this->db->prefix().
"facturedet as fd";
4526 $sql .=
", ".$this->db->prefix().
"facture as f";
4527 $sql .=
", ".$this->db->prefix().
"societe as s";
4528 $sql .=
" WHERE f.rowid = fd.fk_facture";
4529 $sql .=
" AND f.fk_soc = s.rowid";
4530 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
4531 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
4532 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
4533 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4537 $sql .=
" AND f.fk_soc = ".((int) $socid);
4540 $result = $this->db->query($sql);
4542 $obj = $this->db->fetch_object($result);
4543 $this->stats_facture[
'customers'] = (int) $obj->nb_customers;
4544 $this->stats_facture[
'nb'] = (int) $obj->nb;
4545 $this->stats_facture[
'rows'] = (int) $obj->nb_rows;
4546 $this->stats_facture[
'qty'] = $obj->qty ? (float) $obj->qty : 0;
4551 if (is_array($TFather) && !empty($TFather)) {
4552 foreach ($TFather as &$fatherData) {
4553 $pFather =
new Product($this->db);
4554 $pFather->id = $fatherData[
'id'];
4555 $qtyCoef = $fatherData[
'qty'];
4557 if ($fatherData[
'incdec']) {
4558 $pFather->load_stats_facture($socid);
4560 if (!empty($pFather->stats_facture)) {
4561 $this->stats_facture[
'customers'] += $pFather->stats_facture[
'customers'];
4562 $this->stats_facture[
'nb'] += $pFather->stats_facture[
'nb'];
4563 $this->stats_facture[
'rows'] += $pFather->stats_facture[
'rows'];
4564 $this->stats_facture[
'qty'] += $pFather->stats_facture[
'qty'] * $qtyCoef;
4571 $parameters = array(
'socid' => $socid);
4572 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerInvoice', $parameters, $this, $action);
4574 $this->stats_facture = $hookmanager->resArray[
'stats_facture'];
4579 $this->error = $this->db->error();
4595 global $user, $hookmanager, $action;
4597 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,";
4598 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
4599 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet_rec as fd";
4600 $sql .=
", ".MAIN_DB_PREFIX.
"facture_rec as f";
4601 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
4602 $sql .=
" WHERE f.rowid = fd.fk_facture";
4603 $sql .=
" AND f.fk_soc = s.rowid";
4604 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
4605 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
4606 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
4607 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4611 $sql .=
" AND f.fk_soc = ".((int) $socid);
4614 $result = $this->db->query($sql);
4616 $obj = $this->db->fetch_object($result);
4617 $this->stats_facturerec[
'customers'] = (int) $obj->nb_customers;
4618 $this->stats_facturerec[
'nb'] = (int) $obj->nb;
4619 $this->stats_facturerec[
'rows'] = (int) $obj->nb_rows;
4620 $this->stats_facturerec[
'qty'] = $obj->qty ? (float) $obj->qty : 0.0;
4625 if (is_array($TFather) && !empty($TFather)) {
4626 foreach ($TFather as &$fatherData) {
4627 $pFather =
new Product($this->db);
4628 $pFather->id = $fatherData[
'id'];
4629 $qtyCoef = $fatherData[
'qty'];
4631 if ($fatherData[
'incdec']) {
4632 $pFather->load_stats_facture($socid);
4634 $this->stats_facturerec[
'customers'] += $pFather->stats_facturerec[
'customers'];
4635 $this->stats_facturerec[
'nb'] += $pFather->stats_facturerec[
'nb'];
4636 $this->stats_facturerec[
'rows'] += $pFather->stats_facturerec[
'rows'];
4637 $this->stats_facturerec[
'qty'] += $pFather->stats_facturerec[
'qty'] * $qtyCoef;
4643 $parameters = array(
'socid' => $socid);
4644 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerInvoiceRec', $parameters, $this, $action);
4646 $this->stats_facturerec = $hookmanager->resArray[
'stats_facturerec'];
4651 $this->error = $this->db->error();
4666 global $user, $hookmanager, $action;
4668 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,";
4669 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
4670 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn_det as fd";
4671 $sql .=
", ".$this->db->prefix().
"facture_fourn as f";
4672 $sql .=
", ".$this->db->prefix().
"societe as s";
4673 $sql .=
" WHERE f.rowid = fd.fk_facture_fourn";
4674 $sql .=
" AND f.fk_soc = s.rowid";
4675 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
4676 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
4677 if (empty($user->fk_soc) && !$user->hasRight(
'societe',
'client',
'voir')) {
4678 $sql .=
" AND EXISTS (SELECT 1 FROM ".$this->db->prefix().
"societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $user->id).
")";
4682 $sql .=
" AND f.fk_soc = ".((int) $socid);
4685 $result = $this->db->query($sql);
4687 $obj = $this->db->fetch_object($result);
4688 $this->stats_facture_fournisseur[
'suppliers'] = (int) $obj->nb_suppliers;
4689 $this->stats_facture_fournisseur[
'nb'] = (int) $obj->nb;
4690 $this->stats_facture_fournisseur[
'rows'] = (int) $obj->nb_rows;
4691 $this->stats_facture_fournisseur[
'qty'] = $obj->qty ? (float) $obj->qty : 0.0;
4693 $parameters = array(
'socid' => $socid);
4694 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierInvoice', $parameters, $this, $action);
4696 $this->stats_facture_fournisseur = $hookmanager->resArray[
'stats_facture_fournisseur'];
4701 $this->error = $this->db->error();
4716 global $user, $hookmanager, $action;
4718 $sql =
"SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,";
4719 $sql .=
" COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty";
4720 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn_det_rec as fd";
4721 $sql .=
", ".MAIN_DB_PREFIX.
"facture_fourn_rec as f";
4722 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
4723 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4724 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
4726 $sql .=
" WHERE f.rowid = fd.fk_facture";
4727 $sql .=
" AND f.fk_soc = s.rowid";
4728 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
4729 $sql .=
" AND fd.fk_product = ".((int) $this->
id);
4730 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4731 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4735 $sql .=
" AND f.fk_soc = ".((int) $socid);
4738 $result = $this->db->query($sql);
4740 $obj = $this->db->fetch_object($result);
4741 $this->stats_facturefournrec[
'suppliers'] = (int) $obj->nb_suppliers;
4742 $this->stats_facturefournrec[
'nb'] = (int) $obj->nb;
4743 $this->stats_facturefournrec[
'rows'] = (int) $obj->nb_rows;
4744 $this->stats_facturefournrec[
'qty'] = $obj->qty ? (float) $obj->qty : 0.0;
4746 $parameters = array(
'socid' => $socid);
4747 $reshook = $hookmanager->executeHooks(
'loadStatsSupplierInvoiceRec', $parameters, $this, $action);
4749 $this->stats_facturefournrec = $hookmanager->resArray[
'stats_facturefournrec'];
4754 $this->error = $this->db->error();
4773 $resql = $this->db->query($sql);
4775 $num = $this->db->num_rows($resql);
4778 $arr = $this->db->fetch_array($resql);
4779 if (is_array($arr)) {
4780 $keyfortab = (string) $arr[1];
4782 $keyfortab = substr($keyfortab, -2);
4785 if ($mode ==
'byunit') {
4786 $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[0];
4787 } elseif ($mode ==
'bynumber') {
4788 $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[2];
4789 } elseif ($mode ==
'byamount') {
4790 $tab[$keyfortab] = (empty($tab[$keyfortab]) ? 0 : $tab[$keyfortab]) + $arr[2];
4799 $this->error = $this->db->error().
' sql='.$sql;
4806 } elseif ($year == -1) {
4815 for ($j = 0; $j < 12; $j++) {
4817 $idx = ucfirst(
dol_trunc(
dol_print_date(
dol_mktime(12, 0, 0, $month, 1, 1970),
"%b"), 1,
'right',
'UTF-8', 1));
4820 $result[$j] = array($idx, isset($tab[$year.$month]) ? $tab[$year.$month] : 0);
4823 $month =
"0".($month - 1);
4825 $month = substr($month, 1);
4835 return array_reverse($result);
4850 public function get_nb_vente($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4855 $sql =
"SELECT sum(d.qty) as qty, date_format(f.datef, '%Y%m')";
4856 if ($mode ==
'bynumber') {
4857 $sql .=
", count(DISTINCT f.rowid)";
4859 $sql .=
", sum(d.total_ht) as total_ht";
4860 $sql .=
" FROM ".$this->db->prefix().
"facturedet as d, ".$this->db->prefix().
"facture as f, ".$this->db->prefix().
"societe as s";
4861 if ($filteronproducttype >= 0) {
4862 $sql .=
", ".$this->db->prefix().
"product as p";
4864 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4865 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4867 $sql .=
" WHERE f.rowid = d.fk_facture";
4868 if ($this->
id > 0) {
4869 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4871 $sql .=
" AND d.fk_product > 0";
4873 if ($filteronproducttype >= 0) {
4874 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4876 $sql .=
" AND f.fk_soc = s.rowid";
4877 $sql .=
" AND f.entity IN (".getEntity(
'invoice').
")";
4878 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4879 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4882 $sql .=
" AND f.fk_soc = ".((int) $socid);
4884 $sql .= $morefilter;
4885 $sql .=
" GROUP BY date_format(f.datef,'%Y%m')";
4886 $sql .=
" ORDER BY date_format(f.datef,'%Y%m') DESC";
4888 return $this->
_get_stats($sql, $mode, $year);
4903 public function get_nb_achat($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4908 $sql =
"SELECT sum(d.qty) as qty, date_format(f.datef, '%Y%m')";
4909 if ($mode ==
'bynumber') {
4910 $sql .=
", count(DISTINCT f.rowid)";
4912 $sql .=
", sum(d.total_ht) as total_ht";
4913 $sql .=
" FROM ".$this->db->prefix().
"facture_fourn_det as d, ".$this->db->prefix().
"facture_fourn as f, ".$this->db->prefix().
"societe as s";
4914 if ($filteronproducttype >= 0) {
4915 $sql .=
", ".$this->db->prefix().
"product as p";
4917 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4918 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4920 $sql .=
" WHERE f.rowid = d.fk_facture_fourn";
4921 if ($this->
id > 0) {
4922 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4924 $sql .=
" AND d.fk_product > 0";
4926 if ($filteronproducttype >= 0) {
4927 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
4929 $sql .=
" AND f.fk_soc = s.rowid";
4930 $sql .=
" AND f.entity IN (".getEntity(
'facture_fourn').
")";
4931 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4932 $sql .=
" AND f.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4935 $sql .=
" AND f.fk_soc = ".((int) $socid);
4937 $sql .= $morefilter;
4938 $sql .=
" GROUP BY date_format(f.datef,'%Y%m')";
4939 $sql .=
" ORDER BY date_format(f.datef,'%Y%m') DESC";
4941 return $this->
_get_stats($sql, $mode, $year);
4955 public function get_nb_propal($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
4958 global $user, $hookmanager;
4960 $sql =
"SELECT sum(d.qty) as qty, date_format(p.datep, '%Y%m')";
4961 if ($mode ==
'bynumber') {
4962 $sql .=
", count(DISTINCT p.rowid)";
4964 $sql .=
", sum(d.total_ht) as total_ht";
4965 $sql .=
" FROM ".$this->db->prefix().
"propaldet as d, ".$this->db->prefix().
"propal as p, ".$this->db->prefix().
"societe as s";
4966 if ($filteronproducttype >= 0) {
4967 $sql .=
", ".$this->db->prefix().
"product as prod";
4969 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4970 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
4972 $sql .=
" WHERE p.rowid = d.fk_propal";
4973 if ($this->
id > 0) {
4974 $sql .=
" AND d.fk_product = ".((int) $this->
id);
4976 $sql .=
" AND d.fk_product > 0";
4978 if ($filteronproducttype >= 0) {
4979 $sql .=
" AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype);
4981 $sql .=
" AND p.fk_soc = s.rowid";
4982 $sql .=
" AND p.entity IN (".getEntity(
'propal').
")";
4983 if (!$user->hasRight(
'societe',
'client',
'voir')) {
4984 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
4987 $sql .=
" AND p.fk_soc = ".((int) $socid);
4989 $sql .= $morefilter;
4990 $parameters = array(
'socid' => $user->socid);
4991 $hookmanager->executeHooks(
'productGetNbPropal', $parameters, $this);
4992 $sql .= $hookmanager->resPrint;
4993 $sql .=
" GROUP BY date_format(p.datep,'%Y%m')";
4994 $sql .=
" ORDER BY date_format(p.datep,'%Y%m') DESC";
4995 return $this->
_get_stats($sql, $mode, $year);
5014 $sql =
"SELECT sum(d.qty) as qty, date_format(p.date_valid, '%Y%m')";
5015 if ($mode ==
'bynumber') {
5016 $sql .=
", count(DISTINCT p.rowid)";
5018 $sql .=
", sum(d.total_ht) as total_ht";
5019 $sql .=
" FROM ".$this->db->prefix().
"supplier_proposaldet as d, ".$this->db->prefix().
"supplier_proposal as p, ".$this->db->prefix().
"societe as s";
5020 if ($filteronproducttype >= 0) {
5021 $sql .=
", ".$this->db->prefix().
"product as prod";
5023 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5024 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
5026 $sql .=
" WHERE p.rowid = d.fk_supplier_proposal";
5027 if ($this->
id > 0) {
5028 $sql .=
" AND d.fk_product = ".((int) $this->
id);
5030 $sql .=
" AND d.fk_product > 0";
5032 if ($filteronproducttype >= 0) {
5033 $sql .=
" AND prod.rowid = d.fk_product AND prod.fk_product_type = ".((int) $filteronproducttype);
5035 $sql .=
" AND p.fk_soc = s.rowid";
5036 $sql .=
" AND p.entity IN (".getEntity(
'supplier_proposal').
")";
5037 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5038 $sql .=
" AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
5041 $sql .=
" AND p.fk_soc = ".((int) $socid);
5043 $sql .= $morefilter;
5044 $sql .=
" GROUP BY date_format(p.date_valid,'%Y%m')";
5045 $sql .=
" ORDER BY date_format(p.date_valid,'%Y%m') DESC";
5047 return $this->
_get_stats($sql, $mode, $year);
5061 public function get_nb_order($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
5064 global $user, $hookmanager;
5066 $sql =
"SELECT sum(d.qty) as qty, date_format(c.date_commande, '%Y%m')";
5067 if ($mode ==
'bynumber') {
5068 $sql .=
", count(DISTINCT c.rowid)";
5070 $sql .=
", sum(d.total_ht) as total_ht";
5071 $sql .=
" FROM ".$this->db->prefix().
"commandedet as d, ".$this->db->prefix().
"commande as c, ".$this->db->prefix().
"societe as s";
5072 if ($filteronproducttype >= 0) {
5073 $sql .=
", ".$this->db->prefix().
"product as p";
5075 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5076 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
5078 $sql .=
" WHERE c.rowid = d.fk_commande";
5079 if ($this->
id > 0) {
5080 $sql .=
" AND d.fk_product = ".((int) $this->
id);
5082 $sql .=
" AND d.fk_product > 0";
5084 if ($filteronproducttype >= 0) {
5085 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
5087 $sql .=
" AND c.fk_soc = s.rowid";
5088 $sql .=
" AND c.entity IN (".getEntity(
'commande').
")";
5089 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5090 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
5093 $sql .=
" AND c.fk_soc = ".((int) $socid);
5095 $sql .= $morefilter;
5096 $parameters = array(
'socid' => $user->socid);
5097 $hookmanager->executeHooks(
'productGetNbOrder', $parameters, $this);
5098 $sql .= $hookmanager->resPrint;
5099 $sql .=
" GROUP BY date_format(c.date_commande,'%Y%m')";
5100 $sql .=
" ORDER BY date_format(c.date_commande,'%Y%m') DESC";
5102 return $this->
_get_stats($sql, $mode, $year);
5121 $sql =
"SELECT sum(d.qty) as qty, date_format(c.date_commande, '%Y%m')";
5122 if ($mode ==
'bynumber') {
5123 $sql .=
", count(DISTINCT c.rowid)";
5125 $sql .=
", sum(d.total_ht) as total_ht";
5126 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as d, ".$this->db->prefix().
"commande_fournisseur as c, ".$this->db->prefix().
"societe as s";
5127 if ($filteronproducttype >= 0) {
5128 $sql .=
", ".$this->db->prefix().
"product as p";
5130 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5131 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
5133 $sql .=
" WHERE c.rowid = d.fk_commande";
5134 if ($this->
id > 0) {
5135 $sql .=
" AND d.fk_product = ".((int) $this->
id);
5137 $sql .=
" AND d.fk_product > 0";
5139 if ($filteronproducttype >= 0) {
5140 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
5142 $sql .=
" AND c.fk_soc = s.rowid";
5143 $sql .=
" AND c.entity IN (".getEntity(
'supplier_order').
")";
5144 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5145 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
5148 $sql .=
" AND c.fk_soc = ".((int) $socid);
5150 $sql .= $morefilter;
5151 $sql .=
" GROUP BY date_format(c.date_commande,'%Y%m')";
5152 $sql .=
" ORDER BY date_format(c.date_commande,'%Y%m') DESC";
5154 return $this->
_get_stats($sql, $mode, $year);
5168 public function get_nb_contract($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
5173 $sql =
"SELECT sum(d.qty) as qty, date_format(c.date_contrat, '%Y%m')";
5174 if ($mode ==
'bynumber') {
5175 $sql .=
", count(DISTINCT c.rowid)";
5177 $sql .=
", sum(d.total_ht) as total_ht";
5178 $sql .=
" FROM ".$this->db->prefix().
"contratdet as d, ".$this->db->prefix().
"contrat as c, ".$this->db->prefix().
"societe as s";
5179 if ($filteronproducttype >= 0) {
5180 $sql .=
", ".$this->db->prefix().
"product as p";
5182 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5183 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
5185 $sql .=
" WHERE c.entity IN (".getEntity(
'contract').
")";
5186 $sql .=
" AND c.rowid = d.fk_contrat";
5188 if ($this->
id > 0) {
5189 $sql .=
" AND d.fk_product = ".((int) $this->
id);
5191 $sql .=
" AND d.fk_product > 0";
5193 if ($filteronproducttype >= 0) {
5194 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
5196 $sql .=
" AND c.fk_soc = s.rowid";
5198 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5199 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
5202 $sql .=
" AND c.fk_soc = ".((int) $socid);
5204 $sql .= $morefilter;
5205 $sql .=
" GROUP BY date_format(c.date_contrat,'%Y%m')";
5206 $sql .=
" ORDER BY date_format(c.date_contrat,'%Y%m') DESC";
5208 return $this->
_get_stats($sql, $mode, $year);
5222 public function get_nb_mos($socid, $mode, $filteronproducttype = -1, $year = 0, $morefilter =
'')
5227 $sql =
"SELECT sum(d.qty), date_format(d.date_valid, '%Y%m')";
5228 if ($mode ==
'bynumber') {
5229 $sql .=
", count(DISTINCT d.rowid)";
5231 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as d LEFT JOIN ".$this->db->prefix().
"societe as s ON d.fk_soc = s.rowid";
5232 if ($filteronproducttype >= 0) {
5233 $sql .=
", ".$this->db->prefix().
"product as p";
5235 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5236 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
5239 $sql .=
" WHERE d.entity IN (".getEntity(
'mo').
")";
5240 $sql .=
" AND d.status > 0";
5242 if ($this->
id > 0) {
5243 $sql .=
" AND d.fk_product = ".((int) $this->
id);
5245 $sql .=
" AND d.fk_product > 0";
5247 if ($filteronproducttype >= 0) {
5248 $sql .=
" AND p.rowid = d.fk_product AND p.fk_product_type = ".((int) $filteronproducttype);
5251 if (!$user->hasRight(
'societe',
'client',
'voir')) {
5252 $sql .=
" AND d.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
5255 $sql .=
" AND d.fk_soc = ".((int) $socid);
5257 $sql .= $morefilter;
5258 $sql .=
" GROUP BY date_format(d.date_valid,'%Y%m')";
5259 $sql .=
" ORDER BY date_format(d.date_valid,'%Y%m') DESC";
5261 return $this->
_get_stats($sql, $mode, $year);
5281 if (!is_numeric($id_pere)) {
5284 if (!is_numeric($id_fils)) {
5287 if (!is_numeric($incdec)) {
5297 $sql =
"SELECT fk_product_pere from ".$this->db->prefix().
"product_association";
5298 $sql .=
" WHERE fk_product_pere = ".((int) $id_fils).
" AND fk_product_fils = ".((int) $id_pere);
5299 if (!$this->db->query($sql)) {
5300 dol_print_error($this->db);
5304 $sql =
"SELECT MAX(rang) as max_rank FROM ".$this->db->prefix().
"product_association";
5305 $sql .=
" WHERE fk_product_pere = ".((int) $id_pere);
5306 $resql = $this->db->query($sql);
5308 $obj = $this->db->fetch_object($resql);
5309 $rank = $obj->max_rank + 1;
5311 $sql =
"INSERT INTO ".$this->db->prefix().
"product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)";
5312 $sql .=
" VALUES (".((int) $id_pere).
", ".((int) $id_fils).
", ".
price2num($qty,
'MS').
", ".((int) $incdec).
", ".((int) $rank).
")";
5313 if (! $this->db->query($sql)) {
5314 dol_print_error($this->db);
5319 $result = $this->call_trigger(
'PRODUCT_SUBPRODUCT_ADD', $user);
5321 $this->error = $this->db->lasterror();
5322 dol_syslog(get_class($this).
'::addSubproduct error='.$this->error, LOG_ERR);
5331 dol_print_error($this->db);
5354 if (!is_numeric($id_pere)) {
5357 if (!is_numeric($id_fils)) {
5360 if (!is_numeric($incdec)) {
5363 if (!is_numeric($qty)) {
5367 $sql =
'UPDATE '.$this->db->prefix().
'product_association SET ';
5368 $sql .=
'qty = '.price2num($qty,
'MS');
5369 $sql .=
',incdec = '.((int) $incdec);
5370 $sql .=
' WHERE fk_product_pere = '.((int) $id_pere).
' AND fk_product_fils = '.((int) $id_fils);
5372 if (!$this->db->query($sql)) {
5373 dol_print_error($this->db);
5378 $result = $this->call_trigger(
'PRODUCT_SUBPRODUCT_UPDATE', $user);
5380 $this->error = $this->db->lasterror();
5381 dol_syslog(get_class($this).
'::updateSubproduct error='.$this->error, LOG_ERR);
5405 if (!is_numeric($fk_parent)) {
5408 if (!is_numeric($fk_child)) {
5412 $sql =
"DELETE FROM ".$this->db->prefix().
"product_association";
5413 $sql .=
" WHERE fk_product_pere = ".((int) $fk_parent);
5414 $sql .=
" AND fk_product_fils = ".((int) $fk_child);
5416 dol_syslog(get_class($this).
'::del_sousproduit', LOG_DEBUG);
5417 if (!$this->db->query($sql)) {
5418 dol_print_error($this->db);
5423 $sqlrank =
"SELECT rowid, rang FROM ".$this->db->prefix().
"product_association";
5424 $sqlrank .=
" WHERE fk_product_pere = ".((int) $fk_parent);
5425 $sqlrank .=
" ORDER BY rang";
5426 $resqlrank = $this->db->query($sqlrank);
5429 while ($objrank = $this->db->fetch_object($resqlrank)) {
5431 $sql =
"UPDATE ".$this->db->prefix().
"product_association";
5432 $sql .=
" SET rang = ".((int) $cpt);
5433 $sql .=
" WHERE rowid = ".((int) $objrank->rowid);
5434 if (! $this->db->query($sql)) {
5435 dol_print_error($this->db);
5443 $result = $this->call_trigger(
'PRODUCT_SUBPRODUCT_DELETE', $user);
5445 $this->error = $this->db->lasterror();
5446 dol_syslog(get_class($this).
'::delSubproduct error='.$this->error, LOG_ERR);
5466 $sql =
"SELECT fk_product_pere, qty, incdec";
5467 $sql .=
" FROM ".$this->db->prefix().
"product_association";
5468 $sql .=
" WHERE fk_product_pere = ".((int) $fk_parent);
5469 $sql .=
" AND fk_product_fils = ".((int) $fk_child);
5471 $result = $this->db->query($sql);
5473 $num = $this->db->num_rows($result);
5476 $obj = $this->db->fetch_object($result);
5478 $this->is_sousproduit_qty = $obj->qty;
5479 $this->is_sousproduit_incdec = $obj->incdec;
5486 dol_print_error($this->db);
5510 dol_syslog(get_class($this).
"::add_fournisseur id_fourn = ".$id_fourn.
" ref_fourn=".$ref_fourn.
" quantity=".$quantity, LOG_DEBUG);
5517 $sql =
"SELECT rowid, fk_product";
5518 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
5519 $sql .=
" WHERE fk_soc = ".((int) $id_fourn);
5520 $sql .=
" AND ref_fourn = '".$this->db->escape($ref_fourn).
"'";
5521 $sql .=
" AND fk_product <> ".((int) $this->
id);
5522 $sql .=
" AND entity IN (".getEntity(
'productsupplierprice').
")";
5524 $resql = $this->db->query($sql);
5526 $obj = $this->db->fetch_object($resql);
5529 $this->product_id_already_linked = $obj->fk_product;
5532 $this->db->free($resql);
5536 $sql =
"SELECT rowid";
5537 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
5538 $sql .=
" WHERE fk_soc = ".((int) $id_fourn);
5540 $sql .=
" AND ref_fourn = '".$this->db->escape($ref_fourn).
"'";
5542 $sql .=
" AND (ref_fourn = '' OR ref_fourn IS NULL)";
5544 $sql .=
" AND quantity = ".((float) $quantity);
5545 $sql .=
" AND fk_product = ".((int) $this->
id);
5546 $sql .=
" AND entity IN (".getEntity(
'productsupplierprice').
")";
5548 $resql = $this->db->query($sql);
5550 $obj = $this->db->fetch_object($resql);
5554 $sql =
"INSERT INTO ".$this->db->prefix().
"product_fournisseur_price(";
5557 $sql .=
", fk_product";
5559 $sql .=
", ref_fourn";
5560 $sql .=
", quantity";
5561 $sql .=
", fk_user";
5563 $sql .=
") VALUES (";
5564 $sql .=
"'".$this->db->idate($now).
"'";
5565 $sql .=
", ".((int)
$conf->entity);
5566 $sql .=
", ".((int) $this->
id);
5567 $sql .=
", ".((int) $id_fourn);
5568 $sql .=
", '".$this->db->escape($ref_fourn).
"'";
5569 $sql .=
", ".((float) $quantity);
5570 $sql .=
", ".((int) $user->id);
5574 if ($this->db->query($sql)) {
5575 $this->product_fourn_price_id = $this->db->last_insert_id($this->db->prefix().
"product_fournisseur_price");
5578 $this->error = $this->db->lasterror();
5583 $this->product_fourn_price_id = $obj->rowid;
5587 $this->error = $this->db->lasterror();
5606 $sql =
"SELECT DISTINCT p.fk_soc";
5607 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price as p";
5608 $sql .=
" WHERE p.fk_product = ".((int) $this->
id);
5609 $sql .=
" AND p.entity = ".((int)
$conf->entity);
5611 $result = $this->db->query($sql);
5613 $num = $this->db->num_rows($result);
5616 $obj = $this->db->fetch_object($result);
5617 $list[$i] = $obj->fk_soc;
5643 $sql =
"INSERT INTO ".$this->db->prefix().
"product_price (";
5645 $sql .=
", fk_product";
5646 $sql .=
", date_price";
5647 $sql .=
", price_level";
5649 $sql .=
", price_ttc";
5650 $sql .=
", price_min";
5651 $sql .=
", price_min_ttc";
5652 $sql .=
", price_base_type";
5653 $sql .=
", price_label";
5654 $sql .=
", default_vat_code";
5656 $sql .=
", recuperableonly";
5657 $sql .=
", localtax1_tx";
5658 $sql .=
", localtax1_type";
5659 $sql .=
", localtax2_tx";
5660 $sql .=
", localtax2_type";
5661 $sql .=
", fk_user_author";
5663 $sql .=
", price_by_qty";
5664 $sql .=
", fk_price_expression";
5665 $sql .=
", fk_multicurrency";
5666 $sql .=
", multicurrency_code";
5667 $sql .=
", multicurrency_tx";
5668 $sql .=
", multicurrency_price";
5669 $sql .=
", multicurrency_price_ttc";
5673 $sql .=
", ".((int) $toId);
5674 $sql .=
", '".$this->db->idate($now).
"'";
5675 $sql .=
", price_level";
5677 $sql .=
", price_ttc";
5678 $sql .=
", price_min";
5679 $sql .=
", price_min_ttc";
5680 $sql .=
", price_base_type";
5681 $sql .=
", price_label";
5682 $sql .=
", default_vat_code";
5684 $sql .=
", recuperableonly";
5685 $sql .=
", localtax1_tx";
5686 $sql .=
", localtax1_type";
5687 $sql .=
", localtax2_tx";
5688 $sql .=
", localtax2_type";
5689 $sql .=
", ".((int) $user->id);
5691 $sql .=
", price_by_qty";
5692 $sql .=
", fk_price_expression";
5693 $sql .=
", fk_multicurrency";
5694 $sql .=
", multicurrency_code";
5695 $sql .=
", multicurrency_tx";
5696 $sql .=
", multicurrency_price";
5697 $sql .=
", multicurrency_price_ttc";
5698 $sql .=
" FROM ".$this->db->prefix().
"product_price as ps";
5699 $sql .=
" WHERE ps.fk_product = ".((int) $fromId);
5700 $sql .=
" AND ps.date_price IN (SELECT MAX(pd.date_price) FROM ".$this->db->prefix().
"product_price as pd WHERE pd.fk_product = ".((int) $fromId).
" AND pd.price_level = ps.price_level)";
5701 $sql .=
" ORDER BY ps.date_price DESC";
5704 $resql = $this->db->query($sql);
5706 $this->db->rollback();
5709 $this->db->free($resql);
5723 $this->db->commit();
5740 $sql =
'INSERT INTO '.$this->db->prefix().
'product_association (fk_product_pere, fk_product_fils, qty, incdec)';
5741 $sql .=
" SELECT ".((int) $toId).
", fk_product_fils, qty, incdec FROM ".$this->db->prefix().
"product_association";
5742 $sql .=
" WHERE fk_product_pere = ".((int) $fromId);
5744 dol_syslog(get_class($this).
'::clone_association', LOG_DEBUG);
5745 if (!$this->db->query($sql)) {
5746 $this->db->rollback();
5750 $this->db->commit();
5791 $sql =
"INSERT ".$this->db->prefix().
"product_fournisseur_price (";
5792 $sql .=
" datec, fk_product, entity, fk_soc, desc_fourn, fk_availability, price, quantity,";
5793 $sql .=
" remise_percent, remise, unitprice, charges, default_vat_code, tva_tx,";
5794 $sql .=
" localtax1_tx, localtax1_type, localtax2_tx, localtax2_type, info_bits, fk_user,";
5795 $sql .=
" fk_supplier_price_expression, delivery_time_days, supplier_reputation, packaging,";
5796 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_tx, multicurrency_unitprice,";
5797 $sql .=
" multicurrency_price, status)";
5798 $sql .=
" SELECT '".$this->db->idate($now).
"', ".((int) $toId).
", entity, fk_soc, desc_fourn, fk_availability, price, quantity,";
5799 $sql .=
" remise_percent, remise, unitprice, charges, default_vat_code, tva_tx,";
5800 $sql .=
" localtax1_tx, localtax1_type, localtax2_tx, localtax2_type, info_bits, fk_user,";
5801 $sql .=
" fk_supplier_price_expression, delivery_time_days, supplier_reputation, packaging,";
5802 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_tx, multicurrency_unitprice,";
5803 $sql .=
" multicurrency_price, status";
5804 $sql .=
" FROM ".$this->db->prefix().
"product_fournisseur_price";
5805 $sql .=
" WHERE fk_product = ".((int) $fromId);
5807 dol_syslog(get_class($this).
'::clone_fournisseurs', LOG_DEBUG);
5808 $resql = $this->db->query($sql);
5810 $this->db->rollback();
5813 $this->db->commit();
5831 public function fetch_prod_arbo($prod, $compl_path =
'', $multiply = 1, $level = 1, $id_parent = 0, $ignore_stock_load = 0)
5836 if ($multiply < 1) {
5837 dol_syslog(get_class($this).
'::'.__FUNCTION__.
' Product quantity rounded up to 1 from '.$multiply.
'. May result in unexpected end quantity for product children of '.$id_parent, LOG_WARNING);
5841 foreach ($prod as $id_product => $desc_pere) {
5842 if (is_array($desc_pere)) {
5843 $id = (!empty($desc_pere[0]) ? $desc_pere[0] :
'');
5844 $nb = (!empty($desc_pere[1]) ? $desc_pere[1] :
'');
5845 $type = (!empty($desc_pere[2]) ? $desc_pere[2] :
'');
5846 $label = (!empty($desc_pere[3]) ? $desc_pere[3] :
'');
5847 $incdec = (!empty($desc_pere[4]) ? $desc_pere[4] : 0);
5850 if (is_null($tmpproduct)) {
5851 $tmpproduct =
new Product($this->db);
5853 $tmpproduct->fetch($id);
5855 if (empty($ignore_stock_load) && ($tmpproduct->isProduct() ||
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES'))) {
5856 $tmpproduct->load_stock(
'nobatch,novirtual');
5859 $this->res[] = array(
5861 'id_parent' => $id_parent,
5862 'ref' => $tmpproduct->ref,
5864 'nb_total' => $nb * $multiply,
5865 'stock' => $tmpproduct->stock_reel,
5866 'stock_alert' => $tmpproduct->seuil_stock_alerte,
5868 'fullpath' => $compl_path.$label,
5870 'desiredstock' => $tmpproduct->desiredstock,
5872 'incdec' => $incdec,
5873 'entity' => $tmpproduct->entity
5877 if (isset($desc_pere[
'childs']) && is_array($desc_pere[
'childs'])) {
5878 if (!is_int($desc_pere[1] * $multiply)) {
5879 dol_syslog(get_class($this).
'::'.__FUNCTION__.
' Source product quantity and multiplier may result in unexpected end quantity for '.$label.
'/'.$multiply.
' Child product:'.json_encode($desc_pere), LOG_WARNING);
5883 $this->
fetch_prod_arbo($desc_pere[
'childs'], $compl_path.$desc_pere[3].
" -> ", (
int) ceil($desc_pere[1] * $multiply), $level + 1, $id, $ignore_stock_load);
5901 $this->res = array();
5902 if (isset($this->sousprods) && is_array($this->sousprods)) {
5903 foreach ($this->sousprods as $prod_name => $desc_product) {
5904 if (is_array($desc_product)) {
5905 $this->
fetch_prod_arbo($desc_product,
"", $multiply, 1, $this->
id, $ignore_stock_load);
5923 $sql =
"SELECT COUNT(pa.rowid) as nb";
5924 $sql .=
" FROM ".$this->db->prefix().
"product_association as pa";
5926 $sql .=
" WHERE pa.fk_product_fils = ".((int) $this->
id).
" OR pa.fk_product_pere = ".((int) $this->
id);
5927 } elseif ($mode == -1) {
5928 $sql .=
" WHERE pa.fk_product_fils = ".((int) $this->
id);
5929 } elseif ($mode == 1) {
5930 $sql .=
" WHERE pa.fk_product_pere = ".((int) $this->
id);
5933 $resql = $this->db->query($sql);
5935 $obj = $this->db->fetch_object($resql);
5937 $nb = (int) $obj->nb;
5957 $sql =
"SELECT count(rowid) as nb FROM ".$this->db->prefix().
"product_attribute_combination WHERE fk_product_parent = ".((int) $this->
id);
5958 $sql .=
" AND entity IN (".getEntity(
'product').
")";
5960 $resql = $this->db->query($sql);
5962 $obj = $this->db->fetch_object($resql);
5964 $nb = (int) $obj->nb;
5980 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"product_attribute_combination WHERE fk_product_child = ".((int) $this->
id).
" AND entity IN (".
getEntity(
'product').
")";
5982 $query = $this->db->query($sql);
5985 if (!$this->db->num_rows($query)) {
5990 dol_print_error($this->db);
6006 $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";
6007 $sql .=
", p.tosell as status, p.tobuy as status_buy";
6008 $sql .=
" FROM ".$this->db->prefix().
"product_association as pa,";
6009 $sql .=
" ".$this->db->prefix().
"product as p";
6010 $sql .=
" WHERE p.rowid = pa.fk_product_pere";
6011 $sql .=
" AND pa.fk_product_fils = ".((int) $this->
id);
6013 $res = $this->db->query($sql);
6016 while ($record = $this->db->fetch_array($res)) {
6018 $prods[$record[
'id']] = array();
6019 $prods[$record[
'id']][
'id'] = $record[
'rowid'];
6020 $prods[$record[
'id']][
'ref'] = $record[
'ref'];
6021 $prods[$record[
'id']][
'label'] = $record[
'label'];
6022 $prods[$record[
'id']][
'qty'] = $record[
'qty'];
6023 $prods[$record[
'id']][
'incdec'] = $record[
'incdec'];
6024 $prods[$record[
'id']][
'fk_product_type'] = $record[
'fk_product_type'];
6025 $prods[$record[
'id']][
'entity'] = $record[
'entity'];
6026 $prods[$record[
'id']][
'status'] = $record[
'status'];
6027 $prods[$record[
'id']][
'status_buy'] = $record[
'status_buy'];
6031 dol_print_error($this->db);
6046 public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = array())
6052 $sql =
"SELECT p.rowid, p.ref, p.label as label, p.fk_product_type,";
6053 $sql .=
" pa.qty as qty, pa.fk_product_fils as id, pa.incdec,";
6054 $sql .=
" pa.rowid as fk_association, pa.rang";
6055 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
6056 $sql .=
" ".$this->db->prefix().
"product_association as pa";
6057 $sql .=
" WHERE p.rowid = pa.fk_product_fils";
6058 $sql .=
" AND pa.fk_product_pere = ".((int) $id);
6059 $sql .=
" AND pa.fk_product_fils <> ".((int) $id);
6060 $sql .=
" ORDER BY pa.rang";
6062 dol_syslog(get_class($this).
'::getChildsArbo id='.$id.
' level='.$level.
' parents='.(is_array($parents) ? implode(
',', $parents) : $parents), LOG_DEBUG);
6069 $res = $this->db->query($sql);
6072 if ($this->db->num_rows($res) > 0) {
6076 while ($rec = $this->db->fetch_array($res)) {
6077 if (in_array($rec[
'id'], $parents)) {
6078 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);
6082 $prods[$rec[
'rowid']] = array(
6085 2 => $rec[
'fk_product_type'],
6086 3 => $this->db->escape($rec[
'label']),
6087 4 => $rec[
'incdec'],
6089 6 => $rec[
'fk_association'],
6094 if (empty($firstlevelonly)) {
6095 $listofchilds = $this->
getChildsArbo($rec[
'rowid'], 0, $level + 1, $parents);
6096 foreach ($listofchilds as $keyChild => $valueChild) {
6097 $prods[$rec[
'rowid']][
'childs'][$keyChild] = $valueChild;
6104 dol_print_error($this->db);
6121 foreach ($this->
getChildsArbo($this->
id) as $keyChild => $valueChild) {
6122 $parent[$this->label][$keyChild] = $valueChild;
6124 foreach ($parent as $key => $value) {
6125 $this->sousprods[$key] = $value;
6138 global
$conf, $langs, $user;
6140 $langs->loadLangs(array(
'products',
'other'));
6143 $nofetch = !empty($params[
'nofetch']);
6146 return [
'optimize' => $langs->trans(
"ShowProduct")];
6150 $permissiontoreadproduct = 0;
6151 if ($this->
type == self::TYPE_PRODUCT && $user->hasRight(
'product',
'read')) {
6152 $permissiontoreadproduct = 1;
6154 if ($this->
type == self::TYPE_SERVICE && $user->hasRight(
'service',
'read')) {
6155 $permissiontoreadproduct = 1;
6158 if (!empty($this->entity) && $permissiontoreadproduct) {
6159 $tmpphoto = $this->
show_photos(
'product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 80, 0, 0, 0, 0,
'1');
6160 if ($this->nbphoto > 0) {
6161 $datas[
'photo'] =
'<div class="photointooltip floatright">'.
"\n" . $tmpphoto .
'</div>';
6166 $datas[
'picto'] = img_picto(
'',
'product').
' <u class="paddingrightonly">'.$langs->trans(
"Product").
'</u>';
6168 $datas[
'picto'] = img_picto(
'',
'service').
' <u class="paddingrightonly">'.$langs->trans(
"Service").
'</u>';
6170 if (isset($this->
status) && isset($this->status_buy)) {
6171 $datas[
'status'] =
' '.$this->getLibStatut(5, 0) .
' '.$this->getLibStatut(5, 1);
6174 if (!empty($this->
ref)) {
6175 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'ProductRef').
':</b> '.$this->ref;
6177 if (!empty($this->label)) {
6178 $datas[
'label'] =
'<br><b>'.$langs->trans(
'ProductLabel').
':</b> '.$this->label.
'<br>';
6181 if ($permissiontoreadproduct) {
6186 $datas[
'stockmanaged'] =
"<br><b>".$langs->trans(
"StockableProduct").
'</b>: '.yn($this->
isStockManaged());
6190 $langs->load(
"productbatch");
6191 $datas[
'batchstatus'] =
"<br><b>".$langs->trans(
"ManageLotSerial").
'</b>: '.$this->
getLibStatut(0, 2);
6192 if ($this->status_batch) {
6193 $datas[
'batchdlc'] =
"<br><b>".$langs->trans(
"BatchSellOrEatByMandatoryList", $langs->transnoentitiesnoconv(
"SellByDate"), $langs->transnoentitiesnoconv(
"EatByDate")).
'</b>: '.$this->
getSellOrEatByMandatoryLabel();
6198 $datas[
'barcode'] =
'<br><b>'.$langs->trans(
'BarCode').
':</b> '.$this->barcode;
6202 if ($this->weight) {
6203 $datas[
'weight'] =
"<br><b>".$langs->trans(
"Weight").
'</b>: '.$this->weight.
' '.
measuringUnitString(0,
"weight", $this->weight_units);
6206 if ($this->length) {
6207 $labelsize .=
"<b>".$langs->trans(
"Length").
'</b>: '.$this->length.
' '.
measuringUnitString(0,
'size', $this->length_units);
6210 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Width").
'</b>: '.$this->width.
' '.
measuringUnitString(0,
'size', $this->width_units);
6212 if ($this->height) {
6213 $labelsize .= ($labelsize ?
" - " :
"").
"<b>".$langs->trans(
"Height").
'</b>: '.$this->height.
' '.
measuringUnitString(0,
'size', $this->height_units);
6216 $datas[
'size'] =
"<br>".$labelsize;
6219 $labelsurfacevolume =
"";
6220 if ($this->surface) {
6221 $labelsurfacevolume .=
"<b>".$langs->trans(
"Surface").
'</b>: '.$this->surface.
' '.
measuringUnitString(0,
'surface', $this->surface_units);
6223 if ($this->volume) {
6224 $labelsurfacevolume .= ($labelsurfacevolume ?
" - " :
"").
"<b>".$langs->trans(
"Volume").
'</b>: '.$this->volume.
' '.
measuringUnitString(0,
'volume', $this->volume_units);
6226 if ($labelsurfacevolume) {
6227 $datas[
'surface'] =
"<br>" . $labelsurfacevolume;
6230 if ($this->
isService() && !empty($this->duration_value)) {
6232 $datas[
'duration'] =
'<br><b>'.$langs->trans(
"Duration").
':</b> '.$this->duration_value;
6233 if ($this->duration_value > 1) {
6234 $dur = array(
"i" => $langs->trans(
"Minutes"),
"h" => $langs->trans(
"Hours"),
"d" => $langs->trans(
"Days"),
"w" => $langs->trans(
"Weeks"),
"m" => $langs->trans(
"Months"),
"y" => $langs->trans(
"Years"));
6235 } elseif ($this->duration_value > 0) {
6236 $dur = array(
"i" => $langs->trans(
"Minute"),
"h" => $langs->trans(
"Hour"),
"d" => $langs->trans(
"Day"),
"w" => $langs->trans(
"Week"),
"m" => $langs->trans(
"Month"),
"y" => $langs->trans(
"Year"));
6238 $datas[
'duration'] .= (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ?
" ".$langs->trans($dur[$this->duration_unit]) :
'');
6240 if (empty($user->socid)) {
6241 if ($this->
isStockManaged() && isset($this->pmp) && $this->pmp) {
6242 $datas[
'pmp'] =
"<br><b>".$langs->trans(
"PMPValue").
'</b>: '.
price($this->pmp, 0,
'', 1, -1, -1,
$conf->currency);
6246 if ($this->
status && isset($this->accountancy_code_sell)) {
6247 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
6248 $selllabel =
'<br>';
6249 $selllabel .=
'<br><b>'.$langs->trans(
'ProductAccountancySellCode').
':</b> '.
length_accountg($this->accountancy_code_sell);
6250 $selllabel .=
'<br><b>'.$langs->trans(
'ProductAccountancySellIntraCode').
':</b> '.
length_accountg($this->accountancy_code_sell_intra);
6251 $selllabel .=
'<br><b>'.$langs->trans(
'ProductAccountancySellExportCode').
':</b> '.
length_accountg($this->accountancy_code_sell_export);
6252 $datas[
'accountancysell'] = $selllabel;
6254 if ($this->status_buy && isset($this->accountancy_code_buy)) {
6255 include_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
6257 if (empty($this->
status)) {
6258 $buylabel .=
'<br>';
6260 $buylabel .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyCode').
':</b> '.
length_accountg($this->accountancy_code_buy);
6261 $buylabel .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyIntraCode').
':</b> '.
length_accountg($this->accountancy_code_buy_intra);
6262 $buylabel .=
'<br><b>'.$langs->trans(
'ProductAccountancyBuyExportCode').
':</b> '.
length_accountg($this->accountancy_code_buy_export);
6263 $datas[
'accountancybuy'] = $buylabel;
6269 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
6270 $form =
new Form($this->db);
6271 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_PRODUCT, 1);
6292 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $save_lastsearch_value = -1, $notooltip = 0, $morecss =
'', $add_label = 0, $sep =
' - ', $addlinktonotes = 0)
6294 global $langs, $hookmanager, $user;
6296 include_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
6300 $newref = (string) $this->
ref;
6302 $newref =
dol_trunc($newref, $maxlength,
'middle');
6306 'objecttype' => ($this->
type == 1 ?
'service' :
'product'),
6307 'option' => $option,
6310 $classfortooltip =
'classfortooltip';
6313 $classfortooltip =
'classforajaxtooltip';
6314 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
6321 if (empty($notooltip)) {
6323 $label = $langs->trans(
"ShowProduct");
6324 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1, 1).
'"';
6326 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1, 1).
'"' :
' title="tocomplete"');
6327 $linkclose .= $dataparams.
' class="nowraponall '.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
6329 $linkclose =
' class="nowraponall'.($morecss ?
' '.$morecss :
'').
'"';
6332 if ($option ==
'supplier' || $option ==
'category') {
6333 $baseurl = DOL_URL_ROOT.
'/product/price_suppliers.php';
6334 } elseif ($option ==
'stock') {
6335 $baseurl = DOL_URL_ROOT.
'/product/stock/product.php';
6336 } elseif ($option ==
'composition') {
6337 $baseurl = DOL_URL_ROOT.
'/product/composition/card.php';
6339 $baseurl = DOL_URL_ROOT.
'/product/card.php';
6341 $query = [
'id' => $this->id];
6343 if ($option !==
'nolink') {
6345 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
6346 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
6347 $add_save_lastsearch_values = 1;
6349 if ($add_save_lastsearch_values) {
6350 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
6355 $linkstart =
'<a href="'.$url.
'"';
6356 $linkstart .= $linkclose.
'>';
6359 $result .= $linkstart;
6362 $result .= (img_object(($notooltip ?
'' : $label),
'product',
'class="paddingright"', 0, 0, $notooltip ? 0 : 1));
6365 $result .= (img_object(($notooltip ?
'' : $label),
'service',
'class="paddingright"', 0, 0, $notooltip ? 0 : 1));
6368 $result .=
'<span class="aaa">'.dol_escape_htmltag($newref).
'</span>';
6369 $result .= $linkend;
6370 if ($withpicto != 2) {
6371 $result .= (($add_label && $this->label) ? $sep.dol_trunc($this->label, ($add_label > 1 ? $add_label : 0)) :
'');
6374 if ($addlinktonotes) {
6375 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
6378 $result .=
' <span class="note inline-block">';
6379 $result .=
'<a href="'.DOL_URL_ROOT.
'/product/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
6380 $result .= img_picto(
'',
'note');
6382 $result .=
'</span>';
6387 $hookmanager->initHooks(array(
'productdao'));
6388 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result,
'label' => &$label);
6389 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
6391 $result = $hookmanager->resPrint;
6393 $result .= $hookmanager->resPrint;
6410 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
6414 $langs->load(
"products");
6415 $outputlangs->load(
"products");
6421 if (!empty($this->model_pdf)) {
6422 $modele = $this->model_pdf;
6428 if (empty($modele)) {
6431 $modelpath =
"core/modules/product/doc/";
6432 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
6449 return $this->
LibStatut($this->status_buy, $mode, $type);
6451 return $this->
LibStatut($this->status_batch, $mode, $type);
6454 return $this->
LibStatut($this->status_buy, $mode, $type);
6472 $labelStatus = $labelStatusShort =
'';
6474 $langs->load(
'products');
6476 $langs->load(
"productbatch");
6482 $label = ($status == 0 ? $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch') : ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatch') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerial')));
6483 return dolGetStatus($label);
6485 $label = ($status == 0 ? $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatchShort') : ($status == 1 ? $langs->transnoentitiesnoconv(
'ProductStatusOnBatchShort') : $langs->transnoentitiesnoconv(
'ProductStatusOnSerialShort')));
6486 return dolGetStatus($label);
6490 return dolGetStatus($langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch'),
'',
'', empty($status) ?
'status5' :
'status4', 3,
'dot');
6496 return dolGetStatus($langs->transnoentitiesnoconv(
'Unknown'));
6500 $statuttrans = empty($status) ?
'status5' :
'status4';
6505 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnSellShort');
6506 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnSell');
6507 } elseif ($type == 1) {
6508 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBuyShort');
6509 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBuy');
6510 } elseif ($type == 2) {
6511 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatch');
6512 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusNotOnBatchShort');
6514 } elseif ($status == 1) {
6517 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnSellShort');
6518 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnSell');
6519 } elseif ($type == 1) {
6520 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnBuyShort');
6521 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnBuy');
6522 } elseif ($type == 2) {
6523 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnBatch');
6524 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnBatchShort');
6526 } elseif ($type == 2 && $status == 2) {
6527 $labelStatus = $langs->transnoentitiesnoconv(
'ProductStatusOnSerial');
6528 $labelStatusShort = $langs->transnoentitiesnoconv(
'ProductStatusOnSerialShort');
6532 return dolGetStatus($langs->transnoentitiesnoconv(
'Unknown'),
'',
'',
'status0', 0);
6534 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statuttrans, $mode);
6548 $langs->load(
'products');
6551 if (isset($this->finished) && $this->finished >= 0) {
6552 $sql =
"SELECT label, code FROM ".$this->db->prefix().
"c_product_nature where code = ".((int) $this->finished).
" AND active=1";
6553 $resql = $this->db->query($sql);
6555 $this->error = $this->db->error().
' sql='.$sql;
6556 dol_syslog(__METHOD__.
' Error '.$this->error, LOG_ERR);
6558 } elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
6559 $label = $langs->trans($res[
'label']);
6561 $this->db->free($resql);
6585 public function correct_stock($user, $id_entrepot, $nbpiece, $movement, $label =
'', $price = 0, $inventorycode =
'', $origin_element =
'', $origin_id =
null, $disablestockchangeforsubproduct = 0, $extrafields =
null)
6591 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
6594 $nbpiece = (float) $nbpiece;
6599 $nbpiece = abs($nbpiece);
6606 $movementstock->setOrigin($origin_element, (
int) $origin_id);
6607 $result = $movementstock->_create($user, $this->
id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode,
'',
'',
'',
'',
false, 0, $disablestockchangeforsubproduct);
6611 $array_options = $extrafields->getOptionalsFromPost(
'stock_mouvement');
6612 $movementstock->array_options = $array_options;
6613 $movementstock->insertExtraFields();
6615 $this->db->commit();
6620 $this->db->rollback();
6649 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, $force_update_batch =
false)
6655 include_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
6658 $nbpiece = (float) $nbpiece;
6663 $nbpiece = abs($nbpiece);
6671 $movementstock->setOrigin($origin_element, (
int) $origin_id);
6672 $result = $movementstock->_create($user, $this->
id, $id_entrepot, $op[$movement], $movement, $price, $label, $inventorycode,
'', $dlc, $dluo, $lot,
false, 0, $disablestockchangeforsubproduct, 0, $force_update_batch);
6676 $array_options = $extrafields->getOptionalsFromPost(
'stock_mouvement');
6677 $movementstock->array_options = $array_options;
6678 $movementstock->insertExtraFields();
6680 $this->db->commit();
6683 $this->error = $movementstock->error;
6684 $this->errors = $movementstock->errors;
6686 $this->db->rollback();
6706 public function load_stock($option =
'', $includedraftpoforvirtual =
null, $dateofvirtualstock =
null)
6709 $this->stock_reel = 0;
6710 $this->stock_warehouse = array();
6711 $this->stock_theorique = 0;
6714 $warehouseStatus = array();
6715 if (preg_match(
'/warehouseclosed/', $option)) {
6718 if (preg_match(
'/warehouseopen/', $option)) {
6721 if (preg_match(
'/warehouseinternal/', $option)) {
6729 $sql =
"SELECT ps.rowid, ps.reel, ps.fk_entrepot";
6730 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
6731 $sql .=
", ".$this->db->prefix().
"entrepot as w";
6732 $sql .=
" WHERE w.entity IN (".getEntity(
'stock').
")";
6733 $sql .=
" AND w.rowid = ps.fk_entrepot";
6734 $sql .=
" AND ps.fk_product = ".((int) $this->
id);
6735 if (count($warehouseStatus)) {
6736 $sql .=
" AND w.statut IN (".$this->db->sanitize(implode(
',', $warehouseStatus)).
")";
6739 $sql .=
" ORDER BY ps.reel ".(getDolGlobalString(
'DO_NOT_TRY_TO_DEFRAGMENT_STOCKS_WAREHOUSE') ?
'DESC' :
'ASC');
6741 dol_syslog(get_class($this).
"::load_stock", LOG_DEBUG);
6742 $result = $this->db->query($sql);
6744 $num = $this->db->num_rows($result);
6748 $row = $this->db->fetch_object($result);
6749 $this->stock_warehouse[$row->fk_entrepot] =
new stdClass();
6750 $this->stock_warehouse[$row->fk_entrepot]->real = $row->reel;
6751 $this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid;
6752 if ((!preg_match(
'/nobatch/', $option)) && $this->
hasbatch()) {
6753 $this->stock_warehouse[$row->fk_entrepot]->detail_batch =
Productbatch::findAll($this->db, $row->rowid, 1, $this->id);
6755 $this->stock_reel += $row->reel;
6758 $this->stock_reel = (float)
price2num($this->stock_reel,
'MS');
6760 $this->db->free($result);
6762 if (!preg_match(
'/novirtual/', $option)) {
6768 $this->error = $this->db->lasterror();
6787 global $hookmanager, $action;
6789 $stock_commande_client = 0;
6790 $stock_commande_fournisseur = 0;
6791 $stock_sending_client = 0;
6792 $stock_reception_fournisseur = 0;
6793 $stock_inproduction = 0;
6801 $dateofvirtualstockmin = 0;
6802 if (empty($dateofvirtualstock) && $horizoninDays !==
'') {
6803 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
6811 dol_print_error($this->db, $this->error);
6813 $stock_commande_client = $this->stats_commande[
'qty'];
6816 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
6817 $filterShipmentStatus =
'';
6825 dol_print_error($this->db, $this->error);
6827 $stock_sending_client = $this->stats_expedition[
'qty'];
6831 $filterStatus =
getDolGlobalString(
'SUPPLIER_ORDER_STATUS_FOR_VIRTUAL_STOCK',
'3,4');
6832 if (isset($includedraftpoforvirtual)) {
6833 $filterStatus =
'0,1,2,'.$filterStatus;
6837 dol_print_error($this->db, $this->error);
6839 $stock_commande_fournisseur = $this->stats_commande_fournisseur[
'qty'];
6844 if (isset($includedraftpoforvirtual)) {
6845 $filterStatus =
'0,'.$filterStatus;
6847 $result = $this->
load_stats_reception(0, $filterStatus, 1, $dateofvirtualstock, $dateofvirtualstockmin);
6849 dol_print_error($this->db, $this->error);
6851 $stock_reception_fournisseur = $this->stats_reception[
'qty'];
6856 $result = $this->
load_stats_inproduction(0, $filterStatus, 1, $dateofvirtualstock, 0, $dateofvirtualstockmin);
6858 dol_print_error($this->db, $this->error);
6860 $stock_inproduction = $this->stats_mrptoproduce[
'qty'] - $this->stats_mrptoconsume[
'qty'];
6863 $this->stock_theorique = $this->stock_reel + $stock_inproduction;
6867 $weBillOrderOrShipmentReception =
getDolGlobalString(
'STOCK_DO_WE_BILL_ORDER_OR_SHIPMENTECEPTION_FOR_VIRTUALSTOCK',
'order');
6871 $this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
6875 $result = $tmpnewprod->load_stats_commande(0,
'0', 1);
6876 $this->stock_theorique += $tmpnewprod->stats_commande[
'qty'];
6878 } elseif (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') && $weBillOrderOrShipmentReception ==
'order') {
6879 $this->stock_theorique -= $stock_commande_client;
6880 } elseif (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') && $weBillOrderOrShipmentReception ==
'shipmentreception') {
6881 $this->stock_theorique -= ($stock_commande_client - $stock_sending_client);
6886 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
6888 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
6890 if (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER_INCLUDE_DRAFT')) {
6892 $result = $tmpnewprod->load_stats_commande_fournisseur(0,
'0', 1);
6893 $this->stock_theorique += $this->stats_commande_fournisseur[
'qty'];
6895 $this->stock_theorique -= $stock_reception_fournisseur;
6896 } elseif (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $weBillOrderOrShipmentReception ==
'order') {
6897 $this->stock_theorique += $stock_commande_fournisseur;
6898 } elseif (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') && $weBillOrderOrShipmentReception ==
'shipmentreception') {
6899 $this->stock_theorique += ($stock_commande_fournisseur - $stock_reception_fournisseur);
6902 $parameters = array(
'id' => $this->
id,
'includedraftpoforvirtual' => $includedraftpoforvirtual);
6904 $reshook = $hookmanager->executeHooks(
'loadvirtualstock', $parameters, $this, $action);
6906 $this->stock_theorique = $hookmanager->resArray[
'stock_theorique'];
6907 } elseif ($reshook == 0 && isset($hookmanager->resArray[
'stock_stats_hook'])) {
6908 $this->stock_theorique += $hookmanager->resArray[
'stock_stats_hook'];
6912 if (!empty($this->stock_warehouse) &&
getDolGlobalString(
'STOCK_ALLOW_VIRTUAL_STOCK_PER_WAREHOUSE')) {
6913 foreach ($this->stock_warehouse as $warehouseid => $stockwarehouse) {
6917 dol_print_error($this->db, $this->error);
6921 if ($this->fk_default_warehouse == $warehouseid) {
6922 $this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'] + $this->stats_commande_fournisseur[
'qty'] - ($this->stats_commande[
'qty'] + $this->stats_mrptoconsume[
'qty']);
6924 $this->stock_warehouse[$warehouseid]->virtual = $this->stock_warehouse[$warehouseid]->real + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce[
'qty'];
6941 $this->stock_warehouse = array();
6946 if (count($prods_arbo) > 0) {
6947 $productCachedList = array();
6948 $stockByComponentList = array();
6950 foreach ($prods_arbo as $componentArr) {
6951 $componentId = $componentArr[
'id'];
6953 if ($componentArr[
'incdec'] == 1) {
6954 if (!isset($productCachedList[$componentId])) {
6955 $componentStatic =
new self($this->db);
6956 $componentStatic->fetch($componentId);
6958 $childrenNb = $componentStatic->hasFatherOrChild(1);
6959 if ($childrenNb == 0) {
6960 $componentStatic->load_stock(
'nobatch,novirtual');
6961 if (!isset($stockByComponentList[$componentId])) {
6962 $stockByComponentList[$componentId] = array(
6966 $stockByComponentList[$componentId][
'qty_need'] += $componentArr[
'nb_total'];
6968 $productCachedList[$componentId] = $componentStatic;
6973 if (!empty($stockByComponentList)) {
6974 foreach ($stockByComponentList as $componentId => $stockByComponentArr) {
6975 if (!isset($productCachedList[$componentId])) {
6976 $componentStatic =
new self($this->db);
6977 $componentStatic->fetch($componentId);
6978 $componentStatic->load_stock(
'nobatch,novirtual');
6979 $productCachedList[$componentId] = $componentStatic;
6981 $component = $productCachedList[$componentId];
6984 if ($component->stock_reel < $stockByComponentArr[
'qty_need']) {
6987 $this->error =
'Not enough component [id='.$componentId.
'] in stock, real='.$component->stock_reel.
' and need='.$stockByComponentArr[
'qty_need'];
6988 $this->errors[] = $this->error;
6989 dol_syslog(__METHOD__.
' : '.$this->error, LOG_ERR);
6991 if (!empty($component->stock_warehouse)) {
6992 foreach ($component->stock_warehouse as $warehouseId => $warehouseObj) {
6993 $kitWarehouseAvailable =
new stdClass();
6994 $kitWarehouseAvailable->id = $warehouseObj->id;
6995 $kitWarehouseAvailable->real = $qtyWish;
6996 $this->stock_warehouse[$warehouseId] = $kitWarehouseAvailable;
7005 } elseif (
getDolGlobalInt(
'PRODUIT_SOUSPRODUITS_ALSO_ENABLE_PARENT_STOCK_MOVE') && empty($productCachedList)) {
7030 $sql =
"SELECT pb.batch, pl.eatby, pl.sellby, SUM(pb.qty) AS qty FROM ".$this->db->prefix().
"product_batch as pb";
7031 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_stock as ps ON pb.fk_product_stock = ps.rowid";
7032 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_lot as pl ON pl.fk_product = ps.fk_product AND pl.batch = pb.batch";
7033 $sql .=
" WHERE ps.fk_product = ".((int) $this->
id).
" AND pb.batch = '".$this->db->escape($batch).
"'";
7034 $sql .=
" GROUP BY pb.batch, pl.eatby, pl.sellby";
7035 dol_syslog(get_class($this).
"::loadBatchInfo load first entry found for lot/serial = ".$batch, LOG_DEBUG);
7036 $resql = $this->db->query($sql);
7038 $num = $this->db->num_rows($resql);
7041 $obj = $this->db->fetch_object($resql);
7042 $result[] = array(
'batch' => $batch,
'eatby' => $this->db->jdate($obj->eatby),
'sellby' => $this->db->jdate($obj->sellby),
'qty' => $obj->qty);
7047 dol_print_error($this->db);
7048 $this->db->rollback();
7065 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
7071 $dir .=
'/'.get_exdir($this->
id, 2, 0, 0, $this,
'product').$this->id.
"/photos";
7073 $dir .=
'/'.get_exdir(0, 0, 0, 0, $this,
'product').dol_sanitizeFileName($this->
ref);
7078 $dir_osencoded = $dir;
7080 if (is_dir($dir_osencoded)) {
7081 $originImage = $dir.
'/'.$file[
'name'];
7092 if (is_numeric($result) && $result > 0) {
7109 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
7110 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
7114 $dir .=
'/'.get_exdir($this->
id, 2, 0, 0, $this,
'product').$this->id.
"/photos/";
7116 $dir .=
'/'.get_exdir(0, 0, 0, 0, $this,
'product');
7120 if (file_exists($dir_osencoded)) {
7121 $handle = opendir($dir_osencoded);
7122 if (is_resource($handle)) {
7123 while (($file = readdir($handle)) !==
false) {
7125 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
7148 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
7149 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
7155 $handle = @opendir($dir_osencoded);
7156 if (is_resource($handle)) {
7157 while (($file = readdir($handle)) !==
false) {
7159 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
7166 $photo_vignette =
'';
7168 if (preg_match(
'/('.$this->regeximgext.
')$/i', $photo, $regs)) {
7169 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
7172 $dirthumb = $dir.
'thumbs/';
7176 $obj[
'photo'] = $photo;
7177 if ($photo_vignette &&
dol_is_file($dirthumb.$photo_vignette)) {
7178 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
7180 $obj[
'photo_vignette'] =
"";
7183 $tabobj[$nbphoto - 1] = $obj;
7186 if ($nbmax && $nbphoto >= $nbmax) {
7208 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
7209 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
7211 $dir = dirname($file).
'/';
7212 $dirthumb = $dir.
'/thumbs/';
7213 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
7219 if (preg_match(
'/('.$this->regeximgext.
')$/i', $filename, $regs)) {
7220 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
7221 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
7225 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_mini'.$regs[0];
7226 if (file_exists(
dol_osencode($dirthumb.$photo_vignette))) {
7243 $infoImg = getimagesize($file_osencoded);
7244 $this->imgWidth = $infoImg[0];
7245 $this->imgHeight = $infoImg[1];
7255 global $hookmanager;
7257 $this->nb = array();
7259 $sql =
"SELECT count(p.rowid) as nb, fk_product_type";
7260 $sql .=
" FROM ".$this->db->prefix().
"product as p";
7261 $sql .=
' WHERE p.entity IN ('.getEntity($this->element, 1).
')';
7263 if (is_object($hookmanager)) {
7264 $parameters = array();
7265 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
7266 $sql .= $hookmanager->resPrint;
7268 $sql .=
' GROUP BY fk_product_type';
7270 $resql = $this->db->query($sql);
7272 while ($obj = $this->db->fetch_object($resql)) {
7273 if ($obj->fk_product_type == 1) {
7274 $this->nb[
"services"] = $obj->nb;
7276 $this->nb[
"products"] = $obj->nb;
7279 $this->db->free($resql);
7282 dol_print_error($this->db);
7283 $this->error = $this->db->error();
7325 return $this->mandatory_period == 1;
7335 return $this->status_batch > 0;
7355 $dirsociete = array_merge(array(
'/core/modules/barcode/'),
$conf->modules_parts[
'barcode']);
7356 foreach ($dirsociete as $dirroot) {
7364 '@phan-var-force ModeleNumRefBarCode $mod';
7366 $result = $mod->getNextValue(
$object, $type);
7368 dol_syslog(get_class($this).
"::get_barcode barcode=".$result.
" module=".$var);
7385 $this->specimen = 1;
7387 $this->
ref =
'PRODUCT_SPEC';
7388 $this->label =
'PRODUCT SPECIMEN';
7389 $this->
description =
'This is description of this product specimen that was created the '.dol_print_date($now,
'dayhourlog').
'.';
7390 $this->specimen = 1;
7391 $this->country_id = 1;
7393 $this->status_buy = 1;
7395 $this->sell_or_eat_by_mandatory = 0;
7396 $this->note_private =
'This is a comment (private)';
7397 $this->note_public =
'This is a comment (public)';
7398 $this->date_creation = $now;
7399 $this->date_modification = $now;
7402 $this->weight_units = 3;
7405 $this->length_units = 1;
7407 $this->width_units = 0;
7408 $this->height =
null;
7409 $this->height_units =
null;
7411 $this->surface = 30;
7412 $this->surface_units = 0;
7413 $this->volume = 300;
7414 $this->volume_units = 0;
7416 $this->barcode = -1;
7434 if (empty($this->fk_unit)) {
7437 if (empty($outputlangs)) {
7438 $outputlangs = $langs;
7441 $outputlangs->load(
'products');
7444 $sql =
"SELECT code, label, short_label FROM ".$this->db->prefix().
"c_units where rowid = ".((int) $this->fk_unit);
7446 $resql = $this->db->query($sql);
7448 $this->error = $this->db->error();
7449 dol_syslog(get_class($this).
"::getLabelOfUnit Error ".$this->error, LOG_ERR);
7451 } elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
7452 if ($type ==
'short') {
7454 $label = $outputlangs->transnoentitiesnoconv($res[
'short_label']);
7456 $label = $outputlangs->trans($res[
'short_label']);
7458 } elseif ($type ==
'code') {
7459 $label = $res[
'code'];
7461 if ($outputlangs->trans(
'unit'.$res[
'code']) ==
'unit'.$res[
'code']) {
7463 $label = $res[
'label'];
7467 $label = $outputlangs->transnoentitiesnoconv(
'unit'.$res[
'code']);
7469 $label = $outputlangs->trans(
'unit'.$res[
'code']);
7474 $this->db->free($resql);
7488 $maxpricesupplier = 0;
7491 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
7493 $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->
id,
'',
'');
7495 if (is_array($product_fourn_list) && count($product_fourn_list) > 0) {
7496 foreach ($product_fourn_list as $productfourn) {
7497 if ($productfourn->fourn_unitprice > $maxpricesupplier) {
7498 $maxpricesupplier = $productfourn->fourn_unitprice;
7506 return $maxpricesupplier;
7522 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7523 return parent::setCategoriesCommon($categories, Categorie::TYPE_PRODUCT);
7538 global
$conf, $langs, $hookmanager, $user, $action;
7541 $productOrigin =
new Product($this->db);
7543 dol_syslog(
"mergeProduct merge product id=".$product_origin_id.
" (will be deleted) into the product id=".$this->id);
7545 if ($productOrigin->fetch($product_origin_id) < 1) {
7546 $this->error = $langs->trans(
'ErrorRecordNotFound');
7552 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().
"product_stock";
7553 $sql .=
" WHERE fk_product = ".((int) $productOrigin->id).
" AND reel <> 0";
7554 $resql = $this->db->query($sql);
7556 $this->error = $this->db->lasterror();
7559 $obj = $this->db->fetch_object($resql);
7560 if ($obj && $obj->nb > 0) {
7561 $langs->load(
"errors");
7562 $this->error = $langs->trans(
'ErrorMergeOriginProductHasStock', $productOrigin->ref);
7565 $this->db->free($resql);
7573 $listofproperties = array(
7583 'accountancy_code_buy',
7584 'accountancy_code_buy_intra',
7585 'accountancy_code_buy_export',
7586 'accountancy_code_sell',
7587 'accountancy_code_sell_intra',
7588 'accountancy_code_sell_export'
7590 foreach ($listofproperties as $property) {
7591 if (empty($this->$property)) {
7592 $this->$property = $productOrigin->$property;
7596 $listofproperties = array(
7597 'note_public',
'note_private'
7599 foreach ($listofproperties as $property) {
7600 $this->$property =
dol_concatdesc($this->$property, $productOrigin->$property);
7604 if (is_array($productOrigin->array_options)) {
7605 foreach ($productOrigin->array_options as $key => $val) {
7606 if (empty($this->array_options[$key])) {
7607 $this->array_options[$key] = $val;
7613 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7615 $custcats_ori = $static_cat->containing($productOrigin->id,
'product',
'id');
7616 $custcats = $static_cat->containing($this->
id,
'product',
'id');
7617 $custcats = array_merge($custcats, $custcats_ori);
7621 if ($productOrigin->barcode == $this->barcode) {
7622 dol_syslog(
"We clean customer and supplier code so we will be able to make the update of target");
7623 $productOrigin->barcode =
'';
7628 $result = $this->
update($this->
id, $user, 0,
'merge');
7637 'ActionComm' =>
'/comm/action/class/actioncomm.class.php',
7640 'Commande' =>
'/commande/class/commande.class.php',
7641 'CommandeFournisseur' =>
'/fourn/class/fournisseur.commande.class.php',
7642 'Contrat' =>
'/contrat/class/contrat.class.php',
7643 'Delivery' =>
'/delivery/class/delivery.class.php',
7644 'Expedition' =>
'/expedition/class/expedition.class.php',
7645 'Facture' =>
'/compta/facture/class/facture.class.php',
7646 'FactureFournisseur' =>
'/fourn/class/fournisseur.facture.class.php',
7647 'FactureRec' =>
'/compta/facture/class/facture-rec.class.php',
7648 'FichinterRec' =>
'/fichinter/class/fichinterrec.class.php',
7649 'ProductFournisseur' =>
'/fourn/class/fournisseur.product.class.php',
7650 'Propal' =>
'/comm/propal/class/propal.class.php',
7651 'Reception' =>
'/reception/class/reception.class.php',
7652 'SupplierProposal' =>
'/supplier_proposal/class/supplier_proposal.class.php',
7653 'TimeSpent' =>
'/core/class/timespent.class.php',
7656 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'bom_bom')) {
7657 $objects[
'Bom'] =
'/bom/class/bom.class.php';
7659 if ($this->db->DDLListTables((
string)
$conf->db->name, $this->db->prefix().
'mrp_mo')) {
7660 $objects[
'Mo'] =
'/mrp/class/mo.class.php';
7664 foreach ($objects as $object_name => $object_file) {
7665 require_once DOL_DOCUMENT_ROOT.$object_file;
7667 if (!$object_name::replaceProduct($this->db, $productOrigin->id, $this->id)) {
7669 $this->error = $this->db->lasterror();
7677 $parameters = array(
'soc_origin' => $productOrigin->id,
'soc_dest' => $this->id);
7678 $reshook = $hookmanager->executeHooks(
'replaceProduct', $parameters, $this, $action);
7681 $this->error = $hookmanager->error;
7682 $this->errors = $hookmanager->errors;
7689 $this->context = array(
'merge' => 1,
'mergefromid' => $productOrigin->id);
7692 $result = $this->call_trigger(
'PRODUCT_MODIFY', $user);
7704 if (!empty(
$conf->product->multidir_output[$productOrigin->entity ??
$conf->entity])) {
7705 $srcdir =
$conf->product->multidir_output[$productOrigin->entity ??
$conf->entity].
"/".$productOrigin->ref;
7706 $destdir =
$conf->product->multidir_output[$this->entity ??
$conf->entity].
"/".$this->ref;
7710 foreach ($dirlist as $filetomove) {
7711 $destfile = $destdir.
'/'.$filetomove[
'relativename'];
7714 dol_move($filetomove[
'fullname'], $destfile,
'0', 0, 0, 1);
7722 $sql =
"UPDATE ".$this->db->prefix().
"ecm_files SET src_object_id = ".((int) $this->
id);
7723 $sql .=
" WHERE src_object_type = '".$this->db->escape($this->table_element).
"' AND src_object_id = ".((int) $productOrigin->id);
7724 if (!$this->db->query($sql)) {
7725 $this->error = $this->db->lasterror();
7732 if ($productOrigin->delete($user) < 1) {
7733 $this->error = $productOrigin->error;
7734 $this->errors = $productOrigin->errors;
7740 $this->db->commit();
7743 $langs->load(
"errors");
7744 $this->error = $langs->trans(
'ErrorsProductsMerge').
' '.$this->error;
7745 $this->db->rollback();
7764 $sql =
" DELETE FROM ".$dbs->prefix().
"product_customer_price";
7765 $sql .=
" WHERE fk_soc = ".(int) $origin_id;
7766 $sql .=
" AND fk_product IN (SELECT fk_product FROM (SELECT fk_product FROM ".$dbs->prefix().
"product_customer_price WHERE fk_soc = ".(int) $dest_id.
") AS tmp)";
7769 if (!$dbs->
query($sql)) {
7774 'product_customer_price',
7775 'product_customer_price_log'
7794 $sql =
"SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".$this->db->prefix().
"product_pricerules";
7795 $query = $this->db->query($sql);
7799 while ($result = $this->db->fetch_object($query)) {
7800 $rules[$result->level] = $result;
7809 for ($i = 1; $i <= $nbofproducts; $i++) {
7810 $price = $baseprice;
7811 $price_min = $baseprice;
7815 if ($i > 1 && isset($rules[$i]->var_percent) && $rules[$i]->var_percent) {
7816 $price = $prices[$rules[$i]->fk_level] * (1 + ($rules[$i]->var_percent / 100));
7819 $prices[$i] = $price;
7822 if (isset($rules[$i]->var_min_percent) && $rules[$i]->var_min_percent) {
7823 $price_min = $price * (1 - ($rules[$i]->var_min_percent / 100));
7827 $check_amount = (($price == $this->multiprices[$i]) && ($price_min == $this->multiprices_min[$i]));
7828 $check_type = ($baseprice == $this->multiprices_base_type[$i]);
7830 if ($check_amount && $check_type) {
7834 if ($this->
updatePrice($price, $price_type, $user, $price_vat, $price_min, $i, $npr, $psq, 1) < 0) {
7851 $module = $this->
isProduct() ?
'produit' :
'service';
7852 if ($mode ==
'create') {
7855 if (!in_array($mode, array(
'read',
'write',
'delete'))) {
7859 return (
bool) $user->hasRight($module, $mode);
7870 $sql =
"SELECT p.rowid, p.ref, p.datec as date_creation, GREATEST(p.tms, COALESCE(pef.tms, p.tms)) as date_modification,";
7871 $sql .=
" p.fk_user_author, p.fk_user_modif";
7872 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as p";
7873 $sql .=
" LEFT JOIN ".$this->db->prefix().$this->table_element.
"_extrafields as pef ON pef.fk_object=p.rowid";
7874 $sql .=
" WHERE p.rowid = ".((int) $id);
7876 $result = $this->db->query($sql);
7878 if ($this->db->num_rows($result)) {
7879 $obj = $this->db->fetch_object($result);
7881 $this->
id = $obj->rowid;
7882 $this->
ref = $obj->ref;
7884 $this->user_creation_id = $obj->fk_user_author;
7885 $this->user_modification_id = $obj->fk_user_modif;
7887 $this->date_creation = $this->db->jdate($obj->date_creation);
7888 $this->date_modification = $this->db->jdate($obj->date_modification);
7891 $this->db->free($result);
7893 dol_print_error($this->db);
7905 if (empty($this->duration_value)) {
7906 $this->errors[] =
'ErrorDurationForServiceNotDefinedCantCalculateHourlyPrice';
7909 if ($this->duration_unit ==
's') {
7910 $prodDurationHours = 1. / 3600;
7911 } elseif ($this->duration_unit ==
'i' || $this->duration_unit ==
'mn' || $this->duration_unit ==
'min') {
7912 $prodDurationHours = 1. / 60;
7913 } elseif ($this->duration_unit ==
'h') {
7914 $prodDurationHours = 1.;
7915 } elseif ($this->duration_unit ==
'd') {
7916 $prodDurationHours = 24.;
7917 } elseif ($this->duration_unit ==
'w') {
7918 $prodDurationHours = 24. * 7;
7919 } elseif ($this->duration_unit ==
'm') {
7920 $prodDurationHours = 24. * 30;
7921 } elseif ($this->duration_unit ==
'y') {
7922 $prodDurationHours = 24. * 365;
7926 $this->errors[] =
'ErrorDurationForServiceNotDefinedCantCalculateHourlyPrice';
7929 $prodDurationHours *= $this->duration_value;
7931 return $prodDurationHours;
7944 global $langs,
$conf;
7946 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
7948 $return =
'<div class="box-flex-item box-flex-grow-zero">';
7949 $return .=
'<div class="info-box info-box-sm">';
7950 $return .=
'<div class="info-box-img">';
7952 if ($this->entity !==
null && $this->
is_photo_available($conf->product->multidir_output[$this->entity])) {
7953 $label .= $this->
show_photos(
'product', $conf->product->multidir_output[$this->entity], 1, 1, 0, 0, 0, 120, 160, 0, 0, 0,
'',
'photoref photokanban');
7957 $label .= img_picto(
'',
'product');
7959 $label .= img_picto(
'',
'service');
7963 $return .=
'</div>';
7964 $return .=
'<div class="info-box-content">';
7965 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
7966 if ($selected >= 0) {
7967 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
7969 $return .=
'<br><span class="info-box-label opacitymedium inline-block tdoverflowmax150 valignmiddle" title="'.dol_escape_htmltag($this->label).
'">'.
dol_escape_htmltag($this->label).
'</span>';
7970 if ($this->price_base_type ==
'TTC') {
7971 $return .=
'<br><span class="info-box-status amount">'.price($this->price_ttc).
' '.$langs->trans(
"TTC").
'</span>';
7974 $return .=
'<br><span class="info-box-status amount">'.price($this->
price).
' '.$langs->trans(
"HT").
'</span>';
7979 $return .=
'<br><div class="info-box-status opacitymedium inline-block valignmiddle">'.img_picto($langs->trans(
'PhysicalStock'),
'stock').
'</div><div class="inline-block valignmiddle paddingleft" title="'.$langs->trans(
'PhysicalStock').
'">'.$this->stock_reel.
'</div>';
7984 $return .=
'<div class="info-box-status inline-block valignmiddle">'.$this->getLibStatut(3, 1).
' '.$this->
getLibStatut(3, 0).
'</div>';
7986 $return .=
'<div class="info-box-status inline-block valignmiddle marginleftonly paddingleft">'.$this->getLibStatut(3, 1).
' '.$this->
getLibStatut(3, 0).
'</div>';
7988 $return .=
'</div>';
7989 $return .=
'</div>';
7990 $return .=
'</div>';
8013 $sql .=
", price_ttc";
8014 $sql .=
", price_min";
8015 $sql .=
", price_min_ttc";
8016 $sql .=
", price_base_type";
8017 $sql .=
", default_vat_code";
8019 $sql .=
", recuperableonly";
8020 $sql .=
", localtax1_tx";
8021 $sql .=
", localtax1_type";
8022 $sql .=
", localtax2_tx";
8023 $sql .=
", localtax2_type";
8024 $sql .=
", fk_user";
8025 $sql .=
", ref_customer";
8026 $sql .=
", discount_percent";
8027 $sql .=
", date_begin";
8028 $sql .=
", date_end";
8029 $sql .=
", price_label";
8030 $sql .=
", import_key";
8032 $sql .=
" FROM ".$this->db->prefix().
"product_customer_price";
8033 $sql .=
" WHERE fk_product = ".((int) $fromId);
8034 $sql .=
" ORDER BY rowid ASC";
8035 dol_syslog(__METHOD__.
' - '.$sql, LOG_DEBUG);
8037 $resql = $this->db->query($sql);
8039 $this->db->rollback();
8045 $sql_fields =
"SHOW COLUMNS FROM ".$this->db->prefix().
"product_customer_price_extrafields";
8046 $resql_fields = $this->db->query($sql_fields);
8047 if (!$resql_fields) {
8048 $this->db->rollback();
8052 while ($field = $this->db->fetch_object($resql_fields)) {
8053 if (!in_array($field->Field, array(
'rowid',
'tms',
'fk_object'))) {
8054 $fields[] = $field->Field;
8057 $this->db->free($resql_fields);
8059 while ($oldPrice = $this->db->fetch_object($resql)) {
8061 $sql_insert =
"INSERT INTO ".$this->db->prefix().
"product_customer_price (";
8062 $sql_insert .=
"entity";
8063 $sql_insert .=
", datec";
8064 $sql_insert .=
", fk_product";
8065 $sql_insert .=
", fk_soc";
8066 $sql_insert .=
", ref_customer";
8067 $sql_insert .=
", price";
8068 $sql_insert .=
", price_ttc";
8069 $sql_insert .=
", price_min";
8070 $sql_insert .=
", price_min_ttc";
8071 $sql_insert .=
", price_base_type";
8072 $sql_insert .=
", default_vat_code";
8073 $sql_insert .=
", tva_tx";
8074 $sql_insert .=
", recuperableonly";
8075 $sql_insert .=
", localtax1_type";
8076 $sql_insert .=
", localtax1_tx";
8077 $sql_insert .=
", localtax2_type";
8078 $sql_insert .=
", localtax2_tx";
8079 $sql_insert .=
", discount_percent";
8080 $sql_insert .=
", date_begin";
8081 $sql_insert .=
", date_end";
8082 $sql_insert .=
", fk_user";
8083 $sql_insert .=
", price_label";
8084 $sql_insert .=
", import_key";
8085 $sql_insert .=
") VALUES (";
8086 $sql_insert .= ((int) $oldPrice->entity);
8087 $sql_insert .=
", '".$this->db->idate($now).
"'";
8088 $sql_insert .=
", ".((int) $toId);
8089 $sql_insert .=
", ".((int) $oldPrice->fk_soc);
8090 $sql_insert .=
", ".(!isset($oldPrice->ref_customer) ?
"NULL" :
"'".$this->db->escape($oldPrice->ref_customer).
"'");
8091 $sql_insert .=
", ".(is_null($oldPrice->price) ?
"NULL" :
price2num($oldPrice->price));
8092 $sql_insert .=
", ".(is_null($oldPrice->price_ttc) ?
"NULL" :
price2num($oldPrice->price_ttc));
8093 $sql_insert .=
", ".(is_null($oldPrice->price_min) ?
"NULL" :
price2num($oldPrice->price_min));
8094 $sql_insert .=
", ".(is_null($oldPrice->price_min_ttc) ?
"NULL" :
price2num($oldPrice->price_min_ttc));
8095 $sql_insert .=
", ".(!isset($oldPrice->price_base_type) ?
"NULL" :
"'".$this->db->escape($oldPrice->price_base_type).
"'");
8096 $sql_insert .=
", ".(is_null($oldPrice->default_vat_code) ?
"NULL" :
"'".$this->db->escape($oldPrice->default_vat_code).
"'");
8097 $sql_insert .=
", ".(is_null($oldPrice->tva_tx) ?
"NULL" :
price2num($oldPrice->tva_tx));
8098 $sql_insert .=
", ".((int) $oldPrice->recuperableonly);
8099 $sql_insert .=
", ".(is_null($oldPrice->localtax1_type) ?
"NULL" :
"'".$this->db->escape($oldPrice->localtax1_type).
"'");
8100 $sql_insert .=
", ".(is_null($oldPrice->localtax1_tx) ?
"NULL" :
price2num($oldPrice->localtax1_tx));
8101 $sql_insert .=
", ".(is_null($oldPrice->localtax2_type) ?
"NULL" :
"'".$this->db->escape($oldPrice->localtax2_type).
"'");
8102 $sql_insert .=
", ".(is_null($oldPrice->localtax2_tx) ?
"NULL" :
price2num($oldPrice->localtax2_tx));
8103 $sql_insert .=
", ".(is_null($oldPrice->discount_percent) ?
"0" :
price2num($oldPrice->discount_percent));
8104 $sql_insert .=
", ".(empty($oldPrice->date_begin) ?
"NULL" :
"'".$this->db->idate($oldPrice->date_begin).
"'");
8105 $sql_insert .=
", ".(empty($oldPrice->date_end) ?
"NULL" :
"'".$this->db->idate($oldPrice->date_end).
"'");
8106 $sql_insert .=
", ".((int) $user->id);
8107 $sql_insert .=
", ".(is_null($oldPrice->price_label) ?
"NULL" :
"'".$this->db->escape($oldPrice->price_label).
"'");
8108 $sql_insert .=
", ".(is_null($oldPrice->import_key) ?
"NULL" :
"'".$this->db->escape($oldPrice->import_key).
"'");
8111 $resql_insert = $this->db->query($sql_insert);
8113 if (!$resql_insert) {
8114 $this->db->rollback();
8119 $newPriceId = $this->db->last_insert_id($this->db->prefix().
"product_customer_price");
8122 if (!empty($fields)) {
8123 $sql_copy =
"INSERT INTO ".$this->db->prefix().
"product_customer_price_extrafields";
8124 $sql_copy .=
" (fk_object";
8125 foreach ($fields as $field) {
8126 $sql_copy .=
",".$field;
8129 $sql_copy .=
" SELECT ";
8130 $sql_copy .= ((int) $newPriceId);
8132 foreach ($fields as $field) {
8133 $sql_copy .=
",".$field;
8135 $sql_copy .=
" FROM ".$this->db->prefix().
"product_customer_price_extrafields";
8136 $sql_copy .=
" WHERE fk_object = ".((int) $oldPrice->rowid);
8137 $resql_copy = $this->db->query($sql_copy);
8139 $this->db->rollback();
8145 $this->db->free($resql);
8164 $sql_fields =
"SHOW COLUMNS FROM ".MAIN_DB_PREFIX.
"product_price_extrafields";
8165 $resql_fields = $this->db->query($sql_fields);
8166 if (!$resql_fields) {
8167 $this->db->rollback();
8171 while ($field = $this->db->fetch_object($resql_fields)) {
8172 if (!in_array($field->Field, array(
'rowid',
'tms',
'fk_object'))) {
8173 $fields[] = $field->Field;
8176 if (!empty($fields)) {
8178 $sql =
"SELECT oldp.rowid AS old_price_id, oldp.date_price, oldp.price_level,";
8179 $sql .=
" newp.rowid AS new_price_id, newp.price_level";
8180 $sql .=
" FROM ".$this->db->prefix().
"product_price AS oldp";
8181 $sql .=
" INNER JOIN ".$this->db->prefix().
"product_price AS newp ON newp.price_level = oldp.price_level";
8182 $sql .=
" WHERE oldp.fk_product = ".((int) $fromId);
8183 $sql .=
" AND newp.fk_product = ".((int) $toId);
8184 $sql .=
" ORDER BY oldp.date_price DESC";
8185 $resql = $this->db->query($sql);
8187 $this->db->rollback();
8191 while ($obj = $this->db->fetch_object($resql)) {
8192 $sql_copy =
"INSERT INTO ".$this->db->prefix().
"product_price_extrafields";
8193 $sql_copy .=
" (fk_object";
8194 foreach ($fields as $field) {
8195 $sql_copy .=
",".$field;
8198 $sql_copy .=
" SELECT ";
8199 $sql_copy .= ((int) $obj->new_price_id);
8200 foreach ($fields as $field) {
8201 $sql_copy .=
",".$field;
8203 $sql_copy .=
" FROM ".$this->db->prefix().
"product_price_extrafields";
8204 $sql_copy .=
" WHERE fk_object = ".((int) $obj->old_price_id);
8205 $resql_copy = $this->db->query($sql_copy);
8207 $this->db->rollback();
8212 $this->db->free($resql);
8215 $this->db->free($resql_fields);
8227 public $picto =
'service';
if(! $sortfield) if(! $sortorder) $object
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
clean_account($account)
Return accounting account without zero on the right.
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage categories.
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.
setErrorsFromObject($object)
setErrorsFromObject
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
deleteExtraFields()
Delete all extra fields values for the current object.
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, $overwritetitle=0, $usesharelink=0, $cache='', $addphotorefcss='photoref')
Show photos of an object (nbmax maximum), into several columns.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
addThumbs($file, $quality=50)
Build thumb.
Class to manage Dolibarr database access.
Class to manage ECM files.
const STATUS_OPEN_INTERNAL
Warehouse open and only operations for stock transfers/corrections allowed (not for customer shipping...
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
const STATUS_CLOSED
Warehouse closed, inactive.
const STATUS_CLOSED
Closed status -> parcel was received by customer / end of process prev status : validated or shipment...
const STATUS_VALIDATED
Validated status -> parcel is ready to be sent prev status : draft next status : closed or shipment_i...
const STATUS_DRAFT
Draft status.
Class to manage stock movements.
Class to parse product price expressions.
Class ProductCombination Used to represent the relation between a product and one of its variants.
File of class to manage predefined price products or services by customer.
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.
is_sousproduit($fk_parent, $fk_child)
Check if it is a sub-product into a kit.
const DISABLED_STOCK
Stockable product.
const SELL_OR_EAT_BY_MANDATORY_ID_NONE
Const sell or eat by mandatory id.
isStockManaged()
Return if the object is managed in stock.
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 and return it.
load_stats_inproduction($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null, $warehouseid=0, $dateofvirtualstockmin=null)
Charge tableau des stats production pour le produit/service.
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.
updatePrice($newprice, $newpricebase, $user, $newvat=null, $newminprice=0, $level=0, $newnpr=0, $newpbq=0, $ignore_autogen=0, $localtaxes_array=array(), $newdefaultvatcode='', $price_label='', $notrigger=0)
Modify customer price of a product/Service for a given level.
hasVariants()
Return if a product has variants or not.
load_stats_proposal_supplier($socid=0)
Charge tableau des stats propale pour le produit/service.
getLibFinished()
Retour label of nature of product.
add_sousproduit($id_pere, $id_fils, $qty, $incdec=1, $notrigger=0)
Link a product/service to a parent product/service.
add_fournisseur($user, $id_fourn, $ref_fourn, $quantity)
Add a supplier price for the product.
setMultiLangs($user, $notrigger=0)
Update or add a translation for a product.
hasFatherOrChild($mode=0)
Count all parent and children products for current product (first level only)
load_stats_facturerec($socid=0)
Load array of statistics for recurring invoice for product/service.
get_nb_propalsupplier($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in proposals in which product is included.
load_stats_facturefournrec($socid=0)
Load array of statistics for recurring supplier invoice for product/service.
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)
Load array of statistics for vendor invoice for product/service.
get_nb_ordersupplier($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in orders in which product is included.
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.
load_stats_reception($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null, $dateofvirtualstockmin=null)
Loads supplier reception statistics table for given product or service.
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 the object is a service.
loadBatchInfo($batch)
Load existing information about a serial.
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 of a service in hours (for a service based on duration fields)
get_buyprice($prodfournprice, $qty, $product_id=0, $fourn_ref='', $fk_soc=0)
Read price used by a provider.
clone_fournisseurs($fromId, $toId)
Copies the suppliers and supplier pricing of a product/service onto another one.
const TYPE_PRODUCT
Regular product.
fetchAllPriceLogs($id)
Get all price change logs for a product, enriched with supplier info.
mergeProduct($product_origin_id)
Merge a product with current one, deleting the given product $product_origin_id.
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 of this product.
info($id)
Load information for tab info.
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.
static getSellOrEatByMandatoryList()
Get the array of labels of Sell by or Eat by all mandatory flags for each status.
getChildsArbo($id, $firstlevelonly=0, $level=1, $parents=array())
Return children 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_commande_fournisseur($socid=0, $filtrestatut='', $forVirtualStock=0, $dateofvirtualstock=null, $dateofvirtualstockmin=null)
Charge tableau des stats commande fournisseur pour le produit/service.
load_stats_facture($socid=0)
Charge tableau des stats facture pour le produit/service.
setCategories($categories)
Sets object to supplied categories.
get_nb_propal($socid, $mode, $filteronproducttype=-1, $year=0, $morefilter='')
Return nb of units in proposals in which product is included.
update($id, $user, $notrigger=0, $action='update', $updatetype=false)
Update a record into database.
correct_stock_batch($user, $id_entrepot, $nbpiece, $movement, $label='', $price=0, $dlc='', $dluo='', $lot='', $inventorycode='', $origin_element='', $origin_id=null, $disablestockchangeforsubproduct=0, $extrafields=null, $force_update_batch=false)
Adjust stock in a warehouse for product with batch number.
load_stats_bom($socid=0)
Charge tableau des stats OF pour le produit/service.
hasbatch()
Return if the object has a batch management.
getNomUrl($withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0, $morecss='', $add_label=0, $sep=' - ', $addlinktonotes=0)
Return clickable link of object (with eventually picto)
cloneMultipriceExtra($fromId, $toId)
Clone price level extrafields.
hasUserPermission(User $user, $mode='write')
Check if user has a permission on this type of product (product or service)
del_sousproduit($fk_parent, $fk_child, $notrigger=0)
Remove a link between a subproduct and a parent product/service.
fetch($id=0, $ref='', $ref_ext='', $barcode='', $ignore_expression=0, $ignore_price_load=0, $ignore_lang_load=0)
Load a product in memory from database.
update_sousproduit($id_pere, $id_fils, $qty, $incdec=1, $notrigger=0)
Modify composed product.
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)
Function recursive, used only by get_arbo_each_prod(), to build tree of subproducts into ->res Define...
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
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.
delMultiLangs($langtodelete, $user, $notrigger=0)
Delete a language for this product.
check()
Check that ref and label are ok.
initAsSpecimen()
Initialise an instance with random values.
liste_photos($dir, $nbmax=0)
Return an array with all photos of product found on disk.
loadStateBoard()
Load indicators this->nb for the dashboard.
getFather()
Return all parent products for current product (first level only)
getSellOrEatByMandatoryLabel()
Get the label for sell by or eat by mandatory flag of the current product.
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.
loadStockForVirtualProduct($option='', $qtyWish=1)
Load stock for components of virtual product (first level only)
setMultiLangsExtrafields($langcode, $rowidlang)
Save the extrafields of a translation of the product (table llx_product_lang_extrafields).
min_recommended_price()
Return minimum product recommended price.
cloneCustomerPriceAndExtra($fromId, $toId)
Clone customer prices using extra fields.
_log_price($user, $level=0)
Insert a track that we changed a customer price.
getLabelOfUnit($type='long', $outputlangs=null, $noentities=0)
Reads the units dictionary to return the translation code of a unit (if type='code'),...
_get_stats($sql, $mode, $year=0)
Return an array formatted for showing graphs.
isMandatoryPeriod()
Return if the object has a constraint on mandatory_period.
isProduct()
Return if the 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.
getMultiLangs($loadextrafields=0)
Load array this->multilangs.
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.
getTooltipContentArray($params)
getTooltipContentArray
Class of a translation of a product (a row of llx_product_lang).
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.
Class with list of lots and properties.
Class to manage translations.
Class to manage Dolibarr users.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
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)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
measuring_units_squared($unitscale)
Transform a given unit scale into the square of that unit, if known.
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
measuring_units_cubed($unit)
Transform a given unit scale into the cube of that unit, if known.