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