From 8ac851b81a725e71b0daf2cb494522ef989504b7 Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Thu, 28 Dec 2023 18:37:18 +0530 Subject: [PATCH] Event And Invoice default Event : ps --- app/Config/Routes.php | 1 + app/Controllers/Event.php | 38 ++++++- app/Controllers/Invoice.php | 8 +- app/Helpers/financial_year_helper.php | 24 +++++ app/Models/EventModel.php | 3 +- app/Models/HomeModel.php | 4 +- app/Models/SettingsModel.php | 2 +- app/Views/book_form.php | 126 ++++++++++++------------ app/Views/event_list.php | 42 +++++++- app/Views/invoice_form.php | 6 +- app/Views/invoice_number_formatting.php | 5 +- app/Views/setting_form.php | 34 ++++--- 12 files changed, 203 insertions(+), 90 deletions(-) create mode 100644 app/Helpers/financial_year_helper.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1f27cc92..907f2ea6 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -105,6 +105,7 @@ $routes->post('address/generatePdf', 'Address::generatePdf'); $routes->get("event_list/", "Event::index"); $routes->get("new_event/(:any)", "Event::new_event/$1"); $routes->post("insert_event/", "Event::insert_event"); +$routes->post("change_default_event/", "Event::change_default_event"); $routes->get('invoice_number_format/(:any)', 'Event::invoice_number_format/$1'); $routes->post("insert_invoice_number_format", "Event::insert_invoice_number_format"); diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index 803763e6..05eee303 100644 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -105,13 +105,15 @@ class Event extends BaseController public function invoice_number_format($id) { helper('session'); + helper('financial_year_helper'); $session_bid = get_business_id(); $data['page_name'] = 'Edit invoice number formatting'; $model = new EventModel(); $edit_event_details = $model->setTable('invoice_number_formatting')->where(['id' => (int)$id,'business_id'=>$session_bid])->first(); $data['event'] = $edit_event_details; $data['session_bid'] = $session_bid; - + $data['financial_year'] = get_financial_year(); + $this->render_page('invoice_number_formatting', $data); } public function insert_invoice_number_format() @@ -162,4 +164,38 @@ class Event extends BaseController } return redirect()->to(base_url("invoice_number_format/1")); } + + public function change_default_event() { + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $response = ""; + + $EventModel = new EventModel(); + $where = ['events.business_id' => (int)$session_bid, 'events.isactive' => 1, 'events.is_the_default' => 1]; + $events = $EventModel->where($where)->orderBy('event_id', 'DESC')->findAll(); // Retrieve the events + + if (count($events) > 0) { + $dataToUpdate = ['is_the_default' => 0]; + $eventIds = array_column($events, 'event_id'); + // $EventModel->whereIn('event_id', $eventIds)->set($dataToUpdate)->update(); + $affectedRows = $EventModel->whereIn('event_id', $eventIds)->set($dataToUpdate)->update(); + $this->logger->info("Changed To Default as 0 - Event ID are " . implode(", ", $eventIds) . ". Affected Rows: " . $affectedRows); + } + + $data['is_the_default'] = $this->request->getPost('is_the_default'); + $data['updated_by'] = $session_uid; + $where = ['events.business_id' => (int)$session_bid, 'events.isactive' => 1, 'events.event_id' => $this->request->getPost('event_id')]; + $update_result = $EventModel->updateData('events', $data, $where); + + if ($update_result['info']) { + $response = "Event set as Default"; + $this->logger->info($update_result['info']); + } else { + $response = $update_result['err']; + $this->logger->error($update_result['err']); + } + + return $this->response->setJSON(['response' => $response]); + } } diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 9acaa8f9..4b9c4a1b 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -41,15 +41,18 @@ class Invoice extends BaseController public function new_book_invoice($id = '0') { 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); + $data['financial_year'] = get_financial_year(); $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where); $data['books'] = $model->getCategoryBooks(1); // Invocie type = 2 (invoice) - + if ($id === '0') { $this->logger->info("Book Invoice: In Add Details"); $data['page_name'] = 'Add Book Invoice Details'; @@ -158,6 +161,8 @@ class Invoice extends BaseController ## Declarions helper('session'); + helper('financial_year_helper'); + $model = new InvoiceModel(); $duedate = $this->request->getVar('due_date'); $invdate = $this->request->getVar('invoice_date'); @@ -225,6 +230,7 @@ class Invoice extends BaseController ## 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() diff --git a/app/Helpers/financial_year_helper.php b/app/Helpers/financial_year_helper.php new file mode 100644 index 00000000..2ccce077 --- /dev/null +++ b/app/Helpers/financial_year_helper.php @@ -0,0 +1,24 @@ +"","err"=>'Database operation failed: ' . $e->getMessage()]; } } + } ?> \ No newline at end of file diff --git a/app/Models/HomeModel.php b/app/Models/HomeModel.php index cdda3469..92421c95 100644 --- a/app/Models/HomeModel.php +++ b/app/Models/HomeModel.php @@ -26,7 +26,7 @@ class HomeModel extends Model } public function invoice_dtls() { - if (date('m') <= 3) { + if ((int)date('m') <= 3) { $invoice['financial_year'] = (date('Y')-1) . '-' . date('Y'); $start_date = (date('Y')-1).'-04-01'; $end_date = date('Y').'-03-31'; @@ -94,7 +94,7 @@ class HomeModel extends Model public function book_published_dtls(){ - if (date('m') <= 3) { + if ((int)date('m') <= 3) { $start_date = (date('Y')-1).'-04-01'; $end_date = date('Y').'-03-31'; } else { diff --git a/app/Models/SettingsModel.php b/app/Models/SettingsModel.php index b801f2e4..fee4a633 100644 --- a/app/Models/SettingsModel.php +++ b/app/Models/SettingsModel.php @@ -5,7 +5,7 @@ class SettingsModel extends Model { protected $table = 'settings'; protected $primaryKey = 'setting_id'; - protected $allowedFields = ['setting_id','site_name','site_title','favicon','logo','terms_service','footer_about','admin_email','mobile','copyright','pagination_limit','site_info','about_info','mail_protocol','mail_title','mail_host','mail_port','mail_encryption','mail_username','mail_password','currency','country','isactive','business_id']; + protected $allowedFields = ['business_id','setting_id','site_name','site_color','site_short_name','site_email','mobile','country','favicon','site_info','logo','terms_service','footer_about','about_info','copyright','pagination_limit','mail_protocol','mail_title','mail_host','mail_port','mail_encryption','mail_username','mail_password','currency','created_on','created_by','updated_on','updated_by','isactive']; public function saveData($data, $id = null) { diff --git a/app/Views/book_form.php b/app/Views/book_form.php index f0253106..006cc2a7 100644 --- a/app/Views/book_form.php +++ b/app/Views/book_form.php @@ -1,17 +1,17 @@ @@ -29,90 +29,86 @@
- - + +
Please provide.
- - + +
Please provide.
- - + +
Please provide.
- - -
-
-
-
- - + +
Please provide.
-
- - -
Please provide.
-
- + + +
+
+
Please provide.
-
- - - -
-
- -
- - - - -
- -
+
- +
+
+ + +
+
+ + +
Please provide.
+
-
- - - +
+
+ + +
+
+
+ + +
+
+ + + + + +
+ +
@@ -207,4 +203,4 @@ // Set the min and max date attributes DateInput.setAttribute("max", maxDate); - + \ No newline at end of file diff --git a/app/Views/event_list.php b/app/Views/event_list.php index c1cf267b..5efb6bf2 100644 --- a/app/Views/event_list.php +++ b/app/Views/event_list.php @@ -34,7 +34,7 @@ Event Name - Action + Action @@ -42,7 +42,11 @@ - " class="edit-button"> + @@ -60,6 +64,40 @@ }); }); +$("input[type=radio][name=is_the_default]").change(function(event) { + var id = $(this).val(); + var confirmed = window.confirm("Are you sure, you want to set the event as the default event?"); + + if (confirmed) { + $.ajax({ + type: "POST", + url: "", + data: { + event_id: id, + is_the_default: 1 + }, + success: function(response) { + alert(response.response); + $(this).prop('checked', true); + console.error(response); + }, + error: function(error) { + alert(error.response); + console.error(error); + // $(this).prop('checked', false); + refreshPage(); + + } + }); + } else { + alert("Action canceled"); + console.log("Action canceled"); + refreshPage(); + // console.log(event); + // console.log(id);$event->event_id + // $(this).prop('checked', false); + } + }); diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 10a8ab7b..719f4eb6 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -60,7 +60,7 @@ - @@ -582,8 +582,8 @@ var next_id_string = filtered_data[0].next_id; var left_pad_string = filtered_data[0].left_pad; - var prefix_string = String(filtered_data[0].id_formating); - + // var prefix_string = String(filtered_data[0].id_formating); // don't remove + var prefix_string = ; var left_pad_numberic = parseInt(left_pad_string); var next_id_numberic = parseInt(next_id_string); diff --git a/app/Views/invoice_number_formatting.php b/app/Views/invoice_number_formatting.php index 5107b373..01e7b9bc 100644 --- a/app/Views/invoice_number_formatting.php +++ b/app/Views/invoice_number_formatting.php @@ -26,9 +26,10 @@
- + +
diff --git a/app/Views/setting_form.php b/app/Views/setting_form.php index d7340825..2da31280 100644 --- a/app/Views/setting_form.php +++ b/app/Views/setting_form.php @@ -29,19 +29,29 @@
- - + + + + + + + + + +