dolibarr/htdocs/compta/index.php

358 lines
8.5 KiB
PHP
Raw Normal View History

2002-04-30 12:44:42 +02:00
<?PHP
2003-03-23 19:17:15 +01:00
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 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
*/
2003-09-11 22:18:51 +02:00
require("./pre.inc.php");
2002-04-30 12:44:42 +02:00
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
/*
*
*/
if ($action == 'add_bookmark')
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$socidp." AND fk_user=".$user->id;
if (! $db->query($sql) )
{
print $db->error();
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),".$user->id.");";
if (! $db->query($sql) )
{
print $db->error();
}
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
/*
*
*
*/
print_titre(translate("Espace comptabilit<69>"));
2002-04-30 12:44:42 +02:00
print '<table border="0" width="100%" cellspacing="0" cellpadding="4">';
2002-04-30 12:44:42 +02:00
print '<tr><td valign="top" width="30%">';
2003-09-03 16:01:28 +02:00
/*
*
*/
print '<form method="post" action="facture.php">';
print '<table border="0" cellspacing="0" cellpadding="3" width="100%">';
print "<tr class=\"liste_titre\">";
2003-09-03 16:01:28 +02:00
print '<td colspan="2">Rechercher une facture</td></tr>';
print "<tr $bc[1]><td>";
print 'Num. : <input type="text" name="sf_ref">&nbsp;<input type="submit" value="Rechercher" class="flat"></td></tr>';
print "</table></form>";
2003-08-12 15:28:56 +02:00
/*
*
2003-08-12 15:28:56 +02:00
*/
print '<div class="menus">';
if ($user->societe_id == 0)
2002-12-20 00:17:19 +01:00
{
print '<ul>';
print '<li><a href="./charges/index.php">Charges</a></li>';
print '<li><a href="./resultat/">R<>sultats</a></li>';
print '<li><a href="bank/index.php">Banque</a></li>';
2003-08-12 15:28:56 +02:00
}
print '</ul></div><br>';
2003-09-10 15:03:59 +02:00
/*
* Factures brouillons
*/
$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";
2003-09-10 15:03:59 +02:00
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
if ($num)
{
print '<TABLE border="0" cellspacing="0" cellpadding="3" width="100%">';
print '<TR class="liste_titre">';
print '<td colspan="2">Factures brouillons</td></tr>';
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$var=!$var;
2003-10-14 17:13:36 +02:00
print '<tr '.$bc[$var].'><td><a href="facture.php?facid='.$obj->rowid.'">'.$obj->facnumber.'</a></td>';
2003-09-11 22:18:51 +02:00
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td></tr>';
2003-09-10 15:03:59 +02:00
$i++;
}
print "</table><br>";
}
}
else
{
print $sql;
}
2003-03-23 19:17:15 +01:00
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
{
2003-08-17 16:49:16 +02:00
print "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
2003-03-23 19:17:15 +01:00
print "<TR class=\"liste_titre\">";
print "<TD colspan=\"2\">Charges <20> payer</td>";
print "</TR>\n";
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$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
{
print $db->error();
}
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;
2002-05-11 20:53:13 +02:00
2002-05-03 14:16:51 +02:00
print "<TABLE border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">";
2002-05-11 20:53:13 +02:00
print "<TR class=\"liste_titre\">";
print "<TD colspan=\"2\">Bookmark</td>";
2002-05-03 14:16:51 +02:00
print "</TR>\n";
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$var = !$var;
print "<tr $bc[$var]>";
2003-09-11 22:18:51 +02:00
print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
2003-10-21 16:30:06 +02:00
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++;
}
2002-05-11 20:53:13 +02:00
print '</table>';
}
/*
*
*
*/
print '</td><td valign="top" width="70%">';
2002-05-11 20:53:13 +02:00
/*
* Commandes <EFBFBD> facturer
*/
if ($user->comm > 0 && $conf->commercial )
2003-09-05 22:02:40 +02:00
{
$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 border="0" cellspacing="0" cellpadding="3" width="100%">';
print "<tr class=\"liste_titre\">";
print '<td colspan="2">'.translate("Commandes <20> facturer").'</td></tr>';
while ($i < $num)
{
$var=!$var;
$obj = $db->fetch_object($i);
print "<tr $bc[$var]><td width=\"20%\"><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>";
}
}
2003-09-05 22:02:40 +02:00
}
/*
2003-09-10 15:03:59 +02:00
* Factures impay<EFBFBD>es
*/
$sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total_ttc FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut > 0";
2003-09-10 15:03:59 +02:00
if ($socidp)
{
$sql .= " AND f.fk_soc = $socidp";
}
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
if ($num)
{
print '<TABLE border="0" cellspacing="0" cellpadding="3" width="100%">';
2003-09-10 15:03:59 +02:00
print "<TR class=\"liste_titre\">";
print '<td colspan="3">Factures impay<61>es</td></tr>';
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$var=!$var;
print '<tr '.$bc[$var].'><td width="20%"><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_ttc).'</td></tr>';
$i++;
}
print "</table><br>";
}
2003-09-10 15:03:59 +02:00
$db->free();
}
else
{
print $sql;
}
2003-03-23 19:17:15 +01:00
2003-09-10 15:03:59 +02:00
$result = 0;
if ( $result ) {
print '<TABLE border="0" cellspacing="0" cellpadding="3" width="100%">';
print "<TR class=\"liste_titre\">";
print "<td colspan=\"2\">Actions <20> faire</td>";
print "</TR>\n";
$i = 0;
while ($i < $db->num_rows() ) {
$obj = $db->fetch_object($i);
$var=!$var;
2003-09-11 22:18:51 +02:00
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>";
2003-09-10 15:03:59 +02:00
$i++;
}
$db->free();
print "</table><br>";
} else {
print $db->error();
}
/*
*
*
*/
2003-02-02 16:01:56 +01:00
/*
* Factures a payer
2003-02-02 16:01:56 +01:00
*
*/
2003-03-23 19:17:15 +01:00
if ($user->societe_id == 0)
2003-02-02 16:01:56 +01:00
{
$sql = "SELECT ff.total_ttc as amount, ff.libelle, ff.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
2003-03-23 19:17:15 +01:00
$sql .= " WHERE ff.paye=0";
if ( $db->query($sql) )
2003-02-02 16:01:56 +01:00
{
2003-03-23 19:17:15 +01:00
$num = $db->num_rows();
if ($num)
2003-02-02 16:01:56 +01:00
{
2003-03-23 19:17:15 +01:00
print '<table border="0" width="100%" cellspacing="0" cellpadding="4">';
print '<TR class="liste_titre">';
print '<TD colspan="2">Factures <20> payer</td>';
2003-03-23 19:17:15 +01:00
print "</TR>\n";
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object( $i);
$var = !$var;
print "<tr $bc[$var]>";
2003-09-11 22:18:51 +02:00
print '<td><a href="../fourn/facture/fiche.php?facid='.$obj->rowid.'">'.$obj->libelle.'</a></td>';
2003-03-23 19:17:15 +01:00
print '<td align="right">'.price($obj->amount).'</td>';
print '</tr>';
$i++;
}
print '</table><br>';
2003-02-02 16:01:56 +01:00
}
}
2003-03-23 19:17:15 +01:00
else
{
print $db->error();
}
2003-02-02 16:01:56 +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>");
?>