dolibarr 19.0.3
entrepot.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2008 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2016 Francis Appels <francis.appels@yahoo.com>
7 * Copyright (C) 2019-2023 Frédéric France <frederic.france@netlogic.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30
31
36{
40 public $element = 'stock';
41
45 public $table_element = 'entrepot';
46
50 public $picto = 'stock';
51
55 public $ismultientitymanaged = 1;
56
62 public $libelle;
63
67 public $label;
68
72 public $description;
73
74 public $statut;
75
79 public $lieu;
80
84 public $address;
85
89 public $zip;
90
94 public $town;
95
99 public $phone;
100
104 public $fax;
105
109 public $fk_parent;
110
114 public $fk_project;
115
119 public $labelStatus = array();
120
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'=>'integer', 'label'=>'State', 'enabled'=>1, 'visible'=>0, 'position'=>60),
136 'fk_pays' =>array('type'=>'integer:Ccountry:core/class/ccountry.class.php', 'label'=>'Country', 'enabled'=>1, 'visible'=>-1, '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),
139 //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
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),
142 'warehouse_usage' => array('type'=>'integer', 'label' => 'WarehouseUsage', 'enabled'=>'getDolGlobalInt("MAIN_FEATURES_LEVEL")', 'visible'=>1, 'position'=>400, 'arrayofkeyval'=>array(1=>'InternalWarehouse', 2=>'ExternalWarehouse')),
143 //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
144 //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
145 'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>500, 'css'=>'minwidth50'),
146 );
147
151 const STATUS_CLOSED = 0;
152
157
162
166 const STATUS_OPENEXT_ALL = 3; // TODO Implement this
167
168
169
175 public function __construct($db)
176 {
177 global $conf;
178 $this->db = $db;
179
180 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
181 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
182 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
183 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
184 } else {
185 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
186 }
187 }
188
196 public function create($user, $notrigger = false)
197 {
198 global $conf;
199
200 $error = 0;
201
202 $this->label = trim($this->label);
203
204 // Error if label not defined
205 if ($this->label == '') {
206 $this->error = "ErrorFieldRequired";
207 return 0;
208 }
209
210 $now = dol_now();
211
212 $this->db->begin();
213
214 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
215 $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").")";
216
217 dol_syslog(get_class($this)."::create", LOG_DEBUG);
218 $result = $this->db->query($sql);
219 if ($result) {
220 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
221 if ($id > 0) {
222 $this->id = $id;
223
224 if (!$error) {
225 $result = $this->update($id, $user);
226 if ($result <= 0) {
227 $error++;
228 }
229 }
230
231 // Actions on extra fields
232 if (!$error) {
233 $result = $this->insertExtraFields();
234 if ($result < 0) {
235 $error++;
236 }
237 }
238
239 if (!$error && !$notrigger) {
240 // Call triggers
241 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
242 if ($result < 0) {
243 $error++;
244 }
245 // End call triggers
246 }
247
248 if (!$error) {
249 $this->db->commit();
250 return $id;
251 } else {
252 dol_syslog(get_class($this)."::create return -3");
253 $this->db->rollback();
254 return -3;
255 }
256 } else {
257 $this->error = "Failed to get insert id";
258 dol_syslog(get_class($this)."::create return -2");
259 return -2;
260 }
261 } else {
262 $this->error = $this->db->error();
263 dol_syslog(get_class($this)."::create Error ".$this->db->error());
264 $this->db->rollback();
265 return -1;
266 }
267 }
268
277 public function update($id, $user, $notrigger = false)
278 {
279 global $conf;
280
281 $error = 0;
282
283 if (empty($id)) {
284 $id = $this->id;
285 }
286
287 // Check if new parent is already a child of current warehouse
288 if (!empty($this->fk_parent)) {
289 $TChildWarehouses = array($id);
290 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
291 if (in_array($this->fk_parent, $TChildWarehouses)) {
292 $this->error = 'ErrorCannotAddThisParentWarehouse';
293 return -2;
294 }
295 }
296
297 $this->label = trim($this->label);
298
299 $this->description = trim($this->description);
300
301 $this->lieu = trim($this->lieu);
302
303 $this->address = trim($this->address);
304 $this->zip = trim($this->zip);
305 $this->town = trim($this->town);
306 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
307
308 $sql = "UPDATE ".$this->db->prefix()."entrepot";
309 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
310 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
311 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
312 $sql .= ", description = '".$this->db->escape($this->description)."'";
313 $sql .= ", statut = ".((int) $this->statut);
314 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
315 $sql .= ", address = '".$this->db->escape($this->address)."'";
316 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
317 $sql .= ", town = '".$this->db->escape($this->town)."'";
318 $sql .= ", fk_pays = ".((int) $this->country_id);
319 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
320 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
321 $sql .= " WHERE rowid = ".((int) $id);
322
323 $this->db->begin();
324
325 dol_syslog(get_class($this)."::update", LOG_DEBUG);
326 $resql = $this->db->query($sql);
327
328 if (!$resql) {
329 $error++;
330 $this->errors[] = "Error ".$this->db->lasterror();
331 }
332
333 if (!$error) {
334 $result = $this->insertExtraFields();
335 if ($result < 0) {
336 $error++;
337 }
338 }
339
340 if (!$error && !$notrigger) {
341 // Call triggers
342 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
343 if ($result < 0) {
344 $error++;
345 }
346 // End call triggers
347 }
348
349 if (!$error) {
350 $this->db->commit();
351 return 1;
352 } else {
353 $this->db->rollback();
354 $this->error = $this->db->lasterror();
355 return -1;
356 }
357 }
358
359
367 public function delete($user, $notrigger = 0)
368 {
369 global $conf;
370
371 $error = 0;
372
373 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
374
375 $this->db->begin();
376
377 if (!$error && empty($notrigger)) {
378 // Call trigger
379 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
380 if ($result < 0) {
381 $error++;
382 }
383 // End call triggers
384 }
385
386 if (!$error) {
387 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
388 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
389 $result = $this->db->query($sql);
390 if (!$result) {
391 $error++;
392 $this->errors[] = $this->db->lasterror();
393 }
394 }
395
396 if (!$error) {
397 $elements = array('stock_mouvement', 'product_stock');
398 foreach ($elements as $table) {
399 if (!$error) {
400 $sql = "DELETE FROM ".$this->db->prefix().$table;
401 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
402
403 $result = $this->db->query($sql);
404 if (!$result) {
405 $error++;
406 $this->errors[] = $this->db->lasterror();
407 }
408 }
409 }
410 }
411
412 // Removed extrafields
413 if (!$error) {
414 if (!$error) {
415 $result = $this->deleteExtraFields();
416 if ($result < 0) {
417 $error++;
418 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
419 }
420 }
421 }
422
423 if (!$error) {
424 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
425 $sql .= " WHERE rowid = ".((int) $this->id);
426 $resql1 = $this->db->query($sql);
427 if (!$resql1) {
428 $error++;
429 $this->errors[] = $this->db->lasterror();
430 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
431 }
432 }
433
434 if (!$error) {
435 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
436 $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)";
437 $resql2 = $this->db->query($sql);
438 if (!$resql2) {
439 $error++;
440 $this->errors[] = $this->db->lasterror();
441 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
442 }
443 }
444
445 if (!$error) {
446 $this->db->commit();
447 return 1;
448 } else {
449 $this->db->rollback();
450 return -1;
451 }
452 }
453
454
462 public function fetch($id, $ref = '')
463 {
464 global $conf;
465
466 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
467
468 // Check parameters
469 if (!$id && !$ref) {
470 $this->error = 'ErrorWrongParameters';
471 dol_syslog(get_class($this)."::fetch ".$this->error);
472 return -1;
473 }
474
475 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
476 $sql .= " model_pdf, import_key";
477 $sql .= " FROM ".$this->db->prefix()."entrepot";
478 if ($id) {
479 $sql .= " WHERE rowid = ".((int) $id);
480 } else {
481 $sql .= " WHERE entity IN (".getEntity('stock').")";
482 if ($ref) {
483 $sql .= " AND ref = '".$this->db->escape($ref)."'";
484 }
485 }
486
487 $result = $this->db->query($sql);
488 if ($result) {
489 if ($this->db->num_rows($result) > 0) {
490 $obj = $this->db->fetch_object($result);
491
492 $this->id = $obj->rowid;
493 $this->entity = $obj->entity;
494 $this->fk_parent = $obj->fk_parent;
495 $this->fk_project = $obj->fk_project;
496 $this->ref = $obj->label;
497 $this->label = $obj->label;
498 $this->description = $obj->description;
499 $this->statut = $obj->statut;
500 $this->lieu = $obj->lieu;
501 $this->address = $obj->address;
502 $this->zip = $obj->zip;
503 $this->town = $obj->town;
504 $this->country_id = $obj->country_id;
505 $this->phone = $obj->phone;
506 $this->fax = $obj->fax;
507
508 $this->model_pdf = $obj->model_pdf;
509 $this->import_key = $obj->import_key;
510
511 // Retrieve all extrafield
512 // fetch optionals attributes and labels
513 $this->fetch_optionals();
514
515 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
516 $tmp = getCountry($this->country_id, 'all');
517 $this->country = $tmp['label'];
518 $this->country_code = $tmp['code'];
519
520 return 1;
521 } else {
522 $this->error = "Record Not Found";
523 return 0;
524 }
525 } else {
526 $this->error = $this->db->error();
527 return -1;
528 }
529 }
530
531
538 public function info($id)
539 {
540 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
541 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
542 $sql .= " WHERE e.rowid = ".((int) $id);
543
544 dol_syslog(get_class($this)."::info", LOG_DEBUG);
545 $result = $this->db->query($sql);
546 if ($result) {
547 if ($this->db->num_rows($result)) {
548 $obj = $this->db->fetch_object($result);
549
550 $this->id = $obj->rowid;
551
552 $this->user_creation_id = $obj->fk_user_author;
553 $this->date_creation = $this->db->jdate($obj->datec);
554 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
555 }
556
557 $this->db->free($result);
558 } else {
559 dol_print_error($this->db);
560 }
561 }
562
563
564 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
571 public function list_array($status = 1)
572 {
573 // phpcs:enable
574 $liste = array();
575
576 $sql = "SELECT rowid, ref as label";
577 $sql .= " FROM ".$this->db->prefix()."entrepot";
578 $sql .= " WHERE entity IN (".getEntity('stock').")";
579 $sql .= " AND statut = ".((int) $status);
580
581 $result = $this->db->query($sql);
582 $i = 0;
583 $num = $this->db->num_rows($result);
584 if ($result) {
585 while ($i < $num) {
586 $row = $this->db->fetch_row($result);
587 $liste[$row[0]] = $row[1];
588 $i++;
589 }
590 $this->db->free($result);
591 }
592 return $liste;
593 }
594
595 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
601 public function nb_different_products()
602 {
603 // phpcs:enable
604 $ret = array();
605
606 $sql = "SELECT count(distinct p.rowid) as nb";
607 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
608 $sql .= ", ".$this->db->prefix()."product as p";
609 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
610 $sql .= " AND ps.fk_product = p.rowid";
611
612 //print $sql;
613 $result = $this->db->query($sql);
614 if ($result) {
615 $obj = $this->db->fetch_object($result);
616 $ret['nb'] = $obj->nb;
617 $this->db->free($result);
618 } else {
619 $this->error = $this->db->lasterror();
620 return -1;
621 }
622
623 return $ret;
624 }
625
626 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
632 public function nb_products()
633 {
634 global $conf;
635 // phpcs:enable
636 $ret = array();
637
638 //For MultiCompany PMP per entity
639 $separatedPMP = false;
640 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
641 $separatedPMP = true;
642 }
643
644 if ($separatedPMP) {
645 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
646 } else {
647 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
648 }
649 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
650 $sql .= ", ".$this->db->prefix()."product as p";
651 if ($separatedPMP) {
652 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
653 }
654 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
655 if ($separatedPMP) {
656 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
657 }
658 $sql .= " AND ps.fk_product = p.rowid";
659 //print $sql;
660 $result = $this->db->query($sql);
661 if ($result) {
662 $obj = $this->db->fetch_object($result);
663 $ret['nb'] = $obj->nb;
664 $ret['value'] = $obj->value;
665 $this->db->free($result);
666 } else {
667 $this->error = $this->db->lasterror();
668 return -1;
669 }
670
671 return $ret;
672 }
673
680 public function getLibStatut($mode = 0)
681 {
682 return $this->LibStatut($this->statut, $mode);
683 }
684
685 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
693 public function LibStatut($status, $mode = 0)
694 {
695 // phpcs:enable
696 global $langs;
697
698 $statusType = 'status5';
699 if ($status > 0) {
700 $statusType = 'status4';
701 }
702
703 $langs->load('stocks');
704 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
705 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
706
707 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
708 }
709
717 public function getTooltipContentArray($params)
718 {
719 global $conf, $langs, $user;
720
721 $langs->load('stocks');
722
723 $datas = [];
724
725 $option = $params['option'] ?? '';
726 $nofetch = !empty($params['nofetch']);
727
728 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
729 return ['optimize' => $langs->trans("Warehouse")];
730 }
731 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
732 if (isset($this->statut)) {
733 $datas['picto'] .= ' '.$this->getLibStatut(5);
734 }
735 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
736 if (!empty($this->lieu)) {
737 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
738 }
739 // show categories for this record only in ajax to not overload lists
740 if (!$nofetch && isModEnabled('categorie')) {
741 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
742 $form = new Form($this->db);
743 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
744 }
745
746 return $datas;
747 }
748
760 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
761 {
762 global $conf, $langs, $hookmanager;
763 $langs->load("stocks");
764
765 if (!empty($conf->dol_no_mouse_hover)) {
766 $notooltip = 1; // Force disable tooltips
767 }
768
769 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
770 $withpicto = 0;
771 }
772
773 $result = '';
774 $params = [
775 'id' => $this->id,
776 'objecttype' => $this->element,
777 'option' => $option,
778 'nofetch' => 1,
779 ];
780 $classfortooltip = 'classfortooltip';
781 $dataparams = '';
782 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
783 $classfortooltip = 'classforajaxtooltip';
784 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
785 $label = 'ToComplete';
786 } else {
787 $label = implode($this->getTooltipContentArray($params));
788 }
789
790 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
791
792 if ($option != 'nolink') {
793 // Add param to save lastsearch_values or not
794 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
795 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
796 $add_save_lastsearch_values = 1;
797 }
798 if ($add_save_lastsearch_values) {
799 $url .= '&save_lastsearch_values=1';
800 }
801 }
802
803 $linkclose = '';
804 if (empty($notooltip)) {
805 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
806 $label = $langs->trans("Warehouse");
807 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
808 }
809 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
810 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
811 }
812
813 $linkstart = '<a href="'.$url.'"';
814 $linkstart .= $linkclose.'>';
815 $linkend = '</a>';
816
817 $result .= $linkstart;
818 if ($withpicto) {
819 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
820 }
821 if ($withpicto != 2) {
822 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
823 }
824 $result .= $linkend;
825
826 global $action;
827 $hookmanager->initHooks(array('warehousedao'));
828 $parameters = array('id'=>$this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip'=> $notooltip);
829 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
830 if ($reshook > 0) {
831 $result = $hookmanager->resPrint;
832 } else {
833 $result .= $hookmanager->resPrint;
834 }
835
836 return $result;
837 }
838
846 public function initAsSpecimen()
847 {
848 global $user, $langs, $conf, $mysoc;
849
850 $now = dol_now();
851
852 // Initialize parameters
853 $this->id = 0;
854 $this->label = 'WAREHOUSE SPECIMEN';
855 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
856 $this->statut = 1;
857 $this->specimen = 1;
858
859 $this->lieu = 'Location test';
860 $this->address = '21 jump street';
861 $this->zip = '99999';
862 $this->town = 'MyTown';
863 $this->country_id = 1;
864 $this->country_code = 'FR';
865 }
866
867 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
873 public function get_full_arbo()
874 {
875 // phpcs:enable
876 global $user, $langs, $conf;
877
878 $TArbo = array($this->label);
879
880 $protection = 100; // We limit depth of warehouses to 100
881
882 $warehousetmp = new Entrepot($this->db);
883
884 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
885 $i = 0;
886 while ($parentid > 0 && $i < $protection) {
887 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid);
888 $resql = $this->db->query($sql);
889 if ($resql) {
890 $objarbo = $this->db->fetch_object($resql);
891 if ($objarbo) {
892 $warehousetmp->fetch($parentid);
893 $TArbo[] = $warehousetmp->label;
894 $parentid = $objarbo->fk_parent;
895 } else {
896 break;
897 }
898 } else {
899 dol_print_error($this->db);
900 }
901
902 $i++;
903 }
904
905 return implode(' >> ', array_reverse($TArbo));
906 }
907
908 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
916 public function get_children_warehouses($id, &$TChildWarehouses)
917 {
918 // phpcs:enable
919
920 $sql = "SELECT rowid
921 FROM ".$this->db->prefix()."entrepot
922 WHERE fk_parent = ".((int) $id);
923
924 $resql = $this->db->query($sql);
925 if ($resql) {
926 while ($res = $this->db->fetch_object($resql)) {
927 $TChildWarehouses[] = $res->rowid;
928 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
929 }
930 }
931
932 return $TChildWarehouses;
933 }
934
945 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
946 {
947 global $conf, $user, $langs;
948
949 $langs->load("stocks");
950 $outputlangs->load("products");
951
952 if (!dol_strlen($modele)) {
953 $modele = 'standard';
954
955 if ($this->model_pdf) {
956 $modele = $this->model_pdf;
957 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
958 $modele = $conf->global->STOCK_ADDON_PDF;
959 }
960 }
961
962 $modelpath = "core/modules/stock/doc/";
963
964 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
965 }
966
977 public function setCategories($categories)
978 {
979 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
980 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
981 }
982
990 public function getKanbanView($option = '', $arraydata = null)
991 {
992 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
993
994 $return = '<div class="box-flex-item box-flex-grow-zero">';
995 $return .= '<div class="info-box info-box-sm">';
996 $return .= '<div class="info-box-icon bg-infobox-action" >';
997 $return .= img_picto('', $this->picto);
998 $return .= '</div>';
999 $return .= '<div class="info-box-content" >';
1000 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1001 if ($selected >= 0) {
1002 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1003 }
1004 if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
1005 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1006 }
1007 if (property_exists($this, 'sellvalue') && $this->sellvalue != 0) {
1008 $return .= '<br><span class="info-box-label amount">'.price($this->sellvalue).'</span>';
1009 }
1010 if (method_exists($this, 'getLibStatut')) {
1011 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1012 }
1013 $return .= '</div>';
1014 $return .= '</div>';
1015 $return .= '</div>';
1016 return $return;
1017 }
1018}
$object ref
Definition info.php:79
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 only operations for stock transfers/corrections allowed (not for customer shipping...
create($user, $notrigger=false)
Creation d'un entrepot en base.
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.
const STATUS_OPENEXT_ALL
Warehouse open and any operations are allowed, but warehouse is not included into calculation of stoc...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
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.
update($id, $user, $notrigger=false)
Update properties of a warehouse.
info($id)
Load warehouse info data.
nb_products()
Return stock and value of warehosue.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
getTooltipContentArray($params)
getTooltipContentArray
list_array($status=1)
Return list of all warehouses.
get_full_arbo()
Return full path to current warehouse.
__construct($db)
Constructor.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
const STATUS_CLOSED
Warehouse closed, inactive.
Class to manage generation of HTML components Only common components must be here.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926