[freeside-commits] freeside/FS/FS Schema.pm, 1.188, 1.189 cust_bill_pkg_discount.pm, NONE, 1.1 Mason.pm, 1.27, 1.28 cust_main.pm, 1.494, 1.495 cust_bill_pkg.pm, 1.48, 1.49 cust_pkg.pm, 1.152, 1.153
Ivan,,,
ivan at wavetail.420.am
Fri Feb 5 18:54:12 PST 2010
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv1107/FS/FS
Modified Files:
Schema.pm Mason.pm cust_main.pm cust_bill_pkg.pm cust_pkg.pm
Added Files:
cust_bill_pkg_discount.pm
Log Message:
discount reporting, RT#6679
--- NEW FILE: cust_bill_pkg_discount.pm ---
package FS::cust_bill_pkg_discount;
use strict;
use base qw( FS::cust_main_Mixin FS::Record );
use FS::Record qw( qsearch qsearchs );
use FS::cust_bill_pkg;
use FS::cust_pkg_discount;
=head1 NAME
FS::cust_bill_pkg_discount - Object methods for cust_bill_pkg_discount records
=head1 SYNOPSIS
use FS::cust_bill_pkg_discount;
$record = new FS::cust_bill_pkg_discount \%hash;
$record = new FS::cust_bill_pkg_discount { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::cust_bill_pkg_discount object represents the slice of a customer
applied to a line item. FS::cust_bill_pkg_discount inherits from
FS::Record. The following fields are currently supported:
=over 4
=item billpkgdiscountnum
primary key
=item billpkgnum
Line item (see L<FS::cust_bill_pkg>)
=item pkgdiscountnum
Customer discount (see L<FS::cust_pkg_discount>)
=item amount
Amount discounted from the line itme.
=item months
Number of months of discount this represents.
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new record. To add the record to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'cust_bill_pkg_discount'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid record. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
sub check {
my $self = shift;
my $error =
$self->ut_numbern('billpkgdiscountnum')
|| $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum' )
|| $self->ut_foreign_key('pkgdiscountnum', 'cust_pkg_discount', 'pkgdiscountnum' )
|| $self->ut_money('amount')
|| $self->ut_float('months')
;
return $error if $error;
$self->SUPER::check;
}
=item cust_bill_pkg
Returns the associated line item (see L<FS::cust_bill_pkg>).
=cut
sub cust_bill_pkg {
my $self = shift;
qsearchs( 'cust_bill_pkg', { 'billpkgnum' => $self->billpkgnum } ) ;
}
=item cust_pkg_discount
Returns the associated customer discount (see L<FS::cust_pkg_discount>).
=cut
sub cust_pkg_discount {
my $self = shift;
qsearchs( 'cust_pkg_discount', { 'pkgdiscountnum' => $self->pkgdiscountnum });
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
=cut
1;
Index: Mason.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Mason.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- Mason.pm 30 Jan 2010 07:38:31 -0000 1.27
+++ Mason.pm 6 Feb 2010 02:54:09 -0000 1.28
@@ -228,6 +228,8 @@
use FS::contact;
use FS::svc_pbx;
use FS::discount;
+ use FS::cust_pkg_discount;
+ use FS::cust_bill_pkg_discount;
# Sammath Naur
if ( $FS::Mason::addl_handler_use ) {
Index: cust_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pkg.pm,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- cust_pkg.pm 5 Feb 2010 02:39:31 -0000 1.152
+++ cust_pkg.pm 6 Feb 2010 02:54:09 -0000 1.153
@@ -2388,10 +2388,7 @@
sub cust_pkg_discount_active {
my $self = shift;
- grep { my $d = $_->discount;
- ! $d->months || $_->months_used < $d->months; # XXX also end date
- }
- $self->cust_pkg_discount;
+ grep { $_->status eq 'active' } $self->cust_pkg_discount;
}
=back
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.494
retrieving revision 1.495
diff -u -d -r1.494 -r1.495
--- cust_main.pm 3 Feb 2010 19:27:17 -0000 1.494
+++ cust_main.pm 6 Feb 2010 02:54:09 -0000 1.495
@@ -3065,7 +3065,7 @@
my $old_cust_pkg = new FS::cust_pkg \%hash;
my @details = ();
-
+ my @discounts = ();
my $lineitems = 0;
$cust_pkg->pkgpart($part_pkg->pkgpart);
@@ -3150,6 +3150,7 @@
);
my %param = ( 'precommit_hooks' => $precommit_hooks,
'increment_next_bill' => $increment_next_bill,
+ 'discounts' => \@discounts,
);
my $method = $options{cancel} ? 'calc_cancel' : 'calc_recur';
@@ -3229,6 +3230,7 @@
'unitrecur' => $unitrecur,
'quantity' => $cust_pkg->quantity,
'details' => \@details,
+ 'discounts' => \@discounts,
'hidden' => $part_pkg->hidden,
};
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.188
retrieving revision 1.189
diff -u -d -r1.188 -r1.189
--- Schema.pm 30 Jan 2010 07:38:31 -0000 1.188
+++ Schema.pm 6 Feb 2010 02:54:08 -0000 1.189
@@ -1317,12 +1317,26 @@
'months_used', 'decimal', 'NULL', '', '', '',
'end_date', @date_type, '', '',
'otaker', 'varchar', '', 32, '', '',
+ 'disabled', 'char', 'NULL', 1, '', '',
],
'primary_key' => 'pkgdiscountnum',
'unique' => [],
'index' => [ [ 'pkgnum' ], [ 'discountnum' ] ],
},
+ 'cust_bill_pkg_discount' => {
+ 'columns' => [
+ 'billpkgdiscountnum', 'serial', '', '', '', '',
+ 'billpkgnum', 'int', '', '', '', '',
+ 'pkgdiscountnum', 'int', '', '', '', '',
+ 'amount', @money_type, '', '',
+ 'months', 'decimal', 'NULL', '', '', '',
+ ],
+ 'primary_key' => 'billpkgdiscountnum',
+ 'unique' => [],
+ 'index' => [ [ 'billpkgnum' ], [ 'pkgdiscountnum' ] ],
+ },
+
'discount' => {
'columns' => [
'discountnum', 'serial', '', '', '', '',
Index: cust_bill_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg.pm,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- cust_bill_pkg.pm 21 Dec 2009 14:44:09 -0000 1.48
+++ cust_bill_pkg.pm 6 Feb 2010 02:54:09 -0000 1.49
@@ -174,6 +174,17 @@
}
}
+ if ( $self->get('discounts') ) {
+ foreach my $cust_bill_pkg_discount ( @{$self->get('discounts')} ) {
+ $cust_bill_pkg_discount->billpkgnum($self->billpkgnum);
+ $error = $cust_bill_pkg_discount->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "error inserting cust_bill_pkg_discount: $error";
+ }
+ }
+ }
+
if ( $self->_cust_tax_exempt_pkg ) {
foreach my $cust_tax_exempt_pkg ( @{$self->_cust_tax_exempt_pkg} ) {
$cust_tax_exempt_pkg->billpkgnum($self->billpkgnum);
@@ -763,10 +774,10 @@
my $type = $opt{type} if exists $opt{type};
my @result;
- if ( scalar( $self->get('display') ) ) {
+ if ( $self->get('display') ) {
@result = grep { defined($type) ? ($type eq $_->type) : 1 }
@{ $self->get('display') };
- }else{
+ } else {
my $hashref = { 'billpkgnum' => $self->billpkgnum };
$hashref->{type} = $type if defined($type);
More information about the freeside-commits
mailing list