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' =>
'tdoverflowmax250'),
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)
720 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
721 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
722 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
723 $sql .= $this->db->plimit(1);
725 $resql = $this->db->query($sql);
727 $obj = $this->db->fetch_object($resql);
730 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
731 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
735 $this->errors[] =
'Error '.$this->db->lasterror();
736 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
740 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
741 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
742 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
743 $sql .= $this->db->plimit(1);
745 $resql = $this->db->query($sql);
747 $obj = $this->db->fetch_object($resql);
750 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
751 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
755 $this->errors[] =
'Error '.$this->db->lasterror();
756 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
759 if (!$error && !$notrigger) {
761 $result = $this->
call_trigger(
'PRODUCTLOT_DELETE', $user);
776 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
777 $sql .=
' WHERE rowid='.((int) $this->
id);
779 $resql = $this->db->query($sql);
782 $this->errors[] =
'Error '.$this->db->lasterror();
783 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
789 $this->db->rollback();
796 if (!empty(
$conf->productbatch->multidir_output[$this->entity])) {
797 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
798 $dir =
$conf->productbatch->multidir_output[$this->entity].
'/'.
get_exdir(0, 0, 0, 1, $this,
'product_batch');
799 if (file_exists($dir)) {
801 $this->error =
'ErrorFailToDeleteDir';
802 $this->errors[] = $this->error;
837 $object->context[
'createfromclone'] =
'createfromclone';
838 $result =
$object->create($user);
843 $this->errors =
$object->errors;
844 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
847 unset(
$object->context[
'createfromclone']);
855 $this->db->rollback();
869 global $user, $hookmanager, $action;
871 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
872 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
873 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
874 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
875 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
877 if (!$user->hasRight(
'societe',
'client',
'voir')) {
878 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
880 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
881 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
882 if (!$user->hasRight(
'societe',
'client',
'voir')) {
883 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
887 $sql .=
" AND exp.fk_soc = ".((int) $socid);
890 $result = $this->db->query($sql);
892 $obj = $this->db->fetch_object($result);
893 $this->stats_expedition[
'customers'] = $obj->nb_customers;
894 $this->stats_expedition[
'nb'] = $obj->nb;
895 $this->stats_expedition[
'rows'] = $obj->nb_rows;
896 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
922 $parameters = array(
'socid' => $socid);
923 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
925 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
930 $this->error = $this->db->error();
943 global $user, $hookmanager, $action;
945 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
946 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
947 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
948 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
949 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
951 if (!$user->hasRight(
'societe',
'client',
'voir')) {
952 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
954 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
955 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
956 $sql .=
" AND cfdi.fk_product = " . (int) $this->fk_product;
957 if (!$user->hasRight(
'societe',
'client',
'voir')) {
958 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
962 $sql .=
" AND cf.fk_soc = ".((int) $socid);
965 $result = $this->db->query($sql);
967 $obj = $this->db->fetch_object($result);
968 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
969 $this->stats_supplier_order[
'nb'] = $obj->nb;
970 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
971 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
997 $parameters = array(
'socid' => $socid);
998 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
1000 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
1005 $this->error = $this->db->error();
1018 global $user, $hookmanager, $action;
1020 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
1021 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
1022 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
1023 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
1025 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1026 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
1028 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
1029 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
1030 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1031 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1035 $sql .=
" AND recep.fk_soc = ".((int) $socid);
1038 $result = $this->db->query($sql);
1040 $obj = $this->db->fetch_object($result);
1041 $this->stats_reception[
'customers'] = $obj->nb_customers;
1042 $this->stats_reception[
'nb'] = $obj->nb;
1043 $this->stats_reception[
'rows'] = $obj->nb_rows;
1044 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
1070 $parameters = array(
'socid' => $socid);
1071 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
1073 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
1078 $this->error = $this->db->error();
1091 global $user, $hookmanager, $action;
1095 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1096 $this->stats_mo[
'customers_'.$role] = 0;
1097 $this->stats_mo[
'nb_'.$role] = 0;
1098 $this->stats_mo[
'qty_'.$role] = 0;
1100 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1101 $sql .=
" SUM(mp.qty) as qty";
1102 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1103 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
1104 if (!$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
1105 $sql .=
" INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1108 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1110 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1111 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1113 $sql .=
" AND c.fk_soc = ".((int) $socid);
1116 $result = $this->db->query($sql);
1118 $obj = $this->db->fetch_object($result);
1119 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1120 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1121 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1123 $this->error = $this->db->error();
1128 if (!empty($error)) {
1132 $parameters = array(
'socid' => $socid);
1133 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1135 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1182 $langs->loadLangs([
'stocks',
'productbatch']);
1187 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1189 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1191 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->eatby,
'day');
1194 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->sellby,
'day');
1213 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1215 global $langs, $hookmanager;
1220 'objecttype' => $this->element,
1221 'option' => $option,
1223 $classfortooltip =
'classfortooltip';
1226 $classfortooltip =
'classforajaxtooltip';
1227 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1233 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1235 if ($option !=
'nolink') {
1237 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1238 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1239 $add_save_lastsearch_values = 1;
1241 if ($add_save_lastsearch_values) {
1242 $url .=
'&save_lastsearch_values=1';
1247 if (empty($notooltip)) {
1249 $label = $langs->trans(
"ShowMyObject");
1250 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1252 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1253 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1255 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1258 if ($option ==
'nolink') {
1259 $linkstart =
'<span';
1261 $linkstart =
'<a href="'.$url.
'"';
1263 $linkstart .= $linkclose.
'>';
1264 if ($option ==
'nolink') {
1265 $linkend =
'</span>';
1270 $result .= $linkstart;
1272 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1274 if ($withpicto != 2) {
1275 $result .= $this->batch;
1277 $result .= $linkend;
1280 $hookmanager->initHooks(array(
'productlotdao'));
1281 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1282 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1284 $result = $hookmanager->resPrint;
1286 $result .= $hookmanager->resPrint;
1307 $this->
ref =
'SPECIMEN';
1308 $this->specimen = 1;
1310 $this->entity =
$conf->entity;
1311 $this->fk_product = 0;
1312 $this->batch =
'ABCD123456';
1313 $this->eatby = $now - 100000;
1314 $this->sellby = $now - 100000;
1315 $this->datec = $now - 3600;
1317 $this->fk_user_creat = 0;
1318 $this->fk_user_modif = 0;
1319 $this->import_key =
'123456';
1334 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1338 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1339 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1345 if (!empty($this->model_pdf)) {
1346 $modele = $this->model_pdf;
1352 $modelpath =
"core/modules/product_batch/doc/";
1354 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1368 if ($fieldKey ==
'batch') {
1369 if (preg_match(
'/\s/', $fieldValue)) {
1370 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1375 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.
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.
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.
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)
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.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...