= CONCAT(YEAR(NOW()) - IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")', 'causes.created_on < CONCAT(YEAR(NOW()) + IF(MONTH(NOW()) >= 1 AND MONTH(NOW()) <= 3, 1, 0), "-01-01")' ]; $where = ['causes.business_id' => $session_bid]; // $where = array_merge($where, $default_financial_year_condition); $model = new BooksModel(); $model->setTable('causes'); $data['cause_list'] = $model->getData('donations_accepted',null,null); $data['page_name'] = 'Causes List'; $data['details'] = $model->where($where)->where('causes.isactive', 1)->findAll(); $this->render_page('book_list', $data); } else { // Session is not active or user is not logged in return redirect()->to('login'); } } ## To Load Causes Form (Add/Update) public function add_causes($id) { helper('session'); $data['session_bid'] = get_business_id(); // Fetch categories from the model $model = new BooksModel(); if ($id === '0') { $data['page_name'] = 'Add Causes'; $where = ['is_active' => 1 ]; $data['cause_list'] = $model->getData('donations_accepted',$where,null); $data['details'] = []; } elseif ($id !== '0') { $data['page_name'] = 'Edit Causes'; $where = ['is_active' => 1 ]; $data['cause_list'] = $model->getData('donations_accepted',$where,null); $data['details'] = $model->where('causes.causes_id', $id)->findAll(); } $this->render_page('book_form', $data); } ## For inserting/updating details of Cause public function insert_causes() { try{ helper('session'); $session_uid = get_logged_user_id(); $session_bid = get_business_id(); $BooksModel = new BooksModel(); $data = [ 'name' => $this->request->getPost('name'), 'type' => $this->request->getPost('type'), 'description' => $this->request->getPost('description'), 'from_date' => ($this->request->getPost('from_date') != '') ? $this->request->getPost('from_date') : null, 'to_date' => ($this->request->getPost('to_date') != '') ? $this->request->getPost('to_date') : null, 'business_id'=>$session_bid ]; $causes_id = $this->request->getPost('causes_id'); // Get the book ID for update purpose if (empty($causes_id)) { // It's an insert operation $data['isactive'] = 1; $data['created_by'] = $session_uid; $causes_id = $BooksModel->insert($data); if ($causes_id) { session()->setFlashdata('success', 'causes successfully created.'); $this->logger->info("Books: has been added successfully. Inserted ID = " . $BooksModel->insertID()); } else { session()->setFlashdata('error', 'causes could not be created. Please try again..'); $this->logger->error("Books: Err could not be added. Please try again."); } } else { // It's an update operation // $isactive = $this->request->getPost('isactive'); // $data['isactive'] = ($isactive == 'on') ? 1 : 0; $data['isactive'] = 1; $data['updated_by'] = $session_uid; $BooksModel->update($causes_id, $data); if ($BooksModel->update($causes_id, $data)) { session()->setFlashdata('success', 'causes successfully updated.'); $this->logger->info("Books: has been updated successfully. Updated Book ID = " . $causes_id); } else { session()->setFlashdata('error', 'causes updation failed. Please try again.'); $this->logger->error("Books: Err Failed to update ID =" . $causes_id); } } } catch (\Exception $e) { $this->logger->error("Book: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } return redirect()->route('causes_list'); } ## For delete the causes details (Which means inactive the details) public function delete_causes($id) { try { helper('session'); $session_uid = get_logged_user_id(); // print_r($session_uid); $BooksModel = new BooksModel(); $data = ['isactive' => 0 , 'updated_by' => $session_uid]; // print_r($data); die; if ($BooksModel->update($id, $data)) { session()->setFlashdata('success', 'causes successfully deleted.'); $this->logger->info("BOOK: has been Inactived successfully. Inactived ID = " . $id); } else { $this->logger->error("BOOK: Not able to Inactive ID =" . $id); throw new \Exception("Data Not able to Deleted"); } } catch (\Exception $e) { $this->logger->error("Book: Err Occur = ".$e->getMessage()." File = ". $e->getFile() . " Line = " . $e->getLine()); session()->setFlashdata('error', 'Message: ' . $e->getMessage()); } return redirect()->route('causes_list'); } }