From 703d3d90eb6180da8548a721e40b14293431972b Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 24 Nov 2018 22:40:04 +0100 Subject: [PATCH 1/4] Revert "Fix create accounting account from balance" This reverts commit 9154fd366fb30494a0be80f889f76953174efa93. --- htdocs/accountancy/admin/card.php | 9 ++++----- htdocs/accountancy/bookkeeping/balance.php | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 33fdb675ac0..74958d606ec 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -1,7 +1,7 @@ - * Copyright (C) 2013-2018 Alexandre Spangaro - * Copyright (C) 2014 Florian Henry +/* Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2014 Florian Henry * * 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 @@ -41,7 +41,6 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $rowid = GETPOST('rowid', 'int'); $cancel = GETPOST('cancel','alpha'); -$accountingaccount = GETPOST('accountingaccount','alpha'); // Security check @@ -230,7 +229,7 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print ''; + print ''; // Label print '' . $langs->trans("Label") . ''; diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 5183281f4cd..e807d1acced 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -266,7 +266,7 @@ if ($action != 'export_csv') $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); if (empty($description)) { - $link = '' . img_edit_add() . ''; + $link = '' . img_edit_add() . ''; } print ''; From 088c002ed130f0682653d56ac933711b8c7aae89 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 2 Dec 2018 11:01:11 +0100 Subject: [PATCH 2/4] NEW: Add stats on entries & movements by fiscal year --- htdocs/accountancy/admin/card.php | 15 +++--- htdocs/accountancy/admin/fiscalyear.php | 24 +++++---- htdocs/accountancy/bookkeeping/balance.php | 2 +- htdocs/compta/bank/class/account.class.php | 6 +-- htdocs/core/class/fiscalyear.class.php | 63 +++++++++++++++++++++- htdocs/langs/en_US/accountancy.lang | 2 + 6 files changed, 90 insertions(+), 22 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 74958d606ec..c7a46c48323 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -1,7 +1,7 @@ - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2014 Florian Henry +/* Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2013-2018 Alexandre Spangaro + * Copyright (C) 2014 Florian Henry * * 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 @@ -18,9 +18,9 @@ */ /** - * \file htdocs/accountancy/admin/card.php - * \ingroup Advanced accountancy - * \brief Card of accounting account + * \file htdocs/accountancy/admin/card.php + * \ingroup Advanced accountancy + * \brief Card of accounting account */ require '../../main.inc.php'; @@ -41,6 +41,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $rowid = GETPOST('rowid', 'int'); $cancel = GETPOST('cancel','alpha'); +$accountingaccount = GETPOST('accountingaccount','alpha'); // Security check @@ -229,7 +230,7 @@ if ($action == 'create') { // Account number print '' . $langs->trans("AccountNumber") . ''; - print ''; + print ''; // Label print '' . $langs->trans("Label") . ''; diff --git a/htdocs/accountancy/admin/fiscalyear.php b/htdocs/accountancy/admin/fiscalyear.php index 62eda456fe7..63e21d0170b 100644 --- a/htdocs/accountancy/admin/fiscalyear.php +++ b/htdocs/accountancy/admin/fiscalyear.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2013-2018 Alexandre Spangaro * * 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 @@ -16,9 +16,9 @@ */ /** - * \file htdocs/accountancy/admin/fiscalyear.php - * \ingroup Advanced accountancy - * \brief Setup page to configure fiscal year + * \file htdocs/accountancy/admin/fiscalyear.php + * \ingroup Advanced accountancy + * \brief Setup page to configure fiscal year */ require '../../main.inc.php'; @@ -45,8 +45,8 @@ $langs->loadLangs(array("admin","compta")); // Security check if ($user->societe_id > 0) accessforbidden(); -if (! $user->rights->accounting->fiscalyear) // If we can read accounting records, we shoul be able to see fiscal year. - accessforbidden(); +if (! $user->rights->accounting->fiscalyear) // If we can read accounting records, we should be able to see fiscal year. + accessforbidden(); $error = 0; @@ -113,23 +113,26 @@ if ($result) if (! empty($user->rights->accounting->fiscalyear)) { - $addbutton = '' . $langs->trans("NewFiscalYear") . ''; + $addbutton = '' . $langs->trans("NewFiscalYear") .''; } else { - $addbutton = '' . $langs->trans("NewFiscalYear") . ''; + $addbutton = '' . $langs->trans("NewFiscalYear") .''; } $title = $langs->trans('AccountingPeriods'); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $params, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy', 0, $addbutton, '', $limit, 1); // Load attribute_label - print ''; + print '
'; + print '
'; print ''; print ''; print ''; print ''; print ''; + print ''; + print ''; print ''; print ''; @@ -144,6 +147,8 @@ if ($result) print ''; print ''; print ''; + print ''; + print ''; print ''; print ''; $i++; @@ -152,6 +157,7 @@ if ($result) print ''; } print '
' . $langs->trans("Ref") . '' . $langs->trans("Label") . '' . $langs->trans("DateStart") . '' . $langs->trans("DateEnd") . '' . $langs->trans("NumberOfAccountancyEntries") . '' . $langs->trans("NumberOfAccountancyMovements") . '' . $langs->trans("Statut") . '
' . $obj->label . '' . dol_print_date($db->jdate($obj->date_start), 'day') . '' . dol_print_date($db->jdate($obj->date_end), 'day') . '' . $object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end) . '' . $object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end) . '' . $fiscalyearstatic->LibStatut($obj->statut, 5) . '
' . $langs->trans("None") . '
'; + print ''; } else { dol_print_error($db); } diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index b0b6c8fe7f2..de7fa495770 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -265,7 +265,7 @@ if ($action != 'export_csv') $description = $object->get_compte_desc($line->numero_compte); // Search description of the account $root_account_description = $object->get_compte_racine($line->numero_compte); if (empty($description)) { - $link = '' . img_edit_add() . ''; + $link = '' . img_edit_add() . ''; } print ''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 7cb6b09fbaf..6557a8f8874 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -256,7 +256,7 @@ class Account extends CommonObject } /** - * Shows the account number in the appropiate format + * Shows the account number in the appropriate format * * @return string */ @@ -419,7 +419,7 @@ class Account extends CommonObject */ function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='',$banque='', $accountancycode='', $datev=null) { - // Deprecatîon warning + // Deprecation warning if (is_numeric($oper)) { dol_syslog(__METHOD__ . ": using numeric operations is deprecated", LOG_WARNING); } @@ -430,7 +430,7 @@ class Account extends CommonObject $now=dol_now(); - if (is_numeric($oper)) // Clean oper to have a code instead of a rowid + if (is_numeric($oper)) // Clean operation to have a code instead of a rowid { $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE id=".$oper; diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 985d67d5cae..5978a2ca8b7 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -21,13 +21,18 @@ * \brief File of class to manage fiscal years */ -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; /** * Class to manage fiscal year */ class Fiscalyear extends CommonObject { + /** + * @var DoliDB Database handler. + */ + public $db; + /** * @var string ID to identify managed object */ @@ -82,8 +87,10 @@ class Fiscalyear extends CommonObject * * @param DoliDB $db Database handler */ - function __construct($db) + function __construct(DoliDB $db) { + global $langs; + $this->db = $db; $this->statuts_short = array(0 => 'Opened', 1 => 'Closed'); @@ -354,4 +361,56 @@ class Fiscalyear extends CommonObject dol_print_error($this->db); } } + + /** + * Return the number of entries by fiscal year + * + * @param int $year Year to scan + * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month + * @return array Array of values + */ + function getAccountancyEntriesByFiscalYear($datestart, $dateend) + { + global $conf; + + $sql = "SELECT count(DISTINCT piece_num) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; + $sql.= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'"; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $nb = $obj->nb; + } + else dol_print_error($this->db); + + return $nb; + } + + /** + * Return the number of movements by fiscal year + * + * @param string $year Year to scan + * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month + * @return array Array of values + */ + function getAccountancyMovementsByFiscalYear($datestart, $dateend) + { + global $conf; + + $sql = "SELECT count(rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; + $sql.= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'"; + + $resql=$this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $nb = $obj->nb; + } + else dol_print_error($this->db); + + return $nb; + } } diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index e2f6083e6a6..30b015523a0 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -254,6 +254,8 @@ AccountingJournalType8=Inventory AccountingJournalType9=Has-new ErrorAccountingJournalIsAlreadyUse=This journal is already use AccountingAccountForSalesTaxAreDefinedInto=Note: Accounting account for Sales tax are defined into menu %s - %s +NumberOfAccountancyEntries=Number of entries +NumberOfAccountancyMovements=Number of movements ## Export ExportDraftJournal=Export draft journal From 7eee155439ab34a73e649f5359780036775bdae6 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 2 Dec 2018 14:07:38 +0100 Subject: [PATCH 3/4] Correct documentation --- htdocs/core/class/fiscalyear.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 5978a2ca8b7..e49cfe31938 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -365,9 +365,9 @@ class Fiscalyear extends CommonObject /** * Return the number of entries by fiscal year * - * @param int $year Year to scan - * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month - * @return array Array of values + * @param int $datestart Date start to scan + * @param int $dateend Date end to scan + * @return string Number of entries */ function getAccountancyEntriesByFiscalYear($datestart, $dateend) { @@ -391,9 +391,9 @@ class Fiscalyear extends CommonObject /** * Return the number of movements by fiscal year * - * @param string $year Year to scan - * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month - * @return array Array of values + * @param int $datestart Date start to scan + * @param int $dateend Date end to scan + * @return string Number of movements */ function getAccountancyMovementsByFiscalYear($datestart, $dateend) { From 3b8dd718165a87e05ba2369fcd0126b75775ecce Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 3 Dec 2018 21:25:44 +0100 Subject: [PATCH 4/4] Remove public $db --- htdocs/core/class/fiscalyear.class.php | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index e49cfe31938..c1c288cbf79 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014-2018 Alexandre Spangaro * * 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 @@ -28,11 +28,6 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; */ class Fiscalyear extends CommonObject { - /** - * @var DoliDB Database handler. - */ - public $db; - /** * @var string ID to identify managed object */ @@ -65,9 +60,9 @@ class Fiscalyear extends CommonObject public $rowid; /** - * @var string fiscal year label - */ - public $label; + * @var string fiscal year label + */ + public $label; public $date_start; public $date_end; @@ -170,10 +165,10 @@ class Fiscalyear extends CommonObject // Check parameters if (empty($this->date_start) && empty($this->date_end)) - { - $this->error='ErrorBadParameter'; - return -1; - } + { + $this->error='ErrorBadParameter'; + return -1; + } $this->db->begin(); @@ -274,7 +269,7 @@ class Fiscalyear extends CommonObject return $this->LibStatut($this->statut,$mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** * Give a label from a status * @@ -284,7 +279,7 @@ class Fiscalyear extends CommonObject */ function LibStatut($statut,$mode=0) { - // phpcs:enable + // phpcs:enable global $langs; if ($mode == 0)