Fix: Pb sur les centimes dans le paiement d'une charge.
This commit is contained in:
parent
73f0a05f49
commit
be3ca9d5b4
@ -49,7 +49,8 @@ class PaiementCharge {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Creation d'un paiement de charge sociale
|
* \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) {
|
function create($user) {
|
||||||
$sql_err = 0;
|
$sql_err = 0;
|
||||||
@ -63,14 +64,11 @@ class PaiementCharge {
|
|||||||
{
|
{
|
||||||
$facid = $key;
|
$facid = $key;
|
||||||
$value = trim($value);
|
$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)
|
if ($total > 0)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_user_creat)";
|
$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) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge");
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -90,7 +86,7 @@ class PaiementCharge {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $total > 0 && $sql_err == 0 )
|
if ($total > 0 && $sql_err == 0)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
|||||||
@ -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
|
// Creation de la ligne paiement
|
||||||
$paiement = new PaiementCharge($db);
|
$paiement = new PaiementCharge($db);
|
||||||
@ -78,12 +78,10 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
{
|
{
|
||||||
$chid = $key;
|
$chid = $key;
|
||||||
$value = trim($value);
|
$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))
|
if (is_numeric($amount)) $total += $amount;
|
||||||
{
|
|
||||||
$total += $amount;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$total = ereg_replace(",",".",$total);
|
||||||
|
|
||||||
// Insertion dans llx_bank
|
// Insertion dans llx_bank
|
||||||
$label = "Règlement charge";
|
$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);
|
$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
|
// 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);
|
$paiement->update_fk_bank($bank_line_id);
|
||||||
}
|
|
||||||
|
|
||||||
// Mise a jour liens (pour chaque charge concernée par le paiement)
|
// Mise a jour liens (pour chaque charge concernée par le paiement)
|
||||||
//foreach ($paiement->amounts as $key => $value)
|
//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);
|
// $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;
|
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
||||||
Header("Location: $loc");
|
Header("Location: $loc");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$db->rollback();
|
||||||
|
$fiche_erreur_message = "Echec de la création entrée compte: ".$db->error();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Il y a eu erreur
|
$db->rollback();
|
||||||
$fiche_erreur_message = "Echec de la création du paiement: ".$db->error();
|
$fiche_erreur_message = "Echec de la création du paiement: paiement_id=$paiement_id ".$db->error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user