diff --git a/app/Controllers/ApiIntegration.php b/app/Controllers/ApiIntegration.php index 0a9f8f8b..58da7454 100644 --- a/app/Controllers/ApiIntegration.php +++ b/app/Controllers/ApiIntegration.php @@ -916,7 +916,8 @@ class ApiIntegration extends ResourceController $toDateTimestamp = strtotime("+$duration months", $fromDateTimestamp); $fromDate = date("Y-m-d", strtotime($records['date_created'])); $toDate = date("Y-m-d", $toDateTimestamp); - $scheme_id = $result_book_category[$x]['category_id']; + // $scheme_id = $result_book_category[$x]['category_id']; b4 + $scheme_id = $result_book_category[$x]['book_id']; $dataToCheck = ['scheme_id'=>$scheme_id,'customer_id' => $local_customer_id,'invoice_id' => $invoice_id ]; $existing_subscription = $api_model->getData('subscription', $dataToCheck); if (count($existing_subscription) > 0) { diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index c29e1ee8..d7ec43f2 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -119,6 +119,7 @@ class Invoice extends BaseController $data['customer_shipping'] = $this->get_customer_address($where, []); return $this->response->setJSON(['data' => $data]); } + // public function generate_serial_no(){} ## For Gethering Address Details... public function get_customer_address($where, $select) @@ -210,11 +211,12 @@ class Invoice extends BaseController $requestData = $this->request->getPost(); - if($this->request->getPost('event_next_id') != ""){ + if($this->request->getPost('next_id')){ ## Array Formation For Events Details And Updating Events also Here.. $update_events = [ 'id' => 1, - 'next_id' => $this->request->getPost('event_next_id'), + '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_events);} @@ -537,8 +539,7 @@ class Invoice extends BaseController // Fetch the invoice data based on $invoice_id $model = new InvoiceModel(); $data = $model->getInvoiceData($id); - $invoiceItems = $model->getInvoiceItems($id); - $invoiceTerms= $model->getInvoiceData($id); + $invoiceItems = $model->getInvoiceItems($id,'groupby'); foreach($invoiceItems as $index => $singleItem) { @@ -569,13 +570,13 @@ class Invoice extends BaseController } // Generate the PDF content (HTML) with data - $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems,'invoice_type' => $invoice_type,'invoiceTerms'=>$invoiceTerms]); + $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems,'invoice_type' => $invoice_type,'invoiceTerms'=>$data]); // Load HTML into the mPDF instance $mpdf->WriteHTML($html); // Output the PDF to the browser for download - $mpdf->Output('invoice_' . $id . '.pdf', 'D'); + $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); } public function print_address($id) { @@ -602,7 +603,8 @@ class Invoice extends BaseController $mpdf->WriteHTML($html); // Output the PDF for download - $pdfFileName = 'customer_address_' . $id . '.pdf'; + + $pdfFileName = 'customer_address_' . date('Y-m-d H-i-s') . '.pdf'; $mpdf->Output($pdfFileName, 'D'); } } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 76fb6ced..b7c4a2ad 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -54,7 +54,7 @@ public function updateData($table, $data, $where) $scheme_name = []; $from_subscription = []; $to_subscription = []; - $invoiceItems = $this->getInvoiceItems2($invoiceId); + $invoiceItems = $this->getInvoiceItems($invoiceId,''); foreach ($invoiceItems as $j => $child) { if ($child->category_name == 'Membership') { $scheme_name[] = $child->title; @@ -98,7 +98,7 @@ public function updateData($table, $data, $where) if(!empty($result)){ foreach ($result as $object) { $invoiceId = $object['invoice_id']; - $items = $this->getInvoiceItems($invoiceId); + $items = $this->getInvoiceItems($invoiceId,''); } }else{ $items = []; @@ -127,48 +127,46 @@ public function updateData($table, $data, $where) ->join('customer_addresses as A','A.customer_id=invoice.customer_id and A.address_type=1','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.*,concat(C.first_name," ",C.last_name) as customer_name,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no,B.title,B.business_logo,B.terms,B.address,B.city,B.state,B.postal_code,B.email,B.mobile_no') - ->select('states.state_name != "",states.state_name,A.state) as customer_bill_state,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') + ->select('invoice.*,concat(C.first_name," ",C.last_name) as customer_name,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile') + ->select('B.title as ,B.business_logo,B.terms,B.address,B.city,B.state,B.postal_code,B.email,B.mobile_no') + ->select('COALESCE(NULLIF(states.state_name, ""), A.state) AS customer_bill_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') ->get() ->getResult(); } // this function Also Used For Approve Notification. - public function getInvoiceItems($id) + public function getInvoiceItems($id,$stringflag) { - $data = $this->db->table('invoiceitems') - ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1]) - ->join('books as B', 'B.book_id = invoiceitems.product', 'left') - ->join('book_categories as BC', 'BC.book_id = invoiceitems.product', 'left') - ->join('category as C', 'C.id = BC.category_id', 'left') - ->select('invoiceitems.*,B.*,GROUP_CONCAT(C.name SEPARATOR \',\') as name') - ->groupBy('invoiceitems.invoice_child_id') + + if ($stringflag == 'groupby') { + $select = 'invoiceitems.*, B.*, GROUP_CONCAT(C.name SEPARATOR \',\') as name'; + $group_by = 'invoiceitems.invoice_child_id'; + } else { + $select = 'invoiceitems.*, B.*, C.name as category_name'; + $group_by = ""; + } + + $data = $this->db->table('invoiceitems') + ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1]) + ->join('books as B', 'B.book_id = invoiceitems.product', 'left') + ->join('book_categories as BC', 'BC.book_id = invoiceitems.product', 'left') + ->join('category as C', 'C.id = BC.category_id', 'left') + ->select($select) + ->groupBy($group_by) // Fixed the variable name here + ->get() + ->getResult(); + //->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order //->limit(1,0) - ->get() - ->getResult(); + - // print_r($this->db->getLastQuery()); - return $data; - } - - public function getInvoiceItems2($id) - { - $data = $this->db->table('invoiceitems') - ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1]) - ->join('books as B', 'B.book_id = invoiceitems.product', 'left') - ->join('book_categories as BC', 'BC.book_id = invoiceitems.product', 'left') - ->join('category as C', 'C.id = BC.category_id', 'left') - ->select('invoiceitems.*,B.*,C.name as category_name') - //->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order - //->limit(1,0) - ->get() - ->getResult(); - - // print_r($this->db->getLastQuery()); + // print_r($this->db->getLastQuery());die; + // print_r($data);die("ends -- here"); return $data; } + public function getMembershipListForCustomer($category, $id) { $data = $this->db->table('subscription as S') diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index d086f31c..f9a3f87e 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -50,7 +50,6 @@