accountancyexport.class.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  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-2023 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, $hookmanager;
  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. $parameters = array();
  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 : 2023/01/28 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. // Clean some data
  528. $data->doc_ref = dol_string_unaccent($data->doc_ref);
  529. $data->label_operation = dol_string_unaccent($data->label_operation);
  530. $data->numero_compte = dol_string_unaccent($data->numero_compte);
  531. $data->label_compte = dol_string_unaccent($data->label_compte);
  532. $data->subledger_account = dol_string_unaccent($data->subledger_account);
  533. $data->subledger_label = dol_string_unaccent($data->subledger_label);
  534. $code_compta = $data->numero_compte;
  535. if (!empty($data->subledger_account)) {
  536. $code_compta = $data->subledger_account;
  537. }
  538. $Tab = array();
  539. if (!empty($data->subledger_account)) {
  540. $Tab['type_ligne'] = 'C';
  541. $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
  542. // Added by MMI Mathieu Moulin iProspective
  543. // Feature : Option to use Account account as label (in case of multiples customers with same accounts)
  544. // Fix : remove accents using dol_string_unaccent()
  545. if (!empty($conf->global->MMI_COMPTA_EXPORT_LABEL_AS_ACCOUNT))
  546. $Tab['lib_compte'] = str_pad(self::trunc(dol_string_unaccent($data->subledger_account), 8), 30);
  547. else
  548. $Tab['lib_compte'] = str_pad(self::trunc(dol_string_unaccent($data->subledger_label), 30), 30);
  549. if ($data->doc_type == 'customer_invoice') {
  550. $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc(dol_string_unaccent($data->subledger_label), 6), 6));
  551. $Tab['filler'] = str_repeat(' ', 52);
  552. $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
  553. } elseif ($data->doc_type == 'supplier_invoice') {
  554. $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc(dol_string_unaccent($data->subledger_label), 6), 6));
  555. $Tab['filler'] = str_repeat(' ', 52);
  556. $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
  557. } else {
  558. $Tab['filler'] = str_repeat(' ', 59);
  559. $Tab['coll_compte'] = str_pad(' ', 8);
  560. }
  561. $Tab['filler2'] = str_repeat(' ', 110);
  562. $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
  563. if ($data->doc_type == 'customer_invoice') {
  564. $Tab['type_compte'] = 'C';
  565. } elseif ($data->doc_type == 'supplier_invoice') {
  566. $Tab['type_compte'] = 'F';
  567. } else {
  568. $Tab['type_compte'] = 'G';
  569. }
  570. $Tab['filler3'] = str_repeat(' ', 235);
  571. $Tab['end_line'] = $end_line;
  572. print implode($Tab);
  573. }
  574. $Tab = array();
  575. $Tab['type_ligne'] = 'M';
  576. $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
  577. $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
  578. $Tab['folio'] = '000';
  579. // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  580. // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  581. //$Tab['date_ecriture'] = $date_ecriture;
  582. $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  583. $Tab['filler'] = ' ';
  584. $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 20), 20);
  585. // Credit invoice - invert sens
  586. /*
  587. if ($data->montant < 0) {
  588. if ($data->sens == 'C') {
  589. $Tab['sens'] = 'D';
  590. } else {
  591. $Tab['sens'] = 'C';
  592. }
  593. $Tab['signe_montant'] = '-';
  594. } else {
  595. $Tab['sens'] = $data->sens; // C or D
  596. $Tab['signe_montant'] = '+';
  597. }*/
  598. $Tab['sens'] = $data->sens; // C or D
  599. $Tab['signe_montant'] = '+';
  600. // The amount must be in centimes without decimal points.
  601. $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
  602. $Tab['contrepartie'] = str_repeat(' ', 8);
  603. // Force date format : %d%m%y
  604. if (!empty($data->date_lim_reglement)) {
  605. //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
  606. $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
  607. } else {
  608. $Tab['date_echeance'] = '000000';
  609. }
  610. // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
  611. // $Tab['lettrage'] = str_repeat(' ', 5);
  612. $Tab['lettrage'] = str_repeat(' ', 2);
  613. $Tab['codestat'] = str_repeat(' ', 3);
  614. $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
  615. // Keep correct quadra named field instead of anon filler
  616. // $Tab['filler2'] = str_repeat(' ', 20);
  617. $Tab['affaire'] = str_repeat(' ', 10);
  618. $Tab['quantity1'] = str_repeat(' ', 10);
  619. $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
  620. $Tab['devis'] = str_pad($conf->currency, 3);
  621. $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
  622. $Tab['filler3'] = str_repeat(' ', 3);
  623. // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
  624. // 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
  625. // TODO: we should filter more than only accent to avoid wrong line size
  626. // TODO: remove invoice number doc_ref in libelle,
  627. // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
  628. //$Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 30), 30);
  629. $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->label_operation, 30), 30);
  630. $Tab['codetva'] = str_repeat(' ', 2);
  631. // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
  632. // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
  633. $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
  634. $Tab['filler4'] = str_repeat(' ', 73);
  635. $Tab['end_line'] = $end_line;
  636. // Added by MMI Mathieu Moulin iProspective
  637. // Fix : Quadra does not like …
  638. print str_replace('…', '.', implode($Tab));
  639. }
  640. }
  641. /**
  642. * Export format : WinFic - eWinfic - WinSis Compta
  643. * Last review for this format : 2022-11-01 Alexandre Spangaro (aspangaro@open-dsi.fr)
  644. *
  645. * Help : https://wiki.gestan.fr/lib/exe/fetch.php?media=wiki:v15:compta:accountancy-format_winfic-ewinfic-winsiscompta.pdf
  646. *
  647. * @param array $TData data
  648. *
  649. * @return void
  650. */
  651. public function exportWinfic(&$TData)
  652. {
  653. global $conf;
  654. $end_line = "\r\n";
  655. $index = 1;
  656. //We should use dol_now function not time however this is wrong date to transfert in accounting
  657. //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  658. //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
  659. // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
  660. foreach ($TData as $data) {
  661. $code_compta = $data->numero_compte;
  662. if (!empty($data->subledger_account)) {
  663. $code_compta = $data->subledger_account;
  664. }
  665. $Tab = array();
  666. //$Tab['type_ligne'] = 'M';
  667. $Tab['code_journal'] = str_pad(dol_trunc($data->code_journal, 2, 'right', 'UTF-8', 1), 2);
  668. //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
  669. //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
  670. //$Tab['date_ecriture'] = $date_ecriture;
  671. $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
  672. $Tab['folio'] = ' 1';
  673. $Tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
  674. $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
  675. $Tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
  676. if ($data->sens == 'D') {
  677. $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  678. $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  679. } else {
  680. $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  681. $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
  682. }
  683. $Tab['libelle_ecriture'] = str_pad(dol_trunc(dol_string_unaccent($data->doc_ref).' '.dol_string_unaccent($data->label_operation), 30, 'right', 'UTF-8', 1), 30);
  684. $Tab['lettrage'] = str_repeat(dol_trunc($data->lettering_code, 2, 'left', 'UTF-8', 1), 2);
  685. $Tab['code_piece'] = str_pad(dol_trunc($data->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
  686. $Tab['code_stat'] = str_repeat(' ', 4);
  687. if (!empty($data->date_lim_reglement)) {
  688. //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
  689. $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
  690. } else {
  691. $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
  692. }
  693. $Tab['monnaie'] = '1';
  694. $Tab['filler'] = ' ';
  695. $Tab['ind_compteur'] = ' ';
  696. $Tab['quantite'] = '0,000000000';
  697. $Tab['code_pointage'] = str_repeat(' ', 2);
  698. $Tab['end_line'] = $end_line;
  699. print implode('|', $Tab);
  700. $index++;
  701. }
  702. }
  703. /**
  704. * Export format : EBP
  705. *
  706. * @param array $objectLines data
  707. * @return void
  708. */
  709. public function exportEbp($objectLines)
  710. {
  711. $separator = ',';
  712. $end_line = "\n";
  713. foreach ($objectLines as $line) {
  714. $date = dol_print_date($line->doc_date, '%d%m%Y');
  715. print $line->id.$separator;
  716. print $date.$separator;
  717. print $line->code_journal.$separator;
  718. if (empty($line->subledger_account)) {
  719. print $line->numero_compte.$separator;
  720. } else {
  721. print $line->subledger_account.$separator;
  722. }
  723. //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
  724. print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
  725. print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
  726. print price2num(abs($line->debit - $line->credit)).$separator;
  727. print $line->sens.$separator;
  728. print $date.$separator;
  729. //print 'EUR';
  730. print $end_line;
  731. }
  732. }
  733. /**
  734. * Export format : Agiris Isacompta
  735. *
  736. * @param array $objectLines data
  737. * @return void
  738. */
  739. public function exportAgiris($objectLines)
  740. {
  741. $separator = ';';
  742. $end_line = "\n";
  743. foreach ($objectLines as $line) {
  744. $date = dol_print_date($line->doc_date, '%d%m%Y');
  745. print $line->piece_num.$separator;
  746. print self::toAnsi($line->label_operation).$separator;
  747. print $date.$separator;
  748. print self::toAnsi($line->label_operation).$separator;
  749. if (empty($line->subledger_account)) {
  750. print length_accountg($line->numero_compte).$separator;
  751. print self::toAnsi($line->label_compte).$separator;
  752. } else {
  753. print length_accounta($line->subledger_account).$separator;
  754. print self::toAnsi($line->subledger_label).$separator;
  755. }
  756. print self::toAnsi($line->doc_ref).$separator;
  757. print price($line->debit).$separator;
  758. print price($line->credit).$separator;
  759. print price(abs($line->debit - $line->credit)).$separator;
  760. print $line->sens.$separator;
  761. print $line->lettering_code.$separator;
  762. print $line->code_journal;
  763. print $end_line;
  764. }
  765. }
  766. /**
  767. * Export format : OpenConcerto
  768. *
  769. * @param array $objectLines data
  770. * @return void
  771. */
  772. public function exportOpenConcerto($objectLines)
  773. {
  774. $separator = ';';
  775. $end_line = "\n";
  776. foreach ($objectLines as $line) {
  777. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  778. print $date.$separator;
  779. print $line->code_journal.$separator;
  780. if (empty($line->subledger_account)) {
  781. print length_accountg($line->numero_compte).$separator;
  782. } else {
  783. print length_accounta($line->subledger_account).$separator;
  784. }
  785. print $line->doc_ref.$separator;
  786. print $line->label_operation.$separator;
  787. print price($line->debit).$separator;
  788. print price($line->credit).$separator;
  789. print $end_line;
  790. }
  791. }
  792. /**
  793. * Export format : Configurable CSV
  794. *
  795. * @param array $objectLines data
  796. * @return void
  797. */
  798. public function exportConfigurable($objectLines)
  799. {
  800. global $conf;
  801. $separator = $this->separator;
  802. foreach ($objectLines as $line) {
  803. $tab = array();
  804. // export configurable
  805. $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
  806. $tab[] = $line->piece_num;
  807. $tab[] = $date;
  808. $tab[] = $line->doc_ref;
  809. $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
  810. $tab[] = length_accountg($line->numero_compte);
  811. $tab[] = length_accounta($line->subledger_account);
  812. $tab[] = price2num($line->debit);
  813. $tab[] = price2num($line->credit);
  814. $tab[] = price2num($line->debit - $line->credit);
  815. $tab[] = $line->code_journal;
  816. print implode($separator, $tab).$this->end_line;
  817. }
  818. }
  819. /**
  820. * Export format : FEC
  821. *
  822. * @param array $objectLines data
  823. * @return void
  824. */
  825. public function exportFEC($objectLines)
  826. {
  827. global $langs;
  828. $separator = "\t";
  829. $end_line = "\r\n";
  830. print "JournalCode".$separator;
  831. print "JournalLib".$separator;
  832. print "EcritureNum".$separator;
  833. print "EcritureDate".$separator;
  834. print "CompteNum".$separator;
  835. print "CompteLib".$separator;
  836. print "CompAuxNum".$separator;
  837. print "CompAuxLib".$separator;
  838. print "PieceRef".$separator;
  839. print "PieceDate".$separator;
  840. print "EcritureLib".$separator;
  841. print "Debit".$separator;
  842. print "Credit".$separator;
  843. print "EcritureLet".$separator;
  844. print "DateLet".$separator;
  845. print "ValidDate".$separator;
  846. print "Montantdevise".$separator;
  847. print "Idevise".$separator;
  848. print "DateLimitReglmt".$separator;
  849. print "NumFacture";
  850. print $end_line;
  851. foreach ($objectLines as $line) {
  852. if ($line->debit == 0 && $line->credit == 0) {
  853. //unset($array[$line]);
  854. } else {
  855. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  856. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  857. $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
  858. $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
  859. $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  860. $refInvoice = '';
  861. if ($line->doc_type == 'customer_invoice') {
  862. // Customer invoice
  863. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  864. $invoice = new Facture($this->db);
  865. $invoice->fetch($line->fk_doc);
  866. $refInvoice = $invoice->ref;
  867. } elseif ($line->doc_type == 'supplier_invoice') {
  868. // Supplier invoice
  869. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  870. $invoice = new FactureFournisseur($this->db);
  871. $invoice->fetch($line->fk_doc);
  872. $refInvoice = $invoice->ref_supplier;
  873. }
  874. // FEC:JournalCode
  875. print $line->code_journal . $separator;
  876. // FEC:JournalLib
  877. print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
  878. // FEC:EcritureNum
  879. print $line->piece_num . $separator;
  880. // FEC:EcritureDate
  881. print $date_document . $separator;
  882. // FEC:CompteNum
  883. print $line->numero_compte . $separator;
  884. // FEC:CompteLib
  885. print dol_string_unaccent($line->label_compte) . $separator;
  886. // FEC:CompAuxNum
  887. print $line->subledger_account . $separator;
  888. // FEC:CompAuxLib
  889. print dol_string_unaccent($line->subledger_label) . $separator;
  890. // FEC:PieceRef
  891. print $line->doc_ref . $separator;
  892. // FEC:PieceDate
  893. print dol_string_unaccent($date_creation) . $separator;
  894. // FEC:EcritureLib
  895. // Clean label operation to prevent problem on export with tab separator & other character
  896. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  897. print dol_string_unaccent($line->label_operation) . $separator;
  898. // FEC:Debit
  899. print price2fec($line->debit) . $separator;
  900. // FEC:Credit
  901. print price2fec($line->credit) . $separator;
  902. // FEC:EcritureLet
  903. print $line->lettering_code . $separator;
  904. // FEC:DateLet
  905. print $date_lettering . $separator;
  906. // FEC:ValidDate
  907. print $date_validation . $separator;
  908. // FEC:Montantdevise
  909. print $line->multicurrency_amount . $separator;
  910. // FEC:Idevise
  911. print $line->multicurrency_code . $separator;
  912. // FEC_suppl:DateLimitReglmt
  913. print $date_limit_payment . $separator;
  914. // FEC_suppl:NumFacture
  915. // Clean ref invoice to prevent problem on export with tab separator & other character
  916. $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
  917. print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
  918. print $end_line;
  919. }
  920. }
  921. }
  922. /**
  923. * Export format : FEC2
  924. *
  925. * @param array $objectLines data
  926. * @return void
  927. */
  928. public function exportFEC2($objectLines)
  929. {
  930. global $langs;
  931. $separator = "\t";
  932. $end_line = "\r\n";
  933. print "JournalCode".$separator;
  934. print "JournalLib".$separator;
  935. print "EcritureNum".$separator;
  936. print "EcritureDate".$separator;
  937. print "CompteNum".$separator;
  938. print "CompteLib".$separator;
  939. print "CompAuxNum".$separator;
  940. print "CompAuxLib".$separator;
  941. print "PieceRef".$separator;
  942. print "PieceDate".$separator;
  943. print "EcritureLib".$separator;
  944. print "Debit".$separator;
  945. print "Credit".$separator;
  946. print "EcritureLet".$separator;
  947. print "DateLet".$separator;
  948. print "ValidDate".$separator;
  949. print "Montantdevise".$separator;
  950. print "Idevise".$separator;
  951. print "DateLimitReglmt".$separator;
  952. print "NumFacture";
  953. print $end_line;
  954. foreach ($objectLines as $line) {
  955. if ($line->debit == 0 && $line->credit == 0) {
  956. //unset($array[$line]);
  957. } else {
  958. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  959. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  960. $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
  961. $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
  962. $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  963. $refInvoice = '';
  964. if ($line->doc_type == 'customer_invoice') {
  965. // Customer invoice
  966. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  967. $invoice = new Facture($this->db);
  968. $invoice->fetch($line->fk_doc);
  969. $refInvoice = $invoice->ref;
  970. } elseif ($line->doc_type == 'supplier_invoice') {
  971. // Supplier invoice
  972. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  973. $invoice = new FactureFournisseur($this->db);
  974. $invoice->fetch($line->fk_doc);
  975. $refInvoice = $invoice->ref_supplier;
  976. }
  977. // FEC:JournalCode
  978. print $line->code_journal . $separator;
  979. // FEC:JournalLib
  980. print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
  981. // FEC:EcritureNum
  982. print $line->piece_num . $separator;
  983. // FEC:EcritureDate
  984. print $date_creation . $separator;
  985. // FEC:CompteNum
  986. print length_accountg($line->numero_compte) . $separator;
  987. // FEC:CompteLib
  988. print dol_string_unaccent($line->label_compte) . $separator;
  989. // FEC:CompAuxNum
  990. print length_accounta($line->subledger_account) . $separator;
  991. // FEC:CompAuxLib
  992. print dol_string_unaccent($line->subledger_label) . $separator;
  993. // FEC:PieceRef
  994. print $line->doc_ref . $separator;
  995. // FEC:PieceDate
  996. print $date_document . $separator;
  997. // FEC:EcritureLib
  998. // Clean label operation to prevent problem on export with tab separator & other character
  999. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  1000. print dol_string_unaccent($line->label_operation) . $separator;
  1001. // FEC:Debit
  1002. print price2fec($line->debit) . $separator;
  1003. // FEC:Credit
  1004. print price2fec($line->credit) . $separator;
  1005. // FEC:EcritureLet
  1006. print $line->lettering_code . $separator;
  1007. // FEC:DateLet
  1008. print $date_lettering . $separator;
  1009. // FEC:ValidDate
  1010. print $date_validation . $separator;
  1011. // FEC:Montantdevise
  1012. print $line->multicurrency_amount . $separator;
  1013. // FEC:Idevise
  1014. print $line->multicurrency_code . $separator;
  1015. // FEC_suppl:DateLimitReglmt
  1016. print $date_limit_payment . $separator;
  1017. // FEC_suppl:NumFacture
  1018. // Clean ref invoice to prevent problem on export with tab separator & other character
  1019. $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
  1020. print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
  1021. print $end_line;
  1022. }
  1023. }
  1024. }
  1025. /**
  1026. * Export format : SAGE50SWISS
  1027. *
  1028. * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984
  1029. * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf
  1030. *
  1031. * @param array $objectLines data
  1032. *
  1033. * @return void
  1034. */
  1035. public function exportSAGE50SWISS($objectLines)
  1036. {
  1037. // SAGE50SWISS
  1038. $this->separator = ',';
  1039. $this->end_line = "\r\n";
  1040. // Print header line
  1041. print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
  1042. print $this->end_line;
  1043. $thisPieceNum = "";
  1044. $thisPieceAccountNr = "";
  1045. $aSize = count($objectLines);
  1046. foreach ($objectLines as $aIndex => $line) {
  1047. $sammelBuchung = false;
  1048. if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
  1049. $sammelBuchung = true;
  1050. } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
  1051. $sammelBuchung = true;
  1052. } elseif ($aIndex + 1 < $aSize
  1053. && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
  1054. && $aIndex - 1 < $aSize
  1055. && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
  1056. ) {
  1057. $sammelBuchung = true;
  1058. }
  1059. //Blg
  1060. print $line->piece_num.$this->separator;
  1061. // Datum
  1062. $date = dol_print_date($line->doc_date, '%d.%m.%Y');
  1063. print $date.$this->separator;
  1064. // Kto
  1065. print length_accountg($line->numero_compte).$this->separator;
  1066. // S/H
  1067. if ($line->sens == 'D') {
  1068. print 'S'.$this->separator;
  1069. } else {
  1070. print 'H'.$this->separator;
  1071. }
  1072. //Grp
  1073. print self::trunc($line->code_journal, 1).$this->separator;
  1074. // GKto
  1075. if (empty($line->code_tiers)) {
  1076. if ($line->piece_num == $thisPieceNum) {
  1077. print length_accounta($thisPieceAccountNr).$this->separator;
  1078. } else {
  1079. print "div".$this->separator;
  1080. }
  1081. } else {
  1082. print length_accounta($line->code_tiers).$this->separator;
  1083. }
  1084. //SId
  1085. print $this->separator;
  1086. //SIdx
  1087. print "0".$this->separator;
  1088. //KIdx
  1089. print "0".$this->separator;
  1090. //BTyp
  1091. print "0".$this->separator;
  1092. //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
  1093. if ($sammelBuchung) {
  1094. print "2".$this->separator;
  1095. } else {
  1096. print "1".$this->separator;
  1097. }
  1098. // Code
  1099. print '""'.$this->separator;
  1100. // Netto
  1101. print abs($line->debit - $line->credit).$this->separator;
  1102. // Steuer
  1103. print "0.00".$this->separator;
  1104. // FW-Betrag
  1105. print "0.00".$this->separator;
  1106. // Tx1
  1107. $line1 = self::toAnsi($line->label_compte, 29);
  1108. if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
  1109. $line1 = "";
  1110. }
  1111. $line2 = self::toAnsi($line->doc_ref, 29);
  1112. if (strlen($line1) == 0) {
  1113. $line1 = $line2;
  1114. $line2 = "";
  1115. }
  1116. if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
  1117. $line1 = $line1.' / '.$line2;
  1118. $line2 = "";
  1119. }
  1120. print '"'.self::toAnsi($line1).'"'.$this->separator;
  1121. // Tx2
  1122. print '"'.self::toAnsi($line2).'"'.$this->separator;
  1123. //PkKey
  1124. print "0".$this->separator;
  1125. //OpId
  1126. print $this->separator;
  1127. // Flag
  1128. print "0";
  1129. print $this->end_line;
  1130. if ($line->piece_num !== $thisPieceNum) {
  1131. $thisPieceNum = $line->piece_num;
  1132. $thisPieceAccountNr = $line->numero_compte;
  1133. }
  1134. }
  1135. }
  1136. /**
  1137. * Export format : LD Compta version 9
  1138. * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf
  1139. *
  1140. * @param array $objectLines data
  1141. *
  1142. * @return void
  1143. */
  1144. public function exportLDCompta($objectLines)
  1145. {
  1146. $separator = ';';
  1147. $end_line = "\r\n";
  1148. foreach ($objectLines as $line) {
  1149. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  1150. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  1151. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  1152. // TYPE
  1153. $type_enregistrement = 'E'; // For write movement
  1154. print $type_enregistrement.$separator;
  1155. // JNAL
  1156. print substr($line->code_journal, 0, 2).$separator;
  1157. // NECR
  1158. print $line->id.$separator;
  1159. // NPIE
  1160. print $line->piece_num.$separator;
  1161. // DATP
  1162. print $date_document.$separator;
  1163. // LIBE
  1164. print $line->label_operation.$separator;
  1165. // DATH
  1166. print $date_lim_reglement.$separator;
  1167. // CNPI
  1168. if ($line->doc_type == 'supplier_invoice') {
  1169. if (($line->debit - $line->credit) > 0) {
  1170. $nature_piece = 'AF';
  1171. } else {
  1172. $nature_piece = 'FF';
  1173. }
  1174. } elseif ($line->doc_type == 'customer_invoice') {
  1175. if (($line->debit - $line->credit) < 0) {
  1176. $nature_piece = 'AC';
  1177. } else {
  1178. $nature_piece = 'FC';
  1179. }
  1180. } else {
  1181. $nature_piece = '';
  1182. }
  1183. print $nature_piece.$separator;
  1184. // RACI
  1185. // if (! empty($line->subledger_account)) {
  1186. // if ($line->doc_type == 'supplier_invoice') {
  1187. // $racine_subledger_account = '40';
  1188. // } elseif ($line->doc_type == 'customer_invoice') {
  1189. // $racine_subledger_account = '41';
  1190. // } else {
  1191. // $racine_subledger_account = '';
  1192. // }
  1193. // } else {
  1194. $racine_subledger_account = ''; // for records of type E leave this field blank
  1195. // }
  1196. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  1197. // MONT
  1198. print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
  1199. // CODC
  1200. print $line->sens.$separator;
  1201. // CPTG
  1202. print length_accountg($line->numero_compte).$separator;
  1203. // DATE
  1204. print $date_creation.$separator;
  1205. // CLET
  1206. print $line->lettering_code.$separator;
  1207. // DATL
  1208. print $line->date_lettering.$separator;
  1209. // CPTA
  1210. if (!empty($line->subledger_account)) {
  1211. print length_accounta($line->subledger_account).$separator;
  1212. } else {
  1213. print $separator;
  1214. }
  1215. // CNAT
  1216. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  1217. print 'F'.$separator;
  1218. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  1219. print 'C'.$separator;
  1220. } else {
  1221. print $separator;
  1222. }
  1223. // SECT
  1224. print $separator;
  1225. // CTRE
  1226. print $separator;
  1227. // NORL
  1228. print $separator;
  1229. // DATV
  1230. print $separator;
  1231. // REFD
  1232. print $line->doc_ref.$separator;
  1233. // CODH
  1234. print $separator;
  1235. // NSEQ
  1236. print $separator;
  1237. // MTDV
  1238. print '0'.$separator;
  1239. // CODV
  1240. print $separator;
  1241. // TXDV
  1242. print '0'.$separator;
  1243. // MOPM
  1244. print $separator;
  1245. // BONP
  1246. print $separator;
  1247. // BQAF
  1248. print $separator;
  1249. // ECES
  1250. print $separator;
  1251. // TXTL
  1252. print $separator;
  1253. // ECRM
  1254. print $separator;
  1255. // DATK
  1256. print $separator;
  1257. // HEUK
  1258. print $separator;
  1259. print $end_line;
  1260. }
  1261. }
  1262. /**
  1263. * Export format : LD Compta version 10 & higher
  1264. * Last review for this format : 08-15-2021 Alexandre Spangaro (aspangaro@open-dsi.fr)
  1265. *
  1266. * Help : http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf
  1267. *
  1268. * @param array $objectLines data
  1269. *
  1270. * @return void
  1271. */
  1272. public function exportLDCompta10($objectLines)
  1273. {
  1274. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  1275. $separator = ';';
  1276. $end_line = "\r\n";
  1277. $last_codeinvoice = '';
  1278. foreach ($objectLines as $line) {
  1279. // TYPE C
  1280. if ($last_codeinvoice != $line->doc_ref) {
  1281. //recherche societe en fonction de son code client
  1282. $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
  1283. $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
  1284. $resql = $this->db->query($sql);
  1285. if ($resql && $this->db->num_rows($resql) > 0) {
  1286. $soc = $this->db->fetch_object($resql);
  1287. $address = array('', '', '');
  1288. if (strpos($soc->address, "\n") !== false) {
  1289. $address = explode("\n", $soc->address);
  1290. if (is_array($address) && count($address) > 0) {
  1291. foreach ($address as $key => $data) {
  1292. $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
  1293. $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
  1294. }
  1295. }
  1296. } else {
  1297. $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
  1298. $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
  1299. $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
  1300. }
  1301. $type_enregistrement = 'C';
  1302. //TYPE
  1303. print $type_enregistrement.$separator;
  1304. //NOCL
  1305. print $soc->code_client.$separator;
  1306. //NMCM
  1307. print $separator;
  1308. //LIBI
  1309. print $separator;
  1310. //TITR
  1311. print $separator;
  1312. //RSSO
  1313. print $soc->nom.$separator;
  1314. //CAD1
  1315. print $address[0].$separator;
  1316. //CAD2
  1317. print $address[1].$separator;
  1318. //CAD3
  1319. print $address[2].$separator;
  1320. //COPO
  1321. print $soc->zip.$separator;
  1322. //BUDI
  1323. print substr($soc->town, 0, 40).$separator;
  1324. //CPAY
  1325. print $separator;
  1326. //PAYS
  1327. print substr(getCountry($soc->fk_pays), 0, 40).$separator;
  1328. //NTEL
  1329. print $soc->phone.$separator;
  1330. //TLEX
  1331. print $separator;
  1332. //TLPO
  1333. print $separator;
  1334. //TLCY
  1335. print $separator;
  1336. //NINT
  1337. print $separator;
  1338. //COMM
  1339. print $separator;
  1340. //SIRE
  1341. print str_replace(" ", "", $soc->siret).$separator;
  1342. //RIBP
  1343. print $separator;
  1344. //DOBQ
  1345. print $separator;
  1346. //IBBQ
  1347. print $separator;
  1348. //COBQ
  1349. print $separator;
  1350. //GUBQ
  1351. print $separator;
  1352. //CPBQ
  1353. print $separator;
  1354. //CLBQ
  1355. print $separator;
  1356. //BIBQ
  1357. print $separator;
  1358. //MOPM
  1359. print $separator;
  1360. //DJPM
  1361. print $separator;
  1362. //DMPM
  1363. print $separator;
  1364. //REFM
  1365. print $separator;
  1366. //SLVA
  1367. print $separator;
  1368. //PLCR
  1369. print $separator;
  1370. //ECFI
  1371. print $separator;
  1372. //CREP
  1373. print $separator;
  1374. //NREP
  1375. print $separator;
  1376. //TREP
  1377. print $separator;
  1378. //MREP
  1379. print $separator;
  1380. //GRRE
  1381. print $separator;
  1382. //LTTA
  1383. print $separator;
  1384. //CACT
  1385. print $separator;
  1386. //CODV
  1387. print $separator;
  1388. //GRTR
  1389. print $separator;
  1390. //NOFP
  1391. print $separator;
  1392. //BQAF
  1393. print $separator;
  1394. //BONP
  1395. print $separator;
  1396. //CESC
  1397. print $separator;
  1398. print $end_line;
  1399. }
  1400. }
  1401. $date_document = dol_print_date($line->doc_date, '%Y%m%d');
  1402. $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
  1403. $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
  1404. // TYPE E
  1405. $type_enregistrement = 'E'; // For write movement
  1406. print $type_enregistrement.$separator;
  1407. // JNAL
  1408. print substr($line->code_journal, 0, 2).$separator;
  1409. // NECR
  1410. print $line->id.$separator;
  1411. // NPIE
  1412. print $line->piece_num.$separator;
  1413. // DATP
  1414. print $date_document.$separator;
  1415. // LIBE
  1416. print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
  1417. // DATH
  1418. print $date_lim_reglement.$separator;
  1419. // CNPI
  1420. if ($line->doc_type == 'supplier_invoice') {
  1421. 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.
  1422. $nature_piece = 'AF';
  1423. } else {
  1424. $nature_piece = 'FF';
  1425. }
  1426. } elseif ($line->doc_type == 'customer_invoice') {
  1427. if (($line->amount) < 0) {
  1428. $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.
  1429. } else {
  1430. $nature_piece = 'FC';
  1431. }
  1432. } else {
  1433. $nature_piece = '';
  1434. }
  1435. print $nature_piece.$separator;
  1436. // RACI
  1437. // if (! empty($line->subledger_account)) {
  1438. // if ($line->doc_type == 'supplier_invoice') {
  1439. // $racine_subledger_account = '40';
  1440. // } elseif ($line->doc_type == 'customer_invoice') {
  1441. // $racine_subledger_account = '41';
  1442. // } else {
  1443. // $racine_subledger_account = '';
  1444. // }
  1445. // } else {
  1446. $racine_subledger_account = ''; // for records of type E leave this field blank
  1447. // }
  1448. print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
  1449. // MONT
  1450. print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
  1451. // CODC
  1452. print $line->sens.$separator;
  1453. // CPTG
  1454. print length_accountg($line->numero_compte).$separator;
  1455. // DATE
  1456. print $date_document.$separator;
  1457. // CLET
  1458. print $line->lettering_code.$separator;
  1459. // DATL
  1460. print $line->date_lettering.$separator;
  1461. // CPTA
  1462. if (!empty($line->subledger_account)) {
  1463. print length_accounta($line->subledger_account).$separator;
  1464. } else {
  1465. print $separator;
  1466. }
  1467. // CNAT
  1468. if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
  1469. print 'F'.$separator;
  1470. } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
  1471. print 'C'.$separator;
  1472. } else {
  1473. print $separator;
  1474. }
  1475. // CTRE
  1476. print $separator;
  1477. // NORL
  1478. print $separator;
  1479. // DATV
  1480. print $separator;
  1481. // REFD
  1482. print $line->doc_ref.$separator;
  1483. // NECA
  1484. print '0'.$separator;
  1485. // CSEC
  1486. print $separator;
  1487. // CAFF
  1488. print $separator;
  1489. // CDES
  1490. print $separator;
  1491. // QTUE
  1492. print $separator;
  1493. // MTDV
  1494. print '0'.$separator;
  1495. // CODV
  1496. print $separator;
  1497. // TXDV
  1498. print '0'.$separator;
  1499. // MOPM
  1500. print $separator;
  1501. // BONP
  1502. print $separator;
  1503. // BQAF
  1504. print $separator;
  1505. // ECES
  1506. print $separator;
  1507. // TXTL
  1508. print $separator;
  1509. // ECRM
  1510. print $separator;
  1511. // DATK
  1512. print $separator;
  1513. // HEUK
  1514. print $separator;
  1515. print $end_line;
  1516. $last_codeinvoice = $line->doc_ref;
  1517. }
  1518. }
  1519. /**
  1520. * Export format : Charlemagne
  1521. *
  1522. * @param array $objectLines data
  1523. * @return void
  1524. */
  1525. public function exportCharlemagne($objectLines)
  1526. {
  1527. global $langs;
  1528. $langs->load('compta');
  1529. $separator = "\t";
  1530. $end_line = "\n";
  1531. /*
  1532. * Charlemagne export need header
  1533. */
  1534. print $langs->transnoentitiesnoconv('Date').$separator;
  1535. print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
  1536. print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
  1537. print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
  1538. print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
  1539. print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
  1540. print $langs->transnoentitiesnoconv('Amount').$separator;
  1541. print 'S'.$separator;
  1542. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
  1543. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
  1544. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
  1545. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
  1546. print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
  1547. print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
  1548. print $end_line;
  1549. foreach ($objectLines as $line) {
  1550. $date = dol_print_date($line->doc_date, '%Y%m%d');
  1551. print $date.$separator; //Date
  1552. print self::trunc($line->code_journal, 6).$separator; //Journal code
  1553. if (!empty($line->subledger_account)) {
  1554. $account = $line->subledger_account;
  1555. } else {
  1556. $account = $line->numero_compte;
  1557. }
  1558. print self::trunc($account, 15).$separator; //Account number
  1559. print self::trunc($line->label_compte, 60).$separator; //Account label
  1560. print self::trunc($line->doc_ref, 20).$separator; //Piece
  1561. // Clean label operation to prevent problem on export with tab separator & other character
  1562. $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
  1563. print self::trunc($line->label_operation, 60).$separator; //Operation label
  1564. print price(abs($line->debit - $line->credit)).$separator; //Amount
  1565. print $line->sens.$separator; //Direction
  1566. print $separator; //Analytic
  1567. print $separator; //Analytic
  1568. print $separator; //Analytic
  1569. print $separator; //Analytic
  1570. print $separator; //Analytic
  1571. print $separator; //Analytic
  1572. print $end_line;
  1573. }
  1574. }
  1575. /**
  1576. * Export format : Gestimum V3
  1577. *
  1578. * @param array $objectLines data
  1579. *
  1580. * @return void
  1581. */
  1582. public function exportGestimumV3($objectLines)
  1583. {
  1584. global $langs;
  1585. $this->separator = ',';
  1586. $invoices_infos = array();
  1587. $supplier_invoices_infos = array();
  1588. foreach ($objectLines as $line) {
  1589. if ($line->debit == 0 && $line->credit == 0) {
  1590. //unset($array[$line]);
  1591. } else {
  1592. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  1593. $invoice_ref = $line->doc_ref;
  1594. $company_name = "";
  1595. if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
  1596. if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
  1597. ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
  1598. if ($line->doc_type == 'customer_invoice') {
  1599. // Get new customer invoice ref and company name
  1600. $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
  1601. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
  1602. $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
  1603. $resql = $this->db->query($sql);
  1604. if ($resql) {
  1605. if ($obj = $this->db->fetch_object($resql)) {
  1606. // Save invoice infos
  1607. $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
  1608. $invoice_ref = $obj->ref;
  1609. $company_name = $obj->nom;
  1610. }
  1611. }
  1612. } else {
  1613. // Get new supplier invoice ref and company name
  1614. $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
  1615. $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
  1616. $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
  1617. $resql = $this->db->query($sql);
  1618. if ($resql) {
  1619. if ($obj = $this->db->fetch_object($resql)) {
  1620. // Save invoice infos
  1621. $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
  1622. $invoice_ref = $obj->ref;
  1623. $company_name = $obj->nom;
  1624. }
  1625. }
  1626. }
  1627. } elseif ($line->doc_type == 'customer_invoice') {
  1628. // Retrieve invoice infos
  1629. $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
  1630. $company_name = $invoices_infos[$line->fk_doc]['company_name'];
  1631. } else {
  1632. // Retrieve invoice infos
  1633. $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
  1634. $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
  1635. }
  1636. }
  1637. print $line->id . $this->separator;
  1638. print $date . $this->separator;
  1639. print substr($line->code_journal, 0, 4) . $this->separator;
  1640. if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
  1641. print length_accountg($line->subledger_account) . $this->separator;
  1642. } else {
  1643. print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
  1644. }
  1645. //Libellé Auto
  1646. print $this->separator;
  1647. //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
  1648. //Libellé manuel
  1649. print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
  1650. //Numéro de pièce
  1651. print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
  1652. //Devise
  1653. print 'EUR' . $this->separator;
  1654. //Amount
  1655. print price2num(abs($line->debit - $line->credit)) . $this->separator;
  1656. //Sens
  1657. print $line->sens . $this->separator;
  1658. //Code lettrage
  1659. print $this->separator;
  1660. //Date Echéance
  1661. print $date;
  1662. print $this->end_line;
  1663. }
  1664. }
  1665. }
  1666. /**
  1667. * Export format : Gestimum V5
  1668. *
  1669. * @param array $objectLines data
  1670. *
  1671. * @return void
  1672. */
  1673. public function exportGestimumV5($objectLines)
  1674. {
  1675. $this->separator = ',';
  1676. foreach ($objectLines as $line) {
  1677. if ($line->debit == 0 && $line->credit == 0) {
  1678. //unset($array[$line]);
  1679. } else {
  1680. $date = dol_print_date($line->doc_date, '%d%m%Y');
  1681. print $line->id . $this->separator;
  1682. print $date . $this->separator;
  1683. print substr($line->code_journal, 0, 4) . $this->separator;
  1684. if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
  1685. print length_accountg($line->subledger_account) . $this->separator;
  1686. } else {
  1687. print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
  1688. }
  1689. print $this->separator;
  1690. //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
  1691. print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
  1692. print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
  1693. print price2num(abs($line->debit - $line->credit)) . $this->separator;
  1694. print $line->sens . $this->separator;
  1695. print $date . $this->separator;
  1696. print $this->separator;
  1697. print $this->separator;
  1698. print 'EUR';
  1699. print $this->end_line;
  1700. }
  1701. }
  1702. }
  1703. /**
  1704. * Export format : iSuite Expert
  1705. *
  1706. * by OpenSolus [https://opensolus.fr]
  1707. *
  1708. * @param array $objectLines data
  1709. *
  1710. * @return void
  1711. */
  1712. public function exportiSuiteExpert($objectLines)
  1713. {
  1714. $this->separator = ';';
  1715. $this->end_line = "\r\n";
  1716. foreach ($objectLines as $line) {
  1717. $tab = array();
  1718. $date = dol_print_date($line->doc_date, '%d/%m/%Y');
  1719. $tab[] = $line->piece_num;
  1720. $tab[] = $date;
  1721. $tab[] = substr($date, 6, 4);
  1722. $tab[] = substr($date, 3, 2);
  1723. $tab[] = substr($date, 0, 2);
  1724. $tab[] = $line->doc_ref;
  1725. //Conversion de chaine UTF8 en Latin9
  1726. $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
  1727. //Calcul de la longueur des numéros de comptes
  1728. $taille_numero = strlen(length_accountg($line->numero_compte));
  1729. //Création du numéro de client générique
  1730. $numero_cpt_client = '411';
  1731. for ($i = 1; $i <= ($taille_numero - 3); $i++) {
  1732. $numero_cpt_client .= '0';
  1733. }
  1734. //Création des comptes auxiliaire des clients
  1735. if (length_accountg($line->numero_compte) == $numero_cpt_client) {
  1736. $tab[] = rtrim(length_accounta($line->subledger_account), "0");
  1737. } else {
  1738. $tab[] = length_accountg($line->numero_compte);
  1739. }
  1740. $nom_client = explode(" - ", $line->label_operation);
  1741. $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
  1742. $tab[] = price($line->debit);
  1743. $tab[] = price($line->credit);
  1744. $tab[] = price($line->montant);
  1745. $tab[] = $line->code_journal;
  1746. $separator = $this->separator;
  1747. print implode($separator, $tab) . $this->end_line;
  1748. }
  1749. }
  1750. /**
  1751. * trunc
  1752. *
  1753. * @param string $str String
  1754. * @param integer $size Data to trunc
  1755. * @return string
  1756. */
  1757. public static function trunc($str, $size)
  1758. {
  1759. return dol_trunc($str, $size, 'right', 'UTF-8', 1);
  1760. }
  1761. /**
  1762. * toAnsi
  1763. *
  1764. * @param string $str Original string to encode and optionaly truncate
  1765. * @param integer $size Truncate string after $size characters
  1766. * @return string String encoded in Windows-1251 charset
  1767. */
  1768. public static function toAnsi($str, $size = -1)
  1769. {
  1770. $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
  1771. if ($retVal >= 0 && $size >= 0) {
  1772. $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
  1773. }
  1774. return $retVal;
  1775. }
  1776. }