31 require_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;
60 public $stats_expedition;
61 public $stats_reception;
64 public $stats_mrptoconsume;
65 public $stats_mrptoproduce;
66 public $stats_facturerec;
67 public $stats_facture_fournisseur;
98 public $fields = array(
99 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id',
'css' =>
'left'),
100 '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'),
101 '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),
102 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 20),
103 'sellby' => array(
'type' =>
'date',
'label' =>
'SellByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 60),
104 'eatby' => array(
'type' =>
'date',
'label' =>
'EatByDate',
'enabled' =>
'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0',
'visible' => 1,
'notnull' => 0,
'position' => 62),
105 '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),
106 '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),
107 '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),
109 '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),
110 '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),
111 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 215),
112 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -2,
'position' => 310),
113 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 500),
114 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
115 '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'),
116 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 511),
117 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'index' => 0,
'position' => 1000)
136 public $eol_date =
'';
137 public $manufacturing_date =
'';
138 public $scrapping_date =
'';
140 public $qc_frequency =
'';
141 public $lifetime =
'';
147 public $fk_user_creat;
152 public $fk_user_modif;
159 public $stats_supplier_order = array();
171 $this->ismultientitymanaged = 1;
186 $errorMsgArr = array();
187 if ($this->fk_product > 0) {
189 $product = $this->product;
191 $errorMsgArr[] = $product->errorsToString();
194 if (empty($errorMsgArr)) {
199 if (!empty($errorMsgArr)) {
200 $this->errors = array_merge($this->errors, $errorMsgArr);
224 $errorMsgArr = array();
225 if ($productId > 0) {
227 $res = $product->fetch($productId);
229 $errorMsgArr[] = $product->errorsToString();
232 if (empty($errorMsgArr)) {
258 $errorMsgArr = array();
259 $checkSellByMandatory =
false;
260 $checkEatByMandatory =
false;
262 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
263 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
264 $checkSellByMandatory =
true;
265 } elseif (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
266 $checkEatByMandatory =
true;
267 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
268 if (!
getDolGlobalString(
'PRODUCT_DISABLE_SELLBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'sellby')) {
269 $checkSellByMandatory =
true;
271 if (!
getDolGlobalString(
'PRODUCT_DISABLE_EATBY') && ($onlyFieldName ==
'' || $onlyFieldName ==
'eatby')) {
272 $checkEatByMandatory =
true;
276 if ($checkSellByMandatory ===
true) {
277 if (!isset($sellBy) ||
dol_strlen($sellBy) == 0) {
279 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'SellByDate'));
282 if ($checkEatByMandatory ===
true) {
283 if (!isset($eatBy) ||
dol_strlen($eatBy) == 0) {
285 $errorMsgArr[] = $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'EatByDate'));
302 global $conf, $langs;
310 if (isset($this->entity)) {
311 $this->entity = (int) $this->entity;
313 if (isset($this->fk_product)) {
314 $this->fk_product = (int) $this->fk_product;
316 if (isset($this->batch)) {
317 $this->batch = trim($this->batch);
319 if (isset($this->fk_user_creat)) {
320 $this->fk_user_creat = (int) $this->fk_user_creat;
322 if (isset($this->fk_user_modif)) {
323 $this->fk_user_modif = (int) $this->fk_user_modif;
325 if (isset($this->import_key)) {
326 $this->import_key = trim($this->import_key);
330 if ($this->batch ===
'') {
331 $this->errors[] = $langs->trans(
"ErrorBadValueForBatch");
332 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
343 $sql =
'INSERT INTO ' . $this->db->prefix() . $this->table_element .
'(';
345 $sql .=
'fk_product,';
350 $sql .=
'manufacturing_date,';
351 $sql .=
'scrapping_date,';
353 $sql .=
'qc_frequency,';
356 $sql .=
'fk_user_creat,';
357 $sql .=
'fk_user_modif,';
358 $sql .=
'import_key';
359 $sql .=
') VALUES (';
360 $sql .=
' ' . (!isset($this->entity) ? $conf->entity : $this->entity) .
',';
361 $sql .=
' ' . (!isset($this->fk_product) ?
'NULL' : $this->fk_product) .
',';
362 $sql .=
' ' . (!isset($this->batch) ?
'NULL' :
"'" . $this->db->escape($this->batch) .
"'") .
',';
363 $sql .=
' ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eatby) .
"'") .
',';
364 $sql .=
' ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) == 0 ?
'NULL' :
"'" . $this->db->idate($this->sellby) .
"'") .
',';
365 $sql .=
' ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->eol_date) .
"'") .
',';
366 $sql .=
' ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->manufacturing_date) .
"'") .
',';
367 $sql .=
' ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) == 0 ?
'NULL' :
"'" . $this->db->idate($this->scrapping_date) .
"'") .
',';
369 $sql .=
' '.(empty($this->qc_frequency) ?
'NULL' : $this->qc_frequency).
',';
370 $sql .=
' '.(empty($this->lifetime) ?
'NULL' : $this->lifetime).
',';
371 $sql .=
' ' .
"'" . $this->db->idate(
dol_now()) .
"'" .
',';
372 $sql .=
' ' . (!isset($this->fk_user_creat) ?
'NULL' : $this->fk_user_creat) .
',';
373 $sql .=
' ' . (!isset($this->fk_user_modif) ?
'NULL' : $this->fk_user_modif) .
',';
374 $sql .=
' ' . (!isset($this->import_key) ?
'NULL' : $this->import_key);
379 $resql = $this->db->query(
$sql);
382 $this->errors[] =
'Error ' . $this->db->lasterror();
386 $this->
id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
396 if (!$error && !$notrigger) {
398 $result = $this->
call_trigger(
'PRODUCTLOT_CREATE', $user);
408 $this->db->rollback();
415 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
431 public function fetch($id = 0, $product_id = 0, $batch =
'')
438 $sql .=
" t.entity,";
439 $sql .=
" t.fk_product,";
442 $sql .=
" t.sellby,";
443 $sql .=
" t.eol_date,";
444 $sql .=
" t.manufacturing_date,";
445 $sql .=
" t.scrapping_date,";
447 $sql .=
" t.qc_frequency,";
448 $sql .=
" t.lifetime,";
449 $sql .=
" t.model_pdf,";
450 $sql .=
" t.last_main_doc,";
453 $sql .=
" t.fk_user_creat,";
454 $sql .=
" t.fk_user_modif,";
455 $sql .=
" t.import_key,";
456 $sql .=
" t.note_public,";
457 $sql .=
" t.note_private";
458 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
459 if ($product_id > 0 && $batch !=
'') {
460 $sql .=
" WHERE t.batch = '".$this->db->escape($batch).
"' AND t.fk_product = ".((int) $product_id);
462 $sql .=
" WHERE t.rowid = ".((int) $id);
465 $resql = $this->db->query(
$sql);
467 $numrows = $this->db->num_rows($resql);
469 $obj = $this->db->fetch_object($resql);
471 $this->
id = $obj->rowid;
472 $this->
ref = $obj->rowid;
475 $this->batch = $obj->batch;
476 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity);
477 $this->fk_product = $obj->fk_product;
478 $this->eatby = $this->db->jdate($obj->eatby);
479 $this->sellby = $this->db->jdate($obj->sellby);
480 $this->eol_date = $this->db->jdate($obj->eol_date);
481 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
482 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
484 $this->qc_frequency = $obj->qc_frequency;
485 $this->lifetime = $obj->lifetime;
486 $this->model_pdf = $obj->model_pdf;
487 $this->last_main_doc = $obj->last_main_doc;
489 $this->datec = $this->db->jdate($obj->datec);
490 $this->tms = $this->db->jdate($obj->tms);
491 $this->fk_user_creat = $obj->fk_user_creat;
492 $this->fk_user_modif = $obj->fk_user_modif;
493 $this->import_key = $obj->import_key;
494 $this->note_public = $obj->note_public;
495 $this->note_private = $obj->note_private;
501 $this->db->free($resql);
509 $this->errors[] =
'Error '.$this->db->lasterror();
510 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
531 if (isset($this->entity)) {
532 $this->entity = (int) $this->entity;
534 if (isset($this->fk_product)) {
535 $this->fk_product = (int) $this->fk_product;
537 if (isset($this->batch)) {
538 $this->batch = trim($this->batch);
540 if (isset($this->fk_user_creat)) {
541 $this->fk_user_creat = (int) $this->fk_user_creat;
543 if (isset($this->fk_user_modif)) {
544 $this->fk_user_modif = (int) $this->fk_user_modif;
546 if (isset($this->import_key)) {
547 $this->import_key = trim($this->import_key);
558 if (empty($this->oldcopy)) {
564 $sql =
'UPDATE ' . $this->db->prefix() . $this->table_element .
' SET';
565 $sql .=
' entity = ' . (isset($this->entity) ? $this->entity :
"null") .
',';
566 $sql .=
' fk_product = ' . (isset($this->fk_product) ? $this->fk_product :
"null") .
',';
567 $sql .=
' batch = ' . (isset($this->batch) ?
"'" . $this->db->escape($this->batch) .
"'" :
"null") .
',';
568 $sql .=
' eatby = ' . (!isset($this->eatby) ||
dol_strlen($this->eatby) != 0 ?
"'" . $this->db->idate($this->eatby) .
"'" :
'null') .
',';
569 $sql .=
' sellby = ' . (!isset($this->sellby) ||
dol_strlen($this->sellby) != 0 ?
"'" . $this->db->idate($this->sellby) .
"'" :
'null') .
',';
570 $sql .=
' eol_date = ' . (!isset($this->eol_date) ||
dol_strlen($this->eol_date) != 0 ?
"'" . $this->db->idate($this->eol_date) .
"'" :
'null') .
',';
571 $sql .=
' manufacturing_date = ' . (!isset($this->manufacturing_date) ||
dol_strlen($this->manufacturing_date) != 0 ?
"'" . $this->db->idate($this->manufacturing_date) .
"'" :
'null') .
',';
572 $sql .=
' scrapping_date = ' . (!isset($this->scrapping_date) ||
dol_strlen($this->scrapping_date) != 0 ?
"'" . $this->db->idate($this->scrapping_date) .
"'" :
'null') .
',';
574 $sql .=
' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency :
'null').
',';
575 $sql .=
' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime :
'null').
',';
576 $sql .=
' datec = ' . (!isset($this->datec) ||
dol_strlen($this->datec) != 0 ?
"'" . $this->db->idate($this->datec) .
"'" :
'null') .
',';
577 $sql .=
' tms = ' . (
dol_strlen($this->tms) != 0 ?
"'" . $this->db->idate($this->tms) .
"'" :
"'" . $this->db->idate(
dol_now()) .
"'") .
',';
578 $sql .=
' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat :
"null") .
',';
579 $sql .=
' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif :
"null") .
',';
580 $sql .=
' import_key = ' . (isset($this->import_key) ? $this->import_key :
"null");
581 $sql .=
' WHERE rowid=' . ((int) $this->
id);
585 $resql = $this->db->query(
$sql);
588 $this->errors[] =
'Error ' . $this->db->lasterror();
599 if (!$error && !$notrigger) {
601 $result = $this->
call_trigger(
'PRODUCTLOT_MODIFY', $user);
610 $this->db->rollback();
617 dol_syslog(__METHOD__ .
' ' . implode(
',', $this->errors), LOG_ERR);
631 public function delete(
User $user, $notrigger = 0)
640 $sql =
"SELECT pb.rowid FROM ".$this->db->prefix().
"product_batch as pb, ".$this->db->prefix().
"product_stock as ps";
641 $sql .=
" WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch).
"'";
642 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
643 $sql .= $this->db->plimit(1);
645 $resql = $this->db->query(
$sql);
647 $obj = $this->db->fetch_object($resql);
650 $this->errors[] =
'Error Lot is used in stock (ID = '.$obj->rowid.
'). Deletion not possible.';
651 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
655 $this->errors[] =
'Error '.$this->db->lasterror();
656 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
660 $sql =
"SELECT sm.rowid FROM ".$this->db->prefix().
"stock_mouvement as sm";
661 $sql .=
" WHERE sm.batch = '".$this->db->escape($this->batch).
"'";
662 $sql .=
" AND sm.fk_product = ".((int) $this->fk_product);
663 $sql .= $this->db->plimit(1);
665 $resql = $this->db->query(
$sql);
667 $obj = $this->db->fetch_object($resql);
670 $this->errors[] =
'Error Lot was used in a stock movement (ID '.$obj->rowid.
'). Deletion not possible.';
671 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
675 $this->errors[] =
'Error '.$this->db->lasterror();
676 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
693 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element;
694 $sql .=
' WHERE rowid='.((int) $this->
id);
696 $resql = $this->db->query(
$sql);
699 $this->errors[] =
'Error '.$this->db->lasterror();
700 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
706 $this->db->rollback();
741 $object->context[
'createfromclone'] =
'createfromclone';
742 $result =
$object->create($user);
747 $this->errors =
$object->errors;
748 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
751 unset(
$object->context[
'createfromclone']);
759 $this->db->rollback();
774 global $user, $hookmanager, $action;
776 $sql =
"SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
777 $sql .=
" COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
778 $sql .=
" FROM ".$this->db->prefix().
"expeditiondet_batch as edb";
779 $sql .=
" INNER JOIN ".$this->db->prefix().
"expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
780 $sql .=
" INNER JOIN ".$this->db->prefix().
"expedition as exp ON (exp.rowid = ed.fk_expedition)";
782 if (!$user->hasRight(
'societe',
'client',
'voir')) {
783 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
785 $sql .=
" WHERE exp.entity IN (".getEntity(
'expedition').
")";
786 $sql .=
" AND edb.batch = '".($this->db->escape($this->batch)).
"'";
787 if (!$user->hasRight(
'societe',
'client',
'voir')) {
788 $sql .=
" AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
792 $sql .=
" AND exp.fk_soc = ".((int) $socid);
795 $result = $this->db->query(
$sql);
797 $obj = $this->db->fetch_object($result);
798 $this->stats_expedition[
'customers'] = $obj->nb_customers;
799 $this->stats_expedition[
'nb'] = $obj->nb;
800 $this->stats_expedition[
'rows'] = $obj->nb_rows;
801 $this->stats_expedition[
'qty'] = $obj->qty ? $obj->qty : 0;
827 $parameters = array(
'socid' => $socid);
828 $reshook = $hookmanager->executeHooks(
'loadStatsLotExpedition', $parameters, $this, $action);
830 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
835 $this->error = $this->db->error();
849 global $user, $hookmanager, $action;
851 $sql =
"SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
852 $sql .=
" COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
853 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
854 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
855 $sql .=
" INNER JOIN ".$this->db->prefix().
"commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
857 if (!$user->hasRight(
'societe',
'client',
'voir')) {
858 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
860 $sql .=
" WHERE cf.entity IN (".getEntity(
'expedition').
")";
861 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
862 if (!$user->hasRight(
'societe',
'client',
'voir')) {
863 $sql .=
" AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
867 $sql .=
" AND cf.fk_soc = ".((int) $socid);
870 $result = $this->db->query(
$sql);
872 $obj = $this->db->fetch_object($result);
873 $this->stats_supplier_order[
'customers'] = $obj->nb_customers;
874 $this->stats_supplier_order[
'nb'] = $obj->nb;
875 $this->stats_supplier_order[
'rows'] = $obj->nb_rows;
876 $this->stats_supplier_order[
'qty'] = $obj->qty ? $obj->qty : 0;
902 $parameters = array(
'socid' => $socid);
903 $reshook = $hookmanager->executeHooks(
'loadStatsLotSupplierOrder', $parameters, $this, $action);
905 $this->stats_supplier_order = $hookmanager->resArray[
'stats_supplier_order'];
910 $this->error = $this->db->error();
924 global $user, $hookmanager, $action;
926 $sql =
"SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
927 $sql .=
" COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
928 $sql .=
" FROM ".$this->db->prefix().
"receptiondet_batch as cfdi";
929 $sql .=
" INNER JOIN ".$this->db->prefix().
"reception as recep ON (recep.rowid = cfdi.fk_reception)";
931 if (!$user->hasRight(
'societe',
'client',
'voir')) {
932 $sql .=
", ".$this->db->prefix().
"societe_commerciaux as sc";
934 $sql .=
" WHERE recep.entity IN (".getEntity(
'reception').
")";
935 $sql .=
" AND cfdi.batch = '".($this->db->escape($this->batch)).
"'";
936 if (!$user->hasRight(
'societe',
'client',
'voir')) {
937 $sql .=
" AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
941 $sql .=
" AND recep.fk_soc = ".((int) $socid);
944 $result = $this->db->query(
$sql);
946 $obj = $this->db->fetch_object($result);
947 $this->stats_reception[
'customers'] = $obj->nb_customers;
948 $this->stats_reception[
'nb'] = $obj->nb;
949 $this->stats_reception[
'rows'] = $obj->nb_rows;
950 $this->stats_reception[
'qty'] = $obj->qty ? $obj->qty : 0;
976 $parameters = array(
'socid' => $socid);
977 $reshook = $hookmanager->executeHooks(
'loadStatsLotReception', $parameters, $this, $action);
979 $this->stats_expedition = $hookmanager->resArray[
'stats_expedition'];
984 $this->error = $this->db->error();
998 global $user, $hookmanager, $action;
1002 foreach (array(
'toconsume',
'consumed',
'toproduce',
'produced') as $role) {
1003 $this->stats_mo[
'customers_'.$role] = 0;
1004 $this->stats_mo[
'nb_'.$role] = 0;
1005 $this->stats_mo[
'qty_'.$role] = 0;
1007 $sql =
"SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1008 $sql .=
" SUM(mp.qty) as qty";
1009 $sql .=
" FROM ".$this->db->prefix().
"mrp_mo as c";
1010 $sql .=
" INNER JOIN ".$this->db->prefix().
"mrp_production as mp ON mp.fk_mo=c.rowid";
1011 if (!$user->hasRight(
'societe',
'client',
'voir')) {
1012 $sql .=
"INNER JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1015 $sql .=
" c.entity IN (".getEntity(
'mo').
")";
1017 $sql .=
" AND mp.batch = '".($this->db->escape($this->batch)).
"'";
1018 $sql .=
" AND mp.role ='".$this->db->escape($role).
"'";
1020 $sql .=
" AND c.fk_soc = ".((int) $socid);
1023 $result = $this->db->query(
$sql);
1025 $obj = $this->db->fetch_object($result);
1026 $this->stats_mo[
'customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1027 $this->stats_mo[
'nb_'.$role] = $obj->nb ? $obj->nb : 0;
1028 $this->stats_mo[
'qty_'.$role] = $obj->qty ?
price2num($obj->qty,
'MS') : 0;
1030 $this->error = $this->db->error();
1035 if (!empty($error)) {
1039 $parameters = array(
'socid' => $socid);
1040 $reshook = $hookmanager->executeHooks(
'loadStatsCustomerMO', $parameters, $this, $action);
1042 $this->stats_mo = $hookmanager->resArray[
'stats_mo'];
1088 global $langs, $user;
1090 $langs->loadLangs([
'stocks',
'productbatch']);
1095 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Batch").
'</u>';
1097 $datas[
'batch'] =
'<br><b>'.$langs->trans(
'Batch').
':</b> '.$this->batch;
1099 $datas[
'eatby'] =
'<br><b>'.$langs->trans(
'EatByDate').
':</b> '.
dol_print_date($this->db->jdate($this->eatby),
'day');
1102 $datas[
'sellby'] =
'<br><b>'.$langs->trans(
'SellByDate').
':</b> '.
dol_print_date($this->db->jdate($this->sellby),
'day');
1121 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $maxlen = 24, $morecss =
'', $save_lastsearch_value = -1)
1123 global $langs, $hookmanager;
1128 'objecttype' => $this->element,
1129 'option' => $option,
1131 $classfortooltip =
'classfortooltip';
1134 $classfortooltip =
'classforajaxtooltip';
1135 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1141 $url = DOL_URL_ROOT.
'/product/stock/productlot_card.php?id='.$this->id;
1143 if ($option !=
'nolink') {
1145 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1146 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1147 $add_save_lastsearch_values = 1;
1149 if ($add_save_lastsearch_values) {
1150 $url .=
'&save_lastsearch_values=1';
1155 if (empty($notooltip)) {
1157 $label = $langs->trans(
"ShowMyObject");
1158 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1160 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1161 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1163 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1166 if ($option ==
'nolink') {
1167 $linkstart =
'<span';
1169 $linkstart =
'<a href="'.$url.
'"';
1171 $linkstart .= $linkclose.
'>';
1172 if ($option ==
'nolink') {
1173 $linkend =
'</span>';
1178 $result .= $linkstart;
1180 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1182 if ($withpicto != 2) {
1183 $result .= $this->batch;
1185 $result .= $linkend;
1188 $hookmanager->initHooks(array(
'productlotdao'));
1189 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
1190 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1192 $result = $hookmanager->resPrint;
1194 $result .= $hookmanager->resPrint;
1215 $this->
ref =
'SPECIMEN';
1216 $this->specimen = 1;
1218 $this->entity = $conf->entity;
1219 $this->fk_product = 0;
1221 $this->eatby = $now - 100000;
1222 $this->sellby = $now - 100000;
1223 $this->datec = $now - 3600;
1225 $this->fk_user_creat = 0;
1226 $this->fk_user_modif = 0;
1227 $this->import_key =
'123456';
1242 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1246 $langs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1247 $outputlangs->loadLangs(array(
'stocks',
'productbatch',
"products"));
1253 if (!empty($this->model_pdf)) {
1254 $modele = $this->model_pdf;
1260 $modelpath =
"core/modules/product_batch/doc/";
1262 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1276 if ($fieldKey ==
'batch') {
1277 if (preg_match(
'/\s/', $fieldValue)) {
1278 $this->error =
'ErrorABatchShouldNotContainsSpaces';
1283 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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
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 '.
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.