X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fbrowse%2Fdid_order.html;h=f328c1fccb97513c5ca4dc195e787545182a4629;hp=363a20108bc3979894eba19a27009117c35f4270;hb=877a4eb85cb847bd314d6a9192fedb1dc35c5d02;hpb=59be9ba7caf1009a97af97156bbd700bffb18fd4 diff --git a/httemplate/browse/did_order.html b/httemplate/browse/did_order.html index 363a20108..f328c1fcc 100644 --- a/httemplate/browse/did_order.html +++ b/httemplate/browse/did_order.html @@ -1,17 +1,13 @@ <% 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', + 'Received', 'Provision', 'Cancel', 'Merge Into', ], 'fields' => [ sub { my $did_order = shift; @@ -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,48 +30,59 @@ } ) }, - sub { + sub { # Customer my $did_order = shift; - my $cust_main = $did_order->cust_main; - return "Stock" unless $cust_main; - "".$cust_main->name.""; + my @cust_main = $did_order->cust_main; + my $has_stock = $did_order->has_stock; + if (scalar(@cust_main) == 1 && !$has_stock) { + my $cust_main = $cust_main[0]; + return "".$cust_main->name."" + } + elsif(scalar(@cust_main) == 0 && $has_stock) { + return 'Stock'; + } + elsif(scalar(@cust_main) > 0 && !$has_stock) { + return 'Multiple'; + } + 'Multiple/Stock'; }, - 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 + && scalar($did_order->cust_main) && !scalar(@provisioned); include( '/elements/popup_link.html', { 'action' => "${p}misc/did_order_provision.html?ordernum=".$did_order->ordernum, - 'label' => 'Provision All DIDs', + 'label' => 'Provision DIDs', 'actionlabel' => 'Bulk DID order - DID provisioning', 'width' => 520, 'height' => 300, } ) }, - sub { + sub { # Cancel my $did_order = shift; return '' unless !$did_order->received; qq!Cancel! }, + sub { # Merge + my $did_order = shift; + return '' unless !$did_order->received; + &$merge_select($did_order->ordernum); + }, ], 'links' => [ [ $p.'edit/did_order.html?', 'ordernum' ], @@ -86,6 +93,12 @@ if (confirm(msg)) window.location.href = href; } + + function mergeconfirm(select,source_ordernum) { + var target_ordernum = select.options[select.selectedIndex].value; + areyousure("'.$p.'misc/did_order_confirmed.html?action=merge;ordernum="+source_ordernum+";target_ordernum="+target_ordernum, + "Merge order #" + source_ordernum + " into order #" + target_ordernum + "?"); + } ', ) @@ -98,6 +111,56 @@ die "access denied" my $conf = new FS::Conf; my $date_format = $conf->config('date_format') || '%m/%d/%Y'; +my $html_init = 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', + }; +if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { + $query->{'extra_sql'} .= " where (custnum = $1 or $1 in (select distinct " + . " custnum from did_order_item where " + . " did_order_item.ordernum = did_order.ordernum ) )"; +} +if ( $cgi->param('custrcvdunprov') ) { + $query->{'hashref'}->{'received'} = { 'op' => '>', 'value' => '0', }; + $query->{'hashref'}->{'svcnum'} = ''; + $query->{'addl_from'} .= ' left join phone_avail using (ordernum) '; + $query->{'extra_sql'} .= " and (custnum > 0 or 0 < (select count(1) from " + . " did_order_item where did_order_item.custnum > 0 and " + . " did_order_item.ordernum = did_order.ordernum) )"; + $html_init .= qq!Browse all DID orders!; +} +else { + $html_init .= qq! + Browse all non-stock orders with received unprovisioned DIDs + !; +} +$html_init .= "

"; + +my @merge_targets = qsearch({ + 'table' => 'did_order', + 'hashref' => { 'received' => '' }, + 'order_by' => 'ORDER BY ordernum', + }); + +my $merge_select = sub { + my $source_ordernum = shift; + my $merge_select = ''; + my @targets = grep { $_->ordernum != $source_ordernum } @merge_targets; + if ( @targets ) { + $merge_select = ""; + } + $merge_select; +}; + my $display_date = sub { my $date = shift; return '' unless $date;