From 128ec6fd78fa91569f80636a83f90dd8171ad1a1 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 6 May 2020 08:38:36 +0200 Subject: [PATCH 1/4] Add include various payments and loans in accounting report For simplified accouning, behaviour not enable by default and must be enabed in simplified accounting module admin page (or by global settings ACCOUNTING_REPORTS_INCLUDE_VARPAY and ACCOUNTING_REPORTS_INCLUDE_LOAN). --- htdocs/admin/compta.php | 35 ++++++++ htdocs/compta/resultat/clientfourn.php | 116 ++++++++++++++++++++++++- htdocs/compta/resultat/index.php | 112 ++++++++++++++++++++++++ htdocs/langs/en_US/compta.lang | 2 + htdocs/langs/fr_FR/compta.lang | 2 + 5 files changed, 266 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/compta.php b/htdocs/admin/compta.php index cdfa15d9069..b3c66af76ca 100644 --- a/htdocs/admin/compta.php +++ b/htdocs/admin/compta.php @@ -5,6 +5,7 @@ * Copyright (C) 2011-2013 Juanjo Menent * Copyright (C) 2013-2017 Philippe Grand * Copyright (C) 2014 Marcos García + * Copyright (C) 2020 Maxime DEMAREST * * 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 @@ -83,6 +84,20 @@ if ($action == 'update') } } + $report_include_varpay = GETPOST('ACCOUNTING_REPORTS_INCLUDE_VARPAY', 'alpha'); + if (!empty($report_include_varpay)) + if ($report_include_varpay == 'yes') + if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', 1, 'chaine', 0, '', $conf->entity)) $error++; + if ($report_include_varpay == 'no') + if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', $conf->entity)) $error++; + + $report_include_loan = GETPOST('ACCOUNTING_REPORTS_INCLUDE_LOAN', 'alpha'); + if (!empty($report_include_loan)) + if ($report_include_loan == 'yes') + if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', 1, 'chaine', 0, '', $conf->entity)) $error++; + if ($report_include_loan == 'no') + if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', $conf->entity)) $error++; + if (!$error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); @@ -158,6 +173,26 @@ foreach ($list as $key) print ''; } +// Option to include various payment in results +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''; + +// Option to include loan in results +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''."\n"; +print ''; + print "\n"; print '

'; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 44be66a2218..59b7999e4ef 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -8,6 +8,7 @@ * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2014 Florian Henry * Copyright (C) 2018 Frédéric France + * Copyright (C) 2020 Maxime DEMAREST * * 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 @@ -38,7 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php'; // Load translation files required by the page -$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy')); +$langs->loadLangs(array('compta', 'bills', 'donation', 'salaries', 'accountancy', 'loan')); $date_startmonth = GETPOST('date_startmonth', 'int'); $date_startday = GETPOST('date_startday', 'int'); @@ -953,6 +954,119 @@ else print ''; } + /* + * Various Payments + */ + + if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) + { + $subtotal_ht = 0; + $subtotal_ttc = 0; + + print ''.$langs->trans("VariousPayment").''; + + // Debit + $sql = "SELECT SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p"; + $sql .= ' WHERE 1 = 1'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= ' GROUP BY p.sens'; + $sql .= ' ORDER BY p.sens'; + + dol_syslog('get various payments', LOG_DEBUG); + $result = $db->query($sql); + if ($result) + { + + // Debit + $obj = $db->fetch_object($result); + if (isset($obj->amount)) + { + $subtotal_ht += -$obj->amount; + $subtotal_ttc += -$obj->amount; + } + print ' '; + print "".$langs->trans("Debit")."\n"; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount)."\n"; + print "\n"; + + // Credit + $obj = $db->fetch_object($result); + if (isset($obj->amount)) + { + $subtotal_ht += $obj->amount; + $subtotal_ttc += $obj->amount; + } + print ' '; + print "".$langs->trans("Credit")."\n"; + if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).''; + print ''.price($obj->amount)."\n"; + print "\n"; + + // Total + $total_ht += $subtotal_ht; + $total_ttc += $subtotal_ttc; + print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''.price($subtotal_ht).''; + print ''.price($subtotal_ttc).''; + print ''; + + } + else dol_print_error($db); + } + + /* + * Payement Loan + */ + + if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) + { + $subtotal_ht = 0; + $subtotal_ttc = 0; + + print ''.$langs->trans("PaymentLoan").''; + + $sql = 'SELECT l.rowid as id, l.label AS label, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) as amount FROM '.MAIN_DB_PREFIX.'payment_loan as p'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'loan AS l ON l.rowid = p.fk_loan'; + $sql .= ' WHERE 1 = 1'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= ' GROUP BY p.fk_loan'; + $sql .= ' ORDER BY p.fk_loan'; + + dol_syslog('get loan payments', LOG_DEBUG); + $result = $db->query($sql); + if ($result) + { + require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; + $loan_static = new Loan($db); + while ($obj = $db->fetch_object($result)) + { + $loan_static->id = $obj->id; + $loan_static->ref = $obj->id; + $loan_static->label = $obj->label; + print ' '; + print "".$loan_static->getNomUrl(1).' - '.$obj->label."\n"; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount)."\n"; + print "\n"; + $subtotal_ht -= $obj->amount; + $subtotal_ttc -= $obj->amount; + } + + $total_ht += $subtotal_ht; + $total_ttc += $subtotal_ttc; + print ''; + if ($modecompta == 'CREANCES-DETTES') + print ''.price($subtotal_ht).''; + print ''.price($subtotal_ttc).''; + print ''; + } + else dol_print_error($db); + } + /* * VAT diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index d462007d273..ed3befce56c 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -6,6 +6,7 @@ * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2014 Florian Henry * Copyright (C) 2018 Frédéric France + * Copyright (C) 2020 Maxime DEMAREST * * 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 @@ -794,6 +795,117 @@ elseif ($modecompta == 'BOOKKEEPING') { // Nothing from this table } +/* + * Various Payments + */ + +if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) +{ + + // decaiss + + $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p"; + $sql .= ' WHERE p.sens = 0'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= ' GROUP BY dm'; + + dol_syslog("get various payments"); + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($result); + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; + if (isset($obj->amount)) $decaiss_ttc[$obj->dm] += $obj->amount; + $i++; + } + } + } + else + { + dol_print_error($db); + } + + // encaiss + + $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various AS p"; + $sql .= ' WHERE p.sens = 1'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= ' GROUP BY dm'; + + dol_syslog("get various payments"); + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($result); + if (!isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm] = 0; + if (isset($obj->amount)) $encaiss_ttc[$obj->dm] += $obj->amount; + $i++; + } + } + } + else + { + dol_print_error($db); + } + +} +elseif ($modecompta == 'BOOKKEEPING') { + // Useless with BOOKKEEPING +} + +/* + * Payement Loan + */ + +if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) +{ + + $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount FROM ".MAIN_DB_PREFIX."payment_loan AS p"; + $sql .= ' WHERE 1 = 1'; + if (!empty($date_start) && !empty($date_end)) + $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql .= ' GROUP BY dm'; + + dol_syslog("get loan payments"); + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($result); + if (!isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm] = 0; + if (isset($obj->amount)) $decaiss_ttc[$obj->dm] += $obj->amount; + $i++; + } + } + } + else + { + dol_print_error($db); + } + +} +elseif ($modecompta == 'BOOKKEEPING') { + // Not use with BOOKKEEPING +} /* diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang index 6cd046c5607..8a8c837ac87 100644 --- a/htdocs/langs/en_US/compta.lang +++ b/htdocs/langs/en_US/compta.lang @@ -262,3 +262,5 @@ RulesPurchaseTurnoverIn=- It includes all the effective payments of invoices don RulesPurchaseTurnoverTotalPurchaseJournal=It includes all debit lines from the purchase journal. ReportPurchaseTurnover=Purchase turnover invoiced ReportPurchaseTurnoverCollected=Purchase turnover collected +IncludeVarpaysInResults = Include various payments in reports +IncludeLoansInResults = Include loans in reports diff --git a/htdocs/langs/fr_FR/compta.lang b/htdocs/langs/fr_FR/compta.lang index c60c79513c5..d4c59754898 100644 --- a/htdocs/langs/fr_FR/compta.lang +++ b/htdocs/langs/fr_FR/compta.lang @@ -262,3 +262,5 @@ RulesPurchaseTurnoverIn=- It includes all the effective payments of invoices don RulesPurchaseTurnoverTotalPurchaseJournal=It includes all debit lines from the purchase journal. ReportPurchaseTurnover=Purchase turnover invoiced ReportPurchaseTurnoverCollected=Purchase turnover collected +IncludeVarpaysInResults = Inclure les payments divers dans les rapports +IncludeLoansInResults = Inclure les emprunts dans les rapports From bf8cd51a5aaf32db3dd66bf73c1021ce08f38f4b Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 6 May 2020 13:37:24 +0200 Subject: [PATCH 2/4] Fix somes code formating errors --- htdocs/compta/resultat/clientfourn.php | 8 ++------ htdocs/compta/resultat/index.php | 14 ++++++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 59b7999e4ef..27bc4526a3e 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -977,7 +977,6 @@ else $result = $db->query($sql); if ($result) { - // Debit $obj = $db->fetch_object($result); if (isset($obj->amount)) @@ -987,7 +986,7 @@ else } print ' '; print "".$langs->trans("Debit")."\n"; - if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; print ''.price(-$obj->amount)."\n"; print "\n"; @@ -1000,7 +999,7 @@ else } print ' '; print "".$langs->trans("Credit")."\n"; - if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).''; + if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).''; print ''.price($obj->amount)."\n"; print "\n"; @@ -1012,7 +1011,6 @@ else print ''.price($subtotal_ht).''; print ''.price($subtotal_ttc).''; print ''; - } else dol_print_error($db); } @@ -1055,7 +1053,6 @@ else $subtotal_ht -= $obj->amount; $subtotal_ttc -= $obj->amount; } - $total_ht += $subtotal_ht; $total_ttc += $subtotal_ttc; print ''; @@ -1067,7 +1064,6 @@ else else dol_print_error($db); } - /* * VAT */ diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index ed3befce56c..10d0f31fe72 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -801,7 +801,6 @@ elseif ($modecompta == 'BOOKKEEPING') { if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->banque->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { - // decaiss $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p"; @@ -863,9 +862,9 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba } } -elseif ($modecompta == 'BOOKKEEPING') { - // Useless with BOOKKEEPING -} +// Useless with BOOKKEEPING +//elseif ($modecompta == 'BOOKKEEPING') { +//} /* * Payement Loan @@ -873,7 +872,6 @@ elseif ($modecompta == 'BOOKKEEPING') { if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { - $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount FROM ".MAIN_DB_PREFIX."payment_loan AS p"; $sql .= ' WHERE 1 = 1'; if (!empty($date_start) && !empty($date_end)) @@ -903,9 +901,9 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan } } -elseif ($modecompta == 'BOOKKEEPING') { - // Not use with BOOKKEEPING -} +// Useless with BOOKKEEPING +//elseif ($modecompta == 'BOOKKEEPING') { +//} /* From 7bf037ab2ff568e45096d86b5de1d64df7b0239c Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 6 May 2020 13:46:24 +0200 Subject: [PATCH 3/4] Fix blank line at end of control structure --- htdocs/compta/resultat/index.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 10d0f31fe72..ad81a3943c1 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -860,7 +860,6 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba { dol_print_error($db); } - } // Useless with BOOKKEEPING //elseif ($modecompta == 'BOOKKEEPING') { @@ -899,7 +898,6 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan { dol_print_error($db); } - } // Useless with BOOKKEEPING //elseif ($modecompta == 'BOOKKEEPING') { From 889e5db4fbbf8e081f9ab4f6fe34e581bd6477a2 Mon Sep 17 00:00:00 2001 From: "DEMAREST Maxime (Indelog)" Date: Wed, 6 May 2020 13:55:38 +0200 Subject: [PATCH 4/4] Fix use Form::selectyesno() for added options in admin/compta.php --- htdocs/admin/compta.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/htdocs/admin/compta.php b/htdocs/admin/compta.php index b3c66af76ca..3ccc2a213ac 100644 --- a/htdocs/admin/compta.php +++ b/htdocs/admin/compta.php @@ -177,20 +177,14 @@ foreach ($list as $key) print ''."\n"; print ''."\n"; print ''."\n"; -print ''."\n"; +print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_VARPAY', (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY))); print ''; // Option to include loan in results print ''."\n"; print ''."\n"; print ''."\n"; -print ''."\n"; +print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_LOAN', (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN))); print ''; print "\n";