-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreports.pl
executable file
·3237 lines (2762 loc) · 123 KB
/
reports.pl
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
$ENV{NLS_LANG} = 'AMERICAN_AMERICA.AL32UTF8';
$ENV{ORACLE_SID} = 'XE';
$ENV{ORACLE_HOME} = '/usr/lib/oracle/xe/app/oracle/product/10.2.0/server';
$ENV{LD_LIBRARY_PATH} = '/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/lib';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use DBIx::Simple;
use Template;
use CGI::FormBuilder;
use Number::Format;
my $q = new CGI;
my $nf = new Number::Format( -int_curr_symbol => '' );
my $tt = Template->new(
{
INCLUDE_PATH => [ '/var/www/munshi9/tmpl', '/var/www/lighttpd/munshi9/tmpl' ],
INTERPOLATE => 1,
}
) || die "$Template::ERROR\n";
my %attr = ( PrintError => 0, RaiseError => 0 ); # Attributes to pass to DBI->connect() to disable automatic error checking
my $dbh = DBI->connect( "dbi:Oracle:XE", "munshi8", "gbaba4000", \%attr ) or die "Can't connect to database: ", $DBI::errstr, "\n";
my $dbs = DBIx::Simple->connect($dbh);
my $nextsub = $q->param('nextsub');
my $action = $q->param('action');
my $tmpl = $q->param('tmpl');
my $id = $q->param('id');
my $emp_num = $q->param('emp_num');
my $comp_code = $q->param('comp_code');
my $dir = $q->param('dir');
$dir = 'misc' if !$dir;
$nextsub = $q->param('nextsub');
&$nextsub;
1;
#---------------------------------------------------------
# sample report
sub sample {
my @charge_codes = $dbs->query(qq|SELECT charge_code, charge_desc FROM hc_charge_codes ORDER BY 1|)->arrays;
my $form1 = CGI::FormBuilder->new(
method => 'post',
table => 1,
fields => [qw(charge_code charge_desc)],
options => { charge_code => \@charge_codes, },
messages => { form_required_text => '', },
labels => { charge_code => 'Charge Code', },
submit => [qw(Search)],
params => $q,
stylesheet => 1,
template => {
type => 'TT2',
template => 'tmpl/search.tmpl',
variable => 'form1',
},
keepextras => [qw(report_name action)],
);
$form1->field( name => 'charge_code', type => 'select' );
print $q->header();
print $form1->render;
my $table = $dbs->query(qq|SELECT charge_code, charge_desc FROM hc_charge_codes ORDER BY charge_code|)->xto();
$table->modify( table => { cellpadding => "3", cellspacing => "2" } );
$table->modify( tr => { class => [ 'listrow0', 'listrow1' ] } );
$table->modify( th => { class => 'listheading' }, 'head' );
$table->modify( th => { class => 'listtotal' }, 'foot' );
$table->modify( th => { class => 'listsubtotal' } );
$table->modify( th => { align => 'center' }, 'head' );
$table->modify( th => { align => 'right' }, 'foot' );
$table->modify( th => { align => 'right' } );
print $table->output;
print qq|
</body>
</html>
|;
}
#----------------------------------------
sub banquet {
my $vars = {};
$vars->{hdr} = $dbs->query( 'SELECT * FROM banquet_header WHERE event_number=?', $id )->hash;
$vars->{dtl} = $dbs->query( 'SELECT * FROM banquet_lines WHERE event_number=?', $id )->map_hashes('id');
$vars->{dayname} = $dbs->query( "SELECT TO_CHAR(event_date, 'DAY') FROM banquet_header WHERE event_number=?", $id )->list;
$vars->{hdr}->{setup_detail} =~ s/\n/<br>/g;
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub fbchq {
my $vars = {};
$vars->{nf} = $nf;
$vars->{hdr} = $dbs->query( 'SELECT * FROM hc_fb_sale WHERE sale_id=?', $id )->hash;
$vars->{guest_name1} = $dbs->query( 'SELECT guest_name1 FROM hc_res WHERE res_id=?', $vars->{hdr}->{res_id} )->list;
$vars->{dtl} = $dbs->query( 'SELECT * FROM hc_fb_sale_lines WHERE sale_id=?', $id )->map_hashes('id');
$vars->{user} = $dbs->query( "SELECT 'USER: ' || created_by || ' AT ' || TO_CHAR(creation_date, 'DD-MON-RR HH24:MI') FROM hc_fb_sale WHERE sale_id=?", $id )->list;
$vars->{outlet} = $dbs->query( 'SELECT outlet_name FROM hc_fb_outlets WHERE outlet_id = ?', $vars->{hdr}->{outlet_id} )->list;
$vars->{sc_amt} = $dbs->query( 'SELECT ROUND((fsale_amt + bsale_amt + osale_amt) * sc/100,2) FROM hc_fb_sale WHERE sale_id=?', $id )->list;
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub reservation {
my $vars = {};
$vars->{res} = $dbs->query( 'SELECT * FROM hc_res WHERE res_id=?', $id )->hash;
$vars->{company} = $dbs->query( 'SELECT * FROM hc_companies WHERE comp_code = (SELECT comp_code FROM hc_res WHERE res_id = ?)', $id )->hash;
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub guestfolio {
my $vars = {};
$vars->{res} = $dbs->query( 'SELECT * FROM hc_res WHERE res_id=?', $id )->hash;
$vars->{charges} = $dbs->query( 'SELECT * FROM hc_charges WHERE res_id=? ORDER BY charge_date', $id )->map_hashes('tr_num');
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub regcard {
my $vars = {};
$vars->{res} = $dbs->query( 'SELECT * FROM hc_res WHERE res_id=?', $id )->hash;
$vars->{checkin_time} = $dbs->query( "SELECT TO_CHAR(checkin_time2, 'DD-MON-YYYY HH24:MI:SS') FROM hc_res WHERE res_id = ?", $id )->list;
( $vars->{ramada_username}, $vars->{ramada_checkin_time} ) = $dbs->query( "SELECT a\$sec.get_user, TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') FROM hc_res WHERE res_id = ?", $id )->list;
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub invoice {
my $vars = {};
my $taxper = $dbs->query("SELECT global_value FROM z_apps_data WHERE id='FB_TAX1_PER'")->list;
my $taxper = 1 + ( $taxper / 100 );
$vars->{nf} = $nf;
$vars->{hdr} = $dbs->query( 'SELECT * FROM hc_invoices WHERE inv_num=?', $id )->hash;
$vars->{company} = $dbs->query( 'SELECT * FROM hc_companies WHERE comp_code=?', $vars->{hdr}->{comp_code} )->hash;
$vars->{dtl} = $dbs->query( "
SELECT to_char(charge_date, 'yymmdd')||room_num||tr_num id, tr_num, charge_date, res_id, guest_name1, other_ref1, other_ref2, room_num, 0-amount amount, ROUND((0-amount) / $taxper, 2) tax_amt
FROM hc_charges WHERE bill_num=? AND sale_id = 0 ORDER BY 1", $id )->map_hashes('id');
$vars->{chq} = $dbs->query( "
SELECT to_char(sale_date, 'yymmdd')||sale_id id, hc_fb_sale.* FROM hc_fb_sale
WHERE sale_id IN (SELECT sale_id FROM hc_charges WHERE bill_num = ?) ORDER BY 1", $id )->map_hashes('id') or die( $dbs->error );
$vars->{receipts} = $dbs->query( "
SELECT to_char(tr_date, 'yymmdd')||tr_num id, tr_num, tr_date, rec_type, rec_ref, rec_desc, rec_amt, other_ref1, other_ref2
FROM hc_receipts_detail WHERE inv_num = ? ORDER BY 1", $id )->map_hashes('id') or die( $dbs->error );
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub payable {
my $vars = {};
$vars->{nf} = $nf;
$vars->{hdr} = $dbs->query( 'SELECT * FROM ap_header WHERE inv_id=?', $id )->hash;
$vars->{company} = $dbs->query( 'SELECT * FROM ap_vendors WHERE comp_code=?', $vars->{hdr}->{vendor_id} )->hash;
$vars->{dtl} = $dbs->query( "SELECT * FROM ic_trans_header_tmp WHERE inv_id=?", $id )->map_hashes('tr_num');
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub reminder {
my $vars = {};
$vars->{nf} = $nf;
$vars->{company} = $dbs->query( 'SELECT * FROM hc_companies WHERE comp_code=?', $comp_code )->hash;
$vars->{invoices} = $dbs->query( "
SELECT TO_CHAR(inv_date,'yymmdd')||inv_num id, hc_invoices.*
FROM hc_invoices WHERE comp_code=? AND ROUND(inv_amt - rec_amt,0) <> 0 ", $comp_code )->map_hashes('id');
$vars->{tax} = $dbs->query( "
SELECT TO_CHAR(inv_date,'yymmdd')||i.inv_num id, i.inv_num, i.inv_date, i.inv_amt, r.rec_amt, r.other_ref1, r.other_ref2
FROM hc_receipts_detail r, hc_invoices i
WHERE r.inv_num = i.inv_num
AND i.comp_code = ?
AND r.rec_type = 'TAX'
AND r.gl_posted = 'N'
ORDER BY i.inv_num, i.inv_date
", $comp_code )->map_hashes('id');
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub pr {
my $vars = {};
$vars->{nf} = $nf;
$vars->{hdr} = $dbs->query( 'SELECT * FROM pr WHERE tr_num=?', $id )->hash;
$vars->{company} = $dbs->query( 'SELECT * FROM ap_vendors WHERE vendor_id=?', $vars->{hdr}->{vendor_id} )->hash;
$vars->{dtl} = $dbs->query( 'SELECT pr_lines.*, ic_items.uom_stk_id unit FROM pr_lines, ic_items WHERE pr_lines.item_id = ic_items.item_id AND tr_num = ?', $id )->map_hashes('ln');
$vars->{pr_amt} = $dbs->query( 'SELECT SUM(req_qty*cost) FROM pr_lines WHERE tr_num = ?', $id )->list;
$vars->{req_by} = $dbs->query( 'SELECT loc_name FROM ic_locs WHERE loc_id = ?', $vars->{hdr}->{req_by} )->list;
$vars->{store_id} = $dbs->query( 'SELECT loc_name FROM ic_locs WHERE loc_id = ?', $vars->{hdr}->{store_id} )->list;
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub po {
my $vars = {};
$vars->{nf} = $nf;
$vars->{hdr} = $dbs->query( 'SELECT * FROM po WHERE tr_num=?', $id )->hash;
$vars->{hdr}->{terms} =~ s/\n/<br>/g;
$vars->{company} = $dbs->query( 'SELECT * FROM ap_vendors WHERE vendor_id=?', $vars->{hdr}->{vendor_id} )->hash;
$vars->{dtl} = $dbs->query( '
SELECT po_lines.*, ic_items.uom_stk_id unit
FROM po_lines
JOIN ic_items ON (ic_items.item_id = po_lines.item_id)
WHERE tr_num = ?', $id )->map_hashes('id');
print $q->header();
$tt->process( "$tmpl.tmpl", $vars ) || die $tt->error(), "\n";
}
#----------------------------------------
sub report_header {
my $report_title = shift;
print $q->header();
print qq|
<html>
<head>
<title>$report_title</title>
<link rel="stylesheet" href="/munshi9/standard.css" type="text/css">
<link rel="stylesheet" href="/munshi9/standard.css" type="text/css">
<link type="text/css" href="/munshi9/css/start/jquery-ui-1.8.10.custom.css" rel="Stylesheet" />
<script type="text/javascript" language="javascript" src="/munshi9/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" language="javascript" src="/munshi9/js/jquery.validate.min.js"></script>
<script type="text/javascript" language="javascript" src="/munshi9/js/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript" language="javascript" src="/munshi9/js/jquery.tablesorter.min.js"></script>
|;
print q|
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("input[type='text']:first", document.forms[0]).focus();
$("#form1").validate();
})
</script>
<script>
$(function() {
$( ".datepicker" ).datepicker({
dateFormat: 'd-M-yy',
showOn: "button",
buttonImage: "/munshi9/css/calendar.gif",
buttonImageOnly: true,
showOtherMonths: true,
selectOtherMonths: true,
changeMonth: true,
changeYear: true
});
$(function(){
$("#sortedtable").tablesorter();
});
});
</script>
</head>
|;
print qq|
<body>
<h1>$report_title</h1>
|;
}
#----------------------------------------
sub runsql {
&report_header('Sample Report');
print qq|
<form action="reports.pl" method="post">
SQL: <textarea name="query">| . $q->param('query') . qq|</textarea>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my $query = $q->param('query');
die('Invalid query') if $query =~ /(insert|update|delete|drop|create)/i;
if ( $q->param('action') eq 'Update' ) {
my $table = $dbs->query($query)->xto(
table => { cellpadding => "5", cellspacing => "2" },
tr => { class => [ 'listrow0', 'listrow1' ] },
th => { class => ['listheading'] },
) or die( $dbs->error );
print $table->output;
}
}
#----------------------------------------
sub sample_report {
&report_header('Sample Report');
my @columns = qw(charge_code charge_date charge_desc amount);
my @total_columns = qw(amount);
my @search_columns = qw(fromdate todate);
my %sort_positions = {
charge_code => 1,
charge_date => 2,
charge_desc => 3,
charge_amount => 4,
};
my $sort = $q->param('sort') ? $q->param('sort') : 'charge_code';
my $sortorder = $q->param('sortorder');
my $oldsort = $q->param('oldsort');
$sortorder = ( $sort eq $oldsort ) ? ( $sortorder eq 'asc' ? 'desc' : 'asc' ) : 'asc';
print qq|
<form action="reports.pl" method="post">
From date: <input name=fromdate type=text size=12 class="datepicker" value="| . $q->param('fromdate') . qq|"><br/>
To date: <input name=todate type=text size=12 class="datepicker" value="| . $q->param('todate') . qq|"><br/>
Include: |;
for (@columns) {
$checked = ( $action eq 'Update' ) ? ( $q->param("l_$_") ? 'checked' : '' ) : 'checked';
print qq|<input type=checkbox name=l_$_ value="1" $checked> | . ucfirst($_);
}
print qq|<br/>
Subtotal: <input type=checkbox name=l_subtotal value="checked" | . $q->param('l_subtotal') . qq|><br/>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my @report_columns;
for (@columns) { push @report_columns, $_ if $q->param("l_$_") }
my $where = ' 1 = 1 ';
$where = ' 1 = 2 ' if $action ne 'Update'; # Display data only when Update button is pressed.
my @bind = ();
if ( $q->param('fromdate') ) {
$where .= qq| AND charge_date >= ?|;
push @bind, $q->param('fromdate');
}
if ( $q->param('todate') ) {
$where .= qq| AND charge_date <= ?|;
push @bind, $q->param('todate');
}
my $query = qq|
SELECT charge_code, charge_date, charge_desc, amount
FROM hc_charges
WHERE $where
ORDER BY $sort_positions($sort) $sortorder
|;
my @allrows = $dbs->query( $query, @bind )->hashes or die( $dbs->error );
my ( %tabledata, %totals, %subtotals );
my $url = "reports.pl?action=$action&nextsub=$nextsub&oldsort=$sort&sortorder=$sortorder&l_subtotal=" . $q->param(l_subtotal);
for (@report_columns) { $url .= "&l_$_=" . $q->param("l_$_") if $q->param("l_$_") }
for (@search_columns) { $url .= "&$_=" . $q->param("$_") if $q->param("$_") }
for (@report_columns) { $tabledata{$_} = qq|<th><a class="listheading" href="$url&sort=$_">| . ucfirst $_ . qq|</a></th>\n| }
print qq|
<table cellpadding="3" cellspacing="2">
<tr class="listheading">
|;
for (@report_columns) { print $tabledata{$_} }
print qq|
</tr>
|;
my $groupvalue;
my $i = 0;
for $row (@allrows) {
$groupvalue = $row->{$sort} if !$groupvalue;
if ( $q->param(l_subtotal) and $row->{$sort} ne $groupvalue ) {
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$groupvalue = $row->{$sort};
for (@total_columns) { $subtotals{$_} = 0 }
}
for (@report_columns) { $tabledata{$_} = qq|<td>$row->{$_}</td>| }
for (@total_columns) { $tabledata{$_} = qq|<td align="right">| . $nf->format_price( $row->{$_}, 2 ) . qq|</td>| }
for (@total_columns) { $totals{$_} += $row->{$_} }
for (@total_columns) { $subtotals{$_} += $row->{$_} }
print qq|<tr class="listrow$i">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$i += 1;
$i %= 2;
}
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $totals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
}
#----------------------------------------
sub business_analysis {
&report_header('Business Analysis Report');
my @columns = qw(payment_mode res_id room_num comp_code company checkin_date checkout_date room_rate adults nights amount);
my @total_columns = qw(adults room_rate nights amount);
my @search_columns = qw(fromdate todate payment_mode);
my %sort_positions = {
payment_mode => 1,
res_id => 2,
room_num => 3,
comp_code => 4,
company => 5,
checkin_date => 6,
checkout_date => 7,
room_rate => 8,
adults => 9,
nights => 10,
amount => 11,
};
my $sort = $q->param('sort') ? $q->param('sort') : 'payment_mode';
my $sortorder = $q->param('sortorder');
my $oldsort = $q->param('oldsort');
$sortorder = ( $sort eq $oldsort ) ? ( $sortorder eq 'asc' ? 'desc' : 'asc' ) : 'asc';
print qq|
<form action="reports.pl" method="post">
From charge date: <input name=fromdate type=text size=12 class="datepicker" value="| . $q->param('fromdate') . qq|"><br/>
To charge date: <input name=todate type=text size=12 class="datepicker" value="| . $q->param('todate') . qq|"><br/>
Payment Mode: <select name="payment_mode">| . lookup1( 'PAYMENT_MODE', $q->param('payment_mode') ) . qq|</select><br/>
Include: |;
for (@columns) {
$checked = ( $action eq 'Update' ) ? ( $q->param("l_$_") ? 'checked' : '' ) : 'checked';
print qq|<input type=checkbox name=l_$_ value="1" $checked> | . ucfirst($_);
}
print qq|<br/>
Subtotal: <input type=checkbox name=l_subtotal value="checked" | . $q->param('l_subtotal') . qq|><br/>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my @report_columns;
for (@columns) { push @report_columns, $_ if $q->param("l_$_") }
my $where = ' 1 = 1 ';
$where = ' 1 = 2 ' if $action ne 'Update'; # Display data only when Update button is pressed.
my @bind = ();
if ( $q->param('fromdate') ) {
$where .= qq| AND c.charge_date >= ?|;
push @bind, $q->param('fromdate');
}
if ( $q->param('todate') ) {
$where .= qq| AND c.charge_date <= ?|;
push @bind, $q->param('todate');
}
if ( $q->param('payment_mode') ) {
$where .= qq| AND r.payment_mode = ?|;
push @bind, $q->param('payment_mode');
}
my $query = qq|
SELECT r.payment_mode, r.res_id, r.room_num, r.comp_code, r.company, r.checkin_date, r.checkout_date, r.room_rate, r.adults, COUNT(*) nights, SUM(c.amount) amount
FROM hc_res r
JOIN hc_charges c ON (c.res_id = r.res_id)
WHERE $where
AND c.charge_code = '101'
GROUP BY r.payment_mode, r.res_id, r.room_num, r.comp_code, r.company, r.checkin_date, r.checkout_date, r.room_rate, r.adults
ORDER BY $sort_positions($sort) $sortorder
|;
my @allrows = $dbs->query( $query, @bind )->hashes or die( $dbs->error );
my ( %tabledata, %totals, %subtotals );
my $url = "reports.pl?action=$action&nextsub=$nextsub&oldsort=$sort&sortorder=$sortorder&l_subtotal=" . $q->param(l_subtotal);
for (@report_columns) { $url .= "&l_$_=" . $q->param("l_$_") if $q->param("l_$_") }
for (@search_columns) { $url .= "&$_=" . $q->param("$_") if $q->param("$_") }
for (@report_columns) { $tabledata{$_} = qq|<th><a class="listheading" href="$url&sort=$_">| . ucfirst $_ . qq|</a></th>\n| }
print qq|
<table cellpadding="3" cellspacing="2">
<tr class="listheading">
|;
for (@report_columns) { print $tabledata{$_} }
print qq|
</tr>
|;
my $groupvalue;
my $i = 0;
for $row (@allrows) {
$groupvalue = $row->{$sort} if !$groupvalue;
if ( $q->param(l_subtotal) and $row->{$sort} ne $groupvalue ) {
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$groupvalue = $row->{$sort};
for (@total_columns) { $subtotals{$_} = 0 }
}
for (@report_columns) { $tabledata{$_} = qq|<td>$row->{$_}</td>| }
for (@total_columns) { $tabledata{$_} = qq|<td align="right">| . $nf->format_price( $row->{$_}, 2 ) . qq|</td>| }
for (@total_columns) { $totals{$_} += $row->{$_} }
for (@total_columns) { $subtotals{$_} += $row->{$_} }
print qq|<tr class="listrow$i">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$i += 1;
$i %= 2;
}
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $totals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
}
#----------------------------------------
sub revenue_summary {
&report_header('Room Revenue Summary');
my @columns = qw(comp_code company ntn rooms foodbev others salestax bedtax banquettax total);
my @total_columns = qw(rooms foodbev others salestax bedtax banquettax total);
my @search_columns = qw(fromdate todate);
my %sort_positions = {
comp_code => 1,
company => 2,
rooms => 3,
};
my $sort = $q->param('sort') ? $q->param('sort') : 'payment_mode';
my $sortorder = $q->param('sortorder');
my $oldsort = $q->param('oldsort');
$sortorder = ( $sort eq $oldsort ) ? ( $sortorder eq 'asc' ? 'desc' : 'asc' ) : 'asc';
print qq|
<form action="reports.pl" method="post">
From charge date: <input name=fromdate type=text size=12 class="datepicker" value="| . $q->param('fromdate') . qq|"><br/>
To charge date: <input name=todate type=text size=12 class="datepicker" value="| . $q->param('todate') . qq|"><br/>
Include: |;
for (@columns) {
$checked = ( $action eq 'Update' ) ? ( $q->param("l_$_") ? 'checked' : '' ) : 'checked';
print qq|<input type=checkbox name=l_$_ value="1" $checked> | . ucfirst($_);
}
print qq|<br/>
Subtotal: <input type=checkbox name=l_subtotal value="checked" | . $q->param('l_subtotal') . qq|><br/>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my @report_columns;
for (@columns) { push @report_columns, $_ if $q->param("l_$_") }
my $where = ' AND 1 = 1 ';
$where = ' AND 1 = 2 ' if $action ne 'Update'; # Display data only when Update button is pressed.
my @bind = ();
if ( $q->param('fromdate') ) {
$where .= qq| AND ch.charge_date >= ?|;
push @bind, $q->param('fromdate');
}
if ( $q->param('todate') ) {
$where .= qq| AND ch.charge_date <= ?|;
push @bind, $q->param('todate');
}
my $query = qq|
SELECT co.comp_code, co.company, co.ntn,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('ROOM'))
$where
AND ch.comp_code = co.comp_code) rooms,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('F','B'))
$where
AND ch.comp_code = co.comp_code) foodbev,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('O'))
$where
AND ch.comp_code = co.comp_code) others,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('STAX'))
$where
AND ch.comp_code = co.comp_code) salestax,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('BEDTAX'))
$where
AND ch.comp_code = co.comp_code) bedtax,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('BANQTAX'))
$where
AND ch.comp_code = co.comp_code) banquettax,
(SELECT SUM(amount) FROM hc_charges ch
WHERE ch.charge_code IN (SELECT charge_code FROM hc_charge_codes WHERE gl_group IN ('ROOM', 'F', 'B', 'O', 'STAX', 'BEDTAX', 'BANQTAX'))
$where
AND ch.comp_code = co.comp_code) total
FROM hc_companies co
WHERE co.comp_code IN (SELECT DISTINCT comp_code FROM hc_charges ch WHERE 1 = 1 $where)
ORDER BY 1,2
|;
# WHERE $where
# ORDER BY $sort_positions($sort) $sortorder
my @allbinds = ( @bind, @bind, @bind, @bind, @bind, @bind, @bind, @bind );
my @allrows = $dbs->query( $query, @allbinds )->hashes or die( $dbs->error );
my ( %tabledata, %totals, %subtotals );
my $url = "reports.pl?action=$action&nextsub=$nextsub&oldsort=$sort&sortorder=$sortorder&l_subtotal=" . $q->param(l_subtotal);
for (@report_columns) { $url .= "&l_$_=" . $q->param("l_$_") if $q->param("l_$_") }
for (@search_columns) { $url .= "&$_=" . $q->param("$_") if $q->param("$_") }
for (@report_columns) { $tabledata{$_} = qq|<th><a class="listheading" href="$url&sort=$_">| . ucfirst $_ . qq|</a></th>\n| }
print qq|
<table cellpadding="3" cellspacing="2">
<tr class="listheading">
|;
for (@report_columns) { print $tabledata{$_} }
print qq|
</tr>
|;
my $groupvalue;
my $i = 0;
for $row (@allrows) {
$groupvalue = $row->{$sort} if !$groupvalue;
if ( $q->param(l_subtotal) and $row->{$sort} ne $groupvalue ) {
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$groupvalue = $row->{$sort};
for (@total_columns) { $subtotals{$_} = 0 }
}
for (@report_columns) { $tabledata{$_} = qq|<td>$row->{$_}</td>| }
for (@total_columns) { $tabledata{$_} = qq|<td align="right">| . $nf->format_price( $row->{$_}, 2 ) . qq|</td>| }
for (@total_columns) { $totals{$_} += $row->{$_} }
for (@total_columns) { $subtotals{$_} += $row->{$_} }
print qq|<tr class="listrow$i">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$i += 1;
$i %= 2;
}
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $totals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
}
#----------------------------------------
sub lookup1 {
my ( $cname, $default ) = @_;
my @rows = $dbs->query( q|SELECT cval FROM a$lookup WHERE cname = ? ORDER BY seq|, $cname )->hashes;
my $option = qq|<option>\n|;
for $row (@rows) {
if ( $row->{cval} eq $default ) {
$option .= qq|<option value="$row->{cval}" selected>$row->{cval}\n|;
}
else {
$option .= qq|<option value="$row->{cval}">$row->{cval}\n|;
}
}
$option;
}
#----------------------------------------
sub entlist {
&report_header('Officer / Entertainment Report');
my @columns = qw(sale_date chq_num covers type1 type2 table_num food_amt bev_amt sale_amt);
my @total_columns = qw(covers food_amt bev_amt sale_amt);
my @search_columns = qw(fromdate todate);
my %sort_positions = {
sale_date => 1,
chq_num => 2,
covers => 3,
type1 => 4,
type2 => 5,
table_num => 6,
food_amt => 7,
bev_amt => 8,
sale_amt => 9,
};
my $sort = $q->param('sort') ? $q->param('sort') : 'sale_date';
my $sortorder = $q->param('sortorder');
my $oldsort = $q->param('oldsort');
$sortorder = ( $sort eq $oldsort ) ? ( $sortorder eq 'asc' ? 'desc' : 'asc' ) : 'asc';
print qq|
<form action="reports.pl" method="post">
From date: <input name=fromdate type=text size=12 class="datepicker" value="| . $q->param('fromdate') . qq|"><br/>
To date: <input name=todate type=text size=12 class="datepicker" value="| . $q->param('todate') . qq|"><br/>
Chq Type1: <select name="type1">| . lookup1( 'FLAG1', $q->param('type1') ) . qq|</select><br/>
Chq Type2: <select name="type2">| . lookup1( 'FLAG2', $q->param('type2') ) . qq|</select><br/>
Table: <input name=table_num type=text size=15 value="| . $q->param('table_num') . qq|"><br/>
Include: |;
for (@columns) {
$checked = ( $action eq 'Update' ) ? ( $q->param("l_$_") ? 'checked' : '' ) : 'checked';
print qq|<input type=checkbox name=l_$_ value="1" $checked> | . ucfirst($_);
}
print qq|<br/>
Subtotal: <input type=checkbox name=l_subtotal value="checked" | . $q->param('l_subtotal') . qq|><br/>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my @report_columns;
for (@columns) { push @report_columns, $_ if $q->param("l_$_") }
my $where = ' 1 = 1 ';
$where = ' 1 = 2 ' if $action ne 'Update'; # Display data only when Update button is pressed.
my @bind = ();
if ( $q->param('fromdate') ) {
$where .= qq| AND sale_date >= ?|;
push @bind, $q->param('fromdate');
}
if ( $q->param('todate') ) {
$where .= qq| AND sale_date <= ?|;
push @bind, $q->param('todate');
}
if ( $q->param('type1') ) {
$where .= qq| AND flag1 = ?|;
push @bind, $q->param('type1');
}
if ( $q->param('type2') ) {
$where .= qq| AND flag4 = ?|;
push @bind, $q->param('type2');
}
if ( $q->param('table_num') ) {
$where .= qq| AND UPPER(table_num) = ?|;
push @bind, uc $q->param('table_num');
}
my $query = qq|
SELECT sale_date, chq_num, covers,
flag1 type1, flag4 type2, table_num,
fsale_amt food_amt, bsale_amt bev_amt, sale_amt
FROM hc_fb_sale
WHERE $where
AND outlet_id = 'OFF/ENT'
ORDER BY $sort_positions($sort) $sortorder
|;
my @allrows = $dbs->query( $query, @bind )->hashes or die( $dbs->error );
my ( %tabledata, %totals, %subtotals );
my $url = "reports.pl?action=$action&nextsub=$nextsub&oldsort=$sort&sortorder=$sortorder&l_subtotal=" . $q->param(l_subtotal);
for (@report_columns) { $url .= "&l_$_=" . $q->param("l_$_") if $q->param("l_$_") }
for (@search_columns) { $url .= "&$_=" . $q->param("$_") if $q->param("$_") }
for (@report_columns) { $tabledata{$_} = qq|<th><a class="listheading" href="$url&sort=$_">| . ucfirst $_ . qq|</a></th>\n| }
print qq|
<table cellpadding="3" cellspacing="2">
<tr class="listheading">
|;
for (@report_columns) { print $tabledata{$_} }
print qq|
</tr>
|;
my $groupvalue;
my $i = 0;
for $row (@allrows) {
$groupvalue = $row->{$sort} if !$groupvalue;
if ( $q->param(l_subtotal) and $row->{$sort} ne $groupvalue ) {
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$groupvalue = $row->{$sort};
for (@total_columns) { $subtotals{$_} = 0 }
}
for (@report_columns) { $tabledata{$_} = qq|<td>$row->{$_}</td>| }
for (@total_columns) { $tabledata{$_} = qq|<td align="right">| . $nf->format_price( $row->{$_}, 2 ) . qq|</td>| }
for (@total_columns) { $totals{$_} += $row->{$_} }
for (@total_columns) { $subtotals{$_} += $row->{$_} }
print qq|<tr class="listrow$i">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
$i += 1;
$i %= 2;
}
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $totals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listtotal">|;
for (@report_columns) { print $tabledata{$_} }
print qq|</tr>|;
}
#----------------------------------------
sub store_dept_cat_issues {
&report_header('Category wise Issues Summary');
my @columns = qw(store dept item_cat cat_desc net_cost);
my @total_columns = qw(net_cost);
my @search_columns = qw(fromdate todate iss_loc_id rec_loc_id item_cat);
my %sort_positions = {
store => 1,
dept => 2,
item_cat => 3,
cat_desc => 4,
cost_amt => 5,
tax_amt => 6,
net_amt => 7,
};
my $sort = $q->param('sort') ? $q->param('sort') : 'store';
my $sortorder = $q->param('sortorder');
my $oldsort = $q->param('oldsort');
$sortorder = ( $sort eq $oldsort ) ? ( $sortorder eq 'asc' ? 'desc' : 'asc' ) : 'asc';
print qq|
<form action="reports.pl" method="post">
<table>
<tr><th align="right">From date</th><td><input name=fromdate type=text size=12 class="datepicker" value="| . $q->param('fromdate') . qq|"></td></tr>
<tr><th align="right">To date</th><td><input name=todate type=text size=12 class="datepicker" value="| . $q->param('todate') . qq|"></td></tr>
<tr><th align="right">Store</th><td><input name=iss_loc_id type=text size=12 value="| . $q->param('iss_loc_id') . qq|"></td></tr>
<tr><th align="right">Department</th><td><input name=rec_loc_id type=text size=12 value="| . $q->param('rec_loc_id') . qq|"></td></tr>
<tr><th align="right">Category</th><td><input name=item_cat type=text size=12 value="| . $q->param('item_cat') . qq|"></td></tr>
<tr><th align="right">Include</th><td>|;
for (@columns) {
$checked = ( $action eq 'Update' ) ? ( $q->param("l_$_") ? 'checked' : '' ) : 'checked';
print qq|<input type=checkbox name=l_$_ value="1" $checked> | . ucfirst($_);
}
print qq|</td></tr>
<tr><th align="right">Subtotal</th><td><input type=checkbox name=l_subtotal value="checked" | . $q->param('l_subtotal') . qq|></td></tr>
</table>
<hr/>
<input type=hidden name=nextsub value=$nextsub>
<input type=submit name=action class=submit value="Update">
</form>
|;
my @report_columns;
for (@columns) { push @report_columns, $_ if $q->param("l_$_") }
my $where = ' 1 = 1 ';
$where = ' 1 = 2 ' if $action ne 'Update'; # Display data only when Update button is pressed.
my @bind = ();
if ( $q->param('fromdate') ) {
$where .= qq| AND h.tr_date >= ?|;
push @bind, $q->param('fromdate');
}
if ( $q->param('todate') ) {
$where .= qq| AND h.tr_date <= ?|;
push @bind, $q->param('todate');
}
if ( $q->param('iss_loc_id') ) {
$where .= qq| AND h.iss_loc_id LIKE ?|;
push @bind, $q->param('iss_loc_id');
}
if ( $q->param('rec_loc_id') ) {
$where .= qq| AND h.rec_loc_id LIKE ?|;
push @bind, $q->param('rec_loc_id');
}
if ( $q->param('item_cat') ) {
$where .= qq| AND h.item_cat LIKE ?|;
push @bind, $q->param('item_cat');
}
my $query = qq|
SELECT h.iss_loc_id store, h.rec_loc_id dept, c.item_cat, c.cat_desc, SUM(l.net_cost) net_cost
FROM ic_trans_lines_tmp l
JOIN ic_trans_header_tmp h ON (h.tr_num = l.tr_num)
JOIN ic_items i ON (i.item_id = l.item_id)
JOIN ic_items_cats c ON (c.item_cat = i.item_cat)
WHERE $where
AND h.tr_type = 'ISSUE'
GROUP BY h.iss_loc_id, h.rec_loc_id, c.item_cat, c.cat_desc
ORDER BY $sort_positions($sort) $sortorder
|;
my @allrows = $dbs->query( $query, @bind )->hashes or die( $dbs->error );
my ( %tabledata, %totals, %subtotals );
my $url = "reports.pl?action=$action&nextsub=$nextsub&oldsort=$sort&sortorder=$sortorder&l_subtotal=" . $q->param(l_subtotal);
for (@report_columns) { $url .= "&l_$_=" . $q->param("l_$_") if $q->param("l_$_") }
for (@search_columns) { $url .= "&$_=" . $q->param("$_") if $q->param("$_") }
for (@report_columns) { $tabledata{$_} = qq|<th><a class="listheading" href="$url&sort=$_">| . ucfirst $_ . qq|</a></th>\n| }
print qq|
<table cellpadding="3" cellspacing="2">
<tr class="listheading">
|;
for (@report_columns) { print $tabledata{$_} }
print qq|
</tr>
|;
my $groupvalue;
my $i = 0;
for $row (@allrows) {
$groupvalue = $row->{$sort} if !$groupvalue;
if ( $q->param(l_subtotal) and $row->{$sort} ne $groupvalue ) {
for (@report_columns) { $tabledata{$_} = qq|<td> </td>| }
for (@total_columns) { $tabledata{$_} = qq|<th align="right">| . $nf->format_price( $subtotals{$_}, 2 ) . qq|</th>| }
print qq|<tr class="listsubtotal">|;