diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php
index 1596721667e..4f1a3043c76 100644
--- a/htdocs/compta/resultat/clientfourn.php
+++ b/htdocs/compta/resultat/clientfourn.php
@@ -252,7 +252,7 @@ if ($modecompta == 'BOOKKEEPING')
$sql .= " AND f.entity = ".$conf->entity;
if (!empty($date_start) && !empty($date_end))
$sql .= " AND f.doc_date >= '".$db->idate($date_start)."' AND f.doc_date <= '".$db->idate($date_end)."'";
- $sql .= " GROUP BY pcg_type, name, socid";
+ $sql .= " GROUP BY pcg_type DESC, name, socid";
$sql .= $db->order($sortfield, $sortorder);
$oldpcgtype = '';
@@ -284,6 +284,15 @@ if ($modecompta == 'BOOKKEEPING')
$total_ht += (isset($objp->amount) ? $objp->amount : 0);
$total_ttc += (isset($objp->amount) ? $objp->amount : 0);
+ if ($objp->pcg_type == 'INCOME') {
+ $total_ht_income += (isset($objp->amount) ? $objp->amount : 0);
+ $total_ttc_income += (isset($objp->amount) ? $objp->amount : 0);
+ }
+ if ($objp->pcg_type == 'EXPENSE') {
+ $total_ht_outcome -= (isset($objp->amount) ? $objp->amount : 0);
+ $total_ttc_outcome -= (isset($objp->amount) ? $objp->amount : 0);
+ }
+
// Loop on detail of all accounts
// This make 14 calls for each detail of account (NP, N and month m)
if ($showaccountdetail != 'no')
@@ -323,9 +332,6 @@ if ($modecompta == 'BOOKKEEPING')
print '
| '.$langs->trans("NoRecordFound").' |
';
}
} else dol_print_error($db);
-
- $total_ht_income += $total_ht;
- $total_ttc_income += $total_ttc;
} else {
/*
* Factures clients
@@ -1300,19 +1306,22 @@ print '';
print '| | ';
print '
';
-print '| '.$langs->trans("Outcome").' | ';
-if ($modecompta == 'CREANCES-DETTES')
- print ''.price(price2num(-$total_ht_outcome, 'MT')).' | ';
-print ''.price(price2num(-$total_ttc_outcome, 'MT')).' | ';
-print '
';
print '| '.$langs->trans("Income").' | ';
-if ($modecompta == 'CREANCES-DETTES')
+if ($modecompta == 'CREANCES-DETTES') {
print ''.price(price2num($total_ht_income, 'MT')).' | ';
+}
print ''.price(price2num($total_ttc_income, 'MT')).' | ';
print '
';
+print '| '.$langs->trans("Outcome").' | ';
+if ($modecompta == 'CREANCES-DETTES') {
+ print ''.price(price2num(-$total_ht_outcome, 'MT')).' | ';
+}
+print ''.price(price2num(-$total_ttc_outcome, 'MT')).' | ';
+print '
';
print '| '.$langs->trans("Profit").' | ';
-if ($modecompta == 'CREANCES-DETTES')
+if ($modecompta == 'CREANCES-DETTES') {
print ''.price(price2num($total_ht, 'MT')).' | ';
+}
print ''.price(price2num($total_ttc, 'MT')).' | ';
print '
';
diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php
index ec2a8bb2623..b623c1648a2 100644
--- a/htdocs/compta/resultat/index.php
+++ b/htdocs/compta/resultat/index.php
@@ -846,7 +846,7 @@ if (!empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING'))
if (!empty($date_start) && !empty($date_end))
$sql .= " AND b.doc_date >= '".$db->idate($date_start)."' AND b.doc_date <= '".$db->idate($date_end)."'";
$sql .= " GROUP BY b.doc_ref, b.numero_compte, b.subledger_account, b.subledger_label, pcg_type, dm";
- //print $sql;
+//print $sql;
$subtotal_ht = 0;
$subtotal_ttc = 0;
@@ -866,9 +866,9 @@ if (!empty($conf->accounting->enabled) && ($modecompta == 'BOOKKEEPING'))
if ($obj->pcg_type == 'INCOME') {
if (!isset($encaiss[$obj->dm])) $encaiss[$obj->dm] = 0; // To avoid warning of var not defined
$encaiss[$obj->dm] += $obj->credit;
- $encaiss[$obj->dm] -= $obj->credit;
+ $encaiss[$obj->dm] -= $obj->debit;
}
- if ($obj->pcg_type == 'INCOME') {
+ if ($obj->pcg_type == 'EXPENSE') {
if (!isset($decaiss[$obj->dm])) $decaiss[$obj->dm] = 0; // To avoid warning of var not defined
$decaiss[$obj->dm] += $obj->debit;
$decaiss[$obj->dm] -= $obj->credit;