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