/var/www/(Del)pathways.org.hk/MIS20140127/old20140221/student_invoice/invoice.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
<!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 check_all(obj, cName) {
                var checkboxs = document.getElementsByName(cName);
                for (var i = 0; i < checkboxs.length; i++) {
                    checkboxs[i].checked = obj.checked;
                }
            }
            ;
            $(function() {
                $('.date-picker').datetimepicker({pickTime: false, format: 'yyyy-MM-dd'});
            });
        </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 -->
        <form action="" method="POST" class="form-inline">
            <div class="container-fluid pathways-container">
                <table border="0" class="table table-striped table-bordered table-hover table-condensed">
                    <tr>
                        <td colspan="4"><center><h3>INVOICE</h3></center></td>
                    </tr>
                    <?php
                    
if (isset($_POST['gene']) && $_POST['gene'] == "Generate") {
                        
$percent 0;
                        
$from_date $_POST['from_date'];
                        
$to_date $_POST['to_date'];
                        
$stu_id $_POST['stu_id'];
                        
$yr $_POST['sem_yr'];

                        for (
$i 0$i count($_POST['lesson_id']); $i++) {
                            
$lesson_id $_POST['lesson_id'][$i];
                            
$query "Select e.event_id,e.event_code,ss.subsidy_id,s.subsidy_type,s.percent,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,e.package_discount,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' and l.lesson_id='$lesson_id'
                                group by ss.stu_subsidy_id"
;
                            
$result $dbh->query($query); //get invoice data
                            
if ($result) {
                                
$result->setFetchMode(PDO::FETCH_OBJ);

                                
$query1 "Select ss.stu_subsidy_id,Sum(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
                            group by ss.stu_subsidy_id"
;
                                
$result1 $dbh->query($query1); //get percent
                                
$result1->setFetchMode(PDO::FETCH_OBJ);

                                while (
$row $result->fetch()) {
                                    while (
$row1 $result1->fetch()) {
                                        if (
$row->linking_id == $row1->stu_subsidy_id) {
                                            echo 
'<script>' $row->percent '</script>';
                                            
$percent $row1->sum_p;
                                        }
                                    }
                                    
$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='',subsidy_type='$row->subsidy_type'";
                                    
$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 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();
                                    
$price 0;
                                    
$discount 0;
                                    
$total 0;

                                    if (
$row->is_free != 1) {
                                        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;
                                                }
                                            }
                                            
$total = ($price $percent 100);
                                            
$discount $price - ($total);
                                            
$query3 "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),actived=1,
                                deleted=0,invoice_id='
$row4->i',student_linking_id='$row->root_id',event_programme_fee_type='$row->programme_fee_type',
                                     amount='
$total',original_fee='$price',discounted_fee='$discount',hour='($row->end_time-$row->start_time)',subsidy_percent='$percent',remarks=''";
                                        } 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;
                                                    
$discount $row->package_discount;
                                                    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;
                                                    
$discount $row->sec_package_discount;
                                                    break;
                                            }
                                            
$total $price $discount;
                                            
$total = ($price $percent 100);
                                            
$discount $price - ($total);
                                            
$query3 "Insert into invoice_line set createby=0,createdate=Now(),lastupby=0,lastupdate=Now(),actived=1,
                                    deleted=0,invoice_id='
$row4->i',student_linking_id='$row->root_id',event_programme_fee_type='$row->programme_fee_type',
                                        amount='
$total',original_fee='$price',discounted_fee='$discount',hour='',subsidy_percent='$percent',remarks=''";
                                        }
                                    }
                                    
$result3 $dbh->query($query3);
                                    
$result3->setFetchMode(PDO::FETCH_OBJ);
                                    
//insert invoice/invoice line then get it out to print somethings
                                
}
                            } else {
                                echo 
'<script>alert("GGGGGGGGGGGg")</script>';
                            }
                        }
                    }
                    
?>
                </table>

            </div>
        </form>
    </body>
</html>