dolibarr 20.0.2
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("MAIN_FEATURES_LEVEL")', '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
200
204 const STATUS_OPENEXT_ALL = 3; // TODO Implement this
205
206
207
213 public function __construct($db)
214 {
215 $this->db = $db;
216
217 $this->ismultientitymanaged = 1;
218
219 $this->labelStatus[self::STATUS_CLOSED] = 'Closed2';
220 if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
221 $this->labelStatus[self::STATUS_OPEN_ALL] = 'OpenAnyMovement';
222 $this->labelStatus[self::STATUS_OPEN_INTERNAL] = 'OpenInternal';
223 } else {
224 $this->labelStatus[self::STATUS_OPEN_ALL] = 'Opened';
225 }
226 }
227
235 public function create($user, $notrigger = 0)
236 {
237 global $conf;
238
239 $error = 0;
240
241 $this->label = trim($this->label);
242
243 // Error if label not defined
244 if ($this->label == '') {
245 $this->error = "ErrorFieldRequired";
246 return 0;
247 }
248
249 $now = dol_now();
250
251 $this->db->begin();
252
253 $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)";
254 $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").")";
255
256 dol_syslog(get_class($this)."::create", LOG_DEBUG);
257 $result = $this->db->query($sql);
258 if ($result) {
259 $id = $this->db->last_insert_id($this->db->prefix()."entrepot");
260 if ($id > 0) {
261 $this->id = $id;
262
263 if (!$error) {
264 $result = $this->update($id, $user);
265 if ($result <= 0) {
266 $error++;
267 }
268 }
269
270 // Actions on extra fields
271 if (!$error) {
272 $result = $this->insertExtraFields();
273 if ($result < 0) {
274 $error++;
275 }
276 }
277
278 if (!$error && !$notrigger) {
279 // Call triggers
280 $result = $this->call_trigger('WAREHOUSE_CREATE', $user);
281 if ($result < 0) {
282 $error++;
283 }
284 // End call triggers
285 }
286
287 if (!$error) {
288 $this->db->commit();
289 return $id;
290 } else {
291 dol_syslog(get_class($this)."::create return -3");
292 $this->db->rollback();
293 return -3;
294 }
295 } else {
296 $this->error = "Failed to get insert id";
297 dol_syslog(get_class($this)."::create return -2");
298 return -2;
299 }
300 } else {
301 $this->error = $this->db->error();
302 dol_syslog(get_class($this)."::create Error ".$this->db->error());
303 $this->db->rollback();
304 return -1;
305 }
306 }
307
316 public function update($id, $user, $notrigger = 0)
317 {
318 $error = 0;
319
320 if (empty($id)) {
321 $id = $this->id;
322 }
323
324 // Check if new parent is already a child of current warehouse
325 if (!empty($this->fk_parent)) {
326 $TChildWarehouses = array($id);
327 $TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
328 if (in_array($this->fk_parent, $TChildWarehouses)) {
329 $this->error = 'ErrorCannotAddThisParentWarehouse';
330 return -2;
331 }
332 }
333
334 $this->label = trim($this->label);
335
336 $this->description = trim($this->description);
337
338 $this->lieu = trim($this->lieu);
339
340 $this->address = trim($this->address);
341 $this->zip = trim($this->zip);
342 $this->town = trim($this->town);
343 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
344
345 $sql = "UPDATE ".$this->db->prefix()."entrepot";
346 $sql .= " SET ref = '".$this->db->escape($this->label)."'";
347 $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL");
348 $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL");
349 $sql .= ", description = '".$this->db->escape($this->description)."'";
350 $sql .= ", statut = ".((int) $this->statut);
351 $sql .= ", lieu = '".$this->db->escape($this->lieu)."'";
352 $sql .= ", address = '".$this->db->escape($this->address)."'";
353 $sql .= ", zip = '".$this->db->escape($this->zip)."'";
354 $sql .= ", town = '".$this->db->escape($this->town)."'";
355 $sql .= ", fk_pays = ".((int) $this->country_id);
356 $sql .= ", phone = '".$this->db->escape($this->phone)."'";
357 $sql .= ", fax = '".$this->db->escape($this->fax)."'";
358 $sql .= " WHERE rowid = ".((int) $id);
359
360 $this->db->begin();
361
362 dol_syslog(get_class($this)."::update", LOG_DEBUG);
363 $resql = $this->db->query($sql);
364
365 if (!$resql) {
366 $error++;
367 $this->errors[] = "Error ".$this->db->lasterror();
368 }
369
370 if (!$error) {
371 $result = $this->insertExtraFields();
372 if ($result < 0) {
373 $error++;
374 }
375 }
376
377 if (!$error && !$notrigger) {
378 // Call triggers
379 $result = $this->call_trigger('WAREHOUSE_MODIFY', $user);
380 if ($result < 0) {
381 $error++;
382 }
383 // End call triggers
384 }
385
386 if (!$error) {
387 $this->db->commit();
388 return 1;
389 } else {
390 $this->db->rollback();
391 $this->error = $this->db->lasterror();
392 return -1;
393 }
394 }
395
396
404 public function delete($user, $notrigger = 0)
405 {
406 global $conf;
407
408 $error = 0;
409
410 dol_syslog(get_class($this)."::delete id=".$this->id, LOG_DEBUG);
411
412 $this->db->begin();
413
414 if (!$error && empty($notrigger)) {
415 // Call trigger
416 $result = $this->call_trigger('WAREHOUSE_DELETE', $user);
417 if ($result < 0) {
418 $error++;
419 }
420 // End call triggers
421 }
422
423 if (!$error) {
424 $sql = "DELETE FROM ".$this->db->prefix()."product_batch";
425 $sql .= " WHERE fk_product_stock IN (SELECT rowid FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_entrepot = ".((int) $this->id).")";
426 $result = $this->db->query($sql);
427 if (!$result) {
428 $error++;
429 $this->errors[] = $this->db->lasterror();
430 }
431 }
432
433 if (!$error) {
434 $elements = array('stock_mouvement', 'product_stock');
435 foreach ($elements as $table) {
436 if (!$error) {
437 $sql = "DELETE FROM ".$this->db->prefix().$table;
438 $sql .= " WHERE fk_entrepot = ".((int) $this->id);
439
440 $result = $this->db->query($sql);
441 if (!$result) {
442 $error++;
443 $this->errors[] = $this->db->lasterror();
444 }
445 }
446 }
447 }
448
449 // Removed extrafields
450 if (!$error) {
451 $result = $this->deleteExtraFields();
452 if ($result < 0) {
453 $error++;
454 dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR);
455 }
456 }
457
458 if (!$error) {
459 $sql = "DELETE FROM ".$this->db->prefix()."entrepot";
460 $sql .= " WHERE rowid = ".((int) $this->id);
461 $resql1 = $this->db->query($sql);
462 if (!$resql1) {
463 $error++;
464 $this->errors[] = $this->db->lasterror();
465 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
466 }
467 }
468
469 if (!$error) {
470 // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql
471 $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)";
472 $resql2 = $this->db->query($sql);
473 if (!$resql2) {
474 $error++;
475 $this->errors[] = $this->db->lasterror();
476 dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
477 }
478 }
479
480 if (!$error) {
481 $this->db->commit();
482 return 1;
483 } else {
484 $this->db->rollback();
485 return -1;
486 }
487 }
488
489
497 public function fetch($id, $ref = '')
498 {
499 global $conf;
500
501 dol_syslog(get_class($this)."::fetch id=".$id." ref=".$ref);
502
503 // Check parameters
504 if (!$id && !$ref) {
505 $this->error = 'ErrorWrongParameters';
506 dol_syslog(get_class($this)."::fetch ".$this->error);
507 return -1;
508 }
509
510 $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,";
511 $sql .= " model_pdf, import_key";
512 $sql .= " FROM ".$this->db->prefix()."entrepot";
513 if ($id) {
514 $sql .= " WHERE rowid = ".((int) $id);
515 } else {
516 $sql .= " WHERE entity IN (".getEntity('stock').")";
517 if ($ref) {
518 $sql .= " AND ref = '".$this->db->escape($ref)."'";
519 }
520 }
521
522 $result = $this->db->query($sql);
523 if ($result) {
524 if ($this->db->num_rows($result) > 0) {
525 $obj = $this->db->fetch_object($result);
526
527 $this->id = $obj->rowid;
528 $this->entity = $obj->entity;
529 $this->fk_parent = $obj->fk_parent;
530 $this->fk_project = $obj->fk_project;
531 $this->ref = $obj->label;
532 $this->label = $obj->label;
533 $this->description = $obj->description;
534 $this->statut = $obj->statut;
535 $this->lieu = $obj->lieu;
536 $this->address = $obj->address;
537 $this->zip = $obj->zip;
538 $this->town = $obj->town;
539 $this->country_id = $obj->country_id;
540 $this->phone = $obj->phone;
541 $this->fax = $obj->fax;
542
543 $this->model_pdf = $obj->model_pdf;
544 $this->import_key = $obj->import_key;
545
546 // Retrieve all extrafield
547 // fetch optionals attributes and labels
548 $this->fetch_optionals();
549
550 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
551 $tmp = getCountry($this->country_id, 'all');
552 $this->country = $tmp['label'];
553 $this->country_code = $tmp['code'];
554
555 return 1;
556 } else {
557 $this->error = "Record Not Found";
558 return 0;
559 }
560 } else {
561 $this->error = $this->db->error();
562 return -1;
563 }
564 }
565
566
573 public function info($id)
574 {
575 $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author";
576 $sql .= " FROM ".$this->db->prefix()."entrepot as e";
577 $sql .= " WHERE e.rowid = ".((int) $id);
578
579 dol_syslog(get_class($this)."::info", LOG_DEBUG);
580 $result = $this->db->query($sql);
581 if ($result) {
582 if ($this->db->num_rows($result)) {
583 $obj = $this->db->fetch_object($result);
584
585 $this->id = $obj->rowid;
586
587 $this->user_creation_id = $obj->fk_user_author;
588 $this->date_creation = $this->db->jdate($obj->datec);
589 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
590 }
591
592 $this->db->free($result);
593 } else {
594 dol_print_error($this->db);
595 }
596 }
597
598
599 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
606 public function list_array($status = 1)
607 {
608 // phpcs:enable
609 $liste = array();
610
611 $sql = "SELECT rowid, ref as label";
612 $sql .= " FROM ".$this->db->prefix()."entrepot";
613 $sql .= " WHERE entity IN (".getEntity('stock').")";
614 $sql .= " AND statut = ".((int) $status);
615
616 $result = $this->db->query($sql);
617 $i = 0;
618 $num = $this->db->num_rows($result);
619 if ($result) {
620 while ($i < $num) {
621 $row = $this->db->fetch_row($result);
622 $liste[$row[0]] = $row[1];
623 $i++;
624 }
625 $this->db->free($result);
626 }
627 return $liste;
628 }
629
630 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
636 public function nb_different_products()
637 {
638 // phpcs:enable
639 $ret = array();
640
641 $sql = "SELECT count(distinct p.rowid) as nb";
642 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
643 $sql .= ", ".$this->db->prefix()."product as p";
644 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
645 $sql .= " AND ps.fk_product = p.rowid";
646
647 //print $sql;
648 $result = $this->db->query($sql);
649 if ($result) {
650 $obj = $this->db->fetch_object($result);
651 $ret['nb'] = $obj->nb;
652 $this->db->free($result);
653 } else {
654 $this->error = $this->db->lasterror();
655 return -1;
656 }
657
658 return $ret;
659 }
660
661 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
667 public function nb_products()
668 {
669 global $conf;
670 // phpcs:enable
671 $ret = array();
672
673 //For MultiCompany PMP per entity
674 $separatedPMP = false;
675 if (getDolGlobalString('MULTICOMPANY_PRODUCT_SHARING_ENABLED') && getDolGlobalString('MULTICOMPANY_PMP_PER_ENTITY_ENABLED')) {
676 $separatedPMP = true;
677 }
678
679 if ($separatedPMP) {
680 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * pa.pmp) as value";
681 } else {
682 $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value";
683 }
684 $sql .= " FROM ".$this->db->prefix()."product_stock as ps";
685 $sql .= ", ".$this->db->prefix()."product as p";
686 if ($separatedPMP) {
687 $sql .= ", ".$this->db->prefix()."product_perentity as pa";
688 }
689 $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id);
690 if ($separatedPMP) {
691 $sql .= " AND pa.fk_product = p.rowid AND pa.entity = ". (int) $conf->entity;
692 }
693 $sql .= " AND ps.fk_product = p.rowid";
694 //print $sql;
695 $result = $this->db->query($sql);
696 if ($result) {
697 $obj = $this->db->fetch_object($result);
698 $ret['nb'] = $obj->nb;
699 $ret['value'] = $obj->value;
700 $this->db->free($result);
701 } else {
702 $this->error = $this->db->lasterror();
703 return -1;
704 }
705
706 return $ret;
707 }
708
715 public function getLibStatut($mode = 0)
716 {
717 return $this->LibStatut($this->statut, $mode);
718 }
719
720 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
728 public function LibStatut($status, $mode = 0)
729 {
730 // phpcs:enable
731 global $langs;
732
733 $statusType = 'status5';
734 if ($status > 0) {
735 $statusType = 'status4';
736 }
737
738 $langs->load('stocks');
739 $label = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
740 $labelshort = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
741
742 return dolGetStatus($label, $labelshort, '', $statusType, $mode);
743 }
744
752 public function getTooltipContentArray($params)
753 {
754 global $conf, $langs, $user;
755
756 $langs->load('stocks');
757
758 $datas = [];
759
760 $option = $params['option'] ?? '';
761 $nofetch = !empty($params['nofetch']);
762
763 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
764 return ['optimize' => $langs->trans("Warehouse")];
765 }
766 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Warehouse").'</u>';
767 if (isset($this->statut)) {
768 $datas['picto'] .= ' '.$this->getLibStatut(5);
769 }
770 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.(empty($this->ref) ? $this->label : $this->ref);
771 if (!empty($this->lieu)) {
772 $datas['locationsummary'] = '<br><b>'.$langs->trans('LocationSummary').':</b> '.$this->lieu;
773 }
774 // show categories for this record only in ajax to not overload lists
775 if (!$nofetch && isModEnabled('category')) {
776 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
777 $form = new Form($this->db);
778 $datas['categories_warehouse'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_WAREHOUSE, 1, 1);
779 }
780
781 return $datas;
782 }
783
795 public function getNomUrl($withpicto = 0, $option = '', $showfullpath = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
796 {
797 global $conf, $langs, $hookmanager;
798 $langs->load("stocks");
799
800 if (!empty($conf->dol_no_mouse_hover)) {
801 $notooltip = 1; // Force disable tooltips
802 }
803
804 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpicto) {
805 $withpicto = 0;
806 }
807
808 $result = '';
809 $params = [
810 'id' => $this->id,
811 'objecttype' => $this->element,
812 'option' => $option,
813 'nofetch' => 1,
814 ];
815 $classfortooltip = 'classfortooltip';
816 $dataparams = '';
817 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
818 $classfortooltip = 'classforajaxtooltip';
819 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
820 $label = 'ToComplete';
821 } else {
822 $label = implode($this->getTooltipContentArray($params));
823 }
824
825 $url = DOL_URL_ROOT.'/product/stock/card.php?id='.$this->id;
826
827 if ($option != 'nolink') {
828 // Add param to save lastsearch_values or not
829 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
830 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
831 $add_save_lastsearch_values = 1;
832 }
833 if ($add_save_lastsearch_values) {
834 $url .= '&save_lastsearch_values=1';
835 }
836 }
837
838 $linkclose = '';
839 if (empty($notooltip)) {
840 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
841 $label = $langs->trans("Warehouse");
842 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
843 }
844 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
845 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
846 }
847
848 $linkstart = '<a href="'.$url.'"';
849 $linkstart .= $linkclose.'>';
850 $linkend = '</a>';
851
852 $result .= $linkstart;
853 if ($withpicto) {
854 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
855 }
856 if ($withpicto != 2) {
857 $result .= (($showfullpath || getDolGlobalString('STOCK_ALWAYS_SHOW_FULL_ARBO')) ? $this->get_full_arbo() : $this->label);
858 }
859 $result .= $linkend;
860
861 global $action;
862 $hookmanager->initHooks(array('warehousedao'));
863 $parameters = array('id' => $this->id, 'getnomurl' => &$result, 'withpicto' => $withpicto, 'option' => $option, 'showfullpath' => $showfullpath, 'notooltip' => $notooltip);
864 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
865 if ($reshook > 0) {
866 $result = $hookmanager->resPrint;
867 } else {
868 $result .= $hookmanager->resPrint;
869 }
870
871 return $result;
872 }
873
881 public function initAsSpecimen()
882 {
883 global $user, $langs, $conf, $mysoc;
884
885 $now = dol_now();
886
887 // Initialize parameters
888 $this->id = 0;
889 $this->label = 'WAREHOUSE SPECIMEN';
890 $this->description = 'WAREHOUSE SPECIMEN '.dol_print_date($now, 'dayhourlog');
891 $this->statut = 1;
892 $this->specimen = 1;
893
894 $this->lieu = 'Location test';
895 $this->address = '21 jump street';
896 $this->zip = '99999';
897 $this->town = 'MyTown';
898 $this->country_id = 1;
899 $this->country_code = 'FR';
900
901 return 1;
902 }
903
904 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
910 public function get_full_arbo()
911 {
912 // phpcs:enable
913 $TArbo = array($this->label);
914
915 $protection = 100; // We limit depth of warehouses to 100
916
917 $warehousetmp = new Entrepot($this->db);
918
919 $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents
920 $i = 0;
921 while ($parentid > 0 && $i < $protection) {
922 $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot";
923 $sql .= " WHERE rowid = ".((int) $parentid);
924
925 $resql = $this->db->query($sql);
926 if ($resql) {
927 $objarbo = $this->db->fetch_object($resql);
928 if ($objarbo) {
929 $warehousetmp->fetch($parentid);
930 $TArbo[] = $warehousetmp->label;
931 $parentid = $objarbo->fk_parent;
932 } else {
933 break;
934 }
935 } else {
936 dol_print_error($this->db);
937 }
938
939 $i++;
940 }
941
942 return implode(' >> ', array_reverse($TArbo));
943 }
944
945 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
953 public function get_children_warehouses($id, &$TChildWarehouses)
954 {
955 // phpcs:enable
956
957 $sql = "SELECT rowid
958 FROM ".$this->db->prefix()."entrepot
959 WHERE fk_parent = ".((int) $id);
960
961 $resql = $this->db->query($sql);
962 if ($resql) {
963 while ($res = $this->db->fetch_object($resql)) {
964 $TChildWarehouses[] = $res->rowid;
965 $this->get_children_warehouses($res->rowid, $TChildWarehouses);
966 }
967 }
968
969 return $TChildWarehouses;
970 }
971
982 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
983 {
984 global $conf, $user, $langs;
985
986 $langs->load("stocks");
987 $outputlangs->load("products");
988
989 if (!dol_strlen($modele)) {
990 $modele = 'standard';
991
992 if ($this->model_pdf) {
993 $modele = $this->model_pdf;
994 } elseif (getDolGlobalString('STOCK_ADDON_PDF')) {
995 $modele = getDolGlobalString('STOCK_ADDON_PDF');
996 }
997 }
998
999 $modelpath = "core/modules/stock/doc/";
1000
1001 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
1002 }
1003
1014 public function setCategories($categories)
1015 {
1016 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1017 return parent::setCategoriesCommon($categories, Categorie::TYPE_WAREHOUSE);
1018 }
1019
1027 public function getKanbanView($option = '', $arraydata = null)
1028 {
1029 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1030
1031 $return = '<div class="box-flex-item box-flex-grow-zero">';
1032 $return .= '<div class="info-box info-box-sm">';
1033 $return .= '<div class="info-box-icon bg-infobox-action" >';
1034 $return .= img_picto('', $this->picto);
1035 $return .= '</div>';
1036 $return .= '<div class="info-box-content" >';
1037 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1038 if ($selected >= 0) {
1039 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1040 }
1041 if (property_exists($this, 'lieu') && (!empty($this->lieu))) {
1042 $return .= '<br><span class="info-box-label opacitymedium">'.$this->lieu.'</span>';
1043 }
1044 if (property_exists($this, 'sellvalue') && $this->sellvalue != 0) {
1045 $return .= '<br><span class="info-box-label amount">'.price($this->sellvalue).'</span>';
1046 }
1047 if (method_exists($this, 'getLibStatut')) {
1048 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
1049 }
1050 $return .= '</div>';
1051 $return .= '</div>';
1052 $return .= '</div>';
1053 return $return;
1054 }
1055}
$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.
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.
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.
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:2010