diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index 0566b7dda17..b08391495c1 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -56,7 +56,7 @@ $langs->load("bank"); $langs->load('bills'); $langs->load("accountancy"); -$id_accountancy_journal = GETPOST('id_account'); +$id_bank_account = GETPOST('id_account','int'); $date_startmonth = GETPOST('date_startmonth'); $date_startday = GETPOST('date_startday'); @@ -67,17 +67,12 @@ $date_endyear = GETPOST('date_endyear'); $action = GETPOST('action'); // Security check -if ($user->societe_id > 0) +if ($user->societe_id > 0 && empty($id_bank_account)) accessforbidden(); /* * View */ -if (empty($id_accountancy_journal)) -{ - accessforbidden(); -} - $year_current = strftime("%Y", dol_now()); $pastmonth = strftime("%m", dol_now()) - 1; $pastmonthyear = $year_current; @@ -104,7 +99,7 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b"; $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; -$sql .= " WHERE ba.rowid=".$id_accountancy_journal; +$sql .= " WHERE ba.rowid=".$id_bank_account; if (! empty($conf->multicompany->enabled)) { $sql .= " AND ba.entity = " . $conf->entity; } @@ -121,6 +116,11 @@ $chargestatic = new ChargeSociales($db); $paymentvatstatic = new TVA($db); $paymentsalstatic = new PaymentSalary($db); +// Get code of finance journal +$bank_code_journal = new Account($db); +$result=$bank_code_journal->fetch($id_bank_account); +$journal=$bank_code_journal->accountancy_journal; + dol_syslog("accountancy/journal/bankjournal.php:: sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); if ($result) { @@ -278,7 +278,7 @@ if ($result) { */ // Write bookkeeping -if ($action == 'writeBookKeeping') +if ($action == 'writebookkeeping') { $error = 0; foreach ( $tabpay as $key => $val ) @@ -299,7 +299,7 @@ if ($action == 'writeBookKeeping') $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt >= 0 ? $mt : 0); $bookkeeping->credit = ($mt < 0 ? - $mt : 0); - $bookkeeping->code_journal = $conf->global->ACCOUNTING_BANK_JOURNAL; + $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; if ($tabtype[$key] == 'payment') { @@ -350,7 +350,7 @@ if ($action == 'writeBookKeeping') $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0 ? - $mt : 0); $bookkeeping->credit = ($mt >= 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_BANK_JOURNAL; + $bookkeeping->code_journal = $journal; $bookkeeping->fk_user_author = $user->id; if ($tabtype[$key] == 'sc') { @@ -420,10 +420,8 @@ if ($action == 'writeBookKeeping') } } // Export -if ($action == 'export_csv') -{ +if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $bank_journal = $conf->global->ACCOUNTING_BANK_JOURNAL; header('Content-Type: text/csv'); header('Content-Disposition: attachment;filename=journal_banque.csv'); @@ -434,16 +432,20 @@ if ($action == 'export_csv') { $sep = ";"; - foreach ( $tabpay as $key => $val ) { + foreach ($tabpay as $key => $val) + { $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; + $companystatic->client = $tabcompany[$key]['code_client']; + + $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); // Bank foreach ( $tabbq[$key] as $k => $mt ) { print $date . $sep; - print $bank_journal . $sep; + print $journal . $sep; print length_accountg(html_entity_decode($k)) . $sep; print $sep; print ($mt < 0 ? 'C' : 'D') . $sep; @@ -461,7 +463,7 @@ if ($action == 'export_csv') if ($mt) { print $date . $sep; - print $bank_journal . $sep; + print $journal . $sep; if ($val["lib"] == '(SupplierInvoicePayment)') { print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep; } else { @@ -483,8 +485,8 @@ if ($action == 'export_csv') if (1) { print $date . $sep; - print $bank_journal . $sep; - print $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . $sep; + print $journal . $sep; + print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep; print $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; @@ -495,8 +497,7 @@ if ($action == 'export_csv') } } } - } else // Model Classic Export - { + } else { // Model Classic Export foreach ( $tabpay as $key => $val ) { $date = dol_print_date($db->jdate($val["date"]), 'day'); @@ -538,7 +539,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; - print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . '"' . $sep; + print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; print '"' . $langs->trans("Bank") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; @@ -548,67 +549,25 @@ if ($action == 'export_csv') } } } -} -else -{ - +} else { $form = new Form($db); - llxHeader('', $langs->trans("BankJournal")); + llxHeader('', $langs->trans("FinanceJournal")); - $namereport = $langs->trans("BankJournal"); - $description = $langs->trans("DescBankJournal"); + $nom = $langs->trans("FinanceJournal" . ' - ' . $journal); + $builddate = time(); + $description = $langs->trans("DescFinanceJournal") . '
'; $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); - // Report - $h=0; - $head[$h][0] = $_SERVER["PHP_SELF"].'?id_account='.$id_accountancy_journal; - $head[$h][1] = $langs->trans("Report"); - $head[$h][2] = 'card'; - - dol_fiche_head($head, 'card', $langs->trans("BankJournal"), 0, 'payment'); - - print '
'; - print ''; - - // Title - print ''; - print ''; - print ''; - print ''; - print ''; - - // Period report - print ''; - print ''; - if (! $periodlink) print ''; - print ''; - - // Description - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - - print '
'.$langs->trans("ReportName").''.$namereport.'
'.$langs->trans("ReportPeriod").''; - else print ''; - if ($period) print $period; - if ($periodlink) print ''.$periodlink; - print '
'.$langs->trans("ReportDescription").''.$description.'
'; - - print '
'; - - print ''; - // End report + + $varlink = 'id_account='.$id_bank_account; + report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink); + print ''; - print ''; - + print ''; + print '