accountancyexport.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. /*
  3. * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
  6. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
  8. * Copyright (C) 2016-2018 Alexandre Spangaro <aspangaro@zendsi.com>
  9. * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
  10. * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
  11. * Copyright (C) 2017 Frédéric France <frederic.france@netlogic.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/accountancy/class/accountancyexport.class.php
  28. * \ingroup Advanced accountancy
  29. * \brief Class accountancy export
  30. */
  31. /**
  32. * Class AccountancyExport
  33. *
  34. * Manage the different format accountancy export
  35. */
  36. require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
  37. class AccountancyExport
  38. {
  39. /**
  40. * @var Type of export. Defined by $conf->global->ACCOUNTING_EXPORT_MODELCSV
  41. */
  42. public static $EXPORT_TYPE_NORMAL = 1; // Classic CSV
  43. public static $EXPORT_TYPE_CEGID = 2;
  44. public static $EXPORT_TYPE_COALA = 3;
  45. public static $EXPORT_TYPE_BOB50 = 4;
  46. public static $EXPORT_TYPE_CIEL = 5;
  47. public static $EXPORT_TYPE_QUADRATUS = 6;
  48. public static $EXPORT_TYPE_EBP = 7;
  49. public static $EXPORT_TYPE_COGILOG = 8;
  50. public static $EXPORT_TYPE_AGIRIS = 9;
  51. public static $EXPORT_TYPE_CONFIGURABLE = 10;
  52. public static $EXPORT_TYPE_FEC = 11;
  53. /**
  54. * @var string[] Error codes (or messages)
  55. */
  56. public $errors = array();
  57. /**
  58. *
  59. * @var string Separator
  60. */
  61. public $separator = '';
  62. /**
  63. *
  64. * @var string End of line
  65. */
  66. public $end_line = '';
  67. /**
  68. * Constructor
  69. *
  70. * @param DoliDb $db Database handler
  71. */
  72. public function __construct(DoliDB &$db)
  73. {
  74. global $conf;
  75. $this->db = &$db;
  76. $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  77. $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE)?"\n":($conf->global->ACCOUNTING_EXPORT_ENDLINE==1?"\n":"\r\n");
  78. }
  79. /**
  80. * Array with all export type available (key + label)
  81. *
  82. * @return array of type
  83. */
  84. public static function getType()
  85. {
  86. global $langs;
  87. return array (
  88. self::$EXPORT_TYPE_NORMAL => $langs->trans('Modelcsv_normal'),
  89. self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
  90. self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
  91. self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
  92. self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
  93. self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
  94. self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
  95. self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
  96. self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
  97. self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
  98. self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
  99. );
  100. }
  101. /**
  102. * Array with all export type available (key + label) and parameters for config
  103. *
  104. * @return array of type
  105. */
  106. public static function getTypeConfig()
  107. {
  108. global $conf, $langs;
  109. return array (
  110. 'param' => array(
  111. self::$EXPORT_TYPE_NORMAL => array(
  112. 'label' => $langs->trans('Modelcsv_normal'),
  113. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT)?'txt':$conf->global->ACCOUNTING_EXPORT_FORMAT,
  114. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV)?',':$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  115. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE)?1:$conf->global->ACCOUNTING_EXPORT_ENDLINE,
  116. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE)?'%d%m%Y':$conf->global->ACCOUNTING_EXPORT_DATE,
  117. ),
  118. self::$EXPORT_TYPE_CEGID => array(
  119. 'label' => $langs->trans('Modelcsv_CEGID'),
  120. ),
  121. self::$EXPORT_TYPE_COALA => array(
  122. 'label' => $langs->trans('Modelcsv_COALA'),
  123. ),
  124. self::$EXPORT_TYPE_BOB50 => array(
  125. 'label' => $langs->trans('Modelcsv_bob50'),
  126. ),
  127. self::$EXPORT_TYPE_CIEL => array(
  128. 'label' => $langs->trans('Modelcsv_ciel'),
  129. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  130. ),
  131. self::$EXPORT_TYPE_QUADRATUS => array(
  132. 'label' => $langs->trans('Modelcsv_quadratus'),
  133. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  134. ),
  135. self::$EXPORT_TYPE_EBP => array(
  136. 'label' => $langs->trans('Modelcsv_ebp'),
  137. ),
  138. self::$EXPORT_TYPE_COGILOG => array(
  139. 'label' => $langs->trans('Modelcsv_cogilog'),
  140. ),
  141. self::$EXPORT_TYPE_AGIRIS => array(
  142. 'label' => $langs->trans('Modelcsv_agiris'),
  143. ),
  144. self::$EXPORT_TYPE_CONFIGURABLE => array(
  145. 'label' => $langs->trans('Modelcsv_configurable'),
  146. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT)?'txt':$conf->global->ACCOUNTING_EXPORT_FORMAT,
  147. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV)?',':$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  148. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE)?1:$conf->global->ACCOUNTING_EXPORT_ENDLINE,
  149. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE)?'%d%m%Y':$conf->global->ACCOUNTING_EXPORT_DATE,
  150. ),
  151. self::$EXPORT_TYPE_FEC => array(
  152. 'label' => $langs->trans('Modelcsv_FEC'),
  153. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  154. ),
  155. ),
  156. 'cr'=> array (
  157. '1' => $langs->trans("Unix"),
  158. '2' => $langs->trans("Windows")
  159. ),
  160. 'format' => array (
  161. 'csv' => $langs->trans("csv"),
  162. 'txt' => $langs->trans("txt")
  163. ),
  164. );
  165. }
  166. /**
  167. * Download the export
  168. *
  169. * @return void
  170. */
  171. public static function downloadFile()
  172. {
  173. global $conf;
  174. $filename = 'general_ledger';
  175. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  176. }
  177. /**
  178. * Function who chose which export to use with the default config
  179. *
  180. * @param unknown $TData data
  181. * @return void
  182. */
  183. public function export(&$TData)
  184. {
  185. global $conf, $langs;
  186. self::downloadFile();
  187. switch ($conf->global->ACCOUNTING_EXPORT_MODELCSV) {
  188. case self::$EXPORT_TYPE_NORMAL :
  189. $this->exportNormal($TData);
  190. break;
  191. case self::$EXPORT_TYPE_CEGID :
  192. $this->exportCegid($TData);
  193. break;
  194. case self::$EXPORT_TYPE_COALA :
  195. $this->exportCoala($TData);
  196. break;
  197. case self::$EXPORT_TYPE_BOB50 :
  198. $this->exportBob50($TData);
  199. break;
  200. case self::$EXPORT_TYPE_CIEL :
  201. $this->exportCiel($TData);
  202. break;
  203. case self::$EXPORT_TYPE_QUADRATUS :
  204. $this->exportQuadratus($TData);
  205. break;
  206. case self::$EXPORT_TYPE_EBP :
  207. $this->exportEbp($TData);
  208. break;
  209. case self::$EXPORT_TYPE_COGILOG :
  210. $this->exportCogilog($TData);
  211. break;
  212. case self::$EXPORT_TYPE_AGIRIS :
  213. $this->exportAgiris($TData);
  214. break;
  215. case self::$EXPORT_TYPE_CONFIGURABLE :
  216. $this->exportConfigurable($TData);
  217. break;
  218. case self::$EXPORT_TYPE_FEC :
  219. $this->exportFEC($TData);
  220. break;
  221. default:
  222. $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
  223. break;
  224. }
  225. }
  226. /**
  227. * Export format : Normal
  228. *
  229. * @param array $objectLines data
  230. *
  231. * @return void
  232. */
  233. public function exportNormal($objectLines)
  234. {
  235. global $conf;
  236. foreach ( $objectLines as $line ) {
  237. // Std export
  238. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  239. print $date . $this->separator;
  240. print $line->doc_ref . $this->separator;
  241. print length_accountg($line->numero_compte) . $this->separator;
  242. print length_accounta($line->subledger_account) . $this->separator;
  243. print price($line->debit) . $this->separator;
  244. print price($line->credit) . $this->separator;
  245. print $line->code_journal . $this->separator;
  246. print $this->end_line;
  247. }
  248. }
  249. /**
  250. * Export format : CEGID
  251. *
  252. * @param array $objectLines data
  253. *
  254. * @return void
  255. */
  256. public function exportCegid($objectLines)
  257. {
  258. foreach ( $objectLines as $line ) {
  259. $date = dol_print_date($line->doc_date, '%d%m%Y');
  260. $separator = ";";
  261. $end_line = "\n";
  262. print $date . $separator;
  263. print $line->code_journal . $separator;
  264. print length_accountg($line->numero_compte) . $separator;
  265. print length_accounta($line->subledger_account) . $separator;
  266. print $line->sens . $separator;
  267. print price($line->montant) . $separator;
  268. print $line->label_operation . $separator;
  269. print $line->doc_ref;
  270. print $end_line;
  271. }
  272. }
  273. /**
  274. * Export format : COGILOG
  275. *
  276. * @param array $objectLines data
  277. *
  278. * @return void
  279. */
  280. public function exportCogilog($objectLines)
  281. {
  282. foreach ( $objectLines as $line ) {
  283. $date = dol_print_date($line->doc_date, '%d%m%Y');
  284. $separator = ";";
  285. $end_line = "\n";
  286. print $line->code_journal . $separator;
  287. print $date . $separator;
  288. print $line->piece_num . $separator;
  289. print length_accountg($line->numero_compte) . $separator;
  290. print '' . $separator;
  291. print $line->label_operation . $separator;
  292. print $date . $separator;
  293. if ($line->sens=='D') {
  294. print price($line->montant) . $separator;
  295. print '' . $separator;
  296. }elseif ($line->sens=='C') {
  297. print '' . $separator;
  298. print price($line->montant) . $separator;
  299. }
  300. print $line->doc_ref . $separator;
  301. print $line->label_operation . $separator;
  302. print $end_line;
  303. }
  304. }
  305. /**
  306. * Export format : COALA
  307. *
  308. * @param array $objectLines data
  309. *
  310. * @return void
  311. */
  312. public function exportCoala($objectLines)
  313. {
  314. // Coala export
  315. $separator = ";";
  316. $end_line = "\n";
  317. foreach ( $objectLines as $line ) {
  318. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  319. print $date . $separator;
  320. print $line->code_journal . $separator;
  321. print length_accountg($line->numero_compte) . $separator;
  322. print $line->piece_num . $separator;
  323. print $line->doc_ref . $separator;
  324. print price($line->debit) . $separator;
  325. print price($line->credit) . $separator;
  326. print 'E' . $separator;
  327. print length_accountg($line->subledger_account) . $separator;
  328. print $end_line;
  329. }
  330. }
  331. /**
  332. * Export format : BOB50
  333. *
  334. * @param array $objectLines data
  335. *
  336. * @return void
  337. */
  338. public function exportBob50($objectLines)
  339. {
  340. // Bob50
  341. $separator = ";";
  342. $end_line = "\n";
  343. foreach ( $objectLines as $line ) {
  344. print $line->piece_num . $separator;
  345. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  346. print $date . $separator;
  347. if (empty($line->subledger_account)) {
  348. print 'G' . $separator;
  349. print length_accounta($line->numero_compte) . $separator;
  350. } else {
  351. if (substr($line->numero_compte, 0, 3) == '411') {
  352. print 'C' . $separator;
  353. }
  354. if (substr($line->numero_compte, 0, 3) == '401') {
  355. print 'F' . $separator;
  356. }
  357. print length_accountg($line->subledger_account) . $separator;
  358. }
  359. print price($line->debit) . $separator;
  360. print price($line->credit) . $separator;
  361. print dol_trunc($line->label_operation, 32) . $separator;
  362. print $end_line;
  363. }
  364. }
  365. /**
  366. * Export format : CIEL
  367. *
  368. * @param array $TData data
  369. *
  370. * @return void
  371. */
  372. public function exportCiel(&$TData)
  373. {
  374. global $conf;
  375. $end_line ="\r\n";
  376. $i = 1;
  377. $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd
  378. foreach ( $TData as $data ) {
  379. $code_compta = $data->numero_compte;
  380. if (! empty($data->subledger_account))
  381. $code_compta = $data->subledger_account;
  382. $Tab = array ();
  383. $Tab['num_ecriture'] = str_pad($i, 5);
  384. $Tab['code_journal'] = str_pad($data->code_journal, 2);
  385. $Tab['date_ecriture'] = $date_ecriture;
  386. $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  387. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12);
  388. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
  389. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . dol_string_unaccent($data->label_operation), 25), 25);
  390. $Tab['montant'] = str_pad(abs($data->montant), 13, ' ', STR_PAD_LEFT);
  391. $Tab['type_montant'] = str_pad($data->sens, 1);
  392. $Tab['vide'] = str_repeat(' ', 18);
  393. $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
  394. $Tab['end'] = 'O2003';
  395. $Tab['end_line'] = $end_line;
  396. print implode($Tab);
  397. $i ++;
  398. }
  399. }
  400. /**
  401. * Export format : Quadratus
  402. *
  403. * @param array $TData data
  404. *
  405. * @return void
  406. */
  407. public function exportQuadratus(&$TData)
  408. {
  409. global $conf;
  410. $end_line ="\r\n";
  411. //We should use dol_now function not time however this is wrong date to transfert in accounting
  412. //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  413. //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  414. foreach ( $TData as $data ) {
  415. $code_compta = $data->numero_compte;
  416. if (! empty($data->subledger_account))
  417. $code_compta = $data->subledger_account;
  418. $Tab = array ();
  419. $Tab['type_ligne'] = 'M';
  420. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
  421. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  422. $Tab['folio'] = '000';
  423. //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  424. //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  425. //$Tab['date_ecriture'] = $date_ecriture;
  426. $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  427. $Tab['filler'] = ' ';
  428. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 20), 20);
  429. $Tab['sens'] = $data->sens; // C or D
  430. $Tab['signe_montant'] = '+';
  431. //elarifr le montant doit etre en centimes sans point decimal !
  432. $Tab['montant'] = str_pad(abs($data->montant*100), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  433. // $Tab['montant'] = str_pad(abs($data->montant), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  434. $Tab['contrepartie'] = str_repeat(' ', 8);
  435. // elarifr: date format must be fixed format : 6 char ddmmyy = %d%m%yand not defined by user / dolibarr setting
  436. if (! empty($data->date_echeance))
  437. //$Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
  438. $Tab['date_echeance'] = dol_print_date($data->date_echeance, '%d%m%y' ); // elarifr: format must be ddmmyy
  439. else
  440. $Tab['date_echeance'] = '000000';
  441. //elarifr please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
  442. //$Tab['lettrage'] = str_repeat(' ', 5);
  443. $Tab['lettrage'] = str_repeat(' ', 2);
  444. $Tab['codestat'] = str_repeat(' ', 3);
  445. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
  446. //elarifr keep correct quadra named field instead of anon filler
  447. //$Tab['filler2'] = str_repeat(' ', 20);
  448. $Tab['affaire'] = str_repeat(' ', 10);
  449. $Tab['quantity1'] = str_repeat(' ', 10);
  450. $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
  451. $Tab['devis'] = str_pad($conf->currency, 3);
  452. $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
  453. $Tab['filler3'] = str_repeat(' ', 3);
  454. //elarifr keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
  455. //as we use utf8, we must remove accent to have only one ascii char instead of utf8 2 chars for specials that report wrong line size that will exceed import format spec
  456. //todo we should filter more than only accent to avoid wrong line size
  457. //TODO: remove invoice number doc_ref in libelle,
  458. //TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
  459. //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
  460. $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
  461. $Tab['codetva'] = str_repeat(' ', 2);
  462. //elarifr we need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
  463. //$Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
  464. $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
  465. $Tab['filler4'] = str_repeat(' ', 73);
  466. $Tab['end_line'] = $end_line;
  467. print implode($Tab);
  468. }
  469. }
  470. /**
  471. * Export format : EBP
  472. *
  473. * @param array $objectLines data
  474. *
  475. * @return void
  476. */
  477. public function exportEbp($objectLines)
  478. {
  479. $separator = ',';
  480. $end_line = "\n";
  481. foreach ( $objectLines as $line ) {
  482. $date = dol_print_date($line->doc_date, '%d%m%Y');
  483. print $line->id . $separator;
  484. print $date . $separator;
  485. print $line->code_journal . $separator;
  486. print length_accountg($line->numero_compte) . $separator;
  487. print substr(length_accountg($line->numero_compte),0,2) . $separator;
  488. print '"'.dol_trunc($line->label_operation,40,'right','UTF-8',1).'"' . $separator;
  489. print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$separator;
  490. print price2num($line->montant).$separator;
  491. print $line->sens.$separator;
  492. print $date . $separator;
  493. print 'EUR';
  494. print $end_line;
  495. }
  496. }
  497. /**
  498. * Export format : Agiris Isacompta
  499. *
  500. * @param array $objectLines data
  501. *
  502. * @return void
  503. */
  504. public function exportAgiris($objectLines)
  505. {
  506. $separator = ';';
  507. $end_line = "\n";
  508. foreach ( $objectLines as $line ) {
  509. $date = dol_print_date($line->doc_date, '%d%m%Y');
  510. print $line->piece_num . $separator;
  511. print $line->label_operation . $separator;
  512. print $date . $separator;
  513. print $line->label_operation . $separator;
  514. if (empty($line->subledger_account)) {
  515. print length_accountg($line->numero_compte) . $separator;
  516. } else {
  517. print length_accounta($line->subledger_account) . $separator;
  518. }
  519. print $line->doc_ref . $separator;
  520. print price($line->debit) . $separator;
  521. print price($line->credit) . $separator;
  522. print price($line->montant) . $separator;
  523. print $line->sens . $separator;
  524. print $line->code_journal;
  525. print $end_line;
  526. }
  527. }
  528. /**
  529. * Export format : Configurable
  530. *
  531. * @param array $objectLines data
  532. *
  533. * @return void
  534. */
  535. public function exportConfigurable($objectLines)
  536. {
  537. global $conf;
  538. foreach ($objectLines as $line) {
  539. $tab = array();
  540. // export configurable
  541. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  542. $tab[] = $line->piece_num;
  543. $tab[] = $date;
  544. $tab[] = $line->doc_ref;
  545. $tab[] = $line->label_operation;
  546. $tab[] = length_accountg($line->numero_compte);
  547. $tab[] = length_accounta($line->subledger_account);
  548. $tab[] = price($line->debit);
  549. $tab[] = price($line->credit);
  550. $tab[] = price($line->montant);
  551. $tab[] = $line->code_journal;
  552. $separator = $this->separator;
  553. print implode($separator, $tab) . $this->end_line;
  554. }
  555. }
  556. /**
  557. * Export format : FEC
  558. *
  559. * @param array $objectLines data
  560. *
  561. * @return void
  562. */
  563. public function exportFEC($objectLines)
  564. {
  565. $separator = ';';
  566. $end_line = "\n";
  567. foreach ( $objectLines as $line ) {
  568. $date_creation = dol_print_date($line->date_creation, '%d%m%Y');
  569. $date_doc = dol_print_date($line->doc_date, '%d%m%Y');
  570. $date_valid = dol_print_date($line->date_validated, '%d%m%Y');
  571. // FEC:JournalCode
  572. print $line->code_journal;
  573. // FEC:JournalLib
  574. print $line->journal_label;
  575. // FEC:EcritureNum
  576. print $line->piece_num . $separator;
  577. // FEC:EcritureDate
  578. print $date_creation . $separator;
  579. // FEC:CompteNum
  580. print $line->numero_compte . $separator
  581. // FEC:CompteLib
  582. print $line->label_compte . $separator;
  583. // FEC:CompAuxNum
  584. print $line->subledger_account . $separator;
  585. // FEC:CompAuxLib
  586. print $line->subledger_label . $separator;
  587. // FEC:PieceRef
  588. print $line->doc_ref . $separator;
  589. // FEC:PieceDate
  590. print $date_doc . $separator;
  591. // FEC:EcritureLib
  592. print $line->label_operation . $separator;
  593. // FEC:Debit
  594. print price($line->debit) . $separator;
  595. // FEC:Credit
  596. print price($line->credit) . $separator;
  597. // FEC:EcritureLet
  598. print $line->lettering_code . $separator;
  599. // FEC:DateLet
  600. print $line->date_lettering . $separator;
  601. // FEC:ValidDate
  602. print $date_valid . $separator;
  603. // FEC:Montantdevise
  604. print $line->multicurrency_amount . $separator;
  605. // FEC:Idevise
  606. print $line->multicurrency_code;
  607. print $end_line;
  608. }
  609. }
  610. /**
  611. *
  612. * @param unknown $str data
  613. * @param integer $size data
  614. * @return string
  615. */
  616. public static function trunc($str, $size)
  617. {
  618. return dol_trunc($str, $size, 'right', 'UTF-8', 1);
  619. }
  620. }