X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=88aceb935e23acf099c6acd2d523977de6f09156;hb=dd2249efe0daa3fc3257029de84d212aa89a4ee9;hp=78a41f7ae431eba49f06806a799b420b4172494e;hpb=e66bb1fd7c14904103fbf28daa1d9370ad36beba;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 78a41f7ae..88aceb935 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1910,6 +1910,25 @@ sub has_ship_address { scalar( grep { $self->getfield("ship_$_") ne '' } $self->addr_fields ); } +=item location_hash + +Returns a list of key/value pairs, with the following keys: address1, adddress2, +city, county, state, zip, country. The shipping address is used if present. + +=cut + +#geocode? dependent on tax-ship_address config, not available in cust_location +#mostly. not yet then. + +sub location_hash { + my $self = shift; + my $prefix = $self->has_ship_address ? 'ship_' : ''; + + map { $_ => $self->get($prefix.$_) } + qw( address1 address2 city county state zip country geocode ); + #fields that cust_location has +} + =item all_pkgs [ EXTRA_QSEARCH_PARAMS_HASHREF ] Returns all packages (see L) for this customer. @@ -1953,24 +1972,57 @@ sub cust_location { qsearch('cust_location', { 'custnum' => $self->custnum } ); } -=item location_label_short +=item location_label [ OPTION => VALUE ... ] + +Returns the label of the service location (see analog in L) for this customer. + +Options are + +=over 4 + +=item join_string + +used to separate the address elements (defaults to ', ') + +=item escape_function -Returns the short label of the service location (see analog in L) for this customer. +a callback used for escaping the text of the address elements + +=back =cut -# false laziness with FS::cust_location::line_short +# false laziness with FS::cust_location::line -sub location_label_short { +sub location_label { my $self = shift; + my %opt = @_; + + my $separator = $opt{join_string} || ', '; + my $escape = $opt{escape_function} || sub{ shift }; + my $line = ''; my $cydefault = FS::conf->new->config('countrydefault') || 'US'; + my $prefix = length($self->ship_last) ? 'ship_' : ''; - 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; + my $notfirst = 0; + foreach (qw ( address1 address2 ) ) { + my $method = "$prefix$_"; + $line .= ($notfirst ? $separator : ''). &$escape($self->$method) + if $self->$method; + $notfirst++; + } + $notfirst = 0; + foreach (qw ( city county state zip ) ) { + my $method = "$prefix$_"; + if ( $self->$method ) { + $line .= ' (' if $method eq 'county'; + $line .= ($notfirst ? ' ' : $separator). &$escape($self->$method); + $line .= ' )' if $method eq 'county'; + $notfirst++; + } + } + $line .= $separator. &$escape(code2country($self->country)) + if $self->country ne $cydefault; $line; } @@ -2036,7 +2088,7 @@ sub _cust_pkg { # This should be generalized to use config options to determine order. sub sort_packages { - my $locationsort = $a->locationnum <=> $b->locationnum; + my $locationsort = ( $a->locationnum || 0 ) <=> ( $b->locationnum || 0 ); return $locationsort if $locationsort; if ( $a->get('cancel') xor $b->get('cancel') ) { @@ -2393,33 +2445,33 @@ sub bill_and_collect { $error = $self->cancel_expired_pkgs( $options{actual_time} ); if ( $error ) { $error = "Error expiring custnum ". $self->custnum. ": $error"; - if ( $options{'fatal'} eq 'return' ) { return $error; } - elsif ( $options{'fatal'} ) { die $error; } - else { warn $error; } + if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } + elsif ( $options{fatal} ) { die $error; } + else { warn $error; } } $error = $self->suspend_adjourned_pkgs( $options{actual_time} ); if ( $error ) { $error = "Error adjourning custnum ". $self->custnum. ": $error"; - if ( $options{'fatal'} eq 'return' ) { return $error; } - elsif ( $options{'fatal'} ) { die $error; } - else { warn $error; } + if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } + elsif ( $options{fatal} ) { die $error; } + else { warn $error; } } $error = $self->bill( %options ); if ( $error ) { $error = "Error billing custnum ". $self->custnum. ": $error"; - if ( $options{'fatal'} eq 'return' ) { return $error; } - elsif ( $options{'fatal'} ) { die $error; } - else { warn $error; } + if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } + elsif ( $options{fatal} ) { die $error; } + else { warn $error; } } $error = $self->apply_payments_and_credits; if ( $error ) { $error = "Error applying custnum ". $self->custnum. ": $error"; - if ( $options{'fatal'} eq 'return' ) { return $error; } - elsif ( $options{'fatal'} ) { die $error; } - else { warn $error; } + if ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } + elsif ( $options{fatal} ) { die $error; } + else { warn $error; } } unless ( $conf->exists('cancelled_cust-noevents') @@ -2428,9 +2480,9 @@ sub bill_and_collect { $error = $self->collect( %options ); if ( $error ) { $error = "Error collecting custnum ". $self->custnum. ": $error"; - if ( $options{'fatal'} eq 'return' ) { return $error; } - elsif ( $options{'fatal'} ) { die $error; } - else { warn $error; } + if ($options{fatal} && $options{fatal} eq 'return') { return $error; } + elsif ($options{fatal} ) { die $error; } + else { warn $error; } } } @@ -3782,7 +3834,7 @@ sub due_cust_event { warn " invalid conditions not eliminated with condition_sql:\n". join('', map " $_: ".$unsat{$_}."\n", keys %unsat ) - if $DEBUG; # > 1; + if keys %unsat && $DEBUG; # > 1; ## # insert @@ -3963,6 +4015,8 @@ sub realtime_bop { warn " $_ => $options{$_}\n" foreach keys %options; } + return "Amount must be greater than 0" unless $amount > 0; + unless ( $options{'description'} ) { if ( $conf->exists('business-onlinepayment-description') ) { my $dtempl = $conf->config('business-onlinepayment-description'); @@ -4733,9 +4787,19 @@ sub realtime_refund_bop { ) { warn " attempting void\n" if $DEBUG > 1; my $void = new Business::OnlinePayment( $processor, @bop_options ); - $content{'card_number'} = $cust_pay->payinfo - if $cust_pay->payby eq 'CARD' - && $void->can('info') && $void->info('CC_void_requires_card'); + if ( $void->can('info') ) { + if ( $cust_pay->payby eq 'CARD' + && $void->info('CC_void_requires_card') ) + { + $content{'card_number'} = $cust_pay->payinfo + } elsif ( $cust_pay->payby eq 'CHEK' + && $void->info('ECHECK_void_requires_account') ) + { + ( $content{'account_number'}, $content{'routing_code'} ) = + split('@', $cust_pay->payinfo); + $content{'name'} = $self->get('first'). ' '. $self->get('last'); + } + } $void->content( 'action' => 'void', %content ); $void->submit(); if ( $void->is_success ) { @@ -4899,10 +4963,12 @@ sub _new_bop_required { my $botpp = 'Business::OnlineThirdPartyPayment'; return 1 - if ( $conf->config('business-onlinepayment-namespace') eq $botpp || - scalar( grep { $_->gateway_namespace eq $botpp } - qsearch( 'payment_gateway', { 'disabled' => '' } ) - ) + if ( ( $conf->exists('business-onlinepayment-namespace') + && $conf->config('business-onlinepayment-namespace') eq $botpp + ) + or scalar( grep { $_->gateway_namespace eq $botpp } + qsearch( 'payment_gateway', { 'disabled' => '' } ) + ) ) ; @@ -6074,9 +6140,19 @@ sub _new_realtime_refund_bop { ) { warn " attempting void\n" if $DEBUG > 1; my $void = new Business::OnlinePayment( $processor, @bop_options ); - $content{'card_number'} = $cust_pay->payinfo - if $cust_pay->payby eq 'CARD' - && $void->can('info') && $void->info('CC_void_requires_card'); + if ( $void->can('info') ) { + if ( $cust_pay->payby eq 'CARD' + && $void->info('CC_void_requires_card') ) + { + $content{'card_number'} = $cust_pay->payinfo; + } elsif ( $cust_pay->payby eq 'CHEK' + && $void->info('ECHECK_void_requires_account') ) + { + ( $content{'account_number'}, $content{'routing_code'} ) = + split('@', $cust_pay->payinfo); + $content{'name'} = $self->get('first'). ' '. $self->get('last'); + } + } $void->content( 'action' => 'void', %content ); $void->submit(); if ( $void->is_success ) { @@ -7244,7 +7320,7 @@ sub referral_cust_main_ncancelled { Like referral_cust_main, except returns a flat list of all unsuspended (and uncancelled) packages for each customer. The number of items in this list may -be useful for comission calculations (perhaps after a Cpkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ). +be useful for commission calculations (perhaps after a Cpkgpart; grep { $_ == $pkgpart } @commission_worthy_pkgparts> } $cust_main-> ). =cut @@ -7306,8 +7382,10 @@ sub credit { $cust_credit->set('reason', $reason) } - $cust_credit->addlinfo( delete $options{'addlinfo'} ) - if exists($options{'addlinfo'}); + for (qw( addlinfo eventnum )) { + $cust_credit->$_( delete $options{$_} ) + if exists($options{$_}); + } $cust_credit->insert(%options); @@ -7842,9 +7920,11 @@ sub geocode { ? 'ship_' : ''; - my ($zip,$plus4) = split /-/, $self->get("${prefix}zip") + my($zip,$plus4) = split /-/, $self->get("${prefix}zip") if $self->country eq 'US'; + $zip ||= ''; + $plus4 ||= ''; #CCH specific location stuff my $extra_sql = "AND plus4lo <= '$plus4' AND plus4hi >= '$plus4'"; @@ -8257,8 +8337,8 @@ sub _money_table_where { (Class method) -Returns a qsearch hash expression to search for parameters specified in HREF. -Valid parameters are +Returns a qsearch hash expression to search for parameters specified in +HASHREF. Valid parameters are =over 4