From 1f9cad18af5742ee646a56bc0d5a40e6775eabab Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 31 Jul 2013 03:57:07 -0700 Subject: [PATCH] simple A/P --- FS/FS/vend_bill.pm | 19 +++++++++++++++---- httemplate/search/report_vend_bill.html | 11 +++++++++++ httemplate/search/vend_bill.html | 7 ++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/FS/FS/vend_bill.pm b/FS/FS/vend_bill.pm index cd20f9503..81de6949e 100644 --- a/FS/FS/vend_bill.pm +++ b/FS/FS/vend_bill.pm @@ -202,15 +202,26 @@ sub search { "vend_bill._date < $ending"; } + #_date + if ( $param->{payment_date} ) { + my($beginning, $ending) = @{$param->{payment_date}}; + + push @where, "vend_pay._date >= $beginning", + "vend_pay._date < $ending"; + } + my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : ''; - #my $count_query = "SELECT COUNT(*) FROM vend_bill $addl_from $extra_sql"; - my $count_query = "SELECT COUNT(*), SUM(charged) FROM vend_bill $extra_sql"; + #simplistic, but how we are for now + my $addl_from = ' LEFT JOIN vend_bill_pay USING (vendbillnum) '. + ' LEFT JOIN vend_pay USING (vendpaynum) '; + + my $count_query = "SELECT COUNT(*), SUM(charged) FROM vend_bill $addl_from $extra_sql"; +{ 'table' => 'vend_bill', - #'select' => $select, - #'addl_from' => $addl_from, + 'select' => 'vend_bill.*, vend_pay._date as payment_date', + 'addl_from' => $addl_from, 'hashref' => {}, 'extra_sql' => $extra_sql, 'order_by' => 'ORDER BY _date', diff --git a/httemplate/search/report_vend_bill.html b/httemplate/search/report_vend_bill.html index aec1bba8f..defda70ae 100644 --- a/httemplate/search/report_vend_bill.html +++ b/httemplate/search/report_vend_bill.html @@ -16,6 +16,17 @@ + + <% mt('Payment date') |h %> + + + <& /elements/tr-input-beginning_ending.html, + prefix => 'payment_date', + layout => 'horiz', + &> +
+ + diff --git a/httemplate/search/vend_bill.html b/httemplate/search/vend_bill.html index ddcc0c93e..33eb2241c 100644 --- a/httemplate/search/vend_bill.html +++ b/httemplate/search/vend_bill.html @@ -7,6 +7,7 @@ 'count_query' => $count_query, 'count_addl' => [ '$%.2f total', ], 'header' => [ 'Date', + 'Payment date', 'Vendor', 'Class', 'Amount', @@ -14,6 +15,7 @@ ], 'fields' => [ sub { time2str('%D', shift->_date) }, + sub { time2str('%D', shift->payment_date) }, sub { shift->vend_main->vendname }, sub { shift->vend_main->vend_class->classname }, 'charged', @@ -32,9 +34,12 @@ die "access denied" my %search = (); # begin/end/beginning/ending -my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, ''); +my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '_date'); $search{'_date'} = [ $beginning, $ending ]; +($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'payment_date'); +$search{'payment_date'} = [ $beginning, $ending ]; + my $query = FS::vend_bill->search( \%search ); my $count_query = delete( $query->{'count_query'} ); -- 2.11.0