summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorlevinse <levinse>2011-06-08 05:38:55 +0000
committerlevinse <levinse>2011-06-08 05:38:55 +0000
commit9a59cc9d51350d7eefb25697cd0d99188f686ea5 (patch)
tree76323a99701f5bd702663b228813c7b1b6a79c3b /httemplate/misc
parentc647fbae23dc64cdecb1c6fa6fee671cca7e8e7a (diff)
DID inventory/import / bulk DID orders - phase 2, RT12754
Diffstat (limited to 'httemplate/misc')
-rw-r--r--httemplate/misc/did_order_confirmed.html81
-rw-r--r--httemplate/misc/did_order_provision.html82
2 files changed, 101 insertions, 62 deletions
diff --git a/httemplate/misc/did_order_confirmed.html b/httemplate/misc/did_order_confirmed.html
index c0c4795a6..3505a1e1d 100644
--- a/httemplate/misc/did_order_confirmed.html
+++ b/httemplate/misc/did_order_confirmed.html
@@ -1,17 +1,19 @@
-<% include('/elements/header-popup.html', $success_msg ) %>
+<% include("/elements/header$popup.html", $header ) %>
+<% include('/elements/error.html') %>
+% unless ( $cgi->param('error') ) {
<SCRIPT TYPE="text/javascript">
<% $js %>
</SCRIPT>
+% }
</BODY>
</HTML>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
-$cgi->param('action') =~ /^(confirm|cancel|provision)$/ or die 'illegal action';
my $action = $1;
-my $success_msg = '';
-my $error = '';
+my $header = '';
+my $popup = '';
my $js = 'window.top.location.reload();';
$cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
@@ -22,9 +24,10 @@ my $did_order = qsearchs( {
} );
die "No order $ordernum" unless $did_order;
+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,34 +37,62 @@ 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' ) {
- my $sucess_msg = 'DID order provisioned';
- $cgi->param('pkgnum_svcpart') =~ /^(\d+)_(\d+)$/ or die 'illegal pkgnum_svcpart';
- my $pkgnum = $1;
- my $svcpart = $2;
+ $header = 'DID order provisioned';
my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } );
die "no DIDs on order" unless scalar(@dids);
- foreach my $did ( @dids ) {
- my $svc_phone = new FS::svc_phone({
- pkgnum => $pkgnum,
- svcpart => $svcpart,
- countrycode => 1,
- phonenum => $did->npa.$did->nxx.$did->station,
- });
- $error = $svc_phone->insert;
- last if $error;
+ 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 ) {
+ # this is our old per-order custnum case
+
+ foreach my $did ( @dids ) {
+ my $svc_phone = new FS::svc_phone({
+ pkgnum => $pkgnum,
+ svcpart => $svcpart,
+ countrycode => 1,
+ phonenum => $did->npa.$did->nxx.$did->station,
+ });
+ $cgi->param('error',$svc_phone->insert);
+ last if $cgi->param('error');
+ }
+ }
+ # XXX: now what do we do for order items? Not clear how to match a DID in an order item
}
+ $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');
+
</%init>
diff --git a/httemplate/misc/did_order_provision.html b/httemplate/misc/did_order_provision.html
index 8241121a8..1df9444ab 100644
--- a/httemplate/misc/did_order_provision.html
+++ b/httemplate/misc/did_order_provision.html
@@ -5,27 +5,33 @@
<FORM NAME="did_order_confirm" ACTION="<% popurl(1) %>did_order_confirmed.html" METHOD=POST>
<INPUT TYPE="hidden" NAME="action" VALUE="provision">
<INPUT TYPE="hidden" NAME="ordernum" VALUE="<% $ordernum %>">
+
+
<TABLE>
- <TR>
- <TD>Order #</TD>
- <TD><% $ordernum %></TD>
+ <TR>
+ <TH COLSPAN="2" ALIGN="LEFT">Order # <% $ordernum %></TH>
+ </TR>
+ <TR>
+ <TH>Customer</TH>
+ <TH>Package/Service</TH>
</TR>
+% my $anyavail = 0;
+% foreach my $cust_main ( @cust_main ) {
+% my($cust_pkg_phone,$cust_pkg_label,$svc_label) = possible_pkgs($cust_main);
+% my $avail = keys(%$cust_pkg_phone);
+% $anyavail = 1 if $avail;
<TR>
- <TD>Customer</TD>
<TD><% $cust_main->name %></TD>
- <TR>
- <TD>Package/Service</TD>
<TD>
% if ( !$avail ) {
- No packages exist for this customer having at least <% scalar(@dids) %>
- unprovisioned DIDs, as required for this order.
+ No suitable packages exist for this customer.
% } else {
- <SELECT NAME="pkgnum_svcpart">
-% foreach my $pkgnum ( keys %cust_pkg_phone ) {
-% my @svcpart = @{$cust_pkg_phone{$pkgnum}};
+ <SELECT NAME="custnum<%$cust_main->custnum%>_pkgnum_svcpart">
+% foreach my $pkgnum ( keys %$cust_pkg_phone ) {
+% my @svcpart = @{$cust_pkg_phone->{$pkgnum}};
% foreach my $svcpart ( @svcpart ) {
<OPTION value="<%"${pkgnum}_$svcpart"%>">
- <% $cust_pkg_label{$pkgnum} %> / <% $svc_label{$svcpart} %>
+ <% $cust_pkg_label->{$pkgnum} %> / <% $svc_label->{$svcpart} %>
</OPTION>
% }
% }
@@ -33,11 +39,10 @@
% }
</TD>
</TR>
-% if ( $avail ) {
- <TR>
- <TD COLSPAN="2"><INPUT TYPE="SUBMIT" value="Provision"></TD>
- </TR>
-% }
+% }
+% if ( $anyavail ) {
+ <TR><TD COLSPAN="2"><INPUT TYPE="SUBMIT" value="Provision"></TD></TR>
+% }
</TABLE>
<%init>
@@ -53,34 +58,37 @@ my $did_order = qsearchs( {
} );
die "No order $ordernum" unless $did_order;
-die "Order is not in received status and/or DIDs not assigned to a customer"
- unless $did_order->received && $did_order->custnum;
+my @cust_main = $did_order->cust_main;
-my $cust_main = qsearchs('cust_main', { custnum => $did_order->custnum } );
-die "invalid customer" unless $cust_main;
-
-my @pkgs = $cust_main->ncancelled_pkgs;
-die "no packages" unless scalar(@pkgs);
+die "Order is not in received status and/or DIDs not assigned to any customers"
+ unless $did_order->received && scalar(@cust_main);
my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } );
die "no DIDs on order" unless scalar(@dids);
-my (%cust_pkg_phone, %cust_pkg_label, %svc_label );
+sub possible_pkgs {
+ my $cust_main = shift;
+
+ my (%cust_pkg_phone, %cust_pkg_label, %svc_label);
+
+ my @pkgs = $cust_main->ncancelled_pkgs;
+ return (\%cust_pkg_phone,\%cust_pkg_label,\%svc_label) unless scalar(@pkgs);
-foreach my $pkg ( @pkgs ) {
- my @avail_part_svc = $pkg->available_part_svc;
- my @svcpart;
- foreach my $avail_part_svc ( @avail_part_svc ) {
- if ($avail_part_svc->svcdb eq 'svc_phone'
- && $avail_part_svc->num_avail >= scalar(@dids)) {
- push @svcpart, $avail_part_svc->svcpart;
- $svc_label{$avail_part_svc->svcpart} = $avail_part_svc->svc;
+ foreach my $pkg ( @pkgs ) {
+ my @avail_part_svc = $pkg->available_part_svc;
+ my @svcpart;
+ foreach my $avail_part_svc ( @avail_part_svc ) {
+ if ($avail_part_svc->svcdb eq 'svc_phone'
+ && $avail_part_svc->num_avail >= scalar(@dids)) {
+ push @svcpart, $avail_part_svc->svcpart;
+ $svc_label{$avail_part_svc->svcpart} = $avail_part_svc->svc;
+ }
}
+ $cust_pkg_phone{$pkg->pkgnum} = \@svcpart if scalar(@svcpart);
+ $cust_pkg_label{$pkg->pkgnum} = $pkg->part_pkg->pkg;
}
- $cust_pkg_phone{$pkg->pkgnum} = \@svcpart if scalar(@svcpart);
- $cust_pkg_label{$pkg->pkgnum} = $pkg->part_pkg->pkg;
+
+ (\%cust_pkg_phone,\%cust_pkg_label,\%svc_label);
}
-my $avail = keys(%cust_pkg_phone);
-
</%init>