X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=members%2Fpaycollect.pl;h=b189107f25baaeb224d947e2766a0bffbdb7b2d8;hb=d7c1d52051a3cb5f6ae3be9abb0e9e7aa1f9ece5;hp=caf8f3b85164972f5088d2f81b7bf5b677e62354;hpb=308f52d76490d16045944442127939daccdbcc51;p=koha-ffzg.git diff --git a/members/paycollect.pl b/members/paycollect.pl index caf8f3b851..b189107f25 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -18,13 +18,12 @@ # along with Koha; if not, see . use Modern::Perl; -use URI::Escape; +use URI::Escape qw( uri_escape uri_unescape ); use CGI qw ( -utf8 ); use C4::Context; -use C4::Auth; -use C4::Output; -use C4::Members; +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers ); use C4::Accounts; use C4::Koha; @@ -33,8 +32,10 @@ use Koha::Patrons; use Koha::Patron::Categories; use Koha::AuthorisedValues; use Koha::Account; +use Koha::Account::Lines; +use Koha::AdditionalFields; use Koha::Token; -use Koha::DateUtils; +use Koha::DateUtils qw( output_pref ); my $input = CGI->new(); @@ -49,7 +50,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( query => $input, type => 'intranet', flagsrequired => { borrowers => 'edit_borrowers', updatecharges => $updatecharges_permissions }, - debug => 1, } ); @@ -59,7 +59,6 @@ my $logged_in_user = Koha::Patrons->find( $loggedinuser ); my $patron = Koha::Patrons->find( $borrowernumber ); output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); -my $borrower = $patron->unblessed; my $account = $patron->account; my $category = $patron->category; my $user = $input->remote_user; @@ -77,33 +76,7 @@ my $payment_note = uri_unescape scalar $input->param('payment_note'); my $payment_type = scalar $input->param('payment_type'); my $accountlines_id; -my $cash_register_id; -if ( C4::Context->preference('UseCashRegisters') ) { - $cash_register_id = $input->param('cash_register'); - my $registers = Koha::Cash::Registers->search( - { branch => $library_id, archived => 0 }, - { order_by => { '-asc' => 'name' } } - ); - - if ( !$registers->count ) { - $template->param( error_registers => 1 ); - } - else { - - if ( !$cash_register_id ) { - my $default_register = Koha::Cash::Registers->find( - { branch => $library_id, branch_default => 1 } ); - $cash_register_id = $default_register->id if $default_register; - } - $cash_register_id = $registers->next->id if !$cash_register_id; - - $template->param( - default_register => $cash_register_id, - registers => $registers, - ); - } -} - +my $cash_register_id = $input->param('cash_register'); if ( $pay_individual || $writeoff_individual ) { if ($pay_individual) { $template->param( pay_individual => 1 ); @@ -116,14 +89,12 @@ if ( $pay_individual || $writeoff_individual ) { my $amountoutstanding = $input->param('amountoutstanding'); my $itemnumber = $input->param('itemnumber'); my $description = $input->param('description'); - my $title = $input->param('title'); $total_due = $amountoutstanding; $template->param( debit_type_code => $debit_type_code, accountlines_id => $accountlines_id, amount => $amount, amountoutstanding => $amountoutstanding, - title => $title, itemnumber => $itemnumber, individual_description => $description, payment_note => $payment_note, @@ -153,7 +124,7 @@ if ( $selected_accts ) { @selected_accountlines = Koha::Account::Lines->search( $search_params, { order_by => 'date' } - ); + )->as_list; my $sum = Koha::Account::Lines->search( $search_params, @@ -201,6 +172,23 @@ if ( $total_paid and $total_paid ne '0.00' ) { ); $payment_id = $pay_result->{payment_id}; + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' }); + while ( my $field = $accountline_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + if (defined $value) { + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + } + if (@additional_fields) { + my $payment = Koha::Account::Lines->find($payment_id); + $payment->set_additional_fields(\@additional_fields); + } + + $url = "/cgi-bin/koha/members/pay.pl"; } else { if ($selected_accts) { @@ -244,6 +232,22 @@ if ( $total_paid and $total_paid ne '0.00' ) { } $payment_id = $pay_result->{payment_id}; + my @additional_fields; + my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' }); + while ( my $field = $accountline_fields->next ) { + my $value = $input->param('additional_field_' . $field->id); + if (defined $value) { + push @additional_fields, { + id => $field->id, + value => $value, + }; + } + } + if (@additional_fields) { + my $payment = Koha::Account::Lines->find($payment_id); + $payment->set_additional_fields(\@additional_fields); + } + $url = "/cgi-bin/koha/members/boraccount.pl"; } # It's possible renewals took place, parse any renew results @@ -267,8 +271,6 @@ if ( $total_paid and $total_paid ne '0.00' ) { $total_paid = '0.00'; #TODO not right with pay_individual } -$template->param(%$borrower); - if ( $input->param('error_over') ) { $template->param( error_over => 1, total_due => scalar $input->param('amountoutstanding') ); } @@ -282,6 +284,7 @@ $template->param( total => $total_due, csrf_token => Koha::Token->new->generate_csrf( { session_id => scalar $input->cookie('CGISESSID') } ), + available_additional_fields => [ Koha::AdditionalFields->search({ tablename => 'accountlines:credit' })->as_list ], ); output_html_with_http_headers $input, $cookie, $template->output;