blob: 89c558cc21bcda170d4e98a710fa6157b7b8a137 (
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
|
<% encode_rest($return) %>\
<%init>
rest_auth($cgi);
my( $custnum, $command ) = split('/', rest_uri_remain($r, $m), 2 );
if ( $r->method eq 'GET' ) {
my $return = [];
if ( $custnum ) {
my $cust_main = qsearchs('cust_main', { 'custnum'=>$custnum } )
or die "unknown custnum $custnum";
if ( $command eq '' ) {
$return = $cust_main->API_getinfo;
} elsif ( $command =~ /^(cust_(pkg|attachment|bill|pay))$/ ) {
my $method = $1;
$return = [ map $_->API_getinfo, $cust_main->$method ];
} elsif ( $command eq 'part_pkg' ) {
my %pkgpart = map { $_->pkgpart => 1 } $cust_main->cust_pkg;
$return = [ map $_->API_getinfo,
map qsearchs('part_pkg', { 'pkgpart'=>$_ }),
keys %pkgpart;
];
}
} else { #list
my %hash = ( map { $_ => scalar($cgi->param($_)) }
qw( agentnum salesnum refnum classnum usernum
referral_custnum
)
);
my $extra_sql = '';
if ( $cgi->param('cust_main_invoice_dest') ) {
my $dest = dbh->quote(scalar($cgi->param('cust_main_invoice_dest')));
$extra_sql = "
WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
WHERE cust_main.custnum = cust_main_invoice.custnum
AND dest = $dest
)
";
} elsif ( $cgi->param('cust_main_invoice_dest_substring') ) {
my $dest = dbh->quote('%'. scalar($cgi->param('cust_main_invoice_dest_substring')). '%');
$extra_sql = "
WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
WHERE cust_main.custnum = cust_main_invoice.custnum
AND dest ILIKE $dest
)
";
}
my @cust_main = qsearch({
'table' => 'cust_main',
'hashref' => \%hash,
'extra_sql' => $extra_sql;
});
$return = [ map $_->API_getinfo, @cust_main ];
}
} elsif ( $r->method eq 'POST' ) { #create new
} elsif ( $r->method eq 'PUT' ) { #modify
}
</%init>
|