Fix: Supprime gestion explicite transactions multiniveau car gérer automatiquement par gestionnaire de base de donnée

This commit is contained in:
Laurent Destailleur 2005-04-15 21:57:04 +00:00
parent de9fe85246
commit 32a479a834

View File

@ -21,7 +21,8 @@
* *
*/ */
/** \file htdocs/paiement.class.php /**
\file htdocs/paiement.class.php
\ingroup facture \ingroup facture
\brief Fichier de la classe des paiement de factures clients \brief Fichier de la classe des paiement de factures clients
\version $Revision$ \version $Revision$
@ -109,107 +110,85 @@ class Paiement
/** /**
* \brief Création du paiement en base * \brief Création du paiement en base
* \param user object utilisateur qui crée * \param user object utilisateur qui crée
* \param no_commit le begin et le commit sont fait par l'appelant * \return int id du paiement crée, < 0 si erreur
*
*/ */
function create($user, $no_commit = 0) function create($user)
{ {
$sql_err = 0; $total = 0;
/* $sql_err = 0;
* Insertion dans la base
*/
if ($no_commit == 0)
{
$result = $this->db->begin();
}
else
{
$result = 1;
}
if ($result) $this->db->begin();
{
$total = 0;
foreach ($this->amounts as $key => $value) foreach ($this->amounts as $key => $value)
{ {
$facid = $key; $facid = $key;
$value = trim($value); $value = trim($value);
$amount = ereg_replace(",",".",round($value, 2)); $amount = ereg_replace(",",".",round($value, 2));
if (is_numeric($amount)) if (is_numeric($amount))
{ {
$total += $amount; $total += $amount;
} }
} }
$total = ereg_replace(",",".",$total); $total = ereg_replace(",",".",$total);
if ($total <> 0) /* On accepte les montants négatifs pour les rejets de prélèvement */ if ($total <> 0) /* On accepte les montants négatifs pour les rejets de prélèvement */
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (datec, datep, amount, fk_paiement, num_paiement, note, fk_user_creat)";
$sql .= " VALUES (now(), $this->datepaye, '$total', $this->paiementid, '$this->num_paiement', '$this->note', $user->id)"; $sql .= " VALUES (now(), $this->datepaye, '$total', $this->paiementid, '$this->num_paiement', '$this->note', $user->id)";
if ( $this->db->query($sql) ) if ( $this->db->query($sql) )
{ {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiement");
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiement"); foreach ($this->amounts as $key => $value)
{
$facid = $key;
$value = trim($value);
$amount = ereg_replace(",",".",round($value, 2));
foreach ($this->amounts as $key => $value) if (is_numeric($amount) && $amount <> 0)
{ {
$facid = $key; $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
$value = trim($value); $sql .= " VALUES ('".$facid."','". $this->id."','". $amount."')";
$amount = ereg_replace(",",".",round($value, 2));
if (is_numeric($amount) && $amount <> 0) if (! $this->db->query($sql) )
{ {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)"; dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement_facture ".$facid);
$sql .= " VALUES ('".$facid."','". $this->id."','". $amount."')"; $sql_err++;
}
}
else
{
dolibarr_syslog("Paiement::Create Montant non numérique");
}
}
if (! $this->db->query($sql) ) }
{ else
dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement_facture ".$facid); {
dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement");
$sql_err++;
}
}
$sql_err++; if ( $total <> 0 && $sql_err == 0 ) // On accepte les montants négatifs
} {
} $this->db->commit();
else dolibarr_syslog("Paiement::Create Ok Total = $total");
{ return $this->id;
dolibarr_syslog("Paiement::Create Montant non numérique"); }
} else
} {
$this->db->rollback();
dolibarr_syslog("Paiement::Create Erreur");
return -1;
}
} }
else
{
dolibarr_syslog("Paiement::Create Erreur INSERT dans paiement");
$sql_err++;
}
}
if ( $total <> 0 && $sql_err == 0 ) // On accepte les montants négatifs
{
if ($no_commit == 0)
{
$this->db->commit();
}
dolibarr_syslog("Paiement::Create Ok Total = $total");
return $this->id;
}
else
{
if ($no_commit == 0)
{
$this->db->rollback();
}
dolibarr_syslog("Paiement::Create Erreur");
return -1;
}
}
}
/** /**
* \brief Affiche la liste des modes de paiement possible * \brief Affiche la liste des modes de paiement possible