From 4109791a9b80df968edaf2e71da8ebcfb8882be3 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Thu, 8 Aug 2013 18:43:07 -0700 Subject: unearned revenue report: consider primary object dates, not application dates, #13289 --- FS/FS/cust_bill_pkg.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm index 572fe7973..f94bf9b19 100644 --- a/FS/FS/cust_bill_pkg.pm +++ b/FS/FS/cust_bill_pkg.pm @@ -955,8 +955,8 @@ Returns an SQL expression for the sum of payments applied to this item. sub paid_sql { my ($class, $start, $end, %opt) = @_; - my $s = $start ? "AND cust_bill_pay._date <= $start" : ''; - my $e = $end ? "AND cust_bill_pay._date > $end" : ''; + my $s = $start ? "AND cust_pay._date <= $start" : ''; + my $e = $end ? "AND cust_pay._date > $end" : ''; my $setuprecur = $opt{setuprecur} =~ /^s/ ? 'setup' : $opt{setuprecur} =~ /^r/ ? 'recur' : @@ -965,6 +965,7 @@ sub paid_sql { my $paid = "( SELECT COALESCE(SUM(cust_bill_pay_pkg.amount),0) FROM cust_bill_pay_pkg JOIN cust_bill_pay USING (billpaynum) + JOIN cust_pay USING (paynum) WHERE cust_bill_pay_pkg.billpkgnum = cust_bill_pkg.billpkgnum $s $e $setuprecur )"; @@ -983,8 +984,8 @@ sub paid_sql { sub credited_sql { my ($class, $start, $end, %opt) = @_; - my $s = $start ? "AND cust_credit_bill._date <= $start" : ''; - my $e = $end ? "AND cust_credit_bill._date > $end" : ''; + my $s = $start ? "AND cust_credit._date <= $start" : ''; + my $e = $end ? "AND cust_credit._date > $end" : ''; my $setuprecur = $opt{setuprecur} =~ /^s/ ? 'setup' : $opt{setuprecur} =~ /^r/ ? 'recur' : @@ -993,6 +994,7 @@ sub credited_sql { my $credited = "( SELECT COALESCE(SUM(cust_credit_bill_pkg.amount),0) FROM cust_credit_bill_pkg JOIN cust_credit_bill USING (creditbillnum) + JOIN cust_credit USING (crednum) WHERE cust_credit_bill_pkg.billpkgnum = cust_bill_pkg.billpkgnum $s $e $setuprecur )"; -- cgit v1.2.1 From 98ea745e4b55a38ad8b5ba3749c56327d641d65d Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 9 Aug 2013 13:36:43 -0700 Subject: preserve quantity when changing package type/location, #24259 --- FS/FS/cust_pkg.pm | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'FS') diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 01eaf6253..0ecc0ffcb 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -1734,6 +1734,11 @@ New pkgpart (see L). New refnum (see L). +=item quantity + +New quantity; if unspecified, the new package will have the same quantity +as the old. + =item cust_pkg "New" (existing) FS::cust_pkg object. The package's services and other @@ -1769,9 +1774,6 @@ sub change { my $self = shift; my $opt = ref($_[0]) ? shift : { @_ }; -# my ($custnum, $pkgparts, $remove_pkgnum, $return_cust_pkg, $refnum) = @_; -# - my $conf = new FS::Conf; # Transactionize this whole mess @@ -1792,10 +1794,6 @@ sub change { my $time = time; - #$hash{$_} = $self->$_() foreach qw( last_bill bill ); - - #$hash{$_} = $self->$_() foreach qw( setup ); - $hash{'setup'} = $time if $self->setup; $hash{'change_date'} = $time; @@ -1867,6 +1865,7 @@ sub change { } $hash{'contactnum'} = $opt->{'contactnum'} if $opt->{'contactnum'}; + $hash{'quantity'} = $opt->{'quantity'} || $self->quantity; my $cust_pkg; if ( $opt->{'cust_pkg'} ) { @@ -2100,7 +2099,9 @@ The date for the package change. Required, and must be in the future. =item locationnum -The pkgpart and locationnum of the new package, with the same +=item quantity + +The pkgpart. locationnum, and quantity of the new package, with the same meaning as in C. =back @@ -2132,7 +2133,9 @@ sub change_later { if $opt->{'pkgpart'} and $opt->{'pkgpart'} != $change_to->pkgpart; my $new_locationnum = $opt->{'locationnum'} if $opt->{'locationnum'} and $opt->{'locationnum'} != $change_to->locationnum; - if ( $new_pkgpart or $new_locationnum ) { + my $new_quantity = $opt->{'quantity'} + if $opt->{'quantity'} and $opt->{'quantity'} != $change_to->quantity; + if ( $new_pkgpart or $new_locationnum or $new_quantity ) { # it hasn't been billed yet, so in principle we could just edit # it in place (w/o a package change), but that's bad form. # So change the package according to the new options... @@ -2170,12 +2173,16 @@ sub change_later { if $opt->{'pkgpart'} and $opt->{'pkgpart'} != $self->pkgpart; my $new_locationnum = $opt->{'locationnum'} if $opt->{'locationnum'} and $opt->{'locationnum'} != $self->locationnum; - return '' unless $new_pkgpart or $new_locationnum; # wouldn't do anything + my $new_quantity = $opt->{'quantity'} + if $opt->{'quantity'} and $opt->{'quantity'} != $self->quantity; + + return '' unless $new_pkgpart or $new_locationnum or $new_quantity; # wouldn't do anything my %hash = ( 'custnum' => $self->custnum, 'pkgpart' => ($opt->{'pkgpart'} || $self->pkgpart), 'locationnum' => ($opt->{'locationnum'} || $self->locationnum), + 'quantity' => ($opt->{'quantity'} || $self->quantity), 'start_date' => $date, ); my $new = FS::cust_pkg->new(\%hash); -- cgit v1.2.1