diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 3344bf50eb1..20c98fa749e 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -246,8 +246,13 @@ class Commande extends CommonObject $num = $this->ref; } - $sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='$num', fk_statut = 1, date_valid=".$this->db->idate(mktime()).", fk_user_valid=$user->id"; - $sql .= " WHERE rowid = $this->id AND fk_statut = 0"; + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET ref = '".$num."'"; + $sql.= ", fk_statut = 1"; + $sql.= ", date_valid=".$this->db->idate(mktime()); + $sql.= ", fk_user_valid = ".$user->id; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut = 0"; $resql=$this->db->query($sql); if ($resql) @@ -343,8 +348,9 @@ class Commande extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0"; - $sql .= " WHERE rowid = ".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = 0"; + $sql.= " WHERE rowid = ".$this->id; dol_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) @@ -432,8 +438,10 @@ class Commande extends CommonObject { $this->db->begin(); - $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1'; - $sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;"; + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; + $sql.= " SET fk_statut = -1"; + $sql.= " WHERE rowid = ".$this->id; + $sql.= " AND fk_statut = 1"; if ($this->db->query($sql) ) { @@ -505,20 +513,24 @@ class Commande extends CommonObject $this->db->begin(); - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande ('; - $sql.= ' ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client,'; - $sql.= ' model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison, fk_adresse_livraison,'; - $sql.= ' remise_absolue, remise_percent)'; - $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.', '.$this->projetid.','; - $sql.= ' '.$this->db->idate($this->date_commande).','; - $sql.= ' '.($this->source>=0 && $this->source != '' ?$this->source:'null').', '; - $sql.= " '".addslashes($this->note)."', "; - $sql.= " '".addslashes($this->note_public)."', "; - $sql.= " '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."',"; - $sql.= " ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null").","; - $sql.= " ".($this->adresse_livraison_id>0?$this->adresse_livraison_id:'NULL').","; - $sql.= " ".($this->remise_absolue>0?$this->remise_absolue:'NULL').","; - $sql.= " '".$this->remise_percent."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande ("; + $sql.= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, note_public, ref_client"; + $sql.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison, fk_adresse_livraison"; + $sql.= ", remise_absolue, remise_percent"; + $sql.= ", entity"; + $sql.= ")"; + $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->projetid; + $sql.= ", ".$this->db->idate($this->date_commande); + $sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null'); + $sql.= ", '".addslashes($this->note)."'"; + $sql.= ", '".addslashes($this->note_public)."'"; + $sql.= ", '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."'"; + $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); + $sql.= ", ".($this->adresse_livraison_id>0?$this->adresse_livraison_id:'NULL'); + $sql.= ", ".($this->remise_absolue>0?$this->remise_absolue:'NULL'); + $sql.= ", '".$this->remise_percent."'"; + $sql.= ", ".$conf->entity; + $sql.= ")"; dol_syslog("Commande::create sql=".$sql); $resql=$this->db->query($sql); @@ -879,6 +891,8 @@ class Commande extends CommonObject */ function fetch($id,$ref='') { + global $conf; + // Check parameters if (empty($id) && empty($ref)) return -1; @@ -895,8 +909,9 @@ class Commande extends CommonObject $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON (c.fk_cond_reglement = cr.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON (c.fk_mode_reglement = p.id)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_pr as cp ON (cp.fk_commande = c.rowid)'; - if ($ref) $sql.= " WHERE c.ref='".$ref."'"; - else $sql.= " WHERE c.rowid=".$id; + $sql.= " WHERE c.entity = ".$conf->entity; + if ($ref) $sql.= " AND c.ref='".$ref."'"; + else $sql.= " AND c.rowid=".$id; dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql) ; @@ -1296,7 +1311,7 @@ class Commande extends CommonObject $sql = "SELECT fk_product, qty"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE rowid = '$idligne'"; + $sql.= " WHERE rowid = ".$idligne; $result = $this->db->query($sql); if ($result) @@ -1493,24 +1508,22 @@ class Commande extends CommonObject */ function liste_array ($brouillon=0, $user='') { + global $conf; + $ga = array(); - $sql = "SELECT rowid, ref FROM ".MAIN_DB_PREFIX."commande"; + $sql = "SELECT rowid, ref"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE entity = ".$conf->entity; if ($brouillon) { - $sql .= " WHERE fk_statut = 0"; - if ($user) - { - $sql .= " AND fk_user_author".$user; - } + $sql.= " AND fk_statut = 0"; + if ($user) $sql.= " AND fk_user_author".$user; } else { - if ($user) - { - $sql .= " WHERE fk_user_author".$user; - } + if ($user) $sql.= " AND fk_user_author".$user; } $sql .= " ORDER BY date_commande DESC"; @@ -1780,19 +1793,19 @@ class Commande extends CommonObject $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) ) { $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) ) { $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) ) { $err++; @@ -1862,15 +1875,13 @@ class Commande extends CommonObject $sql = "SELECT c.rowid, c.date_creation as datec"; $sql.= " FROM ".MAIN_DB_PREFIX."commande as c"; - $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc"; $sql.= " WHERE sc.fk_user = " .$user->id; $clause = " AND"; } - $sql.= $clause." c.fk_soc = s.rowid"; - $sql.= " AND s.entity = ".$conf->entity; + $sql.= $clause." c.entity = ".$conf->entity; $sql.= " AND (c.fk_statut BETWEEN 1 AND 2 or (c.fk_statut = 3 AND c.facture = 0))"; if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; @@ -2074,13 +2085,19 @@ class Commande extends CommonObject */ function initAsSpecimen() { - global $user,$langs; + global $user,$langs,$conf; dol_syslog("Commande::initAsSpecimen"); // Charge tableau des id de societe socids $socids = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10"; + + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe"; + $sql.= " WHERE client = 1"; + $sql.= " AND entity = ".$conf->entity; + $sql.= " LIMIT 10"; + $resql = $this->db->query($sql); if ($resql) { @@ -2097,7 +2114,12 @@ class Commande extends CommonObject // Charge tableau des produits prodids $prodids = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1"; + + $sql = "SELECT rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."product"; + $sql.= " WHERE envente = 1"; + $sql.= " AND entity = ".$conf->entity; + $resql = $this->db->query($sql); if ($resql) { @@ -2169,7 +2191,7 @@ class Commande extends CommonObject $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." s.entity = ".$conf->entity; + $sql.= " ".$clause." co.entity = ".$conf->entity; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/includes/modules/commande/mod_commande_marbre.php b/htdocs/includes/modules/commande/mod_commande_marbre.php index a4db4818393..25c1166390d 100644 --- a/htdocs/includes/modules/commande/mod_commande_marbre.php +++ b/htdocs/includes/modules/commande/mod_commande_marbre.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2006 Regis Houssin + * Copyright (C) 2005-2009 Regis Houssin * * 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 @@ -21,22 +21,22 @@ /** \file htdocs/includes/modules/commande/mod_commande_marbre.php \ingroup commande - \brief Fichier contenant la classe du mod�le de num�rotation de r�f�rence de commande Marbre + \brief Fichier contenant la classe du modele de num�rotation de reference de commande Marbre \version $Id$ */ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); /** \class mod_commande_marbre - \brief Classe du mod�le de num�rotation de r�f�rence de commande Marbre + \brief Classe du modele de numerotation de reference de commande Marbre */ class mod_commande_marbre extends ModeleNumRefCommandes { var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $prefix='CO'; - var $error=''; - var $nom='Marbre'; + var $error=''; + var $nom='Marbre'; /** \brief Renvoi la description du modele de numerotation @@ -64,22 +64,26 @@ class mod_commande_marbre extends ModeleNumRefCommandes */ function canBeActivated() { - $coyymm=''; - - $sql = "SELECT MAX(ref)"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande"; - $sql.= " WHERE ref like '".$this->prefix."%'"; - $resql=$db->query($sql); - if ($resql) - { - $row = $db->fetch_row($resql); - if ($row) $coyymm = substr($row[0],0,6); - } - if ($coyymm && ! eregi($this->prefix.'[0-9][0-9][0-9][0-9]',$coyymm)) - { - $this->error='Une commande commeneant par $coyymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.'; - return false; - } + global $conf; + + $coyymm=''; + + $sql = "SELECT MAX(ref)"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande"; + $sql.= " WHERE ref like '".$this->prefix."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $row = $db->fetch_row($resql); + if ($row) $coyymm = substr($row[0],0,6); + } + if ($coyymm && ! eregi($this->prefix.'[0-9][0-9][0-9][0-9]',$coyymm)) + { + $this->error='Une commande commencant par $coyymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.'; + return false; + } return true; } @@ -92,33 +96,34 @@ class mod_commande_marbre extends ModeleNumRefCommandes function getNextValue($objsoc,$commande) { global $db; - - // D'abord on recupere la valeur max (reponse immediate car champ indexe) - $posindice=8; - $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; + + // D'abord on recupere la valeur max (reponse immediate car champ indexe) + $posindice=8; + $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."commande"; - $sql.= " WHERE ref like '".$this->prefix."%'"; - - $resql=$db->query($sql); - if ($resql) - { - $obj = $db->fetch_object($resql); - if ($obj) $max = $obj->max; - else $max=0; - } - else - { - dol_syslog("mod_commande_marbre::getNextValue sql=".$sql); - return -1; - } - - //$date=time(); - $date=$commande->date; - $yymm = strftime("%y%m",$date); - $num = sprintf("%04s",$max+1); + $sql.= " WHERE ref like '".$this->prefix."%'"; + $sql.= " AND entity = ".$conf->entity; + + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $max = $obj->max; + else $max=0; + } + else + { + dol_syslog("mod_commande_marbre::getNextValue sql=".$sql); + return -1; + } + + //$date=time(); + $date=$commande->date; + $yymm = strftime("%y%m",$date); + $num = sprintf("%04s",$max+1); - dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num); - return $this->prefix.$yymm."-".$num; + dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num); + return $this->prefix.$yymm."-".$num; } diff --git a/htdocs/includes/modules/commande/mod_commande_saphir.php b/htdocs/includes/modules/commande/mod_commande_saphir.php index 85bd41b7a32..4ce573f98b8 100644 --- a/htdocs/includes/modules/commande/mod_commande_saphir.php +++ b/htdocs/includes/modules/commande/mod_commande_saphir.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2007 Laurent Destailleur - * Copyright (C) 2005-2007 Regis Houssin - * Copyright (C) 2008 Raphael Bertrand (Resultic) +/* Copyright (C) 2003-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) * * 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 @@ -23,7 +23,7 @@ /** \file htdocs/includes/modules/commande/mod_commande_saphir.php \ingroup commande - \brief Fichier contenant la classe du mod�le de num�rotation de r�f�rence de commande Saphir + \brief Fichier contenant la classe du modele de numerotation de reference de commande Saphir \version $Id$ */ @@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php /** \class mod_commande_saphir - \brief Classe du mod�le de num�rotation de r�f�rence de commande Saphir + \brief Classe du modele de numerotation de reference de commande Saphir */ class mod_commande_saphir extends ModeleNumRefCommandes { @@ -41,7 +41,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes var $nom = 'Saphir'; - /** \brief Renvoi la description du modele de num�rotation + /** \brief Renvoi la description du modele de numerotation * \return string Texte descripif */ function info() @@ -78,7 +78,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes return $texte; } - /** \brief Renvoi un exemple de num�rotation + /** \brief Renvoi un exemple de numerotation * \return string Example */ function getExample() diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index c0f04b5860e..ade191d4a22 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -56,11 +56,14 @@ class ModelePDFCommandes extends FPDF */ function liste_modeles($db) { + global $conf; + $type='order'; $liste=array(); - $sql ="SELECT nom as id, nom as lib"; - $sql.=" FROM ".MAIN_DB_PREFIX."document_model"; - $sql.=" WHERE type = '".$type."'"; + $sql = "SELECT nom as id, nom as lib"; + $sql.= " FROM ".MAIN_DB_PREFIX."document_model"; + $sql.= " WHERE type = '".$type."'"; + $sql.= " AND entity = ".$conf->entity; $resql = $db->query($sql); if ($resql) diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 05ec38e762b..a82e0564209 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -538,11 +538,11 @@ class Propal extends CommonObject $sql.= ", ".$this->remise.", ".($this->remise_percent?$this->remise_percent:'null').", ".($this->remise_absolue?$this->remise_absolue:'null'); $sql.= ", 0, 0,".$this->db->idate($this->datep).", ".$this->db->idate(mktime()).", '".$this->ref; $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null"); - $sql.= ", '".addslashes($this->note); - $sql.= ", '".addslashes($this->note_public)."',"; - $sql.= ", '".$this->modelpdf."',".$this->db->idate($this->fin_validite); + $sql.= ", '".addslashes($this->note)."'"; + $sql.= ", '".addslashes($this->note_public)."'"; + $sql.= ", '".$this->modelpdf."',".$this->db->idate($this->fin_validite)."'"; $sql.= ", ".$this->cond_reglement_id.", ".$this->mode_reglement_id; - $sql.= ", '".addslashes($this->ref_client); + $sql.= ", '".addslashes($this->ref_client)."'"; $sql.= ", ".($this->date_livraison!=''?$this->db->idate($this->date_livraison):'null'); $sql.= ", ".$conf->entity; $sql.= ")"; @@ -995,7 +995,7 @@ class Propal extends CommonObject } /** - * \brief D�finit une adresse de livraison + * \brief Definit une adresse de livraison * \param user Objet utilisateur qui modifie * \param adresse_livraison Adresse de livraison * \return int <0 si ko, >0 si ok