From: Ivan Kohler Date: Wed, 11 Dec 2013 20:52:01 +0000 (-0800) Subject: optimize customer view (esp. with lots of commission credits), RT#26416 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=359004f4f4091e9789cb6e23a97c8eb89256d0b2 optimize customer view (esp. with lots of commission credits), RT#26416 --- diff --git a/httemplate/view/cust_main/payment_history.html b/httemplate/view/cust_main/payment_history.html index 73082ce96..95e34a158 100644 --- a/httemplate/view/cust_main/payment_history.html +++ b/httemplate/view/cust_main/payment_history.html @@ -396,12 +396,34 @@ my %status = ( my @history = (); my %opt = ( + + #config ( map { $_ => scalar($conf->config($_)) } qw( card_refund-days date_format ) ), ( map { $_ => $conf->exists($_) } - qw( deleteinvoices deletepayments deleterefunds pkg-balances ) - ) + qw( deleteinvoices deletepayments deleterefunds pkg-balances + cust_credit_bill_pkg-manual cust_bill_pay_pkg-manual + ) + ), + 'money_char ' => $money_char, + + #rights + ( map { $_ => $curuser->access_right($_) } + ( + 'View invoices', 'Void invoices', 'Unvoid invoices', 'Delete invoices', + 'Apply payment', 'Refund credit card payment', 'Refund Echeck payment', + 'Credit card void', 'Echeck void', 'Void payments', 'Unvoid payments', + 'Delete payment', 'Unapply payment', + 'Apply credit', 'Delete Credit', 'Unapply credit', + 'Delete refund', + 'Billing event reports', 'View customer billing events', + ) + ), + + #customer information + 'total_owed' => $cust_main->total_owed, + 'total_unapplied_refunds' => $cust_main->total_unapplied_refunds, ); $opt{'date_format'} ||= '%m/%d/%Y'; diff --git a/httemplate/view/cust_main/payment_history/credit.html b/httemplate/view/cust_main/payment_history/credit.html index 6dd8970c8..ec5041b55 100644 --- a/httemplate/view/cust_main/payment_history/credit.html +++ b/httemplate/view/cust_main/payment_history/credit.html @@ -6,10 +6,6 @@ my( $cust_credit, %opt ) = @_; my $date_format = $opt{'date_format'} || '%m/%d/%Y'; -my $conf = new FS::Conf; -my $money_char = $conf->config('money_char') || '$'; -my $curuser = $FS::CurrentUser::CurrentUser; - my @cust_credit_bill = $cust_credit->cust_credit_bill; my @cust_credit_refund = $cust_credit->cust_credit_refund; @@ -21,7 +17,7 @@ if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) { my %cust_credit_bill_width = ('width' => 392); my %cust_credit_bill_height = (); -if ($conf->exists('cust_credit_bill_pkg-manual')) { +if ( $opt{'cust_credit_bill_pkg-manual'} ) { %cust_credit_bill_width = ('width' => 592); %cust_credit_bill_height = ('height' => 436); } @@ -34,8 +30,8 @@ if ( scalar(@cust_credit_bill) == 0 $credit = '' . emt("Unapplied Credit by [_1]", $cust_credit->otaker ) . ''; - if ( $curuser->access_right('Apply credit') ) { - if ( $cust_credit->cust_main->total_owed > 0 ) { + if ( $opt{'Apply credit'} ) { + if ( $opt{total_owed} > 0 ) { $apply = ' ('. include( '/elements/popup_link.html', 'label' => emt('apply'), @@ -47,7 +43,7 @@ if ( scalar(@cust_credit_bill) == 0 ). ')'; } - if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) { + if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', 'label' => emt('apply to refund'), @@ -75,22 +71,22 @@ if ( scalar(@cust_credit_bill) == 0 foreach my $app ( sort { $a->_date <=> $b->_date } ( @cust_credit_bill, @cust_credit_refund ) ) { if ( $app->isa('FS::cust_credit_bill') ) { - $desc .= '  ' . $money_char . $app->amount . ' ' + $desc .= '  ' . $opt{money_char} . $app->amount . ' ' . $app->applied_to_invoice . '
'; } elsif ( $app->isa('FS::cust_credit_refund') ) { $desc .= '  ' . - emt("[_1][_2] refunded on [_3]", $money_char, $app->amount, + emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount, time2str($date_format, $app->_date) ) . '
'; } else { die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund"; } } if ( $cust_credit->credited > 0 ) { - $desc .= '  ' . - emt("[_1][_2] unapplied", $money_char, $cust_credit->credited) . + $desc .= '  '. + emt("[_1][_2] unapplied",$opt{money_char},$cust_credit->credited). ''; - if ( $curuser->access_right('Apply credit') ) { - if ( $cust_credit->cust_main->total_owed > 0 ) { + if ( $opt{'Apply credit'} ) { + if ( $opt{total_owed} > 0 ) { $apply = ' ('. include( '/elements/popup_link.html', 'label' => emt('apply'), @@ -102,7 +98,7 @@ if ( scalar(@cust_credit_bill) == 0 ). ')'; } - if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) { + if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', 'label' => emt('apply to refund'), @@ -124,7 +120,8 @@ $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->credn '', emt('delete') ) -if ( $cust_credit->closed !~ /^Y/i && $curuser->access_right('Delete credit') ); + if $cust_credit->closed !~ /^Y/i + && $opt{'Delete credit'}; my $unapply = ''; $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum, @@ -132,12 +129,12 @@ $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->cre '', emt('unapply') ) -if ( $cust_credit->closed !~ /^Y/i && scalar(@cust_credit_bill) - && $curuser->access_right('Unapply credit') ); + if $cust_credit->closed !~ /^Y/i + && scalar(@cust_credit_bill) + && $opt{'Unapply credit'}; -my $reason = $cust_credit->reason - ? ' ('. $cust_credit->reason. ')' - : ''; +my $reason = $cust_credit->reason; +$reason = $reason ? " ($reason)" : ''; diff --git a/httemplate/view/cust_main/payment_history/invoice.html b/httemplate/view/cust_main/payment_history/invoice.html index 96a9f5456..acb1d6956 100644 --- a/httemplate/view/cust_main/payment_history/invoice.html +++ b/httemplate/view/cust_main/payment_history/invoice.html @@ -3,10 +3,6 @@ my( $cust_bill, %opt ) = @_; -my $conf = new FS::Conf; - -my $curuser = $FS::CurrentUser::CurrentUser; - my $invoice = emt("Invoice #[_1] (Balance [_2])",$cust_bill->display_invnum,$cust_bill->owed); my $under = ''; @@ -22,12 +18,12 @@ if ( $cust_bill->owed > 0 ) { my $invnum = $cust_bill->invnum; -my $link = $curuser->access_right('View invoices') +my $link = $opt{'View invoices'} ? qq!! : ''; my $void = ''; -if ( $cust_bill->closed !~ /^Y/i && $curuser->access_right('Void invoices') ) { +if ( $cust_bill->closed !~ /^Y/i && $opt{'Void invoices'} ) { $void = ' ('. include('/elements/popup_link.html', 'label' => emt('void'), @@ -44,15 +40,13 @@ $delete = areyousure_link("${p}misc/delete-cust_bill.html?$invnum", emt('Delete this invoice from the database completely'), emt('delete') ) - if ( $opt{'deleteinvoices'} && $curuser->access_right('Delete invoices') ); + if ( $opt{'deleteinvoices'} && $opt{'Delete invoices'} ); my $events = ''; -#1.9 if ( $cust_bill->num_cust_event - && ( $curuser->access_right('Billing event reports') - || $curuser->access_right('View customer billing events') - ) - ) { + && ($opt{'Billing event reports'} || $opt{'View customer billing events'}) + ) +{ $under .= qq!
( !. emt('View invoice events').' )'; diff --git a/httemplate/view/cust_main/payment_history/payment.html b/httemplate/view/cust_main/payment_history/payment.html index ff269bfaf..b71d73fc6 100644 --- a/httemplate/view/cust_main/payment_history/payment.html +++ b/httemplate/view/cust_main/payment_history/payment.html @@ -6,10 +6,6 @@ my( $cust_pay, %opt ) = @_; my $date_format = $opt{'date_format'} || '%m/%d/%Y'; -my $conf = new FS::Conf; -my $money_char = $conf->config('money_char') || '$'; -my $curuser = $FS::CurrentUser::CurrentUser; - my @cust_bill_pay = $cust_pay->cust_bill_pay; my @cust_pay_refund = $cust_pay->cust_pay_refund; @@ -26,7 +22,7 @@ if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) { my %cust_bill_pay_width = ('width' => 392); my %cust_bill_pay_height = (); -if ($conf->exists('cust_bill_pay_pkg-manual')) { +if ( $opt{'cust_bill_pay_pkg-manual'} ) { %cust_bill_pay_width = ('width' => 592); %cust_bill_pay_height = ('height' => 436); } @@ -53,8 +49,8 @@ if ( scalar(@cust_bill_pay) == 0 $payment = emt("Unapplied Payment by [_1]",$otaker); $payment =~ s/$otaker/$otaker<\/i>/ if $italicize_otaker; $payment = ''.$payment.''; - if ( $curuser->access_right('Apply payment') ) { - if ( $cust_pay->cust_main->total_owed > 0 ) { + if ( $opt{'Apply payment'} ) { + if ( $opt{total_owed} > 0 ) { $apply = ' ('. include( '/elements/popup_link.html', 'label' => emt('apply'), @@ -66,7 +62,7 @@ if ( scalar(@cust_bill_pay) == 0 ). ')'; } - if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) { + if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', 'label' => emt('apply to refund'), @@ -94,11 +90,11 @@ if ( scalar(@cust_bill_pay) == 0 foreach my $app ( sort { $a->_date <=> $b->_date } ( @cust_bill_pay, @cust_pay_refund ) ) { if ( $app->isa('FS::cust_bill_pay') ) { - $desc .= '  ' . $money_char . $app->amount . ' ' . + $desc .= '  ' . $opt{money_char} . $app->amount . ' ' . $app->applied_to_invoice . '
'; } elsif ( $app->isa('FS::cust_pay_refund') ) { $desc .= '  ' . - emt("[_1][_2] refunded on [_3]", $money_char, $app->amount, + emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount, time2str($date_format, $app->_date) ) . '
'; } else { die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund"; @@ -106,11 +102,11 @@ if ( scalar(@cust_bill_pay) == 0 } if ( $cust_pay->unapplied > 0 ) { $desc .= '  '. - '' . - emt("[_1][_2] unapplied", $money_char, $cust_pay->unapplied) . + ''. + emt("[_1][_2] unapplied", $opt{money_char}, $cust_pay->unapplied). ''; - if ( $curuser->access_right('Apply payment') ) { - if ( $cust_pay->cust_main->total_owed > 0 ) { + if ( $opt{'Apply payment'} ) { + if ( $opt{total_owed} > 0 ) { $apply = ' ('. include( '/elements/popup_link.html', 'label' => emt('apply'), @@ -122,7 +118,7 @@ if ( scalar(@cust_bill_pay) == 0 ). ')'; } - if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) { + if ( $opt{total_unapplied_refunds} > 0 ) { $apply.= ' ('. include( '/elements/popup_link.html', 'label' => emt('apply to refund'), @@ -149,14 +145,14 @@ my $view = my $refund = ''; my $refund_days = $opt{'card_refund-days'} || 120; -my @rights = ('Refund payment'); -push @rights, 'Refund credit card payment' if $payby eq 'CARD'; -push @rights, 'Refund Echeck payment' if $payby eq 'CHEK'; +my $refund_right = ''; +$refund_right = 'Refund credit card payment' if $payby eq 'CARD'; +$refund_right = 'Refund Echeck payment' if $payby eq 'CHEK'; if ( $cust_pay->closed !~ /^Y/i && $cust_pay->payby =~ /^(CARD|CHEK)$/ && time-$cust_pay->_date < $refund_days*86400 && $cust_pay->unrefunded > 0 - && $curuser->access_right(\@rights) + && $opt{$refund_right} ) { $refund = qq! (paynum, emt('Void this payment from the database') . $voidmsg, emt('void') ) - if ( $cust_pay->closed !~ /^Y/i - && ( ( $cust_pay->payby eq 'CARD' - && $curuser->access_right('Credit card void') - ) - || ( $cust_pay->payby eq 'CHEK' - && $curuser->access_right('Echeck void') - ) - || ( $cust_pay->payby !~ /^(CARD|CHEK)$/ - && $curuser->access_right('Void payments') - ) - ) - ); + if $cust_pay->closed !~ /^Y/i + && ( ( $cust_pay->payby eq 'CARD' && $opt{'Credit card void'} ) + || ( $cust_pay->payby eq 'CHEK' && $opt{'Echeck void'} ) + || ( $cust_pay->payby !~ /^(CARD|CHEK)$/ && $opt{'Void payments'} ) + ); my $delete = ''; $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum, @@ -192,8 +181,9 @@ $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum, emt('Delete this payment from the database completely - not recommended'), emt('delete') ) - if ( $cust_pay->closed !~ /^Y/i && $opt{'deletepayments'} - && $curuser->access_right('Delete payment') ); + if $cust_pay->closed !~ /^Y/i + && $opt{'deletepayments'} + && $opt{'Delete payment'}; my $unapply = ''; $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum, @@ -201,7 +191,8 @@ $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum, emt('Keep this payment, but dissociate it from the invoices it is currently applied against'), emt('unapply') ) - if ( $cust_pay->closed !~ /^Y/i && scalar(@cust_bill_pay) - && $curuser->access_right('Unapply payment') ); + if $cust_pay->closed !~ /^Y/i + && scalar(@cust_bill_pay) + && $opt{'Unapply payment'}; diff --git a/httemplate/view/cust_main/payment_history/pending_payment.html b/httemplate/view/cust_main/payment_history/pending_payment.html index 113022d08..31149231b 100644 --- a/httemplate/view/cust_main/payment_history/pending_payment.html +++ b/httemplate/view/cust_main/payment_history/pending_payment.html @@ -3,10 +3,6 @@ my( $cust_pay_pending, %opt ) = @_; -my $conf = new FS::Conf; - -my $curuser = $FS::CurrentUser::CurrentUser; - my ($payby, $payinfo) = translate_payinfo($cust_pay_pending); my $target = "$payby$payinfo"; $payby = translate_payby($payby,$payinfo); diff --git a/httemplate/view/cust_main/payment_history/refund.html b/httemplate/view/cust_main/payment_history/refund.html index f14713cda..fc2a5ccf0 100644 --- a/httemplate/view/cust_main/payment_history/refund.html +++ b/httemplate/view/cust_main/payment_history/refund.html @@ -5,8 +5,6 @@ my( $cust_refund, %opt ) = @_; -my $curuser = $FS::CurrentUser::CurrentUser; - my $payby = $cust_refund->payby; my $payinfo = $payby eq 'CARD' ? $cust_refund->paymask @@ -34,8 +32,9 @@ $delete = areyousure_link("${p}misc/delete-cust_refund.cgi?".$cust_refund->refun emt('Delete this refund from the database completely - not recommended'), emt('delete') ) - if ( $cust_refund->closed !~ /^Y/i && $opt{'deleterefunds'} - && $curuser->access_right('Delete refund') ); + if $cust_refund->closed !~ /^Y/i + && $opt{'deleterefunds'} + && $opt{'Delete refund'}; diff --git a/httemplate/view/cust_main/payment_history/statement.html b/httemplate/view/cust_main/payment_history/statement.html index dedec9bda..1517fd5c8 100644 --- a/httemplate/view/cust_main/payment_history/statement.html +++ b/httemplate/view/cust_main/payment_history/statement.html @@ -5,8 +5,6 @@ my( $cust_statement, %opt ) = @_; -my $curuser = $FS::CurrentUser::CurrentUser; - my($pre, $post) = ('', ''); #if ( $cust_statement->owed > 0 ) { # $pre = 'Open '; @@ -15,16 +13,14 @@ my($pre, $post) = ('', ''); my $statementnum = $cust_statement->statementnum; -my $link = $curuser->access_right('View invoices') +my $link = $opt{'View invoices'} ? qq!! : ''; my $events = ''; #if ( $cust_statement->num_cust_event -# && ( $curuser->access_right('Billing event reports') -# || $curuser->access_right('View customer billing events') -# ) +# && ($opt{'Billing event reports'} || $opt{'View customer billing events'}) # ) { # $events = # qq!
display_invnum, $cust_bill_void->charged); my $under = ''; my $invnum = $cust_bill_void->invnum; -my $link = $curuser->access_right('View invoices') +my $link = $opt{'View invoices'} ? qq!! : ''; @@ -31,7 +27,7 @@ $unvoid = areyousure_link("${p}misc/unvoid-cust_bill_void.html?invnum=". $cust_b emt('Unvoid this invoice'), emt('unvoid') ) - if $cust_bill_void->closed !~ /^Y/ && $curuser->access_right('Unvoid invoices'); + if $cust_bill_void->closed !~ /^Y/ && $opt{'Unvoid invoices'}; my $delete = ''; $delete = areyousure_link("${p}misc/delete-cust_bill.html?$invnum", @@ -39,15 +35,13 @@ $delete = areyousure_link("${p}misc/delete-cust_bill.html?$invnum", emt('Delete this invoice from the database completely'), emt('delete') ) - if ( $opt{'deleteinvoices'} && $curuser->access_right('Delete invoices') ); + if $opt{'deleteinvoices'} && $opt{'Delete invoices'}; my $events = ''; -#1.9 if ( $cust_bill_void->num_cust_event - && ( $curuser->access_right('Billing event reports') - || $curuser->access_right('View customer billing events') - ) - ) { + && ($opt{'Billing event reports'} || $opt{'View customer billing events'}) + ) +{ $under .= qq!
( !. emt('View invoice events').' )'; diff --git a/httemplate/view/cust_main/payment_history/voided_payment.html b/httemplate/view/cust_main/payment_history/voided_payment.html index 88b5e0a84..a8194a75f 100644 --- a/httemplate/view/cust_main/payment_history/voided_payment.html +++ b/httemplate/view/cust_main/payment_history/voided_payment.html @@ -11,8 +11,6 @@ my( $cust_pay_void, %opt ) = @_; my $date_format = $opt{'date_format'} || '%m/%d/%Y'; -my $curuser = $FS::CurrentUser::CurrentUser; - my ($payby,$payinfo) = translate_payinfo($cust_pay_void); $payby = translate_payby($payby,$payinfo); my $info = $payby ? "($payby$payinfo)" : ''; @@ -31,6 +29,6 @@ $unvoid = areyousure_link("${p}misc/unvoid-cust_pay_void.cgi?".$cust_pay_void->p emt('Unvoid this payment from the database') . $unvoidmsg, emt('unvoid') ) - if ( $cust_pay_void->closed !~ /^Y/i && $curuser->access_right('Unvoid payments') ); + if $cust_pay_void->closed !~ /^Y/i && $opt{'Unvoid payments'};