stocktransfer.class.php 39 KB

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