dolibarr 21.0.0-alpha
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
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;
99 public $stats_bom;
100 public $stats_mrptoconsume;
101 public $stats_mrptoproduce;
102 public $stats_facturerec;
103 public $stats_facture_fournisseur;
104
105
134 public $fields = array(
135 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'noteditable' => 1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id', 'css' => 'left'),
136 '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'),
137 '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),
138 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 20),
139 'sellby' => array('type' => 'date', 'label' => 'SellByDate', 'enabled' => 'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible' => 1, 'notnull' => 0, 'position' => 60),
140 'eatby' => array('type' => 'date', 'label' => 'EatByDate', 'enabled' => 'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0', 'visible' => 1, 'notnull' => 0, 'position' => 62),
141 '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),
142 '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),
143 '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),
144 //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
145 '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),
146 '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),
147 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 215),
148 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -2, 'position' => 310),
149 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 500),
150 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
151 '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'),
152 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511),
153 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000)
154 );
155
159 public $entity;
160
164 public $fk_product;
165
169 public $batch;
170
174 public $eatby = '';
175
179 public $sellby = '';
180
184 public $eol_date = '';
185
189 public $manufacturing_date = '';
190
194 public $scrapping_date = '';
195 //public $commissionning_date = '';
196 public $qc_frequency = '';
197 public $lifetime = '';
198 public $datec = '';
199
203 public $fk_user_creat;
204
208 public $fk_user_modif;
209
213 public $import_key;
214
215
221 public function __construct(DoliDB $db)
222 {
223 $this->db = $db;
224
225 $this->ismultientitymanaged = 1;
226 }
227
234 public function checkSellOrEatByMandatory($onlyFieldName = '')
235 {
236 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
237 return 0;
238 }
239
240 $errorMsgArr = array();
241 if ($this->fk_product > 0) {
242 $res = $this->fetch_product();
243 $product = $this->product;
244 if ($res <= 0) {
245 $errorMsgArr[] = $product->errorsToString();
246 }
247
248 if (empty($errorMsgArr)) {
249 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
250 }
251 }
252
253 if (!empty($errorMsgArr)) {
254 $this->errors = array_merge($this->errors, $errorMsgArr);
255 return -1;
256 } else {
257 return 1;
258 }
259 }
260
270 public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
271 {
272 global $db;
273
274 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
275 return null;
276 }
277
278 $errorMsgArr = array();
279 if ($productId > 0) {
280 $product = new Product($db);
281 $res = $product->fetch($productId);
282 if ($res <= 0) {
283 $errorMsgArr[] = $product->errorsToString();
284 }
285
286 if (empty($errorMsgArr)) {
287 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
288 }
289 }
290
291 return $errorMsgArr;
292 }
293
304 public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
305 {
306 global $langs;
307
308 if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
309 return null;
310 }
311
312 $errorMsgArr = array();
313 $checkSellByMandatory = false;
314 $checkEatByMandatory = false;
315
316 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
317 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
318 $checkSellByMandatory = true;
319 } elseif (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
320 $checkEatByMandatory = true;
321 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
322 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
323 $checkSellByMandatory = true;
324 }
325 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
326 $checkEatByMandatory = true;
327 }
328 }
329
330 if ($checkSellByMandatory) {
331 if (!isset($sellBy) || dol_strlen((string) $sellBy) == 0) {
332 // error : sell by is mandatory
333 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
334 }
335 }
336 if ($checkEatByMandatory) {
337 if (!isset($eatBy) || dol_strlen((string) $eatBy) == 0) {
338 // error : eat by is mandatory
339 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
340 }
341 }
342
343 return $errorMsgArr;
344 }
345
346
354 public function create(User $user, $notrigger = 0)
355 {
356 global $conf, $langs;
357
358 dol_syslog(__METHOD__, LOG_DEBUG);
359
360 $error = 0;
361
362 // Clean parameters
363
364 if (isset($this->entity)) {
365 $this->entity = (int) $this->entity;
366 }
367 if (isset($this->fk_product)) {
368 $this->fk_product = (int) $this->fk_product;
369 }
370 if (isset($this->batch)) {
371 $this->batch = trim($this->batch);
372 }
373 if (isset($this->fk_user_creat)) {
374 $this->fk_user_creat = (int) $this->fk_user_creat;
375 }
376 if (isset($this->fk_user_modif)) {
377 $this->fk_user_modif = (int) $this->fk_user_modif;
378 }
379 if (isset($this->import_key)) {
380 $this->import_key = trim($this->import_key);
381 }
382
383 // Check parameters
384 if ($this->batch === '') {
385 $this->errors[] = $langs->trans("ErrorBadValueForBatch");
386 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
387 return -1;
388 }
389 // Put here code to add control on parameters values
390 $res = $this->checkSellOrEatByMandatory();
391 if ($res < 0) {
392 $error++;
393 }
394
395 if (!$error) {
396 // Insert request
397 $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '(';
398 $sql .= 'entity,';
399 $sql .= 'fk_product,';
400 $sql .= 'batch,';
401 $sql .= 'eatby,';
402 $sql .= 'sellby,';
403 $sql .= 'eol_date,';
404 $sql .= 'manufacturing_date,';
405 $sql .= 'scrapping_date,';
406 //$sql .= 'commissionning_date,';
407 $sql .= 'qc_frequency,';
408 $sql .= 'lifetime,';
409 $sql .= 'datec,';
410 $sql .= 'fk_user_creat,';
411 $sql .= 'fk_user_modif,';
412 $sql .= 'import_key';
413 $sql .= ') VALUES (';
414 $sql .= ' ' . (!isset($this->entity) ? $conf->entity : $this->entity) . ',';
415 $sql .= ' ' . (!isset($this->fk_product) ? 'NULL' : $this->fk_product) . ',';
416 $sql .= ' ' . (!isset($this->batch) ? 'NULL' : "'" . $this->db->escape($this->batch) . "'") . ',';
417 $sql .= ' ' . (!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'" . $this->db->idate($this->eatby) . "'") . ',';
418 $sql .= ' ' . (!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'" . $this->db->idate($this->sellby) . "'") . ',';
419 $sql .= ' ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->eol_date) . "'") . ',';
420 $sql .= ' ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->manufacturing_date) . "'") . ',';
421 $sql .= ' ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->scrapping_date) . "'") . ',';
422 //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").',';
423 $sql .= ' '.(empty($this->qc_frequency) ? 'NULL' : $this->qc_frequency).',';
424 $sql .= ' '.(empty($this->lifetime) ? 'NULL' : $this->lifetime).',';
425 $sql .= ' ' . "'" . $this->db->idate(dol_now()) . "'" . ',';
426 $sql .= ' ' . (!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat) . ',';
427 $sql .= ' ' . (!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif) . ',';
428 $sql .= ' ' . (!isset($this->import_key) ? 'NULL' : $this->import_key);
429 $sql .= ')';
430
431 $this->db->begin();
432
433 $resql = $this->db->query($sql);
434 if (!$resql) {
435 $error++;
436 $this->errors[] = 'Error ' . $this->db->lasterror();
437 }
438
439 if (!$error) {
440 $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
441
442 // Actions on extra fields
443 if (!$error) {
444 $result = $this->insertExtraFields();
445 if ($result < 0) {
446 $error++;
447 }
448 }
449
450 if (!$error && !$notrigger) {
451 // Call triggers
452 $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
453 if ($result < 0) {
454 $error++;
455 }
456 // End call triggers
457 }
458 }
459
460 // Commit or rollback
461 if ($error) {
462 $this->db->rollback();
463 } else {
464 $this->db->commit();
465 }
466 }
467
468 if ($error) {
469 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
470 return -1 * $error;
471 } else {
472 return $this->id;
473 }
474 }
475
485 public function fetch($id = 0, $product_id = 0, $batch = '')
486 {
487 global $conf;
488 dol_syslog(__METHOD__, LOG_DEBUG);
489
490 $sql = "SELECT";
491 $sql .= " t.rowid,";
492 $sql .= " t.entity,";
493 $sql .= " t.fk_product,";
494 $sql .= " t.batch,";
495 $sql .= " t.eatby,";
496 $sql .= " t.sellby,";
497 $sql .= " t.eol_date,";
498 $sql .= " t.manufacturing_date,";
499 $sql .= " t.scrapping_date,";
500 //$sql .= " t.commissionning_date,";
501 $sql .= " t.qc_frequency,";
502 $sql .= " t.lifetime,";
503 $sql .= " t.model_pdf,";
504 $sql .= " t.last_main_doc,";
505 $sql .= " t.datec,";
506 $sql .= " t.tms,";
507 $sql .= " t.fk_user_creat,";
508 $sql .= " t.fk_user_modif,";
509 $sql .= " t.import_key,";
510 $sql .= " t.note_public,";
511 $sql .= " t.note_private";
512 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
513 if ($product_id > 0 && $batch != '') {
514 $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id);
515 } else {
516 $sql .= " WHERE t.rowid = ".((int) $id);
517 }
518
519 $resql = $this->db->query($sql);
520 if ($resql) {
521 $numrows = $this->db->num_rows($resql);
522 if ($numrows) {
523 $obj = $this->db->fetch_object($resql);
524
525 $this->id = $obj->rowid;
526 $this->ref = $obj->rowid;
527 //$this->ref = $obj->fk_product.'_'.$obj->batch;
528
529 $this->batch = $obj->batch;
530 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
531 $this->fk_product = $obj->fk_product;
532 $this->eatby = $this->db->jdate($obj->eatby);
533 $this->sellby = $this->db->jdate($obj->sellby);
534 $this->eol_date = $this->db->jdate($obj->eol_date);
535 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
536 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
537 //$this->commissionning_date = $this->db->jdate($obj->commissionning_date);
538 $this->qc_frequency = $obj->qc_frequency;
539 $this->lifetime = $obj->lifetime;
540 $this->model_pdf = $obj->model_pdf;
541 $this->last_main_doc = $obj->last_main_doc;
542
543 $this->datec = $this->db->jdate($obj->datec);
544 $this->tms = $this->db->jdate($obj->tms);
545 $this->fk_user_creat = $obj->fk_user_creat;
546 $this->fk_user_modif = $obj->fk_user_modif;
547 $this->import_key = $obj->import_key;
548 $this->note_public = $obj->note_public;
549 $this->note_private = $obj->note_private;
550
551 // Retrieve all extrafield
552 // fetch optionals attributes and labels
553 $this->fetch_optionals();
554 }
555 $this->db->free($resql);
556
557 if ($numrows) {
558 return 1;
559 } else {
560 return 0;
561 }
562 } else {
563 $this->errors[] = 'Error '.$this->db->lasterror();
564 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
565
566 return -1;
567 }
568 }
569
577 public function update(User $user, $notrigger = 0)
578 {
579 $error = 0;
580
581 dol_syslog(__METHOD__, LOG_DEBUG);
582
583 // Clean parameters
584
585 if (isset($this->entity)) {
586 $this->entity = (int) $this->entity;
587 }
588 if (isset($this->fk_product)) {
589 $this->fk_product = (int) $this->fk_product;
590 }
591 if (isset($this->batch)) {
592 $this->batch = trim($this->batch);
593 }
594 if (isset($this->fk_user_creat)) {
595 $this->fk_user_creat = (int) $this->fk_user_creat;
596 }
597 if (isset($this->fk_user_modif)) {
598 $this->fk_user_modif = (int) $this->fk_user_modif;
599 }
600 if (isset($this->import_key)) {
601 $this->import_key = trim($this->import_key);
602 }
603
604 // Check parameters
605 // Put here code to add a control on parameters values
606 $res = $this->checkSellOrEatByMandatory();
607 if ($res < 0) {
608 $error++;
609 }
610
611 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
612 if (empty($this->oldcopy)) {
613 $this->oldcopy = dol_clone($this, 2);
614 }
615
616 if (!$error) {
617 // Update request
618 $sql = 'UPDATE ' . $this->db->prefix() . $this->table_element . ' SET';
619 $sql .= ' entity = ' . (isset($this->entity) ? $this->entity : "null") . ',';
620 $sql .= ' fk_product = ' . (isset($this->fk_product) ? $this->fk_product : "null") . ',';
621 $sql .= ' batch = ' . (isset($this->batch) ? "'" . $this->db->escape($this->batch) . "'" : "null") . ',';
622 $sql .= ' eatby = ' . (!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'" . $this->db->idate($this->eatby) . "'" : 'null') . ',';
623 $sql .= ' sellby = ' . (!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'" . $this->db->idate($this->sellby) . "'" : 'null') . ',';
624 $sql .= ' eol_date = ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'" . $this->db->idate($this->eol_date) . "'" : 'null') . ',';
625 $sql .= ' manufacturing_date = ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'" . $this->db->idate($this->manufacturing_date) . "'" : 'null') . ',';
626 $sql .= ' scrapping_date = ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'" . $this->db->idate($this->scrapping_date) . "'" : 'null') . ',';
627 //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').',';
628 $sql .= ' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency : 'null').',';
629 $sql .= ' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime : 'null').',';
630 $sql .= ' datec = ' . (!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ',';
631 $sql .= ' tms = ' . (dol_strlen((string) $this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : "'" . $this->db->idate(dol_now()) . "'") . ',';
632 $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ',';
633 $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ',';
634 $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null");
635 $sql .= ' WHERE rowid=' . ((int) $this->id);
636
637 $this->db->begin();
638
639 $resql = $this->db->query($sql);
640 if (!$resql) {
641 $error++;
642 $this->errors[] = 'Error ' . $this->db->lasterror();
643 }
644
645 // Actions on extra fields
646 if (!$error) {
647 $result = $this->insertExtraFields();
648 if ($result < 0) {
649 $error++;
650 }
651 }
652
653 if (!$error && !$notrigger) {
654 // Call triggers
655 $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
656 if ($result < 0) {
657 $error++;
658 }
659 // End call triggers
660 }
661
662 // Commit or rollback
663 if ($error) {
664 $this->db->rollback();
665 } else {
666 $this->db->commit();
667 }
668 }
669
670 if ($error) {
671 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
672 return -1 * $error;
673 } else {
674 return 1;
675 }
676 }
677
685 public function delete(User $user, $notrigger = 0)
686 {
687 dol_syslog(__METHOD__, LOG_DEBUG);
688
689 $error = 0;
690
691 $this->db->begin();
692
693 // Check there is no stock for this lot
694 $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
695 $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'";
696 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
697 $sql .= $this->db->plimit(1);
698
699 $resql = $this->db->query($sql);
700 if ($resql) {
701 $obj = $this->db->fetch_object($resql);
702 if ($obj) {
703 $error++;
704 $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
705 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
706 }
707 } else {
708 $error++;
709 $this->errors[] = 'Error '.$this->db->lasterror();
710 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
711 }
712
713 // Check there is no movement for this lot
714 $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm";
715 $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'";
716 $sql .= " AND sm.fk_product = ".((int) $this->fk_product);
717 $sql .= $this->db->plimit(1);
718
719 $resql = $this->db->query($sql);
720 if ($resql) {
721 $obj = $this->db->fetch_object($resql);
722 if ($obj) {
723 $error++;
724 $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.';
725 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
726 }
727 } else {
728 $error++;
729 $this->errors[] = 'Error '.$this->db->lasterror();
730 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
731 }
732
733 // TODO
734 //if (!$error) {
735 //if (!$notrigger) {
736 // Uncomment this and change PRODUCTLOT to your own tag if you
737 // want this action calls a trigger.
738
740 //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
741 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
743 //}
744 //}
745
746 if (!$error) {
747 $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
748 $sql .= ' WHERE rowid='.((int) $this->id);
749
750 $resql = $this->db->query($sql);
751 if (!$resql) {
752 $error++;
753 $this->errors[] = 'Error '.$this->db->lasterror();
754 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
755 }
756 }
757
758 // Commit or rollback
759 if ($error) {
760 $this->db->rollback();
761
762 return -1 * $error;
763 } else {
764 $this->db->commit();
765
766 return 1;
767 }
768 }
769
777 public function createFromClone(User $user, $fromid)
778 {
779 dol_syslog(__METHOD__, LOG_DEBUG);
780
781 $error = 0;
782 $object = new Productlot($this->db);
783
784 $this->db->begin();
785
786 // Load source object
787 $object->fetch($fromid);
788 // Reset object
789 $object->id = 0;
790
791 // Clear fields
792 // ...
793
794 // Create clone
795 $object->context['createfromclone'] = 'createfromclone';
796 $result = $object->create($user);
797
798 // Other options
799 if ($result < 0) {
800 $error++;
801 $this->errors = $object->errors;
802 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
803 }
804
805 unset($object->context['createfromclone']);
806
807 // End
808 if (!$error) {
809 $this->db->commit();
810
811 return $object->id;
812 } else {
813 $this->db->rollback();
814
815 return -1;
816 }
817 }
818
825 public function loadStatsExpedition($socid = 0)
826 {
827 // phpcs:enable
828 global $user, $hookmanager, $action;
829
830 $sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
831 $sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
832 $sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
833 $sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
834 $sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
835 // $sql .= ", ".$this->db->prefix()."societe as s";
836 if (!$user->hasRight('societe', 'client', 'voir')) {
837 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
838 }
839 $sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
840 $sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
841 if (!$user->hasRight('societe', 'client', 'voir')) {
842 $sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
843 }
844 //$sql.= " AND exp.fk_statut != 0";
845 if ($socid > 0) {
846 $sql .= " AND exp.fk_soc = ".((int) $socid);
847 }
848
849 $result = $this->db->query($sql);
850 if ($result) {
851 $obj = $this->db->fetch_object($result);
852 $this->stats_expedition['customers'] = $obj->nb_customers;
853 $this->stats_expedition['nb'] = $obj->nb;
854 $this->stats_expedition['rows'] = $obj->nb_rows;
855 $this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
856
857
858 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
859
860 // if it's a virtual product, maybe it is in invoice by extension
861 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
862 // $TFather = $this->getFather();
863 // if (is_array($TFather) && !empty($TFather)) {
864 // foreach ($TFather as &$fatherData) {
865 // $pFather = new Product($this->db);
866 // $pFather->id = $fatherData['id'];
867 // $qtyCoef = $fatherData['qty'];
868 //
869 // if ($fatherData['incdec']) {
870 // $pFather->loadStatsExpedition($socid);
871 //
872 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
873 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
874 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
875 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
876 // }
877 // }
878 // }
879 // }
880
881 $parameters = array('socid' => $socid);
882 $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
883 if ($reshook > 0) {
884 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
885 }
886
887 return 1;
888 } else {
889 $this->error = $this->db->error();
890 return -1;
891 }
892 }
893
900 public function loadStatsSupplierOrder($socid = 0)
901 {
902 // phpcs:enable
903 global $user, $hookmanager, $action;
904
905 $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
906 $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
907 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
908 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
909 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
910 // $sql .= ", ".$this->db->prefix()."societe as s";
911 if (!$user->hasRight('societe', 'client', 'voir')) {
912 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
913 }
914 $sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
915 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
916 if (!$user->hasRight('societe', 'client', 'voir')) {
917 $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
918 }
919 //$sql.= " AND cf.fk_statut != 0";
920 if ($socid > 0) {
921 $sql .= " AND cf.fk_soc = ".((int) $socid);
922 }
923
924 $result = $this->db->query($sql);
925 if ($result) {
926 $obj = $this->db->fetch_object($result);
927 $this->stats_supplier_order['customers'] = $obj->nb_customers;
928 $this->stats_supplier_order['nb'] = $obj->nb;
929 $this->stats_supplier_order['rows'] = $obj->nb_rows;
930 $this->stats_supplier_order['qty'] = $obj->qty ? $obj->qty : 0;
931
932
933 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
934
935 // if it's a virtual product, maybe it is in invoice by extension
936 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
937 // $TFather = $this->getFather();
938 // if (is_array($TFather) && !empty($TFather)) {
939 // foreach ($TFather as &$fatherData) {
940 // $pFather = new Product($this->db);
941 // $pFather->id = $fatherData['id'];
942 // $qtyCoef = $fatherData['qty'];
943 //
944 // if ($fatherData['incdec']) {
945 // $pFather->stats_supplier_order($socid);
946 //
947 // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
948 // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
949 // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
950 // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
951 // }
952 // }
953 // }
954 // }
955
956 $parameters = array('socid' => $socid);
957 $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
958 if ($reshook > 0) {
959 $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
960 }
961
962 return 1;
963 } else {
964 $this->error = $this->db->error();
965 return -1;
966 }
967 }
968
975 public function loadStatsReception($socid = 0)
976 {
977 // phpcs:enable
978 global $user, $hookmanager, $action;
979
980 $sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
981 $sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
982 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
983 $sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
984 // $sql .= ", ".$this->db->prefix()."societe as s";
985 if (!$user->hasRight('societe', 'client', 'voir')) {
986 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
987 }
988 $sql .= " WHERE recep.entity IN (".getEntity('reception').")";
989 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
990 if (!$user->hasRight('societe', 'client', 'voir')) {
991 $sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
992 }
993 //$sql.= " AND exp.fk_statut != 0";
994 if ($socid > 0) {
995 $sql .= " AND recep.fk_soc = ".((int) $socid);
996 }
997
998 $result = $this->db->query($sql);
999 if ($result) {
1000 $obj = $this->db->fetch_object($result);
1001 $this->stats_reception['customers'] = $obj->nb_customers;
1002 $this->stats_reception['nb'] = $obj->nb;
1003 $this->stats_reception['rows'] = $obj->nb_rows;
1004 $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
1005
1006
1007 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
1008
1009 // if it's a virtual product, maybe it is in invoice by extension
1010 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
1011 // $TFather = $this->getFather();
1012 // if (is_array($TFather) && !empty($TFather)) {
1013 // foreach ($TFather as &$fatherData) {
1014 // $pFather = new Product($this->db);
1015 // $pFather->id = $fatherData['id'];
1016 // $qtyCoef = $fatherData['qty'];
1017 //
1018 // if ($fatherData['incdec']) {
1019 // $pFather->loadStatsReception($socid);
1020 //
1021 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
1022 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
1023 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
1024 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
1025 // }
1026 // }
1027 // }
1028 // }
1029
1030 $parameters = array('socid' => $socid);
1031 $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
1032 if ($reshook > 0) {
1033 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
1034 }
1035
1036 return 1;
1037 } else {
1038 $this->error = $this->db->error();
1039 return -1;
1040 }
1041 }
1042
1049 public function loadStatsMo($socid = 0)
1050 {
1051 // phpcs:enable
1052 global $user, $hookmanager, $action;
1053
1054 $error = 0;
1055
1056 foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
1057 $this->stats_mo['customers_'.$role] = 0;
1058 $this->stats_mo['nb_'.$role] = 0;
1059 $this->stats_mo['qty_'.$role] = 0;
1060
1061 $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1062 $sql .= " SUM(mp.qty) as qty";
1063 $sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
1064 $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
1065 if (!$user->hasRight('societe', 'client', 'voir')) {
1066 $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1067 }
1068 $sql .= " WHERE ";
1069 $sql .= " c.entity IN (".getEntity('mo').")";
1070
1071 $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1072 $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1073 if ($socid > 0) {
1074 $sql .= " AND c.fk_soc = ".((int) $socid);
1075 }
1076
1077 $result = $this->db->query($sql);
1078 if ($result) {
1079 $obj = $this->db->fetch_object($result);
1080 $this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1081 $this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
1082 $this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
1083 } else {
1084 $this->error = $this->db->error();
1085 $error++;
1086 }
1087 }
1088
1089 if (!empty($error)) {
1090 return -1;
1091 }
1092
1093 $parameters = array('socid' => $socid);
1094 $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1095 if ($reshook > 0) {
1096 $this->stats_mo = $hookmanager->resArray['stats_mo'];
1097 }
1098
1099 return 1;
1100 }
1101
1102
1109 public function getLibStatut($mode = 0)
1110 {
1111 return $this->LibStatut(0, $mode);
1112 }
1113
1114 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1122 public function LibStatut($status, $mode = 0)
1123 {
1124 // phpcs:enable
1125 //global $langs;
1126
1127 //$langs->load('stocks');
1128
1129 return '';
1130 }
1131
1132
1139 public function getTooltipContentArray($params)
1140 {
1141 global $langs;
1142
1143 $langs->loadLangs(['stocks', 'productbatch']);
1144
1145 //$option = $params['option'] ?? '';
1146
1147 $datas = [];
1148 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1149 //$datas['divopen'] = '<div width="100%">';
1150 $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1151 if (isDolTms($this->eatby) && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1152 $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
1153 }
1154 if (isDolTms($this->sellby) && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1155 $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
1156 }
1157 //$datas['divclose'] = '</div>';
1158
1159 return $datas;
1160 }
1161
1174 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1175 {
1176 global $langs, $hookmanager;
1177
1178 $result = '';
1179 $params = [
1180 'id' => $this->id,
1181 'objecttype' => $this->element,
1182 'option' => $option,
1183 ];
1184 $classfortooltip = 'classfortooltip';
1185 $dataparams = '';
1186 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1187 $classfortooltip = 'classforajaxtooltip';
1188 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1189 $label = '';
1190 } else {
1191 $label = implode($this->getTooltipContentArray($params));
1192 }
1193
1194 $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1195
1196 if ($option != 'nolink') {
1197 // Add param to save lastsearch_values or not
1198 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1199 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1200 $add_save_lastsearch_values = 1;
1201 }
1202 if ($add_save_lastsearch_values) {
1203 $url .= '&save_lastsearch_values=1';
1204 }
1205 }
1206
1207 $linkclose = '';
1208 if (empty($notooltip)) {
1209 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1210 $label = $langs->trans("ShowMyObject");
1211 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1212 }
1213 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1214 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1215 } else {
1216 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1217 }
1218
1219 if ($option == 'nolink') {
1220 $linkstart = '<span';
1221 } else {
1222 $linkstart = '<a href="'.$url.'"';
1223 }
1224 $linkstart .= $linkclose.'>';
1225 if ($option == 'nolink') {
1226 $linkend = '</span>';
1227 } else {
1228 $linkend = '</a>';
1229 }
1230
1231 $result .= $linkstart;
1232 if ($withpicto) {
1233 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1234 }
1235 if ($withpicto != 2) {
1236 $result .= $this->batch;
1237 }
1238 $result .= $linkend;
1239
1240 global $action;
1241 $hookmanager->initHooks(array('productlotdao'));
1242 $parameters = array('id' => $this->id, 'getnomurl' => $result);
1243 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1244 if ($reshook > 0) {
1245 $result = $hookmanager->resPrint;
1246 } else {
1247 $result .= $hookmanager->resPrint;
1248 }
1249
1250 return $result;
1251 }
1252
1253
1260 public function initAsSpecimen()
1261 {
1262 global $conf;
1263
1264 $now = dol_now();
1265
1266 // Initialise parameters
1267 $this->id = 0;
1268 $this->ref = 'SPECIMEN';
1269 $this->specimen = 1;
1270
1271 $this->entity = $conf->entity;
1272 $this->fk_product = 0;
1273 $this->batch = 'ABCD123456';
1274 $this->eatby = $now - 100000;
1275 $this->sellby = $now - 100000;
1276 $this->datec = $now - 3600;
1277 $this->tms = $now;
1278 $this->fk_user_creat = 0;
1279 $this->fk_user_modif = 0;
1280 $this->import_key = '123456';
1281
1282 return 1;
1283 }
1284
1295 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1296 {
1297 global $langs;
1298
1299 $langs->loadLangs(array('stocks', 'productbatch', "products"));
1300 $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1301
1302 // Positionne le modele sur le nom du modele a utiliser
1303 if (!dol_strlen($modele)) {
1304 $modele = '';
1305
1306 if (!empty($this->model_pdf)) {
1307 $modele = $this->model_pdf;
1308 } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1309 $modele = getDolGlobalString('PRODUCT_BATCH_ADDON_PDF');
1310 }
1311 }
1312
1313 $modelpath = "core/modules/product_batch/doc/";
1314
1315 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1316 }
1317
1326 public function validateField($fields, $fieldKey, $fieldValue)
1327 {
1328 // Add your own validation rules here.
1329 if ($fieldKey == 'batch') {
1330 if (preg_match('/\s/', $fieldValue)) {
1331 $this->error = 'ErrorABatchShouldNotContainsSpaces';
1332 return false;
1333 }
1334 }
1335
1336 return parent::validateField($fields, $fieldKey, $fieldValue);
1337 }
1338}
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.
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 '.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.