* Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * \file htdocs/compta/bank/releve.php * \ingroup banque * \brief Page d'affichage d'un releve * \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); $langs->load("companies"); $langs->load("banks"); $langs->load("bills"); // Security check if (isset($_GET["account"]) || isset($_GET["ref"])) { $id = isset($_GET["account"])?$_GET["account"]:(isset($_GET["ref"])?$_GET["ref"]:''); } $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'banque',$id,'bank_account','','',$fieldid); if ($_GET["action"] == 'dvnext') { $ac = new Account($db); $ac->datev_next($_GET["dvid"]); } if ($_GET["action"] == 'dvprev') { $ac = new Account($db); $ac->datev_previous($_GET["dvid"]); } $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"]; if ($page == -1) { $page = 0; } if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="s.nom"; $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; /* * View */ llxHeader(); $html = new Form($db); // Load account $acct = new Account($db); if ($_GET["account"]) { $acct->fetch($_GET["account"]); } if ($_GET["ref"]) { $acct->fetch(0,$_GET["ref"]); $_GET["account"]=$acct->id; } if (! isset($_GET["num"])) { /* * Vue liste tous releves confondus */ $sql = "SELECT DISTINCT(b.num_releve) as numr"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE b.fk_account = ".$_GET["account"]; $sql.= " ORDER BY numr DESC"; $sql.= $db->plimit($conf->liste_limit+1,$offset); $result = $db->query($sql); if ($result) { $var=True; $numrows = $db->num_rows($result); $i = 0; // Onglets $head=bank_prepare_head($acct); dol_fiche_head($head,'statement',$langs->trans("FinancialAccount"),0,'account'); print ''; // Ref print ''; print ''; // Label print ''; print ''; print '
'.$langs->trans("Ref").''; print $html->showrefnav($acct,'ref','',1,'ref'); print '
'.$langs->trans("Label").''.$acct->label.'
'; print '
'; print_barre_liste('', $page, $_SERVER["PHP_SELF"], "&account=".$_GET["account"], $sortfield, $sortorder,'',$numrows); print ''; print ""; print ''; //while ($i < min($numrows,$conf->liste_limit)) // retrait de la limite tant qu'il n'y a pas de pagination while ($i < min($numrows,$conf->liste_limit)) { $objp = $db->fetch_object($result); $var=!$var; if (! isset($objp->numr)) { // } else { print "\n"; } $i++; } print "
'.$langs->trans("AccountStatement").'
numr&account=".$_GET["account"]."\">$objp->numr
\n"; print "\n\n"; } else { dol_print_error($db); } } else { /** * Affiche liste ecritures d'un releve */ $ve=$_GET["ve"]; $found=false; if ($_GET["rel"] == 'prev') { // Recherche valeur pour num = numero releve precedent $sql = "SELECT DISTINCT(b.num_releve) as num"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE b.num_releve < '".$_GET["num"]."'"; $sql.= " AND b.fk_account = ".$_GET["account"]; $sql.= " ORDER BY b.num_releve DESC"; dol_syslog("htdocs/compta/bank/releve.php sql=".$sql); $resql = $db->query($sql); if ($resql) { $numrows = $db->num_rows($resql); if ($numrows > 0) { $obj = $db->fetch_object($resql); $num = $obj->num; $found=true; } } } elseif ($_GET["rel"] == 'next') { // Recherche valeur pour num = numero releve precedent $sql = "SELECT DISTINCT(b.num_releve) as num"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE b.num_releve > '".$_GET["num"]."'"; $sql.= " AND b.fk_account = ".$_GET["account"]; $sql.= " ORDER BY b.num_releve ASC"; dol_syslog("htdocs/compta/bank/releve.php sql=".$sql); $resql = $db->query($sql); if ($resql) { $numrows = $db->num_rows($resql); if ($numrows > 0) { $obj = $db->fetch_object($resql); $num = $obj->num; $found=true; } } } else { // On veut le releve num $num=$_GET["num"]; $found=true; } if (! $found) $num=$_GET["num"]; $mesprevnext ="id\">".img_previous()."  "; $mesprevnext.= $langs->trans("AccountStatement")." $num"; $mesprevnext.="   id\">".img_next().""; print_fiche_titre($langs->trans("AccountStatement").' '.$num.', '.$langs->trans("BankAccount").' : '.$acct->getNomUrl(0),$mesprevnext); print '
'; print "
"; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; // Calcul du solde de depart du releve $sql = "SELECT sum(b.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE b.num_releve < '".$num."'"; $sql.= " AND b.fk_account = ".$acct->id; $resql=$db->query($sql); if ($resql) { $obj=$db->fetch_object($resql); $total = $obj->amount; $db->free($resql); } // Recherche les ecritures pour le releve $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv"; $sql.= ", b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= " WHERE b.num_releve='".$num."'"; if (!isset($num)) $sql.= " OR b.num_releve is null"; $sql.= " AND b.fk_account = ".$acct->id; $sql.= " ORDER BY b.datev ASC"; $result = $db->query($sql); if ($result) { $var=True; $numrows = $db->num_rows($result); $i = 0; // Ligne Solde debut releve print ""; print "\n"; while ($i < $numrows) { $objp = $db->fetch_object($result); $total = $total + $objp->amount; $var=!$var; print ""; // Date operation print ''; // Date de valeur print '\n"; // Num cheque print ''; // Libelle print '"; if ($objp->amount < 0) { $totald = $totald + abs($objp->amount); print '\n"; } else { $totalc = $totalc + abs($objp->amount); print "\n"; } print "\n"; if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ""; } else { print ""; } print ""; $i++; } $db->free($result); } // Ligne Total print ""; // Ligne Solde print "\n"; print "
'.$langs->trans("DateOperationShort").''.$langs->trans("DateValueShort").''.$langs->trans("Type").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").' 
id."\"> ".$langs->trans("InitialBankBalance")." :".price($total)." 
'.dol_print_date($db->jdate($objp->do),"day").''; print ''; print img_previous().' '; print dol_print_date($db->jdate($objp->dv),"day") .' '; print ''; print img_next().''; print "'.$objp->fk_type.' '.($objp->num_chq?$objp->num_chq:'').''; $reg=array(); preg_match('/\((.+)\)/i',$objp->label,$reg); // Si texte entoure de parenthese on tente recherche de traduction if ($reg[1] && $langs->trans($reg[1])!=$reg[1]) print $langs->trans($reg[1]); else print $objp->label; print ''; /* * Ajout les liens (societe, company...) */ $newline=1; $links = $acct->get_url($objp->rowid); foreach($links as $key=>$val) { if (! $newline) print ' - '; else print '
'; if ($links[$key]['type']=='payment') { print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print ''; $newline=0; } elseif ($links[$key]['type']=='payment_supplier') { print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print ''; $newline=0; } elseif ($links[$key]['type']=='company') { print ''; print img_object($langs->trans('ShowCustomer'),'company').' '; print dol_trunc($links[$key]['label'],24); print ''; $newline=0; } else if ($links[$key]['type']=='sc') { print ''; print img_object($langs->trans('ShowBill'),'bill').' '; print $langs->trans("SocialContribution"); print ''; $newline=0; } else if ($links[$key]['type']=='payment_sc') { print ''; print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("SocialContributionPayment"); print ''; $newline=0; } else if ($links[$key]['type']=='member') { print ''; print img_object($langs->trans('ShowMember'),'user').' '; print $links[$key]['label']; print ''; $newline=0; } else if ($links[$key]['type']=='banktransfert') { /* print ''; print img_object($langs->trans('ShowTransaction'),'payment').' '; print $langs->trans("TransactionOnTheOtherAccount"); print ''; $newline=0; */ } else { print ''; print $links[$key]['label']; print ''; $newline=0; } } // Categories if ($ve) { $sql = "SELECT label"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as ct"; $sql.= ", ".MAIN_DB_PREFIX."bank_class as cl"; $sql.= " WHERE ct.rowid = cl.fk_categ"; $sql.= " AND ct.entity = ".$conf->entity; $sql.= " AND cl.lineid = ".$objp->rowid; $resc = $db->query($sql); if ($resc) { $numc = $db->num_rows($resc); $ii = 0; if ($numc && ! $newline) print '
'; while ($ii < $numc) { $objc = $db->fetch_object($resc); print "
$objc->label"; $ii++; } } else { dol_print_error($db); } } print "
'.price($objp->amount * -1)."  ".price($objp->amount)."".price($total)."rowid&account=".$acct->id."\">"; print img_edit(); print " 
".$langs->trans("Total")." :".price($totald)."".price($totalc)."  
 ".$langs->trans("EndBankBalance")." :".price($total)." 
\n"; } $db->close(); llxFooter('$Date$ - $Revision$'); ?>