dolibarr 21.0.0-beta
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;
142 public $date_inventory;
146 public $title;
147
151 public $status;
152
156 public $fk_user_creat;
157
161 public $fk_user_modif;
162
166 public $fk_user_valid;
167
171 public $import_key;
172 // END MODULEBUILDER PROPERTIES
173
174
175
176 // If this object has a subtable with lines
177
181 public $table_element_line = 'inventorydet';
182
186 public $fk_element = 'fk_inventory';
187
191 public $class_element_line = 'Inventoryline';
192
196 protected $childtables = array();
200 protected $childtablesoncascade = array('inventorydet');
201
205 public $lines = array();
206
207
208
214 public function __construct(DoliDB $db)
215 {
216 global $conf;
217
218 $this->db = $db;
219
220 $this->ismultientitymanaged = 1;
221 $this->isextrafieldmanaged = 0;
222
223 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
224 $this->fields['rowid']['visible'] = 0;
225 }
226 if (!isModEnabled('multicompany')) {
227 $this->fields['entity']['enabled'] = 0;
228 }
229 }
230
231
239 public function create(User $user, $notrigger = 0)
240 {
241 $result = $this->createCommon($user, $notrigger);
242
243 return $result;
244 }
245
254 public function validate(User $user, $notrigger = 0, $include_sub_warehouse = 0)
255 {
256 $this->db->begin();
257
258 $result = 0;
259
260 if ($this->status == self::STATUS_DRAFT) {
261 // Delete inventory
262 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
263 $resql = $this->db->query($sql);
264 if (!$resql) {
265 $this->error = $this->db->lasterror();
266 $this->db->rollback();
267 return -1;
268 }
269
270 // Scan existing stock to prefill the inventory
271 $sql = "SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
272 if (isModEnabled('productbatch')) {
273 $sql .= " pb.batch as batch, pb.qty as qty,";
274 } else {
275 $sql .= " '' as batch, 0 as qty,";
276 }
277 $sql .= " p.ref, p.tobatch";
278 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
279 if (isModEnabled('productbatch')) {
280 $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid";
281 }
282 $sql .= ", ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e";
283 $sql .= " WHERE p.entity IN (".getEntity('product').")";
284 $sql .= " AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid";
285 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
286 $sql .= " AND p.fk_product_type = 0";
287 }
288 if ($this->fk_product > 0) {
289 $sql .= " AND ps.fk_product = ".((int) $this->fk_product);
290 }
291 if ($this->fk_warehouse > 0) {
292 $sql .= " AND (ps.fk_entrepot = ".((int) $this->fk_warehouse);
293 if (!empty($include_sub_warehouse) && getDolGlobalInt('INVENTORY_INCLUDE_SUB_WAREHOUSE')) {
294 $TChildWarehouses = array();
295 $this->getChildWarehouse($this->fk_warehouse, $TChildWarehouses);
296 $sql .= " OR ps.fk_entrepot IN (".$this->db->sanitize(implode(',', $TChildWarehouses)).")";
297 }
298 $sql .= ')';
299 }
300 if (!empty($this->categories_product)) {
301 $sql .= " AND EXISTS (";
302 $sql .= " SELECT cp.fk_product";
303 $sql .= " FROM ".$this->db->prefix()."categorie_product AS cp";
304 $sql .= " WHERE cp.fk_product = ps.fk_product";
305 $sql .= " AND cp.fk_categorie IN (".$this->db->sanitize($this->categories_product).")";
306 $sql .= ")";
307 }
308 if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
309 $sql .= " AND NOT EXISTS (";
310 $sql .= " SELECT pa.rowid";
311 $sql .= " FROM ".$this->db->prefix()."product_association as pa";
312 $sql .= " WHERE pa.fk_product_pere = ps.fk_product";
313 $sql .= ")";
314 }
315 $sql .= " ORDER BY p.rowid";
316
317 $inventoryline = new InventoryLine($this->db);
318
319 $resql = $this->db->query($sql);
320 if ($resql) {
321 $num = $this->db->num_rows($resql);
322
323 $i = 0;
324 while ($i < $num) {
325 $obj = $this->db->fetch_object($resql);
326
327 $inventoryline->fk_inventory = $this->id;
328 $inventoryline->fk_warehouse = $obj->fk_warehouse;
329 $inventoryline->fk_product = $obj->fk_product;
330 $inventoryline->batch = $obj->batch;
331 $inventoryline->datec = dol_now();
332
333 if (isModEnabled('productbatch')) {
334 if ($obj->batch && empty($obj->tobatch)) {
335 // Bad consistency of data. The product is not a product with lot/serial but we found a stock for some lot/serial.
336 $result = -2;
337 $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";
338 break;
339 }
340
341 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel); // If there is batch detail, we take qty for batch, else global qty
342 } else {
343 $inventoryline->qty_stock = $obj->reel;
344 }
345 //var_dump($obj->batch.' '.$obj->qty.' '.$obj->reel.' '.$this->error);exit;
346
347 $resultline = $inventoryline->create($user);
348 if ($resultline <= 0) {
349 $this->error = $inventoryline->error;
350 $this->errors = $inventoryline->errors;
351 $result = -1;
352 break;
353 }
354
355 $i++;
356 }
357 } else {
358 $result = -1;
359 $this->error = $this->db->lasterror();
360 }
361 }
362
363 if ($result >= 0) {
364 $result = $this->setStatut($this::STATUS_VALIDATED, null, '', 'INVENTORY_VALIDATED');
365 }
366
367 if ($result > 0) {
368 $this->db->commit();
369 } else {
370 $this->db->rollback();
371 }
372 return $result;
373 }
374
382 public function setDraft(User $user, $notrigger = 0)
383 {
384 $this->db->begin();
385
386 // Delete inventory
387 $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id);
388 $resql = $this->db->query($sql);
389 if (!$resql) {
390 $this->error = $this->db->lasterror();
391 $this->db->rollback();
392 return -1;
393 }
394
395 $result = $this->setStatut($this::STATUS_DRAFT, null, '', 'INVENTORY_DRAFT');
396
397 if ($result > 0) {
398 $this->db->commit();
399 } else {
400 $this->db->rollback();
401 }
402 return $result;
403 }
404
412 public function setRecorded(User $user, $notrigger = 0)
413 {
414 $this->db->begin();
415
416 $result = $this->setStatut($this::STATUS_RECORDED, null, '', 'INVENTORY_RECORDED');
417
418 if ($result > 0) {
419 $this->db->commit();
420 } else {
421 $this->db->rollback();
422 return -1;
423 }
424 return $result;
425 }
426
434 public function setCanceled(User $user, $notrigger = 0)
435 {
436 $this->db->begin();
437
438 $result = $this->setStatut($this::STATUS_CANCELED, null, '', 'INVENTORY_CANCELED');
439
440 if ($result > 0) {
441 $this->db->commit();
442 } else {
443 $this->db->rollback();
444 return -1;
445 }
446 return $result;
447 }
448
456 public function createFromClone(User $user, $fromid)
457 {
458 global $hookmanager, $langs;
459 $error = 0;
460
461 dol_syslog(__METHOD__, LOG_DEBUG);
462
463 $object = new self($this->db);
464
465 $this->db->begin();
466
467 // Load source object
468 $object->fetchCommon($fromid);
469 // Reset some properties
470 unset($object->id);
471 unset($object->fk_user_creat);
472 unset($object->import_key);
473
474 // Clear fields
475 $object->ref = "copy_of_".$object->ref;
476 $object->title = $langs->trans("CopyOf")." ".$object->title;
477 // ...
478
479 // Create clone
480 $object->context['createfromclone'] = 'createfromclone';
481 $result = $object->createCommon($user);
482 if ($result < 0) {
483 $error++;
484 $this->error = $object->error;
485 $this->errors = $object->errors;
486 }
487
488 unset($object->context['createfromclone']);
489
490 // End
491 if (!$error) {
492 $this->db->commit();
493 return $object;
494 } else {
495 $this->db->rollback();
496 return -1;
497 }
498 }
499
507 public function fetch($id, $ref = null)
508 {
509 $result = $this->fetchCommon($id, $ref);
510 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
511 return $result;
512 }
513
519 /*public function fetchLines()
520 {
521 $this->lines=array();
522
523 // Load lines with object MyObjectLine
524
525 return count($this->lines)?1:0;
526 }*/
527
535 public function update(User $user, $notrigger = 0)
536 {
537 return $this->updateCommon($user, $notrigger);
538 }
539
547 public function delete(User $user, $notrigger = 0)
548 {
549 return $this->deleteCommon($user, $notrigger);
550 }
551
560 public function deleteLine(User $user, $idline, $notrigger = 0)
561 {
562 if ($this->status < 0) {
563 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
564 return -2;
565 }
566
567 return $this->deleteLineCommon($user, $idline, $notrigger);
568 }
569
580 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
581 {
582 global $db, $conf, $langs;
583 global $dolibarr_main_authentication, $dolibarr_main_demo;
584 global $menumanager;
585
586 if (!empty($conf->dol_no_mouse_hover)) {
587 $notooltip = 1; // Force disable tooltips
588 }
589
590 $result = '';
591 $companylink = '';
592
593 $label = '<u>'.$langs->trans("Inventory").'</u>';
594 $label .= '<br>';
595 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
596
597 $url = dol_buildpath('/product/inventory/card.php', 1).'?id='.$this->id;
598
599 $linkclose = '';
600 if (empty($notooltip)) {
601 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
602 $label = $langs->trans("ShowInventory");
603 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
604 }
605 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
606 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
607 } else {
608 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
609 }
610
611 $linkstart = '<a href="'.$url.'"';
612 $linkstart .= $linkclose.'>';
613 $linkend = '</a>';
614
615 $result .= $linkstart;
616 if ($withpicto) {
617 $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);
618 }
619 if ($withpicto != 2) {
620 $result .= $this->ref;
621 }
622 $result .= $linkend;
623 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
624
625 return $result;
626 }
627
634 public function getLibStatut($mode = 0)
635 {
636 return $this->LibStatut($this->status, $mode);
637 }
638
639 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
647 public function LibStatut($status, $mode = 0)
648 {
649 // phpcs:enable
650 global $langs, $hookmanager;
651
652 $labelStatus = array();
653 $labelStatusShort = array();
654 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
655 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
656 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
657 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
658 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
659 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
660 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
661 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
662
663 $statusType = 'status'.$status;
664 if ($status == self::STATUS_RECORDED) {
665 $statusType = 'status6';
666 }
667
668 $parameters = array('status' => $status, 'mode' => $mode);
669 $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); // Note that $action and $object may have been modified by hook
670 if ($reshook > 0) {
671 return $hookmanager->resPrint;
672 }
673 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', $statusType, $mode);
674 }
675
683 public function getKanbanView($option = '', $arraydata = null)
684 {
685 global $conf, $langs;
686
687 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
688
689 $return = '<div class="box-flex-item box-flex-grow-zero">';
690 $return .= '<div class="info-box info-box-sm">';
691 $return .= '<span class="info-box-icon bg-infobox-action">';
692 $return .= img_picto('', $this->picto);
693 $return .= '</span>';
694 $return .= '<div class="info-box-content">';
695 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
696 if ($selected >= 0) {
697 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
698 }
699 if (property_exists($this, 'label')) {
700 $return .= ' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.'</div>';
701 }
702 if (property_exists($this, 'amount')) {
703 $return .= '<br>';
704 $return .= '<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
705 }
706 if (method_exists($this, 'getLibStatut')) {
707 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
708 }
709 $return .= '</div>';
710 $return .= '</div>';
711 $return .= '</div>';
712
713 return $return;
714 }
715
722 public function info($id)
723 {
724 $sql = "SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
725 $sql .= " fk_user_creat, fk_user_modif, fk_user_valid";
726 $sql .= " FROM ".$this->db->prefix().$this->table_element." as t";
727 $sql .= " WHERE t.rowid = ".((int) $id);
728 $result = $this->db->query($sql);
729 if ($result) {
730 if ($this->db->num_rows($result)) {
731 $obj = $this->db->fetch_object($result);
732
733 $this->id = $obj->rowid;
734
735 $this->user_creation_id = $obj->fk_user_creat;
736 $this->user_modification_id = $obj->fk_user_modif;
737 $this->user_validation_id = $obj->fk_user_valid;
738
739 $this->date_creation = $this->db->jdate($obj->datec);
740 $this->date_modification = $this->db->jdate($obj->datem);
741 $this->date_validation = $this->db->jdate($obj->datev);
742 }
743
744 $this->db->free($result);
745 } else {
746 dol_print_error($this->db);
747 }
748 }
749
756 public function initAsSpecimen()
757 {
758 $ret = $this->initAsSpecimenCommon();
759 $this->title = '';
760
761 return $ret;
762 }
763
771 public function getChildWarehouse($id, &$TChildWarehouse)
772 {
773 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'entrepot';
774 $sql .= ' WHERE fk_parent='.(int) $id;
775 $sql .= ' ORDER BY rowid';
776 $resql = $this->db->query($sql);
777 if ($resql && $this->db->num_rows($resql) > 0) {
778 while ($obj = $this->db->fetch_object($resql)) {
779 $TChildWarehouse[] = $obj->rowid;
780 $this->getChildWarehouse($obj->rowid, $TChildWarehouse);
781 }
782 return 1;
783 } else {
784 return -1;
785 }
786 }
787}
788
793{
797 public $element = 'inventoryline';
798
802 public $table_element = 'inventorydet';
803
807 public $parent_element = 'inventory';
808
812 public $fk_parent_attribute = 'fk_inventory';
813
817 public $picto = 'stock';
818
836 // BEGIN MODULEBUILDER PROPERTIES
840 public $fields = array(
841 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'visible' => -1, 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'index' => 1, 'comment' => 'Id',),
842 'fk_inventory' => array('type' => 'integer:Inventory:product/inventory/class/inventory.class.php', 'label' => 'Inventory', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToInventory'),
843 'fk_warehouse' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Warehouse', 'visible' => 1, 'enabled' => 1, 'position' => 30, 'index' => 1, 'help' => 'LinkToThirdparty'),
844 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
845 'batch' => array('type' => 'string', 'label' => 'Batch', 'visible' => 1, 'enabled' => 1, 'position' => 32, 'index' => 1, 'help' => 'LinkToProduct'),
846 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 500),
847 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 501),
848 '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)'),
849 'qty_view' => array('type' => 'double', 'label' => 'QtyBefore', 'visible' => 1, 'enabled' => 1, 'position' => 33, 'index' => 1, 'help' => 'Qty before (filled once movements are validated)'),
850 '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)'),
851 'pmp_real' => array('type' => 'double', 'label' => 'PMPReal', 'visible' => 1, 'enabled' => 1, 'position' => 35),
852 'pmp_expected' => array('type' => 'double', 'label' => 'PMPExpected', 'visible' => 1, 'enabled' => 1, 'position' => 36),
853 );
854
858 public $rowid;
859
863 public $fk_inventory;
867 public $fk_warehouse;
871 public $fk_product;
875 public $batch;
879 public $datec;
880
884 public $qty_stock;
885
889 public $qty_view;
890
894 public $qty_regulated;
895
899 public $pmp_real;
903 public $pmp_expected;
904
910 public function __construct($db)
911 {
912 $this->db = $db;
913 $this->ismultientitymanaged = 0;
914
915 $this->isextrafieldmanaged = 0;
916 }
924 public function create(User $user, $notrigger = 0)
925 {
926 return $this->createCommon($user, $notrigger);
927 }
928
936 public function fetch($id, $ref = null)
937 {
938 $result = $this->fetchCommon($id, $ref);
939 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
940 return $result;
941 }
942
950 public function update(User $user, $notrigger = 0)
951 {
952 return $this->updateCommon($user, $notrigger);
953 }
954
962 public function delete(User $user, $notrigger = 0)
963 {
964 return $this->deleteCommon($user, $notrigger);
965 //return $this->deleteCommon($user, $notrigger, 1);
966 }
967}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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".
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.
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.
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:171
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79