diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 00661747..edd66cb4 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -49,7 +49,7 @@ $routes->get('dashboard/', 'Home::index'); # Users Routes $routes->get("user_list/", "Users::index"); -$routes->get("user_page/(:any)", "Users::user_page/$1"); +$routes->get("user_page/(:any)/(:any)", "Users::user_page/$1/$2"); $routes->post("insert_users", "Users::insert_users"); $routes->get('users/fetch_event_names', 'Users::fetch_event_names'); diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php index 6a8c9c3f..1faa7b55 100644 --- a/app/Controllers/ApiIntegration.php +++ b/app/Controllers/ApiIntegration.php @@ -742,8 +742,10 @@ class ApiIntegration extends ResourceController $billing_addr = NULL;$shipping_addr = NULL; $lineitems_array = []; $billing_array = []; $shipping_array = []; - $lineitems_subtotal = 0; $lineitems_tax = 0; - $lineitems_discount = 0; $lineitems_total=0; + $lineitems_subtotal = 0; ## for lineitem product wise price total + $lineitems_tax = 0; ## for lineitem product wise tax + $lineitems_discount = 0; ## for lineitem product wise discount + $lineitems_total=0; ## for lineitem grand total // $line_items = ; @@ -794,7 +796,8 @@ class ApiIntegration extends ResourceController } } - $subtotal = (float)$lineitems_subtotal + (float)$records['shipping_total']; + // $subtotal = (float)$lineitems_subtotal + (float)$records['shipping_total']; + $subtotal = (float)$lineitems_subtotal; $tax = $lineitems_tax + (float)$records['shipping_tax']; $total = ($lineitems_total)+(float)$records['shipping_total'] + (float)$records['shipping_tax']; $final_status = ''; @@ -830,7 +833,8 @@ class ApiIntegration extends ResourceController $invoice_data['subtotal']=(int)$subtotal; $invoice_data['tax']=(int)$tax; $invoice_data['discount']=(int)$lineitems_discount; - $invoice_data['total_amount']= $records['total']; + $invoice_data['total_amount']= round($records['total']); + $invoice_data['exact_total_amount']= (float)$records['total']; $invoice_data['payment_status']=$records['status']; $invoice_data['order_number']=$records['order_key']; $invoice_data['payment_method']=$records['payment_method_title']; diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index aea543f5..d206e80a 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -10,6 +10,7 @@ use App\Helpers\NotificationHelper; use Mpdf\Mpdf; use Dompdf\Dompdf; + class Invoice extends BaseController { ## For Invoice Listing.. @@ -22,10 +23,10 @@ class Invoice extends BaseController if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); - $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>1]; + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1, 'I.invoice_type' => 1]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); - $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>1]; + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL, 'I.invoice_type' => 1]; } $model = new InvoiceModel(); @@ -46,10 +47,10 @@ class Invoice extends BaseController if (!empty($session_role) && $session_role !== "sadmin") { $this->logger->info("Invoice: Listing In Admin BID = " . $session_bid); - $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1,'I.invoice_type'=>1]; + $where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1, 'I.invoice_type' => 1]; } else { $this->logger->info("Invoice: Listing In the Super-Admin "); - $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>1]; + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL, 'I.invoice_type' => 1]; } $model = new InvoiceModel(); @@ -67,10 +68,10 @@ class Invoice extends BaseController { helper('session'); helper('financial_year_helper'); - + $model = new InvoiceModel(); $where = ['business_id' => (int)get_business_id()]; - + // Get customer names for the dropdown, events details, and books details $data['customers'] = $model->getData('customers', $where); $data['events'] = $model->getData('events', $where); @@ -87,17 +88,17 @@ class Invoice extends BaseController } elseif ($id !== '0') { $this->logger->info("Book Invoice: In Edit Details ID =" . $id); $data['page_name'] = 'Edit Book Invoice Details'; - $data['invoice_type'] ='1'; - $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); + $data['invoice_type'] = '1'; + $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; - $where = ['address_type'=>2,'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; + $where = ['address_type' => 2, 'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; $data['customer_shipping_arr'] = $this->get_customer_address($where, $select); $data['invoice_item_details'] = $this->get_invoice_item($id); } - // print_r($data['invoice_details']);die; + // print_r($data['invoice_details']);die; $this->render_page('invoice_form', $data); } - + public function new_subscription_invoice($id = '0') { helper('session'); @@ -105,7 +106,7 @@ class Invoice extends BaseController $data['financial_year'] = get_financial_year(); $model = new InvoiceModel(); $where = ['business_id' => (int)get_business_id()]; - + // Get customer names for the dropdown, events details, and subscription books details $data['customers'] = $model->getData('customers', $where); $data['events'] = $model->getData('events', $where); @@ -114,28 +115,28 @@ class Invoice extends BaseController if ($id === '0') { $this->logger->info("Subscription Invoice: In Add Page"); $data['page_name'] = 'Add Subscription Invoice Details'; - $data['invoice_type'] ='2'; + $data['invoice_type'] = '2'; $data['invoice_details'] = []; $data['invoice_item_details'] = []; } elseif ($id !== '0') { $this->logger->info("Subscription Invoice: In Edit Page ID =" . $id); $data['page_name'] = 'Edit Subscription Invoice Details'; - $data['invoice_type'] ='2'; + $data['invoice_type'] = '2'; $data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first(); $select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"]; - $where = ['address_type'=>2,'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; + $where = ['address_type' => 2, 'customer_addresses.isactive' => 1, 'customer_addresses.customer_id' => (int)$data['invoice_details']['customer_id']]; $data['customer_shipping_arr'] = $this->get_customer_address($where, $select); $data['invoice_item_details'] = $this->get_invoice_item($id); } - + $this->render_page('invoice_form', $data); } - + ## For Ajax Call To Fetch/Retrive Membership Details Only Based On Customer... public function get_customer_membership_details() { $customer_id = $this->request->getPost('customer_id'); - $data['customer_membership'] = $this->get_customer_membership("membership",(int)$customer_id); + $data['customer_membership'] = $this->get_customer_membership("membership", (int)$customer_id); return $this->response->setJSON(['data' => $data]); } @@ -168,22 +169,23 @@ class Invoice extends BaseController $model = new CustomerModel(); $model->setTable('customer_addresses'); 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"]; + $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; } - public function get_customer_membership($category,$id){ + public function get_customer_membership($category, $id) + { $model = new InvoiceModel(); - $result = $model->getMembershipListForCustomer($category,$id); + $result = $model->getMembershipListForCustomer($category, $id); return $result; } ## To insert or update the details of the invoice public function save_invoice() { - + $this->logger->info("Invoice: Insert/Update Details"); try { @@ -204,7 +206,7 @@ class Invoice extends BaseController $requestData = $this->request->getPost(); $itemid = $requestData['invoice_child_id']; $count = count($itemid); - $scheme_id = null; + $scheme_id = null; if ($count > 0) { for ($x = 0; $x < $count; $x++) { if (!empty($requestData['item_details'][$x])) { @@ -214,26 +216,26 @@ class Invoice extends BaseController } // $now = date('Y-m-d'); // $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id,'S.scheme_id' => $scheme_id,'I.status' => 'Approved','I.isactive' => 1,"S.to_subscription <= "=>$now]; - $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id,'S.scheme_id' => $scheme_id,'I.status' => 'Approved','I.isactive' => 1]; + $get_exists_subscription_where = ['S.customer_id' => (int)$customer_id, 'S.scheme_id' => $scheme_id, 'I.status' => 'Approved', 'I.isactive' => 1]; $get_exists_subscription_dtls = $model->existsSubscriptionDetails($get_exists_subscription_where); - + if ($get_exists_subscription_dtls) { // session()->setFlashdata('success', 'This Scheme Already Existing in this Customer.'); $this->logger->info($msg_flag_name . ": This Scheme Already Existing in this Customer. "); $renewal = 1; } } - + ## Array Formation For Invoice Details.. $data = [ 'invoice_number' => $this->request->getPost('invoice_number'), - 'invoice_type'=> $this->request->getPost('invoice_type'), + 'invoice_type' => $this->request->getPost('invoice_type'), 'customer_id' => $customer_id, 'billing_address_id' => (int)$this->request->getPost('billing_address_id'), 'billing_address' => $this->request->getPost('billing_address'), 'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'), 'shipping_address' => $this->request->getPost('shipping_address'), - 'notes'=>$this->request->getPost('notes'), + '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' => (float)$this->request->getPost('sub_total'), @@ -242,133 +244,131 @@ class Invoice extends BaseController 'exact_total_amount' => (float)$this->request->getPost('exact_total_amount'), 'total_amount' => (int)$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, + '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" 'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed." - 'payment_note'=> $this->request->getPost('payment_note'), + 'payment_note' => $this->request->getPost('payment_note'), 'event_id' => (int)$this->request->getPost('event_id'), 'business_id' => (int)get_business_id(), '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(); if ($model->insert($data, 'invoices')) { $invoice_id = $model->insertID(); - session()->setFlashdata('success', $msg_flag_name.'has been added successfully.'); - $this->logger->info($msg_flag_name.": has been added successfully. Inserted ID = " . $invoice_id); + session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.'); + $this->logger->info($msg_flag_name . ": has been added successfully. Inserted ID = " . $invoice_id); // If it's a subscription invoice, also store data in the 'subscription' table - + } else { - session()->setFlashdata('error', $msg_flag_name.'could not be added. Please try again.'); - $this->logger->error($msg_flag_name.": Err Occur could not be added. Please try again."); + session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.'); + $this->logger->error($msg_flag_name . ": Err Occur could not be added. Please try again."); } - } else { $data['updated_by'] = (int)get_logged_user_id(); if ($model->update($invoice_id, $data)) { // echo $model->getLastQuery();die; - session()->setFlashdata('success', $msg_flag_name.'has been updated successfully.'); - $this->logger->info($msg_flag_name.": has been updated successfully. Updated ID = " . $invoice_id); + session()->setFlashdata('success', $msg_flag_name . 'has been updated successfully.'); + $this->logger->info($msg_flag_name . ": has been updated successfully. Updated ID = " . $invoice_id); } else { - session()->setFlashdata('error', $msg_flag_name.'update failed. Please try again.'); - $this->logger->error($msg_flag_name.": Err Failed to update ID =" . $invoice_id); + session()->setFlashdata('error', $msg_flag_name . 'update failed. Please try again.'); + $this->logger->error($msg_flag_name . ": Err Failed to update ID =" . $invoice_id); } } $requestData = $this->request->getPost(); - if($this->request->getPost('next_id')){ - ## Array Formation For Invoice Numbering Format Details.. - $update_invoice_numbering = [ - 'id' => 1, - 'id_formating' => get_financial_year(), - 'next_id' => (int)$this->request->getPost('next_id'), - 'business_id' => (int)get_business_id(), - 'updated_by' => get_logged_user_id() - ]; - $this->update_number_formatting($update_invoice_numbering);} + if ($this->request->getPost('next_id')) { + ## Array Formation For Invoice Numbering Format Details.. + $update_invoice_numbering = [ + 'id' => 1, + 'id_formating' => get_financial_year(), + 'next_id' => (int)$this->request->getPost('next_id'), + 'business_id' => (int)get_business_id(), + 'updated_by' => get_logged_user_id() + ]; + $this->update_number_formatting($update_invoice_numbering); + } ## For Invoice Item Details Insert/Update.. $this->save_invoice_item($invoice_id, $requestData, (int)$this->request->getVar('product')); ## Subscription.. if ((int)$invoiceType === 2) { - + // Loop through invoice items and store them in the 'subscription' table $subscriptionModel = new InvoiceModel(); // Replace with your actual model $invoiceItems = $this->get_invoice_item($invoice_id); - + foreach ($invoiceItems as $item) { - + $product_id = $item['product']; $from_sub_date = $item['from_subscription']; $to_sub_date = $item['to_subscription']; - - + + $subscription_data = [ 'customer_id' => (int)$customer_id, 'invoice_id' => $invoice_id, 'scheme_id' => $product_id, - 'from_subscription'=>$from_sub_date, - 'to_subscription'=> $to_sub_date, + 'from_subscription' => $from_sub_date, + 'to_subscription' => $to_sub_date, 'business_id' => get_business_id(), - 'created_by' =>get_logged_user_id(), + 'created_by' => get_logged_user_id(), 'is_renew' => $renewal ]; if ($invoice_status == 'Draft') { - $get_subscription_draft_dtl_where = ['S.customer_id'=>$customer_id,'I.status'=>$invoice_status]; - // $get_subscription_draft_dtl_id = $model->InactiveSubscriptionDraftDetails($get_subscription_draft_dtl_where,get_logged_user_id()); - // $this->logger->info($msg_flag_name.": has been Inactived. Inv ID = ".implode(", ", $get_subscription_draft_dtl_id)); - $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where,get_logged_user_id()); - $this->logger->info($msg_flag_name.": has been Deleted. Inv ID = ".implode(", ", $get_subscription_draft_dtl_id)); - // $subscriptionModel->insertSubscriptionData($subscription_data); + $get_subscription_draft_dtl_where = ['S.customer_id' => $customer_id, 'I.status' => $invoice_status]; + // $get_subscription_draft_dtl_id = $model->InactiveSubscriptionDraftDetails($get_subscription_draft_dtl_where,get_logged_user_id()); + // $this->logger->info($msg_flag_name.": has been Inactived. Inv ID = ".implode(", ", $get_subscription_draft_dtl_id)); + $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id()); + $this->logger->info($msg_flag_name . ": has been Deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id)); + // $subscriptionModel->insertSubscriptionData($subscription_data); + } else { + // Check if there is a draft entry for the customer_id and scheme_id + $get_subscription_draft_dtl_where = [ + 'S.customer_id' => $customer_id, + 'S.scheme_id' => $scheme_id, // Assuming scheme_id is available here + 'I.status' => 'Draft' + ]; + + $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id()); + + $this->logger->info($msg_flag_name . ": Draft entry has been deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id)); + + // Now insert the new entry + + } } - else{ - // Check if there is a draft entry for the customer_id and scheme_id - $get_subscription_draft_dtl_where = [ - 'S.customer_id' => $customer_id, - 'S.scheme_id' => $scheme_id, // Assuming scheme_id is available here - 'I.status' => 'Draft' - ]; - - $get_subscription_draft_dtl_id = $model->deleteSubscriptionDraftDetails($get_subscription_draft_dtl_where, get_logged_user_id()); - - $this->logger->info($msg_flag_name . ": Draft entry has been deleted. Inv ID = " . implode(", ", $get_subscription_draft_dtl_id)); - - // Now insert the new entry - - } - } - $subscriptionModel->insertSubscriptionData($subscription_data); + $subscriptionModel->insertSubscriptionData($subscription_data); } ## Notification For Approve.. - $this->logger->info($msg_flag_name.": ID = " . $invoice_id.", Status =".$invoice_status); + $this->logger->info($msg_flag_name . ": ID = " . $invoice_id . ", Status =" . $invoice_status); if ($invoice_status == 'Approved' && $invoice_id != "") { - $this->logger->info($msg_flag_name.": in ".$invoice_status.". ID = " . $invoice_id); + $this->logger->info($msg_flag_name . ": in " . $invoice_status . ". ID = " . $invoice_id); $this->approve_notifications((int)$invoice_id); } - } catch (\Exception $e) { - $this->logger->error($msg_flag_name.": Err Occur =" . $e->getMessage()); + $this->logger->error($msg_flag_name . ": Err Occur =" . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } - - - if ($invoiceType === '2') { - $this->logger->info(session()->getFlashdata()); - // If the invoice_type is 2 (subscription invoice), redirect to the subscription list. - return redirect()->route('subscribers_list'); // Adjust the route name as needed. - } else { - // For other invoice types, redirect to the invoice list. - $this->logger->info(session()->getFlashdata()); - return redirect()->route('offline_invoice'); // Adjust the route name as needed. - } + + + if ($invoiceType === '2') { + $this->logger->info(session()->getFlashdata()); + // If the invoice_type is 2 (subscription invoice), redirect to the subscription list. + return redirect()->route('subscribers_list'); // Adjust the route name as needed. + } else { + // For other invoice types, redirect to the invoice list. + $this->logger->info(session()->getFlashdata()); + return redirect()->route('offline_invoice'); // Adjust the route name as needed. + } } ## For Updating Events Details .. @@ -414,7 +414,7 @@ class Invoice extends BaseController $where = ['isactive' => 1, 'invoice_id' => (int)$id]; // $model->inactiveMissingInvoiceItemDetails($where, $missingValues); $model->deleteMissingInvoiceItemDetails($where, $missingValues); - $this->logger->info("Child Item Details : has been Deleted. Inv Child ID = ".implode(", ", $missingValues)); + $this->logger->info("Child Item Details : has been Deleted. Inv Child ID = " . implode(", ", $missingValues)); } } } @@ -423,7 +423,7 @@ class Invoice extends BaseController $invoiceitem_arr = []; if ($count > 0) { for ($x = 0; $x < $count; $x++) { - if(!empty($requestData['item_details'][$x])){ + if (!empty($requestData['item_details'][$x])) { $invoiceitem_arr[$x]['invoice_id'] = $id; $invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x]; $invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x]; @@ -431,11 +431,11 @@ class Invoice extends BaseController $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]; + $invoiceitem_arr[$x]['discount_type'] = $requestData['discount_type'][$x]; if (!empty($requestData['from_subscription'])) { $invoiceitem_arr[0]['from_subscription'] = $requestData['from_subscription']; } - + if (!empty($requestData['to_subscription'])) { $invoiceitem_arr[0]['to_subscription'] = $requestData['to_subscription']; } @@ -531,25 +531,26 @@ class Invoice extends BaseController // Redirect back to the invoice list return redirect()->route('offline_invoice'); } - public function subscription_inactive(){ + public function subscription_inactive() + { $model = new InvoiceModel(); $details = $model->subscription_inactive(); $now = date('d-m-Y'); - if(strtolower(gettype($details)) == "string"){ + if (strtolower(gettype($details)) == "string") { $this->logger->info("Subscription Inactive : " . $details); - $result = $details ; - }else{ - $this->logger->info("Subscription Inactive : " .count($details) . " Subscription Records ". json_encode($details)); - $success_rating = isset($details['success_rating'])?$details['success_rating']:0; - $error_rating = isset($details['error_rating'])?$details['error_rating']:0; - $result = "Total ". count($details) . " Subscription Records.\n success rating = ".$success_rating."\n fail rating = ".$error_rating ."\n Note : Check Your Log File"; + $result = $details; + } else { + $this->logger->info("Subscription Inactive : " . count($details) . " Subscription Records " . json_encode($details)); + $success_rating = isset($details['success_rating']) ? $details['success_rating'] : 0; + $error_rating = isset($details['error_rating']) ? $details['error_rating'] : 0; + $result = "Total " . count($details) . " Subscription Records.\n success rating = " . $success_rating . "\n fail rating = " . $error_rating . "\n Note : Check Your Log File"; } - return $now." ".$result; + return $now . " " . $result; } public function approve_notifications($invoice_id) { - $this->logger->info("Approve Notifications : ID ".$invoice_id); + $this->logger->info("Approve Notifications : ID " . $invoice_id); $model = new InvoiceModel(); $where = ['I.business_id' => (int)get_business_id(), 'I.invoice_id' => $invoice_id, 'I.isactive' => 1]; $details = $model->getDetailForApproveNotifications($where); @@ -565,15 +566,15 @@ class Invoice extends BaseController $tax = ""; $total_amount = ""; $payment_method = ""; - $business_name= ""; - $business_address= ""; - $business_city= ""; - $business_state= ""; - $business_postal_code= ""; - $business_email= ""; - $business_mobile_no= ""; + $business_name = ""; + $business_address = ""; + $business_city = ""; + $business_state = ""; + $business_postal_code = ""; + $business_email = ""; + $business_mobile_no = ""; if (isset($details)) { - $this->logger->info("Invoice: approve notification Request data type = ".gettype($details)); + $this->logger->info("Invoice: approve notification Request data type = " . gettype($details)); } helper('notification'); $notification = new NotificationHelper(); @@ -587,18 +588,17 @@ class Invoice extends BaseController $recipient_mobile = $rec['customer_mobile']; $subtotal = $rec['subtotal']; $tax = $rec['tax']; - $invoiceDate=$rec['invoice_date']; - + $invoiceDate = $rec['invoice_date']; + $total_amount = $rec['total_amount']; $payment_method = $rec['payment_method']; - $business_name= $rec['business_name']; - $business_address= $rec['business_address']; - $business_city= $rec['business_city']; - $business_state= $rec['business_state']; - $business_postal_code= $rec['business_postal_code']; - $business_email= $rec['business_email']; - $business_mobile_no= $rec['business_mobile_no']; - + $business_name = $rec['business_name']; + $business_address = $rec['business_address']; + $business_city = $rec['business_city']; + $business_state = $rec['business_state']; + $business_postal_code = $rec['business_postal_code']; + $business_email = $rec['business_email']; + $business_mobile_no = $rec['business_mobile_no']; } $records['invoice_order_number'] = $reference_number; $records['invoice_serial_number'] = $invoice_serial_number; @@ -614,20 +614,18 @@ class Invoice extends BaseController // view('approve_template',$records); // $this->logger->info("Approve : Request data = ".json_encode($records)); // view('approve_template',$records); - + $records['template_name'] = 'approve_template'; $records['item'] = $details['item']; // print_r($records['item']);die; - $lineitem_html=""; + $lineitem_html = ""; foreach ($records['item'] as $inv) { // print_r($item->title);die; - $lineitem_html.='
'.$inv->title. ' x ' .$inv->quantity .' => ' .$inv->subtotal.'
'; - - + $lineitem_html .= '' . $inv->title . ' x ' . $inv->quantity . ' => ' . $inv->subtotal . '
'; } - // print_r($title);die; + // print_r($title);die; $records['subject'] = $invoice_serial_number . " - Approval Notification"; - + $records['description'] = " @@ -655,11 +653,11 @@ class Invoice extends BaseController "; - - // print_r($records['description']);die; - $url = base_url("download_invoice_pdf/" . md5($invoice_id)); -$encodedUrl = urlencode($url); - $template = "Dear " . $recipient_name . ",\r\r\n\nYour Invoice has been generated.\n\nDetails:\r\n- Invoice Date: " . $invoiceDate . "\r\n- Invoice Number: " . $invoice_serial_number . "\r\n- Click here to download the Invoice: " . base_url("download_invoice_pdf/" .$encodedUrl); + + // print_r($records['description']);die; + $url = base_url("download_invoice_pdf/" . md5($invoice_id)); + $encodedUrl = urlencode($url); + $template = "Dear " . $recipient_name . ",\r\r\n\nYour Invoice has been generated.\n\nDetails:\r\n- Invoice Date: " . $invoiceDate . "\r\n- Invoice Number: " . $invoice_serial_number . "\r\n- Click here to download the Invoice: " . base_url("download_invoice_pdf/" . $encodedUrl); $params = (object) Null; $params->number = (int)'91' . $recipient_mobile; @@ -667,10 +665,10 @@ $encodedUrl = urlencode($url); $params->message = $template; $params->instance_id = $_ENV['WAAI_INSTANCE']; $params->access_token = $_ENV['WAAI_TOKEN']; - $this->logger->info("Approve notification Email Request data = ".json_encode($records)); + $this->logger->info("Approve notification Email Request data = " . json_encode($records)); $email_result = $notification->sendEmail($records); $this->logger->info("Approve notification Email Response = " . json_encode($email_result)); - $this->logger->info("Approve notification Whatsapp Request data = ".json_encode($params)); + $this->logger->info("Approve notification Whatsapp Request data = " . json_encode($params)); $whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params); $this->logger->info("Approve notification Whatsapp Response = " . json_encode($whatsapp_result)); } @@ -682,47 +680,46 @@ $encodedUrl = urlencode($url); // Fetch the invoice data based on $invoice_id $model = new InvoiceModel(); $data = $model->getInvoiceData($id); - $invoiceItems = $model->getInvoiceItems($id,'groupby'); + $invoiceItems = $model->getInvoiceItems($id, 'groupby'); - foreach($invoiceItems as $index => $singleItem) - { - $productImgs= $model->getProductImgs($singleItem->product); + foreach ($invoiceItems as $index => $singleItem) { + $productImgs = $model->getProductImgs($singleItem->product); $invoiceItems[$index]->imgs = $productImgs; - } - - + + // print_r($invoiceItems);die(); $invoice_type = $data[0]->invoice_type; - + // print_r($invoiceItems);die(); // Create an mPDF object $mpdf = new Mpdf([ - 'mode' => '', - 'format' => 'A5', - 'default_font_size' => 0, - 'default_font' => '', - 'margin_left' => 2, - 'margin_right' => 2, - 'margin_top' => 6, - 'margin_bottom' => 6, - 'margin_header' => 6, - 'margin_footer' =>-30, - 'orientation' => 'P', - ]); + 'mode' => '', + 'format' => 'A5', + 'default_font_size' => 0, + 'default_font' => '', + 'margin_left' => 2, + 'margin_right' => 2, + 'margin_top' => 6, + 'margin_bottom' => 6, + 'margin_header' => 6, + 'margin_footer' => -30, + 'orientation' => 'P', + ]); - - $mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true; + + $mpdf->autoLangToFont = true; + $mpdf->autoScriptToLang = true; // Set PDF properties $mpdf->SetTitle('Invoice'); $mpdf->SetAuthor($data[0]->company_name); $mpdf->SetCreator(''); - - $htmlFooter='
| " name="quantity[]" oninput="calculateInvoice(this,= $inx; ?>)" value="= isset($ii_details['quantity']) ? $ii_details['quantity'] : '' ?>" min="1" /> @@ -147,7 +157,7 @@ | " name="amount[]" value="= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" readonly /> | -" name="discount_amount[]" oninput="calculateInvoice(this,= $inx; ?>)" value="= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" min="0" step="0.01"/> + | " name="discount_amount[]" oninput="calculateInvoice(this,= $inx; ?>)" value="= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" min="0" step="0.01" /> | @@ -172,28 +182,30 @@ |
|
+
+
+
+
- | + |
|
@@ -201,7 +213,7 @@ | = $invoice_date; ?> | = $row['customer_name']; ?> | -= $row['status']; ?> | += $row['status']; ?> | = "₹ " . $row['total_amount']; ?> | " class="download-pdf-button" title="Download the Invoice"> @@ -117,19 +122,19 @@ |
Reason: = $value->reason; ?>
+ reason)) { ?> +Reason: = $value->reason; ?>
- terms)) { ?> -+
+= $row->terms ?>-