dolibarr 19.0.3
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) ---Put here your own copyright and developer email---
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Put here all includes required by your class file
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php';
28//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
29//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
30
35{
39 public $element = 'stocktransferline';
40
44 public $table_element = 'stocktransfer_stocktransferline';
45
50 public $ismultientitymanaged = 0;
51
55 public $isextrafieldmanaged = 1;
56
60 public $picto = 'stocktransferline@stocktransfer';
61
62
63 const STATUS_DRAFT = 0;
64 const STATUS_VALIDATED = 1;
65 const STATUS_CANCELED = 9;
66
67
93 // BEGIN MODULEBUILDER PROPERTIES
97 public $fields=array(
98 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
99 'amount' => array('type'=>'price', 'label'=>'Amount', 'enabled'=>'1', 'position'=>40, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"Help text for amount",),
100 '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",),
101 '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,),
102 '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,),
103 'fk_stocktransfer' => array('type'=>'integer:StockTransfer:stocktransfer/stock/class/stocktransfer.class.php', 'label'=>'StockTransfer', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>0,),
104 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php', 'label'=>'Product', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>1,),
105 'batch' => array('type'=>'varchar(128)', 'label'=>'Batch', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>1,),
106 'pmp' => array('type'=>'double'/*, 'help'=>'THMEstimatedHelp'*/, 'label'=>'PMP', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1,),
107 '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",),
108 );
109 public $rowid;
110 public $amount;
111 public $qty;
112 public $fk_warehouse_destination;
113 public $fk_warehouse_source;
114 public $fk_stocktransfer;
115 public $fk_product;
116 public $batch;
117
121 public $pmp;
122
123 // END MODULEBUILDER PROPERTIES
124
125
131 public function __construct(DoliDB $db)
132 {
133 global $conf, $langs;
134
135 $this->db = $db;
136
137 if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
138 $this->fields['rowid']['visible'] = 0;
139 }
140 if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
141 $this->fields['entity']['enabled'] = 0;
142 }
143
144 // Example to show how to set values of fields definition dynamically
145 /*if ($user->rights->stocktransfer->stocktransferline->read) {
146 $this->fields['myfield']['visible'] = 1;
147 $this->fields['myfield']['noteditable'] = 0;
148 }*/
149
150 // Unset fields that are disabled
151 foreach ($this->fields as $key => $val) {
152 if (isset($val['enabled']) && empty($val['enabled'])) {
153 unset($this->fields[$key]);
154 }
155 }
156
157 // Translate some data of arrayofkeyval
158 if (is_object($langs)) {
159 foreach ($this->fields as $key => $val) {
160 if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
161 foreach ($val['arrayofkeyval'] as $key2 => $val2) {
162 $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
163 }
164 }
165 }
166 }
167 }
168
176 public function create(User $user, $notrigger = false)
177 {
178 return $this->createCommon($user, $notrigger);
179 }
180
188 public function createFromClone(User $user, $fromid)
189 {
190 global $langs, $extrafields;
191 $error = 0;
192
193 dol_syslog(__METHOD__, LOG_DEBUG);
194
195 $object = new self($this->db);
196
197 $this->db->begin();
198
199 // Load source object
200 $result = $object->fetchCommon($fromid);
201 if ($result > 0 && !empty($object->table_element_line)) {
202 $object->fetchLines();
203 }
204
205 // get lines so they will be clone
206 //foreach($this->lines as $line)
207 // $line->fetch_optionals();
208
209 // Reset some properties
210 unset($object->id);
211 unset($object->import_key);
212
213
214 // Clear fields
215 $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
216 $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
217 $object->status = self::STATUS_DRAFT;
218 // ...
219 // Clear extrafields that are unique
220 if (is_array($object->array_options) && count($object->array_options) > 0) {
221 $extrafields->fetch_name_optionals_label($this->table_element);
222 foreach ($object->array_options as $key => $option) {
223 $shortkey = preg_replace('/options_/', '', $key);
224 if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
225 //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
226 unset($object->array_options[$key]);
227 }
228 }
229 }
230
231 // Create clone
232 $object->context['createfromclone'] = 'createfromclone';
233 $result = $object->createCommon($user);
234 if ($result < 0) {
235 $error++;
236 $this->error = $object->error;
237 $this->errors = $object->errors;
238 }
239
240 if (!$error) {
241 // copy internal contacts
242 if ($this->copy_linked_contact($object, 'internal') < 0) {
243 $error++;
244 }
245 }
246
247 if (!$error) {
248 // copy external contacts if same company
249 if (property_exists($this, 'socid') && $this->socid == $object->socid) {
250 if ($this->copy_linked_contact($object, 'external') < 0) {
251 $error++;
252 }
253 }
254 }
255
256 unset($object->context['createfromclone']);
257
258 // End
259 if (!$error) {
260 $this->db->commit();
261 return $object;
262 } else {
263 $this->db->rollback();
264 return -1;
265 }
266 }
267
275 public function fetch($id, $ref = null)
276 {
277 $result = $this->fetchCommon($id, $ref);
278 if ($result > 0 && !empty($this->table_element_line)) {
279 $this->fetchLines();
280 }
281 return $result;
282 }
283
289 public function fetchLines()
290 {
291 $this->lines = array();
292
293 $result = $this->fetchLinesCommon();
294 return $result;
295 }
296
297
309 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
310 {
311 dol_syslog(__METHOD__, LOG_DEBUG);
312
313 $records = array();
314
315 $sql = 'SELECT ';
316 $sql .= $this->getFieldList();
317 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
318 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
319 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
320 } else {
321 $sql .= ' WHERE 1 = 1';
322 }
323 // Manage filter
324 $sqlwhere = array();
325 if (count($filter) > 0) {
326 foreach ($filter as $key => $value) {
327 if ($key == 't.rowid') {
328 $sqlwhere[] = $key.'='.$value;
329 } elseif (strpos($key, 'date') !== false) {
330 $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
331 } elseif ($key == 'customsql') {
332 $sqlwhere[] = $value;
333 } else {
334 $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
335 }
336 }
337 }
338 if (count($sqlwhere) > 0) {
339 $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
340 }
341
342 if (!empty($sortfield)) {
343 $sql .= $this->db->order($sortfield, $sortorder);
344 }
345 if (!empty($limit)) {
346 $sql .= ' '.$this->db->plimit($limit, $offset);
347 }
348
349 $resql = $this->db->query($sql);
350 if ($resql) {
351 $num = $this->db->num_rows($resql);
352 $i = 0;
353 while ($i < ($limit ? min($limit, $num) : $num)) {
354 $obj = $this->db->fetch_object($resql);
355
356 $record = new self($this->db);
357 $record->setVarsFromFetchObj($obj);
358
359 $records[$record->id] = $record;
360
361 $i++;
362 }
363 $this->db->free($resql);
364
365 return $records;
366 } else {
367 $this->errors[] = 'Error '.$this->db->lasterror();
368 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
369
370 return -1;
371 }
372 }
373
381 public function update(User $user, $notrigger = false)
382 {
383 return $this->updateCommon($user, $notrigger);
384 }
385
393 public function delete(User $user, $notrigger = false)
394 {
395 return $this->deleteCommon($user, $notrigger);
396 //return $this->deleteCommon($user, $notrigger, 1);
397 }
398
407 public function deleteLine(User $user, $idline, $notrigger = false)
408 {
409 if ($this->status < 0) {
410 $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
411 return -2;
412 }
413
414 return $this->deleteLineCommon($user, $idline, $notrigger);
415 }
416
426 public function doStockMovement($label, $code_inv, $fk_entrepot, $direction = 1)
427 {
428 global $conf, $user, $langs;
429
430 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
431 include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
432 include_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransfer.class.php';
433
434 $p = new Product($this->db);
435 $p->fetch($this->fk_product);
436
437 $op[0] = "+".trim($this->qty);
438 $op[1] = "-".trim($this->qty);
439 $movementstock = new MouvementStock($this->db);
440 $st = new StockTransfer($this->db);
441 $movementstock->origin_type = $st->origin_type;
442 $movementstock->origin_id = $this->fk_stocktransfer;
443
444 if (empty($this->batch)) { // no batch for line
445 /*$result = $p->correct_stock(
446 $user,
447 $fk_entrepot,
448 $this->qty,
449 $direction, // 1=décrémentation
450 $label,
451 empty($direction) ? $this->pmp : 0,
452 GETPOST('inventorycode', 'alphanohtml'),
453 'stocktransfer',
454 $this->fk_stocktransfer
455 );*/
456
457 $result = $movementstock->_create(
458 $user,
459 $p->id,
460 $fk_entrepot,
461 $op[$direction],
462 $direction,
463 empty($direction) ? $this->pmp : 0,
464 $label,
465 $code_inv
466 );
467
468 if ($result < 0) {
469 setEventMessages($p->error, $p->errors, 'errors');
470 return 0;
471 }
472 } else {
473 if ($p->hasbatch()) {
474 $arraybatchinfo = $p->loadBatchInfo($this->batch);
475 if (count($arraybatchinfo) > 0) {
476 $firstrecord = array_shift($arraybatchinfo);
477 $dlc = $firstrecord['eatby'];
478 $dluo = $firstrecord['sellby'];
479 //var_dump($batch); var_dump($arraybatchinfo); var_dump($firstrecord); var_dump($dlc); var_dump($dluo); exit;
480 } else {
481 $dlc = '';
482 $dluo = '';
483 }
484
485 /*$result = $p->correct_stock_batch(
486 $user,
487 $fk_entrepot,
488 $this->qty,
489 $direction,
490 $label,
491 empty($direction) ? $this->pmp : 0,
492 $dlc,
493 $dluo,
494 $this->batch,
495 GETPOST("codemove")
496 );*/
497
498 $result = $movementstock->_create(
499 $user,
500 $p->id,
501 $fk_entrepot,
502 $op[$direction],
503 $direction,
504 empty($direction) ? $this->pmp : 0,
505 $label,
506 $code_inv,
507 '',
508 $dlc,
509 $dluo,
510 $this->batch
511 );
512
513 if ($result < 0) {
514 setEventMessages($p->error, $p->errors, 'errors');
515 return 0;
516 }
517 } else {
518 setEventMessages($langs->trans('StockTransferNoBatchForProduct', $p->getNomUrl()), '', 'errors');
519 return -1;
520 }
521 }
522
523 return 1;
524 }
525
533 public function validate($user, $notrigger = 0)
534 {
535 global $conf, $langs;
536
537 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
538
539 $error = 0;
540
541 // Protection
542 if ($this->status == self::STATUS_VALIDATED) {
543 dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
544 return 0;
545 }
546
547 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransferline->write))
548 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransferline->stocktransferline_advance->validate))))
549 {
550 $this->error='NotEnoughPermissions';
551 dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
552 return -1;
553 }*/
554
555 $now = dol_now();
556
557 $this->db->begin();
558
559 // Define new ref
560 if (!$error && (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
561 $num = $this->getNextNumRef();
562 } else {
563 $num = $this->ref;
564 }
565 $this->newref = $num;
566
567 if (!empty($num)) {
568 // Validate
569 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
570 $sql .= " SET ref = '".$this->db->escape($num)."',";
571 $sql .= " status = ".self::STATUS_VALIDATED;
572 if (!empty($this->fields['date_validation'])) {
573 $sql .= ", date_validation = '".$this->db->idate($now)."',";
574 }
575 if (!empty($this->fields['fk_user_valid'])) {
576 $sql .= ", fk_user_valid = ".((int) $user->id);
577 }
578 $sql .= " WHERE rowid = ".((int) $this->id);
579
580 dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
581 $resql = $this->db->query($sql);
582 if (!$resql) {
583 dol_print_error($this->db);
584 $this->error = $this->db->lasterror();
585 $error++;
586 }
587
588 if (!$error && !$notrigger) {
589 // Call trigger
590 $result = $this->call_trigger('STOCKTRANSFERLINE_VALIDATE', $user);
591 if ($result < 0) {
592 $error++;
593 }
594 // End call triggers
595 }
596 }
597
598 if (!$error) {
599 $this->oldref = $this->ref;
600
601 // Rename directory if dir was a temporary ref
602 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
603 // Now we rename also files into index
604 $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)."'";
605 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
606 $resql = $this->db->query($sql);
607 if (!$resql) {
608 $error++;
609 $this->error = $this->db->lasterror();
610 }
611 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'stocktransferline/".$this->db->escape($this->newref)."'";
612 $sql .= " WHERE filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
613 $resql = $this->db->query($sql);
614 if (!$resql) {
615 $error++;
616 $this->error = $this->db->lasterror();
617 }
618
619 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
620 $oldref = dol_sanitizeFileName($this->ref);
621 $newref = dol_sanitizeFileName($num);
622 $dirsource = $conf->stocktransfer->dir_output.'/stocktransferline/'.$oldref;
623 $dirdest = $conf->stocktransfer->dir_output.'/stocktransferline/'.$newref;
624 if (!$error && file_exists($dirsource)) {
625 dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
626
627 if (@rename($dirsource, $dirdest)) {
628 dol_syslog("Rename ok");
629 // Rename docs starting with $oldref with $newref
630 $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransferline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
631 foreach ($listoffiles as $fileentry) {
632 $dirsource = $fileentry['name'];
633 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
634 $dirsource = $fileentry['path'].'/'.$dirsource;
635 $dirdest = $fileentry['path'].'/'.$dirdest;
636 @rename($dirsource, $dirdest);
637 }
638 }
639 }
640 }
641 }
642
643 // Set new ref and current status
644 if (!$error) {
645 $this->ref = $num;
646 $this->status = self::STATUS_VALIDATED;
647 }
648
649 if (!$error) {
650 $this->db->commit();
651 return 1;
652 } else {
653 $this->db->rollback();
654 return -1;
655 }
656 }
657
658
666 public function setDraft($user, $notrigger = 0)
667 {
668 // Protection
669 if ($this->status <= self::STATUS_DRAFT) {
670 return 0;
671 }
672
673 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
674 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
675 {
676 $this->error='Permission denied';
677 return -1;
678 }*/
679
680 return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFERLINE_UNVALIDATE');
681 }
682
690 public function cancel($user, $notrigger = 0)
691 {
692 // Protection
693 if ($this->status != self::STATUS_VALIDATED) {
694 return 0;
695 }
696
697 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
698 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
699 {
700 $this->error='Permission denied';
701 return -1;
702 }*/
703
704 return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'STOCKTRANSFERLINE_CLOSE');
705 }
706
714 public function reopen($user, $notrigger = 0)
715 {
716 // Protection
717 if ($this->status != self::STATUS_CANCELED) {
718 return 0;
719 }
720
721 /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
722 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
723 {
724 $this->error='Permission denied';
725 return -1;
726 }*/
727
728 return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFERLINE_REOPEN');
729 }
730
741 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
742 {
743 global $conf, $langs, $hookmanager;
744
745 if (!empty($conf->dol_no_mouse_hover)) {
746 $notooltip = 1;
747 } // Force disable tooltips
748
749 $result = '';
750
751 $label = '<u>'.$langs->trans("StockTransferLine").'</u>';
752 $label .= '<br>';
753 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
754 if (isset($this->status)) {
755 $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
756 }
757
758 $url = dol_buildpath('/stocktransfer/stocktransferline_card.php', 1).'?id='.$this->id;
759
760 if ($option != 'nolink') {
761 // Add param to save lastsearch_values or not
762 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
763 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
764 $add_save_lastsearch_values = 1;
765 }
766 if ($add_save_lastsearch_values) {
767 $url .= '&save_lastsearch_values=1';
768 }
769 }
770
771 $linkclose = '';
772 if (empty($notooltip)) {
773 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
774 $label = $langs->trans("ShowStockTransferLine");
775 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
776 }
777 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
778 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
779 } else {
780 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
781 }
782
783 $linkstart = '<a href="'.$url.'"';
784 $linkstart .= $linkclose.'>';
785 $linkend = '</a>';
786
787 $result .= $linkstart;
788
789 if (empty($this->showphoto_on_popup)) {
790 if ($withpicto) {
791 $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);
792 }
793 } else {
794 if ($withpicto) {
795 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
796
797 list($class, $module) = explode('@', $this->picto);
798 $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
799 $filearray = dol_dir_list($upload_dir, "files");
800 $filename = $filearray[0]['name'];
801 if (!empty($filename)) {
802 $pospoint = strpos($filearray[0]['name'], '.');
803
804 $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
805 if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
806 $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>';
807 } else {
808 $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>';
809 }
810
811 $result .= '</div>';
812 } else {
813 $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);
814 }
815 }
816 }
817
818 if ($withpicto != 2) {
819 $result .= $this->ref;
820 }
821
822 $result .= $linkend;
823 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
824
825 global $action, $hookmanager;
826 $hookmanager->initHooks(array('stocktransferlinedao'));
827 $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
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
844 public function getLibStatut($mode = 0)
845 {
846 return $this->LibStatut($this->status, $mode);
847 }
848
849 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
857 public function LibStatut($status, $mode = 0)
858 {
859 // phpcs:enable
860 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
861 global $langs;
862 //$langs->load("stocktransfer@stocktransfer");
863 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
864 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
865 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
866 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
867 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
868 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
869 }
870
871 $statusType = 'status'.$status;
872 //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
873 if ($status == self::STATUS_CANCELED) {
874 $statusType = 'status6';
875 }
876
877 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
878 }
879
886 public function info($id)
887 {
888 $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
889 $sql .= ' fk_user_creat, fk_user_modif';
890 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
891 $sql .= ' WHERE t.rowid = '.((int) $id);
892 $result = $this->db->query($sql);
893 if ($result) {
894 if ($this->db->num_rows($result)) {
895 $obj = $this->db->fetch_object($result);
896 $this->id = $obj->rowid;
897
898 $this->user_creation_id = $obj->fk_user_creat;
899 $this->user_modification_id = $obj->fk_user_modif;
900 $this->date_creation = $this->db->jdate($obj->datec);
901 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
902 }
903
904 $this->db->free($result);
905 } else {
906 dol_print_error($this->db);
907 }
908 }
909
916 public function initAsSpecimen()
917 {
918 $this->initAsSpecimenCommon();
919 }
920
926 public function getNextNumRef()
927 {
928 global $langs, $conf;
929 $langs->load("stocks");
930
931 if (!getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON')) {
932 $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON = 'mod_stocktransferline_standard';
933 }
934
935 if (getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON')) {
936 $mybool = false;
937
938 $file = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFERLINE_ADDON') . ".php";
939 $classname = $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON;
940
941 // Include file with class
942 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
943 foreach ($dirmodels as $reldir) {
944 $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
945
946 // Load file with numbering class (if found)
947 $mybool |= @include_once $dir.$file;
948 }
949
950 if ($mybool === false) {
951 dol_print_error('', "Failed to include file ".$file);
952 return '';
953 }
954
955 if (class_exists($classname)) {
956 $obj = new $classname();
957 $numref = $obj->getNextValue($this);
958
959 if ($numref != '' && $numref != '-1') {
960 return $numref;
961 } else {
962 $this->error = $obj->error;
963 //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
964 return "";
965 }
966 } else {
967 print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
968 return "";
969 }
970 } else {
971 print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
972 return "";
973 }
974 }
975
987 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
988 {
989 global $conf, $langs;
990
991 $result = 0;
992 $includedocgeneration = 0;
993
994 $langs->load("stocks");
995
996 if (!dol_strlen($modele)) {
997 $modele = 'standard_stocktransferline';
998
999 if (!empty($this->model_pdf)) {
1000 $modele = $this->model_pdf;
1001 } elseif (getDolGlobalString('STOCKTRANSFERLINE_ADDON_PDF')) {
1002 $modele = $conf->global->STOCKTRANSFERLINE_ADDON_PDF;
1003 }
1004 }
1005
1006 $modelpath = "core/modules/stocktransfer/doc/";
1007
1008 if ($includedocgeneration) {
1009 $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1010 }
1011
1012 return $result;
1013 }
1014
1022 public function doScheduledJob()
1023 {
1024 //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1025
1026 $error = 0;
1027 $this->output = '';
1028 $this->error = '';
1029
1030 dol_syslog(__METHOD__, LOG_DEBUG);
1031
1032 $now = dol_now();
1033
1034 $this->db->begin();
1035
1036 // ...
1037
1038 $this->db->commit();
1039
1040 return $error;
1041 }
1042}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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.
create(User $user, $notrigger=false)
Create object into database.
validate($user, $notrigger=0)
Validate object.
update(User $user, $notrigger=false)
Update object into database.
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.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
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.
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 optionaly the picto)
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Class to manage Dolibarr users.
dol_dir_list($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:62
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.