30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
44 public $element =
'inventory';
49 public $table_element =
'inventory';
54 public $picto =
'inventory';
56 const STATUS_DRAFT = 0;
57 const STATUS_VALIDATED = 1;
58 const STATUS_RECORDED = 2;
59 const STATUS_CANCELED = 9;
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'),
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'))
128 public $fk_warehouse;
138 public $categories_product;
139 public $date_inventory;
150 public $fk_user_creat;
155 public $fk_user_modif;
160 public $fk_user_valid;
175 public $table_element_line =
'inventorydet';
180 public $fk_element =
'fk_inventory';
185 public $class_element_line =
'Inventoryline';
190 protected $childtables = array();
194 protected $childtablesoncascade = array(
'inventorydet');
199 public $lines = array();
214 $this->ismultientitymanaged = 1;
215 $this->isextrafieldmanaged = 0;
218 $this->fields[
'rowid'][
'visible'] = 0;
220 if (!isModEnabled(
'multicompany')) {
221 $this->fields[
'entity'][
'enabled'] = 0;
248 public function validate(
User $user, $notrigger = 0, $include_sub_warehouse = 0)
254 if ($this->
status == self::STATUS_DRAFT) {
256 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
257 $resql = $this->db->query($sql);
259 $this->error = $this->db->lasterror();
260 $this->db->rollback();
265 $sql =
"SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
266 if (isModEnabled(
'productbatch')) {
267 $sql .=
" pb.batch as batch, pb.qty as qty,";
269 $sql .=
" '' as batch, 0 as qty,";
271 $sql .=
" p.ref, p.tobatch";
272 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
273 if (isModEnabled(
'productbatch')) {
274 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_batch as pb ON pb.fk_product_stock = ps.rowid";
276 $sql .=
", ".$this->db->prefix().
"product as p, ".$this->db->prefix().
"entrepot as e";
277 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
278 $sql .=
" AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid";
280 $sql .=
" AND p.fk_product_type = 0";
282 if ($this->fk_product > 0) {
283 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
285 if ($this->fk_warehouse > 0) {
286 $sql .=
" AND (ps.fk_entrepot = ".((int) $this->fk_warehouse);
287 if (!empty($include_sub_warehouse) &&
getDolGlobalInt(
'INVENTORY_INCLUDE_SUB_WAREHOUSE')) {
288 $TChildWarehouses = array();
290 $sql .=
" OR ps.fk_entrepot IN (".$this->db->sanitize(implode(
',', $TChildWarehouses)).
")";
294 if (!empty($this->categories_product)) {
295 $sql .=
" AND EXISTS (";
296 $sql .=
" SELECT cp.fk_product";
297 $sql .=
" FROM ".$this->db->prefix().
"categorie_product AS cp";
298 $sql .=
" WHERE cp.fk_product = ps.fk_product";
299 $sql .=
" AND cp.fk_categorie IN (".$this->db->sanitize($this->categories_product).
")";
303 $sql .=
" AND NOT EXISTS (";
304 $sql .=
" SELECT pa.rowid";
305 $sql .=
" FROM ".$this->db->prefix().
"product_association as pa";
306 $sql .=
" WHERE pa.fk_product_pere = ps.fk_product";
309 $sql .=
" ORDER BY p.rowid";
313 $resql = $this->db->query($sql);
315 $num = $this->db->num_rows($resql);
319 $obj = $this->db->fetch_object($resql);
321 $inventoryline->fk_inventory = $this->id;
322 $inventoryline->fk_warehouse = $obj->fk_warehouse;
323 $inventoryline->fk_product = $obj->fk_product;
324 $inventoryline->batch = $obj->batch;
325 $inventoryline->datec =
dol_now();
327 if (isModEnabled(
'productbatch')) {
328 if ($obj->batch && empty($obj->tobatch)) {
331 $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";
335 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel);
337 $inventoryline->qty_stock = $obj->reel;
341 $resultline = $inventoryline->create($user);
342 if ($resultline <= 0) {
343 $this->error = $inventoryline->error;
344 $this->errors = $inventoryline->errors;
353 $this->error = $this->db->lasterror();
358 $result = $this->
setStatut($this::STATUS_VALIDATED,
null,
'',
'INVENTORY_VALIDATED');
364 $this->db->rollback();
381 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
382 $resql = $this->db->query($sql);
384 $this->error = $this->db->lasterror();
385 $this->db->rollback();
389 $result = $this->
setStatut($this::STATUS_DRAFT,
null,
'',
'INVENTORY_DRAFT');
394 $this->db->rollback();
410 $result = $this->
setStatut($this::STATUS_RECORDED,
null,
'',
'INVENTORY_RECORDED');
415 $this->db->rollback();
432 $result = $this->
setStatut($this::STATUS_CANCELED,
null,
'',
'INVENTORY_CANCELED');
437 $this->db->rollback();
452 global $hookmanager, $langs;
469 $object->ref =
"copy_of_".$object->ref;
474 $object->context[
'createfromclone'] =
'createfromclone';
475 $result =
$object->createCommon($user);
479 $this->errors =
$object->errors;
482 unset(
$object->context[
'createfromclone']);
489 $this->db->rollback();
501 public function fetch($id, $ref =
null)
541 public function delete(
User $user, $notrigger = 0)
557 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
574 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
576 global $db, $conf, $langs;
577 global $dolibarr_main_authentication, $dolibarr_main_demo;
580 if (!empty($conf->dol_no_mouse_hover)) {
587 $label =
'<u>'.$langs->trans(
"Inventory").
'</u>';
589 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
591 $url =
dol_buildpath(
'/product/inventory/card.php', 1).
'?id='.$this->id;
594 if (empty($notooltip)) {
596 $label = $langs->trans(
"ShowInventory");
597 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
599 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
600 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
602 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
605 $linkstart =
'<a href="'.$url.
'"';
606 $linkstart .= $linkclose.
'>';
609 $result .= $linkstart;
611 $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);
613 if ($withpicto != 2) {
614 $result .= $this->ref;
644 global $langs, $hookmanager;
646 $labelStatus = array();
647 $labelStatusShort = array();
648 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
649 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated').
' ('.$langs->transnoentitiesnoconv(
'InventoryStartedShort').
')';
650 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
651 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
652 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
653 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'InventoryStartedShort');
654 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
655 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
657 $statusType =
'status'.$status;
658 if ($status == self::STATUS_RECORDED) {
659 $statusType =
'status6';
662 $parameters = array(
'status' => $status,
'mode' => $mode);
663 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
665 return $hookmanager->resPrint;
667 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode);
679 global $conf, $langs;
681 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
683 $return =
'<div class="box-flex-item box-flex-grow-zero">';
684 $return .=
'<div class="info-box info-box-sm">';
685 $return .=
'<span class="info-box-icon bg-infobox-action">';
687 $return .=
'</span>';
688 $return .=
'<div class="info-box-content">';
689 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
690 if ($selected >= 0) {
691 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
693 if (property_exists($this,
'label')) {
694 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
696 if (property_exists($this,
'amount')) {
698 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
700 if (method_exists($this,
'getLibStatut')) {
701 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
718 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
719 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
720 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
721 $sql .=
" WHERE t.rowid = ".((int) $id);
722 $result = $this->db->query($sql);
724 if ($this->db->num_rows($result)) {
725 $obj = $this->db->fetch_object($result);
727 $this->
id = $obj->rowid;
729 $this->user_creation_id = $obj->fk_user_creat;
730 $this->user_modification_id = $obj->fk_user_modif;
731 $this->user_validation_id = $obj->fk_user_valid;
733 $this->date_creation = $this->db->jdate($obj->datec);
734 $this->date_modification = $this->db->jdate($obj->datem);
735 $this->date_validation = $this->db->jdate($obj->datev);
738 $this->db->free($result);
767 $sql =
'SELECT rowid FROM '.MAIN_DB_PREFIX.
'entrepot';
768 $sql .=
' WHERE fk_parent='.(int) $id;
769 $sql .=
' ORDER BY rowid';
770 $resql = $this->db->query($sql);
771 if ($resql && $this->db->num_rows($resql) > 0) {
772 while ($obj = $this->db->fetch_object($resql)) {
773 $TChildWarehouse[] = $obj->rowid;
791 public $element =
'inventoryline';
796 public $table_element =
'inventorydet';
811 public $picto =
'stock';
834 public $fields = array(
835 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'visible' => -1,
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'index' => 1,
'comment' =>
'Id',),
836 'fk_inventory' => array(
'type' =>
'integer:Inventory:product/inventory/class/inventory.class.php',
'label' =>
'Inventory',
'visible' => 1,
'enabled' => 1,
'position' => 30,
'index' => 1,
'help' =>
'LinkToInventory'),
837 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Warehouse',
'visible' => 1,
'enabled' => 1,
'position' => 30,
'index' => 1,
'help' =>
'LinkToThirdparty'),
838 'fk_product' => array(
'type' =>
'integer:Product:product/class/product.class.php',
'label' =>
'Product',
'visible' => 1,
'enabled' => 1,
'position' => 32,
'index' => 1,
'help' =>
'LinkToProduct'),
839 'batch' => array(
'type' =>
'string',
'label' =>
'Batch',
'visible' => 1,
'enabled' => 1,
'position' => 32,
'index' => 1,
'help' =>
'LinkToProduct'),
840 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 500),
841 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 501),
842 '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)'),
843 'qty_view' => array(
'type' =>
'double',
'label' =>
'QtyBefore',
'visible' => 1,
'enabled' => 1,
'position' => 33,
'index' => 1,
'help' =>
'Qty before (filled once movements are validated)'),
844 '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)'),
845 'pmp_real' => array(
'type' =>
'double',
'label' =>
'PMPReal',
'visible' => 1,
'enabled' => 1,
'position' => 35),
846 'pmp_expected' => array(
'type' =>
'double',
'label' =>
'PMPExpected',
'visible' => 1,
'enabled' => 1,
'position' => 36),
854 public $fk_inventory;
855 public $fk_warehouse;
873 public $qty_regulated;
876 public $pmp_expected;
886 $this->ismultientitymanaged = 0;
888 $this->isextrafieldmanaged = 0;
909 public function fetch($id, $ref =
null)
935 public function delete(
User $user, $notrigger = 0)
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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.
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...
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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.