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_contact
51 JOIN contact USING (contactnum)
52 JOIN contact_email USING (contactnum)
53 WHERE cust_main.custnum = cust_contact.custnum
54 AND cust_contact.invoice_dest = 'Y'
55 AND contact_email.emailaddress = $dest
58 } elsif ( $cgi->param('cust_main_invoice_dest_substring') ) {
59 my $dest = dbh->quote('%'. scalar($cgi->param('cust_main_invoice_dest_substring')). '%');
61 WHERE EXISTS ( SELECT 1 FROM cust_contact
62 JOIN contact USING (contactnum)
63 JOIN contact_email USING (contactnum)
64 WHERE cust_main.custnum = cust_contact.custnum
65 AND cust_contact.invoice_dest = 'Y'
66 AND contact_email.emailaddress ILIKE $dest
71 my @cust_main = qsearch({
72 'table' => 'cust_main',
74 'extra_sql' => $extra_sql;
77 $return = [ map $_->API_getinfo, @cust_main ];
81 } elsif ( $r->method eq 'POST' ) { #create new
83 if ( !$custnum && $command eq '' ) {
85 my @param = grep { $_ ne 'secret' } $cgi->param;
87 $return = FS::cust_main->API_insert(
88 map { $_ => scalar($cgi->param($_)) } @param
90 # agentnum refnum agent_custid referral_custnum
91 # last first company daytime night fax mobile
92 # invoicing_list postal_invoicing
93 # payby payinfo paydate paycvv payname
95 # address1 address2 city county state zip country
96 # ship_company ship_address1 ship_address2 ship_city ship_county
97 # ship_state ship_zip ship_country
101 if ( $return->{error} ) {
102 #XXX RESTful error handline
103 die $return->{error};
104 } elsif ( $return->{custnum} ) {
105 # Return a 201 Status code and the newly created id
106 my $custnum = $return->{custnum};
107 #$r->headers_out('Location' => );
109 $m->redirect( $r->uri."/$custnum", 201);
111 #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?)
112 die 'guru meditation #159';
115 } elsif ( $custnum && $command eq 'cust_pkg' ) {
117 #XXX this needs to order a package, not just insert a record :/
119 # #XXX does this need to do anything special? what's a "wallet payment"?
120 # } elsif ( $custnum && $command eq 'cust_pay' ) {
122 } elsif ( $custnum && $command =~ /^(cust_(attachment|pay))$/ ) {
125 my $class = 'FS::'.$table;
127 my @param = grep { $_ ne 'secret' } $cgi->param;
130 $class->API_insert( 'custnum' => $custnum,
131 map { $_ => scalar($cgi->param($_)) } @param
134 my $pkey = FS::Record->dbdef_table->$table->primary_key;
136 if ( $return->{error} ) {
137 #XXX RESTful error handline
138 die $return->{error};
139 } elsif ( $return->{$pkey} ) {
140 # Return a 201 Status code and the newly created id
141 my $pkey_value = $return->{$pkey};
142 #$r->headers_out('Location' => );
144 $m->redirect( $r->uri."/$pkey_value", 201);
146 #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?)
147 die 'guru meditation #160';
152 } elsif ( $r->method eq 'PUT' ) { #modify