[followup](bug #4051) add borrower "title", and complete address in csv
[koha.git] / members / mancredit.pl
index d3d182d..5a7ec1d 100755 (executable)
@@ -27,7 +27,10 @@ use C4::Output;
 use CGI;
 
 use C4::Members;
+use C4::Branch;
 use C4::Accounts;
+use C4::Items;
+
 my $input=new CGI;
 
 my $borrowernumber=$input->param('borrowernumber');
@@ -37,7 +40,8 @@ my $data=GetMember($borrowernumber,'borrowernumber');
 my $add=$input->param('add');
 
 if ($add){
-    my $itemnum=$input->param('itemnum');
+    my $barcode=$input->param('barcode');
+    my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
     my $desc=$input->param('desc');
     my $amount=$input->param('amount');
     $amount = -$amount;
@@ -50,9 +54,17 @@ if ($add){
                                          query => $input,
                                          type => "intranet",
                                          authnotrequired => 0,
-                                         flagsrequired => {borrowers => 1},
+                                         flagsrequired => {borrowers => 1, updatecharges => 1},
                                          debug => 1,
                                          });
+                                         
+    if ( $data->{'category_type'} eq 'C') {
+        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
+        my $cnt = scalar(@$catcodes);
+        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
+        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
+    }
+                                         
     $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
     my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
     $template->param( picture => 1 ) if $picture;
@@ -64,13 +76,16 @@ if ($add){
                    cardnumber => $data->{'cardnumber'},
                    categorycode => $data->{'categorycode'},
                    category_type => $data->{'category_type'},
-                   category_description => $data->{'description'},
+                   categoryname  => $data->{'description'},
                    address => $data->{'address'},
                    address2 => $data->{'address2'},
                    city => $data->{'city'},
                    zipcode => $data->{'zipcode'},
                    phone => $data->{'phone'},
                    email => $data->{'email'},
+                   branchcode => $data->{'branchcode'},
+                   branchname => GetBranchName($data->{'branchcode'}),
+                   is_child        => ($data->{'category_type'} eq 'C'),
         );
-    print $input->header( -type => 'utf-8', -cookie => $cookie),$template->output;
+    output_html_with_http_headers $input, $cookie, $template->output;
 }