diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php
index a1a172da482..4a8f93a52f6 100644
--- a/htdocs/compta/paiement.php
+++ b/htdocs/compta/paiement.php
@@ -102,9 +102,8 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
if (! empty($conf->banque->enabled))
{
- // Si module bank actif, un compte est obligatoire lors de la saisie
- // d'un paiement
- if (! $_POST['accountid'])
+ // If bank module is on, account is required to enter a payment
+ if (GETPOST('accountid') <= 0)
{
$fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
$error++;
@@ -157,6 +156,16 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
}
}
+ if (! empty($conf->banque->enabled))
+ {
+ // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
+ if (GETPOST('accountid') <= 0)
+ {
+ $fiche_erreur_message = ''.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
';
+ $error++;
+ }
+ }
+
// Creation of payment line
$paiement = new Paiement($db);
$paiement->datepaye = $datepaye;
@@ -179,7 +188,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
{
$label='(CustomerInvoicePayment)';
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)';
- $result=$paiement->addPaymentToBank($user,'payment',$label,$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
+ $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank'));
if ($result < 0)
{
$errmsg=$paiement->error;
@@ -471,7 +480,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie
{
$sign=1;
if ($facture->type == 2) $sign=-1;
-
+
$arraytitle=$langs->trans('Invoice');
if ($facture->type == 2) $arraytitle=$langs->trans("CreditNotes");
$alreadypayedlabel=$langs->trans('Received');
diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php
index 00741aad4d4..e5dd9e60ea4 100644
--- a/htdocs/compta/paiement/class/paiement.class.php
+++ b/htdocs/compta/paiement/class/paiement.class.php
@@ -366,7 +366,7 @@ class Paiement extends CommonObject
/**
- * A record into bank for payment with links between this bank record and invoices of payment.
+ * Add a record into bank for payment with links between this bank record and invoices of payment.
* All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create().
*
* @param User $user Object of user making payment
@@ -384,16 +384,26 @@ class Paiement extends CommonObject
$error=0;
$bank_line_id=0;
- $this->fk_account=$accountid;
if (! empty($conf->banque->enabled))
{
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+ if ($accountid <= 0)
+ {
+ $this->error='Bad value for parameter accountid';
+ dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
+ return -1;
+ }
+
+ $this->db->begin();
+
+ $this->fk_account=$accountid;
+
+ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque");
$acc = new Account($this->db);
- $acc->fetch($this->fk_account);
+ $result=$acc->fetch($this->fk_account);
$totalamount=$this->amount;
if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
@@ -497,10 +507,19 @@ class Paiement extends CommonObject
}
}
else
- {
+ {
$this->error=$acc->error;
$error++;
}
+
+ if (! $error)
+ {
+ $this->db->commit();
+ }
+ else
+ {
+ $this->db->rollback();
+ }
}
if (! $error)
diff --git a/test/soapui/Dolibarr-soapui-project.xml b/test/soapui/Dolibarr-soapui-project.xml
index 97e6062b57d..12e54e1410c 100755
--- a/test/soapui/Dolibarr-soapui-project.xml
+++ b/test/soapui/Dolibarr-soapui-project.xml
@@ -748,7 +748,7 @@
- ?
+ dolibarrkey
?
admin
admin
@@ -757,22 +757,7 @@
all
-]]>UTF-8http://localhostdolibarr/dolibarrnew/webservices/server_supplier_invoice.php
-
-
-
-
-
- ?
- ?
- ?
- ?
- ?
-
- ?
-
-
-]]>http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl
+]]>http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl