Fix transaction

This commit is contained in:
Laurent Destailleur 2019-02-25 15:09:56 +01:00
parent 7b2f4771f0
commit dde18e803d

View File

@ -372,7 +372,7 @@ class Invoices extends DolibarrApi
throw new RestException(304, $this->invoice->error); throw new RestException(304, $this->invoice->error);
} }
} }
/** /**
* Add a contact type of given invoice * Add a contact type of given invoice
* *
@ -939,9 +939,8 @@ class Invoices extends DolibarrApi
if(! DolibarrApiAccess::$user->rights->facture->creer) { if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401); throw new RestException(401);
} }
$this->db->begin();
$result = $this->invoice->fetch($id); $result = $this->invoice->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Invoice not found'); throw new RestException(404, 'Invoice not found');
@ -958,8 +957,12 @@ class Invoices extends DolibarrApi
if (! $this->invoice->paye) // protection against multiple submit if (! $this->invoice->paye) // protection against multiple submit
{ {
$this->db->begin();
$this->invoice->fetch_lines(); $this->invoice->fetch_lines();
$amount_ht = $amount_tva = $amount_ttc = array();
// Loop on each vat rate // Loop on each vat rate
$i=0; $i=0;
foreach($this->invoice->lines as $line) foreach($this->invoice->lines as $line)
@ -1009,14 +1012,14 @@ class Invoices extends DolibarrApi
} }
else else
{ {
throw new RestException(500, 'Could not set paid'); $this->db->rollback();
$this->db->rollback(); throw new RestException(500, 'Could not set paid');
} }
} }
else else
{ {
throw new RestException(500, 'Discount creation error'); $this->db->rollback();
$this->db->rollback(); throw new RestException(500, 'Discount creation error');
} }
} }