* Copyright (C) 2004-2005 Laurent Destailleur * * 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 commande \version $Revision$ */ require("./pre.inc.php"); if (!$user->rights->fournisseur->commande->lire) accessforbidden(); require_once DOL_DOCUMENT_ROOT."/project.class.php"; require_once DOL_DOCUMENT_ROOT."/propal.class.php"; /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($_POST["action"] == 'classin') { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $commande->classin($_POST["projetid"]); } /* * */ if ($_GET["action"] == 'pdf') { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $commande->generate_pdf(); } /* * */ if ($_POST["action"] == 'setremise' && $user->rights->commande->creer) { $commande = new CommandeFournisseur($db); $commande->fetch($id); $commande->set_remise($user, $_POST["remise"]); } /* * */ if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->creer) { $comf = new CommandeFournisseur($db); $comf->fetch($_GET["id"]); if ($_POST["p_idprod"] > 0) { $result = $comf->addline("DESC", $_POST["pu"], $_POST["pqty"], $_POST["tva_tx"], $_POST["p_idprod"], $_POST["premise"]); } else { $result = $comf->addline($_POST["desc"], $_POST["pu"], $_POST["qty"], $_POST["tva_tx"], 0, $_POST["remise_percent"]); } Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) { $commande = new CommandeFournisseur($db,"",$_GET["id"]); if ($commande->fetch($_GET["id"]) ) { $result = $commande->update_line($_POST["elrowid"], $_POST["eldesc"], $_POST["elprice"], $_POST["elqty"], $_POST["elremise_percent"]); } else { print "Erreur"; } } if ($_GET["action"] == 'deleteline' && $user->rights->fournisseur->commande->creer) { $comf = new CommandeFournisseur($db); $comf->fetch($_GET["id"]); $result = $comf->delete_line($_GET["lineid"]); } if ($_POST["action"] == 'confirm_valid' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->valider) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $soc = new Societe($db); $soc->fetch($commande->soc_id); $result = $commande->valid($user); Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $result = $commande->approve($user); Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $result = $commande->refuse($user); Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'confirm_commande' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->commander) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $result = $commande->commande($user, $_GET["datecommande"], $_GET["methode"]); Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->creer ) { $commande = new CommandeFournisseur($db); $commande->id = $_GET["id"]; $commande->delete(); Header("Location: index.php"); } if ($_POST["action"] == 'livraison' && $user->rights->fournisseur->commande->receptionner) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $date_liv = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $result = $commande->Livraison($user, $date_liv, $_POST["type"]); Header("Location: fiche.php?id=".$_GET["id"]); } if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->annuler) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); $result = $commande->cancel($user); Header("Location: fiche.php?id=".$_GET["id"]); } /* * Créé une commande */ if ($_GET["action"] == 'create') { $fourn = new Fournisseur($db); $fourn->fetch($_GET["socid"]); if ($fourn->create_commande($user) == 0) { $idc = $fourn->single_open_commande; Header("Location:fiche.php?id=".$idc); } } llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur"); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ if ($_GET["id"] > 0) { $commande = new CommandeFournisseur($db); if ( $commande->fetch($_GET["id"]) == 0) { $soc = new Societe($db); $soc->fetch($commande->soc_id); $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("Order").": $commande->ref"; $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("History"); $h++; dolibarr_fiche_head($head, $a, $soc->nom); /* * Confirmation de la suppression de la commande * */ if ($_GET["action"] == 'delete') { $html->form_confirm("fiche.php?id=$commande->id","Supprimer la commande","Etes-vous sûr de vouloir supprimer cette commande ?","confirm_delete"); print '
'; } /* * Confirmation de la validation * */ if ($_GET["action"] == 'valid') { $html->form_confirm("fiche.php?id=$commande->id","Valider la commande","Etes-vous sûr de vouloir valider cette commande ?","confirm_valid"); print '
'; } /* * Confirmation de l'approbation * */ if ($_GET["action"] == 'approve') { $html->form_confirm("fiche.php?id=$commande->id","Approuver la commande","Etes-vous sûr de vouloir approuver cette commande ?","confirm_approve"); print '
'; } /* * Confirmation de l'approbation * */ if ($_GET["action"] == 'refuse') { $html->form_confirm("fiche.php?id=$commande->id","Refuser la commande","Etes-vous sûr de vouloir refuser cette commande ?","confirm_refuse"); print '
'; } /* * Confirmation de l'annulation * */ if ($_GET["action"] == 'cancel') { $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); print '
'; } /* * Confirmation de l'envoi de la commande * */ if ($_GET["action"] == 'commande') { $date_com = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"], "Envoi de la commande","Etes-vous sûr de vouloir confirmer cette commande en date du ".strftime("%d/%m/%Y",$date_com)." ?","confirm_commande"); print '
'; } /* * Commande */ print ''; print ""; print ''; print '"; if ($commande->methode_commande_id > 0) { print '"; } print ''; print '"; // Ligne de 3 colonnes print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($commande->note) { print '"; } print "
".$langs->trans("Supplier")."'; print ''.$soc->nom.''; print ' '; print $commande->statuts[$commande->statut]; print "
'.$langs->trans("Date").''; if ($commande->date_commande) { print strftime("%A %d %B %Y",$commande->date_commande)."\n"; } print ''; if ($commande->methode_commande) { print "Méthode : " .$commande->methode_commande; } print "
'.$langs->trans("Author").''.$author->fullname.''; print " 
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.$conf->monnaie.''.$langs->trans("VAT").''.price($commande->total_tva).''.$conf->monnaie.'
'.$langs->trans("TotalTTC").''.price($commande->total_ttc).''.$conf->monnaie.' 
Note'.nl2br($commande->note)."
"; /* * Lignes de commandes * */ echo '
'; $sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l "; $sql .= " WHERE l.fk_commande = $commande->id ORDER BY l.rowid"; $resql = $db->query($sql); if ($resql) { $num_lignes = $db->num_rows(); $i = 0; $total = 0; if ($num_lignes) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=True; while ($i < $num_lignes) { $objp = $db->fetch_object(); print ""; print "\n"; if ($objp->fk_product > 0) { print ''; } else { print "\n"; } print ''; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer && $_GET["action"] <> 'valid') { print ''; } else { print ''; } print ""; if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) { print "id\" method=\"post\">"; print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print '' . "\n"; print "\n"; } $i++; $var=!$var; } $db->free(); } else { print $db->error(); } /* * Ajouter une ligne * */ if ($_GET["action"] <> 'valid' && $commande->statut == 0 && $user->rights->fournisseur->commande->creer) { $sql = "SELECT p.rowid,p.label,p.ref "; $sql .=" , pf.price"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p "; $sql .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; $sql .= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$commande->fourn_id; $sql .= " AND quantity = 1"; $sql .= " ORDER BY p.ref "; $resql = $db->query($sql); if ($resql) { $opt = ""; if ($resql) { $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $opt .= "\n"; $i++; } } $db->free($resql); } else { print $db->error(); } print ''; print ''; print ""; print ''; print ''; print ''; print ''; print ''; print ''."\n"; $var=!$var; print "".''; print ''; print ''; print ''; print ''; print "\n"; print ""; } print "
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
".$objp->ref."'; print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_tx.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)." '; print img_delete(); print '  
 %
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").''.$langs->trans("Discount").''.$langs->trans("PriceU").'  
% 

"; /* * Fin Ajout ligne * */ print ''; if ($user->societe_id == 0 && $commande->statut < 3 && $_GET["action"] <> 'valid') { print '
'; if ($commande->statut == 0 && $num_lignes > 0) { if ($user->rights->fournisseur->commande->valider) { print ''.$langs->trans("Valid").''; } } if ($commande->statut == 1) { if ($user->rights->fournisseur->commande->annuler) { print ''.$langs->trans("CancelOrder").''; } if ($user->rights->fournisseur->commande->approuver) { print ''.$langs->trans("ApproveOrder").''; print ''.$langs->trans("RefuseOrder").''; } } if ($commande->statut == 2) { if ($user->rights->fournisseur->commande->approuver) { print ''.$langs->trans("RefuseOrder").''; } } if ($commande->statut == 0) { if ($user->rights->fournisseur->commande->creer) { print ''.$langs->trans("Delete").''; } } print "
"; } print "

\n"; /* * Documents générés * */ $file = $conf->commande->dir_output . "/" . $commande->ref . "/" . $commande->ref . ".pdf"; $relativepath=$commande->ref . "/" . $commande->ref . ".pdf"; $var=true; if (file_exists($file)) { print_titre($langs->trans("Documents")); print ''; print ""; print ''; print ''; print ''; print ''; print "
".$langs->trans("Order")." PDF'.$commande->ref.'.pdf'.filesize($file). ' bytes'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'
\n"; print ''; } /* * * */ if ($_GET["action"] == 'classer') { print '

'; print ''; print ''; print '"; print '
Projet'; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($commande->soc_id)); print "
'; } /* * * */ if ( $user->rights->fournisseur->commande->commander && $commande->statut == 2) { /** * Commander */ $form = new Form($db); print '
'; print ''; print ''; print ''; $commande->get_methodes_commande(); print ''; print ''; print ''; print '
Commander
Date commande'; print $form->select_date(); print '
Méthode de commande'; print $form->select_array("methodecommande",$commande->methodes_commande); print '
Commentaire
'; print '
'; } /* * * */ if ( $user->rights->fournisseur->commande->receptionner && ($commande->statut == 3 ||$commande->statut == 4 )) { /** * Réceptionner */ $form = new Form($db); print '
'; print ''; print ''; print ''; print '\n"; print "'; print ''; print ''; print "
Réceptionner
Date de livraison'; print $form->select_date(); print "
Livraison\n"; $liv = array(); $liv['par'] = "Partielle"; $liv['tot'] = "Totale"; print $form->select_array("type",$liv); print '
Commentaire
\n"; print "
\n"; } } else { /* Commande non trouvée */ print "Commande inexistante"; } } $db->close(); llxFooter("Dernière modification $Date$ révision $Revision$"); ?>