* Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * * 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/fourn/commande/fiche.php \ingroup commande \brief Fiche de ventilation des commandes fournisseurs \version $Revision$ */ require('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT.'/fourn/commande/modules/modules_commandefournisseur.php'); require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); $langs->load('orders'); $langs->load('sendings'); $langs->load('companies'); $langs->load('bills'); $langs->load('deliveries'); $langs->load('products'); $langs->load('stocks'); $user->getrights("fournisseur"); if (!$user->rights->fournisseur->commande->lire) accessforbidden(); // Sécurité accés client $socid=0; if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } // Récupération de l'id de projet $projetid = 0; if ($_GET["projetid"]) { $projetid = $_GET["projetid"]; } $mesg=''; /* * Actions */ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->receptionner) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); foreach($_POST as $key => $value) { if ( eregi('^product_([0-9]+)$', $key, $reg) ) { $prod = "product_".$reg[1]; $qty = "qty_".$reg[1]; $ent = "entrepot_".$reg[1]; $pu = "pu_".$reg[1]; $result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu]); } } Header("Location: dispatch.php?id=".$_GET["id"]); exit; } llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur"); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ $id = $_GET['id']; if ($id > 0) { //if ($mesg) print $mesg.'
'; $commande = new CommandeFournisseur($db); if ( $commande->fetch($_GET['id']) >= 0) { $soc = new Societe($db); $soc->fetch($commande->socid); $author = new User($db); $author->id = $commande->user_author_id; $author->fetch(); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id; $head[$h][1] = $langs->trans("OrderCard"); $h++; $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$commande->id; $head[$h][1] = $langs->trans("OrderDispatch"); $a = $h; $h++; $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$commande->id; $head[$h][1] = $langs->trans("Note"); $h++; $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/history.php?id='.$commande->id; $head[$h][1] = $langs->trans("OrderFollow"); $h++; $title=$langs->trans("SupplierOrder"); dolibarr_fiche_head($head, $a, $title); /* * Commande */ print ''; // Ref print ''; print ''; print ''; // Fournisseur print '"; print ''; print ''; // Statut print ''; print ''; print '"; if ($commande->methode_commande_id > 0) { print '"; } // Auteur print ''; print ''; print '"; print "
'.$langs->trans("Ref").''.$commande->ref.'
'.$langs->trans("Supplier")."'; print ''; print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'
'.$langs->trans("Status").''; print $commande->getLibStatut(4); print "
'.$langs->trans("Date").''; if ($commande->date_commande) { print dolibarr_print_date($commande->date_commande,"%A %d %B %Y")."\n"; } print ''; if ($commande->methode_commande) { print "Méthode : " .$commande->methode_commande; } print "
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).''; print " 
"; if ($mesg) print $mesg; else print '
'; /* * Lignes de commandes */ if ($commande->statut == 3 || $commande->statut == 4) { print '
'; print ''; print ''; $sql = "SELECT cfd.fk_product, sum(cfd.qty) as qty"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; $sql.= " WHERE cfd.fk_commande = ".$commande->id; $sql.= " GROUP BY cfd.fk_product"; $resql = $db->query($sql); if ($resql) { while ( $row = $db->fetch_row($resql) ) { $products_dispatched[$row[0]] = $row[1]; } $db->free($resql); } $sql = "SELECT l.ref,l.fk_product,l.description,(sum(l.price * l.qty) / sum(l.qty)) as price, sum(l.qty) as qty"; $sql.= ", l.rowid"; $sql.= ", p.label"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; $sql.= " WHERE l.fk_commande = ".$commande->id; $sql.= " GROUP BY l.fk_product"; $sql.= " ORDER BY l.rowid"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=false; $entrepot = new Entrepot($db); while ($i < $num) { $objp = $db->fetch_object($resql); print ""; print '\n"; print ''; print ''; print '\n"; print ''; print "\n"; $i++; $var=!$var; } $db->free($resql); } else { dolibarr_print_error($db); } print "
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyDispatched").''.$langs->trans("Warehouse").''.$langs->trans("QtyDelivered").'
'; print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; print ' - '.$objp->label; if ($objp->description) print '
'.nl2br($objp->description); print ''; print ''; print "
'.$objp->qty.''.$products_dispatched[$objp->fk_product].''; if (sizeof($user->entrepots) === 1) { $uentrepot = array(); $uentrepot[$user->entrepots[0]['id']] = $user->entrepots[0]['label']; $html->select_array("entrepot_".$i, $uentrepot); } else { $html->select_array("entrepot_".$i, $entrepot->list_array()); } print "
\n"; print '
'; } print "
\n"; print ''; $sql = "SELECT p.ref,cfd.fk_product, cfd.qty"; $sql.= ", cfd.rowid"; $sql.= ", p.label, e.label as entrepot"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; $sql.= " , ".MAIN_DB_PREFIX."product as p "; $sql.= " , ".MAIN_DB_PREFIX."entrepot as e "; $sql.= " WHERE cfd.fk_commande = ".$commande->id; $sql.= " AND cfd.fk_product = p.rowid"; $sql.= " AND cfd.fk_entrepot = e.rowid"; $sql.= " ORDER BY cfd.rowid ASC;"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num) { print ''; print ''; print ''; print ''; print "\n"; } $var=false; while ($i < $num) { $objp = $db->fetch_object($resql); print ""; print '\n"; print ''; print ''; print "\n"; $i++; $var=!$var; } $db->free($resql); } else { dolibarr_print_error($db); } print "
'.$langs->trans("Description").''.$langs->trans("QtyDispatched").''.$langs->trans("Warehouse").'
'; print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; print ' - '.$objp->label; print "'.$objp->qty.''.stripslashes($objp->entrepot).'
\n"; print ''; /** * Boutons actions */ if ($user->societe_id == 0 && $commande->statut < 3 && ($_GET["action"] <> 'valid' || $_GET['action'] == 'builddoc')) { print '
'; if ($commande->statut == 0 && $num > 0) { if ($user->rights->fournisseur->commande->valider) { print ''.$langs->trans("Valid").''; } } if ($commande->statut == 1) { if ($user->rights->fournisseur->commande->approuver) { print ''.$langs->trans("ApproveOrder").''; print ''.$langs->trans("RefuseOrder").''; } if ($user->rights->fournisseur->commande->annuler) { print ''.$langs->trans("CancelOrder").''; } } if ($commande->statut == 2) { if ($user->rights->fournisseur->commande->annuler) { print ''.$langs->trans("CancelOrder").''; } } if ($commande->statut == 0) { if ($user->rights->fournisseur->commande->creer) { print ''.$langs->trans("Delete").''; } } print "
"; } /* * * */ } else { // Commande non trouvée dolibarr_print_error($db); } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>