From e6800a461a23e29db6c269f5e3e4cc8ed289af29 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Jun 2006 01:53:32 +0000 Subject: [PATCH] On stocke le total ht, tva et ttc de chaque ligne de facture au niveau de la ligne (requis pour toute compta) --- htdocs/facture.class.php | 21 +++-- htdocs/install/inc.php | 8 +- htdocs/install/upgrade2.php | 168 +++++++++++++++++++++++++++++++++--- htdocs/propal.class.php | 4 +- 4 files changed, 177 insertions(+), 24 deletions(-) diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 76093eaf7e6..6b51b1c797f 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1236,28 +1236,29 @@ class Facture $err=0; // Liste des lignes factures a sommer - $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_tva, total_ttc'; + $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price,'; + $sql.= ' total_ht, total_tva, total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet'; $sql.= ' WHERE fk_facture = '.$facid; - $result = $this->db->query($sql); - if ($result) + + $resql = $this->db->query($sql); + if ($resql) { $this->total_ht = 0; $this->total_tva = 0; $this->total_ttc = 0; - - $num = $this->db->num_rows($result); + $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { - $obj = $this->db->fetch_object($result); + $obj = $this->db->fetch_object($resql); $this->total_ht += $obj->total_ht; $this->total_tva += ($obj->total_ttc - $obj->total_ht); $this->total_ttc += $obj->total_ttc; // Anciens indicateurs - $this->amount_ht += $obj->price * $obj->qty; + $this->amount_ht += ($obj->price * $obj->qty); $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne) $tvas[$obj->tva_taux] += ($obj->total_ttc - $obj->total_ht); @@ -1269,7 +1270,7 @@ class Facture $i++; } - $this->db->free($result); + $this->db->free($resql); /* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue); @@ -1289,7 +1290,9 @@ class Facture $sql .= ", tva='". price2num($this->total_tva)."'"; $sql .= ", total_ttc='".price2num($this->total_ttc)."'"; $sql .= ' WHERE rowid = '.$facid; - if ( $this->db->query($sql) ) + $resql=$this->db->query($sql); + + if ($resql) { // \TODO A supprimer car l'utilisation de facture_tva_sum non utilisable // dans un context compta propre. On utilisera plutot les lignes. diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index 1f0fe410be6..75166036a17 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -26,7 +26,11 @@ \version $Revision$ */ +define('DOL_DOCUMENT_ROOT','../'); + require_once('../translate.class.php'); +require_once('../lib/functions.inc.php'); + // Forcage du parametrage PHP magic_quots_gpc (Sinon il faudrait a chaque POST, conditionner @@ -106,7 +110,7 @@ function pFooter($nonext=0,$setuplang='') } -function dolibarr_syslog($message) +function xxdolibarr_syslog($message) { // Les fonctions syslog ne sont pas toujours installè± ou autoris褳 chez les hè¡¥rgeurs if (function_exists("define_syslog_variables")) @@ -128,7 +132,7 @@ function dolibarr_syslog($message) \param versionarray2 Tableau de version (vermajeur,vermineur,autre) \return int <0 si versionarray10 si versionarray1>versionarray2 */ -function versioncompare($versionarray1,$versionarray2) +function aaversioncompare($versionarray1,$versionarray2) { $ret=0; $i=0; diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index ae6bf11d932..8d5d9888708 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -21,12 +21,15 @@ */ /** - \file htdocs/install/paiementfourn_newstructure.php - \brief Migre les données de l'ancienne table des paiements fournisseur vers la nouvelle structure + \file htdocs/install/upgrade2.php + \brief Effectue la migration de données diverses \version $Revision$ */ include_once('./inc.php'); +include_once('../facture.class.php'); +include_once('../propal.class.php'); +include_once('../commande/commande.class.php'); $grant_query=''; $etape = 2; @@ -163,8 +166,13 @@ 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. @@ -358,7 +366,7 @@ function migrate_contracts_date1($db,$langs,$conf) $sql="update llx_contrat set date_contrat=tms where date_contrat is null"; $resql = $db->query($sql); if (! $resql) dolibarr_print_error($db); - if ($db->affected_rows() > 0) + if ($db->affected_rows($resql) > 0) print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."
\n"; else print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."
\n"; @@ -366,7 +374,7 @@ function migrate_contracts_date1($db,$langs,$conf) $sql="update llx_contrat set datec=tms where datec is null"; $resql = $db->query($sql); if (! $resql) dolibarr_print_error($db); - if ($db->affected_rows() > 0) + if ($db->affected_rows($resql) > 0) print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."
\n"; else print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."
\n"; @@ -593,24 +601,38 @@ function migrate_price_facture($db,$langs,$conf) { if ($conf->facture->enabled) { + 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"; - if ($db->query($sql)) + $sql.= " WHERE total_ttc = 0 AND remise_percent != 100"; + $resql=$db->query($sql); + if ($resql) { - $num = $db->num_rows(); + $num = $db->num_rows($resql); $i = 0; while ($i < $num) { - $row = $db->fetch_row($i); + $obj = $db->fetch_object($resql); + $facture = new Facture($db); - if ( $facture->fetch($row[0]) ) + $facture->id=$obj->rowid; + + if ( $facture->fetch($facture->id) >= 0) { - if ( $facture->update_price($row[0]) > 0 ) + if ( $facture->update_price($facture->id) > 0 ) { - print "(ok $row[0]) "; + print ". "; } else { - print "Erreur #2"; + print "Error id=".$facture->id; $err++; } } @@ -628,9 +650,131 @@ function migrate_price_facture($db,$langs,$conf) print "Erreur #1"; $err++; } + + print '
'; } } + +/* + * Mise a jour des totaux propal + */ +function migrate_price_propal($db,$langs,$conf) +{ + if ($conf->propal->enabled) + { + 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"; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $propal = new Propal($db); + $propal->id=$obj->rowid; + if ( $propal->fetch($propal->id) >= 0 ) + { + if ( $propal->update_price($propal->id) > 0 ) + { + print ". "; + } + else + { + print "Error id=".$propal->id; + $err++; + } + } + else + { + print "Erreur #3"; + $err++; + } + $i++; + } + $db->free(); + } + else + { + print "Erreur #1"; + $err++; + } + + print '
'; + } +} + + +/* + * Mise a jour des totaux commande + */ +function migrate_price_commande($db,$langs,$conf) +{ + if ($conf->facture->enabled) + { + 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"; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $commande = new Commande($db); + $commande->id = $obj->rowid; + if ( $commande->fetch($commande->id) >= 0 ) + { + if ( $commande->update_price($commande->id) > 0 ) + { + print ". "; + } + else + { + print "Error id=".$commande->id; + $err++; + } + } + else + { + print "Erreur #3"; + $err++; + } + $i++; + } + $db->free(); + } + else + { + print "Erreur #1"; + $err++; + } + + print '
'; + } +} + + /* * Mise a jour des modeles selectionnes */ diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 237a45172a7..9992255c867 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -55,7 +55,9 @@ class Propal var $status; var $datep; var $fin_validite; - var $price; + var $price; // Total HT + var $tva; // Total TVA + var $total; // Total TTC var $cond_reglement_id; var $cond_reglement_code; var $mode_reglement_id;