29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'stock';
45 public $table_element =
'entrepot';
50 public $picto =
'stock';
55 public $ismultientitymanaged = 1;
114 public $statuts = array();
119 public $fields = array(
120 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>10),
121 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'notnull'=>1,
'index'=>1,
'position'=>15),
122 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>25,
'searchall'=>1),
123 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>30),
124 'description' =>array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-2,
'position'=>35,
'searchall'=>1),
125 'lieu' =>array(
'type'=>
'varchar(64)',
'label'=>
'LocationSummary',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'showoncombobox'=>1,
'searchall'=>1),
126 'fk_parent' =>array(
'type'=>
'integer:Entrepot:product/stock/class/entrepot.class.php:1:statut=1 AND entity IN (__SHARED_ENTITIES__)',
'label'=>
'ParentWarehouse',
'enabled'=>1,
'visible'=>-2,
'position'=>41),
127 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-2,
'position'=>45,
'searchall'=>1),
128 'zip' =>array(
'type'=>
'varchar(10)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-2,
'position'=>50,
'searchall'=>1),
129 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-2,
'position'=>55,
'searchall'=>1),
130 'fk_departement' =>array(
'type'=>
'sellist:c_departements:label:rowid::active=1',
'label'=>
'State',
'enabled'=>1,
'visible'=>0,
'position'=>60),
131 'fk_pays' =>array(
'type'=>
'sellist:c_country:label:rowid::active=1',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-2,
'position'=>65),
132 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-2,
'position'=>70,
'searchall'=>1),
133 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-2,
'position'=>75,
'searchall'=>1),
135 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300),
136 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>301),
139 'statut' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'position'=>500),
168 $this->statuts[self::STATUS_CLOSED] =
'Closed2';
169 if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
170 $this->statuts[self::STATUS_OPEN_ALL] =
'OpenAll';
171 $this->statuts[self::STATUS_OPEN_INTERNAL] =
'OpenInternal';
173 $this->statuts[self::STATUS_OPEN_ALL] =
'Opened';
189 $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
192 if ($this->label ==
'') {
193 $this->error =
"ErrorFieldRequired";
201 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"entrepot (ref, entity, datec, fk_user_author, fk_parent)";
202 $sql .=
" VALUES ('".$this->db->escape($this->label).
"', ".$conf->entity.
", '".$this->
db->idate($now).
"', ".$user->id.
", ".($this->fk_parent > 0 ? $this->fk_parent :
"NULL").
")";
204 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
205 $result = $this->
db->query($sql);
208 $id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"entrepot");
215 $result = $this->
update($id, $user);
240 dol_syslog(get_class($this).
"::create return -3");
241 $this->
db->rollback();
245 $this->error =
"Failed to get insert id";
246 dol_syslog(get_class($this).
"::create return -2");
250 $this->error = $this->
db->error();
251 dol_syslog(get_class($this).
"::create Error ".$this->
db->error());
252 $this->
db->rollback();
270 if (empty($id)) $id = $this->id;
271 if (empty($this->label)) $this->label = $this->libelle;
274 if (!empty($this->fk_parent))
276 $TChildWarehouses = array($id);
278 if (in_array($this->fk_parent, $TChildWarehouses))
280 $this->error =
'ErrorCannotAddThisParentWarehouse';
285 $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
289 $this->lieu = trim($this->lieu);
291 $this->address = trim($this->address);
292 $this->zip = trim($this->zip);
293 $this->town = trim($this->town);
294 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
296 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"entrepot ";
297 $sql .=
" SET ref = '".$this->db->escape($this->label).
"'";
298 $sql .=
", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent :
"NULL");
299 $sql .=
", description = '".$this->db->escape($this->
description).
"'";
300 $sql .=
", statut = ".$this->statut;
301 $sql .=
", lieu = '".$this->db->escape($this->lieu).
"'";
302 $sql .=
", address = '".$this->db->escape($this->address).
"'";
303 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
304 $sql .=
", town = '".$this->db->escape($this->town).
"'";
305 $sql .=
", fk_pays = ".$this->country_id;
306 $sql .=
", phone = '".$this->db->escape($this->phone).
"'";
307 $sql .=
", fax = '".$this->db->escape($this->fax).
"'";
308 $sql .=
" WHERE rowid = ".$id;
312 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
317 $this->errors[] =
"Error ".$this->db->lasterror();
332 $this->
db->rollback();
333 $this->error = $this->
db->lasterror();
346 public function delete($user, $notrigger = 0)
352 dol_syslog(get_class($this).
"::delete id=".$this->
id, LOG_DEBUG);
356 if (!$error && empty($notrigger))
359 $result = $this->
call_trigger(
'WAREHOUSE_DELETE', $user);
360 if ($result < 0) { $error++; }
364 $elements = array(
'stock_mouvement',
'product_stock',
'product_warehouse_properties');
365 foreach ($elements as $table)
369 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$table;
370 $sql .=
" WHERE fk_entrepot = ".$this->id;
372 $result = $this->
db->query($sql);
376 $this->errors[] = $this->
db->lasterror();
390 dol_syslog(get_class($this).
"::delete Error ".$this->error, LOG_ERR);
397 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"entrepot";
398 $sql .=
" WHERE rowid = ".$this->id;
399 $resql1 = $this->
db->query($sql);
403 $this->errors[] = $this->
db->lasterror();
404 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
411 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX.
"product_stock as ps WHERE ps.fk_product = p.rowid)";
412 $resql2 = $this->
db->query($sql);
416 $this->errors[] = $this->
db->lasterror();
417 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
426 $this->
db->rollback();
439 public function fetch($id, $ref =
'')
443 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref=".$ref);
448 $this->error =
'ErrorWrongParameters';
449 dol_syslog(get_class($this).
"::fetch ".$this->error);
453 $sql =
"SELECT rowid, entity, fk_parent, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
454 $sql .=
" model_pdf, import_key";
455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"entrepot";
458 $sql .=
" WHERE rowid = '".$id.
"'";
460 $sql .=
" WHERE entity = ".$conf->entity;
461 if ($ref) $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
464 $result = $this->
db->query($sql);
467 if ($this->
db->num_rows($result) > 0)
469 $obj = $this->
db->fetch_object($result);
471 $this->
id = $obj->rowid;
472 $this->entity = $obj->entity;
473 $this->fk_parent = $obj->fk_parent;
474 $this->ref = $obj->label;
475 $this->label = $obj->label;
476 $this->libelle = $obj->label;
478 $this->
statut = $obj->statut;
479 $this->lieu = $obj->lieu;
480 $this->address = $obj->address;
481 $this->zip = $obj->zip;
482 $this->town = $obj->town;
483 $this->country_id = $obj->country_id;
484 $this->phone = $obj->phone;
485 $this->fax = $obj->fax;
487 $this->model_pdf = $obj->model_pdf;
488 $this->import_key = $obj->import_key;
494 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
496 $this->country = $tmp[
'label'];
497 $this->country_code = $tmp[
'code'];
501 $this->error =
"Record Not Found";
505 $this->error = $this->
db->error();
519 $sql =
"SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
520 $sql .=
" FROM ".MAIN_DB_PREFIX.
"entrepot as e";
521 $sql .=
" WHERE e.rowid = ".$id;
523 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
524 $result = $this->
db->query($sql);
527 if ($this->
db->num_rows($result))
529 $obj = $this->
db->fetch_object($result);
531 $this->
id = $obj->rowid;
533 if ($obj->fk_user_author) {
534 $cuser =
new User($this->
db);
535 $cuser->fetch($obj->fk_user_author);
536 $this->user_creation = $cuser;
539 if ($obj->fk_user_valid) {
540 $vuser =
new User($this->
db);
541 $vuser->fetch($obj->fk_user_valid);
542 $this->user_validation = $vuser;
545 $this->date_creation = $this->
db->jdate($obj->datec);
546 $this->date_modification = $this->
db->jdate($obj->datem);
549 $this->
db->free($result);
568 $sql =
"SELECT rowid, ref as label";
569 $sql .=
" FROM ".MAIN_DB_PREFIX.
"entrepot";
570 $sql .=
" WHERE entity IN (".getEntity(
'stock').
")";
571 $sql .=
" AND statut = ".$status;
573 $result = $this->
db->query($sql);
575 $num = $this->
db->num_rows($result);
580 $row = $this->
db->fetch_row($result);
581 $liste[$row[0]] = $row[1];
584 $this->
db->free($result);
600 $sql =
"SELECT count(distinct p.rowid) as nb";
601 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
602 $sql .=
", ".MAIN_DB_PREFIX.
"product as p";
603 $sql .=
" WHERE ps.fk_entrepot = ".$this->id;
604 $sql .=
" AND ps.fk_product = p.rowid";
607 $result = $this->
db->query($sql);
610 $obj = $this->
db->fetch_object($result);
611 $ret[
'nb'] = $obj->nb;
612 $this->
db->free($result);
614 $this->error = $this->
db->lasterror();
632 $sql =
"SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
633 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
634 $sql .=
", ".MAIN_DB_PREFIX.
"product as p";
635 $sql .=
" WHERE ps.fk_entrepot = ".$this->id;
636 $sql .=
" AND ps.fk_product = p.rowid";
639 $result = $this->
db->query($sql);
642 $obj = $this->
db->fetch_object($result);
643 $ret[
'nb'] = $obj->nb;
644 $ret[
'value'] = $obj->value;
645 $this->
db->free($result);
647 $this->error = $this->
db->lasterror();
678 $statusType =
'status5';
679 if ($status > 0) $statusType =
'status4';
681 $langs->load(
'stocks');
682 $label = $langs->trans($this->statuts[$status]);
683 $labelshort = $langs->trans($this->statuts[$status]);
685 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
698 public function getNomUrl($withpicto = 0, $option =
'', $showfullpath = 0, $notooltip = 0)
700 global $conf, $langs, $hookmanager;
701 $langs->load(
"stocks");
703 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
705 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) $withpicto = 0;
709 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Warehouse").
'</u>';
710 if (isset($this->
statut)) {
711 $label .=
' '.$this->getLibStatut(5);
713 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.(empty($this->ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->ref);
714 if (!empty($this->lieu)) {
715 $label .=
'<br><b>'.$langs->trans(
'LocationSummary').
':</b> '.$this->lieu;
718 $url = DOL_URL_ROOT.
'/product/stock/card.php?id='.$this->id;
721 if (empty($notooltip))
723 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
725 $label = $langs->trans(
"Warehouse");
726 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
728 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
729 $linkclose .=
' class="classfortooltip"';
732 $linkstart =
'<a href="'.$url.
'"';
733 $linkstart .= $linkclose.
'>';
736 $result .= $linkstart;
737 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);
738 if ($withpicto != 2) $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->
get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
742 $hookmanager->initHooks(array(
'warehousedao'));
743 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result,
'withpicto' => $withpicto,
'option' => $option,
'showfullpath' => $showfullpath,
'notooltip'=> $notooltip);
744 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
746 $result = $hookmanager->resPrint;
748 $result .= $hookmanager->resPrint;
763 global $user, $langs, $conf, $mysoc;
769 $this->label =
'WAREHOUSE SPECIMEN';
770 $this->
description =
'WAREHOUSE SPECIMEN '.dol_print_date($now,
'dayhourlog');
774 $this->lieu =
'Location test';
775 $this->address =
'21 jump street';
776 $this->zip =
'99999';
777 $this->town =
'MyTown';
778 $this->country_id = 1;
779 $this->country_code =
'FR';
791 global $user, $langs, $conf;
793 $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
799 $parentid = $this->fk_parent;
801 while ($parentid > 0 && $i < $protection)
803 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'entrepot WHERE rowid = '.$parentid;
807 $objarbo = $this->
db->fetch_object(
$resql);
810 $warehousetmp->fetch($parentid);
811 $TArbo[] = $warehousetmp->label;
812 $parentid = $objarbo->fk_parent;
819 return implode(
' >> ', array_reverse($TArbo));
835 FROM '.MAIN_DB_PREFIX.
'entrepot
836 WHERE fk_parent = '.$id;
840 while ($res = $this->
db->fetch_object(
$resql)) {
841 $TChildWarehouses[] = $res->rowid;
846 return $TChildWarehouses;
859 public function generateDocument($modele, $outputlangs =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
861 global $conf, $user, $langs;
863 $langs->load(
"stocks");
864 $outputlangs->load(
"products");
867 $modele =
'standard';
869 if ($this->model_pdf) {
870 $modele = $this->model_pdf;
871 } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
872 $modele = $conf->global->STOCK_ADDON_PDF;
876 $modelpath =
"core/modules/stock/doc/";
878 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
893 $type_categ = Categorie::TYPE_WAREHOUSE;
896 if (!is_array($categories)) {
897 $categories = array($categories);
901 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
903 $existing = $c->containing($this->
id, $type_categ,
'id');
906 if (is_array($existing)) {
907 $to_del = array_diff($existing, $categories);
908 $to_add = array_diff($categories, $existing);
911 $to_add = $categories;
915 foreach ($to_del as $del) {
916 if ($c->fetch($del) > 0) {
917 $c->del_type($this, $type_categ);
920 foreach ($to_add as $add) {
921 if ($c->fetch($add) > 0) {
922 $c->add_type($this, $type_categ);
const STATUS_CLOSED
Warehouse closed, inactive.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
nb_products()
Return stock and value of warehosue.
const STATUS_OPEN_ALL
Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corr...
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
getLibStatut($mode=0)
Return label of status of object.
get_children_warehouses($id, &$TChildWarehouses)
Return array of children warehouses ids from $id warehouse (recursive function)
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
get_full_arbo()
Return full path to current warehouse.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
getNomUrl($withpicto=0, $option= '', $showfullpath=0, $notooltip=0)
Return clickable name (possibility with the pictogram)
initAsSpecimen()
Initialise an instance with random values.
$conf db
API class for accounts.
generateDocument($modele, $outputlangs= '', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
info($id)
Load warehouse info data.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
__construct($db)
Constructor.
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
Class to manage categories.
fetch($id, $ref= '')
Load warehouse data.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
setCategories($categories)
Sets object to supplied categories.
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_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)
deleteExtraFields()
Delete all extra fields values for the current object.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
list_array($status=1)
Return list of all warehouses.
LibStatut($status, $mode=0)
Return label of a given status.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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...
nb_different_products()
Return number of unique different product into a warehouse.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
update($id, $user)
Update properties of a warehouse.
create($user)
Creation d'un entrepot en base.
Class to manage warehouses.