From 083af0898547394abe7ef364f793b4d278c5cb44 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 28 Jun 2024 16:43:21 +0200 Subject: [PATCH 1/6] Fix #29725 Doesn't create new invoice after payment --- htdocs/takepos/ajax/ajax.php | 12 ++++++++++++ htdocs/takepos/index.php | 38 +++++++++++++++++++++++++++++++----- htdocs/takepos/invoice.php | 1 + 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index cb4b489206c79..7925c484a7f8f 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -444,4 +444,16 @@ $printer = new dolReceiptPrinter($db); $printer->sendToPrinter($object, getDolGlobalString('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term), getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$term)); +} elseif ($action == 'createNewInvoice') { + top_httphead('application/json'); + + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + + $invoice = new Facture($db); + $result = $invoice->create($user); + if ($result > 0) { + echo json_encode(array('invoiceid' => $invoice->id)); + } else { + echo json_encode(array('error' => 'Failed to create invoice')); + } } diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 74efda87a5a58..b1abf7be94e12 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -540,16 +540,44 @@ function ClickProduct(position, qty = 1) { console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty+" invoicdeid="+invoiceid); if (idproduct=="") return; // Call page invoice.php to generate the section with product lines - $("#poslines").load("invoice.php?action=addline&token=&place="+place+"&idproduct="+idproduct+"&qty="+qty+"&invoiceid="+invoiceid, function() { - - }); + if (invoiceid == "") { + createNewInvoice(idproduct, qty); + } else { + $.getJSON('/takepos/ajax/ajax.php?action=getInvoice&token=&id=' + invoiceid, function (data) { + if (data['paye'] == 1 && data['status'] == ) { + console.log("Creating new invoice"); + createNewInvoice(idproduct, qty); + } else if (data['paye'] == 0 && data['status'] == ) { + console.log("Adding product to invoice"); + addProductToInvoice(idproduct, qty, invoiceid); + } else if (data['paye'] == 0 && data['status'] == ) { + console.log("Invoice not completely paid"); + alert('Invoice not completly paid !'); + + } + }); + } } ClearSearch(false); } +function createNewInvoice(idproduct, qty) { + $.getJSON('/takepos/ajax/ajax.php?action=createNewInvoice&token=', function (data) { + invoiceid = data['invoiceid']; + $("#invoiceid").val(invoiceid); + addProductToInvoice(idproduct, qty, invoiceid); + }); +} + +function addProductToInvoice(idproduct, qty, invoiceid) { + $("#poslines").load("invoice.php?action=addline&token=&place="+place+"&idproduct="+idproduct+"&qty="+qty+"&invoiceid="+invoiceid, function() { + + }); +} + function ChangeThirdparty(idcustomer) { console.log("ChangeThirdparty"); // Call page list.php to change customer diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3eb2184291be7..dcae97d5a72b0 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -569,6 +569,7 @@ function fail($message) $prod = new Product($db); $prod->fetch($idproduct); + $customer = new Societe($db); $customer->fetch($invoice->socid); From 7b64ad7c62906663fabea6b1959f5b2af03c05bb Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Tue, 16 Jul 2024 00:54:03 +0200 Subject: [PATCH 2/6] fix phan and precomit errors --- htdocs/takepos/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index b1abf7be94e12..28d9dcaacfed5 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -545,14 +545,14 @@ function ClickProduct(position, qty = 1) { } else { $.getJSON('/takepos/ajax/ajax.php?action=getInvoice&token=&id=' + invoiceid, function (data) { if (data['paye'] == 1 && data['status'] == ) { - console.log("Creating new invoice"); + console.log("Creating new invoice"); createNewInvoice(idproduct, qty); } else if (data['paye'] == 0 && data['status'] == ) { console.log("Adding product to invoice"); addProductToInvoice(idproduct, qty, invoiceid); } else if (data['paye'] == 0 && data['status'] == ) { console.log("Invoice not completely paid"); - alert('Invoice not completly paid !'); + alert('Invoice not completely paid !'); } }); From 222016cfaf8a3bc44932bdacec73b3b01d6a9906 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 18 Jul 2024 01:22:39 +0200 Subject: [PATCH 3/6] Update index.php --- htdocs/takepos/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 28d9dcaacfed5..9c5433fed7809 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -548,7 +548,7 @@ function ClickProduct(position, qty = 1) { console.log("Creating new invoice"); createNewInvoice(idproduct, qty); } else if (data['paye'] == 0 && data['status'] == ) { - console.log("Adding product to invoice"); + console.log("Adding product to invoice"); addProductToInvoice(idproduct, qty, invoiceid); } else if (data['paye'] == 0 && data['status'] == ) { console.log("Invoice not completely paid"); From 3d3de6deaaa7ae4569cfe4858100cfcb6e526efd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 18 Jul 2024 01:37:16 +0200 Subject: [PATCH 4/6] Update index.php --- htdocs/takepos/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 9c5433fed7809..d93af19ab379e 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -551,7 +551,7 @@ function ClickProduct(position, qty = 1) { console.log("Adding product to invoice"); addProductToInvoice(idproduct, qty, invoiceid); } else if (data['paye'] == 0 && data['status'] == ) { - console.log("Invoice not completely paid"); + console.log("Invoice not completely paid"); alert('Invoice not completely paid !'); } From dacc6ef586cf581e2ddd2eda7c6e7ee558191e36 Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Fri, 26 Jul 2024 17:38:42 +0200 Subject: [PATCH 5/6] Fix phan errors --- htdocs/takepos/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index d93af19ab379e..a76833b7069f1 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -553,7 +553,6 @@ function ClickProduct(position, qty = 1) { } else if (data['paye'] == 0 && data['status'] == ) { console.log("Invoice not completely paid"); alert('Invoice not completely paid !'); - } }); } From 07ed11337693f1c45843df087d223e33ac125fde Mon Sep 17 00:00:00 2001 From: Lamrani Abdel Date: Mon, 5 Aug 2024 12:46:54 +0200 Subject: [PATCH 6/6] remove whitespace --- htdocs/takepos/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index a76833b7069f1..9ff8a446cfadf 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -553,7 +553,7 @@ function ClickProduct(position, qty = 1) { } else if (data['paye'] == 0 && data['status'] == ) { console.log("Invoice not completely paid"); alert('Invoice not completely paid !'); - } + } }); } }