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",),
106 public $fk_warehouse_destination;
107 public $fk_warehouse_source;
108 public $fk_stocktransfer;
127 global $conf, $langs;
131 $this->ismultientitymanaged = 0;
132 $this->isextrafieldmanaged = 1;
135 $this->fields[
'rowid'][
'visible'] = 0;
137 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
138 $this->fields[
'entity'][
'enabled'] = 0;
148 foreach ($this->fields as $key => $val) {
149 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
150 unset($this->fields[$key]);
155 if (is_object($langs)) {
156 foreach ($this->fields as $key => $val) {
157 if (isset($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
158 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
159 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
187 global $langs, $extrafields;
197 $result =
$object->fetchCommon($fromid);
198 if ($result > 0 && !empty(
$object->table_element_line)) {
212 $object->ref = empty($this->fields[
'ref'][
'default']) ?
"copy_of_".$object->ref : $this->fields[
'ref'][
'default'];
213 $object->label = empty($this->fields[
'label'][
'default']) ? $langs->trans(
"CopyOf").
" ".
$object->label : $this->fields[
'label'][
'default'];
214 $object->status = self::STATUS_DRAFT;
217 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
218 $extrafields->fetch_name_optionals_label($this->table_element);
219 foreach (
$object->array_options as $key => $option) {
220 $shortkey = preg_replace(
'/options_/',
'', $key);
221 if (!empty($extrafields->attributes[$this->table_element][
'unique'][$shortkey])) {
223 unset(
$object->array_options[$key]);
229 $object->context[
'createfromclone'] =
'createfromclone';
230 $result =
$object->createCommon($user);
234 $this->errors =
$object->errors;
246 if (property_exists($this,
'socid') && $this->socid ==
$object->socid) {
253 unset(
$object->context[
'createfromclone']);
260 $this->db->rollback();
272 public function fetch($id, $ref =
null)
275 if ($result > 0 && !empty($this->table_element_line)) {
288 $this->lines = array();
307 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
315 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
316 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
317 $sql .=
' WHERE t.entity IN ('.getEntity($this->element).
')';
319 $sql .=
' WHERE 1 = 1';
326 $this->errors[] = $errormessage;
327 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
331 if (!empty($sortfield)) {
332 $sql .= $this->db->order($sortfield, $sortorder);
334 if (!empty($limit)) {
335 $sql .=
' '.$this->db->plimit($limit, $offset);
338 $resql = $this->db->query($sql);
340 $num = $this->db->num_rows($resql);
342 while ($i < ($limit ? min($limit, $num) : $num)) {
343 $obj = $this->db->fetch_object($resql);
345 $record =
new self($this->db);
346 $record->setVarsFromFetchObj($obj);
348 $records[$record->id] = $record;
352 $this->db->free($resql);
356 $this->errors[] =
'Error '.$this->db->lasterror();
357 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
382 public function delete(
User $user, $notrigger = 0)
399 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
417 global $user, $langs;
419 require_once DOL_DOCUMENT_ROOT .
'/product/class/product.class.php';
420 include_once DOL_DOCUMENT_ROOT .
'/product/stock/class/mouvementstock.class.php';
421 include_once DOL_DOCUMENT_ROOT .
'/product/stock/stocktransfer/class/stocktransfer.class.php';
424 $p->fetch($this->fk_product);
427 $op[0] =
"+".trim((
string) $this->qty);
428 $op[1] =
"-".trim((
string) $this->qty);
431 $movementstock->origin_type = $st->origin_type;
432 $movementstock->origin_id = $this->fk_stocktransfer;
434 if (empty($this->batch)) {
435 $result = $movementstock->_create(
441 empty($direction) ? $this->pmp : 0,
451 if ($p->hasbatch()) {
452 $arraybatchinfo = $p->loadBatchInfo($this->batch);
453 if (count($arraybatchinfo) > 0) {
454 $firstrecord = array_shift($arraybatchinfo);
455 $dlc = $firstrecord[
'eatby'];
456 $dluo = $firstrecord[
'sellby'];
462 $result = $movementstock->_create(
468 empty($direction) ? $this->pmp : 0,
482 $this->error=$langs->trans(
'StockTransferNoBatchForProduct', $p->getNomUrl());
483 $this->errors[]= $this->error;
500 global $conf, $langs;
502 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
507 if ($this->
status == self::STATUS_VALIDATED) {
508 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
525 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
530 $this->newref = $num;
534 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
535 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
536 $sql .=
" status = ".self::STATUS_VALIDATED;
537 if (!empty($this->fields[
'date_validation'])) {
538 $sql .=
", date_validation = '".$this->db->idate($now).
"',";
540 if (!empty($this->fields[
'fk_user_valid'])) {
541 $sql .=
", fk_user_valid = ".((int) $user->id);
543 $sql .=
" WHERE rowid = ".((int) $this->
id);
545 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
546 $resql = $this->db->query($sql);
549 $this->error = $this->db->lasterror();
553 if (!$error && !$notrigger) {
555 $result = $this->
call_trigger(
'STOCKTRANSFERLINE_VALIDATE', $user);
564 $this->oldref = $this->ref;
567 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
569 $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).
"'";
570 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'stocktransferline/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
571 $resql = $this->db->query($sql);
574 $this->error = $this->db->lasterror();
576 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'stocktransferline/".$this->db->escape($this->newref).
"'";
577 $sql .=
" WHERE filepath = 'stocktransferline/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
578 $resql = $this->db->query($sql);
581 $this->error = $this->db->lasterror();
587 $dirsource = $conf->stocktransfer->dir_output.
'/stocktransferline/'.$oldref;
588 $dirdest = $conf->stocktransfer->dir_output.
'/stocktransferline/'.$newref;
589 if (!$error && file_exists($dirsource)) {
590 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
592 if (@rename($dirsource, $dirdest)) {
595 $listoffiles =
dol_dir_list($conf->stocktransfer->dir_output.
'/stocktransferline/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
596 foreach ($listoffiles as $fileentry) {
597 $dirsource = $fileentry[
'name'];
598 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
599 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
600 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
601 @rename($dirsource, $dirdest);
611 $this->
status = self::STATUS_VALIDATED;
618 $this->db->rollback();
634 if ($this->
status <= self::STATUS_DRAFT) {
645 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'STOCKTRANSFERLINE_UNVALIDATE');
655 public function cancel($user, $notrigger = 0)
658 if ($this->
status != self::STATUS_VALIDATED) {
669 return $this->
setStatusCommon($user, self::STATUS_CANCELED, $notrigger,
'STOCKTRANSFERLINE_CLOSE');
679 public function reopen($user, $notrigger = 0)
682 if ($this->
status != self::STATUS_CANCELED) {
693 return $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'STOCKTRANSFERLINE_REOPEN');
706 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
708 global $conf, $langs, $hookmanager;
710 if (!empty($conf->dol_no_mouse_hover)) {
716 $label =
'<u>'.$langs->trans(
"StockTransferLine").
'</u>';
718 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
719 if (isset($this->
status)) {
720 $label .=
'<br><b>'.$langs->trans(
"Status").
":</b> ".$this->
getLibStatut(5);
723 $url =
dol_buildpath(
'/stocktransfer/stocktransferline_card.php', 1).
'?id='.$this->id;
725 if ($option !=
'nolink') {
727 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
728 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
729 $add_save_lastsearch_values = 1;
731 if ($add_save_lastsearch_values) {
732 $url .=
'&save_lastsearch_values=1';
737 if (empty($notooltip)) {
739 $label = $langs->trans(
"ShowStockTransferLine");
740 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
742 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
743 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
745 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
748 $linkstart =
'<a href="'.$url.
'"';
749 $linkstart .= $linkclose.
'>';
752 $result .= $linkstart;
754 if (empty($this->showphoto_on_popup)) {
756 $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);
760 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
762 list($class, $module) = explode(
'@', $this->picto);
765 $filename = $filearray[0][
'name'];
766 if (!empty($filename)) {
767 $pospoint = strpos($filearray[0][
'name'],
'.');
769 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
771 $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>';
773 $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>';
778 $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);
783 if ($withpicto != 2) {
784 $result .= $this->ref;
790 global $action, $hookmanager;
791 $hookmanager->initHooks(array(
'stocktransferlinedao'));
792 $parameters = array(
'id' => $this->
id,
'getnomurl' => $result);
793 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
795 $result = $hookmanager->resPrint;
797 $result .= $hookmanager->resPrint;
825 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
828 $this->labelStatus[self::STATUS_DRAFT] = $langs->trans(
'Draft');
829 $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
830 $this->labelStatus[self::STATUS_CANCELED] = $langs->trans(
'Disabled');
831 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans(
'Draft');
832 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans(
'Enabled');
833 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans(
'Disabled');
836 $statusType =
'status'.$status;
838 if ($status == self::STATUS_CANCELED) {
839 $statusType =
'status6';
842 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
853 $sql =
'SELECT rowid, date_creation as datec, tms as datem,';
854 $sql .=
' fk_user_creat, fk_user_modif';
855 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t';
856 $sql .=
' WHERE t.rowid = '.((int) $id);
857 $result = $this->db->query($sql);
859 if ($this->db->num_rows($result)) {
860 $obj = $this->db->fetch_object($result);
861 $this->
id = $obj->rowid;
863 $this->user_creation_id = $obj->fk_user_creat;
864 $this->user_modification_id = $obj->fk_user_modif;
865 $this->date_creation = $this->db->jdate($obj->datec);
866 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
869 $this->db->free($result);
893 global $langs, $conf;
894 $langs->load(
"stocks");
897 $conf->global->STOCKTRANSFER_STOCKTRANSFERLINE_ADDON =
'mod_stocktransferline_standard';
907 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
908 foreach ($dirmodels as $reldir) {
912 $mybool = ((bool) @include_once $dir.$file) || $mybool;
915 if ($mybool ===
false) {
920 if (class_exists($classname)) {
921 $obj =
new $classname();
922 $numref = $obj->getNextValue($this);
924 if ($numref !=
'' && $numref !=
'-1') {
927 $this->error = $obj->error;
932 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
936 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
952 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
954 global $conf, $langs;
957 $includedocgeneration = 0;
959 $langs->load(
"stocks");
962 $modele =
'standard_stocktransferline';
964 if (!empty($this->model_pdf)) {
965 $modele = $this->model_pdf;
971 $modelpath =
"core/modules/stocktransfer/doc/";
973 if ($includedocgeneration) {
974 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1003 $this->db->commit();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.