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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
|
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php require_once '../include/head.php'; require_once '../include/checkuser.php'; require_once '../include/Nav_bar.php'; include_once '../include/DBConnect.php'; ?> <script> function cal_total(){ var i=$('#i').val(); var total_amount=0; for(var j=0;j<i;j++){ var temp_amount=parseInt($('#amount_'+j).val()); total_amount+=temp_amount; } $('#total_amount').val(total_amount); }; function cal_discount(){ var i=$('#i').val(); var total_discount=0; for(var j=0;j<i;j++){ var temp_discount=parseInt($('#discount_'+j).val()); total_discount+=temp_discount; } $('#total_discount').val(total_discount); }; $(function() { $('.date-picker').datetimepicker({pickTime: false, format: 'yyyy-MM-dd'}); }); function change_discount(obj) { //alert(obj.id); var target_id=obj.id; var target_i=target_id.split('_')[1]; $.ajax({ type: "POST", url: "ajax_invoice.php", data: { type: $('#type_'+target_i).val(), linking_id: $('#linking_id').val() }, cache: false, success: function(html) { if($('#type_'+target_i).val()==1){//subsidy $('#typerate_'+target_i).val(html); var fee=$('#price_'+target_i).val()*(1-(html/100));//fee=amount wrong naming in the very first beginning var discount=$('#price_'+target_i).val()*((html/100)); $('#amount_'+target_i).val(fee); $('#discount_'+target_i).val(discount); $('#typerate_'+target_i).attr("readonly",true); cal_total(); cal_discount(); } else{ if($('#type_'+target_i).val()==2){//package_discount $('#typerate_'+target_i).val(html); $('#discount_'+target_i).val(html); var fee=$('#price_'+target_i).val()-html; $('#amount_'+target_i).val(fee); $('#typerate_'+target_i).attr("readonly",true); cal_total(); cal_discount(); } else{ if($('#type_'+target_i).val()==3){//funding $('#typerate_'+target_i).val(0); $('#discount_'+target_i).val(0); $('#amount_'+target_i).val($('#price_'+target_i).val()); $('#typerate_'+target_i).attr("readonly",false); cal_total(); cal_discount(); } } } } }); } function not_charge(obj){ var target_id=obj.id; var target_i=target_id.split('_')[1]; $('#typerate_'+target_i).val(0); $('#discount_'+target_i).val(0); $('#amount_'+target_i).val(0); cal_total(); cal_discount(); }; function funding(obj){ var target_id=obj.id; var target_i=target_id.split('_')[1]; var type_rate=$('#typerate_'+target_i).val(); var price=$('#price_'+target_i).val(); var fee=price-type_rate;//typerate_ $('#discount_'+target_i).val(type_rate); $('#amount_'+target_i).val(fee); cal_total(); cal_discount(); }; </script> </head> <body> <!-- line between nav bar and content --> <div class="text-right"> <ul class="breadcrumb"> <li class="active"></li> </ul> </div> <!-- line between nav bar and content --> <div class="container-fluid pathways-container"> <?php if (isset($_POST['select']) && $_POST['select'] == "Select") { $percent = 0; $id = $_POST['id']; $temp_id = explode("|", $id); $stu_id = $temp_id[1]; $event_id = $temp_id[0]; $from_date = $_POST['from_date']; $to_date = $_POST['to_date']; //echo $from_date.' '.$to_date; ?> <table border="0" class="table table-striped table-bordered table-hover table-condensed" width="100%"> <?php $query = "Select e.event_id,e.event_code,l.lesson_id,l.start_time,l.end_time,l.date,stu.first_name, stu.last_name,stu.linking_id,stu.root_id, e.programme_fee_type,e.program_id,e.subject_id, e.primary_individual_price,e.primary_group_price,e.secondary_individual_price,e.secondary_group_price, e.primary_package_price,e.secondary_package_price,g.grade,la.attendance,la.package_discount,la.is_charge from event as e, lesson_attendance as la,student_grade as sg,grade as g, student as stu,lesson as l,event_lesson as el where e.event_id=el.event_id and el.lesson_id=l.lesson_id and l.lesson_id=la.lesson_id and sg.student_grade_id=stu.linking_id and sg.grade_id=g.grade_id and stu.root_id=la.stu_linking_id and sg.student_grade_id=stu.linking_id and sg.grade_id=g.grade_id and e.deleted=0 and e.actived=1 and sg.deleted=0 and sg.actived=1 and g.deleted=0 and g.actived=1 and la.deleted=0 and la.actived=1 and stu.deleted=0 and stu.actived=1 and l.deleted=0 and l.actived=1 and el.deleted=0 and el.actived=1 and stu.linking_id='$stu_id' and l.date>='$from_date' and l.date<='$to_date' and e.event_id='$event_id'"; $result = $dbh->query($query); //get invoice data if ($result) { $result->setFetchMode(PDO::FETCH_OBJ); $total_price = 0.0; $total_discount = 0.0; $total_amount = 0.0; $i = 0;
while ($row = $result->fetch()) { $query1 = "Select ss.stu_subsidy_id,s.percent as sum_p from student_subsidy as ss, subsidy as s where ss.subsidy_id = s.subsidy_id and ss.deleted=0 and s.deleted=0 and s.actived=1 and ss.actived=1 and ss.stu_subsidy_id='$stu_id'"; $result1 = $dbh->query($query1); //get percent if ($result1->rowcount() == 0) { $percent = 0; } else { $result1->setFetchMode(PDO::FETCH_OBJ); $row1 = $result1->fetch(); $percent = $row1->sum_p; } if ($i == 0) { ?> <tr> <td colspan="14"><center><h3>INVOICE</h3></center></td> </tr> <tr> <td colspan="8"> Bill To:<input type="text" name="bill_to" required="true" value="<?= $row->last_name . ' ' . $row->first_name ?>"> <input type="hidden" name="linking_id" id="linking_id" value="<?= $row->linking_id ?>"> </td> <td>Invoice Date:</td> <td colspan="6"> <div class="input-append date-picker" id="day_of_birth"> <input type="text" name="invoice_date" id="DOB" class="dateISO"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </td> </tr> <tr> <td colspan="8"> </td> <td>Event Code:</td> <td colspan="6"><input type="text" name="event_code" value="<?= $row->event_code ?>"></td> </tr> <tr> <th> </th> <th>Date</th> <th>Time form</th> <th>Time to</th> <th>Hour(s)</th> <th>Fee type</th> <th>Price($)</th> <th>Attendance</th> <th>Remark</th> <th>Subsidy(%)/Package discount($)/Funding($)</th> <th> </th> <th>Discount($)</th> <th>Charge?</th> <th>Amount($)</th> </tr> <?php } /* $query2 = "Insert into invoice set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),actived=1,deleted=0, stu_linking_id='$row->root_id',code='$row->event_code',remarks=''"; $result2 = $dbh->query($query2); */ $query4 = "Select Max(invoice_id) as i from invoice"; $result4 = $dbh->query($query4); $result4->setFetchMode(PDO::FETCH_OBJ); $row4 = $result4->fetch(); $query5 = "Select count(*) as no_of_stu from lesson_attendance where lesson_id ='$row->lesson_id' and deleted=0 and actived=1 group by lesson_id"; $result5 = $dbh->query($query5); $result5->setFetchMode(PDO::FETCH_OBJ); $row5 = $result5->fetch();
//while ($row5 = $result5->fetch()) { $price = 0.0; $discount = 0.0; $amount = 0.0; if ($row->programme_fee_type != 3) {//3=free if ($row->programme_fee_type == 1) {//1=hour , 2=package if ($row5->no_of_stu > 1) {//group hr switch ($row->grade) { case 'K2': case 'K3': case 'P1': case 'P2': case 'P3': case 'P4': case 'P5': case 'P6': case 'Y1': case 'Y2': case 'Y3': case 'Y4': case 'Y5': case 'Y6': $price+=$row->primary_group_price; break; case 'S1': case 'S2': case 'S3': case 'S4': case 'S5': case 'S6': case 'Y7': case 'Y8': case 'Y9': case 'Y10': case 'Y11': case 'Y12': $price+=$row->secondary_group_price; break; } } else { switch ($row->grade) {//induva hr case 'K2': case 'K3': case 'P1': case 'P2': case 'P3': case 'P4': case 'P5': case 'P6': case 'Y1': case 'Y2': case 'Y3': case 'Y4': case 'Y5': case 'Y6': $price+=$row->primary_individual_price; break; case 'S1': case 'S2': case 'S3': case 'S4': case 'S5': case 'S6': case 'Y7': case 'Y8': case 'Y9': case 'Y10': case 'Y11': case 'Y12': $price+=$row->secondary_individual_price; break; } } $price=$price*((strtotime($row->end_time) - strtotime($row->start_time))/3600); $amount = ($price * (1 - ((double) $percent / 100))); $discount = $price - ($amount); } else {//package switch ($row->grade) { case 'K2': case 'K3': case 'P1': case 'P2': case 'P3': case 'P4': case 'P5': case 'P6': case 'Y1': case 'Y2': case 'Y3': case 'Y4': case 'Y5': case 'Y6': $price+=$row->primary_package_price; break; case 'S1': case 'S2': case 'S3': case 'S4': case 'S5': case 'S6': case 'Y7': case 'Y8': case 'Y9': case 'Y10': case 'Y11': case 'Y12': $price+=$row->secondary_package_price; break; } $amount = (($price) * (1.0 - ((double) $percent / 100))); $discount = $price - ($amount); } } $total_price +=$price; $total_discount +=$discount; $total_amount +=$amount; /* echo "<script>alert('".$price."')</script>"; echo "<script>alert('".$discount."')</script>"; echo "<script>alert('".$fee."')</script>"; */ ?> <tr> <td><input type="checkbox" name="lesson_id[]" value="<?= $row->lesson_id ?>"></td> <td><?= $row->date ?><input type="hidden" name="date[]" value=""></td> <td><?= $row->start_time ?><input type="hidden" name="start_time[]" value=""></td> <td><?= $row->end_time ?><input type="hidden" name="end_time[]" value=""></td> <td><?= (strtotime($row->end_time) - strtotime($row->start_time))/3600 ?><input type="hidden" name="hours[]" value=""></td> <td> <?php if ($row->programme_fee_type == 1) { echo 'Hourly' . '<input type="hidden" name="fee_type[]" value="1">'; } else { if ($row->programme_fee_type == 2) { echo 'Package' . '<input type="hidden" name="fee_type[]" value="2">'; } else { echo 'Free' . '<input type="hidden" name="fee_type[]" value="3">'; } } ?> </td> <td><?= $price ?><input type="hidden" name="price[]" id='price_<?=$i?>' value="<?= $price ?>"></td> <td> <?php if ($row->attendance == 1) { echo 'Present'; echo '<input type="hidden" name="attendance[]" value="1">'; } else { echo 'Absent'; echo '<input type="hidden" name="attendance[]" value="0">'; } ?> </td> <td><textarea name="remarks[]"></textarea></td> <td> <select name="type[]" id="type_<?= $i ?>" onChange="change_discount(this);"> <option value="1" selected>Subsidy</option> <option value="2">Package discount</option> <option value="3">Funding</option> </select> </td> <td><input type="number" name="type_rate[]" id="typerate_<?= $i ?>" value="<?= $percent ?>" readonly='true' onBlur="funding(this);"></td> <td><input type="number" name="discount[]" id="discount_<?= $i ?>" value="<?= $discount ?>" readonly='true'></td> <td><input type="checkbox" name="is_charge[]" id="charge_<?= $i ?>" onClick="not_charge(this);"></td> <td><input type="text" name="amount[]" id='amount_<?=$i?>' value="<?= $amount ?>" readonly="true"></td> </tr> <?php $i++; } } else { echo '<script>alert("GGGGGGGGGGGg")</script>'; } ?> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td>Total price:<?= $total_price ?></td> <td> </td> <td> </td> <td> </td> <td> </td> <td>Total discount:<input type='text' name='total_discount' id='total_discount' value='<?= $total_discount ?>' readonly='true'></td> <td> </td> <td> Total amount:<input type='text' name='total_amount' id='total_amount' value='<?= $total_amount ?>' readonly='true'> <input type="hidden" name="i" id="i" value="<?=$i?>"> </td> </tr> </table> <input type="submit" name="generate" value="Generate" class="btn"> <?php } else { ?> <div> <table border="0" width="100%"> <tr> <td><h2>Generate Invoice</h2></td> </tr> </table> </div> <form action="" method="POST" class="form-inline"> <div class="pathways-search"> <table border="0" width="100%"> <tr> <?php if (isset($_POST['search']) && $_POST['search'] == "Search") { $from_date = $_POST['from_date']; $to_date = $_POST['to_date']; //$yr = $_POST['sem_yr']; ?> <!--<td width="20%"> Semaster_Year <select name="sem_yr"> <?php $query12 = "Select Sem_yr as yr from student group by Sem_yr"; $result12 = $dbh->query($query12); $result12->setFetchMode(PDO::FETCH_OBJ); while ($row12 = $result12->fetch()) { if ($row12->yr == $yr) print '<option value="' . $row12->yr . '" selected>' . $row12->yr . '</option>'; else print '<option value="' . $row12->yr . '">' . $row12->yr . '</option>'; } ?> </select> </td>--> <td width="20%">Date <div class="input-append date-picker"> <input type="text" name="from_date" class="dateISO" required="true" value="<?= $from_date ?>"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </td> <td width="20%">To <div class="input-append date-picker"> <input type="text" name="to_date" class="dateISO" required="true" value="<?= $to_date ?>"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </td> <?php } else { ?> <!--<td width="20%"> Semaster_Year <select name="sem_yr"> <?php /*$curr_yr = date("Y"); $curr_mon = date("M"); echo "<script>alert('.$curr_yr.' '.$curr_mon.')</script>"; $query12 = "Select Sem_yr as yr from student group by Sem_yr"; $result12 = $dbh->query($query12); $result12->setFetchMode(PDO::FETCH_OBJ); while ($row12 = $result12->fetch()) { $year1 = explode("-", $row12->yr)[0]; $year2 = explode("-", $row12->yr)[1]; if ($curr_yr == $year1 && $curr_mon >= 9) { print '<option value="' . $row12->yr . '"selected>' . $row12->yr . '</option>'; } else { if ($curr_yr == $year2 && $curr_mon < 9) { print '<option value="' . $row12->yr . '"selected>' . $row12->yr . '</option>'; } else print '<option value="' . $row12->yr . '">' . $row12->yr . '</option>'; } }*/ ?> </select> </td>--> <td width="20%"> Date <div class="input-append date-picker"> <input type="text" name="from_date" class="dateISO" required="true"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </td> <td width="20%"> To <div class="input-append date-picker"> <input type="text" name="to_date" class="dateISO" required="true"> <span class="add-on"> <i class="icon-calendar" data-date-icon="icon-calendar" data-time-icon="icon-time"></i> </span> </div> </td> <?php } ?> <td><input type="submit" name="search" class="btn" value="Search"></td> </tr> </table> </div> <table border="0" class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th> </th> <th>Name</th> <th>Event Code</th> </tr> </thead> <?php if (isset($_POST['search']) && $_POST['search'] == "Search") { $from_date = $_POST['from_date']; $to_date = $_POST['to_date']; //$yr = $_POST['sem_yr']; $query = "Select e.event_id,e.event_code,l.lesson_id,l.start_time,l.end_time,l.date,stu.first_name,stu.last_name,stu.linking_id,stu.root_id,stu.New_stu_ID as id,e.programme_fee_type,e.program_id,e.subject_id,e.primary_individual_price,e.primary_group_price,e.secondary_individual_price,e.secondary_group_price, e.primary_package_price,e.secondary_package_price,g.grade,la.attendance from event as e, lesson_attendance as la,student_grade as sg,grade as g, student as stu,lesson as l,event_lesson as el where e.event_id=el.event_id and el.lesson_id=l.lesson_id and l.lesson_id=la.lesson_id and sg.student_grade_id=stu.linking_id and sg.grade_id=g.grade_id and stu.root_id=la.stu_linking_id and sg.student_grade_id=stu.linking_id and sg.grade_id=g.grade_id and e.deleted=0 and e.actived=1 and la.deleted=0 and la.actived=1 and stu.deleted=0 and stu.actived=1 and l.deleted=0 and l.actived=1 and el.deleted=0 and el.actived=1 and l.date>='$from_date' and l.date<='$to_date' group by stu.linking_id,e.event_code"; /* Select e.event_id,e.event_code,ss.subsidy_id,s.subsidy_type,s.percent,l.lesson_id,l.start_time,l.end_time,l.date,stu.first_name,stu.last_name,stu.linking_id,stu.root_id, e.programme_fee_type,e.program_id,e.subject_id,e.primary_individual_price,e.primary_group_price,e.secondary_individual_price,e.secondary_group_price, e.primary_package_price,e.secondary_package_price,e.is_free,g.grade,la.attendance from event as e, lesson_attendance as la,student_grade as sg,grade as g, student as stu,student_subsidy as ss,subsidy as s,lesson as l,event_lesson as el where e.event_id=el.event_id and el.lesson_id=l.lesson_id and l.lesson_id=la.lesson_id and stu.linking_id=ss.stu_subsidy_id and ss.subsidy_id=s.Subsidy_ID and sg.student_grade_id=stu.linking_id and sg.grade_id=g.grade_id and e.deleted=0 and e.actived=1 and la.deleted=0 and la.actived=1 and stu.deleted=0 and stu.actived=1 and ss.deleted=0 and ss.actived=1 and s.deleted=0 and s.actived=1 and l.deleted=0 and l.actived=1 and el.deleted=0 and el.actived=1 and l.date>='$from_date' and l.date<='$to_date' and stu.New_stu_ID='$stu_id' and stu.Sem_yr='$yr' group by e.event_id"; */ /* Select e.event_id,e.event_code,l.lesson_id,l.start_time,l.end_time,l.date, e.programme_fee_type,e.program_id,e.subject_id,e.primary_individual_price,e.primary_group_price,e.secondary_individual_price,e.secondary_group_price, e.primary_package_price,e.secondary_package_price from event as e,lesson as l,event_lesson as el where e.event_id=el.event_id and el.lesson_id=l.lesson_id */ $result = $dbh->query($query); //get invoice data $result->setFetchMode(PDO::FETCH_OBJ); while ($row = $result->fetch()) { $query_pro = "Select program_name from program where program_id='$row->program_id'"; $query_sub = "Select sub_name from subject where subject_id='$row->subject_id'"; $result_pro = $dbh->query($query_pro); $result_sub = $dbh->query($query_sub); $result_pro->setFetchMode(PDO::FETCH_OBJ); $result_sub->setFetchMode(PDO::FETCH_OBJ); $sub = $result_sub->fetch(); $pro = $result_pro->fetch(); //*****************************************************************// $query1 = "Select ss.stu_subsidy_id,s.percent as sum_p from student_subsidy as ss, subsidy as s where ss.subsidy_id = s.subsidy_id and ss.deleted=0 and s.deleted=0 "; $result1 = $dbh->query($query1); //get percent $result1->setFetchMode(PDO::FETCH_OBJ);
while ($row1 = $result1->fetch()) { if ($row->linking_id == $row1->stu_subsidy_id) { //echo '<script>' . $row->percent . '</script>'; $percent = $row1->sum_p; } } $query5 = "Select count(*) as no_of_stu from lesson_attendance where lesson_id IN (Select lesson_id from lesson_attendance where stu_linking_id='$row->root_id')"; $result5 = $dbh->query($query5); $result5->setFetchMode(PDO::FETCH_OBJ); $row5 = $result5->fetch(); ?> <tr> <td> <input type="radio" name="id" value="<?= $row->event_id . '|' . $row->linking_id ?>"> </td> <td><?= $row->last_name . " " . $row->first_name."(".$row->id.")" ?></td> <td><?= $row->event_code ?></td> </tr> <?php } } ?> </table> <input type="submit" name="select" class="btn" value="Select"> </form> <?php } ?> </div> </body> </html>
|