use Modern::Perl;
use CGI;
-use C4::Auth;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
use C4::Context;
use Koha::Account::Lines;
use Koha::Cash::Registers;
use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
my $input = CGI->new();
$input->param('trange_t') ? $input->param('trange_t')
: $last_cashup ? $last_cashup->timestamp
: '';
- my $end = dt_from_string($transactions_range_to);
+ my $end = dt_from_string($transactions_range_to);
+ $end = $end->set( { hour => 23, minute => 59, second => 59 } ); # To should be 'inclusive'
if ($transactions_range_from) {
}
}
);
- $template->param( past_accountlines => $past_accountlines );
- $template->param( trange_f => output_pref({dt => $start, dateonly => 1}));
+ $template->param(
+ past_accountlines => $past_accountlines,
+ trange_f => $start,
+ );
}
- $template->param( trange_t => output_pref({dt => $end, dateonly => 1}));
+ $template->param( trange_t => $end, );
my $op = $input->param('op') // '';
if ( $op eq 'cashup' ) {
- $cash_register->add_cashup(
- {
- manager_id => $logged_in_user->id,
- amount => $cash_register->outstanding_accountlines->total
- }
- );
+ if ( $logged_in_user->has_permission( { cash_management => 'cashup' } ) ) {
+ $cash_register->add_cashup(
+ {
+ manager_id => $logged_in_user->id,
+ amount => $cash_register->outstanding_accountlines->total
+ }
+ );
+ }
+ else {
+ $template->param( error_cashup_permission => 1 );
+ }
}
elsif ( $op eq 'refund' ) {
- my $amount = $input->param('amount');
- my $quantity = $input->param('quantity');
- my $accountline_id = $input->param('accountline');
- my $transaction_type = $input->param('transaction_type');
-
- my $accountline = Koha::Account::Lines->find($accountline_id);
- $schema->txn_do(
- sub {
-
- my $refund = $accountline->reduce(
- {
- reduction_type => 'Refund',
- branch => $library_id,
- staff_id => $logged_in_user->id,
- interface => 'intranet',
- amount => $amount
- }
- );
- my $payout = $refund->payout(
- {
- payout_type => $transaction_type,
- branch => $library_id,
- staff_id => $logged_in_user->id,
- cash_register => $cash_register->id,
- interface => 'intranet',
- amount => $amount
- }
- );
+ if ( $logged_in_user->has_permission( { cash_management => 'anonymous_refund' } ) ) {
+ my $amount = $input->param('amount');
+ my $quantity = $input->param('quantity');
+ my $accountline_id = $input->param('accountline');
+ my $refund_type = $input->param('refund_type');
+
+ my $accountline = Koha::Account::Lines->find($accountline_id);
+ $schema->txn_do(
+ sub {
+
+ my $refund = $accountline->reduce(
+ {
+ reduction_type => 'REFUND',
+ branch => $library_id,
+ staff_id => $logged_in_user->id,
+ interface => 'intranet',
+ amount => $amount
+ }
+ );
+ my $payout = $refund->payout(
+ {
+ payout_type => $refund_type,
+ branch => $library_id,
+ staff_id => $logged_in_user->id,
+ cash_register => $cash_register->id,
+ interface => 'intranet',
+ amount => $amount
+ }
+ );
- }
- );
+ }
+ );
+ }
+ else {
+ $template->param( error_refund_permission => 1 );
+ }
}
}