From: ivan Date: Tue, 8 Oct 2002 04:46:40 +0000 (+0000) Subject: payby-default config option, with special "HIDE" option to disable billing X-Git-Tag: freeside_1_5_0pre1~202 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=b97ccb2b958567490841cfc93d2c4a401d98cdb0 payby-default config option, with special "HIDE" option to disable billing information in the web interface (closes: Bug#468) --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 788127a7f..1c4ad04a3 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -952,6 +952,15 @@ httemplate/docs/config.html 'select_enum' => [ 'text/plain', 'text/html' ], }, + { + 'key' => 'payby-default', + 'section' => 'UI', + 'description' => 'Default payment type. HIDE disables display of billing information and sets customers to BILL.', + 'type' => 'select', + 'select_enum' => [ '', 'CARD', 'BILL', 'COMP', 'HIDE' ], + }, + + ); 1; diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index 3a5df086f..a76cd36d1 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -336,48 +336,94 @@ sub expselect { $return; } -print "
Billing information", &itable("#cccccc"), - qq!tax eq "Y"; -print qq!>Tax Exempt!; -print qq!invoicing_list; -print qq! CHECKED! - if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') ) - || grep { $_ eq 'POST' } @invoicing_list; -print qq!>Postal mail invoice!; -my $invoicing_list = join(', ', grep { $_ ne 'POST' } @invoicing_list ); -print qq!Email invoice !; - -print "Billing type", - "", - &table("#cccccc"), ""; - -my($payinfo, $payname)=( - $cust_main->payinfo, - $cust_main->payname, -); +my $payby_default = $conf->config('payby-default'); + +if ( $payby_default eq 'HIDE' ) { + + $cust_main->payby('BILL') unless $cust_main->payby; + + foreach my $field (qw( tax payby )) { + print qq!'; + } + + print qq!'; + + foreach my $payby (qw( CARD BILL COMP )) { + foreach my $field (qw( payinfo payname )) { + print qq!'; + } + + #false laziness w/expselect + my( $m, $y ) = (0, 0); + if ( scalar(@_) ) { + my $date = shift || '01-2000'; + if ( $date =~ /^(\d{4})-(\d{1,2})-\d{1,2}$/ ) { #PostgreSQL date format + ( $m, $y ) = ( $2, $1 ); + } elsif ( $date =~ /^(\d{1,2})-(\d{1,2}-)?(\d{4}$)/ ) { + ( $m, $y ) = ( $1, $3 ); + } else { + die "unrecognized expiration date format: $date"; + } + } + + print qq! qq!Credit card
${r}
${r}Exp !. expselect("CARD"). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", "12-2037"). qq!
Attention
!, - 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP"), +} else { + + print "
Billing information", &itable("#cccccc"), + qq!tax eq "Y"; + print qq!>Tax Exempt!. + qq!invoicing_list; + print qq! CHECKED! + if ( ! @invoicing_list && ! $conf->exists('disablepostalinvoicedefault') ) + || grep { $_ eq 'POST' } @invoicing_list; + print qq!>Postal mail invoice!; + my $invoicing_list = join(', ', grep { $_ ne 'POST' } @invoicing_list ); + print qq!Email invoice !; + + print "Billing type", + "", + &table("#cccccc"), ""; + + my($payinfo, $payname)=( + $cust_main->payinfo, + $cust_main->payname, + ); + + my %payby = ( + 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD"). qq!
${r}Name on card
!, + 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", "12-2037"). qq!
Attention
!, + 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP"), ); -my %paybychecked = ( - 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD", $cust_main->paydate). qq!
${r}Name on card
!, - 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", $cust_main->paydate). qq!
Attention
!, - 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP", $cust_main->paydate), + + my %paybychecked = ( + 'CARD' => qq!Credit card
${r}
${r}Exp !. expselect("CARD", $cust_main->paydate). qq!
${r}Name on card
!, + 'BILL' => qq!Billing
P.O.
${r}Exp !. expselect("BILL", $cust_main->paydate). qq!
Attention
!, + 'COMP' => qq!Complimentary
${r}Approved by
${r}Exp !. expselect("COMP", $cust_main->paydate), ); -for (qw(CARD BILL COMP)) { - print qq!payby eq "$_") { - print qq! CHECKED> $paybychecked{$_}!; - } else { - print qq!> $payby{$_}!; + + $cust_main->payby($payby_default) unless $cust_main->payby; + for (qw(CARD BILL COMP)) { + print qq!payby eq "$_") { + print qq! CHECKED> $paybychecked{$_}!; + } else { + print qq!> $payby{$_}!; + } } -} -print "$r required fields for each billing type"; + print "$r required fields for each billing type"; + +} if ( defined $cust_main->dbdef_table->column('comments') ) { print "

Comments", &itable("#cccccc"), diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index 707de8d70..25260fa3c 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -188,6 +188,8 @@ print ''; print '
'; +if ( $conf->config('payby-default') ne 'HIDE' ) { + my @invoicing_list = $cust_main->invoicing_list; print "Billing information (", qq!!, "Bill now)", @@ -236,6 +238,8 @@ print '
'; print ""; +} + print ''; if ( defined $cust_main->dbdef_table->column('comments') @@ -268,30 +272,34 @@ foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) { print '
'; -print '
'. - qq!
!. - qq!!. - qq!Description:!. - qq! Amount:!. - qq! !; - -#false laziness w/ edit/part_pkg.cgi -if ( $conf->exists('enable_taxclasses') ) { - print '!. + qq!Description:!. + qq! Amount:!. + qq! !; + + #false laziness w/ edit/part_pkg.cgi + if ( $conf->exists('enable_taxclasses') ) { + print ''; + } else { + print ''; } - print ''; -} else { - print ''; -} + + print qq!

!; -print qq!
!; +} print < @@ -451,48 +459,132 @@ function cust_pay_areyousure(href) { END -#formatting -print qq!

Payment History!. - qq! ( !. - qq!!. - qq!Post payment | !. - qq!!. - qq!Post credit )!; - -#get payment history -# -# major problem: this whole thing is way too sloppy. -# minor problem: the description lines need better formatting. - -my @history = (); #needed for mod_perl :) - -my %target = (); - -my @bills = qsearch('cust_bill',{'custnum'=>$custnum}); -foreach my $bill (@bills) { - my($bref)=$bill->hashref; - my $bpre = ( $bill->owed > 0 ) - ? ' Open ' - : ''; - my $bpost = ( $bill->owed > 0 ) ? '' : ''; - push @history, - $bref->{_date} . qq!\t${bpre}Invoice #! . $bref->{invnum} . - qq! (Balance \$! . $bill->owed . qq!)$bpost\t! . - $bref->{charged} . qq!\t\t\t!; - - my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } ); -# my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } ); -# my($payment); -# foreach $payment (@payments) { - foreach my $cust_bill_pay (@cust_bill_pay) { - my $payment = $cust_bill_pay->cust_pay; - my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date, - $cust_bill_pay->invnum, - $payment->payby, - $payment->payinfo, - $cust_bill_pay->amount, - ); +if ( $conf->config('payby-default') ne 'HIDE' ) { + + #formatting + print qq!

Payment History!. + qq! ( !. + qq!!. + qq!Post payment | !. + qq!!. + qq!Post credit )!; + + #get payment history + # + # major problem: this whole thing is way too sloppy. + # minor problem: the description lines need better formatting. + + my @history = (); #needed for mod_perl :) + + my %target = (); + + my @bills = qsearch('cust_bill',{'custnum'=>$custnum}); + foreach my $bill (@bills) { + my($bref)=$bill->hashref; + my $bpre = ( $bill->owed > 0 ) + ? ' Open ' + : ''; + my $bpost = ( $bill->owed > 0 ) ? '' : ''; + push @history, + $bref->{_date} . qq!\t${bpre}Invoice #! . $bref->{invnum} . + qq! (Balance \$! . $bill->owed . qq!)$bpost\t! . + $bref->{charged} . qq!\t\t\t!; + + my(@cust_bill_pay)=qsearch('cust_bill_pay',{'invnum'=> $bref->{invnum} } ); + # my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } ); + # my($payment); + foreach my $cust_bill_pay (@cust_bill_pay) { + my $payment = $cust_bill_pay->cust_pay; + my($date,$invnum,$payby,$payinfo,$paid)=($payment->_date, + $cust_bill_pay->invnum, + $payment->payby, + $payment->payinfo, + $cust_bill_pay->amount, + ); + $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4)) + if $payby eq 'CARD'; + my $target = "$payby$payinfo"; + $payby =~ s/^BILL$/Check #/ if $payinfo; + $payby =~ s/^(CARD|COMP)$/$1 /; + my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments') + ? qq! (delete)! + : ''; + push @history, + "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete\t\t$paid\t\t\t$target"; + } + + my(@cust_credit_bill)= + qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } ); + foreach my $cust_credit_bill (@cust_credit_bill) { + my $cust_credit = $cust_credit_bill->cust_credit; + my($date, $invnum, $crednum, $amount, $reason, $app_date ) = ( + $cust_credit->_date, + $cust_credit_bill->invnum, + $cust_credit_bill->crednum, + $cust_credit_bill->amount, + $cust_credit->reason, + time2str("%D", $cust_credit_bill->_date), + ); + push @history, + "$date\tCredit #$crednum: $reason
". + "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t"; + } + } + + my @credits = grep { scalar(my @array = $_->cust_credit_refund) } + qsearch('cust_credit',{'custnum'=>$custnum}); + foreach my $credit (@credits) { + my($cref)=$credit->hashref; + my(@cust_credit_refund)= + qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } ); + foreach my $cust_credit_refund (@cust_credit_refund) { + my $cust_refund = $cust_credit_refund->cust_credit; + my($date, $crednum, $amount, $reason, $app_date ) = ( + $credit->_date, + $credit->crednum, + $cust_credit_refund->amount, + $credit->reason, + time2str("%D", $cust_credit_refund->_date), + ); + push @history, + "$date\tCredit #$crednum: $reason
". + "(applied to refund on $app_date)\t\t\t$amount\t"; + } + } + + @credits = grep { $_->credited > 0 } + qsearch('cust_credit',{'custnum'=>$custnum}); + foreach my $credit (@credits) { + my($cref)=$credit->hashref; + push @history, + $cref->{_date} . "\t" . + qq!!. + 'Unapplied credit #' . + $cref->{crednum} . ": ". + $cref->{reason} . "\t\t\t" . $credit->credited . "\t"; + } + + my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } ); + foreach my $refund (@refunds) { + my($rref)=$refund->hashref; + my($refundnum) = ( + $refund->refundnum, + ); + + push @history, + $rref->{_date} . "\tRefund #$refundnum, (" . + $rref->{payby} . " " . $rref->{payinfo} . ") by " . + $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" . + $rref->{refund}; + } + + my @unapplied_payments = + grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } ); + foreach my $payment (@unapplied_payments) { + my $payby = $payment->payby; + my $payinfo = $payment->payinfo; + #false laziness w/above $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4)) if $payby eq 'CARD'; my $target = "$payby$payinfo"; @@ -502,161 +594,72 @@ foreach my $bill (@bills) { ? qq! (delete)! : ''; push @history, - "$date\tPayment, Invoice #$invnum ($payby$payinfo)$delete\t\t$paid\t\t\t$target"; - } - - my(@cust_credit_bill)= - qsearch('cust_credit_bill', { 'invnum'=> $bref->{invnum} } ); - foreach my $cust_credit_bill (@cust_credit_bill) { - my $cust_credit = $cust_credit_bill->cust_credit; - my($date, $invnum, $crednum, $amount, $reason, $app_date ) = ( - $cust_credit->_date, - $cust_credit_bill->invnum, - $cust_credit_bill->crednum, - $cust_credit_bill->amount, - $cust_credit->reason, - time2str("%D", $cust_credit_bill->_date), - ); - push @history, - "$date\tCredit #$crednum: $reason
". - "(applied to invoice #$invnum on $app_date)\t\t\t$amount\t"; - } -} - -my @credits = grep { scalar(my @array = $_->cust_credit_refund) } - qsearch('cust_credit',{'custnum'=>$custnum}); -foreach my $credit (@credits) { - my($cref)=$credit->hashref; - my(@cust_credit_refund)= - qsearch('cust_credit_refund', { 'crednum'=> $cref->{crednum} } ); - foreach my $cust_credit_refund (@cust_credit_refund) { - my $cust_refund = $cust_credit_refund->cust_credit; - my($date, $crednum, $amount, $reason, $app_date ) = ( - $credit->_date, - $credit->crednum, - $cust_credit_refund->amount, - $credit->reason, - time2str("%D", $cust_credit_refund->_date), - ); - push @history, - "$date\tCredit #$crednum: $reason
". - "(applied to refund on $app_date)\t\t\t$amount\t"; + $payment->_date. "\t". + 'Unapplied payment #' . + $payment->paynum . " ($payby$payinfo) ". + '('. + "apply)$delete". + "\t\t" . $payment->unapplied . "\t\t\t$target"; } -} - -@credits = grep { $_->credited > 0 } - qsearch('cust_credit',{'custnum'=>$custnum}); -foreach my $credit (@credits) { - my($cref)=$credit->hashref; - push @history, - $cref->{_date} . "\t" . - qq!!. - 'Unapplied credit #' . - $cref->{crednum} . ": ". - $cref->{reason} . "\t\t\t" . $credit->credited . "\t"; -} - -my(@refunds)=qsearch('cust_refund',{'custnum'=> $custnum } ); -foreach my $refund (@refunds) { - my($rref)=$refund->hashref; - my($refundnum) = ( - $refund->refundnum, - ); - - push @history, - $rref->{_date} . "\tRefund #$refundnum, (" . - $rref->{payby} . " " . $rref->{payinfo} . ") by " . - $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" . - $rref->{refund}; -} - -my @unapplied_payments = - grep { $_->unapplied > 0 } qsearch('cust_pay', { 'custnum' => $custnum } ); -foreach my $payment (@unapplied_payments) { - my $payby = $payment->payby; - my $payinfo = $payment->payinfo; - #false laziness w/above - $payinfo = 'x'x(length($payinfo)-4). substr($payinfo,(length($payinfo)-4)) - if $payby eq 'CARD'; - my $target = "$payby$payinfo"; - $payby =~ s/^BILL$/Check #/ if $payinfo; - $payby =~ s/^(CARD|COMP)$/$1 /; - my $delete = $payment->closed !~ /^Y/i && $conf->exists('deletepayments') - ? qq! (delete)! - : ''; - push @history, - $payment->_date. "\t". - 'Unapplied payment #' . - $payment->paynum . " ($payby$payinfo) ". - '('. - "apply)$delete". - "\t\t" . $payment->unapplied . "\t\t\t$target"; -} - - #formatting - print &table(), < - Date - Description - Charge - Payment - In-house
Credit
- Refund - Balance - + + #formatting + print &table(), < + Date + Description + Charge + Payment + In-house
Credit
+ Refund + Balance + END + + #display payment history + + my $balance = 0; + foreach my $item (sort keyfield_numerically @history) { + my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item); + $charge ||= 0; + $payment ||= 0; + $credit ||= 0; + $refund ||= 0; + $balance += $charge - $payment; + $balance -= $credit - $refund; + $balance = sprintf("%.2f", $balance); + $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp + $target = '' unless defined $target; + + print ""; + print qq!! unless $target && $target{$target}++; + print time2str("%D",$date); + print '' if $target && $target{$target} == 1; + print "", + "$desc", + "", + ( $charge ? "\$".sprintf("%.2f",$charge) : '' ), + "", + "", + ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ), + "", + "", + ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ), + "", + "", + ( $refund ? "\$".sprintf("%.2f",$refund) : '' ), + "", + "\$" . $balance, + "", + "\n"; + } + + print ""; -#display payment history - -my $balance = 0; -foreach my $item (sort keyfield_numerically @history) { - my($date,$desc,$charge,$payment,$credit,$refund,$target)=split(/\t/,$item); - $charge ||= 0; - $payment ||= 0; - $credit ||= 0; - $refund ||= 0; - $balance += $charge - $payment; - $balance -= $credit - $refund; - $balance = sprintf("%.2f", $balance); - $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp - $target = '' unless defined $target; - - print ""; - print qq!! unless $target && $target{$target}++; - print time2str("%D",$date); - print '' if $target && $target{$target} == 1; - print "", - "$desc", - "", - ( $charge ? "\$".sprintf("%.2f",$charge) : '' ), - "", - "", - ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ), - "", - "", - ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ), - "", - "", - ( $refund ? "\$".sprintf("%.2f",$refund) : '' ), - "", - "\$" . $balance, - "", - "\n"; } -#formatting -print ""; - -#end - -#formatting -print < - -END +print ''; #subroutiens -sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0] ; } +sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0]; } %>