diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 24ba63ae..3150760f 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -556,7 +556,7 @@ class Customer extends BaseController $data = [ 'first_name' => $this->request->getPost('cus_first_name'), - 'last_name' => $this->request->getPost('cus_last_name'), + 'last_name' => $this->request->getPost('cus_last_name') ? $this->request->getPost('cus_last_name') : '', 'mobile_no' => $this->request->getPost('cus_mobile_no'), 'email' => $this->request->getPost('cus_email'), 'date_of_birth' => NULL, @@ -576,7 +576,7 @@ class Customer extends BaseController $billingAddress = [ 'customer_id' => $customerId, 'first_name' => $this->request->getPost('cus_first_name'), - 'last_name' => $this->request->getPost('cus_last_name'), + 'last_name' => $this->request->getPost('cus_last_name') ? $this->request->getPost('cus_last_name') : '', 'address_type' => 1, // Billing address type 'billing_address1' => $this->request->getPost('baddress1'), 'billing_address2' => $this->request->getPost('baddress2'), @@ -589,7 +589,7 @@ class Customer extends BaseController $shippingAddress = [ 'customer_id' => $customerId, 'first_name' => $this->request->getPost('cus_first_name'), - 'last_name' => $this->request->getPost('cus_last_name'), + 'last_name' => $this->request->getPost('cus_last_name') ? $this->request->getPost('cus_last_name') : '', 'address_type' => 2, // Shipping address type 'shipping_address1' => $this->request->getPost('saddress1'), 'shipping_address2' => $this->request->getPost('saddress2'), @@ -601,10 +601,18 @@ class Customer extends BaseController // Call the method to store both addresses $result = $model->storeCustomerAddresses($billingAddress, $shippingAddress); + if($customerId){ + $cus_first_name = $this->request->getPost('cus_first_name'); + $cus_last_name = $this->request->getPost('cus_last_name'); + $name = $cus_first_name; + if ($cus_last_name !== null) { + $name .= ' ' . $cus_last_name; + } + } - if ($result) { + if ($customerId) { // Success response - $results = ['status' => true, 'message' => 'Customer and addresses saved successfully', 'cus_id' => $customerId]; + $results = ['status' => true, 'message' => 'Customer and addresses saved successfully', 'cus_id' => $customerId,'cus_name'=>$name,"billing_addr_id"=>$result['billing_addr_id'],"shipping_addr_id"=>$result['shipping_addr_id']]; } else { // Error response $results = ['status' => false, 'message' => 'Failed to save customer and addresses']; diff --git a/app/Models/CustomerModel.php b/app/Models/CustomerModel.php index 61137c40..a96343ed 100644 --- a/app/Models/CustomerModel.php +++ b/app/Models/CustomerModel.php @@ -179,6 +179,7 @@ public function storeCustomerAddresses($billingAddress, $shippingAddress) // $this->db->transStart(); // Begin transaction // Insert billing address + if(!empty($billingAddress['billing_address1'])){ $billingData = [ 'customer_id' => $billingAddress['customer_id'], 'first_name'=> $billingAddress['first_name'], @@ -192,7 +193,12 @@ public function storeCustomerAddresses($billingAddress, $shippingAddress) 'address_type' => 1 // Billing address type ]; $this->db->table('customer_addresses')->insert($billingData); + $billing_addr_id = $this->db->insertID(); + }else{ + $billing_addr_id = NULL; + } + if(!empty($shippingAddress['shipping_address1'])){ // Insert shipping address $shippingData = [ 'customer_id' => $shippingAddress['customer_id'], @@ -207,12 +213,11 @@ public function storeCustomerAddresses($billingAddress, $shippingAddress) 'address_type' => 2 // Shipping address type ]; $this->db->table('customer_addresses')->insert($shippingData); - return true; // Return true indicating successful insertion - - // Rollback transaction in case of an error - - - // Returns transaction status + $shipping_addr_id = $this->db->insertID(); + }else{ + $shipping_addr_id = NULL; + } + return ["billing_addr_id"=>$billing_addr_id,"shipping_addr_id"=>$shipping_addr_id]; // Return true indicating successful insertion } } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 4f4b4009..de400331 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -235,16 +235,16 @@ public function getJoinedData($where, $orderby = []) ->where('invoice_id', $id) ->join('customers as C','C.customer_id= invoice.customer_id','left') ->join('business as B','B.business_id = invoice.business_id','left') - ->join('customer_addresses as A','A.customer_address_id=invoice.shipping_address_id','left') - ->join('customer_addresses as S','S.customer_address_id=invoice.billing_address_id','left') + ->join('customer_addresses as A','A.customer_address_id=invoice.billing_address_id AND A.address_type = 1','left') + ->join('customer_addresses as S','S.customer_address_id=invoice.shipping_address_id AND S.address_type = 2','left') ->join('states', 'states.state_short_name = A.state AND A.country = "IN"', 'left') ->join('countries', 'countries.country_short_name = A.country', 'left') ->select('invoice.*,DATE_FORMAT(invoice.invoice_date, "%d/%m/%Y") AS formatted_invoice_date,DATE_FORMAT(invoice.due_date, "%d/%m/%Y") AS formatted_due_date ,concat(C.first_name," ",C.last_name) as customer_name,C.mobile_no,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile') ->select('B.title as company_name,B.business_logo,B.terms as company_terms,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.email as company_email,B.mobile_no as company_mobile_no') ->select('COALESCE(NULLIF(states.state_name, ""), A.state) AS customer_bill_state') ->select('COALESCE(NULLIF(states.state_name, ""), S.state) AS customer_ship_state') - ->select('concat(A.address_1," ", A.address_2) as customer_bill_address,A.postal_code as customer_bill_postal_code ,A.city as customer_bill_city, countries.country_name as customer_bill_country,A.country as bcountry,A.state as bstate') - ->select('concat(S.address_1," ", S.address_2) as customer_ship_address,S.postal_code as customer_ship_postal_code ,S.city as customer_ship_city, countries.country_name as customer_ship_country,S.country as scountry,S.state as sstate') + ->select('concat(A.address_1," ", A.address_2) as customer_bill_address,A.postal_code as customer_bill_postal_code ,A.city as customer_bill_city, countries.country_name as customer_bill_country,A.country as bcountry,A.state as bstate,A.customer_address_id as baddr_id') + ->select('concat(S.address_1," ", S.address_2) as customer_ship_address,S.postal_code as customer_ship_postal_code ,S.city as customer_ship_city, countries.country_name as customer_ship_country,S.country as scountry,S.state as sstate,S.customer_address_id as saddr_id') ->get() ->getResult(); diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index 992e12ce..5dd8c362 100644 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -92,18 +92,18 @@ public function getAllCustomerDetailsBySchemeName($schemeName) $builder = $this->db->table('subscription'); $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name,customer_addresses.mobile_no, customer_addresses.address_1,customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code,business.title as business_name,business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); - $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id'); + $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id AND customer_addresses.address_type = 2','left'); $builder->join('business', 'business.business_id = subscription.business_id'); $builder->join('books', 'books.book_id = subscription.scheme_id'); $builder->join('states', 'states.state_short_name = customer_addresses.state'); $builder->where('books.title', $schemeName); $builder->where('subscription.to_subscription >=', $currentDate); - $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 + // $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers // Fetch the query result $query = $builder->get(); -// print_r($query);die; + $customerDetails = []; if ($query->getNumRows() > 0) { @@ -159,15 +159,15 @@ public function getAllActiveCustomerDetails($selectedScheme) $builder = $this->db->table('subscription'); $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, business.address as business_address,business.city as business_city,business.state as business_state,business.postal_code as business_postal_code,books.title,from_subscription,to_subscription,business.title as business_name,business.mobile_no as business_mobile_no,states.state_name'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); - $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id'); + $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id And customer_addresses.address_type = 2','left'); $builder->join('business', 'business.business_id = subscription.business_id'); $builder->join('books', 'books.book_id = subscription.scheme_id'); $builder->join('states', 'states.state_short_name = customer_addresses.state'); // Active subscriptions only $builder->where('books.title', $schemeName); - $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 + // $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers - + $builder->groupBy('subscription.sub_id'); $query = $builder->get(); $activeCustomerDetails = []; @@ -223,15 +223,15 @@ public function getAllExpiredCustomerDetailsByScheme($schemeName) $builder = $this->db->table('subscription'); $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, states.state_name'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); - $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id'); + $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id And customer_addresses.address_type = 2','left'); $builder->join('business', 'business.business_id = subscription.business_id'); $builder->join('books', 'books.book_id = subscription.scheme_id'); - $builder->join('states', 'states.state_short_name = customer_addresses.state'); + $builder->join('states', 'states.state_short_name = customer_addresses.state','left'); $builder->where('books.title', $schemeName); $builder->where('subscription.to_subscription <', $currentDate); // Expired subscriptions only - $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 + // $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers - + $builder->groupBy('subscription.sub_id'); // Fetch the query result $query = $builder->get(); @@ -281,18 +281,19 @@ public function getAllExpiredCustomerDetailsByScheme($schemeName) public function getBothDetailsSchemeName($schemeName) { $builder = $this->db->table('subscription'); - $builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, business.address as business_address, business.city as business_city, business.state as business_state, business.postal_code as business_postal_code, books.title, states.state_name'); + $builder->select('subscription.sub_id,customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.mobile_no, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code, business.title as business_name, books.title, from_subscription, to_subscription, business.mobile_no as business_mobile_no, business.address as business_address, business.city as business_city, business.state as business_state, business.postal_code as business_postal_code, books.title, states.state_name'); $builder->join('customers', 'customers.customer_id = subscription.customer_id'); - $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id'); + $builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id','left'); $builder->join('business', 'business.business_id = subscription.business_id'); $builder->join('books', 'books.book_id = subscription.scheme_id'); - $builder->join('states', 'states.state_short_name = customer_addresses.state'); + $builder->join('states', 'states.state_short_name = customer_addresses.state','left'); $builder->where('books.title', $schemeName); $builder->where('customer_addresses.address_type', 2); // Filter by address_type 2 + $builder->groupBy('subscription.sub_id'); $builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers $query = $builder->get(); - + // print_r($this->db->getLastQuery());die; $customerDetails = []; if ($query->getNumRows() > 0) { diff --git a/app/Views/address_pdf_template.php b/app/Views/address_pdf_template.php index b9c088ab..69df92a9 100644 --- a/app/Views/address_pdf_template.php +++ b/app/Views/address_pdf_template.php @@ -51,12 +51,15 @@
customer_name ?>
- customer_bill_address." ," ?>
- customer_bill_city ?> customer_bill_state ? $value->customer_bill_state : "" ?> - customer_bill_postal_code ? " - ".$value->customer_bill_postal_code :""; ?> - customer_bill_country." ." ?>
- mobile_no." ." ?> - + customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')){ ?> + customer_ship_address ? $value->customer_ship_address." ," : "" ?>
+ customer_ship_city ? $value->customer_ship_city : "" ?> customer_ship_state ? $value->customer_bill_state : "" ?> + customer_ship_postal_code ? " - " . $value->customer_ship_postal_code : ""; ?> + customer_ship_country ? $value->customer_ship_country . "." : $value->scountry ?>
+ saddr_id === null || $value->saddr_id === '') { + echo $value->shipping_address ? '

'.$value->shipping_address.'

' : ''; + } ?> + mobile_no ? $value->mobile_no." ." : "" ?>
diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index f12320a7..2f4ca518 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -235,62 +235,65 @@

Calculation

-
- - -
- -
- - -
+
+ +
-
- -
- - - > - -
-
- - - step="0.01"> - -
+ +
+ + +
+
+ +
> +
+ + + > + +
+
+ + + min="0"> + +
+
+ +
-
+
-
-
- - -
+
+
+ + +
-
- - -
-
- - -
+
+ + +
+ +
+ + +
@@ -308,31 +311,8 @@
- - -
- - - - - - - - - - - - - - -
- - - - - - - + + + + + + + + + + + + + + @@ -929,7 +932,7 @@ if (cust_id == '0') { $('#customerModal').modal('show'); - } else { + }else if(cust_id != ''){ $('#editAddressesCheckbox').prop('checked', false); $("#storeBillingAddress").prop("readonly", false); $("#storeShippingAddress").prop("readonly", false); @@ -938,6 +941,11 @@ $('#cus_first_name').val(""); $('#cus_last_name').val(""); $('#cus_email').val(""); + $('#baddress1').val("");$('#baddress2').val("");$('#bcountry').val("");$('#bstate').val("");$('#bcity').val("");$('#bzip').val(""); + $('#saddress1').val("");$('#saddress2').val("");$('#scountry').val("");$('#sstate').val("");$('#scity').val("");$('#szip').val(""); + $("#emailValidationMessage").text(""); + $("#mobileValidationMessage").text(""); + $('#addressCopiedAsShipping').prop('checked', false); $('.save-invoice-customer').prop('disabled', false); $.ajax({ type: "POST", @@ -1031,6 +1039,7 @@ // membership ajax call function get_customer_membership_details(cust_id) { + if (parseInt(cust_id) > 0) { $.ajax({ type: "POST", url: "", @@ -1056,6 +1065,7 @@ alert("Error fetching address."); } }); + } } @@ -1260,51 +1270,55 @@ return false; } } + + - - - - $('#closeCustomerModal').click(function() { + \ No newline at end of file diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index f6b7f221..38ed7232 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -218,29 +218,31 @@ - customer_name ?>
- customer_bill_address){ ?> + customer_name ?>
+ customer_bill_address && ($value->baddr_id !== null || $value->baddr_id !== '')){ ?> customer_bill_address ? $value->customer_bill_address." ," : ""?>
customer_bill_city ? $value->customer_bill_city : "" ?> customer_bill_state ? $value->customer_bill_state : "" ?> customer_bill_postal_code ? " - " . $value->customer_bill_postal_code : ""; ?> customer_bill_country ? $value->customer_bill_country . "." : $value->bcountry ?>
- mobile_no ? $value->mobile_no." ." : "" ?> - baddr_id === null || $value->baddr_id === '') { echo $value->billing_address ? '

'.$value->billing_address.'

' : ''; - echo $value->mobile_no ? $value->mobile_no." ." : ""; } endforeach; ?> + } ?> + mobile_no ? $value->mobile_no." ." : "" ?> + customer_name ?>
- customer_ship_address){ ?> + customer_ship_address && ($value->saddr_id !== null || $value->saddr_id !== '')){ ?> customer_ship_address ? $value->customer_ship_address." ," : "" ?>
customer_ship_city ? $value->customer_ship_city : "" ?> customer_ship_state ? $value->customer_bill_state : "" ?> customer_ship_postal_code ? " - " . $value->customer_ship_postal_code : ""; ?> customer_ship_country ? $value->customer_ship_country . "." : $value->scountry ?>
- mobile_no ? $value->mobile_no." ." : "" ?> - saddr_id === null || $value->saddr_id === '') { echo $value->shipping_address ? '

'.$value->shipping_address.'

' : ''; - echo $value->mobile_no ? $value->mobile_no." ." : ""; } endforeach; ?> + } ?> + mobile_no ? $value->mobile_no." ." : "" ?> +