diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 5d3e6d3d662..ac55623f6c8 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -33,16 +33,15 @@ $langs->load("orders"); $langs->load("suppliers"); $langs->load("companies"); -$user->getrights('commande'); -$user->getrights('expedition'); -if (!$user->rights->commande->lire) +$user->getrights('fournisseur'); + +if (!$user->rights->fournisseur->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 @@ -76,7 +75,7 @@ if ($_POST["action"] == 'setremise' && $user->rights->commande->creer) /* * */ -if ($_POST["action"] == 'addligne' && $user->rights->commande->creer) +if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->creer) { $comf = new CommandeFournisseur($db); $comf->fetch($_GET["id"]); @@ -119,38 +118,55 @@ if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) } } -if ($_GET["action"] == 'deleteline' && $user->rights->commande->creer) +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->commande->valider) +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_cancel' && $_POST["confirm"] == yes && $user->rights->commande->valider) +if ($_POST["action"] == 'confirm_approve' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) { $commande = new CommandeFournisseur($db); $commande->fetch($_GET["id"]); - $result = $commande->cancel($user); + $result = $commande->approve($user); + Header("Location: fiche.php?id=".$_GET["id"]); } -if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == yes) +if ($_POST["action"] == 'confirm_refuse' && $_POST["confirm"] == yes && $user->rights->fournisseur->commande->approuver) { - if ($user->rights->commande->supprimer ) - { - $commande = new CommandeFournisseur($db); - $commande->id = $_GET["id"]; - $commande->delete(); - Header("Location: index.php"); - } + $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 ($_GET["action"] == 'pdf') @@ -200,12 +216,17 @@ if ($id > 0) $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[0][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id; - $head[0][1] = $langs->trans("Order").": $commande->ref"; - $h = 1; - $a = 0; - + $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); /* @@ -215,6 +236,7 @@ if ($id > 0) 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"); + print '
'; } /* @@ -223,8 +245,26 @@ if ($id > 0) */ 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"); + print '
'; + } + /* + * Confirmation de l'approbation + * + */ + if ($_GET["action"] == 'approve') + { + $html->form_confirm("fiche.php?id=$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=$id","Refuser la commande","Etes-vous sûr de vouloir refuser cette commande ?","confirm_refuse"); + print '
'; } /* * Confirmation de l'annulation @@ -233,16 +273,26 @@ if ($id > 0) 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"); + print '
'; + } + /* + * Confirmation de l'envoi de la commande + * + */ + if ($_GET["action"] == 'commande') + { + $date_com = mktime(12,12,12,$_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 ''.$soc->nom.''; print '"; print ''; - print "\n"; + print '"; - - print ''; - + print ''; print '"; @@ -292,10 +349,10 @@ if ($id > 0) $result = $db->query($sql); if ($result) { - $num = $db->num_rows(); + $num_lignes = $db->num_rows(); $i = 0; $total = 0; - if ($num) + if ($num_lignes) { print ''; print ''; @@ -308,7 +365,7 @@ if ($id > 0) print "\n"; } $var=True; - while ($i < $num) + while ($i < $num_lignes) { $objp = $db->fetch_object(); print ""; @@ -333,12 +390,13 @@ if ($id > 0) print ''; } print '\n"; - if ($commande->statut == 0 && $user->rights->commande->creer) - { + if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer) + {/* print ''; - print ''; } @@ -376,7 +434,7 @@ if ($id > 0) * Ajouter une ligne * */ - if ($commande->statut == 0 && $user->rights->commande->creer) + if ($commande->statut == 0 && $user->rights->fournisseur->commande->creer) { $sql = "SELECT p.rowid,p.label,p.ref,p.price "; $sql .= " FROM ".MAIN_DB_PREFIX."product as p "; @@ -414,6 +472,7 @@ if ($id > 0) print ''; print ''."\n"; + /* print "".''; print ''; print ''; + */ $var=!$var; print "".''; @@ -446,31 +506,37 @@ if ($id > 0) { 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) + if ($user->rights->fournisseur->commande->creer) + { + print ''.$langs->trans("Delete").''; + } + } + + if ($commande->statut == 0 && $num_lignes > 0) + { + if ($user->rights->fournisseur->commande->valider) { print ''.$langs->trans("Valid").''; } } - if ($commande->statut == 1) + if ($commande->statut == 1) { - $nb_expedition = $commande->nb_expedition(); - if ($user->rights->commande->valider && $nb_expedition == 0) + if ($user->rights->fournisseur->commande->approuver) { - print ''.$langs->trans("Cancel").''; + print ''.$langs->trans("ApproveOrder").''; + + print ''.$langs->trans("RefuseOrder").''; + } + } + + if ($commande->statut == 2) + { + if ($user->rights->fournisseur->commande->approuver) + { + print ''.$langs->trans("RefuseOrder").''; } } @@ -525,7 +591,7 @@ if ($id > 0) $sql .= " WHERE f.rowid = cf.fk_facture AND cf.fk_commande = ". $commande->id; $result = $db->query($sql); - if ($result) + if ($result && 0) { $num = $db->num_rows(); if ($num) @@ -562,7 +628,6 @@ if ($id > 0) if (file_exists($file)) { - print_titre("Documents"); print '
".$langs->trans("Supplier")."'; - print ''.$soc->nom.''; print ' '; @@ -250,13 +300,20 @@ if ($id > 0) print "
'.$langs->trans("Date").'".strftime("%A %d %B %Y",$commande->date)."'; + + if ($commande->date_commande) + { + print strftime("%A %d %B %Y",$commande->date_commande)."\n"; + } - print ' '; + print ' '; + if ($commande->methode_commande) + { + print "Méthode : " .$commande->methode_commande; + } print "
'.$langs->trans("Author").''.$author->fullname.'
'.$langs->trans("Author").''.$author->fullname.''; print " 
'.$langs->trans("Ref").'
 '.price($objp->subprice)."'; print img_edit(); print ''; + */ + print ' '; print img_delete(); print 'P.U.  
'; print $html->select_tva("tva_tx",$conf->defaulttx); @@ -423,6 +482,7 @@ if ($id > 0) print '
'; @@ -596,6 +661,32 @@ if ($id > 0) * * */ + 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 ''; + } } else {