diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3bf3c339..e0bdcd22 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -104,6 +104,9 @@ $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->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("new_book_invoice/(:any)", "Invoice::new_book_invoice/$1"); diff --git a/app/Controllers/Event.php b/app/Controllers/Event.php index df5cbaa8..803763e6 100644 --- a/app/Controllers/Event.php +++ b/app/Controllers/Event.php @@ -7,59 +7,58 @@ use App\Models\EventModel; class Event extends BaseController -{ - public function index() - { - helper('session'); - if (is_session_active()) { - $session_role = get_user_role(); - $session_bid = get_business_id(); + public function index() + { + helper('session'); + if (is_session_active()) { + $session_role = get_user_role(); + $session_bid = get_business_id(); - if (!empty($session_role) && $session_role !== "sadmin") { - $where = ['events.business_id' => (int)$session_bid]; + if (!empty($session_role) && $session_role !== "sadmin") { + $where = ['events.business_id' => (int)$session_bid]; + } else { + $where = ['events.business_id != ' => NULL]; + } + + $EventModel = new EventModel(); + $data['page_name'] = 'Event Details'; + $events = $EventModel->where($where)->orderBy('event_id', 'DESC')->findAll(); // Retrieve the events + + // Sort the events by ID in descending order (newest first) + // usort($events, function ($a, $b) { + // return $b['id'] - $a['id']; + // }); + + $data['event'] = $events; // Assign the sorted array to $data['event'] + $data['session_bid'] = $session_bid; + + $this->render_page('event_list', $data); } else { - $where = ['events.business_id != ' => NULL]; + return redirect()->to('login'); + } + } + + public function new_event($id) + { + helper('session'); + $session_bid = get_business_id(); + if ($id === '0') { + $data['page_name'] = 'Add Event'; + $data['event'] = []; + } else if ($id !== '0') { + $data['page_name'] = 'Edit Event'; + $model = new EventModel(); + $model->setTable('events'); + $edit_event_details = $model->where(['event_id' => $id])->first(); + $data['event'] = $edit_event_details; } - $EventModel = new EventModel(); - $data['page_name'] = 'Event Details'; - // $events = $EventModel->where($where)->orderBy('id', 'desc')->findAll(); // Retrieve the events - $events = $EventModel->where($where)->orderBy('id', 'DESC')->findAll(); // Retrieve the events + $data['session_bid'] = $session_bid; - // Sort the events by ID in descending order (newest first) - // usort($events, function ($a, $b) { - // return $b['id'] - $a['id']; - // }); - - $data['event'] = $events; // Assign the sorted array to $data['event'] - - $this->render_page('event_list', $data); - } else { - return redirect()->to('login'); - } -} - -public function new_event($id) -{ - helper('session'); - $session_bid = get_business_id(); - if ($id === '0') { - $data['page_name'] = 'Add Event'; - $data['event'] = []; - } else if ($id !== '0') { - $data['page_name'] = 'Edit Event'; - $model = new EventModel(); - $model->setTable('events'); - $edit_event_details = $model->where(['id' => $id])->first(); - - $data['event'] = $edit_event_details; + $this->render_page('event_form', $data); } - $data['session_bid'] = $session_bid; - - $this->render_page('event_form', $data); -} public function insert_event() { $this->logger->info("Event: Inserting/Updating Details"); @@ -70,12 +69,9 @@ public function new_event($id) $EventModel = new EventModel(); $data = [ 'event_name' => $this->request->getPost('ename'), - 'next_id' => $this->request->getPost('nextid'), - 'left_pad' => $this->request->getPost('leftpad'), - 'id_formating' => $this->request->getPost('formating'), 'business_id' => $this->request->getPost('business_id') ]; - $event_id = $this->request->getPost('id'); // Get the business ID for update + $event_id = $this->request->getPost('event_id'); // Get the business ID for update if (empty($event_id)) { // It's an insert operation @@ -106,4 +102,64 @@ public function new_event($id) return redirect()->route('event_list'); } -} \ No newline at end of file + public function invoice_number_format($id) + { + helper('session'); + $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; + + $this->render_page('invoice_number_formatting', $data); + } + public function insert_invoice_number_format() + { + $this->logger->info("insert_invoice_number_format: Inserting/Updating Details"); + try { + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $EventModel = new EventModel(); + $data = [ + 'next_id' => $this->request->getPost('nextid'), + 'left_pad' => $this->request->getPost('leftpad'), + 'id_formating' => $this->request->getPost('formating'), + 'business_id' => $this->request->getPost('business_id') + ]; + $pk_id = $this->request->getPost('id'); // Get the business ID for update + + if (empty($pk_id)) { + // It's an insert operation + $data['created_by'] = $session_uid; + // $EventModel->insert($data); + $insert_result = $EventModel->insertData('invoice_number_formatting', $data); + + if ($insert_result['info']) { + session()->setFlashdata('success', "updated Successfully"); + $this->logger->info($insert_result['info']); + } else { + session()->setFlashdata('error', $insert_result['err']); + $this->logger->error($insert_result['err']); + } + } else { + // It's an update operation + $data['updated_by'] = $session_uid; + $where = ['id' => $pk_id, 'business_id' => get_business_id()]; + $update_result = $EventModel->updateData('invoice_number_formatting', $data,$where); + if ($update_result['info']) { + session()->setFlashdata('success',"updated Successfully"); + $this->logger->info($update_result['info']); + } else { + session()->setFlashdata('error', $update_result['err']); + $this->logger->error($update_result['err']); + } + } + } catch (\Exception $e) { + $this->logger->error("Event: Err Occur = " . $e->getMessage() . " Line = " . $e->getLine() . " File = " . $e->getFile()); + session()->setFlashdata('error', 'Message: ' . $e->getMessage()); + } + return redirect()->to(base_url("invoice_number_format/1")); + } +} diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index e8e2f5b6..c29e1ee8 100644 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -47,6 +47,7 @@ class Invoice extends BaseController // Get customer names for the dropdown, events details, and books details $data['customers'] = $model->getData('customers', $where); $data['events'] = $model->getData('events', $where); + $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where); $data['books'] = $model->getNonMembershipCategoryBooks('books', $where); if ($id === '0') { @@ -76,7 +77,7 @@ class Invoice extends BaseController $data['customers'] = $model->getData('customers', $where); $data['events'] = $model->getData('events', $where); $data['books'] = $model->getCategoryBooks('books', $where); - + $data['invoice_number_formatting'] = $model->getData('invoice_number_formatting', $where); if ($id === '0') { $this->logger->info("Subscription Invoice: In Add Page"); $data['page_name'] = 'Add Subscription Invoice Details'; @@ -209,14 +210,14 @@ class Invoice extends BaseController $requestData = $this->request->getPost(); + if($this->request->getPost('event_next_id') != ""){ ## Array Formation For Events Details And Updating Events also Here.. $update_events = [ - 'id' => $this->request->getPost('event_id'), + 'id' => 1, 'next_id' => $this->request->getPost('event_next_id'), - 'business_id' => get_business_id(), 'updated_by' => get_logged_user_id() ]; - $this->update_events($update_events); + $this->update_number_formatting($update_events);} ## For Invoice Item Details Insert/Update.. @@ -275,17 +276,17 @@ class Invoice extends BaseController } ## For Updating Events Details .. - public function update_events($update_events) + public function update_number_formatting($update_events) { // `id``event_name``business_id``updated_by``updated_on``next_id` $model = new InvoiceModel(); - $model->setTable('events'); + $model->setTable('invoice_number_formatting'); $where = ['isactive' => 1, 'id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id'], 'next_id' => $update_events['next_id']]; $details = $model->where($where)->findAll(); if (empty($details)) { $update_where = ['id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id']]; $update_data = ['next_id' => $update_events['next_id'], 'updated_by' => $update_events['updated_by']]; - $model->updateData('events', $update_data, $update_where); + $model->updateData('invoice_number_formatting', $update_data, $update_where); } } diff --git a/app/Controllers/Subscription.php b/app/Controllers/Subscription.php index cb9a5158..849f2950 100644 --- a/app/Controllers/Subscription.php +++ b/app/Controllers/Subscription.php @@ -81,7 +81,6 @@ public function add_subscription() { $SubscriptionModel->insert($data); - // $data['subscriber'] = $subscriberModel->getAllSubscribersWithNames(); // print_r($data);die(); return redirect()->to('subscribers_list')->with('data', $data); diff --git a/app/Models/EventModel.php b/app/Models/EventModel.php index d0bd5483..e5dccad5 100644 --- a/app/Models/EventModel.php +++ b/app/Models/EventModel.php @@ -8,10 +8,8 @@ use CodeIgniter\Model; class EventModel extends Model { protected $table = 'events'; - protected $primaryKey = 'id'; - protected $allowedFields = ['id','event_name','next_id','left_pad','id_formating','created_by','created_on','updated_on' ,'updated_by','business_id']; - - + protected $primaryKey = 'event_id'; + protected $allowedFields = ['event_id','event_name','created_by','created_on','updated_on' ,'updated_by','business_id']; public function getEventnamesByBusiness($business_id) { @@ -19,6 +17,38 @@ class EventModel extends Model $query = $this->builder()->get(); // Use findAll() instead of get() return ($query->getResult()); } + + public function setTable($tableName) + { + $this->table = $tableName; + return $this; + } + + public function insertData($table, $data) + { + try { + $this->db->table($table)->insert($data); + $last_insert_id = $this->db->insertID(); + return ["info"=>$last_insert_id,"err"=>""]; + } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { + return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; + } catch (\Exception $e) { + return ["info"=>"","err"=>'An error occurred: ' . $e->getMessage()]; + } + } + + public function updateData($table, $data, $where) + { + try { + $this->db->table($table)->update($data, $where); + $affected_rows = $this->db->affectedRows(); + return ["info"=>$affected_rows." Affected","err"=>""]; + } catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) { + return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; + } catch (\Exception $e) { + return ["info"=>"","err"=>'Database operation failed: ' . $e->getMessage()]; + } + } } ?> \ No newline at end of file diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 0b728683..76fb6ced 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -54,17 +54,17 @@ public function updateData($table, $data, $where) $scheme_name = []; $from_subscription = []; $to_subscription = []; - $invoiceItems = $this->getInvoiceItems($invoiceId); + $invoiceItems = $this->getInvoiceItems2($invoiceId); foreach ($invoiceItems as $j => $child) { if ($child->category_name == 'Membership') { $scheme_name[] = $child->title; - $from_subscription[] = $child->from_subscription ? date('d/m/Y', strtotime($child->from_subscription)) : ""; - $to_subscription[] = $child->to_subscription ? date('d/m/Y', strtotime($child->to_subscription)) : ""; + $from_subscription[] = ($j == 0 && !empty($child->from_subscription) && $child->from_subscription !== null) ? date('d/m/Y', strtotime($child->from_subscription)) : ""; + $to_subscription[] = ($j == 0 && !empty($child->to_subscription) && $child->from_subscription !== null ) ? date('d/m/Y', strtotime($child->to_subscription)) : ""; } } $result[$i]['scheme_name'] = !empty($scheme_name) ? implode(", ", $scheme_name) : ''; - $result[$i]['from_subscription'] = !empty($from_subscription) ? implode(", ", $from_subscription) : ''; - $result[$i]['to_subscription'] = !empty($to_subscription) ? implode(", ", $to_subscription) : ''; + $result[$i]['from_subscription'] = !empty($from_subscription) ? implode(" ", $from_subscription) : ''; + $result[$i]['to_subscription'] = !empty($to_subscription) ? implode(" ", $to_subscription) : ''; $result[$i]['invoice_items_details'] = $invoiceItems; } } @@ -77,7 +77,7 @@ public function updateData($table, $data, $where) return $this->db->table($this->table.' as I' ) ->join('customers as C', 'C.customer_id = I.customer_id', 'left') - ->join('events as E', 'E.id = I.event_id', 'left') + ->join('events as E', 'E.event_id = I.event_id', 'left') ->join('business as B', 'B.business_id = I.business_id', 'left') ->join('users as U1', 'U1.user_id = I.created_by', 'left') ->join('users as U2', 'U2.user_id = I.updated_by', 'left') @@ -152,6 +152,22 @@ public function updateData($table, $data, $where) return $data; } + public function getInvoiceItems2($id) + { + $data = $this->db->table('invoiceitems') + ->where(['invoice_id' => $id, 'invoiceitems.isactive' => 1]) + ->join('books as B', 'B.book_id = invoiceitems.product', 'left') + ->join('book_categories as BC', 'BC.book_id = invoiceitems.product', 'left') + ->join('category as C', 'C.id = BC.category_id', 'left') + ->select('invoiceitems.*,B.*,C.name as category_name') + //->orderBy("book_img_id", "asc") // Order by book_img_id in ascending order + //->limit(1,0) + ->get() + ->getResult(); + + // print_r($this->db->getLastQuery()); + return $data; + } public function getMembershipListForCustomer($category, $id) { diff --git a/app/Views/event_form.php b/app/Views/event_form.php index dbdeea5b..de95196a 100644 --- a/app/Views/event_form.php +++ b/app/Views/event_form.php @@ -8,19 +8,19 @@
-
+
Please provide.
-
+
-
+ +
diff --git a/app/Views/event_list.php b/app/Views/event_list.php index 37ba51bb..c1cf267b 100644 --- a/app/Views/event_list.php +++ b/app/Views/event_list.php @@ -34,20 +34,15 @@ Event Name - Next ID - Left Pad Action - + - - - " class="edit-button"> - + " class="edit-button"> diff --git a/app/Views/invoice_form.php b/app/Views/invoice_form.php index 954392e6..d086f31c 100644 --- a/app/Views/invoice_form.php +++ b/app/Views/invoice_form.php @@ -54,8 +54,8 @@ @@ -506,9 +506,25 @@ \ No newline at end of file diff --git a/app/Views/template/header.php b/app/Views/template/header.php index c1d102d6..7aa8d27b 100644 --- a/app/Views/template/header.php +++ b/app/Views/template/header.php @@ -178,6 +178,14 @@ +
  • + "> + + Invoice Number Format + +
  • + +
  • ">