New: early development of multi-company module

This commit is contained in:
Regis Houssin 2009-04-29 18:32:22 +00:00
parent 7a01e2098b
commit 48894fadeb
5 changed files with 135 additions and 105 deletions

View File

@ -246,8 +246,13 @@ class Commande extends CommonObject
$num = $this->ref; $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 = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE rowid = $this->id AND fk_statut = 0"; $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); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -343,8 +348,9 @@ class Commande extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET fk_statut = 0"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE rowid = ".$this->id; $sql.= " SET fk_statut = 0";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG); dol_syslog("Commande::set_draft sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -432,8 +438,10 @@ class Commande extends CommonObject
{ {
$this->db->begin(); $this->db->begin();
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET fk_statut = -1'; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql .= " WHERE rowid = $this->id AND fk_statut = 1 ;"; $sql.= " SET fk_statut = -1";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND fk_statut = 1";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
@ -505,20 +513,24 @@ class Commande extends CommonObject
$this->db->begin(); $this->db->begin();
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande ('; $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.= " 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.= ", model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison, fk_adresse_livraison";
$sql.= ' remise_absolue, remise_percent)'; $sql.= ", remise_absolue, remise_percent";
$sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.', '.$this->projetid.','; $sql.= ", entity";
$sql.= ' '.$this->db->idate($this->date_commande).','; $sql.= ")";
$sql.= ' '.($this->source>=0 && $this->source != '' ?$this->source:'null').', '; $sql.= " VALUES ('(PROV)',".$this->socid.", ".$this->db->idate(gmmktime()).", ".$user->id.", ".$this->projetid;
$sql.= " '".addslashes($this->note)."', "; $sql.= ", ".$this->db->idate($this->date_commande);
$sql.= " '".addslashes($this->note_public)."', "; $sql.= ", ".($this->source>=0 && $this->source != '' ?$this->source:'null');
$sql.= " '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."',"; $sql.= ", '".addslashes($this->note)."'";
$sql.= " ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null").","; $sql.= ", '".addslashes($this->note_public)."'";
$sql.= " ".($this->adresse_livraison_id>0?$this->adresse_livraison_id:'NULL').","; $sql.= ", '".addslashes($this->ref_client)."', '".$this->modelpdf."', '".$this->cond_reglement_id."', '".$this->mode_reglement_id."'";
$sql.= " ".($this->remise_absolue>0?$this->remise_absolue:'NULL').","; $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null");
$sql.= " '".$this->remise_percent."')"; $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); dol_syslog("Commande::create sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
@ -879,6 +891,8 @@ class Commande extends CommonObject
*/ */
function fetch($id,$ref='') function fetch($id,$ref='')
{ {
global $conf;
// Check parameters // Check parameters
if (empty($id) && empty($ref)) return -1; 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.'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.'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)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'co_pr as cp ON (cp.fk_commande = c.rowid)';
if ($ref) $sql.= " WHERE c.ref='".$ref."'"; $sql.= " WHERE c.entity = ".$conf->entity;
else $sql.= " WHERE c.rowid=".$id; if ($ref) $sql.= " AND c.ref='".$ref."'";
else $sql.= " AND c.rowid=".$id;
dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql) ; $result = $this->db->query($sql) ;
@ -1296,7 +1311,7 @@ class Commande extends CommonObject
$sql = "SELECT fk_product, qty"; $sql = "SELECT fk_product, qty";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet"; $sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
$sql.= " WHERE rowid = '$idligne'"; $sql.= " WHERE rowid = ".$idligne;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
@ -1493,24 +1508,22 @@ class Commande extends CommonObject
*/ */
function liste_array ($brouillon=0, $user='') function liste_array ($brouillon=0, $user='')
{ {
global $conf;
$ga = array(); $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) if ($brouillon)
{ {
$sql .= " WHERE fk_statut = 0"; $sql.= " AND fk_statut = 0";
if ($user) if ($user) $sql.= " AND fk_user_author".$user;
{
$sql .= " AND fk_user_author".$user;
}
} }
else else
{ {
if ($user) if ($user) $sql.= " AND fk_user_author".$user;
{
$sql .= " WHERE fk_user_author".$user;
}
} }
$sql .= " ORDER BY date_commande DESC"; $sql .= " ORDER BY date_commande DESC";
@ -1780,19 +1793,19 @@ class Commande extends CommonObject
$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++;
@ -1862,15 +1875,13 @@ class Commande extends CommonObject
$sql = "SELECT c.rowid, c.date_creation as datec"; $sql = "SELECT c.rowid, c.date_creation as datec";
$sql.= " FROM ".MAIN_DB_PREFIX."commande as c"; $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$user->societe_id) 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.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc";
$sql.= " WHERE sc.fk_user = " .$user->id; $sql.= " WHERE sc.fk_user = " .$user->id;
$clause = " AND"; $clause = " AND";
} }
$sql.= $clause." c.fk_soc = s.rowid"; $sql.= $clause." c.entity = ".$conf->entity;
$sql.= " AND s.entity = ".$conf->entity;
$sql.= " AND (c.fk_statut BETWEEN 1 AND 2 or (c.fk_statut = 3 AND c.facture = 0))"; $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; if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id;
@ -2074,13 +2085,19 @@ class Commande extends CommonObject
*/ */
function initAsSpecimen() function initAsSpecimen()
{ {
global $user,$langs; global $user,$langs,$conf;
dol_syslog("Commande::initAsSpecimen"); dol_syslog("Commande::initAsSpecimen");
// Charge tableau des id de societe socids // Charge tableau des id de societe socids
$socids = array(); $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); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -2097,7 +2114,12 @@ class Commande extends CommonObject
// Charge tableau des produits prodids // Charge tableau des produits prodids
$prodids = array(); $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); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -2169,7 +2191,7 @@ class Commande extends CommonObject
$sql.= " WHERE sc.fk_user = " .$user->id; $sql.= " WHERE sc.fk_user = " .$user->id;
$clause = "AND"; $clause = "AND";
} }
$sql.= " ".$clause." s.entity = ".$conf->entity; $sql.= " ".$clause." co.entity = ".$conf->entity;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2006 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* 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
@ -21,22 +21,22 @@
/** /**
\file htdocs/includes/modules/commande/mod_commande_marbre.php \file htdocs/includes/modules/commande/mod_commande_marbre.php
\ingroup commande \ingroup commande
\brief Fichier contenant la classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de commande Marbre \brief Fichier contenant la classe du modele de num<EFBFBD>rotation de reference de commande Marbre
\version $Id$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php"); require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php");
/** \class mod_commande_marbre /** \class mod_commande_marbre
\brief Classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de commande Marbre \brief Classe du modele de numerotation de reference de commande Marbre
*/ */
class mod_commande_marbre extends ModeleNumRefCommandes class mod_commande_marbre extends ModeleNumRefCommandes
{ {
var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $version='dolibarr'; // 'development', 'experimental', 'dolibarr'
var $prefix='CO'; var $prefix='CO';
var $error=''; var $error='';
var $nom='Marbre'; var $nom='Marbre';
/** \brief Renvoi la description du modele de numerotation /** \brief Renvoi la description du modele de numerotation
@ -64,22 +64,26 @@ class mod_commande_marbre extends ModeleNumRefCommandes
*/ */
function canBeActivated() function canBeActivated()
{ {
$coyymm=''; global $conf;
$sql = "SELECT MAX(ref)"; $coyymm='';
$sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like '".$this->prefix."%'"; $sql = "SELECT MAX(ref)";
$resql=$db->query($sql); $sql.= " FROM ".MAIN_DB_PREFIX."commande";
if ($resql) $sql.= " WHERE ref like '".$this->prefix."%'";
{ $sql.= " AND entity = ".$conf->entity;
$row = $db->fetch_row($resql);
if ($row) $coyymm = substr($row[0],0,6); $resql=$db->query($sql);
} if ($resql)
if ($coyymm && ! eregi($this->prefix.'[0-9][0-9][0-9][0-9]',$coyymm)) {
{ $row = $db->fetch_row($resql);
$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.'; if ($row) $coyymm = substr($row[0],0,6);
return false; }
} 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; return true;
} }
@ -93,32 +97,33 @@ class mod_commande_marbre extends ModeleNumRefCommandes
{ {
global $db; global $db;
// D'abord on recupere la valeur max (reponse immediate car champ indexe) // D'abord on recupere la valeur max (reponse immediate car champ indexe)
$posindice=8; $posindice=8;
$sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max"; $sql = "SELECT MAX(0+SUBSTRING(ref,".$posindice.")) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."commande"; $sql.= " FROM ".MAIN_DB_PREFIX."commande";
$sql.= " WHERE ref like '".$this->prefix."%'"; $sql.= " WHERE ref like '".$this->prefix."%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
if ($obj) $max = $obj->max; if ($obj) $max = $obj->max;
else $max=0; else $max=0;
} }
else else
{ {
dol_syslog("mod_commande_marbre::getNextValue sql=".$sql); dol_syslog("mod_commande_marbre::getNextValue sql=".$sql);
return -1; return -1;
} }
//$date=time(); //$date=time();
$date=$commande->date; $date=$commande->date;
$yymm = strftime("%y%m",$date); $yymm = strftime("%y%m",$date);
$num = sprintf("%04s",$max+1); $num = sprintf("%04s",$max+1);
dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num); dol_syslog("mod_commande_marbre::getNextValue return ".$this->prefix.$yymm."-".$num);
return $this->prefix.$yymm."-".$num; return $this->prefix.$yymm."-".$num;
} }

View File

@ -1,8 +1,8 @@
<?php <?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr> * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* *
* 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
@ -23,7 +23,7 @@
/** /**
\file htdocs/includes/modules/commande/mod_commande_saphir.php \file htdocs/includes/modules/commande/mod_commande_saphir.php
\ingroup commande \ingroup commande
\brief Fichier contenant la classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de commande Saphir \brief Fichier contenant la classe du modele de numerotation de reference de commande Saphir
\version $Id$ \version $Id$
*/ */
@ -32,7 +32,7 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php
/** /**
\class mod_commande_saphir \class mod_commande_saphir
\brief Classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de commande Saphir \brief Classe du modele de numerotation de reference de commande Saphir
*/ */
class mod_commande_saphir extends ModeleNumRefCommandes class mod_commande_saphir extends ModeleNumRefCommandes
{ {
@ -41,7 +41,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes
var $nom = 'Saphir'; var $nom = 'Saphir';
/** \brief Renvoi la description du modele de num<EFBFBD>rotation /** \brief Renvoi la description du modele de numerotation
* \return string Texte descripif * \return string Texte descripif
*/ */
function info() function info()
@ -78,7 +78,7 @@ class mod_commande_saphir extends ModeleNumRefCommandes
return $texte; return $texte;
} }
/** \brief Renvoi un exemple de num<EFBFBD>rotation /** \brief Renvoi un exemple de numerotation
* \return string Example * \return string Example
*/ */
function getExample() function getExample()

View File

@ -56,11 +56,14 @@ class ModelePDFCommandes extends FPDF
*/ */
function liste_modeles($db) function liste_modeles($db)
{ {
global $conf;
$type='order'; $type='order';
$liste=array(); $liste=array();
$sql ="SELECT nom as id, nom as lib"; $sql = "SELECT nom as id, nom as lib";
$sql.=" FROM ".MAIN_DB_PREFIX."document_model"; $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
$sql.=" WHERE type = '".$type."'"; $sql.= " WHERE type = '".$type."'";
$sql.= " AND entity = ".$conf->entity;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)

View File

@ -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.= ", ".$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.= ", 0, 0,".$this->db->idate($this->datep).", ".$this->db->idate(mktime()).", '".$this->ref;
$sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null"); $sql.= ", ".($user->id > 0 ? "'".$user->id."'":"null");
$sql.= ", '".addslashes($this->note); $sql.= ", '".addslashes($this->note)."'";
$sql.= ", '".addslashes($this->note_public)."',"; $sql.= ", '".addslashes($this->note_public)."'";
$sql.= ", '".$this->modelpdf."',".$this->db->idate($this->fin_validite); $sql.= ", '".$this->modelpdf."',".$this->db->idate($this->fin_validite)."'";
$sql.= ", ".$this->cond_reglement_id.", ".$this->mode_reglement_id; $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.= ", ".($this->date_livraison!=''?$this->db->idate($this->date_livraison):'null');
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ")"; $sql.= ")";
@ -995,7 +995,7 @@ class Propal extends CommonObject
} }
/** /**
* \brief D<EFBFBD>finit une adresse de livraison * \brief Definit une adresse de livraison
* \param user Objet utilisateur qui modifie * \param user Objet utilisateur qui modifie
* \param adresse_livraison Adresse de livraison * \param adresse_livraison Adresse de livraison
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok