stocktransfer.class.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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) 2022 Frédéric France <frederic.france@netlogic.fr>
  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. /**
  20. * \file htdocs/product/stock/stocktransfer/class/stocktransfer.class.php
  21. * \ingroup stocktransfer
  22. * \brief This file is a CRUD class file for StockTransfer (Create/Read/Update/Delete)
  23. */
  24. // Put here all includes required by your class file
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
  27. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  28. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  29. /**
  30. * Class for StockTransfer
  31. */
  32. class StockTransfer extends CommonObject
  33. {
  34. use CommonIncoterm;
  35. /**
  36. * @var string ID to identify managed object.
  37. */
  38. public $element = 'stocktransfer';
  39. /**
  40. * @var string Name of table without prefix where object is stored. This is also the key used for extrafields management.
  41. */
  42. public $table_element = 'stocktransfer_stocktransfer';
  43. /**
  44. * @var int Does this object support multicompany module ?
  45. * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table
  46. */
  47. public $ismultientitymanaged = 0;
  48. /**
  49. * @var int Does object support extrafields ? 0=No, 1=Yes
  50. */
  51. public $isextrafieldmanaged = 1;
  52. /**
  53. * @var array List of child tables. To know object to delete on cascade.
  54. * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
  55. * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
  56. */
  57. protected $childtablesoncascade = array('stocktransfer_stocktransferline');
  58. /**
  59. * @var string Customer ref
  60. * @deprecated
  61. * @see $ref_customer
  62. */
  63. public $ref_client;
  64. /**
  65. * @var string Customer ref
  66. */
  67. public $ref_customer;
  68. /**
  69. * @var string String with name of icon for stocktransfer. Must be the part after the 'object_' into object_stocktransfer.png
  70. */
  71. public $picto = 'stock';
  72. public $date_prevue_depart;
  73. public $date_prevue_arrivee;
  74. public $date_reelle_depart;
  75. public $date_reelle_arrivee;
  76. public $origin_type;
  77. const STATUS_DRAFT = 0;
  78. const STATUS_VALIDATED = 1;
  79. const STATUS_TRANSFERED = 2;
  80. const STATUS_CLOSED = 3;
  81. /**
  82. * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
  83. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  84. * 'label' the translation key.
  85. * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)
  86. * 'position' is the sort order of field.
  87. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  88. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
  89. * 'noteditable' says if field is not editable (1 or 0)
  90. * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
  91. * 'index' if we want an index in database.
  92. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  93. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  94. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  95. * 'css' is the CSS style to use on field. For example: 'maxwidth200'
  96. * 'help' is a string visible as a tooltip on field
  97. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  98. * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
  99. * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  100. * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
  101. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  102. *
  103. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  104. */
  105. // BEGIN MODULEBUILDER PROPERTIES
  106. /**
  107. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  108. */
  109. public $fields=array(
  110. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
  111. 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>'1', 'position'=>1, 'default'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'comment'=>"Id"),
  112. 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>4, 'noteditable'=>'1', 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'comment'=>"Reference of object"),
  113. 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>0, 'visible'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'css'=>'minwidth100', 'csslist'=>'tdoverflowmax125', 'autofocusoncreate'=>1),
  114. 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>'1', 'position'=>31, 'notnull'=>0, 'visible'=>3,),
  115. 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'enabled'=>'$conf->project->enabled', 'position'=>32, 'notnull'=>-1, 'visible'=>-1, 'index'=>1, 'picto'=>'project', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax125'),
  116. 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>50, 'notnull'=>-1, 'visible'=>1, 'index'=>1/*, 'help'=>"LinkToThirdparty"*/, 'picto'=>'company', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax125'),
  117. 'fk_warehouse_source' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Entrepôt source', 'enabled'=>'1', 'position'=>50, 'notnull'=>0, 'visible'=>1, 'help'=>'HelpWarehouseStockTransferSource', 'picto'=>'stock', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150'),
  118. 'fk_warehouse_destination' => array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Entrepôt de destination', 'enabled'=>'1', 'position'=>51, 'notnull'=>0, 'visible'=>1, 'help'=>'HelpWarehouseStockTransferDestination', 'picto'=>'stock', 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150'),
  119. 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>0,),
  120. 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>0,),
  121. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
  122. 'date_prevue_depart' => array('type'=>'date', 'label'=>'DatePrevueDepart', 'enabled'=>'1', 'position'=>100, 'notnull'=>0, 'visible'=>1,),
  123. 'date_reelle_depart' => array('type'=>'date', 'label'=>'DateReelleDepart', 'enabled'=>'1', 'position'=>101, 'notnull'=>0, 'visible'=>5,),
  124. 'date_prevue_arrivee' => array('type'=>'date', 'label'=>'DatePrevueArrivee', 'enabled'=>'1', 'position'=>102, 'notnull'=>0, 'visible'=>1,),
  125. 'date_reelle_arrivee' => array('type'=>'date', 'label'=>'DateReelleArrivee', 'enabled'=>'1', 'position'=>103, 'notnull'=>0, 'visible'=>5,),
  126. 'lead_time_for_warning' => array('type'=>'integer', 'label'=>'LeadTimeForWarning', 'enabled'=>'1', 'position'=>200, 'default'=>0, 'notnull'=>0, 'visible'=>1),
  127. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
  128. 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
  129. 'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'ChangedBy', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
  130. 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
  131. 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
  132. 'fk_incoterms' => array('type'=>'integer', 'label'=>'IncotermCode', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-2, 'position'=>220),
  133. 'location_incoterms' => array('type'=>'varchar(255)', 'label'=>'IncotermLabel', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-2, 'position'=>225),
  134. 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>5, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '2'=>'StockStransferDecremented', '3'=>'StockStransferIncremented'),),
  135. );
  136. public $rowid;
  137. public $ref;
  138. public $label;
  139. public $socid;
  140. public $fk_soc; // deprecated
  141. public $fk_project;
  142. public $description;
  143. public $note_public;
  144. public $note_private;
  145. public $date_creation;
  146. public $tms;
  147. public $lead_time_for_warning;
  148. public $fk_user_creat;
  149. public $fk_user_modif;
  150. public $import_key;
  151. public $model_pdf;
  152. public $status;
  153. /**
  154. * @var StockTransferLine[] stock transfer line
  155. */
  156. public $lines;
  157. public $fk_warehouse_source;
  158. public $fk_warehouse_destination;
  159. // END MODULEBUILDER PROPERTIES
  160. /**
  161. * Constructor
  162. *
  163. * @param DoliDb $db Database handler
  164. */
  165. public function __construct(DoliDB $db)
  166. {
  167. global $conf, $langs;
  168. $this->db = $db;
  169. $this->origin_type = 'StockTransfer@product/stock/stocktransfer';
  170. if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID') && isset($this->fields['rowid'])) {
  171. $this->fields['rowid']['visible'] = 0;
  172. }
  173. if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
  174. $this->fields['entity']['enabled'] = 0;
  175. }
  176. // Example to show how to set values of fields definition dynamically
  177. /*if ($user->rights->stocktransfer->stocktransfer->read) {
  178. $this->fields['myfield']['visible'] = 1;
  179. $this->fields['myfield']['noteditable'] = 0;
  180. }*/
  181. // Unset fields that are disabled
  182. foreach ($this->fields as $key => $val) {
  183. if (isset($val['enabled']) && empty($val['enabled'])) {
  184. unset($this->fields[$key]);
  185. }
  186. }
  187. // Translate some data of arrayofkeyval
  188. if (is_object($langs)) {
  189. foreach ($this->fields as $key => $val) {
  190. if (isset($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  191. foreach ($val['arrayofkeyval'] as $key2 => $val2) {
  192. $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. /**
  199. * Create object into database
  200. *
  201. * @param User $user User that creates
  202. * @param bool $notrigger false=launch triggers after, true=disable triggers
  203. * @return int Return integer <0 if KO, Id of created object if OK
  204. */
  205. public function create(User $user, $notrigger = false)
  206. {
  207. $model_pdf = GETPOST('model');
  208. if (!empty($model_pdf)) {
  209. $this->model_pdf = $model_pdf;
  210. }
  211. $this->status = (int) $this->status;
  212. if ($this->fk_warehouse_source <= 0) {
  213. $this->fk_warehouse_source = 0;
  214. }
  215. if ($this->fk_warehouse_destination <= 0) {
  216. $this->fk_warehouse_destination = 0;
  217. }
  218. return $this->createCommon($user, $notrigger);
  219. }
  220. /**
  221. * Clone an object into another one
  222. *
  223. * @param User $user User that creates
  224. * @param int $fromid Id of object to clone
  225. * @return mixed New object created, <0 if KO
  226. */
  227. public function createFromClone(User $user, $fromid)
  228. {
  229. global $langs, $extrafields;
  230. $error = 0;
  231. dol_syslog(__METHOD__, LOG_DEBUG);
  232. $object = new self($this->db);
  233. $this->db->begin();
  234. // Load source object
  235. $result = $object->fetchCommon($fromid);
  236. if ($result > 0 && !empty($object->table_element_line)) {
  237. $object->fetchLines();
  238. }
  239. // get lines so they will be clone
  240. //foreach($this->lines as $line)
  241. // $line->fetch_optionals();
  242. // Reset some properties
  243. unset($object->id);
  244. unset($object->fk_user_creat);
  245. unset($object->import_key);
  246. unset($object->date_prevue_depart);
  247. unset($object->date_prevue_arrivee);
  248. unset($object->date_reelle_depart);
  249. unset($object->date_reelle_arrivee);
  250. // Clear fields
  251. $object->ref = empty($this->fields['ref']['default']) ? "copy_of_".$object->ref : $this->fields['ref']['default'];
  252. $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
  253. $object->status = self::STATUS_DRAFT;
  254. // ...
  255. // Clear extrafields that are unique
  256. if (is_array($object->array_options) && count($object->array_options) > 0) {
  257. $extrafields->fetch_name_optionals_label($this->table_element);
  258. foreach ($object->array_options as $key => $option) {
  259. $shortkey = preg_replace('/options_/', '', $key);
  260. if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
  261. //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
  262. unset($object->array_options[$key]);
  263. }
  264. }
  265. }
  266. // Create clone
  267. $object->context['createfromclone'] = 'createfromclone';
  268. $result = $object->createCommon($user);
  269. if ($result < 0) {
  270. $error++;
  271. $this->error = $object->error;
  272. $this->errors = $object->errors;
  273. }
  274. if (!$error) {
  275. // copy internal contacts
  276. if ($this->copy_linked_contact($object, 'internal') < 0) {
  277. $error++;
  278. }
  279. }
  280. if (!$error) {
  281. // copy external contacts if same company
  282. if (property_exists($this, 'socid') && $this->socid == $object->socid) {
  283. if ($this->copy_linked_contact($object, 'external') < 0) {
  284. $error++;
  285. }
  286. }
  287. }
  288. unset($object->context['createfromclone']);
  289. // End
  290. if (!$error) {
  291. $this->db->commit();
  292. return $object;
  293. } else {
  294. $this->db->rollback();
  295. return -1;
  296. }
  297. }
  298. /**
  299. * Load object in memory from the database
  300. *
  301. * @param int $id Id object
  302. * @param string $ref Ref
  303. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  304. */
  305. public function fetch($id, $ref = null)
  306. {
  307. $result = $this->fetchCommon($id, $ref);
  308. $this->socid = $this->fk_soc;
  309. if ($result > 0 && !empty($this->table_element_line)) {
  310. $this->fetchLines();
  311. }
  312. return $result;
  313. }
  314. /**
  315. * Load object lines in memory from the database
  316. *
  317. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  318. */
  319. public function fetchLines()
  320. {
  321. require_once DOL_DOCUMENT_ROOT . '/product/stock/stocktransfer/class/stocktransferline.class.php';
  322. $this->lines = array();
  323. $result = $this->fetchLinesCommon();
  324. usort($this->lines, array('StockTransfer', 'stocktransferCmpRank'));
  325. return $result;
  326. }
  327. /**
  328. * Used to sort lines by rank
  329. *
  330. * @param Object $a 1st element to test
  331. * @param Object $b 2nd element to test
  332. * @return int
  333. */
  334. public static function stocktransferCmpRank($a, $b)
  335. {
  336. if ($a->rang == $b->rang) {
  337. return 0;
  338. }
  339. return ($a->rang < $b->rang) ? -1 : 1;
  340. }
  341. /**
  342. * Used to get total PMP amount of all quantities of products of Stock Transfer
  343. *
  344. * @return float total amount of Stock Transfer
  345. */
  346. public function getValorisationTotale()
  347. {
  348. $total_pmp = 0;
  349. if (empty($this->lines)) {
  350. $this->fetchLines();
  351. }
  352. if (!empty($this->lines)) {
  353. foreach ($this->lines as $l) {
  354. $total_pmp+= ($l->pmp * $l->qty);
  355. }
  356. }
  357. return $total_pmp;
  358. }
  359. /**
  360. * Load list of objects in memory from the database.
  361. *
  362. * @param string $sortorder Sort Order
  363. * @param string $sortfield Sort field
  364. * @param int $limit limit
  365. * @param int $offset Offset
  366. * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
  367. * @param string $filtermode Filter mode (AND or OR)
  368. * @return array|int int <0 if KO, array of pages if OK
  369. */
  370. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  371. {
  372. global $conf;
  373. dol_syslog(__METHOD__, LOG_DEBUG);
  374. $records = array();
  375. $sql = 'SELECT ';
  376. $sql .= $this->getFieldList();
  377. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  378. if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
  379. $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
  380. } else {
  381. $sql .= ' WHERE 1 = 1';
  382. }
  383. // Manage filter
  384. $sqlwhere = array();
  385. if (count($filter) > 0) {
  386. foreach ($filter as $key => $value) {
  387. if ($key == 't.rowid') {
  388. $sqlwhere[] = $key.'='.$value;
  389. } elseif (strpos($key, 'date') !== false) {
  390. $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\'';
  391. } elseif ($key == 'customsql') {
  392. $sqlwhere[] = $value;
  393. } else {
  394. $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
  395. }
  396. }
  397. }
  398. if (count($sqlwhere) > 0) {
  399. $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
  400. }
  401. if (!empty($sortfield)) {
  402. $sql .= $this->db->order($sortfield, $sortorder);
  403. }
  404. if (!empty($limit)) {
  405. $sql .= ' '.$this->db->plimit($limit, $offset);
  406. }
  407. $resql = $this->db->query($sql);
  408. if ($resql) {
  409. $num = $this->db->num_rows($resql);
  410. $i = 0;
  411. while ($i < ($limit ? min($limit, $num) : $num)) {
  412. $obj = $this->db->fetch_object($resql);
  413. $record = new self($this->db);
  414. $record->setVarsFromFetchObj($obj);
  415. $records[$record->id] = $record;
  416. $i++;
  417. }
  418. $this->db->free($resql);
  419. return $records;
  420. } else {
  421. $this->errors[] = 'Error '.$this->db->lasterror();
  422. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  423. return -1;
  424. }
  425. }
  426. /**
  427. * Update object into database
  428. *
  429. * @param User $user User that modifies
  430. * @param bool $notrigger false=launch triggers after, true=disable triggers
  431. * @return int Return integer <0 if KO, >0 if OK
  432. */
  433. public function update(User $user, $notrigger = false)
  434. {
  435. $this->tms = ''; // Will be done automatically because tms field is on update cascade
  436. $res = $this->updateCommon($user, $notrigger);
  437. if (($this->socid > 0 || $this->fk_soc > 0) && empty($this->thirdparty)) {
  438. $this->fetch_thirdparty();
  439. }
  440. if (empty($this->socid) && empty($this->fk_soc)) {
  441. unset($this->thirdparty);
  442. }
  443. return $res;
  444. }
  445. /**
  446. * Delete object in database
  447. *
  448. * @param User $user User that deletes
  449. * @param bool $notrigger false=launch triggers after, true=disable triggers
  450. * @return int Return integer <0 if KO, >0 if OK
  451. */
  452. public function delete(User $user, $notrigger = false)
  453. {
  454. if ($this->status > self::STATUS_VALIDATED) {
  455. return 0;
  456. } else {
  457. return $this->deleteCommon($user, $notrigger);
  458. }
  459. }
  460. /**
  461. * Delete a line of object in database
  462. *
  463. * @param User $user User that delete
  464. * @param int $idline Id of line to delete
  465. * @param bool $notrigger false=launch triggers after, true=disable triggers
  466. * @return int >0 if OK, <0 if KO
  467. */
  468. public function deleteLine(User $user, $idline, $notrigger = false)
  469. {
  470. if ($this->status < 0) {
  471. $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
  472. return -2;
  473. }
  474. $res = $this->deleteLineCommon($user, $idline, $notrigger);
  475. $this->line_order(true);
  476. return $res;
  477. }
  478. /**
  479. * Validate object
  480. *
  481. * @param User $user User making status change
  482. * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
  483. * @return int Return integer <=0 if OK, 0=Nothing done, >0 if KO
  484. */
  485. public function validate($user, $notrigger = 0)
  486. {
  487. global $conf, $langs;
  488. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  489. $error = 0;
  490. // Protection
  491. if ($this->status == self::STATUS_VALIDATED) {
  492. dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
  493. return 0;
  494. }
  495. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer->write))
  496. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer->stocktransfer_advance->validate))))
  497. {
  498. $this->error='NotEnoughPermissions';
  499. dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
  500. return -1;
  501. }*/
  502. $now = dol_now();
  503. $this->db->begin();
  504. // Define new ref
  505. if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life
  506. $num = $this->getNextNumRef();
  507. } else {
  508. $num = $this->ref;
  509. }
  510. $this->newref = $num;
  511. if (!empty($num)) {
  512. // Validate
  513. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
  514. $sql .= " SET ref = '".$this->db->escape($num)."',";
  515. $sql .= " status = ".self::STATUS_VALIDATED;
  516. if (!empty($this->fields['date_validation'])) {
  517. $sql .= ", date_validation = '".$this->db->idate($now)."',";
  518. }
  519. if (!empty($this->fields['fk_user_valid'])) {
  520. $sql .= ", fk_user_valid = ".((int) $user->id);
  521. }
  522. $sql .= " WHERE rowid = ".((int) $this->id);
  523. dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
  524. $resql = $this->db->query($sql);
  525. if (!$resql) {
  526. dol_print_error($this->db);
  527. $this->error = $this->db->lasterror();
  528. $error++;
  529. }
  530. if (!$error && !$notrigger) {
  531. // Call trigger
  532. $result = $this->call_trigger('STOCKTRANSFER_VALIDATE', $user);
  533. if ($result < 0) {
  534. $error++;
  535. }
  536. // End call triggers
  537. }
  538. }
  539. if (!$error) {
  540. $this->oldref = $this->ref;
  541. // Rename directory if dir was a temporary ref
  542. if (preg_match('/^[\(]?PROV/i', $this->ref)) {
  543. // Now we rename also files into index
  544. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
  545. $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
  546. $resql = $this->db->query($sql);
  547. if (!$resql) {
  548. $error++;
  549. $this->error = $this->db->lasterror();
  550. }
  551. $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'stocktransfer/".$this->db->escape($this->newref)."'";
  552. $sql .= " WHERE filepath = 'stocktransfer/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
  553. $resql = $this->db->query($sql);
  554. if (!$resql) {
  555. $error++;
  556. $this->error = $this->db->lasterror();
  557. }
  558. // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
  559. $oldref = dol_sanitizeFileName($this->ref);
  560. $newref = dol_sanitizeFileName($num);
  561. $dirsource = $conf->stocktransfer->dir_output.'/stocktransfer/'.$oldref;
  562. $dirdest = $conf->stocktransfer->dir_output.'/stocktransfer/'.$newref;
  563. if (!$error && file_exists($dirsource)) {
  564. dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
  565. if (@rename($dirsource, $dirdest)) {
  566. dol_syslog("Rename ok");
  567. // Rename docs starting with $oldref with $newref
  568. $listoffiles = dol_dir_list($conf->stocktransfer->dir_output.'/stocktransfer/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
  569. foreach ($listoffiles as $fileentry) {
  570. $dirsource = $fileentry['name'];
  571. $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
  572. $dirsource = $fileentry['path'].'/'.$dirsource;
  573. $dirdest = $fileentry['path'].'/'.$dirdest;
  574. @rename($dirsource, $dirdest);
  575. }
  576. }
  577. }
  578. }
  579. }
  580. // Set new ref and current status
  581. if (!$error) {
  582. $this->ref = $num;
  583. $this->status = self::STATUS_VALIDATED;
  584. }
  585. if (!$error) {
  586. $this->db->commit();
  587. return 1;
  588. } else {
  589. $this->db->rollback();
  590. return -1;
  591. }
  592. }
  593. /**
  594. * Set draft status
  595. *
  596. * @param User $user Object user that modify
  597. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  598. * @return int Return integer <0 if KO, >0 if OK
  599. */
  600. public function setDraft($user, $notrigger = 0)
  601. {
  602. // Protection
  603. if ($this->status <= self::STATUS_DRAFT) {
  604. return 0;
  605. }
  606. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
  607. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
  608. {
  609. $this->error='Permission denied';
  610. return -1;
  611. }*/
  612. return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'STOCKTRANSFER_UNVALIDATE');
  613. }
  614. /**
  615. * Set cancel status
  616. *
  617. * @param User $user Object user that modify
  618. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  619. * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK
  620. */
  621. public function cancel($user, $notrigger = 0)
  622. {
  623. // Protection
  624. if ($this->status != self::STATUS_VALIDATED) {
  625. return 0;
  626. }
  627. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
  628. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
  629. {
  630. $this->error='Permission denied';
  631. return -1;
  632. }*/
  633. return $this->setStatusCommon($user, self::STATUS_CLOSED, $notrigger, 'STOCKTRANSFER_CLOSE');
  634. }
  635. /**
  636. * Set back to validated status
  637. *
  638. * @param User $user Object user that modify
  639. * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
  640. * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK
  641. */
  642. public function reopen($user, $notrigger = 0)
  643. {
  644. // Protection
  645. if ($this->status != self::STATUS_CLOSED) {
  646. return 0;
  647. }
  648. /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->write))
  649. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->stocktransfer->stocktransfer_advance->validate))))
  650. {
  651. $this->error='Permission denied';
  652. return -1;
  653. }*/
  654. return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'STOCKTRANSFER_REOPEN');
  655. }
  656. /**
  657. * Return a link to the object card (with optionaly the picto)
  658. *
  659. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  660. * @param string $option On what the link point to ('nolink', ...)
  661. * @param int $notooltip 1=Disable tooltip
  662. * @param string $morecss Add more css on link
  663. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  664. * @return string String with URL
  665. */
  666. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  667. {
  668. global $conf, $langs, $hookmanager;
  669. if (!empty($conf->dol_no_mouse_hover)) {
  670. $notooltip = 1;
  671. } // Force disable tooltips
  672. $result = '';
  673. $label = '<u>'.$langs->trans("StockTransfer").'</u>';
  674. $label .= '<br>';
  675. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
  676. if (isset($this->status)) {
  677. $label .= '<br><b>'.$langs->trans("Status").":</b> ".$this->getLibStatut(5);
  678. }
  679. $url = dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$this->id;
  680. if ($option != 'nolink') {
  681. // Add param to save lastsearch_values or not
  682. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  683. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  684. $add_save_lastsearch_values = 1;
  685. }
  686. if ($add_save_lastsearch_values) {
  687. $url .= '&save_lastsearch_values=1';
  688. }
  689. }
  690. $linkclose = '';
  691. if (empty($notooltip)) {
  692. if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  693. $label = $langs->trans("ShowStockTransfer");
  694. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  695. }
  696. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  697. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  698. } else {
  699. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  700. }
  701. $linkstart = '<a href="'.$url.'"';
  702. $linkstart .= $linkclose.'>';
  703. $linkend = '</a>';
  704. $result .= $linkstart;
  705. if (empty($this->showphoto_on_popup)) {
  706. if ($withpicto) {
  707. $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);
  708. }
  709. } else {
  710. if ($withpicto) {
  711. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  712. list($class, $module) = explode('@', $this->picto);
  713. $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
  714. $filearray = dol_dir_list($upload_dir, "files");
  715. $filename = $filearray[0]['name'];
  716. if (!empty($filename)) {
  717. $pospoint = strpos($filearray[0]['name'], '.');
  718. $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
  719. if (!getDolGlobalString(strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS')) {
  720. $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>';
  721. } else {
  722. $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>';
  723. }
  724. $result .= '</div>';
  725. } else {
  726. $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);
  727. }
  728. }
  729. }
  730. if ($withpicto != 2) {
  731. $result .= $this->ref;
  732. }
  733. $result .= $linkend;
  734. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  735. global $action, $hookmanager;
  736. $hookmanager->initHooks(array('stocktransferdao'));
  737. $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
  738. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  739. if ($reshook > 0) {
  740. $result = $hookmanager->resPrint;
  741. } else {
  742. $result .= $hookmanager->resPrint;
  743. }
  744. return $result;
  745. }
  746. /**
  747. * Return label of the status
  748. *
  749. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  750. * @return string Label of status
  751. */
  752. public function getLibStatut($mode = 0)
  753. {
  754. return $this->LibStatut($this->status, $mode);
  755. }
  756. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  757. /**
  758. * Return the status
  759. *
  760. * @param int $status Id status
  761. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  762. * @return string Label of status
  763. */
  764. public function LibStatut($status, $mode = 0)
  765. {
  766. // phpcs:enable
  767. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  768. global $langs;
  769. //$langs->load("stocktransfer@stocktransfer");
  770. $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
  771. $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
  772. $this->labelStatus[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented');
  773. $this->labelStatus[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented');
  774. $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
  775. $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
  776. $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->trans('StockStransferDecremented');
  777. $this->labelStatusShort[self::STATUS_CLOSED] = $langs->trans('StockStransferIncremented');
  778. }
  779. $statusType = 'status'.$status;
  780. //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
  781. if ($status == self::STATUS_CLOSED) {
  782. $statusType = 'status6';
  783. }
  784. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  785. }
  786. /**
  787. * Load the info information in the object
  788. *
  789. * @param int $id Id of object
  790. * @return void
  791. */
  792. public function info($id)
  793. {
  794. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  795. $sql .= ' fk_user_creat, fk_user_modif';
  796. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  797. $sql .= ' WHERE t.rowid = '.((int) $id);
  798. $result = $this->db->query($sql);
  799. if ($result) {
  800. if ($this->db->num_rows($result)) {
  801. $obj = $this->db->fetch_object($result);
  802. $this->id = $obj->rowid;
  803. $this->user_creation_id = $obj->fk_user_creat;
  804. $this->user_modification_id = $obj->fk_user_modif;
  805. $this->date_creation = $this->db->jdate($obj->datec);
  806. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  807. }
  808. $this->db->free($result);
  809. } else {
  810. dol_print_error($this->db);
  811. }
  812. }
  813. /**
  814. * Initialise object with example values
  815. * Id must be 0 if object instance is a specimen
  816. *
  817. * @return void
  818. */
  819. public function initAsSpecimen()
  820. {
  821. $this->initAsSpecimenCommon();
  822. }
  823. /**
  824. * Create an array of lines
  825. *
  826. * @return array|int array of lines if OK, <0 if KO
  827. */
  828. public function getLinesArray()
  829. {
  830. $this->lines = array();
  831. $objectline = new StockTransferLine($this->db);
  832. $result = $objectline->fetchAll('ASC', 'rang', 0, 0, array('customsql'=>'fk_stocktransfer = '.$this->id));
  833. if (is_numeric($result)) {
  834. $this->error = $objectline->error;
  835. $this->errors = $objectline->errors;
  836. return $result;
  837. } else {
  838. $this->lines = $result;
  839. return $this->lines;
  840. }
  841. }
  842. /**
  843. * Returns the reference to the following non used object depending on the active numbering module.
  844. *
  845. * @return string Object free reference
  846. */
  847. public function getNextNumRef()
  848. {
  849. global $langs, $conf;
  850. $langs->load("stocks");
  851. if (!getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) {
  852. $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON = 'mod_stocktransfer_standard';
  853. }
  854. if (getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON')) {
  855. $mybool = false;
  856. $file = getDolGlobalString('STOCKTRANSFER_STOCKTRANSFER_ADDON') . ".php";
  857. $classname = $conf->global->STOCKTRANSFER_STOCKTRANSFER_ADDON;
  858. // Include file with class
  859. $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
  860. foreach ($dirmodels as $reldir) {
  861. $dir = dol_buildpath($reldir."core/modules/stocktransfer/");
  862. // Load file with numbering class (if found)
  863. $mybool |= @include_once $dir.$file;
  864. }
  865. if ($mybool === false) {
  866. dol_print_error('', "Failed to include file ".$file);
  867. return '';
  868. }
  869. if (class_exists($classname)) {
  870. $obj = new $classname();
  871. $numref = $obj->getNextValue($this);
  872. if ($numref != '' && $numref != '-1') {
  873. return $numref;
  874. } else {
  875. $this->error = $obj->error;
  876. //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
  877. return "";
  878. }
  879. } else {
  880. print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
  881. return "";
  882. }
  883. } else {
  884. print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
  885. return "";
  886. }
  887. }
  888. /**
  889. * Create a document onto disk according to template module.
  890. *
  891. * @param string $modele Force template to use ('' to not force)
  892. * @param Translate $outputlangs objet lang a utiliser pour traduction
  893. * @param int $hidedetails Hide details of lines
  894. * @param int $hidedesc Hide description
  895. * @param int $hideref Hide ref
  896. * @param null|array $moreparams Array to provide more information
  897. * @return int 0 if KO, 1 if OK
  898. */
  899. public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
  900. {
  901. global $conf, $langs;
  902. $result = 0;
  903. $includedocgeneration = 1;
  904. $langs->load("stocks");
  905. if (!dol_strlen($modele)) {
  906. $modele = 'eagle';
  907. if ($this->model_pdf) {
  908. $modele = $this->model_pdf;
  909. } elseif (getDolGlobalString('STOCKTRANSFER_ADDON_PDF')) {
  910. $modele = $conf->global->STOCKTRANSFER_ADDON_PDF;
  911. }
  912. }
  913. $modelpath = "core/modules/stocktransfer/doc/";
  914. if ($includedocgeneration) {
  915. $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
  916. }
  917. return $result;
  918. }
  919. /**
  920. * Action executed by scheduler
  921. * CAN BE A CRON TASK. In such a case, parameters come from the schedule job setup field 'Parameters'
  922. * Use public function doScheduledJob($param1, $param2, ...) to get parameters
  923. *
  924. * @return int 0 if OK, <>0 if KO (this function is used also by cron so only 0 is OK)
  925. */
  926. public function doScheduledJob()
  927. {
  928. global $conf, $langs;
  929. //$conf->global->SYSLOG_FILE = 'DOL_DATA_ROOT/dolibarr_mydedicatedlofile.log';
  930. $error = 0;
  931. $this->output = '';
  932. $this->error = '';
  933. dol_syslog(__METHOD__, LOG_DEBUG);
  934. $now = dol_now();
  935. $this->db->begin();
  936. // ...
  937. $this->db->commit();
  938. return $error;
  939. }
  940. }
  941. /**
  942. * Class StockTransferLine. You can also remove this and generate a CRUD class for lines objects.
  943. */
  944. //class StockTransferLine
  945. //{
  946. // // To complete with content of an object StockTransferLine
  947. // // We should have a field rowid, fk_stocktransfer and position
  948. //
  949. // /**
  950. // * @var int Does object support extrafields ? 0=No, 1=Yes
  951. // */
  952. // public $isextrafieldmanaged = 0;
  953. //
  954. // /**
  955. // * Constructor
  956. // *
  957. // * @param DoliDb $db Database handler
  958. // */
  959. // public function __construct(DoliDB $db)
  960. // {
  961. // $this->db = $db;
  962. // }
  963. //}