31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'productlot';
48 public $table_element =
'product_lot';
53 public $picto =
'lot';
58 public $stats_propale;
63 public $stats_commande;
68 public $stats_contrat;
73 public $stats_facture;
78 public $stats_commande_fournisseur;
83 public $stats_expedition;
88 public $stats_reception;
93 public $stats_supplier_order;
100 public $stats_mrptoconsume;
101 public $stats_mrptoproduce;
102 public $stats_facturerec;
103 public $stats_facture_fournisseur;
134 public $fields = array(
135 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
136 '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'),
137 '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',
'validate' => 1),
138 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 20),
139 'sellby' => array(
'type' =>
'date',
'label' =>
'SellByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 60),
140 'eatby' => array(
'type' =>
'date',
'label' =>
'EatByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 62),
141 '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),
142 '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),
143 '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),
145 '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),
146 '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),
147 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
148 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
149 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 500),
150 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
151 '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'),
152 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
153 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000)
184 public $eol_date =
'';
189 public $manufacturing_date =
'';
194 public $scrapping_date =
'';
196 public $qc_frequency =
'';
197 public $lifetime =
'';
203 public $fk_user_creat;
208 public $fk_user_modif;
225 $this->ismultientitymanaged = 1;
240 $errorMsgArr = array();
241 if ($this->fk_product > 0) {
243 $product = $this->product;
245 $errorMsgArr[] = $product->errorsToString();
248 if (empty($errorMsgArr)) {
253 if (!empty($errorMsgArr)) {
254 $this->errors = array_merge($this->errors, $errorMsgArr);
278 $errorMsgArr = array();
279 if ($productId > 0) {
281 $res = $product->fetch($productId);
283 $errorMsgArr[] = $product->errorsToString();
286 if (empty($errorMsgArr)) {
312 $errorMsgArr = array();
313 $checkSellByMandatory =
false;
314 $checkEatByMandatory =
false;
316 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
317 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
318 $checkSellByMandatory =
true;
319 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
320 $checkEatByMandatory =
true;
321 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
322 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
323 $checkSellByMandatory =
true;
325 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
326 $checkEatByMandatory =
true;
330 if ($checkSellByMandatory) {
331 if (!isset($sellBy) ||
dol_strlen((
string) $sellBy) == 0) {
333 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
336 if ($checkEatByMandatory) {
337 if (!isset($eatBy) ||
dol_strlen((
string) $eatBy) == 0) {
339 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
356 global $conf, $langs;
364 if (isset($this->entity)) {
365 $this->entity = (int) $this->entity;
367 if (isset($this->fk_product)) {
368 $this->fk_product = (int) $this->fk_product;
370 if (isset($this->batch)) {
371 $this->batch = trim($this->batch);
373 if (isset($this->fk_user_creat)) {
374 $this->fk_user_creat = (int) $this->fk_user_creat;
376 if (isset($this->fk_user_modif)) {
377 $this->fk_user_modif = (int) $this->fk_user_modif;
379 if (isset($this->import_key)) {
380 $this->import_key = trim($this->import_key);
384 if ($this->batch ===
'') {
385 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
386 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
397 $sql =
'INSERT INTO ' . $this->db->prefix() . $this->table_element .
'(';
399 $sql .=
'fk_product,';
404 $sql .=
'manufacturing_date,';
405 $sql .=
'scrapping_date,';
407 $sql .=
'qc_frequency,';
410 $sql .=
'fk_user_creat,';
411 $sql .=
'fk_user_modif,';
412 $sql .=
'import_key';
413 $sql .=
') VALUES (';
414 $sql .=
' ' . (!isset($this->entity) ? $conf->entity : $this->entity) .
',';
415 $sql .=
' ' . (!isset($this->fk_product) ?
'NULL' : $this->fk_product) .
',';
416 $sql .=
' ' . (!isset($this->batch) ?
'NULL' :
"'" . $this->db->escape($this->batch) .
"'") .
',';
417 $sql .=
' ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eatby) .
"'") .
',';
418 $sql .=
' ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->sellby) .
"'") .
',';
419 $sql .=
' ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eol_date) .
"'") .
',';
420 $sql .=
' ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->manufacturing_date) .
"'") .
',';
421 $sql .=
' ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->scrapping_date) .
"'") .
',';
423 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : $this->qc_frequency).
',';
424 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : $this->lifetime).
',';
425 $sql .=
' ' .
"'" . $this->db->idate(
dol_now()) .
"'" .
',';
426 $sql .=
' ' . (!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat) .
',';
427 $sql .=
' ' . (!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif) .
',';
428 $sql .=
' ' . (!isset($this->import_key) ?
'NULL' : $this->import_key);
433 $resql = $this->db->query($sql);
436 $this->errors[] =
'Error ' . $this->db->lasterror();
440 $this->
id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
450 if (!$error && !$notrigger) {
452 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
462 $this->db->rollback();
469 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
485 public function fetch($id = 0, $product_id = 0, $batch =
'')
492 $sql .=
" t.entity,";
493 $sql .=
" t.fk_product,";
496 $sql .=
" t.sellby,";
497 $sql .=
" t.eol_date,";
498 $sql .=
" t.manufacturing_date,";
499 $sql .=
" t.scrapping_date,";
501 $sql .=
" t.qc_frequency,";
502 $sql .=
" t.lifetime,";
503 $sql .=
" t.model_pdf,";
504 $sql .=
" t.last_main_doc,";
507 $sql .=
" t.fk_user_creat,";
508 $sql .=
" t.fk_user_modif,";
509 $sql .=
" t.import_key,";
510 $sql .=
" t.note_public,";
511 $sql .=
" t.note_private";
512 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
513 if ($product_id > 0 && $batch !=
'') {
514 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
516 $sql .=
" WHERE t.rowid = ".((int) $id);
519 $resql = $this->db->query($sql);
521 $numrows = $this->db->num_rows($resql);
523 $obj = $this->db->fetch_object($resql);
525 $this->
id = $obj->rowid;
526 $this->
ref = $obj->rowid;
529 $this->batch = $obj->batch;
530 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
531 $this->fk_product = $obj->fk_product;
532 $this->eatby = $this->db->jdate($obj->eatby);
533 $this->sellby = $this->db->jdate($obj->sellby);
534 $this->eol_date = $this->db->jdate($obj->eol_date);
535 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
536 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
538 $this->qc_frequency = $obj->qc_frequency;
539 $this->lifetime = $obj->lifetime;
540 $this->model_pdf = $obj->model_pdf;
541 $this->last_main_doc = $obj->last_main_doc;
543 $this->datec = $this->db->jdate($obj->datec);
544 $this->tms = $this->db->jdate($obj->tms);
545 $this->fk_user_creat = $obj->fk_user_creat;
546 $this->fk_user_modif = $obj->fk_user_modif;
547 $this->import_key = $obj->import_key;
548 $this->note_public = $obj->note_public;
549 $this->note_private = $obj->note_private;
555 $this->db->free($resql);
563 $this->errors[] =
'Error '.$this->db->lasterror();
564 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
585 if (isset($this->entity)) {
586 $this->entity = (int) $this->entity;
588 if (isset($this->fk_product)) {
589 $this->fk_product = (int) $this->fk_product;
591 if (isset($this->batch)) {
592 $this->batch = trim($this->batch);
594 if (isset($this->fk_user_creat)) {
595 $this->fk_user_creat = (int) $this->fk_user_creat;
597 if (isset($this->fk_user_modif)) {
598 $this->fk_user_modif = (int) $this->fk_user_modif;
600 if (isset($this->import_key)) {
601 $this->import_key = trim($this->import_key);
612 if (empty($this->oldcopy)) {
618 $sql =
'UPDATE ' . $this->db->prefix() . $this->table_element .
' SET';
619 $sql .=
' entity = ' . (isset($this->entity) ? $this->entity :
"null") .
',';
620 $sql .=
' fk_product = ' . (isset($this->fk_product) ? $this->fk_product :
"null") .
',';
621 $sql .=
' batch = ' . (isset($this->batch) ?
"'" . $this->db->escape($this->batch) .
"'" :
"null") .
',';
622 $sql .=
' eatby = ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'" . $this->db->idate($this->eatby) .
"'" :
'null') .
',';
623 $sql .=
' sellby = ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'" . $this->db->idate($this->sellby) .
"'" :
'null') .
',';
624 $sql .=
' eol_date = ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'" . $this->db->idate($this->eol_date) .
"'" :
'null') .
',';
625 $sql .=
' manufacturing_date = ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'" . $this->db->idate($this->manufacturing_date) .
"'" :
'null') .
',';
626 $sql .=
' scrapping_date = ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'" . $this->db->idate($this->scrapping_date) .
"'" :
'null') .
',';
628 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
629 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
630 $sql .=
' datec = ' . (!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'" . $this->db->idate($this->datec) .
"'" :
'null') .
',';
631 $sql .=
' tms = ' . (
dol_strlen((
string) $this->tms) != 0 ?
"'" . $this->db->idate($this->tms) .
"'" :
"'" . $this->db->idate(
dol_now()) .
"'") .
',';
632 $sql .=
' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat :
"null") .
',';
633 $sql .=
' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif :
"null") .
',';
634 $sql .=
' import_key = ' . (isset($this->import_key) ? $this->import_key :
"null");
635 $sql .=
' WHERE rowid=' . ((int) $this->
id);
639 $resql = $this->db->query($sql);
642 $this->errors[] =
'Error ' . $this->db->lasterror();
653 if (!$error && !$notrigger) {
655 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
664 $this->db->rollback();
671 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
685 public function delete(
User $user, $notrigger = 0)
694 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
695 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
696 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
697 $sql .= $this->db->plimit(1);
699 $resql = $this->db->query($sql);
701 $obj = $this->db->fetch_object($resql);
704 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
705 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
709 $this->errors[] =
'Error '.$this->db->lasterror();
710 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
714 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
715 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
716 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
717 $sql .= $this->db->plimit(1);
719 $resql = $this->db->query($sql);
721 $obj = $this->db->fetch_object($resql);
724 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
725 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
729 $this->errors[] =
'Error '.$this->db->lasterror();
730 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
747 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
748 $sql .=
' WHERE rowid='.((int) $this->
id);
750 $resql = $this->db->query($sql);
753 $this->errors[] =
'Error '.$this->db->lasterror();
754 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
760 $this->db->rollback();
795 $object->context[
'createfromclone'] =
'createfromclone';
796 $result =
$object->create($user);
801 $this->errors =
$object->errors;
802 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
805 unset(
$object->context[
'createfromclone']);
813 $this->db->rollback();
828 global $user, $hookmanager, $action;
830 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
831 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
832 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
833 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
834 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
836 if (!$user->hasRight(
'societe',
'client',
'voir')) {
837 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
839 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
840 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
841 if (!$user->hasRight(
'societe',
'client',
'voir')) {
842 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
846 $sql .=
" AND exp.fk_soc = ".((int) $socid);
849 $result = $this->db->query($sql);
851 $obj = $this->db->fetch_object($result);
852 $this->stats_expedition[
'customers'] = $obj->nb_customers;
853 $this->stats_expedition[
'nb'] = $obj->nb;
854 $this->stats_expedition[
'rows'] = $obj->nb_rows;
855 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
881 $parameters = array(
'socid' => $socid);
882 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
884 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
889 $this->error = $this->db->error();
903 global $user, $hookmanager, $action;
905 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
906 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
907 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
908 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
909 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
911 if (!$user->hasRight(
'societe',
'client',
'voir')) {
912 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
914 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
915 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
916 if (!$user->hasRight(
'societe',
'client',
'voir')) {
917 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
921 $sql .=
" AND cf.fk_soc = ".((int) $socid);
924 $result = $this->db->query($sql);
926 $obj = $this->db->fetch_object($result);
927 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
928 $this->stats_supplier_order[
'nb'] = $obj->nb;
929 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
930 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
956 $parameters = array(
'socid' => $socid);
957 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
959 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
964 $this->error = $this->db->error();
978 global $user, $hookmanager, $action;
980 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
981 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
982 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
983 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
985 if (!$user->hasRight(
'societe',
'client',
'voir')) {
986 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
988 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
989 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
990 if (!$user->hasRight(
'societe',
'client',
'voir')) {
991 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
995 $sql .=
" AND recep.fk_soc = ".((int) $socid);
998 $result = $this->db->query($sql);
1000 $obj = $this->db->fetch_object($result);
1001 $this->stats_reception[
'customers'] = $obj->nb_customers;
1002 $this->stats_reception[
'nb'] = $obj->nb;
1003 $this->stats_reception[
'rows'] = $obj->nb_rows;
1004 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
1030 $parameters = array(
'socid' => $socid);
1031 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
1033 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
1038 $this->error = $this->db->error();
1052 global $user, $hookmanager, $action;
1056 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1057 $this->stats_mo[
'customers_'.$role] = 0;
1058 $this->stats_mo[
'nb_'.$role] = 0;
1059 $this->stats_mo[
'qty_'.$role] = 0;
1061 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1062 $sql .=
" SUM(mp.qty) as qty";
1063 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1064 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
1065 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1066 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1069 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1071 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1072 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1074 $sql .=
" AND c.fk_soc = ".((int) $socid);
1077 $result = $this->db->query($sql);
1079 $obj = $this->db->fetch_object($result);
1080 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1081 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1082 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1084 $this->error = $this->db->error();
1089 if (!empty($error)) {
1093 $parameters = array(
'socid' => $socid);
1094 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1096 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1143 $langs->loadLangs([
'stocks',
'productbatch']);
1148 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1150 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1152 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1155 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1174 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1176 global $langs, $hookmanager;
1181 'objecttype' => $this->element,
1182 'option' => $option,
1184 $classfortooltip =
'classfortooltip';
1187 $classfortooltip =
'classforajaxtooltip';
1188 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1194 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1196 if ($option !=
'nolink') {
1198 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1199 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1200 $add_save_lastsearch_values = 1;
1202 if ($add_save_lastsearch_values) {
1203 $url .=
'&save_lastsearch_values=1';
1208 if (empty($notooltip)) {
1210 $label = $langs->trans(
"ShowMyObject");
1211 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1213 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1214 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1216 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1219 if ($option ==
'nolink') {
1220 $linkstart =
'<span';
1222 $linkstart =
'<a href="'.$url.
'"';
1224 $linkstart .= $linkclose.
'>';
1225 if ($option ==
'nolink') {
1226 $linkend =
'</span>';
1231 $result .= $linkstart;
1233 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1235 if ($withpicto != 2) {
1236 $result .= $this->batch;
1238 $result .= $linkend;
1241 $hookmanager->initHooks(array(
'productlotdao'));
1242 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1243 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1245 $result = $hookmanager->resPrint;
1247 $result .= $hookmanager->resPrint;
1268 $this->
ref =
'SPECIMEN';
1269 $this->specimen = 1;
1271 $this->entity = $conf->entity;
1272 $this->fk_product = 0;
1273 $this->batch =
'ABCD123456';
1274 $this->eatby = $now - 100000;
1275 $this->sellby = $now - 100000;
1276 $this->datec = $now - 3600;
1278 $this->fk_user_creat = 0;
1279 $this->fk_user_modif = 0;
1280 $this->import_key =
'123456';
1295 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1299 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1300 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1306 if (!empty($this->model_pdf)) {
1307 $modele = $this->model_pdf;
1313 $modelpath =
"core/modules/product_batch/doc/";
1315 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1329 if ($fieldKey ==
'batch') {
1330 if (preg_match(
'/\s/', $fieldValue)) {
1331 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1336 return parent::validateField($fields, $fieldKey, $fieldValue);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
update(User $user, $notrigger=0)
Update object into database.
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 optionally 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.
create(User $user, $notrigger=0)
Create object into database.
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.
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
loadStatsSupplierOrder($socid=0)
Charge tableau des stats commande fournisseur pour le lot/numéro de série.
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.