2004-10-19 20:43:23 +00:00
< ? php
2006-12-02 20:32:02 +00:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2007-03-29 19:35:39 +00:00
* Copyright ( C ) 2004 - 2007 Laurent Destailleur < eldy @ users . sourceforge . net >
2008-06-18 20:01:01 +00:00
* Copyright ( C ) 2005 - 2008 Regis Houssin < regis @ dolibarr . fr >
2003-08-04 12:42:49 +00: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 .
*/
2004-10-24 22:25:38 +00:00
2005-04-25 23:25:18 +00:00
/**
2006-12-09 21:08:43 +00:00
\file htdocs / fourn / index . php
\ingroup fournisseur
\brief Page accueil de la zone fournisseurs
2008-02-25 16:30:43 +00:00
\version $Id $
2005-01-08 22:20:19 +00:00
*/
2003-09-11 20:18:51 +00:00
require ( " ./pre.inc.php " );
2007-03-29 20:07:44 +00:00
require_once ( DOL_DOCUMENT_ROOT . '/fourn/fournisseur.commande.class.php' );
require_once ( DOL_DOCUMENT_ROOT . '/fourn/fournisseur.facture.class.php' );
2004-11-30 19:34:29 +00:00
2004-11-30 09:52:01 +00:00
$langs -> load ( " suppliers " );
$langs -> load ( " orders " );
2004-11-30 19:34:29 +00:00
$langs -> load ( " companies " );
2004-10-24 22:25:38 +00:00
2008-02-25 16:30:43 +00:00
// Security check
$socid = isset ( $_GET [ " socid " ]) ? $_GET [ " socid " ] : '' ;
2008-02-25 20:03:21 +00:00
if ( $user -> societe_id ) $socid = $user -> societe_id ;
2008-03-01 01:26:41 +00:00
$result = restrictedArea ( $user , 'societe' , $socid , '' );
2003-08-04 12:42:49 +00:00
2007-03-29 19:35:39 +00:00
/*
* Affichage page
*/
2007-03-29 20:07:44 +00:00
$commandestatic = new CommandeFournisseur ( $db );
$facturestatic = new FactureFournisseur ( $db );
$companystatic = new Societe ( $db );
2007-03-29 19:35:39 +00:00
llxHeader ( " " , $langs -> trans ( " SuppliersArea " ));
print_fiche_titre ( $langs -> trans ( " SuppliersArea " ));
2006-12-09 21:08:43 +00:00
print '<table border="0" width="100%" class="notopnoleftnoright">' ;
print '<tr><td valign="top" width="30%" class="notopnoleft">' ;
2004-02-02 03:14:29 +00:00
2007-03-29 20:07:44 +00:00
2006-12-09 21:08:43 +00:00
/*
* Liste des categories
*/
2007-11-11 21:31:43 +00:00
$companystatic -> LoadSupplierCateg ();
2003-08-04 12:42:49 +00:00
2007-11-11 21:31:43 +00:00
if ( sizeof ( $companystatic -> SupplierCategories ))
2006-12-09 21:08:43 +00:00
{
2007-03-29 20:07:44 +00:00
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre"><td colspan="2">' ;
print $langs -> trans ( " Category " );
print " </td></tr> \n " ;
$var = True ;
2007-11-11 21:31:43 +00:00
foreach ( $companystatic -> SupplierCategories as $rowid => $label )
2007-03-29 20:07:44 +00:00
{
$var =! $var ;
print " <tr $bc[$var] > \n " ;
2007-11-11 21:31:43 +00:00
print '<td><a href="liste.php?cat=' . $rowid . '">' . stripslashes ( $label ) . '</a>' ;
2007-03-29 20:07:44 +00:00
print '</td><td align="right">' ;
2007-11-11 21:31:43 +00:00
print '<a href="stats.php?cat=' . $rowid . '">(' . $langs -> trans ( " Stats " ) . ')</a>' ;
2007-03-29 20:07:44 +00:00
print " </tr> \n " ;
}
print " </table> \n " ;
print " <br> \n " ;
2006-12-09 21:08:43 +00:00
}
2007-03-29 19:35:39 +00:00
2007-11-11 21:31:43 +00:00
2006-12-13 16:17:27 +00:00
/*
*
*/
$commande = new CommandeFournisseur ( $db );
2007-09-19 14:06:56 +00:00
$sql = " SELECT count(cf.rowid), fk_statut " ;
2006-12-13 16:17:27 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " ;
$sql .= " " . MAIN_DB_PREFIX . " commande_fournisseur as cf " ;
2007-06-11 22:51:47 +00:00
$sql .= " WHERE cf.fk_soc = s.rowid " ;
2006-12-13 16:17:27 +00:00
$sql .= " GROUP BY cf.fk_statut " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
2007-03-29 20:07:44 +00:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2006-12-13 16:17:27 +00:00
2007-03-29 20:07:44 +00:00
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre"><td>' . $langs -> trans ( " Orders " ) . '</td><td align="center">' . $langs -> trans ( " Nb " ) . '</td><td> </td>' ;
print " </tr> \n " ;
$var = True ;
2006-12-13 16:17:27 +00:00
2007-03-29 20:07:44 +00:00
while ( $i < $num )
{
$row = $db -> fetch_row ( $resql );
$var =! $var ;
print " <tr $bc[$var] > " ;
print '<td>' . $commande -> statuts [ $row [ 1 ]] . '</td>' ;
print '<td align="center">' . $row [ 0 ] . '</td>' ;
print '<td align="center"><a href="' . DOL_URL_ROOT . '/fourn/commande/liste.php?statut=' . $row [ 1 ] . '">' . $commande -> LibStatut ( $row [ 1 ], 3 ) . '</a></td>' ;
print " </tr> \n " ;
$i ++ ;
}
print " </table> " ;
print " <br> \n " ;
$db -> free ( $resql );
2006-12-13 16:17:27 +00:00
}
else
{
dolibarr_print_error ( $db );
}
2007-03-29 19:35:39 +00:00
2007-03-29 20:07:44 +00:00
/*
* Commandes brouillons
*/
if ( $conf -> fournisseur -> enabled )
{
$langs -> load ( " orders " );
2007-06-11 22:51:47 +00:00
$sql = " SELECT c.rowid, c.ref, c.total_ttc, s.nom, s.rowid as socid " ;
2007-03-29 20:07:44 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " commande_fournisseur as c, " . MAIN_DB_PREFIX . " societe as s " ;
2007-06-11 22:51:47 +00:00
$sql .= " WHERE c.fk_soc = s.rowid AND c.fk_statut = 0 " ;
2007-03-29 20:07:44 +00:00
if ( $socid )
{
$sql .= " AND c.fk_soc = " . $socid ;
}
$resql = $db -> query ( $sql );
if ( $resql )
{
$total = 0 ;
$num = $db -> num_rows ( $resql );
if ( $num )
{
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td colspan="3">' . $langs -> trans ( " DraftOrders " ) . '</td></tr>' ;
$i = 0 ;
$var = true ;
while ( $i < $num )
{
$var =! $var ;
$obj = $db -> fetch_object ( $resql );
2008-06-18 20:01:01 +00:00
print '<tr $bc[$var]><td nowrap="nowrap">' ;
2007-03-29 20:07:44 +00:00
$commandestatic -> id = $obj -> rowid ;
$commandestatic -> ref = $obj -> ref ;
print $commandestatic -> getNomUrl ( 1 , '' , 16 );
print '</td>' ;
2008-06-18 20:01:01 +00:00
print '<td nowrap="nowrap">' ;
2007-06-11 22:51:47 +00:00
$companystatic -> id = $obj -> socid ;
2007-03-29 20:07:44 +00:00
$companystatic -> nom = $obj -> nom ;
$companystatic -> client = 0 ;
print $companystatic -> getNomUrl ( 1 , '' , 16 );
print '</td>' ;
print '<td align="right" nowrap="nowrap">' . price ( $obj -> total_ttc ) . '</td></tr>' ;
$i ++ ;
$total += $obj -> total_ttc ;
}
if ( $total > 0 )
{
$var =! $var ;
print '<tr class="liste_total"><td>' . $langs -> trans ( " Total " ) . '</td><td colspan="2" align="right">' . price ( $total ) . " </td></tr> " ;
}
print " </table> " ;
print " <br> \n " ;
}
}
}
2007-03-29 19:35:39 +00:00
/**
* Factures brouillons
*/
2007-03-29 20:07:44 +00:00
if ( $conf -> fournisseur -> enabled && $user -> rights -> fournisseur -> facture -> lire )
2007-03-29 19:35:39 +00:00
{
$sql = " SELECT f.facnumber, f.rowid, f.total_ttc, f.type, " ;
2007-06-11 22:51:47 +00:00
$sql .= " s.nom, s.rowid as socid " ;
2007-03-29 20:07:44 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture_fourn as f, " . MAIN_DB_PREFIX . " societe as s " ;
2007-06-11 22:51:47 +00:00
$sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = 0 " ;
2007-03-29 19:35:39 +00:00
if ( $socid )
{
$sql .= " AND f.fk_soc = " . $socid ;
}
$resql = $db -> query ( $sql );
if ( $resql )
{
$num = $db -> num_rows ( $resql );
if ( $num )
{
2007-03-29 20:07:44 +00:00
print '<table class="noborder" width="100%">' ;
2007-03-29 19:35:39 +00:00
print '<tr class="liste_titre">' ;
print '<td colspan="3">' . $langs -> trans ( " DraftBills " ) . ' (' . $num . ')</td></tr>' ;
$i = 0 ;
$tot_ttc = 0 ;
$var = True ;
while ( $i < $num && $i < 20 )
{
$obj = $db -> fetch_object ( $resql );
$var =! $var ;
2008-06-18 20:01:01 +00:00
print '<tr ' . $bc [ $var ] . '><td nowrap="nowrap">' ;
2007-03-29 19:35:39 +00:00
$facturestatic -> ref = $obj -> facnumber ;
$facturestatic -> id = $obj -> rowid ;
$facturestatic -> type = $obj -> type ;
print $facturestatic -> getNomUrl ( 1 , '' );
print '</td>' ;
2008-06-18 20:01:01 +00:00
print '<td nowrap="nowrap">' ;
2008-05-13 16:56:13 +00:00
$companystatic -> id = $obj -> socid ;
2007-03-29 19:35:39 +00:00
$companystatic -> nom = $obj -> nom ;
2007-03-29 20:07:44 +00:00
$companystatic -> client = 0 ;
2007-03-29 19:35:39 +00:00
print $companystatic -> getNomUrl ( 1 , '' , 16 );
print '</td>' ;
print '<td align="right">' . price ( $obj -> total_ttc ) . '</td>' ;
print '</tr>' ;
$tot_ttc += $obj -> total_ttc ;
$i ++ ;
}
print '<tr class="liste_total"><td align="left">' . $langs -> trans ( " Total " ) . '</td>' ;
print '<td colspan="2" align="right">' . price ( $tot_ttc ) . '</td>' ;
print '</tr>' ;
2007-03-29 20:07:44 +00:00
print " </table> " ;
print " <br> \n " ;
2007-03-29 19:35:39 +00:00
}
$db -> free ( $resql );
}
else
{
dolibarr_print_error ( $db );
}
}
2006-12-13 16:17:27 +00:00
/*
*
*
*/
2006-12-09 21:08:43 +00:00
print " </td> \n " ;
print '<td valign="top" width="70%" class="notopnoleft">' ;
2005-01-08 22:20:19 +00:00
/*
2006-12-09 21:08:43 +00:00
* Liste des 10 derniers saisis
2005-01-08 22:20:19 +00:00
*
*/
2007-07-12 22:02:53 +00:00
$max = 10 ;
2007-06-11 22:51:47 +00:00
$sql = " SELECT s.rowid as socid, s.nom, s.ville, " . $db -> pdate ( " s.datec " ) . " as datec, " . $db -> pdate ( " s.datea " ) . " as datea, st.libelle as stcomm, s.prefix_comm " ;
2006-04-08 14:27:49 +00:00
$sql .= " , code_fournisseur, code_compta_fournisseur " ;
2008-03-01 01:26:41 +00:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , sc.fk_soc, sc.fk_user " ;
2005-06-26 01:41:00 +00:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " c_stcomm as st " ;
2008-03-01 01:26:41 +00:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " , " . MAIN_DB_PREFIX . " societe_commerciaux as sc " ;
2005-06-26 01:41:00 +00:00
$sql .= " WHERE s.fk_stcomm = st.id AND s.fournisseur=1 " ;
2008-03-01 01:26:41 +00:00
if ( ! $user -> rights -> societe -> client -> voir && ! $socid ) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user -> id ;
2007-06-11 22:51:47 +00:00
if ( $socid ) $sql .= " AND s.rowid = " . $socid ;
2007-07-12 22:02:53 +00:00
$sql .= " ORDER BY s.datec DESC " ;
$sql .= $db -> plimit ( $max , 0 );
2003-08-04 12:42:49 +00:00
2005-07-20 12:18:41 +00:00
$resql = $db -> query ( $sql );
if ( $resql )
2003-09-06 10:41:29 +00:00
{
2007-07-12 22:02:53 +00:00
$langs -> load ( " boxes " );
$num = $db -> num_rows ( $resql );
$i = 0 ;
print '<table class="liste" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td colspan="2">' . $langs -> trans ( " BoxTitleLastSuppliers " , min ( $max , $num )) . " </td> \n " ;
print '<td align="right">' . $langs -> trans ( " DateCreation " ) . " </td> \n " ;
print " </tr> \n " ;
$var = True ;
2006-12-09 21:08:43 +00:00
2007-07-12 22:02:53 +00:00
while ( $obj = $db -> fetch_object ( $resql ) )
{
$var =! $var ;
print " <tr $bc[$var] > " ;
print '<td><a href="fiche.php?socid=' . $obj -> socid . '">' . img_object ( $langs -> trans ( " ShowSupplier " ), " company " ) . '</a>' ;
print " <a href= \" fiche.php?socid= " . $obj -> socid . " \" > " . $obj -> nom . " </a></td> \n " ;
print '<td align="left">' . $obj -> code_fournisseur . ' </td>' ;
print '<td align="right">' . dolibarr_print_date ( $obj -> datec , 'day' ) . '</td>' ;
print " </tr> \n " ;
}
print " </table> \n " ;
$db -> free ( $resql );
2003-09-06 10:41:29 +00:00
}
else
{
2007-07-12 22:02:53 +00:00
dolibarr_print_error ( $db );
2003-09-06 10:41:29 +00:00
}
2003-08-04 12:42:49 +00:00
2006-12-09 21:08:43 +00:00
print " </td></tr> \n " ;
print " </table> \n " ;
2003-08-04 12:42:49 +00:00
$db -> close ();
2005-08-11 19:04:42 +00:00
llxFooter ( '$Date$ - $Revision$' );
2003-08-04 12:42:49 +00:00
?>