summaryrefslogtreecommitdiff
path: root/httemplate/search/cust_pay.cgi
blob: b5bdf82967771cacd7eb4e1e10463410adc4035d (plain)
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
<%

$cgi->param('payinfo') =~ /^\s*(\d+)\s*$/ or die "illegal payinfo";
my $payinfo = $1;
$cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
my $payby = $1;
my @cust_pay = qsearch('cust_pay', { 'payinfo' => $payinfo,
                                     'payby'   => $payby    } );
my $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("Check # not found.");
  #exit;
} else {
  my $total = scalar(@cust_pay);
  my $s = $total > 1 ? 's' : '';
%>
<!-- mason kludge -->
<%
  print header("Check # Search Results", menubar(
          'Main Menu', popurl(2)
        )), "$total matching check$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, $payinfo, $amount, $date ) = (
      $cust_pay->paynum,
      $cust_pay->custnum,
      $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;

    print <<END;
      <TR>
        <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$payinfo</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;
}
%>