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