dolibarr 21.0.0-beta
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-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31
32
37{
41 public $element = 'stock';
42
46 public $table_element = 'entrepot';
47
51 public $picto = 'stock';
52
58 public $libelle;
59
63 public $label;
64
68 public $description;
69
73 public $statut;
74
78 public $lieu;
79
83 public $address;
84
88 public $zip;
89
93 public $town;
94
98 public $phone;
99
103 public $fax;
104
108 public $fk_parent;
109
113 public $fk_project;
114
118 public $warehouse_usage;
119
159 // BEGIN MODULEBUILDER PROPERTIES
163 public $fields = array(
164 'rowid' => array('type' => 'integer', 'label' => 'ID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 10),
165 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 15),
166 'ref' => array('type' => 'varchar(255)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'showoncombobox' => 1, 'position' => 25, 'searchall' => 1),
167 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'visible' => -2, 'position' => 35, 'searchall' => 1),
168 'lieu' => array('type' => 'varchar(64)', 'label' => 'LocationSummary', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'showoncombobox' => 2, 'searchall' => 1),
169 '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),
170 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label' => 'Project', 'enabled' => '$conf->project->enabled', 'visible' => -1, 'position' => 42),
171 'address' => array('type' => 'varchar(255)', 'label' => 'Address', 'enabled' => 1, 'visible' => -2, 'position' => 45, 'searchall' => 1),
172 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'searchall' => 1),
173 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -2, 'position' => 55, 'searchall' => 1),
174 'fk_departement' => array('type' => 'integer', 'label' => 'State', 'enabled' => 1, 'visible' => 0, 'position' => 60),
175 'fk_pays' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 65),
176 'phone' => array('type' => 'varchar(20)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -2, 'position' => 70, 'searchall' => 1),
177 'fax' => array('type' => 'varchar(20)', 'label' => 'Fax', 'enabled' => 1, 'visible' => -2, 'position' => 75, 'searchall' => 1),
178 //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
179 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300),
180 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301),
181 'warehouse_usage' => array('type' => 'integer', 'label' => 'WarehouseUsage', 'enabled' => 'getDolGlobalInt("STOCK_USE_WAREHOUSE_USAGE")', 'visible' => 1, 'position' => 400, 'default' => 1, 'arrayofkeyval' => array(1 => 'InternalWarehouse', 2 => 'ExternalWarehouse')),
182 //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
183 //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
184 'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'),
185 );
186 // END MODULEBUILDER PROPERTIES
187
188
192 const STATUS_CLOSED = 0;
193
198
204
205
209 const USAGE_INTERNAL = 1;
210
215
216
217
223 public function __construct($db)
224 {
225 $this->db = $db;
226
227 $this->ismultientitymanaged = 1;
228
229 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
230 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
231 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
232 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
233 } else {
234 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
235 }
236 }
237
245 public function create($user, $notrigger = 0)
246 {
247 global $conf;
248
249 $error = 0;
250
251 $this->label = trim($this->label);
252
253 // Error if label not defined
254 if ($this->label == '') {
255 $this->error = "ErrorFieldRequired";
256 return 0;
257 }
258
259 $now = dol_now();
260
261 $this->db->begin();
262
263 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
264 $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").")";
265
266 dol_syslog(get_class($this)."::create", LOG_DEBUG);
267 $result = $this->db->query($sql);
268 if ($result) {
269 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
270 if ($id > 0) {
271 $this->id = $id;
272
273 if (!$error) {
274 $result = $this->update($id, $user);
275 if ($result <= 0) {
276 $error++;
277 }
278 }
279
280 // Actions on extra fields
281 if (!$error) {
282 $result = $this->insertExtraFields();
283 if ($result < 0) {
284 $error++;
285 }
286 }
287
288 if (!$error && !$notrigger) {
289 // Call triggers
290 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
291 if ($result < 0) {
292 $error++;
293 }
294 // End call triggers
295 }
296
297 if (!$error) {
298 $this->db->commit();
299 return $id;
300 } else {
301 dol_syslog(get_class($this)."::create return -3");
302 $this->db->rollback();
303 return -3;
304 }
305 } else {
306 $this->error = "Failed to get insert id";
307 dol_syslog(get_class($this)."::create return -2");
308 return -2;
309 }
310 } else {
311 $this->error = $this->db->error();
312 dol_syslog(get_class($this)."::create Error ".$this->db->error());
313 $this->db->rollback();
314 return -1;
315 }
316 }
317
326 public function update($id, $user, $notrigger = 0)
327 {
328 $error = 0;
329
330 if (empty($id)) {
331 $id = $this->id;
332 }
333
334 // Check if new parent is already a child of current warehouse
335 if (!empty($this->fk_parent)) {
336 $TChildWarehouses = array($id);
337 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
338 if (in_array($this->fk_parent, $TChildWarehouses)) {
339 $this->error = 'ErrorCannotAddThisParentWarehouse';
340 return -2;
341 }
342 }
343
344 $this->label = trim($this->label);
345
346 $this->description = trim($this->description);
347
348 $this->lieu = trim($this->lieu);
349
350 $this->address = trim($this->address);
351 $this->zip = trim($this->zip);
352 $this->town = trim($this->town);
353 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
354
355 $sql = "UPDATE ".$this->db->prefix()."entrepot";
356 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
357 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
358 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
359 $sql .= ", description = '".$this->db->escape($this->description)."'";
360 $sql .= ", statut = ".((int) $this->statut);
361 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
362 $sql .= ", address = '".$this->db->escape($this->address)."'";
363 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
364 $sql .= ", town = '".$this->db->escape($this->town)."'";
365 $sql .= ", fk_pays = ".((int) $this->country_id);
366 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
367 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
368 $sql .= " WHERE rowid = ".((int) $id);
369
370 $this->db->begin();
371
372 dol_syslog(get_class($this)."::update", LOG_DEBUG);
373 $resql = $this->db->query($sql);
374
375 if (!$resql) {
376 $error++;
377 $this->errors[] = "Error ".$this->db->lasterror();
378 }
379
380 if (!$error) {
381 $result = $this->insertExtraFields();
382 if ($result < 0) {
383 $error++;
384 }
385 }
386
387 if (!$error && !$notrigger) {
388 // Call triggers
389 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
390 if ($result < 0) {
391 $error++;
392 }
393 // End call triggers
394 }
395
396 if (!$error) {
397 $this->db->commit();
398 return 1;
399 } else {
400 $this->db->rollback();
401 $this->error = $this->db->lasterror();
402 return -1;
403 }
404 }
405
406
414 public function delete($user, $notrigger = 0)
415 {
416 global $conf;
417
418 $error = 0;
419
420 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
421
422 $this->db->begin();
423
424 if (!$error && empty($notrigger)) {
425 // Call trigger
426 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
427 if ($result < 0) {
428 $error++;
429 }
430 // End call triggers
431 }
432
433 if (!$error) {
434 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
435 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
436 $result = $this->db->query($sql);
437 if (!$result) {
438 $error++;
439 $this->errors[] = $this->db->lasterror();
440 }
441 }
442
443 if (!$error) {
444 $elements = array('stock_mouvement', 'product_stock');
445 foreach ($elements as $table) {
446 if (!$error) {
447 $sql = "DELETE FROM ".$this->db->prefix().$table;
448 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
449
450 $result = $this->db->query($sql);
451 if (!$result) {
452 $error++;
453 $this->errors[] = $this->db->lasterror();
454 }
455 }
456 }
457 }
458
459 // Removed extrafields
460 if (!$error) {
461 $result = $this->deleteExtraFields();
462 if ($result < 0) {
463 $error++;
464 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
465 }
466 }
467
468 if (!$error) {
469 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
470 $sql .= " WHERE rowid = ".((int) $this->id);
471 $resql1 = $this->db->query($sql);
472 if (!$resql1) {
473 $error++;
474 $this->errors[] = $this->db->lasterror();
475 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
476 }
477 }
478
479 if (!$error) {
480 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
481 $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)";
482 $resql2 = $this->db->query($sql);
483 if (!$resql2) {
484 $error++;
485 $this->errors[] = $this->db->lasterror();
486 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
487 }
488 }
489
490 if (!$error) {
491 $this->db->commit();
492 return 1;
493 } else {
494 $this->db->rollback();
495 return -1;
496 }
497 }
498
499
507 public function fetch($id, $ref = '')
508 {
509 global $conf;
510
511 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
512
513 // Check parameters
514 if (!$id && !$ref) {
515 $this->error = 'ErrorWrongParameters';
516 dol_syslog(get_class($this)."::fetch ".$this->error);
517 return -1;
518 }
519
520 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
521 $sql .= " model_pdf, import_key";
522 $sql .= " FROM ".$this->db->prefix()."entrepot";
523 if ($id) {
524 $sql .= " WHERE rowid = ".((int) $id);
525 } else {
526 $sql .= " WHERE entity IN (".getEntity('stock').")";
527 if ($ref) {
528 $sql .= " AND ref = '".$this->db->escape($ref)."'";
529 }
530 }
531
532 $result = $this->db->query($sql);
533 if ($result) {
534 if ($this->db->num_rows($result) > 0) {
535 $obj = $this->db->fetch_object($result);
536
537 $this->id = $obj->rowid;
538 $this->entity = $obj->entity;
539 $this->fk_parent = $obj->fk_parent;
540 $this->fk_project = $obj->fk_project;
541 $this->ref = $obj->label;
542 $this->label = $obj->label;
543 $this->description = $obj->description;
544 $this->statut = $obj->statut;
545 $this->lieu = $obj->lieu;
546 $this->address = $obj->address;
547 $this->zip = $obj->zip;
548 $this->town = $obj->town;
549 $this->country_id = $obj->country_id;
550 $this->phone = $obj->phone;
551 $this->fax = $obj->fax;
552
553 $this->model_pdf = $obj->model_pdf;
554 $this->import_key = $obj->import_key;
555
556 // Retrieve all extrafield
557 // fetch optionals attributes and labels
558 $this->fetch_optionals();
559
560 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
561 $tmp = getCountry($this->country_id, 'all');
562 $this->country = $tmp['label'];
563 $this->country_code = $tmp['code'];
564
565 return 1;
566 } else {
567 $this->error = "Record Not Found";
568 return 0;
569 }
570 } else {
571 $this->error = $this->db->error();
572 return -1;
573 }
574 }
575
576
583 public function info($id)
584 {
585 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
586 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
587 $sql .= " WHERE e.rowid = ".((int) $id);
588
589 dol_syslog(get_class($this)."::info", LOG_DEBUG);
590 $result = $this->db->query($sql);
591 if ($result) {
592 if ($this->db->num_rows($result)) {
593 $obj = $this->db->fetch_object($result);
594
595 $this->id = $obj->rowid;
596
597 $this->user_creation_id = $obj->fk_user_author;
598 $this->date_creation = $this->db->jdate($obj->datec);
599 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
600 }
601
602 $this->db->free($result);
603 } else {
604 dol_print_error($this->db);
605 }
606 }
607
608
609 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
616 public function list_array($status = 1)
617 {
618 // phpcs:enable
619 $liste = array();
620
621 $sql = "SELECT rowid, ref as label";
622 $sql .= " FROM ".$this->db->prefix()."entrepot";
623 $sql .= " WHERE entity IN (".getEntity('stock').")";
624 $sql .= " AND statut = ".((int) $status);
625
626 $result = $this->db->query($sql);
627 $i = 0;
628 $num = $this->db->num_rows($result);
629 if ($result) {
630 while ($i < $num) {
631 $row = $this->db->fetch_row($result);
632 $liste[$row[0]] = $row[1];
633 $i++;
634 }
635 $this->db->free($result);
636 }
637 return $liste;
638 }
639
640 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
646 public function nb_different_products()
647 {
648 // phpcs:enable
649 $ret = array();
650
651 $sql = "SELECT count(distinct p.rowid) as nb";
652 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
653 $sql .= ", ".$this->db->prefix()."product as p";
654 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
655 $sql .= " AND ps.fk_product = p.rowid";
656
657 //print $sql;
658 $result = $this->db->query($sql);
659 if ($result) {
660 $obj = $this->db->fetch_object($result);
661 $ret['nb'] = $obj->nb;
662 $this->db->free($result);
663 } else {
664 $this->error = $this->db->lasterror();
665 return -1;
666 }
667
668 return $ret;
669 }
670
671 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
677 public function nb_products()
678 {
679 global $conf;
680 // phpcs:enable
681 $ret = array();
682
683 //For MultiCompany PMP per entity
684 $separatedPMP = false;
685 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
686 $separatedPMP = true;
687 }
688
689 if ($separatedPMP) {
690 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
691 } else {
692 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
693 }
694 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
695 $sql .= ", ".$this->db->prefix()."product as p";
696 if ($separatedPMP) {
697 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
698 }
699 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
700 if ($separatedPMP) {
701 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
702 }
703 $sql .= " AND ps.fk_product = p.rowid";
704 //print $sql;
705 $result = $this->db->query($sql);
706 if ($result) {
707 $obj = $this->db->fetch_object($result);
708 $ret['nb'] = $obj->nb;
709 $ret['value'] = $obj->value;
710 $this->db->free($result);
711 } else {
712 $this->error = $this->db->lasterror();
713 return -1;
714 }
715
716 return $ret;
717 }
718
725 public function getLibStatut($mode = 0)
726 {
727 return $this->LibStatut($this->statut, $mode);
728 }
729
730 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
738 public function LibStatut($status, $mode = 0)
739 {
740 // phpcs:enable
741 global $langs;
742
743 $statusType = 'status5';
744 if ($status > 0) {
745 $statusType = 'status4';
746 }
747
748 $langs->load('stocks');
749 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
750 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
751
752 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
753 }
754
761 public function getTooltipContentArray($params)
762 {
763 global $conf, $langs, $user;
764
765 $langs->load('stocks');
766
767 $datas = [];
768
769 $option = $params['option'] ?? '';
770 $nofetch = !empty($params['nofetch']);
771
772 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
773 return ['optimize' => $langs->trans("Warehouse")];
774 }
775 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
776 if (!empty($this->statut)) {
777 $datas['picto'] .= ' '.$this->getLibStatut(5);
778 }
779 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
780 if (!empty($this->lieu)) {
781 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
782 }
783 // show categories for this record only in ajax to not overload lists
784 if (!$nofetch && isModEnabled('category')) {
785 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
786 $form = new Form($this->db);
787 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
788 }
789
790 return $datas;
791 }
792
804 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
805 {
806 global $conf, $langs, $hookmanager;
807 $langs->load("stocks");
808
809 if (!empty($conf->dol_no_mouse_hover)) {
810 $notooltip = 1; // Force disable tooltips
811 }
812
813 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
814 $withpicto = 0;
815 }
816
817 $result = '';
818 $params = [
819 'id' => $this->id,
820 'objecttype' => $this->element,
821 'option' => $option,
822 'nofetch' => 1,
823 ];
824 $classfortooltip = 'classfortooltip';
825 $dataparams = '';
826 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
827 $classfortooltip = 'classforajaxtooltip';
828 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
829 $label = 'ToComplete';
830 } else {
831 $label = implode($this->getTooltipContentArray($params));
832 }
833
834 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
835
836 if ($option != 'nolink') {
837 // Add param to save lastsearch_values or not
838 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
839 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
840 $add_save_lastsearch_values = 1;
841 }
842 if ($add_save_lastsearch_values) {
843 $url .= '&save_lastsearch_values=1';
844 }
845 }
846
847 $linkclose = '';
848 if (empty($notooltip)) {
849 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
850 $label = $langs->trans("Warehouse");
851 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
852 }
853 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
854 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
855 }
856
857 $linkstart = '<a href="'.$url.'"';
858 $linkstart .= $linkclose.'>';
859 $linkend = '</a>';
860
861 $result .= $linkstart;
862 if ($withpicto) {
863 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
864 }
865 if ($withpicto != 2) {
866 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
867 }
868 $result .= $linkend;
869
870 global $action;
871 $hookmanager->initHooks(array('warehousedao'));
872 $parameters = array('id' => $this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip' => $notooltip);
873 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
874 if ($reshook > 0) {
875 $result = $hookmanager->resPrint;
876 } else {
877 $result .= $hookmanager->resPrint;
878 }
879
880 return $result;
881 }
882
890 public function initAsSpecimen()
891 {
892 global $user, $langs, $conf, $mysoc;
893
894 $now = dol_now();
895
896 // Initialize parameters
897 $this->id = 0;
898 $this->label = 'WAREHOUSE SPECIMEN';
899 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
900 $this->statut = 1;
901 $this->specimen = 1;
902
903 $this->lieu = 'Location test';
904 $this->address = '21 jump street';
905 $this->zip = '99999';
906 $this->town = 'MyTown';
907 $this->country_id = 1;
908 $this->country_code = 'FR';
909
910 return 1;
911 }
912
913 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
919 public function get_full_arbo()
920 {
921 // phpcs:enable
922 $TArbo = array($this->label);
923
924 $protection = 100; // We limit depth of warehouses to 100
925
926 $warehousetmp = new Entrepot($this->db);
927
928 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
929 $i = 0;
930 while ($parentid > 0 && $i < $protection) {
931 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot";
932 $sql .= " WHERE rowid = ".((int) $parentid);
933
934 $resql = $this->db->query($sql);
935 if ($resql) {
936 $objarbo = $this->db->fetch_object($resql);
937 if ($objarbo) {
938 $warehousetmp->fetch($parentid);
939 $TArbo[] = $warehousetmp->label;
940 $parentid = $objarbo->fk_parent;
941 } else {
942 break;
943 }
944 } else {
945 dol_print_error($this->db);
946 }
947
948 $i++;
949 }
950
951 return implode(' >> ', array_reverse($TArbo));
952 }
953
954 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
962 public function get_children_warehouses($id, &$TChildWarehouses)
963 {
964 // phpcs:enable
965
966 $sql = "SELECT rowid
967 FROM ".$this->db->prefix()."entrepot
968 WHERE fk_parent = ".((int) $id);
969
970 $resql = $this->db->query($sql);
971 if ($resql) {
972 while ($res = $this->db->fetch_object($resql)) {
973 $TChildWarehouses[] = $res->rowid;
974 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
975 }
976 }
977
978 return $TChildWarehouses;
979 }
980
991 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
992 {
993 global $conf, $user, $langs;
994
995 $langs->load("stocks");
996 $outputlangs->load("products");
997
998 if (!dol_strlen($modele)) {
999 $modele = 'standard';
1000
1001 if ($this->model_pdf) {
1002 $modele = $this->model_pdf;
1003 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
1004 $modele = getDolGlobalString('STOCK_ADDON_PDF');
1005 }
1006 }
1007
1008 $modelpath = "core/modules/stock/doc/";
1009
1010 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1011 }
1012
1023 public function setCategories($categories)
1024 {
1025 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1026 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
1027 }
1028
1036 public function getKanbanView($option = '', $arraydata = null)
1037 {
1038 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1039
1040 $return = '<div class="box-flex-item box-flex-grow-zero">';
1041 $return .= '<div class="info-box info-box-sm">';
1042 $return .= '<div class="info-box-icon bg-infobox-action" >';
1043 $return .= img_picto('', $this->picto);
1044 $return .= '</div>';
1045 $return .= '<div class="info-box-content" >';
1046 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1047 if ($selected >= 0) {
1048 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1049 }
1050 if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
1051 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1052 }
1053 if (property_exists($this, 'sellvalue') && $this->sellvalue != 0) {
1054 $return .= '<br><span class="info-box-label amount">'.price($this->sellvalue).'</span>';
1055 }
1056 if (method_exists($this, 'getLibStatut')) {
1057 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1058 }
1059 $return .= '</div>';
1060 $return .= '</div>';
1061 $return .= '</div>';
1062 return $return;
1063 }
1064}
$object ref
Definition info.php:89
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...
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.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
Create object on disk.
const USAGE_EXTTERNAL
Warehouse that must be excluded for stock calculation (scrapping stock, virtual warehouses,...
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 warehouse.
const STATUS_OPEN_ALL
Warehouse open and any operations are allowed (customer shipping, supplier dispatch,...
create($user, $notrigger=0)
Creation d'un entrepot en base.
update($id, $user, $notrigger=0)
Update properties of a warehouse.
getTooltipContentArray($params)
getTooltipContentArray
list_array($status=1)
Return list of all warehouses.
const USAGE_INTERNAL
Warehouse that must be include for stock calculation (default)
get_full_arbo()
Return full path to current warehouse.
__construct($db)
Constructor.
getKanbanView($option='', $arraydata=null)
Return clickable 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=null, $outputlangs=null, $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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
div refaddress div address
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79