28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $element =
'inventory';
46 public $table_element =
'inventory';
51 public $ismultientitymanaged = 1;
56 public $isextrafieldmanaged = 0;
61 public $picto =
'inventory';
63 const STATUS_DRAFT = 0;
64 const STATUS_VALIDATED = 1;
65 const STATUS_RECORDED = 2;
66 const STATUS_CANCELED = 9;
98 public $fields = array(
99 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
100 'ref' => array(
'type'=>
'varchar(64)',
'label'=>
'Ref',
'visible'=>1,
'enabled'=>1,
'position'=>10,
'notnull'=>1,
'index'=>1,
'searchall'=>1,
'comment'=>
'Reference of object',
'css'=>
'maxwidth200'),
101 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
102 'title' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'visible'=>1,
'enabled'=>1,
'position'=>25,
'css'=>
'minwidth300',
'csslist'=>
'tdoverflowmax200'),
103 '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'=>
'tdoverflowmax200'),
104 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'InventoryForASpecificProduct',
'picto'=>
'product',
'css'=>
'minwidth300 maxwidth500 widthcentpercentminusx',
'csslist'=>
'tdoverflowmax200'),
105 'date_inventory' => array(
'type'=>
'date',
'label'=>
'DateValue',
'visible'=>1,
'enabled'=>
'$conf->global->STOCK_INVENTORY_ADD_A_VALUE_DATE',
'position'=>35),
106 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
107 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
108 'date_validation' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>502),
109 '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'=>
'tdoverflowmax200'),
110 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511,
'csslist'=>
'tdoverflowmax200'),
111 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>512,
'csslist'=>
'tdoverflowmax200'),
112 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000),
114 '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'))
135 public $fk_warehouse;
142 public $date_inventory;
153 public $date_creation;
158 public $date_validation;
166 public $fk_user_creat;
171 public $fk_user_modif;
176 public $fk_user_valid;
191 public $table_element_line =
'inventorydet';
196 public $fk_element =
'fk_inventory';
201 public $class_element_line =
'Inventoryline';
206 protected $childtables = array();
210 protected $childtablesoncascade = array(
'inventorydet');
215 public $lines = array();
230 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
231 $this->fields[
'rowid'][
'visible'] = 0;
233 if (empty($conf->multicompany->enabled)) {
234 $this->fields[
'entity'][
'enabled'] = 0;
267 if ($this->status == self::STATUS_DRAFT) {
269 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
272 $this->error = $this->
db->lasterror();
273 $this->
db->rollback();
278 $sql =
"SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,";
279 $sql .=
" pb.batch, pb.qty";
280 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
281 $sql .=
" LEFT JOIN ".$this->db->prefix().
"product_batch as pb ON pb.fk_product_stock = ps.rowid,";
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 (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
286 $sql .=
" AND p.fk_product_type = 0";
288 if ($this->fk_product > 0) {
289 $sql .=
" AND ps.fk_product = ".((int) $this->fk_product);
291 if ($this->fk_warehouse > 0) {
292 $sql .=
" AND ps.fk_entrepot = ".((int) $this->fk_warehouse);
303 $obj = $this->
db->fetch_object(
$resql);
305 $inventoryline->fk_inventory = $this->id;
306 $inventoryline->fk_warehouse = $obj->fk_warehouse;
307 $inventoryline->fk_product = $obj->fk_product;
308 $inventoryline->batch = $obj->batch;
309 $inventoryline->datec =
dol_now();
312 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel);
314 $inventoryline->qty_stock = $obj->reel;
317 $resultline = $inventoryline->create($user);
318 if ($resultline <= 0) {
319 $this->error = $inventoryline->error;
320 $this->errors = $inventoryline->errors;
329 $this->error = $this->
db->lasterror();
334 $result = $this->
setStatut($this::STATUS_VALIDATED, null,
'',
'INVENTORY_VALIDATED');
340 $this->
db->rollback();
357 $sql =
'DELETE FROM '.$this->db->prefix().
'inventorydet WHERE fk_inventory = '.((int) $this->
id);
360 $this->error = $this->
db->lasterror();
361 $this->
db->rollback();
365 $result = $this->
setStatut($this::STATUS_DRAFT, null,
'',
'INVENTORY_DRAFT');
370 $this->
db->rollback();
386 $result = $this->
setStatut($this::STATUS_RECORDED, null,
'',
'INVENTORY_RECORDED');
391 $this->
db->rollback();
408 $result = $this->
setStatut($this::STATUS_CANCELED, null,
'',
'INVENTORY_CANCELED');
413 $this->
db->rollback();
428 global $hookmanager, $langs;
433 $object =
new self($this->db);
438 $object->fetchCommon($fromid);
441 unset($object->fk_user_creat);
442 unset($object->import_key);
445 $object->ref =
"copy_of_".$object->ref;
446 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
450 $object->context[
'createfromclone'] =
'createfromclone';
451 $result = $object->createCommon($user);
454 $this->error = $object->error;
455 $this->errors = $object->errors;
458 unset($object->context[
'createfromclone']);
465 $this->
db->rollback();
477 public function fetch($id, $ref = null)
517 public function delete(
User $user, $notrigger =
false)
532 if ($this->status < 0) {
533 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
550 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
552 global $db, $conf, $langs;
553 global $dolibarr_main_authentication, $dolibarr_main_demo;
556 if (!empty($conf->dol_no_mouse_hover)) {
563 $label =
'<u>'.$langs->trans(
"Inventory").
'</u>';
565 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
567 $url =
dol_buildpath(
'/product/inventory/card.php', 1).
'?id='.$this->id;
570 if (empty($notooltip)) {
571 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
572 $label = $langs->trans(
"ShowInventory");
573 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
575 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
576 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
578 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
581 $linkstart =
'<a href="'.$url.
'"';
582 $linkstart .= $linkclose.
'>';
585 $result .= $linkstart;
587 $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);
589 if ($withpicto != 2) {
590 $result .= $this->ref;
606 return $this->
LibStatut($this->status, $mode);
622 $labelStatus = array();
623 $labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
624 $labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated').
' ('.$langs->transnoentitiesnoconv(
'InventoryStartedShort').
')';
625 $labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
626 $labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
627 $labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
628 $labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'InventoryStartedShort');
629 $labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
630 $labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv(
'Closed');
632 $statusType =
'status'.$status;
633 if ($status == self::STATUS_RECORDED) {
634 $statusType =
'status6';
637 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'', $statusType, $mode);
648 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,";
649 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
650 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
651 $sql .=
" WHERE t.rowid = ".((int) $id);
652 $result = $this->
db->query($sql);
654 if ($this->
db->num_rows($result)) {
655 $obj = $this->
db->fetch_object($result);
657 $this->
id = $obj->rowid;
659 if ($obj->fk_user_creat > 0) {
660 $cuser =
new User($this->
db);
661 $cuser->fetch($obj->fk_user_creat);
662 $this->user_creation = $cuser;
665 if ($obj->fk_user_modif > 0) {
666 $muser =
new User($this->
db);
667 $muser->fetch($obj->fk_user_modif);
668 $this->user_creation = $muser;
671 if ($obj->fk_user_valid > 0) {
672 $vuser =
new User($this->
db);
673 $vuser->fetch($obj->fk_user_valid);
674 $this->user_validation = $vuser;
677 $this->date_creation = $this->
db->jdate($obj->datec);
678 $this->date_modification = $this->
db->jdate($obj->datem);
679 $this->date_validation = $this->
db->jdate($obj->datev);
682 $this->
db->free($result);
709 public $element =
'inventoryline';
714 public $table_element =
'inventorydet';
719 public $ismultientitymanaged = 0;
724 public $isextrafieldmanaged = 0;
729 public $picto =
'stock';
752 public $fields = array(
753 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
754 'fk_inventory' => array(
'type'=>
'integer:Inventory:product/inventory/class/inventory.class.php',
'label'=>
'Inventory',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToInventory'),
755 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToThirparty'),
756 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
757 'batch' => array(
'type'=>
'string',
'label'=>
'Batch',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
758 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
759 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
760 '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)'),
761 'qty_view' => array(
'type'=>
'double',
'label'=>
'QtyBefore',
'visible'=>1,
'enabled'=>1,
'position'=>33,
'index'=>1,
'help'=>
'Qty before (filled once movements are validated)'),
762 '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)'),
763 'pmp_real' => array(
'type'=>
'double',
'label'=>
'PMPReal',
'visible'=>1,
'enabled'=>1,
'position'=>35),
764 'pmp_expected' => array(
'type'=>
'double',
'label'=>
'PMPExpected',
'visible'=>1,
'enabled'=>1,
'position'=>36),
772 public $fk_inventory;
773 public $fk_warehouse;
780 public $qty_regulated;
782 public $pmp_expected;
804 public function fetch($id, $ref = null)
830 public function delete(
User $user, $notrigger =
false)
setDraft(User $user, $notrigger=false)
Go back to draft.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getLibStatut($mode=0)
Retourne le libelle du status d'un user (actif, inactif)
info($id)
Charge les informations d'ordre info dans l'objet commande.
setCanceled(User $user, $notrigger=false)
Set to Canceled.
__construct(DoliDB $db)
Constructor.
$conf db
API class for accounts.
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object into database.
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createFromClone(User $user, $fromid)
Clone and object into another one.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
createCommon(User $user, $notrigger=false)
Create object into database.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
validate(User $user, $notrigger=false)
Validate inventory (start it)
fetch($id, $ref=null)
Load object in memory from the database.
create(User $user, $notrigger=false)
Create object in database.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
update(User $user, $notrigger=false)
Load object lines in memory from the database.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
updateCommon(User $user, $notrigger=false)
Update object into database.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
static LibStatut($status, $mode=0)
Return the status.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
update(User $user, $notrigger=false)
Update object into database.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
setStatut($status, $elementId=null, $elementType= '', $trigkey= '', $fieldstatus= 'fk_statut')
Set status of an object.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.
setRecorded(User $user, $notrigger=false)
Set to inventory to status "Closed".