diff --git a/application/modules/Expence/controllers/Expence.php b/application/modules/Expence/controllers/Expence.php index 20de4e0..f4c3598 100644 --- a/application/modules/Expence/controllers/Expence.php +++ b/application/modules/Expence/controllers/Expence.php @@ -162,127 +162,108 @@ public function edit_expence($id) public function edit_rise_expence_request() { - $id = $this->input->post('expense_pid'); - $data = $this->input->post('emp_id'); - if(!empty($data)){ - $emp_id =$this->input->post('emp_id'); - }else{ - $emp_id = user()->id; - } - $get_manager_id = $this->Expence_model->get_manager_id($emp_id); + // Expense primary key + $id = $this->input->post('expense_pid'); + + // Employee id + $emp_id = (!empty($this->input->post('emp_id'))) ? $this->input->post('emp_id') : user()->id; + + // Manager id + $manager = $this->Expence_model->get_manager_id($emp_id); + $manager_id = (!empty($manager)) ? $manager[0]->manager : 0; - if($get_manager_id[0]->manager == null){ + // Table Name Declarations + $expense_master_table = "expense"; + $expense_child_table = "expense_child"; - $manager = 0; - }else{ - - $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, + // 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'), + 'manager_id' => $manager_id, 'business_id' => user()->business_id, - 'status'=>'Draft', + 'status' => 'Draft', ); - $table="expense"; - $create_Expence = $this->MY_Model->edit_option($data1, $id, $table); - - $count = count($this->input->post('date_of_expence')); - for($i=0;$i<$count;$i++) - { - $expense_child_id = $this->input->post('expense_child_id')[$i]; - $data2 = array( - 'date_of_expense'=> $this->input->post('date_of_expence')[$i], + + // 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'); + $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], 'amount' => $this->input->post('amount')[$i], 'description' => $this->input->post('description')[$i], - ); - $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"; - $update_expence_list = $this->MY_Model->edit_option($data2, $expense_child_id, $table); - - } - - if($this->input->post('date_of_expence2')) - { - - $count = count($this->input->post('date_of_expence2')); - for($i=0;$i<$count;$i++) - { - - $data2 = array( - 'expense_id' => $this->input->post('expense_pid'), - 'emp_id'=>$emp_id , - 'business_id' => user()->business_id, - 'manager_id' => $manager, - 'status' => 'Draft', - 'date_of_expense'=> $this->input->post('date_of_expence2')[$i], - 'amount' => $this->input->post('amount2')[$i], - 'description' => $this->input->post('description2')[$i], - ); - $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['bill2']['name'][$i]; - - $_FILES['userfile']['name'] = $_FILES['bill2']['name'][$i]; - $_FILES['userfile']['type'] = $_FILES['bill2']['type'][$i]; - $_FILES['userfile']['tmp_name'] = $_FILES['bill2']['tmp_name'][$i]; - $_FILES['userfile']['error'] = $_FILES['bill2']['error'][$i]; - $_FILES['userfile']['size'] = $_FILES['bill2']['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); - //print_r($this->db->last_query()); die; - } - + ); + + $update_expense_list = $this->MY_Model->edit_option($first_child, $expense_child_id, $expense_child_table); + log_message('info', "update_expense_list - expense_id => ".$id." is updated == ".$update_expense_list); } - - redirect('Expence/Emp_Expence_List'); - + } + + // Details gathering from JavaScript new entries + $second = $this->input->post('date_of_expence2'); + $additional_count = (gettype($second) == 'array') ? count($second) : 0; + if ($additional_count > 0) { + for ($j = 0; $j < $additional_count; $j++) { + $second_child = array( + 'expense_id' => $id, + 'emp_id' => $emp_id, + 'business_id' => user()->business_id, + 'manager_id' => $manager_id, + 'status' => 'Draft', + 'date_of_expense' => $this->input->post('date_of_expence2')[$j], + 'amount' => $this->input->post('amount2')[$j], + 'description' => $this->input->post('description2')[$j], + ); + 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 { + log_message('error', $upload_result['error']); + } + } + $create_expense_list = $this->MY_Model->insert($second_child, $expense_child_table); + log_message('info', "create_expense_list - expense_id => ".$id." is created == ".$create_expense_list); + } + } + + redirect('Expence/Emp_Expence_List'); } + private function upload_file($file_data, $index) + { + $this->load->library('upload'); + + $config['upload_path'] = APPPATH . '../assets/uploads/Expense_Bill/'; + $config['allowed_types'] = 'jpg|png|jpeg|pdf'; + $config['max_size'] = 80000; + $config['file_name'] = time() . '_' . $file_data['name'][$index]; + + $_FILES['userfile']['name'] = $file_data['name'][$index]; + $_FILES['userfile']['type'] = $file_data['type'][$index]; + $_FILES['userfile']['tmp_name'] = $file_data['tmp_name'][$index]; + $_FILES['userfile']['error'] = $file_data['error'][$index]; + $_FILES['userfile']['size'] = $file_data['size'][$index]; + + $this->upload->initialize($config); + + if ($this->upload->do_upload('userfile')) { + $upload_data = $this->upload->data(); + return array('success' => true, 'file_name' => $upload_data['file_name']); + } else { + $error = $this->upload->display_errors(); + return array('success' => false, 'error' => $error); + } + } + + public function expence_list() { $business_id = user()->business_id; @@ -504,7 +485,7 @@ public function cancled_expence() public function remove_row() { - $get_count_from_child = $this->Expence_model->get_expense_child_data(md5($this->input->post('expence_id'))); + $get_count_from_child = $this->Expence_model->get_expense_child_data2($this->input->post('expence_id')); $count = count($get_count_from_child); if($count === 1) { diff --git a/application/modules/Expence/views/edit_expence.php b/application/modules/Expence/views/edit_expence.php index 2658c91..3d10cce 100644 --- a/application/modules/Expence/views/edit_expence.php +++ b/application/modules/Expence/views/edit_expence.php @@ -8,280 +8,279 @@
-
-
+
+
- - - session->unset_userdata('remove_row');?> - - + - +

-

+ status == 'Draft') { ?> - status == 'Draft') { ?> + Edit Expense - id)) { + echo $expense_data[0]->expense_name; + } ?> - Edit Expense - id)){echo $expense_data[0]->expense_name; } ?> + expense_name; + } ?> - expense_name; } ?> - -

- -
-
-
-
-
- - - -
-
- - -
- - Self - - Others + +
+
+
+ - -
- -
+ -
+
+
+ + +
+ + Self + + Others + +
+ + +
+ +
+ +
-
+
- -
-
- + +
+
+ -
+
-
+
- -
-
- + +
+
+ - + -
+
-
-
-
+
+
+
-
-
- -
-

+
+

- $value) { ?> + $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 $value->status; + } - ?> + ?> "> -
-
+
+
-
+
- -
-
- perm_date_new is in the 'Y-m-d' format - $formatted_date = date('d-m-y', strtotime($value->date_of_expense_new)); - ?> + +
+
+ perm_date_new is in the 'Y-m-d' format + $formatted_date = date('d-m-y', strtotime($value->date_of_expense_new)); + ?> - -
+ +
-
- -
- -
-
+
+ +
+ +
+
- + -
- -
- +
+ +
+ +
+ + + + + status == 'Draft') { ?> + +
1){ ?> + + + +
+ + +
+ + + + + + + +
+
+ + +
+
+
+ status == 'Draft') { ?> + Cancel + + +
+
+ +
- - - - -status == 'Draft') { ?> - -
- - - -
- - -
- - - - - - - -
-
- - -
-
-
- status == 'Draft') { ?> -Cancel - - -
-
- - -
-
+
@@ -297,86 +296,80 @@ - + - + + + - - - + - -}); + + $("#user_dropdown").on("change", function() { + let manager_id = $(this).children(":selected").attr("id"); - + }) + - -} + + var id = $(this).attr('id'); + var expence_id = document.getElementById('expense_id').value; + var url = "Expence/remove_row"; - + // // $.ajax({ + // // data:{id : id}, + // // url: "Expence/get_expense_child_count", + // // type:"GET", + // // success:function(data){ + // // $('#popup').html(JSON.parse(data)); + // // $('.delete_id').attr('value',id); + // // $('.expence_id').attr('value',expence_id); + // // $('.delete_url').attr('action',url); + // // } + // // }); + // }); + \ No newline at end of file