dolibarr 21.0.0-alpha
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
70 public $statut;
71
75 public $lieu;
76
80 public $address;
81
85 public $zip;
86
90 public $town;
91
95 public $phone;
96
100 public $fax;
101
105 public $fk_parent;
106
110 public $fk_project;
111
115 public $warehouse_usage;
116
156 // BEGIN MODULEBUILDER PROPERTIES
160 public $fields = array(
161 'rowid' => array('type' => 'integer', 'label' => 'ID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 10),
162 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'default' => '1', 'notnull' => 1, 'index' => 1, 'position' => 15),
163 'ref' => array('type' => 'varchar(255)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'showoncombobox' => 1, 'position' => 25, 'searchall' => 1),
164 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'visible' => -2, 'position' => 35, 'searchall' => 1),
165 'lieu' => array('type' => 'varchar(64)', 'label' => 'LocationSummary', 'enabled' => 1, 'visible' => 1, 'position' => 40, 'showoncombobox' => 2, 'searchall' => 1),
166 '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),
167 '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),
168 'address' => array('type' => 'varchar(255)', 'label' => 'Address', 'enabled' => 1, 'visible' => -2, 'position' => 45, 'searchall' => 1),
169 'zip' => array('type' => 'varchar(10)', 'label' => 'Zip', 'enabled' => 1, 'visible' => -2, 'position' => 50, 'searchall' => 1),
170 'town' => array('type' => 'varchar(50)', 'label' => 'Town', 'enabled' => 1, 'visible' => -2, 'position' => 55, 'searchall' => 1),
171 'fk_departement' => array('type' => 'integer', 'label' => 'State', 'enabled' => 1, 'visible' => 0, 'position' => 60),
172 'fk_pays' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 65),
173 'phone' => array('type' => 'varchar(20)', 'label' => 'Phone', 'enabled' => 1, 'visible' => -2, 'position' => 70, 'searchall' => 1),
174 'fax' => array('type' => 'varchar(20)', 'label' => 'Fax', 'enabled' => 1, 'visible' => -2, 'position' => 75, 'searchall' => 1),
175 //'fk_user_author' =>array('type'=>'integer', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-2, 'position'=>82),
176 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -2, 'position' => 300),
177 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 301),
178 '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')),
179 //'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000),
180 //'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'ModelPDF', 'enabled'=>1, 'visible'=>0, 'position'=>1010),
181 'statut' => array('type' => 'tinyint(4)', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 500, 'css' => 'minwidth50'),
182 );
183 // END MODULEBUILDER PROPERTIES
184
185
189 const STATUS_CLOSED = 0;
190
195
201
202
206 const USAGE_INTERNAL = 1;
207
212
213
214
220 public function __construct($db)
221 {
222 $this->db = $db;
223
224 $this->ismultientitymanaged = 1;
225
226 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
227 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
228 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
229 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
230 } else {
231 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
232 }
233 }
234
242 public function create($user, $notrigger = 0)
243 {
244 global $conf;
245
246 $error = 0;
247
248 $this->label = trim($this->label);
249
250 // Error if label not defined
251 if ($this->label == '') {
252 $this->error = "ErrorFieldRequired";
253 return 0;
254 }
255
256 $now = dol_now();
257
258 $this->db->begin();
259
260 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
261 $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").")";
262
263 dol_syslog(get_class($this)."::create", LOG_DEBUG);
264 $result = $this->db->query($sql);
265 if ($result) {
266 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
267 if ($id > 0) {
268 $this->id = $id;
269
270 if (!$error) {
271 $result = $this->update($id, $user);
272 if ($result <= 0) {
273 $error++;
274 }
275 }
276
277 // Actions on extra fields
278 if (!$error) {
279 $result = $this->insertExtraFields();
280 if ($result < 0) {
281 $error++;
282 }
283 }
284
285 if (!$error && !$notrigger) {
286 // Call triggers
287 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
288 if ($result < 0) {
289 $error++;
290 }
291 // End call triggers
292 }
293
294 if (!$error) {
295 $this->db->commit();
296 return $id;
297 } else {
298 dol_syslog(get_class($this)."::create return -3");
299 $this->db->rollback();
300 return -3;
301 }
302 } else {
303 $this->error = "Failed to get insert id";
304 dol_syslog(get_class($this)."::create return -2");
305 return -2;
306 }
307 } else {
308 $this->error = $this->db->error();
309 dol_syslog(get_class($this)."::create Error ".$this->db->error());
310 $this->db->rollback();
311 return -1;
312 }
313 }
314
323 public function update($id, $user, $notrigger = 0)
324 {
325 $error = 0;
326
327 if (empty($id)) {
328 $id = $this->id;
329 }
330
331 // Check if new parent is already a child of current warehouse
332 if (!empty($this->fk_parent)) {
333 $TChildWarehouses = array($id);
334 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
335 if (in_array($this->fk_parent, $TChildWarehouses)) {
336 $this->error = 'ErrorCannotAddThisParentWarehouse';
337 return -2;
338 }
339 }
340
341 $this->label = trim($this->label);
342
343 $this->description = trim($this->description);
344
345 $this->lieu = trim($this->lieu);
346
347 $this->address = trim($this->address);
348 $this->zip = trim($this->zip);
349 $this->town = trim($this->town);
350 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
351
352 $sql = "UPDATE ".$this->db->prefix()."entrepot";
353 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
354 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
355 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
356 $sql .= ", description = '".$this->db->escape($this->description)."'";
357 $sql .= ", statut = ".((int) $this->statut);
358 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
359 $sql .= ", address = '".$this->db->escape($this->address)."'";
360 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
361 $sql .= ", town = '".$this->db->escape($this->town)."'";
362 $sql .= ", fk_pays = ".((int) $this->country_id);
363 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
364 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
365 $sql .= " WHERE rowid = ".((int) $id);
366
367 $this->db->begin();
368
369 dol_syslog(get_class($this)."::update", LOG_DEBUG);
370 $resql = $this->db->query($sql);
371
372 if (!$resql) {
373 $error++;
374 $this->errors[] = "Error ".$this->db->lasterror();
375 }
376
377 if (!$error) {
378 $result = $this->insertExtraFields();
379 if ($result < 0) {
380 $error++;
381 }
382 }
383
384 if (!$error && !$notrigger) {
385 // Call triggers
386 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
387 if ($result < 0) {
388 $error++;
389 }
390 // End call triggers
391 }
392
393 if (!$error) {
394 $this->db->commit();
395 return 1;
396 } else {
397 $this->db->rollback();
398 $this->error = $this->db->lasterror();
399 return -1;
400 }
401 }
402
403
411 public function delete($user, $notrigger = 0)
412 {
413 global $conf;
414
415 $error = 0;
416
417 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
418
419 $this->db->begin();
420
421 if (!$error && empty($notrigger)) {
422 // Call trigger
423 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
424 if ($result < 0) {
425 $error++;
426 }
427 // End call triggers
428 }
429
430 if (!$error) {
431 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
432 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
433 $result = $this->db->query($sql);
434 if (!$result) {
435 $error++;
436 $this->errors[] = $this->db->lasterror();
437 }
438 }
439
440 if (!$error) {
441 $elements = array('stock_mouvement', 'product_stock');
442 foreach ($elements as $table) {
443 if (!$error) {
444 $sql = "DELETE FROM ".$this->db->prefix().$table;
445 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
446
447 $result = $this->db->query($sql);
448 if (!$result) {
449 $error++;
450 $this->errors[] = $this->db->lasterror();
451 }
452 }
453 }
454 }
455
456 // Removed extrafields
457 if (!$error) {
458 $result = $this->deleteExtraFields();
459 if ($result < 0) {
460 $error++;
461 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
462 }
463 }
464
465 if (!$error) {
466 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
467 $sql .= " WHERE rowid = ".((int) $this->id);
468 $resql1 = $this->db->query($sql);
469 if (!$resql1) {
470 $error++;
471 $this->errors[] = $this->db->lasterror();
472 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
473 }
474 }
475
476 if (!$error) {
477 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
478 $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)";
479 $resql2 = $this->db->query($sql);
480 if (!$resql2) {
481 $error++;
482 $this->errors[] = $this->db->lasterror();
483 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
484 }
485 }
486
487 if (!$error) {
488 $this->db->commit();
489 return 1;
490 } else {
491 $this->db->rollback();
492 return -1;
493 }
494 }
495
496
504 public function fetch($id, $ref = '')
505 {
506 global $conf;
507
508 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
509
510 // Check parameters
511 if (!$id && !$ref) {
512 $this->error = 'ErrorWrongParameters';
513 dol_syslog(get_class($this)."::fetch ".$this->error);
514 return -1;
515 }
516
517 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
518 $sql .= " model_pdf, import_key";
519 $sql .= " FROM ".$this->db->prefix()."entrepot";
520 if ($id) {
521 $sql .= " WHERE rowid = ".((int) $id);
522 } else {
523 $sql .= " WHERE entity IN (".getEntity('stock').")";
524 if ($ref) {
525 $sql .= " AND ref = '".$this->db->escape($ref)."'";
526 }
527 }
528
529 $result = $this->db->query($sql);
530 if ($result) {
531 if ($this->db->num_rows($result) > 0) {
532 $obj = $this->db->fetch_object($result);
533
534 $this->id = $obj->rowid;
535 $this->entity = $obj->entity;
536 $this->fk_parent = $obj->fk_parent;
537 $this->fk_project = $obj->fk_project;
538 $this->ref = $obj->label;
539 $this->label = $obj->label;
540 $this->description = $obj->description;
541 $this->statut = $obj->statut;
542 $this->lieu = $obj->lieu;
543 $this->address = $obj->address;
544 $this->zip = $obj->zip;
545 $this->town = $obj->town;
546 $this->country_id = $obj->country_id;
547 $this->phone = $obj->phone;
548 $this->fax = $obj->fax;
549
550 $this->model_pdf = $obj->model_pdf;
551 $this->import_key = $obj->import_key;
552
553 // Retrieve all extrafield
554 // fetch optionals attributes and labels
555 $this->fetch_optionals();
556
557 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
558 $tmp = getCountry($this->country_id, 'all');
559 $this->country = $tmp['label'];
560 $this->country_code = $tmp['code'];
561
562 return 1;
563 } else {
564 $this->error = "Record Not Found";
565 return 0;
566 }
567 } else {
568 $this->error = $this->db->error();
569 return -1;
570 }
571 }
572
573
580 public function info($id)
581 {
582 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
583 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
584 $sql .= " WHERE e.rowid = ".((int) $id);
585
586 dol_syslog(get_class($this)."::info", LOG_DEBUG);
587 $result = $this->db->query($sql);
588 if ($result) {
589 if ($this->db->num_rows($result)) {
590 $obj = $this->db->fetch_object($result);
591
592 $this->id = $obj->rowid;
593
594 $this->user_creation_id = $obj->fk_user_author;
595 $this->date_creation = $this->db->jdate($obj->datec);
596 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
597 }
598
599 $this->db->free($result);
600 } else {
601 dol_print_error($this->db);
602 }
603 }
604
605
606 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
613 public function list_array($status = 1)
614 {
615 // phpcs:enable
616 $liste = array();
617
618 $sql = "SELECT rowid, ref as label";
619 $sql .= " FROM ".$this->db->prefix()."entrepot";
620 $sql .= " WHERE entity IN (".getEntity('stock').")";
621 $sql .= " AND statut = ".((int) $status);
622
623 $result = $this->db->query($sql);
624 $i = 0;
625 $num = $this->db->num_rows($result);
626 if ($result) {
627 while ($i < $num) {
628 $row = $this->db->fetch_row($result);
629 $liste[$row[0]] = $row[1];
630 $i++;
631 }
632 $this->db->free($result);
633 }
634 return $liste;
635 }
636
637 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
643 public function nb_different_products()
644 {
645 // phpcs:enable
646 $ret = array();
647
648 $sql = "SELECT count(distinct p.rowid) as nb";
649 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
650 $sql .= ", ".$this->db->prefix()."product as p";
651 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
652 $sql .= " AND ps.fk_product = p.rowid";
653
654 //print $sql;
655 $result = $this->db->query($sql);
656 if ($result) {
657 $obj = $this->db->fetch_object($result);
658 $ret['nb'] = $obj->nb;
659 $this->db->free($result);
660 } else {
661 $this->error = $this->db->lasterror();
662 return -1;
663 }
664
665 return $ret;
666 }
667
668 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
674 public function nb_products()
675 {
676 global $conf;
677 // phpcs:enable
678 $ret = array();
679
680 //For MultiCompany PMP per entity
681 $separatedPMP = false;
682 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
683 $separatedPMP = true;
684 }
685
686 if ($separatedPMP) {
687 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
688 } else {
689 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
690 }
691 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
692 $sql .= ", ".$this->db->prefix()."product as p";
693 if ($separatedPMP) {
694 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
695 }
696 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
697 if ($separatedPMP) {
698 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
699 }
700 $sql .= " AND ps.fk_product = p.rowid";
701 //print $sql;
702 $result = $this->db->query($sql);
703 if ($result) {
704 $obj = $this->db->fetch_object($result);
705 $ret['nb'] = $obj->nb;
706 $ret['value'] = $obj->value;
707 $this->db->free($result);
708 } else {
709 $this->error = $this->db->lasterror();
710 return -1;
711 }
712
713 return $ret;
714 }
715
722 public function getLibStatut($mode = 0)
723 {
724 return $this->LibStatut($this->statut, $mode);
725 }
726
727 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
735 public function LibStatut($status, $mode = 0)
736 {
737 // phpcs:enable
738 global $langs;
739
740 $statusType = 'status5';
741 if ($status > 0) {
742 $statusType = 'status4';
743 }
744
745 $langs->load('stocks');
746 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
747 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
748
749 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
750 }
751
759 public function getTooltipContentArray($params)
760 {
761 global $conf, $langs, $user;
762
763 $langs->load('stocks');
764
765 $datas = [];
766
767 $option = $params['option'] ?? '';
768 $nofetch = !empty($params['nofetch']);
769
770 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
771 return ['optimize' => $langs->trans("Warehouse")];
772 }
773 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
774 if (isset($this->statut)) {
775 $datas['picto'] .= ' '.$this->getLibStatut(5);
776 }
777 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
778 if (!empty($this->lieu)) {
779 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
780 }
781 // show categories for this record only in ajax to not overload lists
782 if (!$nofetch && isModEnabled('category')) {
783 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
784 $form = new Form($this->db);
785 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
786 }
787
788 return $datas;
789 }
790
802 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
803 {
804 global $conf, $langs, $hookmanager;
805 $langs->load("stocks");
806
807 if (!empty($conf->dol_no_mouse_hover)) {
808 $notooltip = 1; // Force disable tooltips
809 }
810
811 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
812 $withpicto = 0;
813 }
814
815 $result = '';
816 $params = [
817 'id' => $this->id,
818 'objecttype' => $this->element,
819 'option' => $option,
820 'nofetch' => 1,
821 ];
822 $classfortooltip = 'classfortooltip';
823 $dataparams = '';
824 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
825 $classfortooltip = 'classforajaxtooltip';
826 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
827 $label = 'ToComplete';
828 } else {
829 $label = implode($this->getTooltipContentArray($params));
830 }
831
832 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
833
834 if ($option != 'nolink') {
835 // Add param to save lastsearch_values or not
836 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
837 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
838 $add_save_lastsearch_values = 1;
839 }
840 if ($add_save_lastsearch_values) {
841 $url .= '&save_lastsearch_values=1';
842 }
843 }
844
845 $linkclose = '';
846 if (empty($notooltip)) {
847 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
848 $label = $langs->trans("Warehouse");
849 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
850 }
851 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
852 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
853 }
854
855 $linkstart = '<a href="'.$url.'"';
856 $linkstart .= $linkclose.'>';
857 $linkend = '</a>';
858
859 $result .= $linkstart;
860 if ($withpicto) {
861 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
862 }
863 if ($withpicto != 2) {
864 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
865 }
866 $result .= $linkend;
867
868 global $action;
869 $hookmanager->initHooks(array('warehousedao'));
870 $parameters = array('id' => $this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip' => $notooltip);
871 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
872 if ($reshook > 0) {
873 $result = $hookmanager->resPrint;
874 } else {
875 $result .= $hookmanager->resPrint;
876 }
877
878 return $result;
879 }
880
888 public function initAsSpecimen()
889 {
890 global $user, $langs, $conf, $mysoc;
891
892 $now = dol_now();
893
894 // Initialize parameters
895 $this->id = 0;
896 $this->label = 'WAREHOUSE SPECIMEN';
897 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
898 $this->statut = 1;
899 $this->specimen = 1;
900
901 $this->lieu = 'Location test';
902 $this->address = '21 jump street';
903 $this->zip = '99999';
904 $this->town = 'MyTown';
905 $this->country_id = 1;
906 $this->country_code = 'FR';
907
908 return 1;
909 }
910
911 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
917 public function get_full_arbo()
918 {
919 // phpcs:enable
920 $TArbo = array($this->label);
921
922 $protection = 100; // We limit depth of warehouses to 100
923
924 $warehousetmp = new Entrepot($this->db);
925
926 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
927 $i = 0;
928 while ($parentid > 0 && $i < $protection) {
929 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot";
930 $sql .= " WHERE rowid = ".((int) $parentid);
931
932 $resql = $this->db->query($sql);
933 if ($resql) {
934 $objarbo = $this->db->fetch_object($resql);
935 if ($objarbo) {
936 $warehousetmp->fetch($parentid);
937 $TArbo[] = $warehousetmp->label;
938 $parentid = $objarbo->fk_parent;
939 } else {
940 break;
941 }
942 } else {
943 dol_print_error($this->db);
944 }
945
946 $i++;
947 }
948
949 return implode(' >> ', array_reverse($TArbo));
950 }
951
952 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
960 public function get_children_warehouses($id, &$TChildWarehouses)
961 {
962 // phpcs:enable
963
964 $sql = "SELECT rowid
965 FROM ".$this->db->prefix()."entrepot
966 WHERE fk_parent = ".((int) $id);
967
968 $resql = $this->db->query($sql);
969 if ($resql) {
970 while ($res = $this->db->fetch_object($resql)) {
971 $TChildWarehouses[] = $res->rowid;
972 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
973 }
974 }
975
976 return $TChildWarehouses;
977 }
978
989 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
990 {
991 global $conf, $user, $langs;
992
993 $langs->load("stocks");
994 $outputlangs->load("products");
995
996 if (!dol_strlen($modele)) {
997 $modele = 'standard';
998
999 if ($this->model_pdf) {
1000 $modele = $this->model_pdf;
1001 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
1002 $modele = getDolGlobalString('STOCK_ADDON_PDF');
1003 }
1004 }
1005
1006 $modelpath = "core/modules/stock/doc/";
1007
1008 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1009 }
1010
1021 public function setCategories($categories)
1022 {
1023 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1024 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
1025 }
1026
1034 public function getKanbanView($option = '', $arraydata = null)
1035 {
1036 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1037
1038 $return = '<div class="box-flex-item box-flex-grow-zero">';
1039 $return .= '<div class="info-box info-box-sm">';
1040 $return .= '<div class="info-box-icon bg-infobox-action" >';
1041 $return .= img_picto('', $this->picto);
1042 $return .= '</div>';
1043 $return .= '<div class="info-box-content" >';
1044 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1045 if ($selected >= 0) {
1046 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1047 }
1048 if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
1049 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1050 }
1051 if (property_exists($this, 'sellvalue') && $this->sellvalue != 0) {
1052 $return .= '<br><span class="info-box-label amount">'.price($this->sellvalue).'</span>';
1053 }
1054 if (method_exists($this, 'getLibStatut')) {
1055 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1056 }
1057 $return .= '</div>';
1058 $return .= '</div>';
1059 $return .= '</div>';
1060 return $return;
1061 }
1062}
$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...
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 warehosue.
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 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=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.
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 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 TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1929