* * 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$ * */ require("./pre.inc.php"); $user->getrights('commande'); $user->getrights('expedition'); if (!$user->rights->commande->lire) accessforbidden(); require("../project.class.php"); require("../propal.class.php"); /* * Sécurité accés client */ if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /* * */ if ($HTTP_POST_VARS["action"] == 'classin') { $commande = new Commande($db); $commande->fetch($_GET["id"]); $commande->classin($HTTP_POST_VARS["projetid"]); } /* * */ if ($HTTP_POST_VARS["action"] == 'add') { $datecommande = mktime(12, 0 , 0, $HTTP_POST_VARS["remonth"], $HTTP_POST_VARS["reday"], $HTTP_POST_VARS["reyear"]); $commande = new Commande($db); $commande->soc_id = $HTTP_POST_VARS["soc_id"]; $commande->date_commande = $datecommande; $commande->note = $HTTP_POST_VARS["note"]; $commande->source = $HTTP_POST_VARS["source_id"]; $commande->projetid = $HTTP_POST_VARS["projetid"]; $commande->remise_percent = $HTTP_POST_VARS["remise_percent"]; $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); $_GET["id"] = $commande->id; $action = ''; } /* * */ if ($HTTP_POST_VARS["action"] == 'setremise' && $user->rights->commande->creer) { $commande = new Commande($db); $commande->fetch($id); $commande->set_remise($user, $HTTP_POST_VARS["remise"]); } if ($HTTP_POST_VARS["action"] == 'addligne' && $user->rights->commande->creer) { $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 ($HTTP_POST_VARS["action"] == 'updateligne' && $user->rights->commande->creer) { $commande = new Commande($db,"",$_GET["id"]); if ($commande->fetch($_GET["id"]) ) { $result = $commande->update_line($HTTP_POST_VARS["elrowid"], $HTTP_POST_VARS["eldesc"], $HTTP_POST_VARS["elprice"], $HTTP_POST_VARS["elqty"], $HTTP_POST_VARS["elremise_percent"]); } else { print "Erreur"; } } if ($action == 'deleteline' && $user->rights->commande->creer) { $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_cancel' && $HTTP_POST_VARS["confirm"] == yes && $user->rights->commande->valider) { $commande = new Commande($db); $commande->fetch($_GET["id"]); $result = $commande->cancel($user); } if ($HTTP_POST_VARS["action"] == 'confirm_delete' && $HTTP_POST_VARS["confirm"] == yes) { if ($user->rights->commande->supprimer ) { $commande = new Commande($db); $commande->id = $_GET["id"]; $commande->delete(); Header("Location: index.php"); } } /* * */ if ($action == 'pdf') { /* * Generation de la commande * définit dans /includes/modules/commande/modules_commande.php */ commande_pdf_create($db, $_GET["id"]); } llxHeader('','Fiche commande','ch-commande.html'); $html = new Form($db); /********************************************************************* * * Mode creation * * * ************************************************************************/ if ($action == 'create') { print_titre("Créer une commande"); $new_commande = new Commande($db); if ($propalid) { $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; $sql .= " AND p.rowid = $propalid"; } else { $sql = "SELECT s.nom, s.prefix_comm, s.idp "; $sql .= "FROM ".MAIN_DB_PREFIX."societe as s "; $sql .= "WHERE s.idp = $socidp"; } if ( $db->query($sql) ) { $num = $db->num_rows(); if ($num) { $obj = $db->fetch_object(0); $soc = new Societe($db); $soc->fetch($obj->idp); print '
'; print ''; print '' ."\n"; print ''; print ''; print ''; print ''; print ""; print ''; print ""; print ""; print ''; print ""; print ""; if ($propalid > 0) { $amount = ($obj->price); print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''."\n"; print ''; print ''; print ''; print '"; print '"; } else { print ''; print ''; } /* * */ print ''; print "\n"; print "
Client :'.$obj->nom.'Commentaire
Auteur :".$user->fullname."'; print '
Date :"; print_date_select(time()); print "
Numéro :Provisoire
Source :"; $html->select_array("source_id",$new_commande->sources,2); print "
Projet :"; $proj = new Project($db); $html->select_array("projetid",$proj->liste_array($socidp),0,1); print "
Proposition'.$obj->ref.'
Montant HT'.price($amount).'
TVA'.price($obj->tva)."
Total TTC'.price($obj->total)."
Services/Produits
'; /* * * Liste des elements * */ $sql = "SELECT p.rowid,p.label,p.ref,p.price FROM ".MAIN_DB_PREFIX."product as p "; $sql .= " WHERE envente = 1"; $sql .= " ORDER BY p.nbvente DESC LIMIT 20"; if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ''; print ''; for ($i = 1 ; $i < 5 ; $i++) { print ''; print ''; print ''; } print '
20 Produits les plus vendusQuan.Remise
%
'; print '
\n"; if ($propalid) { /* * Produits */ print_titre("Produits"); print ''; print ''; print ''; $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propalid"; $sql .= " ORDER BY pt.rowid ASC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows(); $i = 0; $var=True; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ""; print ''; print "\n"; $i++; } } $sql = "SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent"; $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt WHERE pt.fk_propal = $propalid AND pt.fk_product = 0"; $sql .= " ORDER BY pt.rowid ASC"; if ($db->query($sql)) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object($i); $var=!$var; print "\n"; print ''; print ''; print ''; print "\n"; $i++; } } else { print $sql; } print '
RéfProduitPrixRemiseQté.
[$objp->ref]'.$objp->product.'".price($objp->price)."'.$objp->remise_percent.' %".$objp->qty."
 '.$objp->product.''.price($objp->price).''.$objp->remise_percent.' %".$objp->qty."
'; } } } else { print $db->error() . "
$sql";; } } else /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ { $id = $_GET["id"]; if ($id > 0) { $commande = New Commande($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(); print_titre("Commande : ".$commande->ref); /* * Confirmation de la suppression de la commande * */ if ($_GET["action"] == 'delete') { $html->form_confirm("$PHP_SELF?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("$PHP_SELF?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("$PHP_SELF?id=$id","Annuler la commande","Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); } /* * Commande */ if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '
'; print ''; } print ''; print ""; print ''; print '"; print ""; print "\n"; print '"; print ""; print '"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($commande->note) { print '"; } print "
Client'; print ''.$soc->nom.''; print $commande->statuts[$commande->statut]; print "
Date".strftime("%A %d %B %Y",$commande->date)."Source : ' . $commande->sources[$commande->source] ; if ($commande->source == 0) { /* Propale */ $propal = new Propal($db); $propal->fetch($commande->propale_id); print ' -> '.$propal->ref.''; } print "
Auteur$author->fullnameProjet : '; if ($commande->projet_id > 0) { $projet = New Project($db); $projet->fetch($commande->projet_id); print ''.$projet->title.''; } else { print 'Classer la commande'; } print " 
Montant'.price($commande->total_ht).''.MAIN_MONNAIE.' HTNote
Remise globale'; if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '%'; print ''; } else { print $commande->remise_percent.' % '; } print '
TVA'.price($commande->total_tva).''.MAIN_MONNAIE.'
Total'.price($commande->total_ttc).''.MAIN_MONNAIE.' TTC
Note : '.nl2br($commande->note)."
"; if ($commande->brouillon == 1 && $user->rights->commande->creer) { print '
'; } /* * Lignes de commandes * */ echo '
'; $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as l 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 "\n"; } $var=True; while ($i < $num) { $objp = $db->fetch_object( $i); 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->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 FROM ".MAIN_DB_PREFIX."product as p "; $sql .= " WHERE envente = 1"; $sql .= " ORDER BY p.nbvente DESC LIMIT 20"; if ( $db->query($sql) ) { $opt = ""; if ($result) { $num = $db->num_rows(); $i = 0; while ($i < $num) { $objp = $db->fetch_object( $i); $opt .= "\n"; $i++; } } $db->free(); } else { print $db->error(); } print ""; print ""; print ''; print ''; print ''; print ''; print ''; print ''."\n"; print ''; print "".''; print ''; print ''; print ''; print ''; print ''; $var=!$var; print ""; print ''; print ''; print ''; print ''; print "\n"; print ""; } print "
DescriptionTvaQuantitéRemiseP.U.  
'; 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 '  
 %
DescriptionTvaQuantitéRemiseP.U.  
'; print $html->select_tva("tva_tx"); print ' %
% 
"; /* * Fin Ajout ligne * */ if ($user->societe_id == 0 && $commande->statut < 3) { print '

'; if ($commande->statut == 0 && $user->rights->commande->supprimer) { print 'Supprimer'; } elseif ($commande->statut == 1 && abs($resteapayer) > 0 && $user->rights->commande->envoyer) { print 'Envoyer'; } if ($commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) { print 'Expédier'; } if ($commande->statut == 0) { if ($user->rights->commande->valider) { print 'Valider'; } } if ($commande->statut == 1) { $nb_expedition = $commande->nb_expedition(); if ($user->rights->commande->valider && $nb_expedition == 0) { print 'Annuler la commande'; } } 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( $i); $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( $i); $var=!$var; print ""; print ''; print "\n"; $i++; } print "
FactureDate
'.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 ''; print_titre("Actions"); /* * Liste des actions * */ /* * * */ } /* * * */ if ($action == 'classer') { print "

\n"; 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$"); ?>