From ea1a81f5f4dc8b02d47a8d0bf67ce594f6a44724 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 9 Dec 2015 11:53:38 +0100 Subject: [PATCH 1/3] FIX : Comptability when multiple account charts --- htdocs/accountancy/customer/list.php | 16 +++++++++++----- htdocs/accountancy/supplier/list.php | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 820596de166..4800737528d 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -87,10 +87,10 @@ if (! $user->rights->accounting->ventilation->dispatch) accessforbidden(); $formventilation = new FormVentilation($db); - $accounting = new AccountingAccount($db); -$aarowid_s = $accounting->fetch('', ACCOUNTING_SERVICE_SOLD_ACCOUNT); -$aarowid_p = $accounting->fetch('', ACCOUNTING_PRODUCT_SOLD_ACCOUNT); +$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT,1); +$aarowid_p = $accounting->fetch('',$conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT,1); + // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { @@ -278,6 +278,8 @@ if ($result) { $code_sell_p_notset = ''; $objp->aarowid_suggest = $objp->aarowid; + + if (! empty($objp->code_sell)) { $objp->code_sell_p = $objp->code_sell; } else { @@ -290,12 +292,14 @@ if ($result) { } if ($objp->type_l == 1) { $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); - if ($objp->aarowid == '') + if ($objp->aarowid == '') { $objp->aarowid_suggest = $aarowid_s; + } } elseif ($objp->type_l == 0) { $objp->code_sell_l = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); - if ($objp->aarowid == '') + if ($objp->aarowid == '') { $objp->aarowid_suggest = $aarowid_p; + } } if ($objp->code_sell_l != $objp->code_sell_p) $code_sell_p_l_differ = 'color:red'; @@ -311,10 +315,12 @@ if ($result) { $product_static->id = $objp->product_id; $product_static->type = $objp->type; print ''; + if ($product_static->id) print $product_static->getNomUrl(1); else print ' '; + print ''; print '' . dol_trunc($objp->product_label, 24) . ''; diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index 891d8b1439e..c94c8612535 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -94,8 +94,8 @@ $formventilation = new FormVentilation($db); $accounting = new AccountingAccount($db); // TODO: we should need to check if result is a really exist accountaccount rowid..... -$aarowid_s = $accounting->fetch('', ACCOUNTING_SERVICE_BUY_ACCOUNT); -$aarowid_p = $accounting->fetch('', ACCOUNTING_PRODUCT_BUY_ACCOUNT); +$aarowid_s = $accounting->fetch('', $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT,1); +$aarowid_p = $accounting->fetch('', $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT,1); // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers From 96a95d6ae18f3afec8970429c01a5154e3b85001 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Wed, 9 Dec 2015 12:55:08 +0100 Subject: [PATCH 2/3] Debug accountancy on 3.9 --- htdocs/accountancy/bookkeeping/list.php | 29 ++++- .../accountancy/class/bookkeeping.class.php | 30 +++++ .../class/html.formventilation.class.php | 2 +- htdocs/accountancy/journal/bankjournal.php | 114 ++++++------------ .../accountancy/journal/purchasesjournal.php | 4 +- htdocs/core/lib/report.lib.php | 12 +- .../install/mysql/migration/3.8.0-3.9.0.sql | 3 + .../tables/llx_accounting_bookkeeping.sql | 2 +- 8 files changed, 112 insertions(+), 84 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index b9164329031..ec108738647 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -30,6 +30,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; // Langs $langs->load("accountancy"); @@ -52,6 +53,7 @@ if ($sortfield == "") $offset = $conf->liste_limit * $page; $formventilation = new FormVentilation($db); +$formother = new FormOther($db); if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { @@ -77,7 +79,20 @@ if ($action == 'delbookkeeping') { setEventMessages($object->error, $object->errors, 'errors'); } } -} // Export +} +elseif ($action == 'delbookkeepingyear') { + + $delyear = GETPOST('delyear', 'int'); + + if (! empty($delyear)) { + $object = new BookKeeping($db); + $result = $object->delete_by_year($delyear); + Header("Location: list.php"); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } +}// Export else if ($action == 'export_csv') { header('Content-Type: text/csv'); @@ -147,7 +162,7 @@ else { print_barre_liste($langs->trans("Bookkeeping"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num); - print '
'; + /*print ''; print ''; print ''; @@ -155,6 +170,16 @@ else { print '
'; + print '
';*/ + + print '
'; + print ''; + print ''; + + print $formother->select_year(GETPOST('delyear'),'delyear'); + + print '
'; + print '
'; print '
'; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 141b122690c..2eb952a42a3 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -372,6 +372,36 @@ class BookKeeping extends CommonObject $this->db->commit(); return 1; } + + /** + * Delete bookkepping by importkey + * + * @param string $importkey Import key + * @return int Result + */ + function delete_by_year($delyear) { + $this->db->begin(); + + // first check if line not yet in bookkeeping + $sql = "DELETE"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping "; + $sql .= " WHERE YEAR(doc_date) = ".$delyear; + + $resql = $this->db->query($sql); + + if (! $resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + $this->db->rollback(); + return - 1; + } + + $this->db->commit(); + return 1; + } /** * Create object into database diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index de94d645c92..f92f5b3ab88 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -70,7 +70,7 @@ class FormVentilation extends Form $selected = ' selected '; } - $out .= ''; + $out .= ''; $i ++; } diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index be136a38b98..34ebcaf43a9 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -16,7 +16,7 @@ * 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 fr more details. + * 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 . @@ -57,7 +57,7 @@ $langs->load("bank"); $langs->load('bills'); $langs->load("accountancy"); -$id_accountancy_journal = GETPOST('id_account','int'); +$id_bank_account = GETPOST('id_account','int'); $date_startmonth = GETPOST('date_startmonth'); $date_startday = GETPOST('date_startday'); @@ -70,17 +70,12 @@ $action = GETPOST('action'); $now = dol_now(); // 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; @@ -107,7 +102,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; } @@ -125,7 +120,12 @@ $paymentdonstatic = new PaymentDonation($db); $paymentvatstatic = new TVA($db); $paymentsalstatic = new PaymentSalary($db); -dol_syslog("accountancy/journal/bankjournal.php:: sql=" . $sql, LOG_DEBUG); +// 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", LOG_DEBUG); $result = $db->query($sql); if ($result) { @@ -288,8 +288,10 @@ if ($result) { */ // Write bookkeeping -if ($action == 'writeBookKeeping') +if ($action == 'writebookkeeping') { + $now=dol_now(); + $error = 0; foreach ( $tabpay as $key => $val ) { @@ -309,8 +311,9 @@ 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; + $bookkeeping->date_create=$now; if ($tabtype[$key] == 'payment') { @@ -327,7 +330,7 @@ if ($action == 'writeBookKeeping') } } else if ($tabtype[$key] == 'payment_supplier') { - $sqlmid = 'SELECT facf.facnumber'; + $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; @@ -336,7 +339,7 @@ if ($action == 'writeBookKeeping') $resultmid = $db->query($sqlmid); if ($resultmid) { $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; + $bookkeeping->doc_ref = $objmid->ref_supplier.' ('.$objmid->ref.')';; } } @@ -360,8 +363,9 @@ 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; + $bookkeeping->date_create=$now; if ($tabtype[$key] == 'sc') { $bookkeeping->code_tiers = ''; @@ -383,7 +387,7 @@ if ($action == 'writeBookKeeping') $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; } else if ($tabtype[$key] == 'payment_supplier') { - $sqlmid = 'SELECT facf.facnumber'; + $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; @@ -392,7 +396,7 @@ if ($action == 'writeBookKeeping') $resultmid = $db->query($sqlmid); if ($resultmid) { $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; + $bookkeeping->doc_ref = $objmid->ref_supplier.' ('.$objmid->ref.')'; } $bookkeeping->code_tiers = $k; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; @@ -433,7 +437,6 @@ if ($action == 'writeBookKeeping') if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $journal = $conf->global->ACCOUNTING_BANK_JOURNAL; include DOL_DOCUMENT_ROOT.'/accountancy/tpl/export_journal.tpl.php'; @@ -443,16 +446,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; @@ -557,67 +564,26 @@ 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 '