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

(-)a/C4/Circulation.pm (-208 / +205 lines)
Lines 30-36 use C4::Items; Link Here
30
use C4::Members;
30
use C4::Members;
31
use C4::Dates;
31
use C4::Dates;
32
use C4::Dates qw(format_date);
32
use C4::Dates qw(format_date);
33
use C4::Accounts;
33
use Koha::Accounts;
34
use Koha::Accounts::CreditTypes;
34
use C4::ItemCirculationAlertPreference;
35
use C4::ItemCirculationAlertPreference;
35
use C4::Message;
36
use C4::Message;
36
use C4::Debug;
37
use C4::Debug;
Lines 48-53 use Data::Dumper; Link Here
48
use Koha::DateUtils;
49
use Koha::DateUtils;
49
use Koha::Calendar;
50
use Koha::Calendar;
50
use Koha::Borrower::Debarments;
51
use Koha::Borrower::Debarments;
52
use Koha::Database;
51
use Carp;
53
use Carp;
52
use Date::Calc qw(
54
use Date::Calc qw(
53
  Today
55
  Today
Lines 1287-1293 sub AddIssue { Link Here
1287
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1289
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1288
        if ( $item->{'itemlost'} ) {
1290
        if ( $item->{'itemlost'} ) {
1289
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1291
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1290
                _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} );
1292
                _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1291
            }
1293
            }
1292
        }
1294
        }
1293
1295
Lines 1852-1872 sub AddReturn { Link Here
1852
1854
1853
                $type ||= q{};
1855
                $type ||= q{};
1854
1856
1855
                if ( C4::Context->preference('finesMode') eq 'production' ) {
1857
                if ( $amount > 0
1856
                    if ( $amount > 0 ) {
1858
                    && C4::Context->preference('finesMode') eq 'production' )
1857
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1859
                {
1858
                            $issue->{borrowernumber},
1860
                    C4::Overdues::UpdateFine(
1859
                            $amount, $type, output_pref($datedue) );
1861
                        {
1860
                    }
1862
                            itemnumber     => $issue->{itemnumber},
1861
                    elsif ($return_date) {
1863
                            borrowernumber => $issue->{borrowernumber},
1862
1864
                            amount         => $amount,
1863
                       # Backdated returns may have fines that shouldn't exist,
1865
                            due            => output_pref($datedue),
1864
                       # so in this case, we need to drop those fines to 0
1866
                            issue_id       => $issue->{issue_id}
1865
1867
                        }
1866
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1868
                    );
1867
                            $issue->{borrowernumber},
1869
                }
1868
                            0, $type, output_pref($datedue) );
1870
                elsif ($return_date) {
1869
                    }
1871
1872
                    # Backdated returns may have fines that shouldn't exist,
1873
                    # so in this case, we need to drop those fines to 0
1874
                    C4::Overdues::UpdateFine(
1875
                        {
1876
                            itemnumber     => $issue->{itemnumber},
1877
                            borrowernumber => $issue->{borrowernumber},
1878
                            amount         => 0,
1879
                            due            => output_pref($datedue),
1880
                            issue_id       => $issue->{issue_id}
1881
                        }
1882
                    );
1870
                }
1883
                }
1871
            }
1884
            }
1872
1885
Lines 1916-1930 sub AddReturn { Link Here
1916
        $messages->{'WasLost'} = 1;
1929
        $messages->{'WasLost'} = 1;
1917
1930
1918
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1931
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1919
            _FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode);    # can tolerate undef $borrowernumber
1932
            _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1920
            $messages->{'LostItemFeeRefunded'} = 1;
1933
            $messages->{'LostItemFeeRefunded'} = 1;
1921
        }
1934
        }
1922
    }
1935
    }
1923
1936
1924
    # fix up the overdues in accounts...
1937
    # fix up the overdues in accounts...
1925
    if ($borrowernumber) {
1938
    if ($borrowernumber) {
1926
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
1939
        _FinalizeFine(
1927
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
1940
            {
1941
                exempt_fine => $exemptfine,
1942
                dropbox     => $dropbox,
1943
                issue       => Koha::Database->new()->schema->resultset('OldIssue')->find( $issue->{issue_id} ),
1944
            }
1945
        );
1928
        
1946
        
1929
        if ( $issue->{overdue} && $issue->{date_due} ) {
1947
        if ( $issue->{overdue} && $issue->{date_due} ) {
1930
        # fix fine days
1948
        # fix fine days
Lines 2033-2042 of the return. It is ignored when a dropbox_branch is passed in. Link Here
2033
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2051
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2034
the old_issue is immediately anonymised
2052
the old_issue is immediately anonymised
2035
2053
2036
Ideally, this function would be internal to C<C4::Circulation>,
2037
not exported, but it is currently needed by one 
2038
routine in C<C4::Accounts>.
2039
2040
=cut
2054
=cut
2041
2055
2042
sub MarkIssueReturned {
2056
sub MarkIssueReturned {
Lines 2158-2312 sub _debar_user_on_return { Link Here
2158
    return;
2172
    return;
2159
}
2173
}
2160
2174
2161
=head2 _FixOverduesOnReturn
2175
=head2 _FinalizeFine
2162
2163
   &_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode);
2164
2165
C<$brn> borrowernumber
2166
2176
2167
C<$itm> itemnumber
2177
   _FinalizeFine({
2178
        exempt_fine => $exempt_fine,
2179
        dropbox     => $dropbox,
2180
        issue       => $issue,
2181
   });
2168
2182
2169
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. 
2183
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. 
2170
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2184
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2185
C<$issue> -- DBIx::Class::Row for the issue
2171
2186
2172
Internal function, called only by AddReturn
2187
This subrouting closes out the accuruing of a fine, and reduces if it exemptfine or
2188
dropbox flags are passed in.
2173
2189
2174
=cut
2190
=cut
2175
2191
2176
sub _FixOverduesOnReturn {
2192
sub _FinalizeFine {
2177
    my ($borrowernumber, $item);
2193
    my ( $params ) = @_;
2178
    unless ($borrowernumber = shift) {
2194
2179
        warn "_FixOverduesOnReturn() not supplied valid borrowernumber";
2195
    my $exemptfine = $params->{exempt_fine};
2180
        return;
2196
    my $dropbox    = $params->{dropbox};
2181
    }
2197
    my $issue      = $params->{issue};
2182
    unless ($item = shift) {
2198
2183
        warn "_FixOverduesOnReturn() not supplied valid itemnumber";
2184
        return;
2185
    }
2186
    my ($exemptfine, $dropbox) = @_;
2187
    my $dbh = C4::Context->dbh;
2199
    my $dbh = C4::Context->dbh;
2188
2200
2189
    # check for overdue fine
2201
    my $schema = Koha::Database->new()->schema;
2190
    my $sth = $dbh->prepare(
2202
    my $fine = $schema->resultset('AccountDebit')->single(
2191
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')"
2203
        {
2204
            issue_id => $issue->issue_id(),
2205
            type     => Koha::Accounts::DebitTypes::Fine(),
2206
            accruing => 1,
2207
        }
2192
    );
2208
    );
2193
    $sth->execute( $borrowernumber, $item );
2194
2209
2195
    # alter fine to show that the book has been returned
2210
    return unless ( $fine );
2196
    my $data = $sth->fetchrow_hashref;
2211
2197
    return 0 unless $data;    # no warning, there's just nothing to fix
2212
    $fine->accruing(0);
2198
2213
2199
    my $uquery;
2200
    my @bind = ($data->{'accountlines_id'});
2201
    if ($exemptfine) {
2214
    if ($exemptfine) {
2202
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
2215
        AddCredit(
2203
        if (C4::Context->preference("FinesLog")) {
2216
            {
2204
            &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2217
                borrower => $fine->borrowernumber(),
2205
        }
2218
                amount   => $fine->amount_original(),
2206
    } elsif ($dropbox && $data->{lastincrement}) {
2219
                debit_id => $fine->debit_id(),
2207
        my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ;
2220
                type     => Koha::Accounts::CreditTypes::Forgiven(),
2208
        my $amt = $data->{amount} - $data->{lastincrement} ;
2221
            }
2222
        );
2209
        if (C4::Context->preference("FinesLog")) {
2223
        if (C4::Context->preference("FinesLog")) {
2210
            &logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item");
2224
            &logaction(
2211
        }
2225
                "FINES", 'MODIFY',
2212
         $uquery = "update accountlines set accounttype='F' ";
2226
                $issue->{borrowernumber},
2213
         if($outstanding  >= 0 && $amt >=0) {
2227
                "Overdue forgiven: item " . $issue->{itemnumber}
2214
            $uquery .= ", amount = ? , amountoutstanding=? ";
2228
            );
2215
            unshift @bind, ($amt, $outstanding) ;
2216
        }
2229
        }
2217
    } else {
2230
    } elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) {
2218
        $uquery = "update accountlines set accounttype='F' ";
2231
        if ( C4::Context->preference("FinesLog") ) {
2232
            &logaction( "FINES", 'MODIFY', $issue->{borrowernumber},
2233
                    "Dropbox adjustment "
2234
                  . $fine->amount_last_increment()
2235
                  . ", item " . $issue->{itemnumber} );
2236
        }
2237
        $fine->amount_original(
2238
            $fine->amount_original() - $fine->amount_last_increment() );
2239
        $fine->amount_outstanding(
2240
            $fine->amount_outstanding - $fine->amount_last_increment() );
2241
        $schema->resultset('AccountOffset')->create(
2242
            {
2243
                debit_id => $fine->debit_id(),
2244
                type     => Koha::Accounts::OffsetTypes::Dropbox(),
2245
                amount   => $fine->amount_last_increment() * -1,
2246
            }
2247
        );
2219
    }
2248
    }
2220
    $uquery .= " where (accountlines_id = ?)";
2249
2221
    my $usth = $dbh->prepare($uquery);
2250
    return $fine->update();
2222
    return $usth->execute(@bind);
2223
}
2251
}
2224
2252
2225
=head2 _FixAccountForLostAndReturned
2253
=head2 _FixAccountForLostAndReturned
2226
2254
2227
  &_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]);
2255
  &_FixAccountForLostAndReturned($itemnumber);
2228
2229
Calculates the charge for a book lost and returned.
2230
2231
Internal function, not exported, called only by AddReturn.
2232
2256
2233
FIXME: This function reflects how inscrutable fines logic is.  Fix both.
2257
  Refunds a lost item fee in necessary
2234
FIXME: Give a positive return value on success.  It might be the $borrowernumber who received credit, or the amount forgiven.
2235
2258
2236
=cut
2259
=cut
2237
2260
2238
sub _FixAccountForLostAndReturned {
2261
sub _FixAccountForLostAndReturned {
2239
    my $itemnumber     = shift or return;
2262
    my ( $itemnumber ) = @_;
2240
    my $borrowernumber = @_ ? shift : undef;
2263
2241
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2264
    my $schema = Koha::Database->new()->schema;
2242
    my $dbh = C4::Context->dbh;
2265
2243
    # check for charge made for lost book
2266
    # Find the last issue for this item
2244
    my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC");
2267
    my $issue =
2245
    $sth->execute($itemnumber);
2268
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
2246
    my $data = $sth->fetchrow_hashref;
2269
    $issue ||=
2247
    $data or return;    # bail if there is nothing to do
2270
      $schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } );
2248
    $data->{accounttype} eq 'W' and return;    # Written off
2271
2249
2272
    return unless $issue;
2250
    # writeoff this amount
2273
2251
    my $offset;
2274
    # Find a lost fee for this issue
2252
    my $amount = $data->{'amount'};
2275
    my $debit = $schema->resultset('AccountDebit')->single(
2253
    my $acctno = $data->{'accountno'};
2276
        {
2254
    my $amountleft;                                             # Starts off undef/zero.
2277
            issue_id => $issue->issue_id(),
2255
    if ($data->{'amountoutstanding'} == $amount) {
2278
            type     => Koha::Accounts::DebitTypes::Lost()
2256
        $offset     = $data->{'amount'};
2279
        }
2257
        $amountleft = 0;                                        # Hey, it's zero here, too.
2280
    );
2258
    } else {
2281
2259
        $offset     = $amount - $data->{'amountoutstanding'};   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2282
    return unless $debit;
2260
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2283
2261
    }
2284
    # Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing
2262
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
2285
    my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() });
2263
        WHERE (accountlines_id = ?)");
2286
2264
    $usth->execute($data->{'accountlines_id'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.
2287
    return if @credits;
2265
    #check if any credit is left if so writeoff other accounts
2288
2266
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
2289
    # Ok, so we know we have an unrefunded lost item fee, let's refund it
2267
    $amountleft *= -1 if ($amountleft < 0);
2290
    CreditLostItem(
2268
    if ($amountleft > 0) {
2291
        {
2269
        my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?)
2292
            borrower => $issue->borrower(),
2270
                            AND (amountoutstanding >0) ORDER BY date");     # might want to order by amountoustanding ASC (pay smallest first)
2293
            debit    => $debit
2271
        $msth->execute($data->{'borrowernumber'});
2294
        }
2272
        # offset transactions
2295
    );
2273
        my $newamtos;
2296
2274
        my $accdata;
2275
        while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){
2276
            if ($accdata->{'amountoutstanding'} < $amountleft) {
2277
                $newamtos = 0;
2278
                $amountleft -= $accdata->{'amountoutstanding'};
2279
            }  else {
2280
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
2281
                $amountleft = 0;
2282
            }
2283
            my $thisacct = $accdata->{'accountlines_id'};
2284
            # FIXME: move prepares outside while loop!
2285
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
2286
                    WHERE (accountlines_id = ?)");
2287
            $usth->execute($newamtos,$thisacct);
2288
            $usth = $dbh->prepare("INSERT INTO accountoffsets
2289
                (borrowernumber, accountno, offsetaccount,  offsetamount)
2290
                VALUES
2291
                (?,?,?,?)");
2292
            $usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos);
2293
        }
2294
    }
2295
    $amountleft *= -1 if ($amountleft > 0);
2296
    my $desc = "Item Returned " . $item_id;
2297
    $usth = $dbh->prepare("INSERT INTO accountlines
2298
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2299
        VALUES (?,?,now(),?,?,'CR',?)");
2300
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2301
    if ($borrowernumber) {
2302
        # FIXME: same as query above.  use 1 sth for both
2303
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2304
            (borrowernumber, accountno, offsetaccount,  offsetamount)
2305
            VALUES (?,?,?,?)");
2306
        $usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset);
2307
    }
2308
    ModItem({ paidfor => '' }, undef, $itemnumber);
2297
    ModItem({ paidfor => '' }, undef, $itemnumber);
2309
    return;
2310
}
2298
}
2311
2299
2312
=head2 _GetCircControlBranch
2300
=head2 _GetCircControlBranch
Lines 2699-2712 sub AddRenewal { Link Here
2699
    my $dbh = C4::Context->dbh;
2687
    my $dbh = C4::Context->dbh;
2700
2688
2701
    # Find the issues record for this book
2689
    # Find the issues record for this book
2702
    my $sth =
2690
    my $issue = Koha::Database->new()->schema->resultset('Issue')->single({ itemnumber => $itemnumber });
2703
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2704
    $sth->execute( $itemnumber );
2705
    my $issuedata = $sth->fetchrow_hashref;
2706
2691
2707
    return unless ( $issuedata );
2692
    return unless ( $issue );
2708
2693
2709
    $borrowernumber ||= $issuedata->{borrowernumber};
2694
    $borrowernumber ||= $issue->get_column('borrowernumber');
2710
2695
2711
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2696
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2712
        carp 'Invalid date passed to AddRenewal.';
2697
        carp 'Invalid date passed to AddRenewal.';
Lines 2722-2762 sub AddRenewal { Link Here
2722
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2707
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2723
2708
2724
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2709
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2725
                                        dt_from_string( $issuedata->{date_due} ) :
2710
                                        dt_from_string( $issue->get_column('date_due') ) :
2726
                                        DateTime->now( time_zone => C4::Context->tz());
2711
                                        DateTime->now( time_zone => C4::Context->tz());
2727
        $datedue =  CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal');
2712
        $datedue =  CalcDateDue($datedue, $itemtype, $issue->get_column('branchcode'), $borrower, 'is a renewal');
2728
    }
2713
    }
2729
2714
2730
    # Update the issues record to have the new due date, and a new count
2715
    # Update the issues record to have the new due date, and a new count
2731
    # of how many times it has been renewed.
2716
    # of how many times it has been renewed.
2732
    my $renews = $issuedata->{'renewals'} + 1;
2717
    $issue->update(
2733
    $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2718
        {
2734
                            WHERE borrowernumber=? 
2719
            date_due        => $datedue->strftime('%Y-%m-%d %H:%M'),
2735
                            AND itemnumber=?"
2720
            renewals        => $issue->renewals() + 1,
2721
            lastreneweddate => $lastreneweddate,
2722
        }
2736
    );
2723
    );
2737
2724
2738
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2739
2725
2740
    # Update the renewal count on the item, and tell zebra to reindex
2726
    # Update the renewal count on the item, and tell zebra to reindex
2741
    $renews = $biblio->{'renewals'} + 1;
2727
    my $renews = $biblio->{'renewals'} + 1;
2742
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber);
2728
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber);
2743
2729
2744
    # Charge a new rental fee, if applicable?
2730
    # Charge a new rental fee, if applicable?
2745
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2731
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2746
    if ( $charge > 0 ) {
2732
    if ( $charge > 0 ) {
2747
        my $accountno = getnextacctno( $borrowernumber );
2748
        my $item = GetBiblioFromItemNumber($itemnumber);
2733
        my $item = GetBiblioFromItemNumber($itemnumber);
2749
        my $manager_id = 0;
2734
2750
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2735
        my $borrower =
2751
        $sth = $dbh->prepare(
2736
          Koha::Database->new()->schema->resultset('Borrower')
2752
                "INSERT INTO accountlines
2737
          ->find($borrowernumber);
2753
                    (date, borrowernumber, accountno, amount, manager_id,
2738
2754
                    description,accounttype, amountoutstanding, itemnumber)
2739
        AddDebit(
2755
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2740
            {
2741
                borrower   => $borrower,
2742
                itemnumber => $itemnumber,
2743
                amount     => $charge,
2744
                type       => Koha::Accounts::DebitTypes::Rental(),
2745
                description =>
2746
                  "Renewal of Rental Item $item->{'title'} $item->{'barcode'}"
2747
            }
2756
        );
2748
        );
2757
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2758
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2759
            'Rent', $charge, $itemnumber );
2760
    }
2749
    }
2761
2750
2762
    # Send a renewal slip according to checkout alert preferencei
2751
    # Send a renewal slip according to checkout alert preferencei
Lines 2798-2803 sub AddRenewal { Link Here
2798
                borrowernumber => $borrowernumber,
2787
                borrowernumber => $borrowernumber,
2799
                ccode => $item->{'ccode'}}
2788
                ccode => $item->{'ccode'}}
2800
                );
2789
                );
2790
2791
    _FinalizeFine( { issue => $issue } );
2792
2801
	return $datedue;
2793
	return $datedue;
2802
}
2794
}
2803
2795
Lines 2982-3006 sub _get_discount_from_rule { Link Here
2982
2974
2983
=head2 AddIssuingCharge
2975
=head2 AddIssuingCharge
2984
2976
2985
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2977
  &AddIssuingCharge( $itemnumber, $borrowernumber, $amount )
2986
2978
2987
=cut
2979
=cut
2988
2980
2989
sub AddIssuingCharge {
2981
sub AddIssuingCharge {
2990
    my ( $itemnumber, $borrowernumber, $charge ) = @_;
2982
    my ( $itemnumber, $borrowernumber, $amount ) = @_;
2991
    my $dbh = C4::Context->dbh;
2983
2992
    my $nextaccntno = getnextacctno( $borrowernumber );
2984
    return AddDebit(
2993
    my $manager_id = 0;
2985
        {
2994
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
2986
            borrower       => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber),
2995
    my $query ="
2987
            itemnumber     => $itemnumber,
2996
        INSERT INTO accountlines
2988
            amount         => $amount,
2997
            (borrowernumber, itemnumber, accountno,
2989
            type           => Koha::Accounts::DebitTypes::Rental(),
2998
            date, amount, description, accounttype,
2990
        }
2999
            amountoutstanding, manager_id)
2991
    );
3000
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
3001
    ";
3002
    my $sth = $dbh->prepare($query);
3003
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
3004
}
2992
}
3005
2993
3006
=head2 GetTransfers
2994
=head2 GetTransfers
Lines 3519-3548 sub ReturnLostItem{ Link Here
3519
sub LostItem{
3507
sub LostItem{
3520
    my ($itemnumber, $mark_returned) = @_;
3508
    my ($itemnumber, $mark_returned) = @_;
3521
3509
3522
    my $dbh = C4::Context->dbh();
3510
    my $schema = Koha::Database->new()->schema;
3523
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3524
                           FROM issues 
3525
                           JOIN items USING (itemnumber) 
3526
                           JOIN biblio USING (biblionumber)
3527
                           WHERE issues.itemnumber=?");
3528
    $sth->execute($itemnumber);
3529
    my $issues=$sth->fetchrow_hashref();
3530
3511
3531
    # If a borrower lost the item, add a replacement cost to the their record
3512
    my $issue =
3532
    if ( my $borrowernumber = $issues->{borrowernumber} ){
3513
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
3533
        my $borrower = C4::Members::GetMemberDetails( $borrowernumber );
3534
3514
3515
    my ( $borrower, $item );
3516
3517
    if ( $issue ) {
3518
        $borrower = $issue->borrower();
3519
        $item     = $issue->item();
3520
    }
3521
3522
    # If a borrower lost the item, add a replacement cost to the their record
3523
    if ( $borrower ){
3535
        if (C4::Context->preference('WhenLostForgiveFine')){
3524
        if (C4::Context->preference('WhenLostForgiveFine')){
3536
            my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox
3525
            _FinalizeFine(
3537
            defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
3526
                {
3527
                    exempt_fine => 1,
3528
                    dropbox     => 0,
3529
                    issue       => $issue,
3530
                }
3531
            );
3538
        }
3532
        }
3539
        if (C4::Context->preference('WhenLostChargeReplacementFee')){
3533
        if ( C4::Context->preference('WhenLostChargeReplacementFee') ) {
3540
            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
3534
            DebitLostItem( { borrower => $borrower, issue => $issue } );
3541
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
3542
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
3543
        }
3535
        }
3544
3536
3545
        MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned;
3537
        MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned;
3546
    }
3538
    }
3547
}
3539
}
3548
3540
Lines 3660-3669 sub ProcessOfflineIssue { Link Here
3660
sub ProcessOfflinePayment {
3652
sub ProcessOfflinePayment {
3661
    my $operation = shift;
3653
    my $operation = shift;
3662
3654
3663
    my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber
3655
    AddCredit(
3664
    my $amount = $operation->{amount};
3656
        {
3665
3657
            borrower => Koha::Database->new()->schema->resultset('Borrower')
3666
    recordpayment( $borrower->{borrowernumber}, $amount );
3658
              ->single( { cardnumber => $operation->{cardnumber} } ),
3659
            amount => $operation->{amount},
3660
            notes  => 'via offline circulation',
3661
            type   => Koha::Accounts::CreditTypes::Payment,
3662
        }
3663
    );
3667
3664
3668
    return "Success."
3665
    return "Success."
3669
}
3666
}
(-)a/C4/ILSDI/Services.pm (-5 / +4 lines)
Lines 24-30 use C4::Members; Link Here
24
use C4::Items;
24
use C4::Items;
25
use C4::Circulation;
25
use C4::Circulation;
26
use C4::Branch;
26
use C4::Branch;
27
use C4::Accounts;
28
use C4::Biblio;
27
use C4::Biblio;
29
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
28
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
30
use C4::Context;
29
use C4::Context;
Lines 34-39 use HTML::Entities; Link Here
34
use CGI;
33
use CGI;
35
use DateTime;
34
use DateTime;
36
use C4::Auth;
35
use C4::Auth;
36
use Koha::Database;
37
37
38
=head1 NAME
38
=head1 NAME
39
39
Lines 387-396 sub GetPatronInfo { Link Here
387
387
388
    # Fines management
388
    # Fines management
389
    if ( $cgi->param('show_fines') eq "1" ) {
389
    if ( $cgi->param('show_fines') eq "1" ) {
390
        my @charges;
390
        my @charges =
391
        for ( my $i = 1 ; my @charge = getcharges( $borrowernumber, undef, $i ) ; $i++ ) {
391
          Koha::Database->new()->schema()->resultset('AccountDebit')
392
            push( @charges, @charge );
392
          ->search( { borrowernumber => $borrowernumber } );
393
        }
394
        $borrower->{'fines'}->{'fine'} = \@charges;
393
        $borrower->{'fines'}->{'fine'} = \@charges;
395
    }
394
    }
396
395
(-)a/C4/Members.pm (-134 / +54 lines)
Lines 29-35 use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/; Link Here
29
use C4::Log; # logaction
29
use C4::Log; # logaction
30
use C4::Overdues;
30
use C4::Overdues;
31
use C4::Reserves;
31
use C4::Reserves;
32
use C4::Accounts;
33
use C4::Biblio;
32
use C4::Biblio;
34
use C4::Letters;
33
use C4::Letters;
35
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable);
34
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable);
Lines 42-47 use Koha::Borrower::Debarments qw(IsDebarred); Link Here
42
use Text::Unaccent qw( unac_string );
41
use Text::Unaccent qw( unac_string );
43
use Koha::AuthUtils qw(hash_password);
42
use Koha::AuthUtils qw(hash_password);
44
use Koha::Database;
43
use Koha::Database;
44
use Koha::Accounts::DebitTypes;
45
45
46
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
46
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
47
47
Lines 81-88 BEGIN { Link Here
81
        &GetHideLostItemsPreference
81
        &GetHideLostItemsPreference
82
82
83
        &IsMemberBlocked
83
        &IsMemberBlocked
84
        &GetMemberAccountRecords
85
        &GetBorNotifyAcctRecord
86
84
87
        &GetborCatFromCatType
85
        &GetborCatFromCatType
88
        &GetBorrowercategory
86
        &GetBorrowercategory
Lines 356-364 sub GetMemberDetails { Link Here
356
    }
354
    }
357
    my $borrower = $sth->fetchrow_hashref;
355
    my $borrower = $sth->fetchrow_hashref;
358
    return unless $borrower;
356
    return unless $borrower;
359
    my ($amount) = GetMemberAccountRecords( $borrowernumber);
357
    $borrower->{amountoutstanding} = $borrower->{account_balance};
360
    $borrower->{'amountoutstanding'} = $amount;
358
    # FIXME - find all references to $borrower->{amountoutstanding}, replace with $borrower->{account_balance}
361
    # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
362
    my $flags = patronflags( $borrower);
359
    my $flags = patronflags( $borrower);
363
    my $accessflagshash;
360
    my $accessflagshash;
364
361
Lines 462-484 The "message" field that comes from the DB is OK. Link Here
462
# FIXME rename this function.
459
# FIXME rename this function.
463
sub patronflags {
460
sub patronflags {
464
    my %flags;
461
    my %flags;
465
    my ( $patroninformation) = @_;
462
    my ($patroninformation) = @_;
466
    my $dbh=C4::Context->dbh;
463
    my $dbh = C4::Context->dbh;
467
    my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'});
464
    if ( $patroninformation->{account_balance} > 0 ) {
468
    if ( $owing > 0 ) {
469
        my %flaginfo;
465
        my %flaginfo;
470
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
466
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
471
        $flaginfo{'message'} = sprintf 'Patron owes %.02f', $owing;
467
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
472
        $flaginfo{'amount'}  = sprintf "%.02f", $owing;
468
        if (  $patroninformation->{account_balance} > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
473
        if ( $owing > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
474
            $flaginfo{'noissues'} = 1;
469
            $flaginfo{'noissues'} = 1;
475
        }
470
        }
476
        $flags{'CHARGES'} = \%flaginfo;
471
        $flags{'CHARGES'} = \%flaginfo;
477
    }
472
    }
478
    elsif ( $balance < 0 ) {
473
    elsif ( $patroninformation->{account_balance} < 0 ) {
479
        my %flaginfo;
474
        my %flaginfo;
480
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
475
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
481
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
482
        $flags{'CREDITS'} = \%flaginfo;
476
        $flags{'CREDITS'} = \%flaginfo;
483
    }
477
    }
484
    if (   $patroninformation->{'gonenoaddress'}
478
    if (   $patroninformation->{'gonenoaddress'}
Lines 721-727 sub GetMemberIssuesAndFines { Link Here
721
    $sth->execute($borrowernumber);
715
    $sth->execute($borrowernumber);
722
    my $overdue_count = $sth->fetchrow_arrayref->[0];
716
    my $overdue_count = $sth->fetchrow_arrayref->[0];
723
717
724
    $sth = $dbh->prepare("SELECT SUM(amountoutstanding) FROM accountlines WHERE borrowernumber = ?");
718
    $sth = $dbh->prepare("SELECT account_balance FROM borrowers WHERE borrowernumber = ?");
725
    $sth->execute($borrowernumber);
719
    $sth->execute($borrowernumber);
726
    my $total_fines = $sth->fetchrow_arrayref->[0];
720
    my $total_fines = $sth->fetchrow_arrayref->[0];
727
721
Lines 1210-1266 sub GetAllIssues { Link Here
1210
}
1204
}
1211
1205
1212
1206
1213
=head2 GetMemberAccountRecords
1214
1215
  ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1216
1217
Looks up accounting data for the patron with the given borrowernumber.
1218
1219
C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1220
reference-to-array, where each element is a reference-to-hash; the
1221
keys are the fields of the C<accountlines> table in the Koha database.
1222
C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1223
total amount outstanding for all of the account lines.
1224
1225
=cut
1226
1227
sub GetMemberAccountRecords {
1228
    my ($borrowernumber) = @_;
1229
    my $dbh = C4::Context->dbh;
1230
    my @acctlines;
1231
    my $numlines = 0;
1232
    my $strsth      = qq(
1233
                        SELECT * 
1234
                        FROM accountlines 
1235
                        WHERE borrowernumber=?);
1236
    $strsth.=" ORDER BY date desc,timestamp DESC";
1237
    my $sth= $dbh->prepare( $strsth );
1238
    $sth->execute( $borrowernumber );
1239
1240
    my $total = 0;
1241
    while ( my $data = $sth->fetchrow_hashref ) {
1242
        if ( $data->{itemnumber} ) {
1243
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
1244
            $data->{biblionumber} = $biblio->{biblionumber};
1245
            $data->{title}        = $biblio->{title};
1246
        }
1247
        $acctlines[$numlines] = $data;
1248
        $numlines++;
1249
        $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
1250
    }
1251
    $total /= 1000;
1252
    return ( $total, \@acctlines,$numlines);
1253
}
1254
1255
=head2 GetMemberAccountBalance
1207
=head2 GetMemberAccountBalance
1256
1208
1257
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
1209
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
1258
1210
1259
Calculates amount immediately owing by the patron - non-issue charges.
1211
Calculates amount immediately owing by the patron - non-issue charges.
1260
Based on GetMemberAccountRecords.
1261
Charges exempt from non-issue are:
1212
Charges exempt from non-issue are:
1262
* Res (reserves)
1213
* HOLD fees (reserves)
1263
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
1214
* RENTAL if RentalsInNoissuesCharge syspref is set to false
1264
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1215
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1265
1216
1266
=cut
1217
=cut
Lines 1268-1338 Charges exempt from non-issue are: Link Here
1268
sub GetMemberAccountBalance {
1219
sub GetMemberAccountBalance {
1269
    my ($borrowernumber) = @_;
1220
    my ($borrowernumber) = @_;
1270
1221
1271
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
1222
    my $borrower =
1223
      Koha::Database->new()->schema->resultset('Borrower')
1224
      ->find($borrowernumber);
1272
1225
1273
    my @not_fines;
1226
    my @not_fines;
1274
    push @not_fines, 'Res' unless C4::Context->preference('HoldsInNoissuesCharge');
1275
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
1276
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1277
        my $dbh = C4::Context->dbh;
1278
        my $man_inv_types = $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'});
1279
        push @not_fines, map substr($_, 0, $ACCOUNT_TYPE_LENGTH), @$man_inv_types;
1280
    }
1281
    my %not_fine = map {$_ => 1} @not_fines;
1282
1283
    my ($total, $acctlines) = GetMemberAccountRecords($borrowernumber);
1284
    my $other_charges = 0;
1285
    foreach (@$acctlines) {
1286
        $other_charges += $_->{amountoutstanding} if $not_fine{ substr($_->{accounttype}, 0, $ACCOUNT_TYPE_LENGTH) };
1287
    }
1288
1289
    return ( $total, $total - $other_charges, $other_charges);
1290
}
1291
1227
1292
=head2 GetBorNotifyAcctRecord
1228
    push( @not_fines, Koha::Accounts::DebitTypes::Hold() );
1293
1229
1294
  ($total, $acctlines, $count) = &GetBorNotifyAcctRecord($params,$notifyid);
1230
    push( @not_fines, Koha::Accounts::DebitTypes::Rental() )
1231
      unless C4::Context->preference('RentalsInNoissuesCharge');
1295
1232
1296
Looks up accounting data for the patron with the given borrowernumber per file number.
1233
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1297
1234
        my $dbh           = C4::Context->dbh;
1298
C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1235
        my $man_inv_types = $dbh->selectcol_arrayref(q{
1299
reference-to-array, where each element is a reference-to-hash; the
1236
            SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'
1300
keys are the fields of the C<accountlines> table in the Koha database.
1237
        });
1301
C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1238
        push( @not_fines, @$man_inv_types );
1302
total amount outstanding for all of the account lines.
1239
    }
1303
1304
=cut
1305
1240
1306
sub GetBorNotifyAcctRecord {
1241
    my $other_charges =
1307
    my ( $borrowernumber, $notifyid ) = @_;
1242
      Koha::Database->new()->schema->resultset('AccountDebit')->search(
1308
    my $dbh = C4::Context->dbh;
1243
        {
1309
    my @acctlines;
1244
            borrowernumber => $borrowernumber,
1310
    my $numlines = 0;
1245
            type           => { -in => \@not_fines }
1311
    my $sth = $dbh->prepare(
1312
            "SELECT * 
1313
                FROM accountlines 
1314
                WHERE borrowernumber=? 
1315
                    AND notify_id=? 
1316
                    AND amountoutstanding != '0' 
1317
                ORDER BY notify_id,accounttype
1318
                ");
1319
1320
    $sth->execute( $borrowernumber, $notifyid );
1321
    my $total = 0;
1322
    while ( my $data = $sth->fetchrow_hashref ) {
1323
        if ( $data->{itemnumber} ) {
1324
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
1325
            $data->{biblionumber} = $biblio->{biblionumber};
1326
            $data->{title}        = $biblio->{title};
1327
        }
1246
        }
1328
        $acctlines[$numlines] = $data;
1247
      )->get_column('amount_outstanding')->sum();
1329
        $numlines++;
1248
1330
        $total += int(100 * $data->{'amountoutstanding'});
1249
    return (
1331
    }
1250
        $borrower->account_balance(),
1332
    $total /= 100;
1251
        $borrower->account_balance() - $other_charges,
1333
    return ( $total, \@acctlines, $numlines );
1252
        $other_charges
1253
    );
1334
}
1254
}
1335
1255
1256
1336
=head2 checkuniquemember (OUEST-PROVENCE)
1257
=head2 checkuniquemember (OUEST-PROVENCE)
1337
1258
1338
  ($result,$categorycode)  = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
1259
  ($result,$categorycode)  = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
Lines 2463-2484 Add enrolment fee for a patron if needed. Link Here
2463
2384
2464
sub AddEnrolmentFeeIfNeeded {
2385
sub AddEnrolmentFeeIfNeeded {
2465
    my ( $categorycode, $borrowernumber ) = @_;
2386
    my ( $categorycode, $borrowernumber ) = @_;
2466
    # check for enrollment fee & add it if needed
2387
2467
    my $dbh = C4::Context->dbh;
2388
    my $schema = Koha::Database->new()->schema();
2468
    my $sth = $dbh->prepare(q{
2389
2469
        SELECT enrolmentfee
2390
    my $category = $schema->resultset('Category')->find($categorycode);
2470
        FROM categories
2391
    my $fee      = $category->enrolmentfee();
2471
        WHERE categorycode=?
2392
2472
    });
2393
    if ( $fee && $fee > 0 ) {
2473
    $sth->execute( $categorycode );
2394
        AddDebit(
2474
    if ( $sth->err ) {
2395
            {
2475
        warn sprintf('Database returned the following error: %s', $sth->errstr);
2396
                borrower =>
2476
        return;
2397
                  $schema->resultset('Borrower')->find($borrowernumber),
2477
    }
2398
                type   => Koha::Accounts::DebitTypes::AccountManagementFee(),
2478
    my ($enrolmentfee) = $sth->fetchrow;
2399
                amount => $fee,
2479
    if ($enrolmentfee && $enrolmentfee > 0) {
2400
            }
2480
        # insert fee in patron debts
2401
        );
2481
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
2482
    }
2402
    }
2483
}
2403
}
2484
2404
(-)a/C4/Overdues.pm (-216 / +141 lines)
Lines 27-35 use List::MoreUtils qw( uniq ); Link Here
27
27
28
use C4::Circulation;
28
use C4::Circulation;
29
use C4::Context;
29
use C4::Context;
30
use C4::Accounts;
31
use C4::Log; # logaction
30
use C4::Log; # logaction
32
use C4::Debug;
31
use C4::Debug;
32
use Koha::Database;
33
use Koha::DateUtils;
34
use Koha::Accounts::OffsetTypes;
35
use Koha::Accounts::DebitTypes;
33
36
34
use vars qw($VERSION @ISA @EXPORT);
37
use vars qw($VERSION @ISA @EXPORT);
35
38
Lines 43-54 BEGIN { Link Here
43
        &CalcFine
46
        &CalcFine
44
        &Getoverdues
47
        &Getoverdues
45
        &checkoverdues
48
        &checkoverdues
46
        &NumberNotifyId
47
        &AmountNotify
48
        &UpdateFine
49
        &UpdateFine
49
        &GetFine
50
        &GetFine
50
        
51
        &CheckItemNotify
52
        &GetOverduesForBranch
51
        &GetOverduesForBranch
53
        &RemoveNotifyLine
52
        &RemoveNotifyLine
54
        &AddNotifyLine
53
        &AddNotifyLine
Lines 463-616 sub GetIssuesIteminfo { Link Here
463
462
464
=head2 UpdateFine
463
=head2 UpdateFine
465
464
466
    &UpdateFine($itemnumber, $borrowernumber, $amount, $type, $description);
465
    UpdateFine(
466
        {
467
            itemnumber     => $itemnumber,
468
            borrowernumber => $borrowernumber,
469
            amount         => $amount,
470
            due            => $due,
471
            issue_id       => $issue_id
472
        }
473
    );
467
474
468
(Note: the following is mostly conjecture and guesswork.)
475
Updates the fine owed on an overdue item.
469
476
470
Updates the fine owed on an overdue book.
477
C<$itemnumber> is the items's id.
471
478
472
C<$itemnumber> is the book's item number.
479
C<$borrowernumber> is the id of the patron who currently
480
has the item on loan.
473
481
474
C<$borrowernumber> is the borrower number of the patron who currently
482
C<$amount> is the total amount of the fine owed by the patron.
475
has the book on loan.
476
483
477
C<$amount> is the current amount owed by the patron.
484
C<&UpdateFine> updates the amount owed for a given fine if an issue_id
485
is passed to it. Otherwise, a new fine will be created.
478
486
479
C<$type> will be used in the description of the fine.
487
=cut
480
488
481
C<$description> is a string that must be present in the description of
489
sub UpdateFine {
482
the fine. I think this is expected to be a date in DD/MM/YYYY format.
490
    my ($params) = @_;
483
491
484
C<&UpdateFine> looks up the amount currently owed on the given item
492
    my $itemnumber     = $params->{itemnumber};
485
and sets it to C<$amount>, creating, if necessary, a new entry in the
493
    my $borrowernumber = $params->{borrowernumber};
486
accountlines table of the Koha database.
494
    my $amount         = $params->{amount};
495
    my $due            = $params->{due};
496
    my $issue_id       = $params->{issue_id};
487
497
488
=cut
498
    my $schema = Koha::Database->new()->schema;
489
499
490
#
500
    my $borrower = $schema->resultset('Borrower')->find($borrowernumber);
491
# Question: Why should the caller have to
501
492
# specify both the item number and the borrower number? A book can't
502
    if ( my $maxfine = C4::Context->preference('MaxFine') ) {
493
# be on loan to two different people, so the item number should be
503
        if ( $borrower->account_balance() + $amount > $maxfine ) {
494
# sufficient.
504
            my $new_amount = $maxfine - $borrower->account_balance();
495
#
505
            warn "Reducing fine for item $itemnumber borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
496
# Possible Answer: You might update a fine for a damaged item, *after* it is returned.
506
            if ( $new_amount <= 0 ) {
497
#
507
                warn "Fine reduced to a non-positive ammount. Fine not created.";
498
sub UpdateFine {
508
                return;
499
    my ( $itemnum, $borrowernumber, $amount, $type, $due ) = @_;
500
	$debug and warn "UpdateFine($itemnum, $borrowernumber, $amount, " . ($type||'""') . ", $due) called";
501
    my $dbh = C4::Context->dbh;
502
    # FIXME - What exactly is this query supposed to do? It looks up an
503
    # entry in accountlines that matches the given item and borrower
504
    # numbers, where the description contains $due, and where the
505
    # account type has one of several values, but what does this _mean_?
506
    # Does it look up existing fines for this item?
507
    # FIXME - What are these various account types? ("FU", "O", "F", "M")
508
	#	"L"   is LOST item
509
	#   "A"   is Account Management Fee
510
	#   "N"   is New Card
511
	#   "M"   is Sundry
512
	#   "O"   is Overdue ??
513
	#   "F"   is Fine ??
514
	#   "FU"  is Fine UPDATE??
515
	#	"Pay" is Payment
516
	#   "REF" is Cash Refund
517
    my $sth = $dbh->prepare(
518
        "SELECT * FROM accountlines
519
        WHERE borrowernumber=?
520
        AND   accounttype IN ('FU','O','F','M')"
521
    );
522
    $sth->execute( $borrowernumber );
523
    my $data;
524
    my $total_amount_other = 0.00;
525
    my $due_qr = qr/$due/;
526
    # Cycle through the fines and
527
    # - find line that relates to the requested $itemnum
528
    # - accumulate fines for other items
529
    # so we can update $itemnum fine taking in account fine caps
530
    while (my $rec = $sth->fetchrow_hashref) {
531
        if ($rec->{itemnumber} == $itemnum && $rec->{description} =~ /$due_qr/) {
532
            if ($data) {
533
                warn "Not a unique accountlines record for item $itemnum borrower $borrowernumber";
534
            } else {
535
                $data = $rec;
536
                next;
537
            }
509
            }
510
            $amount = $new_amount;
538
        }
511
        }
539
        $total_amount_other += $rec->{'amountoutstanding'};
540
    }
512
    }
541
513
542
    if (my $maxfine = C4::Context->preference('MaxFine')) {
514
    my $timestamp = get_timestamp();
543
        if ($total_amount_other + $amount > $maxfine) {
515
544
            my $new_amount = $maxfine - $total_amount_other;
516
    my $fine = $schema->resultset('AccountDebit')->single(
545
            return if $new_amount <= 0.00;
517
        {
546
            warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
518
            issue_id => $issue_id,
547
            $amount = $new_amount;
519
            type     => Koha::Accounts::DebitTypes::Fine,
520
            accruing => 1,
548
        }
521
        }
549
    }
522
    );
550
523
551
    if ( $data ) {
524
    my $offset = 0;
552
525
    my $credit;
553
		# we're updating an existing fine.  Only modify if amount changed
526
    if ($fine) {
554
        # Note that in the current implementation, you cannot pay against an accruing fine
527
        if ( $fine->accruing() ) { # Don't update or recreate fines no longer accruing
555
        # (i.e. , of accounttype 'FU').  Doing so will break accrual.
528
            if (
556
    	if ( $data->{'amount'} != $amount ) {
529
                sprintf( "%.6f", $fine->amount_original() )
557
            my $diff = $amount - $data->{'amount'};
530
                ne
558
	    #3341: diff could be positive or negative!
531
                sprintf( "%.6f", $amount ) )
559
            my $out  = $data->{'amountoutstanding'} + $diff;
532
            {
560
            my $query = "
533
                my $difference = $amount - $fine->amount_original();
561
                UPDATE accountlines
534
562
				SET date=now(), amount=?, amountoutstanding=?,
535
                # Fine was reduced by a change in circulation rules or another reason
563
					lastincrement=?, accounttype='FU'
536
                # we need to credit the account the difference and zero out the amount outstanding
564
	  			WHERE borrowernumber=?
537
                if ( $difference < 0 ) {
565
				AND   itemnumber=?
538
                    $fine->amount_outstanding( $fine->amount_outstanding() + $difference );
566
				AND   accounttype IN ('FU','O')
539
567
				AND   description LIKE ?
540
                    $credit =
568
				LIMIT 1 ";
541
                      Koha::Database->new()->schema->resultset('AccountCredit')
569
            my $sth2 = $dbh->prepare($query);
542
                      ->create(
570
			# FIXME: BOGUS query cannot ensure uniqueness w/ LIKE %x% !!!
543
                        {
571
			# 		LIMIT 1 added to prevent multiple affected lines
544
                            borrowernumber => $borrowernumber,
572
			# FIXME: accountlines table needs unique key!! Possibly a combo of borrowernumber and accountline.  
545
                            type => Koha::Accounts::CreditTypes::FineReduction(),
573
			# 		But actually, we should just have a regular autoincrementing PK and forget accountline,
546
                            amount_remaining => abs($difference),
574
			# 		including the bogus getnextaccountno function (doesn't prevent conflict on simultaneous ops).
547
                            created_on       => $timestamp,
575
			# FIXME: Why only 2 account types here?
548
                        }
576
			$debug and print STDERR "UpdateFine query: $query\n" .
549
                      );
577
				"w/ args: $amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, \"\%$due\%\"\n";
550
578
            $sth2->execute($amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, "%$due%");
551
                } else {
579
        } else {
552
                    $fine->amount_outstanding( 0 );
580
            #      print "no update needed $data->{'amount'}"
553
                }
554
555
                $fine->amount_last_increment($difference);
556
                $fine->amount_original( $fine->amount_original() + $difference );
557
                $fine->updated_on($timestamp);
558
                $fine->update();
559
560
                $offset = 1;
561
            }
581
        }
562
        }
582
    } else {
563
    }
583
        my $sth4 = $dbh->prepare(
564
    else {
584
            "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
565
        my $item = $schema->resultset('Item')->find($itemnumber);
566
567
        $fine = $schema->resultset('AccountDebit')->create(
568
            {
569
                borrowernumber        => $borrowernumber,
570
                itemnumber            => $itemnumber,
571
                issue_id              => $issue_id,
572
                type                  => Koha::Accounts::DebitTypes::Fine(),
573
                accruing              => 1,
574
                amount_original       => $amount,
575
                amount_outstanding    => $amount,
576
                amount_last_increment => $amount,
577
                description           => $item->biblio()->title() . " / Due:$due",
578
                created_on            => $timestamp,
579
            }
585
        );
580
        );
586
        $sth4->execute($itemnum);
581
587
        my $title = $sth4->fetchrow;
582
        $offset = 1;
588
589
#         #   print "not in account";
590
#         my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
591
#         $sth3->execute;
592
# 
593
#         # FIXME - Make $accountno a scalar.
594
#         my @accountno = $sth3->fetchrow_array;
595
#         $sth3->finish;
596
#         $accountno[0]++;
597
# begin transaction
598
		my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
599
		my $desc = ($type ? "$type " : '') . "$title $due";	# FIXEDME, avoid whitespace prefix on empty $type
600
		my $query = "INSERT INTO accountlines
601
		    (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
602
			    VALUES (?,?,now(),?,?,'FU',?,?,?)";
603
		my $sth2 = $dbh->prepare($query);
604
		$debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
605
        $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno);
606
    }
583
    }
607
    # logging action
584
608
    &logaction(
585
    $schema->resultset('AccountOffset')->create(
609
        "FINES",
586
        {
610
        $type,
587
            debit_id   => $fine->debit_id(),
588
            credit_id  => $credit ? $credit->credit_id() : undef,
589
            amount     => $fine->amount_last_increment(),
590
            created_on => $timestamp,
591
            type       => Koha::Accounts::OffsetTypes::Fine(),
592
        }
593
    ) if $offset;
594
595
    $borrower->account_balance( $borrower->account_balance + $fine->amount_last_increment() );
596
    $borrower->update();
597
598
    logaction( "FINES", Koha::Accounts::DebitTypes::Fine(),
611
        $borrowernumber,
599
        $borrowernumber,
612
        "due=".$due."  amount=".$amount." itemnumber=".$itemnum
600
        "due=" . $due . "  amount=" . $amount . " itemnumber=" . $itemnumber )
613
        ) if C4::Context->preference("FinesLog");
601
      if C4::Context->preference("FinesLog");
614
}
602
}
615
603
616
=head2 BorType
604
=head2 BorType
Lines 665-720 sub GetFine { Link Here
665
    return 0;
653
    return 0;
666
}
654
}
667
655
668
=head2 NumberNotifyId
669
670
    (@notify) = &NumberNotifyId($borrowernumber);
671
672
Returns amount for all file per borrowers
673
C<@notify> array contains all file per borrowers
674
675
C<$notify_id> contains the file number for the borrower number nad item number
676
677
=cut
678
679
sub NumberNotifyId{
680
    my ($borrowernumber)=@_;
681
    my $dbh = C4::Context->dbh;
682
    my $query=qq|    SELECT distinct(notify_id)
683
            FROM accountlines
684
            WHERE borrowernumber=?|;
685
    my @notify;
686
    my $sth = $dbh->prepare($query);
687
    $sth->execute($borrowernumber);
688
    while ( my ($numberofnotify) = $sth->fetchrow ) {
689
        push( @notify, $numberofnotify );
690
    }
691
    return (@notify);
692
}
693
694
=head2 AmountNotify
695
656
696
    ($totalnotify) = &AmountNotify($notifyid);
657
=head2 NumberNotifyId
697
698
Returns amount for all file per borrowers
699
C<$notifyid> is the file number
700
701
C<$totalnotify> contains amount of a file
702
658
703
C<$notify_id> contains the file number for the borrower number and item number
659
    my $schema = Koha::Database->new()->schema;
704
660
705
=cut
661
    my $amount_outstanding = $schema->resultset('AccountDebit')->search(
662
        {
663
            itemnumber     => $itemnumber,
664
            borrowernumber => $borrowernumber,
665
            type           => Koha::Accounts::DebitTypes::Fine(),
666
        },
667
    )->get_column('amount_outstanding')->sum();
706
668
707
sub AmountNotify{
669
    return $amount_outstanding;
708
    my ($notifyid,$borrowernumber)=@_;
709
    my $dbh = C4::Context->dbh;
710
    my $query=qq|    SELECT sum(amountoutstanding)
711
            FROM accountlines
712
            WHERE notify_id=? AND borrowernumber = ?|;
713
    my $sth=$dbh->prepare($query);
714
	$sth->execute($notifyid,$borrowernumber);
715
	my $totalnotify=$sth->fetchrow;
716
    $sth->finish;
717
    return ($totalnotify);
718
}
670
}
719
671
720
=head2 GetItems
672
=head2 GetItems
Lines 770-796 sub GetBranchcodesWithOverdueRules { Link Here
770
    return @$branchcodes;
722
    return @$branchcodes;
771
}
723
}
772
724
773
=head2 CheckItemNotify
774
775
Sql request to check if the document has alreday been notified
776
this function is not exported, only used with GetOverduesForBranch
777
778
=cut
779
780
sub CheckItemNotify {
781
    my ($notify_id,$notify_level,$itemnumber) = @_;
782
    my $dbh = C4::Context->dbh;
783
    my $sth = $dbh->prepare("
784
    SELECT COUNT(*)
785
     FROM notifys
786
    WHERE notify_id    = ?
787
     AND  notify_level = ? 
788
     AND  itemnumber   = ? ");
789
    $sth->execute($notify_id,$notify_level,$itemnumber);
790
    my $notified = $sth->fetchrow;
791
    return ($notified);
792
}
793
794
=head2 GetOverduesForBranch
725
=head2 GetOverduesForBranch
795
726
796
Sql request for display all information for branchoverdues.pl
727
Sql request for display all information for branchoverdues.pl
Lines 816-821 sub GetOverduesForBranch { Link Here
816
               biblio.title,
747
               biblio.title,
817
               biblio.author,
748
               biblio.author,
818
               biblio.biblionumber,
749
               biblio.biblionumber,
750
               issues.issue_id,
819
               issues.date_due,
751
               issues.date_due,
820
               issues.returndate,
752
               issues.returndate,
821
               issues.branchcode,
753
               issues.branchcode,
Lines 826-850 sub GetOverduesForBranch { Link Here
826
                items.location,
758
                items.location,
827
                items.itemnumber,
759
                items.itemnumber,
828
            itemtypes.description,
760
            itemtypes.description,
829
         accountlines.notify_id,
761
            account_debits.amount_outstanding
830
         accountlines.notify_level,
762
    FROM  account_debits
831
         accountlines.amountoutstanding
763
    LEFT JOIN issues      ON    issues.itemnumber     = account_debits.itemnumber
832
    FROM  accountlines
764
                          AND   issues.borrowernumber = account_debits.borrowernumber
833
    LEFT JOIN issues      ON    issues.itemnumber     = accountlines.itemnumber
765
    LEFT JOIN borrowers   ON borrowers.borrowernumber = account_debits.borrowernumber
834
                          AND   issues.borrowernumber = accountlines.borrowernumber
835
    LEFT JOIN borrowers   ON borrowers.borrowernumber = accountlines.borrowernumber
836
    LEFT JOIN items       ON     items.itemnumber     = issues.itemnumber
766
    LEFT JOIN items       ON     items.itemnumber     = issues.itemnumber
837
    LEFT JOIN biblio      ON      biblio.biblionumber =  items.biblionumber
767
    LEFT JOIN biblio      ON      biblio.biblionumber =  items.biblionumber
838
    LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
768
    LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
839
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
769
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
840
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
770
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
841
    WHERE (accountlines.amountoutstanding  != '0.000000')
771
    WHERE (account_debits.amount_outstanding  != '0.000000')
842
      AND (accountlines.accounttype         = 'FU'      )
772
      AND (account_debits.type = 'FINE')
773
      AND (account_debits.accruing = 1 )
843
      AND (issues.branchcode =  ?   )
774
      AND (issues.branchcode =  ?   )
844
      AND (issues.date_due  < NOW())
775
      AND (issues.date_due  < NOW())
845
    ";
776
    ";
846
    my @getoverdues;
777
    my @getoverdues;
847
    my $i = 0;
848
    my $sth;
778
    my $sth;
849
    if ($location) {
779
    if ($location) {
850
        $sth = $dbh->prepare("$select AND items.location = ? ORDER BY borrowers.surname, borrowers.firstname");
780
        $sth = $dbh->prepare("$select AND items.location = ? ORDER BY borrowers.surname, borrowers.firstname");
Lines 854-865 sub GetOverduesForBranch { Link Here
854
        $sth->execute($branch);
784
        $sth->execute($branch);
855
    }
785
    }
856
    while ( my $data = $sth->fetchrow_hashref ) {
786
    while ( my $data = $sth->fetchrow_hashref ) {
857
    #check if the document has already been notified
787
        push( @getoverdues, $data );
858
        my $countnotify = CheckItemNotify($data->{'notify_id'}, $data->{'notify_level'}, $data->{'itemnumber'});
859
        if ($countnotify eq '0') {
860
            $getoverdues[$i] = $data;
861
            $i++;
862
        }
863
    }
788
    }
864
    return (@getoverdues);
789
    return (@getoverdues);
865
}
790
}
(-)a/C4/Reports/Guided.pm (-10 / +19 lines)
Lines 92-109 my %table_areas = ( Link Here
92
    CAT  => [ 'items', 'biblioitems', 'biblio' ],
92
    CAT  => [ 'items', 'biblioitems', 'biblio' ],
93
    PAT  => ['borrowers'],
93
    PAT  => ['borrowers'],
94
    ACQ  => [ 'aqorders', 'biblio', 'items' ],
94
    ACQ  => [ 'aqorders', 'biblio', 'items' ],
95
    ACC  => [ 'borrowers', 'accountlines' ],
95
    ACC  => [ 'borrowers', 'account_credits', 'account_debits' ],
96
);
96
);
97
my %keys = (
97
my %keys = (
98
    CIRC => [ 'statistics.borrowernumber=borrowers.borrowernumber',
98
    CIRC => [
99
              'items.itemnumber = statistics.itemnumber',
99
        'statistics.borrowernumber=borrowers.borrowernumber',
100
              'biblioitems.biblioitemnumber = items.biblioitemnumber' ],
100
        'items.itemnumber = statistics.itemnumber',
101
    CAT  => [ 'items.biblioitemnumber=biblioitems.biblioitemnumber',
101
        'biblioitems.biblioitemnumber = items.biblioitemnumber'
102
              'biblioitems.biblionumber=biblio.biblionumber' ],
102
    ],
103
    PAT  => [],
103
    CAT => [
104
    ACQ  => [ 'aqorders.biblionumber=biblio.biblionumber',
104
        'items.biblioitemnumber=biblioitems.biblioitemnumber',
105
              'biblio.biblionumber=items.biblionumber' ],
105
        'biblioitems.biblionumber=biblio.biblionumber'
106
    ACC  => ['borrowers.borrowernumber=accountlines.borrowernumber'],
106
    ],
107
    PAT => [],
108
    ACQ => [
109
        'aqorders.biblionumber=biblio.biblionumber',
110
        'biblio.biblionumber=items.biblionumber'
111
    ],
112
    ACC => [
113
        'borrowers.borrowernumber=account_credits.borrowernumber',
114
        'borrowers.borrowernumber=account_debits.borrowernumber'
115
    ],
107
);
116
);
108
117
109
# have to do someting here to know if its dropdown, free text, date etc
118
# have to do someting here to know if its dropdown, free text, date etc
(-)a/C4/Reserves.pm (-13 / +10 lines)
Lines 28-34 use C4::Biblio; Link Here
28
use C4::Members;
28
use C4::Members;
29
use C4::Items;
29
use C4::Items;
30
use C4::Circulation;
30
use C4::Circulation;
31
use C4::Accounts;
32
31
33
# for _koha_notify_reserve
32
# for _koha_notify_reserve
34
use C4::Members::Messaging;
33
use C4::Members::Messaging;
Lines 174-192 sub AddReserve { Link Here
174
        $waitingdate = $resdate;
173
        $waitingdate = $resdate;
175
    }
174
    }
176
175
177
    #eval {
178
    # updates take place here
179
    if ( $fee > 0 ) {
176
    if ( $fee > 0 ) {
180
        my $nextacctno = &getnextacctno( $borrowernumber );
177
        AddDebit(
181
        my $query      = qq/
178
            {
182
        INSERT INTO accountlines
179
                borrowernumber => $borrowernumber,
183
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
180
                itemnumber     => $checkitem,
184
        VALUES
181
                amount         => $fee,
185
            (?,?,now(),?,?,'Res',?)
182
                type           => Koha::Accounts::DebitTypes::Hold(),
186
    /;
183
                description    => "Hold fee - $title",
187
        my $usth = $dbh->prepare($query);
184
                notes          => "Record ID: $biblionumber",
188
        $usth->execute( $borrowernumber, $nextacctno, $fee,
185
            }
189
            "Reserve Charge - $title", $fee );
186
        );
190
    }
187
    }
191
188
192
    #if ($const eq 'a'){
189
    #if ($const eq 'a'){
(-)a/C4/SIP/ILS/Patron.pm (-3 / +4 lines)
Lines 79-91 sub new { Link Here
79
        address         => $adr,
79
        address         => $adr,
80
        home_phone      => $kp->{phone},
80
        home_phone      => $kp->{phone},
81
        email_addr      => $kp->{email},
81
        email_addr      => $kp->{email},
82
        charge_ok       => ( !$debarred && !$expired ),
82
        charge_ok       => ( !$debarred && !$expired && ( $fines_amount < C4::Context->preference('noissuescharge') ) ),
83
        renew_ok        => ( !$debarred && !$expired ),
83
        renew_ok        => ( !$debarred && !$expired && ( $fines_amount < C4::Context->preference('OPACFineNoRenewals') ) ),
84
        recall_ok       => ( !$debarred && !$expired ),
84
        recall_ok       => ( !$debarred && !$expired ),
85
        hold_ok         => ( !$debarred && !$expired ),
85
        hold_ok         => ( !$debarred && !$expired ),
86
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
86
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
87
        claims_returned => 0,
87
        claims_returned => 0,
88
        fines           => $fines_amount, # GetMemberAccountRecords($kp->{borrowernumber})
88
        fines           => $fines_amount,
89
        fees            => 0,             # currently not distinct from fines
89
        fees            => 0,             # currently not distinct from fines
90
        recall_overdue  => 0,
90
        recall_overdue  => 0,
91
        items_billed    => 0,
91
        items_billed    => 0,
Lines 99-104 sub new { Link Here
99
        unavail_holds   => [],
99
        unavail_holds   => [],
100
        inet            => ( !$debarred && !$expired ),
100
        inet            => ( !$debarred && !$expired ),
101
        expired         => $expired,
101
        expired         => $expired,
102
        account_balance => $kp->{account_balance},
102
    );
103
    );
103
    }
104
    }
104
    $debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}";
105
    $debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}";
(-)a/C4/SIP/ILS/Transaction/FeePayment.pm (-4 / +15 lines)
Lines 20-26 use strict; Link Here
20
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# with Koha; if not, write to the Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
22
23
use C4::Accounts qw(recordpayment);
23
use Koha::Accounts qw(AddCredit);
24
use Koha::Accounts::CreditTypes;
25
use Koha::Database;
24
use ILS;
26
use ILS;
25
use parent qw(ILS::Transaction);
27
use parent qw(ILS::Transaction);
26
28
Lines 45-54 sub new { Link Here
45
sub pay {
47
sub pay {
46
    my $self           = shift;
48
    my $self           = shift;
47
    my $borrowernumber = shift;
49
    my $borrowernumber = shift;
48
    my $amt            = shift;
50
    my $amount         = shift;
49
    my $type           = shift;
51
    my $type           = shift;
50
    warn("RECORD:$borrowernumber::$amt");
52
51
    recordpayment( $borrowernumber, $amt,$type );
53
    warn("RECORD:$borrowernumber::$amount");
54
55
    AddCredit(
56
        {
57
            borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber),
58
            amount => $amount,
59
            notes  => "via SIP2. Type:$type",
60
            type   => Koha::Accounts::CreditTypes::Payment,
61
        }
62
    );
52
}
63
}
53
64
54
#sub DESTROY {
65
#sub DESTROY {
(-)a/C4/SIP/ILS/Transaction/Renew.pm (+6 lines)
Lines 34-39 sub do_renew_for { Link Here
34
    my $self = shift;
34
    my $self = shift;
35
    my $borrower = shift;
35
    my $borrower = shift;
36
    my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber});
36
    my ($renewokay,$renewerror) = CanBookBeRenewed($borrower->{borrowernumber},$self->{item}->{itemnumber});
37
38
    unless ( $borrower->{account_balance} < C4::Context->preference('OPACFineNoRenewals') ) {
39
        $renewokay = 0;
40
        $renewerror = 'too_many_fines'
41
    }
42
37
    if ($renewokay){
43
    if ($renewokay){
38
        $self->{due} = undef;
44
        $self->{due} = undef;
39
        my $due_date = AddIssue( $borrower, $self->{item}->id, undef, 0 );
45
        my $due_date = AddIssue( $borrower, $self->{item}->id, undef, 0 );
(-)a/Koha/DateUtils.pm (-1 / +6 lines)
Lines 21-33 use warnings; Link Here
21
use 5.010;
21
use 5.010;
22
use DateTime;
22
use DateTime;
23
use DateTime::Format::DateParse;
23
use DateTime::Format::DateParse;
24
use DateTime::Format::MySQL;
24
use C4::Context;
25
use C4::Context;
25
26
26
use base 'Exporter';
27
use base 'Exporter';
27
use version; our $VERSION = qv('1.0.0');
28
use version; our $VERSION = qv('1.0.0');
28
29
29
our @EXPORT = (
30
our @EXPORT = (
30
    qw( dt_from_string output_pref format_sqldatetime )
31
    qw( dt_from_string output_pref format_sqldatetime get_timestamp )
31
);
32
);
32
33
33
=head1 DateUtils
34
=head1 DateUtils
Lines 190-193 sub format_sqldatetime { Link Here
190
    return q{};
191
    return q{};
191
}
192
}
192
193
194
sub get_timestamp {
195
    return DateTime::Format::MySQL->format_datetime( dt_from_string() );
196
}
197
193
1;
198
1;
(-)a/Koha/Template/Plugin/AuthorisedValues.pm (+2 lines)
Lines 74-76 Kyle M Hall <kyle@bywatersolutions.com> Link Here
74
Jonathan Druart <jonathan.druart@biblibre.com>
74
Jonathan Druart <jonathan.druart@biblibre.com>
75
75
76
=cut
76
=cut
77
78
1;
(-)a/Koha/Template/Plugin/Koha.pm (-1 / +5 lines)
Lines 44-47 sub Preference { Link Here
44
    return C4::Context->preference( $pref );
44
    return C4::Context->preference( $pref );
45
}
45
}
46
46
47
sub Get {
48
    my ( $self, $category, $selected, $opac ) = @_;
49
    return GetAuthorisedValues( $category, $selected, $opac );
50
}
51
47
1;
52
1;
48
- 

Return to bug 6427