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;
119 public $statuts = array();
124 public $fields = array(
125 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>10),
126 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'default'=>1,
'notnull'=>1,
'index'=>1,
'position'=>15),
127 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>25,
'searchall'=>1),
128 'description' =>array(
'type'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-2,
'position'=>35,
'searchall'=>1),
129 'lieu' =>array(
'type'=>
'varchar(64)',
'label'=>
'LocationSummary',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'showoncombobox'=>2,
'searchall'=>1),
130 '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),
131 'fk_project' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Project',
'enabled'=>
'$conf->project->enabled',
'visible'=>-1,
'position'=>25),
132 'address' =>array(
'type'=>
'varchar(255)',
'label'=>
'Address',
'enabled'=>1,
'visible'=>-2,
'position'=>45,
'searchall'=>1),
133 'zip' =>array(
'type'=>
'varchar(10)',
'label'=>
'Zip',
'enabled'=>1,
'visible'=>-2,
'position'=>50,
'searchall'=>1),
134 'town' =>array(
'type'=>
'varchar(50)',
'label'=>
'Town',
'enabled'=>1,
'visible'=>-2,
'position'=>55,
'searchall'=>1),
135 'fk_departement' =>array(
'type'=>
'sellist:c_departements:label:rowid::active=1',
'label'=>
'State',
'enabled'=>1,
'visible'=>0,
'position'=>60),
136 'fk_pays' =>array(
'type'=>
'sellist:c_country:label:rowid::active=1',
'label'=>
'Country',
'enabled'=>1,
'visible'=>-2,
'position'=>65),
137 'phone' =>array(
'type'=>
'varchar(20)',
'label'=>
'Phone',
'enabled'=>1,
'visible'=>-2,
'position'=>70,
'searchall'=>1),
138 'fax' =>array(
'type'=>
'varchar(20)',
'label'=>
'Fax',
'enabled'=>1,
'visible'=>-2,
'position'=>75,
'searchall'=>1),
140 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-2,
'position'=>300),
141 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>301),
144 'statut' =>array(
'type'=>
'tinyint(4)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'position'=>500),
174 if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
194 $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
197 if ($this->label ==
'') {
198 $this->error =
"ErrorFieldRequired";
206 $sql =
"INSERT INTO ".$this->db->prefix().
"entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
207 $sql .=
" VALUES ('".$this->db->escape($this->label).
"', ".((int) $conf->entity).
", '".$this->
db->idate($now).
"', ".((int) $user->id).
", ".($this->fk_parent > 0 ? ((int) $this->fk_parent) :
"NULL").
", ".($this->fk_project > 0 ? ((
int) $this->fk_project) :
"NULL").
")";
209 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
210 $result = $this->
db->query($sql);
212 $id = $this->
db->last_insert_id($this->
db->prefix().
"entrepot");
217 $result = $this->
update($id, $user);
237 dol_syslog(get_class($this).
"::create return -3");
238 $this->
db->rollback();
242 $this->error =
"Failed to get insert id";
243 dol_syslog(get_class($this).
"::create return -2");
247 $this->error = $this->
db->error();
248 dol_syslog(get_class($this).
"::create Error ".$this->
db->error());
249 $this->
db->rollback();
270 if (empty($this->label)) {
271 $this->label = $this->libelle;
275 if (!empty($this->fk_parent)) {
276 $TChildWarehouses = array($id);
278 if (in_array($this->fk_parent, $TChildWarehouses)) {
279 $this->error =
'ErrorCannotAddThisParentWarehouse';
284 $this->label = trim(!empty($this->label) ? $this->label : $this->libelle);
288 $this->lieu = trim($this->lieu);
290 $this->address = trim($this->address);
291 $this->zip = trim($this->zip);
292 $this->town = trim($this->town);
293 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
295 $sql =
"UPDATE ".$this->db->prefix().
"entrepot";
296 $sql .=
" SET ref = '".$this->db->escape($this->label).
"'";
297 $sql .=
", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent :
"NULL");
298 $sql .=
", fk_project = ".(($this->fk_project > 0) ? $this->fk_project :
"NULL");
299 $sql .=
", description = '".$this->db->escape($this->
description).
"'";
300 $sql .=
", statut = ".((int) $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 = ".((int) $this->country_id);
306 $sql .=
", phone = '".$this->db->escape($this->phone).
"'";
307 $sql .=
", fax = '".$this->db->escape($this->fax).
"'";
308 $sql .=
" WHERE rowid = ".((int) $id);
312 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
317 $this->errors[] =
"Error ".$this->db->lasterror();
331 $this->
db->rollback();
332 $this->error = $this->
db->lasterror();
345 public function delete($user, $notrigger = 0)
351 dol_syslog(get_class($this).
"::delete id=".$this->
id, LOG_DEBUG);
355 if (!$error && empty($notrigger)) {
357 $result = $this->
call_trigger(
'WAREHOUSE_DELETE', $user);
364 $elements = array(
'stock_mouvement',
'product_stock',
'product_warehouse_properties');
365 foreach ($elements as $table) {
367 $sql =
"DELETE FROM ".$this->db->prefix().$table;
368 $sql .=
" WHERE fk_entrepot = ".((int) $this->
id);
370 $result = $this->
db->query($sql);
373 $this->errors[] = $this->
db->lasterror();
384 dol_syslog(get_class($this).
"::delete Error ".$this->error, LOG_ERR);
390 $sql =
"DELETE FROM ".$this->db->prefix().
"entrepot";
391 $sql .=
" WHERE rowid = ".((int) $this->
id);
392 $resql1 = $this->
db->query($sql);
395 $this->errors[] = $this->
db->lasterror();
396 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
402 $sql =
"UPDATE ".$this->db->prefix().
"product as p SET stock = (SELECT SUM(ps.reel) FROM ".$this->
db->prefix().
"product_stock as ps WHERE ps.fk_product = p.rowid)";
403 $resql2 = $this->
db->query($sql);
406 $this->errors[] = $this->
db->lasterror();
407 dol_syslog(get_class($this).
"::delete Error ".$this->
db->lasterror(), LOG_ERR);
415 $this->
db->rollback();
428 public function fetch($id, $ref =
'')
432 dol_syslog(get_class($this).
"::fetch id=".$id.
" ref=".$ref);
436 $this->error =
'ErrorWrongParameters';
437 dol_syslog(get_class($this).
"::fetch ".$this->error);
441 $sql =
"SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
442 $sql .=
" model_pdf, import_key";
443 $sql .=
" FROM ".$this->db->prefix().
"entrepot";
445 $sql .=
" WHERE rowid = ".((int) $id);
447 $sql .=
" WHERE entity IN (".getEntity(
'stock').
")";
449 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
453 $result = $this->
db->query($sql);
455 if ($this->
db->num_rows($result) > 0) {
456 $obj = $this->
db->fetch_object($result);
458 $this->
id = $obj->rowid;
459 $this->entity = $obj->entity;
460 $this->fk_parent = $obj->fk_parent;
461 $this->fk_project = $obj->fk_project;
462 $this->
ref = $obj->label;
463 $this->label = $obj->label;
464 $this->libelle = $obj->label;
466 $this->statut = $obj->statut;
467 $this->lieu = $obj->lieu;
468 $this->address = $obj->address;
469 $this->zip = $obj->zip;
470 $this->town = $obj->town;
471 $this->country_id = $obj->country_id;
472 $this->phone = $obj->phone;
473 $this->fax = $obj->fax;
475 $this->model_pdf = $obj->model_pdf;
476 $this->import_key = $obj->import_key;
482 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
484 $this->country = $tmp[
'label'];
485 $this->country_code = $tmp[
'code'];
489 $this->error =
"Record Not Found";
493 $this->error = $this->
db->error();
507 $sql =
"SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
508 $sql .=
" FROM ".$this->db->prefix().
"entrepot as e";
509 $sql .=
" WHERE e.rowid = ".((int) $id);
511 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
512 $result = $this->
db->query($sql);
514 if ($this->
db->num_rows($result)) {
515 $obj = $this->
db->fetch_object($result);
517 $this->
id = $obj->rowid;
519 $this->user_creation_id = $obj->fk_user_author;
520 $this->date_creation = $this->
db->jdate($obj->datec);
521 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
524 $this->
db->free($result);
543 $sql =
"SELECT rowid, ref as label";
544 $sql .=
" FROM ".$this->db->prefix().
"entrepot";
545 $sql .=
" WHERE entity IN (".getEntity(
'stock').
")";
546 $sql .=
" AND statut = ".((int) $status);
548 $result = $this->
db->query($sql);
550 $num = $this->
db->num_rows($result);
553 $row = $this->
db->fetch_row($result);
554 $liste[$row[0]] = $row[1];
557 $this->
db->free($result);
573 $sql =
"SELECT count(distinct p.rowid) as nb";
574 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
575 $sql .=
", ".$this->db->prefix().
"product as p";
576 $sql .=
" WHERE ps.fk_entrepot = ".((int) $this->
id);
577 $sql .=
" AND ps.fk_product = p.rowid";
580 $result = $this->
db->query($sql);
582 $obj = $this->
db->fetch_object($result);
583 $ret[
'nb'] = $obj->nb;
584 $this->
db->free($result);
586 $this->error = $this->
db->lasterror();
606 $separatedPMP =
false;
607 if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED) && !empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) {
608 $separatedPMP =
true;
612 $sql =
"SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
614 $sql =
"SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
616 $sql .=
" FROM ".$this->db->prefix().
"product_stock as ps";
617 $sql .=
", ".$this->db->prefix().
"product as p";
619 $sql .=
", ".$this->db->prefix().
"product_perentity as pa";
621 $sql .=
" WHERE ps.fk_entrepot = ".((int) $this->
id);
623 $sql .=
" AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
625 $sql .=
" AND ps.fk_product = p.rowid";
627 $result = $this->
db->query($sql);
629 $obj = $this->
db->fetch_object($result);
630 $ret[
'nb'] = $obj->nb;
631 $ret[
'value'] = $obj->value;
632 $this->
db->free($result);
634 $this->error = $this->
db->lasterror();
649 return $this->
LibStatut($this->statut, $mode);
665 $statusType =
'status5';
667 $statusType =
'status4';
670 $langs->load(
'stocks');
671 $label = $langs->transnoentitiesnoconv($this->statuts[$status]);
672 $labelshort = $langs->transnoentitiesnoconv($this->statuts[$status]);
674 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
689 public function getNomUrl($withpicto = 0, $option =
'', $showfullpath = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
691 global $conf, $langs, $hookmanager;
692 $langs->load(
"stocks");
694 if (!empty($conf->dol_no_mouse_hover)) {
698 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpicto) {
704 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Warehouse").
'</u>';
705 if (isset($this->statut)) {
706 $label .=
' '.$this->getLibStatut(5);
708 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.(empty($this->
ref) ? (empty($this->label) ? $this->libelle : $this->label) : $this->
ref);
709 if (!empty($this->lieu)) {
710 $label .=
'<br><b>'.$langs->trans(
'LocationSummary').
':</b> '.$this->lieu;
713 $url = DOL_URL_ROOT.
'/product/stock/card.php?id='.$this->id;
715 if ($option !=
'nolink') {
717 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
718 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
719 $add_save_lastsearch_values = 1;
721 if ($add_save_lastsearch_values) {
722 $url .=
'&save_lastsearch_values=1';
727 if (empty($notooltip)) {
728 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
729 $label = $langs->trans(
"Warehouse");
730 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
732 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
733 $linkclose .=
' class="classfortooltip"';
736 $linkstart =
'<a href="'.$url.
'"';
737 $linkstart .= $linkclose.
'>';
740 $result .= $linkstart;
742 $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);
744 if ($withpicto != 2) {
745 $result .= (($showfullpath || !empty($conf->global->STOCK_ALWAYS_SHOW_FULL_ARBO)) ? $this->
get_full_arbo() : (empty($this->label) ? $this->libelle : $this->label));
750 $hookmanager->initHooks(array(
'warehousedao'));
751 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result,
'withpicto' => $withpicto,
'option' => $option,
'showfullpath' => $showfullpath,
'notooltip'=> $notooltip);
752 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
754 $result = $hookmanager->resPrint;
756 $result .= $hookmanager->resPrint;
771 global $user, $langs, $conf, $mysoc;
777 $this->label =
'WAREHOUSE SPECIMEN';
778 $this->
description =
'WAREHOUSE SPECIMEN '.dol_print_date($now,
'dayhourlog');
782 $this->lieu =
'Location test';
783 $this->address =
'21 jump street';
784 $this->zip =
'99999';
785 $this->town =
'MyTown';
786 $this->country_id = 1;
787 $this->country_code =
'FR';
799 global $user, $langs, $conf;
801 $TArbo = array(empty($this->label) ? $this->libelle : $this->label);
807 $parentid = $this->fk_parent;
809 while ($parentid > 0 && $i < $protection) {
810 $sql =
"SELECT fk_parent FROM ".$this->db->prefix().
"entrepot WHERE rowid = ".((int) $parentid);
813 $objarbo = $this->
db->fetch_object(
$resql);
815 $warehousetmp->fetch($parentid);
816 $TArbo[] = $warehousetmp->label;
817 $parentid = $objarbo->fk_parent;
828 return implode(
' >> ', array_reverse($TArbo));
844 FROM ".$this->db->prefix().
"entrepot
845 WHERE fk_parent = ".((int) $id);
849 while ($res = $this->
db->fetch_object(
$resql)) {
850 $TChildWarehouses[] = $res->rowid;
855 return $TChildWarehouses;
868 public function generateDocument($modele, $outputlangs =
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
870 global $conf, $user, $langs;
872 $langs->load(
"stocks");
873 $outputlangs->load(
"products");
876 $modele =
'standard';
878 if ($this->model_pdf) {
879 $modele = $this->model_pdf;
880 } elseif (!empty($conf->global->STOCK_ADDON_PDF)) {
881 $modele = $conf->global->STOCK_ADDON_PDF;
885 $modelpath =
"core/modules/stock/doc/";
887 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
902 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
903 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
915 $return =
'<div class="box-flex-item box-flex-grow-zero">';
916 $return .=
'<div class="info-box info-box-sm">';
917 $return .=
'<div class="info-box-icon bg-infobox-action" >';
920 $return .=
'<div class="info-box-content" >';
921 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
922 if (property_exists($this,
'lieu') && (!empty($this->lieu))) {
923 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->lieu.
'</span>';
925 if (property_exists($this,
'sellvalue') && $this->sellvalue != 0) {
926 $return .=
'<br><span class="info-box-label amount">'.price($this->sellvalue).
'</span>';
928 if (method_exists($this,
'getLibStatut')) {
929 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage warehouses.
const STATUS_OPEN_INTERNAL
Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and ...
nb_different_products()
Return number of unique different product into a warehouse.
fetch($id, $ref='')
Load warehouse data.
get_children_warehouses($id, &$TChildWarehouses)
Return array of children warehouses ids from $id warehouse (recursive function)
getLibStatut($mode=0)
Return label of status of object.
LibStatut($status, $mode=0)
Return label of a given status.
create($user)
Creation d'un entrepot en base.
update($id, $user)
Update properties of a warehouse.
getNomUrl($withpicto=0, $option='', $showfullpath=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable name (possibility with the pictogram)
setCategories($categories)
Sets object to supplied categories.
initAsSpecimen()
Initialise an instance with random values.
info($id)
Load warehouse info data.
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...
generateDocument($modele, $outputlangs='', $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
list_array($status=1)
Return list of all warehouses.
get_full_arbo()
Return full path to current warehouse.
__construct($db)
Constructor.
const STATUS_CLOSED
Warehouse closed, inactive.
getKanbanView($option='')
Return clicable link of object (with eventually picto)
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.