dolibarr 25.0.0-alpha
stocktransferline.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) 2024-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 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/commonobjectline.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
30//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
31
36{
40 public $element = 'stocktransferline';
41
45 public $table_element = 'stocktransfer_stocktransferline';
46
50 public $picto = 'stocktransferline@stocktransfer';
51
52 const STATUS_DRAFT = 0;
53 const STATUS_VALIDATED = 1;
54 const STATUS_CANCELED = 9;
55
56
82 // BEGIN MODULEBUILDER PROPERTIES
86 public $fields = array(
87 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => "Id"),
88 'amount' => array('type' => 'price', 'label' => 'Amount', 'enabled' => 1, 'position' => 40, 'notnull' => 0, 'visible' => 1, 'default' => 'null', 'isameasure' => 1, 'help' => "Help text for amount",),
89 'qty' => array('type' => 'real', 'label' => 'Qty', 'enabled' => 1, 'position' => 45, 'notnull' => 0, 'visible' => 1, 'default' => '0', 'isameasure' => 1, 'css' => 'maxwidth75imp', 'help' => "Help text for quantity",),
90 'fk_warehouse_destination' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt de destination', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1,),
91 'fk_warehouse_source' => array('type' => 'integer:Entrepot:product/stock/class/entrepot.class.php', 'label' => 'Entrepôt source', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1,),
92 'fk_stocktransfer' => array('type' => 'integer:StockTransfer:stocktransfer/stock/class/stocktransfer.class.php', 'label' => 'StockTransfer', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 0,),
93 'fk_product' => array('type' => 'integer:Product:product/class/product.class.php', 'label' => 'Product', 'enabled' => 1, 'position' => 50, 'notnull' => 1, 'visible' => 1,),
94 'batch' => array('type' => 'varchar(128)', 'label' => 'Batch', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => 1,),
95 'pmp' => array('type' => 'double'/*, 'help'=>'THMEstimatedHelp'*/, 'label' => 'PMP', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 1,),
96 'rang' => array('type' => 'integer', 'label' => 'Qty', 'enabled' => 1, 'position' => 45, 'notnull' => 0, 'visible' => 0, 'default' => '0', 'isameasure' => 1, 'css' => 'maxwidth75imp', 'help' => "Help text for quantity",),
97 );
101 public $rowid;
105 public $amount;
106
110 public $qty;
114 public $fk_warehouse_destination;
118 public $fk_warehouse_source;
122 public $fk_stocktransfer;
126 public $fk_product;
130 public $batch;
131
135 public $pmp;
136
137 // END MODULEBUILDER PROPERTIES
138
139
145 public function __construct(DoliDB $db)
146 {
147 global $conf, $langs;
148
149 $this->db = $db;
150
151 $this->ismultientitymanaged = 0;
152 $this->isextrafieldmanaged = 1;
153
154 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
155 $this->fields['rowid']['visible'] = 0;
156 }
157 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
158 $this->fields['entity']['enabled'] = 0;
159 }
160
161 // Example to show how to set values of fields definition dynamically
162 /*if ($user->rights->stocktransfer->stocktransferline->read) {
163 $this->fields['myfield']['visible'] = 1;
164 $this->fields['myfield']['noteditable'] = 0;
165 }*/
166
167 // Unset fields that are disabled
168 foreach ($this->fields as $key => $val) {
169 if (isset($val['enabled']) && empty($val['enabled'])) {
170 unset($this->fields[$key]);
171 }
172 }
173
174 // Translate some data of arrayofkeyval
175 if (is_object($langs)) {
176 foreach ($this->fields as $key => $val) {
177 if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
178 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
179 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
180 }
181 }
182 }
183 }
184 }
185
193 public function create(User $user, $notrigger = 0)
194 {
195 return $this->createCommon($user, $notrigger);
196 }
197
205 public function createFromClone(User $user, $fromid)
206 {
207 global $extrafields;
208 $error = 0;
209
210 dol_syslog(__METHOD__, LOG_DEBUG);
211
212 $object = new self($this->db);
213
214 $this->db->begin();
215
216 // Load source object
217 $result = $object->fetchCommon($fromid);
218 if ($result > 0 && !empty($object->table_element_line)) {
219 $object->fetchLines();
220 }
221
222 // get lines so they will be clone
223 //foreach($this->lines as $line)
224 // $line->fetch_optionals();
225
226 // Reset some properties
227 unset($object->id);
228 unset($object->import_key);
229
230
231 // Clear fields
232 $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
233 $object->status = self::STATUS_DRAFT;
234 // ...
235 // Clear extrafields that are unique
236 if (is_array($object->array_options) && count($object->array_options) > 0) {
237 $extrafields->fetch_name_optionals_label($this->table_element);
238 foreach ($object->array_options as $key => $option) {
239 $shortkey = preg_replace('/options_/', '', $key);
240 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
241 unset($object->array_options[$key]);
242 }
243 }
244 }
245
246 // Create clone
247 $object->context['createfromclone'] = 'createfromclone';
248 $result = $object->createCommon($user);
249 if ($result < 0) {
250 $error++;
252 }
253
254 if (!$error) {
255 // copy internal contacts
256 if ($this->copy_linked_contact($object, 'internal') < 0) {
257 $error++;
258 }
259 }
260
261 unset($object->context['createfromclone']);
262
263 // End
264 if (!$error) {
265 $this->db->commit();
266 return $object;
267 } else {
268 $this->db->rollback();
269 return -1;
270 }
271 }
272
280 public function fetch($id, $ref = null)
281 {
282 $result = $this->fetchCommon($id, $ref);
283 if ($result > 0 && !empty($this->table_element_line)) {
284 $this->fetchLines();
285 }
286 return $result;
287 }
288
294 public function fetchLines()
295 {
296 $this->lines = array();
297
298 $result = $this->fetchLinesCommon();
299 return $result;
300 }
301
302
315 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
316 {
317 dol_syslog(__METHOD__, LOG_DEBUG);
318
319 $records = array();
320
321 $sql = 'SELECT ';
322 $sql .= $this->getFieldList();
323 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
324 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
325 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
326 } else {
327 $sql .= ' WHERE 1 = 1';
328 }
329
330 // Manage filter
331 $errormessage = '';
332 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
333 if ($errormessage) {
334 $this->errors[] = $errormessage;
335 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
336 return -1;
337 }
338
339 if (!empty($sortfield)) {
340 $sql .= $this->db->order($sortfield, $sortorder);
341 }
342 if (!empty($limit)) {
343 $sql .= ' '.$this->db->plimit($limit, $offset);
344 }
345
346 $resql = $this->db->query($sql);
347 if ($resql) {
348 $num = $this->db->num_rows($resql);
349 $i = 0;
350 while ($i < ($limit ? min($limit, $num) : $num)) {
351 $obj = $this->db->fetch_object($resql);
352
353 $record = new self($this->db);
354 $record->setVarsFromFetchObj($obj);
355
356 $records[$record->id] = $record;
357
358 $i++;
359 }
360 $this->db->free($resql);
361
362 return $records;
363 } else {
364 $this->errors[] = 'Error '.$this->db->lasterror();
365 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
366
367 return -1;
368 }
369 }
370
378 public function update(User $user, $notrigger = 0)
379 {
380 return $this->updateCommon($user, $notrigger);
381 }
382
390 public function delete(User $user, $notrigger = 0)
391 {
392 return $this->deleteCommon($user, $notrigger);
393 //return $this->deleteCommon($user, $notrigger, 1);
394 }
395
404 public function deleteLine(User $user, $idline, $notrigger = 0)
405 {
406 if ($this->status < 0) {
407 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
408 return -2;
409 }
410
411 return $this->deleteLineCommon($user, $idline, $notrigger);
412 }
413
423 public function doStockMovement($label, $code_inv, $fk_entrepot, $direction = 1)
424 {
425 global $user, $langs;
426
427 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
428 include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
429 include_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransfer.class.php';
430
431 $p = new Product($this->db);
432 $p->fetch($this->fk_product);
433
434 $op = array();
435 $op[0] = "+".trim((string) $this->qty);
436 $op[1] = "-".trim((string) $this->qty);
437 $movementstock = new MouvementStock($this->db);
438 $st = new StockTransfer($this->db);
439 $movementstock->origin_type = $st->origin_type;
440 $movementstock->origin_id = $this->fk_stocktransfer;
441
442 if (empty($this->batch)) { // no batch for line
443 $result = $movementstock->_create(
444 $user,
445 $p->id,
446 $fk_entrepot,
447 (float) $op[$direction],
448 $direction,
449 empty($direction) ? $this->pmp : 0,
450 $label,
451 $code_inv
452 );
453
454 if ($result < 0) {
455 $this->setErrorsFromObject($movementstock);
456 return -1;
457 }
458 } else {
459 if ($p->hasbatch()) {
460 $arraybatchinfo = $p->loadBatchInfo($this->batch);
461 if (count($arraybatchinfo) > 0) {
462 $firstrecord = array_shift($arraybatchinfo);
463 $dlc = $firstrecord['eatby'];
464 $dluo = $firstrecord['sellby'];
465 } else {
466 $dlc = '';
467 $dluo = '';
468 }
469
470 $result = $movementstock->_create(
471 $user,
472 $p->id,
473 $fk_entrepot,
474 (float) $op[$direction],
475 $direction,
476 empty($direction) ? $this->pmp : 0,
477 $label,
478 $code_inv,
479 '',
480 $dlc,
481 $dluo,
482 $this->batch
483 );
484
485 if ($result < 0) {
486 $this->setErrorsFromObject($movementstock);
487 return $result;
488 }
489 } else {
490 $this->error = $langs->trans('StockTransferNoBatchForProduct', $p->getNomUrl());
491 $this->errors[] = $this->error;
492 return -1;
493 }
494 }
495
496 return 1;
497 }
498
506 public function validate($user, $notrigger = 0)
507 {
508 global $conf, $langs;
509
510 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
511
512 $error = 0;
513
514 // Protection
515 if ($this->status == self::STATUS_VALIDATED) {
516 dol_syslog(get_class($this)."::validate action abandoned: already validated", LOG_WARNING);
517 return 0;
518 }
519
520 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransferline->write))
521 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransferline->stocktransferline_advance->validate))))
522 {
523 $this->error='NotEnoughPermissions';
524 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
525 return -1;
526 }*/
527
528 $now = dol_now();
529
530 $this->db->begin();
531
532 // Define new ref
533 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
534 $num = $this->getNextNumRef();
535 } else {
536 $num = (string) $this->ref;
537 }
538 $this->newref = $num;
539
540 if (!empty($num)) {
541 // Validate
542 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
543 $sql .= " SET ref = '".$this->db->escape($num)."',";
544 $sql .= " status = ".self::STATUS_VALIDATED;
545 if (!empty($this->fields['date_validation'])) {
546 $sql .= ", date_validation = '".$this->db->idate($now)."',";
547 }
548 if (!empty($this->fields['fk_user_valid'])) {
549 $sql .= ", fk_user_valid = ".((int) $user->id);
550 }
551 $sql .= " WHERE rowid = ".((int) $this->id);
552
553 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
554 $resql = $this->db->query($sql);
555 if (!$resql) {
556 dol_print_error($this->db);
557 $this->error = $this->db->lasterror();
558 $error++;
559 }
560
561 if (!$error && !$notrigger) {
562 // Call trigger
563 $result = $this->call_trigger('STOCKTRANSFERLINE_VALIDATE', $user);
564 if ($result < 0) {
565 $error++;
566 }
567 // End call triggers
568 }
569 }
570
571 if (!$error) {
572 $this->oldref = $this->ref;
573
574 // Rename directory if dir was a temporary ref
575 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
576 // Now we rename also files into index
577 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransferline/".$this->db->escape($this->newref)."'";
578 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
579 $resql = $this->db->query($sql);
580 if (!$resql) {
581 $error++;
582 $this->error = $this->db->lasterror();
583 }
584 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'stocktransferline/".$this->db->escape($this->newref)."'";
585 $sql .= " WHERE filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
586 $resql = $this->db->query($sql);
587 if (!$resql) {
588 $error++;
589 $this->error = $this->db->lasterror();
590 }
591
592 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
593 $oldref = dol_sanitizeFileName($this->ref);
594 $newref = dol_sanitizeFileName($num);
595 $dirsource = $conf->stocktransfer->dir_output.'/stocktransferline/'.$oldref;
596 $dirdest = $conf->stocktransfer->dir_output.'/stocktransferline/'.$newref;
597 if (!$error && file_exists($dirsource)) {
598 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
599
600 if (@rename($dirsource, $dirdest)) {
601 dol_syslog("Rename ok");
602 // Rename docs starting with $oldref with $newref
603 $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransferline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
604 foreach ($listoffiles as $fileentry) {
605 $dirsource = $fileentry['name'];
606 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
607 $dirsource = $fileentry['path'].'/'.$dirsource;
608 $dirdest = $fileentry['path'].'/'.$dirdest;
609 @rename($dirsource, $dirdest);
610 }
611 }
612 }
613 }
614 }
615
616 // Set new ref and current status
617 if (!$error) {
618 $this->ref = $num;
619 $this->status = self::STATUS_VALIDATED;
620 }
621
622 if (!$error) {
623 $this->db->commit();
624 return 1;
625 } else {
626 $this->db->rollback();
627 return -1;
628 }
629 }
630
631
639 public function setDraft($user, $notrigger = 0)
640 {
641 // Protection
642 if ($this->status <= self::STATUS_DRAFT) {
643 return 0;
644 }
645
646 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
647 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
648 {
649 $this->error='Permission denied';
650 return -1;
651 }*/
652
653 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFERLINE_UNVALIDATE');
654 }
655
663 public function cancel($user, $notrigger = 0)
664 {
665 // Protection
666 if ($this->status != self::STATUS_VALIDATED) {
667 return 0;
668 }
669
670 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
671 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
672 {
673 $this->error='Permission denied';
674 return -1;
675 }*/
676
677 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'STOCKTRANSFERLINE_CLOSE');
678 }
679
687 public function reopen($user, $notrigger = 0)
688 {
689 // Protection
690 if ($this->status != self::STATUS_CANCELED) {
691 return 0;
692 }
693
694 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
695 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
696 {
697 $this->error='Permission denied';
698 return -1;
699 }*/
700
701 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFERLINE_REOPEN');
702 }
703
714 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
715 {
716 global $conf, $langs, $hookmanager;
717
718 if (!empty($conf->dol_no_mouse_hover)) {
719 $notooltip = 1;
720 } // Force disable tooltips
721
722 $result = '';
723
724 $label = '<u>'.$langs->trans("StockTransferLine").'</u>';
725 $label .= '<br>';
726 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
727 if (isset($this->status)) {
728 $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
729 }
730
731 $url = dol_buildpath('/stocktransfer/stocktransferline_card.php', 1).'?id='.$this->id;
732
733 if ($option != 'nolink') {
734 // Add param to save lastsearch_values or not
735 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
736 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
737 $add_save_lastsearch_values = 1;
738 }
739 if ($add_save_lastsearch_values) {
740 $url .= '&save_lastsearch_values=1';
741 }
742 }
743
744 $linkclose = '';
745 if (empty($notooltip)) {
746 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
747 $label = $langs->trans("ShowStockTransferLine");
748 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
749 }
750 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
751 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
752 } else {
753 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
754 }
755
756 $linkstart = '<a href="'.$url.'"';
757 $linkstart .= $linkclose.'>';
758 $linkend = '</a>';
759
760 $result .= $linkstart;
761
762 if (empty($this->showphoto_on_popup)) {
763 if ($withpicto) {
764 $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);
765 }
766 } else {
767 if ($withpicto) {
768 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
769
770 list($class, $module) = explode('@', $this->picto);
771 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
772 $filearray = dol_dir_list($upload_dir, "files");
773 $filename = $filearray[0]['name'];
774 if (!empty($filename)) {
775 $pospoint = strpos($filearray[0]['name'], '.');
776
777 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.dol_substr($filename, 0, $pospoint).'_mini'.dol_substr($filename, $pospoint);
778 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
779 $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>';
780 } else {
781 $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>';
782 }
783
784 $result .= '</div>';
785 } else {
786 $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);
787 }
788 }
789 }
790
791 if ($withpicto != 2) {
792 $result .= $this->ref;
793 }
794
795 $result .= $linkend;
796 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
797
798 global $action, $hookmanager;
799 $hookmanager->initHooks(array('stocktransferlinedao'));
800 $parameters = array('id' => $this->id, 'getnomurl' => $result);
801 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
802 if ($reshook > 0) {
803 $result = $hookmanager->resPrint;
804 } else {
805 $result .= $hookmanager->resPrint;
806 }
807
808 return $result;
809 }
810
817 public function getLibStatut($mode = 0)
818 {
819 return $this->LibStatut($this->status, $mode);
820 }
821
822 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
830 public function LibStatut($status, $mode = 0)
831 {
832 // phpcs:enable
833 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
834 global $langs;
835 //$langs->load("stocktransfer@stocktransfer");
836 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
837 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
838 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
839 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
840 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
841 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
842 }
843
844 $statusType = 'status'.$status;
845 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
846 if ($status == self::STATUS_CANCELED) {
847 $statusType = 'status6';
848 }
849
850 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
851 }
852
859 public function info($id)
860 {
861 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
862 $sql .= ' fk_user_creat, fk_user_modif';
863 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
864 $sql .= ' WHERE t.rowid = '.((int) $id);
865 $result = $this->db->query($sql);
866 if ($result) {
867 if ($this->db->num_rows($result)) {
868 $obj = $this->db->fetch_object($result);
869 $this->id = $obj->rowid;
870
871 $this->user_creation_id = $obj->fk_user_creat;
872 $this->user_modification_id = $obj->fk_user_modif;
873 $this->date_creation = $this->db->jdate($obj->datec);
874 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
875 }
876
877 $this->db->free($result);
878 } else {
879 dol_print_error($this->db);
880 }
881 }
882
889 public function initAsSpecimen()
890 {
891 return $this->initAsSpecimenCommon();
892 }
893
899 public function getNextNumRef()
900 {
901 global $langs, $conf;
902 $langs->load("stocks");
903
904 if (!getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON')) {
905 $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON = 'mod_stocktransferline_standard';
906 }
907
908 if (getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON')) {
909 $mybool = false;
910
911 $file = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON') . ".php";
912 $classname = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON');
913
914 // Include file with class
915 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
916 foreach ($dirmodels as $reldir) {
917 $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
918
919 // Load file with numbering class (if found)
920 $mybool = ((bool) @include_once $dir.$file) || $mybool;
921 }
922
923 if (!$mybool) {
924 dol_print_error(null, "Failed to include file ".$file);
925 return '';
926 }
927
928 if (class_exists($classname)) {
929 $obj = new $classname();
930 '@phan-var-force ModeleNumRefStockTransfer $obj';
931 $numref = $obj->getNextValue($this);
932
933 if ($numref != '' && $numref != '-1') {
934 return $numref;
935 } else {
936 $this->error = $obj->error;
937 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
938 return "";
939 }
940 } else {
941 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
942 return "";
943 }
944 } else {
945 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
946 return "";
947 }
948 }
949
961 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
962 {
963 global $conf, $langs;
964
965 $result = 0;
966 $includedocgeneration = 0;
967
968 $langs->load("stocks");
969
970 if (!dol_strlen($modele)) {
971 $modele = 'standard_stocktransferline';
972
973 if (!empty($this->model_pdf)) {
974 $modele = $this->model_pdf;
975 } elseif (getDolGlobalString('STOCKTRANSFERLINE_ADDON_PDF')) {
976 $modele = getDolGlobalString('STOCKTRANSFERLINE_ADDON_PDF');
977 }
978 }
979
980 $modelpath = "core/modules/stocktransfer/doc/";
981
982 if ($includedocgeneration) {
983 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
984 }
985
986 return $result;
987 }
988
996 public function doScheduledJob()
997 {
998 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
999
1000 $error = 0;
1001 $this->output = '';
1002 $this->error = '';
1003
1004 dol_syslog(__METHOD__, LOG_DEBUG);
1005
1006 $now = dol_now();
1007
1008 $this->db->begin();
1009
1010 // ...
1011
1012 $this->db->commit();
1013
1014 return $error;
1015 }
1016}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
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.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage stock movements.
Class to manage products or services.
Class for StockTransfer.
Class for StockTransferLine.
reopen($user, $notrigger=0)
Set back to validated status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getLibStatut($mode=0)
Return label of the status.
setDraft($user, $notrigger=0)
Set draft status.
fetch($id, $ref=null)
Load object in memory from the database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
__construct(DoliDB $db)
Constructor.
fetchLines()
Load object lines in memory from the database.
validate($user, $notrigger=0)
Validate object.
cancel($user, $notrigger=0)
Set cancel status.
doStockMovement($label, $code_inv, $fk_entrepot, $direction=1)
Makes all stock movements (add quantity, remove quantity or cancel all actions)
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
createFromClone(User $user, $fromid)
Clone an object into another one.
LibStatut($status, $mode=0)
Return the status.
info($id)
Load the info information in the object.
update(User $user, $notrigger=0)
Update object into database.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
create(User $user, $notrigger=0)
Create object into database.
deleteLine(User $user, $idline, $notrigger=0)
Delete a line of object in database.
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:169
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:66
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.