+=cut
+
+sub WriteOffFee {
+ my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount, $branch ) = @_;
+ $branch ||= C4::Context->userenv->{branch};
+ my $manager_id = 0;
+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
+
+ # if no item is attached to fine, make sure to store it as a NULL
+ $itemnum ||= undef;
+
+ my ( $sth, $query );
+ my $dbh = C4::Context->dbh();
+
+ $query = "
+ UPDATE accountlines SET amountoutstanding = 0
+ WHERE accountno = ? AND borrowernumber = ?
+ ";
+ $sth = $dbh->prepare( $query );
+ $sth->execute( $accountnum, $borrowernumber );
+
+ $query ="
+ INSERT INTO accountlines
+ ( borrowernumber, accountno, itemnumber, date, amount, description, accounttype, manager_id )
+ VALUES ( ?, ?, ?, NOW(), ?, 'Writeoff', 'W', ? )
+ ";
+ $sth = $dbh->prepare( $query );
+ my $acct = getnextacctno($borrowernumber);
+ $sth->execute( $borrowernumber, $acct, $itemnum, $amount, $manager_id );
+
+ UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber );
+
+}