X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2FREST%2F1.0%2Fcust_main;h=a8b1511d9f9b852d5c5ca6e819857a3ff2d32ceb;hb=571291dda91dd92db80660aa3d67333b0c88fc34;hp=89c558cc21bcda170d4e98a710fa6157b7b8a137;hpb=7943c96636596806b9fc99195c23b166728280c8;p=freeside.git diff --git a/httemplate/REST/1.0/cust_main b/httemplate/REST/1.0/cust_main index 89c558cc2..a8b1511d9 100644 --- a/httemplate/REST/1.0/cust_main +++ b/httemplate/REST/1.0/cust_main @@ -47,17 +47,23 @@ if ( $r->method eq 'GET' ) { 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 + WHERE EXISTS ( SELECT 1 FROM cust_contact + JOIN contact USING (contactnum) + JOIN contact_email USING (contactnum) + WHERE cust_main.custnum = cust_contact.custnum + AND cust_contact.invoice_dest = 'Y' + AND contact_email.emailaddress = $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 + WHERE EXISTS ( SELECT 1 FROM cust_contact + JOIN contact USING (contactnum) + JOIN contact_email USING (contactnum) + WHERE cust_main.custnum = cust_contact.custnum + AND cust_contact.invoice_dest = 'Y' + AND contact_email.emailaddress ILIKE $dest ) "; } @@ -74,6 +80,75 @@ if ( $r->method eq 'GET' ) { } elsif ( $r->method eq 'POST' ) { #create new + if ( !$custnum && $command eq '' ) { + + my @param = grep { $_ ne 'secret' } $cgi->param; + + $return = FS::cust_main->API_insert( + map { $_ => scalar($cgi->param($_)) } @param + #qw( + # agentnum refnum agent_custid referral_custnum + # last first company daytime night fax mobile + # invoicing_list postal_invoicing + # payby payinfo paydate paycvv payname + + # address1 address2 city county state zip country + # ship_company ship_address1 ship_address2 ship_city ship_county + # ship_state ship_zip ship_country + #) + ); + + if ( $return->{error} ) { + #XXX RESTful error handline + die $return->{error}; + } elsif ( $return->{custnum} ) { + # Return a 201 Status code and the newly created id + my $custnum = $return->{custnum}; + #$r->headers_out('Location' => ); + #$m->abort(201); + $m->redirect( $r->uri."/$custnum", 201); + } else { + #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?) + die 'guru meditation #159'; + } + + } elsif ( $custnum && $command eq 'cust_pkg' ) { + + #XXX this needs to order a package, not just insert a record :/ + + # #XXX does this need to do anything special? what's a "wallet payment"? + # } elsif ( $custnum && $command eq 'cust_pay' ) { + + } elsif ( $custnum && $command =~ /^(cust_(attachment|pay))$/ ) { + + my $table = $1; + my $class = 'FS::'.$table; + + my @param = grep { $_ ne 'secret' } $cgi->param; + + my $return = + $class->API_insert( 'custnum' => $custnum, + map { $_ => scalar($cgi->param($_)) } @param + ); + + my $pkey = FS::Record->dbdef_table->$table->primary_key; + + if ( $return->{error} ) { + #XXX RESTful error handline + die $return->{error}; + } elsif ( $return->{$pkey} ) { + # Return a 201 Status code and the newly created id + my $pkey_value = $return->{$pkey}; + #$r->headers_out('Location' => ); + #$m->abort(201); + $m->redirect( $r->uri."/$pkey_value", 201); + } else { + #XXX RESTful exception handling (cust_main->API_insert didn't even behave like we expect!?) + die 'guru meditation #160'; + } + + } + } elsif ( $r->method eq 'PUT' ) { #modify }