import torrus 1.0.9
[freeside.git] / fs_selfservice / fri / modules / billing.module
index caa28b5..6ef16e5 100644 (file)
@@ -46,7 +46,122 @@ class billing {
    */
   function display($args) {
 
-    global $ARI_HELP_FEATURE_CODES;
+    $display = new Display();
+
+    // args
+    $m = getArgument($args,'m');
+    $q = getArgument($args,'q');
+
+    $displayname = $_SESSION['ari_user']['displayname'];
+    $extension = $_SESSION['ari_user']['extension'];
+
+    // build page content
+    $ret .= checkErrorMessage();
+
+       $header_text = _("Billing");
+       if (!$_SESSION['ari_user']['admin_help']) {
+               $header_text .= sprintf(_(" for %s (%s)"), $displayname, $extension);
+       }
+
+    // build page content
+    $ret .= checkErrorMessage();
+
+    $ret .= $display->displayHeaderText($header_text);
+    $ret .= $display->displayLine();
+
+
+    $freeside = new FreesideSelfService();
+
+   $fs_info = $freeside->customer_info( array(
+      'session_id' => $_SESSION['freeside_session_id'],
+    ) );
+    $error = $fs_info['error'];
+    if ( $error ) {
+      //$_SESSION['ari_error'] = _("Incorrect Username or Password");
+      $_SESSION['ari_error'] = $error; #// XXX report as ari_error???!
+    }
+
+    //$ret .= $fs_info['small_custview'];
+    //$ret .= '<BR>';
+
+    $ret .= 'Balance: <b>$'. $fs_info['balance']. '</b><BR><BR>';
+   
+    if ( $fs_info['balance'] > 0 ) {
+  
+      #$ret .= '<B><A HREF="'. $_SESSION['ARI_ROOT'].
+      #        '?m=billing&f=make_payment">Make a payment</A></B><BR><BR>';
+      $ret .= '<B><A HREF="/selfservice/selfservice.cgi?session='.
+              $_SESSION['freeside_session_id'].
+              ';action=make_payment">Make a payment</A></B><BR><BR>';
+
+    }
+
+    // XXX count() ???
+    if ( count($fs_info['open_invoices']) ) {
+  
+      $ret .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR="#eeeeee">'.
+              '<TR><TH BGCOLOR="#ff6666" COLSPAN=5>Open Invoices</TH></TR>';
+      $link = '<A HREF="'. $_SESSION['ARI_ROOT'].
+              '?m=billing&f=view_invoice&invnum=';
+      
+      $col1 = "eeeeee";
+      $col2 = "cccccc";
+      $col = $col1;
+  
+      while ( $i = each($fs_info['open_invoices']) ) {
+  
+        $invoice = $i[value];
+  
+        $td = '<TD BGCOLOR="#'. $col. '">';
+        $a  = $link. $invoice['invnum']. '">';
+        $ret .=
+          "<TR>$td$a". 'Invoice #'. $invoice['invnum']. "</A></TD>$td</TD>".
+          "$td$a". $invoice['date']. "</A></TD>$td</TD>".
+          '<TD BGCOLOR="#'. $col. '" ALIGN="right">'. $a. '$'. $invoice['owed'].
+            '</A></TD>'.
+          '</TR>';
+
+        if ( $col == $col1 ) {
+          $col = $col2;
+        } else {
+          $col = $col1;
+        }
+
+      }
+
+      $ret .= '</TABLE><BR>';
+    } else {
+      $ret .= 'You have no outstanding invoices.<BR><BR>';
+    }
+
+    #$fs_info = $freeside->customer_info( array(
+    #  'session_id' => $_SESSION['freeside_session_id'],
+    #) );
+    #$error = $fs_info['error'];
+    #if ( $error ) {
+    #  //$_SESSION['ari_error'] = _("Incorrect Username or Password");
+    #  $_SESSION['ari_error'] = $error; #// XXX report as ari_error???!
+    #}
+
+    // $ret .= 'Billing goes here';
+    // XXX navigate to make payment, view invoice,
+    // & myaccount change payment info
+
+    $ret .= '<B><A HREF="/selfservice/selfservice.cgi?session='.
+            $_SESSION['freeside_session_id'].
+            ';action=make_payment">Make a credit card payment</A></B><BR><BR>';
+    $ret .= '<B><A HREF="/selfservice/selfservice.cgi?session='.
+            $_SESSION['freeside_session_id'].
+            ';action=make_payment">Make an electronic check payment</A></B><BR><BR>';
+    $ret .= '<B><A HREF="/selfservice/selfservice.cgi?session='.
+            $_SESSION['freeside_session_id'].
+            ';action=make_payment">Use a prepaid card</A></B><BR><BR>';
+
+    return $ret;
+
+  }
+
+  function make_payment($args) {
 
     $display = new Display();
 
@@ -71,9 +186,63 @@ class billing {
     $ret .= $display->displayHeaderText($header_text);
     $ret .= $display->displayLine();
 
-    $ret .= 'Billing goes here';
+
+    #$freeside = new FreesideSelfService();
+
+    $ret .= 'Make payment goes here';
 
     return $ret;
+
+  }
+
+  function view_invoice($args) {
+
+    $display = new Display();
+
+    // args
+    $m = getArgument($args,'m');
+    $q = getArgument($args,'q');
+
+    $displayname = $_SESSION['ari_user']['displayname'];
+    $extension = $_SESSION['ari_user']['extension'];
+
+    // build page content
+    $ret .= checkErrorMessage();
+
+       $header_text = _("Billing");
+       if (!$_SESSION['ari_user']['admin_help']) {
+               $header_text .= sprintf(_(" for %s (%s)"), $displayname, $extension);
+       }
+
+    // build page content
+    $ret .= checkErrorMessage();
+
+    $ret .= $display->displayHeaderText($header_text);
+    #$ret .= $display->displayLine();
+
+    $invnum = getArgument($args, 'invnum');
+
+    $freeside = new FreesideSelfService();
+    $invoice = $freeside->invoice( array(
+      'session_id' => $_SESSION['freeside_session_id'],
+      'invnum'     => $invnum,
+    ) );
+    $error = $invoice['error'];
+    if ( $error ) {
+      //$_SESSION['ari_error'] = _("Incorrect Username or Password");
+      $_SESSION['ari_error'] = $error; // XXX report as ari_error???!
+    }
+
+    $html = $invoice['invoice_html']->scalar;
+    $html = str_replace( "\xA0", '&nbsp;', $html); // XX doh
+    error_log($html);
+
+    $ret .= '<TABLE BGCOLOR="#000000" BORDER=0><TR><TD>'.
+            $html.
+            '</TD></TR></TABLE>';
+
+    return $ret;
+
   }
 
 }