* Copyright (C) 2004-2012 Laurent Destailleur * * 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 3 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, see . */ /** * \file htdocs/compta/recap-compta.php * \ingroup compta * \brief Page de fiche recap compta */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $langs->load("companies"); if (! empty($conf->facture->enabled)) $langs->load("bills"); // Security check $socid = GETPOST("socid",'int'); if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } /* * View */ $userstatic=new User($db); llxHeader(); if ($socid > 0) { $societe = new Societe($db); $societe->fetch($socid); /* * Affichage onglets */ $head = societe_prepare_head($societe); dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), 0, 'company'); print "\n"; print '
'; print ''; // Name print ''; // Prefix if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } print "
'.$langs->trans("Name").''.$societe->name.'
'.$langs->trans("Prefix").''; print ($societe->prefix_comm?$societe->prefix_comm:' '); print '
"; print "
\n"; print ''; if (! empty($conf->facture->enabled) && $user->rights->facture->lire) { // Factures print_fiche_titre($langs->trans("CustomerPreview")); print ''; $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,"; $sql.= " u.login, u.rowid as userid"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."user as u"; $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"; $resql=$db->query($sql); if ($resql) { $var=true; $num = $db->num_rows($resql); print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if (! $num > 0) { print ''; } $solde = 0; // Boucle sur chaque facture for ($i = 0 ; $i < $num ; $i++) { $objf = $db->fetch_object($resql); $fac = new Facture($db); $ret=$fac->fetch($objf->facid); if ($ret < 0) { print $fac->error."
"; continue; } $totalpaye = $fac->getSommePaiement(); $var=!$var; print ""; print "\n"; print '\n"; print ''; print '\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 '\n"; // Author $userstatic->id=$objf->userid; $userstatic->login=$objf->login; print ''; print "\n"; // Paiements $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,"; $sql.= " p.fk_user_creat, u.login, u.rowid as userid"; $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf,"; $sql.= " ".MAIN_DB_PREFIX."paiement as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON p.fk_user_creat = u.rowid"; $sql.= " WHERE pf.fk_paiement = p.rowid"; $sql.= " AND p.entity = ".$conf->entity; $sql.= " AND pf.fk_facture = ".$fac->id; $resqlp = $db->query($sql); if ($resqlp) { $nump = $db->num_rows($resqlp); $j = 0; while ($j < $nump) { $objp = $db->fetch_object($resqlp); //$var=!$var; print ""; print '\n"; print ''; print "\n"; print "\n"; print ''; $solde = $solde - $objp->amount; print '\n"; // Author $userstatic->id=$objp->userid; $userstatic->login=$objp->login; print ''; print ''; $j++; } $db->free($resqlp); } else { dol_print_error($db); } } } else { dol_print_error($db); } print "
'.$langs->trans("Date").' '.$langs->trans("Status").''.$langs->trans("Debit").''.$langs->trans("Credit").''.$langs->trans("Balance").' 
'.$langs->trans("NoInvoice").'
".dol_print_date($fac->date,'day')."'.img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."'.$fac->getLibStatut(2,$totalpaye).''.price($fac->total_ttc)." '.price($solde)."'; print $userstatic->getLoginUrl(1); print '
'.dol_print_date($db->jdate($objp->dp),'day')."'; print '      '; // Decalage print ''.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.'  '.price($objp->amount).''.price($solde)."'; print $userstatic->getLoginUrl(1); print '
"; print "
"; } } else { dol_print_error($db); } llxFooter(); $db->close();