[freeside-commits] freeside/FS/FS discount.pm, 1.3, 1.4 cust_pkg_discount.pm, 1.3, 1.4 cust_pkg.pm, 1.151, 1.152
Ivan,,,
ivan at wavetail.420.am
Thu Feb 4 18:39:33 PST 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv16400/FS/FS
Modified Files:
discount.pm cust_pkg_discount.pm cust_pkg.pm
Log Message:
discounts, RT#6679
Index: cust_pkg_discount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg_discount.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cust_pkg_discount.pm 31 Jan 2010 02:57:14 -0000 1.3
+++ cust_pkg_discount.pm 5 Feb 2010 02:39:31 -0000 1.4
@@ -2,7 +2,7 @@
use strict;
use base qw( FS::Record );
-use FS::Record qw( qsearchs ); # qsearch );
+use FS::Record qw( dbh qsearchs ); # qsearch );
use FS::cust_pkg;
use FS::discount;
@@ -85,7 +85,47 @@
=cut
-# the insert method can be inherited from FS::Record
+sub insert {
+ #my( $self, %options ) = @_;
+ my $self = shift;
+
+ 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;
+
+ if ( $self->discountnum == -1 ) {
+ my $discount = new FS::discount {
+ '_type' => $self->_type,
+ 'amount' => $self->amount,
+ 'percent' => $self->percent,
+ 'months' => $self->months,
+ 'disabled' => 'Y',
+ };
+ my $error = $discount->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $self->discountnum($discount->discountnum);
+ }
+
+ my $error = $self->SUPER::insert; #(@_); #(%options);
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+ '';
+
+}
=item delete
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.151
retrieving revision 1.152
diff -u -d -r1.151 -r1.152
--- cust_pkg.pm 30 Jan 2010 08:55:11 -0000 1.151
+++ cust_pkg.pm 5 Feb 2010 02:39:31 -0000 1.152
@@ -277,15 +277,7 @@
);
if ( $self->discountnum ) {
- #XXX new/custom discount case
- my $cust_pkg_discount = new FS::cust_pkg_discount {
- 'pkgnum' => $self->pkgnum,
- 'discountnum' => $self->discountnum,
- 'months_used' => 0,
- 'end_date' => '', #XXX
- 'otaker' => $self->otaker,
- };
- my $error = $cust_pkg_discount->insert;
+ my $error = $self->insert_discount();
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
@@ -2303,6 +2295,44 @@
$cust_pkg_reason->insert;
}
+=item insert_discount
+
+Associates this package with a discount (see L<FS::cust_pkg_discount>, possibly
+inserting a new discount on the fly (see L<FS::discount>).
+
+Available options are:
+
+=over 4
+
+=item discountnum
+
+=back
+
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub insert_discount {
+ #my ($self, %options) = @_;
+ my $self = shift;
+
+ my $cust_pkg_discount = new FS::cust_pkg_discount {
+ 'pkgnum' => $self->pkgnum,
+ 'discountnum' => $self->discountnum,
+ 'months_used' => 0,
+ 'end_date' => '', #XXX
+ 'otaker' => $self->otaker,
+ #for the create a new discount case
+ '_type' => $self->discountnum__type,
+ 'amount' => $self->discountnum_amount,
+ 'percent' => $self->discountnum_percent,
+ 'months' => $self->discountnum_months,
+ #'disabled' => $self->discountnum_disabled,
+ };
+
+ $cust_pkg_discount->insert;
+}
+
=item set_usage USAGE_VALUE_HASHREF
USAGE_VALUE_HASHREF is a hashref of svc_acct usage columns and the amounts
Index: discount.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/discount.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- discount.pm 4 Feb 2010 20:39:55 -0000 1.3
+++ discount.pm 5 Feb 2010 02:39:31 -0000 1.4
@@ -113,6 +113,16 @@
sub check {
my $self = shift;
+ if ( $self->_type eq 'Select discount type' ) {
+ return 'Please select a discount type';
+ } elsif ( $self->_type eq 'Amount' ) {
+ $self->percent('0');
+ return 'Amount must be greater than 0' unless $self->amount > 0;
+ } elsif ( $self->_type eq 'Percentage' ) {
+ $self->amount('0.00');
+ return 'Percentage must be greater than 0' unless $self->percent > 0;
+ }
+
my $error =
$self->ut_numbern('discountnum')
|| $self->ut_textn('name')
More information about the freeside-commits
mailing list