diff --git a/CustomerDetails_20231122120827.pdf b/CustomerDetails_20231122120827.pdf new file mode 100644 index 00000000..28d276a2 Binary files /dev/null and b/CustomerDetails_20231122120827.pdf differ diff --git a/CustomerDetails_20231122120845.pdf b/CustomerDetails_20231122120845.pdf new file mode 100644 index 00000000..4d07d2a0 Binary files /dev/null and b/CustomerDetails_20231122120845.pdf differ diff --git a/CustomerDetails_20231122120916.pdf b/CustomerDetails_20231122120916.pdf new file mode 100644 index 00000000..f9f1c38d Binary files /dev/null and b/CustomerDetails_20231122120916.pdf differ diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e0bdcd22..3c099663 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -119,6 +119,11 @@ $routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1"); $routes->add('approve_invoice/(:num)', 'Invoice::approve_invoice/$1'); $routes->get('generate_invoice_pdf/(:num)', 'Invoice::generate_invoice_pdf/$1'); $routes->get('print_address/(:num)', 'Invoice::print_address/$1'); +$routes->get('print_address/(:num)', 'Invoice::print_address/$1'); + +$routes->match(['get','post'],'/general_inv_rp','Invoice::general_inv_rp'); +$routes->match(['get','post'],'/mem_inv_rp','Invoice::general_membership_inv_rp'); +$routes->match(['get','post'],'/itemwise_report','Invoice::itemwise_report'); # Notifications Routes diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index d7ec43f2..93aa559d 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -584,7 +584,21 @@ class Invoice extends BaseController $model = new InvoiceModel(); $invoiceData = $model->getInvoiceData($id); // print_r($invoiceData);die(); - $mpdf = new \Mpdf\Mpdf(); + // Initialize an empty PDF with custom paper size (4x6 inches) + $config = [ + 'mode' => 'utf-8', + 'format' => [101.6, 152.4], + 'default_font_size' => 12, + 'default_font' => 'Arial', + 'margin_left' => 0, + 'margin_right' => 0, + 'margin_top' => 0, + 'margin_bottom' => 0, + 'margin_header' => 0, + 'margin_footer' => 0, + 'orientation' => 'P', // Portrait + ]; + $mpdf = new Mpdf($config); $mpdf->SetTitle('Customer Address'); $mpdf->SetAuthor('Your Company Name'); $mpdf->SetCreator(''); @@ -607,6 +621,88 @@ class Invoice extends BaseController $pdfFileName = 'customer_address_' . date('Y-m-d H-i-s') . '.pdf'; $mpdf->Output($pdfFileName, 'D'); } + + public function general_inv_rp() + { + if($this->request->getmethod() == 'get') + { + $model = new InvoiceModel(); + $data['report_data'] = $model->get_general_invoice_data(); + $this->logger->info("Invoice Report "); + $data['page_name'] = 'General Invoice Report'; + $this->render_page('report_general_invoice', $data); + } + else + { + $dateParts = explode(' - ', $this->request->getVar('date') ); + $fromDate = $dateParts[0]; + $toDate = $dateParts[1]; + + $dateTime = \DateTime::createFromFormat('m/d/Y', $fromDate); + $dateTime1 = \DateTime::createFromFormat('m/d/Y', $toDate); + $model = new InvoiceModel(); + $data['report_data'] = $model->get_general_invoice_data( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') ); + $this->logger->info("Invoice Report "); + $data['page_name'] = 'General Invoice Report'; + $data['selected_data'] = $this->request->getVar('date'); + $this->render_page('report_general_invoice', $data); + } + } + + public function general_membership_inv_rp() + { + if($this->request->getmethod() == 'get') + { + $model = new InvoiceModel(); + $data['report_data'] = $model->get_mem_invoice_data(); + $this->logger->info("Membership Invoice Report "); + $data['page_name'] = 'Membership Invoice Report'; + $this->render_page('report_mem_invoice', $data); + } + else + { + $dateParts = explode(' - ', $this->request->getVar('date') ); + $fromDate = $dateParts[0]; + $toDate = $dateParts[1]; + + $dateTime = \DateTime::createFromFormat('m/d/Y', $fromDate); + $dateTime1 = \DateTime::createFromFormat('m/d/Y', $toDate); + $model = new InvoiceModel(); + $data['report_data'] = $model->get_mem_invoice_data( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') ); + $this->logger->info("Membership Invoice Report "); + $data['page_name'] = 'Membership Invoice Report'; + $data['selected_data'] = $this->request->getVar('date'); + $this->render_page('report_mem_invoice', $data); + } + } + + public function itemwise_report() + { + if($this->request->getmethod() == 'get') + { + $model = new InvoiceModel(); + $data['report_data'] = $model->itemwise_report_data(); + $this->logger->info("Itemwise Report "); + $data['page_name'] = 'Itemwise Report'; + $this->render_page('report_itemwise', $data); + } + else + { + $dateParts = explode(' - ', $this->request->getVar('date') ); + $fromDate = $dateParts[0]; + $toDate = $dateParts[1]; + + $dateTime = \DateTime::createFromFormat('m/d/Y', $fromDate); + $dateTime1 = \DateTime::createFromFormat('m/d/Y', $toDate); + $model = new InvoiceModel(); + $data['report_data'] = $model->itemwise_report_data( $dateTime->format('Y-m-d') , $dateTime1->format('Y-m-d') ); + $this->logger->info("Itemwise Report "); + $data['page_name'] = 'Itemwise Report'; + $data['selected_data'] = $this->request->getVar('date'); + $this->render_page('report_itemwise', $data); + } + + } } // public function generate_invoice_pdf($id) @@ -640,3 +736,6 @@ class Invoice extends BaseController // // Fetch invoice items related to the given invoice ID // return $this->db->table('invoice_items')->where('invoice_id', $invoiceId)->get()->getResult(); // } + + + diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index 849f2950..7986edd0 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -12,6 +12,7 @@ use Mpdf\Mpdf; class Subscription extends BaseController { public function index() { + // echo base_url('public/uploads/vijayabharathampdf.png');die(); helper('session'); if (is_session_active()) { $session_role = get_user_role(); @@ -118,12 +119,43 @@ public function add_subscription() { // echo 'Customer not found'; // } // } + public function download_details() { $selectedSchemes = $this->request->getPost('selected_schemes'); + $action = $this->request->getPost('action'); + // Initialize an empty PDF with custom paper size (4x6 inches) + $config = [ + 'mode' => 'utf-8', + 'format' => [101.6, 152.4], + 'default_font_size' => 12, + 'default_font' => 'Arial', + 'margin_left' => 0, + 'margin_right' => 0, + 'margin_top' => 0, + 'margin_bottom' => 0, + 'margin_header' => 0, + 'margin_footer' => 0, + 'orientation' => 'P', // Portrait + ]; - // Initialize an empty PDF - $pdf = new Mpdf(); + $configA4 = [ + 'mode' => 'utf-8', + 'format' => 'A4', + 'default_font_size' => 12, + 'default_font' => 'Arial', + 'margin_left' => 10, // Adjusted margin for better fit + 'margin_right' => 10, // Adjusted margin for better fit + 'margin_top' => 10, // Adjusted margin for better fit + 'margin_bottom' => 10, // Adjusted margin for better fit + 'margin_header' => 0, + 'margin_footer' => 0, + 'orientation' => 'P', // Portrait + ]; + + + if($action == 1) $pdf = new Mpdf($config); + else $pdf = new Mpdf(); // Iterate through selected schemes foreach ($selectedSchemes as $selectedScheme) { @@ -133,9 +165,9 @@ public function download_details() // Create an HTML content string for the current scheme if (!empty($customerDetails)) { - $html = view('print_addresses_form', ['customerDetails' => $customerDetails]); - + $html = view('print_addresses_form', ['customerDetails' => $customerDetails , 'action' => $action ]); // Add the current scheme's details to the PDF + // $pdf->AddPage(); $pdf->WriteHTML($html); } } @@ -148,6 +180,8 @@ public function download_details() } + + } // public function generate_pdf() // { diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index b7c4a2ad..21b2138a 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -227,9 +227,84 @@ public function insertSubscriptionData($data) { return $this->db->table('subscription')->insert($data); } - + +// ***********************REPORT********************** + +public function get_general_invoice_data($f_date = null, $t_date = null) +{ + // Fetch invoice data + $query = $this->db->table('invoice') + ->select('invoice.*, customers.*, COUNT(invoiceitems.product) as item_count') + ->where('invoice.isactive', 1) + ->where('invoice.invoice_type', 1) + ->where('invoiceitems.isactive', 1); + + // Add date range filter if provided + if ($f_date !== null && $t_date !== null) { + $query->where('invoice.invoice_date >=', $f_date) + ->where('invoice.invoice_date <=', $t_date); + } + + $result = $query->join('customers', 'customers.customer_id = invoice.customer_id', 'left') + ->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left') + ->join('books', 'books.book_id = invoiceitems.product', 'left') + ->groupBy('invoice.invoice_id') // Assuming invoice_id is the primary key of the invoice table + ->get() + ->getResult(); + + return $result; } +public function get_mem_invoice_data($f_date = null, $t_date = null) +{ + // Fetch invoice data + $query = $this->db->table('invoice') + ->select('invoice.*, customers.*, COUNT(invoiceitems.product) as item_count') + ->where('invoice.isactive', 1) + ->where('invoice.invoice_type', 2) + ->where('invoiceitems.isactive', 1); + + // Add date range filter if provided + if ($f_date !== null && $t_date !== null) { + $query->where('invoice.invoice_date >=', $f_date) + ->where('invoice.invoice_date <=', $t_date); + } + + $result = $query->join('customers', 'customers.customer_id = invoice.customer_id', 'left') + ->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left') + ->join('books', 'books.book_id = invoiceitems.product', 'left') + ->groupBy('invoice.invoice_id') // Assuming invoice_id is the primary key of the invoice table + ->get() + ->getResult(); + + return $result; + +} + +public function itemwise_report_data($f_date = null, $t_date = null) +{ + // Fetch invoice data + $query = $this->db->table('invoice') + ->select('invoice.*, books.* , COUNT(invoiceitems.product) as item_count , sum(invoiceitems.product * invoiceitems.unit_price) as item_cost') + ->where('invoice.isactive', 1) + ->where('books.isactive', 1); + + // Add date range filter if provided + if ($f_date !== null && $t_date !== null) { + $query->where('invoice.invoice_date >=', $f_date) + ->where('invoice.invoice_date <=', $t_date); + } + + $result = $query->join('invoiceitems', 'invoiceitems.invoice_id = invoice.invoice_id', 'left') + ->join('books', 'books.book_id = invoiceitems.product', 'left') + ->groupBy('books.book_id') + ->get() + ->getResult(); + + return $result; +} + +} diff --git a/app/Views/address_pdf_template.php b/app/Views/address_pdf_template.php index e45f2dfc..8eccfc2a 100644 --- a/app/Views/address_pdf_template.php +++ b/app/Views/address_pdf_template.php @@ -5,74 +5,70 @@

 ?>)
To:
-= $value->customer_name ?>
-= $value->customer_bill_address ?>
-= $value->customer_bill_city ?> = $value->customer_bill_state ?>
-= $value->customer_bill_postal_code ?>
-= $value->customer_bill_country ?>
-