diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php
index 0b43e99b1d8..1a32c22e12f 100644
--- a/htdocs/accountancy/admin/export.php
+++ b/htdocs/accountancy/admin/export.php
@@ -30,6 +30,7 @@ require '../../main.inc.php';
// Class
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
+require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php';
$langs->load("compta");
$langs->load("bills");
@@ -195,12 +196,7 @@ if (! $conf->use_javascript_ajax) {
print "";
} else {
print '
';
- $listmodelcsv = array (
- '1' => $langs->trans("Modelcsv_normal"),
- '2' => $langs->trans("Modelcsv_CEGID"),
- '3' => $langs->trans("Modelcsv_COALA"),
- '4' => $langs->trans("Modelcsv_bob50")
- );
+ $listmodelcsv = AccountancyExport::getType();
print $form->selectarray("modelcsv", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0);
print ' | ';
diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php
index 515736580f8..b507c4dfffa 100644
--- a/htdocs/accountancy/bookkeeping/list.php
+++ b/htdocs/accountancy/bookkeeping/list.php
@@ -218,16 +218,31 @@ if ($action == 'delbookkeeping') {
exit();
}
} elseif ($action == 'export_csv') {
- $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
- $journal = 'bookkepping';
- include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
+ include DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php';
$result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter);
- if ($result < 0) {
+ if ($result < 0)
+ {
setEventMessages($object->error, $object->errors, 'errors');
}
+ else
+ {
+ if (in_array($conf->global->ACCOUNTING_EXPORT_MODELCSV, array(5,6))) // TODO remove the conditional and keep the code in the "else"
+ {
+ $accountancyexport = new AccountancyExport($db);
+ $accountancyexport->export($object->lines);
+ if (!empty($accountancyexport->errors)) setEventMessages('', $accountancyexport->errors, 'errors');
+ else exit;
+ }
+ }
+
+ // TODO remove next 3 lines and foreach to implement the AccountancyExport method for each model
+ $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+ $journal = 'bookkepping';
+ include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
+
foreach ( $object->lines as $line ) {
if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php
new file mode 100644
index 00000000000..acf490ae787
--- /dev/null
+++ b/htdocs/accountancy/class/accountancyexport.class.php
@@ -0,0 +1,270 @@
+
+ * Copyright (C) 2014 Juanjo Menent
+ * Copyright (C) 2015 Florian Henry
+ * Copyright (C) 2015 Raphaƫl Doursenaud
+ * Copyright (C) 2016 Pierre-Henry Favre
+ *
+ * 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 .
+ */
+
+/**
+ * \file htdocs/accountancy/class/accountancyexport.class.php
+ */
+
+/**
+ * Class AccountancyExport
+ *
+ * Manage the different format accountancy export
+ */
+require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
+
+class AccountancyExport
+{
+ /**
+ * @var Type of export
+ */
+ public static $EXPORT_TYPE_NORMAL = 1;
+ public static $EXPORT_TYPE_CEGID = 2;
+ public static $EXPORT_TYPE_COALA = 3;
+ public static $EXPORT_TYPE_BOB50 = 4;
+ public static $EXPORT_TYPE_CIEL = 5;
+ public static $EXPORT_TYPE_QUADRATUS = 6;
+
+ /**
+ * @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;
+
+ $this->db = &$db;
+ $this->separator = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+ $this->end_line = "\n";
+ return 1;
+ }
+
+ /**
+ * Get all export type are available
+ *
+ * @return array of type
+ */
+ public static function getType()
+ {
+ global $langs;
+
+ return array (
+ self::$EXPORT_TYPE_NORMAL => $langs->trans('Modelcsv_normal'),
+ 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')
+ );
+ }
+
+ /**
+ * Download the export
+ *
+ * @return void
+ */
+ public static function downloadFile()
+ {
+ global $conf;
+ $journal = 'bookkepping';
+ include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
+ }
+
+ /**
+ * Function who chose which export to use with the default config
+ *
+ * @return void
+ */
+ public function export(&$TData)
+ {
+ global $conf, $langs;
+
+ switch ($conf->global->ACCOUNTING_EXPORT_MODELCSV) {
+ case self::$EXPORT_TYPE_NORMAL:
+ $this->exportNormal($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:
+ $this->exportQuadratus($TData);
+ break;
+ default:
+ $this->errors[] = $langs->trans('accountancy_error_modelnotfound');
+ break;
+ }
+
+ if (empty($this->errors)) self::downloadFile();
+ }
+
+ /**
+ * Export format : Normal
+ *
+ * @return void
+ */
+ public function exportNormal(&$TData)
+ {
+
+ }
+
+ /**
+ * Export format : CEGID
+ *
+ * @return void
+ */
+ public function exportCegid(&$TData)
+ {
+
+ }
+
+ /**
+ * Export format : COALA
+ *
+ * @return void
+ */
+ public function exportCoala(&$TData)
+ {
+
+ }
+
+ /**
+ * Export format : BOB50
+ *
+ * @return void
+ */
+ public function exportBob50(&$TData)
+ {
+
+ }
+
+ /**
+ * Export format : CIEL
+ *
+ * @return void
+ */
+ public function exportCiel(&$TData)
+ {
+ global $conf;
+
+ $i=1;
+ $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd
+ foreach ($TData as $data)
+ {
+ $code_compta = $data->numero_compte;
+ if (!empty($data->code_tiers)) $code_compta = $data->code_tiers;
+
+ $Tab = array();
+ $Tab['num_ecriture'] = str_pad($i, 5);
+ $Tab['code_journal'] = str_pad($data->code_journal, 2);
+ $Tab['date_ecriture'] = $date_ecriture;
+ $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE);
+ $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12);
+ $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11);
+ $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref.$data->label_compte, 25), 25);
+ $Tab['montant'] = str_pad(abs($data->montant), 13, ' ', STR_PAD_LEFT);
+ $Tab['type_montant'] = str_pad($data->sens, 1);
+ $Tab['vide'] = str_repeat(' ', 18);
+ $Tab['intitule_compte'] = str_pad(self::trunc($data->label_compte, 34), 34);
+ $Tab['end'] = 'O2003';
+
+ $Tab['end_line'] = $this->end_line;
+
+ print implode($Tab);
+ $i++;
+ }
+ }
+
+ /**
+ * Export format : Quadratus
+ *
+ * @return void
+ */
+ public function exportQuadratus(&$TData)
+ {
+ global $conf;
+
+ $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy
+ foreach ($TData as $data)
+ {
+ $code_compta = $data->numero_compte;
+ if (!empty($data->code_tiers)) $code_compta = $data->code_tiers;
+
+ $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';
+ $Tab['date_ecriture'] = $date_ecriture;
+ $Tab['filler'] = ' ';
+ $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref.' '.$data->label_compte, 20), 20);
+ $Tab['sens'] = $data->sens; // C or D
+ $Tab['signe_montant'] = '+';
+ $Tab['montant'] = str_pad(abs($data->montant)*100, 12, '0', STR_PAD_LEFT); // TODO manage negative amount
+ $Tab['contrepartie'] = str_repeat(' ', 8);
+ if (!empty($data->date_echeance)) $Tab['date_echeance'] = dol_print_date($data->date_echeance, $conf->global->ACCOUNTING_EXPORT_DATE);
+ else $Tab['date_echeance'] = '000000';
+ $Tab['lettrage'] = str_repeat(' ', 5);
+ $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 5), 5);
+ $Tab['filler2'] = str_repeat(' ', 20);
+ $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);
+ $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref.' '.$data->label_compte, 32), 32);
+ $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10);
+ $Tab['filler4'] = str_repeat(' ', 73);
+
+ $Tab['end_line'] = $this->end_line;
+
+ print implode($Tab);
+ }
+ }
+
+ public static function trunc($str, $size)
+ {
+ return dol_trunc($str, $size, 'right', 'UTF-8', 1);
+ }
+
+}
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index f4b478b681e..4a0ebbe8988 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -170,7 +170,7 @@ class BookKeeping extends CommonObject
$this->piece_num = 0;
// first check if line not yet in bookkeeping
- $sql = "SELECT count(*)";
+ $sql = "SELECT count(*) as nb";
$sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE doc_type = '" . $this->doc_type . "'";
$sql .= " AND fk_docdet = " . $this->fk_docdet;
@@ -180,8 +180,8 @@ class BookKeeping extends CommonObject
$resql = $this->db->query($sql);
if ($resql) {
- $row = $this->db->fetch_array($resql);
- if ($row[0] == 0) {
+ $row = $this->db->fetch_object($resql);
+ if ($row->nb == 0) {
// Determine piece_num
$sqlnum = "SELECT piece_num";
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 8ffb4690dba..670875ec52b 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php';
// Langs
+$langs->load("commercial");
$langs->load("compta");
$langs->load("bills");
$langs->load("other");
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index f1b82c9be21..8685cb7d5d4 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -254,11 +254,11 @@ if ($result) {
print '';
print ' | ';
- print ' | ';
+ print '% | ';
print ' | ';
print ' | ';
print ' | ';
- print '% | ';
+ print '% | ';
print ' | ';
print ' | ';
print '';
|