X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_bill_pkg_discount.html;h=6da5787a005f6fe9badaf70b7678f95fc7dda2aa;hb=c0c5709fb022b83a482d0b35f7094505766d5868;hp=088b29115cc2082e8e06be083b093d385f60ed9c;hpb=624b2d44625f69d71175c3348cae635d580c890b;p=freeside.git diff --git a/httemplate/search/cust_bill_pkg_discount.html b/httemplate/search/cust_bill_pkg_discount.html index 088b29115..6da5787a0 100644 --- a/httemplate/search/cust_bill_pkg_discount.html +++ b/httemplate/search/cust_bill_pkg_discount.html @@ -1,4 +1,4 @@ -<% include( 'elements/search.html', +<& elements/search.html, 'title' => 'Discounts', 'name' => 'discounts', 'query' => $query, @@ -7,6 +7,7 @@ 'header' => [ #'#', 'Discount', + 'Class', 'Amount', 'Months', 'Package', @@ -17,6 +18,7 @@ 'fields' => [ #'billpkgdiscountnum', sub { $_[0]->cust_pkg_discount->discount->description }, + sub { $_[0]->cust_pkg_discount->discount->classname }, sub { sprintf($money_char.'%.2f', shift->amount ) }, sub { my $m = shift->months; $m =~ /\./ ? sprintf('%.2f', $m) : $m; @@ -26,12 +28,22 @@ sub { time2str('%b %d %Y', shift->_date ) }, \&FS::UI::Web::cust_fields, ], + 'sort_fields' => [ + '', + '', + 'amount', + 'months', + 'pkg', + 'invnum', + '_date', + ], 'links' => [ #'', '', #link to customer discount??? '', '', '', + '', $ilink, $ilink, ( map { $_ ne 'Cust. Status' ? $clink : '' } @@ -39,7 +51,7 @@ ), ], #'align' => 'rlrrrc'.FS::UI::Web::cust_aligns(), - 'align' => 'lrrlrr'.FS::UI::Web::cust_aligns(), + 'align' => 'lcrrlrr'.FS::UI::Web::cust_aligns(), 'color' => [ #'', '', @@ -48,6 +60,7 @@ '', '', '', + '', FS::UI::Web::cust_colors(), ], 'style' => [ @@ -58,10 +71,11 @@ '', '', '', + '', FS::UI::Web::cust_styles(), ], - ) -%> + +&> <%init> #a little false laziness below w/cust_bill_pkg.cgi @@ -85,7 +99,56 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { push @where, "cust_main.agentnum = $1"; } -# #classnum +#usernum +if ( $cgi->param('usernum') =~ /^(\d+)$/ ) { + push @where, "cust_pkg_discount.usernum = $1"; +} + +# (discount) classnum +my $join_discount = ''; +#false laziness w/cust_pkg_discount.html and cust_pkg.pm::search +if ( grep { $_ eq 'discount_classnum' } $cgi->param ) { + +# my @classnum = (); +# if ( ref($params->{'discount_classnum'}) ) { +# +# if ( ref($params->{'discount_classnum'}) eq 'HASH' ) { +# @classnum = grep $params->{'discount_classnum'}{$_}, keys %{ $params->{'discount_classnum'} }; +# } elsif ( ref($params->{'discount_classnum'}) eq 'ARRAY' ) { +# @classnum = @{ $params->{'discount_classnum'} }; +# } else { +# die 'unhandled discount_classnum ref '. $params->{'discount_classnum'}; +# } +# +# +# } elsif ( $params->{'discount_classnum'} =~ /^(\d*)$/ && $1 ne '0' ) { +# @classnum = ( $1 ); +# } +# +# if ( @classnum ) { + + if ( $cgi->param('discount_classnum') =~ /^(\d*)$/ && $1 ne '0' ) { + my @classnum = ( $1 ); + + $join_discount = 'LEFT JOIN discount USING (discountnum)'; + + my @c_where = (); + my @nums = grep $_, @classnum; + push @c_where, 'discount.classnum IN ('. join(',',@nums). ')' if @nums; + my $null = scalar( grep { $_ eq '' } @classnum ); + push @c_where, 'discount.classnum IS NULL' if $null; + + if ( scalar(@c_where) == 1 ) { + push @where, @c_where; + } elsif ( @c_where ) { + push @where, ' ( '. join(' OR ', @c_where). ' ) '; + } + + } + +} + +# #(package) classnum # # not specified: all classes # # 0: empty class # # N: classnum @@ -108,20 +171,27 @@ if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { # } # } -my $count_query = "SELECT COUNT(*), SUM(amount)"; +my $count_query = "SELECT COUNT(*), SUM(cust_bill_pkg_discount.amount)"; + +my $join_cust_pkg_discount = + 'LEFT JOIN cust_pkg_discount USING (pkgdiscountnum)'; + +my $join_cust = + ' JOIN cust_bill USING ( invnum ) '. + FS::UI::Web::join_cust_main('cust_bill', 'cust_pkg'); -my $join_cust = ' JOIN cust_bill_pkg USING ( billpkgnum ) - JOIN cust_bill USING ( invnum ) - LEFT JOIN cust_main USING ( custnum ) '; +my $join_pkg = + ' JOIN cust_bill_pkg USING ( billpkgnum ) + LEFT JOIN cust_pkg ON ( cust_bill_pkg.pkgnum = cust_pkg.pkgnum ) + LEFT JOIN part_pkg USING ( pkgpart ) '; + #LEFT JOIN part_pkg AS override + # ON pkgpart_override = override.pkgpart '; -my $join_pkg = ' LEFT JOIN cust_pkg USING ( pkgnum ) - LEFT JOIN part_pkg USING ( pkgpart ) '; - #LEFT JOIN part_pkg AS override - # ON pkgpart_override = override.pkgpart '; +my $join = "$join_cust_pkg_discount $join_discount $join_pkg $join_cust"; my $where = ' WHERE '. join(' AND ', @where); -$count_query .= " FROM cust_bill_pkg_discount $join_cust $join_pkg $where"; +$count_query .= " FROM cust_bill_pkg_discount $join $where"; my @select = ( 'cust_bill_pkg_discount.*', @@ -135,7 +205,7 @@ push @select, 'cust_main.custnum', my $query = { 'table' => 'cust_bill_pkg_discount', - 'addl_from' => "$join_cust $join_pkg", + 'addl_from' => $join, 'hashref' => {}, 'select' => join(', ', @select ), 'extra_sql' => $where,