Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 168 lines (156 sloc) 5.841 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
#!/usr/bin/env perl
# Copyright 2009 PTFS
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA

use strict;
use warnings;
use Koha;
use C4::Context;
use C4::Auth;
use C4::Output;
use CGI;
use C4::Members;
use C4::Accounts;
use C4::Koha;
use C4::Branch;
use C4::Dates;

my $input = new CGI;

my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
    { template_name => 'members/paycollect.tmpl',
        query => $input,
        type => 'intranet',
        authnotrequired => 0,
        flagsrequired => { borrowers => '*', updatecharges => 1 },
        debug => 1,
    }
);
my @names = $input->param();
my $borrowernumber = $input->param('borrowernumber');

# get borrower details
my $data = GetMember( $borrowernumber, 'borrowernumber' );
my $user = C4::Context->userenv->{id};

# get account details
my $branches = GetBranches();
my $branch = GetBranch( $input, $branches );

my($total_due,$accts) = C4::Accounts::MemberAllAccounts(borrowernumber=>$borrowernumber);
my $haveRefund = 0;
foreach(@$accts) {
   if (($$_{amountoutstanding} <0) && ($$_{accounttype} eq 'RCR')) {
      $haveRefund = 1;
   }
}
$template->param(refundtab => $haveRefund);

my $total_paid = $input->param('paid');
my $individual = $input->param('pay_individual');
my $writeoff = $input->param('writeoff_individual');
my $accountno;

if ( $individual || $writeoff ) {
    if ($individual) {
        $template->param( pay_individual => 1 );
    } elsif ($writeoff) {
        $template->param( writeoff_individual => 1 );
    }
    my $accounttype = $input->param('accounttype');
    my $amount = $input->param('amount');
    my $amountoutstanding = $input->param('amountoutstanding');
    $accountno = $input->param('accountno');
    my $description = $input->param('description');
    my $title = $input->param('title');
    my $notify_id = $input->param('notify_id');
    my $notify_level = $input->param('notify_level');
    my $itemnumber = $input->param('itemnumber');
    my $biblionumber = $input->param('biblionumber');
    my $barcode = $input->param('barcode');
    my $date = $input->param('date');
    $total_due = $amountoutstanding;
    $template->param(
        itemnumber => $itemnumber,
        biblionumber => $biblionumber,
        barcode => $barcode,
        accounttype => $accounttype,
        accountno => $accountno,
        amount => $amount,
        amountoutstanding => $amountoutstanding,
        date => $date,
        title => $title,
        description => $description,
        notify_id => $notify_id,
        notify_level => $notify_level,
    );
}

if ( $total_paid and $total_paid ne '0.00' ) {
    if (( $total_paid <= 0) or ($total_paid > $total_due )) {
        $template->param(
            error => "You must pay a value less than or equal to $total_due" );
    } else {
        if ($individual) {
            if ( $total_paid == $total_due ) {
                makepayment( $borrowernumber, $accountno, $total_paid, $user,
                    $branch );
            } else {
                makepartialpayment( $borrowernumber, $accountno, $total_paid,
                    $user, $branch );
            }
            print $input->redirect(
                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber" );
        } else {
            recordpayment( $borrowernumber, $total_paid );

# recordpayment does not return success or failure so lets redisplay the boraccount
            print $input->redirect(
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
            );
        }
    }
} else {
    $total_paid = '0.00'; #TODO not right with pay_individual
}
if ( $data->{category_type} eq 'C' ) {
    my ( $catcodes, $labels ) =
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
    my $cnt = scalar @{$catcodes};
    if ( $cnt == 1 ) {
        $template->param( 'catcode' => $catcodes->[0] );
    } elsif ( $cnt > 1 ) {
        $template->param( 'CATCODE_MULTI' => 1 );
    }
}

if ( $data->{'category_type'} eq 'A' ) {
    $template->param( adultborrower => 1 );
}
my ( $picture, $dberror ) = GetPatronImage( $data->{'cardnumber'} );
if ($picture) {
    $template->param( picture => 1 );
}

$template->param(
    firstname => $data->{firstname},
    surname => $data->{surname},
    borrowernumber => $borrowernumber,
    cardnumber => $data->{cardnumber},
    categorycode => $data->{categorycode},
    category_type => $data->{category_type},
    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' ),
    total => sprintf( '%.2f', $total_due ),
);
output_html_with_http_headers $input, $cookie, $template->output;
Something went wrong with that request. Please try again.