* Copyright (C) 2004-2005 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 commande \version $Revision$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/project.class.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); if (!$user->rights->fournisseur->commande->lire) accessforbidden(); // Sécurité accés client $socidp=0; if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } $mesg=''; /* * Actions */ 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($_POST["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"]); } if ($result >= 0) { Header("Location: fiche.php?id=".$_GET["id"]); exit; } else { $mesg='
'.$comf->error.'
'; } } 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"]); exit; } 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"]); exit; } 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"]); exit; } 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"); exit; } 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"]); exit; } 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"]); exit; } /* * 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); exit; } else { $mesg=$fourn->error; } } llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur"); $html = new Form($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ if ($_GET["id"] > 0) { if ($mesg) print $mesg; $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("OrderCard"); $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("Order").": $commande->ref"; dolibarr_fiche_head($head, $a, $title); /* * 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 ''; print ''; print ''; print '"; if ($commande->methode_commande_id > 0) { print '"; } // Auteur print ''; print '"; // Ligne de 3 colonnes print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($commande->note) { print '"; } print "
'.$langs->trans("Supplier")."'; print ''; print img_object($langs->trans("ShowSupplier"),'company').' '.$soc->nom.'
'.$langs->trans("Status").''; print ' '; print $commande->statuts[$commande->statut]; 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("Author").''.$author->fullname.''; print " 
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountVAT").''.price($commande->total_tva).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("AmountTTC").''.price($commande->total_ttc).''.$langs->trans("Currency".$conf->monnaie).' 
'.$langs->trans("Note").''.nl2br($commande->note)."
"; if ($mesg) print $mesg; else print '
'; /* * Lignes de commandes */ print ''; $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"; $sql.= " ORDER BY l.rowid"; $resql = $db->query($sql); if ($resql) { $num_lignes = $db->num_rows($resql); $i = 0; $total = 0; if ($num_lignes) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=false; while ($i < $num_lignes) { $objp = $db->fetch_object($resql); print ""; print ''; 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) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''."\n"; $var=false; 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").'  
'.img_object($langs->trans("ShowProduct"),'product').' '.$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").'  
'; $html->select_produits_fournisseurs($commande->fourn_id,'','p_idprod',$filtre); print '% 
"; print ''; /** * Boutons actions */ 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 "
"; } /* * 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('$Date$ - $Revision$'); ?>