dolibarr/htdocs/compta/index.php

402 lines
11 KiB
PHP
Raw Normal View History

<?php
2004-02-13 15:23:48 +01:00
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
2002-04-30 12:44:42 +02:00
*
* 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.
*
2002-06-20 15:23:17 +02:00
* $Id$
* $Source$
*
2002-04-30 12:44:42 +02:00
*/
/** \file htdocs/compta/index.php
\ingroup compta
2004-11-23 21:25:10 +01:00
\brief Page accueil zone comptabilit<EFBFBD>
\version $Revision$
*/
2003-09-11 22:18:51 +02:00
require("./pre.inc.php");
2002-04-30 12:44:42 +02:00
2004-07-29 17:05:23 +02:00
$user->getrights('banque');
$langs->load("compta");
2003-03-23 19:17:15 +01:00
/*
* S<EFBFBD>curit<EFBFBD> acc<EFBFBD>s client
*/
if ($user->societe_id > 0)
{
$action = '';
$socidp = $user->societe_id;
}
2003-09-10 15:03:59 +02:00
llxHeader("","Accueil Compta");
2002-04-30 12:44:42 +02:00
2002-05-11 20:53:13 +02:00
/*
* Actions
2002-05-11 20:53:13 +02:00
*/
if ($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);
}
2002-04-30 12:44:42 +02:00
}
2002-05-11 20:53:13 +02:00
if ($action == 'del_bookmark')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=$bid";
2002-05-11 20:53:13 +02:00
$result = $db->query($sql);
2002-04-30 12:44:42 +02:00
}
2003-02-02 16:01:56 +01:00
/*
* Affichage page
2003-02-02 16:01:56 +01:00
*
*/
print_titre("Espace comptabilit<69>");
2002-04-30 12:44:42 +02:00
print '<table border="0" width="100%">';
2002-04-30 12:44:42 +02:00
print '<tr><td valign="top" width="30%">';
2003-09-03 16:01:28 +02:00
/*
* Zone recherche facture
2003-09-03 16:01:28 +02:00
*/
print '<form method="post" action="facture.php">';
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">";
2003-09-03 16:01:28 +02:00
print '<td colspan="2">Rechercher une facture</td></tr>';
2004-02-13 15:23:48 +01:00
print "<tr $bc[0]><td>";
2004-08-02 04:41:23 +02:00
print $langs->trans("Ref").' : <input type="text" name="sf_ref">&nbsp;<input type="submit" value="'.$langs->trans("Search").'" class="flat"></td></tr>';
print "</table></form><br>";
/*
* Factures brouillons
*/
2004-07-29 15:32:29 +02:00
if ($conf->facture->enabled)
2003-09-10 15:03:59 +02:00
{
2004-07-29 15:32:29 +02:00
$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.fk_statut = 0";
if ($socidp)
2003-09-10 15:03:59 +02:00
{
2004-07-29 15:32:29 +02:00
$sql .= " AND f.fk_soc = $socidp";
}
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
if ($num)
2003-09-10 15:03:59 +02:00
{
print '<table class="noborder" width="100%">';
2004-07-29 15:32:29 +02:00
print '<tr class="liste_titre">';
print '<td colspan="2">Factures brouillons ('.$num.')</td></tr>';
2004-07-29 15:32:29 +02:00
$var = True;
while ($i < $num && $i < 20)
2004-07-29 15:32:29 +02:00
{
$obj = $db->fetch_object();
2004-07-29 15:32:29 +02:00
$var=!$var;
print '<tr '.$bc[$var].'><td width="92"><a href="facture.php?facid='.$obj->rowid.'">'.img_file().'</a>&nbsp;';
print '<a href="facture.php?facid='.$obj->rowid.'">'.$obj->facnumber.'</a></td>';
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
$i++;
}
print "</table><br>";
2003-09-10 15:03:59 +02:00
}
}
2004-07-29 15:32:29 +02:00
else
{
dolibarr_print_error($db);
2004-07-29 15:32:29 +02:00
}
}
if ($conf->compta->enabled) {
2003-08-12 15:28:56 +02:00
/*
* Charges a payer
*/
if ($user->societe_id == 0)
{
2003-03-23 19:17:15 +01:00
$sql = "SELECT c.amount, cc.libelle";
$sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc";
2003-03-23 19:17:15 +01:00
$sql .= " WHERE c.fk_type = cc.id AND c.paye=0";
if ( $db->query($sql) )
2002-12-20 00:17:19 +01:00
{
2003-03-23 19:17:15 +01:00
$num = $db->num_rows();
if ($num)
2002-12-20 00:17:19 +01:00
{
print '<table class="noborder" width="100%">';
2004-02-13 15:32:53 +01:00
print '<tr class="liste_titre">';
print '<td colspan="2">Charges <20> payer ('.$num.')</td></tr>';
2003-03-23 19:17:15 +01:00
$i = 0;
2004-02-13 15:32:53 +01:00
$var = True;
2003-03-23 19:17:15 +01:00
while ($i < $num)
{
$obj = $db->fetch_object();
2003-03-23 19:17:15 +01:00
$var = !$var;
print "<tr $bc[$var]>";
print '<td>'.$obj->libelle.'</td>';
print '<td align="right">'.price($obj->amount).'</td>';
print '</tr>';
$i++;
}
print '</table><br>';
2002-12-20 00:17:19 +01:00
}
2002-06-20 15:23:17 +02:00
}
2003-03-23 19:17:15 +01:00
else
{
dolibarr_print_error($db);
2003-03-23 19:17:15 +01:00
}
2002-06-20 15:23:17 +02:00
}
}
2002-05-11 20:53:13 +02:00
/*
2002-06-20 15:23:17 +02:00
* Bookmark
2002-05-11 20:53:13 +02:00
*/
$sql = "SELECT s.idp, s.nom,b.rowid as bid";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
2002-05-11 20:53:13 +02:00
$sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id;
$sql .= " ORDER BY lower(s.nom) ASC";
if ( $db->query($sql) )
{
2002-05-11 20:53:13 +02:00
$num = $db->num_rows();
2002-05-03 14:16:51 +02:00
$i = 0;
2004-03-08 15:51:14 +01:00
if ($num)
{
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\"><td colspan=\"2\">Bookmark</td></tr>\n";
2004-03-08 15:51:14 +01:00
$var = True;
while ($i < $num)
{
$obj = $db->fetch_object();
2004-03-08 15:51:14 +01:00
$var = !$var;
print "<tr $bc[$var]>";
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">';
print '<img src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/editdelete.png" alt="Supprimer" border="0"></a></td>';
print '</tr>';
$i++;
}
print '</table>';
}
2002-05-11 20:53:13 +02:00
}
print '</td><td valign="top" width="70%">';
2002-05-11 20:53:13 +02:00
/*
* Commandes <EFBFBD> facturer
*/
if ($conf->commande->enabled && $user->rights->commande->lire)
2003-09-05 22:02:40 +02:00
{
$langs->load("orders");
$sql = "SELECT p.rowid, p.ref, s.nom, s.idp FROM ".MAIN_DB_PREFIX."commande as p, ".MAIN_DB_PREFIX."societe as s";
2003-11-25 13:17:05 +01:00
$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut >= 1 AND p.facture = 0";
if ($socidp)
{
$sql .= " AND p.fk_soc = $socidp";
}
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
$i = 0;
print '<table class="noborder" width="100%">';
print "<tr class=\"liste_titre\">";
print '<td colspan="2">'.$langs->trans("OrdersToBill").' ('.$num.')</td></tr>';
2004-02-13 15:23:48 +01:00
$var = True;
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object();
2004-02-13 15:32:53 +01:00
print "<tr $bc[$var]><td width=\"20%\"><a href=\"commande.php?id=$obj->rowid\">".img_file()."</a>";
print "&nbsp;<a href=\"commande.php?id=$obj->rowid\">$obj->ref</a></td>";
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
$i++;
}
print "</table><br>";
}
}
else {
dolibarr_print_error($db);
}
2003-09-05 22:02:40 +02:00
}
2004-07-29 15:32:29 +02:00
if ($conf->facture->enabled)
{
2004-07-29 15:32:29 +02:00
/*
* Factures impay<EFBFBD>es
*
*/
$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc, sum(pf.amount) as am";
2004-07-29 15:32:29 +02:00
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
$sql .= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
if ($socidp)
{
2004-07-29 15:32:29 +02:00
$sql .= " AND f.fk_soc = $socidp";
}
2004-09-06 22:10:57 +02:00
$sql .= " GROUP BY f.facnumber,f.rowid,s.nom, s.idp, f.total_ttc";
2004-07-29 15:32:29 +02:00
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
if ($num)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">Factures clients impay<61>es ('.$num.')</td><td align="right">Montant HT</td><td align="right">Montant TTC</td><td align="right">Re<52>u</td></tr>';
2004-07-29 15:32:29 +02:00
$var = True;
$total_ttc = $totalam = $total = 0;
2004-12-17 16:25:13 +01:00
while ($i < $num)
2004-07-29 15:32:29 +02:00
{
$obj = $db->fetch_object();
2004-12-17 16:25:13 +01:00
if ($i < 20)
{
$var=!$var;
print '<tr '.$bc[$var].'><td width="20%"><a href="facture.php?facid='.$obj->rowid.'">'.img_file().'</a>';
print '&nbsp;<a href="facture.php?facid='.$obj->rowid.'">'.$obj->facnumber.'</a></td>';
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
print '<td align="right">'.price($obj->total).'</td>';
2004-12-17 16:25:13 +01:00
print '<td align="right">'.price($obj->total_ttc).'</td>';
print '<td align="right">'.price($obj->am).'</td></tr>';
}
$total_ttc += $obj->total_ttc;
$total += $obj->total;
2004-07-29 15:32:29 +02:00
$totalam += $obj->am;
$i++;
}
$var=!$var;
2005-01-19 22:14:00 +01:00
# print '<tr '.$bc[$var].'><td colspan="2" align="left"><i>'.$langs->trans("Total").':</i></td><td align="right"><i>'.price($total)."</i></td><td align=\"right\"><i>".price($total_ttc)."</i></td><td align=\"right\"><i>".price($totalam)."</i></td></tr>";
# print '<tr '.$bc[!$var].'><td colspan="3" align="left"><i>Reste <20> encaisser:</i></td><td align="right"><i>'.price($total_ttc-$totalam).'</i></td><td>&nbsp;</td></tr>';
print '<tr '.$bc[$var].'><td colspan="2" align="left"><i>'.$langs->trans("Total").' &nbsp; (Reste <20> encaisser: '.price($total_ttc-$totalam).')</i></td><td align="right"><i>'.price($total)."</i></td><td align=\"right\"><i>".price($total_ttc)."</i></td><td align=\"right\"><i>".price($totalam)."</i></td></tr>";
2004-07-29 15:32:29 +02:00
print "</table><br>";
}
2004-07-29 15:32:29 +02:00
$db->free();
}
2004-07-29 15:32:29 +02:00
else
{
dolibarr_print_error($db);
2004-07-29 15:32:29 +02:00
}
}
// \todo Mettre ici recup des actions en rapport avec la compta
2003-09-10 15:03:59 +02:00
$result = 0;
2004-02-13 15:23:48 +01:00
if ( $result )
{
print '<table class="noborder" width="100%">';
2004-02-13 15:23:48 +01:00
print '<tr class="liste_titre"><td colspan="2">Actions <20> faire</td>';
print "</tr>\n";
$var = True;
2003-09-10 15:03:59 +02:00
$i = 0;
2004-02-13 15:23:48 +01:00
while ($i < $db->num_rows() )
{
$obj = $db->fetch_object();
2004-02-13 15:23:48 +01:00
$var=!$var;
print "<tr $bc[$var]><td>".strftime("%d %b %Y",$obj->da)."</td><td><a href=\"action/fiche.php\">$obj->libelle $obj->label</a></td></tr>";
$i++;
}
2003-09-10 15:03:59 +02:00
$db->free();
print "</table><br>";
2004-02-13 15:23:48 +01:00
}
2003-09-10 15:03:59 +02:00
2003-02-02 16:01:56 +01:00
/*
* Factures a payer
2003-02-02 16:01:56 +01:00
*/
if ($conf->facture->enabled) {
if ($user->societe_id == 0)
2003-02-02 16:01:56 +01:00
{
$sql = "SELECT ff.rowid, ff.facnumber, ff.libelle, ff.total_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
$sql .= " WHERE ff.paye=0";
if ( $db->query($sql) )
{
$num = $db->num_rows();
if ($num)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">Factures fournisseurs <20> payer ('.$num.')</td><td align="right">Montant TTC</td></tr>';
print "</tr>\n";
$i = 0;
$var = True;
$total = $totalam = 0;
while ($i < $num)
{
$obj = $db->fetch_object();
$var = !$var;
print '<tr '.$bc[$var].'><td width="20%"><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$obj->rowid.'">'.img_file().'</a>';
print '&nbsp;<a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$obj->rowid.'">'.$obj->facnumber.'</a></td>';
print '<td><a href="../fourn/facture/fiche.php?facid='.$obj->rowid.'">'.$obj->libelle.'</a></td>';
print '<td align="right">'.price($obj->total_ttc).'</td>';
print '</tr>';
$total += $obj->total_ttc;
$totalam += $obj->am;
$i++;
}
$var=!$var;
print '<tr '.$bc[$var].'><td colspan="2" align="left">Reste <20> payer : '.price($total-$totalam).'</td><td align="right">'.price($total).'</td></tr>';
print '</table><br>';
}
}
else
{
dolibarr_print_error($db);
}
2003-03-23 19:17:15 +01:00
}
2002-05-03 13:34:33 +02:00
}
print '</td></tr>';
2002-05-11 20:53:13 +02:00
print '</table>';
2002-05-03 13:34:33 +02:00
2002-04-30 12:44:42 +02:00
$db->close();
2002-05-11 20:53:13 +02:00
2002-04-30 12:44:42 +02:00
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>");
?>