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 ""; print $langs->trans("ServerConnection")." : $dolibarr_main_db_host".$langs->trans("OK").""; + dolibarr_install_syslog($langs->trans("ServerConnection")." : $dolibarr_main_db_host ".$langs->trans("OK")); $ok = 1 ; } else { - print "Erreur lors de la création de : $dolibarr_main_db_name".$langs->trans("Error").""; + print "".$langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name)."".$langs->trans("Error").""; + dolibarr_install_syslog($langs->trans("ErrorFailedToCreateDatabase",$dolibarr_main_db_name)); } if ($ok) { if($db->database_selected == 1) { - dolibarr_syslog("Connexion réussie à la base : $dolibarr_main_db_name"); + dolibarr_install_syslog("Database connection successfull : $dolibarr_main_db_name"); } else { @@ -118,6 +123,7 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") $versionarray=$db->getVersionArray(); print ''.$langs->trans("DatabaseVersion").''; print ''.$version.''; + dolibarr_install_syslog($langs->trans("DatabaseVersion")." : $version"); //print ''.join('.',$versionarray).''; } @@ -189,9 +195,9 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") { if ($sql) { - // Ajout trace sur requete (eventuellement à commenter - // si beaucoup de requetes) + // Ajout trace sur requete (eventuellement à commenter si beaucoup de requetes) print(''.$langs->trans("Request").' '.($i+1)." sql='".$sql."'\n"); + dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." sql='".$sql); if ($db->query($sql)) { @@ -219,6 +225,7 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") print ''.$langs->trans("Request").' '.($i+1).''; print ''.$langs->trans("Error")." ".$db->errno()." ".$sql."
".$db->error().""; print ''; + dolibarr_install_syslog($langs->trans("Request").' '.($i+1)." ".$langs->trans("Error")." ".$db->errno()." ".$sql."
".$db->error()); $error++; } } @@ -234,10 +241,16 @@ if (! isset($_GET["action"]) || $_GET["action"] == "upgrade") if ($error == 0) { - print ''; - print $langs->trans("ProcessMigrateScript").''.$langs->trans("OK").''; + print ''.$langs->trans("ProcessMigrateScript").''; + print ''.$langs->trans("OK").''; $ok = 1; } + else + { + print ''.$langs->trans("ProcessMigrateScript").''; + print '
'.$langs->trans("KO").'
'; + $ok = 0; + } } print ''; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 8d5d9888708..2f3997632bb 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -30,6 +30,7 @@ include_once('./inc.php'); include_once('../facture.class.php'); include_once('../propal.class.php'); include_once('../commande/commande.class.php'); +include_once('../lib/price.lib.php'); $grant_query=''; $etape = 2; @@ -52,6 +53,9 @@ $langs->load("bills"); $langs->load("suppliers"); +dolibarr_install_syslog("Entering upgrade2.php page"); + + pHeader($langs->trans('DataMigration'),'etape5','upgrade'); @@ -93,7 +97,7 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade') $db = new DoliDb($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name); if ($db->connected != 1) { - print 'Erreur lors de la création de : '.$dolibarr_main_db_name.''.$langs->trans('Error').''; + print ''.$langs->trans("ErrorFailedToConnectToDatabase",$dolibarr_main_db_name).''.$langs->trans('Error').''; $error++; } @@ -101,7 +105,7 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade') { if($db->database_selected == 1) { - dolibarr_syslog('Connexion réussie à la base : '.$dolibarr_main_db_name); + dolibarr_install_syslog('Database connection successfull : '.$dolibarr_main_db_name); } else { @@ -166,17 +170,17 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade') migrate_modeles($db,$langs,$conf); -/* migrate_price_commande($db,$langs,$conf); migrate_price_propal($db,$langs,$conf); - migrate_price_facture($db,$langs,$conf); -*/ + // On commit dans tous les cas. // La procédure etant conçue pour pouvoir passer plusieurs fois quelquesoit la situation. $db->commit(); + + migrate_price_facture($db,$langs,$conf); $db->close(); } @@ -595,119 +599,203 @@ function migrate_paiementfourn_facturefourn($db,$langs,$conf) /* - * Mise a jour des totaux facture + * Mise a jour des totaux lignes de facture */ function migrate_price_facture($db,$langs,$conf) { if ($conf->facture->enabled) { + $db->begin(); + + dolibarr_install_syslog("Upgrade data for invoice"); + print '
'; print ''.$langs->trans('MigrationInvoice')."
\n"; - - // TODO Ajout requete remplissage champ total_ht, totam_tva, total_ttc - // dans table det - - - - - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture"; - $sql.= " WHERE total_ttc = 0 AND remise_percent != 100"; + + // Liste des lignes facture non a jour + $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_taux, "; + $sql.= " f.rowid as facid, f.remise_percent as remise_percent_global"; + $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE fd.fk_facture = f.rowid"; + $sql.= " AND (fd.total_ttc = 0 or fd.total_ttc IS NULL) AND fd.remise_percent != 100"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) + if ($num) { - $obj = $db->fetch_object($resql); - - $facture = new Facture($db); - $facture->id=$obj->rowid; - - if ( $facture->fetch($facture->id) >= 0) + while ($i < $num) { - if ( $facture->update_price($facture->id) > 0 ) + $obj = $db->fetch_object($resql); + + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $txtva = $obj->tva_taux; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + + // On met a jour les 3 nouveaux champs + $facligne= new FactureLigne($db); + $facligne->fetch($rowid); + + $result=calcul_price_total($qty,$pu,$remise_percent,$txtva,$remise_percent_global); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; + + $facligne->total_ht = $total_ht; + $facligne->total_tva = $total_tva; + $facligne->total_ttc = $total_ttc; + + dolibarr_install_syslog("Line $rowid: facid=$obj->facid pu=$pu qty=$qty tva_taux=$txtva remise_percent=$remise_percent remise_global=$remise_percent_global -> $total_ht, $total_tva, $total_ttc"); + print ". "; +// $facligne->update($rowid); + + + /* On touche pas a facture mere + $facture = new Facture($db); + $facture->id=$obj->facid; + + if ( $facture->fetch($facture->id) >= 0) { - print ". "; + if ( $facture->update_price($facture->id) > 0 ) + { + print ". "; + } + else + { + print "Error id=".$facture->id; + $err++; + } } else { - print "Error id=".$facture->id; + print "Error #3"; $err++; } + */ + $i++; } - else - { - print "Erreur #3"; - $err++; - } - $i++; + } + else + { + print $langs->trans("AlreadyDone"); } $db->free(); + + $db->rollback(); } else { - print "Erreur #1"; + print "Error #1 ".$db->error(); $err++; + + $db->rollback(); } print '
'; + } } /* - * Mise a jour des totaux propal + * Mise a jour des totaux lignes de propal */ function migrate_price_propal($db,$langs,$conf) { if ($conf->propal->enabled) { + $db->begin(); + + dolibarr_install_syslog("Upgrade data for propal"); + print '
'; print ''.$langs->trans('MigrationProposal')."
\n"; - // TODO Ajout requete remplissage champ total_ht, totam_tva, total_ttc - // dans table det - - - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."propal"; - $sql.= " WHERE total = 0 AND remise_percent != 100"; + // Liste des lignes propal non a jour + $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as tva_taux, "; + $sql.= " p.rowid as propalid, p.remise_percent as remise_percent_global"; + $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p"; + $sql.= " WHERE pd.fk_propal = p.rowid"; + $sql.= " AND (pd.total_ttc = 0 or pd.total_ttc IS NULL) AND pd.remise_percent != 100"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) + if ($num) { - $obj = $db->fetch_object($resql); - - $propal = new Propal($db); - $propal->id=$obj->rowid; - if ( $propal->fetch($propal->id) >= 0 ) + while ($i < $num) { - if ( $propal->update_price($propal->id) > 0 ) + $obj = $db->fetch_object($resql); + + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $txtva = $obj->tva_taux; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + + // On met a jour les 3 nouveaux champs + $propalligne= new PropaleLigne($db); + $propalligne->fetch($rowid); + + $result=calcul_price_total($qty,$pu,$remise_percent,$txtva,$remise_percent_global); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; + + $propalligne->total_ht = $total_ht; + $propalligne->total_tva = $total_tva; + $propalligne->total_ttc = $total_ttc; + + dolibarr_install_syslog("Line $rowid: propalid=$obj->facid pu=$pu qty=$qty tva_taux=$txtva remise_percent=$remise_percent remise_global=$remise_percent_global -> $total_ht, $total_tva, $total_ttc"); + print ". "; +// $propalligne->update($rowid); + + + /* On touche pas a propal mere + $propal = new Propal($db); + $propal->id=$obj->rowid; + if ( $propal->fetch($propal->id) >= 0 ) { - print ". "; + if ( $propal->update_price($propal->id) > 0 ) + { + print ". "; + } + else + { + print "Error id=".$propal->id; + $err++; + } } else { - print "Error id=".$propal->id; + print "Error #3"; $err++; } + */ + $i++; } - else - { - print "Erreur #3"; - $err++; - } - $i++; } + else + { + print $langs->trans("AlreadyDone"); + } + $db->free(); + + $db->rollback(); } else { - print "Erreur #1"; + print "Error #1 ".$db->error(); $err++; + + $db->rollback(); } print '
'; @@ -716,58 +804,99 @@ function migrate_price_propal($db,$langs,$conf) /* - * Mise a jour des totaux commande + * Mise a jour des totaux lignes de commande */ function migrate_price_commande($db,$langs,$conf) { if ($conf->facture->enabled) { + $db->begin(); + + dolibarr_install_syslog("Upgrade data for order"); + print '
'; print ''.$langs->trans('MigrationOrder')."
\n"; - // TODO Ajout requete remplissage champ total_ht, totam_tva, total_ttc - // dans table det - - - - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande"; - $sql.= " WHERE total_ttc = 0 AND remise_percent != 100"; + // Liste des lignes commande non a jour + $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, "; + $sql.= " c.rowid as commandeid, c.remise_percent as remise_percent_global"; + $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c"; + $sql.= " WHERE cd.fk_commande = c.rowid"; + $sql.= " AND (cd.total_ttc = 0 or cd.total_ttc IS NULL) AND cd.remise_percent != 100"; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) + if ($num) { - $obj = $db->fetch_object($resql); - - $commande = new Commande($db); - $commande->id = $obj->rowid; - if ( $commande->fetch($commande->id) >= 0 ) + while ($i < $num) { - if ( $commande->update_price($commande->id) > 0 ) + $obj = $db->fetch_object($resql); + + $rowid = $obj->rowid; + $qty = $obj->qty; + $pu = $obj->subprice; + $txtva = $obj->tva_taux; + $remise_percent = $obj->remise_percent; + $remise_percent_global = $obj->remise_percent_global; + + // On met a jour les 3 nouveaux champs + $commandeligne= new CommandeLigne($db); + $commandeligne->fetch($rowid); + + $result=calcul_price_total($qty,$pu,$remise_percent,$txtva,$remise_percent_global); + $total_ht = $result[0]; + $total_tva = $result[1]; + $total_ttc = $result[2]; + + $commandeligne->total_ht = $total_ht; + $commandeligne->total_tva = $total_tva; + $commandeligne->total_ttc = $total_ttc; + + dolibarr_install_syslog("Line $rowid: commandeid=$obj->facid pu=$pu qty=$qty tva_taux=$txtva remise_percent=$remise_percent remise_global=$remise_percent_global -> $total_ht, $total_tva, $total_ttc"); + print ". "; +// $commandeligne->update($rowid); + + /* On touche pas a facture mere + $commande = new Commande($db); + $commande->id = $obj->rowid; + if ( $commande->fetch($commande->id) >= 0 ) { - print ". "; + if ( $commande->update_price($commande->id) > 0 ) + { + print ". "; + } + else + { + print "Error id=".$commande->id; + $err++; + } } else { - print "Error id=".$commande->id; + print "Error #3"; $err++; } + */ + $i++; } - else - { - print "Erreur #3"; - $err++; - } - $i++; } + else + { + print $langs->trans("AlreadyDone"); + } + $db->free(); + + $db->rollback(); } else { - print "Erreur #1"; + print "Error #1 ".$db->error(); $err++; + + $db->rollback(); } print '
'; diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 9a19feaf8a0..50e7d73ec58 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -9,6 +9,12 @@ ConfFileDoesNotExists=Configuration file %s does not exist ! ErrorDirDoesNotExists=Directory %s does not exists. ErrorGoBackAndCorrectParameters=Go backward and correct wrong parameters. ErrorWrongValueForParameter=You may have typed a wrong value for parameter '%s'. +ErrorFaileToCreateDatabase=Failed to create database '%'. +ErrorFaileToConnectToDatabase=Failed to connect to database '%'. +MigrationOrder=Data migration for customers' orders +MigrationProposal=Data migration for commercial proposals +MigrationInvoice=Data migration for customers' invoices +MigrationContract=Data migration for contracts YouCanContinue=You can continue... License=Using license ConfigurationFile=Configuration file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 12edb91a364..247941e402c 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -23,12 +23,14 @@ ErrorYourCountryIsNotDefined=Your country is not defined. Go to Home-Setup-Edit ErrorRecordIsUsedByChild=Failed to delete this record. This record is used by at least on child records. ErrorWrongValue=Wrong value ErrorWrongValueForParameterX=Wrong value for parameter %s +ErrorNoRequestInError=No request in error SeeAbove=See above HomeArea=Home area LastAccess=Last access RequestedUrl=Requested Url DatabaseTypeManager=Database type manager RequestLastAccess=Request for last database access +RequestLastAccessInError=Request for last database access in error ReturnCodeLastAccess=Return code for last database access InformationLastAccess=Information for last database access DolibarrHasDetectedError=Dolibarr has detected a technical error diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index 014a24bdc6e..8285308e95b 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -9,6 +9,12 @@ ConfFileIsWritable=Le fichier %s est modifiable. ErrorDirDoesNotExists=Le répertoire %s n'existe pas ou n'est pas accessible. ErrorGoBackAndCorrectParameters=Revenez en arrière et corrigez les paramètres invalides. ErrorWrongValueForParameter=Vous avez peut-être saisi une mauvaise valeur pour le paramètre '%s'. +ErrorFaileToCreateDatabase=Echec de création de la base '%'. +ErrorFaileToConnectToDatabase=Echec de connection à la base '%'. +MigrationOrder=Migration de données sur les commandes clients +MigrationProposal=Migration de données sur les propositions commerciales +MigrationInvoice=Migration de données sur les factures clients +MigrationContract=Migration de données sur les contrats YouCanContinue=Vous pouvez continuer... License=Licence d'utilisation ConfigurationFile=Fichier de configuration diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 3e4a0264f9d..7aa1300dac9 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -23,12 +23,14 @@ ErrorYourCountryIsNotDefined=Votre pays n'est pas d ErrorRecordIsUsedByChild=Impossible de supprimer cet enregistrement. Ce dernier est utilisé en tant que père par au moins un enregistrement fils. ErrorWrongValue=Valeur incorrecte ErrorWrongValueForParameterX=Valeur incorrecte pour le paramètre %s +ErrorNoRequestInError=Aucune requete en erreur SeeAbove=Voir ci-dessus HomeArea=Espace accueil LastAccess=Dernière connexion RequestedUrl=Url sollicitée DatabaseTypeManager=Type gestionnaire de base de donnée RequestLastAccess=Requete dernier acces en base +RequestLastAccessInError=Requete dernier acces en base en erreur ReturnCodeLastAccess=Code retour dernier acces en base InformationLastAccess=Information sur le dernier accès en base DolibarrHasDetectedError=Dolibarr a détecté une erreur technique diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index f8e23c0cfdb..5f53ed5de34 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -1131,14 +1131,14 @@ function dolibarr_print_error($db='',$msg='') { print "
\n"; print "".$langs->trans("DatabaseTypeManager").": ".$db->type."
\n"; - print "".$langs->trans("RequestLastAccess").": ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."
\n"; + print "".$langs->trans("RequestLastAccessInError").": ".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."
\n"; print "".$langs->trans("ReturnCodeLastAccess").": ".$db->errno()."
\n"; print "".$langs->trans("InformationLastAccess").": ".$db->error()."
\n"; } else // Mode CLI { print $langs->trans("DatabaseTypeManager").":\n".$db->type."\n"; - print $langs->trans("RequestLastAccess").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n"; + print $langs->trans("RequestLastAccessInError").":\n".($db->lastqueryerror()?$db->lastqueryerror():$langs->trans("ErrorNoRequestInError"))."\n"; print $langs->trans("ReturnCodeLastAccess").":\n".$db->errno()."\n"; print $langs->trans("InformationLastAccess").":\n".$db->error()."\n"; diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 9992255c867..7c68bb9cb3c 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -2325,9 +2325,53 @@ class PropaleLigne var $product_desc; // Description produit var $ref; // Reference produit - function PropaleLigne() - { - } + + /** + * \brief Constructeur d'objets ligne de propal + * \param DB handler d'accès base de donnée + */ + function PropaleLigne($DB) + { + $this->db= $DB ; + } + + /** + * \brief Recupére l'objet ligne de propal + * \param rowid id de la ligne de propal + */ + function fetch($rowid) + { + $sql = 'SELECT fk_propal, fk_product, description, price, qty, rowid, tva_tx,'; + $sql.= ' remise, remise_percent, fk_remise_except, subprice,'; + $sql.= ' info_bits, total_ht, total_tva, total_ttc, coef, rang'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet WHERE rowid = '.$rowid; + $result = $this->db->query($sql); + if ($result) + { + $objp = $this->db->fetch_object($result); + $this->fk_propal = $objp->fk_propal; + $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); + } + } } ?>