diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index cf92905e041..720e020f7c8 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -46,7 +46,7 @@ $langs->load("main");
$langs->load("accountancy");
$id_journal = GETPOST('id_journal', 'int');
-$action = GETPOST('action','aZ09');
+$action = GETPOST('action','alpha');
$date_startmonth = GETPOST('date_startmonth');
$date_startday = GETPOST('date_startday');
@@ -54,6 +54,7 @@ $date_startyear = GETPOST('date_startyear');
$date_endmonth = GETPOST('date_endmonth');
$date_endday = GETPOST('date_endday');
$date_endyear = GETPOST('date_endyear');
+$in_bookkeeping = GETPOST('in_bookkeeping');
$now = dol_now();
@@ -113,6 +114,8 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$sql .= " AND fd.product_type IN (0,1)";
if ($date_start && $date_end)
$sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
+if ($in_bookkeeping == 'yes')
+ $sql .= " AND (f.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice') )";
$sql .= " ORDER BY f.datef";
dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
@@ -401,76 +404,18 @@ if ($action == 'writebookkeeping') {
$form = new Form($db);
// Export
-/*if ($action == 'export_csv') {
+if ($action == 'export_csv') {
$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+
include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
$companystatic = new Client($db);
+ $invoicestatic = new Facture($db);
- // Model Cegid Expert Export
- if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
- $sep = ";";
-
- foreach ( $tabfac as $key => $val ) {
- $companystatic->id = $tabcompany[$key]['id'];
- $companystatic->name = $tabcompany[$key]['name'];
- $companystatic->client = $tabcompany[$key]['code_client'];
-
- $invoicestatic->id = $key;
- $invoicestatic->ref = $val["ref"];
-
- $date = dol_print_date($val["date"], '%d%m%Y');
-
- foreach ( $tabttc[$key] as $k => $mt ) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
- print length_accounta(html_entity_decode($k)) . $sep;
- print ($mt < 0 ? 'C' : 'D') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account") . $sep;
- print $val["ref"];
- print "\n";
- }
-
- // Product / Service
- foreach ( $tabht[$key] as $k => $mt ) {
- $accountingaccount_static = new AccountingAccount($db);
- if ($accountingaccount_static->fetch(null, $k, true)) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep;
- print $val["ref"];
- print "\n";
- }
- }
-
- // TVA
- foreach ( $tabtva[$key] as $k => $mt ) {
- if ($mt) {
- print $date . $sep;
- print $sell_journal . $sep;
- print length_accountg(html_entity_decode($k)) . $sep;
- print $sep;
- print ($mt < 0 ? 'D' : 'C') . $sep;
- print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
- print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep;
- // print $langs->trans("VAT") . $sep;
- print $val["ref"];
- print "\n";
- }
- }
- }
- } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
- // Model Classic Export
- foreach ( $tabfac as $key => $val ) {
+ foreach ( $tabfac as $key => $val ) {
$companystatic->id = $tabcompany[$key]['id'];
$companystatic->name = $tabcompany[$key]['name'];
$companystatic->client = $tabcompany[$key]['code_client'];
@@ -479,49 +424,70 @@ $form = new Form($db);
$invoicestatic->ref = $val["ref"];
$date = dol_print_date($val["date"], 'day');
-
+
foreach ( $tabttc[$key] as $k => $mt ) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account") . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep;
+ print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+ print '"' . $langs->trans("Code_tiers") . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
// Product / Service
foreach ( $tabht[$key] as $k => $mt ) {
$accountingaccount = new AccountingAccount($db);
$accountingaccount->fetch(null, $k, true);
+
if ($mt) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep;
+ print '"' . utf8_decode (dol_trunc($companystatic->name, 16) ) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
}
// VAT
foreach ( $tabtva[$key] as $k => $mt ) {
+
+
+
if ($mt) {
- print '"' . $date . '"' . $sep;
- print '"' . $val["ref"] . '"' . $sep;
- print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
- print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
- print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
- print '"' . ($mt >= 0 ? price($mt) : '') . '"';
- print "\n";
+ print '"' . $key . '"' . $sep;
+ print '"' . $date . '"' . $sep;
+ print '"' . $val["ref"] . '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+ print " " . $sep;
+ print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key]. '"' . $sep;
+ print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ). ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
+ print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+ print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+ print '"' . $sell_journal . '"' ;
+ print "\n";
}
}
- }
}
-}
-*/
+ }
+
if (empty($action) || $action == 'view') {
@@ -545,12 +511,6 @@ if (empty($action) || $action == 'view') {
journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink);
- /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) {
- print '';
- } else {
- print '';
- }*/
-
// Button to write into Ledger
if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') {
print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone");
@@ -563,6 +523,7 @@ if (empty($action) || $action == 'view') {
else {
print '';
}
+ print '';
print '';
print '