summaryrefslogtreecommitdiff
path: root/httemplate/REST/1.0/cust_main
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-07-16 06:17:05 -0700
committerIvan Kohler <ivan@freeside.biz>2014-07-16 06:17:05 -0700
commit5f8111de04a4a914c72a1642722476db4728339c (patch)
treeb7ae766bcb35d53828a1690ae78d9bff179dcbab /httemplate/REST/1.0/cust_main
parentc7cc0522832d0e1c056f9bce46dd1b4b5551e612 (diff)
REST API, RT#28181
Diffstat (limited to 'httemplate/REST/1.0/cust_main')
-rw-r--r--httemplate/REST/1.0/cust_main81
1 files changed, 81 insertions, 0 deletions
diff --git a/httemplate/REST/1.0/cust_main b/httemplate/REST/1.0/cust_main
new file mode 100644
index 000000000..89c558cc2
--- /dev/null
+++ b/httemplate/REST/1.0/cust_main
@@ -0,0 +1,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>