X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_bill.pm;h=dda5d81e96437e2bdd5dfc2f6ddfc00c88aa092c;hb=a83f6bb859327c0ff55d6aa30e39e8a0f657be75;hp=fda1c7287fa3f8f830097dfc6e09ab9964c961fa;hpb=4532048fddaf20751dda7721ee6bab4bac8755ac;p=freeside.git diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index fda1c7287..dda5d81e9 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -1,5 +1,7 @@ package FS::cust_bill; -use base qw( FS::Template_Mixin FS::cust_main_Mixin FS::Record ); +use base qw( FS::cust_bill::Search FS::Template_Mixin + FS::cust_main_Mixin FS::Record + ); use strict; use vars qw( $DEBUG $me ); @@ -100,23 +102,19 @@ L and L for conversion functions. =back -Customer info at invoice generation time +Deprecated fields =over 4 -=item billing_balance - the customer's balance at the time the invoice was -generated (not including charges on this invoice) - -=item previous_balance - the billing_balance of this customer's previous -invoice plus the charges on that invoice - -=back - -Deprecated +=item billing_balance - the customer's balance immediately before generating +this invoice. DEPRECATED. Use the L method +to determine the customer's balance at a specific time. -=over 4 +=item previous_balance - the customer's balance immediately after generating +the invoice before this one. DEPRECATED. -=item printed - deprecated +=item printed - formerly used to track the number of times an invoice had +been printed; no longer used. =back @@ -1569,6 +1567,8 @@ sub fax_invoice { Place this invoice into the open batch (see C). If there isn't an open batch, one will be created. +HASHREF may contain any options to be passed to C. + =cut sub batch_invoice { @@ -2458,13 +2458,20 @@ sub invoice_barcode { =item invnum_date_pretty Returns a string with the invoice number and date, for example: -"Invoice #54 (3/20/2008)" +"Invoice #54 (3/20/2008)". + +Intended for back-end context, with regard to translation and date formatting. =cut +#note: this uses _date_pretty_unlocalized because _date_pretty is too expensive +# for backend use (and also does the wrong thing, localizing for end customer +# instead of backoffice configured date format) sub invnum_date_pretty { my $self = shift; - $self->mt('Invoice #'). $self->invnum. ' ('. $self->_date_pretty. ')'; + #$self->mt('Invoice #'). + 'Invoice #'. #XXX should be translated ala web UI user (not invoice customer) + $self->invnum. ' ('. $self->_date_pretty_unlocalized. ')'; } #sub _items_extra_usage_sections { @@ -3364,6 +3371,13 @@ Currently only supported on PostgreSQL. =cut sub due_date_sql { + die "don't use: doesn't account for agent-specific invoice_default_terms"; + + #we're passed a $conf but not a specific customer (that's in the query), so + # to make this work we'd need an agentnum-aware "condition_sql_conf" like + # "condition_sql_option" that retreives a conf value with SQL in an agent- + # aware fashion + my $conf = new FS::Conf; 'COALESCE( SUBSTRING( @@ -3376,219 +3390,6 @@ sub due_date_sql { ) * 86400 + cust_bill._date' } -=item search_sql_where HASHREF - -Class method which returns an SQL WHERE fragment to search for parameters -specified in HASHREF. Valid parameters are - -=over 4 - -=item _date - -List reference of start date, end date, as UNIX timestamps. - -=item invnum_min - -=item invnum_max - -=item agentnum - -=item charged - -List reference of charged limits (exclusive). - -=item owed - -List reference of charged limits (exclusive). - -=item open - -flag, return open invoices only - -=item net - -flag, return net invoices only - -=item days - -=item newest_percust - -=item custnum - -Return only invoices belonging to that customer. - -=item cust_classnum - -Limit to that customer class (single value or arrayref). - -=item payby - -Limit to customers with that payment method (single value or arrayref). - -=item refnum - -Limit to customers with that advertising source. - -=back - -Note: validates all passed-in data; i.e. safe to use with unchecked CGI params. - -=cut - -sub search_sql_where { - my($class, $param) = @_; - if ( $DEBUG ) { - warn "$me search_sql_where called with params: \n". - join("\n", map { " $_: ". $param->{$_} } keys %$param ). "\n"; - } - - my @search = (); - - #agentnum - if ( $param->{'agentnum'} =~ /^(\d+)$/ ) { - push @search, "cust_main.agentnum = $1"; - } - - #refnum - if ( $param->{'refnum'} =~ /^(\d+)$/ ) { - push @search, "cust_main.refnum = $1"; - } - - #custnum - if ( $param->{'custnum'} =~ /^(\d+)$/ ) { - push @search, "cust_bill.custnum = $1"; - } - - #customer classnum (false laziness w/ cust_main/Search.pm) - if ( $param->{'cust_classnum'} ) { - - my @classnum = ref( $param->{'cust_classnum'} ) - ? @{ $param->{'cust_classnum'} } - : ( $param->{'cust_classnum'} ); - - @classnum = grep /^(\d*)$/, @classnum; - - if ( @classnum ) { - push @search, '( '. join(' OR ', map { - $_ ? "cust_main.classnum = $_" - : "cust_main.classnum IS NULL" - } - @classnum - ). - ' )'; - } - - } - - #payby - if ( $param->{payby} ) { - my $payby = $param->{payby}; - $payby = [ $payby ] unless ref $payby; - my $payby_in = join(',', map {dbh->quote($_)} @$payby); - push @search, "cust_main.payby IN($payby_in)" if length($payby_in); - } - - #_date - if ( $param->{_date} ) { - my($beginning, $ending) = @{$param->{_date}}; - - push @search, "cust_bill._date >= $beginning", - "cust_bill._date < $ending"; - } - - #invnum - if ( $param->{'invnum_min'} =~ /^(\d+)$/ ) { - push @search, "cust_bill.invnum >= $1"; - } - if ( $param->{'invnum_max'} =~ /^(\d+)$/ ) { - push @search, "cust_bill.invnum <= $1"; - } - - #charged - if ( $param->{charged} ) { - my @charged = ref($param->{charged}) - ? @{ $param->{charged} } - : ($param->{charged}); - - push @search, map { s/^charged/cust_bill.charged/; $_; } - @charged; - } - - my $owed_sql = FS::cust_bill->owed_sql; - - #owed - if ( $param->{owed} ) { - my @owed = ref($param->{owed}) - ? @{ $param->{owed} } - : ($param->{owed}); - push @search, map { s/^owed/$owed_sql/; $_; } - @owed; - } - - #open/net flags - push @search, "0 != $owed_sql" - if $param->{'open'}; - push @search, '0 != '. FS::cust_bill->net_sql - if $param->{'net'}; - - #days - push @search, "cust_bill._date < ". (time-86400*$param->{'days'}) - if $param->{'days'}; - - #newest_percust - if ( $param->{'newest_percust'} ) { - - #$distinct = 'DISTINCT ON ( cust_bill.custnum )'; - #$orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC'; - - my @newest_where = map { my $x = $_; - $x =~ s/\bcust_bill\./newest_cust_bill./g; - $x; - } - grep ! /^cust_main./, @search; - my $newest_where = scalar(@newest_where) - ? ' AND '. join(' AND ', @newest_where) - : ''; - - - push @search, "cust_bill._date = ( - SELECT(MAX(newest_cust_bill._date)) FROM cust_bill AS newest_cust_bill - WHERE newest_cust_bill.custnum = cust_bill.custnum - $newest_where - )"; - - } - - #promised_date - also has an option to accept nulls - if ( $param->{promised_date} ) { - my($beginning, $ending, $null) = @{$param->{promised_date}}; - - push @search, "(( cust_bill.promised_date >= $beginning AND ". - "cust_bill.promised_date < $ending )" . - ($null ? ' OR cust_bill.promised_date IS NULL ) ' : ')'); - } - - #agent virtualization - my $curuser = $FS::CurrentUser::CurrentUser; - if ( $curuser->username eq 'fs_queue' - && $param->{'CurrentUser'} =~ /^(\w+)$/ ) { - my $username = $1; - my $newuser = qsearchs('access_user', { - 'username' => $username, - 'disabled' => '', - } ); - if ( $newuser ) { - $curuser = $newuser; - } else { - warn "$me WARNING: (fs_queue) can't find CurrentUser $username\n"; - } - } - push @search, $curuser->agentnums_sql; - - join(' AND ', @search ); - -} - =back =head1 BUGS