From 65070afce447d2ad7d728d1f6063b2759347bc91 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 22 May 2019 17:22:49 +0200 Subject: [PATCH] WIP --- htdocs/accountancy/closure/index.php | 103 +++----------------- htdocs/core/menus/standard/eldy.lib.php | 4 +- htdocs/core/modules/modAccounting.class.php | 2 +- htdocs/langs/en_US/accountancy.lang | 4 + 4 files changed, 23 insertions(+), 90 deletions(-) diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index 25fdf013f9a..f060be19440 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2019 Open-DSI * * 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 @@ -58,96 +58,32 @@ $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start); $search_date_end = dol_get_last_day($year_end, $month_end); $year_current = $year_start; -// Validate History -$action = GETPOST('action', 'aZ09'); - - /* * Actions */ -if ($action == 'clean' || $action == 'validatehistory') -{ - // Clean database - $db->begin(); - $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql1 .= " SET fk_code_ventilation = 0"; - $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN'; - $sql1 .= ' (SELECT accnt.rowid '; - $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; - $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; - $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ' AND accnt.entity = '.$conf->entity.')'; - $sql1 .= ' AND fd.fk_facture IN (SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture WHERE entity = '.$conf->entity.')'; - $sql1 .= ' AND fk_code_ventilation <> 0'; - - dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); - $resql1 = $db->query($sql1); - if (! $resql1) { - $error ++; - $db->rollback(); - setEventMessages($db->lasterror(), null, 'errors'); - } else { - $db->commit(); - } - // End clean database -} - -if ($action == 'validatehistory') { - - $error = 0; - $db->begin(); - - // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind - if ($db->type == 'pgsql') { - $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet"; - $sql1 .= " SET fk_code_ventilation = accnt.rowid"; - $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; - $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; - $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0"; - } else { - $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " SET fk_code_ventilation = accnt.rowid"; - $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity; - $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; - $sql1 .= " AND fd.fk_code_ventilation = 0"; - } - - dol_syslog('htdocs/accountancy/customer/index.php'); - - $resql1 = $db->query($sql1); - if (! $resql1) { - $error ++; - $db->rollback(); - setEventMessages($db->lasterror(), null, 'errors'); - } else { - $db->commit(); - setEventMessages($langs->trans('AutomaticBindingDone'), null, 'mesgs'); - } -} - /* * View */ -llxHeader('', $langs->trans("CustomersVentilation")); +llxHeader('', $langs->trans("Closure")); $textprevyear = '' . img_previous() . ''; $textnextyear = ' ' . img_next() . ''; -print load_fiche_titre($langs->trans("CustomersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy'); +print load_fiche_titre($langs->trans("Closure") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy'); -print $langs->trans("DescVentilCustomer") . '
'; +print $langs->trans("DescClosure") . '
'; print '
'; $y = $year_current; -$buttonbind = '' . $langs->trans("ValidateHistory") . ''; +$buttonbind = '' . $langs->trans("ValidateMovements") . ''; -print_barre_liste($langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); +print_barre_liste($langs->trans("OverviewOfMovementsNotValidated"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); print '
'; print ''; @@ -158,25 +94,19 @@ for($i = 1; $i <= 12; $i ++) { } print ''; -$sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number') . " AS codecomptable,"; -$sql .= " " . $db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label') . " AS intitule,"; +$sql = "SELECT COUNT(b.rowid) as detail,"; for($i = 1; $i <= 12; $i ++) { $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START?$conf->global->SOCIETE_FISCAL_MONTH_START:1) - 1; if ($j > 12) $j-=12; - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $j, 'fd.total_ht', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; + $sql .= " SUM(" . $db->ifsql('MONTH(b.doc_date)=' . $j, '1', '0') . ") AS month" . str_pad($j, 2, '0', STR_PAD_LEFT) . ","; } -$sql .= " SUM(fd.total_ht) as total"; -$sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; -$sql .= " WHERE f.datef >= '" . $db->idate($search_date_start) . "'"; -$sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'"; -$sql .= " AND f.fk_statut > 0"; -$sql .= " AND f.entity IN (" . getEntity('invoice', 0) . ")"; // We don't share object for accountancy -$sql .= " AND aa.account_number IS NULL"; -$sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label"; +$sql .= " COUNT(b.rowid) as total"; +$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as b"; +$sql .= " WHERE b.doc_date >= '" . $db->idate($search_date_start) . "'"; +$sql .= " AND b.doc_date <= '" . $db->idate($search_date_end) . "'"; +$sql .= " AND b.entity IN (" . getEntity('bookkeeping', 0) . ")"; // We don't share object for accountancy -dol_syslog('htdocs/accountancy/customer/index.php sql=' . $sql, LOG_DEBUG); +dol_syslog('htdocs/accountancy/closure/index.php sql=' . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -184,11 +114,10 @@ if ($resql) { while ( $row = $db->fetch_row($resql)) { print ''; - for($i = 2; $i <= 12; $i ++) { + for($i = 1; $i <= 12; $i ++) { print ''; } - print ''; - print ''; + print ''; print ''; } $db->free($resql); diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 47ff76d6b56..a432069c9fa 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -1298,7 +1298,7 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM $newmenu->add("/accountancy/closure/index.php?mainmenu=accountancy&leftmenu=accountancy_closure", $langs->trans("MenuAccountancyClosure"), 1, $user->rights->accounting->fiscalyear->closure, '', $mainmenu, 'closure'); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_closure/', $leftmenu)) { - $newmenu->add("/accountancy/closure/validation.php?leftmenu=accountancy_closure", $langs->trans("MenuAccountancyValidationMovements"), 2, $user->rights->accounting->fiscalyear->closure); + $newmenu->add("/accountancy/closure/validate.php?leftmenu=accountancy_closure", $langs->trans("MenuAccountancyValidationMovements"), 2, $user->rights->accounting->fiscalyear->closure); } } @@ -1309,7 +1309,7 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM // Fiscal year - Not really yet used. In a future will lock some periods. if (! empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { - $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("FiscalPeriod"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'fiscalyear', 20); + $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("FiscalPeriod"), 1, $user->rights->accounting->fiscalyear->write, '', $mainmenu, 'fiscalyear', 20); } $newmenu->add("/accountancy/admin/journals_list.php?id=35&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("AccountingJournals"), 1, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_journal', 30); diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 956f7ea24fc..d1a9de7bef4 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -225,7 +225,7 @@ class modAccounting extends DolibarrModules $this->rights[$r][2] = 'r'; $this->rights[$r][3] = 0; $this->rights[$r][4] = 'fiscalyear'; - $this->rights[$r][5] = ''; + $this->rights[$r][5] = 'write'; $r++; $this->rights[$r][0] = 50431; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 17bbfc41f66..01c5752f4b5 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -242,6 +242,10 @@ DescVentilExpenseReport=Consult here the list of expense report lines bound (or DescVentilExpenseReportMore=If you setup accounting account on type of expense report lines, the application will be able to make all the binding between your expense report lines and the accounting account of your chart of accounts, just in one click with the button "%s". If account was not set on fees dictionary or if you still have some lines not bound to any account, you will have to make a manual binding from the menu "%s". DescVentilDoneExpenseReport=Consult here the list of the lines of expenses reports and their fees accounting account +DescClosure=Consult here the number of movements by month who are not validated & fiscal years already open +OverviewOfMovementsNotValidated=Step 1/ Overview of movements not validated. (Necessary to close a fiscal year) +ValidateMovements=Validate movements + ValidateHistory=Bind Automatically AutomaticBindingDone=Automatic binding done
' . $langs->trans("Total") . '
' . price($row[$i]) . '' . price($row[13]) . '' . price($row[14]) . '' . price($row[13]) . '