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
|
<%
my $sortby;
my @cust_pay;
if ( $cgi->param('magic') && $cgi->param('magic') eq '_date' ) {
my %search;
if ( $cgi->param('payby') ) {
$cgi->param('payby') =~ /^(CARD|CHEK|BILL)$/
or die "illegal payby ". $cgi->param('payby');
$search{'payby'} = $1;
}
#false laziness with cust_pkg.cgi
my $range = '';
if ( $cgi->param('beginning')
&& $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
my $beginning = str2time($1);
$range = " WHERE _date >= $beginning ";
}
if ( $cgi->param('ending')
&& $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
my $ending = str2time($1) + 86400;
$range .= ( $range ? ' AND ' : ' WHERE ' ). " _date <= $ending ";
}
$range =~ s/^\s*WHERE/ AND/ if scalar(keys %search) ;
@cust_pay = qsearch('cust_pay', \%search, '', $range );
$sortby = \*date_sort;
} else {
$cgi->param('payinfo') =~ /^\s*(\d+)\s*$/ or die "illegal payinfo";
my $payinfo = $1;
$cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
my $payby = $1;
@cust_pay = qsearch('cust_pay', { 'payinfo' => $payinfo,
'payby' => $payby } );
$sortby = \*date_sort;
}
if (0) {
#if ( scalar(@cust_pay) == 1 ) {
# my $invnum = $cust_bill[0]->invnum;
# print $cgi->redirect(popurl(2). "view/cust_bill.cgi?$invnum"); #redirect
} elsif ( scalar(@cust_pay) == 0 ) {
%>
<!-- mason kludge -->
<%
idiot("Payment not found.");
#exit;
} else {
my $total = scalar(@cust_pay);
my $s = $total > 1 ? 's' : '';
%>
<!-- mason kludge -->
<%
print header("Payment Search Results", menubar(
'Main Menu', popurl(2)
)), "$total matching payment$s found<BR>", &table(), <<END;
<TR>
<TH></TH>
<TH>Amount</TH>
<TH>Date</TH>
<TH>Contact name</TH>
<TH>Company</TH>
</TR>
END
my(%saw, $cust_pay);
foreach my $cust_pay (
sort $sortby grep(!$saw{$_->paynum}++, @cust_pay)
) {
my($paynum, $custnum, $payby, $payinfo, $amount, $date ) = (
$cust_pay->paynum,
$cust_pay->custnum,
$cust_pay->payby,
$cust_pay->payinfo,
sprintf("%.2f", $cust_pay->paid),
$cust_pay->_date,
);
my $pdate = time2str("%b %d %Y", $date);
my $rowspan = 1;
my $view = popurl(2). "view/cust_main.cgi?". $custnum.
"#". $payby. $payinfo;
my $payment_info;
if ( $payby eq 'CARD' ) {
$payment_info = 'Card #'. 'x'x(length($payinfo)-4).
substr($payinfo,(length($payinfo)-4));
} elsif ( $payby eq 'CHEK' ) {
$payment_info = "E-check acct#$payinfo";
} elsif ( $payby eq 'BILL' ) {
$payment_info = "Check #$payinfo";
} else {
$payment_info = "$payby $payinfo";
}
print <<END;
<TR>
<TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$payment_info</FONT></A></TD>
<TD ROWSPAN=$rowspan ALIGN="right"><A HREF="$view"><FONT SIZE=-1>\$$amount</FONT></A></TD>
<TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$pdate</FONT></A></TD>
END
my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
if ( $cust_main ) {
#my $cview = popurl(2). "view/cust_main.cgi?". $cust_main->custnum;
my ( $name, $company ) = (
$cust_main->last. ', '. $cust_main->first,
$cust_main->company,
);
print <<END;
<TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$name</FONT></A></TD>
<TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$company</FONT></A></TD>
END
} else {
print <<END
<TD ROWSPAN=$rowspan COLSPAN=2>WARNING: couldn't find cust_main.custnum $custnum (cust_pay.paynum $paynum)</TD>
END
}
print "</TR>";
}
print <<END;
</TABLE>
</BODY>
</HTML>
END
}
#
#sub invnum_sort {
# $a->invnum <=> $b->invnum;
#}
#
#sub custnum_sort {
# $a->custnum <=> $b->custnum || $a->invnum <=> $b->invnum;
#}
sub date_sort {
$a->_date <=> $b->_date || $a->invnum <=> $b->invnum;
}
%>
|