dolibarr 23.0.4
stocktransfer.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
4 * Copyright (C) 2022-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
30
31//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
32//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
33
38{
39 use CommonIncoterm;
43 public $element = 'stocktransfer';
44
48 public $table_element = 'stocktransfer_stocktransfer';
49
53 public $table_element_line = 'stocktransfer_stocktransferline';
54
58 public $fk_element = 'fk_stocktransfer';
59
65 protected $childtablesoncascade = array('stocktransfer_stocktransferline');
66
72 public $ref_client;
73
77 public $ref_customer;
78
82 public $picto = 'stock';
83
87 public $date_prevue_depart;
88
92 public $date_prevue_arrivee;
93
97 public $date_reelle_depart;
98
102 public $date_reelle_arrivee;
103
107 public $origin_type;
108
109
110 const STATUS_DRAFT = 0;
111 const STATUS_VALIDATED = 1;
112 const STATUS_TRANSFERED = 2;
113 const STATUS_CLOSED = 3;
114
115
141 // BEGIN MODULEBUILDER PROPERTIES
145 public $fields = array(
146 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"),
147 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 1, 'default' => '1', 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"),
148 'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object"),
149 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'css' => 'minwidth100', 'csslist' => 'tdoverflowmax125', 'autofocusoncreate' => 1),
150 'description' => array('type' => 'text', 'label' => 'Description', 'enabled' => 1, 'position' => 31, 'notnull' => 0, 'visible' => 3,),
151 'fk_project' => array('type' => 'integer:Project:projet/class/project.class.php:1', 'label' => 'Project', 'enabled' => 'isModEnabled("project")', 'position' => 32, 'notnull' => -1, 'visible' => -1, 'index' => 1, 'picto' => 'project', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax125'),
152 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 1, 'index' => 1/*, 'help'=>"LinkToThirdparty"*/, 'picto' => 'company', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax125'),
153 'fk_warehouse_source' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt source', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1, 'help' => 'HelpWarehouseStockTransferSource', 'picto' => 'stock', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
154 'fk_warehouse_destination' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt de destination', 'enabled' => 1, 'position' => 51, 'notnull' => 0, 'visible' => 1, 'help' => 'HelpWarehouseStockTransferDestination', 'picto' => 'stock', 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150'),
155 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
156 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
157 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
158 'date_prevue_depart' => array('type' => 'date', 'label' => 'DatePrevueDepart', 'enabled' => 1, 'position' => 100, 'notnull' => 0, 'visible' => 1,),
159 'date_reelle_depart' => array('type' => 'date', 'label' => 'DateReelleDepart', 'enabled' => 1, 'position' => 101, 'notnull' => 0, 'visible' => 5,),
160 'date_prevue_arrivee' => array('type' => 'date', 'label' => 'DatePrevueArrivee', 'enabled' => 1, 'position' => 102, 'notnull' => 0, 'visible' => 1,),
161 'date_reelle_arrivee' => array('type' => 'date', 'label' => 'DateReelleArrivee', 'enabled' => 1, 'position' => 103, 'notnull' => 0, 'visible' => 5,),
162 'lead_time_for_warning' => array('type' => 'integer', 'label' => 'LeadTimeForWarning', 'enabled' => 1, 'position' => 200, 'default' => '0', 'notnull' => 0, 'visible' => 1),
163 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
164 'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
165 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'ChangedBy', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
166 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
167 'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
168 'fk_incoterms' => array('type' => 'integer', 'label' => 'IncotermCode', 'enabled' => 'isModEnabled("incoterm")', 'visible' => -2, 'position' => 220),
169 'location_incoterms' => array('type' => 'varchar(255)', 'label' => 'IncotermLabel', 'enabled' => 'isModEnabled("incoterm")', 'visible' => -2, 'position' => 225),
170 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'notnull' => 1, 'visible' => 5, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '2' => 'StockStransferDecremented', '3' => 'StockStransferIncremented'),),
171 );
175 public $rowid;
179 public $ref;
183 public $label;
184
188 public $description;
189
193 public $socid;
194
199 public $fk_soc;
203 public $lead_time_for_warning;
204
208 public $status;
209
213 public $lines;
214
218 public $fk_warehouse_source;
219
223 public $fk_warehouse_destination;
224 // END MODULEBUILDER PROPERTIES
225
226
232 public function __construct(DoliDB $db)
233 {
234 global $conf, $langs;
235
236 $this->db = $db;
237
238 $this->ismultientitymanaged = 0;
239 $this->isextrafieldmanaged = 1;
240
241 $this->origin_type = 'StockTransfer@product/stock/stocktransfer';
242
243 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
244 $this->fields['rowid']['visible'] = 0;
245 }
246 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
247 $this->fields['entity']['enabled'] = 0;
248 }
249
250 // Example to show how to set values of fields definition dynamically
251 /*if ($user->rights->stocktransfer->stocktransfer->read) {
252 $this->fields['myfield']['visible'] = 1;
253 $this->fields['myfield']['noteditable'] = 0;
254 }*/
255
256 // Unset fields that are disabled
257 foreach ($this->fields as $key => $val) {
258 if (isset($val['enabled']) && empty($val['enabled'])) {
259 unset($this->fields[$key]);
260 }
261 }
262
263 // Translate some data of arrayofkeyval
264 if (is_object($langs)) {
265 foreach ($this->fields as $key => $val) {
266 if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
267 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
268 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
269 }
270 }
271 }
272 }
273 }
274
282 public function create(User $user, $notrigger = 0)
283 {
284 $this->status = (int) $this->status;
285 if ($this->fk_warehouse_source <= 0) {
286 $this->fk_warehouse_source = 0;
287 }
288 if ($this->fk_warehouse_destination <= 0) {
289 $this->fk_warehouse_destination = 0;
290 }
291 return $this->createCommon($user, $notrigger);
292 }
293
301 public function createFromClone(User $user, $fromid)
302 {
303 global $langs, $extrafields;
304 $error = 0;
305
306 dol_syslog(__METHOD__, LOG_DEBUG);
307
308 $object = new self($this->db);
309
310 $this->db->begin();
311
312 // Load source object
313 $result = $object->fetchCommon($fromid);
314 if ($result > 0 && !empty($object->table_element_line)) {
315 $object->fetchLines();
316 }
317
318 // get lines so they will be clone
319 //foreach($this->lines as $line)
320 // $line->fetch_optionals();
321
322 // Reset some properties
323 unset($object->id);
324 unset($object->fk_user_creat);
325 unset($object->import_key);
326 unset($object->date_prevue_depart);
327 unset($object->date_prevue_arrivee);
328 unset($object->date_reelle_depart);
329 unset($object->date_reelle_arrivee);
330
331
332 // Clear fields
333 // @phan-suppress-next-line PhanTypeMismatchProperty
334 $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
335 // @phan-suppress-next-line PhanTypeInvalidDimOffset
336 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
337 $object->status = self::STATUS_DRAFT;
338 // ...
339 // Clear extrafields that are unique
340 if (is_array($object->array_options) && count($object->array_options) > 0) {
341 $extrafields->fetch_name_optionals_label($this->table_element);
342 foreach ($object->array_options as $key => $option) {
343 $shortkey = preg_replace('/options_/', '', $key);
344 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
345 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
346 unset($object->array_options[$key]);
347 }
348 }
349 }
350
351 // Create clone
352 $object->context['createfromclone'] = 'createfromclone';
353 $result = $object->createCommon($user);
354 if ($result < 0) {
355 $error++;
357 }
358
359 if (!$error) {
360 // copy internal contacts
361 if ($this->copy_linked_contact($object, 'internal') < 0) {
362 $error++;
363 }
364 }
365
366 if (!$error) {
367 // copy external contacts if same company
368 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
369 if ($this->copy_linked_contact($object, 'external') < 0) {
370 $error++;
371 }
372 }
373 }
374
375 unset($object->context['createfromclone']);
376
377 // End
378 if (!$error) {
379 $this->db->commit();
380 return $object;
381 } else {
382 $this->db->rollback();
383 return -1;
384 }
385 }
386
394 public function fetch($id, $ref = null)
395 {
396 $result = $this->fetchCommon($id, $ref);
397
398 $this->socid = $this->fk_soc;
399
400 if ($result > 0 && !empty($this->table_element_line)) {
401 $this->fetchLines();
402 }
403 return $result;
404 }
405
411 public function fetchLines()
412 {
413 require_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransferline.class.php';
414 $this->lines = array();
415
416 $result = $this->fetchLinesCommon();
417 usort($this->lines, array('StockTransfer', 'stocktransferCmpRank'));
418 return $result;
419 }
420
428 public static function stocktransferCmpRank($a, $b)
429 {
430 if ($a->rang == $b->rang) {
431 return 0;
432 }
433 return ($a->rang < $b->rang) ? -1 : 1;
434 }
435
441 public function getValorisationTotale()
442 {
443 $total_pmp = 0;
444
445 if (empty($this->lines)) {
446 $this->fetchLines();
447 }
448 if (!empty($this->lines)) {
449 foreach ($this->lines as $l) {
450 $total_pmp += ($l->pmp * $l->qty);
451 }
452 }
453
454 return $total_pmp;
455 }
456
469 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
470 {
471 dol_syslog(__METHOD__, LOG_DEBUG);
472
473 $records = array();
474
475 $sql = 'SELECT ';
476 $sql .= $this->getFieldList();
477 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
478 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
479 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
480 } else {
481 $sql .= ' WHERE 1 = 1';
482 }
483
484 // Manage filter
485 $errormessage = '';
486 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
487 if ($errormessage) {
488 $this->errors[] = $errormessage;
489 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
490 return -1;
491 }
492
493 if (!empty($sortfield)) {
494 $sql .= $this->db->order($sortfield, $sortorder);
495 }
496 if (!empty($limit)) {
497 $sql .= ' '.$this->db->plimit($limit, $offset);
498 }
499
500 $resql = $this->db->query($sql);
501 if ($resql) {
502 $num = $this->db->num_rows($resql);
503 $i = 0;
504 while ($i < ($limit ? min($limit, $num) : $num)) {
505 $obj = $this->db->fetch_object($resql);
506
507 $record = new self($this->db);
508 $record->setVarsFromFetchObj($obj);
509
510 $records[$record->id] = $record;
511
512 $i++;
513 }
514 $this->db->free($resql);
515
516 return $records;
517 } else {
518 $this->errors[] = 'Error '.$this->db->lasterror();
519 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
520
521 return -1;
522 }
523 }
524
532 public function update(User $user, $notrigger = 0)
533 {
534 $this->tms = 0; // Will be done automatically because tms field is on update cascade
535 $res = $this->updateCommon($user, $notrigger);
536 if (($this->socid > 0 || $this->fk_soc > 0) && empty($this->thirdparty)) {
537 $this->fetch_thirdparty();
538 }
539 if (empty($this->socid) && empty($this->fk_soc)) {
540 unset($this->thirdparty);
541 }
542 return $res;
543 }
544
552 public function delete(User $user, $notrigger = 0)
553 {
554 if ($this->status > self::STATUS_VALIDATED) {
555 return 0;
556 } else {
557 return $this->deleteCommon($user, $notrigger);
558 }
559 }
560
569 public function deleteLine(User $user, $idline, $notrigger = 0)
570 {
571 if ($this->status != self::STATUS_DRAFT) { // Lines are used for the stock movements once the transfer is validated
572 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
573 return -2;
574 }
575 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransferline.class.php';
576 $line = new StockTransferLine($this->db);
577 if ($line->fetch($idline) <= 0 || $line->fk_stocktransfer != $this->id) {
578 $this->error = 'ErrorRecordNotFound';
579 return -1;
580 }
581
582 $res = $this->deleteLineCommon($user, $idline, $notrigger);
583 $this->line_order(true);
584 return $res;
585 }
586
587
595 public function validate($user, $notrigger = 0)
596 {
597 global $conf;
598
599 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
600
601 $error = 0;
602
603 // Protection
604 if ($this->status == self::STATUS_VALIDATED) {
605 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
606 return 0;
607 }
608
609 $now = dol_now();
610
611 $this->db->begin();
612
613 // Define new ref
614 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
615 $num = $this->getNextNumRef();
616 } else {
617 $num = (string) $this->ref;
618 }
619 $this->newref = $num;
620
621 if (!empty($num)) {
622 // Validate
623 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
624 $sql .= " SET ref = '".$this->db->escape($num)."',";
625 $sql .= " status = ".self::STATUS_VALIDATED;
626 if (!empty($this->fields['date_validation'])) {
627 $sql .= ", date_validation = '".$this->db->idate($now)."',";
628 }
629 if (!empty($this->fields['fk_user_valid'])) { // @phan-suppress-current-line PhanTypeMismatchProperty
630 $sql .= ", fk_user_valid = ".((int) $user->id);
631 }
632 $sql .= " WHERE rowid = ".((int) $this->id);
633
634 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
635 $resql = $this->db->query($sql);
636 if (!$resql) {
637 dol_print_error($this->db);
638 $this->error = $this->db->lasterror();
639 $error++;
640 }
641
642 if (!$error && !$notrigger) {
643 // Call trigger
644 $result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user);
645 if ($result < 0) {
646 $error++;
647 }
648 // End call triggers
649 }
650 }
651
652 if (!$error) {
653 $this->oldref = $this->ref;
654
655 // Rename directory if dir was a temporary ref
656 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
657 // Now we rename also files into index
658 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
659 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
660 $resql = $this->db->query($sql);
661 if (!$resql) {
662 $error++;
663 $this->error = $this->db->lasterror();
664 }
665 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
666 $sql .= " WHERE filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
667 $resql = $this->db->query($sql);
668 if (!$resql) {
669 $error++;
670 $this->error = $this->db->lasterror();
671 }
672
673 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
674 $oldref = dol_sanitizeFileName($this->ref);
675 $newref = dol_sanitizeFileName($num);
676 $dirsource = $conf->stocktransfer->dir_output.'/stocktransfer/'.$oldref;
677 $dirdest = $conf->stocktransfer->dir_output.'/stocktransfer/'.$newref;
678 if (!$error && file_exists($dirsource)) {
679 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
680
681 if (@rename($dirsource, $dirdest)) {
682 dol_syslog("Rename ok");
683 // Rename docs starting with $oldref with $newref
684 $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransfer/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
685 foreach ($listoffiles as $fileentry) {
686 $dirsource = $fileentry['name'];
687 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
688 $dirsource = $fileentry['path'].'/'.$dirsource;
689 $dirdest = $fileentry['path'].'/'.$dirdest;
690 @rename($dirsource, $dirdest);
691 }
692 }
693 }
694 }
695 }
696
697 // Set new ref and current status
698 if (!$error) {
699 $this->ref = $num;
700 $this->status = self::STATUS_VALIDATED;
701 }
702
703 if (!$error) {
704 $this->db->commit();
705 return 1;
706 } else {
707 $this->db->rollback();
708 return -1;
709 }
710 }
711
712
720 public function setDraft($user, $notrigger = 0)
721 {
722 // Protection
723 if ($this->status <= self::STATUS_DRAFT) {
724 return 0;
725 }
726
727 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFER_UNVALIDATE');
728 }
729
737 public function cancel($user, $notrigger = 0)
738 {
739 // Protection
740 if ($this->status != self::STATUS_VALIDATED) {
741 return 0;
742 }
743
744 return $this->setStatusCommon($user, self::STATUS_CLOSED, $notrigger, 'STOCKTRANSFER_CLOSE');
745 }
746
754 public function reopen($user, $notrigger = 0)
755 {
756 // Protection
757 if ($this->status != self::STATUS_CLOSED) {
758 return 0;
759 }
760
761 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFER_REOPEN');
762 }
763
774 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
775 {
776 global $conf, $langs, $hookmanager;
777
778 if (!empty($conf->dol_no_mouse_hover)) {
779 $notooltip = 1;
780 } // Force disable tooltips
781
782 $result = '';
783
784 $label = '<u>'.$langs->trans("StockTransfer").'</u>';
785 $label .= '<br>';
786 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
787 if (isset($this->status)) {
788 $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
789 }
790
791 $url = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$this->id;
792
793 if ($option != 'nolink') {
794 // Add param to save lastsearch_values or not
795 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
796 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
797 $add_save_lastsearch_values = 1;
798 }
799 if ($add_save_lastsearch_values) {
800 $url .= '&save_lastsearch_values=1';
801 }
802 }
803
804 $linkclose = '';
805 if (empty($notooltip)) {
806 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
807 $label = $langs->trans("ShowStockTransfer");
808 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
809 }
810 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
811 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
812 } else {
813 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
814 }
815
816 $linkstart = '<a href="'.$url.'"';
817 $linkstart .= $linkclose.'>';
818 $linkend = '</a>';
819
820 $result .= $linkstart;
821
822 if (empty($this->showphoto_on_popup)) {
823 if ($withpicto) {
824 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
825 }
826 } else {
827 if ($withpicto) {
828 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
829
830 list($class, $module) = explode('@', $this->picto);
831 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
832 $filearray = dol_dir_list($upload_dir, "files");
833 $filename = $filearray[0]['name'];
834 if (!empty($filename)) {
835 $pospoint = strpos($filearray[0]['name'], '.');
836
837 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
838 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
839 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
840 } else {
841 $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
842 }
843
844 $result .= '</div>';
845 } else {
846 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
847 }
848 }
849 }
850
851 if ($withpicto != 2) {
852 $result .= $this->ref;
853 }
854
855 $result .= $linkend;
856 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
857
858 global $action, $hookmanager;
859 $hookmanager->initHooks(array('stocktransferdao'));
860 $parameters = array('id' => $this->id, 'getnomurl' => $result);
861 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
862 if ($reshook > 0) {
863 $result = $hookmanager->resPrint;
864 } else {
865 $result .= $hookmanager->resPrint;
866 }
867
868 return $result;
869 }
870
877 public function getLibStatut($mode = 0)
878 {
879 return $this->LibStatut($this->status, $mode);
880 }
881
882 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
890 public function LibStatut($status, $mode = 0)
891 {
892 // phpcs:enable
893 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
894 global $langs;
895 //$langs->load("stocktransfer@stocktransfer");
896 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
897 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
898 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented');
899 $this->labelStatus[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented');
900 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
901 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
902 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented');
903 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented');
904 }
905
906 $statusType = 'status'.$status;
907 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
908 if ($status == self::STATUS_CLOSED) {
909 $statusType = 'status6';
910 }
911
912 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
913 }
914
921 public function info($id)
922 {
923 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
924 $sql .= ' fk_user_creat, fk_user_modif';
925 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
926 $sql .= ' WHERE t.rowid = '.((int) $id);
927 $result = $this->db->query($sql);
928 if ($result) {
929 if ($this->db->num_rows($result)) {
930 $obj = $this->db->fetch_object($result);
931 $this->id = $obj->rowid;
932
933 $this->user_creation_id = $obj->fk_user_creat;
934 $this->user_modification_id = $obj->fk_user_modif;
935 $this->date_creation = $this->db->jdate($obj->datec);
936 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
937 }
938
939 $this->db->free($result);
940 } else {
941 dol_print_error($this->db);
942 }
943 }
944
951 public function initAsSpecimen()
952 {
953 return $this->initAsSpecimenCommon();
954 }
955
961 public function getLinesArray()
962 {
963 $this->lines = array();
964
965 $objectline = new StockTransferLine($this->db);
966 $result = $objectline->fetchAll('ASC', 'rang', 0, 0, "(fk_stocktransfer:=:".((int) $this->id).")");
967
968 if (is_numeric($result)) {
969 $this->error = $objectline->error;
970 $this->errors = $objectline->errors;
971 return $result;
972 } else {
973 $this->lines = $result;
974 return $this->lines;
975 }
976 }
977
983 public function getNextNumRef()
984 {
985 global $langs, $conf;
986 $langs->load("stocks");
987
988 if (!getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) {
989 $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON = 'mod_stocktransfer_standard';
990 }
991
992 if (getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) {
993 $mybool = false;
994
995 $file = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON') . ".php";
996 $classname = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON');
997
998 // Include file with class
999 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1000 foreach ($dirmodels as $reldir) {
1001 $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
1002
1003 // Load file with numbering class (if found)
1004 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1005 }
1006
1007 if (!$mybool) {
1008 dol_print_error(null, "Failed to include file ".$file);
1009 return '';
1010 }
1011
1012 if (class_exists($classname)) {
1013 $obj = new $classname();
1014 '@phan-var-force ModeleNumRefStockTransfer $obj';
1015 $numref = $obj->getNextValue($this);
1016
1017 if ($numref != '' && $numref != '-1') {
1018 return $numref;
1019 } else {
1020 $this->error = $obj->error;
1021 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1022 return "";
1023 }
1024 } else {
1025 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1026 return "";
1027 }
1028 } else {
1029 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1030 return "";
1031 }
1032 }
1033
1045 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1046 {
1047 global $langs;
1048
1049 $langs->load("stocks");
1050
1051 if (!dol_strlen($modele)) {
1052 $modele = 'eagle';
1053
1054 if ($this->model_pdf) {
1055 $modele = $this->model_pdf;
1056 } elseif (getDolGlobalString('STOCKTRANSFER_ADDON_PDF')) {
1057 $modele = getDolGlobalString('STOCKTRANSFER_ADDON_PDF');
1058 }
1059 }
1060
1061 $modelpath = "core/modules/stocktransfer/doc/";
1062
1063 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1064
1065 return $result;
1066 }
1067}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
setErrorsFromObject($object)
setErrorsFromObject
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class for StockTransfer.
getValorisationTotale()
Used to get total PMP amount of all quantities of products of Stock Transfer.
update(User $user, $notrigger=0)
Update object into database.
static stocktransferCmpRank($a, $b)
Used to sort lines by rank.
fetch($id, $ref=null)
Load object in memory from the database.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
LibStatut($status, $mode=0)
Return the status.
fetchLines()
Load object lines in memory from the database.
validate($user, $notrigger=0)
Validate object.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
setDraft($user, $notrigger=0)
Set draft status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
create(User $user, $notrigger=0)
Create object into database.
reopen($user, $notrigger=0)
Set back to validated status.
getLibStatut($mode=0)
Return label of the status.
info($id)
Load the info information in the object.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
__construct(DoliDB $db)
Constructor.
createFromClone(User $user, $fromid)
Clone an object into another one.
getLinesArray()
Create an array of lines.
cancel($user, $notrigger=0)
Set cancel status.
Class for StockTransferLine.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.