diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php
index 2d4ea6fc9e0..a5a8d431b5e 100644
--- a/htdocs/compta/resultat/index.php
+++ b/htdocs/compta/resultat/index.php
@@ -140,6 +140,11 @@ $form = new Form($db);
$exportlink = '';
+$encaiss = array();
+$encaiss_ttc = array();
+$decaiss = array();
+$decaiss_ttc = array();
+
// Affiche en-tete du rapport
if ($modecompta == 'CREANCES-DETTES') {
$name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear");
@@ -152,7 +157,7 @@ if ($modecompta == 'CREANCES-DETTES') {
}
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$periodlink = ($year_start ? "".img_previous()." ".img_next()."" : "");
- $description = $langs->trans("RulesAmountWithTaxIncluded");
+ $description = $langs->trans("RulesAmountWithTaxExcluded");
$description .= '
'.$langs->trans("RulesResultDue");
if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description .= "
".$langs->trans("DepositsAreNotIncluded");
@@ -237,10 +242,9 @@ if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mod
$sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
}
}
-
$sql .= " AND f.entity IN (".getEntity('invoice').")";
if ($socid) {
- $sql .= " AND f.fk_soc = $socid";
+ $sql .= " AND f.fk_soc = ".((int) $socid);
}
$sql .= " GROUP BY dm";
$sql .= " ORDER BY dm";
@@ -344,8 +348,8 @@ if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mod
$sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
}
}
+ $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
- $sql .= " AND f.entity = ".$conf->entity;
if ($socid) {
$sql .= " AND f.fk_soc = ".((int) $socid);
}
@@ -438,7 +442,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom
} else {
$sql .= " AND f.type IN (0,1,2,3)";
}
- $sql .= " AND f.entity = ".$conf->entity;
+ $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")";
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}
@@ -474,7 +478,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom
$sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql .= " WHERE amount > 0";
- $sql .= " AND t.entity = ".$conf->entity;
+ $sql .= " AND t.entity IN (".getEntity('vat').")";
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
}
@@ -509,7 +513,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom
$sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm";
$sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
$sql .= " WHERE amount < 0";
- $sql .= " AND t.entity = ".$conf->entity;
+ $sql .= " AND t.entity IN (".getEntity('vat').")";
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'";
}
@@ -572,7 +576,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom
}
}
- $sql .= " AND cs.entity = ".$conf->entity;
+ $sql .= " AND cs.entity IN (".getEntity('social_contributions').")";
$sql .= " GROUP BY c.libelle, dm";
dol_syslog("get social contributions", LOG_DEBUG);
@@ -611,7 +615,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom
if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) {
if ($modecompta == 'CREANCES-DETTES') {
- $column = 'p.datev';
+ $column = 's.dateep';
}
if ($modecompta == "RECETTES-DEPENSES") {
$column = 'p.datep';
@@ -620,8 +624,9 @@ if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo
$subtotal_ht = 0;
$subtotal_ttc = 0;
$sql = "SELECT p.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(p.amount) as amount";
- $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
- $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")";
+ $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p, ".MAIN_DB_PREFIX."salary as s";
+ $sql .= " WHERE p.fk_salary = s.rowid";
+ $sql .= " AND s.entity IN (".getEntity('salary').")";
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'";
}
@@ -786,7 +791,8 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba
// 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';
+ $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
+ $sql .= ' AND 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)."'";
}
@@ -816,7 +822,8 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba
// 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';
+ $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")";
+ $sql .= ' AND 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)."'";
}
@@ -852,8 +859,10 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba
*/
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';
+ $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount";
+ $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan AS p, ".MAIN_DB_PREFIX."loan as l";
+ $sql .= " WHERE l.entity IN (".getEntity('variouspayment').")";
+ $sql .= " AND p.fk_loan = l.rowid";
if (!empty($date_start) && !empty($date_end)) {
$sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
}
@@ -1025,7 +1034,7 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) {
$case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage));
print '