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

(-)a/C4/Reserves.pm (-95 / +38 lines)
Lines 103-109 BEGIN { Link Here
103
        &GetReservesForBranch
103
        &GetReservesForBranch
104
        &GetReservesToBranch
104
        &GetReservesToBranch
105
        &GetReserveCount
105
        &GetReserveCount
106
        &GetReserveFee
107
        &GetReserveInfo
106
        &GetReserveInfo
108
        &GetReserveStatus
107
        &GetReserveStatus
109
108
Lines 156-164 sub AddReserve { Link Here
156
        $bibitems,  $priority, $resdate, $expdate, $notes,
155
        $bibitems,  $priority, $resdate, $expdate, $notes,
157
        $title,      $checkitem, $found
156
        $title,      $checkitem, $found
158
    ) = @_;
157
    ) = @_;
159
    my $fee =
160
          GetReserveFee($borrowernumber, $biblionumber,
161
            $bibitems );
162
    my $dbh     = C4::Context->dbh;
158
    my $dbh     = C4::Context->dbh;
163
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
159
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
164
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
160
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
Lines 178-198 sub AddReserve { Link Here
178
        $waitingdate = $resdate;
174
        $waitingdate = $resdate;
179
    }
175
    }
180
176
181
    #eval {
182
    # updates take place here
177
    # updates take place here
183
    if ( $fee > 0 ) {
184
        my $nextacctno = &getnextacctno( $borrowernumber );
185
        my $query      = qq{
186
        INSERT INTO accountlines
187
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
188
        VALUES
189
            (?,?,now(),?,?,'Res',?)
190
    };
191
        my $usth = $dbh->prepare($query);
192
        $usth->execute( $borrowernumber, $nextacctno, $fee,
193
            "Reserve Charge - $title", $fee );
194
    }
195
196
    my $query = qq{
178
    my $query = qq{
197
        INSERT INTO reserves
179
        INSERT INTO reserves
198
            (borrowernumber,biblionumber,reservedate,branchcode,
180
            (borrowernumber,biblionumber,reservedate,branchcode,
Lines 207-212 sub AddReserve { Link Here
207
        $notes,          $checkitem,    $found,   $waitingdate, $expdate
189
        $notes,          $checkitem,    $found,   $waitingdate, $expdate
208
    );
190
    );
209
    my $reserve_id = $sth->{mysql_insertid};
191
    my $reserve_id = $sth->{mysql_insertid};
192
    # add a reserve fee if needed
193
    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
194
    ChargeReserveFee( $borrowernumber, $fee, $title );
210
195
211
    # Send e-mail to librarian if syspref is active
196
    # Send e-mail to librarian if syspref is active
212
    if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
197
    if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
Lines 655-745 sub GetOtherReserves { Link Here
655
    return ( $messages, $nextreservinfo );
640
    return ( $messages, $nextreservinfo );
656
}
641
}
657
642
658
=head2 GetReserveFee
643
=head2 ChargeReserveFee
659
644
660
  $fee = GetReserveFee($borrowernumber,$biblionumber,$biblionumber);
645
    $fee = ChargeReserveFee( $borrowernumber, $fee, $title );
661
646
662
Calculate the fee for a reserve
647
    Charge the fee for a reserve (if $fee > 0)
663
648
664
=cut
649
=cut
665
650
666
sub GetReserveFee {
651
sub ChargeReserveFee {
667
    my ($borrowernumber, $biblionumber, $bibitems ) = @_;
652
    my ( $borrowernumber, $fee, $title ) = @_;
668
653
    return if !$fee;
669
    #check for issues;
654
    my $accquery = qq{
670
    my $dbh   = C4::Context->dbh;
655
INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?)
671
    my $query = qq{
672
      SELECT * FROM borrowers
673
    LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
674
    WHERE borrowernumber = ?
675
    };
656
    };
676
    my $sth = $dbh->prepare($query);
657
    my $dbh = C4::Context->dbh;
677
    $sth->execute($borrowernumber);
658
    my $nextacctno = &getnextacctno( $borrowernumber );
678
    my $data = $sth->fetchrow_hashref;
659
    $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) );
679
    my $fee      = $data->{'reservefee'};
660
}
680
    my $cntitems = @- > $bibitems;
681
661
682
    if ( $fee > 0 ) {
662
=head2 GetReserveFee
683
663
684
        # check for items on issue
664
    $fee = GetReserveFee( $borrowernumber, $biblionumber );
685
        # first find biblioitem records
686
        my @biblioitems;
687
        my $sth1 = $dbh->prepare(
688
            "SELECT * FROM biblio LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber
689
                   WHERE (biblio.biblionumber = ?)"
690
        );
691
        $sth1->execute($biblionumber);
692
        while ( my $data1 = $sth1->fetchrow_hashref ) {
693
            my $found = 0;
694
            my $x     = 0;
695
            while ( $x < $cntitems ) {
696
                if ( @$bibitems->{'biblioitemnumber'} ==
697
                    $data->{'biblioitemnumber'} )
698
                {
699
                    $found = 1;
700
                }
701
                $x++;
702
            }
703
665
704
            if ( $found == 0 ) {
666
    Calculate the fee for a reserve (if applicable).
705
                push @biblioitems, $data1;
667
706
            }
668
=cut
707
        }
669
708
        my $cntitemsfound = @biblioitems;
670
sub GetReserveFee {
709
        my $issues        = 0;
671
    my ( $borrowernumber, $biblionumber ) = @_;
710
        my $x             = 0;
672
    my $borquery = qq{
711
        my $allissued     = 1;
673
SELECT reservefee FROM borrowers LEFT JOIN categories ON borrowers.categorycode = categories.categorycode WHERE borrowernumber = ?
712
        while ( $x < $cntitemsfound ) {
674
    };
713
            my $bitdata = $biblioitems[$x];
675
714
            my $sth2    = $dbh->prepare(
676
    my $dbh = C4::Context->dbh;
715
                "SELECT * FROM items
677
    my ( $fee ) = $dbh->selectrow_array( $borquery, undef, ($borrowernumber) );
716
                     WHERE biblioitemnumber = ?"
678
    if( $fee && $fee > 0 ) {
717
            );
679
        # This is a reconstruction of the old code:
718
            $sth2->execute( $bitdata->{'biblioitemnumber'} );
680
        # Calculate number of items, items issued and holds
719
            while ( my $itdata = $sth2->fetchrow_hashref ) {
681
        my ( $cnt1 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM items WHERE biblionumber=?", undef, ( $biblionumber ) );
720
                my $sth3 = $dbh->prepare(
682
        my ( $cnt2 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM issues LEFT JOIN items USING (itemnumber) WHERE biblionumber=?", undef, ( $biblionumber ));
721
                    "SELECT * FROM issues
683
        my ( $cnt3 ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM reserves WHERE biblionumber=? AND borrowernumber<>?", undef, ( $biblionumber, $borrowernumber ) );
722
                       WHERE itemnumber = ?"
684
        # If not all items are issued and there are no holds: charge no fee
723
                );
685
        # NOTE: Lost, damaged, not-for-loan, etc. are just ignored here
724
                $sth3->execute( $itdata->{'itemnumber'} );
686
        $fee = 0 if $cnt1 - $cnt2 > 0 && $cnt3 == 0;
725
                if ( my $isdata = $sth3->fetchrow_hashref ) {
726
                }
727
                else {
728
                    $allissued = 0;
729
                }
730
            }
731
            $x++;
732
        }
733
        if ( $allissued == 0 ) {
734
            my $rsth =
735
              $dbh->prepare("SELECT * FROM reserves WHERE biblionumber = ?");
736
            $rsth->execute($biblionumber);
737
            if ( my $rdata = $rsth->fetchrow_hashref ) {
738
            }
739
            else {
740
                $fee = 0;
741
            }
742
        }
743
    }
687
    }
744
    return $fee;
688
    return $fee;
745
}
689
}
746
- 

Return to bug 14702