X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_void.pm;h=b9db81b93379559193778421a45d79b9d348ea87;hb=76d6fe17d02b77301619065ad43d7300432e977c;hp=cce77b3aa7376a0fa6e428d28f5705aafbd733a1;hpb=bec3b6c2bf97d66b992866d7ee7295f1f05452e6;p=freeside.git diff --git a/FS/FS/cust_bill_void.pm b/FS/FS/cust_bill_void.pm index cce77b3aa..b9db81b93 100644 --- a/FS/FS/cust_bill_void.pm +++ b/FS/FS/cust_bill_void.pm @@ -3,7 +3,6 @@ use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::otaker_Mixin FS::Record use strict; use FS::Record qw( qsearch qsearchs dbh fields ); -use FS::cust_main; use FS::cust_statement; use FS::access_user; use FS::cust_bill_pkg_void; @@ -248,24 +247,82 @@ sub void_access_user { =item cust_main +=item cust_bill_pkg + =cut -sub cust_main { +sub cust_bill_pkg { #actually cust_bill_pkg_void objects my $self = shift; - qsearchs('cust_main', { 'custnum' => $self->custnum } ); + qsearch('cust_bill_pkg_void', { invnum=>$self->invnum }); } -=item cust_bill_pkg +=back + +=item cust_pkg + +Returns the packages (see L) corresponding to the line items for +this invoice. =cut -sub cust_bill_pkg { #actually cust_bill_pkg_void objects +sub cust_pkg { my $self = shift; - qsearch('cust_bill_pkg_void', { invnum=>$self->invnum }); + my @cust_pkg = map { $_->pkgnum > 0 ? $_->cust_pkg : () } + $self->cust_bill_pkg; + my %saw = (); + grep { ! $saw{$_->pkgnum}++ } @cust_pkg; } +=item search_sql_where HASHREF + +Class method which returns an SQL WHERE fragment to search for parameters +specified in HASHREF. Accepts the following parameters for +L: C<_date>, C, C, +C, C, C, C. Also +accepts the following: + +=over 4 + +=item void_date + +Arrayref of start and end date to find invoices voided in a date range. + +=item void_usernum + +User identifier (L key) that voided the invoice. + =back +=cut + +sub search_sql_where { + my($class, $param) = @_; + + my $cust_bill_param = { + map { $_ => $param->{$_} } + grep { exists($param->{$_}) } + qw( _date invnum_min invnum_max agentnum custnum cust_classnum + refnum ) + }; + my $search_sql = FS::cust_bill->search_sql_where($cust_bill_param); + $search_sql =~ s/cust_bill/cust_bill_void/g; + my @search = ($search_sql); + + if ( $param->{void_date} ) { + my($beginning, $ending) = @{$param->{void_date}}; + push @search, "cust_bill_void.void_date >= $beginning", + "cust_bill_void.void_date < $ending"; + } + + if ( $param->{void_usernum} =~ /^(\d+)$/ ) { + my $usernum = $1; + push @search, "cust_bill_void.void_usernum = $1"; + } + + join(" AND ", @search); +} + + =item enable_previous =cut