Expense issues fixes : ps

This commit is contained in:
VE10-Sanjeev 2024-03-19 12:59:21 +05:30
parent a19d955513
commit c9f450541a
2 changed files with 465 additions and 492 deletions

View File

@ -162,127 +162,108 @@ public function edit_expence($id)
public function edit_rise_expence_request() public function edit_rise_expence_request()
{ {
$id = $this->input->post('expense_pid'); // Expense primary key
$data = $this->input->post('emp_id'); $id = $this->input->post('expense_pid');
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);
if($get_manager_id[0]->manager == null){ // Employee id
$emp_id = (!empty($this->input->post('emp_id'))) ? $this->input->post('emp_id') : user()->id;
$manager = 0; // Manager id
}else{ $manager = $this->Expence_model->get_manager_id($emp_id);
$manager_id = (!empty($manager)) ? $manager[0]->manager : 0;
$manager = $get_manager_id[0]->manager; // Table Name Declarations
} $expense_master_table = "expense";
$expense_child_table = "expense_child";
// Array formation for updating the master details
$data1 = array( $expense_master_arr = array(
'created_by'=>user()->id, 'created_by' => user()->id,
'requested_for'=>$emp_id , 'requested_for' => $emp_id,
'expense_name'=>$this->input->post('expense_name'), 'expense_name' => $this->input->post('expense_name'),
'business_reason'=>$this->input->post('business_reason'), 'business_reason' => $this->input->post('business_reason'),
'manager_id' => $manager, 'manager_id' => $manager_id,
'business_id' => user()->business_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')); // Update process for master
for($i=0;$i<$count;$i++) $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);
$expense_child_id = $this->input->post('expense_child_id')[$i]; $first = $this->input->post('date_of_expence_new');
$data2 = array( $count = (gettype($first) == 'array') ? count($first) : 0;
'date_of_expense'=> $this->input->post('date_of_expence')[$i], 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], 'amount' => $this->input->post('amount')[$i],
'description' => $this->input->post('description')[$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() public function expence_list()
{ {
$business_id = user()->business_id; $business_id = user()->business_id;
@ -504,7 +485,7 @@ public function cancled_expence()
public function remove_row() 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); $count = count($get_count_from_child);
if($count === 1) if($count === 1)
{ {

View File

@ -8,280 +8,279 @@
<style> <style>
.alert-success { .alert-success {
background-color: #dff0d8; background-color: #dff0d8;
color: #3c763d; color: #3c763d;
border-color: #d6e9c6; border-color: #d6e9c6;
} }
.flash-message { .flash-message {
padding: 20px; padding: 20px;
margin-bottom: 10px; margin-bottom: 10px;
border-radius: 5px; border-radius: 5px;
margin-left: 500px; margin-left: 500px;
} }
.hide-arrow { .hide-arrow {
-webkit-appearance: none; -webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
appearance: none; appearance: none;
background-image: none; background-image: none;
} }
.drop-zone { .drop-zone {
border: 2px dashed #ccc; border: 2px dashed #ccc;
padding: 20px; padding: 20px;
width: 257px; width: 257px;
height:300px; height: 300px;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
} }
.preview-container { .preview-container {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
margin-top: 19px; margin-top: 19px;
margin-left: -18px !important; margin-left: -18px !important;
} }
.preview-item { .preview-item {
width: 100%; width: 100%;
margin-right: 10px; margin-right: 10px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.preview-item img, .preview-item img,
.preview-item object { .preview-item object {
width: 290px; width: 290px;
height: 280px; height: 280px;
} }
a:hover {
background-color: skyblue;
}
a:hover {
background-color: skyblue;
}
</style> </style>
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="row"> <div class="row">
<div class="col-md-12 col-sm-12 "> <div class="col-md-12 col-sm-12 ">
<div class="x_title"> <div class="x_title">
<button hidden id="button" class="btn btn-secondary source" onclick="new PNotify({ <button hidden id="button" class="btn btn-secondary source" onclick="new PNotify({
title: 'Can not Delete', title: 'Can not Delete',
text: 'Only change and Update', text: 'Only change and Update',
styling: 'bootstrap3' styling: 'bootstrap3'
});">Success</button> });">Success</button>
<input type="hidden" id="error" value="<?php echo $this->session->userdata('remove_row');?>" > <input type="hidden" id="error" value="<?php echo $this->session->userdata('remove_row'); ?>">
<?php $this->session->unset_userdata('remove_row');?> <?php $this->session->unset_userdata('remove_row'); ?>
<script> <script>
$(document).ready(function(){ $(document).ready(function() {
if($('#error').val() == 1 ) if ($('#error').val() == 1) {
{ $('#button').click();
$('#button').click(); }
} })
}) </script>
</script> <ul class="nav navbar-right panel_toolbox">
<a href="<?php echo base_url(); ?>Expence/emp_expence_list" class="btn btn-primary" style="margin-top: 20px; font-size: small;">Back</a>
</ul>
<ul class="nav navbar-right panel_toolbox"> <h3>
<a href="<?php echo base_url();?>Expence/emp_expence_list" class="btn btn-primary" style="margin-top: 20px; font-size: small;">Back</a>
</ul>
<h3> <?php if ($expense_data[0]->status == 'Draft') { ?>
<?php if($expense_data[0]->status == 'Draft') { ?> Edit Expense - <?php if (isset($expense_data[0]->id)) {
echo $expense_data[0]->expense_name;
} ?>
Edit Expense - <?php if(isset($expense_data[0]->id)){echo $expense_data[0]->expense_name; } ?> <?php } else {
echo $expense_data[0]->expense_name;
} ?>
<?php } else { echo $expense_data[0]->expense_name; } ?> </h3>
</h3>
<div class="clearfix"></div>
</div>
<div class="x_content">
<br />
<form id="" data-parsley-validate class="form-horizontal form-label-left" method="post" action="<?php echo base_url();?>Expence/edit_rise_expence_request" enctype="multipart/form-data">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name();?>" value="<?php echo $this->security->get_csrf_hash();?>">
<div class="x_panel">
<div class="item form-group">
<label class="control-label col-md-2 col-sm-2" for="last-name">Expense Requested For</label>
<div class="col-md-4 col-sm-4 ">
<input type="radio" name="created_by" value="self (<?php echo user()->id;?>)"style="margin:10px;"checked /><b>Self</b>
<input type="radio" name="created_by" value="<?php echo user()->name;?> (<?php echo user()->id;?>)" style="margin: 10px;" /><b>Others</b>
<div class="clearfix"></div>
</div> </div>
<div class="x_content">
<br />
<form id="" data-parsley-validate class="form-horizontal form-label-left" method="post" action="<?php echo base_url(); ?>Expence/edit_rise_expence_request" enctype="multipart/form-data">
<label class="control-label col-md-1 col-sm-1 " for="last-name"> Employee Name <a style="color:red;">*</a></label> <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
<div class="col-md-5 col-sm-5 ">
<select id="user_dropdown" name="emp_id" style="margin-top: 10px;padding-bottom: 10px;" class="form-control manager" > </select>
</div>
</div> <div class="x_panel">
<div class="item form-group">
<label class="control-label col-md-2 col-sm-2" for="last-name">Expense Requested For</label>
<div class="col-md-4 col-sm-4 ">
<input type="radio" name="created_by" value="self (<?php echo user()->id; ?>)" style="margin:10px;" checked /><b>Self</b>
<input type="radio" name="created_by" value="<?php echo user()->name; ?> (<?php echo user()->id; ?>)" style="margin: 10px;" /><b>Others</b>
</div>
<label class="control-label col-md-1 col-sm-1 " for="last-name"> Employee Name <a style="color:red;">*</a></label>
<div class="col-md-5 col-sm-5 ">
<select id="user_dropdown" name="emp_id" style="margin-top: 10px;padding-bottom: 10px;" class="form-control manager"> </select>
</div>
</div>
<div class="item form-group"> <div class="item form-group">
<label class="control-label col-md-1 col-sm-1 " for="first-name">Expense Name<a style="color:red;">*</a></label> <label class="control-label col-md-1 col-sm-1 " for="first-name">Expense Name<a style="color:red;">*</a></label>
<div class="col-md-5 col-sm-5 "> <div class="col-md-5 col-sm-5 ">
<div class="form-group"> <div class="form-group">
<input type='text' class="form-control" name="expense_name" value="<?php if(isset($expense_data[0]->id)){echo $expense_data[0]->expense_name; } ?>" autocomplete='off' required /> <input type='text' class="form-control" name="expense_name" value="<?php if (isset($expense_data[0]->id)) {
echo $expense_data[0]->expense_name;
} ?>" autocomplete='off' required />
</div> </div>
</div> </div>
<label class="control-label col-md-1 col-sm-1 " for="first-name">Business Reason</label> <label class="control-label col-md-1 col-sm-1 " for="first-name">Business Reason</label>
<div class="col-md-5 col-sm-5 "> <div class="col-md-5 col-sm-5 ">
<div class="form-group"> <div class="form-group">
<input type='text' class="form-control" name="business_reason" value="<?php if(isset($expense_data[0]->id)){echo $expense_data[0]->business_reason; } ?>" autocomplete='off'/> <input type='text' class="form-control" name="business_reason" value="<?php if (isset($expense_data[0]->id)) {
echo $expense_data[0]->business_reason;
} ?>" autocomplete='off' />
<input type="hidden" id="expense_id" name="expense_pid" value="<?php echo $expense_data[0]->id; ?>"> <input type="hidden" id="expense_id" name="expense_pid" value="<?php echo $expense_data[0]->id; ?>">
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="x_panel"> <div class="x_panel">
<div class="x_title"> <div class="x_title">
<!-- <ul class="nav navbar-right panel_toolbox"> <!-- <ul class="nav navbar-right panel_toolbox">
<button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-info" style="font-size:small;" >Add</button> <button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-info" style="font-size:small;" >Add</button>
</ul> --> </ul> -->
<div class="clearfix"></div> <div class="clearfix"></div>
</div><br> </div><br>
<?php $i=1; foreach ($expense_child_data as $key => $value) { ?> <?php $i = 1;
foreach ($expense_child_data as $key => $value) { ?>
<div class="item form-group"> <div class="item form-group">
<label class="control-label col-md-1 col-sm-1 " for="first-name">Status</label> <label class="control-label col-md-1 col-sm-1 " for="first-name">Status</label>
<div class="col-md-5 col-sm-5"> <div class="col-md-5 col-sm-5">
<input id="cost" class="form-control" readonly name="middle-name" autocomplete='off' value=" <input id="cost" class="form-control" readonly name="middle-name" autocomplete='off' value="
<?php if($value->status == "Approved") <?php if ($value->status == "Approved") {
{ echo $value->status . ' By ' . $value->approved_by . ' - ' . date('d-m-Y h:i:s', strtotime($value->approved_at));
echo $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 == "Declined") } else if ($value->status == "Cancelled") {
{ echo $value->status . ' at ' . date('d-m-Y h:i:s', strtotime($value->cancelled_at));
echo $value->status.' By '.$value->decline_by .' ( ' . $value->decline_reason . ' )'; } else {
} echo $value->status;
else if($value->status == "Cancelled") }
{
echo $value->status.' at '.date('d-m-Y h:i:s', strtotime($value->cancelled_at));
}
else
{
echo $value->status;
}
?> ?>
"> ">
</div> </div>
</div> </div>
<div class="item form-group"> <div class="item form-group">
<label class="control-label col-md-1 col-sm-1 " for="first-name"> Date of Expense<a style="color:red;">*</a></label> <label class="control-label col-md-1 col-sm-1 " for="first-name"> Date of Expense<a style="color:red;">*</a></label>
<div class="col-md-5 col-sm-5 "> <div class="col-md-5 col-sm-5 ">
<div class="form-group"> <div class="form-group">
<?php <?php
// Assuming $leave->perm_date_new is in the 'Y-m-d' format // Assuming $leave->perm_date_new is in the 'Y-m-d' format
$formatted_date = date('d-m-y', strtotime($value->date_of_expense_new)); $formatted_date = date('d-m-y', strtotime($value->date_of_expense_new));
?> ?>
<input type='text' id="ExpenseDate<?php echo $i;?>" class="form-control date" placeholder="DD-MM-YYYY" required name="date_of_expence_new[]" value="<?php echo $formatted_date ?>" autocomplete='off'/><i class="fa fa-calendar" style=" position: absolute; right: 25px; top: 12px;z-index: 0;"></i> <input type='text' id="ExpenseDate<?php echo $i; ?>" class="form-control date" placeholder="DD-MM-YYYY" required name="date_of_expence_new[]" value="<?php echo $formatted_date ?>" autocomplete='off' /><i class="fa fa-calendar" style=" position: absolute; right: 25px; top: 12px;z-index: 0;"></i>
</div> </div>
</div> </div>
<label class="control-label col-md-1 col-sm-1 " for="first-name">Amount<a style="color:red;">*</a></label> <label class="control-label col-md-1 col-sm-1 " for="first-name">Amount<a style="color:red;">*</a></label>
<div class="col-md-5 col-sm-5"> <div class="col-md-5 col-sm-5">
<input id="cost" name="amount[]" required value="<?php echo $value->amount ?>" class="form-control" onkeypress = "return matchnum(event)" type="number" name="middle-name" autocomplete='off'> <input id="cost" name="amount[]" required value="<?php echo $value->amount ?>" class="form-control" onkeypress="return matchnum(event)" type="number" name="middle-name" autocomplete='off'>
</div> </div>
</div> </div>
<input type="hidden" name="expense_child_id[]" value="<?php echo $value->id; ?>"> <input type="hidden" name="expense_child_id[]" value="<?php echo $value->id; ?>">
<div class="item form-group flex-wrap"> <div class="item form-group flex-wrap">
<label class="control-label col-md-1 col-sm-1" for="last-name">Description</label> <label class="control-label col-md-1 col-sm-1" for="last-name">Description</label>
<div class="col-md-5 col-sm-5"> <div class="col-md-5 col-sm-5">
<textarea id="comments" name="description[]" value="" class="form-control" style="height:50px !important;" type="text" ><?php echo $value->description ?></textarea> <textarea id="comments" name="description[]" value="" class="form-control" style="height:50px !important;" type="text"><?php echo $value->description ?></textarea>
</div>
<label class="control-label col-md-1 col-sm-1" required for="first-name">Recipt</label>
<div class="col-md-5 col-sm-5 ">
<input id="formFile" name="bill[]" onchange="validateFile(this)" class="typeFile" type="file" value="<?php echo $value->bill ?>" multiple><br>
<a href="<?php echo base_url(); ?>assets/uploads/Expence_Bill/<?php echo $value->bill; ?>" target="_blank" class="float-right" style="font-size: x-small; color: darkblue; margin-top: 7px;"><b>View Recipt(<?php echo $value->bill; ?>)</b></a>
</div>
<?php if ($expense_data[0]->status == 'Draft') { ?>
<div class="col-12"><?php if($i > 1){ ?><button type="button" class="float-right btn btn-danger deleteexpense hidebtn" data-toggle="modal" data-target=".bs-example-modal-sm" id="<?php echo $value->id; ?>"><i class="fa fa-trash"></i></button> <?php } ?>
<button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-primary float-right">Add</button>
</div>
<?php } ?>
</div>
<script>
flatpickr($('#ExpenseDate' + <?php echo $i; ?>), {
dateFormat: 'd-m-Y',
changeYear: true,
yearRange: '2000:' + new Date().getFullYear(),
maxDate: new Date(),
autoclose: true,
allowInput: false,
onChange: function(selectedDates, dateStr) {
console.log('Selected date: ', dateStr);
instance._input.removeAttribute("readonly");
}
});
</script>
<?php $i++;
} ?>
<div id="formContainer"></div>
</div>
<div class="ln_solid"></div>
<div class="item form-group">
<div class=" offset-md-8">
<?php if ($expense_data[0]->status == 'Draft') { ?>
<a href="<?php echo base_url(); ?>Expence/emp_expence_list" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-success" name="update" value="update">Update</button>
<?php } ?>
</div>
</div>
</form>
</div> </div>
</div>
<label class="control-label col-md-1 col-sm-1" required for="first-name">Recipt</label>
<div class="col-md-5 col-sm-5 ">
<input id="formFile" name="bill[]" onchange="validateFile(this)" class="typeFile" type="file" value="<?php echo $value->bill ?>" multiple><br>
<a href="<?php echo base_url(); ?>assets/uploads/Expence_Bill/<?php echo $value->bill; ?>" target="_blank" class="float-right" style="font-size: x-small; color: darkblue; margin-top: 7px;"><b>View Recipt(<?php echo $value->bill; ?>)</b></a></div>
<?php if($expense_data[0]->status == 'Draft') { ?>
<div class="col-12"><button type="button" class="float-right btn btn-danger deleteexpense hidebtn" data-toggle="modal" data-target=".bs-example-modal-sm" id="<?php echo $value->id;?>"><i class="fa fa-trash"></i></button>
<button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-primary float-right">Add</button>
</div>
<?php } ?>
</div>
<script>
flatpickr($('#ExpenseDate'+<?php echo $i;?>), {
dateFormat: 'd-m-Y',
changeYear: true,
yearRange: '2000:' + new Date().getFullYear(),
maxDate: new Date(),
autoclose:true,
allowInput: false,
onChange: function(selectedDates, dateStr) {
console.log('Selected date: ', dateStr);
instance._input.removeAttribute("readonly");
}
});
</script>
<?php $i++; } ?>
<div id="formContainer"></div>
</div>
<div class="ln_solid"></div>
<div class="item form-group">
<div class=" offset-md-8">
<?php if($expense_data[0]->status == 'Draft') { ?>
<a href="<?php echo base_url();?>Expence/emp_expence_list" class="btn btn-secondary">Cancel</a>
<button type="submit" class="btn btn-success" name="update" value="update">Update</button>
<?php } ?>
</div>
</div>
</form>
</div>
</div>
</div> </div>
</div> </div>
@ -297,86 +296,80 @@
<!-- /Body page content --> <!-- /Body page content -->
<script> <script>
// hide the dropdown arrow
// hide the dropdown arrow $(document).ready(function() {
$(document).ready(function() {
$("#user_dropdown").addClass("hide-arrow");
$("input[name='created_by']").on("change", function() {
var inputValue = $(this).val();
if (inputValue === "<?php echo user()->name;?> (<?php echo user()->id;?>)") {
$("#user_dropdown").removeClass("hide-arrow");
} else {
$("#user_dropdown").addClass("hide-arrow"); $("#user_dropdown").addClass("hide-arrow");
$("input[name='created_by']").on("change", function() {
var inputValue = $(this).val();
if (inputValue === "<?php echo user()->name; ?> (<?php echo user()->id; ?>)") {
$("#user_dropdown").removeClass("hide-arrow");
} else {
$("#user_dropdown").addClass("hide-arrow");
}
});
})
</script>
<script>
// $()
// $('.date').on('click', function() {
// const datepickerInput = $(this).attr('id');
// //const datepickerInput = document.getElementById('ExpenseDate');
// console.log(datepickerInput);
// flatpickr(datepickerInput, {
// dateFormat: 'd-m-Y',
// maxDate: new Date(),
// onChange: function(selectedDates, dateStr) {
// console.log('Selected date: ', dateStr);
// }
// });
// });
function validateFile(input) {
const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png", "pdf"];
const fileExtension = file.name.split(".").pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) {
new PNotify({
title: 'Invalid file type.',
text: 'Only JPG, JPEG, PNG, and PDF files are allowed.',
styling: 'bootstrap3'
});
input.value = "";
return;
}
} }
}); </script>
})
</script>
<script>
// $()
// $('.date').on('click', function() {
// const datepickerInput = $(this).attr('id');
// //const datepickerInput = document.getElementById('ExpenseDate');
// console.log(datepickerInput);
// flatpickr(datepickerInput, {
// dateFormat: 'd-m-Y',
// maxDate: new Date(),
// onChange: function(selectedDates, dateStr) {
// console.log('Selected date: ', dateStr);
// }
// });
// });
function validateFile(input) {
const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png", "pdf"];
const fileExtension = file.name.split(".").pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) {
new PNotify({
title: 'Invalid file type.',
text: 'Only JPG, JPEG, PNG, and PDF files are allowed.',
styling: 'bootstrap3'
});
input.value = "";
return;
}
}
</script>
<script> <script>
function matchnum(event) {
var charcode;
function matchnum(event) charcode = event.which || event.keyCode;
{
var charcode;
charcode = event.which || event.keyCode; if (charcode >= 48 && charcode <= 57) return true; //only numbers
return false;
if(charcode>= 48 && charcode <= 57)return true; //only numbers }
return false;
} $(document).ready(function() {
$(document).ready(function(){
var currentUserName = '<?php echo user()->name; ?>'; var currentUserName = '<?php echo user()->name; ?>';
var currentUserId = '<?php echo user()->id; ?>'; var currentUserId = '<?php echo user()->id; ?>';
@ -384,11 +377,11 @@ function matchnum(event)
currentUserName + '</option>'); currentUserName + '</option>');
$('#user_dropdown').prop('disabled', true); $('#user_dropdown').prop('disabled', true);
$('#user_dropdown').on('change',function() { $('#user_dropdown').on('change', function() {
}); });
$('input[type="radio"][name="created_by"]').change(function() { $('input[type="radio"][name="created_by"]').change(function() {
var selectedValue = $(this).val(); var selectedValue = $(this).val();
@ -396,141 +389,140 @@ function matchnum(event)
$userDropdown.empty(); $userDropdown.empty();
if (selectedValue === 'self (<?php echo user()->id;?>)') { if (selectedValue === 'self (<?php echo user()->id; ?>)') {
var currentUserName = '<?php echo user()->name; ?>'; var currentUserName = '<?php echo user()->name; ?>';
var currentUserId = '<?php echo user()->id; ?>'; var currentUserId = '<?php echo user()->id; ?>';
$userDropdown.append('<option value="' + currentUserId + '">' + currentUserName + '</option>'); $userDropdown.append('<option value="' + currentUserId + '">' + currentUserName + '</option>');
$userDropdown.prop('disabled', true); $userDropdown.prop('disabled', true);
} else if (selectedValue === '<?php echo user()->name; ?> (<?php echo user()->id;?>)') { } else if (selectedValue === '<?php echo user()->name; ?> (<?php echo user()->id; ?>)') {
$.ajax({ $.ajax({
url: '<?php echo base_url('Expence/get_emp_name/')?>"', url: '<?php echo base_url('Expence/get_emp_name/') ?>"',
method: 'GET', method: 'GET',
dataType: 'json', dataType: 'json',
success: function(response) { success: function(response) {
$('#user_dropdown').append(response); $('#user_dropdown').append(response);
$('#user_dropdown').prop('disabled', false); $('#user_dropdown').prop('disabled', false);
}, },
error: function(xhr, status, error) { error: function(xhr, status, error) {
console.error(error); console.error(error);
} }
}); });
} }
});
}); });
</script>
}); <script>
//get manager id from the dropdown employee assign the value to $("#manager_id") input field
</script> $("#user_dropdown").on("change", function() {
let manager_id = $(this).children(":selected").attr("id");
<script> console.log(manager_id);
//get manager id from the dropdown employee assign the value to $("#manager_id") input field $("#manager_id").val(manager_id);
$("#user_dropdown").on("change", function(){
let manager_id = $(this).children(":selected").attr("id");
console.log(manager_id);
$("#manager_id").val(manager_id);
}) })
</script> </script>
<script> <script>
var i=1; var i = 1;
function createAndAppendFormGroup() {
var html1 = ''; function createAndAppendFormGroup() {
i++ var html1 = '';
html1 += '<div id="removeChild'+i+'">' i++
html1 += '<br><div class="x_title"></div><br>' html1 += '<div id="removeChild' + i + '">'
html1 += '<div class="item form-group">'; html1 += '<br><div class="x_title"></div><br>'
html1 += '<label class="control-label col-md-1 col-sm-1 " for="first-name"> Date of Expense<a style="color:red;">*</a></label>'; html1 += '<div class="item form-group">';
html1 += '<div class="col-md-5 col-sm-5 "><div class="form-group"><input type="date" id="datepicker'+i+'" class="form-control dates" placeholder="DD-MM-YYYY" required name="date_of_expence2[]" value="" autocomplete="off"/><i class="fa fa-calendar" style=" position: absolute; right: 25px; top: 12px;z-index: 0;"></i></div></div>'; html1 += '<label class="control-label col-md-1 col-sm-1 " for="first-name"> Date of Expense<a style="color:red;">*</a></label>';
html1 += '<label class="control-label col-md-1 col-sm-1 " for="first-name"> Expense Cost <a style="color:red;">*</a></label>'; html1 += '<div class="col-md-5 col-sm-5 "><div class="form-group"><input type="date" id="datepicker' + i + '" class="form-control dates" placeholder="DD-MM-YYYY" required name="date_of_expence2[]" value="" autocomplete="off"/><i class="fa fa-calendar" style=" position: absolute; right: 25px; top: 12px;z-index: 0;"></i></div></div>';
html1 += '<div class="col-md-5 col-sm-5 "><input id="cost" name="amount2[]" required class="form-control" onkeypress="return matchnum(event)" type="number" name="middle-name" autocomplete="off"></div>'; html1 += '<label class="control-label col-md-1 col-sm-1 " for="first-name"> Expense Cost <a style="color:red;">*</a></label>';
html1 += '</div>'; html1 += '<div class="col-md-5 col-sm-5 "><input id="cost" name="amount2[]" required class="form-control" onkeypress="return matchnum(event)" type="number" name="middle-name" autocomplete="off"></div>';
html1 += '</div>';
html1 += '<div class="item form-group flex-wrap">' html1 += '<div class="item form-group flex-wrap">'
html1 += '<label class="control-label col-md-1 col-sm-1" for="last-name">Description</label>' html1 += '<label class="control-label col-md-1 col-sm-1" for="last-name">Description</label>'
html1 += '<div class="col-md-5 col-sm-3"><textarea id="comments" name="description2[]" value="" class="form-control" style="height:50px !important;" type="text" ></textarea></div>' html1 += '<div class="col-md-5 col-sm-3"><textarea id="comments" name="description2[]" value="" class="form-control" style="height:50px !important;" type="text" ></textarea></div>'
html1 += '<label class="control-label col-md-1 col-sm-1" required for="first-name">Receipt </label>' html1 += '<label class="control-label col-md-1 col-sm-1" required for="first-name">Receipt </label>'
html1 += '<div class="col-md-5 col-sm-5 "><input id="formFile" name="bill2[]" multiple onchange="validateFile(this)" class="typeFile" type="file" value="" ></div>' html1 += '<div class="col-md-5 col-sm-5 "><input id="formFile" name="bill2[]" multiple onchange="validateFile(this)" class="typeFile" type="file" value="" ></div>'
html1 += '</div>' html1 += '</div>'
html1 += '<div class="col-12"><button type="button" class="float-right btn btn-danger"" id="remove-button" onclick="removebutton('+i+')"><i class="fa fa-trash"></i></button></div><button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-primary float-right">Add</button></div>' html1 += '<div class="col-12"><button type="button" class="float-right btn btn-danger"" id="remove-button" onclick="removebutton(' + i + ')"><i class="fa fa-trash"></i></button></div><button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-primary float-right">Add</button></div></br>'
var formContainer = document.getElementById('formContainer'); var formContainer = document.getElementById('formContainer');
//formContainer.innerHTML += html1; //formContainer.innerHTML += html1;
formContainer.insertAdjacentHTML('beforeend', html1); formContainer.insertAdjacentHTML('beforeend', html1);
const datepickerInput = document.getElementById('datepicker'+i); const datepickerInput = document.getElementById('datepicker' + i);
flatpickr(datepickerInput, { flatpickr(datepickerInput, {
dateFormat: 'd-m-Y', dateFormat: 'd-m-Y',
maxDate: new Date(), maxDate: new Date(),
autoclose:true, autoclose: true,
allowInput: false, allowInput: false,
onChange: function(selectedDates, dateStr) {
console.log('Selected date: ', dateStr);
}
});
onChange: function(selectedDates, dateStr) {
console.log('Selected date: ', dateStr);
} }
});
function removebutton(index) {
//console.log(index)
var element = document.getElementById('removeChild' + index);
//console.log(element)
if (element) {
element.remove();
}
}
</script>
} <script>
$('.deleteexpense').click(function() {
function removebutton(index) { var id = $(this).attr('id');
//console.log(index) var expence_id = document.getElementById('expense_id').value;
var element = document.getElementById('removeChild'+ index); var url = "<?php echo base_url() ?>Expence/remove_row";
//console.log(element)
if (element) {
element.remove();
}
}
</script>
<script> $.ajax({
$('.deleteexpense').click(function() { url: "<?php echo base_url() ?>Expence/getCancelConfirmationPopup",
type: "GET",
var id = $(this).attr('id'); success: function(data) {
var expence_id = document.getElementById('expense_id').value;
var url = "<?php echo base_url()?>Expence/remove_row";
$.ajax({
url: "<?php echo base_url()?>Expence/getCancelConfirmationPopup",
type:"GET",
success:function(data){
$('#popup').html(JSON.parse(data)); $('#popup').html(JSON.parse(data));
$('.delete_id').attr('value',id); $('.delete_id').attr('value', id);
$('.expence_id').attr('value',expence_id); $('.expence_id').attr('value', expence_id);
$('.delete_url').attr('action',url); $('.delete_url').attr('action', url);
} }
});
}); });
});
// $('.hidebtn').click(function() { // $('.hidebtn').click(function() {
// var id = document.getElementById('expense_id').value; // var id = document.getElementById('expense_id').value;
// alert(id) // alert(id)
// $('.hidebtn').disable() // $('.hidebtn').disable()
// // $.ajax({ // // $.ajax({
// // data:{id : id}, // // data:{id : id},
// // url: "<?php echo base_url()?>Expence/get_expense_child_count", // // url: "<?php echo base_url() ?>Expence/get_expense_child_count",
// // type:"GET", // // type:"GET",
// // success:function(data){ // // success:function(data){
// // $('#popup').html(JSON.parse(data)); // // $('#popup').html(JSON.parse(data));
// // $('.delete_id').attr('value',id); // // $('.delete_id').attr('value',id);
// // $('.expence_id').attr('value',expence_id); // // $('.expence_id').attr('value',expence_id);
// // $('.delete_url').attr('action',url); // // $('.delete_url').attr('action',url);
// // } // // }
// // }); // // });
// }); // });
</script> </script>