29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $element =
'stocktransferline';
46 public $table_element =
'stocktransfer_stocktransferline';
51 public $picto =
'stocktransferline@stocktransfer';
53 const STATUS_DRAFT = 0;
54 const STATUS_VALIDATED = 1;
55 const STATUS_CANCELED = 9;
87 public $fields = array(
88 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'comment' =>
"Id"),
89 'amount' => array(
'type' =>
'price',
'label' =>
'Amount',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => 1,
'default' =>
'null',
'isameasure' => 1,
'help' =>
"Help text for amount",),
90 '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",),
91 '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,),
92 '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,),
93 'fk_stocktransfer' => array(
'type' =>
'integer:StockTransfer:stocktransfer/stock/class/stocktransfer.class.php',
'label' =>
'StockTransfer',
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => 0,),
94 'fk_product' => array(
'type' =>
'integer:Product:product/class/product.class.php',
'label' =>
'Product',
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => 1,),
95 'batch' => array(
'type' =>
'varchar(128)',
'label' =>
'Batch',
'enabled' => 1,
'position' => 1000,
'notnull' => -1,
'visible' => 1,),
96 'pmp' => array(
'type' =>
'double',
'label' =>
'PMP',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => 1,),
97 '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",),
115 public $fk_warehouse_destination;
119 public $fk_warehouse_source;
123 public $fk_stocktransfer;
148 global $conf, $langs;
152 $this->ismultientitymanaged = 0;
153 $this->isextrafieldmanaged = 1;
156 $this->fields[
'rowid'][
'visible'] = 0;
158 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
159 $this->fields[
'entity'][
'enabled'] = 0;
169 foreach ($this->fields as $key => $val) {
170 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
171 unset($this->fields[$key]);
176 if (is_object($langs)) {
177 foreach ($this->fields as $key => $val) {
178 if (isset($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
179 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
180 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
208 global $langs, $extrafields;
218 $result =
$object->fetchCommon($fromid);
219 if ($result > 0 && !empty(
$object->table_element_line)) {
233 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
234 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
235 $object->status = self::STATUS_DRAFT;
238 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
239 $extrafields->fetch_name_optionals_label($this->table_element);
240 foreach (
$object->array_options as $key => $option) {
241 $shortkey = preg_replace(
'/options_/',
'', $key);
242 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
244 unset(
$object->array_options[$key]);
250 $object->context[
'createfromclone'] =
'createfromclone';
251 $result =
$object->createCommon($user);
255 $this->errors =
$object->errors;
267 if (property_exists($this,
'socid') && $this->socid ==
$object->socid) {
274 unset(
$object->context[
'createfromclone']);
281 $this->db->rollback();
293 public function fetch($id, $ref =
null)
296 if ($result > 0 && !empty($this->table_element_line)) {
309 $this->lines = array();
328 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
336 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
337 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
338 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
340 $sql .=
' WHERE 1 = 1';
347 $this->errors[] = $errormessage;
348 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
352 if (!empty($sortfield)) {
353 $sql .= $this->db->order($sortfield, $sortorder);
355 if (!empty($limit)) {
356 $sql .=
' '.$this->db->plimit($limit, $offset);
359 $resql = $this->db->query($sql);
361 $num = $this->db->num_rows($resql);
363 while ($i < ($limit ? min($limit, $num) : $num)) {
364 $obj = $this->db->fetch_object($resql);
366 $record =
new self($this->db);
367 $record->setVarsFromFetchObj($obj);
369 $records[$record->id] = $record;
373 $this->db->free($resql);
377 $this->errors[] =
'Error '.$this->db->lasterror();
378 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
403 public function delete(
User $user, $notrigger = 0)
420 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
438 global $user, $langs;
440 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
441 include_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
442 include_once DOL_DOCUMENT_ROOT .
'/product/stock/stocktransfer/class/stocktransfer.class.php';
445 $p->fetch($this->fk_product);
448 $op[0] =
"+".trim((
string) $this->qty);
449 $op[1] =
"-".trim((
string) $this->qty);
452 $movementstock->origin_type = $st->origin_type;
453 $movementstock->origin_id = $this->fk_stocktransfer;
455 if (empty($this->batch)) {
456 $result = $movementstock->_create(
462 empty($direction) ? $this->pmp : 0,
472 if ($p->hasbatch()) {
473 $arraybatchinfo = $p->loadBatchInfo($this->batch);
474 if (count($arraybatchinfo) > 0) {
475 $firstrecord = array_shift($arraybatchinfo);
476 $dlc = $firstrecord[
'eatby'];
477 $dluo = $firstrecord[
'sellby'];
483 $result = $movementstock->_create(
489 empty($direction) ? $this->pmp : 0,
503 $this->error = $langs->trans(
'StockTransferNoBatchForProduct', $p->getNomUrl());
504 $this->errors[] = $this->error;
521 global $conf, $langs;
523 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
528 if ($this->
status == self::STATUS_VALIDATED) {
529 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
546 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
551 $this->newref = $num;
555 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
556 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
557 $sql .=
" status = ".self::STATUS_VALIDATED;
558 if (!empty($this->fields[
'date_validation'])) {
559 $sql .=
", date_validation = '".$this->db->idate($now).
"',";
561 if (!empty($this->fields[
'fk_user_valid'])) {
562 $sql .=
", fk_user_valid = ".((int) $user->id);
564 $sql .=
" WHERE rowid = ".((int) $this->
id);
566 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
567 $resql = $this->db->query($sql);
570 $this->error = $this->db->lasterror();
574 if (!$error && !$notrigger) {
576 $result = $this->
call_trigger(
'STOCKTRANSFERLINE_VALIDATE', $user);
585 $this->oldref = $this->ref;
588 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
590 $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).
"'";
591 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'stocktransferline/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
592 $resql = $this->db->query($sql);
595 $this->error = $this->db->lasterror();
597 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'stocktransferline/".$this->db->escape($this->newref).
"'";
598 $sql .=
" WHERE filepath = 'stocktransferline/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
599 $resql = $this->db->query($sql);
602 $this->error = $this->db->lasterror();
608 $dirsource = $conf->stocktransfer->dir_output.
'/stocktransferline/'.$oldref;
609 $dirdest = $conf->stocktransfer->dir_output.
'/stocktransferline/'.$newref;
610 if (!$error && file_exists($dirsource)) {
611 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
613 if (@rename($dirsource, $dirdest)) {
616 $listoffiles =
dol_dir_list($conf->stocktransfer->dir_output.
'/stocktransferline/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
617 foreach ($listoffiles as $fileentry) {
618 $dirsource = $fileentry[
'name'];
619 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
620 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
621 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
622 @rename($dirsource, $dirdest);
632 $this->
status = self::STATUS_VALIDATED;
639 $this->db->rollback();
655 if ($this->
status <= self::STATUS_DRAFT) {
666 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'STOCKTRANSFERLINE_UNVALIDATE');
676 public function cancel($user, $notrigger = 0)
679 if ($this->
status != self::STATUS_VALIDATED) {
690 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'STOCKTRANSFERLINE_CLOSE');
700 public function reopen($user, $notrigger = 0)
703 if ($this->
status != self::STATUS_CANCELED) {
714 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'STOCKTRANSFERLINE_REOPEN');
727 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
729 global $conf, $langs, $hookmanager;
731 if (!empty($conf->dol_no_mouse_hover)) {
737 $label =
'<u>'.$langs->trans(
"StockTransferLine").
'</u>';
739 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
740 if (isset($this->
status)) {
741 $label .=
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
744 $url =
dol_buildpath(
'/stocktransfer/stocktransferline_card.php', 1).
'?id='.$this->id;
746 if ($option !=
'nolink') {
748 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
749 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
750 $add_save_lastsearch_values = 1;
752 if ($add_save_lastsearch_values) {
753 $url .=
'&save_lastsearch_values=1';
758 if (empty($notooltip)) {
760 $label = $langs->trans(
"ShowStockTransferLine");
761 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
763 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
764 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
766 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
769 $linkstart =
'<a href="'.$url.
'"';
770 $linkstart .= $linkclose.
'>';
773 $result .= $linkstart;
775 if (empty($this->showphoto_on_popup)) {
777 $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);
781 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
783 list($class, $module) = explode(
'@', $this->picto);
786 $filename = $filearray[0][
'name'];
787 if (!empty($filename)) {
788 $pospoint = strpos($filearray[0][
'name'],
'.');
790 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
792 $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>';
794 $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>';
799 $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);
804 if ($withpicto != 2) {
805 $result .= $this->ref;
811 global $action, $hookmanager;
812 $hookmanager->initHooks(array(
'stocktransferlinedao'));
813 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
814 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
816 $result = $hookmanager->resPrint;
818 $result .= $hookmanager->resPrint;
846 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
849 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Draft');
850 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
851 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans(
'Disabled');
852 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Draft');
853 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
854 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans(
'Disabled');
857 $statusType =
'status'.$status;
859 if ($status == self::STATUS_CANCELED) {
860 $statusType =
'status6';
863 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
874 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
875 $sql .=
' fk_user_creat, fk_user_modif';
876 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
877 $sql .=
' WHERE t.rowid = '.((int) $id);
878 $result = $this->db->query($sql);
880 if ($this->db->num_rows($result)) {
881 $obj = $this->db->fetch_object($result);
882 $this->
id = $obj->rowid;
884 $this->user_creation_id = $obj->fk_user_creat;
885 $this->user_modification_id = $obj->fk_user_modif;
886 $this->date_creation = $this->db->jdate($obj->datec);
887 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
890 $this->db->free($result);
914 global $langs, $conf;
915 $langs->load(
"stocks");
918 $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON =
'mod_stocktransferline_standard';
928 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
929 foreach ($dirmodels as $reldir) {
933 $mybool = ((bool) @include_once $dir.$file) || $mybool;
941 if (class_exists($classname)) {
942 $obj =
new $classname();
943 '@phan-var-force ModeleNumRefStockTransfer $obj';
944 $numref = $obj->getNextValue($this);
946 if ($numref !=
'' && $numref !=
'-1') {
949 $this->error = $obj->error;
954 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
958 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
974 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
976 global $conf, $langs;
979 $includedocgeneration = 0;
981 $langs->load(
"stocks");
984 $modele =
'standard_stocktransferline';
986 if (!empty($this->model_pdf)) {
987 $modele = $this->model_pdf;
993 $modelpath =
"core/modules/stocktransfer/doc/";
995 if ($includedocgeneration) {
996 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1025 $this->db->commit();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
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 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...
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.