From 073169e80bea0560b64e468a76121bf837de34f3 Mon Sep 17 00:00:00 2001 From: levinse Date: Sun, 17 Apr 2011 03:27:42 +0000 Subject: [PATCH] bulk DID orders/inventory enhancements, RT11291 --- FS/FS/AccessRight.pm | 1 + FS/FS/did_order.pm | 15 ++++++ httemplate/browse/did_order.html | 59 +++++++++++++++--------- httemplate/misc/did_order_confirmed.html | 21 ++++++++- httemplate/misc/did_order_provision.html | 51 ++++++++++++++++++++ httemplate/search/phone_avail.html | 5 +- httemplate/view/cust_main/packages/services.html | 4 ++ 7 files changed, 133 insertions(+), 23 deletions(-) diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 09ec94825..aa59e7dbd 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -152,6 +152,7 @@ tie my %rights, 'Tie::IxHash', 'Customer service rights' => [ 'View customer services', #NEW 'Provision customer service', + 'Bulk provision customer service', 'Recharge customer service', #NEW 'Unprovision customer service', 'Change customer service', #NEWNEW diff --git a/FS/FS/did_order.pm b/FS/FS/did_order.pm index b138192f8..c1b34c345 100644 --- a/FS/FS/did_order.pm +++ b/FS/FS/did_order.pm @@ -186,6 +186,21 @@ sub cust_main { qsearchs('cust_main', { 'custnum' => $self->custnum } ); } +=item provisioned + +Returns the provisioned DIDs, if any, as phone_avail (see L) objects. + +=cut + +sub provisioned { + my $self = shift; + qsearch({ table => 'phone_avail', + hashref => { 'ordernum' => $self->ordernum, }, + select => 'phone_avail.*', + extra_sql => ' and svcnum is not null ', + }); +} + =back =head1 SEE ALSO diff --git a/httemplate/browse/did_order.html b/httemplate/browse/did_order.html index 363a20108..3da8cb1ba 100644 --- a/httemplate/browse/did_order.html +++ b/httemplate/browse/did_order.html @@ -1,14 +1,10 @@ <% include( 'elements/browse.html', 'title' => 'Bulk DID Orders', - 'html_init' => qq!Add a bulk DID order

!, + 'html_init' => $html_init, 'name' => 'bulk DID orders', 'disableable' => 0, - 'query' => { 'table' => 'did_order', - 'addl_from' => 'left join did_vendor using (vendornum) ', - 'hashref' => {}, - 'order_by' => 'ORDER BY ordernum', - }, - 'count_query' => 'SELECT COUNT(*) FROM did_order', + 'query' => $query, + 'count_query' => 'SELECT COUNT(*) FROM did_order', # XXX: this is wrong!? 'header' => [ '#', 'Vendor',' Vendor Order #', 'Submitted', 'Confirmed', 'Customer', 'Received', 'Provision', 'Cancel', @@ -20,7 +16,7 @@ 'vendorname', 'vendor_order_id', sub { &$display_date(shift->submitted); }, - sub { + sub { # Confirmed my $did_order = shift; my $ordernum = $did_order->ordernum; return &$display_date($did_order->confirmed) @@ -34,28 +30,24 @@ } ) }, - sub { + sub { # Customer my $did_order = shift; my $cust_main = $did_order->cust_main; return "Stock" unless $cust_main; "".$cust_main->name.""; }, - sub { + sub { # Received my $did_order = shift; my $ordernum = $did_order->ordernum; - return &$display_date($did_order->received) - if $did_order->received; - "Upload Received"; + return "Upload Received" + unless $did_order->received; + "" + . &$display_date($did_order->received) . ""; }, - sub { + sub { # Provision my $did_order = shift; my $ordernum = $did_order->ordernum; - my @provisioned = - qsearch({ table => 'phone_avail', - hashref => { 'ordernum' => $ordernum, }, - select => 'phone_avail.*', - extra_sql => ' and svcnum is not null ', - }); + my @provisioned = $did_order->provisioned; return '' unless $did_order->received && $did_order->custnum @@ -69,7 +61,7 @@ } ) }, - sub { + sub { # Cancel my $did_order = shift; return '' unless !$did_order->received; qq!Add a bulk DID order +

!; + +my $query = { + 'table' => 'did_order', + 'hashref' => {}, + 'addl_from' => 'left join did_vendor using (vendornum) ', + 'order_by' => 'ORDER BY ordernum', + }; +$query->{'hashref'}->{'custnum'} = $1 if $cgi->param('custnum') =~ /^(\d+)$/; +if ( $cgi->param('custrcvdunprov') ) { + $query->{'hashref'}->{'received'} = { 'op' => '>', 'value' => '0', }; + $query->{'hashref'}->{'custnum'} = { 'op' => '>', 'value' => '0', }; + $query->{'addl_from'} .= ' left join phone_avail using (ordernum) '; + $query->{'extra_sql'} .= ' and svcnum is null '; + $html_init .= qq!Browse all DID orders!; +} +else { + $html_init .= qq! + Browse all non-stock orders with received unprovisioned DIDs + !; +} + +$html_init .= "

"; + diff --git a/httemplate/misc/did_order_confirmed.html b/httemplate/misc/did_order_confirmed.html index aaded9f58..c0c4795a6 100644 --- a/httemplate/misc/did_order_confirmed.html +++ b/httemplate/misc/did_order_confirmed.html @@ -8,7 +8,7 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); -$cgi->param('action') =~ /^(confirm|cancel)$/ or die 'illegal action'; +$cgi->param('action') =~ /^(confirm|cancel|provision)$/ or die 'illegal action'; my $action = $1; my $success_msg = ''; my $error = ''; @@ -45,4 +45,23 @@ elsif ( $action eq 'cancel' ) { $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; + 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; + } +} + diff --git a/httemplate/misc/did_order_provision.html b/httemplate/misc/did_order_provision.html index b0c7210b7..8241121a8 100644 --- a/httemplate/misc/did_order_provision.html +++ b/httemplate/misc/did_order_provision.html @@ -10,9 +10,34 @@ Order # <% $ordernum %> + + Customer + <% $cust_main->name %> + + Package/Service + +% if ( !$avail ) { + No packages exist for this customer having at least <% scalar(@dids) %> + unprovisioned DIDs, as required for this order. +% } else { + +% } + + +% if ( $avail ) { +% } <%init> @@ -31,5 +56,31 @@ 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 = 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); + +my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } ); +die "no DIDs on order" unless scalar(@dids); + +my (%cust_pkg_phone, %cust_pkg_label, %svc_label ); + +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; +} + +my $avail = keys(%cust_pkg_phone); diff --git a/httemplate/search/phone_avail.html b/httemplate/search/phone_avail.html index 8dec7b247..1335379ae 100644 --- a/httemplate/search/phone_avail.html +++ b/httemplate/search/phone_avail.html @@ -3,7 +3,7 @@ 'name_singular' => 'phone number', 'query' => { 'table' => 'phone_avail', - 'hashref' => {}, + 'hashref' => $hashref, 'select' => join(', ', 'phone_avail.*', 'cust_main.custnum', @@ -129,6 +129,9 @@ my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '. my $count_query = "SELECT COUNT(*) FROM phone_avail $search"; #$addl_from? +my $hashref = {}; +$hashref->{'ordernum'} = $1 if $cgi->param('ordernum') =~ /^(\d+)$/; + my $link_cust = sub { my $phone_avail = shift; if ( $phone_avail->svcnum ) { diff --git a/httemplate/view/cust_main/packages/services.html b/httemplate/view/cust_main/packages/services.html index 1e636ad4e..a5a55521a 100644 --- a/httemplate/view/cust_main/packages/services.html +++ b/httemplate/view/cust_main/packages/services.html @@ -63,6 +63,10 @@ function clearhint_search_cust_svc(obj, str) { <% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %> +% if ( $curuser->access_right('Bulk provision customer service') +% && $part_svc->svcdb eq 'svc_phone' ) { +
Browse Received DID Inventory +% } -- 2.11.0