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

(-)a/C4/Circulation.pm (-209 / +215 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 1296-1302 sub AddIssue { Link Here
1296
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1297
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1297
        if ( $item->{'itemlost'} ) {
1298
        if ( $item->{'itemlost'} ) {
1298
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1299
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1299
                _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} );
1300
                _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1300
            }
1301
            }
1301
        }
1302
        }
1302
1303
Lines 1855-1861 sub AddReturn { Link Here
1855
        }
1856
        }
1856
1857
1857
        if ($borrowernumber) {
1858
        if ($borrowernumber) {
1858
            if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) {
1859
            if (
1860
                ( !$item->{itemlost} ) # skip lost items
1861
                && (
1862
                    (
1863
                        C4::Context->preference('CalculateFinesOnReturn')
1864
                        && $issue->{'overdue'}
1865
                    )
1866
                    || $return_date # force fine recalculation in case fine needs reduced
1867
                )
1868
              )
1869
            {
1859
                # we only need to calculate and change the fines if we want to do that on return
1870
                # we only need to calculate and change the fines if we want to do that on return
1860
                # Should be on for hourly loans
1871
                # Should be on for hourly loans
1861
                my $control = C4::Context->preference('CircControl');
1872
                my $control = C4::Context->preference('CircControl');
Lines 1873-1893 sub AddReturn { Link Here
1873
1884
1874
                $type ||= q{};
1885
                $type ||= q{};
1875
1886
1876
                if ( C4::Context->preference('finesMode') eq 'production' ) {
1887
                if ( $amount > 0
1877
                    if ( $amount > 0 ) {
1888
                    && C4::Context->preference('finesMode') eq 'production' )
1878
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1889
                {
1879
                            $issue->{borrowernumber},
1890
                    C4::Overdues::UpdateFine(
1880
                            $amount, $type, output_pref($datedue) );
1891
                        {
1881
                    }
1892
                            itemnumber     => $issue->{itemnumber},
1882
                    elsif ($return_date) {
1893
                            borrowernumber => $issue->{borrowernumber},
1883
1894
                            amount         => $amount,
1884
                       # Backdated returns may have fines that shouldn't exist,
1895
                            due            => output_pref($datedue),
1885
                       # so in this case, we need to drop those fines to 0
1896
                            issue_id       => $issue->{issue_id}
1886
1897
                        }
1887
                        C4::Overdues::UpdateFine( $issue->{itemnumber},
1898
                    );
1888
                            $issue->{borrowernumber},
1899
                }
1889
                            0, $type, output_pref($datedue) );
1900
                elsif ($return_date) {
1890
                    }
1901
1902
                    # Backdated returns may have fines that shouldn't exist,
1903
                    # so in this case, we need to drop those fines to 0
1904
                    C4::Overdues::UpdateFine(
1905
                        {
1906
                            itemnumber     => $issue->{itemnumber},
1907
                            borrowernumber => $issue->{borrowernumber},
1908
                            amount         => 0,
1909
                            due            => output_pref($datedue),
1910
                            issue_id       => $issue->{issue_id}
1911
                        }
1912
                    );
1891
                }
1913
                }
1892
            }
1914
            }
1893
1915
Lines 1938-1952 sub AddReturn { Link Here
1938
        $messages->{'WasLost'} = 1;
1960
        $messages->{'WasLost'} = 1;
1939
1961
1940
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1962
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1941
            _FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode);    # can tolerate undef $borrowernumber
1963
            _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1942
            $messages->{'LostItemFeeRefunded'} = 1;
1964
            $messages->{'LostItemFeeRefunded'} = 1;
1943
        }
1965
        }
1944
    }
1966
    }
1945
1967
1946
    # fix up the overdues in accounts...
1968
    # fix up the overdues in accounts...
1947
    if ($borrowernumber) {
1969
    if ($borrowernumber) {
1948
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
1970
        _FinalizeFine(
1949
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
1971
            {
1972
                exempt_fine => $exemptfine,
1973
                dropbox     => $dropbox,
1974
                issue       => Koha::Database->new()->schema->resultset('OldIssue')->find( $issue->{issue_id} ),
1975
            }
1976
        );
1950
        
1977
        
1951
        if ( $issue->{overdue} && $issue->{date_due} ) {
1978
        if ( $issue->{overdue} && $issue->{date_due} ) {
1952
        # fix fine days
1979
        # fix fine days
Lines 2060-2069 of the return. It is ignored when a dropbox_branch is passed in. Link Here
2060
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2087
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2,
2061
the old_issue is immediately anonymised
2088
the old_issue is immediately anonymised
2062
2089
2063
Ideally, this function would be internal to C<C4::Circulation>,
2064
not exported, but it is currently needed by one 
2065
routine in C<C4::Accounts>.
2066
2067
=cut
2090
=cut
2068
2091
2069
sub MarkIssueReturned {
2092
sub MarkIssueReturned {
Lines 2185-2339 sub _debar_user_on_return { Link Here
2185
    return;
2208
    return;
2186
}
2209
}
2187
2210
2188
=head2 _FixOverduesOnReturn
2211
=head2 _FinalizeFine
2189
2212
2190
   &_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode);
2213
   _FinalizeFine({
2191
2214
        exempt_fine => $exempt_fine,
2192
C<$brn> borrowernumber
2215
        dropbox     => $dropbox,
2193
2216
        issue       => $issue,
2194
C<$itm> itemnumber
2217
   });
2195
2218
2196
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. 
2219
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. 
2197
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2220
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue.
2221
C<$issue> -- DBIx::Class::Row for the issue
2198
2222
2199
Internal function, called only by AddReturn
2223
This subrouting closes out the accuruing of a fine, and reduces if it exemptfine or
2224
dropbox flags are passed in.
2200
2225
2201
=cut
2226
=cut
2202
2227
2203
sub _FixOverduesOnReturn {
2228
sub _FinalizeFine {
2204
    my ($borrowernumber, $item);
2229
    my ( $params ) = @_;
2205
    unless ($borrowernumber = shift) {
2230
2206
        warn "_FixOverduesOnReturn() not supplied valid borrowernumber";
2231
    my $exemptfine = $params->{exempt_fine};
2207
        return;
2232
    my $dropbox    = $params->{dropbox};
2208
    }
2233
    my $issue      = $params->{issue};
2209
    unless ($item = shift) {
2234
2210
        warn "_FixOverduesOnReturn() not supplied valid itemnumber";
2211
        return;
2212
    }
2213
    my ($exemptfine, $dropbox) = @_;
2214
    my $dbh = C4::Context->dbh;
2235
    my $dbh = C4::Context->dbh;
2215
2236
2216
    # check for overdue fine
2237
    my $schema = Koha::Database->new()->schema;
2217
    my $sth = $dbh->prepare(
2238
    my $fine = $schema->resultset('AccountDebit')->single(
2218
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')"
2239
        {
2240
            issue_id => $issue->issue_id(),
2241
            type     => Koha::Accounts::DebitTypes::Fine(),
2242
            accruing => 1,
2243
        }
2219
    );
2244
    );
2220
    $sth->execute( $borrowernumber, $item );
2221
2245
2222
    # alter fine to show that the book has been returned
2246
    return unless ( $fine );
2223
    my $data = $sth->fetchrow_hashref;
2247
2224
    return 0 unless $data;    # no warning, there's just nothing to fix
2248
    $fine->accruing(0);
2225
2249
2226
    my $uquery;
2227
    my @bind = ($data->{'accountlines_id'});
2228
    if ($exemptfine) {
2250
    if ($exemptfine) {
2229
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
2251
        AddCredit(
2230
        if (C4::Context->preference("FinesLog")) {
2252
            {
2231
            &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2253
                borrower => $fine->borrowernumber(),
2232
        }
2254
                amount   => $fine->amount_original(),
2233
    } elsif ($dropbox && $data->{lastincrement}) {
2255
                debit_id => $fine->debit_id(),
2234
        my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ;
2256
                type     => Koha::Accounts::CreditTypes::Forgiven(),
2235
        my $amt = $data->{amount} - $data->{lastincrement} ;
2257
            }
2258
        );
2236
        if (C4::Context->preference("FinesLog")) {
2259
        if (C4::Context->preference("FinesLog")) {
2237
            &logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item");
2260
            &logaction(
2238
        }
2261
                "FINES", 'MODIFY',
2239
         $uquery = "update accountlines set accounttype='F' ";
2262
                $issue->{borrowernumber},
2240
         if($outstanding  >= 0 && $amt >=0) {
2263
                "Overdue forgiven: item " . $issue->{itemnumber}
2241
            $uquery .= ", amount = ? , amountoutstanding=? ";
2264
            );
2242
            unshift @bind, ($amt, $outstanding) ;
2243
        }
2265
        }
2244
    } else {
2266
    } elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) {
2245
        $uquery = "update accountlines set accounttype='F' ";
2267
        if ( C4::Context->preference("FinesLog") ) {
2268
            &logaction( "FINES", 'MODIFY', $issue->{borrowernumber},
2269
                    "Dropbox adjustment "
2270
                  . $fine->amount_last_increment()
2271
                  . ", item " . $issue->{itemnumber} );
2272
        }
2273
        $fine->amount_original(
2274
            $fine->amount_original() - $fine->amount_last_increment() );
2275
        $fine->amount_outstanding(
2276
            $fine->amount_outstanding - $fine->amount_last_increment() );
2277
        $schema->resultset('AccountOffset')->create(
2278
            {
2279
                debit_id => $fine->debit_id(),
2280
                type     => Koha::Accounts::OffsetTypes::Dropbox(),
2281
                amount   => $fine->amount_last_increment() * -1,
2282
            }
2283
        );
2246
    }
2284
    }
2247
    $uquery .= " where (accountlines_id = ?)";
2285
2248
    my $usth = $dbh->prepare($uquery);
2286
    return $fine->update();
2249
    return $usth->execute(@bind);
2250
}
2287
}
2251
2288
2252
=head2 _FixAccountForLostAndReturned
2289
=head2 _FixAccountForLostAndReturned
2253
2290
2254
  &_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]);
2291
  &_FixAccountForLostAndReturned($itemnumber);
2255
2292
2256
Calculates the charge for a book lost and returned.
2293
  Refunds a lost item fee in necessary
2257
2258
Internal function, not exported, called only by AddReturn.
2259
2260
FIXME: This function reflects how inscrutable fines logic is.  Fix both.
2261
FIXME: Give a positive return value on success.  It might be the $borrowernumber who received credit, or the amount forgiven.
2262
2294
2263
=cut
2295
=cut
2264
2296
2265
sub _FixAccountForLostAndReturned {
2297
sub _FixAccountForLostAndReturned {
2266
    my $itemnumber     = shift or return;
2298
    my ( $itemnumber ) = @_;
2267
    my $borrowernumber = @_ ? shift : undef;
2299
2268
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2300
    my $schema = Koha::Database->new()->schema;
2269
    my $dbh = C4::Context->dbh;
2301
2270
    # check for charge made for lost book
2302
    # Find the last issue for this item
2271
    my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC");
2303
    my $issue =
2272
    $sth->execute($itemnumber);
2304
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
2273
    my $data = $sth->fetchrow_hashref;
2305
    $issue ||=
2274
    $data or return;    # bail if there is nothing to do
2306
      $schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } );
2275
    $data->{accounttype} eq 'W' and return;    # Written off
2307
2276
2308
    return unless $issue;
2277
    # writeoff this amount
2309
2278
    my $offset;
2310
    # Find a lost fee for this issue
2279
    my $amount = $data->{'amount'};
2311
    my $debit = $schema->resultset('AccountDebit')->single(
2280
    my $acctno = $data->{'accountno'};
2312
        {
2281
    my $amountleft;                                             # Starts off undef/zero.
2313
            issue_id => $issue->issue_id(),
2282
    if ($data->{'amountoutstanding'} == $amount) {
2314
            type     => Koha::Accounts::DebitTypes::Lost()
2283
        $offset     = $data->{'amount'};
2315
        }
2284
        $amountleft = 0;                                        # Hey, it's zero here, too.
2316
    );
2285
    } else {
2317
2286
        $offset     = $amount - $data->{'amountoutstanding'};   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2318
    return unless $debit;
2287
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2319
2288
    }
2320
    # Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing
2289
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
2321
    my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() });
2290
        WHERE (accountlines_id = ?)");
2322
2291
    $usth->execute($data->{'accountlines_id'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.
2323
    return if @credits;
2292
    #check if any credit is left if so writeoff other accounts
2324
2293
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
2325
    # Ok, so we know we have an unrefunded lost item fee, let's refund it
2294
    $amountleft *= -1 if ($amountleft < 0);
2326
    CreditLostItem(
2295
    if ($amountleft > 0) {
2327
        {
2296
        my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?)
2328
            borrower => $issue->borrower(),
2297
                            AND (amountoutstanding >0) ORDER BY date");     # might want to order by amountoustanding ASC (pay smallest first)
2329
            debit    => $debit
2298
        $msth->execute($data->{'borrowernumber'});
2330
        }
2299
        # offset transactions
2331
    );
2300
        my $newamtos;
2332
2301
        my $accdata;
2302
        while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){
2303
            if ($accdata->{'amountoutstanding'} < $amountleft) {
2304
                $newamtos = 0;
2305
                $amountleft -= $accdata->{'amountoutstanding'};
2306
            }  else {
2307
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
2308
                $amountleft = 0;
2309
            }
2310
            my $thisacct = $accdata->{'accountlines_id'};
2311
            # FIXME: move prepares outside while loop!
2312
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
2313
                    WHERE (accountlines_id = ?)");
2314
            $usth->execute($newamtos,$thisacct);
2315
            $usth = $dbh->prepare("INSERT INTO accountoffsets
2316
                (borrowernumber, accountno, offsetaccount,  offsetamount)
2317
                VALUES
2318
                (?,?,?,?)");
2319
            $usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos);
2320
        }
2321
    }
2322
    $amountleft *= -1 if ($amountleft > 0);
2323
    my $desc = "Item Returned " . $item_id;
2324
    $usth = $dbh->prepare("INSERT INTO accountlines
2325
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2326
        VALUES (?,?,now(),?,?,'CR',?)");
2327
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2328
    if ($borrowernumber) {
2329
        # FIXME: same as query above.  use 1 sth for both
2330
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2331
            (borrowernumber, accountno, offsetaccount,  offsetamount)
2332
            VALUES (?,?,?,?)");
2333
        $usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset);
2334
    }
2335
    ModItem({ paidfor => '' }, undef, $itemnumber);
2333
    ModItem({ paidfor => '' }, undef, $itemnumber);
2336
    return;
2337
}
2334
}
2338
2335
2339
=head2 _GetCircControlBranch
2336
=head2 _GetCircControlBranch
Lines 2781-2794 sub AddRenewal { Link Here
2781
    my $dbh = C4::Context->dbh;
2778
    my $dbh = C4::Context->dbh;
2782
2779
2783
    # Find the issues record for this book
2780
    # Find the issues record for this book
2784
    my $sth =
2781
    my $issue = Koha::Database->new()->schema->resultset('Issue')->single({ itemnumber => $itemnumber });
2785
      $dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?");
2786
    $sth->execute( $itemnumber );
2787
    my $issuedata = $sth->fetchrow_hashref;
2788
2782
2789
    return unless ( $issuedata );
2783
    return unless ( $issue );
2790
2784
2791
    $borrowernumber ||= $issuedata->{borrowernumber};
2785
    $borrowernumber ||= $issue->get_column('borrowernumber');
2792
2786
2793
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2787
    if ( defined $datedue && ref $datedue ne 'DateTime' ) {
2794
        carp 'Invalid date passed to AddRenewal.';
2788
        carp 'Invalid date passed to AddRenewal.';
Lines 2804-2844 sub AddRenewal { Link Here
2804
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2798
        my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
2805
2799
2806
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2800
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2807
                                        dt_from_string( $issuedata->{date_due} ) :
2801
                                        dt_from_string( $issue->get_column('date_due') ) :
2808
                                        DateTime->now( time_zone => C4::Context->tz());
2802
                                        DateTime->now( time_zone => C4::Context->tz());
2809
        $datedue =  CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal');
2803
        $datedue =  CalcDateDue($datedue, $itemtype, $issue->get_column('branchcode'), $borrower, 'is a renewal');
2810
    }
2804
    }
2811
2805
2812
    # Update the issues record to have the new due date, and a new count
2806
    # Update the issues record to have the new due date, and a new count
2813
    # of how many times it has been renewed.
2807
    # of how many times it has been renewed.
2814
    my $renews = $issuedata->{'renewals'} + 1;
2808
    $issue->update(
2815
    $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ?
2809
        {
2816
                            WHERE borrowernumber=? 
2810
            date_due        => $datedue->strftime('%Y-%m-%d %H:%M'),
2817
                            AND itemnumber=?"
2811
            renewals        => $issue->renewals() + 1,
2812
            lastreneweddate => $lastreneweddate,
2813
        }
2818
    );
2814
    );
2819
2815
2820
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2821
2816
2822
    # Update the renewal count on the item, and tell zebra to reindex
2817
    # Update the renewal count on the item, and tell zebra to reindex
2823
    $renews = $biblio->{'renewals'} + 1;
2818
    my $renews = $biblio->{'renewals'} + 1;
2824
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber);
2819
    ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber);
2825
2820
2826
    # Charge a new rental fee, if applicable?
2821
    # Charge a new rental fee, if applicable?
2827
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2822
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2828
    if ( $charge > 0 ) {
2823
    if ( $charge > 0 ) {
2829
        my $accountno = getnextacctno( $borrowernumber );
2830
        my $item = GetBiblioFromItemNumber($itemnumber);
2824
        my $item = GetBiblioFromItemNumber($itemnumber);
2831
        my $manager_id = 0;
2825
2832
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2826
        my $borrower =
2833
        $sth = $dbh->prepare(
2827
          Koha::Database->new()->schema->resultset('Borrower')
2834
                "INSERT INTO accountlines
2828
          ->find($borrowernumber);
2835
                    (date, borrowernumber, accountno, amount, manager_id,
2829
2836
                    description,accounttype, amountoutstanding, itemnumber)
2830
        AddDebit(
2837
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2831
            {
2832
                borrower   => $borrower,
2833
                itemnumber => $itemnumber,
2834
                amount     => $charge,
2835
                type       => Koha::Accounts::DebitTypes::Rental(),
2836
                description =>
2837
                  "Renewal of Rental Item $item->{'title'} $item->{'barcode'}"
2838
            }
2838
        );
2839
        );
2839
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2840
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2841
            'Rent', $charge, $itemnumber );
2842
    }
2840
    }
2843
2841
2844
    # Send a renewal slip according to checkout alert preferencei
2842
    # Send a renewal slip according to checkout alert preferencei
Lines 2880-2885 sub AddRenewal { Link Here
2880
                borrowernumber => $borrowernumber,
2878
                borrowernumber => $borrowernumber,
2881
                ccode => $item->{'ccode'}}
2879
                ccode => $item->{'ccode'}}
2882
                );
2880
                );
2881
2882
    _FinalizeFine( { issue => $issue } );
2883
2883
	return $datedue;
2884
	return $datedue;
2884
}
2885
}
2885
2886
Lines 3064-3088 sub _get_discount_from_rule { Link Here
3064
3065
3065
=head2 AddIssuingCharge
3066
=head2 AddIssuingCharge
3066
3067
3067
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
3068
  &AddIssuingCharge( $itemnumber, $borrowernumber, $amount )
3068
3069
3069
=cut
3070
=cut
3070
3071
3071
sub AddIssuingCharge {
3072
sub AddIssuingCharge {
3072
    my ( $itemnumber, $borrowernumber, $charge ) = @_;
3073
    my ( $itemnumber, $borrowernumber, $amount ) = @_;
3073
    my $dbh = C4::Context->dbh;
3074
3074
    my $nextaccntno = getnextacctno( $borrowernumber );
3075
    return AddDebit(
3075
    my $manager_id = 0;
3076
        {
3076
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
3077
            borrower       => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber),
3077
    my $query ="
3078
            itemnumber     => $itemnumber,
3078
        INSERT INTO accountlines
3079
            amount         => $amount,
3079
            (borrowernumber, itemnumber, accountno,
3080
            type           => Koha::Accounts::DebitTypes::Rental(),
3080
            date, amount, description, accounttype,
3081
        }
3081
            amountoutstanding, manager_id)
3082
    );
3082
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
3083
    ";
3084
    my $sth = $dbh->prepare($query);
3085
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
3086
}
3083
}
3087
3084
3088
=head2 GetTransfers
3085
=head2 GetTransfers
Lines 3601-3630 sub ReturnLostItem{ Link Here
3601
sub LostItem{
3598
sub LostItem{
3602
    my ($itemnumber, $mark_returned) = @_;
3599
    my ($itemnumber, $mark_returned) = @_;
3603
3600
3604
    my $dbh = C4::Context->dbh();
3601
    my $schema = Koha::Database->new()->schema;
3605
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3606
                           FROM issues 
3607
                           JOIN items USING (itemnumber) 
3608
                           JOIN biblio USING (biblionumber)
3609
                           WHERE issues.itemnumber=?");
3610
    $sth->execute($itemnumber);
3611
    my $issues=$sth->fetchrow_hashref();
3612
3602
3613
    # If a borrower lost the item, add a replacement cost to the their record
3603
    my $issue =
3614
    if ( my $borrowernumber = $issues->{borrowernumber} ){
3604
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
3615
        my $borrower = C4::Members::GetMemberDetails( $borrowernumber );
3605
3606
    my ( $borrower, $item );
3616
3607
3608
    if ( $issue ) {
3609
        $borrower = $issue->borrower();
3610
        $item     = $issue->item();
3611
    }
3612
3613
    # If a borrower lost the item, add a replacement cost to the their record
3614
    if ( $borrower ){
3617
        if (C4::Context->preference('WhenLostForgiveFine')){
3615
        if (C4::Context->preference('WhenLostForgiveFine')){
3618
            my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox
3616
            _FinalizeFine(
3619
            defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
3617
                {
3618
                    exempt_fine => 1,
3619
                    dropbox     => 0,
3620
                    issue       => $issue,
3621
                }
3622
            );
3620
        }
3623
        }
3621
        if (C4::Context->preference('WhenLostChargeReplacementFee')){
3624
        if ( C4::Context->preference('WhenLostChargeReplacementFee') ) {
3622
            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
3625
            DebitLostItem( { borrower => $borrower, issue => $issue } );
3623
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
3624
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
3625
        }
3626
        }
3626
3627
3627
        MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned;
3628
        MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned;
3628
    }
3629
    }
3629
}
3630
}
3630
3631
Lines 3742-3751 sub ProcessOfflineIssue { Link Here
3742
sub ProcessOfflinePayment {
3743
sub ProcessOfflinePayment {
3743
    my $operation = shift;
3744
    my $operation = shift;
3744
3745
3745
    my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber
3746
    AddCredit(
3746
    my $amount = $operation->{amount};
3747
        {
3747
3748
            borrower => Koha::Database->new()->schema->resultset('Borrower')
3748
    recordpayment( $borrower->{borrowernumber}, $amount );
3749
              ->single( { cardnumber => $operation->{cardnumber} } ),
3750
            amount => $operation->{amount},
3751
            notes  => 'via offline circulation',
3752
            type   => Koha::Accounts::CreditTypes::Payment,
3753
        }
3754
    );
3749
3755
3750
    return "Success."
3756
    return "Success."
3751
}
3757
}
(-)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 47-52 use Module::Load; Link Here
47
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
46
if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
48
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
47
    load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync );
49
}
48
}
49
use Koha::Accounts::DebitTypes;
50
50
51
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
51
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
52
52
Lines 86-93 BEGIN { Link Here
86
        &GetHideLostItemsPreference
86
        &GetHideLostItemsPreference
87
87
88
        &IsMemberBlocked
88
        &IsMemberBlocked
89
        &GetMemberAccountRecords
90
        &GetBorNotifyAcctRecord
91
89
92
        &GetborCatFromCatType
90
        &GetborCatFromCatType
93
        &GetBorrowercategory
91
        &GetBorrowercategory
Lines 361-369 sub GetMemberDetails { Link Here
361
    }
359
    }
362
    my $borrower = $sth->fetchrow_hashref;
360
    my $borrower = $sth->fetchrow_hashref;
363
    return unless $borrower;
361
    return unless $borrower;
364
    my ($amount) = GetMemberAccountRecords( $borrowernumber);
362
    $borrower->{amountoutstanding} = $borrower->{account_balance};
365
    $borrower->{'amountoutstanding'} = $amount;
363
    # FIXME - find all references to $borrower->{amountoutstanding}, replace with $borrower->{account_balance}
366
    # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
367
    my $flags = patronflags( $borrower);
364
    my $flags = patronflags( $borrower);
368
    my $accessflagshash;
365
    my $accessflagshash;
369
366
Lines 467-489 The "message" field that comes from the DB is OK. Link Here
467
# FIXME rename this function.
464
# FIXME rename this function.
468
sub patronflags {
465
sub patronflags {
469
    my %flags;
466
    my %flags;
470
    my ( $patroninformation) = @_;
467
    my ($patroninformation) = @_;
471
    my $dbh=C4::Context->dbh;
468
    my $dbh = C4::Context->dbh;
472
    my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'});
469
    if ( $patroninformation->{account_balance} > 0 ) {
473
    if ( $owing > 0 ) {
474
        my %flaginfo;
470
        my %flaginfo;
475
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
471
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
476
        $flaginfo{'message'} = sprintf 'Patron owes %.02f', $owing;
472
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
477
        $flaginfo{'amount'}  = sprintf "%.02f", $owing;
473
        if (  $patroninformation->{account_balance} > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
478
        if ( $owing > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
479
            $flaginfo{'noissues'} = 1;
474
            $flaginfo{'noissues'} = 1;
480
        }
475
        }
481
        $flags{'CHARGES'} = \%flaginfo;
476
        $flags{'CHARGES'} = \%flaginfo;
482
    }
477
    }
483
    elsif ( $balance < 0 ) {
478
    elsif ( $patroninformation->{account_balance} < 0 ) {
484
        my %flaginfo;
479
        my %flaginfo;
485
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
480
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
486
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
487
        $flags{'CREDITS'} = \%flaginfo;
481
        $flags{'CREDITS'} = \%flaginfo;
488
    }
482
    }
489
    if (   $patroninformation->{'gonenoaddress'}
483
    if (   $patroninformation->{'gonenoaddress'}
Lines 728-734 sub GetMemberIssuesAndFines { Link Here
728
    $sth->execute($borrowernumber);
722
    $sth->execute($borrowernumber);
729
    my $overdue_count = $sth->fetchrow_arrayref->[0];
723
    my $overdue_count = $sth->fetchrow_arrayref->[0];
730
724
731
    $sth = $dbh->prepare("SELECT SUM(amountoutstanding) FROM accountlines WHERE borrowernumber = ?");
725
    $sth = $dbh->prepare("SELECT account_balance FROM borrowers WHERE borrowernumber = ?");
732
    $sth->execute($borrowernumber);
726
    $sth->execute($borrowernumber);
733
    my $total_fines = $sth->fetchrow_arrayref->[0];
727
    my $total_fines = $sth->fetchrow_arrayref->[0];
734
728
Lines 1254-1310 sub GetAllIssues { Link Here
1254
}
1248
}
1255
1249
1256
1250
1257
=head2 GetMemberAccountRecords
1258
1259
  ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1260
1261
Looks up accounting data for the patron with the given borrowernumber.
1262
1263
C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1264
reference-to-array, where each element is a reference-to-hash; the
1265
keys are the fields of the C<accountlines> table in the Koha database.
1266
C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1267
total amount outstanding for all of the account lines.
1268
1269
=cut
1270
1271
sub GetMemberAccountRecords {
1272
    my ($borrowernumber) = @_;
1273
    my $dbh = C4::Context->dbh;
1274
    my @acctlines;
1275
    my $numlines = 0;
1276
    my $strsth      = qq(
1277
                        SELECT * 
1278
                        FROM accountlines 
1279
                        WHERE borrowernumber=?);
1280
    $strsth.=" ORDER BY date desc,timestamp DESC";
1281
    my $sth= $dbh->prepare( $strsth );
1282
    $sth->execute( $borrowernumber );
1283
1284
    my $total = 0;
1285
    while ( my $data = $sth->fetchrow_hashref ) {
1286
        if ( $data->{itemnumber} ) {
1287
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
1288
            $data->{biblionumber} = $biblio->{biblionumber};
1289
            $data->{title}        = $biblio->{title};
1290
        }
1291
        $acctlines[$numlines] = $data;
1292
        $numlines++;
1293
        $total += int(1000 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
1294
    }
1295
    $total /= 1000;
1296
    return ( $total, \@acctlines,$numlines);
1297
}
1298
1299
=head2 GetMemberAccountBalance
1251
=head2 GetMemberAccountBalance
1300
1252
1301
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
1253
  ($total_balance, $non_issue_balance, $other_charges) = &GetMemberAccountBalance($borrowernumber);
1302
1254
1303
Calculates amount immediately owing by the patron - non-issue charges.
1255
Calculates amount immediately owing by the patron - non-issue charges.
1304
Based on GetMemberAccountRecords.
1305
Charges exempt from non-issue are:
1256
Charges exempt from non-issue are:
1306
* Res (reserves)
1257
* HOLD fees (reserves)
1307
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
1258
* RENTAL if RentalsInNoissuesCharge syspref is set to false
1308
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1259
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1309
1260
1310
=cut
1261
=cut
Lines 1312-1382 Charges exempt from non-issue are: Link Here
1312
sub GetMemberAccountBalance {
1263
sub GetMemberAccountBalance {
1313
    my ($borrowernumber) = @_;
1264
    my ($borrowernumber) = @_;
1314
1265
1315
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
1266
    my $borrower =
1267
      Koha::Database->new()->schema->resultset('Borrower')
1268
      ->find($borrowernumber);
1316
1269
1317
    my @not_fines;
1270
    my @not_fines;
1318
    push @not_fines, 'Res' unless C4::Context->preference('HoldsInNoissuesCharge');
1319
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
1320
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1321
        my $dbh = C4::Context->dbh;
1322
        my $man_inv_types = $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'});
1323
        push @not_fines, map substr($_, 0, $ACCOUNT_TYPE_LENGTH), @$man_inv_types;
1324
    }
1325
    my %not_fine = map {$_ => 1} @not_fines;
1326
1327
    my ($total, $acctlines) = GetMemberAccountRecords($borrowernumber);
1328
    my $other_charges = 0;
1329
    foreach (@$acctlines) {
1330
        $other_charges += $_->{amountoutstanding} if $not_fine{ substr($_->{accounttype}, 0, $ACCOUNT_TYPE_LENGTH) };
1331
    }
1332
1333
    return ( $total, $total - $other_charges, $other_charges);
1334
}
1335
1271
1336
=head2 GetBorNotifyAcctRecord
1272
    push( @not_fines, Koha::Accounts::DebitTypes::Hold() );
1337
1273
1338
  ($total, $acctlines, $count) = &GetBorNotifyAcctRecord($params,$notifyid);
1274
    push( @not_fines, Koha::Accounts::DebitTypes::Rental() )
1275
      unless C4::Context->preference('RentalsInNoissuesCharge');
1339
1276
1340
Looks up accounting data for the patron with the given borrowernumber per file number.
1277
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1341
1278
        my $dbh           = C4::Context->dbh;
1342
C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1279
        my $man_inv_types = $dbh->selectcol_arrayref(q{
1343
reference-to-array, where each element is a reference-to-hash; the
1280
            SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'
1344
keys are the fields of the C<accountlines> table in the Koha database.
1281
        });
1345
C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1282
        push( @not_fines, @$man_inv_types );
1346
total amount outstanding for all of the account lines.
1283
    }
1347
1348
=cut
1349
1284
1350
sub GetBorNotifyAcctRecord {
1285
    my $other_charges =
1351
    my ( $borrowernumber, $notifyid ) = @_;
1286
      Koha::Database->new()->schema->resultset('AccountDebit')->search(
1352
    my $dbh = C4::Context->dbh;
1287
        {
1353
    my @acctlines;
1288
            borrowernumber => $borrowernumber,
1354
    my $numlines = 0;
1289
            type           => { -in => \@not_fines }
1355
    my $sth = $dbh->prepare(
1356
            "SELECT * 
1357
                FROM accountlines 
1358
                WHERE borrowernumber=? 
1359
                    AND notify_id=? 
1360
                    AND amountoutstanding != '0' 
1361
                ORDER BY notify_id,accounttype
1362
                ");
1363
1364
    $sth->execute( $borrowernumber, $notifyid );
1365
    my $total = 0;
1366
    while ( my $data = $sth->fetchrow_hashref ) {
1367
        if ( $data->{itemnumber} ) {
1368
            my $biblio = GetBiblioFromItemNumber( $data->{itemnumber} );
1369
            $data->{biblionumber} = $biblio->{biblionumber};
1370
            $data->{title}        = $biblio->{title};
1371
        }
1290
        }
1372
        $acctlines[$numlines] = $data;
1291
      )->get_column('amount_outstanding')->sum();
1373
        $numlines++;
1292
1374
        $total += int(100 * $data->{'amountoutstanding'});
1293
    return (
1375
    }
1294
        $borrower->account_balance(),
1376
    $total /= 100;
1295
        $borrower->account_balance() - $other_charges,
1377
    return ( $total, \@acctlines, $numlines );
1296
        $other_charges
1297
    );
1378
}
1298
}
1379
1299
1300
1380
=head2 checkuniquemember (OUEST-PROVENCE)
1301
=head2 checkuniquemember (OUEST-PROVENCE)
1381
1302
1382
  ($result,$categorycode)  = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
1303
  ($result,$categorycode)  = &checkuniquemember($collectivity,$surname,$firstname,$dateofbirth);
Lines 2542-2563 Add enrolment fee for a patron if needed. Link Here
2542
2463
2543
sub AddEnrolmentFeeIfNeeded {
2464
sub AddEnrolmentFeeIfNeeded {
2544
    my ( $categorycode, $borrowernumber ) = @_;
2465
    my ( $categorycode, $borrowernumber ) = @_;
2545
    # check for enrollment fee & add it if needed
2466
2546
    my $dbh = C4::Context->dbh;
2467
    my $schema = Koha::Database->new()->schema();
2547
    my $sth = $dbh->prepare(q{
2468
2548
        SELECT enrolmentfee
2469
    my $category = $schema->resultset('Category')->find($categorycode);
2549
        FROM categories
2470
    my $fee      = $category->enrolmentfee();
2550
        WHERE categorycode=?
2471
2551
    });
2472
    if ( $fee && $fee > 0 ) {
2552
    $sth->execute( $categorycode );
2473
        AddDebit(
2553
    if ( $sth->err ) {
2474
            {
2554
        warn sprintf('Database returned the following error: %s', $sth->errstr);
2475
                borrower =>
2555
        return;
2476
                  $schema->resultset('Borrower')->find($borrowernumber),
2556
    }
2477
                type   => Koha::Accounts::DebitTypes::AccountManagementFee(),
2557
    my ($enrolmentfee) = $sth->fetchrow;
2478
                amount => $fee,
2558
    if ($enrolmentfee && $enrolmentfee > 0) {
2479
            }
2559
        # insert fee in patron debts
2480
        );
2560
        C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
2561
    }
2481
    }
2562
}
2482
}
2563
2483
(-)a/C4/Overdues.pm (-216 / +143 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( $amount );
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
    elsif ( $amount ) { # No fine to update, don't insert fines of $0.00
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
583
    } else { # No fine to update, amount is 0, just return
589
#         #   print "not in account";
584
        return;
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
    }
585
    }
607
    # logging action
586
608
    &logaction(
587
    $schema->resultset('AccountOffset')->create(
609
        "FINES",
588
        {
610
        $type,
589
            debit_id   => $fine->debit_id(),
590
            credit_id  => $credit ? $credit->credit_id() : undef,
591
            amount     => $fine->amount_last_increment(),
592
            created_on => $timestamp,
593
            type       => Koha::Accounts::OffsetTypes::Fine(),
594
        }
595
    ) if $offset;
596
597
    $borrower->account_balance( $borrower->account_balance + $fine->amount_last_increment() );
598
    $borrower->update();
599
600
    logaction( "FINES", Koha::Accounts::DebitTypes::Fine(),
611
        $borrowernumber,
601
        $borrowernumber,
612
        "due=".$due."  amount=".$amount." itemnumber=".$itemnum
602
        "due=" . $due . "  amount=" . $amount . " itemnumber=" . $itemnumber )
613
        ) if C4::Context->preference("FinesLog");
603
      if C4::Context->preference("FinesLog");
614
}
604
}
615
605
616
=head2 BorType
606
=head2 BorType
Lines 672-727 sub GetFine { Link Here
672
    return 0;
662
    return 0;
673
}
663
}
674
664
675
=head2 NumberNotifyId
676
677
    (@notify) = &NumberNotifyId($borrowernumber);
678
679
Returns amount for all file per borrowers
680
C<@notify> array contains all file per borrowers
681
682
C<$notify_id> contains the file number for the borrower number nad item number
683
684
=cut
685
686
sub NumberNotifyId{
687
    my ($borrowernumber)=@_;
688
    my $dbh = C4::Context->dbh;
689
    my $query=qq|    SELECT distinct(notify_id)
690
            FROM accountlines
691
            WHERE borrowernumber=?|;
692
    my @notify;
693
    my $sth = $dbh->prepare($query);
694
    $sth->execute($borrowernumber);
695
    while ( my ($numberofnotify) = $sth->fetchrow ) {
696
        push( @notify, $numberofnotify );
697
    }
698
    return (@notify);
699
}
700
701
=head2 AmountNotify
702
665
703
    ($totalnotify) = &AmountNotify($notifyid);
666
=head2 NumberNotifyId
704
705
Returns amount for all file per borrowers
706
C<$notifyid> is the file number
707
708
C<$totalnotify> contains amount of a file
709
667
710
C<$notify_id> contains the file number for the borrower number and item number
668
    my $schema = Koha::Database->new()->schema;
711
669
712
=cut
670
    my $amount_outstanding = $schema->resultset('AccountDebit')->search(
671
        {
672
            itemnumber     => $itemnumber,
673
            borrowernumber => $borrowernumber,
674
            type           => Koha::Accounts::DebitTypes::Fine(),
675
        },
676
    )->get_column('amount_outstanding')->sum();
713
677
714
sub AmountNotify{
678
    return $amount_outstanding;
715
    my ($notifyid,$borrowernumber)=@_;
716
    my $dbh = C4::Context->dbh;
717
    my $query=qq|    SELECT sum(amountoutstanding)
718
            FROM accountlines
719
            WHERE notify_id=? AND borrowernumber = ?|;
720
    my $sth=$dbh->prepare($query);
721
	$sth->execute($notifyid,$borrowernumber);
722
	my $totalnotify=$sth->fetchrow;
723
    $sth->finish;
724
    return ($totalnotify);
725
}
679
}
726
680
727
=head2 GetItems
681
=head2 GetItems
Lines 777-803 sub GetBranchcodesWithOverdueRules { Link Here
777
    return @$branchcodes;
731
    return @$branchcodes;
778
}
732
}
779
733
780
=head2 CheckItemNotify
781
782
Sql request to check if the document has alreday been notified
783
this function is not exported, only used with GetOverduesForBranch
784
785
=cut
786
787
sub CheckItemNotify {
788
    my ($notify_id,$notify_level,$itemnumber) = @_;
789
    my $dbh = C4::Context->dbh;
790
    my $sth = $dbh->prepare("
791
    SELECT COUNT(*)
792
     FROM notifys
793
    WHERE notify_id    = ?
794
     AND  notify_level = ? 
795
     AND  itemnumber   = ? ");
796
    $sth->execute($notify_id,$notify_level,$itemnumber);
797
    my $notified = $sth->fetchrow;
798
    return ($notified);
799
}
800
801
=head2 GetOverduesForBranch
734
=head2 GetOverduesForBranch
802
735
803
Sql request for display all information for branchoverdues.pl
736
Sql request for display all information for branchoverdues.pl
Lines 823-828 sub GetOverduesForBranch { Link Here
823
               biblio.title,
756
               biblio.title,
824
               biblio.author,
757
               biblio.author,
825
               biblio.biblionumber,
758
               biblio.biblionumber,
759
               issues.issue_id,
826
               issues.date_due,
760
               issues.date_due,
827
               issues.returndate,
761
               issues.returndate,
828
               issues.branchcode,
762
               issues.branchcode,
Lines 833-857 sub GetOverduesForBranch { Link Here
833
                items.location,
767
                items.location,
834
                items.itemnumber,
768
                items.itemnumber,
835
            itemtypes.description,
769
            itemtypes.description,
836
         accountlines.notify_id,
770
            account_debits.amount_outstanding
837
         accountlines.notify_level,
771
    FROM  account_debits
838
         accountlines.amountoutstanding
772
    LEFT JOIN issues      ON    issues.itemnumber     = account_debits.itemnumber
839
    FROM  accountlines
773
                          AND   issues.borrowernumber = account_debits.borrowernumber
840
    LEFT JOIN issues      ON    issues.itemnumber     = accountlines.itemnumber
774
    LEFT JOIN borrowers   ON borrowers.borrowernumber = account_debits.borrowernumber
841
                          AND   issues.borrowernumber = accountlines.borrowernumber
842
    LEFT JOIN borrowers   ON borrowers.borrowernumber = accountlines.borrowernumber
843
    LEFT JOIN items       ON     items.itemnumber     = issues.itemnumber
775
    LEFT JOIN items       ON     items.itemnumber     = issues.itemnumber
844
    LEFT JOIN biblio      ON      biblio.biblionumber =  items.biblionumber
776
    LEFT JOIN biblio      ON      biblio.biblionumber =  items.biblionumber
845
    LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
777
    LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
846
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
778
    LEFT JOIN itemtypes   ON itemtypes.itemtype       = $itype_link
847
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
779
    LEFT JOIN branches    ON  branches.branchcode     = issues.branchcode
848
    WHERE (accountlines.amountoutstanding  != '0.000000')
780
    WHERE (account_debits.amount_outstanding  != '0.000000')
849
      AND (accountlines.accounttype         = 'FU'      )
781
      AND (account_debits.type = 'FINE')
782
      AND (account_debits.accruing = 1 )
850
      AND (issues.branchcode =  ?   )
783
      AND (issues.branchcode =  ?   )
851
      AND (issues.date_due  < NOW())
784
      AND (issues.date_due  < NOW())
852
    ";
785
    ";
853
    my @getoverdues;
786
    my @getoverdues;
854
    my $i = 0;
855
    my $sth;
787
    my $sth;
856
    if ($location) {
788
    if ($location) {
857
        $sth = $dbh->prepare("$select AND items.location = ? ORDER BY borrowers.surname, borrowers.firstname");
789
        $sth = $dbh->prepare("$select AND items.location = ? ORDER BY borrowers.surname, borrowers.firstname");
Lines 861-872 sub GetOverduesForBranch { Link Here
861
        $sth->execute($branch);
793
        $sth->execute($branch);
862
    }
794
    }
863
    while ( my $data = $sth->fetchrow_hashref ) {
795
    while ( my $data = $sth->fetchrow_hashref ) {
864
    #check if the document has already been notified
796
        push( @getoverdues, $data );
865
        my $countnotify = CheckItemNotify($data->{'notify_id'}, $data->{'notify_level'}, $data->{'itemnumber'});
866
        if ($countnotify eq '0') {
867
            $getoverdues[$i] = $data;
868
            $i++;
869
        }
870
    }
797
    }
871
    return (@getoverdues);
798
    return (@getoverdues);
872
}
799
}
(-)a/C4/Reports/Guided.pm (-1 / +1 lines)
Lines 99-105 sub get_table_areas { Link Here
99
    CAT  => [ 'items', 'biblioitems', 'biblio' ],
99
    CAT  => [ 'items', 'biblioitems', 'biblio' ],
100
    PAT  => ['borrowers'],
100
    PAT  => ['borrowers'],
101
    ACQ  => [ 'aqorders', 'biblio', 'items' ],
101
    ACQ  => [ 'aqorders', 'biblio', 'items' ],
102
    ACC  => [ 'borrowers', 'accountlines' ],
102
    ACC  => [ 'borrowers', 'account_credits', 'account_debits' ],
103
    );
103
    );
104
}
104
}
105
105
(-)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 177-195 sub AddReserve { Link Here
177
        $waitingdate = $resdate;
176
        $waitingdate = $resdate;
178
    }
177
    }
179
178
180
    #eval {
181
    # updates take place here
182
    if ( $fee > 0 ) {
179
    if ( $fee > 0 ) {
183
        my $nextacctno = &getnextacctno( $borrowernumber );
180
        AddDebit(
184
        my $query      = qq/
181
            {
185
        INSERT INTO accountlines
182
                borrowernumber => $borrowernumber,
186
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
183
                itemnumber     => $checkitem,
187
        VALUES
184
                amount         => $fee,
188
            (?,?,now(),?,?,'Res',?)
185
                type           => Koha::Accounts::DebitTypes::Hold(),
189
    /;
186
                description    => "Hold fee - $title",
190
        my $usth = $dbh->prepare($query);
187
                notes          => "Record ID: $biblionumber",
191
        $usth->execute( $borrowernumber, $nextacctno, $fee,
188
            }
192
            "Reserve Charge - $title", $fee );
189
        );
193
    }
190
    }
194
191
195
    #if ($const eq 'a'){
192
    #if ($const eq 'a'){
(-)a/C4/SIP/ILS/Patron.pm (-1 / +2 lines)
Lines 87-93 sub new { Link Here
87
        hold_ok         => ( !$debarred && !$expired && !$fine_blocked),
87
        hold_ok         => ( !$debarred && !$expired && !$fine_blocked),
88
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
88
        card_lost       => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
89
        claims_returned => 0,
89
        claims_returned => 0,
90
        fines           => $fines_amount, # GetMemberAccountRecords($kp->{borrowernumber})
90
        fines           => $fines_amount,
91
        fees            => 0,             # currently not distinct from fines
91
        fees            => 0,             # currently not distinct from fines
92
        recall_overdue  => 0,
92
        recall_overdue  => 0,
93
        items_billed    => 0,
93
        items_billed    => 0,
Lines 102-107 sub new { Link Here
102
        inet            => ( !$debarred && !$expired ),
102
        inet            => ( !$debarred && !$expired ),
103
        expired         => $expired,
103
        expired         => $expired,
104
        fee_limit       => $fee_limit,
104
        fee_limit       => $fee_limit,
105
        account_balance => $kp->{account_balance},
105
    );
106
    );
106
    }
107
    }
107
    $debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}";
108
    $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 196-199 sub format_sqldatetime { Link Here
196
    return q{};
197
    return q{};
197
}
198
}
198
199
200
sub get_timestamp {
201
    return DateTime::Format::MySQL->format_datetime( dt_from_string() );
202
}
203
199
1;
204
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 45-48 sub Preference { Link Here
45
    return encode('UTF-8', C4::Context->preference( $pref ) );
45
    return encode('UTF-8', C4::Context->preference( $pref ) );
46
}
46
}
47
47
48
sub Get {
49
    my ( $self, $category, $selected, $opac ) = @_;
50
    return GetAuthorisedValues( $category, $selected, $opac );
51
}
52
48
1;
53
1;
49
- 

Return to bug 6427