Gestion des références client dans une commande client
This commit is contained in:
parent
2dc987b86f
commit
e7ca38a3ea
@ -19,22 +19,18 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
* $Source$
|
* $Source$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file htdocs/commande/commande.class.php
|
\file htdocs/commande/commande.class.php
|
||||||
\ingroup commande
|
\ingroup commande
|
||||||
\brief Fichier des classes de commandes
|
\brief Fichier des classes de commandes
|
||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class Commande
|
\class Commande
|
||||||
\brief Classe de gestion de commande
|
\brief Classe de gestion de commande
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Commande
|
class Commande
|
||||||
{
|
{
|
||||||
var $db ;
|
var $db ;
|
||||||
@ -52,32 +48,28 @@ class Commande
|
|||||||
function Commande($DB)
|
function Commande($DB)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
$langs->load("orders");
|
$langs->load('orders');
|
||||||
|
|
||||||
$this->db = $DB;
|
$this->db = $DB;
|
||||||
|
$this->statuts[-1] = $langs->trans('StatusOrderCanceled');
|
||||||
|
$this->statuts[0] = $langs->trans('StatusOrderDraft');
|
||||||
|
$this->statuts[1] = $langs->trans('StatusOrderValidated');
|
||||||
|
$this->statuts[2] = $langs->trans('StatusOrderOnProcess');
|
||||||
|
$this->statuts[3] = $langs->trans('StatusOrderProcessed');
|
||||||
|
|
||||||
$this->statuts[-1] = $langs->trans("StatusOrderCanceled");
|
$this->status_label_short[-1] = $langs->trans('StatusOrderCanceled');
|
||||||
$this->statuts[0] = $langs->trans("StatusOrderDraft");
|
$this->status_label_short[0] = $langs->trans('StatusOrderDraft');
|
||||||
$this->statuts[1] = $langs->trans("StatusOrderValidated");
|
$this->status_label_short[1] = $langs->trans('StatusOrderValidated');
|
||||||
$this->statuts[2] = $langs->trans("StatusOrderOnProcess");
|
$this->status_label_short[2] = $langs->trans('StatusOrderOnProcessShort');
|
||||||
$this->statuts[3] = $langs->trans("StatusOrderProcessed");
|
$this->status_label_short[3] = $langs->trans('StatusOrderProcessed');
|
||||||
|
|
||||||
$this->status_label_short[-1] = $langs->trans("StatusOrderCanceled");
|
|
||||||
$this->status_label_short[0] = $langs->trans("StatusOrderDraft");
|
|
||||||
$this->status_label_short[1] = $langs->trans("StatusOrderValidated");
|
|
||||||
$this->status_label_short[2] = $langs->trans("StatusOrderOnProcessShort");
|
|
||||||
$this->status_label_short[3] = $langs->trans("StatusOrderProcessed");
|
|
||||||
|
|
||||||
$this->sources[0] = $langs->trans("OrderSource0");
|
|
||||||
$this->sources[1] = $langs->trans("OrderSource1");
|
|
||||||
$this->sources[2] = $langs->trans("OrderSource2");
|
|
||||||
$this->sources[3] = $langs->trans("OrderSource3");
|
|
||||||
$this->sources[4] = $langs->trans("OrderSource4");
|
|
||||||
$this->sources[5] = $langs->trans("OrderSource5");
|
|
||||||
|
|
||||||
|
$this->sources[0] = $langs->trans('OrderSource0');
|
||||||
|
$this->sources[1] = $langs->trans('OrderSource1');
|
||||||
|
$this->sources[2] = $langs->trans('OrderSource2');
|
||||||
|
$this->sources[3] = $langs->trans('OrderSource3');
|
||||||
|
$this->sources[4] = $langs->trans('OrderSource4');
|
||||||
|
$this->sources[5] = $langs->trans('OrderSource5');
|
||||||
$this->products = array();
|
$this->products = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Créé la facture depuis une propale existante
|
/** \brief Créé la facture depuis une propale existante
|
||||||
\param user Utilisateur qui crée
|
\param user Utilisateur qui crée
|
||||||
\param propale_id id de la propale qui sert de modèle
|
\param propale_id id de la propale qui sert de modèle
|
||||||
@ -86,16 +78,12 @@ class Commande
|
|||||||
{
|
{
|
||||||
$propal = new Propal($this->db);
|
$propal = new Propal($this->db);
|
||||||
$propal->fetch($propale_id);
|
$propal->fetch($propale_id);
|
||||||
|
|
||||||
$this->lines = array();
|
$this->lines = array();
|
||||||
|
|
||||||
$this->date_commande = time();
|
$this->date_commande = time();
|
||||||
$this->source = 0;
|
$this->source = 0;
|
||||||
|
|
||||||
for ($i = 0 ; $i < sizeof($propal->lignes) ; $i++)
|
for ($i = 0 ; $i < sizeof($propal->lignes) ; $i++)
|
||||||
{
|
{
|
||||||
$CommLigne = new CommandeLigne();
|
$CommLigne = new CommandeLigne();
|
||||||
|
|
||||||
$CommLigne->libelle = $propal->lignes[$i]->libelle;
|
$CommLigne->libelle = $propal->lignes[$i]->libelle;
|
||||||
$CommLigne->price = $propal->lignes[$i]->subprice;
|
$CommLigne->price = $propal->lignes[$i]->subprice;
|
||||||
$CommLigne->subprice = $propal->lignes[$i]->subprice;
|
$CommLigne->subprice = $propal->lignes[$i]->subprice;
|
||||||
@ -103,7 +91,6 @@ class Commande
|
|||||||
$CommLigne->qty = $propal->lignes[$i]->qty;
|
$CommLigne->qty = $propal->lignes[$i]->qty;
|
||||||
$CommLigne->remise_percent = $propal->lignes[$i]->remise_percent;
|
$CommLigne->remise_percent = $propal->lignes[$i]->remise_percent;
|
||||||
$CommLigne->product_id = $propal->lignes[$i]->product_id;
|
$CommLigne->product_id = $propal->lignes[$i]->product_id;
|
||||||
|
|
||||||
$this->lines[$i] = $CommLigne;
|
$this->lines[$i] = $CommLigne;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +100,6 @@ class Commande
|
|||||||
$soc = new Societe($this->db);
|
$soc = new Societe($this->db);
|
||||||
$soc->id = $this->soc_id;
|
$soc->id = $this->soc_id;
|
||||||
$soc->set_as_client();
|
$soc->set_as_client();
|
||||||
|
|
||||||
$this->propale_id = $propal->id;
|
$this->propale_id = $propal->id;
|
||||||
return $this->create($user);
|
return $this->create($user);
|
||||||
}
|
}
|
||||||
@ -126,19 +112,19 @@ class Commande
|
|||||||
$result = 0;
|
$result = 0;
|
||||||
if ($user->rights->commande->valider)
|
if ($user->rights->commande->valider)
|
||||||
{
|
{
|
||||||
if (defined("COMMANDE_ADDON"))
|
if (defined('COMMANDE_ADDON'))
|
||||||
{
|
{
|
||||||
if (is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/commande/".COMMANDE_ADDON.".php"))
|
if (is_readable(DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php'))
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT ."/includes/modules/commande/".COMMANDE_ADDON.".php";
|
require_once DOL_DOCUMENT_ROOT .'/includes/modules/commande/'.COMMANDE_ADDON.'.php';
|
||||||
|
|
||||||
// Definition du nom de module de numerotation de commande
|
// Definition du nom de module de numerotation de commande
|
||||||
|
|
||||||
// \todo Normer le nom des classes des modules de numérotation de ref de commande avec un nom du type NumRefCommandesXxxx
|
// \todo Normer le nom des classes des modules de numérotation de ref de commande avec un nom du type NumRefCommandesXxxx
|
||||||
//
|
//
|
||||||
//$list=split("_",COMMANDE_ADDON);
|
//$list=split('_',COMMANDE_ADDON);
|
||||||
//$numrefname=$list[2];
|
//$numrefname=$list[2];
|
||||||
//$modName = "NumRefCommandes".ucfirst($numrefname);
|
//$modName = 'NumRefCommandes'.ucfirst($numrefname);
|
||||||
$modName=COMMANDE_ADDON;
|
$modName=COMMANDE_ADDON;
|
||||||
|
|
||||||
// Recuperation de la nouvelle reference
|
// Recuperation de la nouvelle reference
|
||||||
@ -147,7 +133,7 @@ class Commande
|
|||||||
$soc->fetch($this->soc_id);
|
$soc->fetch($this->soc_id);
|
||||||
$num = $objMod->commande_get_num($soc);
|
$num = $objMod->commande_get_num($soc);
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='$num', fk_statut = 1, date_valid=now(), fk_user_valid=$user->id";
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
@ -163,17 +149,16 @@ class Commande
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Impossible de lire le module de numérotation";
|
print 'Impossible de lire le module de numérotation';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Le module de numérotation n'est pas définit" ;
|
print 'Le module de numérotation n\'est pas défini' ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $result ;
|
return $result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Cloture la commande
|
* \brief Cloture la commande
|
||||||
* \param user Objet utilisateur qui cloture
|
* \param user Objet utilisateur qui cloture
|
||||||
@ -183,10 +168,10 @@ class Commande
|
|||||||
{
|
{
|
||||||
if ($user->rights->commande->valider)
|
if ($user->rights->commande->valider)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande';
|
||||||
$sql.= " SET fk_statut = 3,";
|
$sql.= ' SET fk_statut = 3,';
|
||||||
$sql.= " fk_user_cloture = ".$user->id.",";
|
$sql.= ' fk_user_cloture = '.$user->id.',';
|
||||||
$sql.= " date_cloture = now()";
|
$sql.= ' date_cloture = now()';
|
||||||
$sql.= " WHERE rowid = $this->id AND fk_statut > 0 ;";
|
$sql.= " WHERE rowid = $this->id AND fk_statut > 0 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
@ -200,7 +185,6 @@ class Commande
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annule la commande
|
* Annule la commande
|
||||||
*
|
*
|
||||||
@ -209,8 +193,7 @@ class Commande
|
|||||||
{
|
{
|
||||||
if ($user->rights->commande->valider)
|
if ($user->rights->commande->valider)
|
||||||
{
|
{
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1';
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = -1";
|
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
@ -223,7 +206,6 @@ class Commande
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Créé la commande
|
* Créé la commande
|
||||||
*
|
*
|
||||||
@ -232,7 +214,6 @@ class Commande
|
|||||||
{
|
{
|
||||||
/* On positionne en mode brouillon la commande */
|
/* On positionne en mode brouillon la commande */
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
|
|
||||||
if (! $remise)
|
if (! $remise)
|
||||||
{
|
{
|
||||||
$remise = 0 ;
|
$remise = 0 ;
|
||||||
@ -242,14 +223,12 @@ class Commande
|
|||||||
{
|
{
|
||||||
$this->projetid = 0;
|
$this->projetid = 0;
|
||||||
}
|
}
|
||||||
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande (fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, ref_client) ';
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande (fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source) ";
|
$sql .= ' VALUES ('.$this->soc_id.', now(), '.$user->id.', '.$this->projetid.', '.$this->db->idate($this->date_commande).', '.$this->source.', \''.$this->note.'\', \''.$this->ref_client.'\')';
|
||||||
$sql .= " VALUES ($this->soc_id, now(), $user->id, $this->projetid, ".$this->db->idate($this->date_commande).", $this->source)";
|
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insertion des produits dans la base
|
* Insertion des produits dans la base
|
||||||
*/
|
*/
|
||||||
@ -266,18 +245,12 @@ class Commande
|
|||||||
$this->products_remise_percent[$i]);
|
$this->products_remise_percent[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
|
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->id && $this->propale_id)
|
if ($this->id && $this->propale_id)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."co_pr (fk_commande, fk_propale) VALUES (".$this->id.",".$this->propale_id.")";
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')';
|
||||||
$this->db->query($sql);
|
$this->db->query($sql);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -293,17 +266,11 @@ class Commande
|
|||||||
$this->lines[$i]->tva_tx,
|
$this->lines[$i]->tva_tx,
|
||||||
$this->lines[$i]->product_id,
|
$this->lines[$i]->product_id,
|
||||||
$this->lines[$i]->remise_percent);
|
$this->lines[$i]->remise_percent);
|
||||||
|
|
||||||
if ( $result_insert < 0)
|
if ( $result_insert < 0)
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -330,7 +297,7 @@ class Commande
|
|||||||
$p_qty = 1;
|
$p_qty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$p_price = ereg_replace(",",".",$p_price);
|
$p_price = ereg_replace(',','.',$p_price);
|
||||||
|
|
||||||
$price = $p_price;
|
$price = $p_price;
|
||||||
$subprice = $p_price;
|
$subprice = $p_price;
|
||||||
@ -340,12 +307,10 @@ class Commande
|
|||||||
$price = $p_price - $remise;
|
$price = $p_price - $remise;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ';
|
||||||
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','". $price."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '$subprice') ; ";
|
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','". $price."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '$subprice') ; ";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->update_price() > 0)
|
if ($this->update_price() > 0)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -370,8 +335,8 @@ class Commande
|
|||||||
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
|
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
|
||||||
{
|
{
|
||||||
// Nettoyage parametres
|
// Nettoyage parametres
|
||||||
$qty = ereg_replace(",",".",$qty);
|
$qty = ereg_replace(',','.',$qty);
|
||||||
$pu = ereg_replace(",",".",$pu);
|
$pu = ereg_replace(',','.',$pu);
|
||||||
$desc=trim($desc);
|
$desc=trim($desc);
|
||||||
if (strlen(trim($qty))==0)
|
if (strlen(trim($qty))==0)
|
||||||
{
|
{
|
||||||
@ -395,7 +360,7 @@ class Commande
|
|||||||
}
|
}
|
||||||
|
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$price = round(ereg_replace(",",".",$pu), 2);
|
$price = round(ereg_replace(',','.',$pu), 2);
|
||||||
$subprice = $price;
|
$subprice = $price;
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
{
|
{
|
||||||
@ -403,7 +368,7 @@ class Commande
|
|||||||
$price = $pu - $remise;
|
$price = $pu - $remise;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande,label,description,fk_product, price,qty,tva_tx, remise_percent, subprice, remise)";
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet (fk_commande,label,description,fk_product, price,qty,tva_tx, remise_percent, subprice, remise)';
|
||||||
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."') ;";
|
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."') ;";
|
||||||
|
|
||||||
if ( $this->db->query( $sql) )
|
if ( $this->db->query( $sql) )
|
||||||
@ -445,17 +410,15 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function fetch ($id)
|
function fetch ($id)
|
||||||
{
|
{
|
||||||
$sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva";
|
$sql = 'SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva';
|
||||||
$sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.facture, c.note";
|
$sql .= ', '.$this->db->pdate('c.date_commande').' as date_commande, c.fk_projet, c.remise_percent, c.source, c.facture, c.note, c.ref_client';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande as c';
|
||||||
$sql .= " WHERE c.rowid = ".$id;
|
$sql .= ' WHERE c.rowid = '.$id;
|
||||||
|
|
||||||
$result = $this->db->query($sql) ;
|
$result = $this->db->query($sql) ;
|
||||||
|
|
||||||
if ( $result )
|
if ( $result )
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
$this->ref = $obj->ref;
|
$this->ref = $obj->ref;
|
||||||
$this->soc_id = $obj->fk_soc;
|
$this->soc_id = $obj->fk_soc;
|
||||||
@ -466,21 +429,18 @@ class Commande
|
|||||||
$this->total_ttc = $obj->total_ttc;
|
$this->total_ttc = $obj->total_ttc;
|
||||||
$this->date = $obj->date_commande;
|
$this->date = $obj->date_commande;
|
||||||
$this->remise_percent = $obj->remise_percent;
|
$this->remise_percent = $obj->remise_percent;
|
||||||
|
|
||||||
$this->source = $obj->source;
|
$this->source = $obj->source;
|
||||||
$this->facturee = $obj->facture;
|
$this->facturee = $obj->facture;
|
||||||
$this->note = $obj->note;
|
$this->note = $obj->note;
|
||||||
|
$this->ref_client = $obj->ref_client;
|
||||||
$this->projet_id = $obj->fk_projet;
|
$this->projet_id = $obj->fk_projet;
|
||||||
|
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
|
|
||||||
if ($this->statut == 0)
|
if ($this->statut == 0)
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Propale associée
|
* Propale associée
|
||||||
*/
|
*/
|
||||||
$sql = "SELECT fk_propale FROM ".MAIN_DB_PREFIX."co_pr WHERE fk_commande = ".$this->id;
|
$sql = 'SELECT fk_propale FROM '.MAIN_DB_PREFIX.'co_pr WHERE fk_commande = '.$this->id;
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows())
|
if ($this->db->num_rows())
|
||||||
@ -488,7 +448,6 @@ class Commande
|
|||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
$this->propale_id = $obj->fk_propale;
|
$this->propale_id = $obj->fk_propale;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -510,18 +469,15 @@ class Commande
|
|||||||
function fetch_lignes($only_product=0)
|
function fetch_lignes($only_product=0)
|
||||||
{
|
{
|
||||||
$this->lignes = array();
|
$this->lignes = array();
|
||||||
|
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice';
|
||||||
$sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice";
|
|
||||||
|
|
||||||
if ($only_product==1)
|
if ($only_product==1)
|
||||||
{
|
{
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as l LEFT JOIN ".MAIN_DB_PREFIX."product as p ON (p.rowid = l.fk_product) WHERE l.fk_commande = ".$this->id." AND p.fk_product_type <> 1 ORDER BY l.rowid";
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'commandedet as l LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product) WHERE l.fk_commande = '.$this->id.' AND p.fk_product_type <> 1 ORDER BY l.rowid';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."commandedet as l WHERE l.fk_commande = $this->id ORDER BY l.rowid";
|
$sql .= ' FROM '.MAIN_DB_PREFIX."commandedet as l WHERE l.fk_commande = $this->id ORDER BY l.rowid";
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -530,11 +486,8 @@ class Commande
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$ligne = new CommandeLigne();
|
$ligne = new CommandeLigne();
|
||||||
|
|
||||||
$objp = $this->db->fetch_object($result);
|
$objp = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$ligne->id = $objp->rowid;
|
$ligne->id = $objp->rowid;
|
||||||
|
|
||||||
$ligne->qty = $objp->qty;
|
$ligne->qty = $objp->qty;
|
||||||
$ligne->price = $objp->price;
|
$ligne->price = $objp->price;
|
||||||
$ligne->tva_tx = $objp->tva_tx;
|
$ligne->tva_tx = $objp->tva_tx;
|
||||||
@ -542,13 +495,11 @@ class Commande
|
|||||||
$ligne->remise_percent = $objp->remise_percent;
|
$ligne->remise_percent = $objp->remise_percent;
|
||||||
$ligne->product_id = $objp->fk_product;
|
$ligne->product_id = $objp->fk_product;
|
||||||
$ligne->description = stripslashes($objp->description);
|
$ligne->description = stripslashes($objp->description);
|
||||||
|
|
||||||
$this->lignes[$i] = $ligne;
|
$this->lignes[$i] = $ligne;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->lignes;
|
return $this->lignes;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -559,12 +510,11 @@ class Commande
|
|||||||
function livraison_array()
|
function livraison_array()
|
||||||
{
|
{
|
||||||
$this->livraisons = array();
|
$this->livraisons = array();
|
||||||
|
$sql = 'SELECT fk_product, sum(ed.qty)';
|
||||||
$sql = "SELECT fk_product, sum(ed.qty)";
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed, '.MAIN_DB_PREFIX.'commande as c, '.MAIN_DB_PREFIX.'commandedet as cd';
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."commandedet as cd";
|
$sql .=' WHERE ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid';
|
||||||
$sql .=" WHERE ed.fk_commande_ligne = cd .rowid AND cd.fk_commande = c.rowid";
|
$sql .= ' AND cd.fk_commande =' .$this->id;
|
||||||
$sql .= " AND cd.fk_commande =" .$this->id;
|
$sql .= ' GROUP BY fk_product ';
|
||||||
$sql .= " GROUP BY fk_product ";
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -573,9 +523,7 @@ class Commande
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_row( $i);
|
$row = $this->db->fetch_row( $i);
|
||||||
|
|
||||||
$this->livraisons[$row[0]] = $row[1];
|
$this->livraisons[$row[0]] = $row[1];
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$this->db->free();
|
$this->db->free();
|
||||||
@ -587,18 +535,16 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function nb_expedition()
|
function nb_expedition()
|
||||||
{
|
{
|
||||||
$sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."expedition as e";
|
$sql = 'SELECT count(*) FROM '.MAIN_DB_PREFIX.'expedition as e';
|
||||||
$sql .=" WHERE e.fk_commande = $this->id";
|
$sql .=" WHERE e.fk_commande = $this->id";
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_row(0);
|
$row = $this->db->fetch_row(0);
|
||||||
|
|
||||||
return $row[0];
|
return $row[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Supprime une ligne de la commande
|
* \brief Supprime une ligne de la commande
|
||||||
* \param idligne Id de la ligne à supprimer
|
* \param idligne Id de la ligne à supprimer
|
||||||
@ -608,12 +554,10 @@ class Commande
|
|||||||
{
|
{
|
||||||
if ($this->statut == 0)
|
if ($this->statut == 0)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid = $idligne";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$this->update_price();
|
$this->update_price();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -631,12 +575,9 @@ class Commande
|
|||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
|
$remise = ereg_replace(',','.',$remise);
|
||||||
$remise = ereg_replace(",",".",$remise);
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET remise_percent = '.$remise;
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET remise_percent = ".$remise;
|
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$this->remise_percent = $remise;
|
$this->remise_percent = $remise;
|
||||||
@ -645,11 +586,32 @@ class Commande
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Commande::set_remise Erreur SQL");
|
dolibarr_syslog('Commande::set_remise Erreur SQL');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function set_ref_client($user, $ref_client)
|
||||||
|
{
|
||||||
|
if ($user->rights->commande->creer)
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.addslashes($ref_client).'\'');
|
||||||
|
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut = 0 ;';
|
||||||
|
if ($this->db->query($sql) )
|
||||||
|
{
|
||||||
|
$this->ref_client = $ref_client;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog('Commande::set_ref_client Erreur SQL');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -658,7 +620,7 @@ class Commande
|
|||||||
{
|
{
|
||||||
if ($user->rights->commande->creer)
|
if ($user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET note = '".addslashes($note)."'";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET note = '".addslashes($note)."'";
|
||||||
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;";
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
@ -682,9 +644,8 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function classer_facturee()
|
function classer_facturee()
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET facture = 1";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 1';
|
||||||
$sql .= " WHERE rowid = ".$this->id." AND fk_statut > 0 ;";
|
$sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 ;';
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -701,17 +662,15 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function update_price()
|
function update_price()
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
|
include_once DOL_DOCUMENT_ROOT . '/lib/price.lib.php';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Liste des produits a ajouter
|
* Liste des produits a ajouter
|
||||||
*/
|
*/
|
||||||
$sql = "SELECT price, qty, tva_tx FROM ".MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id";
|
$sql = 'SELECT price, qty, tva_tx FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id";
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$num = $this->db->num_rows();
|
$num = $this->db->num_rows();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object();
|
$obj = $this->db->fetch_object();
|
||||||
@ -735,12 +694,12 @@ class Commande
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande set";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande set';
|
||||||
$sql .= " amount_ht ='".ereg_replace(",",".",$totalht)."'";
|
$sql .= " amount_ht ='".ereg_replace(',','.',$totalht)."'";
|
||||||
$sql .= ", total_ht ='".ereg_replace(",",".",$totalht)."'";
|
$sql .= ", total_ht ='".ereg_replace(',','.',$totalht)."'";
|
||||||
$sql .= ", tva ='".ereg_replace(",",".",$totaltva)."'";
|
$sql .= ", tva ='".ereg_replace(',','.',$totaltva)."'";
|
||||||
$sql .= ", total_ttc ='".ereg_replace(",",".",$totalttc)."'";
|
$sql .= ", total_ttc ='".ereg_replace(',','.',$totalttc)."'";
|
||||||
$sql .= ", remise ='".ereg_replace(",",".",$total_remise)."'";
|
$sql .= ", remise ='".ereg_replace(',','.',$total_remise)."'";
|
||||||
$sql .= " WHERE rowid = $this->id";
|
$sql .= " WHERE rowid = $this->id";
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
@ -748,11 +707,10 @@ class Commande
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "Erreur mise à jour du prix<p>".$sql;
|
print 'Erreur mise à jour du prix<p>'.$sql;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Mets à jour une ligne de commande
|
* \brief Mets à jour une ligne de commande
|
||||||
* \param rowid Id de la ligne de facture
|
* \param rowid Id de la ligne de facture
|
||||||
@ -765,18 +723,16 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function update_line($rowid, $desc, $pu, $qty, $remise_percent=0, $tva_tx)
|
function update_line($rowid, $desc, $pu, $qty, $remise_percent=0, $tva_tx)
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Commande::UpdateLine");
|
dolibarr_syslog('Commande::UpdateLine');
|
||||||
|
|
||||||
if ($this->brouillon)
|
if ($this->brouillon)
|
||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
if (strlen(trim($qty))==0)
|
if (strlen(trim($qty))==0)
|
||||||
{
|
{
|
||||||
$qty=1;
|
$qty=1;
|
||||||
}
|
}
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$price = ereg_replace(",",".",$pu);
|
$price = ereg_replace(',','.',$pu);
|
||||||
$subprice = $price;
|
$subprice = $price;
|
||||||
if (trim(strlen($remise_percent)) > 0)
|
if (trim(strlen($remise_percent)) > 0)
|
||||||
{
|
{
|
||||||
@ -788,35 +744,31 @@ class Commande
|
|||||||
$remise_percent=0;
|
$remise_percent=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commandedet";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commandedet';
|
||||||
$sql.= " SET description='".addslashes($desc)."',price=$price,subprice=$subprice,";
|
$sql.= " SET description='".addslashes($desc)."',price=$price,subprice=$subprice,";
|
||||||
$sql.= " remise=$remise,remise_percent=$remise_percent,qty=$qty,tva_tx='".$tva_tx."'";
|
$sql.= " remise=$remise,remise_percent=$remise_percent,qty=$qty,tva_tx='".$tva_tx."'";
|
||||||
$sql.= " WHERE rowid = ".$rowid;
|
$sql.= ' WHERE rowid = '.$rowid;
|
||||||
|
|
||||||
$result=$this->db->query( $sql);
|
$result=$this->db->query( $sql);
|
||||||
if ( $result )
|
if ( $result )
|
||||||
{
|
{
|
||||||
$this->update_price($this->id);
|
$this->update_price($this->id);
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
|
|
||||||
dolibarr_print_error($this->db);
|
dolibarr_print_error($this->db);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supprime la commande
|
* Supprime la commande
|
||||||
*
|
*
|
||||||
@ -824,22 +776,20 @@ class Commande
|
|||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
$err = 0;
|
$err = 0;
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet WHERE fk_commande = $this->id ;";
|
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commande WHERE rowid = $this->id;";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = $this->id;";
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$err++;
|
$err++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."co_pr WHERE fk_commande = $this->id;";
|
$sql = 'DELETE FROM '.MAIN_DB_PREFIX."co_pr WHERE fk_commande = $this->id;";
|
||||||
if (! $this->db->query($sql) )
|
if (! $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
$err++;
|
$err++;
|
||||||
@ -862,7 +812,7 @@ class Commande
|
|||||||
*/
|
*/
|
||||||
function classin($cat_id)
|
function classin($cat_id)
|
||||||
{
|
{
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_projet = $cat_id";
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET fk_projet = $cat_id";
|
||||||
$sql .= " WHERE rowid = $this->id;";
|
$sql .= " WHERE rowid = $this->id;";
|
||||||
|
|
||||||
if ($this->db->query($sql) )
|
if ($this->db->query($sql) )
|
||||||
@ -876,7 +826,6 @@ class Commande
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
|
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
|
||||||
* \param user Objet user
|
* \param user Objet user
|
||||||
@ -887,10 +836,10 @@ class Commande
|
|||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$this->nbtodo=$this->nbtodolate=0;
|
$this->nbtodo=$this->nbtodolate=0;
|
||||||
$sql = "SELECT c.rowid,".$this->db->pdate("c.date_creation")." as datec";
|
$sql = 'SELECT c.rowid,'.$this->db->pdate('c.date_creation').' as datec';
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
|
||||||
$sql.= " WHERE c.fk_statut BETWEEN 1 AND 2";
|
$sql.= ' WHERE c.fk_statut BETWEEN 1 AND 2';
|
||||||
if ($user->societe_id) $sql.=" AND fk_soc = ".$user->societe_id;
|
if ($user->societe_id) $sql.=' AND fk_soc = '.$user->societe_id;
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -928,42 +877,41 @@ class Commande
|
|||||||
return $this->status_label_short[$statut];
|
return $this->status_label_short[$statut];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Charge les informations d'ordre info dans l'objet commande
|
* \brief Charge les informations d'ordre info dans l'objet commande
|
||||||
* \param id Id de la commande a charger
|
* \param id Id de la commande a charger
|
||||||
*/
|
*/
|
||||||
function info($id)
|
function info($id)
|
||||||
{
|
{
|
||||||
$sql = "SELECT c.rowid, ".$this->db->pdate("date_creation")." as datec,";
|
$sql = 'SELECT c.rowid, '.$this->db->pdate('date_creation').' as datec,';
|
||||||
$sql.= " ".$this->db->pdate("date_valid")." as datev,";
|
$sql.= ' '.$this->db->pdate('date_valid').' as datev,';
|
||||||
$sql.= " ".$this->db->pdate("date_cloture")." as datecloture,";
|
$sql.= ' '.$this->db->pdate('date_cloture').' as datecloture,';
|
||||||
$sql.= " fk_user_author, fk_user_valid, fk_user_cloture";
|
$sql.= ' fk_user_author, fk_user_valid, fk_user_cloture';
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
|
||||||
$sql.= " WHERE c.rowid = ".$id;
|
$sql.= ' WHERE c.rowid = '.$id;
|
||||||
|
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
if ($this->db->num_rows($result))
|
if ($this->db->num_rows($result))
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
|
if ($obj->fk_user_author)
|
||||||
if ($obj->fk_user_author) {
|
{
|
||||||
$cuser = new User($this->db, $obj->fk_user_author);
|
$cuser = new User($this->db, $obj->fk_user_author);
|
||||||
$cuser->fetch();
|
$cuser->fetch();
|
||||||
$this->user_creation = $cuser;
|
$this->user_creation = $cuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($obj->fk_user_valid) {
|
if ($obj->fk_user_valid)
|
||||||
|
{
|
||||||
$vuser = new User($this->db, $obj->fk_user_valid);
|
$vuser = new User($this->db, $obj->fk_user_valid);
|
||||||
$vuser->fetch();
|
$vuser->fetch();
|
||||||
$this->user_validation = $vuser;
|
$this->user_validation = $vuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($obj->fk_user_cloture) {
|
if ($obj->fk_user_cloture)
|
||||||
|
{
|
||||||
$cluser = new User($this->db, $obj->fk_user_cloture);
|
$cluser = new User($this->db, $obj->fk_user_cloture);
|
||||||
$cluser->fetch();
|
$cluser->fetch();
|
||||||
$this->user_cloture = $cluser;
|
$this->user_cloture = $cluser;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -93,7 +93,7 @@ if ( $db->query($sql) )
|
|||||||
*/
|
*/
|
||||||
$sql = "SELECT c.rowid, c.ref, s.nom, s.idp FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
|
$sql = "SELECT c.rowid, c.ref, s.nom, s.idp FROM ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 1";
|
$sql .= " WHERE c.fk_soc = s.idp AND c.fk_statut = 1";
|
||||||
$sql .= " ORDER BY c.rowid ASC";
|
$sql .= " ORDER BY c.rowid DESC";
|
||||||
|
|
||||||
if ( $db->query($sql) )
|
if ( $db->query($sql) )
|
||||||
{
|
{
|
||||||
@ -109,7 +109,7 @@ if ( $db->query($sql) )
|
|||||||
{
|
{
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
$obj = $db->fetch_object();
|
$obj = $db->fetch_object();
|
||||||
print "<tr $bc[$var]><td width=\"30%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref."</a></td>";
|
print "<tr $bc[$var]><td><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref."</a></td>";
|
||||||
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td></tr>';
|
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td></tr>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ if ($resql)
|
|||||||
{
|
{
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
print "<tr $bc[$var]><td width=\"30%\"><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrders"),"order").' ';
|
print "<tr $bc[$var]><td><a href=\"fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrders"),"order").' ';
|
||||||
print $obj->ref.'</a></td>';
|
print $obj->ref.'</a></td>';
|
||||||
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
|
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
|
||||||
print '<td>'.dolibarr_print_date($obj->datec).'</td>';
|
print '<td>'.dolibarr_print_date($obj->datec).'</td>';
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -28,18 +29,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require('./pre.inc.php');
|
||||||
|
|
||||||
$langs->load("orders");
|
$langs->load('orders');
|
||||||
|
|
||||||
if (!$user->rights->commande->lire) accessforbidden();
|
if (!$user->rights->commande->lire)
|
||||||
|
accessforbidden();
|
||||||
|
|
||||||
$sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"];
|
$sref=isset($_GET['sref'])?$_GET['sref']:$_POST['sref'];
|
||||||
$snom=isset($_GET["snom"])?$_GET["snom"]:$_POST["snom"];
|
$sref_client=isset($_GET['sref_client'])?$_GET['sref_client']:(isset($_POST['sref_client'])?$_POST['sref_client']:'');
|
||||||
$sall=isset($_GET["sall"])?$_GET["sall"]:$_POST["sall"];
|
$snom=isset($_GET['snom'])?$_GET['snom']:$_POST['snom'];
|
||||||
|
$sall=isset($_GET['sall'])?$_GET['sall']:$_POST['sall'];
|
||||||
|
|
||||||
// Sécurité accés client
|
// Sécurité accés client
|
||||||
$socidp = $_GET["socidp"];
|
$socidp = $_GET['socidp'];
|
||||||
if ($user->societe_id > 0)
|
if ($user->societe_id > 0)
|
||||||
{
|
{
|
||||||
$action = '';
|
$action = '';
|
||||||
@ -49,19 +52,19 @@ if ($user->societe_id > 0)
|
|||||||
|
|
||||||
llxHeader();
|
llxHeader();
|
||||||
|
|
||||||
$begin=$_GET["begin"];
|
$begin=$_GET['begin'];
|
||||||
$sortorder=$_GET["sortorder"];
|
$sortorder=$_GET['sortorder'];
|
||||||
$sortfield=$_GET["sortfield"];
|
$sortfield=$_GET['sortfield'];
|
||||||
|
|
||||||
if (! $sortfield) $sortfield="c.rowid";
|
if (! $sortfield) $sortfield='c.rowid';
|
||||||
if (! $sortorder) $sortorder="DESC";
|
if (! $sortorder) $sortorder='DESC';
|
||||||
|
|
||||||
$limit = $conf->liste_limit;
|
$limit = $conf->liste_limit;
|
||||||
$offset = $limit * $_GET["page"] ;
|
$offset = $limit * $_GET['page'] ;
|
||||||
|
|
||||||
$sql = "SELECT s.nom, s.idp, c.rowid, c.ref, c.total_ht,".$db->pdate("c.date_commande")." as date_commande, c.fk_statut" ;
|
$sql = 'SELECT s.nom, s.idp, c.rowid, c.ref, c.total_ht,'.$db->pdate('c.date_commande').' as date_commande, c.fk_statut' ;
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'commande as c';
|
||||||
$sql.= " WHERE c.fk_soc = s.idp";
|
$sql.= ' WHERE c.fk_soc = s.idp';
|
||||||
if ($sref)
|
if ($sref)
|
||||||
{
|
{
|
||||||
$sql .= " AND c.ref like '%".$sref."%'";
|
$sql .= " AND c.ref like '%".$sref."%'";
|
||||||
@ -72,105 +75,117 @@ if ($sall)
|
|||||||
}
|
}
|
||||||
if ($socidp)
|
if ($socidp)
|
||||||
{
|
{
|
||||||
$sql .= " AND s.idp = $socidp";
|
$sql .= ' AND s.idp = '.$socidp;
|
||||||
}
|
}
|
||||||
if ($_GET["month"] > 0)
|
if ($_GET['month'] > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND date_format(c.date_commande, '%Y-%m') = '$year-$month'";
|
$sql .= " AND date_format(c.date_commande, '%Y-%m') = '$year-$month'";
|
||||||
}
|
}
|
||||||
if ($_GET["year"] > 0)
|
if ($_GET['year'] > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND date_format(c.date_commande, '%Y') = $year";
|
$sql .= " AND date_format(c.date_commande, '%Y') = $year";
|
||||||
}
|
}
|
||||||
if (isset($_GET["status"]))
|
if (isset($_GET['status']))
|
||||||
{
|
{
|
||||||
$sql .= " AND fk_statut = ".$_GET["status"];
|
$sql .= " AND fk_statut = ".$_GET['status'];
|
||||||
}
|
}
|
||||||
if (isset($_GET["afacturer"]))
|
if (isset($_GET['afacturer']))
|
||||||
{
|
{
|
||||||
$sql .= " AND c.facture = 0";
|
$sql .= ' AND c.facture = 0';
|
||||||
}
|
}
|
||||||
if (strlen($_POST["sf_ref"]) > 0)
|
if (strlen($_POST['sf_ref']) > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND c.ref like '%".$_POST["sf_ref"] . "%'";
|
$sql .= " AND c.ref like '%".$_POST['sf_ref'] . "%'";
|
||||||
|
}
|
||||||
|
if (!empty($snom))
|
||||||
|
{
|
||||||
|
$sql .= ' AND s.nom like \'%'.$snom.'%\'';
|
||||||
|
}
|
||||||
|
if (!empty($sref_client))
|
||||||
|
{
|
||||||
|
$sql .= ' AND c.ref_client like \'%'.$sref_client.'%\'';
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql .= " ORDER BY $sortfield $sortorder";
|
$sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
|
||||||
$sql .= $db->plimit($limit + 1,$offset);
|
$sql .= $db->plimit($limit + 1,$offset);
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($socidp)
|
if ($socidp)
|
||||||
{
|
{
|
||||||
$soc = new Societe($db);
|
$soc = new Societe($db);
|
||||||
$soc->fetch($socidp);
|
$soc->fetch($socidp);
|
||||||
$title = $langs->trans("ListOfOrders") . " - ".$soc->nom;
|
$title = $langs->trans('ListOfOrders') . ' - '.$soc->nom;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$title = $langs->trans("ListOfOrders");
|
$title = $langs->trans('ListOfOrders');
|
||||||
}
|
}
|
||||||
if ($_GET["status"] == 3) $title.=" - ".$langs->trans("StatusOrderToBill");
|
if ($_GET['status'] == 3)
|
||||||
|
$title.=' - '.$langs->trans('StatusOrderToBill');
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
print_barre_liste($title, $_GET["page"], "liste.php","&socidp=$socidp",$sortfield,$sortorder,'',$num);
|
print_barre_liste($title, $_GET['page'], 'liste.php','&socidp='.$socidp,$sortfield,$sortorder,'',$num);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print_liste_field_titre($langs->trans("Ref"),"liste.php","c.ref","","&socidp=$socidp",'width="15%"',$sortfield);
|
print_liste_field_titre($langs->trans('Ref'),'liste.php','c.ref','','&socidp='.$socidp,'width="25%"',$sortfield);
|
||||||
print_liste_field_titre($langs->trans("Company"),"liste.php","s.nom","","&socidp=$socidp",'width="30%"',$sortfield);
|
print_liste_field_titre($langs->trans('Company'),'liste.php','s.nom','','&socidp='.$socidp,'width="30%"',$sortfield);
|
||||||
print_liste_field_titre($langs->trans("Date"),"liste.php","c.date_commande","","&socidp=$socidp", 'width="25%" align="right" colspan="2"',$sortfield);
|
print_liste_field_titre($langs->trans('RefCdeClient'),'liste.php','c.ref_client','','&socidp='.$socidp,'width="15%"',$sortfield);
|
||||||
print_liste_field_titre($langs->trans("Status"),"liste.php","c.fk_statut","","&socidp=$socidp",'width="10%" align="center"',$sortfield);
|
print_liste_field_titre($langs->trans('Date'),'liste.php','c.date_commande','','&socidp='.$socidp, 'width="20%" align="right" colspan="2"',$sortfield);
|
||||||
print "</tr>\n";
|
print_liste_field_titre($langs->trans('Status'),'liste.php','c.fk_statut','','&socidp='.$socidp,'width="10%" align="center"',$sortfield);
|
||||||
|
print '</tr>';
|
||||||
|
// Lignes des champs de filtre
|
||||||
|
print '<form method="get" action="liste.php">';
|
||||||
|
print '<tr class="liste_titre">';
|
||||||
|
print '<td class="liste_titre" valign="right">';
|
||||||
|
print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
|
||||||
|
print '</td><td class="liste_titre" align="left">';
|
||||||
|
print '<input class="flat" type="text" name="snom" value="'.$snom.'">';
|
||||||
|
print '</td><td class="liste_titre" align="left">';
|
||||||
|
print '<input class="flat" type="text" size="10" name="sref_client" value="'.$sref_client.'">';
|
||||||
|
print '</td><td class="liste_titre"> ';
|
||||||
|
print '</td><td class="liste_titre"> ';
|
||||||
|
print '</td><td align="right" class="liste_titre">';
|
||||||
|
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans('Search').'">';
|
||||||
|
print '</td></tr>';
|
||||||
|
print '</form>';
|
||||||
$var=True;
|
$var=True;
|
||||||
|
|
||||||
$generic_commande = new Commande($db);
|
$generic_commande = new Commande($db);
|
||||||
|
|
||||||
while ($i < min($num,$limit))
|
while ($i < min($num,$limit))
|
||||||
{
|
{
|
||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print "<tr $bc[$var]>";
|
print '<tr '.$bc[$var].'>';
|
||||||
print "<td><a href=\"fiche.php?id=$objp->rowid\">".img_object($langs->trans("ShowOrder"),"order")." ".$objp->ref."</a></td>\n";
|
print '<td><a href="fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowOrder'),'order').' '.$objp->ref.'</a></td>';
|
||||||
print "<td><a href=\"../comm/fiche.php?socid=$objp->idp\">".img_object($langs->trans("ShowCompany"),"company")." ".$objp->nom."</a></td>\n";
|
print '<td><a href="../comm/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
|
||||||
|
print '<td>'.$objp->ref_client.'</td>';
|
||||||
$now = time();
|
$now = time();
|
||||||
$lim = 3600 * 24 * 15 ;
|
$lim = 3600 * 24 * 15 ;
|
||||||
|
|
||||||
if ( ($now - $objp->date_commande) > $lim && $objp->statutid == 1 )
|
if ( ($now - $objp->date_commande) > $lim && $objp->statutid == 1 )
|
||||||
{
|
{
|
||||||
print "<td><b> > 15 jours</b></td>";
|
print '<td><b> > 15 jours</b></td>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "<td> </td>";
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
|
print '<td align="right">';
|
||||||
print "<td align=\"right\">";
|
$y = strftime('%Y',$objp->date_commande);
|
||||||
$y = strftime("%Y",$objp->date_commande);
|
$m = strftime('%m',$objp->date_commande);
|
||||||
$m = strftime("%m",$objp->date_commande);
|
print strftime('%d',$objp->date_commande);
|
||||||
|
print ' <a href="liste.php?year='.$y.'&month='.$m.'">';
|
||||||
print strftime("%d",$objp->date_commande)."\n";
|
print strftime('%B',$objp->date_commande).'</a>';
|
||||||
print " <a href=\"liste.php?year=$y&month=$m\">";
|
print ' <a href="liste.php?year='.$y.'">';
|
||||||
print strftime("%B",$objp->date_commande)."</a>\n";
|
print strftime('%Y',$objp->date_commande).'</a></td>';
|
||||||
print " <a href=\"liste.php?year=$y\">";
|
|
||||||
print strftime("%Y",$objp->date_commande)."</a></td>\n";
|
|
||||||
|
|
||||||
print '<td align="center">'.$generic_commande->status_label_short[$objp->fk_statut].'</td>';
|
print '<td align="center">'.$generic_commande->status_label_short[$objp->fk_statut].'</td>';
|
||||||
print "</tr>\n";
|
print '</tr>';
|
||||||
|
|
||||||
$total = $total + $objp->price;
|
$total = $total + $objp->price;
|
||||||
$subtotal = $subtotal + $objp->price;
|
$subtotal = $subtotal + $objp->price;
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
print '</table>';
|
||||||
print "</table>";
|
|
||||||
$db->free($resql);
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1833,3 +1833,5 @@ insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (2
|
|||||||
|
|
||||||
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (80, 'PROJECTLEADER', 'projet', 'Chef de Projet', 1);
|
insert into llx_c_type_contact(rowid, code, element, libelle, active ) values (80, 'PROJECTLEADER', 'projet', 'Chef de Projet', 1);
|
||||||
|
|
||||||
|
alter table llx_commande add ref_client varchar(30);
|
||||||
|
alter table llx_facture add ref_client varchar(30);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user