28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'inventory';
45 public $table_element =
'inventory';
50 public $ismultientitymanaged = 1;
55 public $isextrafieldmanaged = 1;
60 public $picto =
'stock';
62 const STATUS_DRAFT = 0;
63 const STATUS_VALIDATED = 1;
64 const STATUS_RECORDED = 2;
65 const STATUS_CANCELED = 9;
92 public $fields = array(
93 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
94 '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'),
95 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>20,
'notnull'=>1,
'index'=>1,),
96 'title' => array(
'type'=>
'varchar(255)',
'label'=>
'Label',
'visible'=>1,
'enabled'=>1,
'position'=>25,
'css'=>
'minwidth300'),
97 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'InventoryForASpecificWarehouse'),
98 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'InventoryForASpecificProduct'),
99 'date_inventory' => array(
'type'=>
'date',
'label'=>
'DateValue',
'visible'=>1,
'enabled'=>1,
'position'=>35),
101 'date_creation' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
102 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
103 'date_validation' => array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>502),
104 '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'),
105 'fk_user_modif' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>511),
106 'fk_user_valid' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'visible'=>-2,
'enabled'=>1,
'position'=>512),
107 'import_key' => array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'index'=>0,
'position'=>1000),
109 '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=>
'Recorded', 9=>
'Canceled'))
130 public $fk_warehouse;
137 public $date_inventory;
148 public $date_creation;
153 public $date_validation;
161 public $fk_user_creat;
166 public $fk_user_modif;
171 public $fk_user_valid;
186 public $table_element_line =
'inventorydet';
191 public $fk_element =
'fk_inventory';
196 public $class_element_line =
'Inventoryline';
201 protected $childtables = array();
205 protected $childtablesoncascade = array(
'inventorydet');
210 public $lines = array();
225 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->
fields[
'rowid'][
'visible'] = 0;
226 if (empty($conf->multicompany->enabled)) $this->
fields[
'entity'][
'enabled'] = 0;
257 if ($this->status == self::STATUS_DRAFT) {
259 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'inventorydet WHERE fk_inventory = '.$this->id;
262 $this->error = $this->
db->lasterror();
263 $this->
db->rollback();
268 $sql =
'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,';
269 $sql .=
' pb.batch, pb.qty';
270 $sql .=
' FROM '.MAIN_DB_PREFIX.
'product_stock as ps';
271 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_batch as pb ON pb.fk_product_stock = ps.rowid,';
272 $sql .=
' '.MAIN_DB_PREFIX.
'product as p, '.MAIN_DB_PREFIX.
'entrepot as e';
273 $sql .=
' WHERE p.entity IN ('.getEntity(
'product').
')';
274 $sql .=
' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid';
275 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .=
" AND p.fk_product_type = 0";
276 if ($this->fk_product > 0) $sql .=
' AND ps.fk_product = '.$this->fk_product;
277 if ($this->fk_warehouse > 0) $sql .=
' AND ps.fk_entrepot = '.$this->fk_warehouse;
289 $obj = $this->
db->fetch_object(
$resql);
291 $inventoryline->fk_inventory = $this->id;
292 $inventoryline->fk_warehouse = $obj->fk_warehouse;
293 $inventoryline->fk_product = $obj->fk_product;
294 $inventoryline->batch = $obj->batch;
295 $inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel);
296 $inventoryline->datec =
dol_now();
298 $resultline = $inventoryline->create($user);
299 if ($resultline <= 0) {
300 $this->error = $inventoryline->error;
301 $this->errors = $inventoryline->errors;
310 $this->error = $this->
db->lasterror();
315 $result = $this->
setStatut($this::STATUS_VALIDATED, null,
'',
'INVENTORY_VALIDATED');
321 $this->
db->rollback();
337 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'inventorydet WHERE fk_inventory = '.$this->id;
340 $this->error = $this->
db->lasterror();
341 $this->
db->rollback();
345 $result = $this->
setStatut($this::STATUS_DRAFT, null,
'',
'INVENTORY_DRAFT');
350 $this->
db->rollback();
363 global $hookmanager, $langs;
368 $object =
new self($this->db);
373 $object->fetchCommon($fromid);
376 unset($object->fk_user_creat);
377 unset($object->import_key);
380 $object->ref =
"copy_of_".$object->ref;
381 $object->title = $langs->trans(
"CopyOf").
" ".$object->title;
385 $object->context[
'createfromclone'] =
'createfromclone';
386 $result = $object->createCommon($user);
389 $this->error = $object->error;
390 $this->errors = $object->errors;
393 unset($object->context[
'createfromclone']);
400 $this->
db->rollback();
412 public function fetch($id, $ref = null)
452 public function delete(
User $user, $notrigger =
false)
467 if ($this->status < 0)
469 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
486 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
488 global $db, $conf, $langs;
489 global $dolibarr_main_authentication, $dolibarr_main_demo;
492 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
497 $label =
'<u>'.$langs->trans(
"Inventory").
'</u>';
499 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
501 $url =
dol_buildpath(
'/product/inventory/card.php', 1).
'?id='.$this->id;
504 if (empty($notooltip))
506 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
508 $label = $langs->trans(
"ShowInventory");
509 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
511 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
512 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
513 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
515 $linkstart =
'<a href="'.$url.
'"';
516 $linkstart .= $linkclose.
'>';
519 $result .= $linkstart;
520 if ($withpicto) $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);
521 if ($withpicto != 2) $result .= $this->ref;
536 return $this->
LibStatut($this->status, $mode);
552 $labelStatus = array();
553 $labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Draft');
554 $labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Validated').
' ('.$langs->trans(
'Started').
')';
555 $labelStatus[self::STATUS_CANCELED] = $langs->trans(
'Canceled');
556 $labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Draft');
557 $labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Started');
558 $labelStatusShort[self::STATUS_CANCELED] = $langs->trans(
'Canceled');
560 return dolGetStatus($labelStatus[$status], $labelStatusShort[$status],
'',
'status'.$status, $mode);
571 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
572 $sql .=
' fk_user_creat, fk_user_modif';
573 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
574 $sql .=
' WHERE t.rowid = '.$id;
575 $result = $this->
db->query($sql);
578 if ($this->
db->num_rows($result))
580 $obj = $this->
db->fetch_object($result);
581 $this->
id = $obj->rowid;
582 if ($obj->fk_user_author)
584 $cuser =
new User($this->
db);
585 $cuser->fetch($obj->fk_user_author);
586 $this->user_creation = $cuser;
589 if ($obj->fk_user_valid)
591 $vuser =
new User($this->
db);
592 $vuser->fetch($obj->fk_user_valid);
593 $this->user_validation = $vuser;
596 if ($obj->fk_user_cloture)
598 $cluser =
new User($this->
db);
599 $cluser->fetch($obj->fk_user_cloture);
600 $this->user_cloture = $cluser;
603 $this->date_creation = $this->
db->jdate($obj->datec);
604 $this->date_modification = $this->
db->jdate($obj->datem);
605 $this->date_validation = $this->
db->jdate($obj->datev);
608 $this->
db->free($result);
634 public $element =
'inventoryline';
639 public $table_element =
'inventorydet';
644 public $ismultientitymanaged = 0;
649 public $isextrafieldmanaged = 0;
654 public $picto =
'stock';
677 public $fields = array(
678 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-1,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
'Id',),
679 'fk_inventory' => array(
'type'=>
'integer:Inventory:product/inventory/class/inventory.class.php',
'label'=>
'Inventory',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToInventory'),
680 'fk_warehouse' => array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label'=>
'Warehouse',
'visible'=>1,
'enabled'=>1,
'position'=>30,
'index'=>1,
'help'=>
'LinkToThirparty'),
681 'fk_product' => array(
'type'=>
'integer:Product:product/class/product.class.php',
'label'=>
'Product',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
682 'batch' => array(
'type'=>
'string',
'label'=>
'Batch',
'visible'=>1,
'enabled'=>1,
'position'=>32,
'index'=>1,
'help'=>
'LinkToProduct'),
683 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>500),
684 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>501),
685 '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)'),
686 'qty_view' => array(
'type'=>
'double',
'label'=>
'QtyBefore',
'visible'=>1,
'enabled'=>1,
'position'=>33,
'index'=>1,
'help'=>
'Qty before (filled once movements are validated)'),
687 '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)'),
695 public $fk_inventory;
696 public $fk_warehouse;
703 public $qty_regulated;
725 public function fetch($id, $ref = null)
751 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.
__construct(DoliDB $db)
Constructor.
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.
foreach($object->fields as $key=> $val) if(is_array($extrafields->attributes[$object->table_element]['label'])&&count($extrafields->attributes[$object->table_element]['label']) > 0) $object fields
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.
$conf db
API class for accounts.
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.
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.
setStatut($status, $elementId=null, $elementType= '', $trigkey= '')
Set status of an object.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchCommon($id, $ref=null, $morewhere= '')
Load object in memory from the database.