* * 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$ */ /** \file htdocs/compta/bank/treso.php \ingroup banque \brief Page de détail du budget de trésorerie \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.facture.class.php'); require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); $langs->load("banks"); $user->getrights('banque'); if (!$user->admin && !$user->rights->banque) accessforbidden(); $account=isset($_GET["account"])?$_GET["account"]:$_POST["account"]; $vline=isset($_GET["vline"])?$_GET["vline"]:$_POST["vline"]; $page=isset($_GET["page"])?$_GET["page"]:0; $mesg=''; /* * Affichage page */ llxHeader(); $societestatic = new Societe($db); $facturestatic=new Facture($db); $facturefournstatic=new FactureFournisseur($db); $html = new Form($db); if ($_REQUEST["account"] || $_REQUEST["ref"]) { if ($vline) { $viewline = $vline; } else { $viewline = 20; } $acct = new Account($db); if ($_GET["account"]) { $result=$acct->fetch($_GET["account"]); } if ($_GET["ref"]) { $result=$acct->fetch(0,$_GET["ref"]); $_GET["account"]=$acct->id; } /* * * */ // Onglets $head=bank_prepare_head($acct); dolibarr_fiche_head($head,'cash',$langs->trans("FinancialAccount"),0); 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 '
'; if ($mesg) print '
'.$mesg.'
'; /* * Calcul du solde du compte bancaire */ $sql = "SELECT sum( amount ) AS solde"; $sql.= " FROM ".MAIN_DB_PREFIX."bank"; $sql.= " WHERE fk_account =".$account; $result = $db->query($sql); if ($result) { $obj = $db->fetch_object($result); if ($obj) $solde = $obj->solde; } /* * Affiche tableau des echeances à venir * */ print ''; // Ligne de titre tableau des ecritures print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Solde initial print ''; print ''; print ''; // Recuperation des factures clients et fournisseurs impayes $sql = "SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, ".$db->pdate("f.date_lim_reglement")." as dlr,"; $sql.= " s.rowid as socid, s.nom, s.fournisseur"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; $sql.= " WHERE f.paye = 0 AND fk_statut = 1"; $sql.= " UNION DISTINCT"; $sql.= " SELECT ff.rowid as facid, ff.facnumber, (-1*ff.total_ttc), ff.type, ".$db->pdate("ff.date_lim_reglement")." as dlr,"; $sql.= " s.rowid as socid, s.nom, s.fournisseur"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ff.fk_soc = s.rowid"; $sql.= " WHERE ff.paye = 0 AND fk_statut = 1"; $sql.= " ORDER BY dlr ASC"; $result = $db->query($sql); if ($result) { $var=False; $num = $db->num_rows($result); $i = 0; while ($i < $num) { $paiement = ''; $var=!$var; $obj = $db->fetch_object($result); $societestatic->id = $obj->socid; $societestatic->nom = $obj->nom; if ($obj->fournisseur == 1) { $facturefournstatic->ref=$obj->facnumber; $facturefournstatic->id=$obj->facid; $facturefournstatic->type=$obj->type; $facture = $facturefournstatic->getNomUrl(1,''); // On recherche les paiements deja effectue pour les deduires $sqlp = "SELECT sum(-1*amount) as paiement"; $sqlp.= " FROM ".MAIN_DB_PREFIX.'paiementfourn_facturefourn'; $sqlp.= " WHERE fk_facturefourn = ".$obj->facid; $resql = $db->query($sqlp); if ($resql) { $objp = $db->fetch_object($resql); if ($objp) $paiement = $objp->paiement; } } else { $facturestatic->ref=$obj->facnumber; $facturestatic->id=$obj->facid; $facturestatic->type=$obj->type; $facture = $facturestatic->getNomUrl(1,''); // On recherche les paiements deja effectue pour les deduires $sqlp = "SELECT sum(amount) as paiement"; $sqlp.= " FROM ".MAIN_DB_PREFIX.'paiement_facture'; $sqlp.= " WHERE fk_facture = ".$obj->facid; $resql = $db->query($sqlp); if ($resql) { $objp = $db->fetch_object($resql); if ($objp) $paiement = $objp->paiement; } } $total_ttc = $obj->total_ttc; if ($paiement) $total_ttc = $obj->total_ttc - $paiement; $solde += $total_ttc; print ""; print ""; print ""; print ""; if ($obj->total_ttc < 0) { print ""; }; if ($obj->total_ttc >= 0) { print ""; }; print ""; print ""; $i++; } $db->free($result); } else { dolibarr_print_error($db); } print "
'.$langs->trans("Invoices").''.$langs->trans("ThirdParty").''.$langs->trans("DateEcheance").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("BankBalance").'
'.$langs->trans("CurrentBalance").''.price($solde).'
".$facture."".$societestatic->getNomUrl(0,'',16)."".dolibarr_print_date($obj->dlr,"day")."".price($total_ttc)."  ".price($total_ttc)."".price($solde)."
"; } else { print $langs->trans("ErrorBankAccountNotFound"); } $db->close(); llxFooter('$Date$ - $Revision$'); ?>