From dd8d8be3c0d995cfc9723029e09cd58942150b5c Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Wed, 8 May 2024 04:26:00 +0000 Subject: [PATCH] FIX_Expense Module : ps --- .../modules/Expence/controllers/Expence.php | 164 +++++++++--------- .../modules/Expence/views/edit_expence.php | 55 +++--- .../modules/Expence/views/expence_form.php | 18 +- .../Layout/views/includes/default_header.php | 17 +- .../Layout/views/includes/employee_header.php | 18 +- .../Layout/views/includes/employee_menu.php | 19 +- 6 files changed, 153 insertions(+), 138 deletions(-) diff --git a/application/modules/Expence/controllers/Expence.php b/application/modules/Expence/controllers/Expence.php index f4c3598..4b2fedc 100644 --- a/application/modules/Expence/controllers/Expence.php +++ b/application/modules/Expence/controllers/Expence.php @@ -68,85 +68,72 @@ public function get_emp_name() public function rise_expence_request() { - $data = $this->input->post('emp_id'); - if(!empty($data)){ - $emp_id =$this->input->post('emp_id'); - }else{ - $emp_id = user()->id; - } - // echo $emp_id;die; - $get_manager_id = $this->Expence_model->get_manager_id($emp_id); -// echo $get_manager_id[0]->manager;die; - if($get_manager_id[0]->manager == null){ + ## Logged In Variables + $logged_in_user = user()->id; + $logged_in_business = user()->business_id; + + ## Form Requested Data + $requested_data = $this->input->post(); + + //Employee id + $employee_id = (isset($requested_data['emp_id']) && !empty($requested_data['emp_id'])) ? $requested_data['emp_id'] : $logged_in_user; - $manager = 0; - }else{ + //Manager id + $get_manager_details = $this->Expence_model->get_manager_id($employee_id); + $manager_id = ((!empty($get_manager_details)) && $get_manager_details[0]->manager != null) ? $get_manager_details[0]->manager : 0; - $manager = $get_manager_id[0]->manager; - } - - $data1 = array( - 'created_by'=>user()->id, - 'requested_for'=>$emp_id , - 'expense_name'=>$this->input->post('expense_name'), - 'business_reason'=>$this->input->post('business_reason'), - 'manager_id' => $manager, - 'business_id' => user()->business_id, + // Table Name Declarations + $expense_master_table = "expense"; + $expense_child_table = "expense_child"; + + // Array formation for updating the master details + $expense_master_arr = array( + 'created_by'=>$logged_in_user, + 'requested_for'=>$employee_id, + 'expense_name'=>$requested_data['expense_name'], + 'business_reason'=>$requested_data['business_reason'], + 'manager_id' => $manager_id, + 'business_id' => $logged_in_business, 'status'=>'Draft', ); - $table="expense"; - $create_Expence = $this->MY_Model->insert($data1,$table); - // $count = count($this->input->post('date_of_expence')); - $count = ($this->input->post('date_of_expence_new')) ? count($this->input->post('date_of_expence_new')) : 1; - // echo json_encode($this->input->post());die; - for($i=0;$i<$count;$i++) - { - - $data2 = array( - 'expense_id' => $create_Expence, - 'emp_id'=>$emp_id , - 'business_id' => user()->business_id, - 'manager_id' => $manager, + ## Retrive the Inserted ID from Master Table + $create_expence = $this->MY_Model->insert($expense_master_arr,$expense_master_table); + + $first = $requested_data['date_of_expence_new']; + ## Get the Count for Child Expence + $count = (gettype($first) == 'array') ? count($first) : 0; + if ($count > 0) { + for ($i = 0; $i < $count; $i++) { + ##Preparing Array Stored in Expence child Table + $expense_child_arr = array( + 'expense_id' => $create_expence, + 'emp_id'=>$employee_id , + 'business_id' => $logged_in_business, + 'manager_id' => $manager_id, 'status' => 'Draft', - // 'date_of_expense'=> $this->input->post('date_of_expence')[$i], + 'date_of_expense'=> $this->input->post('date_of_expence_new')[$i], 'date_of_expense_new' => date('Y-m-d', strtotime($this->input->post('date_of_expence_new')[$i])), 'amount' => $this->input->post('amount')[$i], 'description' => $this->input->post('description')[$i], - ); - // print_r($data2);die; - $this->load->library('upload'); - - $config['upload_path'] = APPPATH. '../assets/uploads/Expence_Bill/'; - $config['allowed_types'] = 'jpg|png|jpeg|pdf'; - $config['max_size'] = 80000; - $config['file_name'] = time(). '_' . $_FILES['bill']['name'][$i]; - - $_FILES['userfile']['name'] = $_FILES['bill']['name'][$i]; - $_FILES['userfile']['type'] = $_FILES['bill']['type'][$i]; - $_FILES['userfile']['tmp_name'] = $_FILES['bill']['tmp_name'][$i]; - $_FILES['userfile']['error'] = $_FILES['bill']['error'][$i]; - $_FILES['userfile']['size'] = $_FILES['bill']['size'][$i]; - - $this->upload->initialize($config); - if ($this->upload->do_upload('userfile')) - { - $upload_image = $this->upload->data(); - $data2['bill'] = $upload_image['file_name']; - } - else - { - $error = $this->upload->display_errors(); - } - - $table="expense_child"; - $create_expence_list = $this->MY_Model->insert($data2,$table); - } - - + ); + + if (!empty($_FILES['bill']['name'][$i])) { + $upload_result = $this->upload_file($_FILES['bill'], $i); + + if ($upload_result['success']) { + $expense_child_arr['bill'] = $upload_result['file_name']; + } else { + log_message('error', $upload_result['error']); + } + } + + $create_expence_child = $this->MY_Model->insert($expense_child_arr, $expense_child_table); + } + } $this->session->set_flashdata('Create', '1'); redirect('Expence/Emp_Expence_List'); - } + } public function edit_expence($id) @@ -162,15 +149,22 @@ public function edit_expence($id) public function edit_rise_expence_request() { - // Expense primary key - $id = $this->input->post('expense_pid'); + ## Logged In Variables + $logged_in_user = user()->id; + $logged_in_business = user()->business_id; + + ## Form Requested Data + $requested_data = $this->input->post(); + + ## Expense primary key + $id = $requested_data['expense_pid']; // Employee id - $emp_id = (!empty($this->input->post('emp_id'))) ? $this->input->post('emp_id') : user()->id; + $employee_id = (isset($requested_data['emp_id']) && !empty($requested_data['emp_id'])) ? $requested_data['emp_id'] : $logged_in_user; // Manager id - $manager = $this->Expence_model->get_manager_id($emp_id); - $manager_id = (!empty($manager)) ? $manager[0]->manager : 0; + $get_manager_details = $this->Expence_model->get_manager_id($employee_id); + $manager_id = ((!empty($get_manager_details)) && $get_manager_details[0]->manager != null) ? $get_manager_details[0]->manager : 0; // Table Name Declarations $expense_master_table = "expense"; @@ -178,25 +172,26 @@ public function edit_rise_expence_request() // Array formation for updating the master details $expense_master_arr = array( - 'created_by' => user()->id, - 'requested_for' => $emp_id, - 'expense_name' => $this->input->post('expense_name'), - 'business_reason' => $this->input->post('business_reason'), + 'created_by' => $logged_in_user, + 'requested_for' => $employee_id, + 'expense_name' => $requested_data['expense_name'], + 'business_reason' => $requested_data['business_reason'], 'manager_id' => $manager_id, - 'business_id' => user()->business_id, + 'business_id' => $logged_in_business, 'status' => 'Draft', ); // Update process for master $update_expense = $this->MY_Model->edit_option($expense_master_arr, $id, $expense_master_table); log_message('info', "update_expense_master - expense_id => ".$id." is updated == ".$update_expense); - $first = $this->input->post('date_of_expence_new'); + $first = $requested_data['date_of_expence_new']; $count = (gettype($first) == 'array') ? count($first) : 0; if ($count > 0) { for ($i = 0; $i < $count; $i++) { $expense_child_id = $this->input->post('expense_child_id')[$i]; $first_child = array( 'date_of_expense' => $this->input->post('date_of_expence_new')[$i], + 'date_of_expense_new' => date('Y-m-d', strtotime($this->input->post('date_of_expence_new')[$i])), 'amount' => $this->input->post('amount')[$i], 'description' => $this->input->post('description')[$i], ); @@ -213,7 +208,7 @@ public function edit_rise_expence_request() for ($j = 0; $j < $additional_count; $j++) { $second_child = array( 'expense_id' => $id, - 'emp_id' => $emp_id, + 'emp_id' => $employee_id, 'business_id' => user()->business_id, 'manager_id' => $manager_id, 'status' => 'Draft', @@ -223,6 +218,7 @@ public function edit_rise_expence_request() ); if (!empty($_FILES['bill2']['name'][$j])) { $upload_result = $this->upload_file($_FILES['bill2'], $j); + if ($upload_result['success']) { $second_child['bill'] = $upload_result['file_name']; } else { @@ -237,11 +233,13 @@ public function edit_rise_expence_request() redirect('Expence/Emp_Expence_List'); } - private function upload_file($file_data, $index) + public function upload_file($file_data, $index) { $this->load->library('upload'); - - $config['upload_path'] = APPPATH . '../assets/uploads/Expense_Bill/'; + + $upload_path = APPPATH . '../assets/uploads/Expense_Bill/'; + + $config['upload_path'] = realpath($upload_path); $config['allowed_types'] = 'jpg|png|jpeg|pdf'; $config['max_size'] = 80000; $config['file_name'] = time() . '_' . $file_data['name'][$index]; diff --git a/application/modules/Expence/views/edit_expence.php b/application/modules/Expence/views/edit_expence.php index e8044a5..64fec95 100644 --- a/application/modules/Expence/views/edit_expence.php +++ b/application/modules/Expence/views/edit_expence.php @@ -134,10 +134,10 @@
- +
- @@ -145,10 +145,10 @@
- +
- @@ -174,23 +174,18 @@ foreach ($expense_child_data as $key => $value) { ?>
- +
- status . ' By ' . $value->approved_by . ' - ' . date('d-m-Y h:i:s', strtotime($value->approved_at)); - } else if ($value->status == "Declined") { - echo $value->status . ' By ' . $value->decline_by . ' ( ' . $value->decline_reason . ' )'; - } else if ($value->status == "Cancelled") { - echo $value->status . ' at ' . date('d-m-Y h:i:s', strtotime($value->cancelled_at)); - } else { - echo $value->status; - } - - ?> - - -"> + status . ' By ' . $value->approved_by . ' - ' . date('d-m-Y h:i:s', strtotime($value->approved_at)); + } else if ($value->status == "Declined") { + echo $value->status . ' By ' . $value->decline_by . ' ( ' . $value->decline_reason . ' )'; + } else if ($value->status == "Cancelled") { + echo $value->status . ' at ' . date('d-m-Y h:i:s', strtotime($value->cancelled_at)); + } else { + echo trim($value->status); + } ?>">
@@ -210,7 +205,7 @@
- +
@@ -225,11 +220,19 @@
- +

- - View Recipt(bill; ?>) + + bill !== '' || $value->bill !== null) { + $billPath = base_url() . 'assets/uploads/Expence_Bill/' . $value->bill; + $billContents = @file_get_contents($billPath); + $bill = ($billContents !== false) ? $billPath : ""; + } + if (!$bill) { ?> + View Recipt() +
status == 'Draft') { ?> @@ -441,7 +444,7 @@ function createAndAppendFormGroup() { html1 += '
'; html1 += ''; html1 += '
'; - html1 += ''; + html1 += ''; html1 += '
'; html1 += '
'; @@ -450,7 +453,7 @@ function createAndAppendFormGroup() { html1 += '' html1 += '
' - html1 += '' + html1 += '' html1 += '
' html1 += '
' html1 += '

' diff --git a/application/modules/Expence/views/expence_form.php b/application/modules/Expence/views/expence_form.php index 533833a..db5745d 100644 --- a/application/modules/Expence/views/expence_form.php +++ b/application/modules/Expence/views/expence_form.php @@ -109,7 +109,7 @@
- +
@@ -118,10 +118,10 @@
- +
- +
@@ -155,7 +155,7 @@
- +
@@ -171,7 +171,7 @@
- +
@@ -194,7 +194,7 @@ - +
@@ -208,7 +208,7 @@ - +
@@ -403,7 +403,7 @@ function createAndAppendFormGroup() { html1 += '
'; html1 += ''; html1 += '
'; - html1 += ''; + html1 += ''; html1 += '
'; html1 += '
'; @@ -412,7 +412,7 @@ function createAndAppendFormGroup() { html1 += '' html1 += '
' - html1 += '' + html1 += '' html1 += '
' html1 += '' html1 += '
' diff --git a/application/modules/Layout/views/includes/default_header.php b/application/modules/Layout/views/includes/default_header.php index bc8dad1..41a33ed 100644 --- a/application/modules/Layout/views/includes/default_header.php +++ b/application/modules/Layout/views/includes/default_header.php @@ -91,12 +91,17 @@