* Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2007 Laurent Destailleur * Copytight (C) 2004 Christophe Combelles * * 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. * * $Id$ * $Source$ */ /** \file htdocs/compta/bank/account.php \ingroup banque \brief Page de détail des transactions bancaires \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); if (!$user->rights->banque->lire) accessforbidden(); $langs->load("bills"); $account=isset($_GET["account"])?$_GET["account"]:$_POST["account"]; $vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"]; $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"]; $page=isset($_GET["page"])?$_GET["page"]:0; $mesg=''; /* * Action */ if ($_POST["action"] == 'add' && $account && ! isset($_POST["cancel"]) && $user->rights->banque->modifier) { if ($_POST["credit"] > 0) { $amount = str_replace(',','.',$_POST["credit"]); } else { $amount = - str_replace(',','.',$_POST["debit"]); } $dateop = dolibarr_mktime(12,0,0,$_POST["opmonth"],$_POST["opday"],$_POST["opyear"]); $operation=$_POST["operation"]; $num_chq=$_POST["num_chq"]; $label=$_POST["label"]; $cat1=$_POST["cat1"]; if (! $dateop) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Date")); if (! $operation) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Type")); if (! $amount) $mesg=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); if (! $mesg) { $acct=new Account($db,$account); $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); if ($insertid > 0) { Header("Location: account.php?account=" . $account); exit; } else { dolibarr_print_error($db,$acct->error); } } else { $_GET["action"]='addline'; } } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"]=='yes' && $user->rights->banque->modifier) { $acct=new Account($db); $acct->id=$account; $result=$acct->deleteline($_GET["rowid"]); } /* * Affichage page */ llxHeader(); $html = new Form($db); if ($account > 0) { if ($vline) { $viewline = $vline; } else { $viewline = 20; } $acct = new Account($db); $acct->fetch($account); // Chargement des categories bancaires dans $options $nbcategories=0; $sql = "SELECT rowid, label"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; $sql.= " ORDER BY label"; $result = $db->query($sql); if ($result) { $var=True; $num = $db->num_rows($result); $i = 0; $options = ""; while ($i < $num) { $obj = $db->fetch_object($result); $options .= "\n"; $nbcategories++; $i++; } $db->free($result); } /* * * */ $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."bank as b"; $sql .= " WHERE b.fk_account=".$acct->id; $sql_rech=""; if ($_POST["req_desc"]) { $sql_rech .= " AND b.label like '%".strtolower($_POST["req_desc"])."%'"; $mode_search = 1; } else { $mode_search = 0; } if ($_POST["req_debit"]) $sql_rech.=" AND amount = -".$_POST["req_debit"]; if ($_POST["req_credit"]) $sql_rech.=" AND amount = ".$_POST["req_credit"]; $sql .= $sql_rech; $result=$db->query($sql); if ($result) { $obj = $db->fetch_object($result); $nbline = $obj->nb; $total_lines = $nbline; if ($nbline > $viewline ) { $limit = $nbline - $viewline ; } else { $limit = $viewline; } $db->free($result); } else { dolibarr_print_error($db); } if ($page > 0 && $mode_search == 0) { $limitsql = $nbline - ($page * $viewline); if ($limitsql < $viewline) { $limitsql = $viewline; } $nbline = $limitsql; } else { $page = 0; $limitsql = $nbline; } // Onglets $head=bank_prepare_head($acct); dolibarr_fiche_head($head,'journal',$langs->trans("FinancialAccount"),0); if ($mesg) print '
'.$mesg.'
'; /** * Bandeau recherche */ $navig=''; $nbpage=floor($total_lines/$viewline)+($total_lines % $viewline > 0?1:0); // Nombre de page total if ($limitsql > $viewline) { $navig.=''.img_previous().''; } $navig.= ' Page '.($nbpage-$page).'/'.$nbpage.' '; if ($total_lines > $limitsql ) { $navig.= ''.img_next().''; } if (! $_GET["action"]=='addline' && ! $_GET["action"]=='delete') { $titre=$langs->trans("FinancialAccount")." : ".$acct->label; print_fiche_titre($titre,$navig); } if ($_GET["action"]=='delete') { $text=$langs->trans('ConfirmDeleteTransaction'); $html->form_confirm($_SERVER['PHP_SELF'].'?account='.$acct->id.'&rowid='.$_GET["rowid"],$langs->trans('DeleteTransaction'),$text,'confirm_delete'); print '
'; } print ''; // Formulaire de saisie d'une opération hors factures if ($user->rights->banque->modifier && $_GET["action"]=='addline') { $html=new Form($db); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ""; print "\n"; } /* * Affiche tableau des transactions bancaires * */ // Ligne de titre tableau des acritures print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print "\n"; /* Another solution * create temporary table solde type=heap select amount from llx_bank limit 100 ; * select sum(amount) from solde ; */ $sql = "SELECT b.rowid,".$db->pdate("b.dateo")." as do,".$db->pdate("b.datev")." as dv, 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 fk_account=".$acct->id; if ($req_debit) $sql .= " AND b.amount = -".$req_debit; if ($req_credit) $sql .= " AND b.amount = ".$req_credit; $sql.= $sql_rech; if ($vue) { if ($vue == 'credit') { $sql .= " AND b.amount >= 0 "; } else { $sql .= " AND b.amount < 0 "; } } $sql.= " ORDER BY b.datev ASC"; $sql.= $db->plimit($limitsql, 0); $result = $db->query($sql); if ($result) { $total = _print_lines($db, $result, $sql, $acct); if ($page == 0) { print ''; print ''; print ''; print ''; } $db->free($result); } print "
'.$langs->trans("AddBankRecordLong").'
'.$langs->trans("Date").' '.$langs->trans("Type").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").' 
'; $html->select_date(-1,'op',0,0,0,'transaction'); print ''; $html->select_types_paiements('','operation','1,2',1,1); print ''; print ''; if ($nbcategories) { print '
'.$langs->trans("Category").': '; } print '
'; print '
'; print ''; print '
 
'.$langs->trans("Date").''.$langs->trans("Value").''.$langs->trans("Type").''.$langs->trans("Description").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("BankBalance").''; if ($acct->type != 2 && $acct->rappro) print $langs->trans("AccountStatementShort"); else print ' '; print '
  
'.$langs->trans("CurrentBalance").''.price($total).' 
"; print "\n\n"; /* * Boutons actions */ if ($_GET["action"] != 'addline' && $_GET["action"] != 'delete') { print '
'; if ($user->rights->banque->modifier && $acct->type != 2 && $acct->rappro) // Si non compte cash et rapprochable { print ''.$langs->trans("Conciliate").''; } if ($user->rights->banque->modifier) { print ''.$langs->trans("AddBankRecord").''; } print '
'; } print '
'; } else { print $langs->trans("ErrorBankAccountNotFound"); } $db->close(); llxFooter('$Date$ - $Revision$'); /** * \brief Affiche ligne ecriture * \param db Handler d'accès base * \param result Resultset du select * \param sql Requete sql * \param acct Compte * \return Renvoi total solde */ function _print_lines($db,$result,$sql,$acct) { global $langs, $bc, $nbline, $viewline, $user, $page; $var=true; $total=0; $num = $db->num_rows($result); $i = 0; $total = 0; $sep = 0; while ($i < $num) { $objp = $db->fetch_object($result); $total = $total + $objp->amount; $time = time(); if ($i >= ($nbline - $viewline)) { $var=!$var; if ($objp->do > $time && !$sep) { $sep = 1 ; print " "; print "".price($total - $objp->amount).""; print " "; print ''; } print ""; print "".dolibarr_print_date($objp->do,"%d/%m/%y")."\n"; print " ".dolibarr_print_date($objp->dv,"%d/%m/%y")."\n"; print " ".$objp->fk_type." ".($objp->num_chq?$objp->num_chq:"")."\n"; print ''; if (eregi('^\((.*)\)$',$objp->label,$reg)) { // Label générique car entre parenthèses. On l'affiche en le traduisant print $langs->trans($reg[1]); } else { print $objp->label; } print ''; /* * Ajout les liens */ $links = $acct->get_url($objp->rowid); foreach($links as $key=>$val) { print ' - '; if ($links[$key]['type']=='payment') { print ''; //print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print ''; } else if ($links[$key]['type']=='payment_supplier') { print ''; //print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("Payment"); print ''; } else if ($links[$key]['type']=='company') { print ''; //print img_object($langs->trans('ShowCustomer'),'company').' '; print $links[$key]['label']; print ''; } else if ($links[$key]['type']=='sc') { print ''; //print img_object($langs->trans('ShowBill'),'bill').' '; print $langs->trans("SocialContribution"); print ''; } else if ($links[$key]['type']=='payment_sc') { print ''; //print img_object($langs->trans('ShowPayment'),'payment').' '; print $langs->trans("SocialContributionPayment"); print ''; } else { print ''; print $links[$key]['label']; print ''; } } print ''; if ($objp->amount < 0) { print "".price($objp->amount * -1)." \n"; } else { print "  ".price($objp->amount)."\n"; } if ($action !='search') { if ($total >= 0) { print ' '.price($total).''; } else { print ' '.price($total).''; } } else { print '-'; } // Relevé rappro ou lien edition if ($objp->rappro && $acct->type != 2) // Si non compte cash { print "  "; print "num_releve&account=$acct->id\">$objp->num_releve"; print ""; } else { if ($user->rights->banque->modifier) { print ''; print ''; print img_edit(); print '  '; print ''; print img_delete(); print ''; } else { print " "; } } print ""; } $i++; } return $total; } ?>