New: early development of multi-company module

This commit is contained in:
Regis Houssin 2009-04-29 16:54:51 +00:00
parent 8a1d511da4
commit e89044da42
8 changed files with 170 additions and 131 deletions

View File

@ -21,7 +21,7 @@
/** /**
\file htdocs/includes/modules/propale/mod_propale_marbre.php \file htdocs/includes/modules/propale/mod_propale_marbre.php
\ingroup propale \ingroup propale
\brief Fichier contenant la classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de propale Marbre \brief Fichier contenant la classe du modele de numerotation de reference de propale Marbre
\version $Id$ \version $Id$
*/ */
@ -29,7 +29,7 @@ require_once(DOL_DOCUMENT_ROOT ."/includes/modules/propale/modules_propale.php")
/** \class mod_propale_marbre /** \class mod_propale_marbre
\brief Classe du mod<EFBFBD>le de num<EFBFBD>rotation de r<EFBFBD>f<EFBFBD>rence de propale Marbre \brief Classe du modele de numerotation de reference de propale Marbre
*/ */
class mod_propale_marbre extends ModeleNumRefPropales class mod_propale_marbre extends ModeleNumRefPropales
@ -65,10 +65,14 @@ class mod_propale_marbre extends ModeleNumRefPropales
*/ */
function canBeActivated() function canBeActivated()
{ {
global $conf;
$pryymm=''; $pryymm='';
$sql = "SELECT MAX(ref)"; $sql = "SELECT MAX(ref)";
$sql.= " FROM ".MAIN_DB_PREFIX."propal"; $sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE entity = ".$conf->entity;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
@ -81,7 +85,7 @@ class mod_propale_marbre extends ModeleNumRefPropales
} }
else else
{ {
$this->error='Une propal commeneant par $pryymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.'; $this->error='Une propal commencant par $pryymm existe en base et est incompatible avec cette numerotation. Supprimer la ou renommer la pour activer ce module.';
return false; return false;
} }
} }
@ -93,13 +97,14 @@ class mod_propale_marbre extends ModeleNumRefPropales
*/ */
function getNextValue($objsoc,$propal) function getNextValue($objsoc,$propal)
{ {
global $db; global $db,$conf;
// 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."propal"; $sql.= " FROM ".MAIN_DB_PREFIX."propal";
$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)

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-2007 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

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* 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
@ -53,31 +54,34 @@ class ModelePDFPropales extends FPDF
*/ */
function liste_modeles($db) function liste_modeles($db)
{ {
$type='propal'; global $conf;
$liste=array();
$sql ="SELECT nom as id, nom as lib";
$sql.=" FROM ".MAIN_DB_PREFIX."document_model";
$sql.=" WHERE type = '".$type."'";
dol_syslog("modules_propale::liste_modeles sql=".$sql, LOG_DEBUG); $type='propal';
$resql = $db->query($sql); $liste=array();
if ($resql) $sql = "SELECT nom as id, nom as lib";
$sql.= " FROM ".MAIN_DB_PREFIX."document_model";
$sql.= " WHERE type = '".$type."'";
$sql.= " AND entity = ".$cont->entity;
dol_syslog("modules_propale::liste_modeles sql=".$sql, LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
while ($i < $num)
{ {
$num = $db->num_rows($resql); $row = $db->fetch_row($resql);
$i = 0; $liste[$row[0]]=$row[1];
while ($i < $num) $i++;
{
$row = $db->fetch_row($resql);
$liste[$row[0]]=$row[1];
$i++;
}
} }
else }
{ else
$this->error=$db->error(); {
return -1; $this->error=$db->error();
} return -1;
return $liste; }
return $liste;
} }
} }
@ -184,12 +188,12 @@ function propale_pdf_create($db, $id, $modele, $outputlangs)
// Si model pas encore bon // Si model pas encore bon
if (! $modelisok) if (! $modelisok)
{ {
$liste=array(); $liste=array();
$model=new ModelePDFPropales(); $model=new ModelePDFPropales();
$liste=$model->liste_modeles($db); $liste=$model->liste_modeles($db);
$modele=key($liste); // Renvoie premiere valeur de clé trouvé dans le tableau $modele=key($liste); // Renvoie premiere valeur de clé trouvé dans le tableau
$file = "pdf_propale_".$modele.".modules.php"; $file = "pdf_propale_".$modele.".modules.php";
if (file_exists($dir.$file)) $modelisok=1; if (file_exists($dir.$file)) $modelisok=1;
} }

View File

@ -290,6 +290,8 @@ function array2table($data,$tableMarkup=1,$tableoptions='',$troptions='',$tdopti
*/ */
function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date='') function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date='')
{ {
global $conf;
// Clean parameters // Clean parameters
if ($date == '') $date=mktime(); // We use local year and month of PHP server to search numbers if ($date == '') $date=mktime(); // We use local year and month of PHP server to search numbers
// but we should use local year and month of user // but we should use local year and month of user
@ -394,6 +396,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$valueforccc='',$date=
$sql.= " FROM ".MAIN_DB_PREFIX.$table; $sql.= " FROM ".MAIN_DB_PREFIX.$table;
// $sql.= " WHERE ".$field." not like '(%'"; // $sql.= " WHERE ".$field." not like '(%'";
$sql.= " WHERE ".$field." like '".$maskLike."'"; $sql.= " WHERE ".$field." like '".$maskLike."'";
$sql.= " AND entity = ".$conf->entity;
if ($where) $sql.=$where; if ($where) $sql.=$where;
if ($sqlwhere) $sql.=' AND '.$sqlwhere; if ($sqlwhere) $sql.=' AND '.$sqlwhere;
@ -664,12 +667,12 @@ function numero_semaine($time)
/* /*
* Norme ISO-8601: * Norme ISO-8601:
* - La semaine 1 de toute ann<EFBFBD>e est celle qui contient le 4 janvier ou que la semaine 1 de toute ann<EFBFBD>e est celle qui contient le 1er jeudi de janvier. * - La semaine 1 de toute annee est celle qui contient le 4 janvier ou que la semaine 1 de toute annee est celle qui contient le 1er jeudi de janvier.
* - La majorit<EFBFBD> des ann<EFBFBD>es ont 52 semaines mais les ann<EFBFBD>es qui commence un jeudi et les ann<EFBFBD>es bissextiles commen<EFBFBD>ant un mercredi en poss<EFBFBD>de 53. * - La majorite des annees ont 52 semaines mais les annees qui commence un jeudi et les annees bissextiles commencant un mercredi en possede 53.
* - Le 1er jour de la semaine est le Lundi * - Le 1er jour de la semaine est le Lundi
*/ */
// D<EFBFBD>finition du Jeudi de la semaine // Definition du Jeudi de la semaine
if (date("w",mktime(12,0,0,$mois,$jour,$annee))==0) // Dimanche if (date("w",mktime(12,0,0,$mois,$jour,$annee))==0) // Dimanche
$jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-3*24*60*60; $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee)-3*24*60*60;
else if (date("w",mktime(12,0,0,$mois,$jour,$annee))<4) // du Lundi au Mercredi else if (date("w",mktime(12,0,0,$mois,$jour,$annee))<4) // du Lundi au Mercredi
@ -679,7 +682,7 @@ function numero_semaine($time)
else // Jeudi else // Jeudi
$jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee); $jeudiSemaine = mktime(12,0,0,$mois,$jour,$annee);
// D<EFBFBD>finition du premier Jeudi de l'ann<6E>e // Definition du premier Jeudi de l'annee
if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==0) // Dimanche if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==0) // Dimanche
{ {
$premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+4*24*60*60; $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine))+4*24*60*60;
@ -697,7 +700,7 @@ function numero_semaine($time)
$premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine)); $premierJeudiAnnee = mktime(12,0,0,1,1,date("Y",$jeudiSemaine));
} }
// D<>finition du num<EFBFBD>ro de semaine: nb de jours entre "premier Jeudi de l'ann<6E>e" et "Jeudi de la semaine"; // D<>finition du numero de semaine: nb de jours entre "premier Jeudi de l'annee" et "Jeudi de la semaine";
$numeroSemaine = ( $numeroSemaine = (
( (
date("z",mktime(12,0,0,date("m",$jeudiSemaine),date("d",$jeudiSemaine),date("Y",$jeudiSemaine))) date("z",mktime(12,0,0,date("m",$jeudiSemaine),date("d",$jeudiSemaine),date("Y",$jeudiSemaine)))
@ -709,7 +712,7 @@ function numero_semaine($time)
// Cas particulier de la semaine 53 // Cas particulier de la semaine 53
if ($numeroSemaine==53) if ($numeroSemaine==53)
{ {
// Les ann<EFBFBD>es qui commence un Jeudi et les ann<6E>es bissextiles commen<65>ant un Mercredi en poss<73>de 53 // Les annees qui commence un Jeudi et les ann<6E>es bissextiles commencant un Mercredi en possede 53
if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==4 || (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==3 && date("z",mktime(12,0,0,12,31,date("Y",$jeudiSemaine)))==365)) if (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==4 || (date("w",mktime(12,0,0,1,1,date("Y",$jeudiSemaine)))==3 && date("z",mktime(12,0,0,12,31,date("Y",$jeudiSemaine)))==365))
{ {
$numeroSemaine = 53; $numeroSemaine = 53;

View File

@ -527,22 +527,24 @@ class Propal extends CommonObject
$this->fetch_client(); $this->fetch_client();
// Insertion dans la base // Insertion dans la base
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, price,"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal (fk_soc, price";
$sql.= " remise, remise_percent, remise_absolue,"; $sql.= ", remise, remise_percent, remise_absolue";
$sql.= " tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite,"; $sql.= ", tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite";
$sql.= " fk_cond_reglement, fk_mode_reglement, ref_client,"; $sql.= ", fk_cond_reglement, fk_mode_reglement, ref_client";
$sql.= " date_livraison"; $sql.= ", date_livraison";
$sql.= ", entity";
$sql.= ") "; $sql.= ") ";
$sql.= " VALUES (".$this->socid.", 0,"; $sql.= " VALUES (".$this->socid.", 0";
$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.= ")"; $sql.= ")";
dol_syslog("Propal::create sql=".$sql, LOG_DEBUG); dol_syslog("Propal::create sql=".$sql, LOG_DEBUG);
@ -580,14 +582,20 @@ class Propal extends CommonObject
// Affectation au projet // Affectation au projet
if ($resql && $this->projetidp) if ($resql && $this->projetidp)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=".$this->projetidp." WHERE ref='".$this->ref."'"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_projet=".$this->projetidp;
$sql.= " WHERE ref='".$this->ref."'";
$sql.= " AND entity = ".$conf->entity;
$result=$this->db->query($sql); $result=$this->db->query($sql);
} }
// Affectation de l'adresse de livraison // Affectation de l'adresse de livraison
if ($resql && $this->adresse_livraison_id) if ($resql && $this->adresse_livraison_id)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_adresse_livraison=$this->adresse_livraison_id WHERE ref='$this->ref'"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET fk_adresse_livraison = ".$this->adresse_livraison_id;
$sql.= " WHERE ref = '".$this->ref."'";
$sql.= " AND entity = ".$conf->entity;
$result=$this->db->query($sql); $result=$this->db->query($sql);
} }
@ -712,6 +720,8 @@ class Propal extends CommonObject
*/ */
function fetch($rowid,$ref='') function fetch($rowid,$ref='')
{ {
global $conf;
$sql = "SELECT p.rowid,ref,remise,remise_percent,remise_absolue,fk_soc"; $sql = "SELECT p.rowid,ref,remise,remise_percent,remise_absolue,fk_soc";
$sql.= ", total, tva, total_ht"; $sql.= ", total, tva, total_ht";
$sql.= ", datec"; $sql.= ", datec";
@ -732,6 +742,7 @@ class Propal extends CommonObject
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON p.fk_cond_reglement = cr.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'cond_reglement as cr ON p.fk_cond_reglement = cr.rowid';
$sql.= " WHERE p.fk_statut = c.id"; $sql.= " WHERE p.fk_statut = c.id";
$sql.= " AND p.entity = ".$conf->entity;
if ($ref) $sql.= " AND p.ref='".$ref."'"; if ($ref) $sql.= " AND p.ref='".$ref."'";
else $sql.= " AND p.rowid=".$rowid; else $sql.= " AND p.rowid=".$rowid;
@ -1133,14 +1144,14 @@ class Propal extends CommonObject
{ {
if ($statut == 2) if ($statut == 2)
{ {
// Propale sign<EFBFBD>e // Propale signee
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
$result=$this->create_commande($user); $result=$this->create_commande($user);
if ($result >= 0) if ($result >= 0)
{ {
// Classe la soci<EFBFBD>t<EFBFBD> rattach<63>e comme client // Classe la societe rattachee comme client
$soc=new Societe($this->db); $soc=new Societe($this->db);
$soc->id = $this->socid; $soc->id = $this->socid;
$result=$soc->set_as_client(); $result=$soc->set_as_client();
@ -1186,7 +1197,7 @@ class Propal extends CommonObject
} }
/** /**
* \brief Classe la propale comme factur<EFBFBD>e * \brief Classe la propale comme facturee
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function classer_facturee() function classer_facturee()
@ -1205,7 +1216,7 @@ class Propal extends CommonObject
/** /**
* \brief Cr<EFBFBD>e une commande <EFBFBD> partir de la proposition commerciale * \brief Cree une commande a partir de la proposition commerciale
* \param user Utilisateur * \param user Utilisateur
* \return int <0 si ko, >=0 si ok * \return int <0 si ko, >=0 si ok
*/ */
@ -1217,7 +1228,7 @@ class Propal extends CommonObject
{ {
if ($this->statut == 2) if ($this->statut == 2)
{ {
// Propale sign<EFBFBD>e // Propale signee
include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); include_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
$commande = new Commande($this->db); $commande = new Commande($this->db);
$result=$commande->create_from_propale($user, $this->id); $result=$commande->create_from_propale($user, $this->id);
@ -1261,35 +1272,31 @@ class Propal extends CommonObject
/** /**
* \brief Renvoi la liste des propal (<EFBFBD>ventuellement filtr<EFBFBD>e sur un user) dans un tableau * \brief Renvoi la liste des propal (eventuellement filtree sur un user) dans un tableau
* \param brouillon 0=non brouillon, 1=brouillon * \param brouillon 0=non brouillon, 1=brouillon
* \param user Objet user de filtre * \param user Objet user de filtre
* \return int -1 si erreur, tableau r<EFBFBD>sultat si ok * \return int -1 si erreur, tableau resultat si ok
*/ */
function liste_array ($brouillon=0, $user='') function liste_array ($brouillon=0, $user='')
{ {
$ga = array(); $ga = array();
$sql = "SELECT rowid, ref FROM ".MAIN_DB_PREFIX."propal"; $sql = "SELECT rowid, ref";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$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 datep DESC"; $sql.= " ORDER BY datep DESC";
$result=$this->db->query($sql); $result=$this->db->query($sql);
if ($result) if ($result)
@ -1394,7 +1401,7 @@ class Propal extends CommonObject
} }
/** /**
* \brief Renvoie un tableau contenant les num<EFBFBD>ros de factures associ<EFBFBD>es * \brief Renvoie un tableau contenant les numeros de factures associees
* \return array Tableau des id de factures * \return array Tableau des id de factures
*/ */
function getInvoiceArrayList () function getInvoiceArrayList ()
@ -1403,7 +1410,7 @@ class Propal extends CommonObject
} }
/** /**
* \brief Renvoie un tableau contenant les id et ref des factures associ<EFBFBD>es * \brief Renvoie un tableau contenant les id et ref des factures associees
* \param id Id propal * \param id Id propal
* \return array Tableau des id de factures * \return array Tableau des id de factures
*/ */
@ -1541,8 +1548,8 @@ class Propal extends CommonObject
/** /**
* \brief Change les conditions de r<EFBFBD>glement de la facture * \brief Change les conditions de reglement de la facture
* \param cond_reglement_id Id de la nouvelle condition de r<EFBFBD>glement * \param cond_reglement_id Id de la nouvelle condition de reglement
* \return int >0 si ok, <0 si ko * \return int >0 si ok, <0 si ko
*/ */
function cond_reglement($cond_reglement_id) function cond_reglement($cond_reglement_id)
@ -1575,7 +1582,7 @@ class Propal extends CommonObject
/** /**
* \brief Change le mode de r<EFBFBD>glement * \brief Change le mode de reglement
* \param mode_reglement Id du nouveau mode * \param mode_reglement Id du nouveau mode
* \return int >0 si ok, <0 si ko * \return int >0 si ok, <0 si ko
*/ */
@ -1618,7 +1625,7 @@ class Propal extends CommonObject
$sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo"; $sql.= $this->db->pdate("datec")." as datec, ".$this->db->pdate("date_valid")." as datev, ".$this->db->pdate("date_cloture")." as dateo";
$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."propal as c"; $sql.= " FROM ".MAIN_DB_PREFIX."propal as c";
$sql.= " WHERE c.rowid = $id"; $sql.= " WHERE c.rowid = ".$id;
$result = $this->db->query($sql); $result = $this->db->query($sql);
@ -1665,9 +1672,9 @@ class Propal extends CommonObject
/** /**
* \brief Retourne le libell<EFBFBD> du statut d'une propale (brouillon, valid<EFBFBD>e, ...) * \brief Retourne le libelle du statut d'une propale (brouillon, validee, ...)
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Picto * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libell<EFBFBD> * \return string Libelle
*/ */
function getLibStatut($mode=0) function getLibStatut($mode=0)
{ {
@ -1675,10 +1682,10 @@ class Propal extends CommonObject
} }
/** /**
* \brief Renvoi le libell<EFBFBD> d'un statut donn<EFBFBD> * \brief Renvoi le libelle d'un statut donne
* \param statut id statut * \param statut id statut
* \param mode 0=libell<EFBFBD> long, 1=libell<EFBFBD> court, 2=Picto + Libell<EFBFBD> court, 3=Picto, 4=Picto + Libell<EFBFBD> long, 5=Libell<EFBFBD> court + Picto * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* \return string Libell<EFBFBD> * \return string Libelle
*/ */
function LibStatut($statut,$mode=1) function LibStatut($statut,$mode=1)
{ {
@ -1743,17 +1750,15 @@ class Propal extends CommonObject
$this->nbtodo=$this->nbtodolate=0; $this->nbtodo=$this->nbtodolate=0;
$clause = " WHERE"; $clause = " WHERE";
$sql ="SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin"; $sql = "SELECT p.rowid, p.ref, p.datec as datec, p.fin_validite as datefin";
$sql.=" FROM ".MAIN_DB_PREFIX."propal as p"; $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
$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 p.fk_soc = sc.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.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." p.fk_soc = s.rowid"; $sql.= $clause." p.entity = ".$conf->entity;
$sql.= " AND s.entity = ".$conf->entity;
if ($mode == 'opened') $sql.= " AND p.fk_statut = 1"; if ($mode == 'opened') $sql.= " AND p.fk_statut = 1";
if ($mode == 'signed') $sql.= " AND p.fk_statut = 2"; if ($mode == 'signed') $sql.= " AND p.fk_statut = 2";
if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id; if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id;
@ -1793,11 +1798,15 @@ class Propal extends CommonObject
*/ */
function initAsSpecimen() function initAsSpecimen()
{ {
global $user,$langs; global $user,$langs,$conf;
// Charge tableau des id de soci<EFBFBD>t<EFBFBD> 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)
{ {
@ -1814,7 +1823,10 @@ class Propal 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)
{ {
@ -1828,7 +1840,7 @@ class Propal extends CommonObject
} }
} }
// Initialise param<EFBFBD>tres // Initialise parametres
$this->id=0; $this->id=0;
$this->ref = 'SPECIMEN'; $this->ref = 'SPECIMEN';
$this->specimen=1; $this->specimen=1;
@ -1884,7 +1896,7 @@ class Propal 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." p.entity = ".$conf->entity;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1904,13 +1916,15 @@ class Propal extends CommonObject
} }
/** /**
* \brief V<EFBFBD>rifie si la ref n'est pas d<EFBFBD>j<EFBFBD> utilis<EFBFBD>e * \brief Verifie si la ref n'est pas deja utilisee
* \param soc objet societe * \param soc objet societe
*/ */
function verifyNumRef($soc) function verifyNumRef($soc)
{ {
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal"; $sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."propal";
$sql.= " WHERE ref = '".$this->ref."'"; $sql.= " WHERE ref = '".$this->ref."'";
$sql.= " AND entity = ".$conf->entity;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
@ -1925,8 +1939,8 @@ class Propal extends CommonObject
/** /**
* \brief Renvoie la r<EFBFBD>f<EFBFBD>rence de propale suivante non utilis<EFBFBD>e en fonction du module * \brief Renvoie la reference de propale suivante non utilisee en fonction du module
* de num<EFBFBD>rotation actif d<EFBFBD>fini dans PROPALE_ADDON * de numerotation actif defini dans PROPALE_ADDON
* \param soc objet societe * \param soc objet societe
* \return string reference libre pour la propale * \return string reference libre pour la propale
*/ */
@ -1941,7 +1955,7 @@ class Propal extends CommonObject
{ {
$file = PROPALE_ADDON.".php"; $file = PROPALE_ADDON.".php";
// Chargement de la classe de num<EFBFBD>rotation // Chargement de la classe de numerotation
$classname = PROPALE_ADDON; $classname = PROPALE_ADDON;
require_once($dir.$file); require_once($dir.$file);
@ -2244,7 +2258,7 @@ class PropaleLigne
/** /**
* \brief Mise a jour en base des champs total_xxx de ligne * \brief Mise a jour en base des champs total_xxx de ligne
* \remarks Utilis<EFBFBD> par migration * \remarks Utilise par migration
* \return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function update_total() function update_total()

View File

@ -23,6 +23,7 @@ ALTER TABLE llx_menu ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER menu_han
ALTER TABLE llx_ecm_directories ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER label; ALTER TABLE llx_ecm_directories ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER label;
ALTER TABLE llx_mailing ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER titre; ALTER TABLE llx_mailing ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER titre;
ALTER TABLE llx_categorie ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER label; ALTER TABLE llx_categorie ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER label;
ALTER TABLE llx_propal ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER ref;
ALTER TABLE llx_rights_def DROP PRIMARY KEY; ALTER TABLE llx_rights_def DROP PRIMARY KEY;
ALTER TABLE llx_user_param DROP INDEX fk_user; ALTER TABLE llx_user_param DROP INDEX fk_user;
@ -34,6 +35,7 @@ ALTER TABLE llx_bank_account DROP INDEX uk_bank_account_label;
ALTER TABLE llx_document_model DROP INDEX uk_document_model; ALTER TABLE llx_document_model DROP INDEX uk_document_model;
ALTER TABLE llx_menu DROP INDEX idx_menu_uk_menu; ALTER TABLE llx_menu DROP INDEX idx_menu_uk_menu;
ALTER TABLE llx_categorie DROP INDEX uk_categorie_ref; ALTER TABLE llx_categorie DROP INDEX uk_categorie_ref;
ALTER TABLE llx_propal DROP INDEX ref;
ALTER TABLE llx_rights_def ADD PRIMARY KEY (id, entity); ALTER TABLE llx_rights_def ADD PRIMARY KEY (id, entity);
ALTER TABLE llx_user_param ADD UNIQUE INDEX uk_user_param (fk_user,param,entity); ALTER TABLE llx_user_param ADD UNIQUE INDEX uk_user_param (fk_user,param,entity);
@ -45,3 +47,4 @@ ALTER TABLE llx_bank_account ADD UNIQUE INDEX uk_bank_account_label (label, enti
ALTER TABLE llx_document_model ADD UNIQUE INDEX uk_document_model (nom, type, entity); ALTER TABLE llx_document_model ADD UNIQUE INDEX uk_document_model (nom, type, entity);
ALTER TABLE llx_menu ADD UNIQUE INDEX idx_menu_uk_menu (menu_handler, fk_menu, url, entity); ALTER TABLE llx_menu ADD UNIQUE INDEX idx_menu_uk_menu (menu_handler, fk_menu, url, entity);
ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (label, type, entity); ALTER TABLE llx_categorie ADD UNIQUE INDEX uk_categorie_ref (label, type, entity);
ALTER TABLE llx_propal ADD UNIQUE INDEX uk_propal_ref (ref, entity);

View File

@ -1,6 +1,7 @@
-- ============================================================================ -- ============================================================================
-- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> -- Copyright (C) 2002-2004 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-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
@ -20,7 +21,8 @@
-- ============================================================================ -- ============================================================================
ALTER TABLE llx_propal ADD UNIQUE INDEX uk_propal_ref (ref, entity);
ALTER TABLE llx_propal ADD INDEX idx_propal_fk_soc (fk_soc); ALTER TABLE llx_propal ADD INDEX idx_propal_fk_soc (fk_soc);
ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);

View File

@ -1,5 +1,6 @@
-- =================================================================== -- ===================================================================
-- Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> -- Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- 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
@ -22,35 +23,42 @@ create table llx_propal
( (
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_soc integer, fk_soc integer,
fk_projet integer DEFAULT 0, -- projet auquel est rattache la propale fk_projet integer DEFAULT 0, -- projet auquel est rattache la propale
ref varchar(30) NOT NULL, -- propal number ref varchar(30) NOT NULL, -- propal number
ref_client varchar(30), -- customer order number entity integer DEFAULT 1 NOT NULL, -- multi company id
ref_client varchar(30), -- customer order number
datec datetime, -- date de creation datec datetime, -- date de creation
datep date, -- date de la propal datep date, -- date de la propal
fin_validite datetime, -- date de fin de validite fin_validite datetime, -- date de fin de validite
date_valid datetime, -- date de validation date_valid datetime, -- date de validation
date_cloture datetime, -- date de cloture date_cloture datetime, -- date de cloture
fk_user_author integer, -- createur de la propale fk_user_author integer, -- createur de la propale
fk_user_valid integer, -- valideur de la propale fk_user_valid integer, -- valideur de la propale
fk_user_cloture integer, -- cloture de la propale signee ou non signee fk_user_cloture integer, -- cloture de la propale signee ou non signee
fk_statut smallint DEFAULT 0 NOT NULL, fk_statut smallint DEFAULT 0 NOT NULL,
price real DEFAULT 0, -- (obsolete) price real DEFAULT 0, -- (obsolete)
remise_percent real DEFAULT 0, -- remise globale relative en pourcent (obsolete) remise_percent real DEFAULT 0, -- remise globale relative en pourcent (obsolete)
remise_absolue real DEFAULT 0, -- remise globale absolue (obsolete) remise_absolue real DEFAULT 0, -- remise globale absolue (obsolete)
remise real DEFAULT 0, -- remise calculee (obsolete) remise real DEFAULT 0, -- remise calculee (obsolete)
total_ht double(24,8) DEFAULT 0, -- montant total ht apres remise globale total_ht double(24,8) DEFAULT 0, -- montant total ht apres remise globale
tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale tva double(24,8) DEFAULT 0, -- montant total tva apres remise globale
total double(24,8) DEFAULT 0, -- montant total ttc apres remise globale total double(24,8) DEFAULT 0, -- montant total ttc apres remise globale
fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...) fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...)
fk_mode_reglement integer, -- mode de reglement (Virement, Prélèvement) fk_mode_reglement integer, -- mode de reglement (Virement, Prélèvement)
note text, note text,
note_public text, note_public text,
model_pdf varchar(50), model_pdf varchar(50),
date_livraison date default NULL, date_livraison date default NULL,
fk_adresse_livraison integer, -- adresse de livraison fk_adresse_livraison integer -- adresse de livraison
UNIQUE INDEX (ref)
)type=innodb; )type=innodb;
--
-- List of codes for the field entity
--
-- 1 : first company propal
-- 2 : second company propal
-- 3 : etc...
--