On stocke le total ht, tva et ttc de chaque ligne de facture au niveau de la ligne (requis pour toute compta)

This commit is contained in:
Laurent Destailleur 2006-06-17 01:53:32 +00:00
parent 3566ef2692
commit e6800a461a
4 changed files with 177 additions and 24 deletions

View File

@ -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.

View File

@ -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 versionarray1<versionarray2, 0 si =, >0 si versionarray1>versionarray2
*/
function versioncompare($versionarray1,$versionarray2)
function aaversioncompare($versionarray1,$versionarray2)
{
$ret=0;
$i=0;

View File

@ -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')."<br>\n";
else
print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."<br>\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')."<br>\n";
else
print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."<br>\n";
@ -593,24 +601,38 @@ function migrate_price_facture($db,$langs,$conf)
{
if ($conf->facture->enabled)
{
print '<br>';
print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\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 '<br>';
}
}
/*
* Mise a jour des totaux propal
*/
function migrate_price_propal($db,$langs,$conf)
{
if ($conf->propal->enabled)
{
print '<br>';
print '<b>'.$langs->trans('MigrationProposal')."</b><br>\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 '<br>';
}
}
/*
* Mise a jour des totaux commande
*/
function migrate_price_commande($db,$langs,$conf)
{
if ($conf->facture->enabled)
{
print '<br>';
print '<b>'.$langs->trans('MigrationOrder')."</b><br>\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 '<br>';
}
}
/*
* Mise a jour des modeles selectionnes
*/

View File

@ -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;