--- /dev/null
+<% 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>