123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184 |
- <?php
- /*
- * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
- * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
- * Copyright (C) 2016 Pierre-Henry Favre <phf@atm-consulting.fr>
- * Copyright (C) 2016-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
- * Copyright (C) 2022 Lionel Vessiller <lvessiller@open-dsi.fr>
- * Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
- * Copyright (C) 2017 Elarifr. Ari Elbaz <github@accedinfo.com>
- * Copyright (C) 2017-2019 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2017 André Schild <a.schild@aarboard.ch>
- * Copyright (C) 2020 Guillaume Alexandre <guillaume@tag-info.fr>
- * Copyright (C) 2022 Joachim Kueter <jkueter@gmx.de>
- * Copyright (C) 2022 Progiseize <a.bisotti@progiseize.fr>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/accountancy/class/accountancyexport.class.php
- * \ingroup Accountancy (Double entries)
- * \brief Class accountancy export
- */
- require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- /**
- * Manage the different format accountancy export
- */
- class AccountancyExport
- {
- // Type of export. Used into $conf->global->ACCOUNTING_EXPORT_MODELCSV
- public static $EXPORT_TYPE_CONFIGURABLE = 1; // CSV
- public static $EXPORT_TYPE_AGIRIS = 10;
- public static $EXPORT_TYPE_EBP = 15;
- public static $EXPORT_TYPE_CEGID = 20;
- public static $EXPORT_TYPE_COGILOG = 25;
- public static $EXPORT_TYPE_COALA = 30;
- public static $EXPORT_TYPE_BOB50 = 35;
- public static $EXPORT_TYPE_CIEL = 40;
- public static $EXPORT_TYPE_SAGE50_SWISS = 45;
- public static $EXPORT_TYPE_CHARLEMAGNE = 50;
- public static $EXPORT_TYPE_QUADRATUS = 60;
- public static $EXPORT_TYPE_WINFIC = 70;
- public static $EXPORT_TYPE_OPENCONCERTO = 100;
- public static $EXPORT_TYPE_LDCOMPTA = 110;
- public static $EXPORT_TYPE_LDCOMPTA10 = 120;
- public static $EXPORT_TYPE_GESTIMUMV3 = 130;
- public static $EXPORT_TYPE_GESTIMUMV5 = 135;
- public static $EXPORT_TYPE_ISUITEEXPERT = 200;
- // Generic FEC after that
- public static $EXPORT_TYPE_FEC = 1000;
- public static $EXPORT_TYPE_FEC2 = 1010;
- /**
- * @var DoliDB Database handler
- */
- public $db;
- /**
- * @var string[] Error codes (or messages)
- */
- public $errors = array();
- /**
- *
- * @var string Separator
- */
- public $separator = '';
- /**
- *
- * @var string End of line
- */
- public $end_line = '';
- /**
- * Constructor
- *
- * @param DoliDb $db Database handler
- */
- public function __construct(DoliDB $db)
- {
- global $conf, $hookmanager;
- $this->db = $db;
- $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
- $this->end_line = empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? "\n" : ($conf->global->ACCOUNTING_EXPORT_ENDLINE == 1 ? "\n" : "\r\n");
- $hookmanager->initHooks(array('accountancyexport'));
- }
- /**
- * Array with all export type available (key + label)
- *
- * @return array of type
- */
- public function getType()
- {
- global $langs, $hookmanager;
- $listofexporttypes = array(
- self::$EXPORT_TYPE_CONFIGURABLE => $langs->trans('Modelcsv_configurable'),
- self::$EXPORT_TYPE_CEGID => $langs->trans('Modelcsv_CEGID'),
- self::$EXPORT_TYPE_COALA => $langs->trans('Modelcsv_COALA'),
- self::$EXPORT_TYPE_BOB50 => $langs->trans('Modelcsv_bob50'),
- self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'),
- self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'),
- self::$EXPORT_TYPE_WINFIC => $langs->trans('Modelcsv_winfic'),
- self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'),
- self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'),
- self::$EXPORT_TYPE_AGIRIS => $langs->trans('Modelcsv_agiris'),
- self::$EXPORT_TYPE_OPENCONCERTO => $langs->trans('Modelcsv_openconcerto'),
- self::$EXPORT_TYPE_SAGE50_SWISS => $langs->trans('Modelcsv_Sage50_Swiss'),
- self::$EXPORT_TYPE_CHARLEMAGNE => $langs->trans('Modelcsv_charlemagne'),
- self::$EXPORT_TYPE_LDCOMPTA => $langs->trans('Modelcsv_LDCompta'),
- self::$EXPORT_TYPE_LDCOMPTA10 => $langs->trans('Modelcsv_LDCompta10'),
- self::$EXPORT_TYPE_GESTIMUMV3 => $langs->trans('Modelcsv_Gestinumv3'),
- self::$EXPORT_TYPE_GESTIMUMV5 => $langs->trans('Modelcsv_Gestinumv5'),
- self::$EXPORT_TYPE_FEC => $langs->trans('Modelcsv_FEC'),
- self::$EXPORT_TYPE_FEC2 => $langs->trans('Modelcsv_FEC2'),
- self::$EXPORT_TYPE_ISUITEEXPERT => 'Export iSuite Expert',
- );
- // allow modules to define export formats
- $parameters = array();
- $reshook = $hookmanager->executeHooks('getType', $parameters, $listofexporttypes);
- ksort($listofexporttypes, SORT_NUMERIC);
- return $listofexporttypes;
- }
- /**
- * Return string to summarize the format (Used to generated export filename)
- *
- * @param int $type Format id
- * @return string Format code
- */
- public static function getFormatCode($type)
- {
- $formatcode = array(
- self::$EXPORT_TYPE_CONFIGURABLE => 'csv',
- self::$EXPORT_TYPE_CEGID => 'cegid',
- self::$EXPORT_TYPE_COALA => 'coala',
- self::$EXPORT_TYPE_BOB50 => 'bob50',
- self::$EXPORT_TYPE_CIEL => 'ciel',
- self::$EXPORT_TYPE_QUADRATUS => 'quadratus',
- self::$EXPORT_TYPE_WINFIC => 'winfic',
- self::$EXPORT_TYPE_EBP => 'ebp',
- self::$EXPORT_TYPE_COGILOG => 'cogilog',
- self::$EXPORT_TYPE_AGIRIS => 'agiris',
- self::$EXPORT_TYPE_OPENCONCERTO => 'openconcerto',
- self::$EXPORT_TYPE_SAGE50_SWISS => 'sage50ch',
- self::$EXPORT_TYPE_CHARLEMAGNE => 'charlemagne',
- self::$EXPORT_TYPE_LDCOMPTA => 'ldcompta',
- self::$EXPORT_TYPE_LDCOMPTA10 => 'ldcompta10',
- self::$EXPORT_TYPE_GESTIMUMV3 => 'gestimumv3',
- self::$EXPORT_TYPE_GESTIMUMV5 => 'gestimumv5',
- self::$EXPORT_TYPE_FEC => 'fec',
- self::$EXPORT_TYPE_FEC2 => 'fec2',
- self::$EXPORT_TYPE_ISUITEEXPERT => 'isuiteexpert',
- );
- global $hookmanager;
- $code = $formatcode[$type];
- $parameters = array('type' => $type);
- $reshook = $hookmanager->executeHooks('getFormatCode', $parameters, $code);
- return $code;
- }
- /**
- * Array with all export type available (key + label) and parameters for config
- *
- * @return array of type
- */
- public function getTypeConfig()
- {
- global $conf, $langs;
- $exporttypes = array(
- 'param' => array(
- self::$EXPORT_TYPE_CONFIGURABLE => array(
- 'label' => $langs->trans('Modelcsv_configurable'),
- 'ACCOUNTING_EXPORT_FORMAT' => empty($conf->global->ACCOUNTING_EXPORT_FORMAT) ? 'txt' : $conf->global->ACCOUNTING_EXPORT_FORMAT,
- 'ACCOUNTING_EXPORT_SEPARATORCSV' => empty($conf->global->ACCOUNTING_EXPORT_SEPARATORCSV) ? ',' : $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV,
- 'ACCOUNTING_EXPORT_ENDLINE' => empty($conf->global->ACCOUNTING_EXPORT_ENDLINE) ? 1 : $conf->global->ACCOUNTING_EXPORT_ENDLINE,
- 'ACCOUNTING_EXPORT_DATE' => getDolGlobalString('ACCOUNTING_EXPORT_DATE', '%Y-%m-%d'),
- ),
- self::$EXPORT_TYPE_CEGID => array(
- 'label' => $langs->trans('Modelcsv_CEGID'),
- ),
- self::$EXPORT_TYPE_COALA => array(
- 'label' => $langs->trans('Modelcsv_COALA'),
- ),
- self::$EXPORT_TYPE_BOB50 => array(
- 'label' => $langs->trans('Modelcsv_bob50'),
- ),
- self::$EXPORT_TYPE_CIEL => array(
- 'label' => $langs->trans('Modelcsv_ciel'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_QUADRATUS => array(
- 'label' => $langs->trans('Modelcsv_quadratus'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_WINFIC => array(
- 'label' => $langs->trans('Modelcsv_winfic'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_EBP => array(
- 'label' => $langs->trans('Modelcsv_ebp'),
- ),
- self::$EXPORT_TYPE_COGILOG => array(
- 'label' => $langs->trans('Modelcsv_cogilog'),
- ),
- self::$EXPORT_TYPE_AGIRIS => array(
- 'label' => $langs->trans('Modelcsv_agiris'),
- ),
- self::$EXPORT_TYPE_OPENCONCERTO => array(
- 'label' => $langs->trans('Modelcsv_openconcerto'),
- ),
- self::$EXPORT_TYPE_SAGE50_SWISS => array(
- 'label' => $langs->trans('Modelcsv_Sage50_Swiss'),
- ),
- self::$EXPORT_TYPE_CHARLEMAGNE => array(
- 'label' => $langs->trans('Modelcsv_charlemagne'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_LDCOMPTA => array(
- 'label' => $langs->trans('Modelcsv_LDCompta'),
- ),
- self::$EXPORT_TYPE_LDCOMPTA10 => array(
- 'label' => $langs->trans('Modelcsv_LDCompta10'),
- ),
- self::$EXPORT_TYPE_GESTIMUMV3 => array(
- 'label' => $langs->trans('Modelcsv_Gestinumv3'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_GESTIMUMV5 => array(
- 'label' => $langs->trans('Modelcsv_Gestinumv5'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_FEC => array(
- 'label' => $langs->trans('Modelcsv_FEC'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_FEC2 => array(
- 'label' => $langs->trans('Modelcsv_FEC2'),
- 'ACCOUNTING_EXPORT_FORMAT' => 'txt',
- ),
- self::$EXPORT_TYPE_ISUITEEXPERT => array(
- 'label' => 'iSuite Expert',
- 'ACCOUNTING_EXPORT_FORMAT' => 'csv',
- ),
- ),
- 'cr'=> array(
- '1' => $langs->trans("Unix"),
- '2' => $langs->trans("Windows")
- ),
- 'format' => array(
- 'csv' => $langs->trans("csv"),
- 'txt' => $langs->trans("txt")
- ),
- );
- global $hookmanager;
- $parameters = array();
- $reshook = $hookmanager->executeHooks('getTypeConfig', $parameters, $exporttypes);
- return $exporttypes;
- }
- /**
- * Return the MIME type of a file
- *
- * @param int $formatexportset Id of export format
- * @return string MIME type.
- */
- public function getMimeType($formatexportset)
- {
- $mime = 'text/csv';
- switch ($formatexportset) {
- case self::$EXPORT_TYPE_FEC:
- $mime = 'text/tab-separated-values';
- break;
- default:
- $mime = 'text/csv';
- break;
- }
- return $mime;
- }
- /**
- * Function who chose which export to use with the default config, and make the export into a file
- *
- * @param array $TData Array with data
- * @param int $formatexportset Id of export format
- * @param int $withAttachment [=0] Not add files or 1 to have attached in an archive (ex : Quadratus)
- * @return int <0 if KO, >0 OK
- */
- public function export(&$TData, $formatexportset, $withAttachment = 0)
- {
- global $conf, $langs;
- global $search_date_end; // Used into /accountancy/tpl/export_journal.tpl.php
- // Define name of file to save
- $filename = 'general_ledger-'.$this->getFormatCode($formatexportset);
- $type_export = 'general_ledger';
- global $db; // The tpl file use $db
- $completefilename = '';
- $exportFile = null;
- $exportFileName = '';
- $exportFilePath = '';
- $archiveFileList = array();
- if ($withAttachment == 1) {
- // PHP ZIP extension must be enabled
- if (!extension_loaded('zip')) {
- $langs->load('install');
- $this->errors[] = $langs->trans('ErrorPHPDoesNotSupport', 'ZIP');
- return -1;
- }
- } else {
- $mimetype = $this->getMimeType($formatexportset);
- top_httphead($mimetype, 1);
- }
- include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php';
- if ($withAttachment == 1 && !empty($completefilename)) {
- // create export file
- $tmpDir = !empty($conf->accounting->multidir_temp[$conf->entity]) ? $conf->accounting->multidir_temp[$conf->entity] : $conf->accounting->dir_temp;
- $exportFileFullName = $completefilename;
- $exportFileBaseName = basename($exportFileFullName);
- $exportFileName = pathinfo($exportFileBaseName, PATHINFO_FILENAME);
- $exportFilePath = $tmpDir.'/'.$exportFileFullName;
- $exportFile = fopen($exportFilePath, 'w');
- if (!$exportFile) {
- $this->errors[] = $langs->trans('ErrorFileNotFound', $exportFilePath);
- return -1;
- }
- $archiveFileList[0] = array(
- 'path' => $exportFilePath,
- 'name' => $exportFileFullName,
- );
- // archive name and path
- $archiveFullName = $exportFileName.'.zip';
- $archivePath = $tmpDir.'/'.$archiveFullName;
- }
- switch ($formatexportset) {
- case self::$EXPORT_TYPE_CONFIGURABLE:
- $this->exportConfigurable($TData);
- break;
- case self::$EXPORT_TYPE_CEGID:
- $this->exportCegid($TData);
- break;
- case self::$EXPORT_TYPE_COALA:
- $this->exportCoala($TData);
- break;
- case self::$EXPORT_TYPE_BOB50:
- $this->exportBob50($TData);
- break;
- case self::$EXPORT_TYPE_CIEL:
- $this->exportCiel($TData);
- break;
- case self::$EXPORT_TYPE_QUADRATUS:
- $archiveFileList = $this->exportQuadratus($TData, $exportFile, $archiveFileList, $withAttachment);
- break;
- case self::$EXPORT_TYPE_WINFIC:
- $this->exportWinfic($TData);
- break;
- case self::$EXPORT_TYPE_EBP:
- $this->exportEbp($TData);
- break;
- case self::$EXPORT_TYPE_COGILOG:
- $this->exportCogilog($TData);
- break;
- case self::$EXPORT_TYPE_AGIRIS:
- $this->exportAgiris($TData);
- break;
- case self::$EXPORT_TYPE_OPENCONCERTO:
- $this->exportOpenConcerto($TData);
- break;
- case self::$EXPORT_TYPE_SAGE50_SWISS:
- $this->exportSAGE50SWISS($TData);
- break;
- case self::$EXPORT_TYPE_CHARLEMAGNE:
- $this->exportCharlemagne($TData);
- break;
- case self::$EXPORT_TYPE_LDCOMPTA:
- $this->exportLDCompta($TData);
- break;
- case self::$EXPORT_TYPE_LDCOMPTA10:
- $this->exportLDCompta10($TData);
- break;
- case self::$EXPORT_TYPE_GESTIMUMV3:
- $this->exportGestimumV3($TData);
- break;
- case self::$EXPORT_TYPE_GESTIMUMV5:
- $this->exportGestimumV5($TData);
- break;
- case self::$EXPORT_TYPE_FEC:
- $this->exportFEC($TData);
- break;
- case self::$EXPORT_TYPE_FEC2:
- $this->exportFEC2($TData);
- break;
- case self::$EXPORT_TYPE_ISUITEEXPERT :
- $this->exportiSuiteExpert($TData);
- break;
- default:
- global $hookmanager;
- $parameters = array('format' => $formatexportset);
- // file contents will be created in the hooked function via print
- $reshook = $hookmanager->executeHooks('export', $parameters, $TData);
- if ($reshook != 1) {
- $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
- }
- break;
- }
- // create and download export file or archive
- if ($withAttachment == 1) {
- $error = 0;
- // close export file
- if ($exportFile) {
- fclose($exportFile);
- }
- if (!empty($archiveFullName) && !empty($archivePath) && !empty($archiveFileList)) {
- // archive files
- $downloadFileMimeType = 'application/zip';
- $downloadFileFullName = $archiveFullName;
- $downloadFilePath = $archivePath;
- // create archive
- $archive = new ZipArchive();
- $res = $archive->open($archivePath, ZipArchive::OVERWRITE | ZipArchive::CREATE);
- if ($res !== true) {
- $error++;
- $this->errors[] = $langs->trans('ErrorFileNotFound', $archivePath);
- }
- if (!$error) {
- // add files
- foreach ($archiveFileList as $archiveFileArr) {
- $res = $archive->addFile($archiveFileArr['path'], $archiveFileArr['name']);
- if (!$res) {
- $error++;
- $this->errors[] = $langs->trans('ErrorArchiveAddFile', $archiveFileArr['name']);
- break;
- }
- }
- }
- if (!$error) {
- // close archive
- $archive->close();
- }
- } elseif (!empty($exportFileFullName) && !empty($exportFilePath)) {
- // only one file to download
- $downloadFileMimeType = 'text/csv';
- $downloadFileFullName = $exportFileFullName;
- $downloadFilePath = $exportFilePath;
- }
- if (!$error) {
- // download export file
- if (!empty($downloadFileMimeType) && !empty($downloadFileFullName) && !empty($downloadFilePath)) {
- header('Content-Type: '.$downloadFileMimeType);
- header('Content-Disposition: attachment; filename='.$downloadFileFullName);
- header('Cache-Control: Public, must-revalidate');
- header('Pragma: public');
- header('Content-Length: '.dol_filesize($downloadFilePath));
- readfileLowMemory($downloadFilePath);
- }
- }
- if ($error) {
- return -1;
- }
- }
- return 1;
- }
- /**
- * Export format : CEGID
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportCegid($objectLines)
- {
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d%m%Y');
- $separator = ";";
- $end_line = "\n";
- print $date.$separator;
- print $line->code_journal.$separator;
- print length_accountg($line->numero_compte).$separator;
- print length_accounta($line->subledger_account).$separator;
- print $line->sens.$separator;
- print price2fec(abs($line->debit - $line->credit)).$separator;
- print dol_string_unaccent($line->label_operation).$separator;
- print dol_string_unaccent($line->doc_ref);
- print $end_line;
- }
- }
- /**
- * Export format : COGILOG
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportCogilog($objectLines)
- {
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d%m%Y');
- $separator = ";";
- $end_line = "\n";
- print $line->code_journal.$separator;
- print $date.$separator;
- print $line->piece_num.$separator;
- print length_accountg($line->numero_compte).$separator;
- print $separator;
- print $line->label_operation.$separator;
- print $date.$separator;
- if ($line->sens == 'D') {
- print price($line->debit).$separator;
- print $separator;
- } elseif ($line->sens == 'C') {
- print $separator;
- print price($line->credit).$separator;
- }
- print $line->doc_ref.$separator;
- print $line->label_operation.$separator;
- print $end_line;
- }
- }
- /**
- * Export format : COALA
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportCoala($objectLines)
- {
- // Coala export
- $separator = ";";
- $end_line = "\n";
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d/%m/%Y');
- print $date.$separator;
- print $line->code_journal.$separator;
- print length_accountg($line->numero_compte).$separator;
- print $line->piece_num.$separator;
- print $line->doc_ref.$separator;
- print price($line->debit).$separator;
- print price($line->credit).$separator;
- print 'E'.$separator;
- print length_accounta($line->subledger_account).$separator;
- print $end_line;
- }
- }
- /**
- * Export format : BOB50
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportBob50($objectLines)
- {
- // Bob50
- $separator = ";";
- $end_line = "\n";
- foreach ($objectLines as $line) {
- print $line->piece_num.$separator;
- $date = dol_print_date($line->doc_date, '%d/%m/%Y');
- print $date.$separator;
- if (empty($line->subledger_account)) {
- print 'G'.$separator;
- print length_accounta($line->numero_compte).$separator;
- } else {
- if (substr($line->numero_compte, 0, 3) == '411') {
- print 'C'.$separator;
- }
- if (substr($line->numero_compte, 0, 3) == '401') {
- print 'F'.$separator;
- }
- print length_accountg($line->subledger_account).$separator;
- }
- print price($line->debit).$separator;
- print price($line->credit).$separator;
- print dol_trunc($line->label_operation, 32).$separator;
- print $end_line;
- }
- }
- /**
- * Export format : CIEL (Format XIMPORT)
- * Format since 2003 compatible CIEL version > 2002 / Sage50
- * Last review for this format : 2021-09-13 Alexandre Spangaro (aspangaro@open-dsi.fr)
- *
- * Help : https://sage50c.online-help.sage.fr/aide-technique/
- * In sage software | Use menu : "Exchange" > "Importing entries..."
- *
- * If you want to force filename to "XIMPORT.TXT" for automatically import file present in a directory :
- * use constant ACCOUNTING_EXPORT_XIMPORT_FORCE_FILENAME
- *
- * @param array $TData data
- * @return void
- */
- public function exportCiel(&$TData)
- {
- $end_line = "\r\n";
- $i = 1;
- foreach ($TData as $data) {
- $code_compta = length_accountg($data->numero_compte);
- if (!empty($data->subledger_account)) {
- $code_compta = length_accounta($data->subledger_account);
- }
- $date_document = dol_print_date($data->doc_date, '%Y%m%d');
- $date_echeance = dol_print_date($data->date_lim_reglement, '%Y%m%d');
- $Tab = array();
- $Tab['num_ecriture'] = str_pad($data->piece_num, 5);
- $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
- $Tab['date_ecriture'] = str_pad($date_document, 8, ' ', STR_PAD_LEFT);
- $Tab['date_echeance'] = str_pad($date_echeance, 8, ' ', STR_PAD_LEFT);
- $Tab['num_piece'] = str_pad(self::trunc($data->doc_ref, 12), 12);
- $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
- $Tab['libelle_ecriture'] = str_pad(self::trunc(dol_string_unaccent($data->doc_ref).dol_string_unaccent($data->label_operation), 25), 25);
- $Tab['montant'] = str_pad(price2fec(abs($data->debit - $data->credit)), 13, ' ', STR_PAD_LEFT);
- $Tab['type_montant'] = str_pad($data->sens, 1);
- $Tab['vide'] = str_repeat(' ', 18); // Analytical accounting - Not managed in Dolibarr
- $Tab['intitule_compte'] = str_pad(self::trunc(dol_string_unaccent($data->label_operation), 34), 34);
- $Tab['end'] = 'O2003'; // 0 = EUR | 2003 = Format Ciel
- $Tab['end_line'] = $end_line;
- print implode($Tab);
- $i++;
- }
- }
- /**
- * Export format : Quadratus (Format ASCII)
- * Format since 2015 compatible QuadraCOMPTA
- * Last review for this format : 2023/01/28 Alexandre Spangaro (aspangaro@open-dsi.fr)
- *
- * Help : https://docplayer.fr/20769649-Fichier-d-entree-ascii-dans-quadracompta.html
- * In QuadraCompta | Use menu : "Outils" > "Suivi des dossiers" > "Import ASCII(Compta)"
- *
- * @param array $TData Data
- * @param resource $exportFile [=null] File resource to export or print if null
- * @param array $archiveFileList [=array()] Archive file list : array of ['path', 'name']
- * @param bool $withAttachment [=0] Not add files or 1 to have attached in an archive
- * @return array Archive file list : array of ['path', 'name']
- */
- public function exportQuadratus(&$TData, $exportFile = null, $archiveFileList = array(), $withAttachment = 0)
- {
- global $conf, $db;
- $end_line = "\r\n";
- // We should use dol_now function not time however this is wrong date to transfert in accounting
- // $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
- // $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
- foreach ($TData as $data) {
- // Clean some data
- $data->doc_ref = dol_string_unaccent($data->doc_ref);
- $data->label_operation = dol_string_unaccent($data->label_operation);
- $data->numero_compte = dol_string_unaccent($data->numero_compte);
- $data->label_compte = dol_string_unaccent($data->label_compte);
- $data->subledger_account = dol_string_unaccent($data->subledger_account);
- $data->subledger_label = dol_string_unaccent($data->subledger_label);
- $code_compta = $data->numero_compte;
- if (!empty($data->subledger_account)) {
- $code_compta = $data->subledger_account;
- }
- $Tab = array();
- if (!empty($data->subledger_account)) {
- $Tab['type_ligne'] = 'C';
- $Tab['num_compte'] = str_pad(self::trunc($data->subledger_account, 8), 8);
- $Tab['lib_compte'] = str_pad(self::trunc($data->subledger_label, 30), 30);
- if ($data->doc_type == 'customer_invoice') {
- $Tab['lib_alpha'] = strtoupper(str_pad('C'.self::trunc($data->subledger_label, 6), 6));
- $Tab['filler'] = str_repeat(' ', 52);
- $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER, 8), 8);
- } elseif ($data->doc_type == 'supplier_invoice') {
- $Tab['lib_alpha'] = strtoupper(str_pad('F'.self::trunc($data->subledger_label, 6), 6));
- $Tab['filler'] = str_repeat(' ', 52);
- $Tab['coll_compte'] = str_pad(self::trunc($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER, 8), 8);
- } else {
- $Tab['filler'] = str_repeat(' ', 59);
- $Tab['coll_compte'] = str_pad(' ', 8);
- }
- $Tab['filler2'] = str_repeat(' ', 110);
- $Tab['Maj'] = 2; // Partial update (alpha key, label, address, collectif, RIB)
- if ($data->doc_type == 'customer_invoice') {
- $Tab['type_compte'] = 'C';
- } elseif ($data->doc_type == 'supplier_invoice') {
- $Tab['type_compte'] = 'F';
- } else {
- $Tab['type_compte'] = 'G';
- }
- $Tab['filler3'] = str_repeat(' ', 235);
- $Tab['end_line'] = $end_line;
- if ($exportFile) {
- fwrite($exportFile, implode($Tab));
- } else {
- print implode($Tab);
- }
- }
- $Tab = array();
- $Tab['type_ligne'] = 'M';
- $Tab['num_compte'] = str_pad(self::trunc($code_compta, 8), 8);
- $Tab['code_journal'] = str_pad(self::trunc($data->code_journal, 2), 2);
- $Tab['folio'] = '000';
- // We use invoice date $data->doc_date not $date_ecriture which is the transfert date
- // maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
- //$Tab['date_ecriture'] = $date_ecriture;
- $Tab['date_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
- $Tab['filler'] = ' ';
- $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref.' '.$data->label_operation, 20), 20);
- // Credit invoice - invert sens
- /*
- if ($data->montant < 0) {
- if ($data->sens == 'C') {
- $Tab['sens'] = 'D';
- } else {
- $Tab['sens'] = 'C';
- }
- $Tab['signe_montant'] = '-';
- } else {
- $Tab['sens'] = $data->sens; // C or D
- $Tab['signe_montant'] = '+';
- }*/
- $Tab['sens'] = $data->sens; // C or D
- $Tab['signe_montant'] = '+';
- // The amount must be in centimes without decimal points.
- $Tab['montant'] = str_pad(abs(($data->debit - $data->credit) * 100), 12, '0', STR_PAD_LEFT);
- $Tab['contrepartie'] = str_repeat(' ', 8);
- // Force date format : %d%m%y
- if (!empty($data->date_lim_reglement)) {
- //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
- $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%y'); // Format must be ddmmyy
- } else {
- $Tab['date_echeance'] = '000000';
- }
- // Please keep quadra named field lettrage(2) + codestat(3) instead of fake lettrage(5)
- // $Tab['lettrage'] = str_repeat(' ', 5);
- $Tab['lettrage'] = str_repeat(' ', 2);
- $Tab['codestat'] = str_repeat(' ', 3);
- $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
- // Keep correct quadra named field instead of anon filler
- // $Tab['filler2'] = str_repeat(' ', 20);
- $Tab['affaire'] = str_repeat(' ', 10);
- $Tab['quantity1'] = str_repeat(' ', 10);
- $Tab['num_piece2'] = str_pad(self::trunc($data->piece_num, 8), 8);
- $Tab['devis'] = str_pad($conf->currency, 3);
- $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3);
- $Tab['filler3'] = str_repeat(' ', 3);
- // Keep correct quadra named field instead of anon filler libelle_ecriture2 is 30 char not 32 !!!!
- // 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
- // TODO: we should filter more than only accent to avoid wrong line size
- // TODO: remove invoice number doc_ref in libelle,
- // TODO: we should offer an option for customer to build the libelle using invoice number / name / date in accounting software
- //$Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 30), 30);
- $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->label_operation, 30), 30);
- $Tab['codetva'] = str_repeat(' ', 2);
- // We need to keep the 10 lastest number of invoice doc_ref not the beginning part that is the unusefull almost same part
- // $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
- $Tab['num_piece3'] = substr(self::trunc($data->doc_ref, 20), -10);
- $Tab['reserved'] = str_repeat(' ', 10); // position 159
- $Tab['currency_amount'] = str_repeat(' ', 13); // position 169
- // get document file
- $attachmentFileName = '';
- if ($withAttachment == 1) {
- $attachmentFileKey = trim($data->piece_num);
- if (!isset($archiveFileList[$attachmentFileKey])) {
- $objectDirPath = '';
- $objectFileName = dol_sanitizeFileName($data->doc_ref);
- if ($data->doc_type == 'customer_invoice') {
- $objectDirPath = !empty($conf->facture->multidir_output[$conf->entity]) ? $conf->facture->multidir_output[$conf->entity] : $conf->facture->dir_output;
- } elseif ($data->doc_type == 'expense_report') {
- $objectDirPath = !empty($conf->expensereport->multidir_output[$conf->entity]) ? $conf->expensereport->multidir_output[$conf->entity] : $conf->factureexpensereport->dir_output;
- } elseif ($data->doc_type == 'supplier_invoice') {
- $objectDirPath = !empty($conf->fournisseur->facture->multidir_output[$conf->entity]) ? $conf->fournisseur->facture->multidir_output[$conf->entity] : $conf->fournisseur->facture->dir_output;
- }
- $arrayofinclusion = array();
- $arrayofinclusion[] = '^'.preg_quote($objectFileName, '/').'\.pdf$';
- $fileFoundList = dol_dir_list($objectDirPath.'/'.$objectFileName, 'files', 0, implode('|', $arrayofinclusion), '(\.meta|_preview.*\.png)$', 'date', SORT_DESC, 0, true);
- if (!empty($fileFoundList)) {
- $attachmentFileNameTrunc = str_pad(self::trunc($data->piece_num, 8), 8, '0', STR_PAD_LEFT);
- foreach ($fileFoundList as $fileFound) {
- if (strstr($fileFound['name'], $objectFileName)) {
- $fileFoundPath = $objectDirPath.'/'.$objectFileName.'/'.$fileFound['name'];
- if (file_exists($fileFoundPath)) {
- $archiveFileList[$attachmentFileKey] = array(
- 'path' => $fileFoundPath,
- 'name' => $attachmentFileNameTrunc.'.pdf',
- );
- break;
- }
- }
- }
- }
- }
- if (isset($archiveFileList[$attachmentFileKey])) {
- $attachmentFileName = $archiveFileList[$attachmentFileKey]['name'];
- }
- }
- if (dol_strlen($attachmentFileName) == 12) {
- $Tab['attachment'] = $attachmentFileName; // position 182
- } else {
- $Tab['attachment'] = str_repeat(' ', 12); // position 182
- }
- $Tab['filler4'] = str_repeat(' ', 38);
- $Tab['end_line'] = $end_line;
- if ($exportFile) {
- fwrite($exportFile, implode($Tab));
- } else {
- print implode($Tab);
- }
- }
- return $archiveFileList;
- }
- /**
- * Export format : WinFic - eWinfic - WinSis Compta
- * Last review for this format : 2022-11-01 Alexandre Spangaro (aspangaro@open-dsi.fr)
- *
- * Help : https://wiki.gestan.fr/lib/exe/fetch.php?media=wiki:v15:compta:accountancy-format_winfic-ewinfic-winsiscompta.pdf
- *
- * @param array $TData data
- *
- * @return void
- */
- public function exportWinfic(&$TData)
- {
- global $conf;
- $end_line = "\r\n";
- $index = 1;
- //We should use dol_now function not time however this is wrong date to transfert in accounting
- //$date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
- //$date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
- // Warning ! When truncation is necessary, no dot because 3 dots = three characters. The columns are shifted
- foreach ($TData as $data) {
- $code_compta = $data->numero_compte;
- if (!empty($data->subledger_account)) {
- $code_compta = $data->subledger_account;
- }
- $Tab = array();
- //$Tab['type_ligne'] = 'M';
- $Tab['code_journal'] = str_pad(dol_trunc($data->code_journal, 2, 'right', 'UTF-8', 1), 2);
- //We use invoice date $data->doc_date not $date_ecriture which is the transfert date
- //maybe we should set an option for customer who prefer to keep in accounting software the tranfert date instead of invoice date ?
- //$Tab['date_ecriture'] = $date_ecriture;
- $Tab['date_operation'] = dol_print_date($data->doc_date, '%d%m%Y');
- $Tab['folio'] = ' 1';
- $Tab['num_ecriture'] = str_pad(dol_trunc($index, 6, 'right', 'UTF-8', 1), 6, ' ', STR_PAD_LEFT);
- $Tab['jour_ecriture'] = dol_print_date($data->doc_date, '%d%m%y');
- $Tab['num_compte'] = str_pad(dol_trunc($code_compta, 6, 'right', 'UTF-8', 1), 6, '0');
- if ($data->sens == 'D') {
- $Tab['montant_debit'] = str_pad(number_format($data->debit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
- $Tab['montant_crebit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
- } else {
- $Tab['montant_debit'] = str_pad(number_format(0, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
- $Tab['montant_crebit'] = str_pad(number_format($data->credit, 2, ',', ''), 13, ' ', STR_PAD_LEFT);
- }
- $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);
- $Tab['lettrage'] = str_repeat(dol_trunc($data->lettering_code, 2, 'left', 'UTF-8', 1), 2);
- $Tab['code_piece'] = str_pad(dol_trunc($data->piece_num, 5, 'left', 'UTF-8', 1), 5, ' ', STR_PAD_LEFT);
- $Tab['code_stat'] = str_repeat(' ', 4);
- if (!empty($data->date_lim_reglement)) {
- //$Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, $conf->global->ACCOUNTING_EXPORT_DATE);
- $Tab['date_echeance'] = dol_print_date($data->date_lim_reglement, '%d%m%Y');
- } else {
- $Tab['date_echeance'] = dol_print_date($data->doc_date, '%d%m%Y');
- }
- $Tab['monnaie'] = '1';
- $Tab['filler'] = ' ';
- $Tab['ind_compteur'] = ' ';
- $Tab['quantite'] = '0,000000000';
- $Tab['code_pointage'] = str_repeat(' ', 2);
- $Tab['end_line'] = $end_line;
- print implode('|', $Tab);
- $index++;
- }
- }
- /**
- * Export format : EBP
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportEbp($objectLines)
- {
- $separator = ',';
- $end_line = "\n";
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d%m%Y');
- print $line->id.$separator;
- print $date.$separator;
- print $line->code_journal.$separator;
- if (empty($line->subledger_account)) {
- print $line->numero_compte.$separator;
- } else {
- print $line->subledger_account.$separator;
- }
- //print substr(length_accountg($line->numero_compte), 0, 2) . $separator;
- print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"'.$separator;
- print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator;
- print price2num(abs($line->debit - $line->credit)).$separator;
- print $line->sens.$separator;
- print $date.$separator;
- //print 'EUR';
- print $end_line;
- }
- }
- /**
- * Export format : Agiris Isacompta
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportAgiris($objectLines)
- {
- $separator = ';';
- $end_line = "\n";
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d%m%Y');
- print $line->piece_num.$separator;
- print self::toAnsi($line->label_operation).$separator;
- print $date.$separator;
- print self::toAnsi($line->label_operation).$separator;
- if (empty($line->subledger_account)) {
- print length_accountg($line->numero_compte).$separator;
- print self::toAnsi($line->label_compte).$separator;
- } else {
- print length_accounta($line->subledger_account).$separator;
- print self::toAnsi($line->subledger_label).$separator;
- }
- print self::toAnsi($line->doc_ref).$separator;
- print price($line->debit).$separator;
- print price($line->credit).$separator;
- print price(abs($line->debit - $line->credit)).$separator;
- print $line->sens.$separator;
- print $line->lettering_code.$separator;
- print $line->code_journal;
- print $end_line;
- }
- }
- /**
- * Export format : OpenConcerto
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportOpenConcerto($objectLines)
- {
- $separator = ';';
- $end_line = "\n";
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%d/%m/%Y');
- print $date.$separator;
- print $line->code_journal.$separator;
- if (empty($line->subledger_account)) {
- print length_accountg($line->numero_compte).$separator;
- } else {
- print length_accounta($line->subledger_account).$separator;
- }
- print $line->doc_ref.$separator;
- print $line->label_operation.$separator;
- print price($line->debit).$separator;
- print price($line->credit).$separator;
- print $end_line;
- }
- }
- /**
- * Export format : Configurable CSV
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportConfigurable($objectLines)
- {
- global $conf;
- $separator = $this->separator;
- foreach ($objectLines as $line) {
- $tab = array();
- // export configurable
- $date = dol_print_date($line->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
- $tab[] = $line->piece_num;
- $tab[] = $date;
- $tab[] = $line->doc_ref;
- $tab[] = preg_match('/'.$separator.'/', $line->label_operation) ? "'".$line->label_operation."'" : $line->label_operation;
- $tab[] = length_accountg($line->numero_compte);
- $tab[] = length_accounta($line->subledger_account);
- $tab[] = price2num($line->debit);
- $tab[] = price2num($line->credit);
- $tab[] = price2num($line->debit - $line->credit);
- $tab[] = $line->code_journal;
- print implode($separator, $tab).$this->end_line;
- }
- }
- /**
- * Export format : FEC
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportFEC($objectLines)
- {
- global $langs;
- $separator = "\t";
- $end_line = "\r\n";
- print "JournalCode".$separator;
- print "JournalLib".$separator;
- print "EcritureNum".$separator;
- print "EcritureDate".$separator;
- print "CompteNum".$separator;
- print "CompteLib".$separator;
- print "CompAuxNum".$separator;
- print "CompAuxLib".$separator;
- print "PieceRef".$separator;
- print "PieceDate".$separator;
- print "EcritureLib".$separator;
- print "Debit".$separator;
- print "Credit".$separator;
- print "EcritureLet".$separator;
- print "DateLet".$separator;
- print "ValidDate".$separator;
- print "Montantdevise".$separator;
- print "Idevise".$separator;
- print "DateLimitReglmt".$separator;
- print "NumFacture";
- print $end_line;
- foreach ($objectLines as $line) {
- if ($line->debit == 0 && $line->credit == 0) {
- //unset($array[$line]);
- } else {
- $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
- $date_document = dol_print_date($line->doc_date, '%Y%m%d');
- $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
- $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
- $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
- $refInvoice = '';
- if ($line->doc_type == 'customer_invoice') {
- // Customer invoice
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
- $invoice = new Facture($this->db);
- $invoice->fetch($line->fk_doc);
- $refInvoice = $invoice->ref;
- } elseif ($line->doc_type == 'supplier_invoice') {
- // Supplier invoice
- require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
- $invoice = new FactureFournisseur($this->db);
- $invoice->fetch($line->fk_doc);
- $refInvoice = $invoice->ref_supplier;
- }
- // FEC:JournalCode
- print $line->code_journal . $separator;
- // FEC:JournalLib
- print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
- // FEC:EcritureNum
- print $line->piece_num . $separator;
- // FEC:EcritureDate
- print $date_document . $separator;
- // FEC:CompteNum
- print $line->numero_compte . $separator;
- // FEC:CompteLib
- print dol_string_unaccent($line->label_compte) . $separator;
- // FEC:CompAuxNum
- print $line->subledger_account . $separator;
- // FEC:CompAuxLib
- print dol_string_unaccent($line->subledger_label) . $separator;
- // FEC:PieceRef
- print $line->doc_ref . $separator;
- // FEC:PieceDate
- print dol_string_unaccent($date_creation) . $separator;
- // FEC:EcritureLib
- // Clean label operation to prevent problem on export with tab separator & other character
- $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
- print dol_string_unaccent($line->label_operation) . $separator;
- // FEC:Debit
- print price2fec($line->debit) . $separator;
- // FEC:Credit
- print price2fec($line->credit) . $separator;
- // FEC:EcritureLet
- print $line->lettering_code . $separator;
- // FEC:DateLet
- print $date_lettering . $separator;
- // FEC:ValidDate
- print $date_validation . $separator;
- // FEC:Montantdevise
- print $line->multicurrency_amount . $separator;
- // FEC:Idevise
- print $line->multicurrency_code . $separator;
- // FEC_suppl:DateLimitReglmt
- print $date_limit_payment . $separator;
- // FEC_suppl:NumFacture
- // Clean ref invoice to prevent problem on export with tab separator & other character
- $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
- print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
- print $end_line;
- }
- }
- }
- /**
- * Export format : FEC2
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportFEC2($objectLines)
- {
- global $langs;
- $separator = "\t";
- $end_line = "\r\n";
- print "JournalCode".$separator;
- print "JournalLib".$separator;
- print "EcritureNum".$separator;
- print "EcritureDate".$separator;
- print "CompteNum".$separator;
- print "CompteLib".$separator;
- print "CompAuxNum".$separator;
- print "CompAuxLib".$separator;
- print "PieceRef".$separator;
- print "PieceDate".$separator;
- print "EcritureLib".$separator;
- print "Debit".$separator;
- print "Credit".$separator;
- print "EcritureLet".$separator;
- print "DateLet".$separator;
- print "ValidDate".$separator;
- print "Montantdevise".$separator;
- print "Idevise".$separator;
- print "DateLimitReglmt".$separator;
- print "NumFacture";
- print $end_line;
- foreach ($objectLines as $line) {
- if ($line->debit == 0 && $line->credit == 0) {
- //unset($array[$line]);
- } else {
- $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
- $date_document = dol_print_date($line->doc_date, '%Y%m%d');
- $date_lettering = dol_print_date($line->date_lettering, '%Y%m%d');
- $date_validation = dol_print_date($line->date_validation, '%Y%m%d');
- $date_limit_payment = dol_print_date($line->date_lim_reglement, '%Y%m%d');
- $refInvoice = '';
- if ($line->doc_type == 'customer_invoice') {
- // Customer invoice
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
- $invoice = new Facture($this->db);
- $invoice->fetch($line->fk_doc);
- $refInvoice = $invoice->ref;
- } elseif ($line->doc_type == 'supplier_invoice') {
- // Supplier invoice
- require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
- $invoice = new FactureFournisseur($this->db);
- $invoice->fetch($line->fk_doc);
- $refInvoice = $invoice->ref_supplier;
- }
- // FEC:JournalCode
- print $line->code_journal . $separator;
- // FEC:JournalLib
- print dol_string_unaccent($langs->transnoentities($line->journal_label)) . $separator;
- // FEC:EcritureNum
- print $line->piece_num . $separator;
- // FEC:EcritureDate
- print $date_creation . $separator;
- // FEC:CompteNum
- print length_accountg($line->numero_compte) . $separator;
- // FEC:CompteLib
- print dol_string_unaccent($line->label_compte) . $separator;
- // FEC:CompAuxNum
- print length_accounta($line->subledger_account) . $separator;
- // FEC:CompAuxLib
- print dol_string_unaccent($line->subledger_label) . $separator;
- // FEC:PieceRef
- print $line->doc_ref . $separator;
- // FEC:PieceDate
- print $date_document . $separator;
- // FEC:EcritureLib
- // Clean label operation to prevent problem on export with tab separator & other character
- $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
- print dol_string_unaccent($line->label_operation) . $separator;
- // FEC:Debit
- print price2fec($line->debit) . $separator;
- // FEC:Credit
- print price2fec($line->credit) . $separator;
- // FEC:EcritureLet
- print $line->lettering_code . $separator;
- // FEC:DateLet
- print $date_lettering . $separator;
- // FEC:ValidDate
- print $date_validation . $separator;
- // FEC:Montantdevise
- print $line->multicurrency_amount . $separator;
- // FEC:Idevise
- print $line->multicurrency_code . $separator;
- // FEC_suppl:DateLimitReglmt
- print $date_limit_payment . $separator;
- // FEC_suppl:NumFacture
- // Clean ref invoice to prevent problem on export with tab separator & other character
- $refInvoice = str_replace(array("\t", "\n", "\r"), " ", $refInvoice);
- print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1);
- print $end_line;
- }
- }
- }
- /**
- * Export format : SAGE50SWISS
- *
- * https://onlinehelp.sageschweiz.ch/default.aspx?tabid=19984
- * http://media.topal.ch/Public/Schnittstellen/TAF/Specification/Sage50-TAF-format.pdf
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportSAGE50SWISS($objectLines)
- {
- // SAGE50SWISS
- $this->separator = ',';
- $this->end_line = "\r\n";
- // Print header line
- print "Blg,Datum,Kto,S/H,Grp,GKto,SId,SIdx,KIdx,BTyp,MTyp,Code,Netto,Steuer,FW-Betrag,Tx1,Tx2,PkKey,OpId,Flag";
- print $this->end_line;
- $thisPieceNum = "";
- $thisPieceAccountNr = "";
- $aSize = count($objectLines);
- foreach ($objectLines as $aIndex => $line) {
- $sammelBuchung = false;
- if ($aIndex - 2 >= 0 && $objectLines[$aIndex - 2]->piece_num == $line->piece_num) {
- $sammelBuchung = true;
- } elseif ($aIndex + 2 < $aSize && $objectLines[$aIndex + 2]->piece_num == $line->piece_num) {
- $sammelBuchung = true;
- } elseif ($aIndex + 1 < $aSize
- && $objectLines[$aIndex + 1]->piece_num == $line->piece_num
- && $aIndex - 1 < $aSize
- && $objectLines[$aIndex - 1]->piece_num == $line->piece_num
- ) {
- $sammelBuchung = true;
- }
- //Blg
- print $line->piece_num.$this->separator;
- // Datum
- $date = dol_print_date($line->doc_date, '%d.%m.%Y');
- print $date.$this->separator;
- // Kto
- print length_accountg($line->numero_compte).$this->separator;
- // S/H
- if ($line->sens == 'D') {
- print 'S'.$this->separator;
- } else {
- print 'H'.$this->separator;
- }
- //Grp
- print self::trunc($line->code_journal, 1).$this->separator;
- // GKto
- if (empty($line->code_tiers)) {
- if ($line->piece_num == $thisPieceNum) {
- print length_accounta($thisPieceAccountNr).$this->separator;
- } else {
- print "div".$this->separator;
- }
- } else {
- print length_accounta($line->code_tiers).$this->separator;
- }
- //SId
- print $this->separator;
- //SIdx
- print "0".$this->separator;
- //KIdx
- print "0".$this->separator;
- //BTyp
- print "0".$this->separator;
- //MTyp 1=Fibu Einzelbuchung 2=Sammebuchung
- if ($sammelBuchung) {
- print "2".$this->separator;
- } else {
- print "1".$this->separator;
- }
- // Code
- print '""'.$this->separator;
- // Netto
- print abs($line->debit - $line->credit).$this->separator;
- // Steuer
- print "0.00".$this->separator;
- // FW-Betrag
- print "0.00".$this->separator;
- // Tx1
- $line1 = self::toAnsi($line->label_compte, 29);
- if ($line1 == "LIQ" || $line1 == "LIQ Beleg ok" || strlen($line1) <= 3) {
- $line1 = "";
- }
- $line2 = self::toAnsi($line->doc_ref, 29);
- if (strlen($line1) == 0) {
- $line1 = $line2;
- $line2 = "";
- }
- if (strlen($line1) > 0 && strlen($line2) > 0 && (strlen($line1) + strlen($line2)) < 27) {
- $line1 = $line1.' / '.$line2;
- $line2 = "";
- }
- print '"'.self::toAnsi($line1).'"'.$this->separator;
- // Tx2
- print '"'.self::toAnsi($line2).'"'.$this->separator;
- //PkKey
- print "0".$this->separator;
- //OpId
- print $this->separator;
- // Flag
- print "0";
- print $this->end_line;
- if ($line->piece_num !== $thisPieceNum) {
- $thisPieceNum = $line->piece_num;
- $thisPieceAccountNr = $line->numero_compte;
- }
- }
- }
- /**
- * Export format : LD Compta version 9
- * http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW9.pdf
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportLDCompta($objectLines)
- {
- $separator = ';';
- $end_line = "\r\n";
- foreach ($objectLines as $line) {
- $date_document = dol_print_date($line->doc_date, '%Y%m%d');
- $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
- $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
- // TYPE
- $type_enregistrement = 'E'; // For write movement
- print $type_enregistrement.$separator;
- // JNAL
- print substr($line->code_journal, 0, 2).$separator;
- // NECR
- print $line->id.$separator;
- // NPIE
- print $line->piece_num.$separator;
- // DATP
- print $date_document.$separator;
- // LIBE
- print $line->label_operation.$separator;
- // DATH
- print $date_lim_reglement.$separator;
- // CNPI
- if ($line->doc_type == 'supplier_invoice') {
- if (($line->debit - $line->credit) > 0) {
- $nature_piece = 'AF';
- } else {
- $nature_piece = 'FF';
- }
- } elseif ($line->doc_type == 'customer_invoice') {
- if (($line->debit - $line->credit) < 0) {
- $nature_piece = 'AC';
- } else {
- $nature_piece = 'FC';
- }
- } else {
- $nature_piece = '';
- }
- print $nature_piece.$separator;
- // RACI
- // if (!empty($line->subledger_account)) {
- // if ($line->doc_type == 'supplier_invoice') {
- // $racine_subledger_account = '40';
- // } elseif ($line->doc_type == 'customer_invoice') {
- // $racine_subledger_account = '41';
- // } else {
- // $racine_subledger_account = '';
- // }
- // } else {
- $racine_subledger_account = ''; // for records of type E leave this field blank
- // }
- print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
- // MONT
- print price(abs($line->debit - $line->credit), 0, '', 1, 2, 2).$separator;
- // CODC
- print $line->sens.$separator;
- // CPTG
- print length_accountg($line->numero_compte).$separator;
- // DATE
- print $date_creation.$separator;
- // CLET
- print $line->lettering_code.$separator;
- // DATL
- print $line->date_lettering.$separator;
- // CPTA
- if (!empty($line->subledger_account)) {
- print length_accounta($line->subledger_account).$separator;
- } else {
- print $separator;
- }
- // CNAT
- if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
- print 'F'.$separator;
- } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
- print 'C'.$separator;
- } else {
- print $separator;
- }
- // SECT
- print $separator;
- // CTRE
- print $separator;
- // NORL
- print $separator;
- // DATV
- print $separator;
- // REFD
- print $line->doc_ref.$separator;
- // CODH
- print $separator;
- // NSEQ
- print $separator;
- // MTDV
- print '0'.$separator;
- // CODV
- print $separator;
- // TXDV
- print '0'.$separator;
- // MOPM
- print $separator;
- // BONP
- print $separator;
- // BQAF
- print $separator;
- // ECES
- print $separator;
- // TXTL
- print $separator;
- // ECRM
- print $separator;
- // DATK
- print $separator;
- // HEUK
- print $separator;
- print $end_line;
- }
- }
- /**
- * Export format : LD Compta version 10 & higher
- * Last review for this format : 08-15-2021 Alexandre Spangaro (aspangaro@open-dsi.fr)
- *
- * Help : http://www.ldsysteme.fr/fileadmin/telechargement/np/ldcompta/Documentation/IntCptW10.pdf
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportLDCompta10($objectLines)
- {
- require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
- $separator = ';';
- $end_line = "\r\n";
- $last_codeinvoice = '';
- foreach ($objectLines as $line) {
- // TYPE C
- if ($last_codeinvoice != $line->doc_ref) {
- //recherche societe en fonction de son code client
- $sql = "SELECT code_client, fk_forme_juridique, nom, address, zip, town, fk_pays, phone, siret FROM ".MAIN_DB_PREFIX."societe";
- $sql .= " WHERE code_client = '".$this->db->escape($line->thirdparty_code)."'";
- $resql = $this->db->query($sql);
- if ($resql && $this->db->num_rows($resql) > 0) {
- $soc = $this->db->fetch_object($resql);
- $address = array('', '', '');
- if (strpos($soc->address, "\n") !== false) {
- $address = explode("\n", $soc->address);
- if (is_array($address) && count($address) > 0) {
- foreach ($address as $key => $data) {
- $address[$key] = str_replace(array("\t", "\n", "\r"), "", $data);
- $address[$key] = dol_trunc($address[$key], 40, 'right', 'UTF-8', 1);
- }
- }
- } else {
- $address[0] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 0, 40);
- $address[1] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 41, 40);
- $address[2] = substr(str_replace(array("\t", "\r"), " ", $soc->address), 82, 40);
- }
- $type_enregistrement = 'C';
- //TYPE
- print $type_enregistrement.$separator;
- //NOCL
- print $soc->code_client.$separator;
- //NMCM
- print $separator;
- //LIBI
- print $separator;
- //TITR
- print $separator;
- //RSSO
- print $soc->nom.$separator;
- //CAD1
- print $address[0].$separator;
- //CAD2
- print $address[1].$separator;
- //CAD3
- print $address[2].$separator;
- //COPO
- print $soc->zip.$separator;
- //BUDI
- print substr($soc->town, 0, 40).$separator;
- //CPAY
- print $separator;
- //PAYS
- print substr(getCountry($soc->fk_pays), 0, 40).$separator;
- //NTEL
- print $soc->phone.$separator;
- //TLEX
- print $separator;
- //TLPO
- print $separator;
- //TLCY
- print $separator;
- //NINT
- print $separator;
- //COMM
- print $separator;
- //SIRE
- print str_replace(" ", "", $soc->siret).$separator;
- //RIBP
- print $separator;
- //DOBQ
- print $separator;
- //IBBQ
- print $separator;
- //COBQ
- print $separator;
- //GUBQ
- print $separator;
- //CPBQ
- print $separator;
- //CLBQ
- print $separator;
- //BIBQ
- print $separator;
- //MOPM
- print $separator;
- //DJPM
- print $separator;
- //DMPM
- print $separator;
- //REFM
- print $separator;
- //SLVA
- print $separator;
- //PLCR
- print $separator;
- //ECFI
- print $separator;
- //CREP
- print $separator;
- //NREP
- print $separator;
- //TREP
- print $separator;
- //MREP
- print $separator;
- //GRRE
- print $separator;
- //LTTA
- print $separator;
- //CACT
- print $separator;
- //CODV
- print $separator;
- //GRTR
- print $separator;
- //NOFP
- print $separator;
- //BQAF
- print $separator;
- //BONP
- print $separator;
- //CESC
- print $separator;
- print $end_line;
- }
- }
- $date_document = dol_print_date($line->doc_date, '%Y%m%d');
- $date_creation = dol_print_date($line->date_creation, '%Y%m%d');
- $date_lim_reglement = dol_print_date($line->date_lim_reglement, '%Y%m%d');
- // TYPE E
- $type_enregistrement = 'E'; // For write movement
- print $type_enregistrement.$separator;
- // JNAL
- print substr($line->code_journal, 0, 2).$separator;
- // NECR
- print $line->id.$separator;
- // NPIE
- print $line->piece_num.$separator;
- // DATP
- print $date_document.$separator;
- // LIBE
- print dol_trunc($line->label_operation, 25, 'right', 'UTF-8', 1).$separator;
- // DATH
- print $date_lim_reglement.$separator;
- // CNPI
- if ($line->doc_type == 'supplier_invoice') {
- 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.
- $nature_piece = 'AF';
- } else {
- $nature_piece = 'FF';
- }
- } elseif ($line->doc_type == 'customer_invoice') {
- if (($line->amount) < 0) {
- $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.
- } else {
- $nature_piece = 'FC';
- }
- } else {
- $nature_piece = '';
- }
- print $nature_piece.$separator;
- // RACI
- // if (!empty($line->subledger_account)) {
- // if ($line->doc_type == 'supplier_invoice') {
- // $racine_subledger_account = '40';
- // } elseif ($line->doc_type == 'customer_invoice') {
- // $racine_subledger_account = '41';
- // } else {
- // $racine_subledger_account = '';
- // }
- // } else {
- $racine_subledger_account = ''; // for records of type E leave this field blank
- // }
- print $racine_subledger_account.$separator; // deprecated CPTG & CPTA use instead
- // MONT
- print price(abs($line->debit - $line->credit), 0, '', 1, 2).$separator;
- // CODC
- print $line->sens.$separator;
- // CPTG
- print length_accountg($line->numero_compte).$separator;
- // DATE
- print $date_document.$separator;
- // CLET
- print $line->lettering_code.$separator;
- // DATL
- print $line->date_lettering.$separator;
- // CPTA
- if (!empty($line->subledger_account)) {
- print length_accounta($line->subledger_account).$separator;
- } else {
- print $separator;
- }
- // CNAT
- if ($line->doc_type == 'supplier_invoice' && !empty($line->subledger_account)) {
- print 'F'.$separator;
- } elseif ($line->doc_type == 'customer_invoice' && !empty($line->subledger_account)) {
- print 'C'.$separator;
- } else {
- print $separator;
- }
- // CTRE
- print $separator;
- // NORL
- print $separator;
- // DATV
- print $separator;
- // REFD
- print $line->doc_ref.$separator;
- // NECA
- print '0'.$separator;
- // CSEC
- print $separator;
- // CAFF
- print $separator;
- // CDES
- print $separator;
- // QTUE
- print $separator;
- // MTDV
- print '0'.$separator;
- // CODV
- print $separator;
- // TXDV
- print '0'.$separator;
- // MOPM
- print $separator;
- // BONP
- print $separator;
- // BQAF
- print $separator;
- // ECES
- print $separator;
- // TXTL
- print $separator;
- // ECRM
- print $separator;
- // DATK
- print $separator;
- // HEUK
- print $separator;
- print $end_line;
- $last_codeinvoice = $line->doc_ref;
- }
- }
- /**
- * Export format : Charlemagne
- *
- * @param array $objectLines data
- * @return void
- */
- public function exportCharlemagne($objectLines)
- {
- global $langs;
- $langs->load('compta');
- $separator = "\t";
- $end_line = "\n";
- /*
- * Charlemagne export need header
- */
- print $langs->transnoentitiesnoconv('Date').$separator;
- print self::trunc($langs->transnoentitiesnoconv('Journal'), 6).$separator;
- print self::trunc($langs->transnoentitiesnoconv('Account'), 15).$separator;
- print self::trunc($langs->transnoentitiesnoconv('LabelAccount'), 60).$separator;
- print self::trunc($langs->transnoentitiesnoconv('Piece'), 20).$separator;
- print self::trunc($langs->transnoentitiesnoconv('LabelOperation'), 60).$separator;
- print $langs->transnoentitiesnoconv('Amount').$separator;
- print 'S'.$separator;
- print self::trunc($langs->transnoentitiesnoconv('Analytic').' 1', 15).$separator;
- print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 1', 60).$separator;
- print self::trunc($langs->transnoentitiesnoconv('Analytic').' 2', 15).$separator;
- print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 2', 60).$separator;
- print self::trunc($langs->transnoentitiesnoconv('Analytic').' 3', 15).$separator;
- print self::trunc($langs->transnoentitiesnoconv('AnalyticLabel').' 3', 60).$separator;
- print $end_line;
- foreach ($objectLines as $line) {
- $date = dol_print_date($line->doc_date, '%Y%m%d');
- print $date.$separator; //Date
- print self::trunc($line->code_journal, 6).$separator; //Journal code
- if (!empty($line->subledger_account)) {
- $account = $line->subledger_account;
- } else {
- $account = $line->numero_compte;
- }
- print self::trunc($account, 15).$separator; //Account number
- print self::trunc($line->label_compte, 60).$separator; //Account label
- print self::trunc($line->doc_ref, 20).$separator; //Piece
- // Clean label operation to prevent problem on export with tab separator & other character
- $line->label_operation = str_replace(array("\t", "\n", "\r"), " ", $line->label_operation);
- print self::trunc($line->label_operation, 60).$separator; //Operation label
- print price(abs($line->debit - $line->credit)).$separator; //Amount
- print $line->sens.$separator; //Direction
- print $separator; //Analytic
- print $separator; //Analytic
- print $separator; //Analytic
- print $separator; //Analytic
- print $separator; //Analytic
- print $separator; //Analytic
- print $end_line;
- }
- }
- /**
- * Export format : Gestimum V3
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportGestimumV3($objectLines)
- {
- global $langs;
- $this->separator = ',';
- $invoices_infos = array();
- $supplier_invoices_infos = array();
- foreach ($objectLines as $line) {
- if ($line->debit == 0 && $line->credit == 0) {
- //unset($array[$line]);
- } else {
- $date = dol_print_date($line->doc_date, '%d/%m/%Y');
- $invoice_ref = $line->doc_ref;
- $company_name = "";
- if (($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice') && $line->fk_doc > 0) {
- if (($line->doc_type == 'customer_invoice' && !isset($invoices_infos[$line->fk_doc])) ||
- ($line->doc_type == 'supplier_invoice' && !isset($supplier_invoices_infos[$line->fk_doc]))) {
- if ($line->doc_type == 'customer_invoice') {
- // Get new customer invoice ref and company name
- $sql = 'SELECT f.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture as f';
- $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON f.fk_soc = s.rowid';
- $sql .= ' WHERE f.rowid = '.((int) $line->fk_doc);
- $resql = $this->db->query($sql);
- if ($resql) {
- if ($obj = $this->db->fetch_object($resql)) {
- // Save invoice infos
- $invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
- $invoice_ref = $obj->ref;
- $company_name = $obj->nom;
- }
- }
- } else {
- // Get new supplier invoice ref and company name
- $sql = 'SELECT ff.ref, s.nom FROM ' . MAIN_DB_PREFIX . 'facture_fourn as ff';
- $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe AS s ON ff.fk_soc = s.rowid';
- $sql .= ' WHERE ff.rowid = '.((int) $line->fk_doc);
- $resql = $this->db->query($sql);
- if ($resql) {
- if ($obj = $this->db->fetch_object($resql)) {
- // Save invoice infos
- $supplier_invoices_infos[$line->fk_doc] = array('ref' => $obj->ref, 'company_name' => $obj->nom);
- $invoice_ref = $obj->ref;
- $company_name = $obj->nom;
- }
- }
- }
- } elseif ($line->doc_type == 'customer_invoice') {
- // Retrieve invoice infos
- $invoice_ref = $invoices_infos[$line->fk_doc]['ref'];
- $company_name = $invoices_infos[$line->fk_doc]['company_name'];
- } else {
- // Retrieve invoice infos
- $invoice_ref = $supplier_invoices_infos[$line->fk_doc]['ref'];
- $company_name = $supplier_invoices_infos[$line->fk_doc]['company_name'];
- }
- }
- print $line->id . $this->separator;
- print $date . $this->separator;
- print substr($line->code_journal, 0, 4) . $this->separator;
- if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) {
- print length_accountg($line->subledger_account) . $this->separator;
- } else {
- print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
- }
- //Libellé Auto
- print $this->separator;
- //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
- //Libellé manuel
- print dol_trunc(str_replace('"', '', $invoice_ref . (!empty($company_name) ? ' - ' : '') . $company_name), 40, 'right', 'UTF-8', 1) . $this->separator;
- //Numéro de pièce
- print dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . $this->separator;
- //Devise
- print 'EUR' . $this->separator;
- //Amount
- print price2num(abs($line->debit - $line->credit)) . $this->separator;
- //Sens
- print $line->sens . $this->separator;
- //Code lettrage
- print $this->separator;
- //Date Echéance
- print $date;
- print $this->end_line;
- }
- }
- }
- /**
- * Export format : Gestimum V5
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportGestimumV5($objectLines)
- {
- $this->separator = ',';
- foreach ($objectLines as $line) {
- if ($line->debit == 0 && $line->credit == 0) {
- //unset($array[$line]);
- } else {
- $date = dol_print_date($line->doc_date, '%d%m%Y');
- print $line->id . $this->separator;
- print $date . $this->separator;
- print substr($line->code_journal, 0, 4) . $this->separator;
- if ((substr($line->numero_compte, 0, 3) == '411') || (substr($line->numero_compte, 0, 3) == '401')) { // TODO No hard code value
- print length_accountg($line->subledger_account) . $this->separator;
- } else {
- print substr(length_accountg($line->numero_compte), 0, 15) . $this->separator;
- }
- print $this->separator;
- //print '"'.dol_trunc(str_replace('"', '', $line->label_operation),40,'right','UTF-8',1).'"' . $this->separator;
- print '"' . dol_trunc(str_replace('"', '', $line->doc_ref), 40, 'right', 'UTF-8', 1) . '"' . $this->separator;
- print '"' . dol_trunc(str_replace('"', '', $line->piece_num), 10, 'right', 'UTF-8', 1) . '"' . $this->separator;
- print price2num(abs($line->debit - $line->credit)) . $this->separator;
- print $line->sens . $this->separator;
- print $date . $this->separator;
- print $this->separator;
- print $this->separator;
- print 'EUR';
- print $this->end_line;
- }
- }
- }
- /**
- * Export format : iSuite Expert
- *
- * by OpenSolus [https://opensolus.fr]
- *
- * @param array $objectLines data
- *
- * @return void
- */
- public function exportiSuiteExpert($objectLines)
- {
- $this->separator = ';';
- $this->end_line = "\r\n";
- foreach ($objectLines as $line) {
- $tab = array();
- $date = dol_print_date($line->doc_date, '%d/%m/%Y');
- $tab[] = $line->piece_num;
- $tab[] = $date;
- $tab[] = substr($date, 6, 4);
- $tab[] = substr($date, 3, 2);
- $tab[] = substr($date, 0, 2);
- $tab[] = $line->doc_ref;
- //Conversion de chaine UTF8 en Latin9
- $tab[] = mb_convert_encoding(str_replace(' - Compte auxiliaire', '', $line->label_operation), "Windows-1252", 'UTF-8');
- //Calcul de la longueur des numéros de comptes
- $taille_numero = strlen(length_accountg($line->numero_compte));
- //Création du numéro de client générique
- $numero_cpt_client = '411';
- for ($i = 1; $i <= ($taille_numero - 3); $i++) {
- $numero_cpt_client .= '0';
- }
- //Création des comptes auxiliaire des clients
- if (length_accountg($line->numero_compte) == $numero_cpt_client) {
- $tab[] = rtrim(length_accounta($line->subledger_account), "0");
- } else {
- $tab[] = length_accountg($line->numero_compte);
- }
- $nom_client = explode(" - ", $line->label_operation);
- $tab[] = mb_convert_encoding($nom_client[0], "Windows-1252", 'UTF-8');
- $tab[] = price($line->debit);
- $tab[] = price($line->credit);
- $tab[] = price($line->montant);
- $tab[] = $line->code_journal;
- $separator = $this->separator;
- print implode($separator, $tab) . $this->end_line;
- }
- }
- /**
- * trunc
- *
- * @param string $str String
- * @param integer $size Data to trunc
- * @return string
- */
- public static function trunc($str, $size)
- {
- return dol_trunc($str, $size, 'right', 'UTF-8', 1);
- }
- /**
- * toAnsi
- *
- * @param string $str Original string to encode and optionaly truncate
- * @param integer $size Truncate string after $size characters
- * @return string String encoded in Windows-1251 charset
- */
- public static function toAnsi($str, $size = -1)
- {
- $retVal = dol_string_nohtmltag($str, 1, 'Windows-1251');
- if ($retVal >= 0 && $size >= 0) {
- $retVal = mb_substr($retVal, 0, $size, 'Windows-1251');
- }
- return $retVal;
- }
- }
|