accountancyexport.class.php 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984
  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-2021 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. * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
  14. * Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/accountancy/class/accountancyexport.class.php
  31. * \ingroup Accountancy (Double entries)
  32. * \brief Class accountancy export
  33. */
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  37. /**
  38. * Manage the different format accountancy export
  39. */
  40. class AccountancyExport
  41. {
  42. // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
  43. public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
  44. public static $EXPORT_TYPE_AGIRIS = 10;
  45. public static $EXPORT_TYPE_EBP = 15;
  46. public static $EXPORT_TYPE_CEGID = 20;
  47. public static $EXPORT_TYPE_COGILOG = 25;
  48. public static $EXPORT_TYPE_COALA = 30;
  49. public static $EXPORT_TYPE_BOB50 = 35;
  50. public static $EXPORT_TYPE_CIEL = 40;
  51. public static $EXPORT_TYPE_SAGE50_SWISS = 45;
  52. public static $EXPORT_TYPE_CHARLEMAGNE = 50;
  53. public static $EXPORT_TYPE_QUADRATUS = 60;
  54. public static $EXPORT_TYPE_WINFIC = 70;
  55. public static $EXPORT_TYPE_OPENCONCERTO = 100;
  56. public static $EXPORT_TYPE_LDCOMPTA = 110;
  57. public static $EXPORT_TYPE_LDCOMPTA10 = 120;
  58. public static $EXPORT_TYPE_GESTIMUMV3 = 130;
  59. public static $EXPORT_TYPE_GESTIMUMV5 = 135;
  60. public static $EXPORT_TYPE_ISUITEEXPERT = 200;
  61. // Generic FEC after that
  62. public static $EXPORT_TYPE_FEC = 1000;
  63. public static $EXPORT_TYPE_FEC2 = 1010;
  64. /**
  65. * @var DoliDB Database handler
  66. */
  67. public $db;
  68. /**
  69. * @var string[] Error codes (or messages)
  70. */
  71. public $errors = array();
  72. /**
  73. *
  74. * @var string Separator
  75. */
  76. public $separator = '';
  77. /**
  78. *
  79. * @var string End of line
  80. */
  81. public $end_line = '';
  82. /**
  83. * Constructor
  84. *
  85. * @param DoliDb $db Database handler
  86. */
  87. public function __construct(DoliDB $db)
  88. {
  89. global $conf, $hookmanager;
  90. $this->db = $db;
  91. $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
  92. $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
  93. $hookmanager->initHooks(array('accountancyexport'));
  94. }
  95. /**
  96. * Array with all export type available (key + label)
  97. *
  98. * @return array of type
  99. */
  100. public function getType()
  101. {
  102. global $langs;
  103. $listofexporttypes = array(
  104. self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
  105. self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
  106. self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
  107. self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
  108. self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
  109. self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
  110. self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
  111. self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
  112. self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
  113. self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
  114. self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
  115. self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
  116. self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
  117. self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
  118. self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
  119. self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
  120. self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
  121. self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
  122. self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
  123. self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
  124. );
  125. // allow modules to define export formats
  126. global $hookmanager;
  127. $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
  128. ksort($listofexporttypes, SORT_NUMERIC);
  129. return $listofexporttypes;
  130. }
  131. /**
  132. * Return string to summarize the format (Used to generated export filename)
  133. *
  134. * @param int $type Format id
  135. * @return string Format code
  136. */
  137. public static function getFormatCode($type)
  138. {
  139. $formatcode = array(
  140. self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
  141. self::$EXPORT_TYPE_CEGID => 'cegid',
  142. self::$EXPORT_TYPE_COALA => 'coala',
  143. self::$EXPORT_TYPE_BOB50 => 'bob50',
  144. self::$EXPORT_TYPE_CIEL => 'ciel',
  145. self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
  146. self::$EXPORT_TYPE_WINFIC => 'winfic',
  147. self::$EXPORT_TYPE_EBP => 'ebp',
  148. self::$EXPORT_TYPE_COGILOG => 'cogilog',
  149. self::$EXPORT_TYPE_AGIRIS => 'agiris',
  150. self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
  151. self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
  152. self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
  153. self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
  154. self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
  155. self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
  156. self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
  157. self::$EXPORT_TYPE_FEC => 'fec',
  158. self::$EXPORT_TYPE_FEC2 => 'fec2',
  159. self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
  160. );
  161. global $hookmanager;
  162. $code = $formatcode[$type];
  163. $parameters = array('type' => $type);
  164. $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
  165. return $code;
  166. }
  167. /**
  168. * Array with all export type available (key + label) and parameters for config
  169. *
  170. * @return array of type
  171. */
  172. public function getTypeConfig()
  173. {
  174. global $conf, $langs;
  175. $exporttypes = array(
  176. 'param' => array(
  177. self::$EXPORT_TYPE_CONFIGURABLE => array(
  178. 'label' => $langs->trans('Modelcsv_configurable'),
  179. 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
  180. 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
  181. 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
  182. 'ACCOUNTING_EXPORT_DATE' => empty($conf->global->ACCOUNTING_EXPORT_DATE) ? '%d%m%Y' : $conf->global->ACCOUNTING_EXPORT_DATE,
  183. ),
  184. self::$EXPORT_TYPE_CEGID => array(
  185. 'label' => $langs->trans('Modelcsv_CEGID'),
  186. ),
  187. self::$EXPORT_TYPE_COALA => array(
  188. 'label' => $langs->trans('Modelcsv_COALA'),
  189. ),
  190. self::$EXPORT_TYPE_BOB50 => array(
  191. 'label' => $langs->trans('Modelcsv_bob50'),
  192. ),
  193. self::$EXPORT_TYPE_CIEL => array(
  194. 'label' => $langs->trans('Modelcsv_ciel'),
  195. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  196. ),
  197. self::$EXPORT_TYPE_QUADRATUS => array(
  198. 'label' => $langs->trans('Modelcsv_quadratus'),
  199. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  200. ),
  201. self::$EXPORT_TYPE_WINFIC => array(
  202. 'label' => $langs->trans('Modelcsv_winfic'),
  203. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  204. ),
  205. self::$EXPORT_TYPE_EBP => array(
  206. 'label' => $langs->trans('Modelcsv_ebp'),
  207. ),
  208. self::$EXPORT_TYPE_COGILOG => array(
  209. 'label' => $langs->trans('Modelcsv_cogilog'),
  210. ),
  211. self::$EXPORT_TYPE_AGIRIS => array(
  212. 'label' => $langs->trans('Modelcsv_agiris'),
  213. ),
  214. self::$EXPORT_TYPE_OPENCONCERTO => array(
  215. 'label' => $langs->trans('Modelcsv_openconcerto'),
  216. ),
  217. self::$EXPORT_TYPE_SAGE50_SWISS => array(
  218. 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
  219. ),
  220. self::$EXPORT_TYPE_CHARLEMAGNE => array(
  221. 'label' => $langs->trans('Modelcsv_charlemagne'),
  222. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  223. ),
  224. self::$EXPORT_TYPE_LDCOMPTA => array(
  225. 'label' => $langs->trans('Modelcsv_LDCompta'),
  226. ),
  227. self::$EXPORT_TYPE_LDCOMPTA10 => array(
  228. 'label' => $langs->trans('Modelcsv_LDCompta10'),
  229. ),
  230. self::$EXPORT_TYPE_GESTIMUMV3 => array(
  231. 'label' => $langs->trans('Modelcsv_Gestinumv3'),
  232. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  233. ),
  234. self::$EXPORT_TYPE_GESTIMUMV5 => array(
  235. 'label' => $langs->trans('Modelcsv_Gestinumv5'),
  236. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  237. ),
  238. self::$EXPORT_TYPE_FEC => array(
  239. 'label' => $langs->trans('Modelcsv_FEC'),
  240. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  241. ),
  242. self::$EXPORT_TYPE_FEC2 => array(
  243. 'label' => $langs->trans('Modelcsv_FEC2'),
  244. 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
  245. ),
  246. self::$EXPORT_TYPE_ISUITEEXPERT => array(
  247. 'label' => 'iSuite Expert',
  248. 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
  249. ),
  250. ),
  251. 'cr'=> array(
  252. '1' => $langs->trans("Unix"),
  253. '2' => $langs->trans("Windows")
  254. ),
  255. 'format' => array(
  256. 'csv' => $langs->trans("csv"),
  257. 'txt' => $langs->trans("txt")
  258. ),
  259. );
  260. global $hookmanager;
  261. $parameters = array();
  262. $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
  263. return $exporttypes;
  264. }
  265. /**
  266. * Function who chose which export to use with the default config, and make the export into a file
  267. *
  268. * @param array $TData Array with data
  269. * @param int $formatexportset Id of export format
  270. * @return void
  271. */
  272. public function export(&$TData, $formatexportset)
  273. {
  274. global $conf, $langs;
  275. global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
  276. // Define name of file to save
  277. $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
  278. $type_export = 'general_ledger';
  279. global $db; // The tpl file use $db
  280. include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
  281. switch ($formatexportset) {
  282. case self::$EXPORT_TYPE_CONFIGURABLE:
  283. $this->exportConfigurable($TData);
  284. break;
  285. case self::$EXPORT_TYPE_CEGID:
  286. $this->exportCegid($TData);
  287. break;
  288. case self::$EXPORT_TYPE_COALA:
  289. $this->exportCoala($TData);
  290. break;
  291. case self::$EXPORT_TYPE_BOB50:
  292. $this->exportBob50($TData);
  293. break;
  294. case self::$EXPORT_TYPE_CIEL:
  295. $this->exportCiel($TData);
  296. break;
  297. case self::$EXPORT_TYPE_QUADRATUS:
  298. $this->exportQuadratus($TData);
  299. break;
  300. case self::$EXPORT_TYPE_WINFIC:
  301. $this->exportWinfic($TData);
  302. break;
  303. case self::$EXPORT_TYPE_EBP:
  304. $this->exportEbp($TData);
  305. break;
  306. case self::$EXPORT_TYPE_COGILOG:
  307. $this->exportCogilog($TData);
  308. break;
  309. case self::$EXPORT_TYPE_AGIRIS:
  310. $this->exportAgiris($TData);
  311. break;
  312. case self::$EXPORT_TYPE_OPENCONCERTO:
  313. $this->exportOpenConcerto($TData);
  314. break;
  315. case self::$EXPORT_TYPE_SAGE50_SWISS:
  316. $this->exportSAGE50SWISS($TData);
  317. break;
  318. case self::$EXPORT_TYPE_CHARLEMAGNE:
  319. $this->exportCharlemagne($TData);
  320. break;
  321. case self::$EXPORT_TYPE_LDCOMPTA:
  322. $this->exportLDCompta($TData);
  323. break;
  324. case self::$EXPORT_TYPE_LDCOMPTA10:
  325. $this->exportLDCompta10($TData);
  326. break;
  327. case self::$EXPORT_TYPE_GESTIMUMV3:
  328. $this->exportGestimumV3($TData);
  329. break;
  330. case self::$EXPORT_TYPE_GESTIMUMV5:
  331. $this->exportGestimumV5($TData);
  332. break;
  333. case self::$EXPORT_TYPE_FEC:
  334. $this->exportFEC($TData);
  335. break;
  336. case self::$EXPORT_TYPE_FEC2:
  337. $this->exportFEC2($TData);
  338. break;
  339. case self::$EXPORT_TYPE_ISUITEEXPERT :
  340. $this->exportiSuiteExpert($TData);
  341. break;
  342. default:
  343. global $hookmanager;
  344. $parameters = array('format' => $formatexportset);
  345. // file contents will be created in the hooked function via print
  346. $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
  347. if ($reshook != 1) {
  348. $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
  349. }
  350. break;
  351. }
  352. }
  353. /**
  354. * Export format : CEGID
  355. *
  356. * @param array $objectLines data
  357. * @return void
  358. */
  359. public function exportCegid($objectLines)
  360. {
  361. foreach ($objectLines as $line) {
  362. $date = dol_print_date($line->doc_date, '%d%m%Y');
  363. $separator = ";";
  364. $end_line = "\n";
  365. print $date.$separator;
  366. print $line->code_journal.$separator;
  367. print length_accountg($line->numero_compte).$separator;
  368. print length_accounta($line->subledger_account).$separator;
  369. print $line->sens.$separator;
  370. print price2fec(abs($line->debit - $line->credit)).$separator;
  371. print dol_string_unaccent($line->label_operation).$separator;
  372. print dol_string_unaccent($line->doc_ref);
  373. print $end_line;
  374. }
  375. }
  376. /**
  377. * Export format : COGILOG
  378. *
  379. * @param array $objectLines data
  380. * @return void
  381. */
  382. public function exportCogilog($objectLines)
  383. {
  384. foreach ($objectLines as $line) {
  385. $date = dol_print_date($line->doc_date, '%d%m%Y');
  386. $separator = ";";
  387. $end_line = "\n";
  388. print $line->code_journal.$separator;
  389. print $date.$separator;
  390. print $line->piece_num.$separator;
  391. print length_accountg($line->numero_compte).$separator;
  392. print ''.$separator;
  393. print $line->label_operation.$separator;
  394. print $date.$separator;
  395. if ($line->sens == 'D') {
  396. print price($line->debit).$separator;
  397. print ''.$separator;
  398. } elseif ($line->sens == 'C') {
  399. print ''.$separator;
  400. print price($line->credit).$separator;
  401. }
  402. print $line->doc_ref.$separator;
  403. print $line->label_operation.$separator;
  404. print $end_line;
  405. }
  406. }
  407. /**
  408. * Export format : COALA
  409. *
  410. * @param array $objectLines data
  411. * @return void
  412. */
  413. public function exportCoala($objectLines)
  414. {
  415. // Coala export
  416. $separator = ";";
  417. $end_line = "\n";
  418. foreach ($objectLines as $line) {
  419. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  420. print $date.$separator;
  421. print $line->code_journal.$separator;
  422. print length_accountg($line->numero_compte).$separator;
  423. print $line->piece_num.$separator;
  424. print $line->doc_ref.$separator;
  425. print price($line->debit).$separator;
  426. print price($line->credit).$separator;
  427. print 'E'.$separator;
  428. print length_accounta($line->subledger_account).$separator;
  429. print $end_line;
  430. }
  431. }
  432. /**
  433. * Export format : BOB50
  434. *
  435. * @param array $objectLines data
  436. * @return void
  437. */
  438. public function exportBob50($objectLines)
  439. {
  440. // Bob50
  441. $separator = ";";
  442. $end_line = "\n";
  443. foreach ($objectLines as $line) {
  444. print $line->piece_num.$separator;
  445. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  446. print $date.$separator;
  447. if (empty($line->subledger_account)) {
  448. print 'G'.$separator;
  449. print length_accounta($line->numero_compte).$separator;
  450. } else {
  451. if (substr($line->numero_compte, 0, 3) == '411') {
  452. print 'C'.$separator;
  453. }
  454. if (substr($line->numero_compte, 0, 3) == '401') {
  455. print 'F'.$separator;
  456. }
  457. print length_accountg($line->subledger_account).$separator;
  458. }
  459. print price($line->debit).$separator;
  460. print price($line->credit).$separator;
  461. print dol_trunc($line->label_operation, 32).$separator;
  462. print $end_line;
  463. }
  464. }
  465. /**
  466. * Export format : CIEL (Format XIMPORT)
  467. * Format since 2003 compatible CIEL version > 2002 / Sage50
  468. * Last review for this format : 2021-09-13 Alexandre Spangaro (aspangaro@open-dsi.fr)
  469. *
  470. * Help : https://sage50c.online-help.sage.fr/aide-technique/
  471. * In sage software | Use menu : "Exchange" > "Importing entries..."
  472. *
  473. * If you want to force filename to "XIMPORT.TXT" for automatically import file present in a directory :
  474. * use constant ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME
  475. *
  476. * @param array $TData data
  477. * @return void
  478. */
  479. public function exportCiel(&$TData)
  480. {
  481. $end_line = "\r\n";
  482. $i = 1;
  483. foreach ($TData as $data) {
  484. $code_compta = length_accountg($data->numero_compte);
  485. if (!empty($data->subledger_account)) {
  486. $code_compta = length_accounta($data->subledger_account);
  487. }
  488. $date_document = dol_print_date($data->doc_date, '%Y%m%d');
  489. $date_echeance = dol_print_date($data->date_lim_reglement, '%Y%m%d');
  490. $Tab = array();
  491. $Tab['num_ecriture'] = str_pad($data->piece_num, 5);
  492. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  493. $Tab['date_ecriture'] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
  494. $Tab['date_echeance'] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
  495. $Tab['num_piece'] = str_pad(self::trunc($data->doc_ref, 12), 12);
  496. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
  497. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
  498. $Tab['montant'] = str_pad(price2fec(abs($data->debit - $data->credit)), 13, ' ', STR_PAD_LEFT);
  499. $Tab['type_montant'] = str_pad($data->sens, 1);
  500. $Tab['vide'] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
  501. $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
  502. $Tab['end'] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
  503. $Tab['end_line'] = $end_line;
  504. print implode($Tab);
  505. $i++;
  506. }
  507. }
  508. /**
  509. * Export format : Quadratus (Format ASCII)
  510. * Format since 2015 compatible QuadraCOMPTA
  511. * Last review for this format : 2021/09/13 Alexandre Spangaro (aspangaro@open-dsi.fr)
  512. *
  513. * Help : https://docplayer.fr/20769649-Fichier-d-entree-ascii-dans-quadracompta.html
  514. * In QuadraCompta | Use menu : "Outils" > "Suivi des dossiers" > "Import ASCII(Compta)"
  515. *
  516. * @param array $TData data
  517. * @return void
  518. */
  519. public function exportQuadratus(&$TData)
  520. {
  521. global $conf, $db;
  522. $end_line = "\r\n";
  523. // We should use dol_now function not time however this is wrong date to transfert in accounting
  524. // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  525. // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  526. foreach ($TData as $data) {
  527. $code_compta = $data->numero_compte;
  528. if (!empty($data->subledger_account)) {
  529. $code_compta = $data->subledger_account;
  530. }
  531. $Tab = array();
  532. if (!empty($data->subledger_account)) {
  533. $Tab['type_ligne'] = 'C';
  534. $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
  535. $Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30);
  536. if ($data->doc_type == 'customer_invoice') {
  537. $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6));
  538. $Tab['filler'] = str_repeat(' ', 52);
  539. $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
  540. } elseif ($data->doc_type == 'supplier_invoice') {
  541. $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6));
  542. $Tab['filler'] = str_repeat(' ', 52);
  543. $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
  544. } else {
  545. $Tab['filler'] = str_repeat(' ', 59);
  546. $Tab['coll_compte'] = str_pad(' ', 8);
  547. }
  548. $Tab['filler2'] = str_repeat(' ', 110);
  549. $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
  550. if ($data->doc_type == 'customer_invoice') {
  551. $Tab['type_compte'] = 'C';
  552. } elseif ($data->doc_type == 'supplier_invoice') {
  553. $Tab['coll_compte'] = 'F';
  554. } else {
  555. $Tab['coll_compte'] = 'G';
  556. }
  557. $Tab['filler3'] = str_repeat(' ', 235);
  558. $Tab['end_line'] = $end_line;
  559. print implode($Tab);
  560. }
  561. $Tab = array();
  562. $Tab['type_ligne'] = 'M';
  563. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
  564. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  565. $Tab['folio'] = '000';
  566. // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  567. // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  568. //$Tab['date_ecriture'] = $date_ecriture;
  569. $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  570. $Tab['filler'] = ' ';
  571. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
  572. // Credit invoice - invert sens
  573. /*
  574. if ($data->montant < 0) {
  575. if ($data->sens == 'C') {
  576. $Tab['sens'] = 'D';
  577. } else {
  578. $Tab['sens'] = 'C';
  579. }
  580. $Tab['signe_montant'] = '-';
  581. } else {
  582. $Tab['sens'] = $data->sens; // C or D
  583. $Tab['signe_montant'] = '+';
  584. }*/
  585. $Tab['sens'] = $data->sens; // C or D
  586. $Tab['signe_montant'] = '+';
  587. // The amount must be in centimes without decimal points.
  588. $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
  589. $Tab['contrepartie'] = str_repeat(' ', 8);
  590. // Force date format : %d%m%y
  591. if (!empty($data->date_lim_reglement)) {
  592. //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
  593. $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
  594. } else {
  595. $Tab['date_echeance'] = '000000';
  596. }
  597. // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
  598. // $Tab['lettrage'] = str_repeat(' ', 5);
  599. $Tab['lettrage'] = str_repeat(' ', 2);
  600. $Tab['codestat'] = str_repeat(' ', 3);
  601. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
  602. // Keep correct quadra named field instead of anon filler
  603. // $Tab['filler2'] = str_repeat(' ', 20);
  604. $Tab['affaire'] = str_repeat(' ', 10);
  605. $Tab['quantity1'] = str_repeat(' ', 10);
  606. $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
  607. $Tab['devis'] = str_pad($conf->currency, 3);
  608. $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
  609. $Tab['filler3'] = str_repeat(' ', 3);
  610. // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
  611. // 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
  612. // TODO: we should filter more than only accent to avoid wrong line size
  613. // TODO: remove invoice number doc_ref in libelle,
  614. // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
  615. //$Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref) . ' ' . dol_string_unaccent($data->label_operation), 30), 30);
  616. $Tab['libelle_ecriture2'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 30), 30);
  617. $Tab['codetva'] = str_repeat(' ', 2);
  618. // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
  619. // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
  620. $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
  621. $Tab['filler4'] = str_repeat(' ', 73);
  622. $Tab['end_line'] = $end_line;
  623. print implode($Tab);
  624. }
  625. }
  626. /**
  627. * Export format : WinFic - eWinfic - WinSis Compta
  628. *
  629. *
  630. * @param array $TData data
  631. * @return void
  632. */
  633. public function exportWinfic(&$TData)
  634. {
  635. global $conf;
  636. $end_line = "\r\n";
  637. //We should use dol_now function not time however this is wrong date to transfert in accounting
  638. //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  639. //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  640. foreach ($TData as $data) {
  641. $code_compta = $data->numero_compte;
  642. if (!empty($data->subledger_account)) {
  643. $code_compta = $data->subledger_account;
  644. }
  645. $Tab = array();
  646. //$Tab['type_ligne'] = 'M';
  647. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  648. //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  649. //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  650. //$Tab['date_ecriture'] = $date_ecriture;
  651. $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
  652. $Tab['folio'] = ' 1';
  653. $Tab['num_ecriture'] = str_pad(self::trunc($data->piece_num, 6), 6, ' ', STR_PAD_LEFT);
  654. $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  655. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 6), 6, '0');
  656. if ($data->sens == 'D') {
  657. $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  658. $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  659. } else {
  660. $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  661. $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  662. }
  663. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30), 30);
  664. $Tab['lettrage'] = str_repeat(' ', 2);
  665. $Tab['code_piece'] = str_repeat(' ', 5);
  666. $Tab['code_stat'] = str_repeat(' ', 4);
  667. if (!empty($data->date_lim_reglement)) {
  668. //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
  669. $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
  670. } else {
  671. $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
  672. }
  673. $Tab['monnaie'] = '1';
  674. $Tab['filler'] = ' ';
  675. $Tab['ind_compteur'] = ' ';
  676. $Tab['quantite'] = '0,000000000';
  677. $Tab['code_pointage'] = str_repeat(' ', 2);
  678. $Tab['end_line'] = $end_line;
  679. print implode('|', $Tab);
  680. }
  681. }
  682. /**
  683. * Export format : EBP
  684. *
  685. * @param array $objectLines data
  686. * @return void
  687. */
  688. public function exportEbp($objectLines)
  689. {
  690. $separator = ',';
  691. $end_line = "\n";
  692. foreach ($objectLines as $line) {
  693. $date = dol_print_date($line->doc_date, '%d%m%Y');
  694. print $line->id.$separator;
  695. print $date.$separator;
  696. print $line->code_journal.$separator;
  697. if (empty($line->subledger_account)) {
  698. print $line->numero_compte.$separator;
  699. } else {
  700. print $line->subledger_account.$separator;
  701. }
  702. //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
  703. print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
  704. print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
  705. print price2num(abs($line->debit - $line->credit)).$separator;
  706. print $line->sens.$separator;
  707. print $date.$separator;
  708. //print 'EUR';
  709. print $end_line;
  710. }
  711. }
  712. /**
  713. * Export format : Agiris Isacompta
  714. *
  715. * @param array $objectLines data
  716. * @return void
  717. */
  718. public function exportAgiris($objectLines)
  719. {
  720. $separator = ';';
  721. $end_line = "\n";
  722. foreach ($objectLines as $line) {
  723. $date = dol_print_date($line->doc_date, '%d%m%Y');
  724. print $line->piece_num.$separator;
  725. print self::toAnsi($line->label_operation).$separator;
  726. print $date.$separator;
  727. print self::toAnsi($line->label_operation).$separator;
  728. if (empty($line->subledger_account)) {
  729. print length_accountg($line->numero_compte).$separator;
  730. print self::toAnsi($line->label_compte).$separator;
  731. } else {
  732. print length_accounta($line->subledger_account).$separator;
  733. print self::toAnsi($line->subledger_label).$separator;
  734. }
  735. print self::toAnsi($line->doc_ref).$separator;
  736. print price($line->debit).$separator;
  737. print price($line->credit).$separator;
  738. print price(abs($line->debit - $line->credit)).$separator;
  739. print $line->sens.$separator;
  740. print $line->lettering_code.$separator;
  741. print $line->code_journal;
  742. print $end_line;
  743. }
  744. }
  745. /**
  746. * Export format : OpenConcerto
  747. *
  748. * @param array $objectLines data
  749. * @return void
  750. */
  751. public function exportOpenConcerto($objectLines)
  752. {
  753. $separator = ';';
  754. $end_line = "\n";
  755. foreach ($objectLines as $line) {
  756. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  757. print $date.$separator;
  758. print $line->code_journal.$separator;
  759. if (empty($line->subledger_account)) {
  760. print length_accountg($line->numero_compte).$separator;
  761. } else {
  762. print length_accounta($line->subledger_account).$separator;
  763. }
  764. print $line->doc_ref.$separator;
  765. print $line->label_operation.$separator;
  766. print price($line->debit).$separator;
  767. print price($line->credit).$separator;
  768. print $end_line;
  769. }
  770. }
  771. /**
  772. * Export format : Configurable CSV
  773. *
  774. * @param array $objectLines data
  775. * @return void
  776. */
  777. public function exportConfigurable($objectLines)
  778. {
  779. global $conf;
  780. $separator = $this->separator;
  781. foreach ($objectLines as $line) {
  782. $tab = array();
  783. // export configurable
  784. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  785. $tab[] = $line->piece_num;
  786. $tab[] = $date;
  787. $tab[] = $line->doc_ref;
  788. $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
  789. $tab[] = length_accountg($line->numero_compte);
  790. $tab[] = length_accounta($line->subledger_account);
  791. $tab[] = price2num($line->debit);
  792. $tab[] = price2num($line->credit);
  793. $tab[] = price2num($line->debit - $line->credit);
  794. $tab[] = $line->code_journal;
  795. print implode($separator, $tab).$this->end_line;
  796. }
  797. }
  798. /**
  799. * Export format : FEC
  800. *
  801. * @param array $objectLines data
  802. * @return void
  803. */
  804. public function exportFEC($objectLines)
  805. {
  806. global $langs;
  807. $separator = "\t";
  808. $end_line = "\r\n";
  809. print "JournalCode".$separator;
  810. print "JournalLib".$separator;
  811. print "EcritureNum".$separator;
  812. print "EcritureDate".$separator;
  813. print "CompteNum".$separator;
  814. print "CompteLib".$separator;
  815. print "CompAuxNum".$separator;
  816. print "CompAuxLib".$separator;
  817. print "PieceRef".$separator;
  818. print "PieceDate".$separator;
  819. print "EcritureLib".$separator;
  820. print "Debit".$separator;
  821. print "Credit".$separator;
  822. print "EcritureLet".$separator;
  823. print "DateLet".$separator;
  824. print "ValidDate".$separator;
  825. print "Montantdevise".$separator;
  826. print "Idevise".$separator;
  827. print "DateLimitReglmt".$separator;
  828. print "NumFacture";
  829. print $end_line;
  830. foreach ($objectLines as $line) {
  831. if ($line->debit == 0 && $line->credit == 0) {
  832. //unset($array[$line]);
  833. } else {
  834. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  835. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  836. $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
  837. $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
  838. $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  839. $refInvoice = '';
  840. if ($line->doc_type == 'customer_invoice') {
  841. // Customer invoice
  842. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  843. $invoice = new Facture($this->db);
  844. $invoice->fetch($line->fk_doc);
  845. $refInvoice = $invoice->ref;
  846. } elseif ($line->doc_type == 'supplier_invoice') {
  847. // Supplier invoice
  848. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  849. $invoice = new FactureFournisseur($this->db);
  850. $invoice->fetch($line->fk_doc);
  851. $refInvoice = $invoice->ref_supplier;
  852. }
  853. // FEC:JournalCode
  854. print $line->code_journal . $separator;
  855. // FEC:JournalLib
  856. print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
  857. // FEC:EcritureNum
  858. print $line->piece_num . $separator;
  859. // FEC:EcritureDate
  860. print $date_document . $separator;
  861. // FEC:CompteNum
  862. print $line->numero_compte . $separator;
  863. // FEC:CompteLib
  864. print dol_string_unaccent($line->label_compte) . $separator;
  865. // FEC:CompAuxNum
  866. print $line->subledger_account . $separator;
  867. // FEC:CompAuxLib
  868. print dol_string_unaccent($line->subledger_label) . $separator;
  869. // FEC:PieceRef
  870. print $line->doc_ref . $separator;
  871. // FEC:PieceDate
  872. print dol_string_unaccent($date_creation) . $separator;
  873. // FEC:EcritureLib
  874. // Clean label operation to prevent problem on export with tab separator & other character
  875. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  876. print dol_string_unaccent($line->label_operation) . $separator;
  877. // FEC:Debit
  878. print price2fec($line->debit) . $separator;
  879. // FEC:Credit
  880. print price2fec($line->credit) . $separator;
  881. // FEC:EcritureLet
  882. print $line->lettering_code . $separator;
  883. // FEC:DateLet
  884. print $date_lettering . $separator;
  885. // FEC:ValidDate
  886. print $date_validation . $separator;
  887. // FEC:Montantdevise
  888. print $line->multicurrency_amount . $separator;
  889. // FEC:Idevise
  890. print $line->multicurrency_code . $separator;
  891. // FEC_suppl:DateLimitReglmt
  892. print $date_limit_payment . $separator;
  893. // FEC_suppl:NumFacture
  894. // Clean ref invoice to prevent problem on export with tab separator & other character
  895. $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
  896. print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
  897. print $end_line;
  898. }
  899. }
  900. }
  901. /**
  902. * Export format : FEC2
  903. *
  904. * @param array $objectLines data
  905. * @return void
  906. */
  907. public function exportFEC2($objectLines)
  908. {
  909. global $langs;
  910. $separator = "\t";
  911. $end_line = "\r\n";
  912. print "JournalCode".$separator;
  913. print "JournalLib".$separator;
  914. print "EcritureNum".$separator;
  915. print "EcritureDate".$separator;
  916. print "CompteNum".$separator;
  917. print "CompteLib".$separator;
  918. print "CompAuxNum".$separator;
  919. print "CompAuxLib".$separator;
  920. print "PieceRef".$separator;
  921. print "PieceDate".$separator;
  922. print "EcritureLib".$separator;
  923. print "Debit".$separator;
  924. print "Credit".$separator;
  925. print "EcritureLet".$separator;
  926. print "DateLet".$separator;
  927. print "ValidDate".$separator;
  928. print "Montantdevise".$separator;
  929. print "Idevise".$separator;
  930. print "DateLimitReglmt".$separator;
  931. print "NumFacture";
  932. print $end_line;
  933. foreach ($objectLines as $line) {
  934. if ($line->debit == 0 && $line->credit == 0) {
  935. //unset($array[$line]);
  936. } else {
  937. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  938. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  939. $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
  940. $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
  941. $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  942. $refInvoice = '';
  943. if ($line->doc_type == 'customer_invoice') {
  944. // Customer invoice
  945. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  946. $invoice = new Facture($this->db);
  947. $invoice->fetch($line->fk_doc);
  948. $refInvoice = $invoice->ref;
  949. } elseif ($line->doc_type == 'supplier_invoice') {
  950. // Supplier invoice
  951. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  952. $invoice = new FactureFournisseur($this->db);
  953. $invoice->fetch($line->fk_doc);
  954. $refInvoice = $invoice->ref_supplier;
  955. }
  956. // FEC:JournalCode
  957. print $line->code_journal . $separator;
  958. // FEC:JournalLib
  959. print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
  960. // FEC:EcritureNum
  961. print $line->piece_num . $separator;
  962. // FEC:EcritureDate
  963. print $date_creation . $separator;
  964. // FEC:CompteNum
  965. print length_accountg($line->numero_compte) . $separator;
  966. // FEC:CompteLib
  967. print dol_string_unaccent($line->label_compte) . $separator;
  968. // FEC:CompAuxNum
  969. print length_accounta($line->subledger_account) . $separator;
  970. // FEC:CompAuxLib
  971. print dol_string_unaccent($line->subledger_label) . $separator;
  972. // FEC:PieceRef
  973. print $line->doc_ref . $separator;
  974. // FEC:PieceDate
  975. print $date_document . $separator;
  976. // FEC:EcritureLib
  977. // Clean label operation to prevent problem on export with tab separator & other character
  978. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  979. print dol_string_unaccent($line->label_operation) . $separator;
  980. // FEC:Debit
  981. print price2fec($line->debit) . $separator;
  982. // FEC:Credit
  983. print price2fec($line->credit) . $separator;
  984. // FEC:EcritureLet
  985. print $line->lettering_code . $separator;
  986. // FEC:DateLet
  987. print $date_lettering . $separator;
  988. // FEC:ValidDate
  989. print $date_validation . $separator;
  990. // FEC:Montantdevise
  991. print $line->multicurrency_amount . $separator;
  992. // FEC:Idevise
  993. print $line->multicurrency_code . $separator;
  994. // FEC_suppl:DateLimitReglmt
  995. print $date_limit_payment . $separator;
  996. // FEC_suppl:NumFacture
  997. // Clean ref invoice to prevent problem on export with tab separator & other character
  998. $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
  999. print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
  1000. print $end_line;
  1001. }
  1002. }
  1003. }
  1004. /**
  1005. * Export format : SAGE50SWISS
  1006. *
  1007. * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984
  1008. * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf
  1009. *
  1010. * @param array $objectLines data
  1011. *
  1012. * @return void
  1013. */
  1014. public function exportSAGE50SWISS($objectLines)
  1015. {
  1016. // SAGE50SWISS
  1017. $this->separator = ',';
  1018. $this->end_line = "\r\n";
  1019. // Print header line
  1020. print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
  1021. print $this->end_line;
  1022. $thisPieceNum = "";
  1023. $thisPieceAccountNr = "";
  1024. $aSize = count($objectLines);
  1025. foreach ($objectLines as $aIndex => $line) {
  1026. $sammelBuchung = false;
  1027. if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
  1028. $sammelBuchung = true;
  1029. } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
  1030. $sammelBuchung = true;
  1031. } elseif ($aIndex + 1 < $aSize
  1032. && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
  1033. && $aIndex - 1 < $aSize
  1034. && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
  1035. ) {
  1036. $sammelBuchung = true;
  1037. }
  1038. //Blg
  1039. print $line->piece_num.$this->separator;
  1040. // Datum
  1041. $date = dol_print_date($line->doc_date, '%d.%m.%Y');
  1042. print $date.$this->separator;
  1043. // Kto
  1044. print length_accountg($line->numero_compte).$this->separator;
  1045. // S/H
  1046. if ($line->sens == 'D') {
  1047. print 'S'.$this->separator;
  1048. } else {
  1049. print 'H'.$this->separator;
  1050. }
  1051. //Grp
  1052. print self::trunc($line->code_journal, 1).$this->separator;
  1053. // GKto
  1054. if (empty($line->code_tiers)) {
  1055. if ($line->piece_num == $thisPieceNum) {
  1056. print length_accounta($thisPieceAccountNr).$this->separator;
  1057. } else {
  1058. print "div".$this->separator;
  1059. }
  1060. } else {
  1061. print length_accounta($line->code_tiers).$this->separator;
  1062. }
  1063. //SId
  1064. print $this->separator;
  1065. //SIdx
  1066. print "0".$this->separator;
  1067. //KIdx
  1068. print "0".$this->separator;
  1069. //BTyp
  1070. print "0".$this->separator;
  1071. //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
  1072. if ($sammelBuchung) {
  1073. print "2".$this->separator;
  1074. } else {
  1075. print "1".$this->separator;
  1076. }
  1077. // Code
  1078. print '""'.$this->separator;
  1079. // Netto
  1080. print abs($line->debit - $line->credit).$this->separator;
  1081. // Steuer
  1082. print "0.00".$this->separator;
  1083. // FW-Betrag
  1084. print "0.00".$this->separator;
  1085. // Tx1
  1086. $line1 = self::toAnsi($line->label_compte, 29);
  1087. if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
  1088. $line1 = "";
  1089. }
  1090. $line2 = self::toAnsi($line->doc_ref, 29);
  1091. if (strlen($line1) == 0) {
  1092. $line1 = $line2;
  1093. $line2 = "";
  1094. }
  1095. if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
  1096. $line1 = $line1.' / '.$line2;
  1097. $line2 = "";
  1098. }
  1099. print '"'.self::toAnsi($line1).'"'.$this->separator;
  1100. // Tx2
  1101. print '"'.self::toAnsi($line2).'"'.$this->separator;
  1102. //PkKey
  1103. print "0".$this->separator;
  1104. //OpId
  1105. print $this->separator;
  1106. // Flag
  1107. print "0";
  1108. print $this->end_line;
  1109. if ($line->piece_num !== $thisPieceNum) {
  1110. $thisPieceNum = $line->piece_num;
  1111. $thisPieceAccountNr = $line->numero_compte;
  1112. }
  1113. }
  1114. }
  1115. /**
  1116. * Export format : LD Compta version 9
  1117. * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf
  1118. *
  1119. * @param array $objectLines data
  1120. *
  1121. * @return void
  1122. */
  1123. public function exportLDCompta($objectLines)
  1124. {
  1125. $separator = ';';
  1126. $end_line = "\r\n";
  1127. foreach ($objectLines as $line) {
  1128. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  1129. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  1130. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  1131. // TYPE
  1132. $type_enregistrement = 'E'; // For write movement
  1133. print $type_enregistrement.$separator;
  1134. // JNAL
  1135. print substr($line->code_journal, 0, 2).$separator;
  1136. // NECR
  1137. print $line->id.$separator;
  1138. // NPIE
  1139. print $line->piece_num.$separator;
  1140. // DATP
  1141. print $date_document.$separator;
  1142. // LIBE
  1143. print $line->label_operation.$separator;
  1144. // DATH
  1145. print $date_lim_reglement.$separator;
  1146. // CNPI
  1147. if ($line->doc_type == 'supplier_invoice') {
  1148. if (($line->debit - $line->credit) > 0) {
  1149. $nature_piece = 'AF';
  1150. } else {
  1151. $nature_piece = 'FF';
  1152. }
  1153. } elseif ($line->doc_type == 'customer_invoice') {
  1154. if (($line->debit - $line->credit) < 0) {
  1155. $nature_piece = 'AC';
  1156. } else {
  1157. $nature_piece = 'FC';
  1158. }
  1159. } else {
  1160. $nature_piece = '';
  1161. }
  1162. print $nature_piece.$separator;
  1163. // RACI
  1164. // if (! empty($line->subledger_account)) {
  1165. // if ($line->doc_type == 'supplier_invoice') {
  1166. // $racine_subledger_account = '40';
  1167. // } elseif ($line->doc_type == 'customer_invoice') {
  1168. // $racine_subledger_account = '41';
  1169. // } else {
  1170. // $racine_subledger_account = '';
  1171. // }
  1172. // } else {
  1173. $racine_subledger_account = ''; // for records of type E leave this field blank
  1174. // }
  1175. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  1176. // MONT
  1177. print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
  1178. // CODC
  1179. print $line->sens.$separator;
  1180. // CPTG
  1181. print length_accountg($line->numero_compte).$separator;
  1182. // DATE
  1183. print $date_creation.$separator;
  1184. // CLET
  1185. print $line->lettering_code.$separator;
  1186. // DATL
  1187. print $line->date_lettering.$separator;
  1188. // CPTA
  1189. if (!empty($line->subledger_account)) {
  1190. print length_accounta($line->subledger_account).$separator;
  1191. } else {
  1192. print $separator;
  1193. }
  1194. // CNAT
  1195. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  1196. print 'F'.$separator;
  1197. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  1198. print 'C'.$separator;
  1199. } else {
  1200. print $separator;
  1201. }
  1202. // SECT
  1203. print $separator;
  1204. // CTRE
  1205. print $separator;
  1206. // NORL
  1207. print $separator;
  1208. // DATV
  1209. print $separator;
  1210. // REFD
  1211. print $line->doc_ref.$separator;
  1212. // CODH
  1213. print $separator;
  1214. // NSEQ
  1215. print $separator;
  1216. // MTDV
  1217. print '0'.$separator;
  1218. // CODV
  1219. print $separator;
  1220. // TXDV
  1221. print '0'.$separator;
  1222. // MOPM
  1223. print $separator;
  1224. // BONP
  1225. print $separator;
  1226. // BQAF
  1227. print $separator;
  1228. // ECES
  1229. print $separator;
  1230. // TXTL
  1231. print $separator;
  1232. // ECRM
  1233. print $separator;
  1234. // DATK
  1235. print $separator;
  1236. // HEUK
  1237. print $separator;
  1238. print $end_line;
  1239. }
  1240. }
  1241. /**
  1242. * Export format : LD Compta version 10 & higher
  1243. * Last review for this format : 08-15-2021 Alexandre Spangaro (aspangaro@open-dsi.fr)
  1244. *
  1245. * Help : http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf
  1246. *
  1247. * @param array $objectLines data
  1248. *
  1249. * @return void
  1250. */
  1251. public function exportLDCompta10($objectLines)
  1252. {
  1253. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  1254. $separator = ';';
  1255. $end_line = "\r\n";
  1256. $last_codeinvoice = '';
  1257. foreach ($objectLines as $line) {
  1258. // TYPE C
  1259. if ($last_codeinvoice != $line->doc_ref) {
  1260. //recherche societe en fonction de son code client
  1261. $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
  1262. $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
  1263. $resql = $this->db->query($sql);
  1264. if ($resql && $this->db->num_rows($resql) > 0) {
  1265. $soc = $this->db->fetch_object($resql);
  1266. $address = array('', '', '');
  1267. if (strpos($soc->address, "\n") !== false) {
  1268. $address = explode("\n", $soc->address);
  1269. if (is_array($address) && count($address) > 0) {
  1270. foreach ($address as $key => $data) {
  1271. $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
  1272. $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
  1273. }
  1274. }
  1275. } else {
  1276. $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
  1277. $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
  1278. $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
  1279. }
  1280. $type_enregistrement = 'C';
  1281. //TYPE
  1282. print $type_enregistrement.$separator;
  1283. //NOCL
  1284. print $soc->code_client.$separator;
  1285. //NMCM
  1286. print $separator;
  1287. //LIBI
  1288. print $separator;
  1289. //TITR
  1290. print $separator;
  1291. //RSSO
  1292. print $soc->nom.$separator;
  1293. //CAD1
  1294. print $address[0].$separator;
  1295. //CAD2
  1296. print $address[1].$separator;
  1297. //CAD3
  1298. print $address[2].$separator;
  1299. //COPO
  1300. print $soc->zip.$separator;
  1301. //BUDI
  1302. print substr($soc->town, 0, 40).$separator;
  1303. //CPAY
  1304. print $separator;
  1305. //PAYS
  1306. print substr(getCountry($soc->fk_pays), 0, 40).$separator;
  1307. //NTEL
  1308. print $soc->phone.$separator;
  1309. //TLEX
  1310. print $separator;
  1311. //TLPO
  1312. print $separator;
  1313. //TLCY
  1314. print $separator;
  1315. //NINT
  1316. print $separator;
  1317. //COMM
  1318. print $separator;
  1319. //SIRE
  1320. print str_replace(" ", "", $soc->siret).$separator;
  1321. //RIBP
  1322. print $separator;
  1323. //DOBQ
  1324. print $separator;
  1325. //IBBQ
  1326. print $separator;
  1327. //COBQ
  1328. print $separator;
  1329. //GUBQ
  1330. print $separator;
  1331. //CPBQ
  1332. print $separator;
  1333. //CLBQ
  1334. print $separator;
  1335. //BIBQ
  1336. print $separator;
  1337. //MOPM
  1338. print $separator;
  1339. //DJPM
  1340. print $separator;
  1341. //DMPM
  1342. print $separator;
  1343. //REFM
  1344. print $separator;
  1345. //SLVA
  1346. print $separator;
  1347. //PLCR
  1348. print $separator;
  1349. //ECFI
  1350. print $separator;
  1351. //CREP
  1352. print $separator;
  1353. //NREP
  1354. print $separator;
  1355. //TREP
  1356. print $separator;
  1357. //MREP
  1358. print $separator;
  1359. //GRRE
  1360. print $separator;
  1361. //LTTA
  1362. print $separator;
  1363. //CACT
  1364. print $separator;
  1365. //CODV
  1366. print $separator;
  1367. //GRTR
  1368. print $separator;
  1369. //NOFP
  1370. print $separator;
  1371. //BQAF
  1372. print $separator;
  1373. //BONP
  1374. print $separator;
  1375. //CESC
  1376. print $separator;
  1377. print $end_line;
  1378. }
  1379. }
  1380. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  1381. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  1382. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  1383. // TYPE E
  1384. $type_enregistrement = 'E'; // For write movement
  1385. print $type_enregistrement.$separator;
  1386. // JNAL
  1387. print substr($line->code_journal, 0, 2).$separator;
  1388. // NECR
  1389. print $line->id.$separator;
  1390. // NPIE
  1391. print $line->piece_num.$separator;
  1392. // DATP
  1393. print $date_document.$separator;
  1394. // LIBE
  1395. print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
  1396. // DATH
  1397. print $date_lim_reglement.$separator;
  1398. // CNPI
  1399. if ($line->doc_type == 'supplier_invoice') {
  1400. if (($line->amount) < 0) { // Currently, only the sign of amount allows to know the type of invoice (standard or credit note). Other solution is to analyse debit/credit/role of account. TODO Add column doc_type_long or make amount mandatory with rule on sign.
  1401. $nature_piece = 'AF';
  1402. } else {
  1403. $nature_piece = 'FF';
  1404. }
  1405. } elseif ($line->doc_type == 'customer_invoice') {
  1406. if (($line->amount) < 0) {
  1407. $nature_piece = 'AC'; // Currently, only the sign of amount allows to know the type of invoice (standard or credit note). Other solution is to analyse debit/credit/role of account. TODO Add column doc_type_long or make amount mandatory with rule on sign.
  1408. } else {
  1409. $nature_piece = 'FC';
  1410. }
  1411. } else {
  1412. $nature_piece = '';
  1413. }
  1414. print $nature_piece.$separator;
  1415. // RACI
  1416. // if (! empty($line->subledger_account)) {
  1417. // if ($line->doc_type == 'supplier_invoice') {
  1418. // $racine_subledger_account = '40';
  1419. // } elseif ($line->doc_type == 'customer_invoice') {
  1420. // $racine_subledger_account = '41';
  1421. // } else {
  1422. // $racine_subledger_account = '';
  1423. // }
  1424. // } else {
  1425. $racine_subledger_account = ''; // for records of type E leave this field blank
  1426. // }
  1427. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  1428. // MONT
  1429. print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
  1430. // CODC
  1431. print $line->sens.$separator;
  1432. // CPTG
  1433. print length_accountg($line->numero_compte).$separator;
  1434. // DATE
  1435. print $date_document.$separator;
  1436. // CLET
  1437. print $line->lettering_code.$separator;
  1438. // DATL
  1439. print $line->date_lettering.$separator;
  1440. // CPTA
  1441. if (!empty($line->subledger_account)) {
  1442. print length_accounta($line->subledger_account).$separator;
  1443. } else {
  1444. print $separator;
  1445. }
  1446. // CNAT
  1447. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  1448. print 'F'.$separator;
  1449. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  1450. print 'C'.$separator;
  1451. } else {
  1452. print $separator;
  1453. }
  1454. // CTRE
  1455. print $separator;
  1456. // NORL
  1457. print $separator;
  1458. // DATV
  1459. print $separator;
  1460. // REFD
  1461. print $line->doc_ref.$separator;
  1462. // NECA
  1463. print '0'.$separator;
  1464. // CSEC
  1465. print $separator;
  1466. // CAFF
  1467. print $separator;
  1468. // CDES
  1469. print $separator;
  1470. // QTUE
  1471. print $separator;
  1472. // MTDV
  1473. print '0'.$separator;
  1474. // CODV
  1475. print $separator;
  1476. // TXDV
  1477. print '0'.$separator;
  1478. // MOPM
  1479. print $separator;
  1480. // BONP
  1481. print $separator;
  1482. // BQAF
  1483. print $separator;
  1484. // ECES
  1485. print $separator;
  1486. // TXTL
  1487. print $separator;
  1488. // ECRM
  1489. print $separator;
  1490. // DATK
  1491. print $separator;
  1492. // HEUK
  1493. print $separator;
  1494. print $end_line;
  1495. $last_codeinvoice = $line->doc_ref;
  1496. }
  1497. }
  1498. /**
  1499. * Export format : Charlemagne
  1500. *
  1501. * @param array $objectLines data
  1502. * @return void
  1503. */
  1504. public function exportCharlemagne($objectLines)
  1505. {
  1506. global $langs;
  1507. $langs->load('compta');
  1508. $separator = "\t";
  1509. $end_line = "\n";
  1510. /*
  1511. * Charlemagne export need header
  1512. */
  1513. print $langs->transnoentitiesnoconv('Date').$separator;
  1514. print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
  1515. print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
  1516. print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
  1517. print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
  1518. print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
  1519. print $langs->transnoentitiesnoconv('Amount').$separator;
  1520. print 'S'.$separator;
  1521. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
  1522. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
  1523. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
  1524. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
  1525. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
  1526. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
  1527. print $end_line;
  1528. foreach ($objectLines as $line) {
  1529. $date = dol_print_date($line->doc_date, '%Y%m%d');
  1530. print $date.$separator; //Date
  1531. print self::trunc($line->code_journal, 6).$separator; //Journal code
  1532. if (!empty($line->subledger_account)) {
  1533. $account = $line->subledger_account;
  1534. } else {
  1535. $account = $line->numero_compte;
  1536. }
  1537. print self::trunc($account, 15).$separator; //Account number
  1538. print self::trunc($line->label_compte, 60).$separator; //Account label
  1539. print self::trunc($line->doc_ref, 20).$separator; //Piece
  1540. // Clean label operation to prevent problem on export with tab separator & other character
  1541. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  1542. print self::trunc($line->label_operation, 60).$separator; //Operation label
  1543. print price(abs($line->debit - $line->credit)).$separator; //Amount
  1544. print $line->sens.$separator; //Direction
  1545. print $separator; //Analytic
  1546. print $separator; //Analytic
  1547. print $separator; //Analytic
  1548. print $separator; //Analytic
  1549. print $separator; //Analytic
  1550. print $separator; //Analytic
  1551. print $end_line;
  1552. }
  1553. }
  1554. /**
  1555. * Export format : Gestimum V3
  1556. *
  1557. * @param array $objectLines data
  1558. *
  1559. * @return void
  1560. */
  1561. public function exportGestimumV3($objectLines)
  1562. {
  1563. global $langs;
  1564. $this->separator = ',';
  1565. $invoices_infos = array();
  1566. $supplier_invoices_infos = array();
  1567. foreach ($objectLines as $line) {
  1568. if ($line->debit == 0 && $line->credit == 0) {
  1569. //unset($array[$line]);
  1570. } else {
  1571. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  1572. $invoice_ref = $line->doc_ref;
  1573. $company_name = "";
  1574. if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
  1575. if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
  1576. ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
  1577. if ($line->doc_type == 'customer_invoice') {
  1578. // Get new customer invoice ref and company name
  1579. $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
  1580. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
  1581. $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
  1582. $resql = $this->db->query($sql);
  1583. if ($resql) {
  1584. if ($obj = $this->db->fetch_object($resql)) {
  1585. // Save invoice infos
  1586. $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
  1587. $invoice_ref = $obj->ref;
  1588. $company_name = $obj->nom;
  1589. }
  1590. }
  1591. } else {
  1592. // Get new supplier invoice ref and company name
  1593. $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
  1594. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
  1595. $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
  1596. $resql = $this->db->query($sql);
  1597. if ($resql) {
  1598. if ($obj = $this->db->fetch_object($resql)) {
  1599. // Save invoice infos
  1600. $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
  1601. $invoice_ref = $obj->ref;
  1602. $company_name = $obj->nom;
  1603. }
  1604. }
  1605. }
  1606. } elseif ($line->doc_type == 'customer_invoice') {
  1607. // Retrieve invoice infos
  1608. $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
  1609. $company_name = $invoices_infos[$line->fk_doc]['company_name'];
  1610. } else {
  1611. // Retrieve invoice infos
  1612. $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
  1613. $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
  1614. }
  1615. }
  1616. print $line->id . $this->separator;
  1617. print $date . $this->separator;
  1618. print substr($line->code_journal, 0, 4) . $this->separator;
  1619. if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
  1620. print length_accountg($line->subledger_account) . $this->separator;
  1621. } else {
  1622. print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
  1623. }
  1624. //Libellé Auto
  1625. print $this->separator;
  1626. //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
  1627. //Libellé manuel
  1628. print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
  1629. //Numéro de pièce
  1630. print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
  1631. //Devise
  1632. print 'EUR' . $this->separator;
  1633. //Amount
  1634. print price2num(abs($line->debit - $line->credit)) . $this->separator;
  1635. //Sens
  1636. print $line->sens . $this->separator;
  1637. //Code lettrage
  1638. print $this->separator;
  1639. //Date Echéance
  1640. print $date;
  1641. print $this->end_line;
  1642. }
  1643. }
  1644. }
  1645. /**
  1646. * Export format : Gestimum V5
  1647. *
  1648. * @param array $objectLines data
  1649. *
  1650. * @return void
  1651. */
  1652. public function exportGestimumV5($objectLines)
  1653. {
  1654. $this->separator = ',';
  1655. foreach ($objectLines as $line) {
  1656. if ($line->debit == 0 && $line->credit == 0) {
  1657. //unset($array[$line]);
  1658. } else {
  1659. $date = dol_print_date($line->doc_date, '%d%m%Y');
  1660. print $line->id . $this->separator;
  1661. print $date . $this->separator;
  1662. print substr($line->code_journal, 0, 4) . $this->separator;
  1663. if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
  1664. print length_accountg($line->subledger_account) . $this->separator;
  1665. } else {
  1666. print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
  1667. }
  1668. print $this->separator;
  1669. //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
  1670. print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
  1671. print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
  1672. print price2num(abs($line->debit - $line->credit)) . $this->separator;
  1673. print $line->sens . $this->separator;
  1674. print $date . $this->separator;
  1675. print $this->separator;
  1676. print $this->separator;
  1677. print 'EUR';
  1678. print $this->end_line;
  1679. }
  1680. }
  1681. }
  1682. /**
  1683. * Export format : iSuite Expert
  1684. *
  1685. * by OpenSolus [https://opensolus.fr]
  1686. *
  1687. * @param array $objectLines data
  1688. *
  1689. * @return void
  1690. */
  1691. public function exportiSuiteExpert($objectLines)
  1692. {
  1693. $this->separator = ';';
  1694. $this->end_line = "\r\n";
  1695. foreach ($objectLines as $line) {
  1696. $tab = array();
  1697. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  1698. $tab[] = $line->piece_num;
  1699. $tab[] = $date;
  1700. $tab[] = substr($date, 6, 4);
  1701. $tab[] = substr($date, 3, 2);
  1702. $tab[] = substr($date, 0, 2);
  1703. $tab[] = $line->doc_ref;
  1704. //Conversion de chaine UTF8 en Latin9
  1705. $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
  1706. //Calcul de la longueur des numéros de comptes
  1707. $taille_numero = strlen(length_accountg($line->numero_compte));
  1708. //Création du numéro de client générique
  1709. $numero_cpt_client = '411';
  1710. for ($i = 1; $i <= ($taille_numero - 3); $i++) {
  1711. $numero_cpt_client .= '0';
  1712. }
  1713. //Création des comptes auxiliaire des clients
  1714. if (length_accountg($line->numero_compte) == $numero_cpt_client) {
  1715. $tab[] = rtrim(length_accounta($line->subledger_account), "0");
  1716. } else {
  1717. $tab[] = length_accountg($line->numero_compte);
  1718. }
  1719. $nom_client = explode(" - ", $line->label_operation);
  1720. $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
  1721. $tab[] = price($line->debit);
  1722. $tab[] = price($line->credit);
  1723. $tab[] = price($line->montant);
  1724. $tab[] = $line->code_journal;
  1725. $separator = $this->separator;
  1726. print implode($separator, $tab) . $this->end_line;
  1727. }
  1728. }
  1729. /**
  1730. * trunc
  1731. *
  1732. * @param string $str String
  1733. * @param integer $size Data to trunc
  1734. * @return string
  1735. */
  1736. public static function trunc($str, $size)
  1737. {
  1738. return dol_trunc($str, $size, 'right', 'UTF-8', 1);
  1739. }
  1740. /**
  1741. * toAnsi
  1742. *
  1743. * @param string $str Original string to encode and optionaly truncate
  1744. * @param integer $size Truncate string after $size characters
  1745. * @return string String encoded in Windows-1251 charset
  1746. */
  1747. public static function toAnsi($str, $size = -1)
  1748. {
  1749. $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
  1750. if ($retVal >= 0 && $size >= 0) {
  1751. $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
  1752. }
  1753. return $retVal;
  1754. }
  1755. }