* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2011 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 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/fourn/index.php * \ingroup fournisseur * \brief Home page of suppliers area */ // Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $langs->loadLangs(array("suppliers", "orders", "companies")); // Security check $socid = GETPOSTINT("socid"); if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'societe', $socid, ''); /* * View */ $commandestatic = new CommandeFournisseur($db); $facturestatic = new FactureFournisseur($db); $companystatic = new Societe($db); llxHeader("", $langs->trans("SuppliersArea"), '', '', 0, 0, '', '', '', 'mod-fourn-facture page-index'); print load_fiche_titre($langs->trans("SuppliersArea")); //print ''; //print '
'; print '
'; // Orders $sql = "SELECT count(cf.rowid), cf.fk_statut"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql .= " WHERE cf.fk_soc = s.rowid "; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " AND sc.fk_user = ".((int) $user->id); } $sql .= " AND cf.entity = ".$conf->entity; $sql .= " GROUP BY cf.fk_statut"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; print ''; print ''; print "\n"; while ($i < $num) { $row = $db->fetch_row($resql); print ''; print ''; print ''; print ''; print "\n"; $i++; } print "
'.$langs->trans("Orders").''.$langs->trans("Nb").' 
'.$commandestatic->LibStatut($row[1]).''.$row[0].''.$commandestatic->LibStatut($row[1], 3).'
"; print "
\n"; $db->free($resql); } else { dol_print_error($db); } // Draft orders if (isModEnabled("supplier_order")) { $langs->load("orders"); $sql = "SELECT cf.rowid, cf.ref, cf.total_ttc,"; $sql .= " s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql .= " WHERE cf.fk_soc = s.rowid"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " AND sc.fk_user = ".((int) $user->id); } $sql .= " AND cf.entity = ".$conf->entity; $sql .= " AND cf.fk_statut = 0"; if ($socid) { $sql .= " AND cf.fk_soc = ".((int) $socid); } $resql = $db->query($sql); if ($resql) { $total = 0; $num = $db->num_rows($resql); if ($num) { print ''; print ''; print ''; $i = 0; while ($i < $num) { $obj = $db->fetch_object($resql); print ''; print ''; print ''; $i++; $total += $obj->total_ttc; } if ($total > 0) { print '"; } print "
'.$langs->trans("DraftOrders").''.$num.'
'; $commandestatic->id = $obj->rowid; $commandestatic->ref = $obj->ref; print $commandestatic->getNomUrl(1, '', 16); print ''; $companystatic->id = $obj->socid; $companystatic->name = $obj->name; $companystatic->client = 0; print $companystatic->getNomUrl(1, '', 16); print ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($total)."
"; print "
\n"; } } } // Draft invoices if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) { $sql = "SELECT ff.ref_supplier, ff.rowid, ff.total_ttc, ff.type"; $sql .= ", s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff"; $sql .= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql .= " WHERE s.rowid = ff.fk_soc"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " AND sc.fk_user = ".((int) $user->id); } $sql .= " AND ff.entity = ".$conf->entity; $sql .= " AND ff.fk_statut = 0"; if ($socid) { $sql .= " AND f.fk_soc = ".((int) $socid); } $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { print ''; print ''; print ''; $i = 0; $tot_ttc = 0; while ($i < $num && $i < 20) { $obj = $db->fetch_object($resql); print ''; print ''; print ''; print ''; $tot_ttc += $obj->total_ttc; $i++; } print ''; print ''; print ''; print "
'.$langs->trans("DraftBills").''.$num.'
'; $facturestatic->ref = $obj->ref; $facturestatic->id = $obj->rowid; $facturestatic->type = $obj->type; print $facturestatic->getNomUrl(1, ''); print ''; $companystatic->id = $obj->socid; $companystatic->name = $obj->name; $companystatic->client = 0; print $companystatic->getNomUrl(1, '', 16); print ''.price($obj->total_ttc).'
'.$langs->trans("Total").''.price($tot_ttc).'
"; print "
\n"; } $db->free($resql); } else { dol_print_error($db); } } print '
'; /* * List last modified supliers */ $max = 10; $sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur"; if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur"; } else { $sql .= ", s.code_compta_fournisseur"; } $sql .= ", st.libelle as stcomm"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); } $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; } $sql .= " WHERE s.fk_stcomm = st.id"; $sql .= " AND s.fournisseur = 1"; $sql .= " AND s.entity IN (".getEntity('societe').")"; if (!$user->hasRight("societe", "client", "voir") && !$socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); } if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } $sql .= " ORDER BY s.tms DESC"; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); if ($resql) { $langs->load("boxes"); $num = $db->num_rows($resql); $i = 0; print ''; print ''; print '\n"; print '\n"; print "\n"; while ($obj = $db->fetch_object($resql)) { print ''; print '\n"; print ''; print ''; print "\n"; } print "
'.$langs->trans("BoxTitleLastSuppliers", min($max, $num))."'.$langs->trans("DateModification")."
'.img_object($langs->trans("ShowSupplier"), "company").''; print " socid."\">".$obj->name."'.$obj->code_fournisseur.' '.dol_print_date($db->jdate($obj->tms), 'day').'
\n"; $db->free($resql); } else { dol_print_error($db); } /* * List of suppliers categories */ $companystatic->LoadSupplierCateg(); $categstatic = new Categorie($db); if (count($companystatic->SupplierCategories)) { print '
'; print ''; print '\n"; foreach ($companystatic->SupplierCategories as $rowid => $label) { print ''."\n"; print ''."\n"; // TODO this page not exist /* print '\n"; */ } print "
'; print $langs->trans("Category"); print "
'; $categstatic->id = $rowid; $categstatic->ref = $label; $categstatic->label = $label; print $categstatic->getNomUrl(1); print ''; print '('.$langs->trans("Stats").')'; print "
\n"; print "
\n"; } print '
'; // End of page llxFooter(); $db->close();