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()
{ {
// Expense primary key
$id = $this->input->post('expense_pid'); $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);
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);
$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]; $expense_child_id = $this->input->post('expense_child_id')[$i];
$data2 = array( $first_child = array(
'date_of_expense'=> $this->input->post('date_of_expence')[$i], '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/'; $update_expense_list = $this->MY_Model->edit_option($first_child, $expense_child_id, $expense_child_table);
$config['allowed_types'] = 'jpg|png|jpeg|pdf'; log_message('info', "update_expense_list - expense_id => ".$id." is updated == ".$update_expense_list);
$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();
} }
// Details gathering from JavaScript new entries
$table="expense_child"; $second = $this->input->post('date_of_expence2');
$update_expence_list = $this->MY_Model->edit_option($data2, $expense_child_id, $table); $additional_count = (gettype($second) == 'array') ? count($second) : 0;
if ($additional_count > 0) {
} for ($j = 0; $j < $additional_count; $j++) {
$second_child = array(
if($this->input->post('date_of_expence2')) 'expense_id' => $id,
{ 'emp_id' => $emp_id,
$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, 'business_id' => user()->business_id,
'manager_id' => $manager, 'manager_id' => $manager_id,
'status' => 'Draft', 'status' => 'Draft',
'date_of_expense'=> $this->input->post('date_of_expence2')[$i], 'date_of_expense' => $this->input->post('date_of_expence2')[$j],
'amount' => $this->input->post('amount2')[$i], 'amount' => $this->input->post('amount2')[$j],
'description' => $this->input->post('description2')[$i], 'description' => $this->input->post('description2')[$j],
); );
$this->load->library('upload'); if (!empty($_FILES['bill2']['name'][$j])) {
$upload_result = $this->upload_file($_FILES['bill2'], $j);
$config['upload_path'] = APPPATH. '../assets/uploads/Expence_Bill/'; if ($upload_result['success']) {
$config['allowed_types'] = 'jpg|png|jpeg|pdf'; $second_child['bill'] = $upload_result['file_name'];
$config['max_size'] = 80000; } else {
$config['file_name'] = time(). '_' . $_FILES['bill2']['name'][$i]; log_message('error', $upload_result['error']);
$_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();
} }
$create_expense_list = $this->MY_Model->insert($second_child, $expense_child_table);
$table="expense_child"; log_message('info', "create_expense_list - expense_id => ".$id." is created == ".$create_expense_list);
$create_expence_list = $this->MY_Model->insert($data2,$table);
//print_r($this->db->last_query()); die;
} }
} }
redirect('Expence/Emp_Expence_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

@ -12,16 +12,16 @@
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;
@ -29,162 +29,161 @@
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 { a:hover {
background-color: skyblue; 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 class="nav navbar-right panel_toolbox"> </ul>
<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> <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 class="clearfix"></div>
</div> </div>
<div class="x_content"> <div class="x_content">
<br /> <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"> <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();?>"> <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="x_panel">
<div class="item form-group"> <div class="item form-group">
<label class="control-label col-md-2 col-sm-2" for="last-name">Expense Requested For</label> <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 "> <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="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> <input type="radio" name="created_by" value="<?php echo user()->name; ?> (<?php echo user()->id; ?>)" style="margin: 10px;" /><b>Others</b>
</div> </div>
<label class="control-label col-md-1 col-sm-1 " for="last-name"> Employee Name <a style="color:red;">*</a></label> <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 "> <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> <select id="user_dropdown" name="emp_id" style="margin-top: 10px;padding-bottom: 10px;" class="form-control manager"> </select>
</div> </div>
</div>
<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>
<div class="col-md-5 col-sm-5 ">
<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 />
</div> </div>
</div>
<label class="control-label col-md-1 col-sm-1 " for="first-name">Business Reason</label> <div class="item form-group">
<div class="col-md-5 col-sm-5 ">
<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="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="expense_name" value="<?php if (isset($expense_data[0]->id)) {
echo $expense_data[0]->expense_name;
} ?>" autocomplete='off' required />
</div>
</div>
<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="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="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") {
else if($value->status == "Declined") echo $value->status . ' By ' . $value->decline_by . ' ( ' . $value->decline_reason . ' )';
{ } else if ($value->status == "Cancelled") {
echo $value->status.' By '.$value->decline_by .' ( ' . $value->decline_reason . ' )'; echo $value->status . ' at ' . date('d-m-Y h:i:s', strtotime($value->cancelled_at));
} } else {
else if($value->status == "Cancelled")
{
echo $value->status.' at '.date('d-m-Y h:i:s', strtotime($value->cancelled_at));
}
else
{
echo $value->status; echo $value->status;
} }
@ -192,66 +191,66 @@
"> ">
</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> </div>
<label class="control-label col-md-1 col-sm-1" required for="first-name">Recipt</label> <label class="control-label col-md-1 col-sm-1" required for="first-name">Recipt</label>
<div class="col-md-5 col-sm-5 "> <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> <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> <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') { ?> <?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> <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> <button type="button" id="add-button" onclick="createAndAppendFormGroup()" class="btn btn-primary float-right">Add</button>
</div> </div>
<?php } ?> <?php } ?>
</div> </div>
<script> <script>
flatpickr($('#ExpenseDate' + <?php echo $i; ?>), {
flatpickr($('#ExpenseDate'+<?php echo $i;?>), {
dateFormat: 'd-m-Y', dateFormat: 'd-m-Y',
changeYear: true, changeYear: true,
yearRange: '2000:' + new Date().getFullYear(), yearRange: '2000:' + new Date().getFullYear(),
maxDate: new Date(), maxDate: new Date(),
autoclose:true, autoclose: true,
allowInput: false, allowInput: false,
onChange: function(selectedDates, dateStr) { onChange: function(selectedDates, dateStr) {
@ -259,29 +258,29 @@
instance._input.removeAttribute("readonly"); instance._input.removeAttribute("readonly");
} }
}); });
</script>
</script>
<?php $i++; } ?> <?php $i++;
} ?>
<div id="formContainer"></div> <div id="formContainer"></div>
</div> </div>
<div class="ln_solid"></div> <div class="ln_solid"></div>
<div class="item form-group"> <div class="item form-group">
<div class=" offset-md-8"> <div class=" offset-md-8">
<?php if($expense_data[0]->status == 'Draft') { ?> <?php if ($expense_data[0]->status == 'Draft') { ?>
<a href="<?php echo base_url();?>Expence/emp_expence_list" class="btn btn-secondary">Cancel</a> <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> <button type="submit" class="btn btn-success" name="update" value="update">Update</button>
<?php } ?> <?php } ?>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@ -297,10 +296,9 @@
<!-- /Body page content --> <!-- /Body page content -->
<script>
<script>
// hide the dropdown arrow // hide the dropdown arrow
$(document).ready(function() { $(document).ready(function() {
@ -308,7 +306,7 @@
$("#user_dropdown").addClass("hide-arrow"); $("#user_dropdown").addClass("hide-arrow");
$("input[name='created_by']").on("change", function() { $("input[name='created_by']").on("change", function() {
var inputValue = $(this).val(); var inputValue = $(this).val();
if (inputValue === "<?php echo user()->name;?> (<?php echo user()->id;?>)") { if (inputValue === "<?php echo user()->name; ?> (<?php echo user()->id; ?>)") {
$("#user_dropdown").removeClass("hide-arrow"); $("#user_dropdown").removeClass("hide-arrow");
} else { } else {
$("#user_dropdown").addClass("hide-arrow"); $("#user_dropdown").addClass("hide-arrow");
@ -316,12 +314,10 @@
}); });
}) })
</script>
</script>
<script> <script>
// $() // $()
// $('.date').on('click', function() { // $('.date').on('click', function() {
@ -343,7 +339,7 @@
// }); // });
function validateFile(input) { function validateFile(input) {
const file = input.files[0]; const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png", "pdf"]; const allowedExtensions = ["jpg", "jpeg", "png", "pdf"];
const fileExtension = file.name.split(".").pop().toLowerCase(); const fileExtension = file.name.split(".").pop().toLowerCase();
@ -357,26 +353,23 @@ function validateFile(input) {
input.value = ""; input.value = "";
return; return;
} }
} }
</script>
</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,9 +377,9 @@ 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() {
@ -396,16 +389,16 @@ 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) {
@ -420,15 +413,13 @@ function matchnum(event)
} }
}); });
}); });
</script>
</script>
<script> <script>
//get manager id from the dropdown employee assign the value to $("#manager_id") input field
//get manager id from the dropdown employee assign the value to $("#manager_id") input field $("#user_dropdown").on("change", function() {
$("#user_dropdown").on("change", function(){
let manager_id = $(this).children(":selected").attr("id"); let manager_id = $(this).children(":selected").attr("id");
console.log(manager_id); console.log(manager_id);
@ -436,19 +427,20 @@ function matchnum(event)
$("#manager_id").val(manager_id); $("#manager_id").val(manager_id);
}) })
</script> </script>
<script> <script>
var i=1; var i = 1;
function createAndAppendFormGroup() {
function createAndAppendFormGroup() {
var html1 = ''; var html1 = '';
i++ i++
html1 += '<div id="removeChild'+i+'">' html1 += '<div id="removeChild' + i + '">'
html1 += '<br><div class="x_title"></div><br>' html1 += '<br><div class="x_title"></div><br>'
html1 += '<div class="item form-group">'; html1 += '<div class="item form-group">';
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"> Date of Expense<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 "><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"> Expense Cost <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 "><input id="cost" name="amount2[]" required class="form-control" onkeypress="return matchnum(event)" type="number" name="middle-name" autocomplete="off"></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>';
@ -461,7 +453,7 @@ function createAndAppendFormGroup() {
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');
@ -469,11 +461,11 @@ function createAndAppendFormGroup() {
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) { onChange: function(selectedDates, dateStr) {
@ -482,55 +474,55 @@ function createAndAppendFormGroup() {
}); });
} }
function removebutton(index) { function removebutton(index) {
//console.log(index) //console.log(index)
var element = document.getElementById('removeChild'+ index); var element = document.getElementById('removeChild' + index);
//console.log(element) //console.log(element)
if (element) { if (element) {
element.remove(); element.remove();
} }
} }
</script> </script>
<script> <script>
$('.deleteexpense').click(function() { $('.deleteexpense').click(function() {
var id = $(this).attr('id'); var id = $(this).attr('id');
var expence_id = document.getElementById('expense_id').value; var expence_id = document.getElementById('expense_id').value;
var url = "<?php echo base_url()?>Expence/remove_row"; var url = "<?php echo base_url() ?>Expence/remove_row";
$.ajax({ $.ajax({
url: "<?php echo base_url()?>Expence/getCancelConfirmationPopup", url: "<?php echo base_url() ?>Expence/getCancelConfirmationPopup",
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);
} }
}); });
}); });
// $('.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>