View | Details | Raw Unified | Return to bug 2169
Collapse All | Expand All

(-)a/C4/Accounts.pm (-2 / +55 lines)
Lines 36-42 BEGIN { Link Here
36
	@EXPORT = qw(
36
	@EXPORT = qw(
37
		&recordpayment &makepayment &manualinvoice
37
		&recordpayment &makepayment &manualinvoice
38
		&getnextacctno &reconcileaccount &getcharges &getcredits
38
		&getnextacctno &reconcileaccount &getcharges &getcredits
39
		&getrefunds &chargelostitem
39
		&getrefunds &chargelostitem &writeoff &negotiate
40
		&ReversePayment
40
		&ReversePayment
41
	); # removed &fixaccounts
41
	); # removed &fixaccounts
42
}
42
}
Lines 171-177 sub makepayment { Link Here
171
171
172
    $dbh->do(
172
    $dbh->do(
173
        "UPDATE  accountlines
173
        "UPDATE  accountlines
174
        SET     amountoutstanding = 0
174
        SET     amountoutstanding = amountoutstanding - $amount
175
        WHERE   borrowernumber = $borrowernumber
175
        WHERE   borrowernumber = $borrowernumber
176
          AND   accountno = $accountno
176
          AND   accountno = $accountno
177
        "
177
        "
Lines 649-654 sub getrefunds { Link Here
649
    return (@results);
649
    return (@results);
650
}
650
}
651
651
652
sub writeoff {
653
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
654
    my $dbh  = C4::Context->dbh;
655
    undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
656
    
657
    my $query = "UPDATE accountlines SET amountoutstanding = amountoutstanding - $amount WHERE accountno = ? AND borrowernumber = ?";
658
    my $sth = $dbh->prepare( $query );
659
    $sth->execute( $accountnum, $borrowernumber );
660
661
    my $next_accountno = getnextacctno( $borrowernumber );
662
663
    $query = "INSERT INTO accountlines
664
                ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype )
665
              VALUES 
666
                ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W' )
667
             ";
668
    $sth = $dbh->prepare( $query );
669
    $sth->execute( $borrowernumber, $next_accountno, $itemnum, $amount );
670
671
    UpdateStats( C4::Context->userenv->{branch}, 'writeoff', $amount, '', '', '', $borrowernumber );
672
}
673
674
sub negotiate {
675
    my ( $borrowernumber, $accountno, $amount, $itemnumber ) = @_;
676
    my $dbh  = C4::Context->dbh;
677
    
678
    my $query = "
679
      UPDATE
680
        accountlines
681
      SET 
682
        amount = amount - ?,
683
        description = CONCAT( description, '*' ),
684
        amountoutstanding = amountoutstanding - ?,
685
        timestamp = NOW()
686
      WHERE
687
        accountno = ?
688
      AND
689
        borrowernumber = ?
690
    ";    
691
    my $sth = $dbh->prepare( $query );
692
    $sth->execute( $amount, $amount, $accountno, $borrowernumber );
693
694
    my $next_accountno = getnextacctno( $borrowernumber );
695
    
696
    $query = "INSERT INTO accountlines
697
                ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype )
698
              VALUES 
699
                ( ?, ?, ?, NOW(), ?, 'Negotiated', 'N' )
700
             ";
701
    $sth = $dbh->prepare( $query );
702
    $sth->execute( $borrowernumber, $next_accountno, $itemnumber, $amount );
703
}
704
652
sub ReversePayment {
705
sub ReversePayment {
653
  my ( $borrowernumber, $accountno ) = @_;
706
  my ( $borrowernumber, $accountno ) = @_;
654
  my $dbh = C4::Context->dbh;
707
  my $dbh = C4::Context->dbh;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl (-11 / +136 lines)
Lines 1-6 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
2
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
5
<script type='text/javascript'>
6
	function payfineOnChange( id, amount ) {
7
		var selectName = "payfine" + id;
8
		var inputName = "amount_to_pay" + id;
9
10
		var mySelect = document.getElementsByName( selectName )[0];
11
		var myInput = document.getElementsByName( inputName )[0];
12
13
		if ( mySelect.value == "no" ) {
14
			myInput.value = '';
15
		} else {
16
			if ( myInput.value == '' ) {
17
				myInput.value = amount;
18
				myInput.select().focus();
19
			}
20
		}
21
	}
22
23
	function amountOnChange( id ) {
24
                var selectName = "payfine" + id;
25
                var inputName = "amount_to_pay" + id;
26
27
                var mySelect = document.getElementsByName( selectName )[0];
28
                var myInput = document.getElementsByName( inputName )[0];         
29
30
		if ( myInput.value == '' ) {
31
			mySelect.selectedIndex = 0;
32
		} else {
33
			if ( mySelect.selectedIndex == 0 ) {
34
				mySelect.selectedIndex = 1;
35
			}
36
		}
37
	}
38
39
	function checkField( fieldname, total ){
40
41
        	var myInput = document.getElementsByName( fieldname )[0];
42
		total = parseFloat( total );
43
44
		if ( myInput.value != '' ) {
45
		        var regExp = /^\d*(\.\d{2})?$/; // This regular express only accepts floating point numbers ex. 5, 5.30, .80, etc...
46
		        if ( ! regExp.test( myInput.value ) ) {
47
		                alert("Invalid Amount: " + myInput.value );
48
				myInput.focus();
49
				myInput.select();
50
		                return false;
51
		        }
52
53
54
		        if ( myInput.value > total ) {
55
		                if ( confirm("You are trying to make a payment larger then the Amount Outstanding.\n\nAre you sure you want to do this?") ) {
56
		                        return true;
57
		                } else {
58
		                        myInput.focus();   
59
		                        myInput.select();  
60
		                        return false;
61
		                }
62
		        }
63
64
		        if ( myInput.value.indexOf('.') < 0 ) {
65
		                if ( confirm("The amount you've entered has no '.'\n\nAre you sure you want to do this?") ) {
66
		                        return true;
67
		                } else {
68
		                        myInput.focus();   
69
		                        myInput.select();  
70
		
71
		                        return false;
72
		                }
73
		        }
74
75
		}
76
77
	        return true;
78
	}
79
80
	function formatField( myInput ) {
81
		if ( myInput.value && !isNaN( myInput.value ) ) {
82
			myInput.value = formatAsCurrency( myInput.value );
83
		}
84
	}
85
86
	function formatAsCurrency(number) {
87
		number = number.toString().replace(/\$|\,/g,'');
88
		if ( isNaN( number ) ) number = "0";
89
		number = Math.floor( number * 100 + 0.50000000001 );
90
		cents = number % 100;
91
		number = Math.floor(number/100).toString();
92
		
93
		if( cents < 10 ) cents = "0" + cents;
94
95
		for (var i = 0; i < Math.floor((number.length-(1+i))/3); i++) {
96
			number = number.substring( 0, number.length - ( 4 * i + 3 ) ) + ',' + number.substring( number.length - ( 4 * i + 3 ) );
97
		}
98
		return number + '.' + cents;
99
	}
100
</script>
101
4
</head>
102
</head>
5
<body>
103
<body>
6
<!-- TMPL_INCLUDE NAME="header.inc" -->
104
<!-- TMPL_INCLUDE NAME="header.inc" -->
Lines 30-41 Link Here
30
128
31
<table>
129
<table>
32
<tr>
130
<tr>
33
	<th>Fines &amp; Charges</th>
131
	<th>Action</th>
132
	<th>Amount</th>
34
	<th>Description</th>
133
	<th>Description</th>
35
	<th>Account Type</th>
134
	<th>Account Type</th>
36
	<th>Notify id</th>
135
	<th>Notify id</th>
37
	<th>Level</th>
136
	<th>Level</th>
38
	<th>Amount</th>
137
	<th>Fine Amount</th>
39
	<th>Amount Outstanding</th>
138
	<th>Amount Outstanding</th>
40
</tr>
139
</tr>
41
	
140
	
Lines 43-55 Link Here
43
	<!-- TMPL_LOOP name="loop_pay" -->
142
	<!-- TMPL_LOOP name="loop_pay" -->
44
<tr>
143
<tr>
45
	<td>
144
	<td>
46
	<!-- TMPL_IF NAME="net_balance" -->
145
47
	<select name="payfine<!-- TMPL_VAR name="i" -->">
146
	<select name="payfine<!-- TMPL_VAR name="i" -->" onchange="payfineOnChange('<!-- TMPL_VAR name="i" -->', '<!-- TMPL_VAR name="amountoutstanding" -->')" >
48
	<option value="no">Unpaid</option>
147
		<option value="no">Don't Pay</option>
49
	<option value="yes">Paid</option>
148
		<option value="yes">Pay</option>
50
	<option value="wo">Writeoff</option>
149
		<option value="wo">Writeoff</option>
150
		<option value="ng">Negotiate</option>
51
	</select>
151
	</select>
52
	<!-- /TMPL_IF -->
152
53
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
153
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
54
	<input type="hidden" name="accounttype<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accounttype" -->" />
154
	<input type="hidden" name="accounttype<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accounttype" -->" />
55
	<input type="hidden" name="amount<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amount" -->" />
155
	<input type="hidden" name="amount<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amount" -->" />
Lines 60-65 Link Here
60
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
160
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
61
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
161
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
62
	</td>
162
	</td>
163
	<td>
164
		<input 
165
			type="text" 
166
			name="amount_to_pay<!-- TMPL_VAR name="i" -->" 
167
			size="6" 
168
			onkeyup="amountOnChange('<!-- TMPL_VAR name="i" -->')"
169
			onchange="formatField( this )";
170
			onblur="return checkField( 'amount_to_pay<!-- TMPL_VAR name="i" -->', '<!-- TMPL_VAR name="amountoutstanding" -->')"
171
		/>
172
	</td>
63
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
173
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
64
	<td><!-- TMPL_VAR name="accounttype" --></td>
174
	<td><!-- TMPL_VAR name="accounttype" --></td>
65
	<td><!-- TMPL_VAR name="notify_id" --></td>
175
	<td><!-- TMPL_VAR name="notify_id" --></td>
Lines 71-89 Link Here
71
<!-- TMPL_IF  NAME="total"-->
181
<!-- TMPL_IF  NAME="total"-->
72
<tr>
182
<tr>
73
183
74
	<td colspan="6">Sub Total</td>
184
	<td colspan="7">Sub Total</td>
75
	<td><!-- TMPL_VAR name="total" --></td>
185
	<td><!-- TMPL_VAR name="total" --></td>
76
</tr>
186
</tr>
77
<!--/TMPL_IF-->
187
<!--/TMPL_IF-->
78
<!-- /TMPL_LOOP  -->
188
<!-- /TMPL_LOOP  -->
79
<tr>
189
<tr>
80
	<td colspan="6">Total Due</td>
190
	<td colspan="7">Total Due</td>
81
	<td><!-- TMPL_VAR name="total" --></td>
191
	<td><!-- TMPL_VAR name="total" --></td>
82
</tr>
192
</tr>
83
</table>
193
</table>
84
<fieldset class="action"><input type="submit" name="submit"  value="Make Payment" class="submit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset></form><!-- TMPL_ELSE --><p><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> has no outstanding fines.</p><!-- /TMPL_IF -->
194
<fieldset class="action"><input type="submit" name="submit"  value="Update Fines & Charges" class="submit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset></form>
195
196
<fieldset>
197
  <legend>Pay Fines by Amount</legend>
198
  <form class="inline" action="pay.pl" method="post" onsubmit="return checkField( 'pay_by_amount', '<!-- TMPL_VAR name="total" -->')">
199
    <input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR name="borrowernumber" -->" />
200
    <label for="pay_by_amount">Amount to be paid:</label>
201
    <input id="pay_by_amount" name="pay_by_amount" type="text" />
202
    <input type="submit" name="submit"  value="Make Partial Payment" class="submit"/>
203
  </form>
204
</fieldset>
85
</div></div>
205
</div></div>
86
206
207
<!-- TMPL_ELSE -->
208
	<p><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> has no outstanding fines.</p>
209
<!-- /TMPL_IF -->
210
211
87
</div>
212
</div>
88
</div>
213
</div>
89
214
(-)a/members/pay.pl (-127 / +70 lines)
Lines 52-137 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
52
    }
52
    }
53
);
53
);
54
54
55
my $borrowernumber = $input->param('borrowernumber');
55
my $borrowernumber = $input->param('borrowernumber') || $input->param('borrowernumber00');
56
if ( $borrowernumber eq '' ) {
57
    $borrowernumber = $input->param('borrowernumber0');
58
}
59
56
60
# get borrower details
57
# get borrower details
61
my $data = GetMember( borrowernumber => $borrowernumber );
58
my $data = GetMember( borrowernumber => $borrowernumber );
62
my $user = $input->remote_user;
63
59
64
# get account details
60
# get account details
65
my $branches = GetBranches();
61
my $branches = GetBranches();
66
my $branch   = GetBranch( $input, $branches );
62
my $branch = GetBranch( $input, $branches );
67
63
68
my @names = $input->param;
64
my $index = '0';
69
my %inp;
65
while ( $input->param( "payfine$index") ) {
70
my $check = 0;
66
    my $payfine = $input->param( "payfine$index" );
71
for ( my $i = 0 ; $i < @names ; $i++ ) {
67
    my $amount         = $input->param( "amount$index" );
72
    my $temp = $input->param( $names[$i] );
68
    my $accountno      = $input->param( "accountno$index" );
73
    if ( $temp eq 'wo' ) {
69
    my $amount_to_pay  = $input->param( "amount_to_pay$index" );
74
        $inp{ $names[$i] } = $temp;
70
    my $itemnumber     = $input->param( "itemnumber$index" );
75
        $check = 1;
71
    my $accounttype    = $input->param( "accounttype$index" );
76
    }
72
    $amount = $amount_to_pay if ( $amount_to_pay );
77
    if ( $temp eq 'yes' ) {
73
78
74
    if ( $payfine eq 'yes' ) { ## Standard Fine Payment        
79
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
75
        makepayment( $borrowernumber, $accountno, $amount, '', $branch );
80
        my $amount         = $input->param( $names[ $i + 4 ] );
76
    } elsif ( $payfine eq 'wo' ) { ## Writeoff
81
        my $borrowernumber = $input->param( $names[ $i + 5 ] );
77
      writeoff( $borrowernumber, $accountno, $itemnumber, $accounttype, $amount );
82
        my $accountno      = $input->param( $names[ $i + 6 ] );
78
    } elsif ( $payfine eq 'ng' ) { ## Negotiate Fine
83
        makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
79
      negotiate( $borrowernumber, $accountno, $amount, $itemnumber );
84
        $check = 2;
85
    }
80
    }
81
    
82
    $index++;
86
}
83
}
87
my $total = $input->param('total') || '';
88
if ( $check == 0 ) {
89
    if ( $total ne '' ) {
90
        recordpayment( $borrowernumber, $total );
91
    }
92
84
93
    my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
85
## Pay by Amount
94
86
my $total_to_pay = $input->param('pay_by_amount');
95
    my @allfile;
87
if ( $total_to_pay ) {
96
    my @notify = NumberNotifyId($borrowernumber);
88
    recordpayment( $borrowernumber, $total_to_pay );
97
89
}
98
    my $numberofnotify = scalar(@notify);
99
    for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
100
        my @loop_pay;
101
        my ( $total , $accts, $numaccts) =
102
          GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
103
        for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
104
            my %line;
105
            if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
106
                $accts->[$i]{'amount'}            += 0.00;
107
                $accts->[$i]{'amountoutstanding'} += 0.00;
108
                $line{i}           = $j . "" . $i;
109
                $line{itemnumber}  = $accts->[$i]{'itemnumber'};
110
                $line{accounttype} = $accts->[$i]{'accounttype'};
111
                $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
112
                $line{amountoutstanding} =
113
                  sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
114
                $line{borrowernumber} = $borrowernumber;
115
                $line{accountno}      = $accts->[$i]{'accountno'};
116
                $line{description}    = $accts->[$i]{'description'};
117
                $line{title}          = $accts->[$i]{'title'};
118
                $line{notify_id}      = $accts->[$i]{'notify_id'};
119
                $line{notify_level}   = $accts->[$i]{'notify_level'};
120
                $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
121
                push( @loop_pay, \%line );
122
            }
123
        }
124
90
125
        my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
91
## Get Fine Details
126
        ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
92
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
127
        push @allfile,
93
128
          {
94
my @allfile;
129
            'loop_pay' => \@loop_pay,
95
my @notify = NumberNotifyId($borrowernumber);
130
            'notify'   => $notify[$j],
96
131
            'total'    =>  sprintf( "%.2f",$totalnotify),
97
my $numberofnotify = scalar(@notify);
132
			
98
my $k = 0;
133
          };
99
for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
100
    my @loop_pay;
101
    my ( $total , $accts, $numaccts) = GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
102
    for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
103
        my %line;
104
        if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
105
            $accts->[$i]{'amount'}            += 0.00;
106
            $accts->[$i]{'amountoutstanding'} += 0.00;
107
            $line{i}           = $k;
108
            $line{itemnumber}  = $accts->[$i]{'itemnumber'};
109
            $line{accounttype} = $accts->[$i]{'accounttype'};
110
            $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
111
            $line{amountoutstanding} = sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
112
            $line{borrowernumber} = $borrowernumber;
113
            $line{accountno}      = $accts->[$i]{'accountno'};
114
            $line{description}    = $accts->[$i]{'description'};
115
            $line{title}          = $accts->[$i]{'title'};
116
            $line{notify_id}      = $accts->[$i]{'notify_id'};
117
            $line{notify_level}   = $accts->[$i]{'notify_level'};
118
            $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
119
            push( @loop_pay, \%line );
120
            $k++;
121
        }
134
    }
122
    }
123
 
124
    my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
125
    $totalnotify = '0' if ( $totalnotify =~ /^0.00/ );
126
    push @allfile,
127
      {
128
        'loop_pay' => \@loop_pay,
129
        'notify'   => $notify[$j],
130
        'total'    =>  sprintf( "%.2f",$totalnotify),
131
      };
132
}
135
	
133
	
136
if ( $data->{'category_type'} eq 'C') {
134
if ( $data->{'category_type'} eq 'C') {
137
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
135
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
Lines 144-150 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); Link Here
144
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
142
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
145
$template->param( picture => 1 ) if $picture;
143
$template->param( picture => 1 ) if $picture;
146
	
144
	
147
    $template->param(
145
$template->param(
148
        allfile        => \@allfile,
146
        allfile        => \@allfile,
149
        firstname      => $data->{'firstname'},
147
        firstname      => $data->{'firstname'},
150
        surname        => $data->{'surname'},
148
        surname        => $data->{'surname'},
Lines 164-223 $template->param( picture => 1 ) if $picture; Link Here
164
	branchname => GetBranchName($data->{'branchcode'}),
162
	branchname => GetBranchName($data->{'branchcode'}),
165
	is_child        => ($data->{'category_type'} eq 'C'),
163
	is_child        => ($data->{'category_type'} eq 'C'),
166
        total          => sprintf( "%.2f", $total )
164
        total          => sprintf( "%.2f", $total )
167
    );
165
);
168
    output_html_with_http_headers $input, $cookie, $template->output;
169
170
}
171
else {
172
173
    my %inp;
174
    my @name = $input->param;
175
    for ( my $i = 0 ; $i < @name ; $i++ ) {
176
        my $test = $input->param( $name[$i] );
177
        if ( $test eq 'wo' ) {
178
            my $temp = $name[$i];
179
            $temp =~ s/payfine//;
180
            $inp{ $name[$i] } = $temp;
181
        }
182
    }
183
    my $borrowernumber;
184
    while ( my ( $key, $value ) = each %inp ) {
185
186
        my $accounttype = $input->param("accounttype$value");
187
        $borrowernumber = $input->param("borrowernumber$value");
188
        my $itemno    = $input->param("itemnumber$value");
189
        my $amount    = $input->param("amount$value");
190
        my $accountno = $input->param("accountno$value");
191
        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
192
    }
193
    $borrowernumber = $input->param('borrowernumber');
194
    print $input->redirect(
195
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
196
}
197
166
198
sub writeoff {
167
output_html_with_http_headers $input, $cookie, $template->output;
199
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
200
    my $user = $input->remote_user;
201
    my $dbh  = C4::Context->dbh;
202
    undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
203
    my $sth =
204
      $dbh->prepare(
205
"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
206
      );
207
    $sth->execute( $accountnum, $borrowernumber );
208
    $sth->finish;
209
    $sth = $dbh->prepare("select max(accountno) from accountlines");
210
    $sth->execute;
211
    my $account = $sth->fetchrow_hashref;
212
    $sth->finish;
213
    $account->{'max(accountno)'}++;
214
    $sth = $dbh->prepare(
215
"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
216
						values (?,?,?,now(),?,'Writeoff','W')"
217
    );
218
    $sth->execute( $borrowernumber, $account->{'max(accountno)'},
219
        $itemnum, $amount );
220
    $sth->finish;
221
    UpdateStats( $branch, 'writeoff', $amount, '', '', '',
222
        $borrowernumber );
223
}
224
- 

Return to bug 2169