diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index d784f59dc2b..44261206bb0 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -326,20 +326,27 @@ class Commande
// Nettoyage parametres
$this->brouillon = 1; // On positionne en mode brouillon la commande
+ dolibarr_syslog("Commande.class.php::create");
+
// Vérification paramètres
if ($this->source < 0)
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source"));
+ dolibarr_syslog("Commande.class.php::create ".$this->error);
return -1;
}
if (! $remise) $remise=0;
if (! $this->projetid) $this->projetid = 0;
- dolibarr_syslog("Commande.class.php::create");
-
$soc = new Societe($this->db);
- $soc->fetch($this->socidp);
-
+ $result=$soc->fetch($this->soc_id);
+ if ($result < 0)
+ {
+ $this->error="Failed to fetch company";
+ dolibarr_syslog("Commande.class.php::create ".$this->error);
+ return -2;
+ }
+
$this->db->begin();
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande (';
@@ -356,6 +363,8 @@ class Commande
$sql.= " '".$this->remise_absolue."',";
$sql.= " '".$this->remise_percent."')";
+ dolibarr_syslog("Commande.class.php::create sql=".$sql);
+
$resql=$this->db->query($sql);
if ($resql)
{
@@ -407,10 +416,12 @@ class Commande
$this->db->query($sql);
}
+ $this->db->commit();
return $this->id;
}
else
{
+ $this->db->rollback();
return -1;
}
}
@@ -418,7 +429,8 @@ class Commande
else
{
dolibarr_print_error($this->db);
- return 0;
+ $this->db->rollback();
+ return -1;
}
}
@@ -441,7 +453,7 @@ class Commande
*/
function addline($commandeid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
- dolibarr_syslog("commande.class.php::addline $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
+ dolibarr_syslog("commande.class.php::addline this->id=$this->id, $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
@@ -676,10 +688,10 @@ class Commande
}
}
- /**
- * Lit une commande
- *
- */
+ /**
+ * \brief Recupère de la base les caractéristiques d'une commande
+ * \param rowid id de la commande à récupérer
+ */
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, c.fk_cond_reglement, c.fk_mode_reglement,';
@@ -687,157 +699,168 @@ class Commande
$sql.= ' c.fk_projet, c.remise_percent, c.remise, c.remise_absolue, c.source, c.facture as facturee, c.note, c.note_public, c.ref_client, c.model_pdf, c.fk_adresse_livraison';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande as c';
$sql.= ' WHERE c.rowid = '.$id;
-
+
+ dolibarr_syslog("Commande::fetch sql=$sql");
+
$result = $this->db->query($sql) ;
- if ( $result )
+ if ($result)
{
$obj = $this->db->fetch_object($result);
- $this->id = $obj->rowid;
- $this->ref = $obj->ref;
- $this->ref_client = $obj->ref_client;
- $this->soc_id = $obj->fk_soc;
- $this->socidp = $obj->fk_soc;
- $this->statut = $obj->fk_statut;
- $this->user_author_id = $obj->fk_user_author;
- $this->total_ht = $obj->total_ht;
- $this->total_tva = $obj->tva;
- $this->total_ttc = $obj->total_ttc;
- $this->date = $obj->date_commande;
- $this->remise = $obj->remise;
- $this->remise_percent = $obj->remise_percent;
- $this->remise_absolue = $obj->remise_absolue;
- $this->source = $obj->source;
- $this->facturee = $obj->facturee;
- $this->note = $obj->note;
- $this->note_public = $obj->note_public;
- $this->projet_id = $obj->fk_projet;
- $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->adresse_livraison_id = $obj->fk_adresse_livraison;
-
- $this->db->free();
-
- if ($this->cond_reglement_id)
- {
- $sql = "SELECT rowid, libelle, code";
- $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
- $sql.= " WHERE rowid = ".$this->cond_reglement_id;
-
- $resqlcond = $this->db->query($sql);
-
- if ($resqlcond)
- {
- $objc = $this->db->fetch_object($resqlcond);
- $this->cond_reglement = $objc->libelle;
- $this->cond_reglement_code = $objc->code;
- }
- }
-
- if ($this->user_author_id)
- {
- $sql = "SELECT name, firstname";
- $sql.= " FROM ".MAIN_DB_PREFIX."user";
- $sql.= " WHERE rowid = ".$this->user_author_id;
-
- $resqluser = $this->db->query($sql);
-
- if ($resqluser)
- {
- $obju = $this->db->fetch_object($resqluser);
- $this->user_author_name = $obju->name;
- $this->user_author_firstname = $obju->firstname;
- }
- }
-
- if ($this->statut == 0)
- $this->brouillon = 1;
- // exp pdf -----------
- $this->lignes = array();
- $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.coef,';
- $sql.= ' p.label, p.description as product_desc, p.ref, p.fk_product_type, p.rowid as prodid';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
- $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
- $sql.= ' WHERE l.fk_commande = '.$this->id;
- $sql.= ' ORDER BY l.rang';
- $result = $this->db->query($sql);
- if ($result)
- {
- $num = $this->db->num_rows($result);
- $i = 0;
-
- while ($i < $num)
- {
- $objp = $this->db->fetch_object($result);
-
- $ligne = new CommandeLigne($this->db);
-
- $ligne->desc = $objp->description; // Description ligne
- $ligne->qty = $objp->qty;
- $ligne->tva_tx = $objp->tva_tx;
- $ligne->subprice = $objp->subprice;
- $ligne->remise_percent = $objp->remise_percent;
- $ligne->price = $objp->price;
- $ligne->product_id = $objp->fk_product;
- $ligne->coef = $objp->coef;
-
- $ligne->libelle = $objp->label; // Label produit
- $ligne->product_desc = $objp->product_desc; // Description produit
- $ligne->ref = $objp->ref;
-
- $this->lignes[$i] = $ligne;
- //dolibarr_syslog("1 ".$ligne->desc);
- //dolibarr_syslog("2 ".$ligne->product_desc);
- $i++;
- }
- $this->db->free($result);
- }
- else
- {
- dolibarr_syslog("Propal::Fetch Erreur lecture des produits");
- return -1;
- }
-
-
- // -------- exp pdf //
-
- /*
- * Propale associée
- */
- $sql = 'SELECT cp.fk_propale';
- $sql .= ' FROM '.MAIN_DB_PREFIX.'co_pr as cp';
- $sql .= ' WHERE cp.fk_commande = '.$this->id;
- if ($this->db->query($sql) )
+ if ($obj)
{
- if ($this->db->num_rows())
+ $this->id = $obj->rowid;
+ $this->ref = $obj->ref;
+ $this->ref_client = $obj->ref_client;
+ $this->soc_id = $obj->fk_soc;
+ $this->socidp = $obj->fk_soc;
+ $this->statut = $obj->fk_statut;
+ $this->user_author_id = $obj->fk_user_author;
+ $this->total_ht = $obj->total_ht;
+ $this->total_tva = $obj->tva;
+ $this->total_ttc = $obj->total_ttc;
+ $this->date = $obj->date_commande;
+ $this->remise = $obj->remise;
+ $this->remise_percent = $obj->remise_percent;
+ $this->remise_absolue = $obj->remise_absolue;
+ $this->source = $obj->source;
+ $this->facturee = $obj->facturee;
+ $this->note = $obj->note;
+ $this->note_public = $obj->note_public;
+ $this->projet_id = $obj->fk_projet;
+ $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->adresse_livraison_id = $obj->fk_adresse_livraison;
+
+ $this->db->free();
+
+ if ($this->cond_reglement_id)
{
- $obj = $this->db->fetch_object();
- $this->propale_id = $obj->fk_propale;
+ $sql = "SELECT rowid, libelle, code";
+ $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement";
+ $sql.= " WHERE rowid = ".$this->cond_reglement_id;
+
+ $resqlcond = $this->db->query($sql);
+
+ if ($resqlcond)
+ {
+ $objc = $this->db->fetch_object($resqlcond);
+ $this->cond_reglement = $objc->libelle;
+ $this->cond_reglement_code = $objc->code;
+ }
+ }
+
+ if ($this->user_author_id)
+ {
+ $sql = "SELECT name, firstname";
+ $sql.= " FROM ".MAIN_DB_PREFIX."user";
+ $sql.= " WHERE rowid = ".$this->user_author_id;
+
+ $resqluser = $this->db->query($sql);
+
+ if ($resqluser)
+ {
+ $obju = $this->db->fetch_object($resqluser);
+ $this->user_author_name = $obju->name;
+ $this->user_author_firstname = $obju->firstname;
+ }
+ }
+
+ if ($this->statut == 0) $this->brouillon = 1;
+
+ // \todo Utiliser la classe CommandeLigne au lieu de ce code
+ $this->lignes = array();
+ $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.coef,';
+ $sql.= ' p.label, p.description as product_desc, p.ref, p.fk_product_type, p.rowid as prodid';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid';
+ $sql.= ' WHERE l.fk_commande = '.$this->id;
+ $sql.= ' ORDER BY l.rang';
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $num = $this->db->num_rows($result);
+ $i = 0;
+
+ while ($i < $num)
+ {
+ $objp = $this->db->fetch_object($result);
+
+ $ligne = new CommandeLigne($this->db);
+
+ $ligne->desc = $objp->description; // Description ligne
+ $ligne->qty = $objp->qty;
+ $ligne->tva_tx = $objp->tva_tx;
+ $ligne->subprice = $objp->subprice;
+ $ligne->remise_percent = $objp->remise_percent;
+ $ligne->price = $objp->price;
+ $ligne->product_id = $objp->fk_product;
+ $ligne->coef = $objp->coef;
+
+ $ligne->libelle = $objp->label; // Label produit
+ $ligne->product_desc = $objp->product_desc; // Description produit
+ $ligne->ref = $objp->ref;
+
+ $this->lignes[$i] = $ligne;
+ //dolibarr_syslog("1 ".$ligne->desc);
+ //dolibarr_syslog("2 ".$ligne->product_desc);
+ $i++;
+ }
+ $this->db->free($result);
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ dolibarr_syslog("Commande::Fetch Erreur sql=$sql, ".$this->error);
+ return -1;
+ }
+
+
+ // -------- exp pdf //
+
+ /*
+ * Propale associée
+ */
+ $sql = 'SELECT cp.fk_propale';
+ $sql .= ' FROM '.MAIN_DB_PREFIX.'co_pr as cp';
+ $sql .= ' WHERE cp.fk_commande = '.$this->id;
+ if ($this->db->query($sql))
+ {
+ if ($this->db->num_rows())
+ {
+ $obj = $this->db->fetch_object();
+ $this->propale_id = $obj->fk_propale;
+ }
+ return 1;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ return -1;
}
- return 1;
}
else
{
- dolibarr_print_error($this->db);
- return -1;
+ $this->error="Order not found";
+ return -2;
}
}
else
{
dolibarr_print_error($this->db);
- return -1;
+ return -3;
}
}
+
- /*
- *
- *
- *
- */
-
- function set_pdf_model($user, $modelpdf)
- {
+ /*
+ *
+ *
+ *
+ */
+ function set_pdf_model($user, $modelpdf)
+ {
if ($user->rights->commande->creer)
{
@@ -2103,10 +2126,54 @@ class CommandeLigne
var $product_desc; // Description produit
var $ref; // Reference produit
- function CommandeLigne()
+ /**
+ * \brief Constructeur d'objets ligne de commande
+ * \param DB handler d'accès base de donnée
+ */
+ function CommandeLigne($DB)
{
-
+ $this->db= $DB ;
}
+
+ /**
+ * \brief Recupére l'objet ligne de commande
+ * \param rowid id de la ligne de commande
+ */
+ function fetch($rowid)
+ {
+ $sql = 'SELECT fk_commande, fk_product, description, price, qty, rowid, tva_tx,';
+ $sql.= ' label,';
+ $sql.= ' remise, remise_percent, fk_remise_except, subprice,';
+ $sql.= ' info_bits, total_ht, total_tva, total_ttc, coef, rang';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet WHERE rowid = '.$rowid;
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ $objp = $this->db->fetch_object($result);
+ $this->fk_propal = $objp->fk_propal;
+ $this->label = $objp->label;
+ $this->desc = $objp->description;
+ $this->qty = $objp->qty;
+ $this->price = $objp->price;
+ $this->subprice = $objp->subprice;
+ $this->tva_taux = $objp->tva_taux;
+ $this->remise = $objp->remise;
+ $this->remise_percent = $objp->remise_percent;
+ $this->fk_remise_except = $objp->fk_remise_except;
+ $this->produit_id = $objp->fk_product;
+ $this->info_bits = $objp->info_bits;
+ $this->total_ht = $objp->total_ht;
+ $this->total_tva = $objp->total_tva;
+ $this->total_ttc = $objp->total_ttc;
+ $this->coef = $objp->coef;
+ $this->rang = $objp->rang;
+ $this->db->free($result);
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ }
+ }
}
?>
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 361313e2732..1228cc69cfa 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -202,6 +202,11 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
{
$commande = new Commande($db);
$ret=$commande->fetch($_POST['id']);
+ if ($ret < 0)
+ {
+ dolibarr_print_error($db,$commande->error);
+ exit;
+ }
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 6b51b1c797f..4aa5010f99a 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -2413,25 +2413,28 @@ class FactureLigne
/**
* \brief Recupére l'objet ligne de facture
* \param rowid id de la ligne de facture
- * \param societe_id id de la societe
*/
- function fetch($rowid, $societe_id=0)
+ function fetch($rowid)
{
- $sql = 'SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent,';
- $sql.= ' subprice, '.$this->db->pdate('date_start').' as date_start,'.$this->db->pdate('date_end').' as date_end,';
- $sql.= ' info_bits, total_ht, total_tva, total_ttc';
+ $sql = 'SELECT fk_facture, fk_product, description, price, qty, rowid, tva_taux,';
+ $sql.= ' remise, remise_percent, fk_remise_except, subprice,';
+ $sql.= ' '.$this->db->pdate('date_start').' as date_start,'.$this->db->pdate('date_end').' as date_end,';
+ $sql.= ' info_bits, total_ht, total_tva, total_ttc, rang,';
+ $sql.= ' fk_code_ventilation, fk_export_compta';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
$result = $this->db->query($sql);
if ($result)
{
$objp = $this->db->fetch_object($result);
- $this->desc = stripslashes($objp->description);
+ $this->fk_facture = $objp->fk_facture;
+ $this->desc = $objp->description;
$this->qty = $objp->qty;
$this->price = $objp->price;
$this->subprice = $objp->subprice;
$this->tva_taux = $objp->tva_taux;
$this->remise = $objp->remise;
$this->remise_percent = $objp->remise_percent;
+ $this->fk_remise_except = $objp->fk_remise_except;
$this->produit_id = $objp->fk_product;
$this->date_start = $objp->date_start;
$this->date_end = $objp->date_end;
@@ -2439,6 +2442,9 @@ class FactureLigne
$this->total_ht = $objp->total_ht;
$this->total_tva = $objp->total_tva;
$this->total_ttc = $objp->total_ttc;
+ $this->fk_code_ventilation = $objp->fk_code_ventilation;
+ $this->fk_export_compta = $objp->fk_export_compta;
+ $this->rang = $objp->rang;
$this->db->free($result);
}
else
diff --git a/htdocs/install/check.php b/htdocs/install/check.php
index af58799ad33..0a1ae3f282a 100644
--- a/htdocs/install/check.php
+++ b/htdocs/install/check.php
@@ -40,6 +40,9 @@ $langs->setDefaultLang($setuplang);
$langs->load("install");
+dolibarr_install_syslog("Dolibarr install/upgrade process started");
+
+
pHeader($langs->trans("DolibarrWelcome"),""); // Etape suivante = license
print $langs->trans("InstallEasy")."
";
diff --git a/htdocs/install/etape5.php b/htdocs/install/etape5.php
index 7c009eb8e40..2e263a759f4 100644
--- a/htdocs/install/etape5.php
+++ b/htdocs/install/etape5.php
@@ -36,6 +36,10 @@ $langs->setDefaultLang($setuplang);
$langs->load("admin");
$langs->load("install");
+
+dolibarr_install_syslog("Entering etape5.php page");
+
+
$success=0;
if (file_exists($conffile))
@@ -191,6 +195,9 @@ print $langs->trans("GoToSetupArea");
print '';
+dolibarr_install_syslog("Dolibarr install/setup finished");
+
+
pFooter(1,$setuplang);
?>
diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php
index 75166036a17..740ee2b8aba 100644
--- a/htdocs/install/inc.php
+++ b/htdocs/install/inc.php
@@ -110,18 +110,17 @@ function pFooter($nonext=0,$setuplang='')
}
-function xxdolibarr_syslog($message)
+function dolibarr_install_syslog($message)
{
- // Les fonctions syslog ne sont pas toujours installè± ou autoris褳 chez les hè¡¥rgeurs
- if (function_exists("define_syslog_variables"))
- {
- // \todo D財ctiver sous Windows (gros probl笥 m謯ire et faute de protections)
- // if (1 == 2) {
- define_syslog_variables();
- openlog("dolibarr", LOG_PID | LOG_PERROR, LOG_USER); # LOG_USER au lieu de LOG_LOCAL0 car non accept矰ar tous les php
- syslog(LOG_WARNING, $message);
- closelog();
- // }
+ // Ajout user a la log
+ $login='install';
+ $message=sprintf("%-8s",$login)." ".$message;
+
+ $fileinstall="/tmp/dolibarr_install.log";
+ $file=@fopen($fileinstall,"a+");
+ if ($file) {
+ fwrite($file,strftime("%Y-%m-%d %H:%M:%S",time())." ".$level." ".$message."\n");
+ fclose($file);
}
}
diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php
index dcc760e7b22..c411acc1743 100644
--- a/htdocs/install/upgrade.php
+++ b/htdocs/install/upgrade.php
@@ -48,6 +48,9 @@ $langs->load("admin");
$langs->load("install");
+dolibarr_install_syslog("Entering upgrade.php page");
+
+
pHeader($langs->trans("DatabaseMigration"),"upgrade2","upgrade");
@@ -92,18 +95,20 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade")
{
print "