summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2012-05-06 20:06:13 -0700
committerIvan Kohler <ivan@freeside.biz>2012-05-06 20:06:13 -0700
commitf281f59e4b3f8fed53e64b57d9cb4eaedd73e8e0 (patch)
treeab79d2a1d4ec7510b6a4f744622102930c099171 /FS
parent404f8f0494ab5fd2ff947bf82d085fed52c126c5 (diff)
add billing_history selfservice API call, RT#17617
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/ClientAPI/MyAccount.pm103
-rw-r--r--FS/FS/Conf.pm7
2 files changed, 110 insertions, 0 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 46ea66a..605d1ad 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -196,6 +196,8 @@ sub login {
} else {
+warn Dumper($p);
+
my $svc_domain = qsearchs('svc_domain', { 'domain' => $p->{'domain'} } )
or return { error => 'Domain '. $p->{'domain'}. ' not found' };
@@ -383,8 +385,12 @@ sub customer_info {
if ( $session->{'pkgnum'} ) {
$return{balance} = $cust_main->balance_pkgnum( $session->{'pkgnum'} );
+ #next_bill_date from cust_pkg?
} else {
$return{balance} = $cust_main->balance;
+ $return{next_bill_date} = $cust_main->next_bill_date;
+ $return{next_bill_date_pretty} =
+ time2str('%m/%d/%Y', $return{next_bill_date} );
}
my @tickets = $cust_main->tickets;
@@ -566,6 +572,103 @@ sub customer_info_short {
};
}
+sub billing_history {
+ my $p = shift;
+
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
+
+ return { 'error' => 'No customer' } unless $custnum;
+
+ my $search = { 'custnum' => $custnum };
+ $search->{'agentnum'} = $session->{'agentnum'} if $context eq 'agent';
+ my $cust_main = qsearchs('cust_main', $search )
+ or return { 'error' => "unknown custnum $custnum" };
+
+ my %return = ();
+
+ if ( $session->{'pkgnum'} ) {
+ #$return{balance} = $cust_main->balance_pkgnum( $session->{'pkgnum'} );
+ #next_bill_date from cust_pkg?
+ return { 'error' => 'No history for package' };
+ }
+
+ $return{balance} = $cust_main->balance;
+ $return{next_bill_date} = $cust_main->next_bill_date;
+ $return{next_bill_date_pretty} =
+ time2str('%m/%d/%Y', $return{next_bill_date} );
+
+ my @history = ();
+
+ my $conf = new FS::Conf;
+
+ if ( $conf->exists('selfservice-billing_history-line_items') ) {
+
+ foreach my $cust_bill ( $cust_main->cust_bill ) {
+
+ push @history, {
+ 'type' => 'Line item',
+ 'description' => $_->desc. ( $_->sdate && $_->edate
+ ? ' '. time2str('%d-%b-%Y', $_->sdate).
+ ' To '. time2str('%d-%b-%Y', $_->edate)
+ : ''
+ ),
+ 'amount' => sprintf('%.2f', $_->setup + $_->recur ),
+ 'date' => $cust_bill->_date,
+ 'date_pretty' => time2str('%m/%d/%Y', $cust_bill->_date ),
+ }
+ foreach $cust_bill->cust_bill_pkg;
+
+ }
+
+ } else {
+
+ push @history, {
+ 'type' => 'Invoice',
+ 'description' => 'Invoice #'. $_->display_invnum,
+ 'amount' => sprintf('%.2f', $_->charged ),
+ 'date' => $_->_date,
+ 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ }
+ foreach $cust_main->cust_bill;
+
+ }
+
+ push @history, {
+ 'type' => 'Payment',
+ 'description' => 'Payment', #XXX type
+ 'amount' => sprintf('%.2f', 0 - $_->paid ),
+ 'date' => $_->_date,
+ 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ }
+ foreach $cust_main->cust_pay;
+
+ push @history, {
+ 'type' => 'Credit',
+ 'description' => 'Credit', #more info?
+ 'amount' => sprintf('%.2f', 0 -$_->amount ),
+ 'date' => $_->_date,
+ 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ }
+ foreach $cust_main->cust_credit;
+
+ push @history, {
+ 'type' => 'Refund',
+ 'description' => 'Refund', #more info? type, like payment?
+ 'amount' => $_->refund,
+ 'date' => $_->_date,
+ 'date_pretty' => time2str('%m/%d/%Y', $_->_date ),
+ }
+ foreach $cust_main->cust_refund;
+
+ @history = sort { $b->{'date'} <=> $a->{'date'} } @history;
+
+ $return{'history'} = \@history;
+
+ return \%return;
+
+}
+
sub edit_info {
my $p = shift;
my $session = _cache->get($p->{'session_id'})
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index bf7c553..bf2f189 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5043,6 +5043,13 @@ and customer address. Include units.',
'type' => 'checkbox',
},
+ {
+ 'key' => 'selfservice-billing_history-line_items',
+ 'section' => 'self-service',
+ 'description' => 'Return line item billing detail for the self-service billing_history API call.',
+ 'type' => 'checkbox',
+ },
+
{ key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
{ key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
{ key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },