diff --git a/application/modules/Expence/controllers/Expence.php b/application/modules/Expence/controllers/Expence.php index 964ebb2..20de4e0 100644 --- a/application/modules/Expence/controllers/Expence.php +++ b/application/modules/Expence/controllers/Expence.php @@ -110,10 +110,11 @@ public function rise_expence_request() 'manager_id' => $manager, 'status' => 'Draft', // 'date_of_expense'=> $this->input->post('date_of_expence')[$i], - 'date_of_expense_new'=> $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/'; diff --git a/application/modules/Expence/views/edit_expence.php b/application/modules/Expence/views/edit_expence.php index e259a81..2658c91 100644 --- a/application/modules/Expence/views/edit_expence.php +++ b/application/modules/Expence/views/edit_expence.php @@ -11,7 +11,7 @@ .alert-success { background-color: #dff0d8; color: #3c763d; - border-color: #d6e9c6; + border-color: #d6e9c6; } .flash-message { @@ -22,7 +22,7 @@ } .hide-arrow { - + -webkit-appearance: none; -moz-appearance: none; appearance: none; @@ -76,7 +76,7 @@ text: 'Only change and Update', styling: 'bootstrap3' });">Success - + session->unset_userdata('remove_row');?> @@ -463,10 +468,10 @@ function createAndAppendFormGroup() { //formContainer.innerHTML += html1; formContainer.insertAdjacentHTML('beforeend', html1); - + const datepickerInput = document.getElementById('datepicker'+i); flatpickr(datepickerInput, { - dateFormat: 'd-m-Y', + dateFormat: 'd-m-Y', maxDate: new Date(), autoclose:true, allowInput: false, @@ -474,9 +479,9 @@ function createAndAppendFormGroup() { onChange: function(selectedDates, dateStr) { console.log('Selected date: ', dateStr); } - }); + }); + - } function removebutton(index) { @@ -496,14 +501,14 @@ function removebutton(index) { var expence_id = document.getElementById('expense_id').value; var url = "Expence/remove_row"; - $.ajax({ + $.ajax({ url: "Expence/getCancelConfirmationPopup", 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); + $('.delete_url').attr('action',url); } }); }); @@ -513,19 +518,19 @@ function removebutton(index) { // var id = document.getElementById('expense_id').value; // alert(id) - + // $('.hidebtn').disable() -// // $.ajax({ -// // data:{id : id}, +// // $.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); +// // $('.delete_url').attr('action',url); // // } // // }); // }); - \ No newline at end of file + diff --git a/application/modules/Expence/views/expence_form.php b/application/modules/Expence/views/expence_form.php index ffea43c..4858953 100644 --- a/application/modules/Expence/views/expence_form.php +++ b/application/modules/Expence/views/expence_form.php @@ -144,7 +144,12 @@
- + perm_date_new is in the 'Y-m-d' format + $formatted_date = date('d-m-y', strtotime($value->date_of_expense_new)); + ?> + +
diff --git a/application/modules/Expence/views/expence_list_view.php b/application/modules/Expence/views/expence_list_view.php index cda5476..58b6dbb 100644 --- a/application/modules/Expence/views/expence_list_view.php +++ b/application/modules/Expence/views/expence_list_view.php @@ -198,7 +198,7 @@ id; ?> created_on));?> - date_of_expense)) ?> + date_of_expense_new)) ?> amount; ?> description; ?> status == 'pending'){ ?> diff --git a/application/modules/Leave/controllers/Leave.php b/application/modules/Leave/controllers/Leave.php index 594e48b..94fa158 100644 --- a/application/modules/Leave/controllers/Leave.php +++ b/application/modules/Leave/controllers/Leave.php @@ -86,7 +86,7 @@ public function leave_list_report() } } } - + $result = array_values($resultArray); // echo json_encode( $result, JSON_PRETTY_PRINT);die; $this->layout->set('leave_list', $result); @@ -165,19 +165,20 @@ public function createLeave() } else { - + $manager = employee()->manager; } - + }else{ - + $manager = $this->input->post('manager'); } $perm_data['manager'] = $manager; $perm_data['business_id'] = user()->business_id; $perm_data['status'] = 'pending'; // $perm_data['created_date'] = date('d-m-Y'); - $perm_data['created_date_new'] = date('d-m-Y'); + $perm_data['created_date_new'] = date('Y-m-d'); + $perm_data['created_time'] = date('H:i A'); unset($perm_data['from_date']); unset($perm_data['to_date']); @@ -185,35 +186,36 @@ public function createLeave() unset($perm_data['to_date_new']); $table="leave_list"; $perm_data['perm_date_new'] = date("Y-m-d", strtotime( $this->input->post('perm_date_new') )); + $create_permission = $this->MY_Model->insert($perm_data,$table); - + //for notification if($create_permission){ $code = 'LEAVE_PERMISSION'; $type = 'Email'; $this->notification->sendNotification($create_permission, $code, $type); } - + $this->session->set_flashdata('Success', '1'); redirect('Leave/LeaveHistory'); } //end of permission - - + + //Leave create part $data = $this->input->post(); unset($data['perm_date']); unset($data['perm_date_new']); unset($data['from_time']); unset($data['to_time']); - + if(isset($data['emp_id'])){ $emp_id =$this->input->post('emp_id'); }else{ $emp_id = user()->id; } $data['emp_id'] = $emp_id; - + if($data['manager']==""){ if(employee()->manager == null) { @@ -221,12 +223,12 @@ public function createLeave() } else { - + $manager = employee()->manager; } - + }else{ - + $manager = $this->input->post('manager'); } $data['manager'] = $manager; @@ -236,23 +238,23 @@ public function createLeave() $perm_data['created_date_new'] = date('d-m-Y'); $data['created_time'] = date('H:i A'); $leave_year = date('Y', strtotime($this->input->post('from_date_new'))); - + //get employee's leave count $emp_leave_count = $this->Leave_model->get_leave( $emp_id , user()->business_id , "emp_leave_days", $leave_year, $this->input->post('type')); $leave_master_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); - - + + // count number of days between two dates $days_between = ceil(abs(strtotime($this->input->post('to_date_new')) - strtotime($this->input->post('from_date_new'))) / 86400); $data['no_of_days'] = $days_between + 1; $noofdays = $days_between + 1; - - + + //this part is create and update leave data if (count($emp_leave_count) != 0) { - + if($noofdays > $emp_leave_count[0]->remaining_days) { $this->session->set_flashdata('error', '1'); @@ -265,7 +267,7 @@ public function createLeave() $days['remaining_days'] = $emp_leave_count[0]->remaining_days; $this->Leave_model->update_leave($days, $emp_id , 'emp_leave_days', $leave_year, $this->input->post('type')); } - + } else { @@ -279,26 +281,26 @@ public function createLeave() $all_leave_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); $data['leave_bal'] = $all_leave_count[0]->days; $days['remaining_days'] = $all_leave_count[0]->days; - + $days['business_id'] = user()->business_id; $days['emp_id'] = $emp_id; $days['total_days'] = $all_leave_count[0]->days; $days['type'] = $all_leave_count[0]->id; $days['year'] = $leave_year; $this->MY_Model->insert($days,'emp_leave_days'); - + } } - + $get_emp_data = $this->Leave_model->get_emp_data_by_emp_id($emp_id); // echo json_encode( $get_emp_data);die; // print_r($get_emp_data[0]->j_date); die; - + $from_date = new DateTime($this->input->post('from_date_new')); $j_date = new DateTime($get_emp_data[0]->j_date); $to_date = new DateTime($this->input->post('to_date_new')); - - + + if ($from_date >= $j_date && $from_date <= $to_date) { $table="leave_list"; $data['from_date_new'] = date("Y-m-d", strtotime( $this->input->post('from_date_new') )); @@ -308,15 +310,15 @@ public function createLeave() } else { $this->session->set_flashdata('error', '1'); redirect('Leave/applyLeave/'.'update'); - + } - + if($create_leave){ $code = 'APPLY_LEAVE'; $type = 'Email'; $mailres = $this->notification->sendNotification($create_leave, $code, $type); } - + //audit if($create_leave) { @@ -334,8 +336,8 @@ public function createLeave() } catch (Exception $e) { echo "An error occurred: " . $e->getMessage(); } - - + + } @@ -351,7 +353,7 @@ public function edit_leave_function() // print_r($leavetype); // print_r($id); // print_r($editleave); - // // // print_r($emp); + // print_r($emp); // die; $this->layout->set('emp', $emp); $this->layout->set('editleave', $editleave); @@ -367,8 +369,8 @@ public function editleave() if($this->input->post('type') === '1') { $action = $this->input->post(); - unset($action['from_date']); - unset($action['to_date']); + unset($action['from_date_new']); + unset($action['to_date_new']); $id = $this->input->post('id'); if(isset($action['emp_id'])){ @@ -385,10 +387,13 @@ public function editleave() $action['manager'] = $manager; $action['business_id'] = user()->business_id; $action['status'] = 'pending'; + $action['perm_date_new'] = date('Y-m-d', strtotime($this->input->post('perm_date_new'))); + $action['created_date'] = date('d-m-Y'); $action['created_time'] = date('H:i A'); $table="leave_list"; $create_permission = $this->MY_Model->edit_option($action, $id, $table); + $this->session->set_flashdata('update', '0'); redirect('Leave/LeaveHistory'); } @@ -405,27 +410,37 @@ public function editleave() $action['emp_id'] = $emp_id; $action['business_id'] = user()->business_id; $action['status'] = 'pending'; - $leave_year = date('Y', strtotime($this->input->post('from_date'))); + $action['from_date_new'] = date('Y-m-d', strtotime($this->input->post('from_date_new'))); + $action['to_date_new'] = date('Y-m-d', strtotime($this->input->post('to_date_new'))); + + + + $leave_year = date('Y', strtotime($this->input->post('from_date_new'))); $emp_leave_count = $this->Leave_model->get_leave( $emp_id , user()->business_id , "emp_leave_days", $leave_year, $this->input->post('type')); $leave_master_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); // count number of days between two dates - $days_between = ceil(abs(strtotime($this->input->post('to_date')) - strtotime($this->input->post('from_date'))) / 86400); + $days_between = ceil(abs(strtotime(date('Y-m-d', strtotime($this->input->post('to_date_new')))) - strtotime(date('Y-m-d', strtotime($this->input->post('from_date_new'))))) / 86400); + $action['no_of_days'] = $days_between + 1; $noofdays = $days_between + 1; $leave_id = $this->input->post('id'); if (count($emp_leave_count) != 0) { + if($noofdays > $emp_leave_count[0]->remaining_days) { + $this->session->set_flashdata('error', '1'); redirect('Leave/edit_leave_function?id='.md5($leave_id)); } else { + //this part is update if date inculeded in emp_leave_days table $action['leave_bal'] = $emp_leave_count[0]->remaining_days; + $days['remaining_days'] = $emp_leave_count[0]->remaining_days; $this->Leave_model->update_leave($days, $emp_id , 'emp_leave_days', $leave_year, $this->input->post('type')); } @@ -433,11 +448,15 @@ public function editleave() else { if($noofdays > $leave_master_count[0]->days) - { $this->session->set_flashdata('error', '1'); + { + + $this->session->set_flashdata('error', '1'); redirect('Leave/edit_leave_function?id='.md5($leave_id)); } else { + + echo "else stss"; $all_leave_count = $this->Leave_model->get_by_type( $this->input->post('type') , user()->business_id , "leave_master"); $data['leave_bal'] = $all_leave_count[0]->days; $days['remaining_days'] = $all_leave_count[0]->days; @@ -452,14 +471,16 @@ public function editleave() } } - $get_from_date = $this->Leave_model->get_from_date($emp_id, $this->input->post('from_date'), $this->input->post('to_date')); + $get_from_date = $this->Leave_model->get_from_date($emp_id, $this->input->post('from_date_new'), $this->input->post('to_date_new')); // echo "
";
-        // print_r($get_from_date); die();
+
 
         if($get_from_date == 0)
         {
+            echo"update fun:";
             $table="leave_list";
             $update_leave = $this->MY_Model->edit_option($action,$id,$table);
+
             $this->session->set_flashdata('update', '0');
              redirect('Leave/LeaveHistory');
         }
@@ -488,6 +509,7 @@ public function get_all_leave_count()
     {
         $id = $this->input->get('type_id');
         $all_leave_count = $this->Leave_model->get_id( $id , user()->business_id , "leave_master");
+
         echo json_encode($all_leave_count);
 
     }
@@ -512,14 +534,16 @@ public function ApproveLeave()
        $business_id = user()->business_id;
        $emp_id = $this->Leave_model->get_emp_id($id);
        $no_of_days = $this->Leave_model->get_Leave_nodays($id,);
-       $leave_year = date('Y', strtotime($no_of_days->from_date));
+       $leave_year = date('Y', strtotime($no_of_days->from_date_new));
        $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id);
 
+// print_r($leave_year);
+
         if($leave_type->leave_code !== 'permission')
         {
-            $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $no_of_days->type);
+            $remaining_days = $this->Leave_model->remaining_days($emp_id,$business_id, $leave_year, $no_of_days->type);
             $balance_days = $remaining_days[0]->remaining_days - $no_of_days->no_of_days;
-
+            // print_r($balance_days);die;
             $data['leave_bal'] = $balance_days;
             $days['remaining_days'] = $balance_days;
             $this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, $business_id, $no_of_days->type);
@@ -556,7 +580,7 @@ public function ManagerLeaveApprove()
        $business_id = user()->business_id;
        $emp_id = $this->Leave_model->get_emp_id($id);
        $no_of_days = $this->Leave_model->get_Leave_nodays($id,);
-       $leave_year = date('Y', strtotime($no_of_days->from_date));
+       $leave_year = date('Y', strtotime($no_of_days->from_date_new));
        $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id);
 
             $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $no_of_days->type);
@@ -691,7 +715,7 @@ public function DeclinewithdrawLeave()
        $business_id = user()->business_id;
        $emp_id = $this->Leave_model->get_emp_id($id);
        $no_of_days = $this->Leave_model->get_Leave_nodays($id,);
-       $leave_year = date('Y', strtotime($no_of_days->from_date));
+       $leave_year = date('Y', strtotime($no_of_days->from_date_new));
        $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id);
 
         if($leave_type->leave_code !== 'permission')
@@ -730,7 +754,7 @@ public function ApprovewithdrawLeave()
 
         // Update leave balance
         $emp_id = $this->Leave_model->get_emp_id($id);
-        $leave_year = date('Y', strtotime($leave_data->from_date));
+        $leave_year = date('Y', strtotime($leave_data->from_date_new));
         $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $leave_data->type);
         $balance_days = $remaining_days[0]->remaining_days + $leave_data->no_of_days;
 
diff --git a/application/modules/Leave/models/Leave_model.php b/application/modules/Leave/models/Leave_model.php
index 3ce8051..6760aa9 100644
--- a/application/modules/Leave/models/Leave_model.php
+++ b/application/modules/Leave/models/Leave_model.php
@@ -180,6 +180,7 @@ public function remaining_days($emp_id, $business_id, $leave_year, $type)
         $this->db->where('is_active', 1);
         $query = $this->db->get();
         $query = $query->result();
+        // print_r($this->db->last_query());
         return $query;
     }
 
@@ -511,8 +512,8 @@ public function get_from_date($emp_id, $from_date, $to_date)
         $this->db->select('*');
         $this->db->from('leave_list');
         $this->db->where('emp_id', $emp_id);
-        $this->db->where('from_date >=', $from_date);
-        $this->db->where('to_date <=', $to_date);
+        $this->db->where('from_date_new >=', $from_date);
+        $this->db->where('to_date_new <=', $to_date);
         $query = $this->db->count_all_results();
         return $query;
      }
@@ -544,8 +545,8 @@ public function get_approved_leaves_cur_week()
          $this->db->from('leave_list');
          $this->db->join('users', 'users.id = leave_list.emp_id', 'left');
          $this->db->group_start();
-         $this->db->where("STR_TO_DATE(from_date, '%d-%m-%Y') <= '$currentWeekEnd'");
-         $this->db->where("STR_TO_DATE(to_date, '%d-%m-%Y') >= '$currentWeekStart'");
+         $this->db->where("STR_TO_DATE(from_date_new, '%d-%m-%Y') <= '$currentWeekEnd'");
+         $this->db->where("STR_TO_DATE(to_date_new, '%d-%m-%Y') >= '$currentWeekStart'");
          $this->db->or_where("STR_TO_DATE(perm_date, '%d-%m-%Y') <= '$currentWeekEnd'");
          $this->db->or_where("STR_TO_DATE(perm_date, '%d-%m-%Y') >= '$currentWeekStart'");
          $this->db->group_end();
@@ -556,8 +557,8 @@ public function get_approved_leaves_cur_week()
          // Organize approved leave records into columns based on days of the week
          $weekData = [];
          foreach ($approvedLeaveRecords as $leave) {
-             $leaveStartDate = ($leave->from_date) ? date('Y-m-d', strtotime($leave->from_date)) : date('Y-m-d', strtotime($leave->perm_date));
-             $leaveEndDate = ($leave->to_date) ? date('Y-m-d', strtotime($leave->to_date)) : date('Y-m-d', strtotime($leave->perm_date));
+             $leaveStartDate = ($leave->from_date_new) ? date('Y-m-d', strtotime($leave->from_date_new)) : date('Y-m-d', strtotime($leave->perm_date));
+             $leaveEndDate = ($leave->to_date_new) ? date('Y-m-d', strtotime($leave->to_date_new)) : date('Y-m-d', strtotime($leave->perm_date));
 
              // Use from_time and to_time if available
              $fromTime = ($leave->from_time) ? ' ' . $leave->from_time : '';
@@ -586,7 +587,7 @@ public function get_week_leave_count($business_id)
      {
          $startOfWeek = date('Y-m-d', strtotime('monday this week'));
          $endOfWeek = date('Y-m-d', strtotime('sunday this week'));
-         
+
          // Query to get leave records for the specified employee within the current week
          $this->db->select('A.*, U1.name as employee_name');
          $this->db->from('leave_list A');
@@ -606,7 +607,7 @@ public function get_week_leave_count($business_id)
              'friday' => [],
              'saturday' => []
          );
-     
+
          // Iterate over the leave records to count leaves for each day of the week
          foreach ($leaveRecords as $key => $record) {
             if($record->from_date_new < $startOfWeek)
@@ -628,10 +629,10 @@ public function get_week_leave_count($business_id)
              }
              array_push($weeklyLeaveCounts[strtolower($startDate)], $record->employee_name); // Increment for the last day
          }
-     
+
          // Return the array with leave counts for each day of the week
          return $weeklyLeaveCounts;
      }
-     
+
 
 }
diff --git a/application/modules/Leave/views/edit_leave.php b/application/modules/Leave/views/edit_leave.php
index d311407..216a3ca 100644
--- a/application/modules/Leave/views/edit_leave.php
+++ b/application/modules/Leave/views/edit_leave.php
@@ -143,7 +143,7 @@
 
     
     
- +
@@ -154,7 +154,7 @@
- +
@@ -162,14 +162,14 @@
- +
- +
@@ -179,7 +179,12 @@
-
+ perm_date_new is in the 'Y-m-d' format + $formatted_date = date('d-m-y', strtotime($leave->perm_date_new)); + ?> + +
diff --git a/application/modules/Leave/views/leave_list.php b/application/modules/Leave/views/leave_list.php index 950941d..295870d 100644 --- a/application/modules/Leave/views/leave_list.php +++ b/application/modules/Leave/views/leave_list.php @@ -117,7 +117,7 @@ status == 'Withdraw-declined'){ ?> status; ?> By - declined_by; ?>
" DReason; ?> " + DeclineBy; ?>
" DReason; ?> " status == 'Withdraw-Approved'){ ?> status; ?> By