freeside/FS/FS Conf.pm,1.118,1.119 cust_main.pm,1.169,1.170 cust_pkg.pm,1.51,1.52
ivan
ivan at pouncequick.420.am
Tue Jan 18 16:57:14 PST 2005
- Previous message: freeside/httemplate/edit/process rate.cgi,1.1,NONE
- Next message: freeside/FS/FS/part_pkg flat.pm,1.2,1.3 sesmon_hour.pm,1.2,1.3 sesmon_minute.pm,1.2,1.3 sql_external.pm,1.2,1.3 sql_generic.pm,1.2,1.3 sqlradacct_hour.pm,1.2,1.3 voip_sqlradacct.pm,1.6,1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv11730
Modified Files:
Conf.pm cust_main.pm cust_pkg.pm
Log Message:
one-time referral credits
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- cust_main.pm 3 Jan 2005 18:25:06 -0000 1.169
+++ cust_main.pm 19 Jan 2005 00:57:11 -0000 1.170
@@ -2659,6 +2659,19 @@
$self->referral_cust_main($depth);
}
+=item referring_cust_main
+
+Returns the single cust_main record for the customer who referred this customer
+(referral_custnum), or false.
+
+=cut
+
+sub referring_cust_main {
+ my $self = shift;
+ return '' unless $self->referral_custnum;
+ qsearchs('cust_main', { 'custnum' => $self->referral_custnum } );
+}
+
=item credit AMOUNT, REASON
Applies a credit to this customer. If there is an error, returns the error,
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- cust_pkg.pm 29 Dec 2004 12:00:06 -0000 1.51
+++ cust_pkg.pm 19 Jan 2005 00:57:11 -0000 1.52
@@ -141,7 +141,7 @@
sub table { 'cust_pkg'; }
-=item insert
+=item insert [ OPTION => VALUE ... ]
Adds this billing item to the database ("Orders" the item). If there is an
error, returns the error, otherwise returns false.
@@ -150,6 +150,73 @@
will be used to look up the package definition and agent restrictions will be
ignored.
+The following options are available: I<change>
+
+I<change>, if set true, supresses any referral credit to a referring customer.
+
+=cut
+
+sub insert {
+ my( $self, %options ) = @_;
+
+ 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 $error = $self->SUPER::insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ my $conf = new FS::Conf;
+ my $cust_main = $self->cust_main;
+ my $part_pkg = $self->part_pkg;
+ if ( $conf->exists('referral_credit')
+ && $cust_main->referral_custnum
+ && ! $options{'change'}
+ && $part_pkg->freq !~ /^0\D?$/
+ )
+ {
+ my $referring_cust_main = $cust_main->referring_cust_main;
+ if ( $referring_cust_main->status ne 'cancelled' ) {
+ my $error;
+ if ( $part_pkg->freq !~ /^\d+$/ ) {
+ warn 'WARNING: Not crediting customer '. $cust_main->referral_custnum.
+ ' for package '. $self->pkgnum.
+ ' ( customer '. $self->custnum. ')'.
+ ' - One-time referral credits not (yet) available for '.
+ ' packages with '. $part_pkg->freq_pretty. ' frequency';
+ } else {
+
+ my $amount = sprintf( "%.2f", $part_pkg->base_recur / $part_pkg->freq );
+ my $error =
+ $referring_cust_main->credit( $amount,
+ 'Referral credit for '. $cust_main->name
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Error crediting customer ". $cust_main->referral_custnum.
+ " for referral: $error";
+ }
+
+ }
+
+ }
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+
+}
+
=item delete
This method now works but you probably shouldn't use it.
@@ -982,12 +1049,13 @@
my $cust_main = qsearchs('cust_main', { custnum => $custnum });
return "Customer not found: $custnum" unless $cust_main;
+ my $change = scalar(@$remove_pkgnum) != 0;
+
# Create the new packages.
- my $cust_pkg;
- foreach (@$pkgparts) {
- $cust_pkg = new FS::cust_pkg { custnum => $custnum,
- pkgpart => $_ };
- $error = $cust_pkg->insert;
+ foreach my $pkgpart (@$pkgparts) {
+ my $cust_pkg = new FS::cust_pkg { custnum => $custnum,
+ pkgpart => $pkgpart };
+ $error = $cust_pkg->insert( 'change' => $change );
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -d -r1.118 -r1.119
--- Conf.pm 6 Jan 2005 20:58:24 -0000 1.118
+++ Conf.pm 19 Jan 2005 00:57:10 -0000 1.119
@@ -1377,6 +1377,12 @@
'type' => 'checkbox',
},
+ { 'key' => 'referral_credit',
+ 'section' => 'billing',
+ 'description' => "Enables one-time referral credits in the amount of one month <i>referred</i> customer's recurring fee (irregardless of frequency).",
+ 'type' => 'checkbox',
+ },
+
);
1;
- Previous message: freeside/httemplate/edit/process rate.cgi,1.1,NONE
- Next message: freeside/FS/FS/part_pkg flat.pm,1.2,1.3 sesmon_hour.pm,1.2,1.3 sesmon_minute.pm,1.2,1.3 sql_external.pm,1.2,1.3 sql_generic.pm,1.2,1.3 sqlradacct_hour.pm,1.2,1.3 voip_sqlradacct.pm,1.6,1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list