* Copyright (C) 2004-2005 Laurent Destailleur * Copyright (C) 2005-2006 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. * * $Id$ * $Source$ */ /** \file htdocs/compta/index.php \ingroup compta \brief Page accueil zone comptabilité \version $Revision$ */ require("./pre.inc.php"); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); if ($conf->facture->enabled) require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); if ($conf->facture->enabled) require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.facture.class.php'); $user->getrights(); // On a besoin des permissions sur plusieurs modules // L'espace compta/tréso doit toujours etre actif car c'est un espace partagé // par de nombreux modules (banque, facture, commande à facturer, etc...) indépendemment // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction // est protégé par le droit qui va bien du module concerné. //if (!$user->rights->compta->general->lire) // accessforbidden(); $langs->load("compta"); $langs->load("bills"); if ($conf->commande->enabled) $langs->load("orders"); // Sécurité accés client $socidp=''; if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * Actions */ if (isset($_GET["action"]) && $_GET["action"] == 'add_bookmark') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$socidp." AND fk_user=".$user->id; if (! $db->query($sql) ) { dolibarr_print_error($db); } $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),".$user->id.");"; if (! $db->query($sql) ) { dolibarr_print_error($db); } } if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark') { $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$_GET["bid"]; $result = $db->query($sql); } /* * Affichage page * */ llxHeader("",$langs->trans("AccountancyTreasuryArea")); print_fiche_titre($langs->trans("AccountancyTreasuryArea")); print ''; print ''; print '
'; /* * Zone recherche facture */ if ($conf->facture->enabled) { print '
'; print ''; print ""; print ''; print "'; print ''; print "'; print ''; print "
'.$langs->trans("SearchABill").'
".$langs->trans("Ref").':
".$langs->trans("Other").':

"; } /** * Factures brouillons */ if ($conf->facture->enabled && $user->rights->facture->lire) { $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom, s.idp"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user "; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socidp) { $sql .= " AND f.fk_soc = $socidp"; } $resql = $db->query($sql); if ( $resql ) { $num = $db->num_rows($resql); if ($num) { print ''; print ''; print ''; $i = 0; $tot_ttc = 0; $var = True; while ($i < $num && $i < 20) { $obj = $db->fetch_object($resql); $var=!$var; print ''; print ''; print ''; print ''; $tot_ttc+=$obj->total_ttc; $i++; } print ''; print ''; print ''; print "
'.$langs->trans("DraftBills").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,16).''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'

"; } $db->free($resql); } else { dolibarr_print_error($db); } } /** * Charges a payer */ if ($conf->compta->enabled || $conf->comptaexpert->enabled) { if ($user->societe_id == 0) { $sql = "SELECT c.rowid, c.amount, cc.libelle"; $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc"; $sql .= " WHERE c.fk_type = cc.id AND c.paye=0"; $resql = $db->query($sql); if ( $resql ) { $num = $db->num_rows($resql); if ($num) { print ''; print ''; print ''; $i = 0; $tot_ttc=0; $var = True; while ($i < $num) { $obj = $db->fetch_object($resql); $var = !$var; print ""; print ''; print ''; print ''; $tot_ttc+=$obj->amount; $i++; } print ''; print ''; print ''; print '
'.$langs->trans("ContributionsToPay").' ('.$num.')
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->libelle.''.price($obj->amount).'
'.$langs->trans("Total").''.price($tot_ttc).'

'; } $db->free($resql); } else { dolibarr_print_error($db); } } } /** * Bookmark */ $sql = "SELECT s.idp, s.nom,b.rowid as bid"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b"; $sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id; $sql .= " ORDER BY lower(s.nom) ASC"; $resql = $db->query($sql); if ( $resql ) { $num = $db->num_rows($resql); $i = 0; if ($num) { print ''; print "\n"; $var = True; while ($i < $num) { $obj = $db->fetch_object($resql); $var = !$var; print ""; print ''; print ''; print ''; $i++; } print '
".$langs->trans("Bookmarks")."
'.$obj->nom.''.img_delete().'
'; } $db->free($resql); } else { dolibarr_print_error($db); } print '
'; /* * Commandes à facturer */ if ($conf->facture->enabled && $conf->commande->enabled && $user->rights->commande->lire) { $commandestatic=new Commande($db); $langs->load("orders"); $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc,"; $sql.= " s.nom, s.idp,"; $sql.= " p.rowid, p.ref, p.facture, p.fk_statut, p.total_ht, p.total_ttc"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."commande AS p"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid"; $sql.= " WHERE p.fk_soc = s.idp"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socidp) { $sql.= " AND p.fk_soc = $socidp"; } $sql.= " AND p.fk_statut = 3 AND p.facture=0"; $sql.= " GROUP BY p.rowid"; $resql = $db->query($sql); if ( $resql ) { $num = $db->num_rows($resql); if ($num) { $i = 0; print ''; print ""; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; $var = True; $tot_ht=$tot_ttc=$tot_tobill=0; while ($i < $num) { $obj = $db->fetch_object($resql); // if ($obj->total_ttc-$obj->tot_fttc >0) // { $var=!$var; print ""; print "'; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; $tot_ht += $obj->total_ht; $tot_ttc += $obj->total_ttc; $tot_tobill += ($obj->total_ttc-$obj->tot_fttc); // } $i++; } $var=!$var; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("OrdersToBill").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("ToBill").' 
rowid\">".img_object($langs->trans("ShowOrder"),"order").' '; print "rowid\">".$obj->ref.''.img_object($langs->trans("ShowCompany"),"company").' '; print ''.dolibarr_trunc($obj->nom,44).''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->total_ttc-$obj->tot_fttc).''.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,3).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToBill").': '.price($tot_tobill).') '.price($tot_ht).''.price($tot_ttc).''.price($tot_tobill).' 

'; } $db->free($resql); } else { dolibarr_print_error($db); } } /* * Factures impayées */ if ($conf->facture->enabled && $user->rights->facture->lire) { $facstatic=new Facture($db); $sql = "SELECT f.rowid, f.facnumber, f.fk_statut, f.total, f.total_ttc, ".$db->pdate("f.date_lim_reglement")." as datelimite,"; $sql.= " sum(pf.amount) as am,"; $sql.= " s.nom, s.idp"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socidp) $sql .= " AND f.fk_soc = ".$socidp; $sql.= " GROUP BY f.rowid, f.facnumber, f.fk_statut, f.total, f.total_ttc, s.nom, s.idp"; $sql.= " ORDER BY f.datef ASC, f.facnumber ASC"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { print ''; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; $var = True; $total_ttc = $totalam = $total = 0; while ($i < $num) { $obj = $db->fetch_object($resql); if ($i < $conf->liste_limit) { $var=!$var; print ''; print ''; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; } $total_ttc += $obj->total_ttc; $total += $obj->total; $totalam += $obj->am; $i++; } $var=!$var; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("BillsCustomersUnpayed",min($conf->liste_limit,$num)).' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").' 
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''; if ($obj->datelimite < (time() - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late")); print ''.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).''.price($obj->total).''.price($obj->total_ttc).''.price($obj->am).''.$facstatic->LibStatut($obj->paye,$obj->fk_statut,3,$obj->am).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).''.price($totalam).' 

'; } $db->free($resql); } else { dolibarr_print_error($db); } } /* * Factures a payer */ if ($conf->facture->enabled && $user->rights->facture->lire) { $facstatic=new FactureFournisseur($db); if ($user->societe_id == 0) { $sql = "SELECT ff.rowid, ff.facnumber, ff.fk_statut, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc,"; $sql.= " sum(pf.amount) as am,"; $sql.= " s.nom, s.idp"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.idp = ff.fk_soc"; $sql.= " AND ff.paye=0 AND ff.fk_statut = 1"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY ff.rowid, ff.facnumber, ff.fk_statut, ff.total, ff.total_ttc, s.nom, s.idp"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { print ''; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print "\n"; $i = 0; $var = True; $total = $total_ttc = $totalam = 0; while ($i < $num) { $obj = $db->fetch_object($resql); $var = !$var; print ''; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; $total += $obj->total_ht; $total_ttc += $obj->total_ttc; $totalam += $obj->am; $i++; } $var=!$var; print ''; if ($conf->global->MAIN_SHOW_HT_ON_SUMMARY) print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("BillsSuppliersUnpayed").' ('.$num.')'.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Payed").' 
'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.''.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,44).''.price($obj->total_ht).''.price($obj->total_ttc).''.price($obj->am).''.$facstatic->LibStatut($obj->paye,$obj->fk_statut,3).'
'.$langs->trans("Total").'   ('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).') '.price($total).''.price($total_ttc).''.price($totalam).' 

'; } } else { dolibarr_print_error($db); } } } // \todo Mettre ici recup des actions en rapport avec la compta $resql = 0; if ($resql) { print ''; print ''; print "\n"; $var = True; $i = 0; while ($i < $db->num_rows($resql) ) { $obj = $db->fetch_object($resql); $var=!$var; print ""; print ""; $i++; } $db->free($resql); print "
'.$langs->trans("TasksToDo").'
".dolibarr_print_date($obj->da,"%d %b %Y")."$obj->libelle $obj->label

"; } print '
'; $db->close(); llxFooter('$Date$ - $Revision$'); ?>