From 560194c3b95e4eac183d0e6a1245e474fa0b6c4f Mon Sep 17 00:00:00 2001 From: teleassist <30868208+teleassist@users.noreply.github.com> Date: Mon, 30 Nov 2020 11:22:49 +0100 Subject: [PATCH 1/3] FIX #15374 : "New" doesn't clear total amounts Invoice's total amounts where not updated because of direct lines deleting in database. --- htdocs/takepos/invoice.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 1ff0db279b0..7bd15687037 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -411,17 +411,18 @@ if ($action == "delete") { if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) { $db->begin(); - - // We delete the lines - $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); + + // We delete the lines + $resdeletelines = 1; + foreach($invoice->lines as $line){ + $resdeletelines *= $invoice->deleteline($line->id); + } + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; $sql .= " WHERE ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'"; - $resql3 = $db->query($sql); + $resql1 = $db->query($sql); - if ($resql1 && $resql2 && $resql3) + if ($resdeletelines && $resql1) { $db->commit(); } @@ -429,8 +430,8 @@ if ($action == "delete") { { $db->rollback(); } - - $invoice->fetch($placeid); + + $invoice->fetch($placeid); } } } From 9ee37153f77ed142e21483854de03296fe06d8b4 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 30 Nov 2020 10:32:58 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/takepos/invoice.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 7bd15687037..323b105caed 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -411,13 +411,13 @@ if ($action == "delete") { if ($result > 0 && $invoice->statut == Facture::STATUS_DRAFT) { $db->begin(); - + // We delete the lines $resdeletelines = 1; foreach($invoice->lines as $line){ $resdeletelines *= $invoice->deleteline($line->id); } - + $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]}; $sql .= " WHERE ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'"; $resql1 = $db->query($sql); @@ -430,7 +430,7 @@ if ($action == "delete") { { $db->rollback(); } - + $invoice->fetch($placeid); } } From 7870a33fd3de524674ad2dd919929cc89132ec06 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Nov 2020 15:39:35 +0100 Subject: [PATCH 3/3] Update invoice.php --- htdocs/takepos/invoice.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 323b105caed..493202376a9 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -415,7 +415,11 @@ if ($action == "delete") { // We delete the lines $resdeletelines = 1; foreach($invoice->lines as $line){ - $resdeletelines *= $invoice->deleteline($line->id); + $tmpres = $invoice->deleteline($line->id); + if ($tmpres < 0) { + $resdeletelines = 0; + break; + } } $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".$conf->global->{'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"]};