NEW Can sort customer balance summary on date

This commit is contained in:
Laurent Destailleur 2017-05-16 03:34:49 +02:00
parent ab444ce730
commit cc95e046e5

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -39,6 +39,30 @@ $result = restrictedArea($user, 'societe', $id, '&societe');
$object = new Societe($db); $object = new Societe($db);
if ($id > 0) $object->fetch($id); if ($id > 0) $object->fetch($id);
// Load variable for pagination
$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
$sortfield = GETPOST('sortfield','alpha');
$sortorder = GETPOST('sortorder','alpha');
$page = GETPOST('page','int');
if ($page == -1) { $page = 0; }
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortfield) $sortfield="f.datef"; // Set here default search field
if (! $sortorder) $sortorder="DESC";
$arrayfields=array(
'f.datef'=>array('label'=>"Date", 'checked'=>1),
//...
);
/*
* Actions
*/
// None
/* /*
* View * View
@ -55,9 +79,9 @@ llxHeader('',$title,$help_url);
if ($id > 0) if ($id > 0)
{ {
/* $param='';
* Affichage onglets if ($id > 0) $param.='&socid='.$id;
*/
$head = societe_prepare_head($object); $head = societe_prepare_head($object);
dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company');
@ -71,7 +95,7 @@ if ($id > 0)
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="100" align="center">'.$langs->trans("Date").'</td>'; if (! empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'],$_SERVER["PHP_SELF"],"f.datef","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
print '<td>'.$langs->trans("Element").'</td>'; print '<td>'.$langs->trans("Element").'</td>';
print '<td>'.$langs->trans("Status").'</td>'; print '<td>'.$langs->trans("Status").'</td>';
print '<td align="right">'.$langs->trans("Debit").'</td>'; print '<td align="right">'.$langs->trans("Debit").'</td>';
@ -90,7 +114,7 @@ if ($id > 0)
$sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id; $sql.= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id;
$sql.= " AND f.entity = ".$conf->entity; $sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.fk_user_valid = u.rowid"; $sql.= " AND f.fk_user_valid = u.rowid";
$sql.= " ORDER BY f.datef ASC"; $sql.= $db->order($sortfield, $sortorder);
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
@ -177,7 +201,7 @@ if ($id > 0)
} }
if(empty($TData)) { if(empty($TData)) {
print '<tr '.$bc[false].'><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>'; print '<tr class="oddeven"><td colspan="7">'.$langs->trans("NoInvoice").'</td></tr>';
} else { } else {
// Sort array by date // Sort array by date
@ -191,7 +215,8 @@ if ($id > 0)
} }
// Reverse array to have last elements on top // Reverse array to have last elements on top
$TData = array_reverse($TData); $TData = dol_sort_array($TData, 'date', $sortorder);
$totalDebit = 0; $totalDebit = 0;
$totalCredit = 0; $totalCredit = 0;
@ -223,7 +248,8 @@ if ($id > 0)
print '<td colspan="3">&nbsp;</td>'; print '<td colspan="3">&nbsp;</td>';
print '<td align="right">'.price($totalDebit).'</td>'; print '<td align="right">'.price($totalDebit).'</td>';
print '<td align="right">'.price($totalCredit).'</td>'; print '<td align="right">'.price($totalCredit).'</td>';
print '<td colspan="2">&nbsp;</td>'; print '<td align="right">'.price(price2num($totalDebit - $totalCredit, 'MT')).'</td>';
print '<td></td>';
print "</tr>\n"; print "</tr>\n";
} }