28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
42 public $element =
'inventory';
47 public $table_element =
'inventory';
52 public $ismultientitymanaged = 1;
57 public $isextrafieldmanaged = 0;
62 public $picto =
'inventory';
64 const STATUS_DRAFT = 0;
65 const STATUS_VALIDATED = 1;
66 const STATUS_RECORDED = 2;
67 const STATUS_CANCELED = 9;
99 public $fields = array(
100 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
101 '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'),
102 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
103 'title' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'visible'=>1,
'enabled'=>1,
'position'=>25,
'css'=>
'minwidth300',
'csslist'=>
'tdoverflowmax150'),
104 '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'),
105 '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'),
106 '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'),
107 'date_inventory' => array(
'type'=>
'date',
'label'=>
'DateValue',
'visible'=>1,
'enabled'=>
'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE',
'position'=>35,
'csslist'=>
'nowraponall'),
108 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500,
'csslist'=>
'nowraponall'),
109 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501,
'csslist'=>
'nowraponall'),
110 'date_validation' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>502,
'csslist'=>
'nowraponall'),
111 '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'),
112 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511,
'csslist'=>
'tdoverflowmax150'),
113 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>512,
'csslist'=>
'tdoverflowmax150'),
114 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000),
115 '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'))
136 public $fk_warehouse;
146 public $categories_product;
147 public $date_inventory;
158 public $date_creation;
163 public $date_validation;
169 public $fk_user_creat;
174 public $fk_user_modif;
179 public $fk_user_valid;
194 public $table_element_line =
'inventorydet';
199 public $fk_element =
'fk_inventory';
204 public $class_element_line =
'Inventoryline';
209 protected $childtables = array();
213 protected $childtablesoncascade = array(
'inventorydet');
218 public $lines = array();
233 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
234 $this->fields[
'rowid'][
'visible'] = 0;
236 if (!isModEnabled(
'multicompany')) {
237 $this->fields[
'entity'][
'enabled'] = 0;
270 if ($this->status == self::STATUS_DRAFT) {
272 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
273 $resql = $this->db->query($sql);
275 $this->error = $this->db->lasterror();
276 $this->db->rollback();
281 $sql =
"SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
282 $sql .=
" pb.batch, pb.qty";
283 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
284 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_batch as pb ON pb.fk_product_stock = ps.rowid,";
285 $sql .=
" ".$this->db->prefix().
"product as p, ".$this->db->prefix().
"entrepot as e";
286 $sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
287 $sql .=
" AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid";
288 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
289 $sql .=
" AND p.fk_product_type = 0";
291 if ($this->fk_product > 0) {
292 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
294 if ($this->fk_warehouse > 0) {
295 $sql .=
" AND ps.fk_entrepot = ".((int) $this->fk_warehouse);
297 if (!empty($this->categories_product)) {
298 $sql .=
" AND EXISTS (";
299 $sql .=
" SELECT cp.fk_product";
300 $sql .=
" FROM ".$this->db->prefix().
"categorie_product AS cp";
301 $sql .=
" WHERE cp.fk_product = ps.fk_product";
302 $sql .=
" AND cp.fk_categorie IN (".$this->db->sanitize($this->categories_product).
")";
308 $resql = $this->db->query($sql);
310 $num = $this->db->num_rows($resql);
314 $obj = $this->db->fetch_object($resql);
316 $inventoryline->fk_inventory = $this->id;
317 $inventoryline->fk_warehouse = $obj->fk_warehouse;
318 $inventoryline->fk_product = $obj->fk_product;
319 $inventoryline->batch = $obj->batch;
320 $inventoryline->datec =
dol_now();
322 if (isModEnabled(
'productbatch')) {
323 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel);
325 $inventoryline->qty_stock = $obj->reel;
328 $resultline = $inventoryline->create($user);
329 if ($resultline <= 0) {
330 $this->error = $inventoryline->error;
331 $this->errors = $inventoryline->errors;
340 $this->error = $this->db->lasterror();
345 $result = $this->
setStatut($this::STATUS_VALIDATED,
null,
'',
'INVENTORY_VALIDATED');
351 $this->db->rollback();
368 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
369 $resql = $this->db->query($sql);
371 $this->error = $this->db->lasterror();
372 $this->db->rollback();
376 $result = $this->
setStatut($this::STATUS_DRAFT,
null,
'',
'INVENTORY_DRAFT');
381 $this->db->rollback();
397 $result = $this->
setStatut($this::STATUS_RECORDED,
null,
'',
'INVENTORY_RECORDED');
402 $this->db->rollback();
419 $result = $this->
setStatut($this::STATUS_CANCELED,
null,
'',
'INVENTORY_CANCELED');
424 $this->db->rollback();
439 global $hookmanager, $langs;
444 $object =
new self($this->db);
449 $object->fetchCommon($fromid);
452 unset($object->fk_user_creat);
453 unset($object->import_key);
456 $object->ref =
"copy_of_".$object->ref;
457 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
461 $object->context[
'createfromclone'] =
'createfromclone';
462 $result = $object->createCommon($user);
465 $this->error = $object->error;
466 $this->errors = $object->errors;
469 unset($object->context[
'createfromclone']);
476 $this->db->rollback();
488 public function fetch($id, $ref =
null)
528 public function delete(
User $user, $notrigger =
false)
543 if ($this->status < 0) {
544 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
561 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
563 global $db, $conf, $langs;
564 global $dolibarr_main_authentication, $dolibarr_main_demo;
567 if (!empty($conf->dol_no_mouse_hover)) {
574 $label =
'<u>'.$langs->trans(
"Inventory").
'</u>';
576 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
578 $url =
dol_buildpath(
'/product/inventory/card.php', 1).
'?id='.$this->id;
581 if (empty($notooltip)) {
582 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
583 $label = $langs->trans(
"ShowInventory");
584 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
586 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
587 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
589 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
592 $linkstart =
'<a href="'.$url.
'"';
593 $linkstart .= $linkclose.
'>';
596 $result .= $linkstart;
598 $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);
600 if ($withpicto != 2) {
601 $result .= $this->ref;
617 return $this->
LibStatut($this->status, $mode);
633 $labelStatus = array();
634 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
635 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated').
' ('.$langs->transnoentitiesnoconv(
'InventoryStartedShort').
')';
636 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
637 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
638 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
639 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'InventoryStartedShort');
640 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
641 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
643 $statusType =
'status'.$status;
644 if ($status == self::STATUS_RECORDED) {
645 $statusType =
'status6';
648 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode);
660 global $conf, $langs;
662 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
664 $return =
'<div class="box-flex-item box-flex-grow-zero">';
665 $return .=
'<div class="info-box info-box-sm">';
666 $return .=
'<span class="info-box-icon bg-infobox-action">';
668 $return .=
'</span>';
669 $return .=
'<div class="info-box-content">';
670 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
671 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
672 if (property_exists($this,
'label')) {
673 $return .=
' <div class="inline-block opacitymedium valignmiddle tdoverflowmax100">'.$this->label.
'</div>';
675 if (property_exists($this,
'amount')) {
677 $return .=
'<span class="info-box-label amount">'.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency).
'</span>';
679 if (method_exists($this,
'getLibStatut')) {
680 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
697 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
698 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
699 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
700 $sql .=
" WHERE t.rowid = ".((int) $id);
701 $result = $this->db->query($sql);
703 if ($this->db->num_rows($result)) {
704 $obj = $this->db->fetch_object($result);
706 $this->
id = $obj->rowid;
708 if ($obj->fk_user_creat > 0) {
709 $cuser =
new User($this->db);
710 $cuser->fetch($obj->fk_user_creat);
711 $this->user_creation = $cuser;
714 if ($obj->fk_user_modif > 0) {
715 $muser =
new User($this->db);
716 $muser->fetch($obj->fk_user_modif);
717 $this->user_creation = $muser;
720 if ($obj->fk_user_valid > 0) {
721 $vuser =
new User($this->db);
722 $vuser->fetch($obj->fk_user_valid);
723 $this->user_validation = $vuser;
726 $this->date_creation = $this->db->jdate($obj->datec);
727 $this->date_modification = $this->db->jdate($obj->datem);
728 $this->date_validation = $this->db->jdate($obj->datev);
731 $this->db->free($result);
758 public $element =
'inventoryline';
763 public $table_element =
'inventorydet';
768 public $ismultientitymanaged = 0;
773 public $isextrafieldmanaged = 0;
778 public $picto =
'stock';
801 public $fields = array(
802 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
803 'fk_inventory' => array(
'type'=>
'integer:Inventory:product/inventory/class/inventory.class.php',
'label'=>
'Inventory',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToInventory'),
804 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToThirdparty'),
805 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
806 'batch' => array(
'type'=>
'string',
'label'=>
'Batch',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
807 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
808 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
809 '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)'),
810 'qty_view' => array(
'type'=>
'double',
'label'=>
'QtyBefore',
'visible'=>1,
'enabled'=>1,
'position'=>33,
'index'=>1,
'help'=>
'Qty before (filled once movements are validated)'),
811 'qty_regulated' => array(
'type'=>
'double',
'label'=>
'QtyDelta',
'visible'=>1,
'enabled'=>1,
'position'=>34,
'index'=>1,
'help'=>
'Qty aadded or removed (filled once movements are validated)'),
812 'pmp_real' => array(
'type'=>
'double',
'label'=>
'PMPReal',
'visible'=>1,
'enabled'=>1,
'position'=>35),
813 'pmp_expected' => array(
'type'=>
'double',
'label'=>
'PMPExpected',
'visible'=>1,
'enabled'=>1,
'position'=>36),
821 public $fk_inventory;
822 public $fk_warehouse;
829 public $qty_regulated;
831 public $pmp_expected;
853 public function fetch($id, $ref =
null)
879 public function delete(
User $user, $notrigger =
false)
Parent class of all other business classes (invoices, contracts, proposals, orders,...
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into 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 optionaly the picto)
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
create(User $user, $notrigger=false)
Create object into database.
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 informations d'ordre info dans l'objet commande.
validate(User $user, $notrigger=false)
Validate inventory (start it)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
fetch($id, $ref=null)
Load object in memory from the database.
setDraft(User $user, $notrigger=false)
Go back to draft.
static LibStatut($status, $mode=0)
Return the status.
setRecorded(User $user, $notrigger=false)
Set to inventory to status "Closed".
update(User $user, $notrigger=false)
Load object lines in memory from the database.
createFromClone(User $user, $fromid)
Clone and object into another one.
setCanceled(User $user, $notrigger=false)
Set to Canceled.
update(User $user, $notrigger=false)
Update object into database.
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object in database.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.