Add predefined fee types
[koha.git] / members / maninvoice.pl
1 #!/usr/bin/perl
2
3 #wrriten 11/1/2000 by chris@katipo.oc.nz
4 #script to display borrowers account details
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Auth;
26 use C4::Output;
27 use CGI;
28 use C4::Members;
29 use C4::Accounts;
30 use C4::Items;
31 use C4::Branch;
32
33 my $input=new CGI;
34
35 my $borrowernumber=$input->param('borrowernumber');
36
37
38 # get borrower details
39 my $data=GetMember($borrowernumber,'borrowernumber');
40 my $add=$input->param('add');
41 if ($add){
42 #  print $input->header;
43     my $barcode=$input->param('barcode');
44     my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
45     my $desc=$input->param('desc');
46     my $amount=$input->param('amount');
47     my $type=$input->param('type');
48     my $error=manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
49         if ($error){
50                 my ($template, $loggedinuser, $cookie)
51                   = get_template_and_user({template_name => "members/maninvoice.tmpl",
52                                         query => $input,
53                                         type => "intranet",
54                                         authnotrequired => 0,
55                                         flagsrequired => {borrowers => 1},
56                                         debug => 1,
57                                         });
58                 if ($error =~ /FOREIGN KEY/ && $error =~ /itemnumber/){
59                         $template->param('ITEMNUMBER' => 1);
60                 }
61                 $template->param('ERROR' => $error);
62         output_html_with_http_headers $input, $cookie, $template->output;
63         }
64         else {
65                 print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
66                 exit;
67         }
68 } else {
69
70         my ($template, $loggedinuser, $cookie)
71         = get_template_and_user({template_name => "members/maninvoice.tmpl",
72                                         query => $input,
73                                         type => "intranet",
74                                         authnotrequired => 0,
75                                         flagsrequired => {borrowers => 1, updatecharges => 1},
76                                         debug => 1,
77                                         });
78                                         
79   # get authorised values with type of MANUAL_INV
80   my @invoice_types;
81   my $dbh = C4::Context->dbh;
82   my $sth = $dbh->prepare('SELECT * FROM authorised_values WHERE category = "MANUAL_INV"');
83   $sth->execute();
84   while ( my $row = $sth->fetchrow_hashref() ) {
85     push @invoice_types, $row;
86   }
87   $template->param( invoice_types_loop => \@invoice_types );
88
89     if ( $data->{'category_type'} eq 'C') {
90         my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
91         my $cnt = scalar(@$catcodes);
92         $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
93         $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
94     }
95
96     $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
97     my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
98     $template->param( picture => 1 ) if $picture;
99
100         $template->param(
101                 borrowernumber => $borrowernumber,
102                 firstname => $data->{'firstname'},
103                 surname  => $data->{'surname'},
104                 cardnumber => $data->{'cardnumber'},
105                 categorycode => $data->{'categorycode'},
106                 category_type => $data->{'category_type'},
107                 categoryname  => $data->{'description'},
108                 address => $data->{'address'},
109                 address2 => $data->{'address2'},
110                 city => $data->{'city'},
111                 zipcode => $data->{'zipcode'},
112                 country => $data->{'country'},
113                 phone => $data->{'phone'},
114                 email => $data->{'email'},
115                 branchcode => $data->{'branchcode'},
116                 branchname => GetBranchName($data->{'branchcode'}),
117                 is_child        => ($data->{'category_type'} eq 'C'),
118     );
119     output_html_with_http_headers $input, $cookie, $template->output;
120 }