dolibarr 23.0.3
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-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024-2025 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
31require_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
39{
43 public $element = 'productlot';
44
48 public $table_element = 'product_lot';
49
53 public $picto = 'lot';
54
58 public $stats_propale;
59
63 public $stats_commande;
64
68 public $stats_contrat;
69
73 public $stats_facture;
74
78 public $stats_commande_fournisseur;
79
83 public $stats_expedition;
84
88 public $stats_reception;
89
93 public $stats_supplier_order;
94
98 public $stats_mo;
102 public $stats_bom;
106 public $stats_mrptoconsume;
110 public $stats_mrptoproduce;
114 public $stats_facturerec;
118 public $stats_facture_fournisseur;
119
120
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 'manufacturing_date' => array('type' => 'date', 'label' => 'ManufacturingDate', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 1 : 0', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 5 : 0', 'position' => 50, 'help' => 'Date of first manufacturing of the lot'),
155 'sellby' => array('type' => 'date', 'label' => 'SellByDate', 'enabled' => 'getDolGlobalInt("PRODUCT_DISABLE_SELLBY") ? 0 : 1', 'visible' => 1, 'notnull' => 0, 'position' => 60),
156 'eatby' => array('type' => 'date', 'label' => 'EatByDate', 'enabled' => 'getDolGlobalInt("PRODUCT_DISABLE_EATBY") ? 0 : 1', 'visible' => 1, 'notnull' => 0, 'position' => 62),
157 '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),
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),
159 //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
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)
169 );
170
174 public $fk_product;
175
179 public $batch;
180
184 public $eatby = '';
185
189 public $sellby = '';
190
194 public $eol_date = '';
195
199 public $manufacturing_date = '';
200
204 public $scrapping_date = '';
205 //public $commissionning_date = '';
209 public $qc_frequency = '';
213 public $lifetime = '';
217 public $datec = '';
218
222 public $fk_user_creat;
223
227 public $fk_user_modif;
228
232 public $import_key;
233
234
240 public function __construct(DoliDB $db)
241 {
242 $this->db = $db;
243
244 $this->ismultientitymanaged = 1;
245 }
246
253 public function checkSellOrEatByMandatory($onlyFieldName = '')
254 {
255 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
256 return 0;
257 }
258
259 $errorMsgArr = array();
260 if ($this->fk_product > 0) {
261 $res = $this->fetch_product();
262 $product = $this->product;
263 if ($res <= 0) {
264 $errorMsgArr[] = $product->errorsToString();
265 }
266
267 if (empty($errorMsgArr)) {
268 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
269 }
270 }
271
272 if (!empty($errorMsgArr)) {
273 $this->errors = array_merge($this->errors, $errorMsgArr);
274 return -1;
275 } else {
276 return 1;
277 }
278 }
279
289 public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
290 {
291 global $db;
292
293 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
294 return null;
295 }
296
297 $errorMsgArr = array();
298 if ($productId > 0) {
299 $product = new Product($db);
300 $res = $product->fetch($productId);
301 if ($res <= 0) {
302 $errorMsgArr[] = $product->errorsToString();
303 }
304
305 if (empty($errorMsgArr)) {
306 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
307 }
308 }
309
310 return $errorMsgArr;
311 }
312
323 public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
324 {
325 global $langs;
326
327 if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
328 return null;
329 }
330
331 $errorMsgArr = array();
332 $checkSellByMandatory = false;
333 $checkEatByMandatory = false;
334
335 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
336 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
337 $checkSellByMandatory = true;
338 } elseif (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
339 $checkEatByMandatory = true;
340 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
341 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
342 $checkSellByMandatory = true;
343 }
344 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
345 $checkEatByMandatory = true;
346 }
347 }
348
349 if ($checkSellByMandatory) {
350 if (!isset($sellBy) || dol_strlen((string) $sellBy) == 0) {
351 // error : sell by is mandatory
352 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
353 }
354 }
355 if ($checkEatByMandatory) {
356 if (!isset($eatBy) || dol_strlen((string) $eatBy) == 0) {
357 // error : eat by is mandatory
358 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
359 }
360 }
361
362 return $errorMsgArr;
363 }
364
365
373 public function create(User $user, $notrigger = 0)
374 {
375 global $conf, $langs;
376
377 dol_syslog(__METHOD__, LOG_DEBUG);
378
379 $error = 0;
380
381 // Clean parameters
382
383 if (isset($this->entity)) {
384 $this->entity = (int) $this->entity;
385 }
386 if (isset($this->fk_product)) {
387 $this->fk_product = (int) $this->fk_product;
388 }
389 if (isset($this->batch)) {
390 $this->batch = trim($this->batch);
391 }
392 if (isset($this->fk_user_creat)) {
393 $this->fk_user_creat = (int) $this->fk_user_creat;
394 }
395 if (isset($this->fk_user_modif)) {
396 $this->fk_user_modif = (int) $this->fk_user_modif;
397 }
398 if (isset($this->import_key)) {
399 $this->import_key = trim($this->import_key);
400 }
401
402 // Check parameters
403 if ($this->batch === '') {
404 $this->errors[] = $langs->trans("ErrorBadValueForBatch");
405 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
406 return -1;
407 }
408 // Put here code to add control on parameters values
409 $res = $this->checkSellOrEatByMandatory();
410 if ($res < 0) {
411 $error++;
412 }
413
414 if (!$error) {
415 // Insert request
416 $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '(';
417 $sql .= 'entity,';
418 $sql .= 'fk_product,';
419 $sql .= 'batch,';
420 $sql .= 'eatby,';
421 $sql .= 'sellby,';
422 $sql .= 'eol_date,';
423 $sql .= 'manufacturing_date,';
424 $sql .= 'scrapping_date,';
425 //$sql .= 'commissionning_date,';
426 $sql .= 'qc_frequency,';
427 $sql .= 'lifetime,';
428 $sql .= 'datec,';
429 $sql .= 'fk_user_creat,';
430 $sql .= 'fk_user_modif,';
431 $sql .= 'import_key';
432 $sql .= ') VALUES (';
433 $sql .= ' ' . (!isset($this->entity) ? $conf->entity : $this->entity) . ',';
434 $sql .= ' ' . (!isset($this->fk_product) ? 'NULL' : $this->fk_product) . ',';
435 $sql .= ' ' . (!isset($this->batch) ? 'NULL' : "'" . $this->db->escape($this->batch) . "'") . ',';
436 $sql .= ' ' . (!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'" . $this->db->idate($this->eatby) . "'") . ',';
437 $sql .= ' ' . (!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'" . $this->db->idate($this->sellby) . "'") . ',';
438 $sql .= ' ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->eol_date) . "'") . ',';
439 $sql .= ' ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->manufacturing_date) . "'") . ',';
440 $sql .= ' ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->scrapping_date) . "'") . ',';
441 //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").',';
442 $sql .= ' '.(empty($this->qc_frequency) ? 'NULL' : $this->qc_frequency).',';
443 $sql .= ' '.(empty($this->lifetime) ? 'NULL' : $this->lifetime).',';
444 $sql .= ' ' . "'" . $this->db->idate(dol_now()) . "'" . ',';
445 $sql .= ' ' . (!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat) . ',';
446 $sql .= ' ' . (!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif) . ',';
447 $sql .= ' ' . (!isset($this->import_key) ? 'NULL' : $this->import_key);
448 $sql .= ')';
449
450 $this->db->begin();
451
452 $resql = $this->db->query($sql);
453 if (!$resql) {
454 $error++;
455 $this->errors[] = 'Error ' . $this->db->lasterror();
456 }
457
458 if (!$error) {
459 $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
460
461 // Actions on extra fields
462 if (!$error) {
463 $result = $this->insertExtraFields();
464 if ($result < 0) {
465 $error++;
466 }
467 }
468
469 if (!$error && !$notrigger) {
470 // Call triggers
471 $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
472 if ($result < 0) {
473 $error++;
474 }
475 // End call triggers
476 }
477 }
478
479 // Commit or rollback
480 if ($error) {
481 $this->db->rollback();
482 } else {
483 $this->db->commit();
484 }
485 }
486
487 if ($error) {
488 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
489 return -1 * $error;
490 } else {
491 return $this->id;
492 }
493 }
494
504 public function fetch($id = 0, $product_id = 0, $batch = '')
505 {
506 global $conf;
507 dol_syslog(__METHOD__, LOG_DEBUG);
508
509 $sql = "SELECT";
510 $sql .= " t.rowid,";
511 $sql .= " t.entity,";
512 $sql .= " t.fk_product,";
513 $sql .= " t.batch,";
514 $sql .= " t.eatby,";
515 $sql .= " t.sellby,";
516 $sql .= " t.eol_date,";
517 $sql .= " t.manufacturing_date,";
518 $sql .= " t.scrapping_date,";
519 //$sql .= " t.commissionning_date,";
520 $sql .= " t.qc_frequency,";
521 $sql .= " t.lifetime,";
522 $sql .= " t.model_pdf,";
523 $sql .= " t.last_main_doc,";
524 $sql .= " t.datec,";
525 $sql .= " t.tms,";
526 $sql .= " t.fk_user_creat,";
527 $sql .= " t.fk_user_modif,";
528 $sql .= " t.import_key,";
529 $sql .= " t.note_public,";
530 $sql .= " t.note_private";
531 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
532 if ($product_id > 0 && $batch != '') {
533 $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id);
534 } else {
535 $sql .= " WHERE t.rowid = ".((int) $id);
536 }
537
538 $resql = $this->db->query($sql);
539 if ($resql) {
540 $numrows = $this->db->num_rows($resql);
541 if ($numrows) {
542 $obj = $this->db->fetch_object($resql);
543
544 $this->id = $obj->rowid;
545 $this->ref = $obj->rowid;
546 //$this->ref = $obj->fk_product.'_'.$obj->batch;
547
548 $this->batch = $obj->batch;
549 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
550 $this->fk_product = $obj->fk_product;
551 $this->eatby = $this->db->jdate($obj->eatby);
552 $this->sellby = $this->db->jdate($obj->sellby);
553 $this->eol_date = $this->db->jdate($obj->eol_date);
554 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
555 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
556 //$this->commissionning_date = $this->db->jdate($obj->commissionning_date);
557 $this->qc_frequency = $obj->qc_frequency;
558 $this->lifetime = $obj->lifetime;
559 $this->model_pdf = $obj->model_pdf;
560 $this->last_main_doc = $obj->last_main_doc;
561
562 $this->datec = $this->db->jdate($obj->datec);
563 $this->tms = $this->db->jdate($obj->tms);
564 $this->fk_user_creat = $obj->fk_user_creat;
565 $this->fk_user_modif = $obj->fk_user_modif;
566 $this->import_key = $obj->import_key;
567 $this->note_public = $obj->note_public;
568 $this->note_private = $obj->note_private;
569
570 // Retrieve all extrafield
571 // fetch optionals attributes and labels
572 $this->fetch_optionals();
573 }
574 $this->db->free($resql);
575
576 if ($numrows) {
577 return 1;
578 } else {
579 return 0;
580 }
581 } else {
582 $this->errors[] = 'Error '.$this->db->lasterror();
583 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
584
585 return -1;
586 }
587 }
588
596 public function update(User $user, $notrigger = 0)
597 {
598 $error = 0;
599
600 dol_syslog(__METHOD__, LOG_DEBUG);
601
602 // Clean parameters
603
604 if (isset($this->entity)) {
605 $this->entity = (int) $this->entity;
606 }
607 if (isset($this->fk_product)) {
608 $this->fk_product = (int) $this->fk_product;
609 }
610 if (isset($this->batch)) {
611 $this->batch = trim($this->batch);
612 }
613 if (isset($this->fk_user_creat)) {
614 $this->fk_user_creat = (int) $this->fk_user_creat;
615 }
616 if (isset($this->fk_user_modif)) {
617 $this->fk_user_modif = (int) $this->fk_user_modif;
618 }
619 if (isset($this->import_key)) {
620 $this->import_key = trim($this->import_key);
621 }
622
623 // Check parameters
624 // Put here code to add a control on parameters values
625 $res = $this->checkSellOrEatByMandatory();
626 if ($res < 0) {
627 $error++;
628 }
629
630 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
631 if (empty($this->oldcopy)) {
632 $this->oldcopy = dol_clone($this, 2);
633 }
634
635 if (!$error) {
636 // Update request
637 $sql = 'UPDATE ' . $this->db->prefix() . $this->table_element . ' SET';
638 $sql .= ' entity = ' . (isset($this->entity) ? $this->entity : "null") . ',';
639 $sql .= ' fk_product = ' . (isset($this->fk_product) ? $this->fk_product : "null") . ',';
640 $sql .= ' batch = ' . (isset($this->batch) ? "'" . $this->db->escape($this->batch) . "'" : "null") . ',';
641 $sql .= ' eatby = ' . (!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'" . $this->db->idate($this->eatby) . "'" : 'null') . ',';
642 $sql .= ' sellby = ' . (!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'" . $this->db->idate($this->sellby) . "'" : 'null') . ',';
643 $sql .= ' eol_date = ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'" . $this->db->idate($this->eol_date) . "'" : 'null') . ',';
644 $sql .= ' manufacturing_date = ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'" . $this->db->idate($this->manufacturing_date) . "'" : 'null') . ',';
645 $sql .= ' scrapping_date = ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'" . $this->db->idate($this->scrapping_date) . "'" : 'null') . ',';
646 //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').',';
647 $sql .= ' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency : 'null').',';
648 $sql .= ' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime : 'null').',';
649 $sql .= ' datec = ' . (dol_strlen((string) $this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ',';
650 $sql .= ' tms = ' . (dol_strlen((string) $this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : "'" . $this->db->idate(dol_now()) . "'") . ',';
651 $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ',';
652 $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ',';
653 $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null");
654 $sql .= ' WHERE rowid=' . ((int) $this->id);
655
656 $this->db->begin();
657
658 $resql = $this->db->query($sql);
659 if (!$resql) {
660 $error++;
661 $this->errors[] = 'Error ' . $this->db->lasterror();
662 }
663
664 // Actions on extra fields
665 if (!$error) {
666 $result = $this->insertExtraFields();
667 if ($result < 0) {
668 $error++;
669 }
670 }
671
672 if (!$error && !$notrigger) {
673 // Call triggers
674 $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
675 if ($result < 0) {
676 $error++;
677 }
678 // End call triggers
679 }
680
681 // Commit or rollback
682 if ($error) {
683 $this->db->rollback();
684 } else {
685 $this->db->commit();
686 }
687 }
688
689 if ($error) {
690 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
691 return -1 * $error;
692 } else {
693 return 1;
694 }
695 }
696
704 public function delete(User $user, $notrigger = 0)
705 {
706 dol_syslog(__METHOD__, LOG_DEBUG);
707
708 $error = 0;
709
710 $this->db->begin();
711
712 // Check there is no stock for this lot
713 $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
714 $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'";
715 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
716 $sql .= $this->db->plimit(1);
717
718 $resql = $this->db->query($sql);
719 if ($resql) {
720 $obj = $this->db->fetch_object($resql);
721 if ($obj) {
722 $error++;
723 $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
724 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
725 }
726 } else {
727 $error++;
728 $this->errors[] = 'Error '.$this->db->lasterror();
729 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
730 }
731
732 // Check there is no movement for this lot
733 $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm";
734 $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'";
735 $sql .= " AND sm.fk_product = ".((int) $this->fk_product);
736 $sql .= $this->db->plimit(1);
737
738 $resql = $this->db->query($sql);
739 if ($resql) {
740 $obj = $this->db->fetch_object($resql);
741 if ($obj) {
742 $error++;
743 $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.';
744 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
745 }
746 } else {
747 $error++;
748 $this->errors[] = 'Error '.$this->db->lasterror();
749 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
750 }
751
752 // TODO
753 //if (!$error) {
754 //if (!$notrigger) {
755 // Uncomment this and change PRODUCTLOT to your own tag if you
756 // want this action calls a trigger.
757
759 //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
760 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
762 //}
763 //}
764
765 if (!$error) {
766 $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
767 $sql .= ' WHERE rowid='.((int) $this->id);
768
769 $resql = $this->db->query($sql);
770 if (!$resql) {
771 $error++;
772 $this->errors[] = 'Error '.$this->db->lasterror();
773 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
774 }
775 }
776
777 // Commit or rollback
778 if ($error) {
779 $this->db->rollback();
780
781 return -1 * $error;
782 } else {
783 $this->db->commit();
784
785 return 1;
786 }
787 }
788
796 public function createFromClone(User $user, $fromid)
797 {
798 dol_syslog(__METHOD__, LOG_DEBUG);
799
800 $error = 0;
801 $object = new Productlot($this->db);
802
803 $this->db->begin();
804
805 // Load source object
806 $object->fetch($fromid);
807 // Reset object
808 $object->id = 0;
809
810 // Clear fields
811 // ...
812
813 // Create clone
814 $object->context['createfromclone'] = 'createfromclone';
815 $result = $object->create($user);
816
817 // Other options
818 if ($result < 0) {
819 $error++;
820 $this->errors = $object->errors;
821 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
822 }
823
824 unset($object->context['createfromclone']);
825
826 // End
827 if (!$error) {
828 $this->db->commit();
829
830 return $object->id;
831 } else {
832 $this->db->rollback();
833
834 return -1;
835 }
836 }
837
844 public function loadStatsExpedition($socid = 0)
845 {
846 global $user, $hookmanager, $action;
847
848 $sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
849 $sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
850 $sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
851 $sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
852 $sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
853 // $sql .= ", ".$this->db->prefix()."societe as s";
854 if (!$user->hasRight('societe', 'client', 'voir')) {
855 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
856 }
857 $sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
858 $sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
859 if (!$user->hasRight('societe', 'client', 'voir')) {
860 $sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
861 }
862 //$sql.= " AND exp.fk_statut != 0";
863 if ($socid > 0) {
864 $sql .= " AND exp.fk_soc = ".((int) $socid);
865 }
866
867 $result = $this->db->query($sql);
868 if ($result) {
869 $obj = $this->db->fetch_object($result);
870 $this->stats_expedition['customers'] = $obj->nb_customers;
871 $this->stats_expedition['nb'] = $obj->nb;
872 $this->stats_expedition['rows'] = $obj->nb_rows;
873 $this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
874
875
876 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
877
878 // if it's a virtual product, maybe it is in invoice by extension
879 // if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) {
880 // $TFather = $this->getFather();
881 // if (is_array($TFather) && !empty($TFather)) {
882 // foreach ($TFather as &$fatherData) {
883 // $pFather = new Product($this->db);
884 // $pFather->id = $fatherData['id'];
885 // $qtyCoef = $fatherData['qty'];
886 //
887 // if ($fatherData['incdec']) {
888 // $pFather->loadStatsExpedition($socid);
889 //
890 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
891 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
892 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
893 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
894 // }
895 // }
896 // }
897 // }
898
899 $parameters = array('socid' => $socid);
900 $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
901 if ($reshook > 0) {
902 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
903 }
904
905 return 1;
906 } else {
907 $this->error = $this->db->error();
908 return -1;
909 }
910 }
911
918 public function loadStatsSupplierOrder($socid = 0)
919 {
920 global $user, $hookmanager, $action;
921
922 $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
923 $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
924 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
925 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
926 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
927 // $sql .= ", ".$this->db->prefix()."societe as s";
928 if (!$user->hasRight('societe', 'client', 'voir')) {
929 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
930 }
931 $sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
932 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
933 $sql .= " AND cfdi.fk_product = " . (int) $this->fk_product;
934 if (!$user->hasRight('societe', 'client', 'voir')) {
935 $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
936 }
937 //$sql.= " AND cf.fk_statut != 0";
938 if ($socid > 0) {
939 $sql .= " AND cf.fk_soc = ".((int) $socid);
940 }
941
942 $result = $this->db->query($sql);
943 if ($result) {
944 $obj = $this->db->fetch_object($result);
945 $this->stats_supplier_order['customers'] = $obj->nb_customers;
946 $this->stats_supplier_order['nb'] = $obj->nb;
947 $this->stats_supplier_order['rows'] = $obj->nb_rows;
948 $this->stats_supplier_order['qty'] = $obj->qty ? $obj->qty : 0;
949
950
951 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
952
953 // if it's a virtual product, maybe it is in invoice by extension
954 // if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) {
955 // $TFather = $this->getFather();
956 // if (is_array($TFather) && !empty($TFather)) {
957 // foreach ($TFather as &$fatherData) {
958 // $pFather = new Product($this->db);
959 // $pFather->id = $fatherData['id'];
960 // $qtyCoef = $fatherData['qty'];
961 //
962 // if ($fatherData['incdec']) {
963 // $pFather->stats_supplier_order($socid);
964 //
965 // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
966 // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
967 // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
968 // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
969 // }
970 // }
971 // }
972 // }
973
974 $parameters = array('socid' => $socid);
975 $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
976 if ($reshook > 0) {
977 $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
978 }
979
980 return 1;
981 } else {
982 $this->error = $this->db->error();
983 return -1;
984 }
985 }
986
993 public function loadStatsReception($socid = 0)
994 {
995 global $user, $hookmanager, $action;
996
997 $sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
998 $sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
999 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
1000 $sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
1001 // $sql .= ", ".$this->db->prefix()."societe as s";
1002 if (!$user->hasRight('societe', 'client', 'voir')) {
1003 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
1004 }
1005 $sql .= " WHERE recep.entity IN (".getEntity('reception').")";
1006 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
1007 if (!$user->hasRight('societe', 'client', 'voir')) {
1008 $sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1009 }
1010 //$sql.= " AND exp.fk_statut != 0";
1011 if ($socid > 0) {
1012 $sql .= " AND recep.fk_soc = ".((int) $socid);
1013 }
1014
1015 $result = $this->db->query($sql);
1016 if ($result) {
1017 $obj = $this->db->fetch_object($result);
1018 $this->stats_reception['customers'] = $obj->nb_customers;
1019 $this->stats_reception['nb'] = $obj->nb;
1020 $this->stats_reception['rows'] = $obj->nb_rows;
1021 $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
1022
1023
1024 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
1025
1026 // if it's a virtual product, maybe it is in invoice by extension
1027 // if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) {
1028 // $TFather = $this->getFather();
1029 // if (is_array($TFather) && !empty($TFather)) {
1030 // foreach ($TFather as &$fatherData) {
1031 // $pFather = new Product($this->db);
1032 // $pFather->id = $fatherData['id'];
1033 // $qtyCoef = $fatherData['qty'];
1034 //
1035 // if ($fatherData['incdec']) {
1036 // $pFather->loadStatsReception($socid);
1037 //
1038 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
1039 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
1040 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
1041 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
1042 // }
1043 // }
1044 // }
1045 // }
1046
1047 $parameters = array('socid' => $socid);
1048 $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
1049 if ($reshook > 0) {
1050 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
1051 }
1052
1053 return 1;
1054 } else {
1055 $this->error = $this->db->error();
1056 return -1;
1057 }
1058 }
1059
1066 public function loadStatsMo($socid = 0)
1067 {
1068 global $user, $hookmanager, $action;
1069
1070 $error = 0;
1071
1072 foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
1073 $this->stats_mo['customers_'.$role] = 0;
1074 $this->stats_mo['nb_'.$role] = 0;
1075 $this->stats_mo['qty_'.$role] = 0;
1076
1077 $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1078 $sql .= " SUM(mp.qty) as qty";
1079 $sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
1080 $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
1081 if (!$user->hasRight('societe', 'client', 'voir')) {
1082 $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1083 }
1084 $sql .= " WHERE ";
1085 $sql .= " c.entity IN (".getEntity('mo').")";
1086
1087 $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1088 $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1089 if ($socid > 0) {
1090 $sql .= " AND c.fk_soc = ".((int) $socid);
1091 }
1092
1093 $result = $this->db->query($sql);
1094 if ($result) {
1095 $obj = $this->db->fetch_object($result);
1096 $this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1097 $this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
1098 $this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
1099 } else {
1100 $this->error = $this->db->error();
1101 $error++;
1102 }
1103 }
1104
1105 if (!empty($error)) {
1106 return -1;
1107 }
1108
1109 $parameters = array('socid' => $socid);
1110 $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1111 if ($reshook > 0) {
1112 $this->stats_mo = $hookmanager->resArray['stats_mo'];
1113 }
1114
1115 return 1;
1116 }
1117
1118
1125 public function getLibStatut($mode = 0)
1126 {
1127 return $this->LibStatut(0, $mode);
1128 }
1129
1130 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1138 public function LibStatut($status, $mode = 0)
1139 {
1140 // phpcs:enable
1141 //global $langs;
1142
1143 //$langs->load('stocks');
1144
1145 return '';
1146 }
1147
1148
1155 public function getTooltipContentArray($params)
1156 {
1157 global $langs;
1158
1159 $langs->loadLangs(['stocks', 'productbatch']);
1160
1161 //$option = $params['option'] ?? '';
1162
1163 $datas = [];
1164 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1165 //$datas['divopen'] = '<div width="100%">';
1166 $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1167 if (isDolTms($this->eatby) && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1168 $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
1169 }
1170 if (isDolTms($this->sellby) && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1171 $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
1172 }
1173 //$datas['divclose'] = '</div>';
1174
1175 return $datas;
1176 }
1177
1190 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1191 {
1192 global $langs, $hookmanager;
1193
1194 $result = '';
1195 $params = [
1196 'id' => $this->id,
1197 'objecttype' => $this->element,
1198 'option' => $option,
1199 ];
1200 $classfortooltip = 'classfortooltip';
1201 $dataparams = '';
1202 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1203 $classfortooltip = 'classforajaxtooltip';
1204 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1205 $label = '';
1206 } else {
1207 $label = implode($this->getTooltipContentArray($params));
1208 }
1209
1210 $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1211
1212 if ($option != 'nolink') {
1213 // Add param to save lastsearch_values or not
1214 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1215 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1216 $add_save_lastsearch_values = 1;
1217 }
1218 if ($add_save_lastsearch_values) {
1219 $url .= '&save_lastsearch_values=1';
1220 }
1221 }
1222
1223 $linkclose = '';
1224 if (empty($notooltip)) {
1225 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1226 $label = $langs->trans("ShowMyObject");
1227 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1228 }
1229 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1230 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1231 } else {
1232 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1233 }
1234
1235 if ($option == 'nolink') {
1236 $linkstart = '<span';
1237 } else {
1238 $linkstart = '<a href="'.$url.'"';
1239 }
1240 $linkstart .= $linkclose.'>';
1241 if ($option == 'nolink') {
1242 $linkend = '</span>';
1243 } else {
1244 $linkend = '</a>';
1245 }
1246
1247 $result .= $linkstart;
1248 if ($withpicto) {
1249 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1250 }
1251 if ($withpicto != 2) {
1252 $result .= $this->batch;
1253 }
1254 $result .= $linkend;
1255
1256 global $action;
1257 $hookmanager->initHooks(array('productlotdao'));
1258 $parameters = array('id' => $this->id, 'getnomurl' => $result);
1259 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1260 if ($reshook > 0) {
1261 $result = $hookmanager->resPrint;
1262 } else {
1263 $result .= $hookmanager->resPrint;
1264 }
1265
1266 return $result;
1267 }
1268
1269
1276 public function initAsSpecimen()
1277 {
1278 global $conf;
1279
1280 $now = dol_now();
1281
1282 // Initialise parameters
1283 $this->id = 0;
1284 $this->ref = 'SPECIMEN';
1285 $this->specimen = 1;
1286
1287 $this->entity = $conf->entity;
1288 $this->fk_product = 0;
1289 $this->batch = 'ABCD123456';
1290 $this->eatby = $now - 100000;
1291 $this->sellby = $now - 100000;
1292 $this->datec = $now - 3600;
1293 $this->tms = $now;
1294 $this->fk_user_creat = 0;
1295 $this->fk_user_modif = 0;
1296 $this->import_key = '123456';
1297
1298 return 1;
1299 }
1300
1311 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1312 {
1313 global $langs;
1314
1315 $langs->loadLangs(array('stocks', 'productbatch', "products"));
1316 $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1317
1318 // Positionne le modele sur le nom du modele a utiliser
1319 if (!dol_strlen($modele)) {
1320 $modele = '';
1321
1322 if (!empty($this->model_pdf)) {
1323 $modele = $this->model_pdf;
1324 } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1325 $modele = getDolGlobalString('PRODUCT_BATCH_ADDON_PDF');
1326 }
1327 }
1328
1329 $modelpath = "core/modules/product_batch/doc/";
1330
1331 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1332 }
1333
1342 public function validateField($fields, $fieldKey, $fieldValue)
1343 {
1344 // Add your own validation rules here.
1345 if ($fieldKey == 'batch') {
1346 if (preg_match('/\s/', $fieldValue)) {
1347 $this->error = 'ErrorABatchShouldNotContainsSpaces';
1348 return false;
1349 }
1350 }
1351
1352 return parent::validateField($fields, $fieldKey, $fieldValue);
1353 }
1354}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
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.
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_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.