Bug 8485 - Make koha_perl_deps.pl batch friendly Added a -b flag for brief which...
[koha.git] / members / paycollect.pl
blob7dfb6223930a5cbea1c6bf71e4d3e71d2a994e6c
1 #!/usr/bin/perl
2 # Copyright 2009,2010 PTFS Inc.
3 # Copyright 2011 PTFS-Europe Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
22 use C4::Context;
23 use C4::Auth;
24 use C4::Output;
25 use CGI;
26 use C4::Members;
27 use C4::Accounts;
28 use C4::Koha;
29 use C4::Branch;
31 my $input = CGI->new();
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 { template_name => 'members/paycollect.tmpl',
35 query => $input,
36 type => 'intranet',
37 authnotrequired => 0,
38 flagsrequired => { borrowers => 1, updatecharges => 1 },
39 debug => 1,
43 # get borrower details
44 my $borrowernumber = $input->param('borrowernumber');
45 my $borrower = GetMember( borrowernumber => $borrowernumber );
46 my $user = $input->remote_user;
48 # get account details
49 my $branch = GetBranch( $input, GetBranches() );
51 my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
52 my $total_paid = $input->param('paid');
54 my $individual = $input->param('pay_individual');
55 my $writeoff = $input->param('writeoff_individual');
56 my $select_lines = $input->param('selected');
57 my $select = $input->param('selected_accts');
58 my $accountno;
60 if ( $individual || $writeoff ) {
61 if ($individual) {
62 $template->param( pay_individual => 1 );
63 } elsif ($writeoff) {
64 $template->param( writeoff_individual => 1 );
66 my $accounttype = $input->param('accounttype');
67 my $amount = $input->param('amount');
68 my $amountoutstanding = $input->param('amountoutstanding');
69 $accountno = $input->param('accountno');
70 my $itemnumber = $input->param('itemnumber');
71 my $description = $input->param('description');
72 my $title = $input->param('title');
73 my $notify_id = $input->param('notify_id');
74 my $notify_level = $input->param('notify_level');
75 $total_due = $amountoutstanding;
76 $template->param(
77 accounttype => $accounttype,
78 accountno => $accountno,
79 amount => $amount,
80 amountoutstanding => $amountoutstanding,
81 title => $title,
82 itemnumber => $itemnumber,
83 description => $description,
84 notify_id => $notify_id,
85 notify_level => $notify_level,
87 } elsif ($select_lines) {
88 $total_due = $input->param('amt');
89 $template->param(
90 selected_accts => $select_lines,
91 amt => $total_due
95 if ( $total_paid and $total_paid ne '0.00' ) {
96 if ( $total_paid < 0 or $total_paid > $total_due ) {
97 $template->param(
98 error => sprintf( 'You must pay a value less than or equal to %f.2',
99 $total_due )
101 } else {
102 if ($individual) {
103 if ( $total_paid == $total_due ) {
104 makepayment( $borrowernumber, $accountno, $total_paid, $user,
105 $branch );
106 } else {
107 makepartialpayment( $borrowernumber, $accountno, $total_paid,
108 $user, $branch );
110 print $input->redirect(
111 "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
112 } else {
113 if ($select) {
114 if ( $select =~ /^([\d,]*).*/ ) {
115 $select = $1; # ensure passing no junk
117 my @acc = split /,/, $select;
118 recordpayment_selectaccts( $borrowernumber, $total_paid,
119 \@acc );
120 } else {
121 recordpayment( $borrowernumber, $total_paid );
124 # recordpayment does not return success or failure so lets redisplay the boraccount
126 print $input->redirect(
127 "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
131 } else {
132 $total_paid = '0.00'; #TODO not right with pay_individual
135 borrower_add_additional_fields($borrower);
137 $template->param(
138 borrowernumber => $borrowernumber, # some templates require global
139 borrower => $borrower,
140 total => $total_due,
141 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
144 output_html_with_http_headers $input, $cookie, $template->output;
146 sub borrower_add_additional_fields {
147 my $b_ref = shift;
149 # some borrower info is not returned in the standard call despite being assumed
150 # in a number of templates. It should not be the business of this script but in lieu of
151 # a revised api here it is ...
152 if ( $b_ref->{category_type} eq 'C' ) {
153 my ( $catcodes, $labels ) =
154 GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
155 if ( @{$catcodes} ) {
156 if ( @{$catcodes} > 1 ) {
157 $b_ref->{CATCODE_MULTI} = 1;
158 } elsif ( @{$catcodes} == 1 ) {
159 $b_ref->{catcode} = $catcodes->[0];
162 } elsif ( $b_ref->{category_type} eq 'A' ) {
163 $b_ref->{adultborrower} = 1;
165 my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
166 if ($picture) {
167 $b_ref->{has_picture} = 1;
170 $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
171 return;