dolibarr  20.0.0-beta
productlot.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6  * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
7  * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 // Put here all includes required by your class file
31 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
33 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
34 
38 class Productlot extends CommonObject
39 {
43  public $element = 'productlot';
44 
48  public $table_element = 'product_lot';
49 
53  public $picto = 'lot';
54 
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;
62  public $stats_mo;
63  public $stats_bom;
64  public $stats_mrptoconsume;
65  public $stats_mrptoproduce;
66  public $stats_facturerec;
67  public $stats_facture_fournisseur;
68 
69 
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),
108  //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
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)
118  );
119 
123  public $entity;
124 
128  public $fk_product;
129 
133  public $batch;
134  public $eatby = '';
135  public $sellby = '';
136  public $eol_date = '';
137  public $manufacturing_date = '';
138  public $scrapping_date = '';
139  //public $commissionning_date = '';
140  public $qc_frequency = '';
141  public $lifetime = '';
142  public $datec = '';
143 
147  public $fk_user_creat;
148 
152  public $fk_user_modif;
153 
157  public $import_key;
158 
159  public $stats_supplier_order = array();
160 
161 
167  public function __construct(DoliDB $db)
168  {
169  $this->db = $db;
170 
171  $this->ismultientitymanaged = 1;
172  }
173 
180  public function checkSellOrEatByMandatory($onlyFieldName = '')
181  {
182  if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
183  return 0;
184  }
185 
186  $errorMsgArr = array();
187  if ($this->fk_product > 0) {
188  $res = $this->fetch_product();
189  $product = $this->product;
190  if ($res <= 0) {
191  $errorMsgArr[] = $product->errorsToString();
192  }
193 
194  if (empty($errorMsgArr)) {
195  $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
196  }
197  }
198 
199  if (!empty($errorMsgArr)) {
200  $this->errors = array_merge($this->errors, $errorMsgArr);
201  return -1;
202  } else {
203  return 1;
204  }
205  }
206 
216  public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
217  {
218  global $db;
219 
220  if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
221  return null;
222  }
223 
224  $errorMsgArr = array();
225  if ($productId > 0) {
226  $product = new Product($db);
227  $res = $product->fetch($productId);
228  if ($res <= 0) {
229  $errorMsgArr[] = $product->errorsToString();
230  }
231 
232  if (empty($errorMsgArr)) {
233  $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
234  }
235  }
236 
237  return $errorMsgArr;
238  }
239 
250  public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
251  {
252  global $langs;
253 
254  if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
255  return null;
256  }
257 
258  $errorMsgArr = array();
259  $checkSellByMandatory = false;
260  $checkEatByMandatory = false;
261 
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;
270  }
271  if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
272  $checkEatByMandatory = true;
273  }
274  }
275 
276  if ($checkSellByMandatory === true) {
277  if (!isset($sellBy) || dol_strlen($sellBy) == 0) {
278  // error : sell by is mandatory
279  $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
280  }
281  }
282  if ($checkEatByMandatory === true) {
283  if (!isset($eatBy) || dol_strlen($eatBy) == 0) {
284  // error : eat by is mandatory
285  $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
286  }
287  }
288 
289  return $errorMsgArr;
290  }
291 
292 
300  public function create(User $user, $notrigger = 0)
301  {
302  global $conf, $langs;
303 
304  dol_syslog(__METHOD__, LOG_DEBUG);
305 
306  $error = 0;
307 
308  // Clean parameters
309 
310  if (isset($this->entity)) {
311  $this->entity = (int) $this->entity;
312  }
313  if (isset($this->fk_product)) {
314  $this->fk_product = (int) $this->fk_product;
315  }
316  if (isset($this->batch)) {
317  $this->batch = trim($this->batch);
318  }
319  if (isset($this->fk_user_creat)) {
320  $this->fk_user_creat = (int) $this->fk_user_creat;
321  }
322  if (isset($this->fk_user_modif)) {
323  $this->fk_user_modif = (int) $this->fk_user_modif;
324  }
325  if (isset($this->import_key)) {
326  $this->import_key = trim($this->import_key);
327  }
328 
329  // Check parameters
330  if ($this->batch === '') {
331  $this->errors[] = $langs->trans("ErrorBadValueForBatch");
332  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
333  return -1;
334  }
335  // Put here code to add control on parameters values
336  $res = $this->checkSellOrEatByMandatory();
337  if ($res < 0) {
338  $error++;
339  }
340 
341  if (!$error) {
342  // Insert request
343  $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '(';
344  $sql .= 'entity,';
345  $sql .= 'fk_product,';
346  $sql .= 'batch,';
347  $sql .= 'eatby,';
348  $sql .= 'sellby,';
349  $sql .= 'eol_date,';
350  $sql .= 'manufacturing_date,';
351  $sql .= 'scrapping_date,';
352  //$sql .= 'commissionning_date,';
353  $sql .= 'qc_frequency,';
354  $sql .= 'lifetime,';
355  $sql .= 'datec,';
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) . "'") . ',';
368  //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_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);
375  $sql .= ')';
376 
377  $this->db->begin();
378 
379  $resql = $this->db->query($sql);
380  if (!$resql) {
381  $error++;
382  $this->errors[] = 'Error ' . $this->db->lasterror();
383  }
384 
385  if (!$error) {
386  $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
387 
388  // Actions on extra fields
389  if (!$error) {
390  $result = $this->insertExtraFields();
391  if ($result < 0) {
392  $error++;
393  }
394  }
395 
396  if (!$error && !$notrigger) {
397  // Call triggers
398  $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
399  if ($result < 0) {
400  $error++;
401  }
402  // End call triggers
403  }
404  }
405 
406  // Commit or rollback
407  if ($error) {
408  $this->db->rollback();
409  } else {
410  $this->db->commit();
411  }
412  }
413 
414  if ($error) {
415  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
416  return -1 * $error;
417  } else {
418  return $this->id;
419  }
420  }
421 
431  public function fetch($id = 0, $product_id = 0, $batch = '')
432  {
433  global $conf;
434  dol_syslog(__METHOD__, LOG_DEBUG);
435 
436  $sql = "SELECT";
437  $sql .= " t.rowid,";
438  $sql .= " t.entity,";
439  $sql .= " t.fk_product,";
440  $sql .= " t.batch,";
441  $sql .= " t.eatby,";
442  $sql .= " t.sellby,";
443  $sql .= " t.eol_date,";
444  $sql .= " t.manufacturing_date,";
445  $sql .= " t.scrapping_date,";
446  //$sql .= " t.commissionning_date,";
447  $sql .= " t.qc_frequency,";
448  $sql .= " t.lifetime,";
449  $sql .= " t.model_pdf,";
450  $sql .= " t.last_main_doc,";
451  $sql .= " t.datec,";
452  $sql .= " t.tms,";
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);
461  } else {
462  $sql .= " WHERE t.rowid = ".((int) $id);
463  }
464 
465  $resql = $this->db->query($sql);
466  if ($resql) {
467  $numrows = $this->db->num_rows($resql);
468  if ($numrows) {
469  $obj = $this->db->fetch_object($resql);
470 
471  $this->id = $obj->rowid;
472  $this->ref = $obj->rowid;
473  //$this->ref = $obj->fk_product.'_'.$obj->batch;
474 
475  $this->batch = $obj->batch;
476  $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" 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);
483  //$this->commissionning_date = $this->db->jdate($obj->commissionning_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;
488 
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;
496 
497  // Retrieve all extrafield
498  // fetch optionals attributes and labels
499  $this->fetch_optionals();
500  }
501  $this->db->free($resql);
502 
503  if ($numrows) {
504  return 1;
505  } else {
506  return 0;
507  }
508  } else {
509  $this->errors[] = 'Error '.$this->db->lasterror();
510  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
511 
512  return -1;
513  }
514  }
515 
523  public function update(User $user, $notrigger = 0)
524  {
525  $error = 0;
526 
527  dol_syslog(__METHOD__, LOG_DEBUG);
528 
529  // Clean parameters
530 
531  if (isset($this->entity)) {
532  $this->entity = (int) $this->entity;
533  }
534  if (isset($this->fk_product)) {
535  $this->fk_product = (int) $this->fk_product;
536  }
537  if (isset($this->batch)) {
538  $this->batch = trim($this->batch);
539  }
540  if (isset($this->fk_user_creat)) {
541  $this->fk_user_creat = (int) $this->fk_user_creat;
542  }
543  if (isset($this->fk_user_modif)) {
544  $this->fk_user_modif = (int) $this->fk_user_modif;
545  }
546  if (isset($this->import_key)) {
547  $this->import_key = trim($this->import_key);
548  }
549 
550  // Check parameters
551  // Put here code to add a control on parameters values
552  $res = $this->checkSellOrEatByMandatory();
553  if ($res < 0) {
554  $error++;
555  }
556 
557  // $this->oldcopy should have been set by the caller of update (here properties were already modified)
558  if (empty($this->oldcopy)) {
559  $this->oldcopy = dol_clone($this, 2);
560  }
561 
562  if (!$error) {
563  // Update request
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') . ',';
573  //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_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);
582 
583  $this->db->begin();
584 
585  $resql = $this->db->query($sql);
586  if (!$resql) {
587  $error++;
588  $this->errors[] = 'Error ' . $this->db->lasterror();
589  }
590 
591  // Actions on extra fields
592  if (!$error) {
593  $result = $this->insertExtraFields();
594  if ($result < 0) {
595  $error++;
596  }
597  }
598 
599  if (!$error && !$notrigger) {
600  // Call triggers
601  $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
602  if ($result < 0) {
603  $error++;
604  }
605  // End call triggers
606  }
607 
608  // Commit or rollback
609  if ($error) {
610  $this->db->rollback();
611  } else {
612  $this->db->commit();
613  }
614  }
615 
616  if ($error) {
617  dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
618  return -1 * $error;
619  } else {
620  return 1;
621  }
622  }
623 
631  public function delete(User $user, $notrigger = 0)
632  {
633  dol_syslog(__METHOD__, LOG_DEBUG);
634 
635  $error = 0;
636 
637  $this->db->begin();
638 
639  // Check there is no stock for this lot
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);
644 
645  $resql = $this->db->query($sql);
646  if ($resql) {
647  $obj = $this->db->fetch_object($resql);
648  if ($obj) {
649  $error++;
650  $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
651  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
652  }
653  } else {
654  $error++;
655  $this->errors[] = 'Error '.$this->db->lasterror();
656  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
657  }
658 
659  // Check there is no movement for this lot
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);
664 
665  $resql = $this->db->query($sql);
666  if ($resql) {
667  $obj = $this->db->fetch_object($resql);
668  if ($obj) {
669  $error++;
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);
672  }
673  } else {
674  $error++;
675  $this->errors[] = 'Error '.$this->db->lasterror();
676  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
677  }
678 
679  // TODO
680  //if (!$error) {
681  //if (!$notrigger) {
682  // Uncomment this and change PRODUCTLOT to your own tag if you
683  // want this action calls a trigger.
684 
686  //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
687  //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
689  //}
690  //}
691 
692  if (!$error) {
693  $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
694  $sql .= ' WHERE rowid='.((int) $this->id);
695 
696  $resql = $this->db->query($sql);
697  if (!$resql) {
698  $error++;
699  $this->errors[] = 'Error '.$this->db->lasterror();
700  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
701  }
702  }
703 
704  // Commit or rollback
705  if ($error) {
706  $this->db->rollback();
707 
708  return -1 * $error;
709  } else {
710  $this->db->commit();
711 
712  return 1;
713  }
714  }
715 
723  public function createFromClone(User $user, $fromid)
724  {
725  dol_syslog(__METHOD__, LOG_DEBUG);
726 
727  $error = 0;
728  $object = new Productlot($this->db);
729 
730  $this->db->begin();
731 
732  // Load source object
733  $object->fetch($fromid);
734  // Reset object
735  $object->id = 0;
736 
737  // Clear fields
738  // ...
739 
740  // Create clone
741  $object->context['createfromclone'] = 'createfromclone';
742  $result = $object->create($user);
743 
744  // Other options
745  if ($result < 0) {
746  $error++;
747  $this->errors = $object->errors;
748  dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
749  }
750 
751  unset($object->context['createfromclone']);
752 
753  // End
754  if (!$error) {
755  $this->db->commit();
756 
757  return $object->id;
758  } else {
759  $this->db->rollback();
760 
761  return -1;
762  }
763  }
764 
771  public function loadStatsExpedition($socid = 0)
772  {
773  // phpcs:enable
774  global $user, $hookmanager, $action;
775 
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)";
781  // $sql .= ", ".$this->db->prefix()."societe as s";
782  if (!$user->hasRight('societe', 'client', 'voir')) {
783  $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
784  }
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);
789  }
790  //$sql.= " AND exp.fk_statut != 0";
791  if ($socid > 0) {
792  $sql .= " AND exp.fk_soc = ".((int) $socid);
793  }
794 
795  $result = $this->db->query($sql);
796  if ($result) {
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;
802 
803 
804  // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
805 
806  // if it's a virtual product, maybe it is in invoice by extension
807  // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
808  // $TFather = $this->getFather();
809  // if (is_array($TFather) && !empty($TFather)) {
810  // foreach ($TFather as &$fatherData) {
811  // $pFather = new Product($this->db);
812  // $pFather->id = $fatherData['id'];
813  // $qtyCoef = $fatherData['qty'];
814  //
815  // if ($fatherData['incdec']) {
816  // $pFather->loadStatsExpedition($socid);
817  //
818  // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
819  // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
820  // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
821  // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
822  // }
823  // }
824  // }
825  // }
826 
827  $parameters = array('socid' => $socid);
828  $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
829  if ($reshook > 0) {
830  $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
831  }
832 
833  return 1;
834  } else {
835  $this->error = $this->db->error();
836  return -1;
837  }
838  }
839 
846  public function loadStatsSupplierOrder($socid = 0)
847  {
848  // phpcs:enable
849  global $user, $hookmanager, $action;
850 
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)";
856  // $sql .= ", ".$this->db->prefix()."societe as s";
857  if (!$user->hasRight('societe', 'client', 'voir')) {
858  $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
859  }
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);
864  }
865  //$sql.= " AND cf.fk_statut != 0";
866  if ($socid > 0) {
867  $sql .= " AND cf.fk_soc = ".((int) $socid);
868  }
869 
870  $result = $this->db->query($sql);
871  if ($result) {
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;
877 
878 
879  // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
880 
881  // if it's a virtual product, maybe it is in invoice by extension
882  // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
883  // $TFather = $this->getFather();
884  // if (is_array($TFather) && !empty($TFather)) {
885  // foreach ($TFather as &$fatherData) {
886  // $pFather = new Product($this->db);
887  // $pFather->id = $fatherData['id'];
888  // $qtyCoef = $fatherData['qty'];
889  //
890  // if ($fatherData['incdec']) {
891  // $pFather->stats_supplier_order($socid);
892  //
893  // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
894  // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
895  // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
896  // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
897  // }
898  // }
899  // }
900  // }
901 
902  $parameters = array('socid' => $socid);
903  $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
904  if ($reshook > 0) {
905  $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
906  }
907 
908  return 1;
909  } else {
910  $this->error = $this->db->error();
911  return -1;
912  }
913  }
914 
921  public function loadStatsReception($socid = 0)
922  {
923  // phpcs:enable
924  global $user, $hookmanager, $action;
925 
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)";
930  // $sql .= ", ".$this->db->prefix()."societe as s";
931  if (!$user->hasRight('societe', 'client', 'voir')) {
932  $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
933  }
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);
938  }
939  //$sql.= " AND exp.fk_statut != 0";
940  if ($socid > 0) {
941  $sql .= " AND recep.fk_soc = ".((int) $socid);
942  }
943 
944  $result = $this->db->query($sql);
945  if ($result) {
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;
951 
952 
953  // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
954 
955  // if it's a virtual product, maybe it is in invoice by extension
956  // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
957  // $TFather = $this->getFather();
958  // if (is_array($TFather) && !empty($TFather)) {
959  // foreach ($TFather as &$fatherData) {
960  // $pFather = new Product($this->db);
961  // $pFather->id = $fatherData['id'];
962  // $qtyCoef = $fatherData['qty'];
963  //
964  // if ($fatherData['incdec']) {
965  // $pFather->loadStatsReception($socid);
966  //
967  // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
968  // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
969  // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
970  // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
971  // }
972  // }
973  // }
974  // }
975 
976  $parameters = array('socid' => $socid);
977  $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
978  if ($reshook > 0) {
979  $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
980  }
981 
982  return 1;
983  } else {
984  $this->error = $this->db->error();
985  return -1;
986  }
987  }
988 
995  public function loadStatsMo($socid = 0)
996  {
997  // phpcs:enable
998  global $user, $hookmanager, $action;
999 
1000  $error = 0;
1001 
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;
1006 
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);
1013  }
1014  $sql .= " WHERE ";
1015  $sql .= " c.entity IN (".getEntity('mo').")";
1016 
1017  $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1018  $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1019  if ($socid > 0) {
1020  $sql .= " AND c.fk_soc = ".((int) $socid);
1021  }
1022 
1023  $result = $this->db->query($sql);
1024  if ($result) {
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; // qty may be a float due to the SUM()
1029  } else {
1030  $this->error = $this->db->error();
1031  $error++;
1032  }
1033  }
1034 
1035  if (!empty($error)) {
1036  return -1;
1037  }
1038 
1039  $parameters = array('socid' => $socid);
1040  $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1041  if ($reshook > 0) {
1042  $this->stats_mo = $hookmanager->resArray['stats_mo'];
1043  }
1044 
1045  return 1;
1046  }
1047 
1048 
1055  public function getLibStatut($mode = 0)
1056  {
1057  return $this->LibStatut(0, $mode);
1058  }
1059 
1060  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1068  public function LibStatut($status, $mode = 0)
1069  {
1070  // phpcs:enable
1071  //global $langs;
1072 
1073  //$langs->load('stocks');
1074 
1075  return '';
1076  }
1077 
1078 
1086  public function getTooltipContentArray($params)
1087  {
1088  global $langs, $user;
1089 
1090  $langs->loadLangs(['stocks', 'productbatch']);
1091 
1092  //$option = $params['option'] ?? '';
1093 
1094  $datas = [];
1095  $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1096  //$datas['divopen'] = '<div width="100%">';
1097  $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1098  if ($this->eatby && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1099  $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->db->jdate($this->eatby), 'day');
1100  }
1101  if ($this->sellby && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1102  $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->db->jdate($this->sellby), 'day');
1103  }
1104  //$datas['divclose'] = '</div>';
1105 
1106  return $datas;
1107  }
1108 
1121  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1122  {
1123  global $langs, $hookmanager;
1124 
1125  $result = '';
1126  $params = [
1127  'id' => $this->id,
1128  'objecttype' => $this->element,
1129  'option' => $option,
1130  ];
1131  $classfortooltip = 'classfortooltip';
1132  $dataparams = '';
1133  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1134  $classfortooltip = 'classforajaxtooltip';
1135  $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1136  $label = '';
1137  } else {
1138  $label = implode($this->getTooltipContentArray($params));
1139  }
1140 
1141  $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1142 
1143  if ($option != 'nolink') {
1144  // Add param to save lastsearch_values or not
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;
1148  }
1149  if ($add_save_lastsearch_values) {
1150  $url .= '&save_lastsearch_values=1';
1151  }
1152  }
1153 
1154  $linkclose = '';
1155  if (empty($notooltip)) {
1156  if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1157  $label = $langs->trans("ShowMyObject");
1158  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1159  }
1160  $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1161  $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1162  } else {
1163  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1164  }
1165 
1166  if ($option == 'nolink') {
1167  $linkstart = '<span';
1168  } else {
1169  $linkstart = '<a href="'.$url.'"';
1170  }
1171  $linkstart .= $linkclose.'>';
1172  if ($option == 'nolink') {
1173  $linkend = '</span>';
1174  } else {
1175  $linkend = '</a>';
1176  }
1177 
1178  $result .= $linkstart;
1179  if ($withpicto) {
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);
1181  }
1182  if ($withpicto != 2) {
1183  $result .= $this->batch;
1184  }
1185  $result .= $linkend;
1186 
1187  global $action;
1188  $hookmanager->initHooks(array('productlotdao'));
1189  $parameters = array('id' => $this->id, 'getnomurl' => $result);
1190  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1191  if ($reshook > 0) {
1192  $result = $hookmanager->resPrint;
1193  } else {
1194  $result .= $hookmanager->resPrint;
1195  }
1196 
1197  return $result;
1198  }
1199 
1200 
1207  public function initAsSpecimen()
1208  {
1209  global $conf;
1210 
1211  $now = dol_now();
1212 
1213  // Initialise parameters
1214  $this->id = 0;
1215  $this->ref = 'SPECIMEN';
1216  $this->specimen = 1;
1217 
1218  $this->entity = $conf->entity;
1219  $this->fk_product = 0;
1220  $this->batch = '';
1221  $this->eatby = $now - 100000;
1222  $this->sellby = $now - 100000;
1223  $this->datec = $now - 3600;
1224  $this->tms = $now;
1225  $this->fk_user_creat = 0;
1226  $this->fk_user_modif = 0;
1227  $this->import_key = '123456';
1228 
1229  return 1;
1230  }
1231 
1242  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1243  {
1244  global $langs;
1245 
1246  $langs->loadLangs(array('stocks', 'productbatch', "products"));
1247  $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1248 
1249  // Positionne le modele sur le nom du modele a utiliser
1250  if (!dol_strlen($modele)) {
1251  $modele = '';
1252 
1253  if (!empty($this->model_pdf)) {
1254  $modele = $this->model_pdf;
1255  } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1256  $modele = getDolGlobalString('PRODUCT_BATCH_ADDON_PDF');
1257  }
1258  }
1259 
1260  $modelpath = "core/modules/product_batch/doc/";
1261 
1262  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1263  }
1264 
1273  public function validateField($fields, $fieldKey, $fieldValue)
1274  {
1275  // Add your own validation rules here.
1276  if ($fieldKey == 'batch') {
1277  if (preg_match('/\s/', $fieldValue)) {
1278  $this->error = 'ErrorABatchShouldNotContainsSpaces';
1279  return false;
1280  }
1281  }
1282 
1283  return parent::validateField($fields, $fieldKey, $fieldValue);
1284  }
1285 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
$object ref
Definition: info.php:79
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.
Definition: user.class.php:50
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.
Definition: index.php:745
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.