bookkeeping.class.php 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211
  1. <?php
  2. /* Copyright (C) 2014-2017 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2015-2020 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/accountancy/class/bookkeeping.class.php
  22. * \ingroup Accountancy (Double entries)
  23. * \brief File of class to manage Ledger (General Ledger and Subledger)
  24. */
  25. // Class
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  27. /**
  28. * Class to manage Ledger (General Ledger and Subledger)
  29. */
  30. class BookKeeping extends CommonObject
  31. {
  32. /**
  33. * @var string Id to identify managed objects
  34. */
  35. public $element = 'accountingbookkeeping';
  36. /**
  37. * @var string Name of table without prefix where object is stored
  38. */
  39. public $table_element = 'accounting_bookkeeping';
  40. /**
  41. * @var int Entity
  42. */
  43. public $entity;
  44. /**
  45. * @var BookKeepingLine[] Lines
  46. */
  47. public $lines = array();
  48. /**
  49. * @var int ID
  50. */
  51. public $id;
  52. /**
  53. * @var string Date of source document, in db date NOT NULL
  54. */
  55. public $doc_date;
  56. /**
  57. * @var int Deadline for payment
  58. */
  59. public $date_lim_reglement;
  60. /**
  61. * @var string doc_type
  62. */
  63. public $doc_type;
  64. /**
  65. * @var string doc_ref
  66. */
  67. public $doc_ref;
  68. /**
  69. * @var int ID
  70. */
  71. public $fk_doc;
  72. /**
  73. * @var int ID
  74. */
  75. public $fk_docdet;
  76. /**
  77. * @var string thirdparty code
  78. */
  79. public $thirdparty_code;
  80. /**
  81. * @var string subledger account
  82. */
  83. public $subledger_account;
  84. /**
  85. * @var string subledger label
  86. */
  87. public $subledger_label;
  88. /**
  89. * @var string doc_type
  90. */
  91. public $numero_compte;
  92. /**
  93. * @var string label compte
  94. */
  95. public $label_compte;
  96. /**
  97. * @var string label operation
  98. */
  99. public $label_operation;
  100. /**
  101. * @var float FEC:Debit
  102. */
  103. public $debit;
  104. /**
  105. * @var float FEC:Credit
  106. */
  107. public $credit;
  108. /**
  109. * @var float FEC:Amount (Not necessary)
  110. * @deprecated No more used (we have info into debit/credit and sens)
  111. */
  112. public $montant;
  113. /**
  114. * @var float FEC:Amount (Not necessary)
  115. * @deprecated No more used (we have info into debit/credit and sens)
  116. */
  117. public $amount;
  118. /**
  119. * @var string FEC:Sens (Not necessary)
  120. */
  121. public $sens;
  122. /**
  123. * @var int ID
  124. */
  125. public $fk_user_author;
  126. /**
  127. * @var string key for import
  128. */
  129. public $import_key;
  130. /**
  131. * @var string code journal
  132. */
  133. public $code_journal;
  134. /**
  135. * @var string label journal
  136. */
  137. public $journal_label;
  138. /**
  139. * @var int accounting transaction id
  140. */
  141. public $piece_num;
  142. /**
  143. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  144. */
  145. public $picto = 'generic';
  146. /**
  147. * Constructor
  148. *
  149. * @param DoliDb $db Database handler
  150. */
  151. public function __construct(DoliDB $db)
  152. {
  153. $this->db = $db;
  154. }
  155. /**
  156. * Create object into database
  157. *
  158. * @param User $user User that creates
  159. * @param bool $notrigger false=launch triggers after, true=disable triggers
  160. * @return int <0 if KO, Id of created object if OK
  161. */
  162. public function create(User $user, $notrigger = false)
  163. {
  164. global $conf, $langs;
  165. dol_syslog(__METHOD__, LOG_DEBUG);
  166. $error = 0;
  167. // Clean parameters</center>
  168. if (isset($this->doc_type)) {
  169. $this->doc_type = trim($this->doc_type);
  170. }
  171. if (isset($this->doc_ref)) {
  172. $this->doc_ref = trim($this->doc_ref);
  173. }
  174. if (isset($this->fk_doc)) {
  175. $this->fk_doc = (int) $this->fk_doc;
  176. }
  177. if (isset($this->fk_docdet)) {
  178. $this->fk_docdet = (int) $this->fk_docdet;
  179. }
  180. if (isset($this->thirdparty_code)) {
  181. $this->thirdparty_code = trim($this->thirdparty_code);
  182. }
  183. if (isset($this->subledger_account)) {
  184. $this->subledger_account = trim($this->subledger_account);
  185. }
  186. if (isset($this->subledger_label)) {
  187. $this->subledger_label = trim($this->subledger_label);
  188. }
  189. if (isset($this->numero_compte)) {
  190. $this->numero_compte = trim($this->numero_compte);
  191. }
  192. if (isset($this->label_compte)) {
  193. $this->label_compte = trim($this->label_compte);
  194. }
  195. if (isset($this->label_operation)) {
  196. $this->label_operation = trim($this->label_operation);
  197. }
  198. if (isset($this->debit)) {
  199. $this->debit = (float) $this->debit;
  200. }
  201. if (isset($this->credit)) {
  202. $this->credit = (float) $this->credit;
  203. }
  204. if (isset($this->montant)) {
  205. $this->montant = (float) $this->montant;
  206. }
  207. if (isset($this->amount)) {
  208. $this->amount = (float) $this->amount;
  209. }
  210. if (isset($this->sens)) {
  211. $this->sens = trim($this->sens);
  212. }
  213. if (isset($this->import_key)) {
  214. $this->import_key = trim($this->import_key);
  215. }
  216. if (isset($this->code_journal)) {
  217. $this->code_journal = trim($this->code_journal);
  218. }
  219. if (isset($this->journal_label)) {
  220. $this->journal_label = trim($this->journal_label);
  221. }
  222. if (isset($this->piece_num)) {
  223. $this->piece_num = trim($this->piece_num);
  224. }
  225. if (empty($this->debit)) {
  226. $this->debit = 0.0;
  227. }
  228. if (empty($this->credit)) {
  229. $this->credit = 0.0;
  230. }
  231. // Check parameters
  232. if (($this->numero_compte == "") || $this->numero_compte == '-1' || $this->numero_compte == 'NotDefined') {
  233. $langs->loadLangs(array("errors"));
  234. if (in_array($this->doc_type, array('bank', 'expense_report'))) {
  235. $this->errors[] = $langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type);
  236. } else {
  237. //$this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->doc_ref, $this->label_compte);
  238. $mesg = $this->doc_ref.', '.$langs->trans("AccountAccounting").': '.$this->numero_compte;
  239. if ($this->subledger_account && $this->subledger_account != $this->numero_compte) {
  240. $mesg .= ', '.$langs->trans("SubledgerAccount").': '.$this->subledger_account;
  241. }
  242. $this->errors[] = $langs->trans('ErrorFieldAccountNotDefinedForLine', $mesg);
  243. }
  244. return -1;
  245. }
  246. $this->db->begin();
  247. $this->piece_num = 0;
  248. // First check if line not yet already in bookkeeping.
  249. // Note that we must include 'doc_type - fk_doc - numero_compte - label' to be sure to have unicity of line (because we may have several lines
  250. // with same doc_type, fk_doc, numero_compte for 1 invoice line when using localtaxes with same account)
  251. // WARNING: This is not reliable, label may have been modified. This is just a small protection.
  252. // The page that make transfer make the test on couple (doc_type - fk_doc) only.
  253. $sql = "SELECT count(*) as nb";
  254. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  255. $sql .= " WHERE doc_type = '".$this->db->escape($this->doc_type)."'";
  256. $sql .= " AND fk_doc = ".((int) $this->fk_doc);
  257. if (!empty($conf->global->ACCOUNTANCY_ENABLE_FKDOCDET)) {
  258. // DO NOT USE THIS IN PRODUCTION. This will generate a lot of trouble into reports and will corrupt database (by generating duplicate entries.
  259. $sql .= " AND fk_docdet = ".((int) $this->fk_docdet); // This field can be 0 if record is for several lines
  260. }
  261. $sql .= " AND numero_compte = '".$this->db->escape($this->numero_compte)."'";
  262. $sql .= " AND label_operation = '".$this->db->escape($this->label_operation)."'";
  263. $sql .= " AND entity = ".$conf->entity; // Do not use getEntity for accounting features
  264. $resql = $this->db->query($sql);
  265. if ($resql) {
  266. $row = $this->db->fetch_object($resql);
  267. if ($row->nb == 0) { // Not already into bookkeeping
  268. // Check to know if piece_num already exists for data we try to insert to reuse the same value
  269. $sqlnum = "SELECT piece_num";
  270. $sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  271. $sqlnum .= " WHERE doc_type = '".$this->db->escape($this->doc_type)."'"; // For example doc_type = 'bank'
  272. $sqlnum .= " AND fk_doc = ".((int) $this->fk_doc);
  273. if (!empty($conf->global->ACCOUNTANCY_ENABLE_FKDOCDET)) {
  274. // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ...
  275. $sqlnum .= " AND fk_docdet = ".((int) $this->fk_docdet);
  276. }
  277. $sqlnum .= " AND doc_ref = '".$this->db->escape($this->doc_ref)."'"; // ref of source object
  278. $sqlnum .= " AND entity = ".$conf->entity; // Do not use getEntity for accounting features
  279. dol_syslog(get_class($this).":: create sqlnum=".$sqlnum, LOG_DEBUG);
  280. $resqlnum = $this->db->query($sqlnum);
  281. if ($resqlnum) {
  282. $objnum = $this->db->fetch_object($resqlnum);
  283. $this->piece_num = $objnum->piece_num;
  284. }
  285. dol_syslog(get_class($this).":: create this->piece_num=".$this->piece_num, LOG_DEBUG);
  286. if (empty($this->piece_num)) {
  287. $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum";
  288. $sqlnum .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  289. $sqlnum .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  290. $resqlnum = $this->db->query($sqlnum);
  291. if ($resqlnum) {
  292. $objnum = $this->db->fetch_object($resqlnum);
  293. $this->piece_num = $objnum->maxpiecenum;
  294. }
  295. dol_syslog(get_class($this).":: create now this->piece_num=".$this->piece_num, LOG_DEBUG);
  296. }
  297. if (empty($this->piece_num)) {
  298. $this->piece_num = 1;
  299. }
  300. $now = dol_now();
  301. $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (";
  302. $sql .= "doc_date";
  303. $sql .= ", date_lim_reglement";
  304. $sql .= ", doc_type";
  305. $sql .= ", doc_ref";
  306. $sql .= ", fk_doc";
  307. $sql .= ", fk_docdet";
  308. $sql .= ", thirdparty_code";
  309. $sql .= ", subledger_account";
  310. $sql .= ", subledger_label";
  311. $sql .= ", numero_compte";
  312. $sql .= ", label_compte";
  313. $sql .= ", label_operation";
  314. $sql .= ", debit";
  315. $sql .= ", credit";
  316. $sql .= ", montant";
  317. $sql .= ", sens";
  318. $sql .= ", fk_user_author";
  319. $sql .= ", date_creation";
  320. $sql .= ", code_journal";
  321. $sql .= ", journal_label";
  322. $sql .= ", piece_num";
  323. $sql .= ', entity';
  324. $sql .= ") VALUES (";
  325. $sql .= "'".$this->db->idate($this->doc_date)."'";
  326. $sql .= ", ".(!isset($this->date_lim_reglement) || dol_strlen($this->date_lim_reglement) == 0 ? 'NULL' : "'".$this->db->idate($this->date_lim_reglement)."'");
  327. $sql .= ", '".$this->db->escape($this->doc_type)."'";
  328. $sql .= ", '".$this->db->escape($this->doc_ref)."'";
  329. $sql .= ", ".((int) $this->fk_doc);
  330. $sql .= ", ".((int) $this->fk_docdet);
  331. $sql .= ", ".(!empty($this->thirdparty_code) ? ("'".$this->db->escape($this->thirdparty_code)."'") : "NULL");
  332. $sql .= ", ".(!empty($this->subledger_account) ? ("'".$this->db->escape($this->subledger_account)."'") : "NULL");
  333. $sql .= ", ".(!empty($this->subledger_label) ? ("'".$this->db->escape($this->subledger_label)."'") : "NULL");
  334. $sql .= ", '".$this->db->escape($this->numero_compte)."'";
  335. $sql .= ", ".(!empty($this->label_compte) ? ("'".$this->db->escape($this->label_compte)."'") : "NULL");
  336. $sql .= ", '".$this->db->escape($this->label_operation)."'";
  337. $sql .= ", ".((float) $this->debit);
  338. $sql .= ", ".((float) $this->credit);
  339. $sql .= ", ".((float) $this->montant);
  340. $sql .= ", ".(!empty($this->sens) ? ("'".$this->db->escape($this->sens)."'") : "NULL");
  341. $sql .= ", '".$this->db->escape($this->fk_user_author)."'";
  342. $sql .= ", '".$this->db->idate($now)."'";
  343. $sql .= ", '".$this->db->escape($this->code_journal)."'";
  344. $sql .= ", ".(!empty($this->journal_label) ? ("'".$this->db->escape($this->journal_label)."'") : "NULL");
  345. $sql .= ", ".((int) $this->piece_num);
  346. $sql .= ", ".(!isset($this->entity) ? $conf->entity : $this->entity);
  347. $sql .= ")";
  348. $resql = $this->db->query($sql);
  349. if ($resql) {
  350. $id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
  351. if ($id > 0) {
  352. $this->id = $id;
  353. $result = 0;
  354. } else {
  355. $result = -2;
  356. $error++;
  357. $this->errors[] = 'Error Create Error '.$result.' lecture ID';
  358. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  359. }
  360. } else {
  361. $result = -1;
  362. $error++;
  363. $this->errors[] = 'Error '.$this->db->lasterror();
  364. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  365. }
  366. } else { // Already exists
  367. $result = -3;
  368. $error++;
  369. $this->error = 'BookkeepingRecordAlreadyExists';
  370. dol_syslog(__METHOD__.' '.$this->error, LOG_WARNING);
  371. }
  372. } else {
  373. $result = -5;
  374. $error++;
  375. $this->errors[] = 'Error '.$this->db->lasterror();
  376. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  377. }
  378. // Uncomment this and change MYOBJECT to your own tag if you
  379. // want this action to call a trigger.
  380. //if (! $error && ! $notrigger) {
  381. // // Call triggers
  382. // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
  383. // if ($result < 0) $error++;
  384. // // End call triggers
  385. //}
  386. // Commit or rollback
  387. if ($error) {
  388. $this->db->rollback();
  389. return -1 * $error;
  390. } else {
  391. $this->db->commit();
  392. return $result;
  393. }
  394. }
  395. /**
  396. * Return a link to the object card (with optionally the picto)
  397. *
  398. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  399. * @param string $option On what the link point to ('nolink', ...)
  400. * @param int $notooltip 1=Disable tooltip
  401. * @param string $morecss Add more css on link
  402. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  403. * @return string String with URL
  404. */
  405. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  406. {
  407. global $db, $conf, $langs;
  408. global $dolibarr_main_authentication, $dolibarr_main_demo;
  409. global $menumanager, $hookmanager;
  410. if (!empty($conf->dol_no_mouse_hover)) {
  411. $notooltip = 1; // Force disable tooltips
  412. }
  413. $result = '';
  414. $companylink = '';
  415. $label = '<u>'.$langs->trans("Transaction").'</u>';
  416. $label .= '<br>';
  417. $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->piece_num;
  418. $url = DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?piece_num='.$this->piece_num;
  419. if ($option != 'nolink') {
  420. // Add param to save lastsearch_values or not
  421. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  422. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  423. $add_save_lastsearch_values = 1;
  424. }
  425. if ($add_save_lastsearch_values) {
  426. $url .= '&save_lastsearch_values=1';
  427. }
  428. }
  429. $linkclose = '';
  430. if (empty($notooltip)) {
  431. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  432. $label = $langs->trans("ShowTransaction");
  433. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  434. }
  435. $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
  436. $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
  437. } else {
  438. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  439. }
  440. $linkstart = '<a href="'.$url.'"';
  441. $linkstart .= $linkclose.'>';
  442. $linkend = '</a>';
  443. $result .= $linkstart;
  444. if ($withpicto) {
  445. $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);
  446. }
  447. if ($withpicto != 2) {
  448. $result .= $this->piece_num;
  449. }
  450. $result .= $linkend;
  451. //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
  452. global $action;
  453. $hookmanager->initHooks(array($this->element . 'dao'));
  454. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  455. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  456. if ($reshook > 0) {
  457. $result = $hookmanager->resPrint;
  458. } else {
  459. $result .= $hookmanager->resPrint;
  460. }
  461. return $result;
  462. }
  463. /**
  464. * Create object into database
  465. *
  466. * @param User $user User that creates
  467. * @param bool $notrigger false=launch triggers after, true=disable triggers
  468. * @param string $mode Mode
  469. * @return int <0 if KO, Id of created object if OK
  470. */
  471. public function createStd(User $user, $notrigger = false, $mode = '')
  472. {
  473. global $conf, $langs;
  474. $langs->loadLangs(array("accountancy", "bills", "compta"));
  475. dol_syslog(__METHOD__, LOG_DEBUG);
  476. $error = 0;
  477. // Clean parameters
  478. if (isset($this->doc_type)) {
  479. $this->doc_type = trim($this->doc_type);
  480. }
  481. if (isset($this->doc_ref)) {
  482. $this->doc_ref = trim($this->doc_ref);
  483. }
  484. if (isset($this->fk_doc)) {
  485. $this->fk_doc = (int) $this->fk_doc;
  486. }
  487. if (isset($this->fk_docdet)) {
  488. $this->fk_docdet = (int) $this->fk_docdet;
  489. }
  490. if (isset($this->thirdparty_code)) {
  491. $this->thirdparty_code = trim($this->thirdparty_code);
  492. }
  493. if (isset($this->subledger_account)) {
  494. $this->subledger_account = trim($this->subledger_account);
  495. }
  496. if (isset($this->subledger_label)) {
  497. $this->subledger_label = trim($this->subledger_label);
  498. }
  499. if (isset($this->numero_compte)) {
  500. $this->numero_compte = trim($this->numero_compte);
  501. }
  502. if (isset($this->label_compte)) {
  503. $this->label_compte = trim($this->label_compte);
  504. }
  505. if (isset($this->label_operation)) {
  506. $this->label_operation = trim($this->label_operation);
  507. }
  508. if (isset($this->debit)) {
  509. $this->debit = trim($this->debit);
  510. }
  511. if (isset($this->credit)) {
  512. $this->credit = trim($this->credit);
  513. }
  514. if (isset($this->montant)) {
  515. $this->montant = trim($this->montant);
  516. }
  517. if (isset($this->amount)) {
  518. $this->amount = trim($this->amount);
  519. }
  520. if (isset($this->sens)) {
  521. $this->sens = trim($this->sens);
  522. }
  523. if (isset($this->import_key)) {
  524. $this->import_key = trim($this->import_key);
  525. }
  526. if (isset($this->code_journal)) {
  527. $this->code_journal = trim($this->code_journal);
  528. }
  529. if (isset($this->journal_label)) {
  530. $this->journal_label = trim($this->journal_label);
  531. }
  532. if (isset($this->piece_num)) {
  533. $this->piece_num = trim($this->piece_num);
  534. }
  535. if (empty($this->debit)) {
  536. $this->debit = 0;
  537. }
  538. if (empty($this->credit)) {
  539. $this->credit = 0;
  540. }
  541. $this->debit = price2num($this->debit, 'MT');
  542. $this->credit = price2num($this->credit, 'MT');
  543. $now = dol_now();
  544. // Check parameters
  545. $this->journal_label = $langs->trans($this->journal_label);
  546. // Insert request
  547. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.$mode.' (';
  548. $sql .= 'doc_date,';
  549. $sql .= 'date_lim_reglement,';
  550. $sql .= 'doc_type,';
  551. $sql .= 'doc_ref,';
  552. $sql .= 'fk_doc,';
  553. $sql .= 'fk_docdet,';
  554. $sql .= 'thirdparty_code,';
  555. $sql .= 'subledger_account,';
  556. $sql .= 'subledger_label,';
  557. $sql .= 'numero_compte,';
  558. $sql .= 'label_compte,';
  559. $sql .= 'label_operation,';
  560. $sql .= 'debit,';
  561. $sql .= 'credit,';
  562. $sql .= 'montant,';
  563. $sql .= 'sens,';
  564. $sql .= 'fk_user_author,';
  565. $sql .= 'date_creation,';
  566. $sql .= 'code_journal,';
  567. $sql .= 'journal_label,';
  568. $sql .= 'piece_num,';
  569. $sql .= 'entity';
  570. $sql .= ') VALUES (';
  571. $sql .= ' '.(!isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'".$this->db->idate($this->doc_date)."'").',';
  572. $sql .= ' '.(!isset($this->date_lim_reglement) || dol_strlen($this->date_lim_reglement) == 0 ? 'NULL' : "'".$this->db->idate($this->date_lim_reglement)."'").',';
  573. $sql .= ' '.(!isset($this->doc_type) ? 'NULL' : "'".$this->db->escape($this->doc_type)."'").',';
  574. $sql .= ' '.(!isset($this->doc_ref) ? 'NULL' : "'".$this->db->escape($this->doc_ref)."'").',';
  575. $sql .= ' '.(empty($this->fk_doc) ? '0' : (int) $this->fk_doc).',';
  576. $sql .= ' '.(empty($this->fk_docdet) ? '0' : (int) $this->fk_docdet).',';
  577. $sql .= ' '.(!isset($this->thirdparty_code) ? 'NULL' : "'".$this->db->escape($this->thirdparty_code)."'").',';
  578. $sql .= ' '.(!isset($this->subledger_account) ? 'NULL' : "'".$this->db->escape($this->subledger_account)."'").',';
  579. $sql .= ' '.(!isset($this->subledger_label) ? 'NULL' : "'".$this->db->escape($this->subledger_label)."'").',';
  580. $sql .= ' '.(!isset($this->numero_compte) ? 'NULL' : "'".$this->db->escape($this->numero_compte)."'").',';
  581. $sql .= ' '.(!isset($this->label_compte) ? 'NULL' : "'".$this->db->escape($this->label_compte)."'").',';
  582. $sql .= ' '.(!isset($this->label_operation) ? 'NULL' : "'".$this->db->escape($this->label_operation)."'").',';
  583. $sql .= ' '.(!isset($this->debit) ? 'NULL' : $this->debit).',';
  584. $sql .= ' '.(!isset($this->credit) ? 'NULL' : $this->credit).',';
  585. $sql .= ' '.(!isset($this->montant) ? 'NULL' : $this->montant).',';
  586. $sql .= ' '.(!isset($this->sens) ? 'NULL' : "'".$this->db->escape($this->sens)."'").',';
  587. $sql .= ' '.((int) $user->id).',';
  588. $sql .= ' '."'".$this->db->idate($now)."',";
  589. $sql .= ' '.(empty($this->code_journal) ? 'NULL' : "'".$this->db->escape($this->code_journal)."'").',';
  590. $sql .= ' '.(empty($this->journal_label) ? 'NULL' : "'".$this->db->escape($this->journal_label)."'").',';
  591. $sql .= ' '.(empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).',';
  592. $sql .= ' '.(!isset($this->entity) ? $conf->entity : $this->entity);
  593. $sql .= ')';
  594. $this->db->begin();
  595. $resql = $this->db->query($sql);
  596. if (!$resql) {
  597. $error++;
  598. $this->errors[] = 'Error '.$this->db->lasterror();
  599. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  600. }
  601. if (!$error) {
  602. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element.$mode);
  603. // Uncomment this and change MYOBJECT to your own tag if you
  604. // want this action to call a trigger.
  605. //if (! $notrigger) {
  606. // // Call triggers
  607. // $result=$this->call_trigger('MYOBJECT_CREATE',$user);
  608. // if ($result < 0) $error++;
  609. // // End call triggers
  610. //}
  611. }
  612. // Commit or rollback
  613. if ($error) {
  614. $this->db->rollback();
  615. return -1 * $error;
  616. } else {
  617. $this->db->commit();
  618. return $this->id;
  619. }
  620. }
  621. /**
  622. * Load object in memory from the database
  623. *
  624. * @param int $id Id object
  625. * @param string $ref Ref
  626. * @param string $mode Mode
  627. *
  628. * @return int <0 if KO, 0 if not found, >0 if OK
  629. */
  630. public function fetch($id, $ref = null, $mode = '')
  631. {
  632. global $conf;
  633. dol_syslog(__METHOD__, LOG_DEBUG);
  634. $sql = 'SELECT';
  635. $sql .= ' t.rowid,';
  636. $sql .= " t.doc_date,";
  637. $sql .= " t.date_lim_reglement,";
  638. $sql .= " t.doc_type,";
  639. $sql .= " t.doc_ref,";
  640. $sql .= " t.fk_doc,";
  641. $sql .= " t.fk_docdet,";
  642. $sql .= " t.thirdparty_code,";
  643. $sql .= " t.subledger_account,";
  644. $sql .= " t.subledger_label,";
  645. $sql .= " t.numero_compte,";
  646. $sql .= " t.label_compte,";
  647. $sql .= " t.label_operation,";
  648. $sql .= " t.debit,";
  649. $sql .= " t.credit,";
  650. $sql .= " t.montant as amount,";
  651. $sql .= " t.sens,";
  652. $sql .= " t.fk_user_author,";
  653. $sql .= " t.import_key,";
  654. $sql .= " t.code_journal,";
  655. $sql .= " t.journal_label,";
  656. $sql .= " t.piece_num,";
  657. $sql .= " t.date_creation,";
  658. // In llx_accounting_bookkeeping_tmp, field date_export doesn't exist
  659. if ($mode != "_tmp") {
  660. $sql .= " t.date_export,";
  661. }
  662. $sql .= " t.date_validated as date_validation";
  663. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.$mode.' as t';
  664. $sql .= ' WHERE 1 = 1';
  665. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  666. if (null !== $ref) {
  667. $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
  668. } else {
  669. $sql .= ' AND t.rowid = '.((int) $id);
  670. }
  671. $resql = $this->db->query($sql);
  672. if ($resql) {
  673. $numrows = $this->db->num_rows($resql);
  674. if ($numrows) {
  675. $obj = $this->db->fetch_object($resql);
  676. $this->id = $obj->rowid;
  677. $this->doc_date = $this->db->jdate($obj->doc_date);
  678. $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
  679. $this->doc_type = $obj->doc_type;
  680. $this->doc_ref = $obj->doc_ref;
  681. $this->fk_doc = $obj->fk_doc;
  682. $this->fk_docdet = $obj->fk_docdet;
  683. $this->thirdparty_code = $obj->thirdparty_code;
  684. $this->subledger_account = $obj->subledger_account;
  685. $this->subledger_label = $obj->subledger_label;
  686. $this->numero_compte = $obj->numero_compte;
  687. $this->label_compte = $obj->label_compte;
  688. $this->label_operation = $obj->label_operation;
  689. $this->debit = $obj->debit;
  690. $this->credit = $obj->credit;
  691. $this->montant = $obj->amount;
  692. $this->amount = $obj->amount;
  693. $this->sens = $obj->sens;
  694. $this->fk_user_author = $obj->fk_user_author;
  695. $this->import_key = $obj->import_key;
  696. $this->code_journal = $obj->code_journal;
  697. $this->journal_label = $obj->journal_label;
  698. $this->piece_num = $obj->piece_num;
  699. $this->date_creation = $this->db->jdate($obj->date_creation);
  700. $this->date_export = $this->db->jdate($obj->date_export);
  701. $this->date_validation = $this->db->jdate($obj->date_validated);
  702. $this->date_validation = $this->db->jdate($obj->date_validation);
  703. }
  704. $this->db->free($resql);
  705. if ($numrows) {
  706. return 1;
  707. } else {
  708. return 0;
  709. }
  710. } else {
  711. $this->errors[] = 'Error '.$this->db->lasterror();
  712. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  713. return -1;
  714. }
  715. }
  716. /**
  717. * Load object in memory from the database
  718. *
  719. * @param string $sortorder Sort Order
  720. * @param string $sortfield Sort field
  721. * @param int $limit offset limit
  722. * @param int $offset offset limit
  723. * @param array $filter filter array
  724. * @param string $filtermode filter mode (AND or OR)
  725. * @param int $option option (0: general account or 1: subaccount)
  726. *
  727. * @return int <0 if KO, >=0 if OK
  728. */
  729. public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $option = 0)
  730. {
  731. global $conf;
  732. dol_syslog(__METHOD__, LOG_DEBUG);
  733. $this->lines = array();
  734. $sql = 'SELECT';
  735. $sql .= ' t.rowid,';
  736. $sql .= " t.doc_date,";
  737. $sql .= " t.doc_type,";
  738. $sql .= " t.doc_ref,";
  739. $sql .= " t.fk_doc,";
  740. $sql .= " t.fk_docdet,";
  741. $sql .= " t.thirdparty_code,";
  742. $sql .= " t.subledger_account,";
  743. $sql .= " t.subledger_label,";
  744. $sql .= " t.numero_compte,";
  745. $sql .= " t.label_compte,";
  746. $sql .= " t.label_operation,";
  747. $sql .= " t.debit,";
  748. $sql .= " t.credit,";
  749. $sql .= " t.montant as amount,";
  750. $sql .= " t.sens,";
  751. $sql .= " t.multicurrency_amount,";
  752. $sql .= " t.multicurrency_code,";
  753. $sql .= " t.lettering_code,";
  754. $sql .= " t.date_lettering,";
  755. $sql .= " t.fk_user_author,";
  756. $sql .= " t.import_key,";
  757. $sql .= " t.code_journal,";
  758. $sql .= " t.journal_label,";
  759. $sql .= " t.piece_num,";
  760. $sql .= " t.date_creation,";
  761. $sql .= " t.date_export,";
  762. $sql .= " t.date_validated as date_validation,";
  763. $sql .= " t.import_key";
  764. // Manage filter
  765. $sqlwhere = array();
  766. if (count($filter) > 0) {
  767. foreach ($filter as $key => $value) {
  768. if ($key == 't.doc_date') {
  769. $sqlwhere[] = $key.'=\''.$this->db->idate($value).'\'';
  770. } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
  771. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  772. } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
  773. $sqlwhere[] = $key.'\''.$this->db->escape($value).'\'';
  774. } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
  775. $sqlwhere[] = $key.'='.$value;
  776. } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
  777. $sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\'';
  778. } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
  779. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  780. } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') {
  781. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  782. } elseif ($key == 't.date_validated>=' || $key == 't.date_validated<=') {
  783. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  784. } elseif ($key == 't.credit' || $key == 't.debit') {
  785. $sqlwhere[] = natural_search($key, $value, 1, 1);
  786. } elseif ($key == 't.reconciled_option') {
  787. $sqlwhere[] = 't.lettering_code IS NULL';
  788. } elseif ($key == 't.code_journal' && !empty($value)) {
  789. if (is_array($value)) {
  790. $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
  791. } else {
  792. $sqlwhere[] = natural_search("t.code_journal", $value, 3, 1);
  793. }
  794. } else {
  795. $sqlwhere[] = natural_search($key, $value, 0, 1);
  796. }
  797. }
  798. }
  799. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  800. $sql .= ' WHERE 1 = 1';
  801. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  802. if (count($sqlwhere) > 0) {
  803. $sql .= " AND ".implode(" ".$filtermode." ", $sqlwhere);
  804. }
  805. // Affichage par compte comptable
  806. if (!empty($option)) {
  807. $sql .= ' AND t.subledger_account IS NOT NULL';
  808. $sortfield = 't.subledger_account'.($sortfield ? ','.$sortfield : '');
  809. $sortorder = 'ASC'.($sortfield ? ','.$sortfield : '');
  810. } else {
  811. $sortfield = 't.numero_compte'.($sortfield ? ','.$sortfield : '');
  812. $sortorder = 'ASC'.($sortorder ? ','.$sortorder : '');
  813. }
  814. $sql .= $this->db->order($sortfield, $sortorder);
  815. if (!empty($limit)) {
  816. $sql .= $this->db->plimit($limit + 1, $offset);
  817. }
  818. $resql = $this->db->query($sql);
  819. if ($resql) {
  820. $num = $this->db->num_rows($resql);
  821. $i = 0;
  822. while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
  823. $line = new BookKeepingLine();
  824. $line->id = $obj->rowid;
  825. $line->doc_date = $this->db->jdate($obj->doc_date);
  826. $line->doc_type = $obj->doc_type;
  827. $line->doc_ref = $obj->doc_ref;
  828. $line->fk_doc = $obj->fk_doc;
  829. $line->fk_docdet = $obj->fk_docdet;
  830. $line->thirdparty_code = $obj->thirdparty_code;
  831. $line->subledger_account = $obj->subledger_account;
  832. $line->subledger_label = $obj->subledger_label;
  833. $line->numero_compte = $obj->numero_compte;
  834. $line->label_compte = $obj->label_compte;
  835. $line->label_operation = $obj->label_operation;
  836. $line->debit = $obj->debit;
  837. $line->credit = $obj->credit;
  838. $line->montant = $obj->amount; // deprecated
  839. $line->amount = $obj->amount;
  840. $line->sens = $obj->sens;
  841. $line->multicurrency_amount = $obj->multicurrency_amount;
  842. $line->multicurrency_code = $obj->multicurrency_code;
  843. $line->lettering_code = $obj->lettering_code;
  844. $line->date_lettering = $obj->date_lettering;
  845. $line->fk_user_author = $obj->fk_user_author;
  846. $line->import_key = $obj->import_key;
  847. $line->code_journal = $obj->code_journal;
  848. $line->journal_label = $obj->journal_label;
  849. $line->piece_num = $obj->piece_num;
  850. $line->date_creation = $this->db->jdate($obj->date_creation);
  851. $line->date_export = $this->db->jdate($obj->date_export);
  852. $line->date_validation = $this->db->jdate($obj->date_validation);
  853. $line->import_key = $obj->import_key;
  854. $this->lines[] = $line;
  855. $i++;
  856. }
  857. $this->db->free($resql);
  858. return $num;
  859. } else {
  860. $this->errors[] = 'Error '.$this->db->lasterror();
  861. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  862. return -1;
  863. }
  864. }
  865. /**
  866. * Load object in memory from the database
  867. *
  868. * @param string $sortorder Sort Order
  869. * @param string $sortfield Sort field
  870. * @param int $limit Offset limit
  871. * @param int $offset Offset limit
  872. * @param array $filter Filter array
  873. * @param string $filtermode Filter mode (AND or OR)
  874. * @param int $showAlreadyExportMovements Show movements when field 'date_export' is not empty (0:No / 1:Yes (Default))
  875. * @return int <0 if KO, >0 if OK
  876. */
  877. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $showAlreadyExportMovements = 1)
  878. {
  879. global $conf;
  880. dol_syslog(__METHOD__, LOG_DEBUG);
  881. $sql = 'SELECT';
  882. $sql .= ' t.rowid,';
  883. $sql .= " t.doc_date,";
  884. $sql .= " t.doc_type,";
  885. $sql .= " t.doc_ref,";
  886. $sql .= " t.fk_doc,";
  887. $sql .= " t.fk_docdet,";
  888. $sql .= " t.thirdparty_code,";
  889. $sql .= " t.subledger_account,";
  890. $sql .= " t.subledger_label,";
  891. $sql .= " t.numero_compte,";
  892. $sql .= " t.label_compte,";
  893. $sql .= " t.label_operation,";
  894. $sql .= " t.debit,";
  895. $sql .= " t.credit,";
  896. $sql .= " t.lettering_code,";
  897. $sql .= " t.date_lettering,";
  898. $sql .= " t.montant as amount,";
  899. $sql .= " t.sens,";
  900. $sql .= " t.fk_user_author,";
  901. $sql .= " t.import_key,";
  902. $sql .= " t.code_journal,";
  903. $sql .= " t.journal_label,";
  904. $sql .= " t.piece_num,";
  905. $sql .= " t.date_creation,";
  906. $sql .= " t.date_lim_reglement,";
  907. $sql .= " t.tms as date_modification,";
  908. $sql .= " t.date_export,";
  909. $sql .= " t.date_validated as date_validation";
  910. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  911. // Manage filter
  912. $sqlwhere = array();
  913. if (count($filter) > 0) {
  914. foreach ($filter as $key => $value) {
  915. if ($key == 't.doc_date') {
  916. $sqlwhere[] = $key.'=\''.$this->db->idate($value).'\'';
  917. } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
  918. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  919. } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
  920. $sqlwhere[] = $key.'\''.$this->db->escape($value).'\'';
  921. } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
  922. $sqlwhere[] = $key.'='.((int) $value);
  923. } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
  924. $sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\'';
  925. } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') {
  926. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  927. } elseif ($key == 't.tms>=' || $key == 't.tms<=') {
  928. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  929. } elseif ($key == 't.date_export>=' || $key == 't.date_export<=') {
  930. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  931. } elseif ($key == 't.date_validated>=' || $key == 't.date_validated<=') {
  932. $sqlwhere[] = $key.'\''.$this->db->idate($value).'\'';
  933. } elseif ($key == 't.credit' || $key == 't.debit') {
  934. $sqlwhere[] = natural_search($key, $value, 1, 1);
  935. } elseif ($key == 't.code_journal' && !empty($value)) {
  936. if (is_array($value)) {
  937. $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
  938. } else {
  939. $sqlwhere[] = natural_search("t.code_journal", $value, 3, 1);
  940. }
  941. } else {
  942. $sqlwhere[] = natural_search($key, $value, 0, 1);
  943. }
  944. }
  945. }
  946. $sql .= ' WHERE t.entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features
  947. if ($showAlreadyExportMovements == 0) {
  948. $sql .= " AND t.date_export IS NULL";
  949. }
  950. if (count($sqlwhere) > 0) {
  951. $sql .= ' AND '.implode(" ".$filtermode." ", $sqlwhere);
  952. }
  953. if (!empty($sortfield)) {
  954. $sql .= $this->db->order($sortfield, $sortorder);
  955. }
  956. if (!empty($limit)) {
  957. $sql .= $this->db->plimit($limit + 1, $offset);
  958. }
  959. $this->lines = array();
  960. $resql = $this->db->query($sql);
  961. if ($resql) {
  962. $num = $this->db->num_rows($resql);
  963. $i = 0;
  964. while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
  965. $line = new BookKeepingLine();
  966. $line->id = $obj->rowid;
  967. $line->doc_date = $this->db->jdate($obj->doc_date);
  968. $line->doc_type = $obj->doc_type;
  969. $line->doc_ref = $obj->doc_ref;
  970. $line->fk_doc = $obj->fk_doc;
  971. $line->fk_docdet = $obj->fk_docdet;
  972. $line->thirdparty_code = $obj->thirdparty_code;
  973. $line->subledger_account = $obj->subledger_account;
  974. $line->subledger_label = $obj->subledger_label;
  975. $line->numero_compte = $obj->numero_compte;
  976. $line->label_compte = $obj->label_compte;
  977. $line->label_operation = $obj->label_operation;
  978. $line->debit = $obj->debit;
  979. $line->credit = $obj->credit;
  980. $line->montant = $obj->amount; // deprecated
  981. $line->amount = $obj->amount;
  982. $line->sens = $obj->sens;
  983. $line->lettering_code = $obj->lettering_code;
  984. $line->date_lettering = $obj->date_lettering;
  985. $line->fk_user_author = $obj->fk_user_author;
  986. $line->import_key = $obj->import_key;
  987. $line->code_journal = $obj->code_journal;
  988. $line->journal_label = $obj->journal_label;
  989. $line->piece_num = $obj->piece_num;
  990. $line->date_creation = $this->db->jdate($obj->date_creation);
  991. $line->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
  992. $line->date_modification = $this->db->jdate($obj->date_modification);
  993. $line->date_export = $this->db->jdate($obj->date_export);
  994. $line->date_validation = $this->db->jdate($obj->date_validation);
  995. $this->lines[] = $line;
  996. $i++;
  997. }
  998. $this->db->free($resql);
  999. return $num;
  1000. } else {
  1001. $this->errors[] = 'Error '.$this->db->lasterror();
  1002. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1003. return -1;
  1004. }
  1005. }
  1006. /**
  1007. * Load object in memory from the database
  1008. *
  1009. * @param string $sortorder Sort Order
  1010. * @param string $sortfield Sort field
  1011. * @param int $limit offset limit
  1012. * @param int $offset offset limit
  1013. * @param array $filter filter array
  1014. * @param string $filtermode filter mode (AND or OR)
  1015. *
  1016. * @return int <0 if KO, >0 if OK
  1017. */
  1018. public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  1019. {
  1020. global $conf;
  1021. $this->lines = array();
  1022. dol_syslog(__METHOD__, LOG_DEBUG);
  1023. $sql = 'SELECT';
  1024. $sql .= " t.numero_compte,";
  1025. $sql .= " SUM(t.debit) as debit,";
  1026. $sql .= " SUM(t.credit) as credit";
  1027. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  1028. // Manage filter
  1029. $sqlwhere = array();
  1030. if (count($filter) > 0) {
  1031. foreach ($filter as $key => $value) {
  1032. if ($key == 't.doc_date') {
  1033. $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
  1034. } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') {
  1035. $sqlwhere[] = $key."'".$this->db->idate($value)."'";
  1036. } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') {
  1037. $sqlwhere[] = $key."'".$this->db->escape($value)."'";
  1038. } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') {
  1039. $sqlwhere[] = $key." = ".((int) $value);
  1040. } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') {
  1041. $sqlwhere[] = $key." LIKE '".$this->db->escape($value)."%'";
  1042. } elseif ($key == 't.subledger_label') {
  1043. $sqlwhere[] = $key." LIKE '".$this->db->escape($value)."%'";
  1044. } elseif ($key == 't.code_journal' && !empty($value)) {
  1045. if (is_array($value)) {
  1046. $sqlwhere[] = natural_search("t.code_journal", join(',', $value), 3, 1);
  1047. } else {
  1048. $sqlwhere[] = natural_search("t.code_journal", $value, 3, 1);
  1049. }
  1050. } else {
  1051. $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
  1052. }
  1053. }
  1054. }
  1055. $sql .= ' WHERE entity = ' . ((int) $conf->entity); // Do not use getEntity for accounting features
  1056. if (count($sqlwhere) > 0) {
  1057. $sql .= " AND ".implode(" ".$filtermode." ", $sqlwhere);
  1058. }
  1059. $sql .= ' GROUP BY t.numero_compte';
  1060. if (!empty($sortfield)) {
  1061. $sql .= $this->db->order($sortfield, $sortorder);
  1062. }
  1063. if (!empty($limit)) {
  1064. $sql .= $this->db->plimit($limit + 1, $offset);
  1065. }
  1066. $resql = $this->db->query($sql);
  1067. if ($resql) {
  1068. $num = $this->db->num_rows($resql);
  1069. $i = 0;
  1070. while (($obj = $this->db->fetch_object($resql)) && (empty($limit) || $i < min($limit, $num))) {
  1071. $line = new BookKeepingLine();
  1072. $line->numero_compte = $obj->numero_compte;
  1073. $line->debit = $obj->debit;
  1074. $line->credit = $obj->credit;
  1075. $this->lines[] = $line;
  1076. $i++;
  1077. }
  1078. $this->db->free($resql);
  1079. return $num;
  1080. } else {
  1081. $this->errors[] = 'Error '.$this->db->lasterror();
  1082. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1083. return -1;
  1084. }
  1085. }
  1086. /**
  1087. * Update object into database
  1088. *
  1089. * @param User $user User that modifies
  1090. * @param bool $notrigger false=launch triggers after, true=disable triggers
  1091. * @param string $mode Mode ('' or _tmp')
  1092. * @return int <0 if KO, >0 if OK
  1093. */
  1094. public function update(User $user, $notrigger = false, $mode = '')
  1095. {
  1096. $error = 0;
  1097. dol_syslog(__METHOD__, LOG_DEBUG);
  1098. // Clean parameters
  1099. if (isset($this->doc_type)) {
  1100. $this->doc_type = trim($this->doc_type);
  1101. }
  1102. if (isset($this->doc_ref)) {
  1103. $this->doc_ref = trim($this->doc_ref);
  1104. }
  1105. if (isset($this->fk_doc)) {
  1106. $this->fk_doc = (int) $this->fk_doc;
  1107. }
  1108. if (isset($this->fk_docdet)) {
  1109. $this->fk_docdet = (int) $this->fk_docdet;
  1110. }
  1111. if (isset($this->thirdparty_code)) {
  1112. $this->thirdparty_code = trim($this->thirdparty_code);
  1113. }
  1114. if (isset($this->subledger_account)) {
  1115. $this->subledger_account = trim($this->subledger_account);
  1116. }
  1117. if (isset($this->subledger_label)) {
  1118. $this->subledger_label = trim($this->subledger_label);
  1119. }
  1120. if (isset($this->numero_compte)) {
  1121. $this->numero_compte = trim($this->numero_compte);
  1122. }
  1123. if (isset($this->label_compte)) {
  1124. $this->label_compte = trim($this->label_compte);
  1125. }
  1126. if (isset($this->label_operation)) {
  1127. $this->label_operation = trim($this->label_operation);
  1128. }
  1129. if (isset($this->debit)) {
  1130. $this->debit = trim($this->debit);
  1131. }
  1132. if (isset($this->credit)) {
  1133. $this->credit = trim($this->credit);
  1134. }
  1135. if (isset($this->amount)) {
  1136. $this->amount = trim($this->amount);
  1137. }
  1138. if (isset($this->sens)) {
  1139. $this->sens = trim($this->sens);
  1140. }
  1141. if (isset($this->import_key)) {
  1142. $this->import_key = trim($this->import_key);
  1143. }
  1144. if (isset($this->code_journal)) {
  1145. $this->code_journal = trim($this->code_journal);
  1146. }
  1147. if (isset($this->journal_label)) {
  1148. $this->journal_label = trim($this->journal_label);
  1149. }
  1150. if (isset($this->piece_num)) {
  1151. $this->piece_num = trim($this->piece_num);
  1152. }
  1153. $this->debit = price2num($this->debit, 'MT');
  1154. $this->credit = price2num($this->credit, 'MT');
  1155. // Check parameters
  1156. // Put here code to add a control on parameters values
  1157. // Update request
  1158. $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.$mode.' SET';
  1159. $sql .= ' doc_date = '.(!isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'".$this->db->idate($this->doc_date)."'" : 'null').',';
  1160. $sql .= ' doc_type = '.(isset($this->doc_type) ? "'".$this->db->escape($this->doc_type)."'" : "null").',';
  1161. $sql .= ' doc_ref = '.(isset($this->doc_ref) ? "'".$this->db->escape($this->doc_ref)."'" : "null").',';
  1162. $sql .= ' fk_doc = '.(isset($this->fk_doc) ? $this->fk_doc : "null").',';
  1163. $sql .= ' fk_docdet = '.(isset($this->fk_docdet) ? $this->fk_docdet : "null").',';
  1164. $sql .= ' thirdparty_code = '.(isset($this->thirdparty_code) ? "'".$this->db->escape($this->thirdparty_code)."'" : "null").',';
  1165. $sql .= ' subledger_account = '.(isset($this->subledger_account) ? "'".$this->db->escape($this->subledger_account)."'" : "null").',';
  1166. $sql .= ' subledger_label = '.(isset($this->subledger_label) ? "'".$this->db->escape($this->subledger_label)."'" : "null").',';
  1167. $sql .= ' numero_compte = '.(isset($this->numero_compte) ? "'".$this->db->escape($this->numero_compte)."'" : "null").',';
  1168. $sql .= ' label_compte = '.(isset($this->label_compte) ? "'".$this->db->escape($this->label_compte)."'" : "null").',';
  1169. $sql .= ' label_operation = '.(isset($this->label_operation) ? "'".$this->db->escape($this->label_operation)."'" : "null").',';
  1170. $sql .= ' debit = '.(isset($this->debit) ? $this->debit : "null").',';
  1171. $sql .= ' credit = '.(isset($this->credit) ? $this->credit : "null").',';
  1172. $sql .= ' montant = '.(isset($this->montant) ? $this->montant : "null").',';
  1173. $sql .= ' sens = '.(isset($this->sens) ? "'".$this->db->escape($this->sens)."'" : "null").',';
  1174. $sql .= ' fk_user_author = '.(isset($this->fk_user_author) ? $this->fk_user_author : "null").',';
  1175. $sql .= ' import_key = '.(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").',';
  1176. $sql .= ' code_journal = '.(isset($this->code_journal) ? "'".$this->db->escape($this->code_journal)."'" : "null").',';
  1177. $sql .= ' journal_label = '.(isset($this->journal_label) ? "'".$this->db->escape($this->journal_label)."'" : "null").',';
  1178. $sql .= ' piece_num = '.(isset($this->piece_num) ? $this->piece_num : "null");
  1179. $sql .= ' WHERE rowid='.((int) $this->id);
  1180. $this->db->begin();
  1181. $resql = $this->db->query($sql);
  1182. if (!$resql) {
  1183. $error++;
  1184. $this->errors[] = 'Error '.$this->db->lasterror();
  1185. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1186. }
  1187. // Uncomment this and change MYOBJECT to your own tag if you
  1188. // want this action calls a trigger.
  1189. //if (! $error && ! $notrigger) {
  1190. // // Call triggers
  1191. // $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
  1192. // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
  1193. // // End call triggers
  1194. //}
  1195. // Commit or rollback
  1196. if ($error) {
  1197. $this->db->rollback();
  1198. return -1 * $error;
  1199. } else {
  1200. $this->db->commit();
  1201. return 1;
  1202. }
  1203. }
  1204. /**
  1205. * Update accounting movement
  1206. *
  1207. * @param string $piece_num Piece num
  1208. * @param string $field Field
  1209. * @param string $value Value
  1210. * @param string $mode Mode ('' or _tmp')
  1211. * @return number <0 if KO, >0 if OK
  1212. */
  1213. public function updateByMvt($piece_num = '', $field = '', $value = '', $mode = '')
  1214. {
  1215. $error = 0;
  1216. $this->db->begin();
  1217. $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.$mode;
  1218. $sql .= " SET ".$field." = ".(is_numeric($value) ? ((float) $value) : "'".$this->db->escape($value)."'");
  1219. $sql .= " WHERE piece_num = ".((int) $piece_num);
  1220. $resql = $this->db->query($sql);
  1221. if (!$resql) {
  1222. $error++;
  1223. $this->errors[] = 'Error '.$this->db->lasterror();
  1224. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1225. }
  1226. if ($error) {
  1227. $this->db->rollback();
  1228. return -1 * $error;
  1229. } else {
  1230. $this->db->commit();
  1231. return 1;
  1232. }
  1233. }
  1234. /**
  1235. * Delete object in database
  1236. *
  1237. * @param User $user User that deletes
  1238. * @param bool $notrigger false=launch triggers after, true=disable triggers
  1239. * @param string $mode Mode
  1240. * @return int <0 if KO, >0 if OK
  1241. */
  1242. public function delete(User $user, $notrigger = false, $mode = '')
  1243. {
  1244. dol_syslog(__METHOD__, LOG_DEBUG);
  1245. $error = 0;
  1246. $this->db->begin();
  1247. // Uncomment this and change MYOBJECT to your own tag if you
  1248. // want this action calls a trigger.
  1249. //if (! $error && ! $notrigger) {
  1250. // // Call triggers
  1251. // $result=$this->call_trigger('MYOBJECT_DELETE',$user);
  1252. // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
  1253. // // End call triggers
  1254. //}
  1255. if (!$error) {
  1256. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.$mode;
  1257. $sql .= ' WHERE rowid='.((int) $this->id);
  1258. $resql = $this->db->query($sql);
  1259. if (!$resql) {
  1260. $error++;
  1261. $this->errors[] = 'Error '.$this->db->lasterror();
  1262. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1263. }
  1264. }
  1265. // Commit or rollback
  1266. if ($error) {
  1267. $this->db->rollback();
  1268. return -1 * $error;
  1269. } else {
  1270. $this->db->commit();
  1271. return 1;
  1272. }
  1273. }
  1274. /**
  1275. * Delete bookkeeping by importkey
  1276. *
  1277. * @param string $importkey Import key
  1278. * @return int Result
  1279. */
  1280. public function deleteByImportkey($importkey)
  1281. {
  1282. $this->db->begin();
  1283. // first check if line not yet in bookkeeping
  1284. $sql = "DELETE";
  1285. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  1286. $sql .= " WHERE import_key = '".$this->db->escape($importkey)."'";
  1287. $resql = $this->db->query($sql);
  1288. if (!$resql) {
  1289. $this->errors[] = "Error ".$this->db->lasterror();
  1290. dol_syslog(get_class($this)."::delete Error ".$this->db->lasterror(), LOG_ERR);
  1291. $this->db->rollback();
  1292. return -1;
  1293. }
  1294. $this->db->commit();
  1295. return 1;
  1296. }
  1297. /**
  1298. * Delete bookkeeping by year
  1299. *
  1300. * @param int $delyear Year to delete
  1301. * @param string $journal Journal to delete
  1302. * @param string $mode Mode
  1303. * @param int $delmonth Month
  1304. * @return int <0 if KO, >0 if OK
  1305. */
  1306. public function deleteByYearAndJournal($delyear = 0, $journal = '', $mode = '', $delmonth = 0)
  1307. {
  1308. global $conf, $langs;
  1309. if (empty($delyear) && empty($journal)) {
  1310. $this->error = 'ErrorOneFieldRequired';
  1311. return -1;
  1312. }
  1313. if (!empty($delmonth) && empty($delyear)) {
  1314. $this->error = 'YearRequiredIfMonthDefined';
  1315. return -2;
  1316. }
  1317. $this->db->begin();
  1318. // Delete record in bookkeeping
  1319. $sql = "DELETE";
  1320. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
  1321. $sql .= " WHERE 1 = 1";
  1322. $sql .= dolSqlDateFilter('doc_date', 0, $delmonth, $delyear);
  1323. if (!empty($journal)) {
  1324. $sql .= " AND code_journal = '".$this->db->escape($journal)."'";
  1325. }
  1326. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1327. // Exclusion of validated entries at the time of deletion
  1328. $sql .= " AND date_validated IS NULL";
  1329. // TODO: In a future we must forbid deletion if record is inside a closed fiscal period.
  1330. $resql = $this->db->query($sql);
  1331. if (!$resql) {
  1332. $this->errors[] = "Error ".$this->db->lasterror();
  1333. foreach ($this->errors as $errmsg) {
  1334. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  1335. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  1336. }
  1337. $this->db->rollback();
  1338. return -1;
  1339. }
  1340. $this->db->commit();
  1341. return 1;
  1342. }
  1343. /**
  1344. * Delete bookkeeping by piece number
  1345. *
  1346. * @param int $piecenum Piecenum to delete
  1347. * @return int Result
  1348. */
  1349. public function deleteMvtNum($piecenum)
  1350. {
  1351. global $conf;
  1352. $this->db->begin();
  1353. // first check if line not yet in bookkeeping
  1354. $sql = "DELETE";
  1355. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  1356. $sql .= " WHERE piece_num = ".(int) $piecenum;
  1357. $sql .= " AND date_validated IS NULL"; // For security, exclusion of validated entries at the time of deletion
  1358. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1359. $resql = $this->db->query($sql);
  1360. if (!$resql) {
  1361. $this->errors[] = "Error ".$this->db->lasterror();
  1362. foreach ($this->errors as $errmsg) {
  1363. dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
  1364. $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
  1365. }
  1366. $this->db->rollback();
  1367. return -1;
  1368. }
  1369. $this->db->commit();
  1370. return 1;
  1371. }
  1372. /**
  1373. * Load an object from its id and create a new one in database
  1374. *
  1375. * @param User $user User making the clone
  1376. * @param int $fromid Id of object to clone
  1377. * @return int New id of clone
  1378. */
  1379. public function createFromClone(User $user, $fromid)
  1380. {
  1381. dol_syslog(__METHOD__, LOG_DEBUG);
  1382. $error = 0;
  1383. $object = new BookKeeping($this->db);
  1384. $this->db->begin();
  1385. // Load source object
  1386. $object->fetch($fromid);
  1387. // Reset object
  1388. $object->id = 0;
  1389. // Clear fields
  1390. // ...
  1391. // Create clone
  1392. $object->context['createfromclone'] = 'createfromclone';
  1393. $result = $object->create($user);
  1394. // Other options
  1395. if ($result < 0) {
  1396. $error++;
  1397. $this->errors = $object->errors;
  1398. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1399. }
  1400. unset($object->context['createfromclone']);
  1401. // End
  1402. if (!$error) {
  1403. $this->db->commit();
  1404. return $object->id;
  1405. } else {
  1406. $this->db->rollback();
  1407. return -1;
  1408. }
  1409. }
  1410. /**
  1411. * Initialise object with example values
  1412. * Id must be 0 if object instance is a specimen
  1413. *
  1414. * @return void
  1415. */
  1416. public function initAsSpecimen()
  1417. {
  1418. global $user;
  1419. $now = dol_now();
  1420. $this->id = 0;
  1421. $this->doc_date = $now;
  1422. $this->doc_type = '';
  1423. $this->doc_ref = '';
  1424. $this->fk_doc = 0;
  1425. $this->fk_docdet = 0;
  1426. $this->thirdparty_code = 'CU001';
  1427. $this->subledger_account = '41100001';
  1428. $this->subledger_label = 'My customer company';
  1429. $this->numero_compte = '411';
  1430. $this->label_compte = 'Customer';
  1431. $this->label_operation = 'Sales of pea';
  1432. $this->debit = 99.9;
  1433. $this->credit = 0.0;
  1434. $this->amount = 0.0;
  1435. $this->sens = 'D';
  1436. $this->fk_user_author = $user->id;
  1437. $this->import_key = '20201027';
  1438. $this->code_journal = 'VT';
  1439. $this->journal_label = 'Journal de vente';
  1440. $this->piece_num = 1234;
  1441. $this->date_creation = $now;
  1442. }
  1443. /**
  1444. * Load an accounting document into memory from database
  1445. *
  1446. * @param int $piecenum Accounting document to get
  1447. * @param string $mode Mode
  1448. * @return int <0 if KO, >0 if OK
  1449. */
  1450. public function fetchPerMvt($piecenum, $mode = '')
  1451. {
  1452. global $conf;
  1453. $sql = "SELECT piece_num, doc_date,code_journal, journal_label, doc_ref, doc_type,";
  1454. $sql .= " date_creation, tms as date_modification, date_validated as date_validation";
  1455. // In llx_accounting_bookkeeping_tmp, field date_export doesn't exist
  1456. if ($mode != "_tmp") {
  1457. $sql .= ", date_export";
  1458. }
  1459. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
  1460. $sql .= " WHERE piece_num = ".((int) $piecenum);
  1461. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1462. dol_syslog(__METHOD__, LOG_DEBUG);
  1463. $result = $this->db->query($sql);
  1464. if ($result) {
  1465. $obj = $this->db->fetch_object($result);
  1466. $this->piece_num = $obj->piece_num;
  1467. $this->code_journal = $obj->code_journal;
  1468. $this->journal_label = $obj->journal_label;
  1469. $this->doc_date = $this->db->jdate($obj->doc_date);
  1470. $this->doc_ref = $obj->doc_ref;
  1471. $this->doc_type = $obj->doc_type;
  1472. $this->date_creation = $obj->date_creation;
  1473. $this->date_modification = $obj->date_modification;
  1474. $this->date_export = $obj->date_export;
  1475. $this->date_validation = $obj->date_validated;
  1476. $this->date_validation = $obj->date_validation;
  1477. } else {
  1478. $this->error = "Error ".$this->db->lasterror();
  1479. dol_syslog(__METHOD__.$this->error, LOG_ERR);
  1480. return -1;
  1481. }
  1482. return 1;
  1483. }
  1484. /**
  1485. * Return next number movement
  1486. *
  1487. * @param string $mode Mode
  1488. * @return string Next numero to use
  1489. */
  1490. public function getNextNumMvt($mode = '')
  1491. {
  1492. global $conf;
  1493. $sql = "SELECT MAX(piece_num)+1 as max FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
  1494. $sql .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1495. dol_syslog(get_class($this)."::getNextNumMvt", LOG_DEBUG);
  1496. $result = $this->db->query($sql);
  1497. if ($result) {
  1498. $obj = $this->db->fetch_object($result);
  1499. if ($obj) {
  1500. $result = $obj->max;
  1501. }
  1502. if (empty($result)) {
  1503. $result = 1;
  1504. }
  1505. return $result;
  1506. } else {
  1507. $this->error = "Error ".$this->db->lasterror();
  1508. dol_syslog(get_class($this)."::getNextNumMvt ".$this->error, LOG_ERR);
  1509. return -1;
  1510. }
  1511. }
  1512. /**
  1513. * Load all informations of accountancy document
  1514. *
  1515. * @param int $piecenum Id of line to get
  1516. * @param string $mode Mode
  1517. * @return int <0 if KO, >0 if OK
  1518. */
  1519. public function fetchAllPerMvt($piecenum, $mode = '')
  1520. {
  1521. global $conf;
  1522. $sql = "SELECT rowid, doc_date, doc_type,";
  1523. $sql .= " doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
  1524. $sql .= " numero_compte, label_compte, label_operation, debit, credit,";
  1525. $sql .= " montant as amount, sens, fk_user_author, import_key, code_journal, journal_label, piece_num,";
  1526. $sql .= " date_creation, tms as date_modification, date_validated as date_validation";
  1527. // In llx_accounting_bookkeeping_tmp, field date_export doesn't exist
  1528. if ($mode != "_tmp") {
  1529. $sql .= ", date_export";
  1530. }
  1531. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.$mode;
  1532. $sql .= " WHERE piece_num = ".((int) $piecenum);
  1533. $sql .= " AND entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1534. dol_syslog(__METHOD__, LOG_DEBUG);
  1535. $result = $this->db->query($sql);
  1536. if ($result) {
  1537. while ($obj = $this->db->fetch_object($result)) {
  1538. $line = new BookKeepingLine();
  1539. $line->id = $obj->rowid;
  1540. $line->doc_date = $this->db->jdate($obj->doc_date);
  1541. $line->doc_type = $obj->doc_type;
  1542. $line->doc_ref = $obj->doc_ref;
  1543. $line->fk_doc = $obj->fk_doc;
  1544. $line->fk_docdet = $obj->fk_docdet;
  1545. $line->thirdparty_code = $obj->thirdparty_code;
  1546. $line->subledger_account = $obj->subledger_account;
  1547. $line->subledger_label = $obj->subledger_label;
  1548. $line->numero_compte = $obj->numero_compte;
  1549. $line->label_compte = $obj->label_compte;
  1550. $line->label_operation = $obj->label_operation;
  1551. $line->debit = $obj->debit;
  1552. $line->credit = $obj->credit;
  1553. $line->montant = $obj->amount;
  1554. $line->amount = $obj->amount;
  1555. $line->sens = $obj->sens;
  1556. $line->code_journal = $obj->code_journal;
  1557. $line->journal_label = $obj->journal_label;
  1558. $line->piece_num = $obj->piece_num;
  1559. $line->date_creation = $obj->date_creation;
  1560. $line->date_modification = $obj->date_modification;
  1561. $line->date_export = $obj->date_export;
  1562. $line->date_validation = $obj->date_validation;
  1563. $this->linesmvt[] = $line;
  1564. }
  1565. } else {
  1566. $this->error = "Error ".$this->db->lasterror();
  1567. dol_syslog(__METHOD__.$this->error, LOG_ERR);
  1568. return -1;
  1569. }
  1570. return 1;
  1571. }
  1572. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1573. /**
  1574. * Export bookkeeping
  1575. *
  1576. * @param string $model Model
  1577. * @return int Result
  1578. */
  1579. public function export_bookkeeping($model = 'ebp')
  1580. {
  1581. // phpcs:enable
  1582. global $conf;
  1583. $sql = "SELECT rowid, doc_date, doc_type,";
  1584. $sql .= " doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,";
  1585. $sql .= " numero_compte, label_compte, label_operation, debit, credit,";
  1586. $sql .= " montant as amount, sens, fk_user_author, import_key, code_journal, piece_num,";
  1587. $sql .= " date_validated as date_validation";
  1588. $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element;
  1589. $sql .= " WHERE entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1590. dol_syslog(get_class($this)."::export_bookkeeping", LOG_DEBUG);
  1591. $resql = $this->db->query($sql);
  1592. if ($resql) {
  1593. $this->linesexport = array();
  1594. $num = $this->db->num_rows($resql);
  1595. while ($obj = $this->db->fetch_object($resql)) {
  1596. $line = new BookKeepingLine();
  1597. $line->id = $obj->rowid;
  1598. $line->doc_date = $this->db->jdate($obj->doc_date);
  1599. $line->doc_type = $obj->doc_type;
  1600. $line->doc_ref = $obj->doc_ref;
  1601. $line->fk_doc = $obj->fk_doc;
  1602. $line->fk_docdet = $obj->fk_docdet;
  1603. $line->thirdparty_code = $obj->thirdparty_code;
  1604. $line->subledger_account = $obj->subledger_account;
  1605. $line->subledger_label = $obj->subledger_label;
  1606. $line->numero_compte = $obj->numero_compte;
  1607. $line->label_compte = $obj->label_compte;
  1608. $line->label_operation = $obj->label_operation;
  1609. $line->debit = $obj->debit;
  1610. $line->credit = $obj->credit;
  1611. $line->montant = $obj->amount;
  1612. $line->amount = $obj->amount;
  1613. $line->sens = $obj->sens;
  1614. $line->code_journal = $obj->code_journal;
  1615. $line->piece_num = $obj->piece_num;
  1616. $line->date_validation = $obj->date_validation;
  1617. $this->linesexport[] = $line;
  1618. }
  1619. $this->db->free($resql);
  1620. return $num;
  1621. } else {
  1622. $this->error = "Error ".$this->db->lasterror();
  1623. dol_syslog(get_class($this)."::export_bookkeeping ".$this->error, LOG_ERR);
  1624. return -1;
  1625. }
  1626. }
  1627. /**
  1628. * Transform transaction
  1629. *
  1630. * @param number $direction If 0: tmp => real, if 1: real => tmp
  1631. * @param string $piece_num Piece num = Transaction ref
  1632. * @return int int <0 if KO, >0 if OK
  1633. */
  1634. public function transformTransaction($direction = 0, $piece_num = '')
  1635. {
  1636. global $conf;
  1637. $error = 0;
  1638. $this->db->begin();
  1639. if ($direction == 0) {
  1640. $next_piecenum = $this->getNextNumMvt();
  1641. $now = dol_now();
  1642. if ($next_piecenum < 0) {
  1643. $error++;
  1644. }
  1645. if (!$error) {
  1646. // Delete if there is an empty line
  1647. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity)." AND numero_compte IS NULL AND debit = 0 AND credit = 0";
  1648. $resql = $this->db->query($sql);
  1649. if (!$resql) {
  1650. $error++;
  1651. $this->errors[] = 'Error '.$this->db->lasterror();
  1652. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1653. }
  1654. }
  1655. if (!$error) {
  1656. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' (doc_date, doc_type,';
  1657. $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
  1658. $sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
  1659. $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)';
  1660. $sql .= ' SELECT doc_date, doc_type,';
  1661. $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,';
  1662. $sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
  1663. $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.((int) $next_piecenum).", '".$this->db->idate($now)."'";
  1664. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND numero_compte IS NOT NULL AND entity = ' .((int) $conf->entity);
  1665. $resql = $this->db->query($sql);
  1666. if (!$resql) {
  1667. $error++;
  1668. $this->errors[] = 'Error '.$this->db->lasterror();
  1669. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1670. }
  1671. }
  1672. if (!$error) {
  1673. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
  1674. $resql = $this->db->query($sql);
  1675. if (!$resql) {
  1676. $error++;
  1677. $this->errors[] = 'Error '.$this->db->lasterror();
  1678. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1679. }
  1680. }
  1681. } elseif ($direction == 1) {
  1682. if (!$error) {
  1683. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
  1684. $resql = $this->db->query($sql);
  1685. if (!$resql) {
  1686. $error++;
  1687. $this->errors[] = 'Error '.$this->db->lasterror();
  1688. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1689. }
  1690. }
  1691. if (!$error) {
  1692. $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'_tmp (doc_date, doc_type,';
  1693. $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
  1694. $sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
  1695. $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)';
  1696. $sql .= ' SELECT doc_date, doc_type,';
  1697. $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,';
  1698. $sql .= ' numero_compte, label_compte, label_operation, debit, credit,';
  1699. $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num';
  1700. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
  1701. $resql = $this->db->query($sql);
  1702. if (!$resql) {
  1703. $error++;
  1704. $this->errors[] = 'Error '.$this->db->lasterror();
  1705. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1706. }
  1707. }
  1708. if (!$error) {
  1709. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.'_tmp WHERE piece_num = '.((int) $piece_num).' AND entity = ' .((int) $conf->entity);
  1710. $resql = $this->db->query($sql);
  1711. if (!$resql) {
  1712. $error++;
  1713. $this->errors[] = 'Error '.$this->db->lasterror();
  1714. dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
  1715. }
  1716. }
  1717. }
  1718. if (!$error) {
  1719. $this->db->commit();
  1720. return 1;
  1721. } else {
  1722. $this->db->rollback();
  1723. return -1;
  1724. }
  1725. /*
  1726. $sql = "DELETE FROM ";
  1727. $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab";
  1728. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte";
  1729. $sql .= " AND aa.active = 1";
  1730. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  1731. $sql .= " AND asy.rowid = " . ((int) $pcgver);
  1732. $sql .= " AND ab.entity IN (" . getEntity('accountancy') . ")";
  1733. $sql .= " ORDER BY account_number ASC";
  1734. */
  1735. }
  1736. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1737. /**
  1738. * Return list of accounts with label by chart of accounts
  1739. *
  1740. * @param string $selectid Preselected chart of accounts
  1741. * @param string $htmlname Name of field in html form
  1742. * @param int $showempty Add an empty field
  1743. * @param array $event Event options
  1744. * @param int $select_in Value is a aa.rowid (0 default) or aa.account_number (1)
  1745. * @param int $select_out Set value returned by select 0=rowid (default), 1=account_number
  1746. * @param int $aabase Set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number
  1747. * @return string String with HTML select
  1748. */
  1749. public function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '')
  1750. {
  1751. // phpcs:enable
  1752. global $conf;
  1753. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  1754. $pcgver = $conf->global->CHARTOFACCOUNTS;
  1755. $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version";
  1756. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab";
  1757. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.account_number = ab.numero_compte";
  1758. $sql .= " AND aa.active = 1";
  1759. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  1760. $sql .= " AND asy.rowid = ".((int) $pcgver);
  1761. $sql .= " AND ab.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1762. $sql .= " ORDER BY account_number ASC";
  1763. dol_syslog(get_class($this)."::select_account", LOG_DEBUG);
  1764. $resql = $this->db->query($sql);
  1765. if (!$resql) {
  1766. $this->error = "Error ".$this->db->lasterror();
  1767. dol_syslog(get_class($this)."::select_account ".$this->error, LOG_ERR);
  1768. return -1;
  1769. }
  1770. $out = ajax_combobox($htmlname, $event);
  1771. $options = array();
  1772. $selected = null;
  1773. while ($obj = $this->db->fetch_object($resql)) {
  1774. $label = length_accountg($obj->account_number).' - '.$obj->label;
  1775. $select_value_in = $obj->rowid;
  1776. $select_value_out = $obj->rowid;
  1777. if ($select_in == 1) {
  1778. $select_value_in = $obj->account_number;
  1779. }
  1780. if ($select_out == 1) {
  1781. $select_value_out = $obj->account_number;
  1782. }
  1783. // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
  1784. // Because same account_number can be share between different accounting_system and do have the same meaning
  1785. if (($selectid != '') && $selectid == $select_value_in) {
  1786. $selected = $select_value_out;
  1787. }
  1788. $options[$select_value_out] = $label;
  1789. }
  1790. $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300');
  1791. $this->db->free($resql);
  1792. return $out;
  1793. }
  1794. /**
  1795. * Return id and description of a root accounting account.
  1796. * FIXME: This function takes the parent of parent to get the root account !
  1797. *
  1798. * @param string $account Accounting account
  1799. * @return array Array with root account information (max 2 upper level)
  1800. */
  1801. public function getRootAccount($account = null)
  1802. {
  1803. global $conf;
  1804. $pcgver = $conf->global->CHARTOFACCOUNTS;
  1805. $sql = "SELECT root.rowid, root.account_number, root.label as label,";
  1806. $sql .= " parent.rowid as parent_rowid, parent.account_number as parent_account_number, parent.label as parent_label";
  1807. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
  1808. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  1809. $sql .= " AND asy.rowid = ".((int) $pcgver);
  1810. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as parent ON aa.account_parent = parent.rowid AND parent.active = 1";
  1811. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as root ON parent.account_parent = root.rowid AND root.active = 1";
  1812. $sql .= " WHERE aa.account_number = '".$this->db->escape($account)."'";
  1813. $sql .= " AND aa.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1814. dol_syslog(get_class($this)."::select_account", LOG_DEBUG);
  1815. $resql = $this->db->query($sql);
  1816. if ($resql) {
  1817. $obj = '';
  1818. if ($this->db->num_rows($resql)) {
  1819. $obj = $this->db->fetch_object($resql);
  1820. }
  1821. $result = array('id'=>$obj->rowid, 'account_number'=>$obj->account_number, 'label'=>$obj->label);
  1822. return $result;
  1823. } else {
  1824. $this->error = "Error ".$this->db->lasterror();
  1825. dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
  1826. return -1;
  1827. }
  1828. }
  1829. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1830. /**
  1831. * Description of accounting account
  1832. *
  1833. * @param string $account Accounting account
  1834. * @return string Account desc
  1835. */
  1836. public function get_compte_desc($account = null)
  1837. {
  1838. // phpcs:enable
  1839. global $conf;
  1840. $pcgver = $conf->global->CHARTOFACCOUNTS;
  1841. $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
  1842. $sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa ";
  1843. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
  1844. $sql .= " AND aa.account_number = '".$this->db->escape($account)."'";
  1845. $sql .= " AND asy.rowid = ".((int) $pcgver);
  1846. $sql .= " AND aa.active = 1";
  1847. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
  1848. $sql .= " WHERE aa.entity = " . ((int) $conf->entity); // Do not use getEntity for accounting features
  1849. dol_syslog(get_class($this)."::select_account", LOG_DEBUG);
  1850. $resql = $this->db->query($sql);
  1851. if ($resql) {
  1852. $obj = '';
  1853. if ($this->db->num_rows($resql)) {
  1854. $obj = $this->db->fetch_object($resql);
  1855. }
  1856. if (empty($obj->category)) {
  1857. return $obj->label;
  1858. } else {
  1859. return $obj->label.' ('.$obj->category.')';
  1860. }
  1861. } else {
  1862. $this->error = "Error ".$this->db->lasterror();
  1863. dol_syslog(__METHOD__." ".$this->error, LOG_ERR);
  1864. return -1;
  1865. }
  1866. }
  1867. }
  1868. /**
  1869. * Class BookKeepingLine
  1870. */
  1871. class BookKeepingLine
  1872. {
  1873. /**
  1874. * @var int ID
  1875. */
  1876. public $id;
  1877. public $doc_date = '';
  1878. public $doc_type;
  1879. public $doc_ref;
  1880. /**
  1881. * @var int ID
  1882. */
  1883. public $fk_doc;
  1884. /**
  1885. * @var int ID
  1886. */
  1887. public $fk_docdet;
  1888. public $thirdparty_code;
  1889. public $subledger_account;
  1890. public $subledger_label;
  1891. public $numero_compte;
  1892. public $label_compte;
  1893. public $label_operation;
  1894. public $debit;
  1895. public $credit;
  1896. /**
  1897. * @var float Amount
  1898. * @deprecated see $amount
  1899. */
  1900. public $montant;
  1901. /**
  1902. * @var float Amount
  1903. */
  1904. public $amount;
  1905. /**
  1906. * @var float Multicurrency amount
  1907. */
  1908. public $multicurrency_amount;
  1909. /**
  1910. * @var float Multicurrency code
  1911. */
  1912. public $multicurrency_code;
  1913. /**
  1914. * @var string Sens
  1915. */
  1916. public $sens;
  1917. public $lettering_code;
  1918. public $date_lettering;
  1919. /**
  1920. * @var int ID
  1921. */
  1922. public $fk_user_author;
  1923. public $import_key;
  1924. public $code_journal;
  1925. public $journal_label;
  1926. public $piece_num;
  1927. /**
  1928. * @var integer|string date_creation
  1929. */
  1930. public $date_creation;
  1931. /**
  1932. * @var integer|string $date_modification;
  1933. */
  1934. public $date_modification;
  1935. /**
  1936. * @var integer|string $date_export;
  1937. */
  1938. public $date_export;
  1939. /**
  1940. * @var integer|string $date_validation;
  1941. */
  1942. public $date_validation;
  1943. /**
  1944. * @var integer|string $date_lim_reglement;
  1945. */
  1946. public $date_lim_reglement;
  1947. }