dolibarr 20.0.2
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
55 public $stats_propale;
56 public $stats_commande;
57 public $stats_contrat;
58 public $stats_facture;
59 public $stats_commande_fournisseur;
60
64 public $stats_expedition;
65
69 public $stats_reception;
70
74 public $stats_supplier_order;
75
76 public $stats_mo;
77 public $stats_bom;
78 public $stats_mrptoconsume;
79 public $stats_mrptoproduce;
80 public $stats_facturerec;
81 public $stats_facture_fournisseur;
82
83
112 public $fields = array(
113 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -2, 'noteditable' => 1, 'notnull' => 1, 'index' => 1, 'position' => 1, 'comment' => 'Id', 'css' => 'left'),
114 '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'),
115 '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),
116 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 20),
117 'sellby' => array('type' => 'date', 'label' => 'SellByDate', 'enabled' => 'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible' => 1, 'notnull' => 0, 'position' => 60),
118 'eatby' => array('type' => 'date', 'label' => 'EatByDate', 'enabled' => 'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0', 'visible' => 1, 'notnull' => 0, 'position' => 62),
119 '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),
120 '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),
121 '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),
122 //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
123 '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),
124 '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),
125 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 215),
126 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -2, 'position' => 310),
127 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 500),
128 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
129 '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'),
130 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511),
131 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000)
132 );
133
137 public $entity;
138
142 public $fk_product;
143
147 public $batch;
148
152 public $eatby = '';
153
157 public $sellby = '';
158
162 public $eol_date = '';
163
167 public $manufacturing_date = '';
168
172 public $scrapping_date = '';
173 //public $commissionning_date = '';
174 public $qc_frequency = '';
175 public $lifetime = '';
176 public $datec = '';
177
181 public $fk_user_creat;
182
186 public $fk_user_modif;
187
191 public $import_key;
192
193
199 public function __construct(DoliDB $db)
200 {
201 $this->db = $db;
202
203 $this->ismultientitymanaged = 1;
204 }
205
212 public function checkSellOrEatByMandatory($onlyFieldName = '')
213 {
214 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
215 return 0;
216 }
217
218 $errorMsgArr = array();
219 if ($this->fk_product > 0) {
220 $res = $this->fetch_product();
221 $product = $this->product;
222 if ($res <= 0) {
223 $errorMsgArr[] = $product->errorsToString();
224 }
225
226 if (empty($errorMsgArr)) {
227 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
228 }
229 }
230
231 if (!empty($errorMsgArr)) {
232 $this->errors = array_merge($this->errors, $errorMsgArr);
233 return -1;
234 } else {
235 return 1;
236 }
237 }
238
248 public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
249 {
250 global $db;
251
252 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
253 return null;
254 }
255
256 $errorMsgArr = array();
257 if ($productId > 0) {
258 $product = new Product($db);
259 $res = $product->fetch($productId);
260 if ($res <= 0) {
261 $errorMsgArr[] = $product->errorsToString();
262 }
263
264 if (empty($errorMsgArr)) {
265 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
266 }
267 }
268
269 return $errorMsgArr;
270 }
271
282 public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
283 {
284 global $langs;
285
286 if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
287 return null;
288 }
289
290 $errorMsgArr = array();
291 $checkSellByMandatory = false;
292 $checkEatByMandatory = false;
293
294 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
295 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
296 $checkSellByMandatory = true;
297 } elseif (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
298 $checkEatByMandatory = true;
299 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
300 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
301 $checkSellByMandatory = true;
302 }
303 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
304 $checkEatByMandatory = true;
305 }
306 }
307
308 if ($checkSellByMandatory === true) {
309 if (!isset($sellBy) || dol_strlen($sellBy) == 0) {
310 // error : sell by is mandatory
311 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
312 }
313 }
314 if ($checkEatByMandatory === true) {
315 if (!isset($eatBy) || dol_strlen($eatBy) == 0) {
316 // error : eat by is mandatory
317 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
318 }
319 }
320
321 return $errorMsgArr;
322 }
323
324
332 public function create(User $user, $notrigger = 0)
333 {
334 global $conf, $langs;
335
336 dol_syslog(__METHOD__, LOG_DEBUG);
337
338 $error = 0;
339
340 // Clean parameters
341
342 if (isset($this->entity)) {
343 $this->entity = (int) $this->entity;
344 }
345 if (isset($this->fk_product)) {
346 $this->fk_product = (int) $this->fk_product;
347 }
348 if (isset($this->batch)) {
349 $this->batch = trim($this->batch);
350 }
351 if (isset($this->fk_user_creat)) {
352 $this->fk_user_creat = (int) $this->fk_user_creat;
353 }
354 if (isset($this->fk_user_modif)) {
355 $this->fk_user_modif = (int) $this->fk_user_modif;
356 }
357 if (isset($this->import_key)) {
358 $this->import_key = trim($this->import_key);
359 }
360
361 // Check parameters
362 if ($this->batch === '') {
363 $this->errors[] = $langs->trans("ErrorBadValueForBatch");
364 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
365 return -1;
366 }
367 // Put here code to add control on parameters values
368 $res = $this->checkSellOrEatByMandatory();
369 if ($res < 0) {
370 $error++;
371 }
372
373 if (!$error) {
374 // Insert request
375 $sql = 'INSERT INTO ' . $this->db->prefix() . $this->table_element . '(';
376 $sql .= 'entity,';
377 $sql .= 'fk_product,';
378 $sql .= 'batch,';
379 $sql .= 'eatby,';
380 $sql .= 'sellby,';
381 $sql .= 'eol_date,';
382 $sql .= 'manufacturing_date,';
383 $sql .= 'scrapping_date,';
384 //$sql .= 'commissionning_date,';
385 $sql .= 'qc_frequency,';
386 $sql .= 'lifetime,';
387 $sql .= 'datec,';
388 $sql .= 'fk_user_creat,';
389 $sql .= 'fk_user_modif,';
390 $sql .= 'import_key';
391 $sql .= ') VALUES (';
392 $sql .= ' ' . (!isset($this->entity) ? $conf->entity : $this->entity) . ',';
393 $sql .= ' ' . (!isset($this->fk_product) ? 'NULL' : $this->fk_product) . ',';
394 $sql .= ' ' . (!isset($this->batch) ? 'NULL' : "'" . $this->db->escape($this->batch) . "'") . ',';
395 $sql .= ' ' . (!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'" . $this->db->idate($this->eatby) . "'") . ',';
396 $sql .= ' ' . (!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'" . $this->db->idate($this->sellby) . "'") . ',';
397 $sql .= ' ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->eol_date) . "'") . ',';
398 $sql .= ' ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->manufacturing_date) . "'") . ',';
399 $sql .= ' ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->scrapping_date) . "'") . ',';
400 //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").',';
401 $sql .= ' '.(empty($this->qc_frequency) ? 'NULL' : $this->qc_frequency).',';
402 $sql .= ' '.(empty($this->lifetime) ? 'NULL' : $this->lifetime).',';
403 $sql .= ' ' . "'" . $this->db->idate(dol_now()) . "'" . ',';
404 $sql .= ' ' . (!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat) . ',';
405 $sql .= ' ' . (!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif) . ',';
406 $sql .= ' ' . (!isset($this->import_key) ? 'NULL' : $this->import_key);
407 $sql .= ')';
408
409 $this->db->begin();
410
411 $resql = $this->db->query($sql);
412 if (!$resql) {
413 $error++;
414 $this->errors[] = 'Error ' . $this->db->lasterror();
415 }
416
417 if (!$error) {
418 $this->id = $this->db->last_insert_id($this->db->prefix() . $this->table_element);
419
420 // Actions on extra fields
421 if (!$error) {
422 $result = $this->insertExtraFields();
423 if ($result < 0) {
424 $error++;
425 }
426 }
427
428 if (!$error && !$notrigger) {
429 // Call triggers
430 $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
431 if ($result < 0) {
432 $error++;
433 }
434 // End call triggers
435 }
436 }
437
438 // Commit or rollback
439 if ($error) {
440 $this->db->rollback();
441 } else {
442 $this->db->commit();
443 }
444 }
445
446 if ($error) {
447 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
448 return -1 * $error;
449 } else {
450 return $this->id;
451 }
452 }
453
463 public function fetch($id = 0, $product_id = 0, $batch = '')
464 {
465 global $conf;
466 dol_syslog(__METHOD__, LOG_DEBUG);
467
468 $sql = "SELECT";
469 $sql .= " t.rowid,";
470 $sql .= " t.entity,";
471 $sql .= " t.fk_product,";
472 $sql .= " t.batch,";
473 $sql .= " t.eatby,";
474 $sql .= " t.sellby,";
475 $sql .= " t.eol_date,";
476 $sql .= " t.manufacturing_date,";
477 $sql .= " t.scrapping_date,";
478 //$sql .= " t.commissionning_date,";
479 $sql .= " t.qc_frequency,";
480 $sql .= " t.lifetime,";
481 $sql .= " t.model_pdf,";
482 $sql .= " t.last_main_doc,";
483 $sql .= " t.datec,";
484 $sql .= " t.tms,";
485 $sql .= " t.fk_user_creat,";
486 $sql .= " t.fk_user_modif,";
487 $sql .= " t.import_key,";
488 $sql .= " t.note_public,";
489 $sql .= " t.note_private";
490 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
491 if ($product_id > 0 && $batch != '') {
492 $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id);
493 } else {
494 $sql .= " WHERE t.rowid = ".((int) $id);
495 }
496
497 $resql = $this->db->query($sql);
498 if ($resql) {
499 $numrows = $this->db->num_rows($resql);
500 if ($numrows) {
501 $obj = $this->db->fetch_object($resql);
502
503 $this->id = $obj->rowid;
504 $this->ref = $obj->rowid;
505 //$this->ref = $obj->fk_product.'_'.$obj->batch;
506
507 $this->batch = $obj->batch;
508 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
509 $this->fk_product = $obj->fk_product;
510 $this->eatby = $this->db->jdate($obj->eatby);
511 $this->sellby = $this->db->jdate($obj->sellby);
512 $this->eol_date = $this->db->jdate($obj->eol_date);
513 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
514 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
515 //$this->commissionning_date = $this->db->jdate($obj->commissionning_date);
516 $this->qc_frequency = $obj->qc_frequency;
517 $this->lifetime = $obj->lifetime;
518 $this->model_pdf = $obj->model_pdf;
519 $this->last_main_doc = $obj->last_main_doc;
520
521 $this->datec = $this->db->jdate($obj->datec);
522 $this->tms = $this->db->jdate($obj->tms);
523 $this->fk_user_creat = $obj->fk_user_creat;
524 $this->fk_user_modif = $obj->fk_user_modif;
525 $this->import_key = $obj->import_key;
526 $this->note_public = $obj->note_public;
527 $this->note_private = $obj->note_private;
528
529 // Retrieve all extrafield
530 // fetch optionals attributes and labels
531 $this->fetch_optionals();
532 }
533 $this->db->free($resql);
534
535 if ($numrows) {
536 return 1;
537 } else {
538 return 0;
539 }
540 } else {
541 $this->errors[] = 'Error '.$this->db->lasterror();
542 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
543
544 return -1;
545 }
546 }
547
555 public function update(User $user, $notrigger = 0)
556 {
557 $error = 0;
558
559 dol_syslog(__METHOD__, LOG_DEBUG);
560
561 // Clean parameters
562
563 if (isset($this->entity)) {
564 $this->entity = (int) $this->entity;
565 }
566 if (isset($this->fk_product)) {
567 $this->fk_product = (int) $this->fk_product;
568 }
569 if (isset($this->batch)) {
570 $this->batch = trim($this->batch);
571 }
572 if (isset($this->fk_user_creat)) {
573 $this->fk_user_creat = (int) $this->fk_user_creat;
574 }
575 if (isset($this->fk_user_modif)) {
576 $this->fk_user_modif = (int) $this->fk_user_modif;
577 }
578 if (isset($this->import_key)) {
579 $this->import_key = trim($this->import_key);
580 }
581
582 // Check parameters
583 // Put here code to add a control on parameters values
584 $res = $this->checkSellOrEatByMandatory();
585 if ($res < 0) {
586 $error++;
587 }
588
589 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
590 if (empty($this->oldcopy)) {
591 $this->oldcopy = dol_clone($this, 2);
592 }
593
594 if (!$error) {
595 // Update request
596 $sql = 'UPDATE ' . $this->db->prefix() . $this->table_element . ' SET';
597 $sql .= ' entity = ' . (isset($this->entity) ? $this->entity : "null") . ',';
598 $sql .= ' fk_product = ' . (isset($this->fk_product) ? $this->fk_product : "null") . ',';
599 $sql .= ' batch = ' . (isset($this->batch) ? "'" . $this->db->escape($this->batch) . "'" : "null") . ',';
600 $sql .= ' eatby = ' . (!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'" . $this->db->idate($this->eatby) . "'" : 'null') . ',';
601 $sql .= ' sellby = ' . (!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'" . $this->db->idate($this->sellby) . "'" : 'null') . ',';
602 $sql .= ' eol_date = ' . (!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'" . $this->db->idate($this->eol_date) . "'" : 'null') . ',';
603 $sql .= ' manufacturing_date = ' . (!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'" . $this->db->idate($this->manufacturing_date) . "'" : 'null') . ',';
604 $sql .= ' scrapping_date = ' . (!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'" . $this->db->idate($this->scrapping_date) . "'" : 'null') . ',';
605 //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').',';
606 $sql .= ' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency : 'null').',';
607 $sql .= ' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime : 'null').',';
608 $sql .= ' datec = ' . (!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'" . $this->db->idate($this->datec) . "'" : 'null') . ',';
609 $sql .= ' tms = ' . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : "'" . $this->db->idate(dol_now()) . "'") . ',';
610 $sql .= ' fk_user_creat = ' . (isset($this->fk_user_creat) ? $this->fk_user_creat : "null") . ',';
611 $sql .= ' fk_user_modif = ' . (isset($this->fk_user_modif) ? $this->fk_user_modif : "null") . ',';
612 $sql .= ' import_key = ' . (isset($this->import_key) ? $this->import_key : "null");
613 $sql .= ' WHERE rowid=' . ((int) $this->id);
614
615 $this->db->begin();
616
617 $resql = $this->db->query($sql);
618 if (!$resql) {
619 $error++;
620 $this->errors[] = 'Error ' . $this->db->lasterror();
621 }
622
623 // Actions on extra fields
624 if (!$error) {
625 $result = $this->insertExtraFields();
626 if ($result < 0) {
627 $error++;
628 }
629 }
630
631 if (!$error && !$notrigger) {
632 // Call triggers
633 $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
634 if ($result < 0) {
635 $error++;
636 }
637 // End call triggers
638 }
639
640 // Commit or rollback
641 if ($error) {
642 $this->db->rollback();
643 } else {
644 $this->db->commit();
645 }
646 }
647
648 if ($error) {
649 dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
650 return -1 * $error;
651 } else {
652 return 1;
653 }
654 }
655
663 public function delete(User $user, $notrigger = 0)
664 {
665 dol_syslog(__METHOD__, LOG_DEBUG);
666
667 $error = 0;
668
669 $this->db->begin();
670
671 // Check there is no stock for this lot
672 $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
673 $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'";
674 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
675 $sql .= $this->db->plimit(1);
676
677 $resql = $this->db->query($sql);
678 if ($resql) {
679 $obj = $this->db->fetch_object($resql);
680 if ($obj) {
681 $error++;
682 $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
683 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
684 }
685 } else {
686 $error++;
687 $this->errors[] = 'Error '.$this->db->lasterror();
688 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
689 }
690
691 // Check there is no movement for this lot
692 $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm";
693 $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'";
694 $sql .= " AND sm.fk_product = ".((int) $this->fk_product);
695 $sql .= $this->db->plimit(1);
696
697 $resql = $this->db->query($sql);
698 if ($resql) {
699 $obj = $this->db->fetch_object($resql);
700 if ($obj) {
701 $error++;
702 $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.';
703 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
704 }
705 } else {
706 $error++;
707 $this->errors[] = 'Error '.$this->db->lasterror();
708 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
709 }
710
711 // TODO
712 //if (!$error) {
713 //if (!$notrigger) {
714 // Uncomment this and change PRODUCTLOT to your own tag if you
715 // want this action calls a trigger.
716
718 //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
719 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
721 //}
722 //}
723
724 if (!$error) {
725 $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
726 $sql .= ' WHERE rowid='.((int) $this->id);
727
728 $resql = $this->db->query($sql);
729 if (!$resql) {
730 $error++;
731 $this->errors[] = 'Error '.$this->db->lasterror();
732 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
733 }
734 }
735
736 // Commit or rollback
737 if ($error) {
738 $this->db->rollback();
739
740 return -1 * $error;
741 } else {
742 $this->db->commit();
743
744 return 1;
745 }
746 }
747
755 public function createFromClone(User $user, $fromid)
756 {
757 dol_syslog(__METHOD__, LOG_DEBUG);
758
759 $error = 0;
760 $object = new Productlot($this->db);
761
762 $this->db->begin();
763
764 // Load source object
765 $object->fetch($fromid);
766 // Reset object
767 $object->id = 0;
768
769 // Clear fields
770 // ...
771
772 // Create clone
773 $object->context['createfromclone'] = 'createfromclone';
774 $result = $object->create($user);
775
776 // Other options
777 if ($result < 0) {
778 $error++;
779 $this->errors = $object->errors;
780 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
781 }
782
783 unset($object->context['createfromclone']);
784
785 // End
786 if (!$error) {
787 $this->db->commit();
788
789 return $object->id;
790 } else {
791 $this->db->rollback();
792
793 return -1;
794 }
795 }
796
803 public function loadStatsExpedition($socid = 0)
804 {
805 // phpcs:enable
806 global $user, $hookmanager, $action;
807
808 $sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
809 $sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
810 $sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
811 $sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
812 $sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
813 // $sql .= ", ".$this->db->prefix()."societe as s";
814 if (!$user->hasRight('societe', 'client', 'voir')) {
815 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
816 }
817 $sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
818 $sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
819 if (!$user->hasRight('societe', 'client', 'voir')) {
820 $sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
821 }
822 //$sql.= " AND exp.fk_statut != 0";
823 if ($socid > 0) {
824 $sql .= " AND exp.fk_soc = ".((int) $socid);
825 }
826
827 $result = $this->db->query($sql);
828 if ($result) {
829 $obj = $this->db->fetch_object($result);
830 $this->stats_expedition['customers'] = $obj->nb_customers;
831 $this->stats_expedition['nb'] = $obj->nb;
832 $this->stats_expedition['rows'] = $obj->nb_rows;
833 $this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
834
835
836 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
837
838 // if it's a virtual product, maybe it is in invoice by extension
839 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
840 // $TFather = $this->getFather();
841 // if (is_array($TFather) && !empty($TFather)) {
842 // foreach ($TFather as &$fatherData) {
843 // $pFather = new Product($this->db);
844 // $pFather->id = $fatherData['id'];
845 // $qtyCoef = $fatherData['qty'];
846 //
847 // if ($fatherData['incdec']) {
848 // $pFather->loadStatsExpedition($socid);
849 //
850 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
851 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
852 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
853 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
854 // }
855 // }
856 // }
857 // }
858
859 $parameters = array('socid' => $socid);
860 $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
861 if ($reshook > 0) {
862 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
863 }
864
865 return 1;
866 } else {
867 $this->error = $this->db->error();
868 return -1;
869 }
870 }
871
878 public function loadStatsSupplierOrder($socid = 0)
879 {
880 // phpcs:enable
881 global $user, $hookmanager, $action;
882
883 $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
884 $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
885 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
886 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_elementdet)";
887 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
888 // $sql .= ", ".$this->db->prefix()."societe as s";
889 if (!$user->hasRight('societe', 'client', 'voir')) {
890 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
891 }
892 $sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
893 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
894 if (!$user->hasRight('societe', 'client', 'voir')) {
895 $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
896 }
897 //$sql.= " AND cf.fk_statut != 0";
898 if ($socid > 0) {
899 $sql .= " AND cf.fk_soc = ".((int) $socid);
900 }
901
902 $result = $this->db->query($sql);
903 if ($result) {
904 $obj = $this->db->fetch_object($result);
905 $this->stats_supplier_order['customers'] = $obj->nb_customers;
906 $this->stats_supplier_order['nb'] = $obj->nb;
907 $this->stats_supplier_order['rows'] = $obj->nb_rows;
908 $this->stats_supplier_order['qty'] = $obj->qty ? $obj->qty : 0;
909
910
911 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
912
913 // if it's a virtual product, maybe it is in invoice by extension
914 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
915 // $TFather = $this->getFather();
916 // if (is_array($TFather) && !empty($TFather)) {
917 // foreach ($TFather as &$fatherData) {
918 // $pFather = new Product($this->db);
919 // $pFather->id = $fatherData['id'];
920 // $qtyCoef = $fatherData['qty'];
921 //
922 // if ($fatherData['incdec']) {
923 // $pFather->stats_supplier_order($socid);
924 //
925 // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
926 // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
927 // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
928 // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
929 // }
930 // }
931 // }
932 // }
933
934 $parameters = array('socid' => $socid);
935 $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
936 if ($reshook > 0) {
937 $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
938 }
939
940 return 1;
941 } else {
942 $this->error = $this->db->error();
943 return -1;
944 }
945 }
946
953 public function loadStatsReception($socid = 0)
954 {
955 // phpcs:enable
956 global $user, $hookmanager, $action;
957
958 $sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
959 $sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
960 $sql .= " FROM ".$this->db->prefix()."receptiondet_batch as cfdi";
961 $sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
962 // $sql .= ", ".$this->db->prefix()."societe as s";
963 if (!$user->hasRight('societe', 'client', 'voir')) {
964 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
965 }
966 $sql .= " WHERE recep.entity IN (".getEntity('reception').")";
967 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
968 if (!$user->hasRight('societe', 'client', 'voir')) {
969 $sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
970 }
971 //$sql.= " AND exp.fk_statut != 0";
972 if ($socid > 0) {
973 $sql .= " AND recep.fk_soc = ".((int) $socid);
974 }
975
976 $result = $this->db->query($sql);
977 if ($result) {
978 $obj = $this->db->fetch_object($result);
979 $this->stats_reception['customers'] = $obj->nb_customers;
980 $this->stats_reception['nb'] = $obj->nb;
981 $this->stats_reception['rows'] = $obj->nb_rows;
982 $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
983
984
985 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
986
987 // if it's a virtual product, maybe it is in invoice by extension
988 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
989 // $TFather = $this->getFather();
990 // if (is_array($TFather) && !empty($TFather)) {
991 // foreach ($TFather as &$fatherData) {
992 // $pFather = new Product($this->db);
993 // $pFather->id = $fatherData['id'];
994 // $qtyCoef = $fatherData['qty'];
995 //
996 // if ($fatherData['incdec']) {
997 // $pFather->loadStatsReception($socid);
998 //
999 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
1000 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
1001 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
1002 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
1003 // }
1004 // }
1005 // }
1006 // }
1007
1008 $parameters = array('socid' => $socid);
1009 $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
1010 if ($reshook > 0) {
1011 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
1012 }
1013
1014 return 1;
1015 } else {
1016 $this->error = $this->db->error();
1017 return -1;
1018 }
1019 }
1020
1027 public function loadStatsMo($socid = 0)
1028 {
1029 // phpcs:enable
1030 global $user, $hookmanager, $action;
1031
1032 $error = 0;
1033
1034 foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
1035 $this->stats_mo['customers_'.$role] = 0;
1036 $this->stats_mo['nb_'.$role] = 0;
1037 $this->stats_mo['qty_'.$role] = 0;
1038
1039 $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
1040 $sql .= " SUM(mp.qty) as qty";
1041 $sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
1042 $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
1043 if (!$user->hasRight('societe', 'client', 'voir')) {
1044 $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1045 }
1046 $sql .= " WHERE ";
1047 $sql .= " c.entity IN (".getEntity('mo').")";
1048
1049 $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1050 $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1051 if ($socid > 0) {
1052 $sql .= " AND c.fk_soc = ".((int) $socid);
1053 }
1054
1055 $result = $this->db->query($sql);
1056 if ($result) {
1057 $obj = $this->db->fetch_object($result);
1058 $this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1059 $this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
1060 $this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
1061 } else {
1062 $this->error = $this->db->error();
1063 $error++;
1064 }
1065 }
1066
1067 if (!empty($error)) {
1068 return -1;
1069 }
1070
1071 $parameters = array('socid' => $socid);
1072 $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1073 if ($reshook > 0) {
1074 $this->stats_mo = $hookmanager->resArray['stats_mo'];
1075 }
1076
1077 return 1;
1078 }
1079
1080
1087 public function getLibStatut($mode = 0)
1088 {
1089 return $this->LibStatut(0, $mode);
1090 }
1091
1092 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1100 public function LibStatut($status, $mode = 0)
1101 {
1102 // phpcs:enable
1103 //global $langs;
1104
1105 //$langs->load('stocks');
1106
1107 return '';
1108 }
1109
1110
1118 public function getTooltipContentArray($params)
1119 {
1120 global $langs;
1121
1122 $langs->loadLangs(['stocks', 'productbatch']);
1123
1124 //$option = $params['option'] ?? '';
1125
1126 $datas = [];
1127 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1128 //$datas['divopen'] = '<div width="100%">';
1129 $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1130 if (isDolTms($this->eatby) && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1131 $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
1132 }
1133 if (isDolTms($this->sellby) && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1134 $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
1135 }
1136 //$datas['divclose'] = '</div>';
1137
1138 return $datas;
1139 }
1140
1153 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1154 {
1155 global $langs, $hookmanager;
1156
1157 $result = '';
1158 $params = [
1159 'id' => $this->id,
1160 'objecttype' => $this->element,
1161 'option' => $option,
1162 ];
1163 $classfortooltip = 'classfortooltip';
1164 $dataparams = '';
1165 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1166 $classfortooltip = 'classforajaxtooltip';
1167 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1168 $label = '';
1169 } else {
1170 $label = implode($this->getTooltipContentArray($params));
1171 }
1172
1173 $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1174
1175 if ($option != 'nolink') {
1176 // Add param to save lastsearch_values or not
1177 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1178 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1179 $add_save_lastsearch_values = 1;
1180 }
1181 if ($add_save_lastsearch_values) {
1182 $url .= '&save_lastsearch_values=1';
1183 }
1184 }
1185
1186 $linkclose = '';
1187 if (empty($notooltip)) {
1188 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1189 $label = $langs->trans("ShowMyObject");
1190 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1191 }
1192 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1193 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1194 } else {
1195 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1196 }
1197
1198 if ($option == 'nolink') {
1199 $linkstart = '<span';
1200 } else {
1201 $linkstart = '<a href="'.$url.'"';
1202 }
1203 $linkstart .= $linkclose.'>';
1204 if ($option == 'nolink') {
1205 $linkend = '</span>';
1206 } else {
1207 $linkend = '</a>';
1208 }
1209
1210 $result .= $linkstart;
1211 if ($withpicto) {
1212 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1213 }
1214 if ($withpicto != 2) {
1215 $result .= $this->batch;
1216 }
1217 $result .= $linkend;
1218
1219 global $action;
1220 $hookmanager->initHooks(array('productlotdao'));
1221 $parameters = array('id' => $this->id, 'getnomurl' => $result);
1222 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1223 if ($reshook > 0) {
1224 $result = $hookmanager->resPrint;
1225 } else {
1226 $result .= $hookmanager->resPrint;
1227 }
1228
1229 return $result;
1230 }
1231
1232
1239 public function initAsSpecimen()
1240 {
1241 global $conf;
1242
1243 $now = dol_now();
1244
1245 // Initialise parameters
1246 $this->id = 0;
1247 $this->ref = 'SPECIMEN';
1248 $this->specimen = 1;
1249
1250 $this->entity = $conf->entity;
1251 $this->fk_product = 0;
1252 $this->batch = 'ABCD123456';
1253 $this->eatby = $now - 100000;
1254 $this->sellby = $now - 100000;
1255 $this->datec = $now - 3600;
1256 $this->tms = $now;
1257 $this->fk_user_creat = 0;
1258 $this->fk_user_modif = 0;
1259 $this->import_key = '123456';
1260
1261 return 1;
1262 }
1263
1274 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1275 {
1276 global $langs;
1277
1278 $langs->loadLangs(array('stocks', 'productbatch', "products"));
1279 $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1280
1281 // Positionne le modele sur le nom du modele a utiliser
1282 if (!dol_strlen($modele)) {
1283 $modele = '';
1284
1285 if (!empty($this->model_pdf)) {
1286 $modele = $this->model_pdf;
1287 } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1288 $modele = getDolGlobalString('PRODUCT_BATCH_ADDON_PDF');
1289 }
1290 }
1291
1292 $modelpath = "core/modules/product_batch/doc/";
1293
1294 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1295 }
1296
1305 public function validateField($fields, $fieldKey, $fieldValue)
1306 {
1307 // Add your own validation rules here.
1308 if ($fieldKey == 'batch') {
1309 if (preg_match('/\s/', $fieldValue)) {
1310 $this->error = 'ErrorABatchShouldNotContainsSpaces';
1311 return false;
1312 }
1313 }
1314
1315 return parent::validateField($fields, $fieldKey, $fieldValue);
1316 }
1317}
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.