diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index bee7f0be150..93777d950ec 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -40,7 +40,7 @@ class Commande
var $db ;
var $id ;
var $socidp;
- var $contactid;
+ var $contactid;
var $brouillon;
var $cond_reglement_id;
var $cond_reglement_code;
@@ -60,6 +60,7 @@ class Commande
global $langs;
$langs->load('orders');
$this->db = $DB;
+
$this->statuts[-1] = $langs->trans('StatusOrderCanceled');
$this->statuts[0] = $langs->trans('StatusOrderDraft');
$this->statuts[1] = $langs->trans('StatusOrderValidated');
@@ -78,6 +79,7 @@ class Commande
$this->sources[3] = $langs->trans('OrderSource3');
$this->sources[4] = $langs->trans('OrderSource4');
$this->sources[5] = $langs->trans('OrderSource5');
+
$this->products = array();
}
@@ -107,9 +109,9 @@ class Commande
}
$this->soc_id = $propal->soc_id;
- $this->cond_reglement_id = $propal->cond_reglement_id;
- $this->mode_reglement_id = $propal->mode_reglement_id;
- $this->date_livraison = $propal->date_livraison;
+ $this->cond_reglement_id = $propal->cond_reglement_id;
+ $this->mode_reglement_id = $propal->mode_reglement_id;
+ $this->date_livraison = $propal->date_livraison;
/* Définit la société comme un client */
$soc = new Societe($this->db);
@@ -222,26 +224,43 @@ class Commande
}
}
}
- /**
- * Créé la commande
- *
- */
+
+ /**
+ * \brief Créé la commande
+ * \param user Id utilisateur qui crée
+ */
function create($user)
{
- global $conf;
- /* On positionne en mode brouillon la commande */
+ global $conf,$langs;
+
+ // Vérification paramètres
+ if ($this->source < 0)
+ {
+ $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source"));
+ return -1;
+ }
+
+ // On positionne en mode brouillon la commande
$this->brouillon = 1;
if (! $remise)
{
$remise = 0 ;
}
-
if (! $this->projetid)
{
$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, model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison) ';
- $sql .= ' VALUES ('.$this->soc_id.', now(), '.$user->id.', '.$this->projetid.', '.$this->db->idate($this->date_commande).', '.$this->source.', \''.$this->note.'\', \''.$this->ref_client.'\', \''.$this->modelpdf.'\', \''.$this->cond_reglement_id.'\', \''.$this->mode_reglement_id.'\', \''.$this->date_livraison.'\')';
+
+ $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande (';
+ $sql.= 'fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, ref_client, model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison) ';
+ $sql.= ' VALUES ('.$this->soc_id.', now(), '.$user->id.', '.$this->projetid.',';
+ $sql.= ' '.$this->db->idate($this->date_commande).',';
+ $sql.= ' '.$this->source.', ';
+ $sql.= " '".addslashes($this->note)."', ";
+ $sql.= " '".$this->ref_client."', '".$this->modelpdf.'\', \''.$this->cond_reglement_id.'\', \''.$this->mode_reglement_id.'\',';
+ $sql.= " ".($this->date_livraison?$this->db->idate($this->date_livraison):'null').")";
+
+ dolibarr_syslog("Commande.class.php::create sql=$sql");
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande');
@@ -565,7 +584,7 @@ class Commande
$this->modelpdf = $obj->model_pdf;
$this->cond_reglement_id = $obj->fk_cond_reglement;
$this->mode_reglement_id = $obj->fk_mode_reglement;
- $this->date_livraison = $obj->date_livraison;
+ $this->date_livraison = $obj->date_livraison;
$this->db->free();
if ($this->statut == 0)
@@ -804,9 +823,9 @@ class Commande
}
/**
* \brief Définit une date de livraison
- * \param user Objet utilisateur qui modifie
- * \param date_livraison date de livraison
- * \return int <0 si ko, >0 si ok
+ * \param user Objet utilisateur qui modifie
+ * \param date_livraison Date de livraison
+ * \return int <0 si ko, >0 si ok
*/
function set_date_livraison($user, $date_livraison)
{
@@ -1177,10 +1196,11 @@ class Commande
return -1;
}
}
- /**
- * \brief Classer la commande dans un projet
- * \param cat_id Id du projet
- */
+
+ /**
+ * \brief Classer la commande dans un projet
+ * \param cat_id Id du projet
+ */
function classin($cat_id)
{
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET fk_projet = $cat_id";
@@ -1197,6 +1217,7 @@ class Commande
}
}
+
/**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param user Objet user
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index aeb5875a024..6dd69a3b703 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -32,6 +32,9 @@
require('./pre.inc.php');
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/modules_commande.php");
+if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php');
+require_once(DOL_DOCUMENT_ROOT.'/propal.class.php');
+require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php');
$langs->load('orders');
$langs->load('sendings');
@@ -44,13 +47,6 @@ $user->getrights('expedition');
if (!$user->rights->commande->lire) accessforbidden();
-if ($conf->projet->enabled)
-{
- require_once(DOL_DOCUMENT_ROOT.'/project.class.php');
-}
-
-require_once(DOL_DOCUMENT_ROOT.'/propal.class.php');
-require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php');
// Sécurité accés client
$socidp=0;
@@ -77,7 +73,8 @@ if ($_POST['action'] == 'classin' && $user->rights->commande->creer)
if ($_POST['action'] == 'add' && $user->rights->commande->creer)
{
$datecommande='';
- $datecommande = @mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $datecommande = @mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ $datelivraison = @mktime(12, 0, 0, $_POST['liv_month'],$_POST['liv_day'],$_POST['liv_year']);
$commande = new Commande($db);
@@ -91,7 +88,7 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$commande->modelpdf = $_POST['model'];
$commande->cond_reglement_id = $_POST['cond_reglement_id'];
$commande->mode_reglement_id = $_POST['mode_reglement_id'];
- $commande->date_livraison = $_POST['liv_year']."-".$_POST['liv_month']."-".$_POST['liv_day'];
+ $commande->date_livraison = $datelivraison;
$commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']);
$commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']);
@@ -104,9 +101,17 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$commande_id = $commande->create($user);
- $_GET['id'] = $commande->id;
-
- $action = '';
+ if ($commande_id <= 0)
+ {
+ $_GET['action']='create';
+ $_GET['socidp']=$_POST['soc_id'];
+ $mesg='
'.$commande->error.'
';
+ }
+ else
+ {
+ $_GET['id'] = $commande->id;
+ $action = '';
+ }
}
// Positionne ref commande client
@@ -215,6 +220,7 @@ if ($_GET['action'] == 'deleteline' && $user->rights->commande->creer)
$commande->fetch($_GET['id']);
$result = $commande->delete_line($_GET['lineid']);
Header('Location: fiche.php?id='.$_GET['id']);
+ exit;
}
if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider)
@@ -248,6 +254,7 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
$commande->id = $_GET['id'];
$commande->delete();
Header('Location: index.php');
+ exit;
}
}
@@ -271,7 +278,6 @@ if($_GET['action'] == 'builddoc')
llxHeader('',$langs->trans('OrderCard'),'Commande');
-
$html = new Form($db);
/*********************************************************************
@@ -283,6 +289,8 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
{
print_titre($langs->trans('CreateOrder'));
+ if ($mesg) print $mesg.' ';
+
$new_commande = new Commande($db);
if ($propalid)
@@ -338,30 +346,29 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
$html->select_date('','re','','','',"crea_commande");
print '';
- // date de livraison
+ // Date de livraison
print "".$langs->trans("DateDelivery")." ";
- if(DATE_LIVRAISON_WEEK_DELAY != "")
+ if ($conf->global->DATE_LIVRAISON_WEEK_DELAY)
{
- $tmpdte = time() + ((7*DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
- $syear = date("Y", $tmpdte);
- $smonth = date("m", $tmpdte);
- $sday = date("d", $tmpdte);
- $html->select_date($syear."-".$smonth."-".$sday,'liv_','','','',"crea_commande");
+ $tmpdte = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
+ $html->select_date($tmpdte,'liv_','','',1,"crea_commande");
}
else
- $html->select_date('','liv_','','','',"crea_commande");
+ {
+ $html->select_date(-1,'liv_','','',1,"crea_commande");
+ }
print " ";
// Conditions de réglement
- print ''.$langs->trans('PaymentConditions').' ';
- $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id');
- print ' ';
-
- // Mode de réglement
- print ''.$langs->trans('PaymentMode').' ';
- $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
- print ' ';
+ print ''.$langs->trans('PaymentConditions').' ';
+ $html->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id',-1,1);
+ print ' ';
+
+ // Mode de réglement
+ print ''.$langs->trans('PaymentMode').' ';
+ $html->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
+ print ' ';
if ($conf->projet->enabled)
{
@@ -371,16 +378,15 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer)
}
print ''.$langs->trans('Source').' ';
- $html->select_array('source_id',$new_commande->sources,2);
+ $html->selectSourcesCommande('','source_id',1);
print ' ';
print 'Modèle ';
print '';
// pdf
include_once(DOL_DOCUMENT_ROOT.'/includes/modules/commande/modules_commande.php');
- $form=new Form($db);
$model=new ModelePDFCommandes();
$liste=$model->liste_modeles($db);
- $form->select_array("model",$liste,$conf->global->COMMANDE_ADDON_PDF);
+ $html->select_array("model",$liste,$conf->global->COMMANDE_ADDON_PDF);
print " ";
if ($propalid > 0)
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 4e74c75997f..f54d2162241 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -220,24 +220,46 @@ class Form
}
}
- /**
- * \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur
- * \param selected Code pays pré-sélectionné
- * \param htmlname Nom de la liste deroulante
- * \param htmloption Options html sur le select
- * \todo trier liste sur noms après traduction plutot que avant
- */
-
- function select_pays($selected='',$htmlname='pays_id',$htmloption='')
- {
- global $conf,$langs;
- $langs->load("dict");
-
- $sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays";
- $sql .= " WHERE active = 1";
- $sql .= " ORDER BY code ASC;";
-
- if ($this->db->query($sql))
+
+ /**
+ * \brief Renvoie la liste des sources de commandes
+ * \param selected Id de la source pré-sélectionnée
+ * \param htmlname Nom de la liste deroulante
+ * \param addempty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
+ * \return array Tableau des sources de commandes
+ */
+ function selectSourcesCommande($selected='',$htmlname='source_id',$addempty=0)
+ {
+ global $conf,$langs;
+ print '';
+ if ($addempty) print ' ';
+ print ''.$langs->trans('OrderSource0').' ';
+ print ''.$langs->trans('OrderSource1').' ';
+ print ''.$langs->trans('OrderSource2').' ';
+ print ''.$langs->trans('OrderSource3').' ';
+ print ''.$langs->trans('OrderSource4').' ';
+ print ''.$langs->trans('OrderSource5').' ';
+ print ' ';
+ }
+
+
+ /**
+ * \brief Retourne la liste déroulante des pays actifs, dans la langue de l'utilisateur
+ * \param selected Code pays pré-sélectionné
+ * \param htmlname Nom de la liste deroulante
+ * \param htmloption Options html sur le select
+ * \todo trier liste sur noms après traduction plutot que avant
+ */
+ function select_pays($selected='',$htmlname='pays_id',$htmloption='')
+ {
+ global $conf,$langs;
+ $langs->load("dict");
+
+ $sql = "SELECT rowid, libelle, code, active FROM ".MAIN_DB_PREFIX."c_pays";
+ $sql .= " WHERE active = 1";
+ $sql .= " ORDER BY code ASC;";
+
+ if ($this->db->query($sql))
{
print '';
$num = $this->db->num_rows();
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index fb3a4ca3db7..dd1c6caa321 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -399,7 +399,7 @@ function dolibarr_time_plus_duree($time,$duration_value,$duration_unit)
\brief Formattage de la date en fonction de la langue $conf->langage
\param time Date 'timestamp' ou format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS'
\param format Format d'affichage de la date ("%d %b %Y", "%d/%m/%Y", ...)
- \return string Date formatée ou '?' si time null
+ \return string Date formatée ou '' si time null
*/
function dolibarr_print_date($time,$format='')
{
@@ -408,8 +408,8 @@ function dolibarr_print_date($time,$format='')
// Si format non défini, on prend $conf->format_date_text_short
if (! $format) $format=$conf->format_date_text_short;
- // Si date non définie, on renvoie '?'
- if (! $time) return '?';
+ // Si date non définie, on renvoie ''
+ if (! $time) return '';
// Analyse de la date
if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?',$time,$reg))
diff --git a/htdocs/user.class.php b/htdocs/user.class.php
index a04550351a8..4354771abcb 100644
--- a/htdocs/user.class.php
+++ b/htdocs/user.class.php
@@ -46,53 +46,52 @@
class User
{
- var $db;
+ var $db;
- var $id;
- var $fullname;
- var $nom;
- var $prenom;
- var $note;
- var $code;
- var $email;
- var $office_tel;
- var $office_fax;
- var $user_mobile;
- var $admin;
- var $login;
- var $pass;
- var $lang;
- var $datec;
- var $datem;
- var $societe_id;
- var $webcal_login;
- var $datelastaccess;
-
- var $error;
- var $userpref_limite_liste;
- var $all_permissions_are_loaded; /**< \private all_permissions_are_loaded */
-
-
- /**
- * \brief Constructeur de la classe
- * \param $DB handler accès base de données
- * \param $id id de l'utilisateur (0 par défaut)
- */
-
- function User($DB, $id=0)
- {
-
- $this->db = $DB;
- $this->id = $id;
-
- // Preference utilisateur
- $this->liste_limit = 0;
- $this->clicktodial_enabled = 0;
+ var $id;
+ var $fullname;
+ var $nom;
+ var $prenom;
+ var $note;
+ var $code;
+ var $email;
+ var $office_tel;
+ var $office_fax;
+ var $user_mobile;
+ var $admin;
+ var $login;
+ var $pass;
+ var $lang;
+ var $datec;
+ var $datem;
+ var $societe_id;
+ var $webcal_login;
+ var $datelastaccess;
+
+ var $error;
+ var $userpref_limite_liste;
+ var $all_permissions_are_loaded; /**< \private all_permissions_are_loaded */
+
+
+ /**
+ * \brief Constructeur de la classe
+ * \param $DB handler accès base de données
+ * \param $id id de l'utilisateur (0 par défaut)
+ */
+ function User($DB, $id=0)
+ {
+ $this->db = $DB;
+ $this->id = $id;
+
+ // Preference utilisateur
+ $this->liste_limit = 0;
+ $this->clicktodial_enabled = 0;
- $this->all_permissions_are_loaded = 0;
+ $this->all_permissions_are_loaded = 0;
+ $this->admin=0;
- return 1;
- }
+ return 1;
+ }
/**
@@ -564,7 +563,8 @@ class User
$this->db->begin();
- $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user WHERE login ='".addslashes($this->login)."'";
+ $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user";
+ $sql.= " WHERE login ='".addslashes($this->login)."'";
$resql=$this->db->query($sql);
if ($resql)
{
@@ -574,7 +574,7 @@ class User
if ($num)
{
$this->error = $langs->trans("ErrorLoginAlreadyExists");
- return -5;
+ return -6;
}
else
{
@@ -589,19 +589,17 @@ class User
// Set default rights
if ($this->set_default_rights() < 0)
{
- $this->db->rollback();
-
$this->error=$this->db->error();
- return -4;
+ $this->db->rollback();
+ return -5;
}
// Update minor fields
if ($this->update() < 0)
{
- $this->db->rollback();
-
$this->error=$this->db->error();
- return -5;
+ $this->db->rollback();
+ return -4;
}
// Appel des triggers
@@ -614,29 +612,27 @@ class User
if (! $error)
{
$this->db->commit();
-
return $this->id;
}
else
{
- $this->db->rollback();
-
$this->error=$interface->error;
+ $this->db->rollback();
return -3;
}
}
else
{
- $this->db->rollback();
$this->error=$this->db->error();
+ $this->db->rollback();
return -2;
}
}
}
else
{
- $this->db->rollback();
$this->error=$this->db->error();
+ $this->db->rollback();
return -1;
}
}
@@ -767,6 +763,7 @@ class User
$this->pass=trim($this->pass);
$this->email=trim($this->email);
$this->note=trim($this->note);
+ $this->admin=$this->admin?$this->admin:0;
$error=0;
@@ -777,7 +774,7 @@ class User
$sql .= ", firstname = '".addslashes($this->prenom)."'";
$sql .= ", login = '".addslashes($this->login)."'";
if ($this->pass) $sql .= ", pass = '".addslashes($this->pass)."'";
- $sql .= ", admin = $this->admin";
+ $sql .= ", admin = ".$this->admin;
$sql .= ", office_phone = '$this->office_phone'";
$sql .= ", office_fax = '$this->office_fax'";
$sql .= ", user_mobile = '$this->user_mobile'";