diff --git a/.env b/.env index 2f4479a2..5c76d53b 100644 --- a/.env +++ b/.env @@ -142,3 +142,9 @@ CI_ENVIRONMENT = development # curlrequest.shareOptions = true APP_TIMEZONE = 'Asia/Kolkata' + +#-------------------------------------------------------------------- +# Whatsapp Access Token And Instance ID +#-------------------------------------------------------------------- +WAAI_TOKEN = '6568739969f28' +WAAI_INSTANCE = '656876690A9FD' 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/Constants.php b/app/Config/Constants.php index 9bca1d84..970e6799 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -115,8 +115,17 @@ define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]); define('order_child','invoiceitems'); define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]); -define('WAAI_TOKEN', '652548474f4e4'); -define('WAAI_INSTANCE', '65254894E4A88'); +// define('WAAI_TOKEN', '652548474f4e4'); +// define('WAAI_INSTANCE', '65254894E4A88'); + +// UAT - for testing Purpose.. +// define('WAAI_TOKEN', '65685e954bcf6'); +// define('WAAI_INSTANCE', '656863C54F90C'); + +// LIVE - Vel given.30th Nov. +// define('WAAI_TOKEN', '6568739969f28'); +// define('WAAI_INSTANCE', '656876690A9FD'); + define('SEND_WAAI_URL', 'https://waai.in/api/send'); define('SEND_WAAI_GROUP_URL', 'https://waai.in/api/send_group'); define('EXPIRAY_NOTIFY_TEMPLATE_EMAIL','EXPIRAY_NOTIFY_TEMPLATE_EMAIL'); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 774e6455..96592346 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 6cb2205c..368a7341 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -586,7 +586,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(''); @@ -609,6 +623,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) @@ -642,3 +738,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/Notifications.php b/app/Controllers/Notifications.php index 8ce26836..a5f08ecd 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -35,9 +35,9 @@ class Notifications extends BaseController if ($request->is('post')) { $records = $request->getVar(); $params = (object) Null; - $this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE); + + $this->logger->info("Whatsapp : sending message instance id = " . $_ENV['WAAI_INSTANCE'] ." - ". $_ENV['WAAI_TOKEN']); try { - $this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE); if ($records['categories'] == 'SEND_WAAI_GROUP_URL') { if($records['group_id'] != ""){ $params->group_id = $records['group_id']; } else{ throw new \Exception("Group Id Missing Please Try again.."); } @@ -54,9 +54,10 @@ class Notifications extends BaseController $url = constant($records['categories']); $params->type = $records['type'] == "" ? "text" : $records['type']; - $params->instance_id = WAAI_INSTANCE; - $params->access_token = WAAI_TOKEN; + $params->instance_id = $_ENV['WAAI_INSTANCE']; + $params->access_token = $_ENV['WAAI_TOKEN']; $params->message = $records['description']; + $this->logger->info("Whatsapp : sending message request = " . json_encode($params)); $this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params)); helper('notification'); $notification = new NotificationHelper(); diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index 849f2950..e173d3bb 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,36 +119,79 @@ 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' => [101.6 * 2, 152.4 * 4], // 2x4 inches for each label + '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 + ]; + + if($action == 1) $pdf = new Mpdf($config); + else $pdf = new Mpdf(); + $customerDetails = []; // Iterate through selected schemes + if (!empty($selectedSchemes)) { foreach ($selectedSchemes as $selectedScheme) { // Call the model method to get customer details for each selected scheme $subscriptionModel = new SubscriptionModel(); - $customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); - - // Create an HTML content string for the current scheme - if (!empty($customerDetails)) { - $html = view('print_addresses_form', ['customerDetails' => $customerDetails]); - - // Add the current scheme's details to the PDF - $pdf->WriteHTML($html); - } + $details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme); + $customerDetails = array_merge($customerDetails, $details); } + + if (!empty($customerDetails)) { + $html = view('print_addresses_form', ['customerDetails' => $customerDetails , 'action' => $action , 'pdf' => $pdf]); + // Add the current scheme's details to the PDF + // echo $html;die; + // $pdf->AddPage(); + $pdf->WriteHTML($html); + // Set the PDF filename + $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf'; - // Set the PDF filename - $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf'; - - // Output the PDF for download - $pdf->Output($filename, 'D'); + // Output the PDF for download + $pdf->Output($filename, 'D'); + $this->logger->info("Print Addresses (Scheme) : Downloaded = ".$filename); + } else { + echo ""; + $this->logger->info("Print Addresses (Scheme) : Details Not Available "); + } + } else { + echo ""; + $this->logger->info("Print Addresses (Scheme) : Schemes Not Choosen "); + } + } + + } // public function generate_pdf() // { diff --git a/app/Helpers/NotificationHelper.php b/app/Helpers/NotificationHelper.php index d995e9a2..d7c44d63 100644 --- a/app/Helpers/NotificationHelper.php +++ b/app/Helpers/NotificationHelper.php @@ -77,13 +77,15 @@ class NotificationHelper $this->logger->info('Helper : Whatsapp'); $curl = curl_init(); $headers = array('Content-Type:application/json'); + $jsonencoded = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE); curl_setopt( $curl,CURLOPT_URL, $url); $this->logger->info('Helper : Whatsapp url = '.$url); switch ($method) { case "POST": curl_setopt( $curl,CURLOPT_POST, true ); if ($data) { - curl_setopt( $curl,CURLOPT_POSTFIELDS, json_encode($data)); + $this->logger->info('Helper : Whatsapp jsonencoded = '.$jsonencoded); + curl_setopt( $curl,CURLOPT_POSTFIELDS, $jsonencoded); } break; case "PUT": @@ -123,4 +125,4 @@ class NotificationHelper } } -?> \ No newline at end of file +?> 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 @@ Shipping Label Template - -
-
-
- address ?>,
city ?>, state ?>, + +
+ + +
+ customer_name ?> + customer_bill_address ?> + customer_bill_city ?> customer_bill_state ?> + customer_bill_postal_code ?> + customer_bill_country ?> +
+ +
+ +
+
From
+ address ?>,
city ?>, state ?>, postal_code ?> -
- -
-

To:

-

customer_name ?>

-

customer_bill_address ?>

-

customer_bill_city ?> customer_bill_state ?>

-

customer_bill_postal_code ?>

-

customer_bill_country ?>

-
-
- Barcode -
- -
- +
+
+ + + diff --git a/app/Views/notifications_form.php b/app/Views/notifications_form.php index 064b4f04..ac20c904 100644 --- a/app/Views/notifications_form.php +++ b/app/Views/notifications_form.php @@ -146,7 +146,7 @@
- + diff --git a/app/Views/template/footer.php b/app/Views/template/footer.php index bc3d7553..110e717b 100644 --- a/app/Views/template/footer.php +++ b/app/Views/template/footer.php @@ -790,6 +790,19 @@ + + + + + + + + + + + + +