31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'productlot';
48 public $table_element =
'product_lot';
53 public $picto =
'lot';
55 public $stats_propale;
56 public $stats_commande;
57 public $stats_contrat;
58 public $stats_facture;
59 public $stats_commande_fournisseur;
64 public $stats_expedition;
69 public $stats_reception;
74 public $stats_supplier_order;
78 public $stats_mrptoconsume;
79 public $stats_mrptoproduce;
80 public $stats_facturerec;
81 public $stats_facture_fournisseur;
112 public $fields = array(
113 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
114 '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'),
115 '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),
116 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 20),
117 'sellby' => array(
'type' =>
'date',
'label' =>
'SellByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 60),
118 'eatby' => array(
'type' =>
'date',
'label' =>
'EatByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 62),
119 '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),
120 '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),
121 '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),
123 '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),
124 '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),
125 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
126 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
127 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 500),
128 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
129 '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'),
130 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
131 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000)
162 public $eol_date =
'';
167 public $manufacturing_date =
'';
172 public $scrapping_date =
'';
174 public $qc_frequency =
'';
175 public $lifetime =
'';
181 public $fk_user_creat;
186 public $fk_user_modif;
203 $this->ismultientitymanaged = 1;
218 $errorMsgArr = array();
219 if ($this->fk_product > 0) {
221 $product = $this->product;
223 $errorMsgArr[] = $product->errorsToString();
226 if (empty($errorMsgArr)) {
231 if (!empty($errorMsgArr)) {
232 $this->errors = array_merge($this->errors, $errorMsgArr);
256 $errorMsgArr = array();
257 if ($productId > 0) {
259 $res = $product->fetch($productId);
261 $errorMsgArr[] = $product->errorsToString();
264 if (empty($errorMsgArr)) {
290 $errorMsgArr = array();
291 $checkSellByMandatory =
false;
292 $checkEatByMandatory =
false;
294 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
295 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
296 $checkSellByMandatory =
true;
297 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
298 $checkEatByMandatory =
true;
299 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
300 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
301 $checkSellByMandatory =
true;
303 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
304 $checkEatByMandatory =
true;
308 if ($checkSellByMandatory ===
true) {
309 if (!isset($sellBy) ||
dol_strlen($sellBy) == 0) {
311 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
314 if ($checkEatByMandatory ===
true) {
315 if (!isset($eatBy) ||
dol_strlen($eatBy) == 0) {
317 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
334 global $conf, $langs;
342 if (isset($this->entity)) {
343 $this->entity = (int) $this->entity;
345 if (isset($this->fk_product)) {
346 $this->fk_product = (int) $this->fk_product;
348 if (isset($this->batch)) {
349 $this->batch = trim($this->batch);
351 if (isset($this->fk_user_creat)) {
352 $this->fk_user_creat = (int) $this->fk_user_creat;
354 if (isset($this->fk_user_modif)) {
355 $this->fk_user_modif = (int) $this->fk_user_modif;
357 if (isset($this->import_key)) {
358 $this->import_key = trim($this->import_key);
362 if ($this->batch ===
'') {
363 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
364 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
375 $sql =
'INSERT INTO ' . $this->db->prefix() . $this->table_element .
'(';
377 $sql .=
'fk_product,';
382 $sql .=
'manufacturing_date,';
383 $sql .=
'scrapping_date,';
385 $sql .=
'qc_frequency,';
388 $sql .=
'fk_user_creat,';
389 $sql .=
'fk_user_modif,';
390 $sql .=
'import_key';
391 $sql .=
') VALUES (';
392 $sql .=
' ' . (!isset($this->entity) ? $conf->entity : $this->entity) .
',';
393 $sql .=
' ' . (!isset($this->fk_product) ?
'NULL' : $this->fk_product) .
',';
394 $sql .=
' ' . (!isset($this->batch) ?
'NULL' :
"'" . $this->db->escape($this->batch) .
"'") .
',';
395 $sql .=
' ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eatby) .
"'") .
',';
396 $sql .=
' ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->sellby) .
"'") .
',';
397 $sql .=
' ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eol_date) .
"'") .
',';
398 $sql .=
' ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->manufacturing_date) .
"'") .
',';
399 $sql .=
' ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->scrapping_date) .
"'") .
',';
401 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : $this->qc_frequency).
',';
402 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : $this->lifetime).
',';
403 $sql .=
' ' .
"'" . $this->db->idate(
dol_now()) .
"'" .
',';
404 $sql .=
' ' . (!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat) .
',';
405 $sql .=
' ' . (!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif) .
',';
406 $sql .=
' ' . (!isset($this->import_key) ?
'NULL' : $this->import_key);
411 $resql = $this->db->query($sql);
414 $this->errors[] =
'Error ' . $this->db->lasterror();
418 $this->
id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
428 if (!$error && !$notrigger) {
430 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
440 $this->db->rollback();
447 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
463 public function fetch($id = 0, $product_id = 0, $batch =
'')
470 $sql .=
" t.entity,";
471 $sql .=
" t.fk_product,";
474 $sql .=
" t.sellby,";
475 $sql .=
" t.eol_date,";
476 $sql .=
" t.manufacturing_date,";
477 $sql .=
" t.scrapping_date,";
479 $sql .=
" t.qc_frequency,";
480 $sql .=
" t.lifetime,";
481 $sql .=
" t.model_pdf,";
482 $sql .=
" t.last_main_doc,";
485 $sql .=
" t.fk_user_creat,";
486 $sql .=
" t.fk_user_modif,";
487 $sql .=
" t.import_key,";
488 $sql .=
" t.note_public,";
489 $sql .=
" t.note_private";
490 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
491 if ($product_id > 0 && $batch !=
'') {
492 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
494 $sql .=
" WHERE t.rowid = ".((int) $id);
497 $resql = $this->db->query($sql);
499 $numrows = $this->db->num_rows($resql);
501 $obj = $this->db->fetch_object($resql);
503 $this->
id = $obj->rowid;
504 $this->
ref = $obj->rowid;
507 $this->batch = $obj->batch;
508 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
509 $this->fk_product = $obj->fk_product;
510 $this->eatby = $this->db->jdate($obj->eatby);
511 $this->sellby = $this->db->jdate($obj->sellby);
512 $this->eol_date = $this->db->jdate($obj->eol_date);
513 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
514 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
516 $this->qc_frequency = $obj->qc_frequency;
517 $this->lifetime = $obj->lifetime;
518 $this->model_pdf = $obj->model_pdf;
519 $this->last_main_doc = $obj->last_main_doc;
521 $this->datec = $this->db->jdate($obj->datec);
522 $this->tms = $this->db->jdate($obj->tms);
523 $this->fk_user_creat = $obj->fk_user_creat;
524 $this->fk_user_modif = $obj->fk_user_modif;
525 $this->import_key = $obj->import_key;
526 $this->note_public = $obj->note_public;
527 $this->note_private = $obj->note_private;
533 $this->db->free($resql);
541 $this->errors[] =
'Error '.$this->db->lasterror();
542 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
563 if (isset($this->entity)) {
564 $this->entity = (int) $this->entity;
566 if (isset($this->fk_product)) {
567 $this->fk_product = (int) $this->fk_product;
569 if (isset($this->batch)) {
570 $this->batch = trim($this->batch);
572 if (isset($this->fk_user_creat)) {
573 $this->fk_user_creat = (int) $this->fk_user_creat;
575 if (isset($this->fk_user_modif)) {
576 $this->fk_user_modif = (int) $this->fk_user_modif;
578 if (isset($this->import_key)) {
579 $this->import_key = trim($this->import_key);
590 if (empty($this->oldcopy)) {
596 $sql =
'UPDATE ' . $this->db->prefix() . $this->table_element .
' SET';
597 $sql .=
' entity = ' . (isset($this->entity) ? $this->entity :
"null") .
',';
598 $sql .=
' fk_product = ' . (isset($this->fk_product) ? $this->fk_product :
"null") .
',';
599 $sql .=
' batch = ' . (isset($this->batch) ?
"'" . $this->db->escape($this->batch) .
"'" :
"null") .
',';
600 $sql .=
' eatby = ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'" . $this->db->idate($this->eatby) .
"'" :
'null') .
',';
601 $sql .=
' sellby = ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'" . $this->db->idate($this->sellby) .
"'" :
'null') .
',';
602 $sql .=
' eol_date = ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'" . $this->db->idate($this->eol_date) .
"'" :
'null') .
',';
603 $sql .=
' manufacturing_date = ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'" . $this->db->idate($this->manufacturing_date) .
"'" :
'null') .
',';
604 $sql .=
' scrapping_date = ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'" . $this->db->idate($this->scrapping_date) .
"'" :
'null') .
',';
606 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
607 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
608 $sql .=
' datec = ' . (!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'" . $this->db->idate($this->datec) .
"'" :
'null') .
',';
609 $sql .=
' tms = ' . (
dol_strlen($this->tms) != 0 ?
"'" . $this->db->idate($this->tms) .
"'" :
"'" . $this->db->idate(
dol_now()) .
"'") .
',';
610 $sql .=
' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat :
"null") .
',';
611 $sql .=
' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif :
"null") .
',';
612 $sql .=
' import_key = ' . (isset($this->import_key) ? $this->import_key :
"null");
613 $sql .=
' WHERE rowid=' . ((int) $this->
id);
617 $resql = $this->db->query($sql);
620 $this->errors[] =
'Error ' . $this->db->lasterror();
631 if (!$error && !$notrigger) {
633 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
642 $this->db->rollback();
649 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
663 public function delete(
User $user, $notrigger = 0)
672 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
673 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
674 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
675 $sql .= $this->db->plimit(1);
677 $resql = $this->db->query($sql);
679 $obj = $this->db->fetch_object($resql);
682 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
683 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
687 $this->errors[] =
'Error '.$this->db->lasterror();
688 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
692 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
693 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
694 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
695 $sql .= $this->db->plimit(1);
697 $resql = $this->db->query($sql);
699 $obj = $this->db->fetch_object($resql);
702 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
703 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
707 $this->errors[] =
'Error '.$this->db->lasterror();
708 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
725 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
726 $sql .=
' WHERE rowid='.((int) $this->
id);
728 $resql = $this->db->query($sql);
731 $this->errors[] =
'Error '.$this->db->lasterror();
732 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
738 $this->db->rollback();
773 $object->context[
'createfromclone'] =
'createfromclone';
774 $result =
$object->create($user);
779 $this->errors =
$object->errors;
780 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
783 unset(
$object->context[
'createfromclone']);
791 $this->db->rollback();
806 global $user, $hookmanager, $action;
808 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
809 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
810 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
811 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
812 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
814 if (!$user->hasRight(
'societe',
'client',
'voir')) {
815 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
817 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
818 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
819 if (!$user->hasRight(
'societe',
'client',
'voir')) {
820 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
824 $sql .=
" AND exp.fk_soc = ".((int) $socid);
827 $result = $this->db->query($sql);
829 $obj = $this->db->fetch_object($result);
830 $this->stats_expedition[
'customers'] = $obj->nb_customers;
831 $this->stats_expedition[
'nb'] = $obj->nb;
832 $this->stats_expedition[
'rows'] = $obj->nb_rows;
833 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
859 $parameters = array(
'socid' => $socid);
860 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
862 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
867 $this->error = $this->db->error();
881 global $user, $hookmanager, $action;
883 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
884 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
885 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
886 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
887 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
889 if (!$user->hasRight(
'societe',
'client',
'voir')) {
890 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
892 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
893 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
894 if (!$user->hasRight(
'societe',
'client',
'voir')) {
895 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
899 $sql .=
" AND cf.fk_soc = ".((int) $socid);
902 $result = $this->db->query($sql);
904 $obj = $this->db->fetch_object($result);
905 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
906 $this->stats_supplier_order[
'nb'] = $obj->nb;
907 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
908 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
934 $parameters = array(
'socid' => $socid);
935 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
937 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
942 $this->error = $this->db->error();
956 global $user, $hookmanager, $action;
958 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
959 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
960 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
961 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
963 if (!$user->hasRight(
'societe',
'client',
'voir')) {
964 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
966 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
967 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
968 if (!$user->hasRight(
'societe',
'client',
'voir')) {
969 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
973 $sql .=
" AND recep.fk_soc = ".((int) $socid);
976 $result = $this->db->query($sql);
978 $obj = $this->db->fetch_object($result);
979 $this->stats_reception[
'customers'] = $obj->nb_customers;
980 $this->stats_reception[
'nb'] = $obj->nb;
981 $this->stats_reception[
'rows'] = $obj->nb_rows;
982 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
1008 $parameters = array(
'socid' => $socid);
1009 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
1011 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
1016 $this->error = $this->db->error();
1030 global $user, $hookmanager, $action;
1034 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1035 $this->stats_mo[
'customers_'.$role] = 0;
1036 $this->stats_mo[
'nb_'.$role] = 0;
1037 $this->stats_mo[
'qty_'.$role] = 0;
1039 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1040 $sql .=
" SUM(mp.qty) as qty";
1041 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1042 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
1043 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1044 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1047 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1049 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1050 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1052 $sql .=
" AND c.fk_soc = ".((int) $socid);
1055 $result = $this->db->query($sql);
1057 $obj = $this->db->fetch_object($result);
1058 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1059 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1060 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1062 $this->error = $this->db->error();
1067 if (!empty($error)) {
1071 $parameters = array(
'socid' => $socid);
1072 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1074 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1122 $langs->loadLangs([
'stocks',
'productbatch']);
1127 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1129 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1131 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1134 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1153 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1155 global $langs, $hookmanager;
1160 'objecttype' => $this->element,
1161 'option' => $option,
1163 $classfortooltip =
'classfortooltip';
1166 $classfortooltip =
'classforajaxtooltip';
1167 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1173 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1175 if ($option !=
'nolink') {
1177 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1178 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1179 $add_save_lastsearch_values = 1;
1181 if ($add_save_lastsearch_values) {
1182 $url .=
'&save_lastsearch_values=1';
1187 if (empty($notooltip)) {
1189 $label = $langs->trans(
"ShowMyObject");
1190 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1192 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1193 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1195 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1198 if ($option ==
'nolink') {
1199 $linkstart =
'<span';
1201 $linkstart =
'<a href="'.$url.
'"';
1203 $linkstart .= $linkclose.
'>';
1204 if ($option ==
'nolink') {
1205 $linkend =
'</span>';
1210 $result .= $linkstart;
1212 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1214 if ($withpicto != 2) {
1215 $result .= $this->batch;
1217 $result .= $linkend;
1220 $hookmanager->initHooks(array(
'productlotdao'));
1221 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1222 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1224 $result = $hookmanager->resPrint;
1226 $result .= $hookmanager->resPrint;
1247 $this->
ref =
'SPECIMEN';
1248 $this->specimen = 1;
1250 $this->entity = $conf->entity;
1251 $this->fk_product = 0;
1252 $this->batch =
'ABCD123456';
1253 $this->eatby = $now - 100000;
1254 $this->sellby = $now - 100000;
1255 $this->datec = $now - 3600;
1257 $this->fk_user_creat = 0;
1258 $this->fk_user_modif = 0;
1259 $this->import_key =
'123456';
1274 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1278 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1279 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1285 if (!empty($this->model_pdf)) {
1286 $modele = $this->model_pdf;
1292 $modelpath =
"core/modules/product_batch/doc/";
1294 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1308 if ($fieldKey ==
'batch') {
1309 if (preg_match(
'/\s/', $fieldValue)) {
1310 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1315 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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.