X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fedit%2Fprocess%2Fcust_credit.cgi;h=0b93c64e5e4a79d8d2c137bbe3989e0d018f949f;hb=1fc8addc56f8daf12397da568eb1ac1b27fd3984;hp=245f31af7deffeda67080de820db2b5f5f56fd27;hpb=a60615bf7bde77aa2b9faf3fc268c149eecdb5ab;p=freeside.git diff --git a/httemplate/edit/process/cust_credit.cgi b/httemplate/edit/process/cust_credit.cgi index 245f31af7..0b93c64e5 100755 --- a/httemplate/edit/process/cust_credit.cgi +++ b/httemplate/edit/process/cust_credit.cgi @@ -1,5 +1,4 @@ %if ( $error ) { -% $cgi->param('reasonnum', $reasonnum); % $cgi->param('error', $error); % $dbh->rollback if $oldAutoCommit; % @@ -15,9 +14,9 @@ % % $dbh->commit or die $dbh->errstr if $oldAutoCommit; % -<% header(emt('Credit successful')) %> +<& /elements/header-popup.html, emt('Credit successful') &> @@ -37,25 +36,26 @@ my $oldAutoCommit = $FS::UID::AutoCommit; local $FS::UID::AutoCommit = 0; my $dbh = dbh; -my $error = ''; -if ($reasonnum == -1) { - - $error = 'Enter a new reason (or select an existing one)' - unless $cgi->param('newreasonnum') !~ /^\s*$/; - my $reason = new FS::reason { - 'reason_type' => scalar($cgi->param('newreasonnumT')), - 'reason' => scalar($cgi->param('newreasonnum')), - }; - $error ||= $reason->insert; - $cgi->param('reasonnum', $reason->reasonnum) - unless $error; +my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason'); +if (!$reasonnum) { + $error ||= 'Reason required' } +$cgi->param('reasonnum', $reasonnum) unless $error; + +my $_date; +if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + $_date = parse_datetime($cgi->param('_date')); +} +else { + $_date = time; +} + +my @fields = grep { $_ ne '_date' } fields('cust_credit'); unless ($error) { my $new = new FS::cust_credit ( { - map { - $_, scalar($cgi->param($_)); - } fields('cust_credit') + _date => $_date, + map { $_ => scalar($cgi->param($_)) } @fields } ); $error = $new->insert; }