dolibarr 19.0.3
productlot.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
6 * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Put here all includes required by your class file
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33
38{
42 public $element = 'productlot';
43
47 public $table_element = 'product_lot';
48
52 public $picto = 'lot';
53
58 public $ismultientitymanaged = 1;
59
60 public $stats_propale;
61 public $stats_commande;
62 public $stats_contrat;
63 public $stats_facture;
64 public $stats_commande_fournisseur;
65 public $stats_expedition;
66 public $stats_reception;
67 public $stats_mo;
68 public $stats_bom;
69 public $stats_mrptoconsume;
70 public $stats_mrptoproduce;
71 public $stats_facturerec;
72 public $stats_facture_fournisseur;
73
74
103 public $fields = array(
104 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'),
105 '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'),
106 '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'),
107 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
108 'sellby' => array('type'=>'date', 'label'=>'SellByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_SELLBY)?1:0', 'visible'=>1, 'notnull'=>0, 'position'=>60),
109 'eatby' => array('type'=>'date', 'label'=>'EatByDate', 'enabled'=>'empty($conf->global->PRODUCT_DISABLE_EATBY)?1:0', 'visible'=>1, 'notnull'=>0, 'position'=>62),
110 '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),
111 '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),
112 '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),
113 //'commissionning_date' => array('type'=>'date', 'label'=>'FirstUseDate', 'enabled'=>'getDolGlobalInt("PRODUCT_LOT_ENABLE_TRACEABILITY", 0)', 'visible'=>5, 'position'=>100),
114 '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),
115 '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),
116 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'visible' => 0, 'position' => 215),
117 'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'visible' => -2, 'position' => 310),
118 'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>500),
119 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
120 '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'),
121 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
122 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000)
123 );
124
128 public $entity;
129
133 public $fk_product;
134
138 public $batch;
139 public $eatby = '';
140 public $sellby = '';
141 public $eol_date = '';
142 public $manufacturing_date = '';
143 public $scrapping_date = '';
144 //public $commissionning_date = '';
145 public $qc_frequency = '';
146 public $lifetime = '';
147 public $datec = '';
148 public $tms = '';
149
153 public $fk_user_creat;
154
158 public $fk_user_modif;
159
163 public $import_key;
164
165 public $stats_supplier_order=array();
166
167
173 public function __construct(DoliDB $db)
174 {
175 $this->db = $db;
176 }
177
184 public function checkSellOrEatByMandatory($onlyFieldName = '')
185 {
186 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
187 return 0;
188 }
189
190 $errorMsgArr = array();
191 if ($this->fk_product > 0) {
192 $res = $this->fetch_product();
193 $product = $this->product;
194 if ($res <= 0) {
195 $errorMsgArr[] = $product->errorsToString();
196 }
197
198 if (empty($errorMsgArr)) {
199 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $this->sellby, $this->eatby, $onlyFieldName, true);
200 }
201 }
202
203 if (!empty($errorMsgArr)) {
204 $this->errors = array_merge($this->errors, $errorMsgArr);
205 return -1;
206 } else {
207 return 1;
208 }
209 }
210
220 public static function checkSellOrEatByMandatoryFromProductIdAndDates($productId, $sellBy, $eatBy, $onlyFieldName = '')
221 {
222 global $db;
223
224 if (getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
225 return null;
226 }
227
228 $errorMsgArr = array();
229 if ($productId > 0) {
230 $product = new Product($db);
231 $res = $product->fetch($productId);
232 if ($res <= 0) {
233 $errorMsgArr[] = $product->errorsToString();
234 }
235
236 if (empty($errorMsgArr)) {
237 $errorMsgArr = self::checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName, true);
238 }
239 }
240
241 return $errorMsgArr;
242 }
243
254 public static function checkSellOrEatByMandatoryFromProductAndDates($product, $sellBy, $eatBy, $onlyFieldName = '', $alreadyCheckConf = false)
255 {
256 global $langs;
257
258 if ($alreadyCheckConf === false && getDolGlobalString('PRODUCT_DISABLE_SELLBY') && getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
259 return null;
260 }
261
262 $errorMsgArr = array();
263 $checkSellByMandatory = false;
264 $checkEatByMandatory = false;
265
266 $sellOrEatByMandatoryId = $product->sell_or_eat_by_mandatory;
267 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_BY && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
268 $checkSellByMandatory = true;
269 } elseif (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && $sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_EAT_BY && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
270 $checkEatByMandatory = true;
271 } elseif ($sellOrEatByMandatoryId == Product::SELL_OR_EAT_BY_MANDATORY_ID_SELL_AND_EAT) {
272 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && ($onlyFieldName == '' || $onlyFieldName == 'sellby')) {
273 $checkSellByMandatory = true;
274 }
275 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && ($onlyFieldName == '' || $onlyFieldName == 'eatby')) {
276 $checkEatByMandatory = true;
277 }
278 }
279
280 if ($checkSellByMandatory === true) {
281 if (!isset($sellBy) || dol_strlen($sellBy) == 0) {
282 // error : sell by is mandatory
283 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('SellByDate'));
284 }
285 }
286 if ($checkEatByMandatory === true) {
287 if (!isset($eatBy) || dol_strlen($eatBy) == 0) {
288 // error : eat by is mandatory
289 $errorMsgArr[] = $langs->trans('ErrorFieldRequired', $langs->transnoentities('EatByDate'));
290 }
291 }
292
293 return $errorMsgArr;
294 }
295
296
305 public function create(User $user, $notrigger = false)
306 {
307 global $conf, $langs;
308
309 dol_syslog(__METHOD__, LOG_DEBUG);
310
311 $error = 0;
312
313 // Clean parameters
314
315 if (isset($this->entity)) {
316 $this->entity = (int) $this->entity;
317 }
318 if (isset($this->fk_product)) {
319 $this->fk_product = (int) $this->fk_product;
320 }
321 if (isset($this->batch)) {
322 $this->batch = trim($this->batch);
323 }
324 if (isset($this->fk_user_creat)) {
325 $this->fk_user_creat = (int) $this->fk_user_creat;
326 }
327 if (isset($this->fk_user_modif)) {
328 $this->fk_user_modif = (int) $this->fk_user_modif;
329 }
330 if (isset($this->import_key)) {
331 $this->import_key = trim($this->import_key);
332 }
333
334 // Check parameters
335 if ($this->batch === '') {
336 $this->errors[] = $langs->trans("ErrorBadValueForBatch");
337 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
338 return -1;
339 }
340 // Put here code to add control on parameters values
341
342 // Insert request
343 $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'(';
344 $sql .= 'entity,';
345 $sql .= 'fk_product,';
346 $sql .= 'batch,';
347 $sql .= 'eatby,';
348 $sql .= 'sellby,';
349 $sql .= 'eol_date,';
350 $sql .= 'manufacturing_date,';
351 $sql .= 'scrapping_date,';
352 //$sql .= 'commissionning_date,';
353 $sql .= 'qc_frequency,';
354 $sql .= 'lifetime,';
355 $sql .= 'datec,';
356 $sql .= 'fk_user_creat,';
357 $sql .= 'fk_user_modif,';
358 $sql .= 'import_key';
359 $sql .= ') VALUES (';
360 $sql .= ' '.(!isset($this->entity) ? $conf->entity : $this->entity).',';
361 $sql .= ' '.(!isset($this->fk_product) ? 'NULL' : $this->fk_product).',';
362 $sql .= ' '.(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").',';
363 $sql .= ' '.(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").',';
364 $sql .= ' '.(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").',';
365 $sql .= ' '.(!isset($this->eol_date) || dol_strlen($this->eol_date) == 0 ? 'NULL' : "'".$this->db->idate($this->eol_date)."'").',';
366 $sql .= ' '.(!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) == 0 ? 'NULL' : "'".$this->db->idate($this->manufacturing_date)."'").',';
367 $sql .= ' '.(!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) == 0 ? 'NULL' : "'".$this->db->idate($this->scrapping_date)."'").',';
368 //$sql .= ' '.(!isset($this->commissionning_date) || dol_strlen($this->commissionning_date) == 0 ? 'NULL' : "'".$this->db->idate($this->commissionning_date)."'").',';
369 $sql .= ' '.(empty($this->qc_frequency) ? 'NULL' : $this->qc_frequency).',';
370 $sql .= ' '.(empty($this->lifetime) ? 'NULL' : $this->lifetime).',';
371 $sql .= ' '."'".$this->db->idate(dol_now())."'".',';
372 $sql .= ' '.(!isset($this->fk_user_creat) ? 'NULL' : $this->fk_user_creat).',';
373 $sql .= ' '.(!isset($this->fk_user_modif) ? 'NULL' : $this->fk_user_modif).',';
374 $sql .= ' '.(!isset($this->import_key) ? 'NULL' : $this->import_key);
375 $sql .= ')';
376
377 $this->db->begin();
378
379 $resql = $this->db->query($sql);
380 if (!$resql) {
381 $error++;
382 $this->errors[] = 'Error '.$this->db->lasterror();
383 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
384 }
385
386 if (!$error) {
387 $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
388
389 // Actions on extra fields
390 if (!$error) {
391 $result = $this->insertExtraFields();
392 if ($result < 0) {
393 $error++;
394 }
395 }
396
397 if (!$error && !$notrigger) {
398 // Call triggers
399 $result = $this->call_trigger('PRODUCTLOT_CREATE', $user);
400 if ($result < 0) {
401 $error++;
402 }
403 // End call triggers
404 }
405 }
406
407 // Commit or rollback
408 if ($error) {
409 $this->db->rollback();
410
411 return -1 * $error;
412 } else {
413 $this->db->commit();
414
415 return $this->id;
416 }
417 }
418
428 public function fetch($id = 0, $product_id = 0, $batch = '')
429 {
430 global $conf;
431 dol_syslog(__METHOD__, LOG_DEBUG);
432
433 $sql = "SELECT";
434 $sql .= " t.rowid,";
435 $sql .= " t.entity,";
436 $sql .= " t.fk_product,";
437 $sql .= " t.batch,";
438 $sql .= " t.eatby,";
439 $sql .= " t.sellby,";
440 $sql .= " t.eol_date,";
441 $sql .= " t.manufacturing_date,";
442 $sql .= " t.scrapping_date,";
443 //$sql .= " t.commissionning_date,";
444 $sql .= " t.qc_frequency,";
445 $sql .= " t.lifetime,";
446 $sql .= " t.model_pdf,";
447 $sql .= " t.last_main_doc,";
448 $sql .= " t.datec,";
449 $sql .= " t.tms,";
450 $sql .= " t.fk_user_creat,";
451 $sql .= " t.fk_user_modif,";
452 $sql .= " t.import_key,";
453 $sql .= " t.note_public,";
454 $sql .= " t.note_private";
455 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
456 if ($product_id > 0 && $batch != '') {
457 $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id);
458 } else {
459 $sql .= " WHERE t.rowid = ".((int) $id);
460 }
461
462 $resql = $this->db->query($sql);
463 if ($resql) {
464 $numrows = $this->db->num_rows($resql);
465 if ($numrows) {
466 $obj = $this->db->fetch_object($resql);
467
468 $this->id = $obj->rowid;
469 $this->ref = $obj->rowid;
470 //$this->ref = $obj->fk_product.'_'.$obj->batch;
471
472 $this->batch = $obj->batch;
473 $this->entity = (!empty($obj->entity) ? $obj->entity : $conf->entity); // Prevent "null" entity
474 $this->fk_product = $obj->fk_product;
475 $this->eatby = $this->db->jdate($obj->eatby);
476 $this->sellby = $this->db->jdate($obj->sellby);
477 $this->eol_date = $this->db->jdate($obj->eol_date);
478 $this->manufacturing_date = $this->db->jdate($obj->manufacturing_date);
479 $this->scrapping_date = $this->db->jdate($obj->scrapping_date);
480 //$this->commissionning_date = $this->db->jdate($obj->commissionning_date);
481 $this->qc_frequency = $obj->qc_frequency;
482 $this->lifetime = $obj->lifetime;
483 $this->model_pdf = $obj->model_pdf;
484 $this->last_main_doc = $obj->last_main_doc;
485
486 $this->datec = $this->db->jdate($obj->datec);
487 $this->tms = $this->db->jdate($obj->tms);
488 $this->fk_user_creat = $obj->fk_user_creat;
489 $this->fk_user_modif = $obj->fk_user_modif;
490 $this->import_key = $obj->import_key;
491 $this->note_public = $obj->note_public;
492 $this->note_private = $obj->note_private;
493
494 // Retrieve all extrafield
495 // fetch optionals attributes and labels
496 $this->fetch_optionals();
497 }
498 $this->db->free($resql);
499
500 if ($numrows) {
501 return 1;
502 } else {
503 return 0;
504 }
505 } else {
506 $this->errors[] = 'Error '.$this->db->lasterror();
507 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
508
509 return -1;
510 }
511 }
512
521 public function update(User $user, $notrigger = false)
522 {
523 $error = 0;
524
525 dol_syslog(__METHOD__, LOG_DEBUG);
526
527 // Clean parameters
528
529 if (isset($this->entity)) {
530 $this->entity = (int) $this->entity;
531 }
532 if (isset($this->fk_product)) {
533 $this->fk_product = (int) $this->fk_product;
534 }
535 if (isset($this->batch)) {
536 $this->batch = trim($this->batch);
537 }
538 if (isset($this->fk_user_creat)) {
539 $this->fk_user_creat = (int) $this->fk_user_creat;
540 }
541 if (isset($this->fk_user_modif)) {
542 $this->fk_user_modif = (int) $this->fk_user_modif;
543 }
544 if (isset($this->import_key)) {
545 $this->import_key = trim($this->import_key);
546 }
547
548 // $this->oldcopy should have been set by the caller of update (here properties were already modified)
549 if (empty($this->oldcopy)) {
550 $this->oldcopy = dol_clone($this);
551 }
552
553 // Update request
554 $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET';
555 $sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").',';
556 $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").',';
557 $sql .= ' batch = '.(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").',';
558 $sql .= ' eatby = '.(!isset($this->eatby) || dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').',';
559 $sql .= ' sellby = '.(!isset($this->sellby) || dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').',';
560 $sql .= ' eol_date = '.(!isset($this->eol_date) || dol_strlen($this->eol_date) != 0 ? "'".$this->db->idate($this->eol_date)."'" : 'null').',';
561 $sql .= ' manufacturing_date = '.(!isset($this->manufacturing_date) || dol_strlen($this->manufacturing_date) != 0 ? "'".$this->db->idate($this->manufacturing_date)."'" : 'null').',';
562 $sql .= ' scrapping_date = '.(!isset($this->scrapping_date) || dol_strlen($this->scrapping_date) != 0 ? "'".$this->db->idate($this->scrapping_date)."'" : 'null').',';
563 //$sql .= ' commissionning_date = '.(!isset($this->first_use_date) || dol_strlen($this->first_use_date) != 0 ? "'".$this->db->idate($this->first_use_date)."'" : 'null').',';
564 $sql .= ' qc_frequency = '.(!empty($this->qc_frequency) ? (int) $this->qc_frequency : 'null').',';
565 $sql .= ' lifetime = '.(!empty($this->lifetime) ? (int) $this->lifetime : 'null').',';
566 $sql .= ' datec = '.(!isset($this->datec) || dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').',';
567 $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").',';
568 $sql .= ' fk_user_creat = '.(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").',';
569 $sql .= ' fk_user_modif = '.(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").',';
570 $sql .= ' import_key = '.(isset($this->import_key) ? $this->import_key : "null");
571 $sql .= ' WHERE rowid='.((int) $this->id);
572
573 $this->db->begin();
574
575 $resql = $this->db->query($sql);
576 if (!$resql) {
577 $error++;
578 $this->errors[] = 'Error '.$this->db->lasterror();
579 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
580 }
581
582 // Actions on extra fields
583 if (!$error) {
584 $result = $this->insertExtraFields();
585 if ($result < 0) {
586 $error++;
587 }
588 }
589
590 if (!$error && !$notrigger) {
591 // Call triggers
592 $result = $this->call_trigger('PRODUCTLOT_MODIFY', $user);
593 if ($result < 0) {
594 $error++;
595 }
596 // End call triggers
597 }
598
599 // Commit or rollback
600 if ($error) {
601 $this->db->rollback();
602
603 return -1 * $error;
604 } else {
605 $this->db->commit();
606
607 return 1;
608 }
609 }
610
619 public function delete(User $user, $notrigger = false)
620 {
621 dol_syslog(__METHOD__, LOG_DEBUG);
622
623 $error = 0;
624
625 $this->db->begin();
626
627 // Check there is no stock for this lot
628 $sql = "SELECT pb.rowid FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps";
629 $sql .= " WHERE pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($this->batch)."'";
630 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
631 $sql .= $this->db->plimit(1);
632
633 $resql = $this->db->query($sql);
634 if ($resql) {
635 $obj = $this->db->fetch_object($resql);
636 if ($obj) {
637 $error++;
638 $this->errors[] = 'Error Lot is used in stock (ID = '.$obj->rowid.'). Deletion not possible.';
639 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
640 }
641 } else {
642 $error++;
643 $this->errors[] = 'Error '.$this->db->lasterror();
644 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
645 }
646
647 // Check there is no movement for this lot
648 $sql = "SELECT sm.rowid FROM ".$this->db->prefix()."stock_mouvement as sm";
649 $sql .= " WHERE sm.batch = '".$this->db->escape($this->batch)."'";
650 $sql .= " AND sm.fk_product = ".((int) $this->fk_product);
651 $sql .= $this->db->plimit(1);
652
653 $resql = $this->db->query($sql);
654 if ($resql) {
655 $obj = $this->db->fetch_object($resql);
656 if ($obj) {
657 $error++;
658 $this->errors[] = 'Error Lot was used in a stock movement (ID '.$obj->rowid.'). Deletion not possible.';
659 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
660 }
661 } else {
662 $error++;
663 $this->errors[] = 'Error '.$this->db->lasterror();
664 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
665 }
666
667 // TODO
668 //if (!$error) {
669 //if (!$notrigger) {
670 // Uncomment this and change PRODUCTLOT to your own tag if you
671 // want this action calls a trigger.
672
674 //$result=$this->call_trigger('PRODUCTLOT_DELETE',$user);
675 //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
677 //}
678 //}
679
680 if (!$error) {
681 $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element;
682 $sql .= ' WHERE rowid='.((int) $this->id);
683
684 $resql = $this->db->query($sql);
685 if (!$resql) {
686 $error++;
687 $this->errors[] = 'Error '.$this->db->lasterror();
688 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
689 }
690 }
691
692 // Commit or rollback
693 if ($error) {
694 $this->db->rollback();
695
696 return -1 * $error;
697 } else {
698 $this->db->commit();
699
700 return 1;
701 }
702 }
703
711 public function createFromClone(User $user, $fromid)
712 {
713 dol_syslog(__METHOD__, LOG_DEBUG);
714
715 $error = 0;
716 $object = new Productlot($this->db);
717
718 $this->db->begin();
719
720 // Load source object
721 $object->fetch($fromid);
722 // Reset object
723 $object->id = 0;
724
725 // Clear fields
726 // ...
727
728 // Create clone
729 $object->context['createfromclone'] = 'createfromclone';
730 $result = $object->create($user);
731
732 // Other options
733 if ($result < 0) {
734 $error++;
735 $this->errors = $object->errors;
736 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
737 }
738
739 unset($object->context['createfromclone']);
740
741 // End
742 if (!$error) {
743 $this->db->commit();
744
745 return $object->id;
746 } else {
747 $this->db->rollback();
748
749 return -1;
750 }
751 }
752
759 public function loadStatsExpedition($socid = 0)
760 {
761 // phpcs:enable
762 global $db, $conf, $user, $hookmanager, $action;
763
764 $sql = "SELECT COUNT(DISTINCT exp.fk_soc) as nb_customers, COUNT(DISTINCT exp.rowid) as nb,";
765 $sql .= " COUNT(ed.rowid) as nb_rows, SUM(edb.qty) as qty";
766 $sql .= " FROM ".$this->db->prefix()."expeditiondet_batch as edb";
767 $sql .= " INNER JOIN ".$this->db->prefix()."expeditiondet as ed ON (ed.rowid = edb.fk_expeditiondet)";
768 $sql .= " INNER JOIN ".$this->db->prefix()."expedition as exp ON (exp.rowid = ed.fk_expedition)";
769 // $sql .= ", ".$this->db->prefix()."societe as s";
770 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
771 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
772 }
773 $sql .= " WHERE exp.entity IN (".getEntity('expedition').")";
774 $sql .= " AND edb.batch = '".($this->db->escape($this->batch))."'";
775 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
776 $sql .= " AND exp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
777 }
778 //$sql.= " AND exp.fk_statut != 0";
779 if ($socid > 0) {
780 $sql .= " AND exp.fk_soc = ".((int) $socid);
781 }
782
783 $result = $this->db->query($sql);
784 if ($result) {
785 $obj = $this->db->fetch_object($result);
786 $this->stats_expedition['customers'] = $obj->nb_customers;
787 $this->stats_expedition['nb'] = $obj->nb;
788 $this->stats_expedition['rows'] = $obj->nb_rows;
789 $this->stats_expedition['qty'] = $obj->qty ? $obj->qty : 0;
790
791
792 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
793
794 // if it's a virtual product, maybe it is in invoice by extension
795 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
796 // $TFather = $this->getFather();
797 // if (is_array($TFather) && !empty($TFather)) {
798 // foreach ($TFather as &$fatherData) {
799 // $pFather = new Product($this->db);
800 // $pFather->id = $fatherData['id'];
801 // $qtyCoef = $fatherData['qty'];
802 //
803 // if ($fatherData['incdec']) {
804 // $pFather->loadStatsExpedition($socid);
805 //
806 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
807 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
808 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
809 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
810 // }
811 // }
812 // }
813 // }
814
815 $parameters = array('socid' => $socid);
816 $reshook = $hookmanager->executeHooks('loadStatsLotExpedition', $parameters, $this, $action);
817 if ($reshook > 0) {
818 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
819 }
820
821 return 1;
822 } else {
823 $this->error = $this->db->error();
824 return -1;
825 }
826 }
827
834 public function loadStatsSupplierOrder($socid = 0)
835 {
836 // phpcs:enable
837 global $db, $conf, $user, $hookmanager, $action;
838
839 $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_customers, COUNT(DISTINCT cf.rowid) as nb,";
840 $sql .= " COUNT(cfd.rowid) as nb_rows, SUM(cfdi.qty) as qty";
841 $sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as cfdi";
842 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseurdet as cfd ON (cfd.rowid = cfdi.fk_commandefourndet)";
843 $sql .= " INNER JOIN ".$this->db->prefix()."commande_fournisseur as cf ON (cf.rowid = cfd.fk_commande)";
844 // $sql .= ", ".$this->db->prefix()."societe as s";
845 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
846 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
847 }
848 $sql .= " WHERE cf.entity IN (".getEntity('expedition').")";
849 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
850 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
851 $sql .= " AND cf.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
852 }
853 //$sql.= " AND cf.fk_statut != 0";
854 if ($socid > 0) {
855 $sql .= " AND cf.fk_soc = ".((int) $socid);
856 }
857
858 $result = $this->db->query($sql);
859 if ($result) {
860 $obj = $this->db->fetch_object($result);
861 $this->stats_supplier_order['customers'] = $obj->nb_customers;
862 $this->stats_supplier_order['nb'] = $obj->nb;
863 $this->stats_supplier_order['rows'] = $obj->nb_rows;
864 $this->stats_supplier_order['qty'] = $obj->qty ? $obj->qty : 0;
865
866
867 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
868
869 // if it's a virtual product, maybe it is in invoice by extension
870 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
871 // $TFather = $this->getFather();
872 // if (is_array($TFather) && !empty($TFather)) {
873 // foreach ($TFather as &$fatherData) {
874 // $pFather = new Product($this->db);
875 // $pFather->id = $fatherData['id'];
876 // $qtyCoef = $fatherData['qty'];
877 //
878 // if ($fatherData['incdec']) {
879 // $pFather->stats_supplier_order($socid);
880 //
881 // $this->stats_supplier_order['customers'] += $pFather->stats_supplier_order['customers'];
882 // $this->stats_supplier_order['nb'] += $pFather->stats_supplier_order['nb'];
883 // $this->stats_supplier_order['rows'] += $pFather->stats_supplier_order['rows'];
884 // $this->stats_supplier_order['qty'] += $pFather->stats_supplier_order['qty'] * $qtyCoef;
885 // }
886 // }
887 // }
888 // }
889
890 $parameters = array('socid' => $socid);
891 $reshook = $hookmanager->executeHooks('loadStatsLotSupplierOrder', $parameters, $this, $action);
892 if ($reshook > 0) {
893 $this->stats_supplier_order = $hookmanager->resArray['stats_supplier_order'];
894 }
895
896 return 1;
897 } else {
898 $this->error = $this->db->error();
899 return -1;
900 }
901 }
902
909 public function loadStatsReception($socid = 0)
910 {
911 // phpcs:enable
912 global $db, $conf, $user, $hookmanager, $action;
913
914 $sql = "SELECT COUNT(DISTINCT recep.fk_soc) as nb_customers, COUNT(DISTINCT recep.rowid) as nb,";
915 $sql .= " COUNT(cfdi.rowid) as nb_rows, SUM(cfdi.qty) as qty";
916 $sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as cfdi";
917 $sql .= " INNER JOIN ".$this->db->prefix()."reception as recep ON (recep.rowid = cfdi.fk_reception)";
918 // $sql .= ", ".$this->db->prefix()."societe as s";
919 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
920 $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc";
921 }
922 $sql .= " WHERE recep.entity IN (".getEntity('reception').")";
923 $sql .= " AND cfdi.batch = '".($this->db->escape($this->batch))."'";
924 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
925 $sql .= " AND recep.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
926 }
927 //$sql.= " AND exp.fk_statut != 0";
928 if ($socid > 0) {
929 $sql .= " AND recep.fk_soc = ".((int) $socid);
930 }
931
932 $result = $this->db->query($sql);
933 if ($result) {
934 $obj = $this->db->fetch_object($result);
935 $this->stats_reception['customers'] = $obj->nb_customers;
936 $this->stats_reception['nb'] = $obj->nb;
937 $this->stats_reception['rows'] = $obj->nb_rows;
938 $this->stats_reception['qty'] = $obj->qty ? $obj->qty : 0;
939
940
941 // Virtual products can't be used with kits (see langs with key ErrorNoteAlsoThatSubProductCantBeFollowedByLot)
942
943 // if it's a virtual product, maybe it is in invoice by extension
944 // if (!empty($conf->global->PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC)) {
945 // $TFather = $this->getFather();
946 // if (is_array($TFather) && !empty($TFather)) {
947 // foreach ($TFather as &$fatherData) {
948 // $pFather = new Product($this->db);
949 // $pFather->id = $fatherData['id'];
950 // $qtyCoef = $fatherData['qty'];
951 //
952 // if ($fatherData['incdec']) {
953 // $pFather->loadStatsReception($socid);
954 //
955 // $this->stats_expedition['customers'] += $pFather->stats_expedition['customers'];
956 // $this->stats_expedition['nb'] += $pFather->stats_expedition['nb'];
957 // $this->stats_expedition['rows'] += $pFather->stats_expedition['rows'];
958 // $this->stats_expedition['qty'] += $pFather->stats_expedition['qty'] * $qtyCoef;
959 // }
960 // }
961 // }
962 // }
963
964 $parameters = array('socid' => $socid);
965 $reshook = $hookmanager->executeHooks('loadStatsLotReception', $parameters, $this, $action);
966 if ($reshook > 0) {
967 $this->stats_expedition = $hookmanager->resArray['stats_expedition'];
968 }
969
970 return 1;
971 } else {
972 $this->error = $this->db->error();
973 return -1;
974 }
975 }
976
983 public function loadStatsMo($socid = 0)
984 {
985 // phpcs:enable
986 global $user, $hookmanager, $action;
987
988 $error = 0;
989
990 foreach (array('toconsume', 'consumed', 'toproduce', 'produced') as $role) {
991 $this->stats_mo['customers_'.$role] = 0;
992 $this->stats_mo['nb_'.$role] = 0;
993 $this->stats_mo['qty_'.$role] = 0;
994
995 $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
996 $sql .= " SUM(mp.qty) as qty";
997 $sql .= " FROM ".$this->db->prefix()."mrp_mo as c";
998 $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid";
999 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
1000 $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id);
1001 }
1002 $sql .= " WHERE ";
1003 $sql .= " c.entity IN (".getEntity('mo').")";
1004
1005 $sql .= " AND mp.batch = '".($this->db->escape($this->batch))."'";
1006 $sql .= " AND mp.role ='".$this->db->escape($role)."'";
1007 if ($socid > 0) {
1008 $sql .= " AND c.fk_soc = ".((int) $socid);
1009 }
1010
1011 $result = $this->db->query($sql);
1012 if ($result) {
1013 $obj = $this->db->fetch_object($result);
1014 $this->stats_mo['customers_'.$role] = $obj->nb_customers ? $obj->nb_customers : 0;
1015 $this->stats_mo['nb_'.$role] = $obj->nb ? $obj->nb : 0;
1016 $this->stats_mo['qty_'.$role] = $obj->qty ? price2num($obj->qty, 'MS') : 0; // qty may be a float due to the SUM()
1017 } else {
1018 $this->error = $this->db->error();
1019 $error++;
1020 }
1021 }
1022
1023 if (!empty($error)) {
1024 return -1;
1025 }
1026
1027 $parameters = array('socid' => $socid);
1028 $reshook = $hookmanager->executeHooks('loadStatsCustomerMO', $parameters, $this, $action);
1029 if ($reshook > 0) {
1030 $this->stats_mo = $hookmanager->resArray['stats_mo'];
1031 }
1032
1033 return 1;
1034 }
1035
1036
1043 public function getLibStatut($mode = 0)
1044 {
1045 return $this->LibStatut(0, $mode);
1046 }
1047
1048 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1056 public function LibStatut($status, $mode = 0)
1057 {
1058 // phpcs:enable
1059 global $langs;
1060
1061 //$langs->load('stocks');
1062
1063 return '';
1064 }
1065
1066
1074 public function getTooltipContentArray($params)
1075 {
1076 global $conf, $langs, $user;
1077
1078 $langs->loadLangs(['stocks', 'productbatch']);
1079
1080 $option = $params['option'] ?? '';
1081
1082 $datas = [];
1083 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Batch").'</u>';
1084 //$datas['divopen'] = '<div width="100%">';
1085 $datas['batch'] = '<br><b>'.$langs->trans('Batch').':</b> '.$this->batch;
1086 if ($this->eatby && !getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1087 $datas['eatby'] = '<br><b>'.$langs->trans('EatByDate').':</b> '.dol_print_date($this->eatby, 'day');
1088 }
1089 if ($this->sellby && !getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1090 $datas['sellby'] = '<br><b>'.$langs->trans('SellByDate').':</b> '.dol_print_date($this->sellby, 'day');
1091 }
1092 //$datas['divclose'] = '</div>';
1093
1094 return $datas;
1095 }
1096
1109 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $maxlen = 24, $morecss = '', $save_lastsearch_value = -1)
1110 {
1111 global $langs, $conf, $hookmanager;
1112
1113 $result = '';
1114 $params = [
1115 'id' => $this->id,
1116 'objecttype' => $this->element,
1117 'option' => $option,
1118 ];
1119 $classfortooltip = 'classfortooltip';
1120 $dataparams = '';
1121 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1122 $classfortooltip = 'classforajaxtooltip';
1123 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1124 $label = '';
1125 } else {
1126 $label = implode($this->getTooltipContentArray($params));
1127 }
1128
1129 $url = DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$this->id;
1130
1131 if ($option != 'nolink') {
1132 // Add param to save lastsearch_values or not
1133 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1134 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1135 $add_save_lastsearch_values = 1;
1136 }
1137 if ($add_save_lastsearch_values) {
1138 $url .= '&save_lastsearch_values=1';
1139 }
1140 }
1141
1142 $linkclose = '';
1143 if (empty($notooltip)) {
1144 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1145 $label = $langs->trans("ShowMyObject");
1146 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1147 }
1148 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
1149 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
1150 } else {
1151 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1152 }
1153
1154 if ($option == 'nolink') {
1155 $linkstart = '<span';
1156 } else {
1157 $linkstart = '<a href="'.$url.'"';
1158 }
1159 $linkstart .= $linkclose.'>';
1160 if ($option == 'nolink') {
1161 $linkend = '</span>';
1162 } else {
1163 $linkend = '</a>';
1164 }
1165
1166 $result .= $linkstart;
1167 if ($withpicto) {
1168 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1169 }
1170 if ($withpicto != 2) {
1171 $result .= $this->batch;
1172 }
1173 $result .= $linkend;
1174
1175 global $action;
1176 $hookmanager->initHooks(array('productlotdao'));
1177 $parameters = array('id' => $this->id, 'getnomurl' => $result);
1178 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1179 if ($reshook > 0) {
1180 $result = $hookmanager->resPrint;
1181 } else {
1182 $result .= $hookmanager->resPrint;
1183 }
1184
1185 return $result;
1186 }
1187
1188
1195 public function initAsSpecimen()
1196 {
1197 global $conf;
1198
1199 // Initialise parametres
1200 $this->id = 0;
1201 $this->ref = 'SPECIMEN';
1202 $this->specimen = 1;
1203
1204 $this->entity = $conf->entity;
1205 $this->fk_product = null;
1206 $this->batch = '';
1207 $this->eatby = '';
1208 $this->sellby = '';
1209 $this->datec = '';
1210 $this->tms = '';
1211 $this->fk_user_creat = null;
1212 $this->fk_user_modif = null;
1213 $this->import_key = '';
1214 }
1215
1226 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
1227 {
1228 global $conf, $user, $langs;
1229
1230 $langs->loadLangs(array('stocks', 'productbatch', "products"));
1231 $outputlangs->loadLangs(array('stocks', 'productbatch', "products"));
1232
1233 // Positionne le modele sur le nom du modele a utiliser
1234 if (!dol_strlen($modele)) {
1235 $modele = '';
1236
1237 if (!empty($this->model_pdf)) {
1238 $modele = $this->model_pdf;
1239 } elseif (getDolGlobalString('PRODUCT_BATCH_ADDON_PDF')) {
1240 $modele = $conf->global->PRODUCT_BATCH_ADDON_PDF;
1241 }
1242 }
1243
1244 $modelpath = "core/modules/product_batch/doc/";
1245
1246 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1247 }
1248}
$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.
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 optionaly 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.
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.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
create(User $user, $notrigger=false)
Create object into database.
loadStatsSupplierOrder($socid=0)
Charge tableau des stats commande fournisseur pour le lot/numéro de série.
update(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.