*
* 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 ($_POST["action"] == 'classin')
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
$commande->classin($_POST["projetid"]);
}
/*
*
*/
if ($_POST["action"] == 'add')
{
$datecommande = mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$commande = new Commande($db);
$commande->soc_id = $_POST["soc_id"];
$commande->date_commande = $datecommande;
$commande->note = $_POST["note"];
$commande->source = $_POST["source_id"];
$commande->projetid = $_POST["projetid"];
$commande->remise_percent = $_POST["remise_percent"];
$commande->add_product($_POST["idprod1"],$_POST["qty1"],$_POST["remise_percent1"]);
$commande->add_product($_POST["idprod2"],$_POST["qty2"],$_POST["remise_percent2"]);
$commande->add_product($_POST["idprod3"],$_POST["qty3"],$_POST["remise_percent3"]);
$commande->add_product($_POST["idprod4"],$_POST["qty4"],$_POST["remise_percent4"]);
$commande_id = $commande->create($user);
$_GET["id"] = $commande->id;
$action = '';
}
/*
*
*/
if ($_POST["action"] == 'setremise' && $user->rights->commande->creer)
{
$commande = new Commande($db);
$commande->fetch($id);
$commande->set_remise($user, $_POST["remise"]);
}
if ($_POST["action"] == 'addligne' && $user->rights->commande->creer)
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
if ($_POST["p_idprod"] > 0)
{
$result = $commande->addline("DESC",
$_POST["pu"],
$_POST["pqty"],
$_POST["tva_tx"],
$_POST["p_idprod"],
$_POST["premise"]);
}
else
{
$result = $commande->addline($_POST["desc"],
$_POST["pu"],
$_POST["qty"],
$_POST["tva_tx"],
0,
$_POST["remise_percent"]);
}
}
if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer)
{
$commande = new Commande($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 ($action == 'deleteline' && $user->rights->commande->creer)
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
$result = $commande->delete_line($_GET["lineid"]);
}
if ($_POST["action"] == 'confirm_valid' && $_POST["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 ($_POST["action"] == 'confirm_cancel' && $_POST["confirm"] == yes && $user->rights->commande->valider)
{
$commande = new Commande($db);
$commande->fetch($_GET["id"]);
$result = $commande->cancel($user);
}
if ($_POST["action"] == 'confirm_delete' && $_POST["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','Commande');
$html = new Form($db);
/*********************************************************************
*
* Mode creation
*
*
*
************************************************************************/
if ($_GET["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 = ".$_GET["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 '
';
}
/*
* 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 '