X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fh_Common.pm;h=d55da8cfb3c529d36ab5a97a75a6dbd39a7aca23;hb=d33015393db77e9bc8e0deeb1a39500b3b5a49eb;hp=58ead88e4f0e12427009219e4e952ae45a7fee62;hpb=f7afca1829f8496509d10806439c37fcc1349135;p=freeside.git diff --git a/FS/FS/h_Common.pm b/FS/FS/h_Common.pm index 58ead88e4..d55da8cfb 100644 --- a/FS/FS/h_Common.pm +++ b/FS/FS/h_Common.pm @@ -2,6 +2,7 @@ package FS::h_Common; use strict; use FS::Record qw(dbdef); +use Carp qw(confess); =head1 NAME @@ -39,8 +40,13 @@ sub sql_h_search { my( $self, $end ) = ( shift, shift ); my $table = $self->table; - my $pkey = dbdef->table($table)->primary_key - or die "can't (yet) search history table $table without a primary key"; + my $real_table = ($table =~ /^h_(.*)$/) ? $1 : $table; + my $pkey = dbdef->table($real_table)->primary_key + or die "can't (yet) search history table $real_table without a primary key"; + + unless ($end) { + confess 'Called sql_h_search without END_TIMESTAMP'; + } my $notcancelled = ''; if ( scalar(@_) && $_[0] ) { @@ -64,11 +70,25 @@ sub sql_h_search { '', - 'maintable', + 'AS maintable', ); } +=item sql_h_searchs END_TIMESTAMP [ START_TIMESTAMP ] + +Like sql_h_search, but limited to the single most recent record (before +END_TIMESTAMP) + +=cut + +sub sql_h_searchs { + my $self = shift; + my($select, $where, $cacheobj, $as) = $self->sql_h_search(@_); + $where .= ' LIMIT 1'; + ($select, $where, $cacheobj, $as); +} + =back =head1 BUGS