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 @@