-sub writeoff {
- my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
- my $user = $input->remote_user;
- my $dbh = C4::Context->dbh;
- undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
- my $sth =
- $dbh->prepare(
-"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
- );
- $sth->execute( $accountnum, $borrowernumber );
- $sth->finish;
- $sth = $dbh->prepare("select max(accountno) from accountlines");
- $sth->execute;
- my $account = $sth->fetchrow_hashref;
- $sth->finish;
- $account->{'max(accountno)'}++;
- $sth = $dbh->prepare(
-"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
- values (?,?,?,now(),?,'Writeoff','W')"
- );
- $sth->execute( $borrowernumber, $account->{'max(accountno)'},
- $itemnum, $amount );
- $sth->finish;
- UpdateStats( $branch, 'writeoff', $amount, '', '', '',
- $borrowernumber );
+sub borrower_add_additional_fields {
+ my $b_ref = shift;
+
+# some borrower info is not returned in the standard call despite being assumed
+# in a number of templates. It should not be the business of this script but in lieu of
+# a revised api here it is ...
+ if ( $b_ref->{category_type} eq 'C' ) {
+ my ( $catcodes, $labels ) =
+ GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
+ if ( @{$catcodes} ) {
+ if ( @{$catcodes} > 1 ) {
+ $b_ref->{CATCODE_MULTI} = 1;
+ } elsif ( @{$catcodes} == 1 ) {
+ $b_ref->{catcode} = $catcodes->[0];
+ }
+ }
+ } elsif ( $b_ref->{category_type} eq 'A' ) {
+ $b_ref->{adultborrower} = 1;
+ }
+ my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} );
+ if ($picture) {
+ $b_ref->{has_picture} = 1;
+ }
+ $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber);
+
+ $b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} );
+ return;
+}
+
+sub payselected {
+ my @params = @_;
+ my $amt = 0;
+ my @lines_to_pay;
+ foreach (@params) {
+ if (/^incl_par_(\d+)$/) {
+ my $index = $1;
+ push @lines_to_pay, $input->param("accountno$index");
+ $amt += $input->param("amountoutstanding$index");
+ }
+ }
+ $amt = '&amt=' . $amt;
+ my $sel = '&selected=' . join ',', @lines_to_pay;
+ my $redirect =
+ "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"
+ . $amt
+ . $sel;
+
+ print $input->redirect($redirect);
+ return;
+}
+
+sub get_writeoff_sth {
+
+ # lets prepare these statement handles only once
+ if ($writeoff_sth) {
+ return;
+ } else {
+ my $dbh = C4::Context->dbh;
+
+ # Do we need to validate accounttype
+ my $sql = 'Update accountlines set amountoutstanding=0 '
+ . 'WHERE accountno=? and borrowernumber=?';
+ $writeoff_sth = $dbh->prepare($sql);
+ my $insert =
+q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)}
+ . q{values (?,?,?,now(),?,'Writeoff','W')};
+ $add_writeoff_sth = $dbh->prepare($insert);
+ }
+ return;