From 2af8b7078ce8b13825ee9e900e2c028c99853505 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 31 Mar 2021 19:50:43 +0200 Subject: [PATCH] Fix turnover calculation was wrong. We must include only --- htdocs/accountancy/admin/account.php | 2 +- htdocs/accountancy/journal/sellsjournal.php | 1 + htdocs/compta/stats/index.php | 24 ++++++++++++------- htdocs/compta/stats/supplier_turnover.php | 20 ++++++++++++---- .../stats/supplier_turnover_by_thirdparty.php | 2 +- htdocs/langs/en_US/compta.lang | 2 ++ 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 39bf2b07b29..4b18fc03c5b 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -349,7 +349,7 @@ if ($resql) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1"; $sql .= " WHERE a.active = 1"; dol_syslog('accountancy/admin/account.php $sql='.$sql); - print $sql; + $resqlchart = $db->query($sql); if ($resqlchart) { $numbis = $db->num_rows($resqlchart); diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index d1361d1296e..e5f52cbc2ea 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -115,6 +115,7 @@ if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " p.accountancy_code_sell"; } $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; +$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = fd.fk_product"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as pa ON pa.fk_product = p.rowid AND pa.entity = " . ((int) $conf->entity); } diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index d1a2d422732..58d4458ca6a 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -179,7 +179,7 @@ if ($modecompta == "CREANCES-DETTES") { $calcmode = str_replace('{link2}', '', $calcmode); //$calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); - $description = $langs->trans("RulesCATotalSaleJournal"); + $description = $langs->trans("RulesSalesTurnoverOfIncomeAccounts"); $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } @@ -227,17 +227,25 @@ if ($modecompta == 'CREANCES-DETTES') { $sql .= " AND f.fk_soc = ".((int) $socid); } } elseif ($modecompta == "BOOKKEEPING") { - $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.credit) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; - $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities - $sql .= " AND aj.entity = ".$conf->entity; - $sql .= " AND b.code_journal = aj.code AND aj.nature = 2"; // @todo currently count amount in sale journal, but we need to define a category group for turnover -} + $pcgverid = $conf->global->CHARTOFACCOUNTS; + $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version'); + if (empty($pcgvercode)) { + $pcgvercode = $pcgverid; + } + $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,"; + $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa"; + $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities + $sql .= " AND b.numero_compte = aa.account_number"; + $sql .= " AND b.doc_type = 'customer_invoice'"; + $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'"; + $sql .= " AND aa.pcg_type = 'INCOME'"; // TODO Be able to use a custom group +} $sql .= " GROUP BY dm"; $sql .= " ORDER BY dm"; // TODO Add a filter on $date_start and $date_end to reduce quantity on data -//print $sql; $minyearmonth = $maxyearmonth = 0; diff --git a/htdocs/compta/stats/supplier_turnover.php b/htdocs/compta/stats/supplier_turnover.php index afec3c3d124..dc8417e58a1 100644 --- a/htdocs/compta/stats/supplier_turnover.php +++ b/htdocs/compta/stats/supplier_turnover.php @@ -153,7 +153,7 @@ if ($modecompta == "CREANCES-DETTES") { $calcmode = str_replace('{link1}', '', $calcmode); $calcmode = str_replace('{link2}', '', $calcmode); $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); - $description = $langs->trans("RulesPurchaseTurnoverTotalPurchaseJournal"); + $description = $langs->trans("RulesPurchaseTurnoverOfExpenseAccounts"); $builddate = dol_now(); //$exportlink=$langs->trans("NotYetAvailable"); } @@ -193,11 +193,21 @@ if ($modecompta == 'CREANCES-DETTES') { $sql .= " AND f.fk_soc = ".$socid; } } elseif ($modecompta == "BOOKKEEPING") { - $sql = "SELECT date_format(b.doc_date,'%Y-%m') as dm, sum(b.debit) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b, ".MAIN_DB_PREFIX."accounting_journal as aj"; + $pcgverid = $conf->global->CHARTOFACCOUNTS; + $pcgvercode = dol_getIdFromCode($db, $pcgverid, 'accounting_system', 'rowid', 'pcg_version'); + if (empty($pcgvercode)) { + $pcgvercode = $pcgverid; + } + + $sql = "SELECT date_format(b.doc_date, '%Y-%m') as dm, sum(b.debit) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as b,"; + $sql .= " ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " WHERE b.entity = ".$conf->entity; // In module double party accounting, we never share entities - $sql .= " AND aj.entity = ".$conf->entity; - $sql .= " AND b.code_journal = aj.code AND aj.nature = 3"; // @todo currently count amount in sale journal, but we need to define a category group for turnover + $sql .= " AND b.doc_type = 'supplier_invoice'"; + $sql .= " AND b.numero_compte = aa.account_number"; + $sql .= " AND aa.entity = ".$conf->entity; + $sql .= " AND aa.fk_pcg_version = '".$db->escape($pcgvercode)."'"; + $sql .= " AND aa.pcg_type = 'EXPENSE'"; // TODO Be able to use a custom group } $sql .= " GROUP BY dm"; diff --git a/htdocs/compta/stats/supplier_turnover_by_thirdparty.php b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php index 4e19d81f94a..556c4437df7 100644 --- a/htdocs/compta/stats/supplier_turnover_by_thirdparty.php +++ b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php @@ -258,7 +258,7 @@ if ($modecompta == 'CREANCES-DETTES') { $sql .= ")"; $sql .= " AND cs.fk_categorie = c.rowid AND cs.fk_soc = s.rowid"; } -} else { +} elseif ($modecompta == "RECETTES-DEPENSES") { $sql = "SELECT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays, sum(pf.amount) as amount_ttc"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index d42d8845aeb..befb6adf75b 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -175,6 +175,7 @@ RulesResultInOut=- It includes the real payments made on invoices, expenses, VAT RulesCADue=- It includes the customer's due invoices whether they are paid or not.
- It is based on the billing date of these invoices.
RulesCAIn=- It includes all the effective payments of invoices received from customers.
- It is based on the payment date of these invoices
RulesCATotalSaleJournal=It includes all credit lines from the Sale journal. +RulesSalesTurnoverOfIncomeAccounts=It includes all debit of product accounts in group INCOME RulesAmountOnInOutBookkeepingRecord=It includes record in your Ledger with accounting accounts that has the group "EXPENSE" or "INCOME" RulesResultBookkeepingPredefined=It includes record in your Ledger with accounting accounts that has the group "EXPENSE" or "INCOME" RulesResultBookkeepingPersonalized=It show record in your Ledger with accounting accounts grouped by personalized groups @@ -280,6 +281,7 @@ PurchaseTurnoverCollected=Purchase turnover collected RulesPurchaseTurnoverDue=- It includes the supplier's due invoices whether they are paid or not.
- It is based on the invoice date of these invoices.
RulesPurchaseTurnoverIn=- It includes all the effective payments of invoices done to suppliers.
- It is based on the payment date of these invoices
RulesPurchaseTurnoverTotalPurchaseJournal=It includes all debit lines from the purchase journal. +RulesPurchaseTurnoverOfExpenseAccounts=It includes all debit of product accounts in group EXPENSE ReportPurchaseTurnover=Purchase turnover invoiced ReportPurchaseTurnoverCollected=Purchase turnover collected IncludeVarpaysInResults = Include various payments in reports