From 7dd8215a91ca6ca4a9988a0108647ada7f2a11d8 Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Thu, 4 Dec 2014 14:47:49 -0800 Subject: [PATCH] backdate credits, RT#32320 --- FS/FS/AccessRight.pm | 2 ++ FS/FS/access_right.pm | 1 + httemplate/edit/cust_credit.cgi | 20 ++++++++++++----- httemplate/edit/cust_pay.cgi | 39 ++++++++++++--------------------- httemplate/edit/process/cust_credit.cgi | 15 ++++++++++--- httemplate/elements/tr-fixed-date.html | 10 +++++++-- 6 files changed, 52 insertions(+), 35 deletions(-) diff --git a/FS/FS/AccessRight.pm b/FS/FS/AccessRight.pm index 92cede6a5..4a1f89aa0 100644 --- a/FS/FS/AccessRight.pm +++ b/FS/FS/AccessRight.pm @@ -217,6 +217,7 @@ tie my %rights, 'Tie::IxHash', ### 'Customer credit and refund rights' => [ 'Post credit', + { rightname=>'Backdate credit', desc=>'Enable credits to be posted for days other than today.' }, 'Credit line items', #NEWNEWNEW 'Apply credit', #NEWNEW { rightname=>'Unapply credit', desc=>'Enable "unapplication" of unclosed credits.' }, #aka unapplycredits @@ -444,6 +445,7 @@ sub default_superuser_rights { 'Credit card void', 'Echeck void', 'Void invoices',#people are overusing this when credits are more appropriate + 'Backdate credit', ); no warnings 'uninitialized'; diff --git a/FS/FS/access_right.pm b/FS/FS/access_right.pm index ee0c494ae..e5a5781a9 100644 --- a/FS/FS/access_right.pm +++ b/FS/FS/access_right.pm @@ -249,6 +249,7 @@ sub _upgrade_data { # class method 'Edit package definition costs' => 'View package definition costs', 'List prospects' => 'List contacts', 'List customers' => 'List contacts', + 'Backdate payment' => 'Backdate credit', ); # foreach my $old_acl ( keys %onetime ) { diff --git a/httemplate/edit/cust_credit.cgi b/httemplate/edit/cust_credit.cgi index 29801efef..18416c5fb 100755 --- a/httemplate/edit/cust_credit.cgi +++ b/httemplate/edit/cust_credit.cgi @@ -6,15 +6,25 @@ - <% ntable("#cccccc", 2) %> - - <% mt('Date') |h %> - <% time2str($date_format, $_date) %> - +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% ); +% if ( $FS::CurrentUser::CurrentUser->access_right('Backdate credit') ) { + + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + +% } <% mt('Amount') |h %> diff --git a/httemplate/edit/cust_pay.cgi b/httemplate/edit/cust_pay.cgi index ec7391b20..888335fbb 100755 --- a/httemplate/edit/cust_pay.cgi +++ b/httemplate/edit/cust_pay.cgi @@ -23,37 +23,26 @@ <% mt('Payment') |h %> <% ntable("#cccccc", 2) %> +% my %date_args = ( +% 'name' => '_date', +% 'label' => emt('Date'), +% 'value' => $_date, +% 'format' => $date_format. ' %r', +% 'colspan' => 2, +% ); % if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) { - - <% mt('Date') |h %> - - - - - - -% } -% else { - - <% mt('Date') |h %> - - <% time2str($date_format.' %r',$_date) %> - - + <& /elements/tr-input-date-field.html, \%date_args &> + +% } else { + + <& /elements/tr-fixed-date.html, \%date_args &> + % } <% mt('Amount') |h %> - <% $money_char %> - <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %> + <% $money_char |h %> <% mt('by') |h %> <% mt(FS::payby->payname($payby)) |h %> % if ( $conf->exists('part_pkg-term_discounts') ) { diff --git a/httemplate/edit/process/cust_credit.cgi b/httemplate/edit/process/cust_credit.cgi index e442d7fa6..39c6f1997 100755 --- a/httemplate/edit/process/cust_credit.cgi +++ b/httemplate/edit/process/cust_credit.cgi @@ -42,11 +42,20 @@ if (!$reasonnum) { } $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; } diff --git a/httemplate/elements/tr-fixed-date.html b/httemplate/elements/tr-fixed-date.html index 716e5ceb8..ef599796d 100644 --- a/httemplate/elements/tr-fixed-date.html +++ b/httemplate/elements/tr-fixed-date.html @@ -1,12 +1,18 @@ <% include('tr-fixed.html', %opt ) %> <%init> -my %opt = @_; +my %opt; +if ( ref($_[0]) ) { + my $hashref = shift; + %opt = %$hashref; +} else { + %opt = @_; +} my $value = $opt{'curr_value'} || $opt{'value'}; my $conf = new FS::Conf; -my $date_format = $conf->config('date_format') || '%m/%d/%Y'; +my $date_format = $opt{'format'} || $conf->config('date_format') || '%m/%d/%Y'; $opt{'formatted_value'} = time2str($date_format, $value); -- 2.11.0