FS/FS/msa.pm
authorlevinse <levinse>
Fri, 15 Apr 2011 03:04:13 +0000 (03:04 +0000)
committerlevinse <levinse>
Fri, 15 Apr 2011 03:04:13 +0000 (03:04 +0000)
14 files changed:
FS/FS/Schema.pm
FS/FS/did_order.pm
FS/FS/did_order_item.pm
FS/FS/rate_center.pm [new file with mode: 0644]
FS/bin/freeside-msa-import [new file with mode: 0755]
FS/t/msa.t [new file with mode: 0644]
FS/t/rate_center.t [new file with mode: 0644]
httemplate/browse/did_order.html
httemplate/edit/did_order.html
httemplate/edit/process/did_order.html
httemplate/elements/did_order_item.html
httemplate/misc/did_order_confirm.html
httemplate/misc/did_order_confirmed.html
httemplate/misc/did_order_provision.html [new file with mode: 0644]

index c9775fc..37660f2 100644 (file)
@@ -3125,6 +3125,26 @@ sub tables_hashref {
       'index'  => [],
     },
     
+    'msa' => {
+      'columns' => [
+        'msanum',    'int',      '',      '', '', '', 
+        'description',   'varchar',    '',      $char_d, '', '', 
+      ],
+      'primary_key' => 'msanum',
+      'unique' => [],
+      'index'  => [],
+    },
+    
+    'rate_center' => {
+      'columns' => [
+        'ratecenternum',    'serial',      '',      '', '', '', 
+        'description',   'varchar',    '',      $char_d, '', '', 
+      ],
+      'primary_key' => 'ratecenternum',
+      'unique' => [],
+      'index'  => [],
+    },
+
     'did_vendor' => {
       'columns' => [
         'vendornum',    'serial',      '',      '', '', '', 
@@ -3139,10 +3159,10 @@ sub tables_hashref {
       'columns' => [
         'orderitemnum',    'serial',      '',      '', '', '', 
         'ordernum',    'int',      '',      '', '', '', 
-        'msa',        'varchar', 'NULL', $char_d, '', '',
+        'msanum',      'int',     'NULL',      '', '', '',
         'npa',      'int',     'NULL',      '', '', '',
         'latanum',      'int',     'NULL',      '', '', '',
-        'ratecenter',        'varchar', 'NULL', $char_d, '', '',
+        'ratecenternum',      'int',     'NULL',      '', '', '',
         'state',       'char',    'NULL',       2, '', '', 
         'quantity',      'int',     '',      '', '', '',
       ],
index adc965f..b138192 100644 (file)
@@ -2,7 +2,7 @@ package FS::did_order;
 
 use strict;
 use base qw( FS::o2m_Common FS::Record );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearch qsearchs dbh );
 
 =head1 NAME
 
@@ -89,7 +89,43 @@ Delete this record from the database.
 
 =cut
 
-# the delete method can be inherited from FS::Record
+sub delete {
+  my $self = shift;
+
+  return "Can't delete a DID order which has DIDs received"
+    if qsearch( 'phone_avail', { 'ordernum' => $self->ordernum } );
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  my @did_order_item = $self->did_order_item;
+
+  foreach my $did_order_item ( @did_order_item ) {
+    my $error = $did_order_item->delete;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return "can't delete DID order item "
+                                . $did_order_item->orderitemnum . ": $error";
+    }
+  }
+
+  my $error = $self->SUPER::delete(@_);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+}
+
 
 =item replace OLD_RECORD
 
index 4408c50..c2d657a 100644 (file)
@@ -37,33 +37,18 @@ primary key
 
 =item ordernum
 
-ordernum
-
-=item msa
-
-msa
+=item msanum - foreign key to msa table
 
 =item npa
 
-npa
-
-=item latanum
-
-latanum
+=item latanum - foreign key to lata table
 
-=item rate_center
-
-rate_center
+=item ratecenternum - foreign key to rate_center table
 
 =item state
 
-state
-
 =item quantity
 
-quantity
-
-
 =back
 
 =head1 METHODS
@@ -126,10 +111,10 @@ sub check {
   my $error = 
     $self->ut_numbern('orderitemnum')
     || $self->ut_number('ordernum')
-    || $self->ut_textn('msa')
+    || $self->ut_foreign_keyn('msanum', 'msa', 'msanum')
     || $self->ut_numbern('npa')
     || $self->ut_foreign_keyn('latanum', 'lata', 'latanum')
-    || $self->ut_textn('rate_center')
+    || $self->ut_foreign_keyn('ratecenternum', 'rate_center', 'ratecenternum')
     || $self->ut_textn('state')
     || $self->ut_number('quantity')
   ;
diff --git a/FS/FS/rate_center.pm b/FS/FS/rate_center.pm
new file mode 100644 (file)
index 0000000..d566b63
--- /dev/null
@@ -0,0 +1,119 @@
+package FS::rate_center;
+
+use strict;
+use base qw( FS::Record );
+use FS::Record qw( qsearch qsearchs );
+
+=head1 NAME
+
+FS::rate_center - Object methods for rate_center records
+
+=head1 SYNOPSIS
+
+  use FS::rate_center;
+
+  $record = new FS::rate_center \%hash;
+  $record = new FS::rate_center { 'column' => 'value' };
+
+  $error = $record->insert;
+
+  $error = $new_record->replace($old_record);
+
+  $error = $record->delete;
+
+  $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::rate_center object represents an rate center.  FS::rate_center inherits from
+FS::Record.  The following fields are currently supported:
+
+=over 4
+
+=item ratecenternum
+
+primary key
+
+=item description
+
+description
+
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new rate center.  To add the rate center to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to.  You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'rate_center'; }
+
+=item insert
+
+Adds this record to the database.  If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+# the insert method can be inherited from FS::Record
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database.  If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid rate center.  If there is
+an error, returns the error, otherwise returns false.  Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+  my $self = shift;
+
+  my $error = 
+    $self->ut_numbern('ratecenternum')
+    || $self->ut_text('description')
+  ;
+  return $error if $error;
+
+  $self->SUPER::check;
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
diff --git a/FS/bin/freeside-msa-import b/FS/bin/freeside-msa-import
new file mode 100755 (executable)
index 0000000..ade3efa
--- /dev/null
@@ -0,0 +1,74 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Getopt::Std;
+use FS::UID qw(adminsuidsetup);
+use FS::Conf;
+use FS::Record qw(qsearch qsearchs dbh);
+use LWP::Simple;
+use Data::Dumper;
+
+&untaint_argv; #what it sounds like  (eww)
+use vars qw(%opt);
+
+my $user = shift or die &usage;
+my $dbh = adminsuidsetup $user;
+
+my $content = get("http://www.census.gov/population/www/metroareas/lists/2009/List1.txt");
+my @content = split(/\n/,$content);
+
+my $sql = 'insert into msa (msanum, description) values ';
+my @sql;
+foreach my $row ( @content ) {
+    next unless $row =~ /^([0-9]{5})\s+([A-Za-z, \-]{5,80}) .{3}ropolitan Statistical Area/;
+    push @sql, "( $1, '$2')";
+}
+$sql .= join(',',@sql);
+
+my $sth = $dbh->prepare('delete from msa');
+$sth->execute or die $sth->errstr;
+
+$sth = $dbh->prepare($sql);
+$sth->execute or die $sth->errstr;
+
+$dbh->commit;
+
+###
+# subroutines
+###
+
+sub untaint_argv {
+  foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+    #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    # Date::Parse
+    $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    $ARGV[$_]=$1;
+  }
+}
+
+sub usage {
+  die "Usage:\n  freeside-msa-import user \n";
+}
+
+###
+# documentation
+###
+
+=head1 NAME
+
+freeside-msa-import - Pull MSA data from census.gov and insert into MSA table
+
+=head1 SYNOPSIS
+
+  freeside-msa-import user
+
+=head1 DESCRIPTION
+
+user - name of an internal Freeside user
+
+=head1 SEE ALSO
+
+L<FS::msa>
+
+=cut
+
diff --git a/FS/t/msa.t b/FS/t/msa.t
new file mode 100644 (file)
index 0000000..84b6033
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::msa;
+$loaded=1;
+print "ok 1\n";
diff --git a/FS/t/rate_center.t b/FS/t/rate_center.t
new file mode 100644 (file)
index 0000000..8b272d4
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::rate_center;
+$loaded=1;
+print "ok 1\n";
index 570b784..363a201 100644 (file)
@@ -1,19 +1,93 @@
 <% include( 'elements/browse.html',
                  'title'       => 'Bulk DID Orders',
-                 'html_init'   => $html_init,
+                 'html_init'   => qq!<A HREF="${p}edit/did_order.html"><I>Add a bulk DID order</I></A><BR><BR>!,
                  'name'        => 'bulk DID orders',
                  'disableable' => 0,
                  'query'       => { 'table'     => 'did_order',
-                                   'addl_from' => 'left join did_vendor using (vendornum) ',
+                                                   'addl_from' => 'left join did_vendor using (vendornum) ',
                                     'hashref'   => {},
                                     'order_by' => 'ORDER BY ordernum',
                                   },
-                 'count_query' => $count_query,
-                 'header'      => $header,
-                 'fields'      => $fields,
+                 'count_query' => 'SELECT COUNT(*) FROM did_order',
+                 'header'      => [ '#', 'Vendor',' Vendor Order #', 
+                                    'Submitted', 'Confirmed', 'Customer',
+                                    'Received', 'Provision', 'Cancel',
+                                  ],
+                 'fields'      => [ sub {
+                                        my $did_order = shift;
+                                        $did_order->ordernum;
+                                    }, 
+                                    'vendorname', 
+                                    'vendor_order_id', 
+                                    sub { &$display_date(shift->submitted); },
+                                    sub {
+                                        my $did_order = shift;
+                                        my $ordernum = $did_order->ordernum;
+                                        return &$display_date($did_order->confirmed) 
+                                            if $did_order->confirmed;
+                                        include( '/elements/popup_link.html',
+                                          { 'action'      => "${p}misc/did_order_confirm.html?ordernum=$ordernum",
+                                            'label'       => 'Confirm',
+                                            'actionlabel' => 'Confirm Bulk DID Order',
+                                            'width'       => 480,
+                                            'height'      => 300,
+                                          }
+                                        )
+                                    }, 
+                                    sub {
+                                        my $did_order = shift;
+                                        my $cust_main = $did_order->cust_main;
+                                        return "Stock" unless $cust_main;
+                                        "<A HREF='${p}view/cust_main.cgi?".$cust_main->custnum."'>".$cust_main->name."</A>";
+                                    },
+                                    sub { 
+                                        my $did_order = shift;
+                                        my $ordernum = $did_order->ordernum;
+                                        return &$display_date($did_order->received) 
+                                            if $did_order->received;
+                                        "<A HREF='${p}misc/phone_avail-import.html?ordernum=$ordernum'>Upload Received</A>";
+                                    },
+                                    sub {
+                                        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 ',
+                                                    });
+                                        return '' 
+                                            unless $did_order->received 
+                                                        && $did_order->custnum
+                                                        && !scalar(@provisioned);
+                                        include( '/elements/popup_link.html',
+                                          { 'action'      => "${p}misc/did_order_provision.html?ordernum=".$did_order->ordernum,
+                                            'label'       => 'Provision All DIDs',
+                                            'actionlabel' => 'Bulk DID order - DID provisioning',
+                                            'width'       => 520,
+                                            'height'      => 300,
+                                          }
+                                        )
+                                    },
+                                    sub {
+                                        my $did_order = shift;
+                                        return '' unless !$did_order->received;
+                                        qq!<A HREF="javascript:areyousure('${p}misc/did_order_confirmed.html?action=cancel;ordernum=!
+                                        . $did_order->ordernum . qq!', 'Cancel this order (#!
+                                        . $did_order->ordernum . qq!)?')">Cancel</A>!
+                                    },
+                                  ],
                  'links'       => [
-                                   [ $p.'edit/did_order.html?', 'ordernum' ],
-                                 ],
+                                    [ $p.'edit/did_order.html?', 'ordernum' ],
+                                                 ],
+                 'html_foot' => '
+                            <script type="text/javascript">
+                                function areyousure(href,msg) {
+                                    if (confirm(msg))
+                                        window.location.href = href;
+                                }
+                            </script>
+                                ',
              )
 %>
 <%init>
@@ -24,50 +98,10 @@ die "access denied"
 my $conf = new FS::Conf;
 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
 
-my $html_init = 
-  qq!<A HREF="${p}edit/did_order.html"><I>Add a bulk DID order</I></A><BR><BR>!;
-
-my $count_query = 'SELECT COUNT(*) FROM did_order';
-
 my $display_date = sub {
     my $date = shift;
     return '' unless $date;
     time2str($date_format, $date);
 };
 
-my $header = [ '#', 'Vendor',' Vendor Order #', 'Submitted', 'Confirmed',
-                'Customer', 'Received', ];
-my $fields = [  sub {
-                   my $did_order = shift;
-                   $did_order->ordernum;
-               }, 'vendorname', 'vendor_order_id', 
-               sub { &$display_date(shift->submitted); }, 
-               sub {
-                   my $did_order = shift;
-                   my $ordernum = $did_order->ordernum;
-            return &$display_date($did_order->confirmed) if $did_order->confirmed;
-            include( '/elements/popup_link.html',
-              { 'action'      => "${p}misc/did_order_confirm.html?ordernum=$ordernum",
-                'label'       => 'Confirm&nbsp;Bulk&nbsp;DID&nbsp;Order',
-                'actionlabel' => 'Confirm Bulk DID Order',
-                'width'       => 480,
-                'height'      => 300,
-              }
-            )
-        }, 
-        sub {
-            my $did_order = shift;
-            my $cust_main = $did_order->cust_main;
-            return "Stock" unless $cust_main;
-            "<A HREF='${p}view/cust_main.cgi?".$cust_main->custnum."'>".$cust_main->name."</A>";
-        },
-               sub { 
-                   my $did_order = shift;
-                   my $ordernum = $did_order->ordernum;
-                   return &$display_date($did_order->received) 
-                           if $did_order->received;
-                   "<A HREF='${p}misc/phone_avail-import.html?ordernum=$ordernum'>Upload Received</A>";
-               }, 
-            ];
-
 </%init>
index f20e347..cbd3300 100644 (file)
@@ -65,7 +65,7 @@ my $m2_error_callback = sub {
   my($cgi, $object) = @_;
 
   #process_o2m fields in process/did_order.html
-  my @fields = qw( msa npa latanum ratecenter state quantity );
+  my @fields = qw( msanum npa latanum ratecenternum state quantity );
   my @gfields = ( '', map "_$_", @fields );
 
   map {
@@ -111,6 +111,22 @@ my $javascript = <<END;
             custnum.value = '';
             custnum_search.value = '';
         }
+
+        /* o2m or something else is broken, can't put this in the actual
+            component because random JS and other crap is rendered 
+            onto the final output page */
+        function ratecenter_changed(rc) {
+            var idbase = rc.id.substring(0,rc.id.indexOf('_'));
+            var div = document.getElementById(idbase+'_rc_div');
+            var input = document.getElementById(idbase+'_rc_new');
+            if(rc.options[rc.selectedIndex].value == '0') {
+                div.style.display = 'inline';
+            }
+            else {
+                div.style.display = 'none';
+            }
+            input.value = '';
+        }
     </SCRIPT>
 END
 
index 1762cfa..a7d30c3 100644 (file)
@@ -4,7 +4,8 @@
                'value_callback' => $value_callback,
                'process_o2m' => {
                     'table'  => 'did_order_item',
-                    'fields' => \@item_fields,
+                    'fields' => [ qw( msanum npa latanum ratecenternum state
+                                  quantity ) ],
                 },
            )
 %>
@@ -22,6 +23,16 @@ my $value_callback = sub {
      ($field =~ /ed$/ && $value !~ /^\d+$/) ? parse_datetime($value) : $value;
 };
 
-my @item_fields = qw( msa npa latanum ratecenter state quantity );
+my @params = $cgi->param;
+foreach my $param ( @params ) {
+    next unless $param =~ /^(orderitemnum[0-9]+)_rc_new$/;
+    my $prefix = $1;
+    my $value = $cgi->param($param);
+    next unless $value =~ /^[A-Za-z0-9\- ]+$/;
+    my $rc = new FS::rate_center({ description => $value });
+    my $error = $rc->insert;
+    die "error inserting new rate center: $error" if $error;
+    $cgi->param("${prefix}_ratecenternum",$rc->ratecenternum);
+}
 
 </%init>
index 0f5a765..00668f9 100644 (file)
@@ -4,24 +4,70 @@
 
   <TABLE>
     <TR>
-%     foreach my $field ( @textfields ) {
-%
-%       my $value = '';
-%         $value = $item->get($field);
+%     my $value = '';
 
-        <TD>
+%     $value = $item->get('quantity');
+      <TD>
           <INPUT TYPE  = "text"
-                 NAME  = "<%$name%>_<%$field%>"
-                 ID    = "<%$id%>_<%$field%>"
-                 SIZE  = "<% $size{$field} || 15 %>"
-                 VALUE = "<% scalar($cgi->param($name."_$field"))
+                 NAME  = "<%$name%>_quantity"
+                 ID    = "<%$id%>_quantity"
+                 SIZE  = "3"
+                 VALUE = "<% scalar($cgi->param($name."_quantity"))
                              || $value |h %>"
-                 <% $onchange %>
           >
-          <BR><FONT SIZE="-1"><% $label{$field} %></FONT>
-        </TD>
-%     }
-%     my $value = '';
+          <BR><FONT SIZE="-1">Quantity</FONT>
+      </TD>
+      
+%     $value = $item->get('npa');
+      <TD>
+          <INPUT TYPE  = "text"
+                 NAME  = "<%$name%>_npa"
+                 ID    = "<%$id%>_npa"
+                 SIZE  = "3"
+                 VALUE = "<% scalar($cgi->param($name."_npa"))
+                             || $value |h %>"
+          >
+          <BR><FONT SIZE="-1">NPA</FONT>
+      </TD>
+
+%     $value = $item->get('ratecenternum');
+      <TD>
+        <% include('/elements/select-table.html',
+                         'name_col'      => 'description',
+                         'table'         => 'rate_center',
+                         'disable_empty' => 0,
+                         'empty_label'   => ' ',
+                         'field'         => "${name}_ratecenternum",
+                         'id'            => "${id}_ratecenternum",
+                         'curr_value'    => scalar($cgi->param("${name}_ratecenternum"))
+                                             || $value,
+                         'post_options'  => [ 0 => 'Add new...' ],
+                         onchange        => 'ratecenter_changed',
+                  )
+         %>
+        <BR><FONT SIZE="-1">Rate Center</FONT>
+        <div style="display:none; font-size: 80%" id="<%$id%>_rc_div">
+             - add new: <INPUT TYPE  = "text"
+                 NAME  = "<%$name%>_rc_new"
+                 ID    = "<%$id%>_rc_new">
+        </div>
+      </TD>
+
+%     $value = $item->get('msanum');
+      <TD>
+        <% include('/elements/select-table.html',
+                         'name_col'      => 'description',
+                         'table'         => 'msa',
+                         'disable_empty' => 0,
+                         'empty_label'   => ' ',
+                         'field'         => "${name}_msanum",
+                         'curr_value'    => scalar($cgi->param("${name}_msanum"))
+                                             || $value,
+                   )
+         %>
+        <BR><FONT SIZE="-1">MSA</FONT>
+      </TD>
+
 %     $value = $item->get('latanum');
       <TD><% include('/elements/select-table.html',
                          'name_col'      => 'description',
                          'field'         => "${name}_latanum",
                          'curr_value'    => scalar($cgi->param("${name}_latanum"))
                                              || $value,
-                      )
+                     )
             %>
         <BR><FONT SIZE="-1">LATA #</FONT>
       </TD>
+
 %     $value = $item->get('state');
       <TD><% include('/elements/select-state.html',
                          'disable_empty' => 0,
                          'prefix'        => "${name}_",
                          'state'         => scalar($cgi->param("${name}_state"))
                                             || $value,
-                      )
+                     )
             %>
           <BR><FONT SIZE="-1">State</FONT>
       </TD>
+
     </TR>
   </TABLE>
 
@@ -61,15 +109,6 @@ my $id = $opt{'id'} || 'orderitemnum';
 
 my $curr_value = $opt{'curr_value'} || $opt{'value'};
 
-my $onchange = '';
-if ( $opt{'onchange'} ) {
-  $onchange = $opt{'onchange'};
-  $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
-  $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
-                                        #callbacks should act the same
-  $onchange = 'onChange="'. $onchange. '"';
-}
-
 my $item;
 if ( $curr_value ) {
   $item = qsearchs('did_order_item', { 'orderitemnum' => $curr_value } );
@@ -77,15 +116,4 @@ if ( $curr_value ) {
   $item = new FS::did_order_item {};
 }
 
-my %size = ( 'npa' => 3, 
-            'quantity' => 3,);
-
-tie my %label, 'Tie::IxHash',
-  'quantity' => 'Quantity',
-  'npa'        => 'NPA',
-  'ratecenter'        => 'Rate Center',
-  'msa'        => 'MSA',
-;
-my @textfields = keys %label;
-
 </%init>
index 40495a5..e55958d 100644 (file)
@@ -4,6 +4,7 @@
 
 <FORM NAME="did_order_confirm" ACTION="<% popurl(1) %>did_order_confirmed.html" METHOD=POST>
 <INPUT TYPE="hidden" NAME="ordernum" VALUE="<% $ordernum %>">
+<INPUT TYPE="hidden" NAME="action" VALUE="confirm">
 <TABLE>
     <TR>    
         <TD>Order #</TD>
index 53a41a7..aaded9f 100644 (file)
@@ -1,6 +1,6 @@
-<% include('/elements/header-popup.html', "DID order confirmed") %>
+<% include('/elements/header-popup.html', $success_msg ) %>
   <SCRIPT TYPE="text/javascript">
-    window.top.location.reload();
+    <% $js %>
   </SCRIPT>
   </BODY>
 </HTML>
@@ -8,6 +8,12 @@
 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();';
+
 $cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
 my $ordernum = $1;
 my $did_order = qsearchs( {
@@ -16,22 +22,27 @@ my $did_order = qsearchs( {
 } );
 die "No order $ordernum" unless $did_order;
 
-my $confirmed = '';
-$confirmed = parse_datetime($cgi->param('confirmed'))
-    if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
-$confirmed = $1
-    if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;
-
-die "invalid confirmation date" unless $confirmed;
+if ( $action eq 'confirm' ) {
+    my $confirmed = '';
+    my $sucess_msg = 'DID order confirmed';
+    $confirmed = parse_datetime($cgi->param('confirmed'))
+        if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
+    $confirmed = $1
+        if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;
 
-my $error = '';
-$did_order->confirmed($confirmed);
-$did_order->vendor_order_id($cgi->param('vendor_order_id'));
-$error = $did_order->replace;
+    die "invalid confirmation date" unless $confirmed;
 
-if ( $error ) {
-  $cgi->param('error', $error);
-  print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string );
+    $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 );
+    }
+}
+elsif ( $action eq 'cancel' ) {
+    my $sucess_msg = 'DID order cancelled';
+    $error = $did_order->delete;
+    $js = "window.location.href = '${p}browse/did_order.html'";
 }
-
 </%init>
diff --git a/httemplate/misc/did_order_provision.html b/httemplate/misc/did_order_provision.html
new file mode 100644 (file)
index 0000000..b0c7210
--- /dev/null
@@ -0,0 +1,35 @@
+<% include('/elements/header-popup.html', 'Bulk DID order - DID provisioning' ) %>
+
+<% include('/elements/error.html') %>
+
+<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>
+    <TR>
+        <TD COLSPAN="2"><INPUT TYPE="SUBMIT" value="Provision"></TD>
+    </TR>
+</TABLE>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Import');
+
+$cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
+my $ordernum = $1;
+my $did_order = qsearchs( {
+  'table'     => 'did_order',
+  'hashref'   => { 'ordernum' => $ordernum },
+} );
+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; 
+
+
+</%init>