dolibarr 25.0.0-alpha
inventory.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014-2016 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) 2024-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.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';
32require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
33//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
34//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
35
41{
45 public $element = 'inventory';
46
50 public $table_element = 'inventory';
51
55 public $picto = 'inventory';
56
57 const STATUS_DRAFT = 0; // Draft
58 const STATUS_VALIDATED = 1; // Inventory is in process
59 const STATUS_RECORDED = 2; // Inventory is finisged. Stock movement has been recorded.
60 const STATUS_CANCELED = 9; // Canceled
61
69 const START_MODE_CURRENT = 'current';
70 const START_MODE_NONE = 'none';
71 const START_MODE_ZERO = 'zero';
72
99 // BEGIN MODULEBUILDER PROPERTIES
103 public $fields = array(
104 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
105 'ref' => array('type' => 'varchar(64)', 'label' => 'Ref', 'visible' => 1, 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'index' => 1, 'searchall' => 1, 'comment' => 'Reference of object', 'css' => 'maxwidth150'),
106 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
107 'title' => array('type' => 'varchar(255)', 'label' => 'Label', 'visible' => 1, 'enabled' => 1, 'position' => 25, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax150', 'alwayseditable' => 1),
108 'fk_warehouse' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Warehouse', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'InventoryForASpecificWarehouse', 'picto' => 'stock', 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist' => 'tdoverflowmax150'),
109 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'get_name_url_params' => '0::0:-1:0::1', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'InventoryForASpecificProduct', 'picto' => 'product', 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx', 'csslist' => 'tdoverflowmax150'),
110 'categories_product' => array('type' => 'chkbxlst:categorie:label:rowid::type=0:0:', 'label' => 'OrProductsWithCategories', 'visible' => 3, 'enabled' => 1, 'position' => 33, 'help' => '', 'picto' => 'category', 'css' => 'minwidth300 maxwidth500 widthcentpercentminusx'),
111 'date_inventory' => array('type' => 'date', 'label' => 'DateValue', 'visible' => 1, 'enabled' => 'getDolGlobalInt("STOCK_INVENTORY_ADD_A_VALUE_DATE")', 'position' => 35, 'csslist' => 'nowraponall'), // This date is not used so disabled by default.
112 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500, 'csslist' => 'nowraponall'),
113 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501, 'csslist' => 'nowraponall'),
114 'date_validation' => array('type' => 'datetime', 'label' => 'DateValidation', 'visible' => -2, 'enabled' => 1, 'position' => 502, 'csslist' => 'nowraponall'),
115 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 510, 'foreignkey' => 'user.rowid', 'csslist' => 'tdoverflowmax150'),
116 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511, 'csslist' => 'tdoverflowmax150'),
117 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'visible' => -2, 'enabled' => 1, 'position' => 512, 'csslist' => 'tdoverflowmax150'),
118 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000),
119 'status' => array('type' => 'integer', 'label' => 'Status', 'visible' => 4, 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'default' => '0', 'index' => 1, 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', 2 => 'Closed', 9 => 'Canceled'))
120 );
121
125 public $rowid;
126
130 public $ref;
131
135 public $fk_warehouse;
136
140 public $fk_product;
141
145 public $categories_product;
149 public $date_inventory;
153 public $title;
154
158 public $status;
159
163 public $fk_user_creat;
164
168 public $fk_user_modif;
169
173 public $fk_user_valid;
174
178 public $import_key;
179 // END MODULEBUILDER PROPERTIES
180
181
182
183 // If this object has a subtable with lines
184
188 public $table_element_line = 'inventorydet';
189
193 public $fk_element = 'fk_inventory';
194
198 public $class_element_line = 'Inventoryline';
199
203 protected $childtables = array();
207 protected $childtablesoncascade = array('inventorydet');
208
212 public $lines = array();
213
214
215
221 public function __construct(DoliDB $db)
222 {
223 $this->db = $db;
224
225 $this->ismultientitymanaged = 1;
226 $this->isextrafieldmanaged = 0;
227
228 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
229 $this->fields['rowid']['visible'] = 0;
230 }
231 if (!isModEnabled('multicompany')) {
232 $this->fields['entity']['enabled'] = 0;
233 }
234 }
235
236
244 public function create(User $user, $notrigger = 0)
245 {
246 $result = $this->createCommon($user, $notrigger);
247
248 return $result;
249 }
250
262 public function validate(User $user, $notrigger = 0, $include_sub_warehouse = 0, $startmode = '')
263 {
264 $this->db->begin();
265
266 $result = 0;
267
268 if (empty($startmode)) {
269 $startmode = getDolGlobalString('INVENTORY_DEFAULT_START_MODE', self::START_MODE_CURRENT);
270 }
271 if (!in_array($startmode, array(self::START_MODE_CURRENT, self::START_MODE_NONE, self::START_MODE_ZERO))) {
272 $startmode = self::START_MODE_CURRENT;
273 }
274
275 if ($this->status == self::STATUS_DRAFT) {
276 // Delete inventory
277 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
278 $resql = $this->db->query($sql);
279 if (!$resql) {
280 $this->error = $this->db->lasterror();
281 $this->db->rollback();
282 return -1;
283 }
284
285 if ($startmode == self::START_MODE_NONE) {
286 // Start with no line at all: they will be added manually or with a barcode scanner while counting
287 $result = $this->setStatut($this::STATUS_VALIDATED, null, '', 'INVENTORY_VALIDATED');
288 if ($result > 0) {
289 $this->db->commit();
290 } else {
291 $this->db->rollback();
292 }
293 return $result;
294 }
295
296 // Scan existing stock to prefill the inventory
297 $sql = "SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
298 if (isModEnabled('productbatch')) {
299 $sql .= " COALESCE(pb.batch, '') as batch, pb.qty as qty,";
300 } else {
301 $sql .= " '' as batch, 0 as qty,";
302 }
303 $sql .= " p.ref, p.tobatch";
304 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
305 if (isModEnabled('productbatch')) {
306 $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid";
307 }
308 $sql .= ", ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e";
309 $sql .= " WHERE p.entity IN (".getEntity('product').")";
310 $sql .= " AND e.entity IN (".getEntity('stock').")";
311 $sql .= " AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid";
312 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
313 $sql .= " AND p.fk_product_type = 0";
314 }
315 if ($this->fk_product > 0) {
316 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
317 }
318 if ($this->fk_warehouse > 0) {
319 $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse);
320 if (!empty($include_sub_warehouse) && getDolGlobalInt('INVENTORY_INCLUDE_SUB_WAREHOUSE')) {
321 $TChildWarehouses = array();
322 $this->getChildWarehouse($this->fk_warehouse, $TChildWarehouses);
323 if (!empty($TChildWarehouses)) {
324 $sql .= " OR ps.fk_entrepot IN (" . $this->db->sanitize(implode(',', $TChildWarehouses)) . ")";
325 }
326 }
327 $sql .= ')';
328 }
329 if (!empty($this->categories_product)) {
330 $sql .= " AND EXISTS (";
331 $sql .= " SELECT cp.fk_product";
332 $sql .= " FROM ".$this->db->prefix()."categorie_product AS cp";
333 $sql .= " WHERE cp.fk_product = ps.fk_product";
334 $sql .= " AND cp.fk_categorie IN (".$this->db->sanitize($this->categories_product).")";
335 $sql .= ")";
336 }
337 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
338 $sql .= " AND NOT EXISTS (";
339 $sql .= " SELECT pa.rowid";
340 $sql .= " FROM ".$this->db->prefix()."product_association as pa";
341 $sql .= " WHERE pa.fk_product_pere = ps.fk_product";
342 $sql .= ")";
343 }
344 $sql .= " ORDER BY p.rowid";
345
346 $inventoryline = new InventoryLine($this->db);
347
348 $resql = $this->db->query($sql);
349 if ($resql) {
350 $num = $this->db->num_rows($resql);
351
352 $i = 0;
353 while ($i < $num) {
354 $obj = $this->db->fetch_object($resql);
355
356 $inventoryline->fk_inventory = $this->id;
357 $inventoryline->fk_warehouse = $obj->fk_warehouse;
358 $inventoryline->fk_product = $obj->fk_product;
359 $inventoryline->batch = $obj->batch;
360 $inventoryline->datec = dol_now();
361 // With the "zero" start mode, the counted qty is preset to 0 instead of being left empty,
362 // so a product that is never counted is regulated to zero when the inventory is recorded.
363 $inventoryline->qty_view = ($startmode == self::START_MODE_ZERO) ? 0 : null;
364
365 if (isModEnabled('productbatch')) {
366 if ($obj->batch && empty($obj->tobatch)) {
367 // Bad consistency of data. The product is not a product with lot/serial but we found a stock for some lot/serial.
368 $result = -2;
369 $this->error = 'The product ID='.$obj->ref." has stock with lot/serial but is configured to not manage lot/serial. You must first fix this, this way: Set the product to have 'Management of Lot/Serial' to Yes, then set it back to 'Management of Lot/Serial to No";
370 break;
371 }
372
373 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel); // If there is batch detail, we take qty for batch, else global qty
374 } else {
375 $inventoryline->qty_stock = $obj->reel;
376 }
377
378 $resultline = $inventoryline->create($user);
379 if ($resultline <= 0) {
380 $this->error = $inventoryline->error;
381 $this->errors = $inventoryline->errors;
382 $result = -1;
383 break;
384 }
385
386 $i++;
387 }
388 } else {
389 $result = -1;
390 $this->error = $this->db->lasterror();
391 }
392 }
393
394 if ($result >= 0) {
395 $result = $this->setStatut($this::STATUS_VALIDATED, null, '', 'INVENTORY_VALIDATED');
396 }
397
398 if ($result > 0) {
399 $this->db->commit();
400 } else {
401 $this->db->rollback();
402 }
403 return $result;
404 }
405
413 public function setDraft(User $user, $notrigger = 0)
414 {
415 $this->db->begin();
416
417 // Delete inventory
418 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
419 $resql = $this->db->query($sql);
420 if (!$resql) {
421 $this->error = $this->db->lasterror();
422 $this->db->rollback();
423 return -1;
424 }
425
426 $result = $this->setStatut($this::STATUS_DRAFT, null, '', 'INVENTORY_DRAFT');
427
428 if ($result > 0) {
429 $this->db->commit();
430 } else {
431 $this->db->rollback();
432 }
433 return $result;
434 }
435
443 public function setRecorded(User $user, $notrigger = 0)
444 {
445 $this->db->begin();
446
447 $result = $this->setStatut($this::STATUS_RECORDED, null, '', 'INVENTORY_RECORDED');
448
449 if ($result > 0) {
450 $this->db->commit();
451 } else {
452 $this->db->rollback();
453 return -1;
454 }
455 return $result;
456 }
457
465 public function setCanceled(User $user, $notrigger = 0)
466 {
467 $this->db->begin();
468
469 $result = $this->setStatut($this::STATUS_CANCELED, null, '', 'INVENTORY_CANCELED');
470
471 if ($result > 0) {
472 $this->db->commit();
473 } else {
474 $this->db->rollback();
475 return -1;
476 }
477 return $result;
478 }
479
487 public function createFromClone(User $user, $fromid)
488 {
489 global $langs;
490
491 $error = 0;
492
493 dol_syslog(__METHOD__, LOG_DEBUG);
494
495 $object = new self($this->db);
496
497 $this->db->begin();
498
499 // Load source object
500 $object->fetchCommon($fromid);
501 // Reset some properties
502 unset($object->id);
503 unset($object->fk_user_creat);
504 unset($object->import_key);
505
506 // Clear fields
507 $object->ref = "copy_of_".$object->ref;
508 $object->title = $langs->trans("CopyOf")." ".$object->title;
509 // ...
510
511 // Create clone
512 $object->context['createfromclone'] = 'createfromclone';
513 $result = $object->createCommon($user);
514 if ($result < 0) {
515 $error++;
517 }
518
519 unset($object->context['createfromclone']);
520
521 // End
522 if (!$error) {
523 $this->db->commit();
524 return $object;
525 } else {
526 $this->db->rollback();
527 return -1;
528 }
529 }
530
538 public function fetch($id, $ref = null)
539 {
540 $result = $this->fetchCommon($id, $ref);
541 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
542 return $result;
543 }
544
550 /*public function fetchLines()
551 {
552 $this->lines=array();
553
554 // Load lines with object MyObjectLine
555
556 return count($this->lines)?1:0;
557 }*/
558
566 public function update(User $user, $notrigger = 0)
567 {
568 return $this->updateCommon($user, $notrigger);
569 }
570
578 public function delete(User $user, $notrigger = 0)
579 {
580 return $this->deleteCommon($user, $notrigger);
581 }
582
591 public function deleteLine(User $user, $idline, $notrigger = 0)
592 {
593 if ($this->status < 0) {
594 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
595 return -2;
596 }
597
598 return $this->deleteLineCommon($user, $idline, $notrigger);
599 }
600
611 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
612 {
613 global $conf, $langs;
614
615 if (!empty($conf->dol_no_mouse_hover)) {
616 $notooltip = 1; // Force disable tooltips
617 }
618
619 $result = '';
620
621 $label = '<u>'.$langs->trans("Inventory").'</u>';
622 $label .= '<br>';
623 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
624
625 $url = dol_buildpath('/product/inventory/card.php', 1).'?id='.$this->id;
626
627 $linkclose = '';
628 if (empty($notooltip)) {
629 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
630 $label = $langs->trans("ShowInventory");
631 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
632 }
633 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
634 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
635 } else {
636 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
637 }
638
639 $linkstart = '<a href="'.$url.'"';
640 $linkstart .= $linkclose.'>';
641 $linkend = '</a>';
642
643 $result .= $linkstart;
644 if ($withpicto) {
645 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
646 }
647 if ($withpicto != 2) {
648 $result .= $this->ref;
649 }
650 $result .= $linkend;
651 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
652
653 global $action, $hookmanager;
654 $hookmanager->initHooks(array($this->element . 'dao'));
655 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
656 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
657 if ($reshook > 0) {
658 $result = $hookmanager->resPrint;
659 } else {
660 $result .= $hookmanager->resPrint;
661 }
662
663 return $result;
664 }
665
672 public function getLibStatut($mode = 0)
673 {
674 return $this->LibStatut($this->status, $mode);
675 }
676
677 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
685 public function LibStatut($status, $mode = 0)
686 {
687 // phpcs:enable
688 global $langs, $hookmanager;
689
690 $labelStatus = array();
691 $labelStatusShort = array();
692 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
693 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
694 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
695 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
696 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
697 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
698 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
699 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
700
701 $statusType = 'status'.$status;
702 if ($status == self::STATUS_RECORDED) {
703 $statusType = 'status6';
704 }
705
706 $parameters = array('status' => $status, 'mode' => $mode);
707 $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); // Note that $action and $object may have been modified by hook
708 if ($reshook > 0) {
709 return $hookmanager->resPrint;
710 }
711 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
712 }
713
721 public function getKanbanView($option = '', $arraydata = null)
722 {
723 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
724
725 $return = '<div class="box-flex-item box-flex-grow-zero">';
726 $return .= '<div class="info-box info-box-sm">';
727 $return .= '<span class="info-box-icon bg-infobox-action">';
728 $return .= img_picto('', $this->picto);
729 $return .= '</span>';
730 $return .= '<div class="info-box-content">';
731 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
732 if ($selected >= 0) {
733 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
734 }
735 if (method_exists($this, 'getLibStatut')) {
736 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
737 }
738 $return .= '</div>';
739 $return .= '</div>';
740 $return .= '</div>';
741
742 return $return;
743 }
744
751 public function info($id)
752 {
753 $sql = "SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
754 $sql .= " fk_user_creat, fk_user_modif, fk_user_valid";
755 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
756 $sql .= " WHERE t.rowid = ".((int) $id);
757 $result = $this->db->query($sql);
758 if ($result) {
759 if ($this->db->num_rows($result)) {
760 $obj = $this->db->fetch_object($result);
761
762 $this->id = $obj->rowid;
763
764 $this->user_creation_id = $obj->fk_user_creat;
765 $this->user_modification_id = $obj->fk_user_modif;
766 $this->user_validation_id = $obj->fk_user_valid;
767
768 $this->date_creation = $this->db->jdate($obj->datec);
769 $this->date_modification = $this->db->jdate($obj->datem);
770 $this->date_validation = $this->db->jdate($obj->datev);
771 }
772
773 $this->db->free($result);
774 } else {
775 dol_print_error($this->db);
776 }
777 }
778
785 public function initAsSpecimen()
786 {
787 $ret = $this->initAsSpecimenCommon();
788 $this->title = '';
789
790 return $ret;
791 }
792
800 public function getChildWarehouse($id, &$TChildWarehouse)
801 {
802 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot';
803 $sql .= ' WHERE fk_parent='.(int) $id;
804 $sql .= ' ORDER BY rowid';
805 $resql = $this->db->query($sql);
806 if ($resql && $this->db->num_rows($resql) > 0) {
807 while ($obj = $this->db->fetch_object($resql)) {
808 $TChildWarehouse[] = $obj->rowid;
809 $this->getChildWarehouse($obj->rowid, $TChildWarehouse);
810 }
811 return 1;
812 } else {
813 return -1;
814 }
815 }
816
817
824 public function getNextNumRef()
825 {
826 global $langs, $conf;
827 $langs->load("stocks");
828
829 if (!getDolGlobalString('INVENTORY_ADDON')) {
830 return ''; // Free reference, typed by the user (historical behaviour)
831 }
832
833 $mybool = false;
834
835 $file = getDolGlobalString('INVENTORY_ADDON').".php";
836 $classname = getDolGlobalString('INVENTORY_ADDON');
837
838 // Include file with class
839 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
840 foreach ($dirmodels as $reldir) {
841 $dir = dol_buildpath($reldir."core/modules/inventory/");
842
843 // Load file with numbering class (if found)
844 $mybool = ((bool) @include_once $dir.$file) || $mybool;
845 }
846
847 if (!$mybool) {
848 dol_print_error(null, "Failed to include file ".$file);
849 return '';
850 }
851
852 if (class_exists($classname)) {
853 $obj = new $classname();
854 '@phan-var-force ModeleNumRefInventory $obj';
855 $numref = $obj->getNextValue($this);
856
857 if ($numref != '' && $numref != '-1') {
858 return $numref;
859 } else {
860 $this->error = $obj->error;
861 return '';
862 }
863 }
864
865 return '';
866 }
867
879 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
880 {
881 global $langs;
882
883 $langs->load("stocks");
884
885 if (!dol_strlen($modele)) {
886 $modele = ''; // Remove this once a pdf_standard.php exists.
887
888 if ($this->model_pdf) {
889 $modele = $this->model_pdf;
890 } elseif (getDolGlobalString('INVENTORY_ADDON_PDF')) {
891 $modele = getDolGlobalString('INVENTORY_ADDON_PDF');
892 }
893 }
894
895 $modelpath = "core/modules/inventory/doc/";
896
897 if (empty($modele)) {
898 return 1; // Remove this once a pdf_standard.php exists.
899 }
900
901 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
902 }
903}
904
909{
913 public $element = 'inventoryline';
914
918 public $table_element = 'inventorydet';
919
923 public $parent_element = 'inventory';
924
928 public $fk_parent_attribute = 'fk_inventory';
929
933 public $picto = 'stock';
934
952 // BEGIN MODULEBUILDER PROPERTIES
956 public $fields = array(
957 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
958 'fk_inventory' => array('type' => 'integer:Inventory:product/inventory/class/inventory.class.php', 'label' => 'Inventory', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToInventory'),
959 'fk_warehouse' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Warehouse', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToThirdparty'),
960 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
961 'batch' => array('type' => 'string', 'label' => 'Batch', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
962 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500),
963 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
964 'qty_stock' => array('type' => 'double', 'label' => 'QtyFound', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'Qty we found/want (to define during draft edition)'),
965 'qty_view' => array('type' => 'double', 'label' => 'QtyBefore', 'visible' => 1, 'enabled' => 1, 'position' => 33, 'index' => 1, 'help' => 'Qty before (filled once movements are validated)'),
966 'qty_regulated' => array('type' => 'double', 'label' => 'QtyDelta', 'visible' => 1, 'enabled' => 1, 'position' => 34, 'index' => 1, 'help' => 'Qty added or removed (filled once movements are validated)'),
967 'pmp_real' => array('type' => 'double', 'label' => 'PMPReal', 'visible' => 1, 'enabled' => 1, 'position' => 35),
968 'pmp_expected' => array('type' => 'double', 'label' => 'PMPExpected', 'visible' => 1, 'enabled' => 1, 'position' => 36),
969 );
970
974 public $rowid;
975
979 public $fk_inventory;
983 public $fk_warehouse;
987 public $fk_product;
991 public $batch;
995 public $datec;
996
1000 public $qty_stock;
1001
1005 public $qty_view;
1006
1010 public $qty_regulated;
1011
1015 public $pmp_real;
1019 public $pmp_expected;
1020
1026 public function __construct($db)
1027 {
1028 $this->db = $db;
1029 $this->ismultientitymanaged = 0;
1030
1031 $this->isextrafieldmanaged = 0;
1032 }
1040 public function create(User $user, $notrigger = 0)
1041 {
1042 return $this->createCommon($user, $notrigger);
1043 }
1044
1052 public function fetch($id, $ref = null)
1053 {
1054 $result = $this->fetchCommon($id, $ref);
1055 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
1056 return $result;
1057 }
1058
1066 public function update(User $user, $notrigger = 0)
1067 {
1068 return $this->updateCommon($user, $notrigger);
1069 }
1070
1078 public function delete(User $user, $notrigger = 0)
1079 {
1080 return $this->deleteCommon($user, $notrigger);
1081 //return $this->deleteCommon($user, $notrigger, 1);
1082 }
1083}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='')
Set status of an object.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class for Inventory.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
create(User $user, $notrigger=0)
Create object into database.
setRecorded(User $user, $notrigger=0)
Set to inventory to status "Closed".
LibStatut($status, $mode=0)
Return the status.
getKanbanView($option='', $arraydata=null)
Return a thumb for kanban views.
__construct(DoliDB $db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
info($id)
Charge les information d'ordre info dans l'objet commande.
setDraft(User $user, $notrigger=0)
Go back to draft.
update(User $user, $notrigger=0)
Load object lines in memory from the database.
setCanceled(User $user, $notrigger=0)
Set to Canceled.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
const START_MODE_CURRENT
How the lines of the inventory are initialized when it is started.
fetch($id, $ref=null)
Load object in memory from the database.
validate(User $user, $notrigger=0, $include_sub_warehouse=0, $startmode='')
Validate inventory (start it)
getChildWarehouse($id, &$TChildWarehouse)
Return the child warehouse of the current one.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
createFromClone(User $user, $fromid)
Clone and object into another one.
Class InventoryLine.
update(User $user, $notrigger=0)
Update object into database.
__construct($db)
Constructor.
create(User $user, $notrigger=0)
Create object in database.
fetch($id, $ref=null)
Load object in memory from the database.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.