From 6a57d1a640aaa5ec267e20153ab83883d2f561d8 Mon Sep 17 00:00:00 2001 From: heama Date: Wed, 20 Mar 2024 14:33:08 +0530 Subject: [PATCH] Tracker issue --- app/Config/Routes.php | 8 + app/Controllers/Invoice.php | 167 ++++++++++++- app/Models/BooksModel.php | 26 ++ app/Models/InvoiceModel.php | 52 +++- app/Views/address_pdf_template.php | 6 +- app/Views/invoice_form.php | 365 ++++++++++++++++++++++++++-- app/Views/invoice_list.php | 370 +++++++++++++++++++---------- app/Views/invoice_pdf_template.php | 18 +- app/Views/offline_invoice_list.php | 278 ++++++++++++++++++++++ app/Views/template/header.php | 34 ++- 10 files changed, 1144 insertions(+), 180 deletions(-) create mode 100644 app/Views/offline_invoice_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 75a760cf..f9a64c85 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -114,12 +114,17 @@ $routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1'); $routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format"); #invoices $routes->get("invoice_list/", "Invoice::index"); +$routes->get("offline_invoice/", "Invoice::offline_invoice"); $routes->get("new_book_invoice/(:any)", "Invoice::new_book_invoice/$1"); $routes->get("new_subscription_invoice/(:any)", "Invoice::new_subscription_invoice/$1"); // $routes->get("download_invoice_pdf/(:num)",'Invoice::download_invoice_pdf/$1'); $routes->get("download_invoice_pdf/(:any)", 'Invoice::download_invoice_pdf/$1'); +$routes->post("saveBook", "Invoice::saveBook"); +$routes->post("updateInvoiceStatus", "Invoice::updateInvoiceStatus"); +$routes->post("updateInvoiceCancelStatus", "Invoice::updateInvoiceCancelStatus"); + $routes->post("get_customer_billing_details", "Invoice::get_customer_billing_details"); $routes->post("get_customer_membership_details", "Invoice::get_customer_membership_details"); @@ -128,6 +133,9 @@ $routes->post("save_invoice/", "Invoice::save_invoice/"); $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('generate_invoice_pdf_preview/(:any)', 'Invoice::generate_invoice_pdf_preview/$1'); + + $routes->get('print_address/(:num)', 'Invoice::print_address/$1'); $routes->match(['get','post'],'/general_inv_rp','Invoice::general_inv_rp'); diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index b3b5af8d..5c3da750 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -5,6 +5,7 @@ namespace App\Controllers; use App\Models\EventModel; use App\Models\CustomerModel; use App\Models\InvoiceModel; +use App\Models\BooksModel; use App\Helpers\NotificationHelper; use Mpdf\Mpdf; @@ -28,7 +29,7 @@ class Invoice extends BaseController } $model = new InvoiceModel(); - $data['page_name'] = 'Invoice Details'; + $data['page_name'] = 'Online Invoice Details'; $data['invoice'] = $model->getJoinedData($where); $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); $this->render_page('invoice_list', $data); @@ -36,6 +37,30 @@ class Invoice extends BaseController return redirect()->to('login'); } } + public function offline_invoice() + { + helper('session'); + if (is_session_active()) { + $session_role = get_user_role(); + $session_bid = get_business_id(); + + 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]; + } else { + $this->logger->info("Invoice: Listing In the Super-Admin "); + $where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL,'I.invoice_type'=>1]; + } + + $model = new InvoiceModel(); + $data['page_name'] = 'Offline Invoice Details'; + $data['invoice'] = $model->getJoinedData($where); + $this->logger->info("Invoice: Listing Count ." . count($data['invoice'])); + $this->render_page('offline_invoice_list', $data); + } else { + return redirect()->to('login'); + } + } ## To Load Invoice ADD/EDIT page... public function new_book_invoice($id = '0') @@ -339,7 +364,7 @@ class Invoice extends BaseController } else { // For other invoice types, redirect to the invoice list. $this->logger->info(session()->getFlashdata()); - return redirect()->route('invoice_list'); // Adjust the route name as needed. + return redirect()->route('offline_invoice'); // Adjust the route name as needed. } } @@ -467,7 +492,7 @@ class Invoice extends BaseController $this->logger->error("Invoice: Err Occur = " . $e->getMessage()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } - return redirect()->route('invoice_list'); + return redirect()->route('offline_invoice'); } ## To Approve Invoice details based on invoice ID @@ -501,7 +526,7 @@ class Invoice extends BaseController session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } // Redirect back to the invoice list - return redirect()->route('invoice_list'); + return redirect()->route('offline_invoice'); } public function subscription_inactive(){ $model = new InvoiceModel(); @@ -694,7 +719,7 @@ $encodedUrl = urlencode($url); $htmlFooter='
'; - $mpdf->setHTMLFooter($htmlFooter); + $mpdf->setHTMLFooter($htmlFooter); // Generate the PDF content (HTML) if ($data[0]->status === 'Draft') { @@ -702,16 +727,53 @@ $encodedUrl = urlencode($url); $mpdf->SetWatermarkText('Draft'); $mpdf->showWatermarkText = true; } + if ($data[0]->status === 'Cancelled') { + // Set the watermark text and options + $mpdf->SetWatermarkText('Cancelled'); + $mpdf->showWatermarkText = true; + } + if ($data[0]->status === 'Void') { + // Set the watermark text and options + $mpdf->SetWatermarkText('Void'); + $mpdf->showWatermarkText = true; + } + // Generate the PDF content (HTML) with data $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems,'invoice_type' => $invoice_type,'invoiceTerms'=>$data]); - +// echo $html;die; // Load HTML into the mPDF instance $mpdf->WriteHTML($html); // Output the PDF to the browser for download $mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D'); } + public function generate_invoice_pdf_preview($id) + { + // Load required model + $model = new InvoiceModel(); + $data = $model->getInvoiceData($id); + + $invoiceItems = $model->getInvoiceItems($id,'groupby'); + + foreach($invoiceItems as $index => $singleItem) + { + $productImgs= $model->getProductImgs($singleItem->product); + $invoiceItems[$index]->imgs = $productImgs; + } + + $invoice_type = $data[0]->invoice_type; + + // Get status data + $status = $data[0]->status; + + // Load view with data + $html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems, 'invoice_type' => $invoice_type, 'invoiceTerms' => $data, 'status' => $status]); + + // Return HTML content + echo $html; + } + // public function generate_invoice_pdf($id) // { // // Fetch the invoice data based on $invoice_id @@ -1096,6 +1158,99 @@ private function getInvoiceIdByMd5($md5Hash) return $result ? $result->invoice_id : null; } +public function saveBook() { + // Retrieve book details from POST data + $bookName = $this->request->getPost('bookName'); + $publication_date = $this->request->getPost('publication_date'); + $publication_code = $this->request->getPost('publishers_code'); + $isbn_code = $this->request->getPost('isbn_code'); + $bookPrice = $this->request->getPost('bookPrice'); + $publisher_name = $this->request->getPost('publisher'); + + // Load the model + $model = new BooksModel(); + + // Call the model function to save the book + $bookId = $model->saveBook($bookName, $bookPrice, $isbn_code, $publication_date, $publication_code, $publisher_name); + + // Return a response (e.g., JSON response) + $response = array(); + if ($bookId) { + $response['success'] = true; + $response['message'] = 'Book saved successfully.'; + $response['book_id'] = $bookId; // Include the book ID in the response + $response['title'] = $bookName; + // $response['tax'] = $bookId; + $response['price'] = $bookPrice; + } else { + $response['success'] = false; + $response['message'] = 'Failed to save book.'; + } + + // Send JSON response + return $this->response->setJSON($response); +} + + + +// Your controller method to handle updating status and reason +public function updateInvoiceStatus() +{ + // Retrieve data from the request + $invoiceId = $this->request->getPost('invoice_id'); + $voidReason = $this->request->getPost('void_reason'); + + // Perform any validation if needed + + // Update the invoice status and void reason in the database + $model = new InvoiceModel(); // Assuming you have a model named InvoiceModel + $updated = $model->updateInvoiceStatus($invoiceId, $voidReason); + + // Prepare the response + $response = []; + if ($updated) { + $response['success'] = true; + $response['message'] = 'Invoice status updated successfully.'; + } else { + $response['success'] = false; + $response['message'] = 'Failed to update invoice status.'; + } + if ($updated) { + + } + // Return the response as JSON + return $this->response->setJSON($response); +} +public function updateInvoiceCancelStatus() +{ + // Retrieve data from the request + $invoiceIds = $this->request->getPost('invoice_id'); + $cancelReason = $this->request->getPost('cancel_reason'); + + // Perform any validation if needed + + // Update the invoice status and cancel reason in the database + $model = new InvoiceModel(); // Assuming you have a model named InvoiceModel + $updated = $model->updateInvoiceCancelStatus($invoiceIds, $cancelReason); + + // Prepare the response + $response = []; + if ($updated) { + $response['success'] = true; + $response['message'] = 'Invoice status updated successfully.'; + // Redirect to the invoice_list page upon successful cancellation + // return redirect()->to('invoice_list'); + } else { + $response['success'] = false; + $response['message'] = 'Failed to update invoice status.'; + } + + // Return the response as JSON + return $this->response->setJSON($response); +} } + + + diff --git a/app/Models/BooksModel.php b/app/Models/BooksModel.php index 04f99eb4..e36e136e 100644 --- a/app/Models/BooksModel.php +++ b/app/Models/BooksModel.php @@ -147,5 +147,31 @@ public function getData($table, $where = null,$whereIn = null) return ""; } } + public function saveBook($bookName, $bookPrice,$isbn_code,$publication_date,$publication_code,$publisher_name) { + // Prepare data to insert into the database + $data = array( + 'title' => $bookName, + 'price' => $bookPrice, + 'isbn_code'=>$isbn_code, + 'publication_date'=>$publication_date, + 'publishers_code'=>$publication_code, + 'publisher'=>$publisher_name + // Add other columns as needed + ); + + // Use Query Builder to insert data into the 'books' table + $this->db->table('books')->insert($data); + + // Return the ID of the inserted record + return $this->db->insertID(); + } + public function getAllActiveBooks() { + // Fetch active books from the database + $query = $this->db->table('books') + ->where('isactive', 1) + ->get(); // No need to pass 'books' again here + return $query->getResult(); // Use getResult() instead of result() + } + } diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 140ab62c..d366c003 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -206,13 +206,11 @@ public function getSubscriptionInvoiceDetail($where) ->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_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.*,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,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no as customer_mobile') + + ->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 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('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('COALESCE(NULLIF(states.state_name, ""), A.state) AS customer_bill_state') + // ->select(' customer_bill_country') ->get() ->getResult(); @@ -506,6 +504,48 @@ public function itemwise_report_data_with_publish_code($f_date = null, $t_date = return $result; } +public function updateInvoiceStatus($invoiceId, $voidReason) +{ + // Assuming 'invoices' is the name of your table + $builder = $this->db->table('invoice'); + + // Define the data to be updated + $data = [ + 'status' => 'Void', // Set the status to 'Void' + 'reason' => $voidReason, // Set the void reason + // You can add more fields to update here if needed + ]; + + // Set the where condition to identify the invoice by its ID + $builder->where('invoice_id', $invoiceId); + + // Perform the update and check if successful + $updated = $builder->update($data); + + return $updated; +} +public function updateInvoiceCancelStatus($invoiceIds, $cancelReason) +{ + // Assuming 'invoices' is the name of your table + $builder = $this->db->table('invoice'); + + // Define the data to be updated + $data = [ + 'status' => 'Cancelled', // Set the status to 'Canceled' + 'reason' => $cancelReason, // Set the cancel reason + // You can add more fields to update here if needed + ]; + + // Set the where condition to identify the invoices by their IDs + $builder->where('invoice_id', $invoiceIds); + + // Perform the update and check if successful + $updated = $builder->update($data); + + return $updated; +} + + } diff --git a/app/Views/address_pdf_template.php b/app/Views/address_pdf_template.php index 9bf023b1..f9f04c21 100644 --- a/app/Views/address_pdf_template.php +++ b/app/Views/address_pdf_template.php @@ -51,10 +51,8 @@
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." ." ?> + shipping_address ?>
+
diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index d8865f4b..612c9050 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -84,16 +84,15 @@
-
- - -
-
-
+ + +
+ +
@@ -105,10 +104,11 @@
-
+

Item Details


+ @@ -127,8 +127,9 @@ $ii_details) : ?> - @@ -160,14 +164,12 @@ td.invoice-number {
+ + + + +
@@ -381,11 +388,113 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/Views/invoice_list.php b/app/Views/invoice_list.php index 211cd59d..aded8aeb 100644 --- a/app/Views/invoice_list.php +++ b/app/Views/invoice_list.php @@ -1,139 +1,251 @@ -
-
-
-
- - + - -
-

- getFlashdata('success') || session()->getFlashdata('error')) : ?> - getFlashdata('success')) : ?> - - - getFlashdata('error')) : ?> - - + +
+
+
+
+
+ +
+
+

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + -
- - - - - - - - - - - - - - + getFlashdata('error')) : ?> + + + +
+
Invoice NumberInvoice DateCustomer NameStatusTotalAction
+ + + + + + + + + + + + + - - - - - - - + + + + + + + " class="download-pdf-button" title="Download the Invoice">  + " class="print-address-button" title="Print Address"> + - - -
Order NumberInvoice DateCustomer NameStatusTotalAction
- - - " class="edit-button" title="Edit the Invoice">  - - " class="edit-button" title="Edit the Invoice">  - + + + " class="edit-button" title="Edit the Invoice">  + + + - " class="download-pdf-button" title="Download the Invoice">  - " class="print-address-button" title="Print Address"> -
-
-
-
-
-
- + + - + - \ No newline at end of file + }); + + + diff --git a/app/Views/invoice_pdf_template.php b/app/Views/invoice_pdf_template.php index b6a32203..777e19b4 100644 --- a/app/Views/invoice_pdf_template.php +++ b/app/Views/invoice_pdf_template.php @@ -15,7 +15,7 @@ table.main-table { width: 100%; border-collapse: collapse; - border: 1px solid black; /* Add a border around the entire invoice */ + border: -0.5px solid black; /* Add a border around the entire invoice */ } table.main-table th, @@ -128,6 +128,10 @@ td.invoice-number { font-size: 18px; /* Increase font size to your desired value */ /* Highlight background color */ font-weight: bold; /* Make the text bold */ +} +p { + margin-top: 0; + margin-bottom: 0rem; } @@ -148,7 +152,7 @@ td.invoice-number {

company_address ?>,
company_city ?>, company_state ?> - company_postal_code ? " - ".$value->company_postal_code:"" ?>.


+ company_postal_code ? " - ".$value->company_postal_code:"" ?>.

company_email ?>

company_mobile_no ?>

- + - - - + due_date) : ?> @@ -290,10 +292,10 @@ td.invoice-number { - + diff --git a/app/Views/offline_invoice_list.php b/app/Views/offline_invoice_list.php new file mode 100644 index 00000000..b212648f --- /dev/null +++ b/app/Views/offline_invoice_list.php @@ -0,0 +1,278 @@ + + + +
+
+
+
+ + + + +
+

+ getFlashdata('success') || session()->getFlashdata('error')) : ?> + getFlashdata('success')) : ?> + + + getFlashdata('error')) : ?> + + + +
+
Invoice # invoice_number ?>order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?>
Invoice Date : formatted_invoice_date ?>
Order Number : order_number ? $value->order_number : "-" ?>
Due Date : formatted_due_date ?>
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Invoice NumberInvoice DateCustomer NameStatusTotalAction
+ + + " class="edit-button" title="Edit the Invoice">  + + " class="edit-button" title="Edit the Invoice">  + + + " class="download-pdf-button" title="Download the Invoice">  + " class="print-address-button" title="Print Address"> +
+
+
+
+ + + + + + + + + + + + + diff --git a/app/Views/template/header.php b/app/Views/template/header.php index 02fda9ee..16ad7ea9 100644 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -53,11 +53,11 @@
@@ -133,12 +133,34 @@ -
  • + +
  • + + + Sales + + +
    + +
    +