From: jeff Date: Fri, 12 Jan 2007 02:04:50 +0000 (+0000) Subject: one-time charge enhancements X-Git-Tag: TRIXBOX_2_6~763 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=2a863bbb144830dfb8fca4afb3af76a84a647c76 one-time charge enhancements --- diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 8603bde3d..0534686c4 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1904,7 +1904,7 @@ sub bill { warn " bill setup\n" if $DEBUG > 1; - $setup = eval { $cust_pkg->calc_setup( $time ) }; + $setup = eval { $cust_pkg->calc_setup( $time, \@details ) }; if ( $@ ) { $dbh->rollback if $oldAutoCommit; return "$@ running calc_setup for $cust_pkg\n"; @@ -3615,10 +3615,22 @@ the error, otherwise returns false. =cut sub charge { - my ( $self, $amount ) = ( shift, shift ); - my $pkg = @_ ? shift : 'One-time charge'; - my $comment = @_ ? shift : '$'. sprintf("%.2f",$amount); - my $taxclass = @_ ? shift : ''; + my $self = shift; + my ( $amount, $pkg, $comment, $taxclass, $additional ); + if ( ref( $_[0] ) ) { + $amount = $_[0]->{amount}; + $pkg = exists($_[0]->{pkg}) ? $_[0]->{pkg} : 'One-time charge'; + $comment = exists($_[0]->{comment}) ? $_[0]->{comment} + : '$'. sprintf("%.2f",$amount); + $taxclass = exists($_[0]->{taxclass}) ? $_[0]->{taxclass} : ''; + $additional = $_[0]->{additional}; + }else{ + $amount = shift; + $pkg = @_ ? shift : 'One-time charge'; + $comment = @_ ? shift : '$'. sprintf("%.2f",$amount); + $taxclass = @_ ? shift : ''; + $additional = []; + } local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -3634,16 +3646,20 @@ sub charge { my $part_pkg = new FS::part_pkg ( { 'pkg' => $pkg, 'comment' => $comment, - #'setup' => $amount, - #'recur' => '0', 'plan' => 'flat', - 'plandata' => "setup_fee=$amount", 'freq' => 0, 'disabled' => 'Y', 'taxclass' => $taxclass, } ); - my $error = $part_pkg->insert; + my %options = ( ( map { ("additional_info$_" => $additional->[$_] ) } + ( 0 .. @$additional - 1 ) + ), + 'additional_count' => scalar(@$additional), + 'setup_fee' => $amount, + ); + + my $error = $part_pkg->insert( options => \%options ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm index 39be37933..f4031ec79 100644 --- a/FS/FS/part_pkg/flat.pm +++ b/FS/FS/part_pkg/flat.pm @@ -60,7 +60,13 @@ use FS::part_pkg; ); sub calc_setup { - my($self, $cust_pkg ) = @_; + my($self, $cust_pkg, $sdate, $details ) = @_; + + my ( $i, $count ) = ( 0, $self->option( 'additional_count' ) ); + while ($i < $count) { + push @$details, $self->option( 'additional_info' . $i++ ); + } + $self->option('setup_fee'); } diff --git a/httemplate/edit/process/quick-charge.cgi b/httemplate/edit/process/quick-charge.cgi index 2c5ac81b0..f614dd5cf 100644 --- a/httemplate/edit/process/quick-charge.cgi +++ b/httemplate/edit/process/quick-charge.cgi @@ -1,41 +1,47 @@ -%#untaint custnum -%$cgi->param('custnum') =~ /^(\d+)$/ -% or die 'illegal custnum '. $cgi->param('custnum'); -%my $custnum = $1; % -%$cgi->param('amount') =~ /^\s*\$?\s*(\d+(\.\d{1,2})?)\s*$/ -% or die 'illegal amount '. $cgi->param('amount'); -%my $amount = $1; -% -%my( $error, $cust_main); -%if ( $cgi->param('taxclass') eq '(select)' ) { -% -% -% $error = 'Must select a tax class'; -%} else { -% -% my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) -% or die "unknown custnum $custnum"; -% -% $error = $cust_main->charge( -% $amount, -% $cgi->param('pkg'), -% '$'. sprintf("%.2f",$amount), -% $cgi->param('taxclass') -% ); -% -%} -% -%if ($error) { -% - - -% -% eidiot($error); -%} else { -% print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum" ); -%} -% -% - +% my $error = ''; +% my $param = $cgi->Vars; +% +% my @description = (); +% for ( my $row = 0; exists($param->{"description$row"}); $row++ ) { +% push @description, $param->{"description$row"}; +% } +% pop @description until ($description[$#description]); +% +% $param->{"custnum"} =~ /^(\d+)$/ +% or $error .= "Illegal customer number " . $param->{"custnum"} . " "; +% my $custnum = $1; +% +% $param->{"amount"} =~ /^\s*(\d+(\.\d{1,2})?)\s*$/ +% or $error .= "Illegal amount " . $param->{"amount"} . " "; +% my $amount = $1; +% +% if ( $param->{'taxclass'} eq '(select)' ) { +% $error .= "Must select a tax class. "; +% } +% +% unless ( $error ) { +% my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) +% or $error .= "Unknown customer number $custnum. "; +% +% $error ||= $cust_main->charge({ 'amount' => $amount, +% 'pkg' => $cgi->param('pkg'), +% 'taxclass' => $cgi->param('taxclass'), +% 'additional' => \@description, +% } +% ); +% } +% +% if ( $error ) { +% +% $cgi->param('error', "$error" ); +% +<% $cgi->redirect($p.'quick-charge.html?'. $cgi->query_string) %> +% +% } +<% header("One-time charge added") %> + + diff --git a/httemplate/edit/quick-charge.html b/httemplate/edit/quick-charge.html new file mode 100644 index 000000000..b30285c21 --- /dev/null +++ b/httemplate/edit/quick-charge.html @@ -0,0 +1,163 @@ +<% include("/elements/header-popup.html", 'One-time charge entry', '', + ( $cgi->param('error') ? '' : 'onload="addRow()"' ), + ) +%> +% if ( $cgi->param('error') ) { + + <% $cgi->param('error') %>

+% } + + + + + +
+ + + + + + + + + + + + +% my $row = 0; +% if ( $cgi->param('error') ) { +% my $param = $cgi->Vars; +% +% for ( $row = 0; exists($param->{"description$row"}); $row++ ) { + + + + + +% } +% } + + +
Amount: + $ + + <% include('/elements/select-taxclass.html') %> +
Description: + +
+ " rownum="<% $row %>" onkeyup = "possiblyAddRow;" > +
+ +
+ + +
+ + + + + + diff --git a/httemplate/view/cust_main/packages.html b/httemplate/view/cust_main/packages.html index 37f3ec4bb..6ec92ef0d 100755 --- a/httemplate/view/cust_main/packages.html +++ b/httemplate/view/cust_main/packages.html @@ -16,7 +16,8 @@ % ) { % - <% include('quick-charge.html', $cust_main ) %> + <% popup_link('edit/quick-charge.html?custnum='. $cust_main->custnum, 'One-time charge', 'One-time charge', 684) %> +
% } % if ( $curuser->access_right('Bulk change customer packages') ) { @@ -518,19 +519,19 @@ Current packages % my($action, $label, $actionlabel, $cust_pkg) = @_; % $action .= '&pkgnum='. $cust_pkg->pkgnum; % $actionlabel .= ' package '. $cust_pkg->pkgnum; -% popup_link($action, $label, $actionlabel); +% popup_link($action, $label, $actionlabel, 392); %} % %sub svc_popup_link { % my($action, $label, $actionlabel, $cust_svc) = @_; % $action .= '?svcnum='. $cust_svc->svcnum; % $actionlabel .= ' service '. $cust_svc->svcnum; -% popup_link($action, $label, $actionlabel); +% popup_link($action, $label, $actionlabel, 392); %} % %sub popup_link { -% my($action, $label, $actionlabel) = @_; -% qq!$label!; +% my($action, $label, $actionlabel, $width) = @_; +% qq!$label!; %} % %sub pkg_customize_link {