bbone/application/modules/Expence/views/edit_expence.php
2024-03-05 14:10:53 +05:30

537 lines
16 KiB
PHP

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> -->
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://localhost/ams//assets/default/bootstrap-daterangepicker/daterangepicker.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<style>
.alert-success {
background-color: #dff0d8;
color: #3c763d;
border-color: #d6e9c6;
}
.flash-message {
padding: 20px;
margin-bottom: 10px;
border-radius: 5px;
margin-left: 500px;
}
.hide-arrow {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-image: none;
}
.drop-zone {
border: 2px dashed #ccc;
padding: 20px;
width: 257px;
height:300px;
text-align: center;
cursor: pointer;
}
.preview-container {
display: flex;
flex-wrap: wrap;
margin-top: 19px;
margin-left: -18px !important;
}
.preview-item {
width: 100%;
margin-right: 10px;
margin-bottom: 10px;
}
.preview-item img,
.preview-item object {
width: 290px;
height: 280px;
}
a:hover {
background-color: skyblue;
}
</style>
<div class="clearfix"></div>
<div class="row">
<div class="col-md-12 col-sm-12 ">
<div class="x_title">
<button hidden id="button" class="btn btn-secondary source" onclick="new PNotify({
title: 'Can not Delete',
text: 'Only change and Update',
styling: 'bootstrap3'
});">Success</button>
<input type="hidden" id="error" value="<?php echo $this->session->userdata('remove_row');?>" >
<?php $this->session->unset_userdata('remove_row');?>
<script>
$(document).ready(function(){
if($('#error').val() == 1 )
{
$('#button').click();
}
})
</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>
<h3>
<?php if($expense_data[0]->status == 'Draft') { ?>
Edit Expense - <?php if(isset($expense_data[0]->id)){echo $expense_data[0]->expense_name; } ?>
<?php } else { echo $expense_data[0]->expense_name; } ?>
</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>
<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">
<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>
<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; ?>">
</div>
</div>
</div>
</div>
<div class="x_panel">
<div class="x_title">
<!-- <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>
</ul> -->
<div class="clearfix"></div>
</div><br>
<?php $i=1; foreach ($expense_child_data as $key => $value) { ?>
<div class="item form-group">
<label class="control-label col-md-1 col-sm-1 " for="first-name">Status</label>
<div class="col-md-5 col-sm-5">
<input id="cost" class="form-control" readonly name="middle-name" autocomplete='off' value="
<?php if($value->status == "Approved")
{
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 == "Cancelled")
{
echo $value->status.' at '.date('d-m-Y h:i:s', strtotime($value->cancelled_at));
}
else
{
echo $value->status;
}
?>
">
</div>
</div>
<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>
<div class="col-md-5 col-sm-5 ">
<div class="form-group">
<?php
// Assuming $leave->perm_date_new is in the 'Y-m-d' format
$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>
</div>
</div>
<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">
<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>
<input type="hidden" name="expense_child_id[]" value="<?php echo $value->id; ?>">
<div class="item form-group flex-wrap">
<label class="control-label col-md-1 col-sm-1" for="last-name">Description</label>
<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>
</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 class="modal fade bs-example-modal-lg" id="ItemModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
<div class="modal bs-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true" id="popup"> </div>
<div style="display:none" id="sub-value">
<!-- /Body page content -->
<script>
// hide the dropdown arrow
$(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");
}
});
})
</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>
function matchnum(event)
{
var charcode;
charcode = event.which || event.keyCode;
if(charcode>= 48 && charcode <= 57)return true; //only numbers
return false;
}
$(document).ready(function(){
var currentUserName = '<?php echo user()->name; ?>';
var currentUserId = '<?php echo user()->id; ?>';
$('#user_dropdown').append('<option value="' + currentUserId + '">' +
currentUserName + '</option>');
$('#user_dropdown').prop('disabled', true);
$('#user_dropdown').on('change',function() {
});
$('input[type="radio"][name="created_by"]').change(function() {
var selectedValue = $(this).val();
var $userDropdown = $('#user_dropdown');
$userDropdown.empty();
if (selectedValue === 'self (<?php echo user()->id;?>)') {
var currentUserName = '<?php echo user()->name; ?>';
var currentUserId = '<?php echo user()->id; ?>';
$userDropdown.append('<option value="' + currentUserId + '">' + currentUserName + '</option>');
$userDropdown.prop('disabled', true);
} else if (selectedValue === '<?php echo user()->name; ?> (<?php echo user()->id;?>)') {
$.ajax({
url: '<?php echo base_url('Expence/get_emp_name/')?>"',
method: 'GET',
dataType: 'json',
success: function(response) {
$('#user_dropdown').append(response);
$('#user_dropdown').prop('disabled', false);
},
error: function(xhr, status, error) {
console.error(error);
}
});
}
});
});
</script>
<script>
//get manager id from the dropdown employee assign the value to $("#manager_id") input field
$("#user_dropdown").on("change", function(){
let manager_id = $(this).children(":selected").attr("id");
console.log(manager_id);
$("#manager_id").val(manager_id);
})
</script>
<script>
var i=1;
function createAndAppendFormGroup() {
var html1 = '';
i++
html1 += '<div id="removeChild'+i+'">'
html1 += '<br><div class="x_title"></div><br>'
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 += '<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 += '<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 += '<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 += '<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>'
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>'
var formContainer = document.getElementById('formContainer');
//formContainer.innerHTML += html1;
formContainer.insertAdjacentHTML('beforeend', html1);
const datepickerInput = document.getElementById('datepicker'+i);
flatpickr(datepickerInput, {
dateFormat: 'd-m-Y',
maxDate: new Date(),
autoclose:true,
allowInput: false,
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() {
var id = $(this).attr('id');
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));
$('.delete_id').attr('value',id);
$('.expence_id').attr('value',expence_id);
$('.delete_url').attr('action',url);
}
});
});
// $('.hidebtn').click(function() {
// var id = document.getElementById('expense_id').value;
// alert(id)
// $('.hidebtn').disable()
// // $.ajax({
// // data:{id : id},
// // url: "<?php echo base_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);
// // }
// // });
// });
</script>