/
ajaxfunctions.php
513 lines (491 loc) · 16.9 KB
/
ajaxfunctions.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
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
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
include_once ("queryfunctions.php");
include_once ("functions.php");
switch ($_POST["button"]){
case "Agent":
agents();
break;
case "GetRates":
$conn=db_connect(HOST,USER,PASS,DB,PORT);
//check room availability
$roomid=$_POST["roomid"];
$sql="Select rooms.roomid,rooms.roomno,rooms.status,booking.checkin_date,booking.checkout_date
From rooms
Left Join booking ON rooms.roomid = booking.roomid
Where rooms.status = 'V' and rooms.roomid=$roomid";
$results=mkr_query($sql,$conn);
$msg[0]="";
$msg[1]="";
AddSuccess($results,$conn,$msg);
if (num_rows($results)==0){
//rooms.status - could tell if room is locked/booked/reserverd/vacant
//get room id and find out status - to do
echo "<h2><blink>Sorry room is either occupied or reserved</blink></h2>";
}else{
echo "<h1>Room ready for occupancy</h1>";
}
//get rate if available
/*$booking_type=$_POST["booking_type"]; //direct booking / booking through agents
//$agents_ac_no=$_POST["agents_ac_no"]; //agents account code
$no_adults=$_POST["no_adults"]>1 ? 'D' : 'S'; //double or single
$meal_plan=$_POST["meal_plan"]; //meal plan - bed only/half board/bed & breakfast/full board
//$rate_type=$_POST["rate_type"]; //residence or non-residence
if ($booking_type='D'){ //direct booking
"Select rates.bookingtype,rates.occupancy,rates.ratesid,rates.rate_type,rates.currency,$meal_plan
From rates
Where rates.occupancy = 'S' AND
rates.rate_type = $rate_type";
}elseif($booking_type='A'){
//link with agent id
"Select agents.agentid,agents.agentname,rates.ratesid,rates.bookingtype,rates.occupancy,rates.rate_type,agents.agents_ac_no,$meal_plan
From agents
Inner Join rates ON agents.ratesid = rates.ratesid
Where rates.bookingtype = 'A' AND
rates.rate_type = $rate_type AND
agents.agents_ac_no = $agents_ac_no";
}*/
break;
case "Cash" || "Debit":
trans_type();
break;
case "UpdateBill":
updatebill();
break;
}
switch ($_GET["submit"]){
case "Rates":
rates_table();
break;
case "RoomDetails":
rooms_details();
break;
case "Roomtype":
room_types();
break;
case "Bills":
bills_details();
break;
case "transdetails":
transdetails();
break;
case "Documents":
Documents();
break;
case "Transtypes":
Transtypes();
break;
case "PaymentMode":
PaymentMode();
break;
default:
echo $_GET["submit"];
}
function rates_table(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select ratesid,bookingtype,occupancy,rate_type,bo,bb,hb,fb,currency,date_started,date_stopped From rates";
$rates=mkr_query($sql,$conn);
$n=mysql_num_fields($rates);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Rate ID</th>
<th>Booking Type</th>
<th>Occupancy</th>
<th>Rate Type</th>
<th>Currency</th>
<th>BO</th>
<th>BB</th>
<th>HB</th>
<th>FB</th>
<th>Starting</th>
<th>Ending</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($rates)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
//"bookingtype,occupancy,rate_type,bo,bb,hb,fb,currency,date_started,date_stopped"
echo "<td>" . $row->ratesid . "</td>";
echo "<td>" . ((trim($row->bookingtype)=="D") ? "Direct" : "Agent") . "</td>";
echo "<td>" . $row->occupancy . "</td>";
echo "<td>" . $row->rate_type . "</td>";
echo "<td>" . $row->currency . "</td>";
echo "<td>" . $row->bo . "</td>";
echo "<td>" . $row->bb . "</td>";
echo "<td>" . $row->hb . "</td>";
echo "<td>" . $row->fb . "</td>";
echo "<td>" . $row->date_started . "</td>";
echo "<td>" . $row->date_stopped . "</td>";
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
}
function rooms_details(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select roomid,roomno,roomtypeid,roomname,noofrooms,occupancy,tv,aircondition,fun,safe,fridge,status,photo From rooms";
$rates=mkr_query($sql,$conn);
$n=mysql_num_fields($rates);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Room No.</th>
<th>Room Type</th>
<th>Name</th>
<th>No. of Rooms</th>
<th>Occupancy</th>
<th>TV</th>
<th>Air con.</th>
<th>Fun</th>
<th>Safe</th>
<th>Fridge</th>
<th>Status</th>
<th>Photo</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($rates)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
echo "<td>" . $row->roomno . "</td>";
echo "<td>" . $row->roomtypeid . "</td>";
echo "<td>" . $row->roomname . "</td>";
echo "<td>" . $row->noofrooms . "</td>";
echo "<td>" . $row->tv . "</td>";
echo "<td>" . $row->occupancy . "</td>";
echo "<td>" . $row->aircondition . "</td>";
echo "<td>" . $row->fun . "</td>";
echo "<td>" . $row->safe . "</td>";
echo "<td>" . $row->fridge . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->photo . "</td>";
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
}
function bills_details(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="SELECT bill_id,book_id,date_billed,billno,status,date_checked FROM bills";
$bills=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Action</th>
<th>Bill ID.</th>
<th>Booking ID.</th>
<th>Date Billed</th>
<th>Bill No.</th>
<th>Status</th>
<th>Checked In</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($bills)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
echo "<td><a href=\"billings.php?search=$row->bill_id&action=search\"><img src=\"images/button_view.png\" width=\"16\" height=\"16\" border=\"0\" title=\"view bill\"/></a></td>";
echo "<td>" . $row->bill_id . "</td>";
echo "<td>" . $row->book_id . "</td>";
echo "<td>" . $row->date_billed . "</td>";
echo "<td>" . $row->billno . "</td>";
echo "<td>" . $row->status . "</td>";
echo "<td>" . $row->date_checked . "</td>";
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
}
function transdetails(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select itemid,item,description,sale,expense From details";
$bills=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Item ID.</th>
<th>Item</th>
<th>Description</th>
<th>Sale</th>
<th>Expense</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($bills)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
echo "<td title=\"edit details\"><a href=\"lookup.php?search=$row->itemid\"><img src=\"images/button_edit.png\" width=\"16\" height=\"16\" border=\"0\" title=\"edit details\"/></a></td>";
//echo "<td>" . $row->itemid . "</td>";
echo "<td>" . $row->item . "</td>";
echo "<td>" . $row->description . "</td>";
echo "<td>" . $row->sale . "</td>";
echo "<td>" . $row->expense . "</td>";
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
}
function Documents(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select doc_id,doc_code,doc_type,remarks,accounts,cooperative,payroll From doctypes";
$docs=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Document ID.</th>
<th>Document Code</th>
<th>Document Type</th>
<th>Remarks</th>
<th>Accounts</th>
<th>Cooperative</th>
<th>Payroll</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($docs)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
/*echo "<td>" . $row->doc_id . "</td>";*/
//
$i = 0;
while ($i < mysql_num_fields($docs)) {
$meta = mysql_fetch_field($docs, $i);
$field=$meta->name;
echo "<td>" . $row->$field . "</td>";
$i++;
}
//
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
mysql_free_result($docs);
}
function Transtypes(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select trans_id,trans_code,trans_type,remarks,accounts,cooperative,payroll From transtype";
$trans=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Trans. Type ID.</th>
<th>Trans. Type Code</th>
<th>Transaction Type</th>
<th>Remarks</th>
<th>Accounts</th>
<th>Cooperative</th>
<th>Payroll</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
while ($row = fetch_object($trans)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
/*echo "<td>" . $row->doc_id . "</td>";*/
//
$i = 0;
while ($i < mysql_num_fields($trans)) {
$meta = mysql_fetch_field($trans, $i);
$field=$meta->name;
echo "<td>" . $row->$field . "</td>";
$i++;
}
//
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
mysql_free_result($trans);
}
function PaymentMode(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="Select paymentid,payment_option From payment_mode";
$paymode=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Payment ID.</th>
<th>Payment Mode</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
//consider having this as a function - is being called in several places
while ($row = fetch_object($paymode)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
$i = 0;
while ($i < mysql_num_fields($paymode)) {
$meta = mysql_fetch_field($paymode, $i);
$field=$meta->name;
echo "<td>" . $row->$field . "</td>";
$i++;
}
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
mysql_free_result($paymode);
}
function room_types(){
$conn=db_connect(HOST,USER,PASS,DB,PORT);
$sql="SELECT * FROM roomtype";
$roomtype=mkr_query($sql,$conn);
//$n=mysql_num_fields($bills);
echo "<table valign=\"top\">";
//get field names to create the column header
echo "<tr bgcolor=\"#009999\">
<th>Room Type ID.</th>
<th>Room Type</th>
<th>Description</th>
</tr>";
//end of field header
//get data from selected table on the selected fields
//consider having this as a function - is being called in several places - todo
while ($row = fetch_object($roomtype)) {
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
$i = 0;
while ($i < mysql_num_fields($roomtype)) {
$meta = mysql_fetch_field($roomtype, $i);
$field=$meta->name;
echo "<td>" . $row->$field . "</td>";
$i++;
}
echo "</tr>"; //end of - data rows
} //end of while row
echo "</table>";
mysql_free_result($roomtype);
}
function agents(){
echo "<td>Agent Name</td><td><select name=\"agent\" id=\"agent\">
<option value=\"\">Select Agent</option>";
echo populate_select('agents','agents_ac_no','agentname',$reservations->agents_ac_no);
echo "</select></td>";
}
function trans_type(){
//get items for cashsale or get items for expenses
switch($_POST["button"]){
case "Cash":
echo "<table>
<tr>
<td width=\"27%\">Date</td>
<td width=\"22%\">Details</td>
<td width=\"26%\">CR Amount</td>
<td width=\"25%\">Rec No. </td>
<td align=\"center\">Post</td>
</tr>
<tr><td><input type=\"text\" name=\"doc_date\" id=\"doc_date\" size=\"15\"/><a href=\"javascript:showCal('Calendar7')\"> <img src=\"images/ew_calendar.gif\" width=\"16\" height=\"15\" border=\"0\"/></a></td>
<td><select name=\"details\">
<option value=\"\">Select Item</option>";
populate_select("details","itemid","item",0);
echo "</select></td>
<td><input type=\"text\" name=\"cr\" size=\"20\"/></td>
<td><input type=\"text\" name=\"doc_no\" size=\"15\" /></td>
<td align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Update\"/></td>
</tr></table>";
break;
case "Debit":
echo "<table>
<tr>
<td width=\"27%\">Date</td>
<td width=\"22%\">Details</td>
<td width=\"26%\">DR Amount</td>
<td width=\"25%\">Chit No. </td>
<td align=\"center\">Post</td>
</tr>
<tr><td><input type=\"text\" name=\"doc_date\" id=\"doc_date\" size=\"15\"/><a href=\"javascript:showCal('Calendar7')\"> <img src=\"images/ew_calendar.gif\" width=\"16\" height=\"15\" border=\"0\"/></a></td>
<td><select name=\"details\">
<option value=\"\">Select Item</option>";
populate_select("details","itemid","item",0);
echo "</select></td>
<td><input type=\"text\" name=\"dr\" size=\"20\"/></td>
<td><input type=\"text\" name=\"doc_no\" size=\"15\" /></td>
<td align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Update\" /></td>
</tr></table>";
break;
}
}
function updatebill(){
$billno=!empty($_POST['search']) ? $_POST['search'] : 0;
//$billno=!empty($_POST['billid']) ? $_POST['billid'] : 1;
$sql="Select transactions.doc_date,details.item,transactions.dr,transactions.cr,transactions.doc_no,transactions.doc_type,details.itemid
From transactions
Inner Join details ON transactions.details = details.itemid
Where transactions.billno = '$search'";
$results=mkr_query($sql,$conn);
echo "<table width=\"100%\" border=\"0\" cellpadding=\"1\">
<tr bgcolor=\"#FF9900\">
<th></th>
<th>Date</th>
<th>Details</th>
<th>DR</th>
<th>CR</th>
<th>Balance</th>
<th>Doc. No. </th>
<th>Doc. Type</th>
</tr>";
//get data from selected table on the selected fields
while ($trans = fetch_object($results)) {
$balance=$balance-$trans->cr+$trans->dr;
//alternate row colour
$j++;
if($j%2==1){
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#CCCCCC\">";
}else{
echo "<tr id=\"row$j\" onmouseover=\"javascript:setColor('$j')\" onmouseout=\"javascript:origColor('$j')\" bgcolor=\"#EEEEF8\">";
}
echo "<td><a href=\"billings.php?search=$guest->guestid&action=search\"><img src=\"images/button_signout.png\" width=\"16\" height=\"16\" border=\"0\" title=\"bill guest\"/></a></td>";
echo "<td>" . $trans->doc_date . "</td>";
echo "<td>" . $trans->item . "</td>";
echo "<td>" . $trans->dr . "</td>";
echo "<td>" . $trans->cr . "</td>";
echo "<td>" . $balance . "</td>";
echo "<td>" . $trans->doc_no . "</td>";
echo "<td>" . $trans->doc_type . "</td>"; //calucate running balance
echo "</tr>"; //end of - data rows
} //end of while row
echo "<tr><td colspan=\"3\" align=\"center\"><b>TOTAL</b></td><td><b>DR Total</b></td><td><b>CR Total</b></td><td><b>Total Bal.</b></td><tr>";
echo "</table>";
}
?>