summaryrefslogtreecommitdiff
path: root/FS/FS
diff options
context:
space:
mode:
authorivan <ivan>2009-01-22 17:29:22 +0000
committerivan <ivan>2009-01-22 17:29:22 +0000
commit2b8e51c711674efa5878354cd17e2875a5ee19b2 (patch)
tree40a332d8f38ac08a350970cef232ba66e020fdad /FS/FS
parent455556cc709f205cb63d42cfe941bb874f36c2f5 (diff)
add self-service methods renew_info, order_renew and process_payment_order_renew to enable self-renewal through self-service. RT#4623
Diffstat (limited to 'FS/FS')
-rw-r--r--FS/FS/ClientAPI/MyAccount.pm67
-rw-r--r--FS/FS/part_pkg.pm36
2 files changed, 103 insertions, 0 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index e15476153..bd95c2883 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -540,6 +540,15 @@ sub process_payment_order_pkg {
order_pkg($p);
}
+sub process_payment_order_renew {
+ my $p = shift;
+
+ my $hr = process_payment($p);
+ return $hr if $hr->{'error'};
+
+ order_renew($p);
+}
+
sub process_prepay {
my $p = shift;
@@ -1096,6 +1105,64 @@ sub _do_bop_realtime {
'';
}
+sub renew_info {
+ my $p = shift;
+
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ or return { 'error' => "unknown custnum $custnum" };
+
+ my @cust_pkg = sort { $a->bill <=> $b->bill }
+ grep { $_->part_pkg->freq ne '0' }
+ $cust_main->ncancelled_pkgs;
+
+ #return { 'error' => 'No active packages to renew.' } unless @cust_pkg;
+
+ my $total = 0;
+
+ my @array = map {
+ $total += $_->part_pkg->base_recur;
+ my $renew_date = $_->part_pkg->add_freq($_->bill);
+ {
+ 'bill_date' => $_->bill,
+ 'bill_date_pretty' => time2str('%x', $_->bill),
+ 'renew_date' => $renew_date,
+ 'renew_date_pretty' => time2str('%x', $renew_date),
+ 'amount' => $total,
+ };
+ }
+ @cust_pkg;
+
+ return { 'dates' => \@array };
+
+}
+
+sub order_renew {
+ my $p = shift;
+
+ my($context, $session, $custnum) = _custoragent_session_custnum($p);
+ return { 'error' => $session } if $context eq 'error';
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
+ or return { 'error' => "unknown custnum $custnum" };
+
+ my $date = $p->{'date'};
+
+ my $now = time;
+
+ #freeside-daily -n -d $date fs_daily $custnum
+ $cust_main->bill_and_collect( 'time' => $date,
+ 'invoice_time' => $now,
+ 'actual_time' => $now,
+ 'check_freq' => '1d',
+ );
+
+ return { 'error' => '' };
+
+}
+
sub cancel_pkg {
my $p = shift;
my $session = _cache->get($p->{'session_id'})
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index f521d65e2..38fc03e42 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -4,6 +4,7 @@ use strict;
use vars qw( @ISA %plans $DEBUG );
use Carp qw(carp cluck confess);
use Scalar::Util qw( blessed );
+use Time::Local qw( timelocal_nocheck );
use Tie::IxHash;
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh dbdef );
@@ -728,6 +729,41 @@ sub freq_pretty {
}
}
+=item add_freq TIMESTAMP
+
+Adds the frequency of this package to the provided timestamp and returns
+the resulting timestamp, or -1 if the frequency of this package could not be
+parsed (shouldn't happen).
+
+=cut
+
+sub add_freq {
+ my( $self, $date ) = @_;
+ my $freq = $self->freq;
+
+ #change this bit to use Date::Manip? CAREFUL with timezones (see
+ # mailing list archive)
+ my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($date) )[0,1,2,3,4,5];
+
+ if ( $self->freq =~ /^\d+$/ ) {
+ $mon += $self->freq;
+ until ( $mon < 12 ) { $mon -= 12; $year++; }
+ } elsif ( $self->freq =~ /^(\d+)w$/ ) {
+ my $weeks = $1;
+ $mday += $weeks * 7;
+ } elsif ( $self->freq =~ /^(\d+)d$/ ) {
+ my $days = $1;
+ $mday += $days;
+ } elsif ( $self->freq =~ /^(\d+)h$/ ) {
+ my $hours = $1;
+ $hour += $hours;
+ } else {
+ return -1;
+ }
+
+ timelocal_nocheck($sec,$min,$hour,$mday,$mon,$year);
+}
+
=item plandata
For backwards compatibility, returns the plandata field as well as all options