torrus various changes, RT10574
[freeside.git] / FS / FS / ClientAPI / MyAccount.pm
index ecabe31..be1146e 100644 (file)
@@ -18,6 +18,7 @@ use FS::Conf;
 use FS::Record qw(qsearch qsearchs dbh);
 use FS::Msgcat qw(gettext);
 use FS::Misc qw(card_types);
+use FS::Misc::DateTime qw(parse_datetime);
 use FS::ClientAPI_SessionCache;
 use FS::svc_acct;
 use FS::svc_domain;
@@ -532,6 +533,8 @@ sub payment_info {
       'show_paystate' => $conf->exists('show_bankstate'),
 
       'save_unchecked' => $conf->exists('selfservice-save_unchecked'),
+
+      'credit_card_surcharge_percentage' => $conf->config('credit-card-surcharge-percentage'),
     };
 
   }
@@ -637,6 +640,7 @@ sub process_payment {
   #false laziness w/process/payment.cgi
   my $payinfo;
   my $paycvv = '';
+  my $paynum = '';
   if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
   
     $p->{'payinfo1'} =~ /^([\dx]+)$/
@@ -698,6 +702,7 @@ sub process_payment {
     'payname'  => $payname,
     'paybatch' => $paybatch, #this doesn't actually do anything
     'paycvv'   => $paycvv,
+    'paynum_ref' => \$paynum,
     'pkgnum'   => $session->{'pkgnum'},
     'discount_term' => $discount_term,
     'selfservice' => 1,
@@ -740,7 +745,46 @@ sub process_payment {
     }
   }
 
-  return { 'error' => '' };
+  my $receipt_html = '';
+  if($paynum) { 
+      # currently supported for realtime CC only; send receipt data to SS
+      my $cust_pay = qsearchs('cust_pay', { 'paynum' => $paynum } );
+      if($cust_pay) {
+       $receipt_html = qq!
+<TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=2>
+
+<TR>
+  <TD ALIGN="right">Payment#</TD>
+  <TD BGCOLOR="#FFFFFF"><B>! . $cust_pay->paynum . qq!</B></TD>
+</TR>
+
+<TR>
+  <TD ALIGN="right">Date</TD>
+
+  <TD BGCOLOR="#FFFFFF"><B>! . 
+       time2str("%a&nbsp;%b&nbsp;%o,&nbsp;%Y&nbsp;%r", $cust_pay->_date)
+                                                           . qq!</B></TD>
+</TR>
+
+
+<TR>
+  <TD ALIGN="right">Amount</TD>
+  <TD BGCOLOR="#FFFFFF"><B>! . $cust_pay->paid . qq!</B></TD>
+
+</TR>
+
+<TR>
+  <TD ALIGN="right">Payment method</TD>
+  <TD BGCOLOR="#FFFFFF"><B>! . $cust_pay->payby_name .' #'. $cust_pay->paymask
+                                                               . qq!</B></TD>
+</TR>
+
+</TABLE>
+!;
+      }
+  }
+
+  return { 'error' => '', 'receipt_html' => $receipt_html, };
 
 }
 
@@ -978,6 +1022,7 @@ sub list_pkgs {
     'wholesale_view' => 1,
     'login_svcpart' => [ $conf->config('selfservice_server-login_svcpart') ],
     'date_format' => $conf->config('date_format') || '%m/%d/%Y',
+    'lnp' => $conf->exists('svc_phone-lnp'),
       };
   }
 
@@ -1039,9 +1084,12 @@ sub list_svcs {
   #@svc_x = sort { $a->domain cmp $b->domain || $a->username cmp $b->username }
   #              @svc_x;
 
+    my $conf = new FS::Conf;
+
   { 
     'svcnum'   => $session->{'svcnum'},
     'custnum'  => $custnum,
+    'date_format' => $conf->config('date_format') || '%m/%d/%Y',
     'svcs'     => [
       map { 
             my $svc_x = $_->svc_x;
@@ -1077,7 +1125,7 @@ sub list_svcs {
                 # more...
               );
 
-            } elsif ( $svcdb eq 'svc_phone' ) {
+            } elsif ( $svcdb eq 'svc_phone' || $svcdb eq 'svc_port' ) {
               %hash = (
                 %hash,
               );
@@ -1091,6 +1139,20 @@ sub list_svcs {
 
 }
 
+sub port_graph {
+  my $p = shift;
+  _usage_details( \&_port_graph, $p,
+                  'svcdb' => 'svc_port',
+                );
+}
+
+sub _port_graph {
+  my($svc_port, $begin, $end) = @_;
+  my @usage = ();
+  push @usage, 999;
+  (@usage);
+}
+
 sub _list_svc_usage {
   my($svc_acct, $begin, $end) = @_;
   my @usage = ();
@@ -1270,7 +1332,7 @@ sub order_pkg {
       map { $_ => $p->{$_} } @{$fields{$svcdb}}
     } );
     
-    if ( $svcdb eq 'svc_acct' ) {
+    if ( $svcdb eq 'svc_acct' && exists($p->{"snarf_machine1"}) ) {
       my @acct_snarf;
       my $snarfnum = 1;
       while ( length($p->{"snarf_machine$snarfnum"}) ) {
@@ -1300,7 +1362,7 @@ sub order_pkg {
   tie my %hash, 'Tie::RefHash';
   %hash = ( $cust_pkg => \@svc );
   #msgcat
-  $error = $cust_main->order_pkgs( \%hash, '', 'noexport' => 1 );
+  $error = $cust_main->order_pkgs( \%hash, 'noexport' => 1 );
   return { 'error' => $error } if $error;
 
   my $conf = new FS::Conf;
@@ -1568,7 +1630,23 @@ sub cancel_pkg {
 
 sub provision_phone {
  my $p = shift;
- my @bulkdid = @{$p->{'bulkdid'}};
+ my @bulkdid;
+ @bulkdid = @{$p->{'bulkdid'}} if $p->{'bulkdid'};
+
+# single DID LNP
+ unless($p->{'lnp'}) {
+    $p->{'lnp_desired_due_date'} = parse_datetime($p->{'lnp_desired_due_date'});
+    $p->{'lnp_status'} = "portingin";
+    return _provision( 'FS::svc_phone',
+                 [qw(lnp_desired_due_date lnp_other_provider 
+                   lnp_other_provider_account phonenum countrycode lnp_status)],
+                 [qw(phonenum countrycode)],
+                 $p,
+                 @_
+               );
+ }
+
+# single DID order
  unless (scalar(@bulkdid)) {
     return _provision( 'FS::svc_phone',
                  [qw(phonenum countrycode)],
@@ -1577,7 +1655,25 @@ sub provision_phone {
                  @_
                );
  }
-#XXX: finish bulk orders
+
+# bulk DID order case
+  my $error;
+  foreach my $did ( @bulkdid ) {
+    $did =~ s/[^0-9]//g;
+    $error = _provision( 'FS::svc_phone',
+             [qw(phonenum countrycode)],
+             [qw(phonenum countrycode)],
+             {
+               'pkgnum' => $p->{'pkgnum'},
+               'svcpart' => $p->{'svcpart'},
+               'phonenum' => $did,
+               'countrycode' => $p->{'countrycode'},
+               'session_id' => $p->{'session_id'},
+             }
+           );
+    return $error if ($error->{'error'} && length($error->{'error'}) > 1);
+  }
+  { 'bulkdid' => [ @bulkdid ], 'svc' => $error->{'svc'} }
 }
 
 sub provision_acct {
@@ -1939,16 +2035,24 @@ sub get_ticket {
 # the requested ticket was actually linked to this customer
     my @custs = @{$err_or_ticket->{'custs'}};
     my @txns = @{$err_or_ticket->{'txns'}};
+    my @filtered_txns;
 
     return { 'error' => 'no customer' } unless ( $custnum && scalar(@custs) );
 
     return { 'error' => 'invalid ticket requested' } 
        unless grep($_ eq $custnum, @custs);
 
+    foreach my $txn ( @txns ) {
+       push @filtered_txns, $txn 
+           if ($txn->{'type'} eq 'EmailRecord' 
+               || $txn->{'type'} eq 'Correspond'
+               || $txn->{'type'} eq 'Create');
+    }
+
     warn "$me get_ticket: sucessful: \n"
       if $DEBUG;
     return { 'error'     => '',
-             'transactions' => \@txns,
+             'transactions' => \@filtered_txns,
             'ticket_id' => $p->{'ticket_id'},
            };
   } else {