1 <% encode_rest($return) %>\
6 my( $custnum, $command ) = split('/', rest_uri_remain($r, $m), 2 );
8 if ( $r->method eq 'GET' ) {
14 my $cust_main = qsearchs('cust_main', { 'custnum'=>$custnum } )
15 or die "unknown custnum $custnum";
17 if ( $command eq '' ) {
19 $return = $cust_main->API_getinfo;
21 } elsif ( $command =~ /^(cust_(pkg|attachment|bill|pay))$/ ) {
25 $return = [ map $_->API_getinfo, $cust_main->$method ];
27 } elsif ( $command eq 'part_pkg' ) {
29 my %pkgpart = map { $_->pkgpart => 1 } $cust_main->cust_pkg;
31 $return = [ map $_->API_getinfo,
32 map qsearchs('part_pkg', { 'pkgpart'=>$_ }),
40 my %hash = ( map { $_ => scalar($cgi->param($_)) }
41 qw( agentnum salesnum refnum classnum usernum
47 if ( $cgi->param('cust_main_invoice_dest') ) {
48 my $dest = dbh->quote(scalar($cgi->param('cust_main_invoice_dest')));
50 WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
51 WHERE cust_main.custnum = cust_main_invoice.custnum
55 } elsif ( $cgi->param('cust_main_invoice_dest_substring') ) {
56 my $dest = dbh->quote('%'. scalar($cgi->param('cust_main_invoice_dest_substring')). '%');
58 WHERE EXISTS ( SELECT 1 FROM cust_main_invoice
59 WHERE cust_main.custnum = cust_main_invoice.custnum
65 my @cust_main = qsearch({
66 'table' => 'cust_main',
68 'extra_sql' => $extra_sql;
71 $return = [ map $_->API_getinfo, @cust_main ];
75 } elsif ( $r->method eq 'POST' ) { #create new
77 if ( !$custnum && $command eq '' ) {
79 my @param = grep { $_ ne 'secret' } $cgi->param;
81 $return = FS::cust_main->API_insert(
82 map { $_ => scalar($cgi->param($_)) } @param
84 # agentnum refnum agent_custid referral_custnum
85 # last first company daytime night fax mobile
86 # invoicing_list postal_invoicing
87 # payby payinfo paydate paycvv payname
89 # address1 address2 city county state zip country
90 # ship_company ship_address1 ship_address2 ship_city ship_county
91 # ship_state ship_zip ship_country
95 if ( $return->{error} ) {
96 #XXX RESTful error handline
98 } elsif ( $return->{custnum} ) {
99 # Return a 201 Status code and the newly created id
100 my $custnum = $return->{custnum};
101 #$r->headers_out('Location' => );
103 $m->redirect( $r->uri."/$custnum", 201);
105 #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?)
106 die 'guru meditation #159';
109 } elsif ( $custnum && $command eq 'cust_pkg' ) {
111 #XXX this needs to order a package, not just insert a record :/
113 # #XXX does this need to do anything special? what's a "wallet payment"?
114 # } elsif ( $custnum && $command eq 'cust_pay' ) {
116 } elsif ( $custnum && $command =~ /^(cust_(attachment|pay))$/ ) {
119 my $class = 'FS::'.$table;
121 my @param = grep { $_ ne 'secret' } $cgi->param;
124 $class->API_insert( 'custnum' => $custnum,
125 map { $_ => scalar($cgi->param($_)) } @param
128 my $pkey = FS::Record->dbdef_table->$table->primary_key;
130 if ( $return->{error} ) {
131 #XXX RESTful error handline
132 die $return->{error};
133 } elsif ( $return->{$pkey} ) {
134 # Return a 201 Status code and the newly created id
135 my $pkey_value = $return->{$pkey};
136 #$r->headers_out('Location' => );
138 $m->redirect( $r->uri."/$pkey_value", 201);
140 #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?)
141 die 'guru meditation #160';
146 } elsif ( $r->method eq 'PUT' ) { #modify