From 5b7e6e6d8c7d208e42aa76c7cd2c3448db8dde6e Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Mon, 1 Apr 2024 14:00:36 +0530 Subject: [PATCH] invoice Datatype Int into Float : ps --- app/Controllers/Invoice.php | 20 +++++------ app/Views/invoice_form.php | 56 +++++++++++++++--------------- app/Views/invoice_list.php | 4 ++- app/Views/offline_invoice_list.php | 4 ++- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 87a77eec..6bf7e94d 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -183,6 +183,7 @@ class Invoice extends BaseController ## To insert or update the details of the invoice public function save_invoice() { + $this->logger->info("Invoice: Insert/Update Details"); try { @@ -235,11 +236,11 @@ class Invoice extends BaseController 'notes'=>$this->request->getPost('notes'), 'invoice_date' => (!empty($invdate)) ? date("Y-m-d", strtotime($invdate)) : NULL, 'due_date' => (!empty($duedate)) ? date("Y-m-d", strtotime($duedate)) : NULL, - 'subtotal' => (int)$this->request->getPost('sub_total'), - 'tax' => (int)$this->request->getPost('invoice_tax'), - 'discount' => (int)$this->request->getPost('discount'), - 'total_amount' => (int)$this->request->getPost('grand_total'), - 'shipping_charge' => ((int)$invoiceType === 1) ? (int)$this->request->getPost('shippingCharges') : NULL, + 'subtotal' => (float)$this->request->getPost('sub_total'), + 'tax' => (float)$this->request->getPost('invoice_tax'), + 'discount' => (float)$this->request->getPost('discount'), + 'total_amount' => (float)$this->request->getPost('grand_total'), + 'shipping_charge' => ((int)$invoiceType === 1) ? (float)$this->request->getPost('shippingCharges') : NULL, 'shipping_label' => ((int)$invoiceType === 1) ? $this->request->getPost('shippingChargesLabel') : NULL, 'order_number' => $this->request->getPost('order_number'), 'payment_method' => $invoice_status !== 'Draft' ? $this->request->getPost('payment_method') : NULL, // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay" @@ -250,7 +251,6 @@ class Invoice extends BaseController 'status' => $invoice_status, 'isactive' => 1 ]; - ## Based on the invoice ID, we designated Insert or Update on Details... if (empty($invoice_id)) { $data['created_by'] = (int)get_logged_user_id(); @@ -424,10 +424,10 @@ class Invoice extends BaseController $invoiceitem_arr[$x]['invoice_id'] = $id; $invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x]; $invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x]; - $invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x]; - $invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x]; - $invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x]; - $invoiceitem_arr[$x]['discount_amount'] = (int)$requestData['discount_amount'][$x]; + $invoiceitem_arr[$x]['tax'] = (float)$requestData['tax'][$x]; + $invoiceitem_arr[$x]['unit_price'] = (float)$requestData['rate'][$x]; + $invoiceitem_arr[$x]['subtotal'] = (float)$requestData['amount'][$x]; + $invoiceitem_arr[$x]['discount_amount'] = (float)$requestData['discount_amount'][$x]; $invoiceitem_arr[$x]['discount_type'] =$requestData['discount_type'][$x]; if (!empty($requestData['from_subscription'])) { $invoiceitem_arr[0]['from_subscription'] = $requestData['from_subscription']; diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 994eb475..a66e9434 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -143,11 +143,11 @@ " name="rate[]" oninput="calculateInvoice(this,)" value="" readonly /> - " name="tax[]" value="" readonly /> + " name="tax[]" value="" readonly /> - " name="amount[]" value="" readonly /> + " name="amount[]" value="" readonly /> - " name="discount_amount[]" oninput="calculateInvoice(this,)" value="" min="0"/> + " name="discount_amount[]" oninput="calculateInvoice(this,)" value="" min="0" step="0.01"/> @@ -186,7 +186,7 @@ - + @@ -224,11 +224,11 @@

Calculation

- +
- +
- > + >
- min="0" > + min="0" step="0.01">
@@ -257,21 +257,21 @@
- +
- +
- +
- +
@@ -533,7 +533,7 @@
- +
@@ -610,10 +610,10 @@ cell1.innerHTML=html; // cell1.innerHTML = ''; cell2.innerHTML = ''; - cell3.innerHTML = ''; - cell4.innerHTML = ''; - cell5.innerHTML = ''; - cell6.innerHTML = ''; + cell3.innerHTML = ''; + cell4.innerHTML = ''; + cell5.innerHTML = ''; + cell6.innerHTML = ''; cell7.innerHTML = ''; cell8.innerHTML = '
'; $(newRow.querySelector('.book-select')).select2(); @@ -667,17 +667,17 @@ cell1.innerHTML=html; if (discountType === '₹') { // Calculate discount based on ₹ - var discountedAmount = amount - discountAmount; - row.querySelector('#amount' + counter).value = amount.toFixed(2); + var discountedAmount = parseFloat(amount - discountAmount); + row.querySelector('#amount' + counter).value = parseFloat(amount.toFixed(2)); } else if (discountType === '%') { // Calculate discount based on % var discountPercentage = discountAmount; - var discountValue = (amount * discountPercentage) / 100; - var discountedAmount = amount - discountValue; - row.querySelector('#amount' + counter).value = amount.toFixed(2); + var discountValue = parseFloat((amount * discountPercentage) / 100); + var discountedAmount = parseFloat(amount - discountValue); + row.querySelector('#amount' + counter).value = parseFloat(amount.toFixed(2)); } else { // Invalid discount type - row.querySelector('#amount' + counter).value = amount.toFixed(2); // No discount applied + row.querySelector('#amount' + counter).value = parseFloat(amount.toFixed(2)); // No discount applied } } else { row.querySelector('#amount' + counter).value = ''; // Clear the amount if either quantity or rate is not a number @@ -723,16 +723,16 @@ cell1.innerHTML=html; var total = overallAmount - overallTax + shippingCharges - overallDiscount; // Update the subtotal, tax, shipping charges, discount, and total in the calculation card - var subtotalElement = overallAmount.toFixed(2); + var subtotalElement = parseFloat(overallAmount.toFixed(2)); $("#subtotal").val(subtotalElement); - var taxElement = overallTax.toFixed(2); + var taxElement = parseFloat(overallTax.toFixed(2)); $("#invoicetax").val(taxElement); - var discountElement = overallDiscount.toFixed(2); + var discountElement = parseFloat(overallDiscount.toFixed(2)); $("#discount").val(discountElement); - var totalElement = total.toFixed(2); + var totalElement = parseFloat(total.toFixed(2)); $("#grandtotal").val(totalElement); var status = document.getElementById('status').value; @@ -787,7 +787,7 @@ cell1.innerHTML=html; grandTotal -= manuallyEnteredDiscount; // Update the grand total in the UI - var grandTotalElement = grandTotal.toFixed(2); + var grandTotalElement = parseFloat(grandTotal.toFixed(2)); document.getElementById("grandtotal").value = grandTotalElement; } diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index 98557eb5..cab49ff5 100644 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -70,7 +70,9 @@ ?> - + + + diff --git a/app/Views/offline_invoice_list.php b/app/Views/offline_invoice_list.php index f6344c84..8f82f633 100644 --- a/app/Views/offline_invoice_list.php +++ b/app/Views/offline_invoice_list.php @@ -106,7 +106,9 @@ if (empty($row['order_number'])) : // Check if order_number is empty ?> - + + +