diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index 5b9ada6c075..3e20d611785 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -376,17 +376,6 @@ if ($id > 0)
$limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
if (empty($object->outstanding_limit)) print $langs->trans("NoLimit");
- // display amount and link to unpaid bill
- $outstandingBills = $object->get_OutstandingBill();
- print ' (' . $langs->trans('CurrentOutstandingBill') . ': ';
- print price($outstandingBills, '', $langs, 0, 0, - 1, $conf->currency);
- if ($object->outstanding_limit != '')
- {
- if ($outstandingBills > $object->outstanding_limit)
- print img_warning($langs->trans("OutstandingBillReached"));
- //print ' / ' . price($soc->outstanding_limit);
- }
- print ')';
print '';
print '';
@@ -494,10 +483,21 @@ if ($id > 0)
$MAXLIST=$conf->global->MAIN_SIZE_SHORTLISTE_LIMIT;
// Lien recap
+ $outstandingBills = $object->get_OutstandingBill();
+ $warn = '';
+ if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingBills)
+ {
+ $warn = img_warning($langs->trans("OutstandingBillReached"));
+ }
+
print '
';
+ print '';
+ print '| '.$langs->trans("Date").' | ';
+ print ''.$langs->trans("Element").' | ';
+ print ''.$langs->trans("Status").' | ';
+ print ''.$langs->trans("Debit").' | ';
+ print ''.$langs->trans("Credit").' | ';
+ print ''.$langs->trans("Balance").' | ';
+ print ''.$langs->trans("Author").' | ';
+ print '
';
+
+ $TData = array();
+ $TDataSort = array();
$sql = "SELECT s.nom, s.rowid as socid, f.facnumber, f.amount, f.datef as df,";
$sql.= " f.paye as paye, f.fk_statut as statut, f.rowid as facid,";
@@ -95,7 +88,7 @@ if ($socid > 0)
$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$societe->id;
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.fk_user_valid = u.rowid";
- $sql.= " ORDER BY f.datef DESC";
+ $sql.= " ORDER BY f.datef ASC";
$resql=$db->query($sql);
if ($resql)
@@ -103,23 +96,6 @@ if ($socid > 0)
$var=true;
$num = $db->num_rows($resql);
- print '';
- print '| '.$langs->trans("Date").' | ';
- print ' | ';
- print ''.$langs->trans("Status").' | ';
- print ''.$langs->trans("Debit").' | ';
- print ''.$langs->trans("Credit").' | ';
- print ''.$langs->trans("Balance").' | ';
- print ' | ';
- print '
';
-
- if (! $num > 0)
- {
- print '| '.$langs->trans("NoInvoice").' |
';
- }
-
- $solde = 0;
-
// Boucle sur chaque facture
for ($i = 0 ; $i < $num ; $i++)
{
@@ -133,29 +109,18 @@ if ($socid > 0)
continue;
}
$totalpaye = $fac->getSommePaiement();
-
- $var=!$var;
- print "";
-
- print "| ".dol_print_date($fac->date,'day')." | \n";
- print ''.img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref." | \n";
-
- print ''.$fac->getLibStatut(2,$totalpaye).' | ';
- print ''.price($fac->total_ttc)." | \n";
- if (($fac->statut == Facture::STATUS_ABANDONED ) || ($fac->statut == Facture::STATUS_CLOSED && ! $fact->close_code) ) $solde = $solde = $solde + $totalpaye;
- else $solde = $solde + $fac->total_ttc;
-
- print ' | ';
- print ''.price($solde)." | \n";
-
- // Author
+
$userstatic->id=$objf->userid;
$userstatic->login=$objf->login;
- print '';
- print $userstatic->getLoginUrl(1);
- print ' | ';
-
- print "
\n";
+
+ $TData[] = array(
+ 'date' => $fac->date,
+ 'link' => $fac->getNomUrl(1),
+ 'status' => $fac->getLibStatut(2,$totalpaye),
+ 'amount' => $fac->total_ttc,
+ 'author' => $userstatic->getLoginUrl(1)
+ );
+ $TDataSort[] = $fac->date;
// Paiements
$sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
@@ -166,6 +131,7 @@ if ($socid > 0)
$sql.= " WHERE pf.fk_paiement = p.rowid";
$sql.= " AND p.entity = ".$conf->entity;
$sql.= " AND pf.fk_facture = ".$fac->id;
+ $sql.= " ORDER BY p.datep ASC";
$resqlp = $db->query($sql);
if ($resqlp)
@@ -176,26 +142,21 @@ if ($socid > 0)
while ($j < $nump)
{
$objp = $db->fetch_object($resqlp);
- //$var=!$var;
- print "";
- print '| '.dol_print_date($db->jdate($objp->dp),'day')." | \n";
- print '';
- print ' '; // Decalage
- print ''.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.' | ';
- print " | \n";
- print " | \n";
- print ''.price($objp->amount).' | ';
- $solde = $solde - $objp->amount;
- print ''.price($solde)." | \n";
-
- // Author
+
+ $paymentstatic = new Paiement($db);
+ $paymentstatic->id = $objp->rowid;
+
$userstatic->id=$objp->userid;
$userstatic->login=$objp->login;
- print '';
- print $userstatic->getLoginUrl(1);
- print ' | ';
-
- print '
';
+
+ $TData[] = array(
+ 'date' => $db->jdate($objp->dp),
+ 'link' => $langs->trans("Payment") .' '. $paymentstatic->getNomUrl(1),
+ 'status' => '',
+ 'amount' => -$objp->amount,
+ 'author' => $userstatic->getLoginUrl(1)
+ );
+ $TDataSort[] = $db->jdate($objp->dp);
$j++;
}
@@ -212,9 +173,63 @@ if ($socid > 0)
{
dol_print_error($db);
}
+
+ if(empty($TData)) {
+ print '| '.$langs->trans("NoInvoice").' |
';
+ } else {
+
+ // Sort array by date
+ asort($TDataSort);
+ array_multisort($TData,$TDataSort);
+
+ // Balance calculation
+ foreach($TData as &$data1) {
+ $balance += $data1['amount'];
+ $data1['balance'] += $balance;
+ }
+
+ // Reverse array to have last elements on top
+ $TData = array_reverse($TData);
+
+ $totalDebit = 0;
+ $totalCredit = 0;
+
+ // Display array
+ foreach($TData as $data) {
+ $var=!$var;
+ print "";
+
+ print "| ".dol_print_date($data['date'],'day')." | \n";
+ print ''.$data['link']." | \n";
+
+ print ''.$data['status'].' | ';
+ print ''.(($data['amount'] > 0) ? price(abs($data['amount'])) : '')." | \n";
+ $totalDebit += ($data['amount'] > 0) ? abs($data['amount']) : 0;
+ print ''.(($data['amount'] > 0) ? '' : price(abs($data['amount'])))." | \n";
+ $totalCredit += ($data['amount'] > 0) ? 0 : abs($data['amount']);
+ print ''.price($data['balance'])." | \n";
+
+ // Author
+ print '';
+ print $data['author'];
+ print ' | ';
+
+ print "
\n";
+ }
+
+ print '';
+ print '| | ';
+ print ''.price($totalDebit).' | ';
+ print ''.price($totalCredit).' | ';
+ print ' | ';
+ print "
\n";
+ }
+
print "
";
print "