From: Ivan Kohler Date: Wed, 19 Jun 2013 22:29:55 +0000 (-0700) Subject: Merge branch 'master' of git.freeside.biz:/home/git/freeside X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a6dd5bc6ba6c655b1707a016db4e97e269b718e5;hp=66906f54d1099dcae84e69240c3a16bc9a82c37f Merge branch 'master' of git.freeside.biz:/home/git/freeside --- diff --git a/FS/FS/h_cust_pkg.pm b/FS/FS/h_cust_pkg.pm index e796f4145..99037c22f 100644 --- a/FS/FS/h_cust_pkg.pm +++ b/FS/FS/h_cust_pkg.pm @@ -20,6 +20,79 @@ FS::h_cust_pkg - Historical record of customer package changes An FS::h_cust_pkg object represents historical changes to packages. FS::h_cust_pkg inherits from FS::h_Common and FS::cust_pkg. +=head1 CLASS METHODS + +=over 4 + +=item search HASHREF + +Like L, but adapted for searching historical records. +Takes the additional parameter "date", which is the timestamp to perform +the search "as of" (i.e. search the most recent insert or replace_new record +for each pkgnum that is not later than that date). + +=cut + +sub search { + my ($class, $params) = @_; + my $date = delete $params->{'date'}; + $date =~ /^\d*$/ or die "invalid search date '$date'\n"; + + my $query = FS::cust_pkg->search($params); + + # allow multiple status criteria + # this might be useful in the base cust_pkg search, but I haven't + # tested it there yet + my $status = delete $params->{'status'}; + if( $status ) { + my @status_where; + foreach ( split(',', $status) ) { + if ( /^active$/ ) { + push @status_where, $class->active_sql(); + } elsif ( /^not[ _]yet[ _]billed$/ ) { + push @status_where, $class->not_yet_billed_sql(); + } elsif ( /^(one-time charge|inactive)$/ ) { + push @status_where, $class->inactive_sql(); + } elsif ( /^suspended$/ ) { + push @status_where, $class->suspended_sql(); + } elsif ( /^cancell?ed$/ ) { + push @status_where, $class->cancelled_sql(); + } + } + if ( @status_where ) { + $query->{'extra_sql'} .= ' AND ('.join(' OR ', @status_where).')'; + $query->{'count_query'} .= ' AND ('.join(' OR ', @status_where).')'; + } + } + + # make some adjustments + $query->{'table'} = 'h_cust_pkg'; + foreach (qw(select addl_from extra_sql count_query)) { + $query->{$_} =~ s/cust_pkg\b/h_cust_pkg/g; + $query->{$_} =~ s/cust_main\b/h_cust_main/g; + } + + my $and_where = " AND h_cust_pkg.historynum = + (SELECT historynum FROM h_cust_pkg AS mostrecent + WHERE mostrecent.pkgnum = h_cust_pkg.pkgnum + AND mostrecent.history_date <= $date + AND mostrecent.history_action IN ('insert', 'replace_new') + ORDER BY history_date DESC,historynum DESC LIMIT 1 + ) AND h_cust_main.historynum = + (SELECT historynum FROM h_cust_main AS mostrecent + WHERE mostrecent.custnum = h_cust_main.custnum + AND mostrecent.history_date <= h_cust_pkg.history_date + AND mostrecent.history_action IN ('insert', 'replace_new') + ORDER BY history_date DESC,historynum DESC LIMIT 1 + )"; + + $query->{'extra_sql'} .= $and_where; + $query->{'count_query'} .= $and_where; + + $query; +} + + =head1 BUGS =head1 SEE ALSO diff --git a/httemplate/edit/cust_location.cgi b/httemplate/edit/cust_location.cgi index b90ba66b8..93ce32382 100755 --- a/httemplate/edit/cust_location.cgi +++ b/httemplate/edit/cust_location.cgi @@ -18,6 +18,7 @@ ACTION="<% $p %>edit/process/cust_location.cgi" METHOD=POST> <& /elements/standardize_locations.html, 'form' => 'EditLocationForm', 'callback' => 'document.EditLocationForm.submit();', + 'with_census' => 1, &> @@ -31,6 +32,10 @@ function go() { document.EditLocationForm.submit(); % } } + +function submit_abort() { + nd(1); +} diff --git a/httemplate/elements/standardize_locations.js b/httemplate/elements/standardize_locations.js index e98039d9d..d7c36701e 100644 --- a/httemplate/elements/standardize_locations.js +++ b/httemplate/elements/standardize_locations.js @@ -11,13 +11,13 @@ function form_address_info() { % if ( $billship ) { returnobj['same'] = cf.elements['same'].checked; % } -% if ( $withfirm ) { -% # not part of either address, really - returnobj['company'] = cf.elements['company'].value; -% } % if ( $withcensus ) { % # "entered" censustract always goes with the ship_ address if there is one - returnobj['ship_censustract'] = cf.elements['enter_censustract'].value; +% if ( $billship ) { + returnobj['ship_censustract'] = cf.elements['enter_censustract'].value; +% } else { # there's only a package address, so it's just "censustract" + returnobj['censustract'] = cf.elements['enter_censustract'].value; +% } % } % for my $pre (@prefixes) { if ( <% $pre eq 'ship_' ? 1 : 0 %> && returnobj['same'] ) { @@ -78,6 +78,7 @@ function standardize_locations() { % # censustract so that we don't ask the user to confirm it again. if ( !changed && <% $withcensus %> ) { +% if ( $billship ) { if ( address_info['same'] ) { cf.elements['bill_censustract'].value = address_info['bill_censustract']; @@ -85,6 +86,10 @@ function standardize_locations() { cf.elements['ship_censustract'].value = address_info['ship_censustract']; } +% } else { + cf.elements['censustract'].value = + address_info['censustract']; +% } } % if ( $conf->config('address_standardize_method') ) { @@ -176,6 +181,7 @@ function confirm_manual_address() { %# not much to do in this case, just confirm the censustract % if ( $withcensus ) { var cf = document.<% $formname %>; +% if ( $billship ) { if ( cf.elements['same'] && cf.elements['same'].checked ) { cf.elements['bill_censustract'].value = cf.elements['enter_censustract'].value; @@ -183,6 +189,9 @@ function confirm_manual_address() { cf.elements['ship_censustract'].value = cf.elements['enter_censustract'].value; } +% } else { + cf.elements['censustract'].value = cf.elements['enter_censustract'].value; +% } % } post_standardization(); } @@ -277,12 +286,13 @@ function setselect(el, value) { my %opt = @_; my $conf = new FS::Conf; -my $withfirm = $opt{'with_firm'} ? 1 : 0; my $withcensus = $opt{'with_census'} ? 1 : 0; my @prefixes = ''; my $billship = $opt{'billship'} ? 1 : 0; # whether to have bill_ and ship_ prefixes my $taxpre = ''; +# probably should just geocode both addresses, since either one could +# be a package address in the future if ($billship) { @prefixes = qw(bill_ ship_); $taxpre = $conf->exists('tax-ship_address') ? 'ship_' : 'bill_'; diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html index 780bf96ad..e1fa825c1 100644 --- a/httemplate/elements/tr-select-cust_location.html +++ b/httemplate/elements/tr-select-cust_location.html @@ -209,6 +209,7 @@ Example: 'no_bold' => $opt{'no_bold'}, 'alt_format' => $opt{'alt_format'}, 'enable_coords'=> 1, + 'enable_censustract' => 1, ) %>