-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan.php
197 lines (183 loc) · 5.45 KB
/
plan.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
192
193
194
195
196
197
<?php include('db_connect.php');?>
<div class="container-fluid">
<div class="col-lg-12">
<div class="row">
<!-- FORM Panel -->
<div class="col-md-4">
<form action="" id="manage-plan">
<div class="card">
<div class="card-header">
Plan's Form
</div>
<div class="card-body">
<input type="hidden" name="id">
<div class="form-group">
<label class="control-label">Plan (months)</label>
<input type="number" name="months" id="" class="form-control text-right">
</div>
<div class="form-group">
<label class="control-label">Interest</label>
<div class="input-group">
<input type="number" step="any" min="0" max="100" class="form-control text-right" name="interest_percentage" aria-label="Interest">
<div class="input-group-append">
<span class="input-group-text">%</span>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Monthly Over due's Penalty</label>
<div class="input-group">
<input type="number" step="any" min="0" max="100" class="form-control text-right" aria-label="Penalty percentage" name="penalty_rate">
<div class="input-group-append">
<span class="input-group-text">%</span>
</div>
</div>
</div>
</div>
<div class="card-footer">
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-primary col-sm-3 offset-md-3"> Save</button>
<button class="btn btn-sm btn-default col-sm-3" type="button" onclick="_reset()"> Cancel</button>
</div>
</div>
</div>
</div>
</form>
</div>
<!-- FORM Panel -->
<!-- Table Panel -->
<div class="col-md-8">
<div class="card">
<div class="card-body">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center">Plan</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$plan = $conn->query("SELECT * FROM loan_plan order by id asc");
while($row=$plan->fetch_assoc()):
$months = $row['months'];
$months = $months / 12;
if($months < 1){
$months = $row['months']. " months";
}else{
$m = explode(".", $months);
$months = $m[0] . " yrs.";
if(isset($m[1])){
$months .= " and ".number_format(12 * ($m[1] /100 ),0)."month/s";
}
}
?>
<tr>
<td class="text-center"><?php echo $i++ ?></td>
<td class="">
<p>Years/Month: <b><?php echo $months ?></b></p>
<p><small>Interest: <b><?php echo $row['interest_percentage']."%" ?></b></small></p>
<p><small>Over dure Penalty: <b><?php echo $row['penalty_rate']."%" ?></b></small></p>
</td>
<td class="text-center">
<button class="btn btn-sm btn-primary edit_plan" type="button" data-id="<?php echo $row['id'] ?>" data-months="<?php echo $row['months'] ?>" data-interest_percentage="<?php echo $row['interest_percentage'] ?>" >Edit</button>
<button class="btn btn-sm btn-danger delete_plan" type="button" data-id="<?php echo $row['id'] ?>">Delete</button>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Table Panel -->
</div>
</div>
</div>
<style>
td{
vertical-align: middle !important;
}
td p{
margin: unset
}
img{
max-width:100px;
max-height: :150px;
}
</style>
<script>
function _reset(){
$('#cimg').attr('src','');
$('[name="id"]').val('');
$('#manage-plan').get(0).reset();
}
$('#manage-plan').submit(function(e){
e.preventDefault()
start_load()
$.ajax({
url:'ajax.php?action=save_plan',
data: new FormData($(this)[0]),
cache: false,
contentType: false,
processData: false,
method: 'POST',
type: 'POST',
success:function(resp){
if(resp==1){
alert_toast("Data successfully added",'success')
setTimeout(function(){
location.reload()
},1500)
}
else if(resp==2){
alert_toast("Data successfully updated",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
})
$('.edit_plan').click(function(){
start_load()
var plan = $('#manage-plan')
plan.get(0).reset()
plan.find("[name='id']").val($(this).attr('data-id'))
plan.find("[name='months']").val($(this).attr('data-months'))
plan.find("[name='interest_percentage']").val($(this).attr('data-interest_percentage'))
plan.find("[name='penalty_reate']").val($(this).attr('data-penalty_reate'))
end_load()
})
$('.delete_plan').click(function(){
_conf("Are you sure to delete this Plan?","delete_plan",[$(this).attr('data-id')])
})
function displayImg(input,_this) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#cimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
function delete_plan($id){
start_load()
$.ajax({
url:'ajax.php?action=delete_plan',
method:'POST',
data:{id:$id},
success:function(resp){
if(resp==1){
alert_toast("Data successfully deleted",'success')
setTimeout(function(){
location.reload()
},1500)
}
}
})
}
</script>