X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Fdid_order_confirmed.html;h=3cc121c6fd33f882e8c8d314f66dc5d3c47a3bee;hp=aaded9f5824a91e4c7d06e5c73bdaf9c8ee49660;hb=79c8be3bd0c5db42794b36bf5b5dd25addba67cb;hpb=59be9ba7caf1009a97af97156bbd700bffb18fd4 diff --git a/httemplate/misc/did_order_confirmed.html b/httemplate/misc/did_order_confirmed.html index aaded9f58..3cc121c6f 100644 --- a/httemplate/misc/did_order_confirmed.html +++ b/httemplate/misc/did_order_confirmed.html @@ -1,18 +1,20 @@ -<% include('/elements/header-popup.html', $success_msg ) %> +<% include("/elements/header$popup.html", $header ) %> +<% include('/elements/error.html') %> +% unless ( $cgi->param('error') ) { +% } <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); -$cgi->param('action') =~ /^(confirm|cancel)$/ or die 'illegal action'; my $action = $1; -my $success_msg = ''; -my $error = ''; -my $js = 'window.top.location.reload();'; +my $header = ''; +my $popup = ''; +my $js = 'topreload();'; $cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum'; my $ordernum = $1; @@ -22,9 +24,21 @@ my $did_order = qsearchs( { } ); die "No order $ordernum" unless $did_order; +sub didprov { + my($pkgnum,$svcpart,$phonenum) = (shift,shift,shift); + my $svc_phone = new FS::svc_phone({ + pkgnum => $pkgnum, + svcpart => $svcpart, + countrycode => 1, + phonenum => $phonenum, + }); + $cgi->param('error',$svc_phone->insert); +} + +my $action = $cgi->param('action'); if ( $action eq 'confirm' ) { my $confirmed = ''; - my $sucess_msg = 'DID order confirmed'; + $header = 'DID order confirmed'; $confirmed = parse_datetime($cgi->param('confirmed')) if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/; $confirmed = $1 @@ -34,15 +48,89 @@ if ( $action eq 'confirm' ) { $did_order->confirmed($confirmed); $did_order->vendor_order_id($cgi->param('vendor_order_id')); - $error = $did_order->replace; - if ( $error ) { - $cgi->param('error', $error); - print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string ); - } + $cgi->param('error',$did_order->replace); + print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string ) + if $cgi->param('error'); + $popup = '-popup'; } elsif ( $action eq 'cancel' ) { - my $sucess_msg = 'DID order cancelled'; - $error = $did_order->delete; + $header = 'DID order cancelled'; + $cgi->param('error',$did_order->delete); $js = "window.location.href = '${p}browse/did_order.html'"; } +elsif ( $action eq 'provision' ) { + # XXX: most of this should move into did_order.pm and become transaction-enabled + + $header = 'DID order provisioned'; + my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } ); + die "no DIDs on order" unless scalar(@dids); + my @params = $cgi->param; + foreach my $param ( @params ) { + next unless $param =~ /^custnum(\d+)_pkgnum_svcpart$/; + my $custnum = $1; + my $value = $cgi->param($param); + next unless $value =~ /^(\d+)_(\d+)$/; + my $pkgnum = $1; + my $svcpart = $2; + if ( $did_order->custnum && $did_order->custnum == $custnum ) { + # per-order custnum case + + foreach my $did ( @dids ) { + didprov($pkgnum,$svcpart,$did->npa.$did->nxx.$did->station); + last if $cgi->param('error'); + } + } + elsif(!$did_order->custnum) { # multi-customer/stock case + + # get each order item for this customer for this order + my @did_order_item = qsearch('did_order_item', { + 'ordernum' => $ordernum, + 'custnum' => $custnum, + }); + foreach my $did_order_item ( @did_order_item ) { + # get imported unprovisioned DIDs for this order matching this order item + my $didsearch = { 'ordernum' => $ordernum, + 'svcnum' => '', + }; + $didsearch->{'npa'} = $did_order_item->npa + if $did_order_item->npa; + $didsearch->{'state'} = $did_order_item->state + if $did_order_item->state; + $didsearch->{'name'} = $did_order_item->rate_center->description + if $did_order_item->rate_center; + $didsearch->{'msanum'} = $did_order_item->msanum + if $did_order_item->msanum; + $didsearch->{'latanum'} = $did_order_item->latanum + if $did_order_item->latanum; + @dids = qsearch('phone_avail', $didsearch); + my $limit = $did_order_item->quantity; + foreach my $did ( @dids ) { + didprov($pkgnum,$svcpart,$did->npa.$did->nxx.$did->station); + $limit--; + last if $cgi->param('error') || $limit == 0; + } + last if $cgi->param('error'); + } + } + } + $popup = '-popup'; +} +elsif ( $action eq 'merge' ) { + $header = 'DID order merged'; + $cgi->param('target_ordernum') =~ /^(\d+)$/ or die 'illegal target_ordernum'; + my $target_ordernum = $1; + my $target_did_order = qsearchs( { + 'table' => 'did_order', + 'hashref' => { 'ordernum' => $target_ordernum }, + } ); + die "No order $target_ordernum" unless $target_did_order; + $cgi->param('error',$target_did_order->merge($did_order)); + $js = "window.location.href = '${p}browse/did_order.html'"; +} +else { + die "illegal action"; +} + +$header = 'Error' if $cgi->param('error'); +