diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index d9fe062d..e8e2f5b6 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -99,7 +99,7 @@ class Invoice extends BaseController public function load_details1() { $id = $this->request->getPost('selectedValue'); - $where = ['isactive' => 1, 'customer_id' => (int)$id]; + $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$id]; $where['address_type'] = 1; $data['customer_billing'] = $this->get_customer_address($where, []); $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; @@ -114,7 +114,7 @@ class Invoice extends BaseController { $customer_id = $this->request->getPost('customerValue'); $address_id = $this->request->getPost('selectedValue'); - $where = ['isactive' => 1, 'customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id]; + $where = ['customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id]; $data['customer_shipping'] = $this->get_customer_address($where, []); return $this->response->setJSON(['data' => $data]); } @@ -124,11 +124,10 @@ class Invoice extends BaseController { $model = new CustomerModel(); $model->setTable('customer_addresses'); - if (!empty($select)) { - $address_details = $model->select($select)->where($where)->findAll(); - } else { - $address_details = $model->where($where)->findAll(); + if (empty($select)) { + $select = ["customer_addresses.customer_id","customer_addresses.customer_address_id","customer_addresses.first_name","customer_addresses.last_name ","customer_addresses.company","customer_addresses.email","customer_addresses.mobile_no","customer_addresses.address_type","customer_addresses.address_1","customer_addresses.address_2","customer_addresses.city","customer_addresses.state","customer_addresses.postal_code","customer_addresses.country","states.state_name","countries.country_name"]; } + $address_details = $model->select($select)->join('states', 'states.state_short_name = customer_addresses.state AND customer_addresses.country = "IN"', 'left')->join('countries', 'countries.country_short_name = customer_addresses.country', 'left')->where($where)->findAll(); return $address_details; } diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 81a3fff7..39037dbe 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -3,32 +3,26 @@

-

- - +
- +
-
" id="myForm" name="myForm" > - -
- -
+ " id="myForm" name="myForm"> +
@@ -42,7 +36,7 @@
- +
@@ -72,7 +66,6 @@
Billing Address
-
@@ -134,24 +127,24 @@
Please provide.
-
- - - -
- - +
+ + + +
+ +
@@ -206,9 +199,9 @@
Please provide.
- - - +
Please select customer.
- +
@@ -28,7 +36,7 @@
- +
@@ -71,12 +79,12 @@
- - + +
- - + +
@@ -101,16 +109,16 @@ $ii_details) : ?> - " name="item_details[]" onchange="displayBookTag(this,)" required data-toggle="select2" style="width: 249px !important;"> - " name="quantity[]" oninput="calculateInvoice(this,)" value="" /> + " name="quantity[]" oninput="calculateInvoice(this,)" value="" /> - " name="rate[]" oninput="calculateInvoice(this,)" value="" readonly /> + " name="rate[]" oninput="calculateInvoice(this,)" value="" readonly /> " name="tax[]" value="" readonly /> @@ -136,16 +144,16 @@ - - + - + @@ -312,41 +320,20 @@ `; + // cell1.innerHTML = ''; - cell2.innerHTML = ''; - cell3.innerHTML = ''; + cell2.innerHTML = ''; + cell3.innerHTML = ''; cell4.innerHTML = ''; cell5.innerHTML = ''; - cell6.innerHTML = ''; + cell6.innerHTML = ''; cell7.innerHTML = ''; cell8.innerHTML = '
'; - - // Attach the calculateInvoice function to new input fields' change events - // cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); - // cell2.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); - // cell3.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); - newRow.querySelector('.book-select').addEventListener("change", function() { - displayBookTag(this, counter); - }); $(newRow.querySelector('.book-select')).select2(); - newRow.querySelector('.quantity-input').addEventListener("input", function() { - calculateInvoice(this, counter); - }); - newRow.querySelector('.rate-input').addEventListener("input", function() { - calculateInvoice(this, counter); - }); - newRow.querySelector('.discount-amount-input').addEventListener("input", function() { - calculateInvoice(this, counter); - }); - newRow.querySelector('.discount-type-select').addEventListener("change", function() { - calculateInvoice(this, counter); - }); + + }); - // cell4.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice); - - - function displayBookTag(inputElement, counter) { var row = inputElement.parentElement.parentElement; var bookId = inputElement.value; @@ -453,9 +440,6 @@ } - - - // Define a function to calculate the grand total // Define a function to calculate the grand total function calculateGrandTotal() { var invoiceItems = []; // Create an empty array to store item details @@ -499,68 +483,7 @@ var grandTotalElement = grandTotal.toFixed(2); document.getElementById("grandtotal").value = grandTotalElement; } - - // the calculateOverallTotals function whenever you need to recalculate the totals, such as when a new item is added or an item is edited. - - - - // function calculateSubTotal() { - // var amountInputs = document.querySelectorAll('.amount-input'); - // var subTotal = 0; - // var taxInputs = document.querySelectorAll('.tax-input'); - // var taxTotal = 0; - // var discountAmountInputs = document.querySelectorAll('.discount-amount-input'); - // var discountTypeSelects = document.querySelectorAll('.discount-type-select'); - // var overallDiscount = 0; - - // amountInputs.forEach(function (input, index) { - // var amount = parseFloat(input.value) || 0; - // subTotal += amount; - - - // var tax = parseFloat(taxInputs[index].value) || 0; - // taxTotal += tax; - - // var discountType = discountTypeSelects[index].value; - // var discountAmount = parseFloat(discountAmountInputs[index].value) || 0; - - // if (discountType === '₹') { - // // Calculate discount based on ₹ - // var discountedAmount = amount - discountAmount; - // overallDiscount += discountAmount; - // } else if (discountType === '%') { - // // Calculate discount based on % - // var discountPercentage = discountAmount; - // var discountValue = (amount * discountPercentage) / 100; - // var discountedAmount = amount - discountValue; - // overallDiscount += discountValue; - // } - // }); - - // var subTotalElement = subTotal.toFixed(2); - // $("#subtotal").val(subTotalElement); - - // var taxElement = taxTotal.toFixed(2); - // $("#invoicetax").val(taxElement); - - // var overallDiscountElement = overallDiscount.toFixed(2); - // $("#discount").val(overallDiscountElement); - - // calculateGrandTotal(subTotal, taxTotal, overallDiscount); - // } - - - - // function calculateGrandTotal(subTotal, invoiceTax, discount) { - // var grandTotal = 0; - - // if (!isNaN(subTotal) && !isNaN(invoiceTax) && !isNaN(discount)) { - // grandTotal = subTotal + invoiceTax - discount; - // } - - // var grandElement = grandTotal.toFixed(2); - // $("#grandtotal").val(grandElement); - // } + @@ -569,7 +492,7 @@ function removeItem(row) { var table = document.getElementById("itemTable").getElementsByTagName("tbody")[0]; table.removeChild(row); - calculateSubTotal(); // Call the calculation function to update the totals + calculateOverallTotals(); // Call the calculation function to update the totals } // Attach the removeItem function to the Remove buttons using event delegation @@ -588,18 +511,17 @@ var cust_id = ""; var ship_addr_id = ""; if (cust_id != '') { - load_details1(ship_addr_id, cust_id); load_details2(ship_addr_id, cust_id); } - var ship_addr = ""; + var bill_addr = ""; - // $("#customerName").val(customer_id).change(); - + $("#customerName").change(function() { var cust_id = $(this).val(); var ship_addr_id = ""; load_details1(ship_addr_id, cust_id); + $('#storeShippingAddress').val(''); }); $("#loadShippingDropdown").change(function() { @@ -644,12 +566,17 @@ cm = response['data']['customer_membership']; $('#hiddenBillingAddressId').val(''); customer_billing = ""; + var customer_billing_addressDetails = []; if (cb.length > 0) { - $.each(cb, function(k, v) { - customer_billing = v.address_1 + " " + v.address_2 + ",\n" + v - .city + ",\n" + v.state + " - " + v.postal_code + ",\n" + v - .country + "." - customer_billing_id = v.customer_address_id + $.each(cb, function(k, v) { + var state = v.state_name ? v.state_name : v.state; + state = v.postal_code ? state+"-"+v.postal_code : state; + v.address_1 ? customer_billing_addressDetails.push(v.address_1 + " " + v.address_2):""; + v.city ? customer_billing_addressDetails.push(v.city):""; + state ? customer_billing_addressDetails.push(state):""; + v.country_name ? customer_billing_addressDetails.push(v.country_name) :""; + customer_billing_id = v.customer_address_id; + }); } if (cm.length > 0) { @@ -660,25 +587,17 @@ $("#schemeName").text("No Earlier Membership found"); } - - // var address_compare = bill_addr == customer_billing ? customer_billing : bill_addr - // if ((bill_addr != "") && (bill_addr != customer_billing)) { $("#storeBillingAddress").val(bill_addr).prop("readonly", false); $('#editAddressesCheckbox').prop('checked', true); } else { - $("#storeBillingAddress").val(customer_billing).prop("readonly", true); + $("#storeBillingAddress").val(customer_billing_addressDetails.join(', \n')+".").prop("readonly", true); $('#editAddressesCheckbox').prop('checked', false); } $('#hiddenBillingAddressId').val(customer_billing_id); if (cs.length > 0) { $('#loadShippingDropdown').empty(); - if (ship_addr != '') { - $("#storeShippingAddress").val(ship_addr); - } else { - $('#storeShippingAddress').val(''); - } $('#loadShippingDropdown').append($('
+
+
+ + +
+
+ + +
+
+ + +
+
-
- -
- - -
- - -
- - -
-
- - -
- - -
- - -
- +
- +
- -
+ +
- +
- -
- -
-
- Business Logo -
-
Existing Profile Picture
-

- -
+ +
+ +
+
+ Business Logo +
+
Existing Profile Picture
+

+
-
- +
+
+
@@ -108,20 +99,20 @@
-
- - -
+
- + - +
> @@ -137,9 +128,9 @@ Reset - " class="btn btn-secondary waves-effect">Cancel + " class="btn btn-secondary waves-effect">Cancel -
+ @@ -171,21 +162,22 @@ // Set the min attribute of the date input field to "1965-01-01" document.getElementById('date_of_birth').setAttribute('min', '1965-01-01'); + function validateFile(input) { const file = input.files[0]; const errorMessage = document.getElementById("error_message"); if (file) { if (file.type.startsWith("image/")) { - // It's an image file, no error - errorMessage.textContent = ""; + // It's an image file, no error + errorMessage.textContent = ""; } else { - // Invalid file type - errorMessage.textContent = "Invalid file type. Please select an image."; - input.value = ""; // Clear the input field + // Invalid file type + errorMessage.textContent = "Invalid file type. Please select an image."; + input.value = ""; // Clear the input field } } - } + } \ No newline at end of file