X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=1b663c9ae11a12b615ee0037a60523542646ca64;hb=8fda124d646333848b311c99263813c7d2466592;hp=80db9dd8f95844ced01fe81cde76bf1f103fd417;hpb=557a6bdc1302aa7addd313327dcf62bbc0533429;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 80db9dd8f..1b663c9ae 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1955,6 +1955,28 @@ sub cust_location { qsearch('cust_location', { 'custnum' => $self->custnum } ); } +=item location_label_short + +Returns the short label of the service location (see analog in L) for this customer. + +=cut + +# false laziness with FS::cust_location::line_short + +sub location_label_short { + my $self = shift; + my $cydefault = FS::conf->new->config('countrydefault') || 'US'; + + my $line = $self->address1; + #$line .= ', '. $self->address2 if $self->address2; + $line .= ', '. $self->city; + $line .= ', '. $self->state if $self->state; + $line .= ' '. $self->zip if $self->zip; + $line .= ' '. code2country($self->country) if $self->country ne $cydefault; + + $line; +} + =item ncancelled_pkgs [ EXTRA_QSEARCH_PARAMS_HASHREF ] Returns all non-cancelled packages (see L) for this customer. @@ -2016,6 +2038,9 @@ sub _cust_pkg { # This should be generalized to use config options to determine order. sub sort_packages { + my $locationsort = $a->locationnum <=> $b->locationnum; + return $locationsort if $locationsort; + if ( $a->get('cancel') xor $b->get('cancel') ) { return -1 if $b->get('cancel'); return 1 if $a->get('cancel'); @@ -6853,6 +6878,36 @@ sub balance_date { ); } +=item balance_date_range START_TIME [ END_TIME [ OPTION => VALUE ... ] ] + +Returns the balance for this customer, only considering invoices with date +earlier than START_TIME, and optionally not later than END_TIME +(total_owed_date minus total_unapplied_credits minus total_unapplied_payments). + +Times are specified as SQL fragments or numeric +UNIX timestamps; see L). Also see L and +L for conversion functions. The empty string can be passed +to disable that time constraint completely. + +Available options are: + +=over 4 + +=item unapplied_date + +set to true to disregard unapplied credits, payments and refunds outside the specified time period - by default the time period restriction only applies to invoices (useful for reporting, probably a bad idea for event triggering) + +=back + +=cut + +sub balance_date_range { + my $self = shift; + my $sql = 'SELECT SUM('. $self->balance_date_sql(@_). + ') FROM cust_main WHERE custnum='. $self->custnum; + sprintf( "%.2f", $self->scalar_sql($sql) ); +} + =item balance_pkgnum PKGNUM Returns the balance for this customer's specific package when using