diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 0b5c41a7818..d62c9197f97 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -25,7 +25,6 @@ $user->getrights('commande'); if (!$user->rights->commande->lire) accessforbidden(); -require("../commande.class.php"); require("../project.class.php"); require("../propal.class.php"); @@ -45,7 +44,7 @@ if ($user->societe_id > 0) if ($HTTP_POST_VARS["action"] == 'classin') { $commande = new Commande($db); - $commande->fetch($facid); + $commande->fetch($_GET["id"]); $commande->classin($HTTP_POST_VARS["projetid"]); } /* @@ -53,74 +52,25 @@ if ($HTTP_POST_VARS["action"] == 'classin') */ if ($HTTP_POST_VARS["action"] == 'add') { - $datecommande = mktime(12, 0 , 0, $remonth, $reday, $reyear); + $datecommande = mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]); - $commande = new Commande($db, $socid); + $commande = new Commande($db); - $commande->number = $HTTP_POST_VARS["facnumber"]; - $commande->date = $datecommande; + $commande->soc_id = $HTTP_POST_VARS["soc_id"]; + $commande->date_commande = $datecommande; $commande->note = $HTTP_POST_VARS["note"]; - if ($HTTP_POST_VARS["fac_rec"] > 0) - { - /* - * Commande récurrente - */ - $commande->fac_rec = $HTTP_POST_VARS["fac_rec"]; - $facid = $commande->create($user); - } - else - { - $commande->projetid = $HTTP_POST_VARS["projetid"]; - $commande->cond_reglement = $HTTP_POST_VARS["condid"]; - $commande->amount = $HTTP_POST_VARS["amount"]; - $commande->remise = $HTTP_POST_VARS["remise"]; - $commande->remise_percent = $HTTP_POST_VARS["remise_percent"]; + $commande->projetid = $HTTP_POST_VARS["projetid"]; + $commande->remise_percent = $HTTP_POST_VARS["remise_percent"]; - if (!$HTTP_POST_VARS["propalid"]) - { - $commande->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"],$HTTP_POST_VARS["remise_percent1"]); - $commande->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"],$HTTP_POST_VARS["remise_percent2"]); - $commande->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"],$HTTP_POST_VARS["remise_percent3"]); - $commande->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"],$HTTP_POST_VARS["remise_percent4"]); - - $facid = $commande->create($user); - } - else - { - $commande->propalid = $HTTP_POST_VARS["propalid"]; - - $facid = $commande->create($user); - - if ($facid) - { - $prop = New Propal($db); - if ( $prop->fetch($HTTP_POST_VARS["propalid"]) ) - { - for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) - { - $result = $commande->addline($facid, - addslashes($prop->lignes[$i]->libelle), - $prop->lignes[$i]->subprice, - $prop->lignes[$i]->qty, - $prop->lignes[$i]->tva_tx, - $prop->lignes[$i]->product_id, - $prop->lignes[$i]->remise_percent); - } - } - else - { - print "Erreur"; - } - } - else - { - print "
Erreur : la commande n'a pas été créée, vérifier le numéro !"; - print "
Retour à la propal"; - print $db->error(); - } - } - } + $commande->add_product($HTTP_POST_VARS["idprod1"],$HTTP_POST_VARS["qty1"],$HTTP_POST_VARS["remise_percent1"]); + $commande->add_product($HTTP_POST_VARS["idprod2"],$HTTP_POST_VARS["qty2"],$HTTP_POST_VARS["remise_percent2"]); + $commande->add_product($HTTP_POST_VARS["idprod3"],$HTTP_POST_VARS["qty3"],$HTTP_POST_VARS["remise_percent3"]); + $commande->add_product($HTTP_POST_VARS["idprod4"],$HTTP_POST_VARS["qty4"],$HTTP_POST_VARS["remise_percent4"]); + + $commande_id = $commande->create($user); + + $id = $commande->id; $action = ''; } @@ -129,142 +79,78 @@ if ($HTTP_POST_VARS["action"] == 'add') * */ -if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->commande->valider) -{ - $fac = new Commande($db); - $fac->fetch($facid); - $soc = new Societe($db); - $soc->fetch($fac->socidp); - $result = $fac->set_valid($facid, $user, $soc); - if ($result) - { - commande_pdf_create($db, $facid); - } -} - -if ($action == 'payed' && $user->rights->commande->paiement) -{ - $fac = new Commande($db); - $result = $fac->set_payed($facid); -} if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->commande->creer) { - $fac = new Commande($db); - $fac->fetch($facid); + $commande = new Commande($db); + $commande->fetch($id); - $fac->set_remise($user, $HTTP_POST_VARS["remise"]); + $commande->set_remise($user, $HTTP_POST_VARS["remise"]); } - -if ($action == 'addligne' && $user->rights->commande->creer) +if ($HTTP_POST_VARS["action"] == 'addligne' && $user->rights->commande->creer) { - $fac = new Commande($db); - $fac->fetch($facid); - $result = $fac->addline($facid, - $HTTP_POST_VARS["desc"], - $HTTP_POST_VARS["pu"], - $HTTP_POST_VARS["qty"], - $HTTP_POST_VARS["tva_tx"], - 0, - $HTTP_POST_VARS["remise_percent"]); + $commande = new Commande($db); + $commande->fetch($_GET["id"]); + + if ($HTTP_POST_VARS["p_idprod"] > 0) + { + $result = $commande->addline("DESC", + $HTTP_POST_VARS["pu"], + $HTTP_POST_VARS["pqty"], + $HTTP_POST_VARS["tva_tx"], + $HTTP_POST_VARS["p_idprod"], + $HTTP_POST_VARS["premise"]); + } + else + { + $result = $commande->addline($HTTP_POST_VARS["desc"], + $HTTP_POST_VARS["pu"], + $HTTP_POST_VARS["qty"], + $HTTP_POST_VARS["tva_tx"], + 0, + $HTTP_POST_VARS["remise_percent"]); + } } if ($action == 'updateligne' && $user->rights->commande->creer) { - $fac = new Commande($db,"",$facid); - $fac->fetch($facid); - $result = $fac->updateline($rowid, - $HTTP_POST_VARS["desc"], - $HTTP_POST_VARS["price"], - $HTTP_POST_VARS["qty"], - $HTTP_POST_VARS["remise_percent"]); + $fac = new Commande($db,"",$id); + $commande->fetch($id); + $result = $commande->updateline(rowid, + $HTTP_POST_VARS["desc"], + $HTTP_POST_VARS["price"], + $HTTP_POST_VARS["qty"], + $HTTP_POST_VARS["remise_percent"]); } if ($action == 'deleteline' && $user->rights->commande->creer) { - $fac = new Commande($db,"",$facid); - $fac->fetch($facid); - $result = $fac->deleteline($rowid); + $commande = new Commande($db); + $commande->fetch($_GET["id"]); + $result = $commande->delete_line($_GET["lineid"]); +} + +if ($HTTP_POST_VARS["action"] == 'confirm_valid' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->commande->valider) +{ + $commande = new Commande($db); + $commande->fetch($_GET["id"]); + $soc = new Societe($db); + $soc->fetch($commande->soc_id); + $result = $commande->valid($user); } if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes) { if ($user->rights->commande->supprimer ) { - $fac = new Commande($db); - $fac->delete($facid); - $facid = 0 ; + $commande = new Commande($db); + $commande->id = $_GET["id"]; + $commande->delete(); + $id = 0 ; } } -/* - * - */ -if ($action == 'send') -{ - $fac = new Commande($db,"",$facid); - $fac->fetch($facid); - - $soc = new Societe($db, $fac->socidp); - - $file = FAC_OUTPUTDIR . "/" . $fac->ref . "/" . $fac->ref . ".pdf"; - - if (file_exists($file)) - { - - $sendto = $soc->contact_get_email($HTTP_POST_VARS["destinataire"]); - $sendtoid = $HTTP_POST_VARS["destinataire"]; - - if (strlen($sendto)) - { - - $subject = "Commande $fac->ref"; - $message = "Veuillez trouver ci-joint la commande $fac->ref\n\nCordialement\n\n"; - $filename = "$fac->ref.pdf"; - - $replyto = $HTTP_POST_VARS["replytoname"] . " <".$HTTP_POST_VARS["replytomail"] .">"; - - $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$file, "application/pdf", $filename); - - if ( $mailfile->sendfile() ) - { - - $sendto = htmlentities($sendto); - - $sql = "INSERT INTO llx_actioncomm (datea,fk_action,fk_soc,note,fk_commande, fk_contact,fk_user_author, label, percent) VALUES (now(), 9 ,$fac->socidp ,'Envoyée à $sendto',$fac->id, $sendtoid, $user->id, 'Envoi Commande par mail',100);"; - - if (! $db->query($sql) ) - { - print $db->error(); - print "
$sql
"; - } - } - else - { - print "!! erreur d'envoi| Description | '; - print 'Tva | '; - print 'Quantité | '; - print 'Remise | '; - print 'P.U. | '; - print ''; - print " | |||||
| '.stripslashes(nl2br($objp->description)).' | '; - } - else - { - print "".stripslashes(nl2br($objp->description))." | \n"; - } - print ''.$objp->tva_taux.' % | '; - print ''.$objp->qty.' | '; - if ($objp->remise_percent > 0) - { - print ''.$objp->remise_percent." % | \n"; - } - else - { - print ''; - } - print ' | '.price($objp->subprice)." | \n"; - if ($fac->statut == 0 && $user->rights->commande->creer) - { - print 'del | '; - print 'edit | '; - } - else - { - print ''; - } - print " | |
| TVA | '.price($commande->total_tva).' | '; + print ''.MAIN_MONNAIE.' | ||||||||
| Total | '.price($commande->total_ttc).' | '; + print ''.MAIN_MONNAIE.' TTC | ||||||||
| Note : '.nl2br($commande->note)." | ||||||||||
| Description | '; + print 'Tva | '; + print 'Quantité | '; + print 'Remise | '; + print 'P.U. | '; + print ''; + print " | |||||
| '.stripslashes(nl2br($objp->description)).' | '; + } + else + { + print "".stripslashes(nl2br($objp->description))." | \n"; + } + print ''.$objp->tva_tx.' % | '; + print ''.$objp->qty.' | '; + if ($objp->remise_percent > 0) + { + print ''.$objp->remise_percent." % | \n"; + } + else + { + print ''; + } + print ' | '.price($objp->subprice)." | \n"; + if ($commande->statut == 0 && $user->rights->commande->creer) + { + print 'del | '; + print 'edit | '; + } + else + { + print ''; + } + print " |