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;
106 public $stats_mrptoconsume;
110 public $stats_mrptoproduce;
114 public $stats_facturerec;
118 public $stats_facture_fournisseur;
149 public $fields = array(
150 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
151 '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'),
152 '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),
153 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 20),
154 'sellby' => array(
'type' =>
'date',
'label' =>
'SellByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 60),
155 'eatby' => array(
'type' =>
'date',
'label' =>
'EatByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 62),
156 '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),
157 '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),
158 '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),
160 '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),
161 '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),
162 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
163 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
164 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 500),
165 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
166 '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'),
167 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
168 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000)
199 public $eol_date =
'';
204 public $manufacturing_date =
'';
209 public $scrapping_date =
'';
214 public $qc_frequency =
'';
218 public $lifetime =
'';
227 public $fk_user_creat;
232 public $fk_user_modif;
249 $this->ismultientitymanaged = 1;
264 $errorMsgArr = array();
265 if ($this->fk_product > 0) {
267 $product = $this->product;
269 $errorMsgArr[] = $product->errorsToString();
272 if (empty($errorMsgArr)) {
277 if (!empty($errorMsgArr)) {
278 $this->errors = array_merge($this->errors, $errorMsgArr);
302 $errorMsgArr = array();
303 if ($productId > 0) {
305 $res = $product->fetch($productId);
307 $errorMsgArr[] = $product->errorsToString();
310 if (empty($errorMsgArr)) {
336 $errorMsgArr = array();
337 $checkSellByMandatory =
false;
338 $checkEatByMandatory =
false;
340 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
341 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
342 $checkSellByMandatory =
true;
343 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
344 $checkEatByMandatory =
true;
345 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
346 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
347 $checkSellByMandatory =
true;
349 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
350 $checkEatByMandatory =
true;
354 if ($checkSellByMandatory) {
355 if (!isset($sellBy) ||
dol_strlen((
string) $sellBy) == 0) {
357 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
360 if ($checkEatByMandatory) {
361 if (!isset($eatBy) ||
dol_strlen((
string) $eatBy) == 0) {
363 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
380 global
$conf, $langs;
388 if (isset($this->entity)) {
389 $this->entity = (int) $this->entity;
391 if (isset($this->fk_product)) {
392 $this->fk_product = (int) $this->fk_product;
394 if (isset($this->batch)) {
395 $this->batch = trim($this->batch);
397 if (isset($this->fk_user_creat)) {
398 $this->fk_user_creat = (int) $this->fk_user_creat;
400 if (isset($this->fk_user_modif)) {
401 $this->fk_user_modif = (int) $this->fk_user_modif;
403 if (isset($this->import_key)) {
404 $this->import_key = trim($this->import_key);
408 if ($this->batch ===
'') {
409 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
410 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
421 $sql =
'INSERT INTO ' . $this->db->prefix() . $this->table_element .
'(';
423 $sql .=
'fk_product,';
428 $sql .=
'manufacturing_date,';
429 $sql .=
'scrapping_date,';
431 $sql .=
'qc_frequency,';
434 $sql .=
'fk_user_creat,';
435 $sql .=
'fk_user_modif,';
436 $sql .=
'import_key';
437 $sql .=
') VALUES (';
438 $sql .=
' ' . (!isset($this->entity) ?
$conf->entity : $this->entity) .
',';
439 $sql .=
' ' . (!isset($this->fk_product) ?
'NULL' : $this->fk_product) .
',';
440 $sql .=
' ' . (!isset($this->batch) ?
'NULL' :
"'" . $this->db->escape($this->batch) .
"'") .
',';
441 $sql .=
' ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eatby) .
"'") .
',';
442 $sql .=
' ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->sellby) .
"'") .
',';
443 $sql .=
' ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eol_date) .
"'") .
',';
444 $sql .=
' ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->manufacturing_date) .
"'") .
',';
445 $sql .=
' ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->scrapping_date) .
"'") .
',';
447 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : $this->qc_frequency).
',';
448 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : $this->lifetime).
',';
449 $sql .=
' ' .
"'" . $this->db->idate(
dol_now()) .
"'" .
',';
450 $sql .=
' ' . (!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat) .
',';
451 $sql .=
' ' . (!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif) .
',';
452 $sql .=
' ' . (!isset($this->import_key) ?
'NULL' : $this->import_key);
457 $resql = $this->db->query($sql);
460 $this->errors[] =
'Error ' . $this->db->lasterror();
464 $this->
id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
474 if (!$error && !$notrigger) {
476 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
486 $this->db->rollback();
493 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
509 public function fetch($id = 0, $product_id = 0, $batch =
'')
516 $sql .=
" t.entity,";
517 $sql .=
" t.fk_product,";
520 $sql .=
" t.sellby,";
521 $sql .=
" t.eol_date,";
522 $sql .=
" t.manufacturing_date,";
523 $sql .=
" t.scrapping_date,";
525 $sql .=
" t.qc_frequency,";
526 $sql .=
" t.lifetime,";
527 $sql .=
" t.model_pdf,";
528 $sql .=
" t.last_main_doc,";
531 $sql .=
" t.fk_user_creat,";
532 $sql .=
" t.fk_user_modif,";
533 $sql .=
" t.import_key,";
534 $sql .=
" t.note_public,";
535 $sql .=
" t.note_private";
536 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
537 if ($product_id > 0 && $batch !=
'') {
538 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
540 $sql .=
" WHERE t.rowid = ".((int) $id);
543 $resql = $this->db->query($sql);
545 $numrows = $this->db->num_rows($resql);
547 $obj = $this->db->fetch_object($resql);
549 $this->
id = $obj->rowid;
550 $this->
ref = $obj->rowid;
553 $this->batch = $obj->batch;
554 $this->entity = (!empty($obj->entity) ? $obj->entity :
$conf->entity);
555 $this->fk_product = $obj->fk_product;
556 $this->eatby = $this->db->jdate($obj->eatby);
557 $this->sellby = $this->db->jdate($obj->sellby);
558 $this->eol_date = $this->db->jdate($obj->eol_date);
559 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
560 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
562 $this->qc_frequency = $obj->qc_frequency;
563 $this->lifetime = $obj->lifetime;
564 $this->model_pdf = $obj->model_pdf;
565 $this->last_main_doc = $obj->last_main_doc;
567 $this->datec = $this->db->jdate($obj->datec);
568 $this->tms = $this->db->jdate($obj->tms);
569 $this->fk_user_creat = $obj->fk_user_creat;
570 $this->fk_user_modif = $obj->fk_user_modif;
571 $this->import_key = $obj->import_key;
572 $this->note_public = $obj->note_public;
573 $this->note_private = $obj->note_private;
579 $this->db->free($resql);
587 $this->errors[] =
'Error '.$this->db->lasterror();
588 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
609 if (isset($this->entity)) {
610 $this->entity = (int) $this->entity;
612 if (isset($this->fk_product)) {
613 $this->fk_product = (int) $this->fk_product;
615 if (isset($this->batch)) {
616 $this->batch = trim($this->batch);
618 if (isset($this->fk_user_creat)) {
619 $this->fk_user_creat = (int) $this->fk_user_creat;
621 if (isset($this->fk_user_modif)) {
622 $this->fk_user_modif = (int) $this->fk_user_modif;
624 if (isset($this->import_key)) {
625 $this->import_key = trim($this->import_key);
636 if (empty($this->oldcopy)) {
642 $sql =
'UPDATE ' . $this->db->prefix() . $this->table_element .
' SET';
643 $sql .=
' entity = ' . (isset($this->entity) ? $this->entity :
"null") .
',';
644 $sql .=
' fk_product = ' . (isset($this->fk_product) ? $this->fk_product :
"null") .
',';
645 $sql .=
' batch = ' . (isset($this->batch) ?
"'" . $this->db->escape($this->batch) .
"'" :
"null") .
',';
646 $sql .=
' eatby = ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'" . $this->db->idate($this->eatby) .
"'" :
'null') .
',';
647 $sql .=
' sellby = ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'" . $this->db->idate($this->sellby) .
"'" :
'null') .
',';
648 $sql .=
' eol_date = ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'" . $this->db->idate($this->eol_date) .
"'" :
'null') .
',';
649 $sql .=
' manufacturing_date = ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'" . $this->db->idate($this->manufacturing_date) .
"'" :
'null') .
',';
650 $sql .=
' scrapping_date = ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'" . $this->db->idate($this->scrapping_date) .
"'" :
'null') .
',';
652 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
653 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
654 $sql .=
' datec = ' . (
dol_strlen((
string) $this->datec) != 0 ?
"'" . $this->db->idate($this->datec) .
"'" :
'null') .
',';
655 $sql .=
' tms = ' . (
dol_strlen((
string) $this->tms) != 0 ?
"'" . $this->db->idate($this->tms) .
"'" :
"'" . $this->db->idate(
dol_now()) .
"'") .
',';
656 $sql .=
' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat :
"null") .
',';
657 $sql .=
' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif :
"null") .
',';
658 $sql .=
' import_key = ' . (isset($this->import_key) ? $this->import_key :
"null");
659 $sql .=
' WHERE rowid=' . ((int) $this->
id);
663 $resql = $this->db->query($sql);
666 $this->errors[] =
'Error ' . $this->db->lasterror();
677 if (!$error && !$notrigger) {
679 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
688 $this->db->rollback();
695 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
709 public function delete(
User $user, $notrigger = 0)
718 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
719 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
720 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
721 $sql .= $this->db->plimit(1);
723 $resql = $this->db->query($sql);
725 $obj = $this->db->fetch_object($resql);
728 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
729 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
733 $this->errors[] =
'Error '.$this->db->lasterror();
734 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
738 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
739 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
740 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
741 $sql .= $this->db->plimit(1);
743 $resql = $this->db->query($sql);
745 $obj = $this->db->fetch_object($resql);
748 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
749 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
753 $this->errors[] =
'Error '.$this->db->lasterror();
754 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
771 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
772 $sql .=
' WHERE rowid='.((int) $this->
id);
774 $resql = $this->db->query($sql);
777 $this->errors[] =
'Error '.$this->db->lasterror();
778 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
784 $this->db->rollback();
819 $object->context[
'createfromclone'] =
'createfromclone';
820 $result =
$object->create($user);
825 $this->errors =
$object->errors;
826 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
829 unset(
$object->context[
'createfromclone']);
837 $this->db->rollback();
851 global $user, $hookmanager, $action;
853 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
854 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
855 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
856 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
857 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
859 if (!$user->hasRight(
'societe',
'client',
'voir')) {
860 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
862 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
863 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
864 if (!$user->hasRight(
'societe',
'client',
'voir')) {
865 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
869 $sql .=
" AND exp.fk_soc = ".((int) $socid);
872 $result = $this->db->query($sql);
874 $obj = $this->db->fetch_object($result);
875 $this->stats_expedition[
'customers'] = $obj->nb_customers;
876 $this->stats_expedition[
'nb'] = $obj->nb;
877 $this->stats_expedition[
'rows'] = $obj->nb_rows;
878 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
904 $parameters = array(
'socid' => $socid);
905 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
907 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
912 $this->error = $this->db->error();
925 global $user, $hookmanager, $action;
927 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
928 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
929 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
930 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
931 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
933 if (!$user->hasRight(
'societe',
'client',
'voir')) {
934 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
936 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
937 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
938 if (!$user->hasRight(
'societe',
'client',
'voir')) {
939 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
943 $sql .=
" AND cf.fk_soc = ".((int) $socid);
946 $result = $this->db->query($sql);
948 $obj = $this->db->fetch_object($result);
949 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
950 $this->stats_supplier_order[
'nb'] = $obj->nb;
951 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
952 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
978 $parameters = array(
'socid' => $socid);
979 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
981 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
986 $this->error = $this->db->error();
999 global $user, $hookmanager, $action;
1001 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
1002 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
1003 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
1004 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
1006 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1007 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
1009 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
1010 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
1011 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1012 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1016 $sql .=
" AND recep.fk_soc = ".((int) $socid);
1019 $result = $this->db->query($sql);
1021 $obj = $this->db->fetch_object($result);
1022 $this->stats_reception[
'customers'] = $obj->nb_customers;
1023 $this->stats_reception[
'nb'] = $obj->nb;
1024 $this->stats_reception[
'rows'] = $obj->nb_rows;
1025 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
1051 $parameters = array(
'socid' => $socid);
1052 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
1054 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
1059 $this->error = $this->db->error();
1072 global $user, $hookmanager, $action;
1076 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1077 $this->stats_mo[
'customers_'.$role] = 0;
1078 $this->stats_mo[
'nb_'.$role] = 0;
1079 $this->stats_mo[
'qty_'.$role] = 0;
1081 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1082 $sql .=
" SUM(mp.qty) as qty";
1083 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1084 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
1085 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1086 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1089 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1091 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1092 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1094 $sql .=
" AND c.fk_soc = ".((int) $socid);
1097 $result = $this->db->query($sql);
1099 $obj = $this->db->fetch_object($result);
1100 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1101 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1102 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1104 $this->error = $this->db->error();
1109 if (!empty($error)) {
1113 $parameters = array(
'socid' => $socid);
1114 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1116 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1163 $langs->loadLangs([
'stocks',
'productbatch']);
1168 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1170 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1172 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1175 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1194 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1196 global $langs, $hookmanager;
1201 'objecttype' => $this->element,
1202 'option' => $option,
1204 $classfortooltip =
'classfortooltip';
1207 $classfortooltip =
'classforajaxtooltip';
1208 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1214 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1216 if ($option !=
'nolink') {
1218 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1219 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1220 $add_save_lastsearch_values = 1;
1222 if ($add_save_lastsearch_values) {
1223 $url .=
'&save_lastsearch_values=1';
1228 if (empty($notooltip)) {
1230 $label = $langs->trans(
"ShowMyObject");
1231 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1233 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1234 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1236 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1239 if ($option ==
'nolink') {
1240 $linkstart =
'<span';
1242 $linkstart =
'<a href="'.$url.
'"';
1244 $linkstart .= $linkclose.
'>';
1245 if ($option ==
'nolink') {
1246 $linkend =
'</span>';
1251 $result .= $linkstart;
1253 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1255 if ($withpicto != 2) {
1256 $result .= $this->batch;
1258 $result .= $linkend;
1261 $hookmanager->initHooks(array(
'productlotdao'));
1262 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1263 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1265 $result = $hookmanager->resPrint;
1267 $result .= $hookmanager->resPrint;
1288 $this->
ref =
'SPECIMEN';
1289 $this->specimen = 1;
1291 $this->entity =
$conf->entity;
1292 $this->fk_product = 0;
1293 $this->batch =
'ABCD123456';
1294 $this->eatby = $now - 100000;
1295 $this->sellby = $now - 100000;
1296 $this->datec = $now - 3600;
1298 $this->fk_user_creat = 0;
1299 $this->fk_user_modif = 0;
1300 $this->import_key =
'123456';
1315 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1319 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1320 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1326 if (!empty($this->model_pdf)) {
1327 $modele = $this->model_pdf;
1333 $modelpath =
"core/modules/product_batch/doc/";
1335 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1349 if ($fieldKey ==
'batch') {
1350 if (preg_match(
'/\s/', $fieldValue)) {
1351 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1356 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=2)
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...