Enhancement Bug 4444: Centralize Code Handling Perl Dependencies
[koha.git] / members / maninvoice.pl
blobdf12a2a47707d2bcf8c713fe2fd63c4a791a0c2b
1 #!/usr/bin/perl
3 #written 11/1/2000 by chris@katipo.oc.nz
4 #script to display borrowers account details
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use warnings;
27 use C4::Auth;
28 use C4::Output;
29 use CGI;
30 use C4::Members;
31 use C4::Accounts;
32 use C4::Items;
33 use C4::Branch;
35 my $input=new CGI;
37 my $borrowernumber=$input->param('borrowernumber');
40 # get borrower details
41 my $data=GetMember('borrowernumber'=>$borrowernumber);
42 my $add=$input->param('add');
43 if ($add){
44 # print $input->header;
45 my $barcode=$input->param('barcode');
46 my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
47 my $desc=$input->param('desc');
48 my $amount=$input->param('amount');
49 my $type=$input->param('type');
50 my $error=manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
51 if ($error){
52 my ($template, $loggedinuser, $cookie)
53 = get_template_and_user({template_name => "members/maninvoice.tmpl",
54 query => $input,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => {borrowers => 1},
58 debug => 1,
59 });
60 if ($error =~ /FOREIGN KEY/ && $error =~ /itemnumber/){
61 $template->param('ITEMNUMBER' => 1);
63 $template->param('ERROR' => $error);
64 output_html_with_http_headers $input, $cookie, $template->output;
66 else {
67 print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
68 exit;
70 } else {
72 my ($template, $loggedinuser, $cookie)
73 = get_template_and_user({template_name => "members/maninvoice.tmpl",
74 query => $input,
75 type => "intranet",
76 authnotrequired => 0,
77 flagsrequired => {borrowers => 1, updatecharges => 1},
78 debug => 1,
79 });
81 # get authorised values with type of MANUAL_INV
82 my @invoice_types;
83 my $dbh = C4::Context->dbh;
84 my $sth = $dbh->prepare('SELECT * FROM authorised_values WHERE category = "MANUAL_INV"');
85 $sth->execute();
86 while ( my $row = $sth->fetchrow_hashref() ) {
87 push @invoice_types, $row;
89 $template->param( invoice_types_loop => \@invoice_types );
91 if ( $data->{'category_type'} eq 'C') {
92 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
93 my $cnt = scalar(@$catcodes);
94 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
95 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
98 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
99 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
100 $template->param( picture => 1 ) if $picture;
102 $template->param(
103 borrowernumber => $borrowernumber,
104 firstname => $data->{'firstname'},
105 surname => $data->{'surname'},
106 cardnumber => $data->{'cardnumber'},
107 categorycode => $data->{'categorycode'},
108 category_type => $data->{'category_type'},
109 categoryname => $data->{'description'},
110 address => $data->{'address'},
111 address2 => $data->{'address2'},
112 city => $data->{'city'},
113 zipcode => $data->{'zipcode'},
114 country => $data->{'country'},
115 phone => $data->{'phone'},
116 email => $data->{'email'},
117 branchcode => $data->{'branchcode'},
118 branchname => GetBranchName($data->{'branchcode'}),
119 is_child => ($data->{'category_type'} eq 'C'),
121 output_html_with_http_headers $input, $cookie, $template->output;