From a2b1d96d427016496605137aef116c3b9c3670e6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 27 Aug 2019 15:42:35 +0200 Subject: [PATCH] Fix protection in cleaning invoice with transaction. Delete also extrafield lines. --- htdocs/takepos/invoice.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index a1b51e6b50b..9616085f6fb 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -267,9 +267,22 @@ if ($action == "delete") { if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) { + $db->begin(); + // We delete the lines - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "facturedet where fk_facture='".$placeid."'"; - $resql = $db->query($sql); + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "facturedet_extrafields where fk_object = ".$placeid; + $resql1 = $db->query($sql); + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "facturedet where fk_facture = ".$placeid; + $resql2 = $db->query($sql); + + if ($resql1 && $resql2) + { + $db->commit(); + } + else + { + $db->rollback(); + } $invoice->fetch($placeid); }