accountancyexport.class.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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@open-dsi.fr>
  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; // CSV
  43. public static $EXPORT_TYPE_CONFIGURABLE = 10; // CSV
  44. public static $EXPORT_TYPE_CEGID = 2;
  45. public static $EXPORT_TYPE_COALA = 3;
  46. public static $EXPORT_TYPE_BOB50 = 4;
  47. public static $EXPORT_TYPE_CIEL = 5;
  48. public static $EXPORT_TYPE_QUADRATUS = 6;
  49. public static $EXPORT_TYPE_EBP = 7;
  50. public static $EXPORT_TYPE_COGILOG = 8;
  51. public static $EXPORT_TYPE_AGIRIS = 9;
  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_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
  90. self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
  91. self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
  92. self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
  93. self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
  94. self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
  95. self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
  96. self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
  97. self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
  98. self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
  99. );
  100. }
  101. /**
  102. * Return string to summarize the format (Used to generated export filename)
  103. *
  104. * @param int $type Format id
  105. * @return string Format code
  106. */
  107. private static function getFormatCode($type)
  108. {
  109. $formatcode = array (
  110. //self::$EXPORT_TYPE_NORMAL => 'csv',
  111. self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
  112. self::$EXPORT_TYPE_CEGID => 'cegid',
  113. self::$EXPORT_TYPE_COALA => 'coala',
  114. self::$EXPORT_TYPE_BOB50 => 'bob50',
  115. self::$EXPORT_TYPE_CIEL => 'ciel',
  116. self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
  117. self::$EXPORT_TYPE_EBP => 'ebp',
  118. self::$EXPORT_TYPE_COGILOG => 'cogilog',
  119. self::$EXPORT_TYPE_AGIRIS => 'agiris',
  120. self::$EXPORT_TYPE_FEC => 'fec',
  121. );
  122. return $formatcode[$type];
  123. }
  124. /**
  125. * Array with all export type available (key + label) and parameters for config
  126. *
  127. * @return array of type
  128. */
  129. public static function getTypeConfig()
  130. {
  131. global $conf, $langs;
  132. return array (
  133. 'param' => array(
  134. /*self::$EXPORT_TYPE_NORMAL => array(
  135. 'label' => $langs->trans('Modelcsv_normal'),
  136. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT)?'txt':$conf->global->ACCOUNTING_EXPORT_FORMAT,
  137. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV)?',':$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  138. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE)?1:$conf->global->ACCOUNTING_EXPORT_ENDLINE,
  139. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE)?'%d%m%Y':$conf->global->ACCOUNTING_EXPORT_DATE,
  140. ),*/
  141. self::$EXPORT_TYPE_CEGID => array(
  142. 'label' => $langs->trans('Modelcsv_CEGID'),
  143. ),
  144. self::$EXPORT_TYPE_COALA => array(
  145. 'label' => $langs->trans('Modelcsv_COALA'),
  146. ),
  147. self::$EXPORT_TYPE_BOB50 => array(
  148. 'label' => $langs->trans('Modelcsv_bob50'),
  149. ),
  150. self::$EXPORT_TYPE_CIEL => array(
  151. 'label' => $langs->trans('Modelcsv_ciel'),
  152. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  153. ),
  154. self::$EXPORT_TYPE_QUADRATUS => array(
  155. 'label' => $langs->trans('Modelcsv_quadratus'),
  156. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  157. ),
  158. self::$EXPORT_TYPE_EBP => array(
  159. 'label' => $langs->trans('Modelcsv_ebp'),
  160. ),
  161. self::$EXPORT_TYPE_COGILOG => array(
  162. 'label' => $langs->trans('Modelcsv_cogilog'),
  163. ),
  164. self::$EXPORT_TYPE_AGIRIS => array(
  165. 'label' => $langs->trans('Modelcsv_agiris'),
  166. ),
  167. self::$EXPORT_TYPE_CONFIGURABLE => array(
  168. 'label' => $langs->trans('Modelcsv_configurable'),
  169. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT)?'txt':$conf->global->ACCOUNTING_EXPORT_FORMAT,
  170. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV)?',':$conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  171. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE)?1:$conf->global->ACCOUNTING_EXPORT_ENDLINE,
  172. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE)?'%d%m%Y':$conf->global->ACCOUNTING_EXPORT_DATE,
  173. ),
  174. self::$EXPORT_TYPE_FEC => array(
  175. 'label' => $langs->trans('Modelcsv_FEC'),
  176. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  177. ),
  178. ),
  179. 'cr'=> array (
  180. '1' => $langs->trans("Unix"),
  181. '2' => $langs->trans("Windows")
  182. ),
  183. 'format' => array (
  184. 'csv' => $langs->trans("csv"),
  185. 'txt' => $langs->trans("txt")
  186. ),
  187. );
  188. }
  189. /**
  190. * Function who chose which export to use with the default config, and make the export into a file
  191. *
  192. * @param array $TData data
  193. * @return void
  194. */
  195. public function export(&$TData)
  196. {
  197. global $conf, $langs;
  198. global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
  199. // Define name of file to save
  200. $filename = 'general_ledger-'.$this->getFormatCode($conf->global->ACCOUNTING_EXPORT_MODELCSV);
  201. $type_export = 'general_ledger';
  202. include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
  203. switch ($conf->global->ACCOUNTING_EXPORT_MODELCSV) {
  204. case self::$EXPORT_TYPE_NORMAL :
  205. case self::$EXPORT_TYPE_CONFIGURABLE :
  206. $this->exportConfigurable($TData);
  207. break;
  208. case self::$EXPORT_TYPE_NORMAL :
  209. case self::$EXPORT_TYPE_CEGID :
  210. $this->exportCegid($TData);
  211. break;
  212. case self::$EXPORT_TYPE_COALA :
  213. $this->exportCoala($TData);
  214. break;
  215. case self::$EXPORT_TYPE_BOB50 :
  216. $this->exportBob50($TData);
  217. break;
  218. case self::$EXPORT_TYPE_CIEL :
  219. $this->exportCiel($TData);
  220. break;
  221. case self::$EXPORT_TYPE_QUADRATUS :
  222. $this->exportQuadratus($TData);
  223. break;
  224. case self::$EXPORT_TYPE_EBP :
  225. $this->exportEbp($TData);
  226. break;
  227. case self::$EXPORT_TYPE_COGILOG :
  228. $this->exportCogilog($TData);
  229. break;
  230. case self::$EXPORT_TYPE_AGIRIS :
  231. $this->exportAgiris($TData);
  232. break;
  233. case self::$EXPORT_TYPE_FEC :
  234. $this->exportFEC($TData);
  235. break;
  236. default:
  237. $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
  238. break;
  239. }
  240. }
  241. /**
  242. * Export format : CEGID
  243. *
  244. * @param array $objectLines data
  245. *
  246. * @return void
  247. */
  248. public function exportCegid($objectLines)
  249. {
  250. foreach ( $objectLines as $line ) {
  251. $date = dol_print_date($line->doc_date, '%d%m%Y');
  252. $separator = ";";
  253. $end_line = "\n";
  254. print $date . $separator;
  255. print $line->code_journal . $separator;
  256. print length_accountg($line->numero_compte) . $separator;
  257. print length_accounta($line->subledger_account) . $separator;
  258. print $line->sens . $separator;
  259. print price($line->montant) . $separator;
  260. print $line->label_operation . $separator;
  261. print $line->doc_ref;
  262. print $end_line;
  263. }
  264. }
  265. /**
  266. * Export format : COGILOG
  267. *
  268. * @param array $objectLines data
  269. *
  270. * @return void
  271. */
  272. public function exportCogilog($objectLines)
  273. {
  274. foreach ( $objectLines as $line ) {
  275. $date = dol_print_date($line->doc_date, '%d%m%Y');
  276. $separator = ";";
  277. $end_line = "\n";
  278. print $line->code_journal . $separator;
  279. print $date . $separator;
  280. print $line->piece_num . $separator;
  281. print length_accountg($line->numero_compte) . $separator;
  282. print '' . $separator;
  283. print $line->label_operation . $separator;
  284. print $date . $separator;
  285. if ($line->sens=='D') {
  286. print price($line->montant) . $separator;
  287. print '' . $separator;
  288. }elseif ($line->sens=='C') {
  289. print '' . $separator;
  290. print price($line->montant) . $separator;
  291. }
  292. print $line->doc_ref . $separator;
  293. print $line->label_operation . $separator;
  294. print $end_line;
  295. }
  296. }
  297. /**
  298. * Export format : COALA
  299. *
  300. * @param array $objectLines data
  301. *
  302. * @return void
  303. */
  304. public function exportCoala($objectLines)
  305. {
  306. // Coala export
  307. $separator = ";";
  308. $end_line = "\n";
  309. foreach ( $objectLines as $line ) {
  310. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  311. print $date . $separator;
  312. print $line->code_journal . $separator;
  313. print length_accountg($line->numero_compte) . $separator;
  314. print $line->piece_num . $separator;
  315. print $line->doc_ref . $separator;
  316. print price($line->debit) . $separator;
  317. print price($line->credit) . $separator;
  318. print 'E' . $separator;
  319. print length_accountg($line->subledger_account) . $separator;
  320. print $end_line;
  321. }
  322. }
  323. /**
  324. * Export format : BOB50
  325. *
  326. * @param array $objectLines data
  327. *
  328. * @return void
  329. */
  330. public function exportBob50($objectLines)
  331. {
  332. // Bob50
  333. $separator = ";";
  334. $end_line = "\n";
  335. foreach ( $objectLines as $line ) {
  336. print $line->piece_num . $separator;
  337. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  338. print $date . $separator;
  339. if (empty($line->subledger_account)) {
  340. print 'G' . $separator;
  341. print length_accounta($line->numero_compte) . $separator;
  342. } else {
  343. if (substr($line->numero_compte, 0, 3) == '411') {
  344. print 'C' . $separator;
  345. }
  346. if (substr($line->numero_compte, 0, 3) == '401') {
  347. print 'F' . $separator;
  348. }
  349. print length_accountg($line->subledger_account) . $separator;
  350. }
  351. print price($line->debit) . $separator;
  352. print price($line->credit) . $separator;
  353. print dol_trunc($line->label_operation, 32) . $separator;
  354. print $end_line;
  355. }
  356. }
  357. /**
  358. * Export format : CIEL
  359. *
  360. * @param array $TData data
  361. *
  362. * @return void
  363. */
  364. public function exportCiel(&$TData)
  365. {
  366. global $conf;
  367. $end_line ="\r\n";
  368. $i = 1;
  369. $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd
  370. foreach ( $TData as $data ) {
  371. $code_compta = $data->numero_compte;
  372. if (! empty($data->subledger_account))
  373. $code_compta = $data->subledger_account;
  374. $Tab = array ();
  375. $Tab['num_ecriture'] = str_pad($i, 5);
  376. $Tab['code_journal'] = str_pad($data->code_journal, 2);
  377. $Tab['date_ecriture'] = $date_ecriture;
  378. $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  379. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12);
  380. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
  381. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . dol_string_unaccent($data->label_operation), 25), 25);
  382. $Tab['montant'] = str_pad(abs($data->montant), 13, ' ', STR_PAD_LEFT);
  383. $Tab['type_montant'] = str_pad($data->sens, 1);
  384. $Tab['vide'] = str_repeat(' ', 18);
  385. $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
  386. $Tab['end'] = 'O2003';
  387. $Tab['end_line'] = $end_line;
  388. print implode($Tab);
  389. $i ++;
  390. }
  391. }
  392. /**
  393. * Export format : Quadratus
  394. *
  395. * @param array $TData data
  396. *
  397. * @return void
  398. */
  399. public function exportQuadratus(&$TData)
  400. {
  401. global $conf;
  402. $end_line ="\r\n";
  403. //We should use dol_now function not time however this is wrong date to transfert in accounting
  404. //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  405. //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  406. foreach ( $TData as $data ) {
  407. $code_compta = $data->numero_compte;
  408. if (! empty($data->subledger_account))
  409. $code_compta = $data->subledger_account;
  410. $Tab = array ();
  411. $Tab['type_ligne'] = 'M';
  412. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
  413. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  414. $Tab['folio'] = '000';
  415. //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  416. //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  417. //$Tab['date_ecriture'] = $date_ecriture;
  418. $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  419. $Tab['filler'] = ' ';
  420. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 20), 20);
  421. $Tab['sens'] = $data->sens; // C or D
  422. $Tab['signe_montant'] = '+';
  423. //elarifr le montant doit etre en centimes sans point decimal !
  424. $Tab['montant'] = str_pad(abs($data->montant*100), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  425. // $Tab['montant'] = str_pad(abs($data->montant), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  426. $Tab['contrepartie'] = str_repeat(' ', 8);
  427. // elarifr: date format must be fixed format : 6 char ddmmyy = %d%m%yand not defined by user / dolibarr setting
  428. if (! empty($data->date_echeance))
  429. //$Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
  430. $Tab['date_echeance'] = dol_print_date($data->date_echeance, '%d%m%y' ); // elarifr: format must be ddmmyy
  431. else
  432. $Tab['date_echeance'] = '000000';
  433. //elarifr please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
  434. //$Tab['lettrage'] = str_repeat(' ', 5);
  435. $Tab['lettrage'] = str_repeat(' ', 2);
  436. $Tab['codestat'] = str_repeat(' ', 3);
  437. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
  438. //elarifr keep correct quadra named field instead of anon filler
  439. //$Tab['filler2'] = str_repeat(' ', 20);
  440. $Tab['affaire'] = str_repeat(' ', 10);
  441. $Tab['quantity1'] = str_repeat(' ', 10);
  442. $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
  443. $Tab['devis'] = str_pad($conf->currency, 3);
  444. $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
  445. $Tab['filler3'] = str_repeat(' ', 3);
  446. //elarifr keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
  447. //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
  448. //todo we should filter more than only accent to avoid wrong line size
  449. //TODO: remove invoice number doc_ref in libelle,
  450. //TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
  451. //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
  452. $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
  453. $Tab['codetva'] = str_repeat(' ', 2);
  454. //elarifr we need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
  455. //$Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
  456. $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
  457. $Tab['filler4'] = str_repeat(' ', 73);
  458. $Tab['end_line'] = $end_line;
  459. print implode($Tab);
  460. }
  461. }
  462. /**
  463. * Export format : EBP
  464. *
  465. * @param array $objectLines data
  466. *
  467. * @return void
  468. */
  469. public function exportEbp($objectLines)
  470. {
  471. $separator = ',';
  472. $end_line = "\n";
  473. foreach ( $objectLines as $line ) {
  474. $date = dol_print_date($line->doc_date, '%d%m%Y');
  475. print $line->id . $separator;
  476. print $date . $separator;
  477. print $line->code_journal . $separator;
  478. print length_accountg($line->numero_compte) . $separator;
  479. print substr(length_accountg($line->numero_compte),0,2) . $separator;
  480. print '"'.dol_trunc($line->label_operation,40,'right','UTF-8',1).'"' . $separator;
  481. print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$separator;
  482. print price2num($line->montant).$separator;
  483. print $line->sens.$separator;
  484. print $date . $separator;
  485. print 'EUR';
  486. print $end_line;
  487. }
  488. }
  489. /**
  490. * Export format : Agiris Isacompta
  491. *
  492. * @param array $objectLines data
  493. *
  494. * @return void
  495. */
  496. public function exportAgiris($objectLines)
  497. {
  498. $separator = ';';
  499. $end_line = "\n";
  500. foreach ( $objectLines as $line ) {
  501. $date = dol_print_date($line->doc_date, '%d%m%Y');
  502. print $line->piece_num . $separator;
  503. print $line->label_operation . $separator;
  504. print $date . $separator;
  505. print $line->label_operation . $separator;
  506. if (empty($line->subledger_account)) {
  507. print length_accountg($line->numero_compte) . $separator;
  508. print $line->label_compte . $separator;
  509. } else {
  510. print length_accounta($line->subledger_account) . $separator;
  511. print $line->subledger_label . $separator;
  512. }
  513. print $line->doc_ref . $separator;
  514. print price($line->debit) . $separator;
  515. print price($line->credit) . $separator;
  516. print price($line->montant) . $separator;
  517. print $line->sens . $separator;
  518. print $line->lettering_code . $separator;
  519. print $line->code_journal;
  520. print $end_line;
  521. }
  522. }
  523. /**
  524. * Export format : Configurable
  525. *
  526. * @param array $objectLines data
  527. *
  528. * @return void
  529. */
  530. public function exportConfigurable($objectLines)
  531. {
  532. global $conf;
  533. foreach ($objectLines as $line) {
  534. $tab = array();
  535. // export configurable
  536. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  537. $tab[] = $line->piece_num;
  538. $tab[] = $date;
  539. $tab[] = $line->doc_ref;
  540. $tab[] = $line->label_operation;
  541. $tab[] = length_accountg($line->numero_compte);
  542. $tab[] = length_accounta($line->subledger_account);
  543. $tab[] = price($line->debit);
  544. $tab[] = price($line->credit);
  545. $tab[] = price($line->montant);
  546. $tab[] = $line->code_journal;
  547. $separator = $this->separator;
  548. print implode($separator, $tab) . $this->end_line;
  549. }
  550. }
  551. /**
  552. * Export format : FEC
  553. *
  554. * @param array $objectLines data
  555. *
  556. * @return void
  557. */
  558. public function exportFEC($objectLines)
  559. {
  560. $separator = "\t";
  561. $end_line = "\n";
  562. print "JournalCode" . $separator;
  563. print "JournalLib" . $separator;
  564. print "EcritureNum" . $separator;
  565. print "EcritureDate" . $separator;
  566. print "CompteNum" . $separator;
  567. print "CompteLib" . $separator;
  568. print "CompAuxNum" . $separator;
  569. print "CompAuxLib" . $separator;
  570. print "PieceRef" . $separator;
  571. print "PieceDate" . $separator;
  572. print "EcritureLib" . $separator;
  573. print "Debit" . $separator;
  574. print "Credit" . $separator;
  575. print "EcritureLet" . $separator;
  576. print "DateLet" . $separator;
  577. print "ValidDate" . $separator;
  578. print "Montantdevise" . $separator;
  579. print "Idevise";
  580. print $end_line;
  581. foreach ( $objectLines as $line ) {
  582. $date_creation = dol_print_date($line->date_creation, '%d%m%Y');
  583. $date_doc = dol_print_date($line->doc_date, '%d%m%Y');
  584. $date_valid = dol_print_date($line->date_validated, '%d%m%Y');
  585. // FEC:JournalCode
  586. print $line->code_journal . $separator;
  587. // FEC:JournalLib
  588. print $line->journal_label . $separator;
  589. // FEC:EcritureNum
  590. print $line->piece_num . $separator;
  591. // FEC:EcritureDate
  592. print $date_creation . $separator;
  593. // FEC:CompteNum
  594. print $line->numero_compte . $separator;
  595. // FEC:CompteLib
  596. print $line->label_compte . $separator;
  597. // FEC:CompAuxNum
  598. print $line->subledger_account . $separator;
  599. // FEC:CompAuxLib
  600. print $line->subledger_label . $separator;
  601. // FEC:PieceRef
  602. print $line->doc_ref . $separator;
  603. // FEC:PieceDate
  604. print $date_doc . $separator;
  605. // FEC:EcritureLib
  606. print $line->label_operation . $separator;
  607. // FEC:Debit
  608. print price2num($line->debit) . $separator;
  609. // FEC:Credit
  610. print price2num($line->credit) . $separator;
  611. // FEC:EcritureLet
  612. print $line->lettering_code . $separator;
  613. // FEC:DateLet
  614. print $line->date_lettering . $separator;
  615. // FEC:ValidDate
  616. print $date_valid . $separator;
  617. // FEC:Montantdevise
  618. print $line->multicurrency_amount . $separator;
  619. // FEC:Idevise
  620. print $line->multicurrency_code;
  621. print $end_line;
  622. }
  623. }
  624. /**
  625. *
  626. * @param string $str data
  627. * @param integer $size data
  628. * @return string
  629. */
  630. public static function trunc($str, $size)
  631. {
  632. return dol_trunc($str, $size, 'right', 'UTF-8', 1);
  633. }
  634. }