diff --git a/app/Controllers/Customer.php b/app/Controllers/Customer.php index 26e07483..8a5ba75d 100644 --- a/app/Controllers/Customer.php +++ b/app/Controllers/Customer.php @@ -10,9 +10,10 @@ class Customer extends BaseController ## For Business Listing public function index() { - $session = \Config\Services::session(); - $session_role = $session->get('user_role'); - $session_bid = $session->get('business_id'); + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $CustomerModel =new CustomerModel(); $data['page_name'] = 'Customer Listing'; @@ -28,11 +29,11 @@ class Customer extends BaseController $data['customer'] = []; } else if ($id !== '0') { $data['page_name'] = 'Edit Customer'; - $model = new BusinessModel(); - $model->setTable('business'); - $edit_user_details = $model->where(['business_id ' => $id])->first(); + $model = new CustomerModel(); + $model->setTable('customers'); + $edit_user_details = $model->where(['customer_id' => $id])->first(); - $data['businesses'] = $edit_user_details; + $data['customer'] = $edit_user_details; } @@ -40,7 +41,30 @@ class Customer extends BaseController } public function insert_customer() { - + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $validationRule = [ + 'userfile' => [ + 'label' => 'Image File', + 'rules' => [ + 'uploaded[cfile]', + 'is_image[cfile]', + 'mime_in[cfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]', + + ], + ], + ]; + if (!$this->validate($validationRule)) { + $data = ['errors' => $this->validator->getErrors()]; + print_r($data); + return 'hello'; + } + $img = $this->request->getFile('cfile'); + + if (!$img->hasMoved()) { + $filepath = WRITEPATH . 'uploads/' . $img->store(); + $fileName = $img->getName(); $CustomerModel =new CustomerModel(); $data = [ 'first_name' => $this->request->getPost('cfname'), @@ -59,12 +83,24 @@ class Customer extends BaseController 'mode'=>$this->request->getPost('cmode'), 'isactive' => $this->request->getPost('ccheckbox') ? 1 : 0 ]; - + $customer_id = $this->request->getPost('customer_id'); // Get the business ID for update + + if (empty($customer_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; + $CustomerModel->insert($data); + } else { + // It's an update operation + $isactive = $this->request->getPost('isactivce'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $CustomerModel->update($customer_id, $data); + } + return redirect()->route('customer_list'); + } + } - $CustomerModel->insert($data); - - - $this->index(); - } - } + +} \ No newline at end of file diff --git a/app/Controllers/Scheme.php b/app/Controllers/Scheme.php index 52d77415..14aecabc 100644 --- a/app/Controllers/Scheme.php +++ b/app/Controllers/Scheme.php @@ -10,9 +10,10 @@ class Scheme extends BaseController ## For Business Listing public function index() { - $session = \Config\Services::session(); - $session_role = $session->get('user_role'); - $session_bid = $session->get('business_id'); + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $SchemeModel =new SchemeModel(); $data['page_name'] = 'Scheme Listing'; @@ -27,12 +28,12 @@ class Scheme extends BaseController $data['page_name'] = 'Add Scheme'; $data['scheme'] = []; } else if ($id !== '0') { - $data['page_name'] = 'Edit Customer'; - $model = new BusinessModel(); - $model->setTable('business'); - $edit_user_details = $model->where(['business_id ' => $id])->first(); + $data['page_name'] = 'Edit Scheme'; + $model = new SchemeModel(); + $model->setTable('schemes'); + $edit_user_details = $model->where(['scheme_id ' => $id])->first(); - $data['businesses'] = $edit_user_details; + $data['scheme'] = $edit_user_details; } @@ -40,7 +41,10 @@ class Scheme extends BaseController } public function insert_scheme() { - + helper('session'); + $session_bid = get_business_id(); + $session_uid = get_logged_user_id(); + $SchemeModel =new SchemeModel(); $data = [ 'scheme_name' => $this->request->getPost('sname'), @@ -49,12 +53,20 @@ class Scheme extends BaseController 'duration' => $this->request->getPost('sduration') ]; - - - + $scheme_id = $this->request->getPost('scheme_id'); // Get the business ID for update + + if (empty($scheme_id)) { + // It's an insert operation + $data['isactive'] = 1; + $data['created_by'] = $session_uid; $SchemeModel->insert($data); - - - $this->index(); - } - } + } else { + // It's an update operation + $isactive = $this->request->getPost('isactive'); + $data['isactive'] = ($isactive == 'on') ? 1 : 0; + $data['updated_by'] = $session_uid; + $SchemeModel->update($scheme_id, $data); + } + return redirect()->route('scheme_list'); + } + } \ No newline at end of file diff --git a/app/Views/business_list.php b/app/Views/business_list.php index 4c994124..c2b05827 100644 --- a/app/Views/business_list.php +++ b/app/Views/business_list.php @@ -3,7 +3,7 @@

@@ -12,7 +12,7 @@ - +
diff --git a/app/Views/customer_form.php b/app/Views/customer_form.php index 17e60d34..5c000659 100644 --- a/app/Views/customer_form.php +++ b/app/Views/customer_form.php @@ -10,34 +10,34 @@
- +
- +
- +
- +
- +
- +
@@ -45,32 +45,32 @@
- +
- +
- +
- +
- @@ -81,22 +81,23 @@
- +
- +
- +
- + +
- > + >

diff --git a/app/Views/customer_list.php b/app/Views/customer_list.php index c1f3c5fd..1889dd22 100644 --- a/app/Views/customer_list.php +++ b/app/Views/customer_list.php @@ -1,3 +1,8 @@ + + + + +
@@ -15,7 +20,7 @@ -
+
@@ -29,6 +34,7 @@ + @@ -48,6 +54,10 @@ + diff --git a/app/Views/scheme_form.php b/app/Views/scheme_form.php index f6d56865..bcfefdc8 100644 --- a/app/Views/scheme_form.php +++ b/app/Views/scheme_form.php @@ -10,29 +10,29 @@
- +
- +
- +
- +
- +
- > + >

diff --git a/app/Views/scheme_list.php b/app/Views/scheme_list.php index e9848510..b1ea05c4 100644 --- a/app/Views/scheme_list.php +++ b/app/Views/scheme_list.php @@ -6,7 +6,7 @@

@@ -23,6 +23,7 @@ + @@ -37,6 +38,12 @@ + +
City Type ModeAction
+ " class="edit-button"> + " class="delete-button"> +
Description Price DurationAction + " class="edit-button"> + " class="edit-button"> + +