Suite gestion des arrondis sur les montants.

Fix: Pb du update sur vieilles version mysql
This commit is contained in:
Laurent Destailleur 2007-07-04 22:07:53 +00:00
parent 7ae57dda4e
commit adf61a88c9
9 changed files with 125 additions and 108 deletions

View File

@ -297,7 +297,7 @@ if ($socid > 0)
print '<td colspan="3">'; print '<td colspan="3">';
$amount_discount=$objsoc->getcurrentDiscount(); $amount_discount=$objsoc->getcurrentDiscount();
if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); if ($amount_discount < 0) dolibarr_print_error($db,$societe->error);
if ($amount_discount > 0) print $amount_discount.'&nbsp;'.$langs->trans("Currency".$conf->monnaie); if ($amount_discount > 0) print price($amount_discount).'&nbsp;'.$langs->trans("Currency".$conf->monnaie);
else print $langs->trans("DiscountNone"); else print $langs->trans("DiscountNone");
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@ -232,7 +232,7 @@ if ($_socid > 0)
} }
print '</td>'; print '</td>';
print '<td align="right">'.price($obj->amount_ht).'</td>'; print '<td align="right">'.price($obj->amount_ht).'</td>';
print '<td align="right">'.price($obj->tva_tx).'%</td>'; print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
print '<td align="right">'.price($obj->amount_ttc).'</td>'; print '<td align="right">'.price($obj->amount_ttc).'</td>';
print '<td align="center">'; print '<td align="center">';
print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login; print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login;
@ -311,7 +311,7 @@ if ($_socid > 0)
print '</td>'; print '</td>';
print '<td align="left"><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>'; print '<td align="left"><a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),'bill').' '.$obj->facnumber.'</a></td>';
print '<td align="right">'.price($obj->amount_ht).'</td>'; print '<td align="right">'.price($obj->amount_ht).'</td>';
print '<td align="right">'.price($obj->tva_tx).'%</td>'; print '<td align="right">'.price2num($obj->tva_tx,'MU').'%</td>';
print '<td align="right">'.price($obj->amount_ttc).'</td>'; print '<td align="right">'.price($obj->amount_ttc).'</td>';
print '<td align="center">'; print '<td align="center">';
print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login; print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login;

View File

@ -1938,12 +1938,12 @@ else
{ {
if ($fac->statut > 0 || $fac->type == 2) if ($fac->statut > 0 || $fac->type == 2)
{ {
print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
} }
else else
{ {
print '<br>'; print '<br>';
print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount); print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,price($absolute_discount));
} }
} }
else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';

View File

@ -189,7 +189,7 @@ if ($socid > 0)
print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>'; print '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$societe->id.'">'.img_edit($langs->trans("Modify")).'</a>';
} }
print '</td></tr></table>'; print '</td></tr></table>';
print '</td><td colspan="3">'.($societe->remise_client?$societe->remise_client.'%':$langs->trans("DiscountNone")).'</td>'; print '</td><td colspan="3">'.($societe->remise_client?price2num($societe->remise_client,'MT').'%':$langs->trans("DiscountNone")).'</td>';
print '</tr>'; print '</tr>';
// Réductions (Remises-Ristournes-Rabbais) // Réductions (Remises-Ristournes-Rabbais)
@ -207,7 +207,7 @@ if ($socid > 0)
print '<td colspan="3">'; print '<td colspan="3">';
$amount_discount=$societe->getCurrentDiscount(); $amount_discount=$societe->getCurrentDiscount();
if ($amount_discount < 0) dolibarr_print_error($db,$societe->error); if ($amount_discount < 0) dolibarr_print_error($db,$societe->error);
if ($amount_discount > 0) print $amount_discount.'&nbsp;'.$langs->trans("Currency".$conf->monnaie); if ($amount_discount > 0) print price($amount_discount).'&nbsp;'.$langs->trans("Currency".$conf->monnaie);
else print $langs->trans("DiscountNone"); else print $langs->trans("DiscountNone");
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';

View File

@ -702,102 +702,112 @@ class Facture extends CommonObject
} }
} }
/** /**
\brief Supprime la facture \brief Supprime la facture
\param rowid Id de la facture à supprimer \param rowid Id de la facture à supprimer
\return int <0 si ko, >0 si ok \return int <0 si ko, >0 si ok
*/ */
function delete($rowid=0) function delete($rowid=0)
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
if (! $rowid) $rowid=$this->id; if (! $rowid) $rowid=$this->id;
dolibarr_syslog("Facture::Delete rowid=".$rowid, LOG_DEBUG); dolibarr_syslog("Facture::delete rowid=".$rowid, LOG_DEBUG);
$this->db->begin(); $this->db->begin();
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{
// On désaffecte de la facture les remises liées
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except as re,';
$sql.= ' '.MAIN_DB_PREFIX.'facturedet as fd';
$sql.= ' SET re.fk_facture = NULL';
$sql.= ' WHERE fd.rowid=re.fk_facture AND fd.fk_facture = '.$rowid;
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$rowid;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'fa_pr WHERE fk_facture = '.$rowid;
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'co_fa WHERE fk_facture = '.$rowid;
$resql=$this->db->query($sql); if ($this->db->query($sql))
if ($resql) {
{ // On met a jour le lien des remises
// Appel des triggers $list_rowid_det=array();
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); $sql = 'SELECT fd.rowid FROM '.MAIN_DB_PREFIX.'facturedet as fd WHERE fk_facture = '.$rowid;
$interface=new Interfaces($this->db); $resql=$this->db->query($sql);
$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf); while ($obj = $this->db->fetch_object($resql))
// Fin appel triggers {
$list_rowid_det[]=$obj->rowid;
$this->db->commit(); }
return 1;
} // On désaffecte de la facture les remises liées
if (sizeof($list_rowid_det))
{
$sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except as re';
$sql.= ' SET re.fk_facture = NULL';
$sql.= ' WHERE re.fk_facture in ('.join(',',$list_rowid_det).')';
dolibarr_syslog("Facture.class::delete sql=".$sql);
if (! $this->db->query($sql))
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -5;
}
}
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid;
if ($this->db->query($sql))
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid;
$resql=$this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('BILL_DELETE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -6;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -4;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -3;
}
}
else else
{ {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error); dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -6; return -2;
} }
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error); dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback(); $this->db->rollback();
return -4; return -1;
} }
} }
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -5;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -3;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -2;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
dolibarr_syslog("Facture.class::delete ".$this->error);
$this->db->rollback();
return -1;
}
}
/** /**

View File

@ -706,11 +706,11 @@ class Form
if ($selected > 0 && $selected == $obj->rowid) if ($selected > 0 && $selected == $obj->rowid)
{ {
print '<option value="'.$obj->rowid.'" selected="true">'.$desc.' ('.$obj->amount_ht.' '.$langs->trans("Currency".$conf->monnaie).')'.'</option>'; print '<option value="'.$obj->rowid.'" selected="true">'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
} }
else else
{ {
print '<option value="'.$obj->rowid.'">'.$desc.' ('.$obj->amount_ht.' '.$langs->trans("Currency".$conf->monnaie).')'.'</option>'; print '<option value="'.$obj->rowid.'">'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
} }
$i++; $i++;
} }
@ -2039,7 +2039,7 @@ class Form
print '<input type="hidden" name="action" value="setabsolutediscount">'; print '<input type="hidden" name="action" value="setabsolutediscount">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>'; print '<tr><td>';
print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)).': '; print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)).': ';
// print $langs->trans("AvailableGlobalDiscounts").': '; // print $langs->trans("AvailableGlobalDiscounts").': ';
print $this->select_remises('',$htmlname,'fk_facture IS NULL',$socid); print $this->select_remises('',$htmlname,'fk_facture IS NULL',$socid);
print '</td>'; print '</td>';
@ -2051,7 +2051,9 @@ class Form
if ($selected) if ($selected)
{ {
print $selected; print $selected;
} else { }
else
{
print "0"; print "0";
} }
} }

View File

@ -994,10 +994,10 @@ class Societe
{ {
$discount = new DiscountAbsolute($this->db); $discount = new DiscountAbsolute($this->db);
$discount->fk_soc=$this->id; $discount->fk_soc=$this->id;
$discount->amount_ht=$remise; $discount->amount_ht=price2num($remise,'MT');
$discount->amount_tva=($remise*$tva_tx/100); $discount->amount_tva=price2num($remise*$tva_tx/100,'MT');
$discount->amount_ttc=$discount->amount_ht+$discount->amount_tva; $discount->amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
$discount->tva_tx=$tva_tx; $discount->tva_tx=price2num($tva_tx,'MT');
$discount->desc=$desc; $discount->desc=$desc;
$result=$discount->create($user); $result=$discount->create($user);
if ($result > 0) if ($result > 0)

View File

@ -599,6 +599,11 @@ ALTER TABLE llx_facture_fourn_det MODIFY tva_taux double(16,8) DEFAULT
ALTER TABLE llx_facture_fourn_det MODIFY tva double(16,8) DEFAULT 0; ALTER TABLE llx_facture_fourn_det MODIFY tva double(16,8) DEFAULT 0;
ALTER TABLE llx_facture_fourn_det MODIFY total_ttc double(16,8) DEFAULT 0; ALTER TABLE llx_facture_fourn_det MODIFY total_ttc double(16,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except MODIFY amount_ht double(16,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except MODIFY amount_tva double(16,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except MODIFY amount_ttc double(16,8) DEFAULT 0;
ALTER TABLE llx_societe_remise_except MODIFY tva_tx double(6,3) DEFAULT 0;
-- Changement de idp en rowid -- Changement de idp en rowid
-- V4 ALTER TABLE llx_propal DROP FOREIGN KEY llx_propal_ibfk1; -- V4 ALTER TABLE llx_propal DROP FOREIGN KEY llx_propal_ibfk1;

View File

@ -27,12 +27,12 @@ create table llx_societe_remise_except
rowid integer AUTO_INCREMENT PRIMARY KEY, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_soc integer NOT NULL, -- client fk_soc integer NOT NULL, -- client
datec datetime, datec datetime,
amount_ht real NOT NULL, amount_ht double(16,8) NOT NULL,
amount_tva real DEFAULT 0 NOT NULL, amount_tva double(16,8) DEFAULT 0 NOT NULL,
amount_ttc real DEFAULT 0 NOT NULL, amount_ttc double(16,8) DEFAULT 0 NOT NULL,
tva_tx real DEFAULT 0 NOT NULL, tva_tx double(6,3) DEFAULT 0 NOT NULL,
fk_user integer NOT NULL, fk_user integer NOT NULL,
fk_facture integer, fk_facture integer,
fk_facture_source integer, fk_facture_source integer,
description varchar(255) NOT NULL description varchar(255) NOT NULL
)type=innodb; )type=innodb;