diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php new file mode 100644 index 00000000000..5d3e6d3d662 --- /dev/null +++ b/htdocs/fourn/commande/fiche.php @@ -0,0 +1,611 @@ + + * Copyright (C) 2004 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/commande/fiche.php + \ingroup commande + \brief Fiche commande + \version $Revision$ +*/ + +require("./pre.inc.php"); + +$langs->load("orders"); +$langs->load("suppliers"); +$langs->load("companies"); + +$user->getrights('commande'); +$user->getrights('expedition'); + +if (!$user->rights->commande->lire) + accessforbidden(); + +require_once "../../project.class.php"; +require_once "../../propal.class.php"; +require_once DOL_DOCUMENT_ROOT."/fournisseur.class.php"; +require_once DOL_DOCUMENT_ROOT."/fournisseur.commande.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 ($_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->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->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->commande->valider) +{ + $commande = new CommandeFournisseur($db); + $commande->fetch($_GET["id"]); + $soc = new Societe($db); + $soc->fetch($commande->soc_id); + $result = $commande->valid($user); +} + +if ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->commande->valider) +{ + $commande = new CommandeFournisseur($db); + $commande->fetch($_GET["id"]); + $result = $commande->cancel($user); +} + +if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes) +{ + if ($user->rights->commande->supprimer ) + { + $commande = new CommandeFournisseur($db); + $commande->id = $_GET["id"]; + $commande->delete(); + Header("Location: index.php"); + } +} + +if ($_GET["action"] == 'pdf') +{ + /* + * Generation de la commande + * définit dans /includes/modules/commande/modules_commande.php + */ + commande_pdf_create($db, $_GET["id"]); +} + +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"),"Commande"); + + + +$html = new Form($db); + + +/* *************************************************************************** */ +/* */ +/* Mode vue et edition */ +/* */ +/* *************************************************************************** */ + +$id = $_GET["id"]; +if ($id > 0) +{ + $commande = new CommandeFournisseur($db); + if ( $commande->fetch($id) == 0) + { + $soc = new Societe($db); + $soc->fetch($commande->soc_id); + $author = new User($db); + $author->id = $commande->user_author_id; + $author->fetch(); + + + $head[0][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id; + $head[0][1] = $langs->trans("Order").": $commande->ref"; + $h = 1; + $a = 0; + + dolibarr_fiche_head($head, $a, $soc->nom); + + /* + * Confirmation de la suppression de la commande + * + */ + if ($_GET["action"] == 'delete') + { + $html->form_confirm("fiche.php?id=$id","Supprimer la commande","Etes-vous sûr de vouloir supprimer cette commande ?","confirm_delete"); + } + + /* + * Confirmation de la validation + * + */ + if ($_GET["action"] == 'valid') + { + //$numfa = commande_get_num($soc); + $html->form_confirm("fiche.php?id=$id","Valider la commande","Etes-vous sûr de vouloir valider cette commande ?","confirm_valid"); + } + /* + * Confirmation de l'annulation + * + */ + if ($_GET["action"] == 'annuler') + { + $html->form_confirm("fiche.php?id=$id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); + } + + /* + * Commande + */ + + print ''; + print ""; + print ''; + + print '"; + + print ''; + print "\n"; + + print '"; + + print ''; + + print '"; + + // Ligne de 3 colonnes + print ''; + 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").'".strftime("%A %d %B %Y",$commande->date)." '; + print "
'.$langs->trans("Author").''.$author->fullname.''; + print " 
'.$langs->trans("AmountHT").''.price($commande->total_ht).''.MAIN_MONNAIE.''.$langs->trans("Note").' :
'.$langs->trans("VAT").''.price($commande->total_tva).''.MAIN_MONNAIE.'
'.$langs->trans("TotalTTC").''.price($commande->total_ttc).''.MAIN_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 = $id ORDER BY l.rowid"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; $total = 0; + + if ($num) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=True; + while ($i < $num) + { + $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->commande->creer) + { + print ''; + print ''; + } + else + { + print ''; + } + print ""; + + if ($_GET["action"] == 'editline' && $_GET["rowid"] == $objp->rowid) + { + print ""; + 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 ($commande->statut == 0 && $user->rights->commande->creer) + { + $sql = "SELECT p.rowid,p.label,p.ref,p.price "; + $sql .= " FROM ".MAIN_DB_PREFIX."product as p "; + $sql .= " , ".MAIN_DB_PREFIX."product_fournisseur as pf "; + $sql .= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$commande->fourn_id; + $sql .= " ORDER BY p.ref "; + if ( $db->query($sql) ) + { + $opt = ""; + if ($result) + { + $num = $db->num_rows(); $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object(); + $opt .= "\n"; + $i++; + } + } + $db->free(); + } + else + { + print $db->error(); + } + + print ""; + print ''; + + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + + print "".''; + print ''; + print ''; + print ''; + print ''; + + print ''; + + $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").'P.U.  
".$objp->ref."'; + print ''.stripslashes(nl2br($objp->description)).'".stripslashes(nl2br($objp->description))."'.$objp->tva_tx.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'; + print img_edit(); + print ''; + print img_delete(); + print '  
 %
'.$langs->trans("Description").'TvaQuantitéRemiseP.U.  
'; + print $html->select_tva("tva_tx",$conf->defaulttx); + print ' %
% 

"; + /* + * Fin Ajout ligne + * + */ + + print ''; + + if ($user->societe_id == 0 && $commande->statut < 3) + { + print '
'; + + if ($commande->statut == 0 && $user->rights->commande->supprimer) + { + print ''.$langs->trans("Delete").''; + } + + if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) + { + print 'Expédier'; + } + + + if ($commande->statut == 0) + { + if ($user->rights->commande->valider) + { + print ''.$langs->trans("Valid").''; + } + } + + if ($commande->statut == 1) + { + $nb_expedition = $commande->nb_expedition(); + if ($user->rights->commande->valider && $nb_expedition == 0) + { + print ''.$langs->trans("Cancel").''; + } + } + + print "
"; + } + print "

\n"; + + + print '
'; + /* + * Liste des expéditions + */ + $sql = "SELECT e.rowid,e.ref,".$db->pdate("e.date_expedition")." as de"; + $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; + $sql .= " WHERE e.fk_commande = ". $commande->id; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + if ($num) + { + print_titre("Expéditions"); + $i = 0; $total = 0; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object(); + $var=!$var; + print ""; + print ''; + print "\n"; + $i++; + } + print "
ExpéditionDate
'.stripslashes($objp->ref).'".strftime("%d %B %Y",$objp->de)."
"; + } + } + else + { + print $db->error(); + } + print " 
"; + + /* + * Liste des factures + */ + $sql = "SELECT f.rowid,f.facnumber,".$db->pdate("f.datef")." as df"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."co_fa as cf"; + $sql .= " WHERE f.rowid = cf.fk_facture AND cf.fk_commande = ". $commande->id; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + if ($num) + { + print_titre("Factures"); + $i = 0; $total = 0; + print ''; + print "\n"; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object(); + $var=!$var; + print ""; + print ''; + print "\n"; + $i++; + } + print "
Facture".$langs->trans("Date")."
'.stripslashes($objp->facnumber).'".strftime("%d %B %Y",$objp->df)."
"; + } + } + else + { + print $db->error(); + } + print " 
"; + + /* + * Documents générés + * + */ + $file = FAC_OUTPUTDIR . "/" . $commande->ref . "/" . $commande->ref . ".pdf"; + + if (file_exists($file)) + { + + print_titre("Documents"); + print ''; + + print ""; + print ''; + print ''; + print ''; + print ''; + + print "
Commande PDFref."/".$commande->ref.'.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 "
'; + } + /* + * + * + */ + } + else + { + /* Commande non trouvée */ + print "Commande inexistante ou accés refusé"; + } +} + + +$db->close(); + +llxFooter("Dernière modification $Date$ révision $Revision$"); +?>