30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 public $element =
'productlot';
47 public $table_element =
'product_lot';
52 public $picto =
'lot';
58 public $ismultientitymanaged = 1;
60 public $stats_propale;
61 public $stats_commande;
62 public $stats_contrat;
63 public $stats_facture;
64 public $stats_commande_fournisseur;
65 public $stats_expedition;
66 public $stats_reception;
69 public $stats_mrptoconsume;
70 public $stats_mrptoproduce;
71 public $stats_facturerec;
72 public $stats_facture_fournisseur;
103 public $fields = array(
104 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'noteditable'=>1,
'notnull'=> 1,
'index'=>1,
'position'=>1,
'comment'=>
'Id',
'css'=>
'left'),
105 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'enabled'=>1,
'visible'=>1,
'position'=>5,
'notnull'=>1,
'index'=>1,
'searchall'=>1,
'picto' =>
'product',
'css'=>
'maxwidth500 widthcentpercentminusxx',
'csslist'=>
'maxwidth150'),
106 'batch' => array(
'type'=>
'varchar(30)',
'label'=>
'Batch',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'comment'=>
'Batch',
'searchall'=>1,
'picto'=>
'lot'),
107 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'notnull'=>1,
'index'=>1,
'position'=>20),
108 'sellby' => array(
'type'=>
'date',
'label'=>
'SellByDate',
'enabled'=>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible'=>1,
'notnull'=>0,
'position'=>60),
109 'eatby' => array(
'type'=>
'date',
'label'=>
'EatByDate',
'enabled'=>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible'=>1,
'notnull'=>0,
'position'=>62),
110 'eol_date' => array(
'type'=>
'date',
'label'=>
'EndOfLife',
'enabled'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?1:0',
'visible'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?5:0',
'position'=>70),
111 'manufacturing_date' => array(
'type'=>
'date',
'label'=>
'ManufacturingDate',
'enabled'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY")?1:0',
'visible'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY")?5:0',
'position'=>80),
112 'scrapping_date' => array(
'type'=>
'date',
'label'=>
'DestructionDate',
'enabled'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY")?1:0',
'visible'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY")?5:0',
'position'=>90),
114 'qc_frequency' => array(
'type'=>
'integer',
'label'=>
'QCFrequency',
'enabled'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?1:0',
'visible'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?5:0',
'position'=>110),
115 'lifetime' => array(
'type'=>
'integer',
'label'=>
'Lifetime',
'enabled'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?1:0',
'visible'=>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL")?5:0',
'position'=>110),
116 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
117 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
118 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>500),
119 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
120 'fk_user_creat' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>510,
'foreignkey'=>
'llx_user.rowid'),
121 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511),
122 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000)
141 public $eol_date =
'';
142 public $manufacturing_date =
'';
143 public $scrapping_date =
'';
145 public $qc_frequency =
'';
146 public $lifetime =
'';
153 public $fk_user_creat;
158 public $fk_user_modif;
165 public $stats_supplier_order=array();
190 $errorMsgArr = array();
191 if ($this->fk_product > 0) {
193 $product = $this->product;
195 $errorMsgArr[] = $product->errorsToString();
198 if (empty($errorMsgArr)) {
203 if (!empty($errorMsgArr)) {
204 $this->errors = array_merge($this->errors, $errorMsgArr);
228 $errorMsgArr = array();
229 if ($productId > 0) {
231 $res = $product->fetch($productId);
233 $errorMsgArr[] = $product->errorsToString();
236 if (empty($errorMsgArr)) {
262 $errorMsgArr = array();
263 $checkSellByMandatory =
false;
264 $checkEatByMandatory =
false;
266 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
267 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
268 $checkSellByMandatory =
true;
269 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
270 $checkEatByMandatory =
true;
271 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
272 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
273 $checkSellByMandatory =
true;
275 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
276 $checkEatByMandatory =
true;
280 if ($checkSellByMandatory ===
true) {
281 if (!isset($sellBy) ||
dol_strlen($sellBy) == 0) {
283 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
286 if ($checkEatByMandatory ===
true) {
287 if (!isset($eatBy) ||
dol_strlen($eatBy) == 0) {
289 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
307 global $conf, $langs;
315 if (isset($this->entity)) {
316 $this->entity = (int) $this->entity;
318 if (isset($this->fk_product)) {
319 $this->fk_product = (int) $this->fk_product;
321 if (isset($this->batch)) {
322 $this->batch = trim($this->batch);
324 if (isset($this->fk_user_creat)) {
325 $this->fk_user_creat = (int) $this->fk_user_creat;
327 if (isset($this->fk_user_modif)) {
328 $this->fk_user_modif = (int) $this->fk_user_modif;
330 if (isset($this->import_key)) {
331 $this->import_key = trim($this->import_key);
335 if ($this->batch ===
'') {
336 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
337 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
343 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element.
'(';
345 $sql .=
'fk_product,';
350 $sql .=
'manufacturing_date,';
351 $sql .=
'scrapping_date,';
353 $sql .=
'qc_frequency,';
356 $sql .=
'fk_user_creat,';
357 $sql .=
'fk_user_modif,';
358 $sql .=
'import_key';
359 $sql .=
') VALUES (';
360 $sql .=
' '.(!isset($this->entity) ? $conf->entity : $this->entity).
',';
361 $sql .=
' '.(!isset($this->fk_product) ?
'NULL' : $this->fk_product).
',';
362 $sql .=
' '.(!isset($this->batch) ?
'NULL' :
"'".$this->db->escape($this->batch).
"'").
',';
363 $sql .=
' '.(!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'".$this->db->idate($this->eatby).
"'").
',';
364 $sql .=
' '.(!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'".$this->db->idate($this->sellby).
"'").
',';
365 $sql .=
' '.(!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->eol_date).
"'").
',';
366 $sql .=
' '.(!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->manufacturing_date).
"'").
',';
367 $sql .=
' '.(!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'".$this->db->idate($this->scrapping_date).
"'").
',';
369 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : $this->qc_frequency).
',';
370 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : $this->lifetime).
',';
371 $sql .=
' '.
"'".$this->db->idate(
dol_now()).
"'".
',';
372 $sql .=
' '.(!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat).
',';
373 $sql .=
' '.(!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif).
',';
374 $sql .=
' '.(!isset($this->import_key) ?
'NULL' : $this->import_key);
379 $resql = $this->db->query($sql);
382 $this->errors[] =
'Error '.$this->db->lasterror();
383 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
387 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
397 if (!$error && !$notrigger) {
399 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
409 $this->db->rollback();
428 public function fetch($id = 0, $product_id = 0, $batch =
'')
435 $sql .=
" t.entity,";
436 $sql .=
" t.fk_product,";
439 $sql .=
" t.sellby,";
440 $sql .=
" t.eol_date,";
441 $sql .=
" t.manufacturing_date,";
442 $sql .=
" t.scrapping_date,";
444 $sql .=
" t.qc_frequency,";
445 $sql .=
" t.lifetime,";
446 $sql .=
" t.model_pdf,";
447 $sql .=
" t.last_main_doc,";
450 $sql .=
" t.fk_user_creat,";
451 $sql .=
" t.fk_user_modif,";
452 $sql .=
" t.import_key,";
453 $sql .=
" t.note_public,";
454 $sql .=
" t.note_private";
455 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
456 if ($product_id > 0 && $batch !=
'') {
457 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
459 $sql .=
" WHERE t.rowid = ".((int) $id);
462 $resql = $this->db->query($sql);
464 $numrows = $this->db->num_rows($resql);
466 $obj = $this->db->fetch_object($resql);
468 $this->
id = $obj->rowid;
469 $this->
ref = $obj->rowid;
472 $this->batch = $obj->batch;
473 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
474 $this->fk_product = $obj->fk_product;
475 $this->eatby = $this->db->jdate($obj->eatby);
476 $this->sellby = $this->db->jdate($obj->sellby);
477 $this->eol_date = $this->db->jdate($obj->eol_date);
478 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
479 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
481 $this->qc_frequency = $obj->qc_frequency;
482 $this->lifetime = $obj->lifetime;
483 $this->model_pdf = $obj->model_pdf;
484 $this->last_main_doc = $obj->last_main_doc;
486 $this->datec = $this->db->jdate($obj->datec);
487 $this->tms = $this->db->jdate($obj->tms);
488 $this->fk_user_creat = $obj->fk_user_creat;
489 $this->fk_user_modif = $obj->fk_user_modif;
490 $this->import_key = $obj->import_key;
491 $this->note_public = $obj->note_public;
492 $this->note_private = $obj->note_private;
498 $this->db->free($resql);
506 $this->errors[] =
'Error '.$this->db->lasterror();
507 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
529 if (isset($this->entity)) {
530 $this->entity = (int) $this->entity;
532 if (isset($this->fk_product)) {
533 $this->fk_product = (int) $this->fk_product;
535 if (isset($this->batch)) {
536 $this->batch = trim($this->batch);
538 if (isset($this->fk_user_creat)) {
539 $this->fk_user_creat = (int) $this->fk_user_creat;
541 if (isset($this->fk_user_modif)) {
542 $this->fk_user_modif = (int) $this->fk_user_modif;
544 if (isset($this->import_key)) {
545 $this->import_key = trim($this->import_key);
549 if (empty($this->oldcopy)) {
554 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET';
555 $sql .=
' entity = '.(isset($this->entity) ? $this->entity :
"null").
',';
556 $sql .=
' fk_product = '.(isset($this->fk_product) ? $this->fk_product :
"null").
',';
557 $sql .=
' batch = '.(isset($this->batch) ?
"'".$this->db->escape($this->batch).
"'" :
"null").
',';
558 $sql .=
' eatby = '.(!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'".$this->db->idate($this->eatby).
"'" :
'null').
',';
559 $sql .=
' sellby = '.(!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'".$this->db->idate($this->sellby).
"'" :
'null').
',';
560 $sql .=
' eol_date = '.(!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'".$this->db->idate($this->eol_date).
"'" :
'null').
',';
561 $sql .=
' manufacturing_date = '.(!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'".$this->db->idate($this->manufacturing_date).
"'" :
'null').
',';
562 $sql .=
' scrapping_date = '.(!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'".$this->db->idate($this->scrapping_date).
"'" :
'null').
',';
564 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
565 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
566 $sql .=
' datec = '.(!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
',';
567 $sql .=
' tms = '.(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
"'".$this->db->idate(
dol_now()).
"'").
',';
568 $sql .=
' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
',';
569 $sql .=
' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
',';
570 $sql .=
' import_key = '.(isset($this->import_key) ? $this->import_key :
"null");
571 $sql .=
' WHERE rowid='.((int) $this->
id);
575 $resql = $this->db->query($sql);
578 $this->errors[] =
'Error '.$this->db->lasterror();
579 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
590 if (!$error && !$notrigger) {
592 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
601 $this->db->rollback();
619 public function delete(
User $user, $notrigger =
false)
628 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
629 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
630 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
631 $sql .= $this->db->plimit(1);
633 $resql = $this->db->query($sql);
635 $obj = $this->db->fetch_object($resql);
638 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
639 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
643 $this->errors[] =
'Error '.$this->db->lasterror();
644 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
648 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
649 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
650 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
651 $sql .= $this->db->plimit(1);
653 $resql = $this->db->query($sql);
655 $obj = $this->db->fetch_object($resql);
658 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
659 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
663 $this->errors[] =
'Error '.$this->db->lasterror();
664 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
681 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
682 $sql .=
' WHERE rowid='.((int) $this->
id);
684 $resql = $this->db->query($sql);
687 $this->errors[] =
'Error '.$this->db->lasterror();
688 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
694 $this->db->rollback();
721 $object->fetch($fromid);
729 $object->context[
'createfromclone'] =
'createfromclone';
730 $result = $object->create($user);
735 $this->errors = $object->errors;
736 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
739 unset($object->context[
'createfromclone']);
747 $this->db->rollback();
762 global $db, $conf, $user, $hookmanager, $action;
764 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
765 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
766 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
767 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
768 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
770 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
771 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
773 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
774 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
775 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
776 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
780 $sql .=
" AND exp.fk_soc = ".((int) $socid);
783 $result = $this->db->query($sql);
785 $obj = $this->db->fetch_object($result);
786 $this->stats_expedition[
'customers'] = $obj->nb_customers;
787 $this->stats_expedition[
'nb'] = $obj->nb;
788 $this->stats_expedition[
'rows'] = $obj->nb_rows;
789 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
815 $parameters = array(
'socid' => $socid);
816 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
818 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
823 $this->error = $this->db->error();
837 global $db, $conf, $user, $hookmanager, $action;
839 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
840 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
841 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur_dispatch as cfdi";
842 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_commandefourndet)";
843 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
845 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
846 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
848 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
849 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
850 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
851 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
855 $sql .=
" AND cf.fk_soc = ".((int) $socid);
858 $result = $this->db->query($sql);
860 $obj = $this->db->fetch_object($result);
861 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
862 $this->stats_supplier_order[
'nb'] = $obj->nb;
863 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
864 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
890 $parameters = array(
'socid' => $socid);
891 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
893 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
898 $this->error = $this->db->error();
912 global $db, $conf, $user, $hookmanager, $action;
914 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
915 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
916 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur_dispatch as cfdi";
917 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
919 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
920 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
922 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
923 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
924 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
925 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
929 $sql .=
" AND recep.fk_soc = ".((int) $socid);
932 $result = $this->db->query($sql);
934 $obj = $this->db->fetch_object($result);
935 $this->stats_reception[
'customers'] = $obj->nb_customers;
936 $this->stats_reception[
'nb'] = $obj->nb;
937 $this->stats_reception[
'rows'] = $obj->nb_rows;
938 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
964 $parameters = array(
'socid' => $socid);
965 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
967 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
972 $this->error = $this->db->error();
986 global $user, $hookmanager, $action;
990 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
991 $this->stats_mo[
'customers_'.$role] = 0;
992 $this->stats_mo[
'nb_'.$role] = 0;
993 $this->stats_mo[
'qty_'.$role] = 0;
995 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
996 $sql .=
" SUM(mp.qty) as qty";
997 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
998 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
999 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
1000 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1003 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1005 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1006 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1008 $sql .=
" AND c.fk_soc = ".((int) $socid);
1011 $result = $this->db->query($sql);
1013 $obj = $this->db->fetch_object($result);
1014 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1015 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1016 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1018 $this->error = $this->db->error();
1023 if (!empty($error)) {
1027 $parameters = array(
'socid' => $socid);
1028 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1030 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1076 global $conf, $langs, $user;
1078 $langs->loadLangs([
'stocks',
'productbatch']);
1080 $option = $params[
'option'] ??
'';
1083 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1085 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1087 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1090 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1109 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1111 global $langs, $conf, $hookmanager;
1116 'objecttype' => $this->element,
1117 'option' => $option,
1119 $classfortooltip =
'classfortooltip';
1122 $classfortooltip =
'classforajaxtooltip';
1123 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1129 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1131 if ($option !=
'nolink') {
1133 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1134 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1135 $add_save_lastsearch_values = 1;
1137 if ($add_save_lastsearch_values) {
1138 $url .=
'&save_lastsearch_values=1';
1143 if (empty($notooltip)) {
1145 $label = $langs->trans(
"ShowMyObject");
1146 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1148 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1149 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1151 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1154 if ($option ==
'nolink') {
1155 $linkstart =
'<span';
1157 $linkstart =
'<a href="'.$url.
'"';
1159 $linkstart .= $linkclose.
'>';
1160 if ($option ==
'nolink') {
1161 $linkend =
'</span>';
1166 $result .= $linkstart;
1168 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1170 if ($withpicto != 2) {
1171 $result .= $this->batch;
1173 $result .= $linkend;
1176 $hookmanager->initHooks(array(
'productlotdao'));
1177 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1178 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1180 $result = $hookmanager->resPrint;
1182 $result .= $hookmanager->resPrint;
1201 $this->
ref =
'SPECIMEN';
1202 $this->specimen = 1;
1204 $this->entity = $conf->entity;
1205 $this->fk_product =
null;
1211 $this->fk_user_creat =
null;
1212 $this->fk_user_modif =
null;
1213 $this->import_key =
'';
1226 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1228 global $conf, $user, $langs;
1230 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1231 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1237 if (!empty($this->model_pdf)) {
1238 $modele = $this->model_pdf;
1240 $modele = $conf->global->PRODUCT_BATCH_ADDON_PDF;
1244 $modelpath =
"core/modules/product_batch/doc/";
1246 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_product()
Load the product with id $this->fk_product into this->product.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage products or services.
Class with list of lots and properties.
loadStatsReception($socid=0)
Charge tableau des stats expedition pour le lot/numéro de série.
getLibStatut($mode=0)
Return label of status of object.
static checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName='')
Check sell or eat by date is mandatory from product id and sell-by and eat-by dates.
getTooltipContentArray($params)
getTooltipContentArray
fetch($id=0, $product_id=0, $batch='')
Load object in memory from the database.
loadStatsExpedition($socid=0)
Charge tableau des stats expedition pour le lot/numéro de série.
LibStatut($status, $mode=0)
Return label of a given status.
getNomUrl($withpicto=0, $option='', $notooltip=0, $maxlen=24, $morecss='', $save_lastsearch_value=-1)
Return a link to the a lot card (with optionaly the picto) Use this->id,this->lastname,...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create a document onto disk according to template module.
loadStatsMo($socid=0)
Charge tableau des stats expedition pour le lot/numéro de série.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
checkSellOrEatByMandatory($onlyFieldName='')
Check sell or eat by date is mandatory.
static checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName='', $alreadyCheckConf=false)
Check sell or eat by date is mandatory from product and sell-by and eat-by dates.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
create(User $user, $notrigger=false)
Create object into database.
loadStatsSupplierOrder($socid=0)
Charge tableau des stats commande fournisseur pour le lot/numéro de série.
update(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.