diff options
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/Report/Table/Monthly.pm | 137 | ||||
-rw-r--r-- | FS/FS/cust_bill_pay.pm | 3 | ||||
-rw-r--r-- | FS/FS/cust_credit_refund.pm | 4 | ||||
-rw-r--r-- | FS/FS/cust_refund.pm | 4 | ||||
-rw-r--r-- | FS/FS/payby.pm | 2 | ||||
-rw-r--r-- | FS/FS/payinfo_Mixin.pm | 48 |
6 files changed, 123 insertions, 75 deletions
diff --git a/FS/FS/Report/Table/Monthly.pm b/FS/FS/Report/Table/Monthly.pm index 6daa02637..d75f0be79 100644 --- a/FS/FS/Report/Table/Monthly.pm +++ b/FS/FS/Report/Table/Monthly.pm @@ -1,7 +1,7 @@ package FS::Report::Table::Monthly; use strict; -use vars qw( @ISA $expenses_kludge ); +use vars qw( @ISA ); use Time::Local; use FS::UID qw( dbh ); use FS::Report::Table; @@ -9,8 +9,6 @@ use FS::CurrentUser; @ISA = qw( FS::Report::Table ); -$expenses_kludge = 0; - =head1 NAME FS::Report::Table::Monthly - Tables of report data, indexed monthly @@ -142,70 +140,24 @@ sub invoiced { #invoiced sub netsales { #net sales my( $self, $speriod, $eperiod, $agentnum ) = @_; - my $credited = $self->scalar_sql(" - SELECT SUM(cust_credit_bill.amount) - FROM cust_credit_bill - LEFT JOIN cust_bill USING ( invnum ) - LEFT JOIN cust_main USING ( custnum ) - WHERE ". $self->in_time_period_and_agent( $speriod, - $eperiod, - $agentnum, - 'cust_bill._date' - ) - ); - - #horrible local kludge - my $expenses = !$expenses_kludge ? 0 : $self->scalar_sql(" - SELECT SUM(cust_bill_pkg.setup) - FROM cust_bill_pkg - LEFT JOIN cust_bill USING ( invnum ) - LEFT JOIN cust_main USING ( custnum ) - LEFT JOIN cust_pkg USING ( pkgnum ) - LEFT JOIN part_pkg USING ( pkgpart ) - WHERE ". $self->in_time_period_and_agent( $speriod, - $eperiod, - $agentnum, - 'cust_bill._date' - ). " - AND LOWER(part_pkg.pkg) LIKE 'expense _%' - "); - - $self->invoiced($speriod,$eperiod,$agentnum) - $credited - $expenses; + $self->invoiced($speriod,$eperiod,$agentnum) + - $self->credits( $speriod,$eperiod,$agentnum); } #deferred revenue -sub receipts { #cashflow +sub cashflow { my( $self, $speriod, $eperiod, $agentnum ) = @_; - my $refunded = $self->scalar_sql(" - SELECT SUM(refund) - FROM cust_refund - LEFT JOIN cust_main USING ( custnum ) - WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum) - ); + $self->payments($speriod, $eperiod, $agentnum) + - $self->refunds( $speriod, $eperiod, $agentnum); +} - #horrible local kludge that doesn't even really work right - my $expenses = !$expenses_kludge ? 0 : $self->scalar_sql(" - SELECT SUM(cust_bill_pay.amount) - FROM cust_bill_pay - LEFT JOIN cust_bill USING ( invnum ) - LEFT JOIN cust_main USING ( custnum ) - WHERE ". $self->in_time_period_and_agent( $speriod, - $eperiod, - $agentnum, - 'cust_bill_pay._date' - ). " - AND 0 < ( SELECT COUNT(*) from cust_bill_pkg, cust_pkg, part_pkg - WHERE cust_bill.invnum = cust_bill_pkg.invnum - AND cust_pkg.pkgnum = cust_bill_pkg.pkgnum - AND cust_pkg.pkgpart = part_pkg.pkgpart - AND LOWER(part_pkg.pkg) LIKE 'expense _%' - ) - "); - # my $expenses_sql2 = "SELECT SUM(cust_bill_pay.amount) FROM cust_bill_pay, cust_bill_pkg, cust_bill, cust_pkg, part_pkg WHERE cust_bill_pay.invnum = cust_bill.invnum AND cust_bill.invnum = cust_bill_pkg.invnum AND cust_bill_pay._date >= $speriod AND cust_bill_pay._date < $eperiod AND cust_pkg.pkgnum = cust_bill_pkg.pkgnum AND cust_pkg.pkgpart = part_pkg.pkgpart AND LOWER(part_pkg.pkg) LIKE 'expense _%'"; - - $self->payments($speriod, $eperiod, $agentnum) - $refunded - $expenses; +sub netcashflow { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + + $self->receipts($speriod, $eperiod, $agentnum) + - $self->netrefunds( $speriod, $eperiod, $agentnum); } sub payments { @@ -228,6 +180,16 @@ sub credits { ); } +sub refunds { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $self->scalar_sql(" + SELECT SUM(refund) + FROM cust_refund + LEFT JOIN cust_main USING ( custnum ) + WHERE ". $self->in_time_period_and_agent($speriod, $eperiod, $agentnum) + ); +} + sub netcredits { my( $self, $speriod, $eperiod, $agentnum ) = @_; $self->scalar_sql(" @@ -243,6 +205,36 @@ sub netcredits { ); } +sub receipts { #net payments + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $self->scalar_sql(" + SELECT SUM(cust_bill_pay.amount) + FROM cust_bill_pay + LEFT JOIN cust_bill USING ( invnum ) + LEFT JOIN cust_main USING ( custnum ) + WHERE ". $self->in_time_period_and_agent( $speriod, + $eperiod, + $agentnum, + 'cust_bill._date' + ) + ); +} + +sub netrefunds { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $self->scalar_sql(" + SELECT SUM(cust_credit_refund.amount) + FROM cust_credit_refund + LEFT JOIN cust_credit USING ( crednum ) + LEFT JOIN cust_main USING ( custnum ) + WHERE ". $self->in_time_period_and_agent( $speriod, + $eperiod, + $agentnum, + 'cust_credit._date' + ) + ); +} + #these should be auto-generated or $AUTOLOADed or something sub invoiced_12mo { my( $self, $speriod, $eperiod, $agentnum ) = @_; @@ -280,6 +272,31 @@ sub netcredits_12mo { $self->netcredits($speriod, $eperiod, $agentnum); } +sub cashflow_12mo { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $speriod = $self->_subtract_11mo($speriod); + $self->cashflow($speriod, $eperiod, $agentnum); +} + +sub netcashflow_12mo { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $speriod = $self->_subtract_11mo($speriod); + $self->cashflow($speriod, $eperiod, $agentnum); +} + +sub refunds_12mo { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $speriod = $self->_subtract_11mo($speriod); + $self->refunds($speriod, $eperiod, $agentnum); +} + +sub netrefunds_12mo { + my( $self, $speriod, $eperiod, $agentnum ) = @_; + $speriod = $self->_subtract_11mo($speriod); + $self->netrefunds($speriod, $eperiod, $agentnum); +} + + #not being too bad with the false laziness use Time::Local qw(timelocal); sub _subtract_11mo { diff --git a/FS/FS/cust_bill_pay.pm b/FS/FS/cust_bill_pay.pm index 74a8bcdd4..b7ba2b711 100644 --- a/FS/FS/cust_bill_pay.pm +++ b/FS/FS/cust_bill_pay.pm @@ -3,11 +3,12 @@ package FS::cust_bill_pay; use strict; use vars qw( @ISA $conf ); use FS::Record qw( qsearchs ); +use FS::cust_main_Mixin; use FS::cust_bill_ApplicationCommon; use FS::cust_bill; use FS::cust_pay; -@ISA = qw( FS::cust_bill_ApplicationCommon ); +@ISA = qw( FS::cust_main_Mixin FS::cust_bill_ApplicationCommon ); #ask FS::UID to run this stuff for us later FS::UID->install_callback( sub { diff --git a/FS/FS/cust_credit_refund.pm b/FS/FS/cust_credit_refund.pm index f237efed2..9fc03f2d3 100644 --- a/FS/FS/cust_credit_refund.pm +++ b/FS/FS/cust_credit_refund.pm @@ -3,11 +3,11 @@ package FS::cust_credit_refund; use strict; use vars qw( @ISA ); use FS::Record qw( qsearch qsearchs dbh ); -#use FS::UID qw(getotaker); +use FS::cust_main_Mixin; use FS::cust_credit; use FS::cust_refund; -@ISA = qw( FS::Record ); +@ISA = qw( FS::cust_main_Mixin FS::Record ); =head1 NAME diff --git a/FS/FS/cust_refund.pm b/FS/FS/cust_refund.pm index 498179553..e075e3ed5 100644 --- a/FS/FS/cust_refund.pm +++ b/FS/FS/cust_refund.pm @@ -11,7 +11,7 @@ use FS::cust_pay_refund; use FS::cust_main; use FS::payinfo_Mixin; -@ISA = qw( FS::Record FS::payinfo_Mixin ); +@ISA = qw( FS::payinfo_Mixin FS::cust_main_Mixin FS::Record ); @encrypted_fields = ('payinfo'); @@ -216,7 +216,7 @@ sub delete { =item replace OLD_RECORD -Currently unimplemented (accounting reasons). +Modifying a refund? Well, don't say I didn't warn you. =cut diff --git a/FS/FS/payby.pm b/FS/FS/payby.pm index 6684c95f0..349d266a3 100644 --- a/FS/FS/payby.pm +++ b/FS/FS/payby.pm @@ -124,7 +124,7 @@ sub can_payby { #return "Illegal payby" unless $hash{$payby}; return 0 unless $hash{$payby}; - $table = 'cust_pay' if $table eq 'cust_pay_batch' || $table eq 'cust_refund'; + $table = 'cust_pay' if $table =~ /^cust_(pay_pending|pay_batch|pay_void|refund)$/; return 0 if exists( $hash{$payby}->{$table} ); return 1; diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm index bdfe6c950..fb56371e3 100644 --- a/FS/FS/payinfo_Mixin.pm +++ b/FS/FS/payinfo_Mixin.pm @@ -22,9 +22,7 @@ This class handles the following functions for payinfo... Payment Mask (Generation and Storage) Data Validation (parent checks need to be sure to call this) -Encryption - In the Future (Pull from Record.pm) -Bad Card Stuff - In the Future (Integrate Banned Pay) -Currency - In the Future +Pretty printing =head1 FIELDS @@ -182,11 +180,6 @@ sub mask_payinfo { return $paymask; } -=cut - -sub _mask_payinfo { - my $self = shift; - =item payinfo_check Checks payby and payinfo. @@ -244,9 +237,46 @@ sub payinfo_check { } +=item payby_payinfo_pretty + +Returns payment method and information (suitably masked, if applicable) as +a human-readable string, such as: + + Card #54xxxxxxxxxxxx32 + +or + + Check #119006 + +=cut + +sub payby_payinfo_pretty { + my $self = shift; + if ( $self->payby eq 'CARD' ) { + 'Card #'. $self->paymask; + } elsif ( $self->payby eq 'CHEK' ) { + 'E-check acct#'. $self->payinfo; + } elsif ( $self->payby eq 'BILL' ) { + 'Check #'. $self->payinfo; + } elsif ( $self->payby eq 'PREP' ) { + 'Prepaid card #'. $self->payinfo; + } elsif ( $self->payby eq 'CASH' ) { + 'Cash '. $self->payinfo; + } elsif ( $self->payby eq 'WEST' ) { + 'Western Union'; #. $self->payinfo; + } elsif ( $self->payby eq 'MCRD' ) { + 'Manual credit card'; #. $self->payinfo; + } else { + $self->payby. ' '. $self->payinfo; + } +} + =head1 BUGS -Have to add the future items... +Future items? + Encryption - In the Future (Pull from Record.pm) + Bad Card Stuff - In the Future (Integrate Banned Pay) + Currency - In the Future =head1 SEE ALSO |