-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_employee_deductions.php
191 lines (176 loc) · 5.33 KB
/
manage_employee_deductions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php include 'db_connect.php' ?>
<?php ?>
<div class="container-fluid">
<form action="" id="employee-deduction">
<input type="hidden" name="employee_id" value="<?php echo $_GET['id'] ?>">
<div class="row form-group">
<div class="col-md-5">
<label for="" class="control-label">Deduction</label>
<select id="deduction_id" class="borwser-default select2">
<option value=""></option>
<?php
$deduction = $conn->query("SELECT * FROM deductions order by deduction asc");
while($row = $deduction->fetch_assoc()):
?>
<option value="<?php echo $row['id'] ?>"><?php echo $row['deduction'] ?></option>
<?php endwhile; ?>
</select>
</div>
<div class="col-md-3">
<label for="" class="control-label">Type</label>
<select id="type" class="borwser-default custom-select">
<option value="1">Monthly</option>
<option value="2">Semi-Monthly</option>
<option value="3">Once</option>
</select>
</div>
<div class="col-md-3" style="display: none" id="dfield">
<label for="" class="control-label">Effective Date</label>
<input type="date" id="edate" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-5">
<label for="" class="control-label">Amount</label>
<input type="number" id="amount" class="form-control text-right" step="any" >
</div>
<div class="col-md-5" id="loan-with-interest-amount">
<label for="" class="control-label">Total Loan Amount</label>
<input type="number" id="total-loan-input" disabled placeholder="Total loan with interest" class="form-control text-right" step="any" >
<p class="font-italic text-secondary h6">*According to company policy, the sum will be subject to a 6-month payment period.</p>
</div>
<div class="col-md-2 offset-md-2">
<label for="" class="control-label"> </label>
<button class="btn btn-primary btn-block btn-sm" type="button" id="add_list"> Add to List</button>
</div>
</div>
<hr>
<div class="row">
<table class="table table-bordered" id="deduction-list">
<thead>
<tr>
<th class="text-center">
deduction
</th>
<th class="text-center">
Type
</th>
<th class="text-center">
Amount
</th>
<th class="text-center">
Date
</th>
<th class="text-center">
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</form>
</div>
<div id="tr_clone" style="display: none">
<table>
<tr>
<td>
<input type="hidden" name="deduction_id[]">
<p class="deduction"></p>
</td>
<td>
<input type="hidden" name="type[]">
<p class="type"></p>
</td>
<td>
<input type="hidden" name="amount[]">
<p class="amount"></p>
</td>
<td>
<input type="hidden" name="effective_date[]">
<p class="edate"></p>
</td>
<td class="text-center">
<button class="btn-sm btn-danger" type="button" onclick="$(this).closest('tr').remove()"><i class="fa fa-trash"></i></button>
</td>
</tr>
</table>
</div>
<script>
$('#loan-with-interest-amount').hide()
$('.select2').select2({
placeholder:"Select here",
width:"100%"
})
$('#type').change(function(){
if($(this).val() == 3){
$('#dfield').show()
}else{
$('#dfield').hide()
}
$('#amount').val(null)
$('#total-loan-input').val(null)
})
$('#deduction_id').change(function(){
if($(this).val() == 5){
$('#loan-with-interest-amount').show()
}else{
$('#loan-with-interest-amount').hide()
}
})
$('#amount').on("input", ()=>{
if($('#type').val() == 1){
var interest_rate = $('#amount').val()*0.02
$('#total-loan-input').val((parseFloat(interest_rate) + parseFloat($('#amount').val())) / 6)
}
if($('#type').val() == 2){
var interest_rate = $('#amount').val()*0.02
$('#total-loan-input').val(((parseFloat(interest_rate) + parseFloat($('#amount').val()))/ 6)/2)
}
})
$('#add_list').click(function(){
var deduction_id = $('#deduction_id').val(),
type = $('#type').val(),
amount = $('#amount').val(),
edate = $('#edate').val();
// deduction is is on 'loan' then get the loan amount from total loan input text box
if(deduction_id == 5){
amount = $('#total-loan-input').val()
}
var tr = $('#tr_clone tr').clone()
tr.find('[name="deduction_id[]"]').val(deduction_id)
tr.find('[name="type[]"]').val(type)
tr.find('[name="effective_date[]"]').val(edate)
tr.find('[name="amount[]"]').val(amount)
tr.find('.deduction').html($('#deduction_id option[value="'+deduction_id+'"]').html())
tr.find('.type').html($('#type option[value="'+type+'"]').html())
tr.find('.amount').html(amount)
tr.find('.edate').html(edate)
$('#deduction-list tbody').append(tr)
$('#deduction_id').val('').select2({
placeholder:"Select here",
width:"100%"
})
$('#type').val('')
$('#amount').val('')
$('#edate').val('')
})
$(document).ready(function(){
$('#employee-deduction').submit(function(e){
e.preventDefault()
start_load();
$.ajax({
url:'ajax.php?action=save_employee_deduction',
method:"POST",
data:$(this).serialize(),
error:err=>console.log(),
success:function(resp){
if(resp == 1){
alert_toast("Employee's data successfully saved","success");
end_load()
uni_modal("Employee Details",'view_employee.php?id=<?php echo $_GET['id'] ?>','mid-large')
}
}
})
})
})
</script>