dolibarr 20.0.5
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 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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';
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.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
40{
44 public $element = 'inventory';
45
49 public $table_element = 'inventory';
50
54 public $picto = 'inventory';
55
56 const STATUS_DRAFT = 0; // Draft
57 const STATUS_VALIDATED = 1; // Inventory is in process
58 const STATUS_RECORDED = 2; // Inventory is finisged. Stock movement has been recorded.
59 const STATUS_CANCELED = 9; // Canceled
60
87 // BEGIN MODULEBUILDER PROPERTIES
91 public $fields = array(
92 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
93 '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'),
94 'entity' => array('type' => 'integer', 'label' => 'Entity', 'visible' => 0, 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'index' => 1,),
95 'title' => array('type' => 'varchar(255)', 'label' => 'Label', 'visible' => 1, 'enabled' => 1, 'position' => 25, 'css' => 'minwidth300', 'csslist' => 'tdoverflowmax150', 'alwayseditable' => 1),
96 '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'),
97 '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'),
98 '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'),
99 'date_inventory' => array('type' => 'date', 'label' => 'DateValue', 'visible' => 1, 'enabled' => '$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE', 'position' => 35, 'csslist' => 'nowraponall'), // This date is not used so disabled by default.
100 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500, 'csslist' => 'nowraponall'),
101 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501, 'csslist' => 'nowraponall'),
102 'date_validation' => array('type' => 'datetime', 'label' => 'DateValidation', 'visible' => -2, 'enabled' => 1, 'position' => 502, 'csslist' => 'nowraponall'),
103 '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'),
104 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 511, 'csslist' => 'tdoverflowmax150'),
105 'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'visible' => -2, 'enabled' => 1, 'position' => 512, 'csslist' => 'tdoverflowmax150'),
106 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'index' => 0, 'position' => 1000),
107 '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'))
108 );
109
113 public $rowid;
114
118 public $ref;
119
123 public $entity;
124
128 public $fk_warehouse;
129
133 public $fk_product;
134
138 public $categories_product;
139 public $date_inventory;
140 public $title;
141
145 public $status;
146
150 public $date_creation;
151
155 public $date_validation;
156
160 public $fk_user_creat;
161
165 public $fk_user_modif;
166
170 public $fk_user_valid;
171
175 public $import_key;
176 // END MODULEBUILDER PROPERTIES
177
178
179
180 // If this object has a subtable with lines
181
185 public $table_element_line = 'inventorydet';
186
190 public $fk_element = 'fk_inventory';
191
195 public $class_element_line = 'Inventoryline';
196
200 protected $childtables = array();
204 protected $childtablesoncascade = array('inventorydet');
205
209 public $lines = array();
210
211
212
218 public function __construct(DoliDB $db)
219 {
220 global $conf;
221
222 $this->db = $db;
223
224 $this->ismultientitymanaged = 1;
225 $this->isextrafieldmanaged = 0;
226
227 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
228 $this->fields['rowid']['visible'] = 0;
229 }
230 if (!isModEnabled('multicompany')) {
231 $this->fields['entity']['enabled'] = 0;
232 }
233 }
234
235
243 public function create(User $user, $notrigger = 0)
244 {
245 $result = $this->createCommon($user, $notrigger);
246
247 return $result;
248 }
249
258 public function validate(User $user, $notrigger = 0, $include_sub_warehouse = 0)
259 {
260 $this->db->begin();
261
262 $result = 0;
263
264 if ($this->status == self::STATUS_DRAFT) {
265 // Delete inventory
266 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
267 $resql = $this->db->query($sql);
268 if (!$resql) {
269 $this->error = $this->db->lasterror();
270 $this->db->rollback();
271 return -1;
272 }
273
274 // Scan existing stock to prefill the inventory
275 $sql = "SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
276 if (isModEnabled('productbatch')) {
277 $sql .= " COALESCE(pb.batch, '') as batch, pb.qty as qty,";
278 } else {
279 $sql .= " '' as batch, 0 as qty,";
280 }
281 $sql .= " p.ref, p.tobatch";
282 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
283 if (isModEnabled('productbatch')) {
284 $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid";
285 }
286 $sql .= ", ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e";
287 $sql .= " WHERE p.entity IN (".getEntity('product').")";
288 $sql .= " AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid";
289 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
290 $sql .= " AND p.fk_product_type = 0";
291 }
292 if ($this->fk_product > 0) {
293 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
294 }
295 if ($this->fk_warehouse > 0) {
296 $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse);
297 if (!empty($include_sub_warehouse) && getDolGlobalInt('INVENTORY_INCLUDE_SUB_WAREHOUSE')) {
298 $TChildWarehouses = array();
299 $this->getChildWarehouse($this->fk_warehouse, $TChildWarehouses);
300 if (!empty($TChildWarehouses)) {
301 $sql .= " OR ps.fk_entrepot IN (" . $this->db->sanitize(implode(',', $TChildWarehouses)) . ")";
302 }
303 }
304 $sql .= ')';
305 }
306 if (!empty($this->categories_product)) {
307 $sql .= " AND EXISTS (";
308 $sql .= " SELECT cp.fk_product";
309 $sql .= " FROM ".$this->db->prefix()."categorie_product AS cp";
310 $sql .= " WHERE cp.fk_product = ps.fk_product";
311 $sql .= " AND cp.fk_categorie IN (".$this->db->sanitize($this->categories_product).")";
312 $sql .= ")";
313 }
314 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
315 $sql .= " AND NOT EXISTS (";
316 $sql .= " SELECT pa.rowid";
317 $sql .= " FROM ".$this->db->prefix()."product_association as pa";
318 $sql .= " WHERE pa.fk_product_pere = ps.fk_product";
319 $sql .= ")";
320 }
321 $sql .= " ORDER BY p.rowid";
322
323 $inventoryline = new InventoryLine($this->db);
324
325 $resql = $this->db->query($sql);
326 if ($resql) {
327 $num = $this->db->num_rows($resql);
328
329 $i = 0;
330 while ($i < $num) {
331 $obj = $this->db->fetch_object($resql);
332
333 $inventoryline->fk_inventory = $this->id;
334 $inventoryline->fk_warehouse = $obj->fk_warehouse;
335 $inventoryline->fk_product = $obj->fk_product;
336 $inventoryline->batch = $obj->batch;
337 $inventoryline->datec = dol_now();
338
339 if (isModEnabled('productbatch')) {
340 if ($obj->batch && empty($obj->tobatch)) {
341 // Bad consistency of data. The product is not a product with lot/serial but we found a stock for some lot/serial.
342 $result = -2;
343 $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";
344 break;
345 }
346
347 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel); // If there is batch detail, we take qty for batch, else global qty
348 } else {
349 $inventoryline->qty_stock = $obj->reel;
350 }
351 //var_dump($obj->batch.' '.$obj->qty.' '.$obj->reel.' '.$this->error);exit;
352
353 $resultline = $inventoryline->create($user);
354 if ($resultline <= 0) {
355 $this->error = $inventoryline->error;
356 $this->errors = $inventoryline->errors;
357 $result = -1;
358 break;
359 }
360
361 $i++;
362 }
363 } else {
364 $result = -1;
365 $this->error = $this->db->lasterror();
366 }
367 }
368
369 if ($result >= 0) {
370 $result = $this->setStatut($this::STATUS_VALIDATED, null, '', 'INVENTORY_VALIDATED');
371 }
372
373 if ($result > 0) {
374 $this->db->commit();
375 } else {
376 $this->db->rollback();
377 }
378 return $result;
379 }
380
388 public function setDraft(User $user, $notrigger = 0)
389 {
390 $this->db->begin();
391
392 // Delete inventory
393 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
394 $resql = $this->db->query($sql);
395 if (!$resql) {
396 $this->error = $this->db->lasterror();
397 $this->db->rollback();
398 return -1;
399 }
400
401 $result = $this->setStatut($this::STATUS_DRAFT, null, '', 'INVENTORY_DRAFT');
402
403 if ($result > 0) {
404 $this->db->commit();
405 } else {
406 $this->db->rollback();
407 }
408 return $result;
409 }
410
418 public function setRecorded(User $user, $notrigger = 0)
419 {
420 $this->db->begin();
421
422 $result = $this->setStatut($this::STATUS_RECORDED, null, '', 'INVENTORY_RECORDED');
423
424 if ($result > 0) {
425 $this->db->commit();
426 } else {
427 $this->db->rollback();
428 return -1;
429 }
430 return $result;
431 }
432
440 public function setCanceled(User $user, $notrigger = 0)
441 {
442 $this->db->begin();
443
444 $result = $this->setStatut($this::STATUS_CANCELED, null, '', 'INVENTORY_CANCELED');
445
446 if ($result > 0) {
447 $this->db->commit();
448 } else {
449 $this->db->rollback();
450 return -1;
451 }
452 return $result;
453 }
454
462 public function createFromClone(User $user, $fromid)
463 {
464 global $hookmanager, $langs;
465 $error = 0;
466
467 dol_syslog(__METHOD__, LOG_DEBUG);
468
469 $object = new self($this->db);
470
471 $this->db->begin();
472
473 // Load source object
474 $object->fetchCommon($fromid);
475 // Reset some properties
476 unset($object->id);
477 unset($object->fk_user_creat);
478 unset($object->import_key);
479
480 // Clear fields
481 $object->ref = "copy_of_".$object->ref;
482 $object->title = $langs->trans("CopyOf")." ".$object->title;
483 // ...
484
485 // Create clone
486 $object->context['createfromclone'] = 'createfromclone';
487 $result = $object->createCommon($user);
488 if ($result < 0) {
489 $error++;
490 $this->error = $object->error;
491 $this->errors = $object->errors;
492 }
493
494 unset($object->context['createfromclone']);
495
496 // End
497 if (!$error) {
498 $this->db->commit();
499 return $object;
500 } else {
501 $this->db->rollback();
502 return -1;
503 }
504 }
505
513 public function fetch($id, $ref = null)
514 {
515 $result = $this->fetchCommon($id, $ref);
516 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
517 return $result;
518 }
519
525 /*public function fetchLines()
526 {
527 $this->lines=array();
528
529 // Load lines with object MyObjectLine
530
531 return count($this->lines)?1:0;
532 }*/
533
541 public function update(User $user, $notrigger = 0)
542 {
543 return $this->updateCommon($user, $notrigger);
544 }
545
553 public function delete(User $user, $notrigger = 0)
554 {
555 return $this->deleteCommon($user, $notrigger);
556 }
557
566 public function deleteLine(User $user, $idline, $notrigger = 0)
567 {
568 if ($this->status < 0) {
569 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
570 return -2;
571 }
572
573 return $this->deleteLineCommon($user, $idline, $notrigger);
574 }
575
586 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
587 {
588 global $db, $conf, $langs;
589 global $dolibarr_main_authentication, $dolibarr_main_demo;
590 global $menumanager;
591
592 if (!empty($conf->dol_no_mouse_hover)) {
593 $notooltip = 1; // Force disable tooltips
594 }
595
596 $result = '';
597 $companylink = '';
598
599 $label = '<u>'.$langs->trans("Inventory").'</u>';
600 $label .= '<br>';
601 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
602
603 $url = dol_buildpath('/product/inventory/card.php', 1).'?id='.$this->id;
604
605 $linkclose = '';
606 if (empty($notooltip)) {
607 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
608 $label = $langs->trans("ShowInventory");
609 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
610 }
611 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
612 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
613 } else {
614 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
615 }
616
617 $linkstart = '<a href="'.$url.'"';
618 $linkstart .= $linkclose.'>';
619 $linkend = '</a>';
620
621 $result .= $linkstart;
622 if ($withpicto) {
623 $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);
624 }
625 if ($withpicto != 2) {
626 $result .= $this->ref;
627 }
628 $result .= $linkend;
629 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
630
631 return $result;
632 }
633
640 public function getLibStatut($mode = 0)
641 {
642 return $this->LibStatut($this->status, $mode);
643 }
644
645 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
653 public static function LibStatut($status, $mode = 0)
654 {
655 // phpcs:enable
656 global $langs;
657
658 $labelStatus = array();
659 $labelStatusShort = array();
660 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
661 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
662 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
663 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
664 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
665 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
666 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
667 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
668
669 $statusType = 'status'.$status;
670 if ($status == self::STATUS_RECORDED) {
671 $statusType = 'status6';
672 }
673
674 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
675 }
676
684 public function getKanbanView($option = '', $arraydata = null)
685 {
686 global $conf, $langs;
687
688 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
689
690 $return = '<div class="box-flex-item box-flex-grow-zero">';
691 $return .= '<div class="info-box info-box-sm">';
692 $return .= '<span class="info-box-icon bg-infobox-action">';
693 $return .= img_picto('', $this->picto);
694 $return .= '</span>';
695 $return .= '<div class="info-box-content">';
696 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
697 if ($selected >= 0) {
698 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
699 }
700 if (property_exists($this, 'label')) {
701 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
702 }
703 if (property_exists($this, 'amount')) {
704 $return .= '<br>';
705 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
706 }
707 if (method_exists($this, 'getLibStatut')) {
708 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
709 }
710 $return .= '</div>';
711 $return .= '</div>';
712 $return .= '</div>';
713
714 return $return;
715 }
716
723 public function info($id)
724 {
725 $sql = "SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
726 $sql .= " fk_user_creat, fk_user_modif, fk_user_valid";
727 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
728 $sql .= " WHERE t.rowid = ".((int) $id);
729 $result = $this->db->query($sql);
730 if ($result) {
731 if ($this->db->num_rows($result)) {
732 $obj = $this->db->fetch_object($result);
733
734 $this->id = $obj->rowid;
735
736 $this->user_creation_id = $obj->fk_user_creat;
737 $this->user_modification_id = $obj->fk_user_modif;
738 $this->user_validation_id = $obj->fk_user_valid;
739
740 $this->date_creation = $this->db->jdate($obj->datec);
741 $this->date_modification = $this->db->jdate($obj->datem);
742 $this->date_validation = $this->db->jdate($obj->datev);
743 }
744
745 $this->db->free($result);
746 } else {
747 dol_print_error($this->db);
748 }
749 }
750
757 public function initAsSpecimen()
758 {
759 $ret = $this->initAsSpecimenCommon();
760 $this->title = '';
761
762 return $ret;
763 }
764
772 public function getChildWarehouse($id, &$TChildWarehouse)
773 {
774 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot';
775 $sql .= ' WHERE fk_parent='.(int) $id;
776 $sql .= ' ORDER BY rowid';
777 $resql = $this->db->query($sql);
778 if ($resql && $this->db->num_rows($resql) > 0) {
779 while ($obj = $this->db->fetch_object($resql)) {
780 $TChildWarehouse[] = $obj->rowid;
781 $this->getChildWarehouse($obj->rowid, $TChildWarehouse);
782 }
783 return 1;
784 } else {
785 return -1;
786 }
787 }
788}
789
794{
798 public $element = 'inventoryline';
799
803 public $table_element = 'inventorydet';
804
808 public $parent_element = 'inventory';
809
813 public $fk_parent_attribute = 'fk_inventory';
814
818 public $picto = 'stock';
819
837 // BEGIN MODULEBUILDER PROPERTIES
841 public $fields = array(
842 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
843 'fk_inventory' => array('type' => 'integer:Inventory:product/inventory/class/inventory.class.php', 'label' => 'Inventory', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToInventory'),
844 'fk_warehouse' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Warehouse', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToThirdparty'),
845 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
846 'batch' => array('type' => 'string', 'label' => 'Batch', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
847 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500),
848 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
849 '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)'),
850 'qty_view' => array('type' => 'double', 'label' => 'QtyBefore', 'visible' => 1, 'enabled' => 1, 'position' => 33, 'index' => 1, 'help' => 'Qty before (filled once movements are validated)'),
851 '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)'),
852 'pmp_real' => array('type' => 'double', 'label' => 'PMPReal', 'visible' => 1, 'enabled' => 1, 'position' => 35),
853 'pmp_expected' => array('type' => 'double', 'label' => 'PMPExpected', 'visible' => 1, 'enabled' => 1, 'position' => 36),
854 );
855
859 public $rowid;
860
861 public $fk_inventory;
862 public $fk_warehouse;
863 public $fk_product;
864 public $batch;
865 public $datec;
866
870 public $qty_stock;
871
875 public $qty_view;
876
880 public $qty_regulated;
881
882 public $pmp_real;
883 public $pmp_expected;
884
890 public function __construct($db)
891 {
892 $this->db = $db;
893 $this->ismultientitymanaged = 0;
894
895 $this->isextrafieldmanaged = 0;
896 }
904 public function create(User $user, $notrigger = 0)
905 {
906 return $this->createCommon($user, $notrigger);
907 }
908
916 public function fetch($id, $ref = null)
917 {
918 $result = $this->fetchCommon($id, $ref);
919 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
920 return $result;
921 }
922
930 public function update(User $user, $notrigger = 0)
931 {
932 return $this->updateCommon($user, $notrigger);
933 }
934
942 public function delete(User $user, $notrigger = 0)
943 {
944 return $this->deleteCommon($user, $notrigger);
945 //return $this->deleteCommon($user, $notrigger, 1);
946 }
947}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
createCommon(User $user, $notrigger=0)
Create object in the database.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
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".
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.
validate(User $user, $notrigger=0, $include_sub_warehouse=0)
Validate inventory (start it)
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.
fetch($id, $ref=null)
Load object in memory from the database.
getChildWarehouse($id, &$TChildWarehouse)
Return the child warehouse of the current one.
static LibStatut($status, $mode=0)
Return the status.
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.
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)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.