-
Notifications
You must be signed in to change notification settings - Fork 1
/
add-expense.php
302 lines (254 loc) · 11.9 KB
/
add-expense.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php require_once 'config/config.php';
$Title = "Expense";
$title = "expense";
$accounts = fetchBySess($_SESSION['user_id'],'accounts');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add <?=$Title?></title>
<?php require_once $include_path.'head.php'; ?>
</head>
<body>
<!-- HK Wrapper -->
<div class="hk-wrapper hk-vertical-nav">
<!-- Top Navbar -->
<?php require_once $include_path.'navbar.php'; ?>
<!-- /Top Navbar -->
<!-- Vertical Nav -->
<?php require_once $include_path.'sidebar.php'; ?>
<!-- /Vertical Nav -->
<!-- Setting Panel -->
<?php require_once $include_path.'setting.php'; ?>
<!-- /Setting Panel -->
<!-- Main Content -->
<div class="hk-pg-wrapper">
<!-- Container -->
<div class="container mt-xl-50 mt-sm-30 mt-15">
<!-- Title -->
<!-- /Title -->
<!-- Row -->
<div class="row">
<div class="col-xl-12">
<section class="hk-sec-wrapper">
<h5 class="hk-sec-title">Add <?=$Title?></h5>
<div class="row">
<div class="col-sm">
<form id="myform">
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Date</label>
<div class="col-sm-10">
<input class="form-control" id="date" type="text" name="Date" />
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Expense Category</label>
<div class="col-sm-10">
<select class="form-control" id="mainexptypeid" name="ExpMainTyepId">
</select>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Sub Category</label>
<div class="col-sm-10">
<select class="form-control" id="subexptypeid" name="ExpSubTyepId">
</select>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Child Category</label>
<div class="col-sm-10">
<select class="form-control" id="childexptypeid" name="ExpChildTyepId">
</select>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Account</label>
<div class="col-sm-10">
<select class="form-control" id="accountid" name="AccountId">
<?php for ($i=0; $i < count($accounts); $i++) {
?>
<option value="<?=$accounts[$i]->Id?>"><?=$accounts[$i]->Name." ".$accounts[$i]->Number." [Balance: ".$accounts[$i]->Balance."]"?></option> <?php } ?>
</select>
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Amount</label>
<div class="col-sm-10">
<input type="number" name="Amount" class="form-control" id="amount" placeholder="Amount">
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
<input type="text" name="Description" class="form-control" id="description" placeholder="Description">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-sm-6">
<button type="submit" id="submit" class="btn btn-gradient-info">Add <?=$Title?></button>
</div>
</div>
</form>
</div>
</div>
</section>
</div>
</div>
<!-- /Row -->
</div>
<!-- /Container -->
<!-- Footer -->
<?php require_once $include_path.'footer.php'; ?>
<!-- /Footer -->
</div>
<!-- /Main Content -->
</div>
<!-- /HK Wrapper -->
<!-- jQuery -->
<?php require_once $include_path.'foot.php'; ?>
<script type="text/javascript">
var prevent = false;
$(window).bind("load", function () {
fetchmaintype();
});
function fetchmaintype(){
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo $action_url; ?>fetch_mainexptype.php",
success: function(data){
if (data.length === 0) {
return;
}
var mainlist = '';
$.each(data, function(key, value){
mainlist += '<option value=' + value.Id + '>' + value.Name + '</option>';
});
$("#mainexptypeid").html(mainlist);
prevent = true;
fetchsubtype();
}
});
}
function fetchsubtype(){
var mainexptypeid = $("#mainexptypeid option:selected").val();
if (mainexptypeid == null) {
return;
}
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo $action_url; ?>fetch_subexptype.php",
data: { mainexptypeid : mainexptypeid },
success: function(data){
if (data.length === 0) {
return;
}
var sublist = '';
$.each(data, function(key, value){
sublist += '<option value=' + value.Id + '>' + value.Name + '</option>';
});
$("#subexptypeid").html(sublist);
prevent = true;
fetchchildtype();
}
});
}
function fetchchildtype(){
var mainexptypeid = $("#mainexptypeid option:selected").val();
var subexptypeid = $("#subexptypeid option:selected").val();
if (subexptypeid == null || mainexptypeid == null) {
return;
}
$.ajax({
type: "POST",
dataType: "json",
url: "<?php echo $action_url; ?>fetch_childexptype.php",
data: { subexptypeid : subexptypeid, mainexptypeid : mainexptypeid },
success: function(data){
if (data.length === 0) {
return;
}
var childlist = '';
$.each(data, function(key, value){
childlist += '<option value=' + value.Id + '>' + value.Name + '</option>';
});
$("#childexptypeid").html(childlist);
}
});
}
$("#mainexptypeid").change(function(){
if (prevent) {
fetchsubtype();
}
});
$("#subexptypeid").change(function(){
if (prevent) {
fetchchildtype();
}
});
$('input[name="Date"]').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
minYear: 2010,
maxYear: 2028,
locale: {
format: 'YYYY-MM-DD'
},
"cancelClass": "btn-secondary"
});
$(document).ready(function () {
iziToast.settings({
timeout: 2500,
resetOnHover: true,
animateInside: true,
transitionIn: 'bounceInUp',
transitionOut: 'flipOutX'
});
$("#myform").submit(function (e) {
e.preventDefault();
var formData = $("#myform").serialize();
$.ajax({
type: "POST",
url : "<?php echo $action_url; ?>add_<?=$title?>.php",
data: formData,
beforeSend: function() {
$('#submit').attr('disabled', true);
$("#submit").html("<i id='sub' class='fad fa-sync-alt fa-spin fa-lg'></i>").addClass("btn-success");
},
complete: function() {
$('#submit').empty().addClass('btn btn-gradient-info').html('Add <?=$Title?>');
$('#submit').attr('disabled', false);
},
success: function (response) {
if (response == "Success") {
iziToast.success({
title: 'Succes',
message: '<?=$Title?> Added'
});
$('#myform').trigger("reset");
}else if(response == "Existed"){
iziToast.info({
title: 'Existed',
message: 'Already Existed'
});
}else if (response == "Invalid") {
iziToast.error({
title: 'Invalid',
message: 'Something Went Wrong'
});
}
},
error: function(e) {
iziToast.warning({
title: 'Request Error',
message: e.statusText
});
}
});
});
});
</script>
</body>
</html>