Fix: Pb sur les centimes dans le paiement d'une charge.

This commit is contained in:
Laurent Destailleur 2005-07-02 16:33:39 +00:00
parent 73f0a05f49
commit be3ca9d5b4
2 changed files with 86 additions and 84 deletions

View File

@ -49,7 +49,8 @@ class PaiementCharge {
/**
* \brief Creation d'un paiement de charge sociale
*
* \user user Utilisateur qui crée le paiement
* \return int <0 si erreur, >0 si ok
*/
function create($user) {
$sql_err = 0;
@ -63,14 +64,11 @@ class PaiementCharge {
{
$facid = $key;
$value = trim($value);
$amount = round(ereg_replace(",",".",$value), 2);
$amount = round(ereg_replace(",",".",$value), 2); // Un round est ok si nb avec '.'
if (is_numeric($amount)) $total += $amount;
}
$total = ereg_replace(",",".",$total);
if (is_numeric($amount))
{
$total += $amount;
}
}
$total = round(ereg_replace(",",".",$total), 2);
if ($total > 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_user_creat)";
@ -78,9 +76,7 @@ class PaiementCharge {
if ( $this->db->query($sql) )
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
}
else
{

View File

@ -58,7 +58,7 @@ if ($_POST["action"] == 'add_paiement')
}
}
// TODO Mettre toute la chaine dans une même transaction
$db->begin();
// Creation de la ligne paiement
$paiement = new PaiementCharge($db);
@ -78,12 +78,10 @@ if ($_POST["action"] == 'add_paiement')
{
$chid = $key;
$value = trim($value);
$amount = round(ereg_replace(",",".",$value), 2);
if (is_numeric($amount))
{
$total += $amount;
}
$amount = round(ereg_replace(",",".",$value), 2); // Un round est ok si nb avec '.'
if (is_numeric($amount)) $total += $amount;
}
$total = ereg_replace(",",".",$total);
// Insertion dans llx_bank
$label = "Règlement charge";
@ -91,9 +89,9 @@ if ($_POST["action"] == 'add_paiement')
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user);
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a généré l'écriture bancaire
if ($bank_line_id) {
if ($bank_line_id > 0)
{
$paiement->update_fk_bank($bank_line_id);
}
// Mise a jour liens (pour chaque charge concernée par le paiement)
//foreach ($paiement->amounts as $key => $value)
@ -106,13 +104,21 @@ if ($_POST["action"] == 'add_paiement')
// $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom);
//}
$db->commit();
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
Header("Location: $loc");
exit;
}
else {
$db->rollback();
$fiche_erreur_message = "Echec de la création entrée compte: ".$db->error();
}
}
else
{
// Il y a eu erreur
$fiche_erreur_message = "Echec de la création du paiement: ".$db->error();
$db->rollback();
$fiche_erreur_message = "Echec de la création du paiement: paiement_id=$paiement_id ".$db->error();
}
}
else