accountancyexport.class.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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-2019 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-2019 Frédéric France <frederic.france@netlogic.fr>
  12. * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/accountancy/class/accountancyexport.class.php
  29. * \ingroup Accountancy (Double entries)
  30. * \brief Class accountancy export
  31. */
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  34. /**
  35. * Manage the different format accountancy export
  36. */
  37. class AccountancyExport
  38. {
  39. // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
  40. public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
  41. public static $EXPORT_TYPE_AGIRIS = 10;
  42. public static $EXPORT_TYPE_EBP = 15;
  43. public static $EXPORT_TYPE_CEGID = 20;
  44. public static $EXPORT_TYPE_COGILOG = 25;
  45. public static $EXPORT_TYPE_COALA = 30;
  46. public static $EXPORT_TYPE_BOB50 = 35;
  47. public static $EXPORT_TYPE_CIEL = 40;
  48. public static $EXPORT_TYPE_SAGE50_SWISS = 45;
  49. public static $EXPORT_TYPE_CHARLEMAGNE = 50;
  50. public static $EXPORT_TYPE_QUADRATUS = 60;
  51. public static $EXPORT_TYPE_OPENCONCERTO = 100;
  52. public static $EXPORT_TYPE_LDCOMPTA = 110;
  53. public static $EXPORT_TYPE_LDCOMPTA10 = 120;
  54. public static $EXPORT_TYPE_FEC = 1000;
  55. /**
  56. * @var string[] Error codes (or messages)
  57. */
  58. public $errors = array();
  59. /**
  60. *
  61. * @var string Separator
  62. */
  63. public $separator = '';
  64. /**
  65. *
  66. * @var string End of line
  67. */
  68. public $end_line = '';
  69. /**
  70. * Constructor
  71. *
  72. * @param DoliDb $db Database handler
  73. */
  74. public function __construct(DoliDB &$db)
  75. {
  76. global $conf;
  77. $this->db = &$db;
  78. $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  79. $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
  80. }
  81. /**
  82. * Array with all export type available (key + label)
  83. *
  84. * @return array of type
  85. */
  86. public static function getType()
  87. {
  88. global $langs;
  89. $listofexporttypes = array(
  90. self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
  91. self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
  92. self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
  93. self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
  94. self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
  95. self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
  96. self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
  97. self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
  98. self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
  99. self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
  100. self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
  101. self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
  102. self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
  103. self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
  104. self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
  105. );
  106. ksort($listofexporttypes, SORT_NUMERIC);
  107. return $listofexporttypes;
  108. }
  109. /**
  110. * Return string to summarize the format (Used to generated export filename)
  111. *
  112. * @param int $type Format id
  113. * @return string Format code
  114. */
  115. public static function getFormatCode($type)
  116. {
  117. $formatcode = array(
  118. self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
  119. self::$EXPORT_TYPE_CEGID => 'cegid',
  120. self::$EXPORT_TYPE_COALA => 'coala',
  121. self::$EXPORT_TYPE_BOB50 => 'bob50',
  122. self::$EXPORT_TYPE_CIEL => 'ciel',
  123. self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
  124. self::$EXPORT_TYPE_EBP => 'ebp',
  125. self::$EXPORT_TYPE_COGILOG => 'cogilog',
  126. self::$EXPORT_TYPE_AGIRIS => 'agiris',
  127. self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
  128. self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
  129. self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
  130. self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
  131. self::$EXPORT_TYPE_FEC => 'fec',
  132. );
  133. return $formatcode[$type];
  134. }
  135. /**
  136. * Array with all export type available (key + label) and parameters for config
  137. *
  138. * @return array of type
  139. */
  140. public static function getTypeConfig()
  141. {
  142. global $conf, $langs;
  143. return array(
  144. 'param' => array(
  145. self::$EXPORT_TYPE_CONFIGURABLE => array(
  146. 'label' => $langs->trans('Modelcsv_configurable'),
  147. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
  148. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  149. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
  150. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE) ? '%d%m%Y' : $conf->global->ACCOUNTING_EXPORT_DATE,
  151. ),
  152. self::$EXPORT_TYPE_CEGID => array(
  153. 'label' => $langs->trans('Modelcsv_CEGID'),
  154. ),
  155. self::$EXPORT_TYPE_COALA => array(
  156. 'label' => $langs->trans('Modelcsv_COALA'),
  157. ),
  158. self::$EXPORT_TYPE_BOB50 => array(
  159. 'label' => $langs->trans('Modelcsv_bob50'),
  160. ),
  161. self::$EXPORT_TYPE_CIEL => array(
  162. 'label' => $langs->trans('Modelcsv_ciel'),
  163. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  164. ),
  165. self::$EXPORT_TYPE_QUADRATUS => array(
  166. 'label' => $langs->trans('Modelcsv_quadratus'),
  167. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  168. ),
  169. self::$EXPORT_TYPE_EBP => array(
  170. 'label' => $langs->trans('Modelcsv_ebp'),
  171. ),
  172. self::$EXPORT_TYPE_COGILOG => array(
  173. 'label' => $langs->trans('Modelcsv_cogilog'),
  174. ),
  175. self::$EXPORT_TYPE_AGIRIS => array(
  176. 'label' => $langs->trans('Modelcsv_agiris'),
  177. ),
  178. self::$EXPORT_TYPE_OPENCONCERTO => array(
  179. 'label' => $langs->trans('Modelcsv_openconcerto'),
  180. 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
  181. ),
  182. self::$EXPORT_TYPE_SAGE50_SWISS => array(
  183. 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
  184. 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
  185. ),
  186. self::$EXPORT_TYPE_LDCOMPTA => array(
  187. 'label' => $langs->trans('Modelcsv_LDCompta'),
  188. 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
  189. ),
  190. self::$EXPORT_TYPE_LDCOMPTA10 => array(
  191. 'label' => $langs->trans('Modelcsv_LDCompta10'),
  192. 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
  193. ),
  194. self::$EXPORT_TYPE_FEC => array(
  195. 'label' => $langs->trans('Modelcsv_FEC'),
  196. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  197. ),
  198. self::$EXPORT_TYPE_CHARLEMAGNE => array(
  199. 'label' => $langs->trans('Modelcsv_charlemagne'),
  200. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  201. ),
  202. ),
  203. 'cr'=> array(
  204. '1' => $langs->trans("Unix"),
  205. '2' => $langs->trans("Windows")
  206. ),
  207. 'format' => array(
  208. 'csv' => $langs->trans("csv"),
  209. 'txt' => $langs->trans("txt")
  210. ),
  211. );
  212. }
  213. /**
  214. * Function who chose which export to use with the default config, and make the export into a file
  215. *
  216. * @param array $TData Array with data
  217. * @param int $formatexportset Id of export format
  218. * @return void
  219. */
  220. public function export(&$TData, $formatexportset)
  221. {
  222. global $conf, $langs;
  223. global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
  224. // Define name of file to save
  225. $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
  226. $type_export = 'general_ledger';
  227. global $db; // The tpl file use $db
  228. include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
  229. switch ($formatexportset) {
  230. case self::$EXPORT_TYPE_CONFIGURABLE :
  231. $this->exportConfigurable($TData);
  232. break;
  233. case self::$EXPORT_TYPE_CEGID :
  234. $this->exportCegid($TData);
  235. break;
  236. case self::$EXPORT_TYPE_COALA :
  237. $this->exportCoala($TData);
  238. break;
  239. case self::$EXPORT_TYPE_BOB50 :
  240. $this->exportBob50($TData);
  241. break;
  242. case self::$EXPORT_TYPE_CIEL :
  243. $this->exportCiel($TData);
  244. break;
  245. case self::$EXPORT_TYPE_QUADRATUS :
  246. $this->exportQuadratus($TData);
  247. break;
  248. case self::$EXPORT_TYPE_EBP :
  249. $this->exportEbp($TData);
  250. break;
  251. case self::$EXPORT_TYPE_COGILOG :
  252. $this->exportCogilog($TData);
  253. break;
  254. case self::$EXPORT_TYPE_AGIRIS :
  255. $this->exportAgiris($TData);
  256. break;
  257. case self::$EXPORT_TYPE_OPENCONCERTO :
  258. $this->exportOpenConcerto($TData);
  259. break;
  260. case self::$EXPORT_TYPE_SAGE50_SWISS :
  261. $this->exportSAGE50SWISS($TData);
  262. break;
  263. case self::$EXPORT_TYPE_LDCOMPTA :
  264. $this->exportLDCompta($TData);
  265. break;
  266. case self::$EXPORT_TYPE_LDCOMPTA10 :
  267. $this->exportLDCompta10($TData);
  268. break;
  269. case self::$EXPORT_TYPE_FEC :
  270. $this->exportFEC($TData);
  271. break;
  272. case self::$EXPORT_TYPE_CHARLEMAGNE :
  273. $this->exportCharlemagne($TData);
  274. break;
  275. default:
  276. $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
  277. break;
  278. }
  279. }
  280. /**
  281. * Export format : CEGID
  282. *
  283. * @param array $objectLines data
  284. * @return void
  285. */
  286. public function exportCegid($objectLines)
  287. {
  288. foreach ($objectLines as $line) {
  289. $date = dol_print_date($line->doc_date, '%d%m%Y');
  290. $separator = ";";
  291. $end_line = "\n";
  292. print $date.$separator;
  293. print $line->code_journal.$separator;
  294. print length_accountg($line->numero_compte).$separator;
  295. print length_accounta($line->subledger_account).$separator;
  296. print $line->sens.$separator;
  297. print price($line->montant).$separator;
  298. print $line->label_operation.$separator;
  299. print $line->doc_ref;
  300. print $end_line;
  301. }
  302. }
  303. /**
  304. * Export format : COGILOG
  305. *
  306. * @param array $objectLines data
  307. * @return void
  308. */
  309. public function exportCogilog($objectLines)
  310. {
  311. foreach ($objectLines as $line) {
  312. $date = dol_print_date($line->doc_date, '%d%m%Y');
  313. $separator = ";";
  314. $end_line = "\n";
  315. print $line->code_journal.$separator;
  316. print $date.$separator;
  317. print $line->piece_num.$separator;
  318. print length_accountg($line->numero_compte).$separator;
  319. print ''.$separator;
  320. print $line->label_operation.$separator;
  321. print $date.$separator;
  322. if ($line->sens == 'D') {
  323. print price($line->montant).$separator;
  324. print ''.$separator;
  325. }elseif ($line->sens == 'C') {
  326. print ''.$separator;
  327. print price($line->montant).$separator;
  328. }
  329. print $line->doc_ref.$separator;
  330. print $line->label_operation.$separator;
  331. print $end_line;
  332. }
  333. }
  334. /**
  335. * Export format : COALA
  336. *
  337. * @param array $objectLines data
  338. * @return void
  339. */
  340. public function exportCoala($objectLines)
  341. {
  342. // Coala export
  343. $separator = ";";
  344. $end_line = "\n";
  345. foreach ($objectLines as $line) {
  346. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  347. print $date.$separator;
  348. print $line->code_journal.$separator;
  349. print length_accountg($line->numero_compte).$separator;
  350. print $line->piece_num.$separator;
  351. print $line->doc_ref.$separator;
  352. print price($line->debit).$separator;
  353. print price($line->credit).$separator;
  354. print 'E'.$separator;
  355. print length_accountg($line->subledger_account).$separator;
  356. print $end_line;
  357. }
  358. }
  359. /**
  360. * Export format : BOB50
  361. *
  362. * @param array $objectLines data
  363. * @return void
  364. */
  365. public function exportBob50($objectLines)
  366. {
  367. // Bob50
  368. $separator = ";";
  369. $end_line = "\n";
  370. foreach ($objectLines as $line) {
  371. print $line->piece_num.$separator;
  372. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  373. print $date.$separator;
  374. if (empty($line->subledger_account)) {
  375. print 'G'.$separator;
  376. print length_accounta($line->numero_compte).$separator;
  377. } else {
  378. if (substr($line->numero_compte, 0, 3) == '411') {
  379. print 'C'.$separator;
  380. }
  381. if (substr($line->numero_compte, 0, 3) == '401') {
  382. print 'F'.$separator;
  383. }
  384. print length_accountg($line->subledger_account).$separator;
  385. }
  386. print price($line->debit).$separator;
  387. print price($line->credit).$separator;
  388. print dol_trunc($line->label_operation, 32).$separator;
  389. print $end_line;
  390. }
  391. }
  392. /**
  393. * Export format : CIEL
  394. *
  395. * @param array $TData data
  396. * @return void
  397. */
  398. public function exportCiel(&$TData)
  399. {
  400. global $conf;
  401. $end_line = "\r\n";
  402. $i = 1;
  403. $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd
  404. foreach ($TData as $data) {
  405. $code_compta = $data->numero_compte;
  406. if (!empty($data->subledger_account))
  407. $code_compta = $data->subledger_account;
  408. $Tab = array();
  409. $Tab['num_ecriture'] = str_pad($i, 5);
  410. $Tab['code_journal'] = str_pad($data->code_journal, 2);
  411. $Tab['date_ecriture'] = $date_ecriture;
  412. $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  413. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12);
  414. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
  415. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
  416. $Tab['montant'] = str_pad(abs($data->montant), 13, ' ', STR_PAD_LEFT);
  417. $Tab['type_montant'] = str_pad($data->sens, 1);
  418. $Tab['vide'] = str_repeat(' ', 18);
  419. $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
  420. $Tab['end'] = 'O2003';
  421. $Tab['end_line'] = $end_line;
  422. print implode($Tab);
  423. $i++;
  424. }
  425. }
  426. /**
  427. * Export format : Quadratus
  428. *
  429. * @param array $TData data
  430. * @return void
  431. */
  432. public function exportQuadratus(&$TData)
  433. {
  434. global $conf;
  435. $end_line = "\r\n";
  436. //We should use dol_now function not time however this is wrong date to transfert in accounting
  437. //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  438. //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  439. foreach ($TData as $data) {
  440. $code_compta = $data->numero_compte;
  441. if (!empty($data->subledger_account))
  442. $code_compta = $data->subledger_account;
  443. $Tab = array();
  444. $Tab['type_ligne'] = 'M';
  445. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
  446. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  447. $Tab['folio'] = '000';
  448. //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  449. //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  450. //$Tab['date_ecriture'] = $date_ecriture;
  451. $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  452. $Tab['filler'] = ' ';
  453. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
  454. $Tab['sens'] = $data->sens; // C or D
  455. $Tab['signe_montant'] = '+';
  456. //elarifr le montant doit etre en centimes sans point decimal !
  457. $Tab['montant'] = str_pad(abs($data->montant * 100), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  458. // $Tab['montant'] = str_pad(abs($data->montant), 12, '0', STR_PAD_LEFT); // TODO manage negative amount
  459. $Tab['contrepartie'] = str_repeat(' ', 8);
  460. // elarifr: date format must be fixed format : 6 char ddmmyy = %d%m%yand not defined by user / dolibarr setting
  461. if (!empty($data->date_echeance))
  462. //$Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
  463. $Tab['date_echeance'] = dol_print_date($data->date_echeance, '%d%m%y'); // elarifr: format must be ddmmyy
  464. else
  465. $Tab['date_echeance'] = '000000';
  466. //elarifr please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
  467. //$Tab['lettrage'] = str_repeat(' ', 5);
  468. $Tab['lettrage'] = str_repeat(' ', 2);
  469. $Tab['codestat'] = str_repeat(' ', 3);
  470. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
  471. //elarifr keep correct quadra named field instead of anon filler
  472. //$Tab['filler2'] = str_repeat(' ', 20);
  473. $Tab['affaire'] = str_repeat(' ', 10);
  474. $Tab['quantity1'] = str_repeat(' ', 10);
  475. $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
  476. $Tab['devis'] = str_pad($conf->currency, 3);
  477. $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
  478. $Tab['filler3'] = str_repeat(' ', 3);
  479. //elarifr keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
  480. //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
  481. //todo we should filter more than only accent to avoid wrong line size
  482. //TODO: remove invoice number doc_ref in libelle,
  483. //TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
  484. //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
  485. $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
  486. $Tab['codetva'] = str_repeat(' ', 2);
  487. //elarifr we need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
  488. //$Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
  489. $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
  490. $Tab['filler4'] = str_repeat(' ', 73);
  491. $Tab['end_line'] = $end_line;
  492. print implode($Tab);
  493. }
  494. }
  495. /**
  496. * Export format : EBP
  497. *
  498. * @param array $objectLines data
  499. * @return void
  500. */
  501. public function exportEbp($objectLines)
  502. {
  503. $separator = ',';
  504. $end_line = "\n";
  505. foreach ($objectLines as $line) {
  506. $date = dol_print_date($line->doc_date, '%d%m%Y');
  507. print $line->id.$separator;
  508. print $date.$separator;
  509. print $line->code_journal.$separator;
  510. if (empty($line->subledger_account)) {
  511. print $line->numero_compte.$separator;
  512. } else {
  513. print $line->subledger_account.$separator;
  514. }
  515. //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
  516. print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
  517. print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
  518. print price2num(abs($line->montant)).$separator;
  519. print $line->sens.$separator;
  520. print $date.$separator;
  521. //print 'EUR';
  522. print $end_line;
  523. }
  524. }
  525. /**
  526. * Export format : Agiris Isacompta
  527. *
  528. * @param array $objectLines data
  529. * @return void
  530. */
  531. public function exportAgiris($objectLines)
  532. {
  533. $separator = ';';
  534. $end_line = "\n";
  535. foreach ($objectLines as $line) {
  536. $date = dol_print_date($line->doc_date, '%d%m%Y');
  537. print $line->piece_num.$separator;
  538. print self::toAnsi($line->label_operation).$separator;
  539. print $date.$separator;
  540. print self::toAnsi($line->label_operation).$separator;
  541. if (empty($line->subledger_account)) {
  542. print length_accountg($line->numero_compte).$separator;
  543. print self::toAnsi($line->label_compte).$separator;
  544. } else {
  545. print length_accounta($line->subledger_account).$separator;
  546. print self::toAnsi($line->subledger_label).$separator;
  547. }
  548. print self::toAnsi($line->doc_ref).$separator;
  549. print price($line->debit).$separator;
  550. print price($line->credit).$separator;
  551. print price($line->montant).$separator;
  552. print $line->sens.$separator;
  553. print $line->lettering_code.$separator;
  554. print $line->code_journal;
  555. print $end_line;
  556. }
  557. }
  558. /**
  559. * Export format : OpenConcerto
  560. *
  561. * @param array $objectLines data
  562. * @return void
  563. */
  564. public function exportOpenConcerto($objectLines)
  565. {
  566. $separator = ';';
  567. $end_line = "\n";
  568. foreach ($objectLines as $line) {
  569. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  570. print $date.$separator;
  571. print $line->code_journal.$separator;
  572. if (empty($line->subledger_account)) {
  573. print length_accountg($line->numero_compte).$separator;
  574. } else {
  575. print length_accounta($line->subledger_account).$separator;
  576. }
  577. print $line->doc_ref.$separator;
  578. print $line->label_operation.$separator;
  579. print price($line->debit).$separator;
  580. print price($line->credit).$separator;
  581. print $end_line;
  582. }
  583. }
  584. /**
  585. * Export format : Configurable CSV
  586. *
  587. * @param array $objectLines data
  588. * @return void
  589. */
  590. public function exportConfigurable($objectLines)
  591. {
  592. global $conf;
  593. $separator = $this->separator;
  594. foreach ($objectLines as $line) {
  595. $tab = array();
  596. // export configurable
  597. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  598. $tab[] = $line->piece_num;
  599. $tab[] = $date;
  600. $tab[] = $line->doc_ref;
  601. $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
  602. $tab[] = length_accountg($line->numero_compte);
  603. $tab[] = length_accounta($line->subledger_account);
  604. $tab[] = price2num($line->debit);
  605. $tab[] = price2num($line->credit);
  606. $tab[] = price2num($line->montant);
  607. $tab[] = $line->code_journal;
  608. print implode($separator, $tab).$this->end_line;
  609. }
  610. }
  611. /**
  612. * Export format : FEC
  613. *
  614. * @param array $objectLines data
  615. * @return void
  616. */
  617. public function exportFEC($objectLines)
  618. {
  619. $separator = "\t";
  620. $end_line = "\n";
  621. print "JournalCode".$separator;
  622. print "JournalLib".$separator;
  623. print "EcritureNum".$separator;
  624. print "EcritureDate".$separator;
  625. print "CompteNum".$separator;
  626. print "CompteLib".$separator;
  627. print "CompAuxNum".$separator;
  628. print "CompAuxLib".$separator;
  629. print "PieceRef".$separator;
  630. print "PieceDate".$separator;
  631. print "EcritureLib".$separator;
  632. print "Debit".$separator;
  633. print "Credit".$separator;
  634. print "EcritureLet".$separator;
  635. print "DateLet".$separator;
  636. print "ValidDate".$separator;
  637. print "Montantdevise".$separator;
  638. print "Idevise";
  639. print $end_line;
  640. foreach ($objectLines as $line) {
  641. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  642. $date_doc = dol_print_date($line->doc_date, '%Y%m%d');
  643. $date_valid = dol_print_date($line->date_validated, '%Y%m%d');
  644. // FEC:JournalCode
  645. print $line->code_journal.$separator;
  646. // FEC:JournalLib
  647. print $line->journal_label.$separator;
  648. // FEC:EcritureNum
  649. print $line->piece_num.$separator;
  650. // FEC:EcritureDate
  651. print $date_creation.$separator;
  652. // FEC:CompteNum
  653. print $line->numero_compte.$separator;
  654. // FEC:CompteLib
  655. print $line->label_compte.$separator;
  656. // FEC:CompAuxNum
  657. print $line->subledger_account.$separator;
  658. // FEC:CompAuxLib
  659. print $line->subledger_label.$separator;
  660. // FEC:PieceRef
  661. print $line->doc_ref.$separator;
  662. // FEC:PieceDate
  663. print $date_doc.$separator;
  664. // FEC:EcritureLib
  665. print $line->label_operation.$separator;
  666. // FEC:Debit
  667. print price2fec($line->debit).$separator;
  668. // FEC:Credit
  669. print price2fec($line->credit).$separator;
  670. // FEC:EcritureLet
  671. print $line->lettering_code.$separator;
  672. // FEC:DateLet
  673. print $line->date_lettering.$separator;
  674. // FEC:ValidDate
  675. print $date_valid.$separator;
  676. // FEC:Montantdevise
  677. print $line->multicurrency_amount.$separator;
  678. // FEC:Idevise
  679. print $line->multicurrency_code;
  680. print $end_line;
  681. }
  682. }
  683. /**
  684. * Export format : SAGE50SWISS
  685. *
  686. * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984
  687. * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf
  688. *
  689. * @param array $objectLines data
  690. *
  691. * @return void
  692. */
  693. public function exportSAGE50SWISS($objectLines)
  694. {
  695. // SAGE50SWISS
  696. $this->separator = ',';
  697. $this->end_line = "\r\n";
  698. // Print header line
  699. print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
  700. print $this->end_line;
  701. $thisPieceNum = "";
  702. $thisPieceAccountNr = "";
  703. $aSize = count($objectLines);
  704. foreach ($objectLines as $aIndex=>$line)
  705. {
  706. $sammelBuchung = false;
  707. if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num)
  708. {
  709. $sammelBuchung = true;
  710. }
  711. elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num)
  712. {
  713. $sammelBuchung = true;
  714. }
  715. elseif ($aIndex + 1 < $aSize
  716. && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
  717. && $aIndex - 1 < $aSize
  718. && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
  719. )
  720. {
  721. $sammelBuchung = true;
  722. }
  723. //Blg
  724. print $line->piece_num.$this->separator;
  725. // Datum
  726. $date = dol_print_date($line->doc_date, '%d.%m.%Y');
  727. print $date.$this->separator;
  728. // Kto
  729. print length_accountg($line->numero_compte).$this->separator;
  730. // S/H
  731. if ($line->sens == 'D')
  732. {
  733. print 'S'.$this->separator;
  734. }
  735. else
  736. {
  737. print 'H'.$this->separator;
  738. }
  739. //Grp
  740. print self::trunc($line->code_journal, 1).$this->separator;
  741. // GKto
  742. if (empty($line->code_tiers))
  743. {
  744. if ($line->piece_num == $thisPieceNum)
  745. {
  746. print length_accounta($thisPieceAccountNr).$this->separator;
  747. }
  748. else
  749. {
  750. print "div".$this->separator;
  751. }
  752. }
  753. else
  754. {
  755. print length_accounta($line->code_tiers).$this->separator;
  756. }
  757. //SId
  758. print $this->separator;
  759. //SIdx
  760. print "0".$this->separator;
  761. //KIdx
  762. print "0".$this->separator;
  763. //BTyp
  764. print "0".$this->separator;
  765. //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
  766. if ($sammelBuchung)
  767. {
  768. print "2".$this->separator;
  769. }
  770. else
  771. {
  772. print "1".$this->separator;
  773. }
  774. // Code
  775. print '""'.$this->separator;
  776. // Netto
  777. if ($line->montant >= 0)
  778. {
  779. print $line->montant.$this->separator;
  780. }
  781. else
  782. {
  783. print ($line->montant * -1).$this->separator;
  784. }
  785. // Steuer
  786. print "0.00".$this->separator;
  787. // FW-Betrag
  788. print "0.00".$this->separator;
  789. // Tx1
  790. $line1 = self::toAnsi($line->label_compte, 29);
  791. if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3)
  792. {
  793. $line1 = "";
  794. }
  795. $line2 = self::toAnsi($line->doc_ref, 29);
  796. if (strlen($line1) == 0)
  797. {
  798. $line1 = $line2;
  799. $line2 = "";
  800. }
  801. if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27)
  802. {
  803. $line1 = $line1.' / '.$line2;
  804. $line2 = "";
  805. }
  806. print '"'.self::toAnsi($line1).'"'.$this->separator;
  807. // Tx2
  808. print '"'.self::toAnsi($line2).'"'.$this->separator;
  809. //PkKey
  810. print "0".$this->separator;
  811. //OpId
  812. print $this->separator;
  813. // Flag
  814. print "0";
  815. print $this->end_line;
  816. if ($line->piece_num !== $thisPieceNum)
  817. {
  818. $thisPieceNum = $line->piece_num;
  819. $thisPieceAccountNr = $line->numero_compte;
  820. }
  821. }
  822. }
  823. /**
  824. * Export format : LD Compta version 9 & higher
  825. * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf
  826. *
  827. * @param array $objectLines data
  828. *
  829. * @return void
  830. */
  831. public function exportLDCompta($objectLines)
  832. {
  833. $separator = ';';
  834. $end_line = "\r\n";
  835. foreach ($objectLines as $line) {
  836. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  837. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  838. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  839. // TYPE
  840. $type_enregistrement = 'E'; // For write movement
  841. print $type_enregistrement.$separator;
  842. // JNAL
  843. print substr($line->code_journal, 0, 2).$separator;
  844. // NECR
  845. print $line->id.$separator;
  846. // NPIE
  847. print $line->piece_num.$separator;
  848. // DATP
  849. print $date_document.$separator;
  850. // LIBE
  851. print $line->label_operation.$separator;
  852. // DATH
  853. print $date_lim_reglement.$separator;
  854. // CNPI
  855. if ($line->doc_type == 'supplier_invoice') {
  856. if ($line->montant < 0) {
  857. $nature_piece = 'AF';
  858. } else {
  859. $nature_piece = 'FF';
  860. }
  861. } elseif ($line->doc_type == 'customer_invoice') {
  862. if ($line->montant < 0) {
  863. $nature_piece = 'AC';
  864. } else {
  865. $nature_piece = 'FC';
  866. }
  867. } else {
  868. $nature_piece = '';
  869. }
  870. print $nature_piece.$separator;
  871. // RACI
  872. // if (! empty($line->subledger_account)) {
  873. // if ($line->doc_type == 'supplier_invoice') {
  874. // $racine_subledger_account = '40';
  875. // } elseif ($line->doc_type == 'customer_invoice') {
  876. // $racine_subledger_account = '41';
  877. // } else {
  878. // $racine_subledger_account = '';
  879. // }
  880. // } else {
  881. $racine_subledger_account = ''; // for records of type E leave this field blank
  882. // }
  883. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  884. // MONT
  885. print price(abs($line->montant), 0, '', 1, 2).$separator;
  886. // CODC
  887. print $line->sens.$separator;
  888. // CPTG
  889. print length_accountg($line->numero_compte).$separator;
  890. // DATE
  891. print $date_creation.$separator;
  892. // CLET
  893. print $line->lettering_code.$separator;
  894. // DATL
  895. print $line->date_lettering.$separator;
  896. // CPTA
  897. if (!empty($line->subledger_account)) {
  898. print length_accounta($line->subledger_account).$separator;
  899. } else {
  900. print $separator;
  901. }
  902. // CNAT
  903. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  904. print 'F'.$separator;
  905. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  906. print 'C'.$separator;
  907. } else {
  908. print $separator;
  909. }
  910. // SECT
  911. print $separator;
  912. // CTRE
  913. print $separator;
  914. // NORL
  915. print $separator;
  916. // DATV
  917. print $separator;
  918. // REFD
  919. print $line->doc_ref.$separator;
  920. // CODH
  921. print $separator;
  922. // NSEQ
  923. print $separator;
  924. // MTDV
  925. print '0'.$separator;
  926. // CODV
  927. print $separator;
  928. // TXDV
  929. print '0'.$separator;
  930. // MOPM
  931. print $separator;
  932. // BONP
  933. print $separator;
  934. // BQAF
  935. print $separator;
  936. // ECES
  937. print $separator;
  938. // TXTL
  939. print $separator;
  940. // ECRM
  941. print $separator;
  942. // DATK
  943. print $separator;
  944. // HEUK
  945. print $separator;
  946. print $end_line;
  947. }
  948. }
  949. /**
  950. * Export format : LD Compta version 10 & higher
  951. * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf
  952. *
  953. * @param array $objectLines data
  954. *
  955. * @return void
  956. */
  957. public function exportLDCompta10($objectLines)
  958. {
  959. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  960. $separator = ';';
  961. $end_line = "\r\n";
  962. $last_codeinvoice = '';
  963. foreach ($objectLines as $line) {
  964. // TYPE C
  965. if ($last_codeinvoice != $line->doc_ref) {
  966. //recherche societe en fonction de son code client
  967. $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe WHERE code_client = '".$line->thirdparty_code."'";
  968. $resql = $this->db->query($sql);
  969. if ($resql && $this->db->num_rows($resql) > 0)
  970. {
  971. $soc = $this->db->fetch_object($resql);
  972. $address = array('', '', '');
  973. if (strpos($soc->address, "\n") !== false) {
  974. $address = explode("\n", $soc->address);
  975. if (is_array($address) && count($address) > 0) {
  976. foreach ($address as $key=>$data) {
  977. $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
  978. $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
  979. }
  980. }
  981. } else {
  982. $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
  983. $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
  984. $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
  985. }
  986. $type_enregistrement = 'C';
  987. //TYPE
  988. print $type_enregistrement.$separator;
  989. //NOCL
  990. print $soc->code_client.$separator;
  991. //NMCM
  992. print $separator;
  993. //LIBI
  994. print $separator;
  995. //TITR
  996. print $separator;
  997. //RSSO
  998. print $soc->nom.$separator;
  999. //CAD1
  1000. print $address[0].$separator;
  1001. //CAD2
  1002. print $address[1].$separator;
  1003. //CAD3
  1004. print $address[2].$separator;
  1005. //COPO
  1006. print $soc->zip.$separator;
  1007. //BUDI
  1008. print substr($soc->town, 0, 40).$separator;
  1009. //CPAY
  1010. print $separator;
  1011. //PAYS
  1012. print substr(getCountry($soc->fk_pays), 0, 40).$separator;
  1013. //NTEL
  1014. print $soc->phone.$separator;
  1015. //TLEX
  1016. print $separator;
  1017. //TLPO
  1018. print $separator;
  1019. //TLCY
  1020. print $separator;
  1021. //NINT
  1022. print $separator;
  1023. //COMM
  1024. print $separator;
  1025. //SIRE
  1026. print str_replace(" ", "", $soc->siret).$separator;
  1027. //RIBP
  1028. print $separator;
  1029. //DOBQ
  1030. print $separator;
  1031. //IBBQ
  1032. print $separator;
  1033. //COBQ
  1034. print $separator;
  1035. //GUBQ
  1036. print $separator;
  1037. //CPBQ
  1038. print $separator;
  1039. //CLBQ
  1040. print $separator;
  1041. //BIBQ
  1042. print $separator;
  1043. //MOPM
  1044. print $separator;
  1045. //DJPM
  1046. print $separator;
  1047. //DMPM
  1048. print $separator;
  1049. //REFM
  1050. print $separator;
  1051. //SLVA
  1052. print $separator;
  1053. //PLCR
  1054. print $separator;
  1055. //ECFI
  1056. print $separator;
  1057. //CREP
  1058. print $separator;
  1059. //NREP
  1060. print $separator;
  1061. //TREP
  1062. print $separator;
  1063. //MREP
  1064. print $separator;
  1065. //GRRE
  1066. print $separator;
  1067. //LTTA
  1068. print $separator;
  1069. //CACT
  1070. print $separator;
  1071. //CODV
  1072. print $separator;
  1073. //GRTR
  1074. print $separator;
  1075. //NOFP
  1076. print $separator;
  1077. //BQAF
  1078. print $separator;
  1079. //BONP
  1080. print $separator;
  1081. //CESC
  1082. print $separator;
  1083. print $end_line;
  1084. }
  1085. }
  1086. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  1087. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  1088. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  1089. // TYPE E
  1090. $type_enregistrement = 'E'; // For write movement
  1091. print $type_enregistrement.$separator;
  1092. // JNAL
  1093. print substr($line->code_journal, 0, 2).$separator;
  1094. // NECR
  1095. print $line->id.$separator;
  1096. // NPIE
  1097. print $line->piece_num.$separator;
  1098. // DATP
  1099. print $date_document.$separator;
  1100. // LIBE
  1101. print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
  1102. // DATH
  1103. print $date_lim_reglement.$separator;
  1104. // CNPI
  1105. if ($line->doc_type == 'supplier_invoice') {
  1106. if ($line->montant < 0) {
  1107. $nature_piece = 'AF';
  1108. } else {
  1109. $nature_piece = 'FF';
  1110. }
  1111. } elseif ($line->doc_type == 'customer_invoice') {
  1112. if ($line->montant < 0) {
  1113. $nature_piece = 'AC';
  1114. } else {
  1115. $nature_piece = 'FC';
  1116. }
  1117. } else {
  1118. $nature_piece = '';
  1119. }
  1120. print $nature_piece.$separator;
  1121. // RACI
  1122. // if (! empty($line->subledger_account)) {
  1123. // if ($line->doc_type == 'supplier_invoice') {
  1124. // $racine_subledger_account = '40';
  1125. // } elseif ($line->doc_type == 'customer_invoice') {
  1126. // $racine_subledger_account = '41';
  1127. // } else {
  1128. // $racine_subledger_account = '';
  1129. // }
  1130. // } else {
  1131. $racine_subledger_account = ''; // for records of type E leave this field blank
  1132. // }
  1133. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  1134. // MONT
  1135. print price(abs($line->montant), 0, '', 1, 2).$separator;
  1136. // CODC
  1137. print $line->sens.$separator;
  1138. // CPTG
  1139. print length_accountg($line->numero_compte).$separator;
  1140. // DATE
  1141. print $date_document.$separator;
  1142. // CLET
  1143. print $line->lettering_code.$separator;
  1144. // DATL
  1145. print $line->date_lettering.$separator;
  1146. // CPTA
  1147. if (!empty($line->subledger_account)) {
  1148. print length_accounta($line->subledger_account).$separator;
  1149. } else {
  1150. print $separator;
  1151. }
  1152. // CNAT
  1153. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  1154. print 'F'.$separator;
  1155. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  1156. print 'C'.$separator;
  1157. } else {
  1158. print $separator;
  1159. }
  1160. // CTRE
  1161. print $separator;
  1162. // NORL
  1163. print $separator;
  1164. // DATV
  1165. print $separator;
  1166. // REFD
  1167. print $line->doc_ref.$separator;
  1168. // NECA
  1169. print '0'.$separator;
  1170. // CSEC
  1171. print $separator;
  1172. // CAFF
  1173. print $separator;
  1174. // CDES
  1175. print $separator;
  1176. // QTUE
  1177. print $separator;
  1178. // MTDV
  1179. print '0'.$separator;
  1180. // CODV
  1181. print $separator;
  1182. // TXDV
  1183. print '0'.$separator;
  1184. // MOPM
  1185. print $separator;
  1186. // BONP
  1187. print $separator;
  1188. // BQAF
  1189. print $separator;
  1190. // ECES
  1191. print $separator;
  1192. // TXTL
  1193. print $separator;
  1194. // ECRM
  1195. print $separator;
  1196. // DATK
  1197. print $separator;
  1198. // HEUK
  1199. print $separator;
  1200. print $end_line;
  1201. $last_codeinvoice = $line->doc_ref;
  1202. }
  1203. }
  1204. /**
  1205. * Export format : Charlemagne
  1206. *
  1207. * @param array $objectLines data
  1208. * @return void
  1209. */
  1210. public function exportCharlemagne($objectLines)
  1211. {
  1212. global $langs;
  1213. $langs->load('compta');
  1214. $separator = "\t";
  1215. $end_line = "\n";
  1216. /*
  1217. * Charlemagne export need header
  1218. */
  1219. print $langs->transnoentitiesnoconv('Date').$separator;
  1220. print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
  1221. print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
  1222. print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
  1223. print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
  1224. print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
  1225. print $langs->transnoentitiesnoconv('Amount').$separator;
  1226. print 'S'.$separator;
  1227. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
  1228. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
  1229. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
  1230. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
  1231. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
  1232. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
  1233. print $end_line;
  1234. foreach ($objectLines as $line) {
  1235. $date = dol_print_date($line->doc_date, '%Y%m%d');
  1236. print $date.$separator; //Date
  1237. print self::trunc($line->code_journal, 6).$separator; //Journal code
  1238. if (!empty($line->subledger_account)) $account = $line->subledger_account;
  1239. else $account = $line->numero_compte;
  1240. print self::trunc($account, 15).$separator; //Account number
  1241. print self::trunc($line->label_compte, 60).$separator; //Account label
  1242. print self::trunc($line->doc_ref, 20).$separator; //Piece
  1243. print self::trunc($line->label_operation, 60).$separator; //Operation label
  1244. print price(abs($line->montant)).$separator; //Amount
  1245. print $line->sens.$separator; //Direction
  1246. print $separator; //Analytic
  1247. print $separator; //Analytic
  1248. print $separator; //Analytic
  1249. print $separator; //Analytic
  1250. print $separator; //Analytic
  1251. print $separator; //Analytic
  1252. print $end_line;
  1253. }
  1254. }
  1255. /**
  1256. * trunc
  1257. *
  1258. * @param string $str String
  1259. * @param integer $size Data to trunc
  1260. * @return string
  1261. */
  1262. public static function trunc($str, $size)
  1263. {
  1264. return dol_trunc($str, $size, 'right', 'UTF-8', 1);
  1265. }
  1266. /**
  1267. * toAnsi
  1268. *
  1269. * @param string $str Original string to encode and optionaly truncate
  1270. * @param integer $size Truncate string after $size characters
  1271. * @return string String encoded in Windows-1251 charset
  1272. */
  1273. public static function toAnsi($str, $size = -1)
  1274. {
  1275. $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
  1276. if ($retVal >= 0 && $size >= 0)
  1277. {
  1278. $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
  1279. }
  1280. return $retVal;
  1281. }
  1282. }