dolibarr 24.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-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Charlene Benke <charlene@patas-monkey.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Put here all includes required by your class file
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
33//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
34//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
35
40{
44 public $element = 'productlot';
45
49 public $table_element = 'product_lot';
50
54 public $picto = 'lot';
55
59 public $stats_propale;
60
64 public $stats_commande;
65
69 public $stats_contrat;
70
74 public $stats_facture;
75
79 public $stats_commande_fournisseur;
80
84 public $stats_expedition;
85
89 public $stats_reception;
90
94 public $stats_supplier_order;
95
99 public $stats_mo;
103 public $stats_bom;
107 public $stats_mrptoconsume;
111 public $stats_mrptoproduce;
115 public $stats_facturerec;
119 public $stats_facture_fournisseur;
120
121
150 public $fields = array(
151 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'noteditable' => 1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id', 'css' => 'left'),
152 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'enabled' => 1, 'visible' => 1, 'position' => 5, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'picto' => 'product', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax250'),
153 'batch' => array('type' => 'varchar(30)', 'label' => 'Batch', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'showoncombobox' => 1, 'index' => 1, 'position' => 10, 'comment' => 'Batch', 'searchall' => 1, 'picto' => 'lot', 'validate' => 1),
154 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 20),
155 'manufacturing_date' => array('type' => 'date', 'label' => 'ManufacturingDate', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 1 : 0', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 5 : 0', 'position' => 50, 'help' => 'Date of first manufacturing of the lot'),
156 'sellby' => array('type' => 'date', 'label' => 'SellByDate', 'enabled' => 'getDolGlobalInt("PRODUCT_DISABLE_SELLBY") ? 0 : 1', 'visible' => 1, 'notnull' => 0, 'position' => 60),
157 'eatby' => array('type' => 'date', 'label' => 'EatByDate', 'enabled' => 'getDolGlobalInt("PRODUCT_DISABLE_EATBY") ? 0 : 1', 'visible' => 1, 'notnull' => 0, 'position' => 62),
158 'eol_date' => array('type' => 'date', 'label' => 'EndOfLife', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 1 : 0 ', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 5 : 0', 'position' => 70),
159 'scrapping_date' => array('type' => 'date', 'label' => 'DestructionDate', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 1 : 0', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY") ? 5 : 0', 'position' => 90),
160 //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
161 'qc_frequency' => array('type' => 'integer', 'label' => 'QCFrequency', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 1 : 0', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 5 : 0', 'position' => 110),
162 'lifetime' => array('type' => 'integer', 'label' => 'Lifetime', 'enabled' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 1 : 0', 'visible' => 'getDolGlobalInt("PRODUCT_LOT_ENABLE_QUALITY_CONTROL") ? 5 : 0', 'position' => 110),
163 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 215),
164 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -2, 'position' => 310),
165 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 500),
166 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
167 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510, 'foreignkey' => 'llx_user.rowid'),
168 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511),
169 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000)
170 );
171
175 public $fk_product;
176
180 public $batch;
181
185 public $eatby = '';
186
190 public $sellby = '';
191
195 public $eol_date = '';
196
200 public $manufacturing_date = '';
201
205 public $scrapping_date = '';
206 //public $commissionning_date = '';
210 public $qc_frequency = '';
214 public $lifetime = '';
218 public $datec = '';
219
223 public $fk_user_creat;
224
228 public $fk_user_modif;
229
233 public $import_key;
234
235
241 public function __construct(DoliDB $db)
242 {
243 $this->db = $db;
244
245 $this->ismultientitymanaged = 1;
246 $this->isextrafieldmanaged = 1;
247 }
248
255 public function checkSellOrEatByMandatory($onlyFieldName = '')
256 {
257 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
258 return 0;
259 }
260
261 $errorMsgArr = array();
262 if ($this->fk_product > 0) {
263 $res = $this->fetch_product();
264 $product = $this->product;
265 if ($res <= 0) {
266 $errorMsgArr[] = $product->errorsToString();
267 }
268
269 if (empty($errorMsgArr)) {
270 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
271 }
272 }
273
274 if (!empty($errorMsgArr)) {
275 $this->errors = array_merge($this->errors, $errorMsgArr);
276 return -1;
277 } else {
278 return 1;
279 }
280 }
281
291 public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
292 {
293 global $db;
294
295 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
296 return null;
297 }
298
299 $errorMsgArr = array();
300 if ($productId > 0) {
301 $product = new Product($db);
302 $res = $product->fetch($productId);
303 if ($res <= 0) {
304 $errorMsgArr[] = $product->errorsToString();
305 }
306
307 if (empty($errorMsgArr)) {
308 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
309 }
310 }
311
312 return $errorMsgArr;
313 }
314
325 public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
326 {
327 global $langs;
328
329 if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
330 return null;
331 }
332
333 $errorMsgArr = array();
334 $checkSellByMandatory = false;
335 $checkEatByMandatory = false;
336
337 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
338 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
339 $checkSellByMandatory = true;
340 } elseif (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
341 $checkEatByMandatory = true;
342 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
343 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
344 $checkSellByMandatory = true;
345 }
346 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
347 $checkEatByMandatory = true;
348 }
349 }
350
351 if ($checkSellByMandatory) {
352 if (!isset($sellBy) || dol_strlen((string) $sellBy) == 0) {
353 // error : sell by is mandatory
354 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
355 }
356 }
357 if ($checkEatByMandatory) {
358 if (!isset($eatBy) || dol_strlen((string) $eatBy) == 0) {
359 // error : eat by is mandatory
360 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
361 }
362 }
363
364 return $errorMsgArr;
365 }
366
367
375 public function create(User $user, $notrigger = 0)
376 {
377 global $conf, $langs;
378
379 dol_syslog(__METHOD__, LOG_DEBUG);
380
381 $error = 0;
382
383 // Clean parameters
384
385 if (isset($this->entity)) {
386 $this->entity = (int) $this->entity;
387 }
388 if (isset($this->fk_product)) {
389 $this->fk_product = (int) $this->fk_product;
390 }
391 if (isset($this->batch)) {
392 $this->batch = trim($this->batch);
393 }
394 if (isset($this->fk_user_creat)) {
395 $this->fk_user_creat = (int) $this->fk_user_creat;
396 }
397 if (isset($this->fk_user_modif)) {
398 $this->fk_user_modif = (int) $this->fk_user_modif;
399 }
400 if (isset($this->import_key)) {
401 $this->import_key = trim($this->import_key);
402 }
403
404 // Check parameters
405 if ($this->batch === '') {
406 $this->errors[] = $langs->trans("ErrorBadValueForBatch");
407 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
408 return -1;
409 }
410 // Put here code to add control on parameters values
411 $res = $this->checkSellOrEatByMandatory();
412 if ($res < 0) {
413 $error++;
414 }
415
416 if (!$error) {
417 // Insert request
418 $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '(';
419 $sql .= 'entity,';
420 $sql .= 'fk_product,';
421 $sql .= 'batch,';
422 $sql .= 'eatby,';
423 $sql .= 'sellby,';
424 $sql .= 'eol_date,';
425 $sql .= 'manufacturing_date,';
426 $sql .= 'scrapping_date,';
427 //$sql .= 'commissionning_date,';
428 $sql .= 'qc_frequency,';
429 $sql .= 'lifetime,';
430 $sql .= 'datec,';
431 $sql .= 'fk_user_creat,';
432 $sql .= 'fk_user_modif,';
433 $sql .= 'import_key';
434 $sql .= ') VALUES (';
435 $sql .= ' ' . (!isset($this->entity) ? $conf->entity : $this->entity) . ',';
436 $sql .= ' ' . (!isset($this->fk_product) ? 'NULL' : $this->fk_product) . ',';
437 $sql .= ' ' . (!isset($this->batch) ? 'NULL' : "'" . $this->db->escape($this->batch) . "'") . ',';
438 $sql .= ' ' . (!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'" . $this->db->idate($this->eatby) . "'") . ',';
439 $sql .= ' ' . (!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'" . $this->db->idate($this->sellby) . "'") . ',';
440 $sql .= ' ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->eol_date) . "'") . ',';
441 $sql .= ' ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->manufacturing_date) . "'") . ',';
442 $sql .= ' ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->scrapping_date) . "'") . ',';
443 //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").',';
444 $sql .= ' '.(empty($this->qc_frequency) ? 'NULL' : $this->qc_frequency).',';
445 $sql .= ' '.(empty($this->lifetime) ? 'NULL' : $this->lifetime).',';
446 $sql .= ' ' . "'" . $this->db->idate(dol_now()) . "'" . ',';
447 $sql .= ' ' . (!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat) . ',';
448 $sql .= ' ' . (!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif) . ',';
449 $sql .= ' ' . (!isset($this->import_key) ? 'NULL' : $this->import_key);
450 $sql .= ')';
451
452 $this->db->begin();
453
454 $resql = $this->db->query($sql);
455 if (!$resql) {
456 $error++;
457 $this->errors[] = 'Error ' . $this->db->lasterror();
458 }
459
460 if (!$error) {
461 $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
462
463 // Actions on extra fields
464 if (!$error) {
465 $result = $this->insertExtraFields();
466 if ($result < 0) {
467 $error++;
468 }
469 }
470
471 if (!$error && !$notrigger) {
472 // Call triggers
473 $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
474 if ($result < 0) {
475 $error++;
476 }
477 // End call triggers
478 }
479 }
480
481 // Commit or rollback
482 if ($error) {
483 $this->db->rollback();
484 } else {
485 $this->db->commit();
486 }
487 }
488
489 if ($error) {
490 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
491 return -1 * $error;
492 } else {
493 return $this->id;
494 }
495 }
496
506 public function fetch($id = 0, $product_id = 0, $batch = '')
507 {
508 global $conf;
509 dol_syslog(__METHOD__, LOG_DEBUG);
510
511 $sql = "SELECT";
512 $sql .= " t.rowid,";
513 $sql .= " t.entity,";
514 $sql .= " t.fk_product,";
515 $sql .= " t.batch,";
516 $sql .= " t.eatby,";
517 $sql .= " t.sellby,";
518 $sql .= " t.eol_date,";
519 $sql .= " t.manufacturing_date,";
520 $sql .= " t.scrapping_date,";
521 //$sql .= " t.commissionning_date,";
522 $sql .= " t.qc_frequency,";
523 $sql .= " t.lifetime,";
524 $sql .= " t.model_pdf,";
525 $sql .= " t.last_main_doc,";
526 $sql .= " t.datec,";
527 $sql .= " t.tms,";
528 $sql .= " t.fk_user_creat,";
529 $sql .= " t.fk_user_modif,";
530 $sql .= " t.import_key,";
531 $sql .= " t.note_public,";
532 $sql .= " t.note_private";
533 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
534 if ($product_id > 0 && $batch != '') {
535 $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id);
536 } else {
537 $sql .= " WHERE t.rowid = ".((int) $id);
538 }
539
540 $resql = $this->db->query($sql);
541 if ($resql) {
542 $numrows = $this->db->num_rows($resql);
543 if ($numrows) {
544 $obj = $this->db->fetch_object($resql);
545
546 $this->id = $obj->rowid;
547 $this->ref = $obj->rowid;
548 //$this->ref = $obj->fk_product.'_'.$obj->batch;
549
550 $this->batch = $obj->batch;
551 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
552 $this->fk_product = $obj->fk_product;
553 $this->eatby = $this->db->jdate($obj->eatby);
554 $this->sellby = $this->db->jdate($obj->sellby);
555 $this->eol_date = $this->db->jdate($obj->eol_date);
556 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
557 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
558 //$this->commissionning_date = $this->db->jdate($obj->commissionning_date);
559 $this->qc_frequency = $obj->qc_frequency;
560 $this->lifetime = $obj->lifetime;
561 $this->model_pdf = $obj->model_pdf;
562 $this->last_main_doc = $obj->last_main_doc;
563
564 $this->datec = $this->db->jdate($obj->datec);
565 $this->tms = $this->db->jdate($obj->tms);
566 $this->fk_user_creat = $obj->fk_user_creat;
567 $this->fk_user_modif = $obj->fk_user_modif;
568 $this->import_key = $obj->import_key;
569 $this->note_public = $obj->note_public;
570 $this->note_private = $obj->note_private;
571
572 // Retrieve all extrafield
573 // fetch optionals attributes and labels
574 $this->fetch_optionals();
575 }
576 $this->db->free($resql);
577
578 if ($numrows) {
579 return 1;
580 } else {
581 return 0;
582 }
583 } else {
584 $this->errors[] = 'Error '.$this->db->lasterror();
585 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
586
587 return -1;
588 }
589 }
590
598 public function update(User $user, $notrigger = 0)
599 {
600 $error = 0;
601
602 dol_syslog(__METHOD__, LOG_DEBUG);
603
604 // Clean parameters
605
606 if (isset($this->entity)) {
607 $this->entity = (int) $this->entity;
608 }
609 if (isset($this->fk_product)) {
610 $this->fk_product = (int) $this->fk_product;
611 }
612 if (isset($this->batch)) {
613 $this->batch = trim($this->batch);
614 }
615 if (isset($this->fk_user_creat)) {
616 $this->fk_user_creat = (int) $this->fk_user_creat;
617 }
618 if (isset($this->fk_user_modif)) {
619 $this->fk_user_modif = (int) $this->fk_user_modif;
620 }
621 if (isset($this->import_key)) {
622 $this->import_key = trim($this->import_key);
623 }
624
625 // Check parameters
626 // Put here code to add a control on parameters values
627 $res = $this->checkSellOrEatByMandatory();
628 if ($res < 0) {
629 $error++;
630 }
631
632 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
633 if (empty($this->oldcopy)) {
634 $this->oldcopy = dol_clone($this, 2);
635 }
636
637 if (!$error) {
638 // Update request
639 $sql = 'UPDATE ' . $this->db->prefix() . $this->table_element . ' SET';
640 $sql .= ' entity = ' . (isset($this->entity) ? $this->entity : "null") . ',';
641 $sql .= ' fk_product = ' . (isset($this->fk_product) ? $this->fk_product : "null") . ',';
642 $sql .= ' batch = ' . (isset($this->batch) ? "'" . $this->db->escape($this->batch) . "'" : "null") . ',';
643 $sql .= ' eatby = ' . (!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'" . $this->db->idate($this->eatby) . "'" : 'null') . ',';
644 $sql .= ' sellby = ' . (!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'" . $this->db->idate($this->sellby) . "'" : 'null') . ',';
645 $sql .= ' eol_date = ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'" . $this->db->idate($this->eol_date) . "'" : 'null') . ',';
646 $sql .= ' manufacturing_date = ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'" . $this->db->idate($this->manufacturing_date) . "'" : 'null') . ',';
647 $sql .= ' scrapping_date = ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'" . $this->db->idate($this->scrapping_date) . "'" : 'null') . ',';
648 //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').',';
649 $sql .= ' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency : 'null').',';
650 $sql .= ' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime : 'null').',';
651 $sql .= ' datec = ' . (dol_strlen((string) $this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ',';
652 $sql .= ' tms = ' . (dol_strlen((string) $this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : "'" . $this->db->idate(dol_now()) . "'") . ',';
653 $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ',';
654 $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ',';
655 $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null");
656 $sql .= ' WHERE rowid=' . ((int) $this->id);
657
658 $this->db->begin();
659
660 $resql = $this->db->query($sql);
661 if (!$resql) {
662 $error++;
663 $this->errors[] = 'Error ' . $this->db->lasterror();
664 }
665
666 // Actions on extra fields
667 if (!$error) {
668 $result = $this->insertExtraFields();
669 if ($result < 0) {
670 $error++;
671 }
672 }
673
674 if (!$error && !$notrigger) {
675 // Call triggers
676 $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
677 if ($result < 0) {
678 $error++;
679 }
680 // End call triggers
681 }
682
683 // Commit or rollback
684 if ($error) {
685 $this->db->rollback();
686 } else {
687 $this->db->commit();
688 }
689 }
690
691 if ($error) {
692 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
693 return -1 * $error;
694 } else {
695 return 1;
696 }
697 }
698
706 public function delete(User $user, $notrigger = 0)
707 {
708 dol_syslog(__METHOD__, LOG_DEBUG);
709
710 $error = 0;
711
712 $this->db->begin();
713
714 // Check there is no stock for this lot
715 $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
716 $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'";
717 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
718 $sql .= $this->db->plimit(1);
719
720 $resql = $this->db->query($sql);
721 if ($resql) {
722 $obj = $this->db->fetch_object($resql);
723 if ($obj) {
724 $error++;
725 $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
726 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
727 }
728 } else {
729 $error++;
730 $this->errors[] = 'Error '.$this->db->lasterror();
731 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
732 }
733
734 // Check there is no movement for this lot
735 $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm";
736 $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'";
737 $sql .= " AND sm.fk_product = ".((int) $this->fk_product);
738 $sql .= $this->db->plimit(1);
739
740 $resql = $this->db->query($sql);
741 if ($resql) {
742 $obj = $this->db->fetch_object($resql);
743 if ($obj) {
744 $error++;
745 $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.';
746 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
747 }
748 } else {
749 $error++;
750 $this->errors[] = 'Error '.$this->db->lasterror();
751 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
752 }
753
754 // TODO
755 //if (!$error) {
756 //if (!$notrigger) {
757 // Uncomment this and change PRODUCTLOT to your own tag if you
758 // want this action calls a trigger.
759
761 //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
762 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
764 //}
765 //}
766
767 if (!$error) {
768 $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
769 $sql .= ' WHERE rowid='.((int) $this->id);
770
771 $resql = $this->db->query($sql);
772 if (!$resql) {
773 $error++;
774 $this->errors[] = 'Error '.$this->db->lasterror();
775 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
776 }
777 }
778
779 // Commit or rollback
780 if ($error) {
781 $this->db->rollback();
782
783 return -1 * $error;
784 } else {
785 $this->db->commit();
786
787 return 1;
788 }
789 }
790
798 public function createFromClone(User $user, $fromid)
799 {
800 dol_syslog(__METHOD__, LOG_DEBUG);
801
802 $error = 0;
803 $object = new Productlot($this->db);
804
805 $this->db->begin();
806
807 // Load source object
808 $object->fetch($fromid);
809 // Reset object
810 $object->id = 0;
811
812 // Clear fields
813 // ...
814
815 // Create clone
816 $object->context['createfromclone'] = 'createfromclone';
817 $result = $object->create($user);
818
819 // Other options
820 if ($result < 0) {
821 $error++;
822 $this->errors = $object->errors;
823 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
824 }
825
826 unset($object->context['createfromclone']);
827
828 // End
829 if (!$error) {
830 $this->db->commit();
831
832 return $object->id;
833 } else {
834 $this->db->rollback();
835
836 return -1;
837 }
838 }
839
846 public function loadStatsExpedition($socid = 0)
847 {
848 global $user, $hookmanager, $action;
849
850 $sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
851 $sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
852 $sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
853 $sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
854 $sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
855 // $sql .= ", ".$this->db->prefix()."societe as s";
856 if (!$user->hasRight('societe', 'client', 'voir')) {
857 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
858 }
859 $sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
860 $sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
861 if (!$user->hasRight('societe', 'client', 'voir')) {
862 $sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
863 }
864 //$sql.= " AND exp.fk_statut != 0";
865 if ($socid > 0) {
866 $sql .= " AND exp.fk_soc = ".((int) $socid);
867 }
868
869 $result = $this->db->query($sql);
870 if ($result) {
871 $obj = $this->db->fetch_object($result);
872 $this->stats_expedition['customers'] = $obj->nb_customers;
873 $this->stats_expedition['nb'] = $obj->nb;
874 $this->stats_expedition['rows'] = $obj->nb_rows;
875 $this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
876
877
878 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
879
880 // if it's a virtual product, maybe it is in invoice by extension
881 // if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) {
882 // $TFather = $this->getFather();
883 // if (is_array($TFather) && !empty($TFather)) {
884 // foreach ($TFather as &$fatherData) {
885 // $pFather = new Product($this->db);
886 // $pFather->id = $fatherData['id'];
887 // $qtyCoef = $fatherData['qty'];
888 //
889 // if ($fatherData['incdec']) {
890 // $pFather->loadStatsExpedition($socid);
891 //
892 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
893 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
894 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
895 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
896 // }
897 // }
898 // }
899 // }
900
901 $parameters = array('socid' => $socid);
902 $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
903 if ($reshook > 0) {
904 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
905 }
906
907 return 1;
908 } else {
909 $this->error = $this->db->error();
910 return -1;
911 }
912 }
913
920 public function loadStatsSupplierOrder($socid = 0)
921 {
922 global $user, $hookmanager, $action;
923
924 $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
925 $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
926 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
927 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
928 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
929 // $sql .= ", ".$this->db->prefix()."societe as s";
930 if (!$user->hasRight('societe', 'client', 'voir')) {
931 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
932 }
933 $sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
934 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
935 $sql .= " AND cfdi.fk_product = " . (int) $this->fk_product;
936 if (!$user->hasRight('societe', 'client', 'voir')) {
937 $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
938 }
939 //$sql.= " AND cf.fk_statut != 0";
940 if ($socid > 0) {
941 $sql .= " AND cf.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_supplier_order['customers'] = $obj->nb_customers;
948 $this->stats_supplier_order['nb'] = $obj->nb;
949 $this->stats_supplier_order['rows'] = $obj->nb_rows;
950 $this->stats_supplier_order['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 (getDolGlobalString('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->stats_supplier_order($socid);
966 //
967 // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
968 // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
969 // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
970 // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
971 // }
972 // }
973 // }
974 // }
975
976 $parameters = array('socid' => $socid);
977 $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
978 if ($reshook > 0) {
979 $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
980 }
981
982 return 1;
983 } else {
984 $this->error = $this->db->error();
985 return -1;
986 }
987 }
988
995 public function loadStatsReception($socid = 0)
996 {
997 global $user, $hookmanager, $action;
998
999 $sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
1000 $sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
1001 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
1002 $sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
1003 // $sql .= ", ".$this->db->prefix()."societe as s";
1004 if (!$user->hasRight('societe', 'client', 'voir')) {
1005 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
1006 }
1007 $sql .= " WHERE recep.entity IN (".getEntity('reception').")";
1008 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
1009 if (!$user->hasRight('societe', 'client', 'voir')) {
1010 $sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1011 }
1012 //$sql.= " AND exp.fk_statut != 0";
1013 if ($socid > 0) {
1014 $sql .= " AND recep.fk_soc = ".((int) $socid);
1015 }
1016
1017 $result = $this->db->query($sql);
1018 if ($result) {
1019 $obj = $this->db->fetch_object($result);
1020 $this->stats_reception['customers'] = $obj->nb_customers;
1021 $this->stats_reception['nb'] = $obj->nb;
1022 $this->stats_reception['rows'] = $obj->nb_rows;
1023 $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
1024
1025
1026 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
1027
1028 // if it's a virtual product, maybe it is in invoice by extension
1029 // if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) {
1030 // $TFather = $this->getFather();
1031 // if (is_array($TFather) && !empty($TFather)) {
1032 // foreach ($TFather as &$fatherData) {
1033 // $pFather = new Product($this->db);
1034 // $pFather->id = $fatherData['id'];
1035 // $qtyCoef = $fatherData['qty'];
1036 //
1037 // if ($fatherData['incdec']) {
1038 // $pFather->loadStatsReception($socid);
1039 //
1040 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
1041 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
1042 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
1043 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
1044 // }
1045 // }
1046 // }
1047 // }
1048
1049 $parameters = array('socid' => $socid);
1050 $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
1051 if ($reshook > 0) {
1052 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
1053 }
1054
1055 return 1;
1056 } else {
1057 $this->error = $this->db->error();
1058 return -1;
1059 }
1060 }
1061
1068 public function loadStatsMo($socid = 0)
1069 {
1070 global $user, $hookmanager, $action;
1071
1072 $error = 0;
1073
1074 foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
1075 $this->stats_mo['customers_'.$role] = 0;
1076 $this->stats_mo['nb_'.$role] = 0;
1077 $this->stats_mo['qty_'.$role] = 0;
1078
1079 $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1080 $sql .= " SUM(mp.qty) as qty";
1081 $sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
1082 $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
1083 if (!$user->hasRight('societe', 'client', 'voir')) {
1084 $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1085 }
1086 $sql .= " WHERE ";
1087 $sql .= " c.entity IN (".getEntity('mo').")";
1088
1089 $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1090 $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1091 if ($socid > 0) {
1092 $sql .= " AND c.fk_soc = ".((int) $socid);
1093 }
1094
1095 $result = $this->db->query($sql);
1096 if ($result) {
1097 $obj = $this->db->fetch_object($result);
1098 $this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1099 $this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
1100 $this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
1101 } else {
1102 $this->error = $this->db->error();
1103 $error++;
1104 }
1105 }
1106
1107 if (!empty($error)) {
1108 return -1;
1109 }
1110
1111 $parameters = array('socid' => $socid);
1112 $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1113 if ($reshook > 0) {
1114 $this->stats_mo = $hookmanager->resArray['stats_mo'];
1115 }
1116
1117 return 1;
1118 }
1119
1120
1127 public function getLibStatut($mode = 0)
1128 {
1129 return $this->LibStatut(0, $mode);
1130 }
1131
1132 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1140 public function LibStatut($status, $mode = 0)
1141 {
1142 // phpcs:enable
1143 //global $langs;
1144
1145 //$langs->load('stocks');
1146
1147 return '';
1148 }
1149
1150
1157 public function getTooltipContentArray($params)
1158 {
1159 global $langs;
1160
1161 $langs->loadLangs(['stocks', 'productbatch']);
1162
1163 //$option = $params['option'] ?? '';
1164
1165 $datas = [];
1166 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1167 //$datas['divopen'] = '<div width="100%">';
1168 $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1169 if (isDolTms($this->eatby) && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1170 $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
1171 }
1172 if (isDolTms($this->sellby) && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1173 $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
1174 }
1175 //$datas['divclose'] = '</div>';
1176
1177 return $datas;
1178 }
1179
1192 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1193 {
1194 global $langs, $hookmanager;
1195
1196 $result = '';
1197 $params = [
1198 'id' => $this->id,
1199 'objecttype' => $this->element,
1200 'option' => $option,
1201 ];
1202 $classfortooltip = 'classfortooltip';
1203 $dataparams = '';
1204 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1205 $classfortooltip = 'classforajaxtooltip';
1206 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1207 $label = '';
1208 } else {
1209 $label = implode($this->getTooltipContentArray($params));
1210 }
1211
1212 $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1213
1214 if ($option != 'nolink') {
1215 // Add param to save lastsearch_values or not
1216 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1217 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1218 $add_save_lastsearch_values = 1;
1219 }
1220 if ($add_save_lastsearch_values) {
1221 $url .= '&save_lastsearch_values=1';
1222 }
1223 }
1224
1225 $linkclose = '';
1226 if (empty($notooltip)) {
1227 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1228 $label = $langs->trans("ShowMyObject");
1229 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1230 }
1231 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
1232 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1233 } else {
1234 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1235 }
1236
1237 if ($option == 'nolink') {
1238 $linkstart = '<span';
1239 } else {
1240 $linkstart = '<a href="'.$url.'"';
1241 }
1242 $linkstart .= $linkclose.'>';
1243 if ($option == 'nolink') {
1244 $linkend = '</span>';
1245 } else {
1246 $linkend = '</a>';
1247 }
1248
1249 $result .= $linkstart;
1250 if ($withpicto) {
1251 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1252 }
1253 if ($withpicto != 2) {
1254 $result .= $this->batch;
1255 }
1256 $result .= $linkend;
1257
1258 global $action;
1259 $hookmanager->initHooks(array('productlotdao'));
1260 $parameters = array('id' => $this->id, 'getnomurl' => $result);
1261 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1262 if ($reshook > 0) {
1263 $result = $hookmanager->resPrint;
1264 } else {
1265 $result .= $hookmanager->resPrint;
1266 }
1267
1268 return $result;
1269 }
1270
1271
1278 public function initAsSpecimen()
1279 {
1280 global $conf;
1281
1282 $now = dol_now();
1283
1284 // Initialise parameters
1285 $this->id = 0;
1286 $this->ref = 'SPECIMEN';
1287 $this->specimen = 1;
1288
1289 $this->entity = $conf->entity;
1290 $this->fk_product = 0;
1291 $this->batch = 'ABCD123456';
1292 $this->eatby = $now - 100000;
1293 $this->sellby = $now - 100000;
1294 $this->datec = $now - 3600;
1295 $this->tms = $now;
1296 $this->fk_user_creat = 0;
1297 $this->fk_user_modif = 0;
1298 $this->import_key = '123456';
1299
1300 return 1;
1301 }
1302
1313 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1314 {
1315 global $langs;
1316
1317 $langs->loadLangs(array('stocks', 'productbatch', "products"));
1318 $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1319
1320 // Positionne le modele sur le nom du modele a utiliser
1321 if (!dol_strlen($modele)) {
1322 $modele = '';
1323
1324 if (!empty($this->model_pdf)) {
1325 $modele = $this->model_pdf;
1326 } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1327 $modele = getDolGlobalString('PRODUCT_BATCH_ADDON_PDF');
1328 }
1329 }
1330
1331 $modelpath = "core/modules/product_batch/doc/";
1332
1333 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1334 }
1335
1344 public function validateField($fields, $fieldKey, $fieldValue)
1345 {
1346 // Add your own validation rules here.
1347 if ($fieldKey == 'batch') {
1348 if (preg_match('/\s/', $fieldValue)) {
1349 $this->error = 'ErrorABatchShouldNotContainsSpaces';
1350 return false;
1351 }
1352 }
1353
1354 return parent::validateField($fields, $fieldKey, $fieldValue);
1355 }
1356}
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.