Skip to content
Snippets Groups Projects
Commit 8e2171b6 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Fix: Error management and missing transactions check

parent 59dfab9d
Branches
Tags
No related merge requests found
...@@ -102,9 +102,8 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye ...@@ -102,9 +102,8 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye
if (! empty($conf->banque->enabled)) if (! empty($conf->banque->enabled))
{ {
// Si module bank actif, un compte est obligatoire lors de la saisie // If bank module is on, account is required to enter a payment
// d'un paiement if (GETPOST('accountid') <= 0)
if (! $_POST['accountid'])
{ {
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>'; $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$error++; $error++;
...@@ -157,6 +156,16 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') ...@@ -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 = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
$error++;
}
}
// Creation of payment line // Creation of payment line
$paiement = new Paiement($db); $paiement = new Paiement($db);
$paiement->datepaye = $datepaye; $paiement->datepaye = $datepaye;
...@@ -179,7 +188,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') ...@@ -179,7 +188,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes')
{ {
$label='(CustomerInvoicePayment)'; $label='(CustomerInvoicePayment)';
if (GETPOST('type') == 2) $label='(CustomerInvoicePaymentBack)'; 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) if ($result < 0)
{ {
$errmsg=$paiement->error; $errmsg=$paiement->error;
......
...@@ -366,7 +366,7 @@ class Paiement extends CommonObject ...@@ -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(). * 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 * @param User $user Object of user making payment
...@@ -384,16 +384,26 @@ class Paiement extends CommonObject ...@@ -384,16 +384,26 @@ class Paiement extends CommonObject
$error=0; $error=0;
$bank_line_id=0; $bank_line_id=0;
$this->fk_account=$accountid;
if (! empty($conf->banque->enabled)) if (! empty($conf->banque->enabled))
{ {
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'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque"); dol_syslog("$user->id,$mode,$label,$this->fk_account,$emetteur_nom,$emetteur_banque");
$acc = new Account($this->db); $acc = new Account($this->db);
$acc->fetch($this->fk_account); $result=$acc->fetch($this->fk_account);
$totalamount=$this->amount; $totalamount=$this->amount;
if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
...@@ -501,6 +511,15 @@ class Paiement extends CommonObject ...@@ -501,6 +511,15 @@ class Paiement extends CommonObject
$this->error=$acc->error; $this->error=$acc->error;
$error++; $error++;
} }
if (! $error)
{
$this->db->commit();
}
else
{
$this->db->rollback();
}
} }
if (! $error) if (! $error)
......
...@@ -748,7 +748,7 @@ ...@@ -748,7 +748,7 @@
<ns:getSupplierInvoicesForThirdParty soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <ns:getSupplierInvoicesForThirdParty soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<authentication xsi:type="ns:authentication"> <authentication xsi:type="ns:authentication">
<!--You may enter the following 5 items in any order--> <!--You may enter the following 5 items in any order-->
<dolibarrkey xsi:type="xsd:string">?</dolibarrkey> <dolibarrkey xsi:type="xsd:string">dolibarrkey</dolibarrkey>
<sourceapplication xsi:type="xsd:string">?</sourceapplication> <sourceapplication xsi:type="xsd:string">?</sourceapplication>
<login xsi:type="xsd:string">admin</login> <login xsi:type="xsd:string">admin</login>
<password xsi:type="xsd:string">admin</password> <password xsi:type="xsd:string">admin</password>
...@@ -757,22 +757,7 @@ ...@@ -757,22 +757,7 @@
<idthirdparty xsi:type="xsd:string">all</idthirdparty> <idthirdparty xsi:type="xsd:string">all</idthirdparty>
</ns:getSupplierInvoicesForThirdParty> </ns:getSupplierInvoicesForThirdParty>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://www.dolibarr.org/ns/#getSupplierInvoicesForThirdParty"/><con:wsrmConfig version="1.2"/></con:call><con:call name="Request 1"><con:settings/><con:encoding>UTF-8</con:encoding><con:endpoint>http://localhostdolibarr/dolibarrnew/webservices/server_supplier_invoice.php</con:endpoint><con:request><![CDATA[<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.dolibarr.org/ns/"> </soapenv:Envelope>]]></con:request><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://www.dolibarr.org/ns/#getSupplierInvoicesForThirdParty"/><con:wsrmConfig version="1.2"/></con:call></con:operation></con:interface><con:interface xsi:type="con:WsdlInterface" wsaVersion="NONE" name="WebServicesDolibarrProductOrServiceBinding" type="wsdl" bindingName="{http://www.dolibarr.org/ns/}WebServicesDolibarrProductOrServiceBinding" soapVersion="1_1" anonymous="optional" definition="http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings/><con:definitionCache type="TEXT" rootPart="http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl"><con:part><con:url>http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl</con:url><con:content><![CDATA[<definitions targetNamespace="http://www.dolibarr.org/ns/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.dolibarr.org/ns/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<soapenv:Header/>
<soapenv:Body>
<ns:getSupplierInvoicesForThirdParty soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<authentication xsi:type="ns:authentication">
<!--You may enter the following 5 items in any order-->
<dolibarrkey xsi:type="xsd:string">?</dolibarrkey>
<sourceapplication xsi:type="xsd:string">?</sourceapplication>
<login xsi:type="xsd:string">?</login>
<password xsi:type="xsd:string">?</password>
<entity xsi:type="xsd:string">?</entity>
</authentication>
<idthirdparty xsi:type="xsd:string">?</idthirdparty>
</ns:getSupplierInvoicesForThirdParty>
</soapenv:Body>
</soapenv:Envelope>]]></con:request><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://www.dolibarr.org/ns/#getSupplierInvoicesForThirdParty"/></con:call></con:operation></con:interface><con:interface xsi:type="con:WsdlInterface" wsaVersion="NONE" name="WebServicesDolibarrProductOrServiceBinding" type="wsdl" bindingName="{http://www.dolibarr.org/ns/}WebServicesDolibarrProductOrServiceBinding" soapVersion="1_1" anonymous="optional" definition="http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings/><con:definitionCache type="TEXT" rootPart="http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl"><con:part><con:url>http://localhostdolibarr/dolibarrnew/webservices/server_productorservice.php?wsdl</con:url><con:content><![CDATA[<definitions targetNamespace="http://www.dolibarr.org/ns/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.dolibarr.org/ns/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types> <types>
<xsd:schema targetNamespace="http://www.dolibarr.org/ns/"> <xsd:schema targetNamespace="http://www.dolibarr.org/ns/">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment