dolibarr  16.0.5
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
27 require_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  // END MODULEBUILDER PROPERTIES
118 
119 
120  // If this object has a subtable with lines
121 
125  //public $table_element_line = 'stocktransfer_stocktransferlineline';
126 
130  //public $fk_element = 'fk_stocktransferline';
131 
135  //public $class_element_line = 'StockTransferLineline';
136 
140  //protected $childtables = array();
141 
147  //protected $childtablesoncascade = array('stocktransfer_stocktransferlinedet');
148 
152  //public $lines = array();
153 
154 
155 
161  public function __construct(DoliDB $db)
162  {
163  global $conf, $langs;
164 
165  $this->db = $db;
166 
167  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
168  if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
169 
170  // Example to show how to set values of fields definition dynamically
171  /*if ($user->rights->stocktransfer->stocktransferline->read) {
172  $this->fields['myfield']['visible'] = 1;
173  $this->fields['myfield']['noteditable'] = 0;
174  }*/
175 
176  // Unset fields that are disabled
177  foreach ($this->fields as $key => $val) {
178  if (isset($val['enabled']) && empty($val['enabled'])) {
179  unset($this->fields[$key]);
180  }
181  }
182 
183  // Translate some data of arrayofkeyval
184  if (is_object($langs)) {
185  foreach ($this->fields as $key => $val) {
186  if (is_array($val['arrayofkeyval'])) {
187  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
188  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
189  }
190  }
191  }
192  }
193  }
194 
202  public function create(User $user, $notrigger = false)
203  {
204  return $this->createCommon($user, $notrigger);
205  }
206 
214  public function createFromClone(User $user, $fromid)
215  {
216  global $langs, $extrafields;
217  $error = 0;
218 
219  dol_syslog(__METHOD__, LOG_DEBUG);
220 
221  $object = new self($this->db);
222 
223  $this->db->begin();
224 
225  // Load source object
226  $result = $object->fetchCommon($fromid);
227  if ($result > 0 && !empty($object->table_element_line)) $object->fetchLines();
228 
229  // get lines so they will be clone
230  //foreach($this->lines as $line)
231  // $line->fetch_optionals();
232 
233  // Reset some properties
234  unset($object->id);
235  unset($object->fk_user_creat);
236  unset($object->import_key);
237 
238 
239  // Clear fields
240  $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
241  $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
242  $object->status = self::STATUS_DRAFT;
243  // ...
244  // Clear extrafields that are unique
245  if (is_array($object->array_options) && count($object->array_options) > 0) {
246  $extrafields->fetch_name_optionals_label($this->table_element);
247  foreach ($object->array_options as $key => $option) {
248  $shortkey = preg_replace('/options_/', '', $key);
249  if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
250  //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
251  unset($object->array_options[$key]);
252  }
253  }
254  }
255 
256  // Create clone
257  $object->context['createfromclone'] = 'createfromclone';
258  $result = $object->createCommon($user);
259  if ($result < 0) {
260  $error++;
261  $this->error = $object->error;
262  $this->errors = $object->errors;
263  }
264 
265  if (!$error) {
266  // copy internal contacts
267  if ($this->copy_linked_contact($object, 'internal') < 0) {
268  $error++;
269  }
270  }
271 
272  if (!$error) {
273  // copy external contacts if same company
274  if (property_exists($this, 'socid') && $this->socid == $object->socid) {
275  if ($this->copy_linked_contact($object, 'external') < 0)
276  $error++;
277  }
278  }
279 
280  unset($object->context['createfromclone']);
281 
282  // End
283  if (!$error) {
284  $this->db->commit();
285  return $object;
286  } else {
287  $this->db->rollback();
288  return -1;
289  }
290  }
291 
299  public function fetch($id, $ref = null)
300  {
301  $result = $this->fetchCommon($id, $ref);
302  if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
303  return $result;
304  }
305 
311  public function fetchLines()
312  {
313  $this->lines = array();
314 
315  $result = $this->fetchLinesCommon();
316  return $result;
317  }
318 
319 
331  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
332  {
333  global $conf;
334 
335  dol_syslog(__METHOD__, LOG_DEBUG);
336 
337  $records = array();
338 
339  $sql = 'SELECT ';
340  $sql .= $this->getFieldList();
341  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
342  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
343  else $sql .= ' WHERE 1 = 1';
344  // Manage filter
345  $sqlwhere = array();
346  if (count($filter) > 0) {
347  foreach ($filter as $key => $value) {
348  if ($key == 't.rowid') {
349  $sqlwhere[] = $key.'='.$value;
350  } elseif (strpos($key, 'date') !== false) {
351  $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
352  } elseif ($key == 'customsql') {
353  $sqlwhere[] = $value;
354  } else {
355  $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
356  }
357  }
358  }
359  if (count($sqlwhere) > 0) {
360  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
361  }
362 
363  if (!empty($sortfield)) {
364  $sql .= $this->db->order($sortfield, $sortorder);
365  }
366  if (!empty($limit)) {
367  $sql .= ' '.$this->db->plimit($limit, $offset);
368  }
369 
370  $resql = $this->db->query($sql);
371  if ($resql) {
372  $num = $this->db->num_rows($resql);
373  $i = 0;
374  while ($i < ($limit ? min($limit, $num) : $num)) {
375  $obj = $this->db->fetch_object($resql);
376 
377  $record = new self($this->db);
378  $record->setVarsFromFetchObj($obj);
379 
380  $records[$record->id] = $record;
381 
382  $i++;
383  }
384  $this->db->free($resql);
385 
386  return $records;
387  } else {
388  $this->errors[] = 'Error '.$this->db->lasterror();
389  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
390 
391  return -1;
392  }
393  }
394 
402  public function update(User $user, $notrigger = false)
403  {
404  return $this->updateCommon($user, $notrigger);
405  }
406 
414  public function delete(User $user, $notrigger = false)
415  {
416  return $this->deleteCommon($user, $notrigger);
417  //return $this->deleteCommon($user, $notrigger, 1);
418  }
419 
428  public function deleteLine(User $user, $idline, $notrigger = false)
429  {
430  if ($this->status < 0) {
431  $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
432  return -2;
433  }
434 
435  return $this->deleteLineCommon($user, $idline, $notrigger);
436  }
437 
447  public function doStockMovement($label, $code_inv, $fk_entrepot, $direction = 1)
448  {
449 
450  global $conf, $user, $langs;
451 
452  require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
453  include_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php';
454  include_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransfer.class.php';
455 
456  $p = new Product($this->db);
457  $p->fetch($this->fk_product);
458 
459  $op[0] = "+".trim($this->qty);
460  $op[1] = "-".trim($this->qty);
461  $movementstock = new MouvementStock($this->db);
462  $st = new StockTransfer($this->db);
463  $movementstock->origin_type = $st->origin_type;
464  $movementstock->origin_id = $this->fk_stocktransfer;
465 
466  if (empty($this->batch)) { // no batch for line
467  /*$result = $p->correct_stock(
468  $user,
469  $fk_entrepot,
470  $this->qty,
471  $direction, // 1=décrémentation
472  $label,
473  empty($direction) ? $this->pmp : 0,
474  GETPOST('inventorycode', 'alphanohtml'),
475  'stocktransfer',
476  $this->fk_stocktransfer
477  );*/
478 
479  $result = $movementstock->_create($user,
480  $p->id,
481  $fk_entrepot,
482  $op[$direction],
483  $direction,
484  empty($direction) ? $this->pmp : 0,
485  $label,
486  $code_inv);
487 
488  if ($result < 0) {
489  setEventMessages($p->errors, $p->errorss, 'errors');
490  return 0;
491  }
492  } else {
493  if ($p->hasbatch()) {
494  $arraybatchinfo = $p->loadBatchInfo($this->batch);
495  if (count($arraybatchinfo) > 0) {
496  $firstrecord = array_shift($arraybatchinfo);
497  $dlc = $firstrecord['eatby'];
498  $dluo = $firstrecord['sellby'];
499  //var_dump($batch); var_dump($arraybatchinfo); var_dump($firstrecord); var_dump($dlc); var_dump($dluo); exit;
500  } else {
501  $dlc = '';
502  $dluo = '';
503  }
504 
505  /*$result = $p->correct_stock_batch(
506  $user,
507  $fk_entrepot,
508  $this->qty,
509  $direction,
510  $label,
511  empty($direction) ? $this->pmp : 0,
512  $dlc,
513  $dluo,
514  $this->batch,
515  GETPOST("codemove")
516  );*/
517 
518  $result = $movementstock->_create($user,
519  $p->id,
520  $fk_entrepot,
521  $op[$direction],
522  $direction,
523  empty($direction) ? $this->pmp : 0,
524  $label,
525  $code_inv,
526  '',
527  $dlc,
528  $dluo,
529  $this->batch);
530 
531  if ($result < 0) {
532  setEventMessages($p->errors, $p->errorss, 'errors');
533  return 0;
534  }
535  } else {
536  setEventMessages($langs->trans('StockTransferNoBatchForProduct', $p->getNomUrl()), '', 'errors');
537  return -1;
538  }
539  }
540 
541  return 1;
542  }
543 
551  public function validate($user, $notrigger = 0)
552  {
553  global $conf, $langs;
554 
555  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
556 
557  $error = 0;
558 
559  // Protection
560  if ($this->status == self::STATUS_VALIDATED) {
561  dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
562  return 0;
563  }
564 
565  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->stocktransferline->write))
566  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->stocktransferline->stocktransferline_advance->validate))))
567  {
568  $this->error='NotEnoughPermissions';
569  dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
570  return -1;
571  }*/
572 
573  $now = dol_now();
574 
575  $this->db->begin();
576 
577  // Define new ref
578  if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
579  $num = $this->getNextNumRef();
580  } else {
581  $num = $this->ref;
582  }
583  $this->newref = $num;
584 
585  if (!empty($num)) {
586  // Validate
587  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
588  $sql .= " SET ref = '".$this->db->escape($num)."',";
589  $sql .= " status = ".self::STATUS_VALIDATED;
590  if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."',";
591  if (!empty($this->fields['fk_user_valid'])) $sql .= ", fk_user_valid = ".((int) $user->id);
592  $sql .= " WHERE rowid = ".((int) $this->id);
593 
594  dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
595  $resql = $this->db->query($sql);
596  if (!$resql) {
597  dol_print_error($this->db);
598  $this->error = $this->db->lasterror();
599  $error++;
600  }
601 
602  if (!$error && !$notrigger) {
603  // Call trigger
604  $result = $this->call_trigger('STOCKTRANSFERLINE_VALIDATE', $user);
605  if ($result < 0) $error++;
606  // End call triggers
607  }
608  }
609 
610  if (!$error) {
611  $this->oldref = $this->ref;
612 
613  // Rename directory if dir was a temporary ref
614  if (preg_match('/^[\(]?PROV/i', $this->ref)) {
615  // Now we rename also files into index
616  $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)."'";
617  $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransferline/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
618  $resql = $this->db->query($sql);
619  if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
620 
621  // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
622  $oldref = dol_sanitizeFileName($this->ref);
623  $newref = dol_sanitizeFileName($num);
624  $dirsource = $conf->stocktransfer->dir_output.'/stocktransferline/'.$oldref;
625  $dirdest = $conf->stocktransfer->dir_output.'/stocktransferline/'.$newref;
626  if (!$error && file_exists($dirsource)) {
627  dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
628 
629  if (@rename($dirsource, $dirdest)) {
630  dol_syslog("Rename ok");
631  // Rename docs starting with $oldref with $newref
632  $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransferline/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
633  foreach ($listoffiles as $fileentry) {
634  $dirsource = $fileentry['name'];
635  $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
636  $dirsource = $fileentry['path'].'/'.$dirsource;
637  $dirdest = $fileentry['path'].'/'.$dirdest;
638  @rename($dirsource, $dirdest);
639  }
640  }
641  }
642  }
643  }
644 
645  // Set new ref and current status
646  if (!$error) {
647  $this->ref = $num;
648  $this->status = self::STATUS_VALIDATED;
649  }
650 
651  if (!$error) {
652  $this->db->commit();
653  return 1;
654  } else {
655  $this->db->rollback();
656  return -1;
657  }
658  }
659 
660 
668  public function setDraft($user, $notrigger = 0)
669  {
670  // Protection
671  if ($this->status <= self::STATUS_DRAFT) {
672  return 0;
673  }
674 
675  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->write))
676  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
677  {
678  $this->error='Permission denied';
679  return -1;
680  }*/
681 
682  return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFERLINE_UNVALIDATE');
683  }
684 
692  public function cancel($user, $notrigger = 0)
693  {
694  // Protection
695  if ($this->status != self::STATUS_VALIDATED) {
696  return 0;
697  }
698 
699  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->write))
700  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
701  {
702  $this->error='Permission denied';
703  return -1;
704  }*/
705 
706  return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'STOCKTRANSFERLINE_CLOSE');
707  }
708 
716  public function reopen($user, $notrigger = 0)
717  {
718  // Protection
719  if ($this->status != self::STATUS_CANCELED) {
720  return 0;
721  }
722 
723  /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->write))
724  || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
725  {
726  $this->error='Permission denied';
727  return -1;
728  }*/
729 
730  return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFERLINE_REOPEN');
731  }
732 
743  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
744  {
745  global $conf, $langs, $hookmanager;
746 
747  if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // 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 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
764  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
765  }
766 
767  $linkclose = '';
768  if (empty($notooltip)) {
769  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
770  $label = $langs->trans("ShowStockTransferLine");
771  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
772  }
773  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
774  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
775  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
776 
777  $linkstart = '<a href="'.$url.'"';
778  $linkstart .= $linkclose.'>';
779  $linkend = '</a>';
780 
781  $result .= $linkstart;
782 
783  if (empty($this->showphoto_on_popup)) {
784  if ($withpicto) $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);
785  } else {
786  if ($withpicto) {
787  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
788 
789  list($class, $module) = explode('@', $this->picto);
790  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
791  $filearray = dol_dir_list($upload_dir, "files");
792  $filename = $filearray[0]['name'];
793  if (!empty($filename)) {
794  $pospoint = strpos($filearray[0]['name'], '.');
795 
796  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
797  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
798  $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>';
799  } else {
800  $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>';
801  }
802 
803  $result .= '</div>';
804  } else {
805  $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);
806  }
807  }
808  }
809 
810  if ($withpicto != 2) $result .= $this->ref;
811 
812  $result .= $linkend;
813  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
814 
815  global $action, $hookmanager;
816  $hookmanager->initHooks(array('stocktransferlinedao'));
817  $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
818  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
819  if ($reshook > 0) $result = $hookmanager->resPrint;
820  else $result .= $hookmanager->resPrint;
821 
822  return $result;
823  }
824 
831  public function getLibStatut($mode = 0)
832  {
833  return $this->LibStatut($this->status, $mode);
834  }
835 
836  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
844  public function LibStatut($status, $mode = 0)
845  {
846  // phpcs:enable
847  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
848  global $langs;
849  //$langs->load("stocktransfer@stocktransfer");
850  $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
851  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
852  $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Disabled');
853  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
854  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Enabled');
855  $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Disabled');
856  }
857 
858  $statusType = 'status'.$status;
859  //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
860  if ($status == self::STATUS_CANCELED) $statusType = 'status6';
861 
862  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
863  }
864 
871  public function info($id)
872  {
873  $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
874  $sql .= ' fk_user_creat, fk_user_modif';
875  $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
876  $sql .= ' WHERE t.rowid = '.((int) $id);
877  $result = $this->db->query($sql);
878  if ($result) {
879  if ($this->db->num_rows($result)) {
880  $obj = $this->db->fetch_object($result);
881  $this->id = $obj->rowid;
882 
883  $this->user_creation_id = $obj->fk_user_creat;
884  $this->user_modification_id = $obj->fk_user_modif;
885  $this->date_creation = $this->db->jdate($obj->datec);
886  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
887  }
888 
889  $this->db->free($result);
890  } else {
891  dol_print_error($this->db);
892  }
893  }
894 
901  public function initAsSpecimen()
902  {
903  $this->initAsSpecimenCommon();
904  }
905 
911  public function getLinesArray()
912  {
913  $this->lines = array();
914 
915  $objectline = new StockTransferLineLine($this->db);
916  $result = $objectline->fetchAll('ASC', 'position', 0, 0, array('customsql'=>'fk_stocktransferline = '.((int) $this->id)));
917 
918  if (is_numeric($result)) {
919  $this->error = $this->error;
920  $this->errors = $this->errors;
921  return $result;
922  } else {
923  $this->lines = $result;
924  return $this->lines;
925  }
926  }
927 
933  public function getNextNumRef()
934  {
935  global $langs, $conf;
936  $langs->load("stocks");
937 
938  if (empty($conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON)) {
939  $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON = 'mod_stocktransferline_standard';
940  }
941 
942  if (!empty($conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON)) {
943  $mybool = false;
944 
945  $file = $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON.".php";
946  $classname = $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON;
947 
948  // Include file with class
949  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
950  foreach ($dirmodels as $reldir) {
951  $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
952 
953  // Load file with numbering class (if found)
954  $mybool |= @include_once $dir.$file;
955  }
956 
957  if ($mybool === false) {
958  dol_print_error('', "Failed to include file ".$file);
959  return '';
960  }
961 
962  if (class_exists($classname)) {
963  $obj = new $classname();
964  $numref = $obj->getNextValue($this);
965 
966  if ($numref != '' && $numref != '-1') {
967  return $numref;
968  } else {
969  $this->error = $obj->error;
970  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
971  return "";
972  }
973  } else {
974  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
975  return "";
976  }
977  } else {
978  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
979  return "";
980  }
981  }
982 
994  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
995  {
996  global $conf, $langs;
997 
998  $result = 0;
999  $includedocgeneration = 0;
1000 
1001  $langs->load("stocks");
1002 
1003  if (!dol_strlen($modele)) {
1004  $modele = 'standard_stocktransferline';
1005 
1006  if ($this->modelpdf) {
1007  $modele = $this->modelpdf;
1008  } elseif (!empty($conf->global->STOCKTRANSFERLINE_ADDON_PDF)) {
1009  $modele = $conf->global->STOCKTRANSFERLINE_ADDON_PDF;
1010  }
1011  }
1012 
1013  $modelpath = "core/modules/stocktransfer/doc/";
1014 
1015  if ($includedocgeneration) {
1016  $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1017  }
1018 
1019  return $result;
1020  }
1021 
1029  public function doScheduledJob()
1030  {
1031  global $conf, $langs;
1032 
1033  //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
1034 
1035  $error = 0;
1036  $this->output = '';
1037  $this->error = '';
1038 
1039  dol_syslog(__METHOD__, LOG_DEBUG);
1040 
1041  $now = dol_now();
1042 
1043  $this->db->begin();
1044 
1045  // ...
1046 
1047  $this->db->commit();
1048 
1049  return $error;
1050  }
1051 }
1052 
1057 {
1058  // To complete with content of an object StockTransferLineLine
1059  // We should have a field rowid, fk_stocktransferline and position
1060 
1064  public $isextrafieldmanaged = 0;
1065 
1071  public function __construct(DoliDB $db)
1072  {
1073  $this->db = $db;
1074  }
1075 }
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9406
StockTransferLine\doStockMovement
doStockMovement($label, $code_inv, $fk_entrepot, $direction=1)
Makes all stock movements (add quantity, remove quantity or cancel all actions)
Definition: stocktransferline.class.php:447
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9683
db
$conf db
API class for accounts.
Definition: inc.php:41
StockTransferLine\getLinesArray
getLinesArray()
Create an array of lines.
Definition: stocktransferline.class.php:911
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9202
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
CommonObject\copy_linked_contact
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
Definition: commonobject.class.php:1217
StockTransferLine\create
create(User $user, $notrigger=false)
Create object into database.
Definition: stocktransferline.class.php:202
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
CommonObject\fetchLinesCommon
fetchLinesCommon($morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9258
ref
$object ref
Definition: info.php:77
StockTransfer
Class for StockTransfer.
Definition: stocktransfer.class.php:36
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
CommonObjectLine
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Definition: commonobjectline.class.php:32
StockTransferLine\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: stocktransferline.class.php:311
StockTransferLine\update
update(User $user, $notrigger=false)
Update object into database.
Definition: stocktransferline.class.php:402
StockTransferLine\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: stocktransferline.class.php:716
StockTransferLine\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Definition: stocktransferline.class.php:994
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9035
StockTransferLine\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: stocktransferline.class.php:901
StockTransferLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: stocktransferline.class.php:161
StockTransferLine\getLibStatut
getLibStatut($mode=0)
Return label of the status.
Definition: stocktransferline.class.php:831
MouvementStock
Class to manage stock movements.
Definition: mouvementstock.class.php:31
StockTransferLineLine
Class StockTransferLineLine.
Definition: stocktransferline.class.php:1056
StockTransferLine
Class for StockTransferLine.
Definition: stocktransferline.class.php:34
StockTransferLineLine\__construct
__construct(DoliDB $db)
Constructor.
Definition: stocktransferline.class.php:1071
StockTransferLine\cancel
cancel($user, $notrigger=0)
Set cancel status.
Definition: stocktransferline.class.php:692
StockTransferLine\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: stocktransferline.class.php:743
StockTransferLine\info
info($id)
Load the info information in the object.
Definition: stocktransferline.class.php:871
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
StockTransferLine\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: stocktransferline.class.php:933
StockTransferLine\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: stocktransferline.class.php:844
StockTransferLine\setDraft
setDraft($user, $notrigger=0)
Set draft status.
Definition: stocktransferline.class.php:668
StockTransferLine\doScheduledJob
doScheduledJob()
Action executed by scheduler CAN BE A CRON TASK.
Definition: stocktransferline.class.php:1029
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9308
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
StockTransferLine\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: stocktransferline.class.php:214
StockTransferLine\validate
validate($user, $notrigger=0)
Validate object.
Definition: stocktransferline.class.php:551
User
Class to manage Dolibarr users.
Definition: user.class.php:44
StockTransferLine\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: stocktransferline.class.php:299
Product
Class to manage products or services.
Definition: product.class.php:46
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\deleteLineCommon
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: commonobject.class.php:9622
StockTransferLine\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: stocktransferline.class.php:331
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:8987
StockTransferLine\deleteLine
deleteLine(User $user, $idline, $notrigger=false)
Delete a line of object in database.
Definition: stocktransferline.class.php:428