32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
44 public $element =
'productlot';
49 public $table_element =
'product_lot';
54 public $picto =
'lot';
59 public $stats_propale;
64 public $stats_commande;
69 public $stats_contrat;
74 public $stats_facture;
79 public $stats_commande_fournisseur;
84 public $stats_expedition;
89 public $stats_reception;
94 public $stats_supplier_order;
107 public $stats_mrptoconsume;
111 public $stats_mrptoproduce;
115 public $stats_facturerec;
119 public $stats_facture_fournisseur;
150 public $fields = array(
151 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
152 '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' =>
'tdoverflowmax250'),
153 '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),
154 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 20),
155 'manufacturing_date' => array(
'type' =>
'date',
'label' =>
'ManufacturingDate',
'enabled' =>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 1 : 0',
'visible' =>
'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 5 : 0',
'position' => 50,
'help' =>
'Date of first manufacturing of the lot'),
156 'sellby' => array(
'type' =>
'date',
'label' =>
'SellByDate',
'enabled' =>
'getDolGlobalInt("PRODUCT_DISABLE_SELLBY") ? 0 : 1',
'visible' => 1,
'notnull' => 0,
'position' => 60),
157 'eatby' => array(
'type' =>
'date',
'label' =>
'EatByDate',
'enabled' =>
'getDolGlobalInt("PRODUCT_DISABLE_EATBY") ? 0 : 1',
'visible' => 1,
'notnull' => 0,
'position' => 62),
158 '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),
159 '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),
161 '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),
162 '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),
163 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
164 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
165 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 500),
166 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
167 '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'),
168 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
169 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000)
195 public $eol_date =
'';
200 public $manufacturing_date =
'';
205 public $scrapping_date =
'';
210 public $qc_frequency =
'';
214 public $lifetime =
'';
223 public $fk_user_creat;
228 public $fk_user_modif;
245 $this->ismultientitymanaged = 1;
246 $this->isextrafieldmanaged = 1;
261 $errorMsgArr = array();
262 if ($this->fk_product > 0) {
264 $product = $this->product;
266 $errorMsgArr[] = $product->errorsToString();
269 if (empty($errorMsgArr)) {
274 if (!empty($errorMsgArr)) {
275 $this->errors = array_merge($this->errors, $errorMsgArr);
299 $errorMsgArr = array();
300 if ($productId > 0) {
302 $res = $product->fetch($productId);
304 $errorMsgArr[] = $product->errorsToString();
307 if (empty($errorMsgArr)) {
333 $errorMsgArr = array();
334 $checkSellByMandatory =
false;
335 $checkEatByMandatory =
false;
337 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
338 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
339 $checkSellByMandatory =
true;
340 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
341 $checkEatByMandatory =
true;
342 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
343 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
344 $checkSellByMandatory =
true;
346 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
347 $checkEatByMandatory =
true;
351 if ($checkSellByMandatory) {
352 if (!isset($sellBy) ||
dol_strlen((
string) $sellBy) == 0) {
354 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
357 if ($checkEatByMandatory) {
358 if (!isset($eatBy) ||
dol_strlen((
string) $eatBy) == 0) {
360 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
377 global
$conf, $langs;
385 if (isset($this->entity)) {
386 $this->entity = (int) $this->entity;
388 if (isset($this->fk_product)) {
389 $this->fk_product = (int) $this->fk_product;
391 if (isset($this->batch)) {
392 $this->batch = trim($this->batch);
394 if (isset($this->fk_user_creat)) {
395 $this->fk_user_creat = (int) $this->fk_user_creat;
397 if (isset($this->fk_user_modif)) {
398 $this->fk_user_modif = (int) $this->fk_user_modif;
400 if (isset($this->import_key)) {
401 $this->import_key = trim($this->import_key);
405 if ($this->batch ===
'') {
406 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
407 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
418 $sql =
'INSERT INTO ' . $this->db->prefix() . $this->table_element .
'(';
420 $sql .=
'fk_product,';
425 $sql .=
'manufacturing_date,';
426 $sql .=
'scrapping_date,';
428 $sql .=
'qc_frequency,';
431 $sql .=
'fk_user_creat,';
432 $sql .=
'fk_user_modif,';
433 $sql .=
'import_key';
434 $sql .=
') VALUES (';
435 $sql .=
' ' . (!isset($this->entity) ? ((int)
$conf->entity) : ((int) $this->entity)) .
',';
436 $sql .=
' ' . (!isset($this->fk_product) ?
'NULL' : ((int) $this->fk_product)) .
',';
437 $sql .=
' ' . (!isset($this->batch) ?
'NULL' :
"'" . $this->db->escape($this->batch) .
"'") .
',';
438 $sql .=
' ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eatby) .
"'") .
',';
439 $sql .=
' ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->sellby) .
"'") .
',';
440 $sql .=
' ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eol_date) .
"'") .
',';
441 $sql .=
' ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->manufacturing_date) .
"'") .
',';
442 $sql .=
' ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->scrapping_date) .
"'") .
',';
444 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : ((int) $this->qc_frequency)).
',';
445 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : ((int) $this->lifetime)).
',';
446 $sql .=
' ' .
"'" . $this->db->idate(
dol_now()) .
"'" .
',';
447 $sql .=
' ' . (!isset($this->fk_user_creat) ?
'NULL' : ((int) $this->fk_user_creat)) .
',';
448 $sql .=
' ' . (!isset($this->fk_user_modif) ?
'NULL' : ((int) $this->fk_user_modif)) .
',';
449 $sql .=
' ' . (!isset($this->import_key) ?
'NULL' :
"'".$this->db->escape($this->import_key).
"'");
454 $resql = $this->db->query($sql);
457 $this->errors[] =
'Error ' . $this->db->lasterror();
461 $this->
id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
471 if (!$error && !$notrigger) {
473 $result = $this->call_trigger(
'PRODUCTLOT_CREATE', $user);
483 $this->db->rollback();
490 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
506 public function fetch($id = 0, $product_id = 0, $batch =
'')
513 $sql .=
" t.entity,";
514 $sql .=
" t.fk_product,";
517 $sql .=
" t.sellby,";
518 $sql .=
" t.eol_date,";
519 $sql .=
" t.manufacturing_date,";
520 $sql .=
" t.scrapping_date,";
522 $sql .=
" t.qc_frequency,";
523 $sql .=
" t.lifetime,";
524 $sql .=
" t.model_pdf,";
525 $sql .=
" t.last_main_doc,";
528 $sql .=
" t.fk_user_creat,";
529 $sql .=
" t.fk_user_modif,";
530 $sql .=
" t.import_key,";
531 $sql .=
" t.note_public,";
532 $sql .=
" t.note_private";
533 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
534 if ($product_id > 0 && $batch !=
'') {
535 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
537 $sql .=
" WHERE t.rowid = ".((int) $id);
540 $resql = $this->db->query($sql);
542 $numrows = $this->db->num_rows($resql);
544 $obj = $this->db->fetch_object($resql);
546 $this->
id = $obj->rowid;
547 $this->
ref = $obj->rowid;
550 $this->batch = $obj->batch;
551 $this->entity = (!empty($obj->entity) ? $obj->entity :
$conf->entity);
552 $this->fk_product = $obj->fk_product;
553 $this->eatby = $this->db->jdate($obj->eatby);
554 $this->sellby = $this->db->jdate($obj->sellby);
555 $this->eol_date = $this->db->jdate($obj->eol_date);
556 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
557 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
559 $this->qc_frequency = $obj->qc_frequency;
560 $this->lifetime = $obj->lifetime;
561 $this->model_pdf = $obj->model_pdf;
562 $this->last_main_doc = $obj->last_main_doc;
564 $this->datec = $this->db->jdate($obj->datec);
565 $this->tms = $this->db->jdate($obj->tms);
566 $this->fk_user_creat = $obj->fk_user_creat;
567 $this->fk_user_modif = $obj->fk_user_modif;
568 $this->import_key = $obj->import_key;
569 $this->note_public = $obj->note_public;
570 $this->note_private = $obj->note_private;
576 $this->db->free($resql);
584 $this->errors[] =
'Error '.$this->db->lasterror();
585 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
606 if (isset($this->entity)) {
607 $this->entity = (int) $this->entity;
609 if (isset($this->fk_product)) {
610 $this->fk_product = (int) $this->fk_product;
612 if (isset($this->batch)) {
613 $this->batch = trim($this->batch);
615 if (isset($this->fk_user_creat)) {
616 $this->fk_user_creat = (int) $this->fk_user_creat;
618 if (isset($this->fk_user_modif)) {
619 $this->fk_user_modif = (int) $this->fk_user_modif;
621 if (isset($this->import_key)) {
622 $this->import_key = trim($this->import_key);
633 if (empty($this->oldcopy)) {
639 $sql =
'UPDATE ' . $this->db->prefix() . $this->table_element .
' SET';
640 $sql .=
' entity = ' . (isset($this->entity) ? ((int) $this->entity) :
"null") .
',';
641 $sql .=
' fk_product = ' . (isset($this->fk_product) ? ((int) $this->fk_product) :
"null") .
',';
642 $sql .=
' batch = ' . (isset($this->batch) ?
"'" . $this->db->escape($this->batch) .
"'" :
"null") .
',';
643 $sql .=
' eatby = ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'" . $this->db->idate($this->eatby) .
"'" :
'null') .
',';
644 $sql .=
' sellby = ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'" . $this->db->idate($this->sellby) .
"'" :
'null') .
',';
645 $sql .=
' eol_date = ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'" . $this->db->idate($this->eol_date) .
"'" :
'null') .
',';
646 $sql .=
' manufacturing_date = ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'" . $this->db->idate($this->manufacturing_date) .
"'" :
'null') .
',';
647 $sql .=
' scrapping_date = ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'" . $this->db->idate($this->scrapping_date) .
"'" :
'null') .
',';
649 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
650 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
651 $sql .=
' datec = ' . (
dol_strlen((
string) $this->datec) != 0 ?
"'" . $this->db->idate($this->datec) .
"'" :
'null') .
',';
652 $sql .=
' tms = ' . (
dol_strlen((
string) $this->tms) != 0 ?
"'" . $this->db->idate($this->tms) .
"'" :
"'" . $this->db->idate(
dol_now()) .
"'") .
',';
653 $sql .=
' fk_user_creat = ' . (isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null") .
',';
654 $sql .=
' fk_user_modif = ' . (isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null") .
',';
655 $sql .=
' import_key = ' . (isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
656 $sql .=
' WHERE rowid=' . ((int) $this->
id);
660 $resql = $this->db->query($sql);
663 $this->errors[] =
'Error ' . $this->db->lasterror();
674 if (!$error && !$notrigger) {
676 $result = $this->call_trigger(
'PRODUCTLOT_MODIFY', $user);
685 $this->db->rollback();
692 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
706 public function delete(
User $user, $notrigger = 0)
717 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
718 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
719 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
720 $sql .= $this->db->plimit(1);
722 $resql = $this->db->query($sql);
724 $obj = $this->db->fetch_object($resql);
727 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
728 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
732 $this->errors[] =
'Error '.$this->db->lasterror();
733 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
737 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
738 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
739 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
740 $sql .= $this->db->plimit(1);
742 $resql = $this->db->query($sql);
744 $obj = $this->db->fetch_object($resql);
747 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
748 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
752 $this->errors[] =
'Error '.$this->db->lasterror();
753 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
756 if (!$error && !$notrigger) {
758 $result = $this->call_trigger(
'PRODUCTLOT_DELETE', $user);
773 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
774 $sql .=
' WHERE rowid='.((int) $this->
id);
776 $resql = $this->db->query($sql);
779 $this->errors[] =
'Error '.$this->db->lasterror();
780 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
786 $this->db->rollback();
793 if (!empty(
$conf->productbatch->multidir_output[$this->entity])) {
794 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
795 $dir =
$conf->productbatch->multidir_output[$this->entity].
'/'.
get_exdir(0, 0, 0, 1, $this,
'product_batch');
796 if (file_exists($dir)) {
798 $this->error =
'ErrorFailToDeleteDir';
799 $this->errors[] = $this->error;
834 $object->context[
'createfromclone'] =
'createfromclone';
835 $result =
$object->create($user);
840 $this->errors =
$object->errors;
841 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
844 unset(
$object->context[
'createfromclone']);
852 $this->db->rollback();
866 global $user, $hookmanager, $action;
868 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
869 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
870 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
871 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
872 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
874 if (!$user->hasRight(
'societe',
'client',
'voir')) {
875 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
877 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
878 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
879 if (!$user->hasRight(
'societe',
'client',
'voir')) {
880 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
884 $sql .=
" AND exp.fk_soc = ".((int) $socid);
887 $result = $this->db->query($sql);
889 $obj = $this->db->fetch_object($result);
890 $this->stats_expedition[
'customers'] = $obj->nb_customers;
891 $this->stats_expedition[
'nb'] = $obj->nb;
892 $this->stats_expedition[
'rows'] = $obj->nb_rows;
893 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
919 $parameters = array(
'socid' => $socid);
920 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
922 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
927 $this->error = $this->db->error();
940 global $user, $hookmanager, $action;
942 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
943 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
944 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
945 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
946 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
948 if (!$user->hasRight(
'societe',
'client',
'voir')) {
949 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
951 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
952 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
953 $sql .=
" AND cfdi.fk_product = " . (int) $this->fk_product;
954 if (!$user->hasRight(
'societe',
'client',
'voir')) {
955 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
959 $sql .=
" AND cf.fk_soc = ".((int) $socid);
962 $result = $this->db->query($sql);
964 $obj = $this->db->fetch_object($result);
965 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
966 $this->stats_supplier_order[
'nb'] = $obj->nb;
967 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
968 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
994 $parameters = array(
'socid' => $socid);
995 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
997 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
1002 $this->error = $this->db->error();
1015 global $user, $hookmanager, $action;
1017 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
1018 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
1019 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
1020 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
1022 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1023 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
1025 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
1026 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
1027 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1028 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1032 $sql .=
" AND recep.fk_soc = ".((int) $socid);
1035 $result = $this->db->query($sql);
1037 $obj = $this->db->fetch_object($result);
1038 $this->stats_reception[
'customers'] = $obj->nb_customers;
1039 $this->stats_reception[
'nb'] = $obj->nb;
1040 $this->stats_reception[
'rows'] = $obj->nb_rows;
1041 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
1067 $parameters = array(
'socid' => $socid);
1068 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
1070 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
1075 $this->error = $this->db->error();
1088 global $user, $hookmanager, $action;
1092 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1093 $this->stats_mo[
'customers_'.$role] = 0;
1094 $this->stats_mo[
'nb_'.$role] = 0;
1095 $this->stats_mo[
'qty_'.$role] = 0;
1097 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1098 $sql .=
" SUM(mp.qty) as qty";
1099 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1100 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo = c.rowid";
1101 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
1102 $sql .=
" INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id);
1105 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1107 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1108 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1110 $sql .=
" AND c.fk_soc = ".((int) $socid);
1113 $result = $this->db->query($sql);
1115 $obj = $this->db->fetch_object($result);
1116 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1117 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1118 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1120 $this->error = $this->db->error();
1125 if (!empty($error)) {
1129 $parameters = array(
'socid' => $socid);
1130 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1132 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1179 $langs->loadLangs([
'stocks',
'productbatch']);
1184 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1186 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1188 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1191 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1210 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1212 global $langs, $hookmanager;
1217 'objecttype' => $this->element,
1218 'option' => $option,
1220 $classfortooltip =
'classfortooltip';
1223 $classfortooltip =
'classforajaxtooltip';
1224 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1230 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1232 if ($option !=
'nolink') {
1234 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1235 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1236 $add_save_lastsearch_values = 1;
1238 if ($add_save_lastsearch_values) {
1239 $url .=
'&save_lastsearch_values=1';
1244 if (empty($notooltip)) {
1246 $label = $langs->trans(
"ShowMyObject");
1247 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1249 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1250 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1252 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1255 if ($option ==
'nolink') {
1256 $linkstart =
'<span';
1258 $linkstart =
'<a href="'.$url.
'"';
1260 $linkstart .= $linkclose.
'>';
1261 if ($option ==
'nolink') {
1262 $linkend =
'</span>';
1267 $result .= $linkstart;
1269 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1271 if ($withpicto != 2) {
1272 $result .= $this->batch;
1274 $result .= $linkend;
1277 $hookmanager->initHooks(array(
'productlotdao'));
1278 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1279 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1281 $result = $hookmanager->resPrint;
1283 $result .= $hookmanager->resPrint;
1304 $this->
ref =
'SPECIMEN';
1305 $this->specimen = 1;
1307 $this->entity =
$conf->entity;
1308 $this->fk_product = 0;
1309 $this->batch =
'ABCD123456';
1310 $this->eatby = $now - 100000;
1311 $this->sellby = $now - 100000;
1312 $this->datec = $now - 3600;
1314 $this->fk_user_creat = 0;
1315 $this->fk_user_modif = 0;
1316 $this->import_key =
'123456';
1331 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1335 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1336 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1342 if (!empty($this->model_pdf)) {
1343 $modele = $this->model_pdf;
1349 $modelpath =
"core/modules/product_batch/doc/";
1351 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1365 if ($fieldKey ==
'batch') {
1366 if (preg_match(
'/\s/', $fieldValue)) {
1367 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1372 return parent::validateField($fields, $fieldKey, $fieldValue);
if(! $sortfield) if(! $sortorder) $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.
deleteExtraFields()
Delete all extra fields values for the current object.
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.
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)
Load the array of shipment stats for the lot/serial number.
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)
Load the array of shipment stats for the lot/serial number.
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)
Load the array of shipment stats for the lot/serial number.
__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)
Load the array of supplier order stats for the lot/serial number.
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.