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

(-)a/C4/Circulation.pm (-166 / +145 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 C4::ItemCirculationAlertPreference;
34
use C4::ItemCirculationAlertPreference;
35
use C4::Message;
35
use C4::Message;
36
use C4::Debug;
36
use C4::Debug;
Lines 48-53 use Data::Dumper; Link Here
48
use Koha::DateUtils;
48
use Koha::DateUtils;
49
use Koha::Calendar;
49
use Koha::Calendar;
50
use Koha::Borrower::Debarments;
50
use Koha::Borrower::Debarments;
51
use Koha::Database;
51
use Carp;
52
use Carp;
52
use Date::Calc qw(
53
use Date::Calc qw(
53
  Today
54
  Today
Lines 1275-1281 sub AddIssue { Link Here
1275
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1276
        ## If item was lost, it has now been found, reverse any list item charges if neccessary.
1276
        if ( $item->{'itemlost'} ) {
1277
        if ( $item->{'itemlost'} ) {
1277
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1278
            if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1278
                _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} );
1279
                _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1279
            }
1280
            }
1280
        }
1281
        }
1281
1282
Lines 1812-1820 sub AddReturn { Link Here
1812
                if ( $amount > 0
1813
                if ( $amount > 0
1813
                    && C4::Context->preference('finesMode') eq 'production' )
1814
                    && C4::Context->preference('finesMode') eq 'production' )
1814
                {
1815
                {
1815
                    C4::Overdues::UpdateFine( $issue->{itemnumber},
1816
                    C4::Overdues::UpdateFine(
1816
                        $issue->{borrowernumber},
1817
                        {
1817
                        $amount, $type, output_pref($datedue) );
1818
                            itemnumber     => $issue->{itemnumber},
1819
                            borrowernumber => $issue->{borrowernumber},
1820
                            amount         => $amount,
1821
                            due            => output_pref($datedue),
1822
                            issue_id       => $issue->{issue_id}
1823
                        }
1824
                    );
1818
                }
1825
                }
1819
            }
1826
            }
1820
1827
Lines 1864-1881 sub AddReturn { Link Here
1864
        $messages->{'WasLost'} = 1;
1871
        $messages->{'WasLost'} = 1;
1865
1872
1866
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1873
        if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) {
1867
            _FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode);    # can tolerate undef $borrowernumber
1874
            _FixAccountForLostAndReturned( $item->{'itemnumber'} );
1868
            $messages->{'LostItemFeeRefunded'} = 1;
1875
            $messages->{'LostItemFeeRefunded'} = 1;
1869
        }
1876
        }
1870
    }
1877
    }
1871
1878
1872
    # fix up the overdues in accounts...
1879
    # fix up the overdues in accounts...
1873
    if ($borrowernumber) {
1880
    if ($borrowernumber) {
1874
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
1881
        _FixOverduesOnReturn(
1875
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
1882
            {
1883
                exempt_fine => $exemptfine,
1884
                dropbox     => $dropbox,
1885
                issue       => $issue,
1886
            }
1887
        );
1876
        
1888
        
1877
        if ( $issue->{overdue} && $issue->{date_due} ) {
1889
        if ( $issue->{overdue} && $issue->{date_due} ) {
1878
# fix fine days
1890
            # fix fine days
1879
            my $debardate =
1891
            my $debardate =
1880
              _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today );
1892
              _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today );
1881
            $messages->{Debarred} = $debardate if ($debardate);
1893
            $messages->{Debarred} = $debardate if ($debardate);
Lines 2093-2231 Internal function, called only by AddReturn Link Here
2093
=cut
2105
=cut
2094
2106
2095
sub _FixOverduesOnReturn {
2107
sub _FixOverduesOnReturn {
2096
    my ($borrowernumber, $item);
2108
    my ( $params ) = @_;
2097
    unless ($borrowernumber = shift) {
2109
2098
        warn "_FixOverduesOnReturn() not supplied valid borrowernumber";
2110
    my $exemptfine = $params->{exempt_fine};
2099
        return;
2111
    my $dropbox    = $params->{dropbox};
2100
    }
2112
    my $issue      = $params->{issue};
2101
    unless ($item = shift) {
2113
2102
        warn "_FixOverduesOnReturn() not supplied valid itemnumber";
2103
        return;
2104
    }
2105
    my ($exemptfine, $dropbox) = @_;
2106
    my $dbh = C4::Context->dbh;
2114
    my $dbh = C4::Context->dbh;
2107
2115
2108
    # check for overdue fine
2116
    my $schema = Koha::Database->new()->schema;
2109
    my $sth = $dbh->prepare(
2117
    my $fine =
2110
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')"
2118
      $schema->resultset('AccountDebit')
2111
    );
2119
      ->single( { issue_id => $issue->issue_id(), type => Koha::Accounts::DebitTypes::Fine() } );
2112
    $sth->execute( $borrowernumber, $item );
2113
2120
2114
    # alter fine to show that the book has been returned
2121
    return unless ( $fine );
2115
    my $data = $sth->fetchrow_hashref;
2122
2116
    return 0 unless $data;    # no warning, there's just nothing to fix
2123
    $fine->accruing(0);
2117
2124
2118
    my $uquery;
2119
    my @bind = ($data->{'accountlines_id'});
2120
    if ($exemptfine) {
2125
    if ($exemptfine) {
2121
        $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
2126
        AddCredit(
2122
        if (C4::Context->preference("FinesLog")) {
2127
            {
2123
            &logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item");
2128
                borrower => $fine->borrowernumber(),
2124
        }
2129
                amount   => $fine->amount_original(),
2125
    } elsif ($dropbox && $data->{lastincrement}) {
2130
                debit_id => $fine->debit_id(),
2126
        my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ;
2131
                type     => Koha::Accounts::CreditTypes::Forgiven(),
2127
        my $amt = $data->{amount} - $data->{lastincrement} ;
2132
            }
2133
        );
2128
        if (C4::Context->preference("FinesLog")) {
2134
        if (C4::Context->preference("FinesLog")) {
2129
            &logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item");
2135
            &logaction(
2136
                "FINES", 'MODIFY',
2137
                $issue->borrowernumber(),
2138
                "Overdue forgiven: item " . $issue->itemnumber()
2139
            );
2130
        }
2140
        }
2131
         $uquery = "update accountlines set accounttype='F' ";
2141
    } elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) {
2132
         if($outstanding  >= 0 && $amt >=0) {
2142
        if ( C4::Context->preference("FinesLog") ) {
2133
            $uquery .= ", amount = ? , amountoutstanding=? ";
2143
            &logaction( "FINES", 'MODIFY', $issue->borrowernumber(),
2134
            unshift @bind, ($amt, $outstanding) ;
2144
                    "Dropbox adjustment "
2145
                  . $fine->amount_last_increment()
2146
                  . ", item " . $issue->itemnumber() );
2135
        }
2147
        }
2136
    } else {
2148
        $fine->amount_original(
2137
        $uquery = "update accountlines set accounttype='F' ";
2149
            $fine->amount_original() - $fine->amount_last_increment() );
2150
        $fine->amount_outstanding(
2151
            $fine->amount_outstanding - $fine->amount_last_increment() );
2152
        $schema->resultset('AccountOffset')->create(
2153
            {
2154
                debit_id => $fine->debit_id(),
2155
                type     => Koha::Accounts::OffsetTypes::Dropbox(),
2156
                amount   => $fine->amount_last_increment() * -1,
2157
            }
2158
        );
2138
    }
2159
    }
2139
    $uquery .= " where (accountlines_id = ?)";
2160
2140
    my $usth = $dbh->prepare($uquery);
2161
    return $fine->update();
2141
    return $usth->execute(@bind);
2142
}
2162
}
2143
2163
2144
=head2 _FixAccountForLostAndReturned
2164
=head2 _FixAccountForLostAndReturned
2145
2165
2146
  &_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]);
2166
  &_FixAccountForLostAndReturned($itemnumber);
2147
2148
Calculates the charge for a book lost and returned.
2149
2167
2150
Internal function, not exported, called only by AddReturn.
2168
  Refunds a lost item fee in necessary
2151
2152
FIXME: This function reflects how inscrutable fines logic is.  Fix both.
2153
FIXME: Give a positive return value on success.  It might be the $borrowernumber who received credit, or the amount forgiven.
2154
2169
2155
=cut
2170
=cut
2156
2171
2157
sub _FixAccountForLostAndReturned {
2172
sub _FixAccountForLostAndReturned {
2158
    my $itemnumber     = shift or return;
2173
    my ( $itemnumber ) = @_;
2159
    my $borrowernumber = @_ ? shift : undef;
2174
2160
    my $item_id        = @_ ? shift : $itemnumber;  # Send the barcode if you want that logged in the description
2175
    my $schema = Koha::Database->new()->schema;
2161
    my $dbh = C4::Context->dbh;
2176
2162
    # check for charge made for lost book
2177
    # Find the last issue for this item
2163
    my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC");
2178
    my $issue =
2164
    $sth->execute($itemnumber);
2179
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
2165
    my $data = $sth->fetchrow_hashref;
2180
    $issue ||=
2166
    $data or return;    # bail if there is nothing to do
2181
      $schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } );
2167
    $data->{accounttype} eq 'W' and return;    # Written off
2182
2168
2183
    return unless $issue;
2169
    # writeoff this amount
2184
2170
    my $offset;
2185
    # Find a lost fee for this issue
2171
    my $amount = $data->{'amount'};
2186
    my $debit = $schema->resultset('AccountDebit')->single(
2172
    my $acctno = $data->{'accountno'};
2187
        {
2173
    my $amountleft;                                             # Starts off undef/zero.
2188
            issue_id => $issue->issue_id(),
2174
    if ($data->{'amountoutstanding'} == $amount) {
2189
            type     => Koha::Accounts::DebitTypes::Lost()
2175
        $offset     = $data->{'amount'};
2176
        $amountleft = 0;                                        # Hey, it's zero here, too.
2177
    } else {
2178
        $offset     = $amount - $data->{'amountoutstanding'};   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2179
        $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
2180
    }
2181
    my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
2182
        WHERE (accountlines_id = ?)");
2183
    $usth->execute($data->{'accountlines_id'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.
2184
    #check if any credit is left if so writeoff other accounts
2185
    my $nextaccntno = getnextacctno($data->{'borrowernumber'});
2186
    $amountleft *= -1 if ($amountleft < 0);
2187
    if ($amountleft > 0) {
2188
        my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?)
2189
                            AND (amountoutstanding >0) ORDER BY date");     # might want to order by amountoustanding ASC (pay smallest first)
2190
        $msth->execute($data->{'borrowernumber'});
2191
        # offset transactions
2192
        my $newamtos;
2193
        my $accdata;
2194
        while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){
2195
            if ($accdata->{'amountoutstanding'} < $amountleft) {
2196
                $newamtos = 0;
2197
                $amountleft -= $accdata->{'amountoutstanding'};
2198
            }  else {
2199
                $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
2200
                $amountleft = 0;
2201
            }
2202
            my $thisacct = $accdata->{'accountlines_id'};
2203
            # FIXME: move prepares outside while loop!
2204
            my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
2205
                    WHERE (accountlines_id = ?)");
2206
            $usth->execute($newamtos,$thisacct);
2207
            $usth = $dbh->prepare("INSERT INTO accountoffsets
2208
                (borrowernumber, accountno, offsetaccount,  offsetamount)
2209
                VALUES
2210
                (?,?,?,?)");
2211
            $usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos);
2212
        }
2190
        }
2213
    }
2191
    );
2214
    $amountleft *= -1 if ($amountleft > 0);
2192
2215
    my $desc = "Item Returned " . $item_id;
2193
    return unless $debit;
2216
    $usth = $dbh->prepare("INSERT INTO accountlines
2194
2217
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
2195
    # Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing
2218
        VALUES (?,?,now(),?,?,'CR',?)");
2196
    my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() });
2219
    $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft);
2197
2220
    if ($borrowernumber) {
2198
    return if @credits;
2221
        # FIXME: same as query above.  use 1 sth for both
2199
2222
        $usth = $dbh->prepare("INSERT INTO accountoffsets
2200
    # Ok, so we know we have an unrefunded lost item fee, let's refund it
2223
            (borrowernumber, accountno, offsetaccount,  offsetamount)
2201
    CreditLostItem(
2224
            VALUES (?,?,?,?)");
2202
        {
2225
        $usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset);
2203
            borrower => $issue->borrower(),
2226
    }
2204
            debit    => $debit
2205
        }
2206
    );
2207
2227
    ModItem({ paidfor => '' }, undef, $itemnumber);
2208
    ModItem({ paidfor => '' }, undef, $itemnumber);
2228
    return;
2229
}
2209
}
2230
2210
2231
=head2 _GetCircControlBranch
2211
=head2 _GetCircControlBranch
Lines 2584-2602 sub AddRenewal { Link Here
2584
    # Charge a new rental fee, if applicable?
2564
    # Charge a new rental fee, if applicable?
2585
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2565
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2586
    if ( $charge > 0 ) {
2566
    if ( $charge > 0 ) {
2587
        my $accountno = getnextacctno( $borrowernumber );
2588
        my $item = GetBiblioFromItemNumber($itemnumber);
2567
        my $item = GetBiblioFromItemNumber($itemnumber);
2589
        my $manager_id = 0;
2568
2590
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2569
        my $borrower =
2591
        $sth = $dbh->prepare(
2570
          Koha::Database->new()->schema->resultset('Borrower')
2592
                "INSERT INTO accountlines
2571
          ->find($borrowernumber);
2593
                    (date, borrowernumber, accountno, amount, manager_id,
2572
2594
                    description,accounttype, amountoutstanding, itemnumber)
2573
        AddDebit(
2595
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2574
            {
2575
                borrower   => $borrower,
2576
                itemnumber => $itemnumber,
2577
                amount     => $charge,
2578
                type       => Koha::Accounts::DebitTypes::Rental(),
2579
                description =>
2580
                  "Renewal of Rental Item $item->{'title'} $item->{'barcode'}"
2581
            }
2596
        );
2582
        );
2597
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2598
            "Renewal of Rental Item $item->{'title'} $item->{'barcode'}",
2599
            'Rent', $charge, $itemnumber );
2600
    }
2583
    }
2601
2584
2602
    # Send a renewal slip according to checkout alert preferencei
2585
    # Send a renewal slip according to checkout alert preferencei
Lines 2767-2791 sub _get_discount_from_rule { Link Here
2767
2750
2768
=head2 AddIssuingCharge
2751
=head2 AddIssuingCharge
2769
2752
2770
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2753
  &AddIssuingCharge( $itemnumber, $borrowernumber, $amount )
2771
2754
2772
=cut
2755
=cut
2773
2756
2774
sub AddIssuingCharge {
2757
sub AddIssuingCharge {
2775
    my ( $itemnumber, $borrowernumber, $charge ) = @_;
2758
    my ( $itemnumber, $borrowernumber, $amount ) = @_;
2776
    my $dbh = C4::Context->dbh;
2759
2777
    my $nextaccntno = getnextacctno( $borrowernumber );
2760
    return AddDebit(
2778
    my $manager_id = 0;
2761
        {
2779
    $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
2762
            borrower       => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber),
2780
    my $query ="
2763
            itemnumber     => $itemnumber,
2781
        INSERT INTO accountlines
2764
            amount         => $amount,
2782
            (borrowernumber, itemnumber, accountno,
2765
            type           => Koha::Accounts::DebitTypes::Rental(),
2783
            date, amount, description, accounttype,
2766
        }
2784
            amountoutstanding, manager_id)
2767
    );
2785
        VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?)
2786
    ";
2787
    my $sth = $dbh->prepare($query);
2788
    $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id );
2789
}
2768
}
2790
2769
2791
=head2 GetTransfers
2770
=head2 GetTransfers
Lines 3304-3333 sub ReturnLostItem{ Link Here
3304
sub LostItem{
3283
sub LostItem{
3305
    my ($itemnumber, $mark_returned) = @_;
3284
    my ($itemnumber, $mark_returned) = @_;
3306
3285
3307
    my $dbh = C4::Context->dbh();
3286
    my $schema = Koha::Database->new()->schema;
3308
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
3309
                           FROM issues 
3310
                           JOIN items USING (itemnumber) 
3311
                           JOIN biblio USING (biblionumber)
3312
                           WHERE issues.itemnumber=?");
3313
    $sth->execute($itemnumber);
3314
    my $issues=$sth->fetchrow_hashref();
3315
3287
3316
    # If a borrower lost the item, add a replacement cost to the their record
3288
    my $issue =
3317
    if ( my $borrowernumber = $issues->{borrowernumber} ){
3289
      $schema->resultset('Issue')->single( { itemnumber => $itemnumber } );
3318
        my $borrower = C4::Members::GetMemberDetails( $borrowernumber );
3319
3290
3291
    my $borrower = $issue->borrower();
3292
    my $item     = $issue->item();
3293
3294
    # If a borrower lost the item, add a replacement cost to the their record
3295
    if ( $borrower ){
3320
        if (C4::Context->preference('WhenLostForgiveFine')){
3296
        if (C4::Context->preference('WhenLostForgiveFine')){
3321
            my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox
3297
            _FixOverduesOnReturn(
3322
            defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!";  # zero is OK, check defined
3298
                {
3299
                    exempt_fine => 1,
3300
                    dropbox     => 0,
3301
                    issue       => $issue,
3302
                }
3303
            );
3323
        }
3304
        }
3324
        if (C4::Context->preference('WhenLostChargeReplacementFee')){
3305
        if ( C4::Context->preference('WhenLostChargeReplacementFee') ) {
3325
            C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
3306
            DebitLostItem( { borrower => $borrower, issue => $issue } );
3326
            #FIXME : Should probably have a way to distinguish this from an item that really was returned.
3327
            #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
3328
        }
3307
        }
3329
3308
3330
        MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned;
3309
        MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned;
3331
    }
3310
    }
3332
}
3311
}
3333
3312
(-)a/C4/Members.pm (-29 / +38 lines)
Lines 41-46 use Koha::DateUtils; Link Here
41
use Koha::Borrower::Debarments qw(IsDebarred);
41
use Koha::Borrower::Debarments qw(IsDebarred);
42
use Text::Unaccent qw( unac_string );
42
use Text::Unaccent qw( unac_string );
43
use Koha::AuthUtils qw(hash_password);
43
use Koha::AuthUtils qw(hash_password);
44
use Koha::Accounts::DebitTypes;
44
45
45
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
46
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
46
47
Lines 338-346 sub GetMemberDetails { Link Here
338
        return;
339
        return;
339
    }
340
    }
340
    my $borrower = $sth->fetchrow_hashref;
341
    my $borrower = $sth->fetchrow_hashref;
341
    my ($amount) = GetMemberAccountRecords( $borrowernumber);
342
    $borrower->{'amountoutstanding'} = $amount;
343
    # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
344
    my $flags = patronflags( $borrower);
342
    my $flags = patronflags( $borrower);
345
    my $accessflagshash;
343
    my $accessflagshash;
346
344
Lines 432-454 The "message" field that comes from the DB is OK. Link Here
432
# FIXME rename this function.
430
# FIXME rename this function.
433
sub patronflags {
431
sub patronflags {
434
    my %flags;
432
    my %flags;
435
    my ( $patroninformation) = @_;
433
    my ($patroninformation) = @_;
436
    my $dbh=C4::Context->dbh;
434
    my $dbh = C4::Context->dbh;
437
    my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'});
435
    if ( $patroninformation->{account_balance} > 0 ) {
438
    if ( $owing > 0 ) {
439
        my %flaginfo;
436
        my %flaginfo;
440
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
437
        my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
441
        $flaginfo{'message'} = sprintf 'Patron owes %.02f', $owing;
438
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
442
        $flaginfo{'amount'}  = sprintf "%.02f", $owing;
439
        if (  $patroninformation->{account_balance} > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
443
        if ( $owing > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
444
            $flaginfo{'noissues'} = 1;
440
            $flaginfo{'noissues'} = 1;
445
        }
441
        }
446
        $flags{'CHARGES'} = \%flaginfo;
442
        $flags{'CHARGES'} = \%flaginfo;
447
    }
443
    }
448
    elsif ( $balance < 0 ) {
444
    elsif ( $patroninformation->{account_balance} < 0 ) {
449
        my %flaginfo;
445
        my %flaginfo;
450
        $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance;
446
        $flaginfo{'amount'}  = $patroninformation->{account_balance};
451
        $flaginfo{'amount'}  = sprintf "%.02f", $balance;
452
        $flags{'CREDITS'} = \%flaginfo;
447
        $flags{'CREDITS'} = \%flaginfo;
453
    }
448
    }
454
    if (   $patroninformation->{'gonenoaddress'}
449
    if (   $patroninformation->{'gonenoaddress'}
Lines 691-697 sub GetMemberIssuesAndFines { Link Here
691
    $sth->execute($borrowernumber);
686
    $sth->execute($borrowernumber);
692
    my $overdue_count = $sth->fetchrow_arrayref->[0];
687
    my $overdue_count = $sth->fetchrow_arrayref->[0];
693
688
694
    $sth = $dbh->prepare("SELECT SUM(amountoutstanding) FROM accountlines WHERE borrowernumber = ?");
689
    $sth = $dbh->prepare("SELECT account_balance FROM borrowers WHERE borrowernumber = ?");
695
    $sth->execute($borrowernumber);
690
    $sth->execute($borrowernumber);
696
    my $total_fines = $sth->fetchrow_arrayref->[0];
691
    my $total_fines = $sth->fetchrow_arrayref->[0];
697
692
Lines 1216-1223 sub GetMemberAccountRecords { Link Here
1216
Calculates amount immediately owing by the patron - non-issue charges.
1211
Calculates amount immediately owing by the patron - non-issue charges.
1217
Based on GetMemberAccountRecords.
1212
Based on GetMemberAccountRecords.
1218
Charges exempt from non-issue are:
1213
Charges exempt from non-issue are:
1219
* Res (reserves)
1214
* HOLD fees (reserves)
1220
* Rent (rental) if RentalsInNoissuesCharge syspref is set to false
1215
* RENTAL if RentalsInNoissuesCharge syspref is set to false
1221
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1216
* Manual invoices if ManInvInNoissuesCharge syspref is set to false
1222
1217
1223
=cut
1218
=cut
Lines 1225-1248 Charges exempt from non-issue are: Link Here
1225
sub GetMemberAccountBalance {
1220
sub GetMemberAccountBalance {
1226
    my ($borrowernumber) = @_;
1221
    my ($borrowernumber) = @_;
1227
1222
1228
    my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous...
1223
    my $borrower =
1224
      Koha::Database->new()->schema->resultset('Borrower')
1225
      ->find($borrowernumber);
1226
1227
    my @not_fines;
1228
1229
    push( @not_fines, Koha::Accounts::DebitTypes::Hold() );
1230
1231
    push( @not_fines, Koha::Accounts::DebitTypes::Rental() )
1232
      unless C4::Context->preference('RentalsInNoissuesCharge');
1229
1233
1230
    my @not_fines = ('Res');
1231
    push @not_fines, 'Rent' unless C4::Context->preference('RentalsInNoissuesCharge');
1232
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1234
    unless ( C4::Context->preference('ManInvInNoissuesCharge') ) {
1233
        my $dbh = C4::Context->dbh;
1235
        my $dbh           = C4::Context->dbh;
1234
        my $man_inv_types = $dbh->selectcol_arrayref(qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'});
1236
        my $man_inv_types = $dbh->selectcol_arrayref(
1235
        push @not_fines, map substr($_, 0, $ACCOUNT_TYPE_LENGTH), @$man_inv_types;
1237
            qq{SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'}
1238
        );
1239
        push( @not_fines, @$man_inv_types );
1236
    }
1240
    }
1237
    my %not_fine = map {$_ => 1} @not_fines;
1238
1241
1239
    my ($total, $acctlines) = GetMemberAccountRecords($borrowernumber);
1242
    my $other_charges =
1240
    my $other_charges = 0;
1243
      Koha::Database->new()->schema->resultset('AccountDebit')->search(
1241
    foreach (@$acctlines) {
1244
        {
1242
        $other_charges += $_->{amountoutstanding} if $not_fine{ substr($_->{accounttype}, 0, $ACCOUNT_TYPE_LENGTH) };
1245
            borrowernumber => $borrowernumber,
1243
    }
1246
            type           => { -not_in => \@not_fines }
1247
        }
1248
      )->get_column('amount_outstanding')->sum();
1244
1249
1245
    return ( $total, $total - $other_charges, $other_charges);
1250
    return (
1251
        $borrower->account_balance(),
1252
        $borrower->account_balance() - $other_charges,
1253
        $other_charges
1254
    );
1246
}
1255
}
1247
1256
1248
=head2 GetBorNotifyAcctRecord
1257
=head2 GetBorNotifyAcctRecord
(-)a/C4/Overdues.pm (-129 / +90 lines)
Lines 28-33 use C4::Context; Link Here
28
use C4::Accounts;
28
use C4::Accounts;
29
use C4::Log; # logaction
29
use C4::Log; # logaction
30
use C4::Debug;
30
use C4::Debug;
31
use Koha::Database;
32
use Koha::DateUtils;
31
33
32
use vars qw($VERSION @ISA @EXPORT);
34
use vars qw($VERSION @ISA @EXPORT);
33
35
Lines 456-609 sub GetIssuesIteminfo { Link Here
456
458
457
=head2 UpdateFine
459
=head2 UpdateFine
458
460
459
    &UpdateFine($itemnumber, $borrowernumber, $amount, $type, $description);
461
    UpdateFine(
462
        {
463
            itemnumber     => $itemnumber,
464
            borrowernumber => $borrowernumber,
465
            amount         => $amount,
466
            due            => $due,
467
            issue_id       => $issue_id
468
        }
469
    );
460
470
461
(Note: the following is mostly conjecture and guesswork.)
471
Updates the fine owed on an overdue item.
462
472
463
Updates the fine owed on an overdue book.
473
C<$itemnumber> is the items's id.
464
474
465
C<$itemnumber> is the book's item number.
475
C<$borrowernumber> is the id of the patron who currently
476
has the item on loan.
466
477
467
C<$borrowernumber> is the borrower number of the patron who currently
478
C<$amount> is the total amount of the fine owed by the patron.
468
has the book on loan.
469
479
470
C<$amount> is the current amount owed by the patron.
480
C<&UpdateFine> updates the amount owed for a given fine if an issue_id
481
is passed to it. Otherwise, a new fine will be created.
471
482
472
C<$type> will be used in the description of the fine.
483
=cut
473
484
474
C<$description> is a string that must be present in the description of
485
sub UpdateFine {
475
the fine. I think this is expected to be a date in DD/MM/YYYY format.
486
    my ($params) = @_;
476
487
477
C<&UpdateFine> looks up the amount currently owed on the given item
488
    my $itemnumber     = $params->{itemnumber};
478
and sets it to C<$amount>, creating, if necessary, a new entry in the
489
    my $borrowernumber = $params->{borrowernumber};
479
accountlines table of the Koha database.
490
    my $amount         = $params->{amount};
491
    my $due            = $params->{due};
492
    my $issue_id       = $params->{issue_id};
480
493
481
=cut
494
    my $schema = Koha::Database->new()->schema;
482
495
483
#
496
    my $borrower = $schema->resultset('Borrower')->find($borrowernumber);
484
# Question: Why should the caller have to
485
# specify both the item number and the borrower number? A book can't
486
# be on loan to two different people, so the item number should be
487
# sufficient.
488
#
489
# Possible Answer: You might update a fine for a damaged item, *after* it is returned.
490
#
491
sub UpdateFine {
492
    my ( $itemnum, $borrowernumber, $amount, $type, $due ) = @_;
493
	$debug and warn "UpdateFine($itemnum, $borrowernumber, $amount, " . ($type||'""') . ", $due) called";
494
    my $dbh = C4::Context->dbh;
495
    # FIXME - What exactly is this query supposed to do? It looks up an
496
    # entry in accountlines that matches the given item and borrower
497
    # numbers, where the description contains $due, and where the
498
    # account type has one of several values, but what does this _mean_?
499
    # Does it look up existing fines for this item?
500
    # FIXME - What are these various account types? ("FU", "O", "F", "M")
501
	#	"L"   is LOST item
502
	#   "A"   is Account Management Fee
503
	#   "N"   is New Card
504
	#   "M"   is Sundry
505
	#   "O"   is Overdue ??
506
	#   "F"   is Fine ??
507
	#   "FU"  is Fine UPDATE??
508
	#	"Pay" is Payment
509
	#   "REF" is Cash Refund
510
    my $sth = $dbh->prepare(
511
        "SELECT * FROM accountlines
512
        WHERE borrowernumber=?
513
        AND   accounttype IN ('FU','O','F','M')"
514
    );
515
    $sth->execute( $borrowernumber );
516
    my $data;
517
    my $total_amount_other = 0.00;
518
    my $due_qr = qr/$due/;
519
    # Cycle through the fines and
520
    # - find line that relates to the requested $itemnum
521
    # - accumulate fines for other items
522
    # so we can update $itemnum fine taking in account fine caps
523
    while (my $rec = $sth->fetchrow_hashref) {
524
        if ($rec->{itemnumber} == $itemnum && $rec->{description} =~ /$due_qr/) {
525
            if ($data) {
526
                warn "Not a unique accountlines record for item $itemnum borrower $borrowernumber";
527
            } else {
528
                $data = $rec;
529
                next;
530
            }
531
        }
532
        $total_amount_other += $rec->{'amountoutstanding'};
533
    }
534
497
535
    if (my $maxfine = C4::Context->preference('MaxFine')) {
498
    if ( my $maxfine = C4::Context->preference('MaxFine') ) {
536
        if ($total_amount_other + $amount > $maxfine) {
499
        if ( $borrower->account_balance() + $amount > $maxfine ) {
537
            my $new_amount = $maxfine - $total_amount_other;
500
            my $new_amount = $maxfine - $borrower->account_balance();
538
            return if $new_amount <= 0.00;
501
            warn "Reducing fine for item $itemnumber borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
539
            warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
502
            if ( $new_amount <= 0 ) {
503
                warn "Fine reduced to a non-positive ammount. Fine not created.";
504
                return;
505
            }
540
            $amount = $new_amount;
506
            $amount = $new_amount;
541
        }
507
        }
542
    }
508
    }
543
509
544
    if ( $data ) {
510
    my $timestamp = get_timestamp();
545
511
546
		# we're updating an existing fine.  Only modify if amount changed
512
    my $fine =
547
        # Note that in the current implementation, you cannot pay against an accruing fine
513
      $schema->resultset('AccountDebit')->single( { issue_id => $issue_id } );
548
        # (i.e. , of accounttype 'FU').  Doing so will break accrual.
514
549
    	if ( $data->{'amount'} != $amount ) {
515
    my $offset = 0;
550
            my $diff = $amount - $data->{'amount'};
516
    if ($fine) {
551
	    #3341: diff could be positive or negative!
517
        if (
552
            my $out  = $data->{'amountoutstanding'} + $diff;
518
            sprintf( "%.6f", $fine->amount_original() )
553
            my $query = "
519
            ne
554
                UPDATE accountlines
520
            sprintf( "%.6f", $amount ) )
555
				SET date=now(), amount=?, amountoutstanding=?,
521
        {
556
					lastincrement=?, accounttype='FU'
522
            my $difference = $amount - $fine->amount_original();
557
	  			WHERE borrowernumber=?
523
558
				AND   itemnumber=?
524
            $fine->amount_original( $fine->amount_original() + $difference );
559
				AND   accounttype IN ('FU','O')
525
            $fine->amount_outstanding( $fine->amount_outstanding() + $difference );
560
				AND   description LIKE ?
526
            $fine->amount_last_increment($difference);
561
				LIMIT 1 ";
527
            $fine->updated_on($timestamp);
562
            my $sth2 = $dbh->prepare($query);
528
            $fine->update();
563
			# FIXME: BOGUS query cannot ensure uniqueness w/ LIKE %x% !!!
529
564
			# 		LIMIT 1 added to prevent multiple affected lines
530
            $offset = 1;
565
			# FIXME: accountlines table needs unique key!! Possibly a combo of borrowernumber and accountline.  
566
			# 		But actually, we should just have a regular autoincrementing PK and forget accountline,
567
			# 		including the bogus getnextaccountno function (doesn't prevent conflict on simultaneous ops).
568
			# FIXME: Why only 2 account types here?
569
			$debug and print STDERR "UpdateFine query: $query\n" .
570
				"w/ args: $amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, \"\%$due\%\"\n";
571
            $sth2->execute($amount, $out, $diff, $data->{'borrowernumber'}, $data->{'itemnumber'}, "%$due%");
572
        } else {
573
            #      print "no update needed $data->{'amount'}"
574
        }
531
        }
575
    } else {
532
    }
576
        my $sth4 = $dbh->prepare(
533
    else {
577
            "SELECT title FROM biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber WHERE items.itemnumber=?"
534
        my $item = $schema->resultset('Item')->find($itemnumber);
535
536
        $fine = $schema->resultset('AccountDebit')->create(
537
            {
538
                borrowernumber        => $borrowernumber,
539
                itemnumber            => $itemnumber,
540
                issue_id              => $issue_id,
541
                type                  => Koha::Accounts::DebitTypes::Fine(),
542
                accruing              => 1,
543
                amount_original       => $amount,
544
                amount_outstanding    => $amount,
545
                amount_last_increment => $amount,
546
                description           => $item->biblio()->title() . " / Due:$due",
547
                created_on            => $timestamp,
548
            }
578
        );
549
        );
579
        $sth4->execute($itemnum);
550
580
        my $title = $sth4->fetchrow;
551
        $offset = 1;
581
582
#         #   print "not in account";
583
#         my $sth3 = $dbh->prepare("Select max(accountno) from accountlines");
584
#         $sth3->execute;
585
# 
586
#         # FIXME - Make $accountno a scalar.
587
#         my @accountno = $sth3->fetchrow_array;
588
#         $sth3->finish;
589
#         $accountno[0]++;
590
# begin transaction
591
		my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
592
		my $desc = ($type ? "$type " : '') . "$title $due";	# FIXEDME, avoid whitespace prefix on empty $type
593
		my $query = "INSERT INTO accountlines
594
		    (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
595
			    VALUES (?,?,now(),?,?,'FU',?,?,?)";
596
		my $sth2 = $dbh->prepare($query);
597
		$debug and print STDERR "UpdateFine query: $query\nw/ args: $borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno\n";
598
        $sth2->execute($borrowernumber, $itemnum, $amount, $desc, $amount, $amount, $nextaccntno);
599
    }
552
    }
600
    # logging action
553
601
    &logaction(
554
    $schema->resultset('AccountOffset')->create(
602
        "FINES",
555
        {
603
        $type,
556
            debit_id   => $fine->debit_id(),
557
            amount     => $fine->amount_last_increment(),
558
            created_on => $timestamp,
559
            type       => Koha::Accounts::OffsetTypes::Fine(),
560
        }
561
    ) if $offset;
562
563
    logaction( "FINES", Koha::Accounts::DebitTypes::Fine(),
604
        $borrowernumber,
564
        $borrowernumber,
605
        "due=".$due."  amount=".$amount." itemnumber=".$itemnum
565
        "due=" . $due . "  amount=" . $amount . " itemnumber=" . $itemnumber )
606
        ) if C4::Context->preference("FinesLog");
566
      if C4::Context->preference("FinesLog");
607
}
567
}
608
568
609
=head2 BorType
569
=head2 BorType
Lines 804-809 sub GetOverduesForBranch { Link Here
804
               biblio.title,
764
               biblio.title,
805
               biblio.author,
765
               biblio.author,
806
               biblio.biblionumber,
766
               biblio.biblionumber,
767
               issues.issue_id,
807
               issues.date_due,
768
               issues.date_due,
808
               issues.returndate,
769
               issues.returndate,
809
               issues.branchcode,
770
               issues.branchcode,
(-)a/C4/Reserves.pm (-12 / +10 lines)
Lines 172-190 sub AddReserve { Link Here
172
        $waitingdate = $resdate;
172
        $waitingdate = $resdate;
173
    }
173
    }
174
174
175
    #eval {
176
    # updates take place here
177
    if ( $fee > 0 ) {
175
    if ( $fee > 0 ) {
178
        my $nextacctno = &getnextacctno( $borrowernumber );
176
        AddDebit(
179
        my $query      = qq/
177
            {
180
        INSERT INTO accountlines
178
                borrowernumber => $borrowernumber,
181
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
179
                itemnumber     => $checkitem,
182
        VALUES
180
                amount         => $fee,
183
            (?,?,now(),?,?,'Res',?)
181
                type           => Koha::Accounts::DebitTypes::Hold(),
184
    /;
182
                description    => "Hold fee - $title",
185
        my $usth = $dbh->prepare($query);
183
                notes          => "Record ID: $biblionumber",
186
        $usth->execute( $borrowernumber, $nextacctno, $fee,
184
            }
187
            "Reserve Charge - $title", $fee );
185
        );
188
    }
186
    }
189
187
190
    #if ($const eq 'a'){
188
    #if ($const eq 'a'){
(-)a/Koha/Accounts.pm (+515 lines)
Line 0 Link Here
1
package Koha::Accounts;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
use Data::Dumper qw(Dumper);
24
25
use C4::Context;
26
use C4::Log qw(logaction);
27
use Koha::DateUtils qw(get_timestamp);
28
29
use Koha::Accounts::CreditTypes;
30
use Koha::Accounts::DebitTypes;
31
32
use vars qw($VERSION @ISA @EXPORT);
33
34
BEGIN {
35
    require Exporter;
36
    @ISA    = qw(Exporter);
37
    @EXPORT = qw(
38
      AddDebit
39
      AddCredit
40
41
      NormalizeBalances
42
43
      RecalculateAccountBalance
44
45
      DebitLostItem
46
      CreditLostItem
47
    );
48
}
49
50
=head1 NAME
51
52
Koha::Accounts - Functions for dealing with Koha accounts
53
54
=head1 SYNOPSIS
55
56
use Koha::Accounts;
57
58
=head1 DESCRIPTION
59
60
The functions in this module deal with the monetary aspect of Koha,
61
including looking up and modifying the amount of money owed by a
62
patron.
63
64
=head1 FUNCTIONS
65
66
=head2 AddDebit
67
68
my $debit = AddDebit({
69
    borrower       => $borrower,
70
    amount         => $amount,
71
    [ type         => $type,        ]
72
    [ itemnumber   => $itemnumber,  ]
73
    [ issue_id     => $issue_id,    ]
74
    [ description  => $description, ]
75
    [ notes        => $notes,       ]
76
    [ branchcode   => $branchcode,  ]
77
    [ manager_id   => $manager_id,  ]
78
    [ accruing     => $accruing,    ] # Default 0 if not accruing, 1 if accruing
79
});
80
81
Create a new debit for a given borrower. To standardize nomenclature, any charge
82
against a borrower ( e.g. a fine, a new card charge, the cost of losing an item )
83
will be referred to as a 'debit'.
84
85
=cut
86
87
sub AddDebit {
88
    my ($params) = @_;
89
90
    my $borrower = $params->{borrower};
91
    my $amount   = $params->{amount};
92
93
    my $type        = $params->{type};
94
    my $itemnumber  = $params->{itemnumber};
95
    my $issue_id    = $params->{issue_id};
96
    my $description = $params->{description};
97
    my $notes       = $params->{notes};
98
99
    my $branchcode = $params->{branchcode};
100
    $branchcode ||=
101
      defined( C4::Context->userenv )
102
      ? C4::Context->userenv->{branch}
103
      : undef;
104
105
    my $manager_id = $params->{manager_id};
106
    $manager_id ||=
107
      defined( C4::Context->userenv )
108
      ? C4::Context->userenv->{manager_id}
109
      : undef;
110
111
    my $accruing = $params->{accruing} || 0;
112
113
    croak("Required parameter 'borrower' not passed in.")
114
      unless ($borrower);
115
    croak("Required parameter 'amount' not passed in.")
116
      unless ($amount);
117
    croak("Invalid debit type: '$type'!")
118
      unless ( Koha::Accounts::DebitTypes::IsValid($type) );
119
    croak("No issue id passed in for accruing debit!")
120
      if ( $accruing && !$issue_id );
121
122
    my $debit = Koha::Database->new()->schema->resultset('AccountDebit')->create(
123
        {
124
            borrowernumber        => $borrower->borrowernumber(),
125
            itemnumber            => $itemnumber,
126
            issue_id              => $issue_id,
127
            type                  => $type,
128
            accruing              => $accruing,
129
            amount_original       => $amount,
130
            amount_outstanding    => $amount,
131
            amount_last_increment => $amount,
132
            description           => $description,
133
            notes                 => $notes,
134
            manager_id            => $manager_id,
135
            created_on            => get_timestamp(),
136
        }
137
    );
138
139
    if ($debit) {
140
        $borrower->account_balance( $borrower->account_balance() + $amount );
141
        $borrower->update();
142
143
        NormalizeBalances( { borrower => $borrower } );
144
145
        if ( C4::Context->preference("FinesLog") ) {
146
            logaction( "FINES", "CREATE_FEE", $debit->id,
147
                Dumper( { $debit->get_columns(), accruing => $accruing } ) );
148
        }
149
    }
150
    else {
151
        carp("Something went wrong! Debit not created!");
152
    }
153
154
    return $debit;
155
}
156
157
=head2 DebitLostItem
158
159
my $debit = DebitLostItem({
160
    borrower       => $borrower,
161
    issue          => $issue,
162
});
163
164
DebitLostItem adds a replacement fee charge for the item
165
of the given issue.
166
167
=cut
168
169
sub DebitLostItem {
170
    my ($params) = @_;
171
172
    my $borrower = $params->{borrower};
173
    my $issue    = $params->{issue};
174
175
    croak("Required param 'borrower' not passed in!") unless ($borrower);
176
    croak("Required param 'issue' not passed in!")    unless ($issue);
177
178
    # Don't add lost debit if borrower has already been charged for this lost item before,
179
    # for this issue. It seems reasonable that a borrower could lose an item, find and return it,
180
    # check it out again, and lose it again, so we should do this based on issue_id, not itemnumber.
181
    unless (
182
        Koha::Database->new()->schema->resultset('AccountDebit')->search(
183
            {
184
                borrowernumber => $borrower->borrowernumber(),
185
                issue_id       => $issue->issue_id(),
186
                type           => Koha::Accounts::DebitTypes::Lost
187
            }
188
        )->count()
189
      )
190
    {
191
        my $item = $issue->item();
192
193
        $params->{accruing}   = 0;
194
        $params->{type}       = Koha::Accounts::DebitTypes::Lost;
195
        $params->{amount}     = $item->replacementprice();
196
        $params->{itemnumber} = $item->itemnumber();
197
        $params->{issue_id}   = $issue->issue_id();
198
199
        #TODO: Shouldn't we have a default replacement price as a syspref?
200
        if ( $params->{amount} ) {
201
            return AddDebit($params);
202
        }
203
        else {
204
            carp("Cannot add lost debit! Item has no replacement price!");
205
        }
206
    }
207
}
208
209
=head2 CreditLostItem
210
211
my $debit = CreditLostItem(
212
    {
213
        borrower => $borrower,
214
        debit    => $debit,
215
    }
216
);
217
218
CreditLostItem creates a payment in the amount equal
219
to the replacement price charge created by DebitLostItem.
220
221
=cut
222
223
sub CreditLostItem {
224
    my ($params) = @_;
225
226
    my $borrower = $params->{borrower};
227
    my $debit    = $params->{debit};
228
229
    croak("Required param 'borrower' not passed in!") unless ($borrower);
230
    croak("Required param 'debit' not passed in!")
231
      unless ($debit);
232
233
    my $item =
234
      Koha::Database->new()->schema->resultset('Item')
235
      ->find( $debit->itemnumber() );
236
    carp("No item found!") unless $item;
237
238
    $params->{type}     = Koha::Accounts::CreditTypes::Found;
239
    $params->{amount}   = $debit->amount_original();
240
    $params->{debit_id} = $debit->debit_id();
241
    $params->{notes}    = "Lost item found: " . $item->barcode();
242
243
    return AddCredit($params);
244
}
245
246
=head2 AddCredit
247
248
AddCredit({
249
    borrower       => $borrower,
250
    amount         => $amount,
251
    [ branchcode   => $branchcode, ]
252
    [ manager_id   => $manager_id, ]
253
    [ debit_id     => $debit_id, ] # The primary debit to be paid
254
    [ notes        => $notes, ]
255
});
256
257
Record credit by a patron. C<$borrowernumber> is the patron's
258
borrower number. C<$credit> is a floating-point number, giving the
259
amount that was paid.
260
261
Amounts owed are paid off oldest first. That is, if the patron has a
262
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a credit
263
of $1.50, then the oldest fine will be paid off in full, and $0.50
264
will be credited to the next one.
265
266
debit_id can be passed as a scalar or an array ref to make the passed
267
in debit or debits the first to be credited.
268
269
=cut
270
271
sub AddCredit {
272
    my ($params) = @_;
273
274
    my $type       = $params->{type};
275
    my $borrower   = $params->{borrower};
276
    my $amount     = $params->{amount};
277
    my $debit_id   = $params->{debit_id};
278
    my $notes      = $params->{notes};
279
    my $branchcode = $params->{branchcode};
280
    my $manager_id = $params->{manager_id};
281
282
    my $userenv = C4::Context->userenv;
283
284
    unless ( $manager_id || $userenv ) {
285
        $manager_id = $userenv->{number};
286
    }
287
288
    unless ( $branchcode || $userenv ) {
289
        $branchcode = $userenv->{branch};
290
    }
291
292
    unless ($borrower) {
293
        croak("Required parameter 'borrower' not passed in");
294
    }
295
    unless ($amount) {
296
        croak("Required parameter amount not passed in");
297
    }
298
299
    unless ( Koha::Accounts::CreditTypes::IsValid($type) ) {
300
        carp("Invalid credit type! Returning without creating credit.");
301
        return;
302
    }
303
304
    unless ($type) {
305
        carp("No type passed in, assuming Payment");
306
        $type = Koha::Accounts::CreditTypes::Payment;
307
    }
308
309
    my $debit = Koha::Database->new()->schema->resultset('AccountDebit')->find($debit_id);
310
311
    # First, we make the credit. We'll worry about what we paid later on
312
    my $credit = Koha::Database->new()->schema->resultset('AccountCredit')->create(
313
        {
314
            borrowernumber   => $borrower->borrowernumber(),
315
            type             => $type,
316
            amount_paid      => $amount,
317
            amount_remaining => $amount,
318
            notes            => $notes,
319
            manager_id       => $manager_id,
320
            created_on       => get_timestamp(),
321
        }
322
    );
323
324
    $borrower->account_balance( $borrower->account_balance() - $amount );
325
    $borrower->update();
326
327
    # If we are given specific debits, pay those ones first.
328
    if ( $debit_id ) {
329
        my @debit_ids = ref( $debit_id ) eq "ARRAY" ? @$debit_id : $debit_id;
330
        foreach my $debit_id (@debit_ids) {
331
            my $debit =
332
              Koha::Database->new()->schema->resultset('AccountDebit')->find($debit_id);
333
334
            if ($debit) {
335
                CreditDebit( { credit => $credit, debit => $debit } );
336
            }
337
            else {
338
                carp("Invalid debit_id passed in!");
339
            }
340
        }
341
    }
342
343
    # We still have leftover money, or we weren't given a specific debit to pay
344
    if ( $credit->amount_remaining() > 0 ) {
345
        my @debits = Koha::Database->new()->schema->resultset('AccountDebit')->search(
346
            {
347
                borrowernumber     => $borrower->borrowernumber(),
348
                amount_outstanding => { '>' => '0' }
349
            }
350
        );
351
352
        foreach my $debit (@debits) {
353
            if ( $credit->amount_remaining() > 0 ) {
354
                CreditDebit(
355
                    {
356
                        credit   => $credit,
357
                        debit    => $debit,
358
                        borrower => $borrower,
359
                        type     => $type,
360
                    }
361
                );
362
            }
363
        }
364
    }
365
366
    return $credit;
367
}
368
369
=head2 CreditDebit
370
371
$account_offset = CreditDebit({
372
    credit => $credit,
373
    debit => $debit,
374
});
375
376
Given a credit and a debit, this subroutine
377
will pay the appropriate amount of the debit,
378
update the debit's amount outstanding, the credit's
379
amout remaining, and create the appropriate account
380
offset.
381
382
=cut
383
384
sub CreditDebit {
385
    my ($params) = @_;
386
387
    my $credit = $params->{credit};
388
    my $debit  = $params->{debit};
389
390
    croak("Required parameter 'credit' not passed in!")
391
      unless $credit;
392
    croak("Required parameter 'debit' not passed in!") unless $debit;
393
394
    my $amount_to_pay =
395
      ( $debit->amount_outstanding() > $credit->amount_remaining() )
396
      ? $credit->amount_remaining()
397
      : $debit->amount_outstanding();
398
399
    if ( $amount_to_pay > 0 ) {
400
        $debit->amount_outstanding(
401
            $debit->amount_outstanding() - $amount_to_pay );
402
        $debit->update();
403
404
        $credit->amount_remaining(
405
            $credit->amount_remaining() - $amount_to_pay );
406
        $credit->update();
407
408
        my $offset = Koha::Database->new()->schema->resultset('AccountOffset')->create(
409
            {
410
                amount     => $amount_to_pay * -1,
411
                debit_id   => $debit->id(),
412
                credit_id  => $credit->id(),
413
                created_on => get_timestamp(),
414
            }
415
        );
416
417
        return $offset;
418
    }
419
}
420
421
=head2 RecalculateAccountBalance
422
423
$account_balance = RecalculateAccountBalance({
424
    borrower => $borrower
425
});
426
427
Recalculates a borrower's balance based on the
428
sum of the amount outstanding for the borrower's
429
debits minus the sum of the amount remaining for
430
the borrowers credits.
431
432
TODO: Would it be better to use af.amount_original - ap.amount_paid for any reason?
433
      Or, perhaps calculate both and compare the two, for error checking purposes.
434
=cut
435
436
sub RecalculateAccountBalance {
437
    my ($params) = @_;
438
439
    my $borrower = $params->{borrower};
440
    croak("Requred paramter 'borrower' not passed in!")
441
      unless ($borrower);
442
443
    my $debits =
444
      Koha::Database->new()->schema->resultset('AccountDebit')
445
      ->search( { borrowernumber => $borrower->borrowernumber() } );
446
    my $amount_outstanding = $debits->get_column('amount_outstanding')->sum();
447
448
    my $credits =
449
      Koha::Database->new()->schema->resultset('AccountCredit')
450
      ->search( { borrowernumber => $borrower->borrowernumber() } );
451
    my $amount_remaining = $credits->get_column('amount_remaining')->sum();
452
453
    my $account_balance = $amount_outstanding - $amount_remaining;
454
    $borrower->account_balance($account_balance);
455
    $borrower->update();
456
457
    return $account_balance;
458
}
459
460
=head2 NormalizeBalances
461
462
    $account_balance = NormalizeBalances({ borrower => $borrower });
463
464
    For a given borrower, this subroutine will find all debits
465
    with an outstanding balance and all credits with an unused
466
    amount remaining and will pay those debits with those credits.
467
468
=cut
469
470
sub NormalizeBalances {
471
    my ($params) = @_;
472
473
    my $borrower = $params->{borrower};
474
475
    croak("Required param 'borrower' not passed in!") unless $borrower;
476
477
    my @credits = Koha::Database->new()->schema->resultset('AccountCredit')->search(
478
        {
479
            borrowernumber   => $borrower->borrowernumber(),
480
            amount_remaining => { '>' => '0' }
481
        }
482
    );
483
484
    return unless @credits;
485
486
    my @debits = Koha::Database->new()->schema->resultset('AccountDebit')->search(
487
        {
488
            borrowernumber     => $borrower->borrowernumber(),
489
            amount_outstanding => { '>' => '0' }
490
        }
491
    );
492
493
    return unless @debits;
494
495
    foreach my $credit (@credits) {
496
        foreach my $debit (@debits) {
497
            if (   $credit->amount_remaining()
498
                && $debit->amount_outstanding() )
499
            {
500
                CreditDebit( { credit => $credit, debit => $debit } );
501
            }
502
        }
503
    }
504
505
    return RecalculateAccountBalance( { borrower => $borrower } );
506
}
507
508
1;
509
__END__
510
511
=head1 AUTHOR
512
513
Kyle M Hall <kyle@bywatersolutions.com>
514
515
=cut
(-)a/Koha/Accounts/CreditTypes.pm (+117 lines)
Line 0 Link Here
1
package Koha::Accounts::CreditTypes;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::AccountsCreditTypes - Module representing the enumerated data types for account fees
25
26
=head1 SYNOPSIS
27
28
use Koha::Accounts::CreditTypes;
29
30
my $type = Koha::Accounts::CreditTypes::Payment;
31
32
=head1 DESCRIPTION
33
34
The subroutines in this modules act as enumerated data types for the
35
different credit types in Koha ( i.e. payments, writeoffs, etc. )
36
37
=head1 FUNCTIONS
38
39
=head2 IsValid
40
41
This subroutine takes a given string and returns 1 if
42
the string matches one of the data types, and 0 if not.
43
44
FIXME: Perhaps we should use Class::Inspector instead of hard
45
coding the subs? It seems like it would be a major trade off
46
of speed just so we don't update something in two separate places
47
in the same file.
48
49
=cut
50
51
sub IsValid {
52
    my ($string) = @_;
53
54
    my $is_valid =
55
      (      $string eq Koha::Accounts::CreditTypes::Payment()
56
          || $string eq Koha::Accounts::CreditTypes::WriteOff()
57
          || $string eq Koha::Accounts::CreditTypes::Found()
58
          || $string eq Koha::Accounts::CreditTypes::Credit()
59
          || $string eq Koha::Accounts::CreditTypes::Forgiven() );
60
61
    unless ($is_valid) {
62
        $is_valid =
63
          Koha::Database->new()->schema->resultset('AuthorisedValue')
64
          ->count(
65
            { category => 'ACCOUNT_CREDIT', authorised_value => $string } );
66
    }
67
68
    return $is_valid;
69
}
70
71
=head2 Credit
72
73
=cut
74
75
sub Credit {
76
    return 'CREDIT';
77
}
78
79
=head2 Payment
80
81
=cut
82
83
sub Payment {
84
    return 'PAYMENT';
85
}
86
87
=head2 Writeoff
88
89
=cut
90
91
sub WriteOff {
92
    return 'WRITEOFF';
93
}
94
95
=head2 Writeoff
96
97
=cut
98
99
sub Found {
100
    return 'FOUND';
101
}
102
103
=head2 Forgiven
104
105
=cut
106
107
sub Forgiven {
108
    return 'FORGIVEN';
109
}
110
111
1;
112
113
=head1 AUTHOR
114
115
Kyle M Hall <kyle@bywatersolutions.com>
116
117
=cut
(-)a/Koha/Accounts/DebitTypes.pm (+160 lines)
Line 0 Link Here
1
package Koha::Accounts::DebitTypes;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::Accounts::DebitTypes - Module representing an enumerated data type for account fees
25
26
=head1 SYNOPSIS
27
28
use Koha::Accounts::DebitTypes;
29
30
my $type = Koha::Accounts::DebitTypes::Fine;
31
32
=head1 DESCRIPTION
33
34
The subroutines in this modules act as an enumerated data type
35
for debit types ( stored in account_debits.type ) in Koha.
36
37
=head1 FUNCTIONS
38
39
=head2 IsValid
40
41
This subroutine takes a given string and returns 1 if
42
the string matches one of the data types, and 0 if not.
43
44
=cut
45
46
sub IsValid {
47
    my ($string) = @_;
48
49
    my $is_valid =
50
      (      $string eq Koha::Accounts::DebitTypes::Fine()
51
          || $string eq Koha::Accounts::DebitTypes::AccountManagementFee()
52
          || $string eq Koha::Accounts::DebitTypes::Sundry()
53
          || $string eq Koha::Accounts::DebitTypes::Lost()
54
          || $string eq Koha::Accounts::DebitTypes::Hold()
55
          || $string eq Koha::Accounts::DebitTypes::Rental()
56
          || $string eq Koha::Accounts::DebitTypes::NewCard() );
57
58
    unless ($is_valid) {
59
        $is_valid =
60
          Koha::Database->new()->schema->resultset('AuthorisedValue')
61
          ->count( { category => 'MANUAL_INV', authorised_value => $string } );
62
    }
63
64
    return $is_valid;
65
}
66
67
=head2 Fine
68
69
This data type represents a standard fine within Koha.
70
71
A fine still accruing no longer needs to be differiated by type
72
from a fine done accuring. Instead, that differentication is made
73
by which table the fine exists in, account_fees_accruing vs account_fees_accrued.
74
75
In addition, fines can be checked for correctness based on the issue_id
76
they have. A fine in account_fees_accruing should always have a matching
77
issue_id in the issues table. A fine done accruing will almost always have
78
a matching issue_id in the old_issues table. However, in the case of an overdue
79
item with fines that has been renewed, and becomes overdue again, you may have
80
a case where a given issue may have a matching fine in account_fees_accruing and
81
one or more matching fines in account_fees_accrued ( one for each for the first
82
checkout and one each for any subsequent renewals )
83
84
=cut
85
86
sub Fine {
87
    return 'FINE';
88
}
89
90
=head2 AccountManagementFee
91
92
This fee type is usually reserved for payments for library cards,
93
in cases where a library must charge a patron for the ability to
94
check out items.
95
96
=cut
97
98
sub AccountManagementFee {
99
    return 'ACCOUNT_MANAGEMENT_FEE';
100
}
101
102
=head2 Sundry
103
104
This fee type is basically a 'misc' type, and should be used
105
when no other fee type is more appropriate.
106
107
=cut
108
109
sub Sundry {
110
    return 'SUNDRY';
111
}
112
113
=head2 Lost
114
115
This fee type is used when a library charges for lost items.
116
117
=cut
118
119
sub Lost {
120
    return 'LOST';
121
}
122
123
=head2 Hold
124
125
This fee type is used when a library charges for holds.
126
127
=cut
128
129
sub Hold {
130
    return 'HOLD';
131
}
132
133
=head2 Rental
134
135
This fee type is used when a library charges a rental fee for the item type.
136
137
=cut
138
139
sub Rental {
140
    return 'RENTAL';
141
}
142
143
=head2 NewCard
144
145
This fee type is used when a library charges for replacement
146
library cards.
147
148
=cut
149
150
sub NewCard {
151
    return 'NEW_CARD';
152
}
153
154
1;
155
156
=head1 AUTHOR
157
158
Kyle M Hall <kyle@bywatersolutions.com>
159
160
=cut
(-)a/Koha/Accounts/OffsetTypes.pm (+72 lines)
Line 0 Link Here
1
package Koha::Accounts::OffsetTypes;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::AccountsOffsetTypes - Module representing the enumerated data types for account fees
25
26
=head1 SYNOPSIS
27
28
use Koha::Accounts::OffsetTypes;
29
30
my $type = Koha::Accounts::OffsetTypes::Dropbox;
31
32
=head1 DESCRIPTION
33
34
The subroutines in this modules act as enumerated data types for the
35
different automatic offset types in Koha ( i.e. forgiveness, dropbox mode, etc )
36
37
These types are used for account offsets that have no corrosponding account credit,
38
e.g. automatic fine increments, dropbox mode, etc.
39
40
=head1 FUNCTIONS
41
42
=cut
43
44
=head2 Dropbox
45
46
Offset type for automatic fine reductions
47
via dropbox mode.
48
49
=cut
50
51
sub Dropbox {
52
    return 'DROPBOX';
53
}
54
55
=head2 Fine
56
57
Indicates this offset was an automatically
58
generated fine increment/decrement.
59
60
=cut
61
62
sub Fine {
63
    return 'FINE';
64
}
65
66
1;
67
68
=head1 AUTHOR
69
70
Kyle M Hall <kyle@bywatersolutions.com>
71
72
=cut
(-)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 output_pref_due format_sqlduedatetime)
31
    qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime get_timestamp )
31
);
32
);
32
33
33
=head1 DateUtils
34
=head1 DateUtils
Lines 239-242 sub format_sqlduedatetime { Link Here
239
    return q{};
240
    return q{};
240
}
241
}
241
242
243
sub get_timestamp {
244
    return DateTime::Format::MySQL->format_datetime( dt_from_string() );
245
}
246
242
1;
247
1;
(-)a/Koha/Schema/Result/AccountCredit.pm (+140 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountCredit;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountCredit
15
16
=cut
17
18
__PACKAGE__->table("account_credits");
19
20
=head1 ACCESSORS
21
22
=head2 credit_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 borrowernumber
29
30
  data_type: 'integer'
31
  is_foreign_key: 1
32
  is_nullable: 0
33
34
=head2 type
35
36
  data_type: 'varchar'
37
  is_nullable: 0
38
  size: 255
39
40
=head2 amount_paid
41
42
  data_type: 'decimal'
43
  is_nullable: 0
44
  size: [28,6]
45
46
=head2 amount_remaining
47
48
  data_type: 'decimal'
49
  is_nullable: 0
50
  size: [28,6]
51
52
=head2 notes
53
54
  data_type: 'text'
55
  is_nullable: 1
56
57
=head2 manager_id
58
59
  data_type: 'integer'
60
  is_nullable: 1
61
62
=head2 created_on
63
64
  data_type: 'timestamp'
65
  is_nullable: 1
66
67
=head2 updated_on
68
69
  data_type: 'timestamp'
70
  is_nullable: 1
71
72
=cut
73
74
__PACKAGE__->add_columns(
75
  "credit_id",
76
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
77
  "borrowernumber",
78
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
79
  "type",
80
  { data_type => "varchar", is_nullable => 0, size => 255 },
81
  "amount_paid",
82
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
83
  "amount_remaining",
84
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
85
  "notes",
86
  { data_type => "text", is_nullable => 1 },
87
  "manager_id",
88
  { data_type => "integer", is_nullable => 1 },
89
  "created_on",
90
  { data_type => "timestamp", is_nullable => 1 },
91
  "updated_on",
92
  { data_type => "timestamp", is_nullable => 1 },
93
);
94
__PACKAGE__->set_primary_key("credit_id");
95
96
=head1 RELATIONS
97
98
=head2 borrowernumber
99
100
Type: belongs_to
101
102
Related object: L<Koha::Schema::Result::Borrower>
103
104
=cut
105
106
__PACKAGE__->belongs_to(
107
  "borrowernumber",
108
  "Koha::Schema::Result::Borrower",
109
  { borrowernumber => "borrowernumber" },
110
  { on_delete => "CASCADE", on_update => "CASCADE" },
111
);
112
113
=head2 account_offsets
114
115
Type: has_many
116
117
Related object: L<Koha::Schema::Result::AccountOffset>
118
119
=cut
120
121
__PACKAGE__->has_many(
122
  "account_offsets",
123
  "Koha::Schema::Result::AccountOffset",
124
  { "foreign.credit_id" => "self.credit_id" },
125
  { cascade_copy => 0, cascade_delete => 0 },
126
);
127
128
129
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-10-09 10:37:23
130
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uvt4OuaJxv4jk08zJsKouw
131
132
__PACKAGE__->belongs_to(
133
  "borrower",
134
  "Koha::Schema::Result::Borrower",
135
  { borrowernumber => "borrowernumber" },
136
);
137
138
139
# You can replace this text with custom content, and it will be preserved on regeneration
140
1;
(-)a/Koha/Schema/Result/AccountDebit.pm (+207 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountDebit;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountDebit
15
16
=cut
17
18
__PACKAGE__->table("account_debits");
19
20
=head1 ACCESSORS
21
22
=head2 debit_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 borrowernumber
29
30
  data_type: 'integer'
31
  default_value: 0
32
  is_foreign_key: 1
33
  is_nullable: 0
34
35
=head2 itemnumber
36
37
  data_type: 'integer'
38
  is_nullable: 1
39
40
=head2 issue_id
41
42
  data_type: 'integer'
43
  is_nullable: 1
44
45
=head2 type
46
47
  data_type: 'varchar'
48
  is_nullable: 0
49
  size: 255
50
51
=head2 accruing
52
53
  data_type: 'tinyint'
54
  default_value: 0
55
  is_nullable: 0
56
57
=head2 amount_original
58
59
  data_type: 'decimal'
60
  is_nullable: 1
61
  size: [28,6]
62
63
=head2 amount_outstanding
64
65
  data_type: 'decimal'
66
  is_nullable: 1
67
  size: [28,6]
68
69
=head2 amount_last_increment
70
71
  data_type: 'decimal'
72
  is_nullable: 1
73
  size: [28,6]
74
75
=head2 description
76
77
  data_type: 'mediumtext'
78
  is_nullable: 1
79
80
=head2 notes
81
82
  data_type: 'text'
83
  is_nullable: 1
84
85
=head2 manager_id
86
87
  data_type: 'integer'
88
  is_nullable: 1
89
90
=head2 created_on
91
92
  data_type: 'timestamp'
93
  is_nullable: 1
94
95
=head2 updated_on
96
97
  data_type: 'timestamp'
98
  is_nullable: 1
99
100
=cut
101
102
__PACKAGE__->add_columns(
103
  "debit_id",
104
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
105
  "borrowernumber",
106
  {
107
    data_type      => "integer",
108
    default_value  => 0,
109
    is_foreign_key => 1,
110
    is_nullable    => 0,
111
  },
112
  "itemnumber",
113
  { data_type => "integer", is_nullable => 1 },
114
  "issue_id",
115
  { data_type => "integer", is_nullable => 1 },
116
  "type",
117
  { data_type => "varchar", is_nullable => 0, size => 255 },
118
  "accruing",
119
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
120
  "amount_original",
121
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
122
  "amount_outstanding",
123
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
124
  "amount_last_increment",
125
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
126
  "description",
127
  { data_type => "mediumtext", is_nullable => 1 },
128
  "notes",
129
  { data_type => "text", is_nullable => 1 },
130
  "manager_id",
131
  { data_type => "integer", is_nullable => 1 },
132
  "created_on",
133
  { data_type => "timestamp", is_nullable => 1 },
134
  "updated_on",
135
  { data_type => "timestamp", is_nullable => 1 },
136
);
137
__PACKAGE__->set_primary_key("debit_id");
138
139
=head1 RELATIONS
140
141
=head2 borrowernumber
142
143
Type: belongs_to
144
145
Related object: L<Koha::Schema::Result::Borrower>
146
147
=cut
148
149
__PACKAGE__->belongs_to(
150
  "borrowernumber",
151
  "Koha::Schema::Result::Borrower",
152
  { borrowernumber => "borrowernumber" },
153
  { on_delete => "CASCADE", on_update => "CASCADE" },
154
);
155
156
=head2 account_offsets
157
158
Type: has_many
159
160
Related object: L<Koha::Schema::Result::AccountOffset>
161
162
=cut
163
164
__PACKAGE__->has_many(
165
  "account_offsets",
166
  "Koha::Schema::Result::AccountOffset",
167
  { "foreign.debit_id" => "self.debit_id" },
168
  { cascade_copy => 0, cascade_delete => 0 },
169
);
170
171
172
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-11-05 08:09:09
173
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ulQStZJSzcD4hvrPbtew4g
174
175
__PACKAGE__->belongs_to(
176
  "item",
177
  "Koha::Schema::Result::Item",
178
  { itemnumber => "itemnumber" }
179
);
180
181
__PACKAGE__->belongs_to(
182
  "deleted_item",
183
  "Koha::Schema::Result::Deleteditem",
184
  { itemnumber => "itemnumber" }
185
);
186
187
__PACKAGE__->belongs_to(
188
  "issue",
189
  "Koha::Schema::Result::Issue",
190
  { issue_id => "issue_id" }
191
);
192
193
__PACKAGE__->belongs_to(
194
  "old_issue",
195
  "Koha::Schema::Result::OldIssue",
196
  { issue_id => "issue_id" }
197
);
198
199
__PACKAGE__->belongs_to(
200
  "borrower",
201
  "Koha::Schema::Result::Borrower",
202
  { borrowernumber => "borrowernumber" },
203
  { on_delete => "CASCADE", on_update => "CASCADE" },
204
);
205
206
# You can replace this text with custom content, and it will be preserved on regeneration
207
1;
(-)a/Koha/Schema/Result/AccountOffset.pm (+118 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountOffset;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountOffset
15
16
=cut
17
18
__PACKAGE__->table("account_offsets");
19
20
=head1 ACCESSORS
21
22
=head2 offset_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 debit_id
29
30
  data_type: 'integer'
31
  is_foreign_key: 1
32
  is_nullable: 1
33
34
=head2 credit_id
35
36
  data_type: 'integer'
37
  is_foreign_key: 1
38
  is_nullable: 1
39
40
=head2 type
41
42
  data_type: 'varchar'
43
  is_nullable: 1
44
  size: 255
45
46
=head2 amount
47
48
  data_type: 'decimal'
49
  is_nullable: 0
50
  size: [28,6]
51
52
=head2 created_on
53
54
  data_type: 'timestamp'
55
  default_value: current_timestamp
56
  is_nullable: 0
57
58
=cut
59
60
__PACKAGE__->add_columns(
61
  "offset_id",
62
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
63
  "debit_id",
64
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
65
  "credit_id",
66
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
67
  "type",
68
  { data_type => "varchar", is_nullable => 1, size => 255 },
69
  "amount",
70
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
71
  "created_on",
72
  {
73
    data_type     => "timestamp",
74
    default_value => \"current_timestamp",
75
    is_nullable   => 0,
76
  },
77
);
78
__PACKAGE__->set_primary_key("offset_id");
79
80
=head1 RELATIONS
81
82
=head2 debit
83
84
Type: belongs_to
85
86
Related object: L<Koha::Schema::Result::AccountDebit>
87
88
=cut
89
90
__PACKAGE__->belongs_to(
91
  "debit",
92
  "Koha::Schema::Result::AccountDebit",
93
  { debit_id => "debit_id" },
94
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
95
);
96
97
=head2 credit
98
99
Type: belongs_to
100
101
Related object: L<Koha::Schema::Result::AccountCredit>
102
103
=cut
104
105
__PACKAGE__->belongs_to(
106
  "credit",
107
  "Koha::Schema::Result::AccountCredit",
108
  { credit_id => "credit_id" },
109
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
110
);
111
112
113
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-11-05 08:47:10
114
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BLjpL8skXmzxOQ/J0jzdvw
115
116
117
# You can replace this text with custom content, and it will be preserved on regeneration
118
1;
(-)a/Koha/Schema/Result/Borrower.pm (-75 / +62 lines)
Lines 1-21 Link Here
1
use utf8;
2
package Koha::Schema::Result::Borrower;
1
package Koha::Schema::Result::Borrower;
3
2
4
# Created by DBIx::Class::Schema::Loader
3
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
5
7
=head1 NAME
8
9
Koha::Schema::Result::Borrower
10
11
=cut
12
13
use strict;
6
use strict;
14
use warnings;
7
use warnings;
15
8
16
use base 'DBIx::Class::Core';
9
use base 'DBIx::Class::Core';
17
10
18
=head1 TABLE: C<borrowers>
11
12
=head1 NAME
13
14
Koha::Schema::Result::Borrower
19
15
20
=cut
16
=cut
21
17
Lines 191-197 __PACKAGE__->table("borrowers"); Link Here
191
=head2 dateofbirth
187
=head2 dateofbirth
192
188
193
  data_type: 'date'
189
  data_type: 'date'
194
  datetime_undef_if_invalid: 1
195
  is_nullable: 1
190
  is_nullable: 1
196
191
197
=head2 branchcode
192
=head2 branchcode
Lines 213-225 __PACKAGE__->table("borrowers"); Link Here
213
=head2 dateenrolled
208
=head2 dateenrolled
214
209
215
  data_type: 'date'
210
  data_type: 'date'
216
  datetime_undef_if_invalid: 1
217
  is_nullable: 1
211
  is_nullable: 1
218
212
219
=head2 dateexpiry
213
=head2 dateexpiry
220
214
221
  data_type: 'date'
215
  data_type: 'date'
222
  datetime_undef_if_invalid: 1
223
  is_nullable: 1
216
  is_nullable: 1
224
217
225
=head2 gonenoaddress
218
=head2 gonenoaddress
Lines 235-241 __PACKAGE__->table("borrowers"); Link Here
235
=head2 debarred
228
=head2 debarred
236
229
237
  data_type: 'date'
230
  data_type: 'date'
238
  datetime_undef_if_invalid: 1
239
  is_nullable: 1
231
  is_nullable: 1
240
232
241
=head2 debarredcomment
233
=head2 debarredcomment
Lines 397-402 __PACKAGE__->table("borrowers"); Link Here
397
  default_value: 1
389
  default_value: 1
398
  is_nullable: 0
390
  is_nullable: 0
399
391
392
=head2 account_balance
393
394
  data_type: 'decimal'
395
  default_value: 0.000000
396
  is_nullable: 0
397
  size: [28,6]
398
400
=cut
399
=cut
401
400
402
__PACKAGE__->add_columns(
401
__PACKAGE__->add_columns(
Lines 463-469 __PACKAGE__->add_columns( Link Here
463
  "b_phone",
462
  "b_phone",
464
  { data_type => "mediumtext", is_nullable => 1 },
463
  { data_type => "mediumtext", is_nullable => 1 },
465
  "dateofbirth",
464
  "dateofbirth",
466
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
465
  { data_type => "date", is_nullable => 1 },
467
  "branchcode",
466
  "branchcode",
468
  {
467
  {
469
    data_type => "varchar",
468
    data_type => "varchar",
Lines 481-495 __PACKAGE__->add_columns( Link Here
481
    size => 10,
480
    size => 10,
482
  },
481
  },
483
  "dateenrolled",
482
  "dateenrolled",
484
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
483
  { data_type => "date", is_nullable => 1 },
485
  "dateexpiry",
484
  "dateexpiry",
486
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
485
  { data_type => "date", is_nullable => 1 },
487
  "gonenoaddress",
486
  "gonenoaddress",
488
  { data_type => "tinyint", is_nullable => 1 },
487
  { data_type => "tinyint", is_nullable => 1 },
489
  "lost",
488
  "lost",
490
  { data_type => "tinyint", is_nullable => 1 },
489
  { data_type => "tinyint", is_nullable => 1 },
491
  "debarred",
490
  "debarred",
492
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
491
  { data_type => "date", is_nullable => 1 },
493
  "debarredcomment",
492
  "debarredcomment",
494
  { data_type => "varchar", is_nullable => 1, size => 255 },
493
  { data_type => "varchar", is_nullable => 1, size => 255 },
495
  "contactname",
494
  "contactname",
Lines 546-580 __PACKAGE__->add_columns( Link Here
546
  { data_type => "varchar", is_nullable => 1, size => 50 },
545
  { data_type => "varchar", is_nullable => 1, size => 50 },
547
  "privacy",
546
  "privacy",
548
  { data_type => "integer", default_value => 1, is_nullable => 0 },
547
  { data_type => "integer", default_value => 1, is_nullable => 0 },
548
  "account_balance",
549
  {
550
    data_type => "decimal",
551
    default_value => "0.000000",
552
    is_nullable => 0,
553
    size => [28, 6],
554
  },
549
);
555
);
556
__PACKAGE__->set_primary_key("borrowernumber");
557
__PACKAGE__->add_unique_constraint("cardnumber", ["cardnumber"]);
550
558
551
=head1 PRIMARY KEY
559
=head1 RELATIONS
552
560
553
=over 4
561
=head2 account_credits
554
562
555
=item * L</borrowernumber>
563
Type: has_many
556
564
557
=back
565
Related object: L<Koha::Schema::Result::AccountCredit>
558
566
559
=cut
567
=cut
560
568
561
__PACKAGE__->set_primary_key("borrowernumber");
569
__PACKAGE__->has_many(
562
570
  "account_credits",
563
=head1 UNIQUE CONSTRAINTS
571
  "Koha::Schema::Result::AccountCredit",
564
572
  { "foreign.borrowernumber" => "self.borrowernumber" },
565
=head2 C<cardnumber>
573
  { cascade_copy => 0, cascade_delete => 0 },
574
);
566
575
567
=over 4
576
=head2 account_debits
568
577
569
=item * L</cardnumber>
578
Type: has_many
570
579
571
=back
580
Related object: L<Koha::Schema::Result::AccountDebit>
572
581
573
=cut
582
=cut
574
583
575
__PACKAGE__->add_unique_constraint("cardnumber", ["cardnumber"]);
584
__PACKAGE__->has_many(
576
585
  "account_debits",
577
=head1 RELATIONS
586
  "Koha::Schema::Result::AccountDebit",
587
  { "foreign.borrowernumber" => "self.borrowernumber" },
588
  { cascade_copy => 0, cascade_delete => 0 },
589
);
578
590
579
=head2 accountlines
591
=head2 accountlines
580
592
Lines 696-729 __PACKAGE__->has_many( Link Here
696
  { cascade_copy => 0, cascade_delete => 0 },
708
  { cascade_copy => 0, cascade_delete => 0 },
697
);
709
);
698
710
699
=head2 branchcode
711
=head2 categorycode
700
712
701
Type: belongs_to
713
Type: belongs_to
702
714
703
Related object: L<Koha::Schema::Result::Branch>
715
Related object: L<Koha::Schema::Result::Category>
704
716
705
=cut
717
=cut
706
718
707
__PACKAGE__->belongs_to(
719
__PACKAGE__->belongs_to(
708
  "branchcode",
720
  "categorycode",
709
  "Koha::Schema::Result::Branch",
721
  "Koha::Schema::Result::Category",
710
  { branchcode => "branchcode" },
722
  { categorycode => "categorycode" },
711
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
723
  { on_delete => "CASCADE", on_update => "CASCADE" },
712
);
724
);
713
725
714
=head2 categorycode
726
=head2 branchcode
715
727
716
Type: belongs_to
728
Type: belongs_to
717
729
718
Related object: L<Koha::Schema::Result::Category>
730
Related object: L<Koha::Schema::Result::Branch>
719
731
720
=cut
732
=cut
721
733
722
__PACKAGE__->belongs_to(
734
__PACKAGE__->belongs_to(
723
  "categorycode",
735
  "branchcode",
724
  "Koha::Schema::Result::Category",
736
  "Koha::Schema::Result::Branch",
725
  { categorycode => "categorycode" },
737
  { branchcode => "branchcode" },
726
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
738
  { on_delete => "CASCADE", on_update => "CASCADE" },
727
);
739
);
728
740
729
=head2 course_instructors
741
=head2 course_instructors
Lines 1041-1080 __PACKAGE__->has_many( Link Here
1041
  { cascade_copy => 0, cascade_delete => 0 },
1053
  { cascade_copy => 0, cascade_delete => 0 },
1042
);
1054
);
1043
1055
1044
=head2 basketnoes
1045
1046
Type: many_to_many
1047
1048
Composing rels: L</aqbasketusers> -> basketno
1049
1050
=cut
1051
1052
__PACKAGE__->many_to_many("basketnoes", "aqbasketusers", "basketno");
1053
1054
=head2 budgets
1055
1056
Type: many_to_many
1057
1058
Composing rels: L</aqbudgetborrowers> -> budget
1059
1060
=cut
1061
1062
__PACKAGE__->many_to_many("budgets", "aqbudgetborrowers", "budget");
1063
1064
=head2 courses
1065
1066
Type: many_to_many
1067
1056
1068
Composing rels: L</course_instructors> -> course
1057
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-11-12 08:27:25
1069
1058
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CcXsGi7pVHQtO+YH3pY/1A
1070
=cut
1071
1072
__PACKAGE__->many_to_many("courses", "course_instructors", "course");
1073
1074
1075
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-31 16:31:19
1076
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:z4kW3xYX1CyrwvGdZu32nA
1077
1059
1060
__PACKAGE__->belongs_to(
1061
  "branch",
1062
  "Koha::Schema::Result::Branch",
1063
  { branchcode => "branchcode" },
1064
);
1078
1065
1079
# You can replace this text with custom content, and it will be preserved on regeneration
1066
# You can replace this text with custom content, and it will be preserved on regeneration
1080
1;
1067
1;
(-)a/Koha/Schema/Result/Deleteditem.pm (+11 lines)
Lines 367-372 __PACKAGE__->set_primary_key("itemnumber"); Link Here
367
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
367
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
368
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dfUPy7ijJ/uh9+0AqKjSBw
368
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dfUPy7ijJ/uh9+0AqKjSBw
369
369
370
__PACKAGE__->belongs_to(
371
  "biblio",
372
  "Koha::Schema::Result::Biblio",
373
  { biblionumber => "biblionumber" }
374
);
375
376
__PACKAGE__->belongs_to(
377
  "deleted_biblio",
378
  "Koha::Schema::Result::Deletedbiblio",
379
  { biblionumber => "biblionumber" }
380
);
370
381
371
# You can replace this text with custom content, and it will be preserved on regeneration
382
# You can replace this text with custom content, and it will be preserved on regeneration
372
1;
383
1;
(-)a/Koha/Schema/Result/Issue.pm (-51 / +31 lines)
Lines 1-21 Link Here
1
use utf8;
2
package Koha::Schema::Result::Issue;
1
package Koha::Schema::Result::Issue;
3
2
4
# Created by DBIx::Class::Schema::Loader
3
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
5
7
=head1 NAME
8
9
Koha::Schema::Result::Issue
10
11
=cut
12
13
use strict;
6
use strict;
14
use warnings;
7
use warnings;
15
8
16
use base 'DBIx::Class::Core';
9
use base 'DBIx::Class::Core';
17
10
18
=head1 TABLE: C<issues>
11
12
=head1 NAME
13
14
Koha::Schema::Result::Issue
19
15
20
=cut
16
=cut
21
17
Lines 23-28 __PACKAGE__->table("issues"); Link Here
23
19
24
=head1 ACCESSORS
20
=head1 ACCESSORS
25
21
22
=head2 issue_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
26
=head2 borrowernumber
28
=head2 borrowernumber
27
29
28
  data_type: 'integer'
30
  data_type: 'integer'
Lines 38-44 __PACKAGE__->table("issues"); Link Here
38
=head2 date_due
40
=head2 date_due
39
41
40
  data_type: 'datetime'
42
  data_type: 'datetime'
41
  datetime_undef_if_invalid: 1
42
  is_nullable: 1
43
  is_nullable: 1
43
44
44
=head2 branchcode
45
=head2 branchcode
Lines 56-68 __PACKAGE__->table("issues"); Link Here
56
=head2 returndate
57
=head2 returndate
57
58
58
  data_type: 'datetime'
59
  data_type: 'datetime'
59
  datetime_undef_if_invalid: 1
60
  is_nullable: 1
60
  is_nullable: 1
61
61
62
=head2 lastreneweddate
62
=head2 lastreneweddate
63
63
64
  data_type: 'datetime'
64
  data_type: 'datetime'
65
  datetime_undef_if_invalid: 1
66
  is_nullable: 1
65
  is_nullable: 1
67
66
68
=head2 return
67
=head2 return
Lines 79-141 __PACKAGE__->table("issues"); Link Here
79
=head2 timestamp
78
=head2 timestamp
80
79
81
  data_type: 'timestamp'
80
  data_type: 'timestamp'
82
  datetime_undef_if_invalid: 1
83
  default_value: current_timestamp
81
  default_value: current_timestamp
84
  is_nullable: 0
82
  is_nullable: 0
85
83
86
=head2 issuedate
84
=head2 issuedate
87
85
88
  data_type: 'datetime'
86
  data_type: 'datetime'
89
  datetime_undef_if_invalid: 1
90
  is_nullable: 1
87
  is_nullable: 1
91
88
92
=cut
89
=cut
93
90
94
__PACKAGE__->add_columns(
91
__PACKAGE__->add_columns(
92
  "issue_id",
93
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
95
  "borrowernumber",
94
  "borrowernumber",
96
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
95
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
97
  "itemnumber",
96
  "itemnumber",
98
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
97
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
99
  "date_due",
98
  "date_due",
100
  {
99
  { data_type => "datetime", is_nullable => 1 },
101
    data_type => "datetime",
102
    datetime_undef_if_invalid => 1,
103
    is_nullable => 1,
104
  },
105
  "branchcode",
100
  "branchcode",
106
  { data_type => "varchar", is_nullable => 1, size => 10 },
101
  { data_type => "varchar", is_nullable => 1, size => 10 },
107
  "issuingbranch",
102
  "issuingbranch",
108
  { data_type => "varchar", is_nullable => 1, size => 18 },
103
  { data_type => "varchar", is_nullable => 1, size => 18 },
109
  "returndate",
104
  "returndate",
110
  {
105
  { data_type => "datetime", is_nullable => 1 },
111
    data_type => "datetime",
112
    datetime_undef_if_invalid => 1,
113
    is_nullable => 1,
114
  },
115
  "lastreneweddate",
106
  "lastreneweddate",
116
  {
107
  { data_type => "datetime", is_nullable => 1 },
117
    data_type => "datetime",
118
    datetime_undef_if_invalid => 1,
119
    is_nullable => 1,
120
  },
121
  "return",
108
  "return",
122
  { data_type => "varchar", is_nullable => 1, size => 4 },
109
  { data_type => "varchar", is_nullable => 1, size => 4 },
123
  "renewals",
110
  "renewals",
124
  { data_type => "tinyint", is_nullable => 1 },
111
  { data_type => "tinyint", is_nullable => 1 },
125
  "timestamp",
112
  "timestamp",
126
  {
113
  {
127
    data_type => "timestamp",
114
    data_type     => "timestamp",
128
    datetime_undef_if_invalid => 1,
129
    default_value => \"current_timestamp",
115
    default_value => \"current_timestamp",
130
    is_nullable => 0,
116
    is_nullable   => 0,
131
  },
117
  },
132
  "issuedate",
118
  "issuedate",
133
  {
119
  { data_type => "datetime", is_nullable => 1 },
134
    data_type => "datetime",
135
    datetime_undef_if_invalid => 1,
136
    is_nullable => 1,
137
  },
138
);
120
);
121
__PACKAGE__->set_primary_key("issue_id");
139
122
140
=head1 RELATIONS
123
=head1 RELATIONS
141
124
Lines 151-162 __PACKAGE__->belongs_to( Link Here
151
  "borrowernumber",
134
  "borrowernumber",
152
  "Koha::Schema::Result::Borrower",
135
  "Koha::Schema::Result::Borrower",
153
  { borrowernumber => "borrowernumber" },
136
  { borrowernumber => "borrowernumber" },
154
  {
137
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
155
    is_deferrable => 1,
156
    join_type     => "LEFT",
157
    on_delete     => "CASCADE",
158
    on_update     => "CASCADE",
159
  },
160
);
138
);
161
139
162
=head2 itemnumber
140
=head2 itemnumber
Lines 171-193 __PACKAGE__->belongs_to( Link Here
171
  "itemnumber",
149
  "itemnumber",
172
  "Koha::Schema::Result::Item",
150
  "Koha::Schema::Result::Item",
173
  { itemnumber => "itemnumber" },
151
  { itemnumber => "itemnumber" },
174
  {
152
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
175
    is_deferrable => 1,
176
    join_type     => "LEFT",
177
    on_delete     => "CASCADE",
178
    on_update     => "CASCADE",
179
  },
180
);
153
);
181
154
182
155
183
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
156
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-11-12 09:32:52
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZEh31EKBmURMKxDxI+H3EA
157
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zBewWFig+yZYtSkcIxCZpg
185
158
186
__PACKAGE__->belongs_to(
159
__PACKAGE__->belongs_to(
187
  "borrower",
160
  "borrower",
188
  "Koha::Schema::Result::Borrower",
161
  "Koha::Schema::Result::Borrower",
189
  { borrowernumber => "borrowernumber" },
162
  { borrowernumber => "borrowernumber" },
190
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
163
  { join_type => "LEFT" },
164
);
165
166
__PACKAGE__->belongs_to(
167
  "item",
168
  "Koha::Schema::Result::Item",
169
  { itemnumber => "itemnumber" },
170
  { join_type => "LEFT" },
191
);
171
);
192
172
193
1;
173
1;
(-)a/Koha/Schema/Result/OldIssue.pm (-1 / +27 lines)
Lines 183-188 __PACKAGE__->belongs_to( Link Here
183
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
183
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2013-10-14 20:56:21
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uPOxNROoMMRZ0qZsXsxEjA
184
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uPOxNROoMMRZ0qZsXsxEjA
185
185
186
__PACKAGE__->belongs_to(
187
  "borrower",
188
  "Koha::Schema::Result::Borrower",
189
  { borrowernumber => "borrowernumber" },
190
  { join_type => "LEFT" },
191
);
192
193
__PACKAGE__->belongs_to(
194
  "item",
195
  "Koha::Schema::Result::Item",
196
  { itemnumber => "itemnumber" },
197
  { join_type => "LEFT" },
198
);
199
200
__PACKAGE__->belongs_to(
201
  "deletedborrower",
202
  "Koha::Schema::Result::Deletedborrower",
203
  { borrowernumber => "borrowernumber" },
204
  { join_type => "LEFT" },
205
);
206
207
__PACKAGE__->belongs_to(
208
  "deleteditem",
209
  "Koha::Schema::Result::Deleteditem",
210
  { itemnumber => "itemnumber" },
211
  { join_type => "LEFT" },
212
);
186
213
187
# You can replace this text with custom content, and it will be preserved on regeneration
188
1;
214
1;
(-)a/Koha/Template/Plugin/Currency.pm (+90 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::Currency;
2
3
# Copyright ByWater Solutions 2013
4
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use base qw( Template::Plugin::Filter );
23
24
use Locale::Currency::Format;
25
26
use C4::Context;
27
use Koha::DateUtils;
28
29
sub init {
30
    my $self = shift;
31
    $self->{ _DYNAMIC } = 1;
32
33
    my $active_currency = C4::Context->dbh->selectrow_hashref(
34
        'SELECT * FROM currency WHERE active = 1', {} );
35
    $self->{active_currency} = $active_currency;
36
37
    return $self;
38
}
39
40
sub filter {
41
    my ( $self, $amount, $args, $conf ) = @_;
42
43
    return $self->format( $amount, undef, $conf->{highlight} );
44
}
45
46
sub format {
47
    my ( $self, $amount, $format, $highlight ) = @_;
48
49
    my $is_negative = $amount < 0;
50
    $amount = abs( $amount ) if $highlight;
51
52
    # A negative debit is a credit and visa versa
53
    if ($highlight) {
54
        if ( $highlight eq 'debit' ) {
55
            if ($is_negative) {
56
                $highlight = 'credit';
57
            }
58
        }
59
        elsif ( $highlight eq 'credit' ) {
60
            if ($is_negative) {
61
                $highlight = 'debit';
62
            }
63
64
        }
65
        elsif ( $highlight eq 'offset' ) {
66
            $highlight = $is_negative ? 'credit' : 'debit';
67
        }
68
    }
69
70
    my $formatted = currency_format( $self->{active_currency}->{currency},
71
        $amount, $format || FMT_HTML );
72
73
    $formatted = "<span class='$highlight'>$formatted</span>" if ( $highlight && $amount );
74
75
    return $formatted;
76
}
77
78
sub format_without_symbol {
79
    my ( $self, $amount ) = @_;
80
81
    return substr( $self->format( $amount, FMT_SYMBOL ), 1, 0 );
82
}
83
84
sub symbol {
85
    my ($self) = @_;
86
87
    return currency_symbol( $self->{active_currency}->{'currency'}, SYM_HTML );
88
}
89
90
1;
(-)a/installer/data/mysql/kohastructure.sql (+84 lines)
Lines 265-270 CREATE TABLE `borrowers` ( -- this table includes information about your patrons Link Here
265
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
265
  `altcontactphone` varchar(50) default NULL, -- the phone number for the alternate contact for the patron/borrower
266
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
266
  `smsalertnumber` varchar(50) default NULL, -- the mobile phone number where the patron/borrower would like to receive notices (if SNS turned on)
267
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
267
  `privacy` integer(11) DEFAULT '1' NOT NULL, -- patron/borrower's privacy settings related to their reading history
268
  `account_balance` decimal(28,6) NOT NULL,
268
  UNIQUE KEY `cardnumber` (`cardnumber`),
269
  UNIQUE KEY `cardnumber` (`cardnumber`),
269
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
270
  PRIMARY KEY `borrowernumber` (`borrowernumber`),
270
  KEY `categorycode` (`categorycode`),
271
  KEY `categorycode` (`categorycode`),
Lines 3387-3392 CREATE TABLE IF NOT EXISTS marc_modification_template_actions ( Link Here
3387
  CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3388
  CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3388
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3389
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3389
3390
3391
--
3392
-- Table structure for table 'account_credits'
3393
--
3394
DROP TABLE IF EXISTS account_credits;
3395
CREATE TABLE IF account_credits (
3396
    credit_id int(11) NOT NULL AUTO_INCREMENT,
3397
    borrowernumber int(11) NOT NULL,
3398
    `type` varchar(255) NOT NULL,
3399
    amount_paid decimal(28,6) NOT NULL,
3400
    amount_remaining decimal(28,6) NOT NULL,
3401
    notes text,
3402
    manager_id int(11) DEFAULT NULL,
3403
    created_on timestamp NULL DEFAULT NULL,
3404
    updated_on timestamp NULL DEFAULT NULL,
3405
    PRIMARY KEY (credit_id),
3406
    KEY borrowernumber (borrowernumber)
3407
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3408
3409
--
3410
-- Constraints for table `account_credits`
3411
--
3412
ALTER TABLE `account_credits`
3413
  ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
3414
3415
--
3416
-- Table structure for table 'account_debits'
3417
--
3418
3419
DROP TABLE IF EXISTS account_debits;
3420
CREATE TABLE account_debits (
3421
    debit_id int(11) NOT NULL AUTO_INCREMENT,
3422
    borrowernumber int(11) NOT NULL DEFAULT '0',
3423
    itemnumber int(11) DEFAULT NULL,
3424
    issue_id int(11) DEFAULT NULL,
3425
    `type` varchar(255) NOT NULL,
3426
    accruing tinyint(1) NOT NULL DEFAULT '0',
3427
    amount_original decimal(28,6) DEFAULT NULL,
3428
    amount_outstanding decimal(28,6) DEFAULT NULL,
3429
    amount_last_increment decimal(28,6) DEFAULT NULL,
3430
    description mediumtext,
3431
    notes text,
3432
    manager_id int(11) DEFAULT NULL,
3433
    created_on timestamp NULL DEFAULT NULL,
3434
    updated_on timestamp NULL DEFAULT NULL,
3435
    PRIMARY KEY (debit_id),
3436
    KEY acctsborridx (borrowernumber),
3437
    KEY itemnumber (itemnumber),
3438
    KEY borrowernumber (borrowernumber),
3439
    KEY issue_id (issue_id)
3440
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3441
3442
--
3443
-- Constraints for table `account_debits`
3444
--
3445
ALTER TABLE `account_debits`
3446
    ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
3447
3448
--
3449
-- Table structure for table 'account_offsets'
3450
--
3451
3452
DROP TABLE IF EXISTS account_offsets;
3453
CREATE TABLE account_offsets (
3454
    offset_id int(11) NOT NULL AUTO_INCREMENT,
3455
    debit_id int(11) DEFAULT NULL,
3456
    credit_id int(11) DEFAULT NULL,
3457
    `type` varchar(255) DEFAULT NULL,
3458
    amount decimal(28,6) NOT NULL,
3459
    created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
3460
    PRIMARY KEY (offset_id),
3461
    KEY fee_id (debit_id),
3462
    KEY payment_id (credit_id)
3463
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3464
3465
--
3466
-- Constraints for table `account_offsets`
3467
--
3468
ALTER TABLE `account_offsets`
3469
    ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
3470
    ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
3471
3472
>>>>>>> 0c386fa... Bug 6427 - Rewrite of the accounts system - WIP
3473
3390
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3474
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3391
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3475
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3392
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3476
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+80 lines)
Lines 7259-7264 if ( CheckVersion($DBversion) ) { Link Here
7259
7259
7260
    $dbh->{AutoCommit} = 1;
7260
    $dbh->{AutoCommit} = 1;
7261
    $dbh->{RaiseError} = 0;
7261
    $dbh->{RaiseError} = 0;
7262
   SetVersion ($DBversion);
7262
}
7263
}
7263
7264
7264
$DBversion = "3.13.00.031";
7265
$DBversion = "3.13.00.031";
Lines 7743-7748 if(CheckVersion($DBversion)) { Link Here
7743
    SetVersion($DBversion);
7744
    SetVersion($DBversion);
7744
}
7745
}
7745
7746
7747
$DBversion = "3.15.00.XXX";
7748
if ( CheckVersion($DBversion) ) {
7749
    $dbh->do("ALTER TABLE issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
7750
    $dbh->do("ALTER TABLE old_issues ADD issue_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
7751
    $dbh->do("
7752
        CREATE TABLE IF NOT EXISTS account_credits (
7753
            credit_id int(11) NOT NULL AUTO_INCREMENT,
7754
            borrowernumber int(11) NOT NULL,
7755
            `type` varchar(255) NOT NULL,
7756
            amount_paid decimal(28,6) NOT NULL,
7757
            amount_remaining decimal(28,6) NOT NULL,
7758
            notes text,
7759
            manager_id int(11) DEFAULT NULL,
7760
            created_on timestamp NULL DEFAULT NULL,
7761
            updated_on timestamp NULL DEFAULT NULL,
7762
            PRIMARY KEY (credit_id),
7763
            KEY borrowernumber (borrowernumber)
7764
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7765
    ");
7766
    $dbh->do("
7767
        CREATE TABLE IF NOT EXISTS account_debits (
7768
            debit_id int(11) NOT NULL AUTO_INCREMENT,
7769
            borrowernumber int(11) NOT NULL DEFAULT '0',
7770
            itemnumber int(11) DEFAULT NULL,
7771
            issue_id int(11) DEFAULT NULL,
7772
            `type` varchar(255) NOT NULL,
7773
            accruing tinyint(1) NOT NULL DEFAULT '0',
7774
            amount_original decimal(28,6) DEFAULT NULL,
7775
            amount_outstanding decimal(28,6) DEFAULT NULL,
7776
            amount_last_increment decimal(28,6) DEFAULT NULL,
7777
            description mediumtext,
7778
            notes text,
7779
            manager_id int(11) DEFAULT NULL,
7780
            created_on timestamp NULL DEFAULT NULL,
7781
            updated_on timestamp NULL DEFAULT NULL,
7782
            PRIMARY KEY (debit_id),
7783
            KEY acctsborridx (borrowernumber),
7784
            KEY itemnumber (itemnumber),
7785
            KEY borrowernumber (borrowernumber),
7786
            KEY issue_id (issue_id)
7787
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7788
    ");
7789
7790
    $dbh->do("
7791
        CREATE TABLE account_offsets (
7792
            offset_id int(11) NOT NULL AUTO_INCREMENT,
7793
            debit_id int(11) DEFAULT NULL,
7794
            credit_id int(11) DEFAULT NULL,
7795
            `type` varchar(255) DEFAULT NULL,
7796
            amount decimal(28,6) NOT NULL COMMENT 'A positive number here represents a payment, a negative is a increase in a fine.',
7797
            created_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
7798
            PRIMARY KEY (offset_id),
7799
            KEY fee_id (debit_id),
7800
            KEY payment_id (credit_id)
7801
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7802
    ");
7803
7804
    $dbh->do("
7805
        ALTER TABLE `account_credits`
7806
          ADD CONSTRAINT account_credits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
7807
    ");
7808
    $dbh->do("
7809
        ALTER TABLE `account_debits`
7810
          ADD CONSTRAINT account_debits_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
7811
    ");
7812
    $dbh->do("
7813
        ALTER TABLE `account_offsets`
7814
          ADD CONSTRAINT account_offsets_ibfk_1 FOREIGN KEY (debit_id) REFERENCES account_debits (debit_id) ON DELETE CASCADE ON UPDATE CASCADE,
7815
          ADD CONSTRAINT account_offsets_ibfk_2 FOREIGN KEY (credit_id) REFERENCES account_credits (credit_id) ON DELETE CASCADE ON UPDATE CASCADE;
7816
    ");
7817
7818
    $dbh->do("
7819
        ALTER TABLE borrowers ADD account_balance DECIMAL( 28, 6 ) NOT NULL;
7820
    ");
7821
7822
    print "Upgrade to $DBversion done ( Bug 6427 - Rewrite of the accounts system )\n";
7823
    SetVersion ($DBversion);
7824
}
7825
7746
=head1 FUNCTIONS
7826
=head1 FUNCTIONS
7747
7827
7748
=head2 TableExists($table)
7828
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc (-1 / +1 lines)
Lines 67-73 Link Here
67
        [% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">Details</a></li>
67
        [% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">Details</a></li>
68
    [% END %]
68
    [% END %]
69
    [% IF ( CAN_user_updatecharges ) %]
69
    [% IF ( CAN_user_updatecharges ) %]
70
        [% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Fines</a></li>
70
        [% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Fines</a></li>
71
    [% END %]
71
    [% END %]
72
    [% IF ( RoutingSerials ) %][% IF ( routinglistview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/routing-lists.pl?borrowernumber=[% borrowernumber %]">Routing lists</a></li>[% END %]
72
    [% IF ( RoutingSerials ) %][% IF ( routinglistview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/routing-lists.pl?borrowernumber=[% borrowernumber %]">Routing lists</a></li>[% END %]
73
    [% IF ( intranetreadinghistory ) %]
73
    [% IF ( intranetreadinghistory ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.tt (-1 / +1 lines)
Lines 70-76 in the global namespace %] Link Here
70
	[% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">Details</a></li>
70
	[% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">Details</a></li>
71
	[% END %]
71
	[% END %]
72
	 [% IF ( CAN_user_updatecharges ) %]
72
	 [% IF ( CAN_user_updatecharges ) %]
73
	[% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Fines</a></li>
73
 [% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Fines</a></li>
74
	[% END %]
74
	[% END %]
75
    [% IF ( RoutingSerials ) %][% IF ( routinglistview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/routing-lists.pl?borrowernumber=[% borrower.borrowernumber %]">Routing lists</a></li>[% END %]
75
    [% IF ( RoutingSerials ) %][% IF ( routinglistview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/routing-lists.pl?borrowernumber=[% borrower.borrowernumber %]">Routing lists</a></li>[% END %]
76
    [% IF ( intranetreadinghistory ) %][% IF ( readingrecordview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=[% borrower.borrowernumber %]">Circulation history</a></li>[% END %]
76
    [% IF ( intranetreadinghistory ) %][% IF ( readingrecordview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=[% borrower.borrowernumber %]">Circulation history</a></li>[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/members-menu.inc (-1 / +1 lines)
Lines 4-10 Link Here
4
    [% IF ( circview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% borrowernumber %]">Check out</a></li>
4
    [% IF ( circview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% borrowernumber %]">Check out</a></li>
5
    [% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">Details</a></li>
5
    [% IF ( detailview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrowernumber %]">Details</a></li>
6
    [% IF ( CAN_user_updatecharges ) %]
6
    [% IF ( CAN_user_updatecharges ) %]
7
        [% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Fines</a></li>
7
        [% IF ( finesview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Fines</a></li>
8
    [% END %]
8
    [% END %]
9
    [% IF ( intranetreadinghistory ) %]
9
    [% IF ( intranetreadinghistory ) %]
10
        [% IF ( readingrecordview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=[% borrowernumber %]">Circulation history</a></li>
10
        [% IF ( readingrecordview ) %]<li class="active">[% ELSE %]<li>[% END %]<a href="/cgi-bin/koha/members/readingrec.pl?borrowernumber=[% borrowernumber %]">Circulation history</a></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-3 / +4 lines)
Lines 1-5 Link Here
1
[% USE KohaBranchName %]
1
[% USE KohaBranchName %]
2
[% USE KohaDates %]
2
[% USE KohaDates %]
3
[% USE Currency %]
3
[% IF ( export_remove_fields OR export_with_csv_profile ) %]
4
[% IF ( export_remove_fields OR export_with_csv_profile ) %]
4
   [% SET exports_enabled = 1 %]
5
   [% SET exports_enabled = 1 %]
5
[% END %]
6
[% END %]
Lines 577-592 No patron matched <span class="ex">[% message %]</span> Link Here
577
578
578
        	[% IF ( charges ) %]
579
        	[% IF ( charges ) %]
579
			    <li>
580
			    <li>
580
            <span class="circ-hlt">Fees &amp; Charges:</span> Patron has  <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Outstanding fees &amp; charges[% IF ( chargesamount ) %] of [% chargesamount %][% END %]</a>.
581
            <span class="circ-hlt">Fees &amp; Charges:</span> Patron has  <a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Outstanding fees &amp; charges[% IF ( chargesamount ) %] of [% chargesamount | $Currency %][% END %]</a>.
581
                [% IF ( charges_is_blocker ) %]
582
                [% IF ( charges_is_blocker ) %]
582
                    Checkouts are <span class="circ-hlt">BLOCKED</span> because fine balance is <span class="circ-hlt">OVER THE LIMIT</span>.
583
                    Checkouts are <span class="circ-hlt">BLOCKED</span> because fine balance is <span class="circ-hlt">OVER THE LIMIT</span>.
583
                [% END %]
584
                [% END %]
584
            <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]">Make payment</a></li>
585
            <a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]">Make payment</a></li>
585
			[% END %]
586
			[% END %]
586
587
587
        	[% IF ( credits ) %]
588
        	[% IF ( credits ) %]
588
			<li>
589
			<li>
589
                <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount %][% END %]
590
                <span class="circ-hlt">Credits:</span> Patron has a credit[% IF ( creditsamount ) %] of [% creditsamount | $Currency %][% END %]
590
            </li>
591
            </li>
591
			[% END %]
592
			[% END %]
592
593
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-1 / +1 lines)
Lines 74-80 $(document).ready(function () { Link Here
74
[% IF ( fines ) %]
74
[% IF ( fines ) %]
75
    <div class="dialog alert">
75
    <div class="dialog alert">
76
        <h3>Patron has outstanding fines of [% fines %].</h3>
76
        <h3>Patron has outstanding fines of [% fines %].</h3>
77
        <p><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% fineborrowernumber %]">Make payment</a>.</p>
77
        <p><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% fineborrowernumber %]">Make payment</a>.</p>
78
    </div>
78
    </div>
79
[% END %]
79
[% END %]
80
80
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account.tt (+418 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
[% USE Currency %]
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Patrons &rsaquo; Account for [% INCLUDE 'patron-title.inc' %]</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
7
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/en/css/datatables.css" />
8
<script type="text/javascript" src="[% interface %]/[% theme %]/en/lib/jquery/plugins/jquery.dataTables.min.js"></script>
9
[% INCLUDE 'datatables-strings.inc' %]
10
<script type="text/javascript" src="[% interface %]/[% theme %]/en/js/datatables.js"></script>
11
12
<script type="text/javascript">
13
//<![CDATA[
14
$(document).ready(function() {
15
    $('#account-credits').hide();    
16
    $('#account-debits-switcher').click(function() {
17
         $('#account-debits').slideUp();
18
         $('#account-credits').slideDown();
19
    });
20
    $('#account-credits-switcher').click(function() {
21
         $('#account-credits').slideUp();
22
         $('#account-debits').slideDown();
23
    });
24
25
    var anOpen = [];
26
    var sImageUrl = "[% interface %]/[% theme %]/img/";
27
28
    var debitsTable = $('#debits-table').dataTable( {
29
        "bProcessing": true,
30
        "aoColumns": [
31
            {
32
                "mDataProp": null,
33
                "sClass": "control center",
34
                "sDefaultContent": '<img src="'+sImageUrl+'details_open.png'+'">'
35
            },
36
            { "mDataProp": "debit_id" },
37
            { "mDataProp": "description" },
38
            { "mDataProp": "type" },
39
            { "mDataProp": "amount_original" },
40
            { "mDataProp": "amount_outstanding" },
41
            { "mDataProp": "created_on" },
42
            { "mDataProp": "updated_on" }
43
        ],
44
        "aaData": [
45
            [% FOREACH d IN debits %]
46
                {
47
                    [% PROCESS format_data data=d highlight='debit' %]
48
49
                    // Data for related item if there is one linked
50
                    "title": "[% d.item.biblio.title || d.deleted_item.biblio.title || d.deleted_item.deleted_biblio.title %]",
51
                    "biblionumber": "[% d.item.biblio.biblionumber || d.deleted_item.biblio.biblionumber %]",
52
                    "barcode": "[% d.item.barcode || d.deleted_item.barcode %]",
53
                    "itemnumber": "[% d.item.itemnumber %]", //This way itemnumber will be undef if deleted
54
55
56
                    // Data for related issue if there is one linked
57
                    [% IF d.issue %]
58
                        [% SET table = 'issue' %]
59
                    [% ELSIF d.old_issue %]
60
                        [% SET table = 'old_issue' %]
61
                    [% END %]
62
63
                    [% IF table %]
64
                        "issue": {
65
                            [% PROCESS format_data data=d.$table %]
66
                        },
67
                    [% END %]
68
69
70
                    "account_offsets": [
71
                        [% FOREACH ao IN d.account_offsets %]
72
                            {
73
                                [% PROCESS format_data data=ao highlight='offset'%]
74
75
                                "credit": {
76
                                    [% PROCESS format_data data=ao.credit highlight='credit' %]
77
                                } 
78
                            },
79
                        [% END %]
80
                    ] 
81
82
                },
83
            [% END %]
84
        ] 
85
    } );
86
87
    $('#debits-table td.control').live( 'click', function () {
88
        var nTr = this.parentNode;
89
        var i = $.inArray( nTr, anOpen );
90
91
        if ( i === -1 ) {
92
            $('img', this).attr( 'src', sImageUrl+"details_close.png" );
93
            var nDetailsRow = debitsTable.fnOpen( nTr, fnFormatDebitDetails(debitsTable, nTr), 'details' );
94
            $('div.innerDetails', nDetailsRow).slideDown();
95
            anOpen.push( nTr );
96
        } 
97
        else {
98
            $('img', this).attr( 'src', sImageUrl+"details_open.png" );
99
            $('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
100
                debitsTable.fnClose( nTr );
101
                anOpen.splice( i, 1 );
102
            } );
103
        }
104
    } );
105
106
    var creditsTable = $('#credits-table').dataTable( {
107
        "bProcessing": true,
108
        "aoColumns": [
109
            {
110
                "mDataProp": null,
111
                "sClass": "control center",
112
                "sDefaultContent": '<img src="'+sImageUrl+'details_open.png'+'">'
113
            },
114
            { "mDataProp": "credit_id" },
115
            { "mDataProp": "notes" },
116
            { "mDataProp": "type" },
117
            { "mDataProp": "amount_paid" },
118
            { "mDataProp": "amount_remaining" },
119
            { "mDataProp": "created_on" },
120
            { "mDataProp": "updated_on" }
121
        ],
122
        "aaData": [
123
            [% FOREACH c IN credits %]
124
                {
125
                    [% PROCESS format_data data=c highlight='credit' %]
126
127
                    "account_offsets": [
128
                        [% FOREACH ao IN c.account_offsets %]
129
                            {
130
                                [% PROCESS format_data data=ao highlight='offset' %]
131
132
                                "debit": {
133
                                    [% PROCESS format_data data=ao.debit highlight='debit' %]
134
                                } 
135
                            },
136
                        [% END %]
137
                    ] 
138
139
                },
140
            [% END %]
141
        ] 
142
    } );
143
144
    $('#credits-table td.control').live( 'click', function () {
145
        var nTr = this.parentNode;
146
        var i = $.inArray( nTr, anOpen );
147
148
        if ( i === -1 ) {
149
            $('img', this).attr( 'src', sImageUrl+"details_close.png" );
150
            var nDetailsRow = creditsTable.fnOpen( nTr, fnFormatCreditDetails(creditsTable, nTr), 'details' );
151
            $('div.innerDetails', nDetailsRow).slideDown();
152
            anOpen.push( nTr );
153
        } 
154
        else {
155
            $('img', this).attr( 'src', sImageUrl+"details_open.png" );
156
            $('div.innerDetails', $(nTr).next()[0]).slideUp( function () {
157
                creditsTable.fnClose( nTr );
158
                anOpen.splice( i, 1 );
159
            } );
160
        }
161
    } );
162
163
} );
164
165
function fnFormatDebitDetails( debitsTable, nTr ) {
166
    var oData = debitsTable.fnGetData( nTr );
167
168
    var sOut = '<div class="innerDetails" style="display:none;">';
169
170
    var account_offsets = oData.account_offsets;
171
172
    sOut += '<a class="debit_print btn btn-small" style="margin:5px;" onclick="accountPrint(\'debit\',' + oData.debit_id + ')">' + 
173
                '<i class="icon-print"></i> ' + _('Print receipt') + 
174
            '</a>';
175
176
    sOut += '<ul>';
177
    if ( oData.title ) {
178
        sOut += '<li>' + _('Title: ');
179
        if ( oData.biblionumber ) {
180
            sOut += '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oData.biblionumber + '">';
181
        }
182
183
        sOut += oData.title;
184
185
        if ( oData.biblionumber ) {
186
            sOut += '</a>';
187
        }
188
            
189
        sOut += '</li>';
190
    }
191
192
    if ( oData.barcode ) {
193
        sOut += '<li>' + _('Barcode: ');
194
        if ( oData.itemnumber ) {
195
            sOut += '<a href="/cgi-bin/koha/catalogue/moredetail.pl?itemnumber=11&biblionumber=' + oData.biblionumber + '&bi=' + oData.biblionumber + '#item' + oData.itemnumber + '' + oData.biblionumber + '">';
196
        }
197
198
        sOut += oData.barcode;
199
200
        if ( oData.itemnumber ) {
201
            sOut += '</a>';
202
        }
203
            
204
        sOut += '</li>';
205
    }
206
207
    if ( oData.notes ) {
208
        sOut += '<li>' + _('Notes: ') + oData.notes + '</li>';
209
    }
210
211
    sOut += '</ul>';
212
213
    if ( account_offsets.length ) {
214
        sOut +=
215
            '<div class="innerDetails">' +
216
                '<table cellpadding="5" cellspacing="0" border="0" style="margin:10px;">' +
217
                    '<thead>' +
218
                        '<tr><th colspan="99">' + _('Payments applied') + '</th></tr>' +
219
                        '<tr>' +
220
                            '<th>' + _('ID') + '</th>' +
221
                            '<th>' + _('Created on') + '</th>' +
222
                            '<th>' + _('Payment amount') + '</th>' +
223
                            '<th>' + _('Applied amount') + '</th>' +
224
                            '<th>' + _('Type') + '</th>' +
225
                            '<th>' + _('Notes') + '</th>' +
226
                        '</tr>' +
227
                    '</thead>' +
228
                    '<tbody>';
229
230
        for ( var i = 0; i < account_offsets.length; i++ ) {
231
            ao = account_offsets[i];
232
            sOut +=
233
            '<tr>' +
234
                '<td>' + ao.credit_id + '</td>' +
235
                '<td>' + ao.created_on + '</td>' +
236
                '<td>' + ao.credit.amount_paid + '</td>' +
237
                '<td>' + ao.amount + '</td>' +
238
                '<td>' + ao.credit.type + '</td>' +
239
                '<td>' + ao.credit.notes + '</td>' +
240
            '</tr>';
241
        }
242
243
        sOut +=
244
            '</tbody>'+
245
            '</table>';
246
    }
247
248
    sOut +=
249
        '</div>';
250
251
    return sOut;
252
}
253
254
function fnFormatCreditDetails( creditsTable, nTr ) {
255
    var oData = creditsTable.fnGetData( nTr );
256
257
    var sOut = '<div class="innerDetails" style="display:none;">';
258
259
    sOut += '<button class="credit_print btn btn-small" style="margin:5px;" onclick="accountPrint(\'credit\',' + oData.credit_id + ')">' + 
260
                '<i class="icon-print"></i> ' + _('Print receipt') + 
261
            '</button>';
262
263
    var account_offsets = oData.account_offsets;
264
265
    if ( account_offsets.length ) {
266
        sOut +=
267
                '<table cellpadding="5" cellspacing="0" border="0" style="margin:10px;">' +
268
                    '<thead>' +
269
                        '<tr><th colspan="99">' + _('Fees paid') + '</th></tr>' +
270
                        '<tr>' +
271
                            '<th>' + _('ID') + '</th>' +
272
                            '<th>' + _('Description') + '</th>' +
273
                            '<th>' + _('Type') + '</th>' +
274
                            '<th>' + _('Amount') + '</th>' +
275
                            '<th>' + _('Remaining') + '</th>' +
276
                            '<th>' + _('Created on') + '</th>' +
277
                            '<th>' + _('Updated on') + '</th>' +
278
                            '<th>' + _('Notes') + '</th>' +
279
                        '</tr>' +
280
                    '</thead>' +
281
                    '<tbody>';
282
283
        for ( var i = 0; i < account_offsets.length; i++ ) {
284
            ao = account_offsets[i];
285
            sOut +=
286
            '<tr>' +
287
                '<td>' + ao.debit.debit_id + '</td>' +
288
                '<td>' + ao.debit.description + '</td>' +
289
                '<td>' + ao.debit.type + '</td>' +
290
                '<td>' + ao.debit.amount_original + '</td>' +
291
                '<td>' + ao.debit.amount_outstanding + '</td>' +
292
                '<td>' + ao.debit.created_on + '</td>' +
293
                '<td>' + ao.debit.updated_on + '</td>' +
294
                '<td>' + ao.debit.notes + '</td>' +
295
            '</tr>';
296
        }
297
298
        sOut +=
299
            '</tbody>'+
300
            '</table>';
301
    }
302
303
    sOut +=
304
        '</div>';
305
306
    return sOut;
307
}
308
309
function accountPrint( type, id ) {
310
    window.open( '/cgi-bin/koha/members/account_print.pl?type=' + type + '&id=' + id );
311
}
312
//]]>
313
</script>
314
</head>
315
<body>
316
[% INCLUDE 'header.inc' %]
317
[% INCLUDE 'patron-search.inc' %]
318
319
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Account for [% INCLUDE 'patron-title.inc' %]</div>
320
321
<div id="doc3" class="yui-t2">
322
    <div id="bd">
323
           <div id="yui-main">
324
                <div class="yui-b">
325
                [% INCLUDE 'members-toolbar.inc' %]
326
327
                <div class="statictabs">
328
                    <ul>
329
                        <li class="active">
330
                            <a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a>
331
                        </li>
332
333
                        <li>
334
                            <a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a>
335
                        </li>
336
337
                        <li>
338
                            <a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a>
339
                        </li>
340
341
                        <li>
342
                            <a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a>
343
                        </li>
344
                    </ul>
345
                </div>
346
347
                <div class="tabs-container">
348
349
                    <p>
350
                        <h3>Account balance: [% borrower.account_balance | $Currency %]</h3>
351
                    </p>
352
353
                    <div>
354
                        <div id="account-debits">
355
                            <a id="account-debits-switcher" href="#" onclick="return false">View payments</a>
356
                            <table cellpadding="0" cellspacing="0" border="0" class="display" id="debits-table">
357
                                <thead>
358
                                    <tr>
359
                                        <th colspan="99">Fees</th>
360
                                    </tr>
361
                                    <tr>
362
                                        <th></th>
363
                                        <th>ID</th>
364
                                        <th>Description</th>
365
                                        <th>Type</th>
366
                                        <th>Amount</th>
367
                                        <th>Outsanding</th>
368
                                        <th>Created on</th>
369
                                        <th>Updated on</th>
370
                                    </tr>
371
                                </thead>
372
                                <tbody></tbody>
373
                            </table>
374
                        </div>
375
376
                        <div id="account-credits">
377
                            <a id="account-credits-switcher" href="#"  onclick="return false">View fees</a>
378
                            <table cellpadding="0" cellspacing="0" border="0" class="display" id="credits-table">
379
                                <thead>
380
                                    <tr>
381
                                        <th colspan="99">Payments</th>
382
                                    </tr>
383
                                    <tr>
384
                                        <th></th>
385
                                        <th>ID</th>
386
                                        <th>Notes</th>
387
                                        <th>Type</th>
388
                                        <th>Amount</th>
389
                                        <th>Remaining</th>
390
                                        <th>Created on</th>
391
                                        <th>Updated on</th>
392
                                    </tr>
393
                                </thead>
394
                                <tbody></tbody>
395
                            </table>
396
                        </div>
397
                    </div>
398
                </div>
399
            </div>
400
        </div>
401
402
    <div class="yui-b">
403
        [% INCLUDE 'circ-menu.inc' %]
404
    </div>
405
</div>
406
[% INCLUDE 'intranet-bottom.inc' %]
407
408
[% BLOCK format_data %]
409
    [% FOREACH key IN data.result_source.columns %]
410
        [% IF key.match('^amount') %]
411
            "[% key %]": "[% data.$key FILTER $Currency highlight => highlight %]",
412
        [% ELSIF key.match('_on$') %]
413
            "[% key %]": "[% data.$key | $KohaDates %]",
414
        [% ELSE %]
415
            "[% key %]": "[% data.$key %]",
416
        [% END %]
417
    [% END %]
418
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_credit.tt (+91 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Borrowers &rsaquo; Create manual credit</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
$(document).ready(function(){
7
        $('#account_credit').preventDoubleFormSubmit();
8
        $("fieldset.rows input").addClass("noEnterSubmit");
9
});
10
//]]>
11
</script>
12
</head>
13
<body id="pat_account_credit" class="pat">
14
    [% INCLUDE 'header.inc' %]
15
    [% INCLUDE 'patron-search.inc' %]
16
17
    <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Manual credit</div>
18
19
    <div id="doc3" class="yui-t2">
20
        <div id="bd">
21
               <div id="yui-main">
22
            <div class="yui-b">
23
                    [% INCLUDE 'members-toolbar.inc' %]
24
25
                    <div class="statictabs">
26
                        <ul>
27
                            <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
28
                            <li><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
29
                            <li><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
30
                            <li class="active"><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
31
                        </ul>
32
33
                        <div class="tabs-container">
34
35
                            <form action="/cgi-bin/koha/members/account_credit_do.pl" method="post" id="account_credit">
36
                                <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
37
38
                                <fieldset class="rows">
39
                                    <legend>Manual credit</legend>
40
41
                                    <ol>
42
                                        <li>
43
                                            <label for="type">Credit Type: </label>
44
                                            <select name="type" id="type">
45
                                                <option value="CREDIT">Credit</option>
46
                                                <option value="FORGIVEN">Forgiven</option>
47
                                                [% FOREACH c IN credit_types_loop %]
48
                                                    <option value="[% c.authorised_value %]">[% c.lib %]</option>
49
                                                [% END %]
50
                                            </select>
51
                                        </li>
52
53
                                        <li>
54
                                            <label for="barcode">Barcode: </label>
55
                                            <input type="text" name="barcode" id="barcode" />
56
                                        </li>
57
58
                                        <li>
59
                                            <label for="desc">Description: </label>
60
                                            <input type="text" name="desc" size="50" id="desc" />
61
                                        </li>
62
63
                                        <li>
64
                                            <label for="note">Note: </label>
65
                                            <input type="text" name="note" size="50" id="note" />
66
                                        </li>
67
68
                                        <li>
69
                                            <label for="amount">Amount: </label>
70
                                            <input type="text" name="amount" id="amount" />
71
                                            Example: 5.00
72
                                        </li>
73
                                    </ol>
74
75
                                </fieldset>
76
77
                                <fieldset class="action">
78
                                    <input type="submit" name="add" value="Add credit" />
79
                                    <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Cancel</a>
80
                                </fieldset>
81
                            </form>
82
83
                        </div>
84
                    </div>
85
                </div>
86
            </div>
87
        <div class="yui-b">
88
            [% INCLUDE 'circ-menu.inc' %]
89
        </div>
90
    </div>
91
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_debit.tt (+108 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Borrowers &rsaquo; Create manual invoice</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript">
5
//<![CDATA[
6
$(document).ready(function(){
7
    $('#maninvoice').preventDoubleFormSubmit();
8
    $("fieldset.rows input").addClass("noEnterSubmit");
9
10
    var type_fees = new Array();
11
    type_fees['L'] = '';
12
    type_fees['F'] = '';
13
    type_fees['A'] = '';
14
    type_fees['N'] = '';
15
    type_fees['M'] = '';
16
    [% FOREACH invoice_types_loo IN invoice_types_loop %]
17
        type_fees['[% invoice_types_loo.authorised_value %]'] = "[% invoice_types_loo.lib %]";
18
    [% END %]
19
});
20
//]]>
21
</script>
22
</head>
23
24
<body>
25
    [% INCLUDE 'header.inc' %]
26
    [% INCLUDE 'patron-search.inc' %]
27
28
    <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Manual invoice</div>
29
30
    <div id="doc3" class="yui-t2">
31
        <div id="bd">
32
            <div id="yui-main">
33
                <div class="yui-b">
34
                    [% INCLUDE 'members-toolbar.inc' %]
35
36
                    <div class="statictabs">
37
                    <ul>
38
                        <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
39
                        <li><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
40
                        <li class="active"><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
41
                        <li><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
42
                    </ul>
43
                    <div class="tabs-container">
44
45
                    <form action="/cgi-bin/koha/members/account_debit_do.pl" method="post" id="account_debit">
46
                        <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
47
48
                        <fieldset class="rows">
49
                            <legend>Manual Invoice</legend>
50
51
                            <ol>
52
                                <li>
53
                                    <label for="type">Type: </label>
54
                                    <select name="type" id="type">
55
                                        <option value="LOST">Lost item</option>
56
                                        <option value="FINE">Fine</option>
57
                                        <option value="ACCOUNT_MANAGEMENT_FEE">Account management fee</option>
58
                                        <option value="NEW_CARD">New card</option>
59
                                        <option value="SUNDRY">Sundry</option>
60
61
                                        [% FOREACH invoice_types_loo IN invoice_types_loop %]
62
                                            <option value="[% invoice_types_loo.authorised_value %]">[% invoice_types_loo.lib %]</option>
63
                                        [% END %]
64
                                    </select>
65
                                </li>
66
67
                                <!-- TODO: Write ajax barcode validator that appends the itemnumber for this form in a hidden input -->
68
                                 <li>
69
                                    <label for="barcode">Barcode: </label>
70
                                    <input type="text" name="barcode" id="barcode" />
71
                                </li>
72
73
                                <li>
74
                                    <label for="description">Description: </label>
75
                                    <input type="text" name="description" id="description" size="50" />
76
                                </li>
77
78
                                <li>
79
                                    <label for="notes">Notes: </label>
80
                                    <input type="text" name="notes" size="50" id="notes" />
81
                                </li>
82
83
                                <li>
84
                                    <label for="amount">Amount: </label>
85
                                    <input type="text" name="amount" id="amount" /> Example: 5.00
86
                                </li>
87
88
                            </ol>
89
                        </fieldset>
90
91
                        <fieldset class="action">
92
                            <input type="submit" name="add" value="Save" />
93
                            <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Cancel</a>
94
                        </fieldset>
95
96
                    </form>
97
98
                </div>
99
            </div>
100
        </div>
101
    </div>
102
103
<div class="yui-b">
104
  [% INCLUDE 'circ-menu.inc' %]
105
</div>
106
107
</div>
108
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_payment.tt (+200 lines)
Line 0 Link Here
1
[% USE Currency %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  [% borrower.firstname %] [% borrower.surname %]</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
6
<script type= "text/javascript">
7
//<![CDATA[
8
$( document ).ready(function() {
9
    // Show amount recieved only if the "Receive different amount" checkbox is checked
10
    $("#amount-received-p").hide();
11
    $('#receive_different_amount').click(function() {
12
        if( $(this).is(':checked')) {
13
            $("#amount-received-p").show();
14
        } else {
15
            $("#amount-received-p").hide();
16
        }
17
    });
18
19
    // Enable the "Select all/Clear all" links
20
    $('#CheckAll').click(function() {
21
        $("input[name='debit_id']" ).prop('checked', true);
22
    });
23
    $('#ClearAll').click(function() {
24
        $("input[name='debit_id']" ).prop('checked', false);
25
    });
26
27
    // Update the "amount to pay" field whenever a fee checkbox is changed
28
    // Note, this is just a payment suggestion and can be changed to any amount
29
    $("input[name='debit_id']" ).change(function() {
30
        var sum = 0;
31
        $("input[name='debit_id']:checked" ).each(function(i,n){
32
            sum += parseFloat( $( "#amount_outstanding_" + $(this).val() ).val() );
33
        });
34
        $('#amount_to_pay').val( sum );
35
    });
36
});
37
38
function checkForm(){
39
    // If using the "amount to receive" field, make sure the librarian is recieving at
40
    // least enough to pay those fees.
41
    if ( $('#amount_to_receive').val() ) {
42
        if ( parseFloat( $('#amount_to_receive').val() ) < parseFloat( $('#amount_to_pay').val() ) ) {
43
            alert( _("Cannot pay more than receieved!") );
44
            return false;
45
        }
46
    }
47
48
    return true;
49
}
50
//]]>
51
</script>
52
</head>
53
<body id="pat_pay" class="pat">
54
    [% INCLUDE 'header.inc' %]
55
    [% INCLUDE 'patron-search.inc' %]
56
57
    <div id="breadcrumbs">
58
        <a href="/cgi-bin/koha/mainpage.pl">Home</a>
59
        &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
60
        &rsaquo; Pay fines for [% borrower.firstname %] [% borrower.surname %]
61
    </div>
62
63
    <div id="doc3" class="yui-t2">
64
        <div id="bd">
65
            <div id="yui-main">
66
                <div class="yui-b">
67
                    [% INCLUDE 'members-toolbar.inc' borrowernumber=borrower.borrowernumber %]
68
69
                    <div class="statictabs">
70
                        <ul>
71
                            <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a></li>
72
                            <li class="active"><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a></li>
73
                            <li><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual invoice</a></li>
74
                            <li><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual credit</a></li>
75
                        </ul>
76
77
                        <div class="tabs-container">
78
79
                        [% IF ( debits ) %]
80
                            <form action="/cgi-bin/koha/members/account_payment_do.pl" method="post" id="account-payment-form" onsubmit="return checkForm()">
81
82
                                <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
83
84
                                <p>
85
                                    <span class="checkall">
86
                                        <a id="CheckAll" href="#">Select all</a>
87
                                    </span>
88
89
                                    |
90
91
                                    <span class="clearall">
92
                                        <a id="ClearAll" href="#">Clear all</a>
93
                                    </span>
94
                                </p>
95
96
                                <table id="finest">
97
                                    <thead>
98
                                        <tr>
99
                                            <th>&nbsp;</th>
100
                                            <th>Description</th>
101
                                            <th>Account type</th>
102
                                            <th>Original amount</th>
103
                                            <th>Amount outstanding</th>
104
                                        </tr>
105
                                    </thead>
106
107
                                    <tbody>
108
                                        [% SET total_due = 0 %]
109
                                        [% FOREACH d IN debits %]
110
                                            [% SET total_due = total_due + d.amount_outstanding %]
111
                                            <tr>
112
                                                <td>
113
                                                    <input type="checkbox" checked="checked" name="debit_id" value="[% d.debit_id %]" />
114
                                                </td>
115
116
                                                <td>
117
                                                    [% d.description %]
118
119
                                                    [% IF d.notes %]
120
                                                        ( <i>[% d.notes %]</i> )
121
                                                    [% END %]
122
                                                </td>
123
124
                                                <td>
125
                                                    [% d.type %]
126
                                                </td>
127
128
                                                <td class="debit">
129
                                                    [% d.amount_original | $Currency %]
130
                                                    <input type="hidden" id="amount_original_[% d.debit_id %]" value="[% Currency.format_without_symbol( d.amount_original ) %]" />
131
                                                </td>
132
133
                                                <td class="debit">
134
                                                    [% d.amount_outstanding | $Currency %]
135
                                                    <input type="hidden" id="amount_outstanding_[% d.debit_id %]" value="[% Currency.format_without_symbol( d.amount_outstanding ) %]" />
136
                                                </td>
137
                                            </tr>
138
                                        [% END %]
139
                                    </tbody>
140
141
                                    <tfoot>
142
                                        <tr>
143
                                            <td class="total" colspan="4">Total Due:</td>
144
                                            <td>[% total_due | $Currency %]</td>
145
                                        </tr>
146
                                    </tfoot>
147
148
                                </table>
149
150
                                <fieldset>
151
                                    <p>
152
                                        <label for="amount_to_pay">Amount to pay: [% Currency.symbol() %]</label>
153
                                        <input type="text" name="amount_to_pay" id="amount_to_pay" value="[% Currency.format_without_symbol( total_due ) %]" />
154
155
                                        <input type="checkbox" id="receive_different_amount" />
156
                                        <label for="receive_different_amount"><i>Receive different amount</i></label>
157
                                    </p>
158
159
                                    <p id="amount-received-p">
160
                                        <label for="amount_to_receive">Amount recieved: [% Currency.symbol() %]</label>
161
                                        <input type="text" name="amount_to_receive" id="amount_to_receive" />
162
                                    </p>
163
164
                                    <p>
165
                                        <label for="type">Type:</label>
166
                                        <select id="type" name="type">
167
                                            <option value="PAYMENT">Payment</option>
168
                                            <option value="WRITEOFF">Write-off</option>
169
                                        </select>
170
                                    </p>
171
172
                                    <p>
173
                                        <label for="notes">Payment notes:</label>
174
                                        <input type="textbox" name="notes" id="notes" />
175
                                    <p>
176
                                </fieldset>
177
178
                                <fieldset class="action">
179
                                    <input type="submit" value="Process" class="submit" />
180
                                    <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
181
                                </fieldset>
182
183
                            </form>
184
185
                        [% ELSE %]
186
                            <p>
187
                                [% borrower.firstname %] [% borrower.surname %] has no outstanding fines.
188
                            </p>
189
                        [% END %]
190
191
                    </div>
192
                </div>
193
            </div>
194
        </div>
195
196
        <div class="yui-b">
197
            [% INCLUDE 'circ-menu.tt' %]
198
        </div>
199
    </div>
200
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/account_print.tt (+136 lines)
Line 0 Link Here
1
[% USE KohaDates %]
2
[% USE Currency %]
3
[% USE EncodeUTF8 %]
4
[% INCLUDE 'doc-head-open.inc' %]
5
<title>Print Receipt for [% cardnumber %]</title>
6
[% INCLUDE 'doc-head-close.inc' %]
7
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
<link rel="shortcut icon" href="[% IF ( IntranetFavicon ) %][% IntranetFavicon %][% ELSE %][% interface %]/[% theme %]/img/favicon.ico[% END %]" type="image/x-icon" />
9
<script type="text/javascript">
10
    function printThenClose() {
11
        window.print();
12
        window.close();
13
    }
14
</script>
15
</head>
16
17
[% SET account = debit || credit %]
18
[% SET borrower = account.borrower %]
19
20
<body id="account-print-body" onload="printThenClose();">
21
22
    <table>
23
        <thead>
24
            <tr>
25
                <th colspan="99">
26
                    [% IF debit %]
27
                        Invoice
28
                    [% ELSIF credit %]
29
                        Payment receipt
30
                    [% END %]
31
                </th>
32
            </tr>
33
            
34
            <tr>
35
                <th colspan="99">
36
                    [% borrower.branch.branchname | $EncodeUTF8 %]
37
                </th>
38
            </tr>
39
40
            <tr>
41
                <th>Name:</th>
42
                <th colspan="99">[% borrower.firstname | $EncodeUTF8 %] [% borrower.surname | $EncodeUTF8 %]</th>
43
            </tr>
44
45
            <tr>
46
                <th>Card number:</th>
47
                <th colspan="99">[% borrower.cardnumber %]</th>
48
            </tr>
49
50
            <tr>
51
                <th>Date:</th>
52
                <th colspan="99">[% account.created_on | $KohaDates %]</th>
53
            </tr>
54
55
            [% IF account.description %]
56
                <tr>
57
                    <th>Description:</th>
58
                    <th colspan="99">[% account.description | $EncodeUTF8 %]</th>
59
                </tr>
60
            [% END %]
61
62
            [% IF credit %]
63
                <tr>
64
                    <th>Amount:</th>
65
                    <th colspan="99">[% credit.amount_paid | $Currency highlight => type %]</th>
66
                </tr>
67
                <tr>
68
                    <th>Balance:</th>
69
                    <th colspan="99">[% credit.amount_remaining | $Currency highlight => type %]</th>
70
                </tr>
71
                [% IF credit.account_offsets %]
72
                    <tr>
73
                        <th colspan="99">Fees paid</th>
74
                    </tr>
75
                    <tr>
76
                        <th>Description</th>
77
                        <th>Type</th>
78
                        <th>Amount</th>
79
                        <th>Paid</th>
80
                        <th>Outstanding</th>
81
                        <th>Date</th>
82
                    </tr>
83
                [% END %]
84
            [% ELSIF debit %]
85
                <tr>
86
                    <th>Amount:</th>
87
                    <th colspan="99">[% debit.amount_original | $Currency highlight => type %]</th>
88
                </tr>
89
                <tr>
90
                    <th>Outstanding:</th>
91
                    <th colspan="99">[% debit.amount_outstanding | $Currency highlight => type %]</th>
92
                </tr>
93
                [% IF debit.account_offsets %]
94
                    <tr>
95
                        <th colspan="99">Payments applied</th>
96
                    </tr>
97
                    <tr>
98
                        <th>Date</th>
99
                        <th>Type</th>
100
                        <th>Payment</th>
101
                        <th>Applied</th>
102
                        <th>Balance</th>
103
                        <th>Notes</th>
104
                    </tr>
105
                [% END %]
106
            [% END %]
107
        </thead>
108
109
        <tbody>
110
            [% IF credit.account_offsets %]
111
                [% FOREACH ao IN credit.account_offsets %]
112
                    <tr>
113
                        <td>[% ao.debit.description %]</td>
114
                        <td>[% ao.debit.type %]</td>
115
                        <td>[% ao.debit.amount_original | $Currency highlight => 'debit' %]</td>
116
                        <td>[% ao.amount | $Currency highlight => 'offset' %]</td>
117
                        <td>[% ao.debit.amount_outstanding | $Currency highlight => 'debit' %]</td>
118
                        <td>[% ao.debit.created_on | $KohaDates %]</td>
119
                    </tr>
120
                [% END %]
121
            [% ELSIF debit.account_offsets %]
122
                [% FOREACH ao IN debit.account_offsets %]
123
                    <tr>
124
                        <td>[% ao.credit.type %]</td>
125
                        <td>[% ao.credit.created_on | $KohaDates %]</td>
126
                        <td>[% ao.credit.amount_paid | $Currency highlight => 'credit' %]</td>
127
                        <td>[% ao.amount | $Currency highlight => 'offset' %]</td>
128
                        <td>[% ao.credit.amount_remaining | $Currency highlight => 'credit' %]</td>
129
                        <td>[% ao.credit.notes %]</td>
130
                    </tr>
131
                [% END %]
132
            [% END %]
133
        </tbody>
134
    </table>
135
136
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tt (-6 / +6 lines)
Lines 14-28 Link Here
14
	<div id="yui-main">
14
	<div id="yui-main">
15
	<div class="yui-b">
15
	<div class="yui-b">
16
[% INCLUDE 'members-toolbar.inc' %]
16
[% INCLUDE 'members-toolbar.inc' %]
17
<form action="/cgi-bin/koha/members/boraccount.pl" method="get"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" /></form>
17
<form action="/cgi-bin/koha/members/account.pl" method="get"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" /></form>
18
18
19
<!-- The manual invoice and credit buttons -->
19
<!-- The manual invoice and credit buttons -->
20
<div class="statictabs">
20
<div class="statictabs">
21
<ul>
21
<ul>
22
    <li class="active"><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
22
    <li class="active"><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
23
	<li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
23
  <li><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
24
	<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
24
 <li><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
25
	<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
25
       <li><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
26
</ul>
26
</ul>
27
<div class="tabs-container">
27
<div class="tabs-container">
28
<!-- The table with the account items -->
28
<!-- The table with the account items -->
Lines 51-57 Link Here
51
    [% IF ( reverse_col ) %]
51
    [% IF ( reverse_col ) %]
52
      <td>
52
      <td>
53
	[% IF ( account.payment ) %]
53
	[% IF ( account.payment ) %]
54
		<a href="boraccount.pl?action=reverse&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]">Reverse</a>
54
          <a href="account.pl?action=reverse&amp;accountlines_id=[% account.accountlines_id %]&amp;borrowernumber=[% account.borrowernumber %]">Reverse</a>
55
	[% ELSE %]
55
	[% ELSE %]
56
		&nbsp;
56
		&nbsp;
57
	[% END %]
57
	[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt (-6 / +6 lines)
Lines 26-39 $(document).ready(function(){ Link Here
26
<!-- The manual invoice and credit buttons -->
26
<!-- The manual invoice and credit buttons -->
27
<div class="statictabs">
27
<div class="statictabs">
28
<ul>
28
<ul>
29
	<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
29
   <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
30
	<li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
30
    <li><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
31
	<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
31
 <li><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
32
    <li class="active"><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
32
    <li class="active"><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
33
</ul>
33
</ul>
34
<div class="tabs-container">
34
<div class="tabs-container">
35
35
36
<form action="/cgi-bin/koha/members/mancredit.pl" method="post" id="mancredit">
36
<form action="/cgi-bin/koha/members/account_credit.pl" method="post" id="mancredit">
37
<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
37
<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
38
38
39
<fieldset class="rows">
39
<fieldset class="rows">
Lines 48-54 $(document).ready(function(){ Link Here
48
	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
48
	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
49
</ol></fieldset>
49
</ol></fieldset>
50
50
51
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset>
51
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset>
52
</form>
52
</form>
53
53
54
</div></div>
54
</div></div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-6 / +6 lines)
Lines 26-35 $(document).ready(function(){ Link Here
26
<!-- The manual invoice and credit buttons -->
26
<!-- The manual invoice and credit buttons -->
27
<div class="statictabs">
27
<div class="statictabs">
28
<ul>
28
<ul>
29
	<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
29
   <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Account</a></li>
30
	<li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
30
    <li><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrowernumber %]" >Pay fines</a></li>
31
    <li class="active"><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
31
    <li class="active"><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrowernumber %]" >Create manual invoice</a></li>
32
	<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
32
     <li><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrowernumber %]" >Create manual credit</a></li>
33
</ul>
33
</ul>
34
<div class="tabs-container">
34
<div class="tabs-container">
35
35
Lines 38-44 $(document).ready(function(){ Link Here
38
  ERROR an invalid itemnumber was entered, please hit back and try again
38
  ERROR an invalid itemnumber was entered, please hit back and try again
39
[% END %]
39
[% END %]
40
[% ELSE %]
40
[% ELSE %]
41
<form action="/cgi-bin/koha/members/maninvoice.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
41
<form action="/cgi-bin/koha/members/account_debit.pl" method="post" id="maninvoice"><input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrowernumber %]" />
42
	<fieldset class="rows">
42
	<fieldset class="rows">
43
	<legend>Manual Invoice</legend>
43
	<legend>Manual Invoice</legend>
44
	<ol>
44
	<ol>
Lines 71-77 type_fees['[% invoice_types_loo.authorised_value %]'] = "[% invoice_types_loo.li Link Here
71
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
71
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
72
	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
72
	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
73
	</ol></fieldset>
73
	</ol></fieldset>
74
<fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset>
74
<fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset>
75
</form>
75
</form>
76
76
77
[% END %]
77
[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt (-6 / +6 lines)
Lines 55-69 function enableCheckboxActions(){ Link Here
55
<!-- The manual invoice and credit buttons -->
55
<!-- The manual invoice and credit buttons -->
56
<div class="statictabs">
56
<div class="statictabs">
57
<ul>
57
<ul>
58
	<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a></li>
58
   <li><a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a></li>
59
    <li class="active"><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a></li>
59
    <li class="active"><a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a></li>
60
	<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual invoice</a></li>
60
        <li><a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual invoice</a></li>
61
	<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual credit</a></li>
61
      <li><a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual credit</a></li>
62
</ul>
62
</ul>
63
<div class="tabs-container">
63
<div class="tabs-container">
64
64
65
[% IF ( accounts ) %]
65
[% IF ( accounts ) %]
66
    <form action="/cgi-bin/koha/members/pay.pl" method="post" id="pay-fines-form">
66
    <form action="/cgi-bin/koha/members/account_payment.pl" method="post" id="pay-fines-form">
67
	<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
67
	<input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
68
<p><span class="checkall"><a id="CheckAll" href="#">Select all</a></span> | <span class="clearall"><a id="CheckNone" href="#">Clear all</a></span></p>
68
<p><span class="checkall"><a id="CheckAll" href="#">Select all</a></span> | <span class="clearall"><a id="CheckNone" href="#">Clear all</a></span></p>
69
<table id="finest">
69
<table id="finest">
Lines 135-141 function enableCheckboxActions(){ Link Here
135
<input type="submit" id="paycollect" name="paycollect"  value="Pay amount" class="submit" />
135
<input type="submit" id="paycollect" name="paycollect"  value="Pay amount" class="submit" />
136
<input type="submit" name="woall"  id="woall" value="Write off all" class="submit" />
136
<input type="submit" name="woall"  id="woall" value="Write off all" class="submit" />
137
<input type="submit" id="payselected" name="payselected"  value="Pay selected" class="submit" />
137
<input type="submit" id="payselected" name="payselected"  value="Pay selected" class="submit" />
138
<a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
138
<a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a>
139
</fieldset>
139
</fieldset>
140
</form>
140
</form>
141
[% ELSE %]
141
[% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (-9 / +9 lines)
Lines 64-70 function moneyFormat(textObj) { Link Here
64
<body id="pat_paycollect" class="pat">
64
<body id="pat_paycollect" class="pat">
65
[% INCLUDE 'header.inc' %]
65
[% INCLUDE 'header.inc' %]
66
[% INCLUDE 'patron-search.inc' %]
66
[% INCLUDE 'patron-search.inc' %]
67
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]">Pay fines for [% borrower.firstname %] [% borrower.surname %]</a> &rsaquo; [% IF ( pay_individual ) %]Pay an individual fine[% ELSIF ( writeoff_individual ) %]Write off an individual fine[% ELSE %][% IF ( selected_accts ) %]Pay an amount toward selected fines[% ELSE %]Pay an amount toward all fines[% END %][% END %]</div>
67
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; <a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]">Pay fines for [% borrower.firstname %] [% borrower.surname %]</a> &rsaquo; [% IF ( pay_individual ) %]Pay an individual fine[% ELSIF ( writeoff_individual ) %]Write off an individual fine[% ELSE %][% IF ( selected_accts ) %]Pay an amount toward selected fines[% ELSE %]Pay an amount toward all fines[% END %][% END %]</div>
68
68
69
<div id="doc3" class="yui-t2">
69
<div id="doc3" class="yui-t2">
70
70
Lines 78-93 function moneyFormat(textObj) { Link Here
78
<div class="statictabs">
78
<div class="statictabs">
79
<ul>
79
<ul>
80
    <li>
80
    <li>
81
    <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a>
81
    <a href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Account</a>
82
    </li>
82
    </li>
83
    <li class="active">
83
    <li class="active">
84
    <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a>
84
    <a href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]" >Pay fines</a>
85
    </li>
85
    </li>
86
    <li>
86
    <li>
87
    <a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual invoice</a>
87
    <a href="/cgi-bin/koha/members/account_debit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual invoice</a>
88
    </li>
88
    </li>
89
    <li>
89
    <li>
90
    <a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual credit</a>
90
    <a href="/cgi-bin/koha/members/account_credit.pl?borrowernumber=[% borrower.borrowernumber %]" >Create manual credit</a>
91
    </li>
91
    </li>
92
</ul>
92
</ul>
93
<div class="tabs-container">
93
<div class="tabs-container">
Lines 150-159 function moneyFormat(textObj) { Link Here
150
</fieldset>
150
</fieldset>
151
151
152
    <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
152
    <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
153
        <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
153
        <a class="cancel" href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
154
    </form>
154
    </form>
155
[% ELSIF ( writeoff_individual ) %]
155
[% ELSIF ( writeoff_individual ) %]
156
    <form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
156
    <form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/account_payment.pl" method="post" >
157
    <fieldset class="rows">
157
    <fieldset class="rows">
158
    <legend>Write off an individual fine</legend>
158
    <legend>Write off an individual fine</legend>
159
    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
159
    <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% borrower.borrowernumber %]" />
Lines 190-196 function moneyFormat(textObj) { Link Here
190
    </table>
190
    </table>
191
    </fieldset>
191
    </fieldset>
192
    <div class="action"><input type="submit" name="confirm_writeoff" id="confirm_writeoff" value="Write off this charge" />
192
    <div class="action"><input type="submit" name="confirm_writeoff" id="confirm_writeoff" value="Write off this charge" />
193
        <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
193
        <a class="cancel" href="/cgi-bin/koha/members/account_payment.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
194
    </form>
194
    </form>
195
[% ELSE %]
195
[% ELSE %]
196
196
Lines 218-224 function moneyFormat(textObj) { Link Here
218
    </ol>
218
    </ol>
219
    </fieldset>
219
    </fieldset>
220
    <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
220
    <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
221
        <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
221
        <a class="cancel" href="/cgi-bin/koha/members/account.pl?borrowernumber=[% borrower.borrowernumber %]">Cancel</a></div>
222
    </form>
222
    </form>
223
[% END %]
223
[% END %]
224
</div></div>
224
</div></div>
(-)a/members/account.pl (+113 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2013 ByWater Solutions
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 2 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
use Modern::Perl;
22
23
use CGI;
24
25
use C4::Auth;
26
use C4::Output;
27
use C4::Dates qw/format_date/;
28
use C4::Members;
29
use C4::Branch;
30
use C4::Accounts;
31
use C4::Members::Attributes qw(GetBorrowerAttributes);
32
use Koha::Database;
33
34
my $cgi = new CGI;
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name   => "members/account.tt",
39
        query           => $cgi,
40
        type            => "intranet",
41
        authnotrequired => 0,
42
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
43
        debug           => 1,
44
    }
45
);
46
47
my $borrowernumber = $cgi->param('borrowernumber');
48
49
my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
50
51
my @debits = Koha::Database->new()->schema->resultset('AccountDebit')->search(
52
    { 'me.borrowernumber' => $borrowernumber },
53
    { prefetch            => { account_offsets => 'credit' } }
54
);
55
56
my @credits = Koha::Database->new()->schema->resultset('AccountCredit')->search(
57
    { 'me.borrowernumber' => $borrowernumber },
58
    { prefetch            => { account_offsets => 'debit' } }
59
);
60
61
$template->param(
62
    debits   => \@debits,
63
    credits  => \@credits,
64
    borrower => $borrower,
65
);
66
67
# Standard /members/ borrower details data
68
## FIXME: This code is in every /members/ script and should be unified
69
70
if ( $borrower->{'category_type'} eq 'C' ) {
71
    my ( $catcodes, $labels ) =
72
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
73
    my $cnt = scalar(@$catcodes);
74
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
75
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
76
}
77
78
my ( $picture, $dberror ) = GetPatronImage( $borrower->{'borrowernumber'} );
79
$template->param( picture => 1 ) if $picture;
80
81
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
82
    my $attributes = GetBorrowerAttributes($borrowernumber);
83
    $template->param(
84
        ExtendedPatronAttributes => 1,
85
        extendedattributes       => $attributes
86
    );
87
}
88
89
$template->param(
90
    borrowernumber => $borrowernumber,
91
    firstname      => $borrower->{'firstname'},
92
    surname        => $borrower->{'surname'},
93
    cardnumber     => $borrower->{'cardnumber'},
94
    categorycode   => $borrower->{'categorycode'},
95
    category_type  => $borrower->{'category_type'},
96
    categoryname   => $borrower->{'description'},
97
    address        => $borrower->{'address'},
98
    address2       => $borrower->{'address2'},
99
    city           => $borrower->{'city'},
100
    state          => $borrower->{'state'},
101
    zipcode        => $borrower->{'zipcode'},
102
    country        => $borrower->{'country'},
103
    phone          => $borrower->{'phone'},
104
    email          => $borrower->{'email'},
105
    branchcode     => $borrower->{'branchcode'},
106
    branchname     => GetBranchName( $borrower->{'branchcode'} ),
107
    is_child       => ( $borrower->{'category_type'} eq 'C' ),
108
    activeBorrowerRelationship =>
109
      ( C4::Context->preference('borrowerRelationship') ne '' ),
110
    RoutingSerials => C4::Context->preference('RoutingSerials'),
111
);
112
113
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/members/account_credit.pl (+104 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
#written 11/1/2000 by chris@katipo.oc.nz
4
#script to display borrowers account details
5
6
# Copyright 2000-2002 Katipo Communications
7
# Copyright 2010 BibLibre
8
#
9
# This file is part of Koha.
10
#
11
# Koha is free software; you can redistribute it and/or modify it under the
12
# terms of the GNU General Public License as published by the Free Software
13
# Foundation; either version 2 of the License, or (at your option) any later
14
# version.
15
#
16
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License along
21
# with Koha; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
use strict;
25
use warnings;
26
27
use C4::Auth;
28
use C4::Output;
29
use CGI;
30
31
use C4::Koha;
32
use C4::Members;
33
use C4::Branch;
34
use C4::Accounts;
35
use C4::Items;
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
37
use Koha::Database;
38
39
my $cgi = new CGI;
40
41
my $borrowernumber = $cgi->param('borrowernumber');
42
43
my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
44
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46
    {
47
        template_name   => "members/account_credit.tt",
48
        query           => $cgi,
49
        type            => "intranet",
50
        authnotrequired => 0,
51
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
52
        debug           => 1,
53
    }
54
);
55
56
$template->param( credit_types_loop => GetAuthorisedValues('ACCOUNT_CREDIT') );
57
58
# Standard /members/ borrower details data
59
## FIXME: This code is in every /members/ script and should be unified
60
61
if ( $borrower->{'category_type'} eq 'C' ) {
62
    my ( $catcodes, $labels ) =
63
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
64
    my $cnt = scalar(@$catcodes);
65
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
66
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
67
}
68
69
my ( $picture, $dberror ) = GetPatronImage( $borrower->{'borrowernumber'} );
70
$template->param( picture => 1 ) if $picture;
71
72
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
73
    my $attributes = GetBorrowerAttributes($borrowernumber);
74
    $template->param(
75
        ExtendedPatronAttributes => 1,
76
        extendedattributes       => $attributes
77
    );
78
}
79
80
$template->param(
81
    borrowernumber => $borrowernumber,
82
    firstname      => $borrower->{'firstname'},
83
    surname        => $borrower->{'surname'},
84
    cardnumber     => $borrower->{'cardnumber'},
85
    categorycode   => $borrower->{'categorycode'},
86
    category_type  => $borrower->{'category_type'},
87
    categoryname   => $borrower->{'description'},
88
    address        => $borrower->{'address'},
89
    address2       => $borrower->{'address2'},
90
    city           => $borrower->{'city'},
91
    state          => $borrower->{'state'},
92
    zipcode        => $borrower->{'zipcode'},
93
    country        => $borrower->{'country'},
94
    phone          => $borrower->{'phone'},
95
    email          => $borrower->{'email'},
96
    branchcode     => $borrower->{'branchcode'},
97
    branchname     => GetBranchName( $borrower->{'branchcode'} ),
98
    is_child       => ( $borrower->{'category_type'} eq 'C' ),
99
    activeBorrowerRelationship =>
100
      ( C4::Context->preference('borrowerRelationship') ne '' ),
101
    RoutingSerials => C4::Context->preference('RoutingSerials'),
102
);
103
104
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/members/account_credit_do.pl (+68 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
5
# Copyright 2013 ByWater Solutions
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
24
use CGI;
25
26
use C4::Auth;
27
use C4::Output;
28
use C4::Members;
29
use C4::Items;
30
use C4::Branch;
31
use C4::Members::Attributes qw(GetBorrowerAttributes);
32
use Koha::Accounts;
33
use Koha::Database;
34
35
my $cgi = new CGI;
36
37
my $borrowernumber = $cgi->param('borrowernumber');
38
my $borrower =
39
  Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber);
40
41
if ( checkauth( $cgi, 0, { borrowers => 1 }, 'intranet' ) ) {
42
43
    my $barcode     = $cgi->param('barcode');
44
    my $itemnumber  = $cgi->param('itemnumber');
45
    my $description = $cgi->param('description');
46
    my $amount      = $cgi->param('amount');
47
    my $type        = $cgi->param('type');
48
    my $notes       = $cgi->param('notes');
49
50
    if ( !$itemnumber && $barcode ) {
51
        $itemnumber = GetItemnumberFromBarcode($barcode);
52
    }
53
54
    my $debit = AddCredit(
55
        {
56
            borrower    => $borrower,
57
            amount      => $amount,
58
            type        => $type,
59
            itemnumber  => $itemnumber,
60
            description => $description,
61
            notes       => $notes,
62
63
        }
64
    );
65
66
    print $cgi->redirect(
67
        "/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
68
}
(-)a/members/account_debit.pl (+104 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
#written 11/1/2000 by chris@katipo.oc.nz
4
#script to display borrowers account details
5
6
# Copyright 2000-2002 Katipo Communications
7
# Copyright 2010 BibLibre
8
#
9
# This file is part of Koha.
10
#
11
# Koha is free software; you can redistribute it and/or modify it under the
12
# terms of the GNU General Public License as published by the Free Software
13
# Foundation; either version 2 of the License, or (at your option) any later
14
# version.
15
#
16
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License along
21
# with Koha; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
use strict;
25
use warnings;
26
27
use CGI;
28
29
use C4::Auth;
30
use C4::Output;
31
use C4::Members;
32
use C4::Items;
33
use C4::Branch;
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
use C4::Koha;
36
use Koha::Accounts;
37
use Koha::Database;
38
39
my $input = new CGI;
40
41
my $borrowernumber = $input->param('borrowernumber');
42
43
my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
44
45
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46
    {
47
        template_name   => "members/account_debit.tt",
48
        query           => $input,
49
        type            => "intranet",
50
        authnotrequired => 0,
51
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
52
        debug           => 1,
53
    }
54
);
55
56
$template->param( invoice_types_loop => GetAuthorisedValues('MANUAL_INV') );
57
58
# Standard /members/ borrower details data
59
## FIXME: This code is in every /members/ script and should be unified
60
61
if ( $borrower->{'category_type'} eq 'C' ) {
62
    my ( $catcodes, $labels ) =
63
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
64
    my $cnt = scalar(@$catcodes);
65
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
66
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
67
}
68
69
my ( $picture, $dberror ) = GetPatronImage( $borrower->{'borrowernumber'} );
70
$template->param( picture => 1 ) if $picture;
71
72
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
73
    my $attributes = GetBorrowerAttributes($borrowernumber);
74
    $template->param(
75
        ExtendedPatronAttributes => 1,
76
        extendedattributes       => $attributes
77
    );
78
}
79
80
$template->param(
81
    borrowernumber => $borrowernumber,
82
    firstname      => $borrower->{'firstname'},
83
    surname        => $borrower->{'surname'},
84
    cardnumber     => $borrower->{'cardnumber'},
85
    categorycode   => $borrower->{'categorycode'},
86
    category_type  => $borrower->{'category_type'},
87
    categoryname   => $borrower->{'description'},
88
    address        => $borrower->{'address'},
89
    address2       => $borrower->{'address2'},
90
    city           => $borrower->{'city'},
91
    state          => $borrower->{'state'},
92
    zipcode        => $borrower->{'zipcode'},
93
    country        => $borrower->{'country'},
94
    phone          => $borrower->{'phone'},
95
    email          => $borrower->{'email'},
96
    branchcode     => $borrower->{'branchcode'},
97
    branchname     => GetBranchName( $borrower->{'branchcode'} ),
98
    is_child       => ( $borrower->{'category_type'} eq 'C' ),
99
    activeBorrowerRelationship =>
100
      ( C4::Context->preference('borrowerRelationship') ne '' ),
101
    RoutingSerials => C4::Context->preference('RoutingSerials'),
102
);
103
104
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/members/account_debit_do.pl (+69 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
5
# Copyright 2013 ByWater Solutions
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
24
use CGI;
25
26
use C4::Auth;
27
use C4::Output;
28
use C4::Members;
29
use C4::Items;
30
use C4::Branch;
31
use C4::Members::Attributes qw(GetBorrowerAttributes);
32
use Koha::Accounts;
33
use Koha::Database;
34
35
my $cgi = new CGI;
36
37
my $borrowernumber = $cgi->param('borrowernumber');
38
my $borrower =
39
  Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber);
40
41
if ( checkauth( $cgi, 0, { borrowers => 1 }, 'intranet' ) ) {
42
43
    #  print $cgi->header;
44
    my $barcode     = $cgi->param('barcode');
45
    my $itemnumber  = $cgi->param('itemnumber');
46
    my $description = $cgi->param('description');
47
    my $amount      = $cgi->param('amount');
48
    my $type        = $cgi->param('type');
49
    my $notes       = $cgi->param('notes');
50
51
    if ( !$itemnumber && $barcode ) {
52
        $itemnumber = GetItemnumberFromBarcode($barcode);
53
    }
54
55
    my $debit = AddDebit(
56
        {
57
            borrower    => $borrower,
58
            amount      => $amount,
59
            type        => $type,
60
            itemnumber  => $itemnumber,
61
            description => $description,
62
            notes       => $notes,
63
64
        }
65
    );
66
67
    print $cgi->redirect(
68
        "/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
69
}
(-)a/members/account_payment.pl (+123 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
5
# Copyright 2010,2011 PTFS-Europe Ltd
6
# Copyright 2013 ByWater Solutions
7
#
8
# This file is part of Koha.
9
#
10
# Koha is free software; you can redistribute it and/or modify it under the
11
# terms of the GNU General Public License as published by the Free Software
12
# Foundation; either version 2 of the License, or (at your option) any later
13
# version.
14
#
15
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18
#
19
# You should have received a copy of the GNU General Public License along
20
# with Koha; if not, write to the Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23
=head1 account_payment.pl
24
25
 written 11/1/2000 by chris@katipo.oc.nz
26
 part of the koha library system, script to facilitate paying off fines
27
28
=cut
29
30
use Modern::Perl;
31
32
use CGI;
33
34
use URI::Escape;
35
36
use C4::Context;
37
use C4::Auth;
38
use C4::Output;
39
use C4::Members;
40
use C4::Accounts;
41
use C4::Stats;
42
use C4::Koha;
43
use C4::Overdues;
44
use C4::Branch;
45
use C4::Members::Attributes qw(GetBorrowerAttributes);
46
use Koha::Database;
47
48
our $cgi = CGI->new;
49
50
our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51
    {
52
        template_name   => 'members/account_payment.tt',
53
        query           => $cgi,
54
        type            => 'intranet',
55
        authnotrequired => 0,
56
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
57
        debug           => 1,
58
    }
59
);
60
61
my $borrowernumber = $cgi->param('borrowernumber');
62
63
my $borrower = GetMember( borrowernumber => $borrowernumber );
64
65
my @debits = Koha::Database->new()->schema->resultset('AccountDebit')->search(
66
    {
67
        'me.borrowernumber' => $borrowernumber,
68
        amount_outstanding  => { '>' => 0 }
69
    }
70
);
71
72
$template->param(
73
    debits   => \@debits,
74
    borrower => $borrower,
75
);
76
77
# Standard /members/ borrower details data
78
## FIXME: This code is in every /members/ script and should be unified
79
80
if ( $borrower->{'category_type'} eq 'C' ) {
81
    my ( $catcodes, $labels ) =
82
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
83
    my $cnt = scalar(@$catcodes);
84
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
85
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
86
}
87
88
my ( $picture, $dberror ) = GetPatronImage( $borrower->{'borrowernumber'} );
89
$template->param( picture => 1 ) if $picture;
90
91
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
92
    my $attributes = GetBorrowerAttributes($borrowernumber);
93
    $template->param(
94
        ExtendedPatronAttributes => 1,
95
        extendedattributes       => $attributes
96
    );
97
}
98
99
$template->param(
100
    borrowernumber => $borrowernumber,
101
    firstname      => $borrower->{'firstname'},
102
    surname        => $borrower->{'surname'},
103
    cardnumber     => $borrower->{'cardnumber'},
104
    categorycode   => $borrower->{'categorycode'},
105
    category_type  => $borrower->{'category_type'},
106
    categoryname   => $borrower->{'description'},
107
    address        => $borrower->{'address'},
108
    address2       => $borrower->{'address2'},
109
    city           => $borrower->{'city'},
110
    state          => $borrower->{'state'},
111
    zipcode        => $borrower->{'zipcode'},
112
    country        => $borrower->{'country'},
113
    phone          => $borrower->{'phone'},
114
    email          => $borrower->{'email'},
115
    branchcode     => $borrower->{'branchcode'},
116
    branchname     => GetBranchName( $borrower->{'branchcode'} ),
117
    is_child       => ( $borrower->{'category_type'} eq 'C' ),
118
    activeBorrowerRelationship =>
119
      ( C4::Context->preference('borrowerRelationship') ne '' ),
120
    RoutingSerials => C4::Context->preference('RoutingSerials'),
121
);
122
123
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/members/account_payment_do.pl (+62 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2010 BibLibre
5
# Copyright 2013 ByWater Solutions
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
24
use CGI;
25
26
use C4::Auth;
27
use C4::Members;
28
use C4::Items;
29
use C4::Branch;
30
use C4::Members::Attributes qw(GetBorrowerAttributes);
31
use Koha::Accounts;
32
use Koha::Database;
33
34
my $cgi = new CGI;
35
36
if ( checkauth( $cgi, 0, { borrowers => 1 }, 'intranet' ) ) {
37
    my $borrowernumber = $cgi->param('borrowernumber');
38
39
    my $borrower =
40
      Koha::Database->new()->schema->resultset('Borrower')
41
      ->find($borrowernumber);
42
43
    my $amount_to_pay   = $cgi->param('amount_to_pay');
44
    my $amount_received = $cgi->param('amount_received');
45
    my $type            = $cgi->param('type');
46
    my $notes           = $cgi->param('notes');
47
    my @debit_id        = $cgi->param('debit_id');
48
49
    my $debit = AddCredit(
50
        {
51
            borrower => $borrower,
52
            amount   => $amount_to_pay,
53
            type     => $type,
54
            notes    => $notes,
55
            debit_id => \@debit_id,
56
57
        }
58
    );
59
60
    print $cgi->redirect(
61
        "/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
62
}
(-)a/members/account_print.pl (+58 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 2 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use CGI;
21
22
use C4::Auth;
23
use C4::Output;
24
use Koha::Database;
25
26
my $cgi = new CGI;
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
30
        template_name   => "members/account_print.tt",
31
        query           => $cgi,
32
        type            => "intranet",
33
        authnotrequired => 0,
34
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
35
        debug           => 1,
36
    }
37
);
38
39
my $type = $cgi->param('type');
40
my $id   = $cgi->param('id');
41
42
warn "No type passed in!" unless $type;
43
warn "No id passed in!"   unless $id;
44
45
if ( $type eq 'debit' ) {
46
    my $debit =
47
      Koha::Database->new()->schema->resultset('AccountDebit')->find($id);
48
    $template->param( debit => $debit );
49
}
50
elsif ( $type eq 'credit' ) {
51
    my $credit =
52
      Koha::Database->new()->schema->resultset('AccountCredit')->find($id);
53
    $template->param( credit => $credit );
54
}
55
56
$template->param( type => $type );
57
58
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/members/mancredit.pl (-1 / +1 lines)
Lines 57-63 if ($add){ Link Here
57
        $amount = -$amount;
57
        $amount = -$amount;
58
        my $type = $input->param('type');
58
        my $type = $input->param('type');
59
        manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note );
59
        manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note );
60
        print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
60
        print $input->redirect("/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
61
    }
61
    }
62
} else {
62
} else {
63
	my ($template, $loggedinuser, $cookie)
63
	my ($template, $loggedinuser, $cookie)
(-)a/members/maninvoice.pl (-1 / +1 lines)
Lines 72-78 if ($add){ Link Here
72
            $template->param( 'ERROR' => $error );
72
            $template->param( 'ERROR' => $error );
73
            output_html_with_http_headers $input, $cookie, $template->output;
73
            output_html_with_http_headers $input, $cookie, $template->output;
74
        } else {
74
        } else {
75
            print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
75
            print $input->redirect("/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
76
            exit;
76
            exit;
77
        }
77
        }
78
    }
78
    }
(-)a/members/pay.pl (-2 / +2 lines)
Lines 19-25 Link Here
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
21
22
=head1 pay.pl
22
=head1 account_payment.pl
23
23
24
 written 11/1/2000 by chris@katipo.oc.nz
24
 written 11/1/2000 by chris@katipo.oc.nz
25
 part of the koha library system, script to facilitate paying off fines
25
 part of the koha library system, script to facilitate paying off fines
Lines 197-203 sub writeoff_all { Link Here
197
197
198
    $borrowernumber = $input->param('borrowernumber');
198
    $borrowernumber = $input->param('borrowernumber');
199
    print $input->redirect(
199
    print $input->redirect(
200
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
200
        "/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber");
201
    return;
201
    return;
202
}
202
}
203
203
(-)a/members/paycollect.pl (-2 / +2 lines)
Lines 114-120 if ( $total_paid and $total_paid ne '0.00' ) { Link Here
114
                    $user, $branch, $payment_note );
114
                    $user, $branch, $payment_note );
115
            }
115
            }
116
            print $input->redirect(
116
            print $input->redirect(
117
                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
117
                "/cgi-bin/koha/members/account_payment.pl?borrowernumber=$borrowernumber");
118
        } else {
118
        } else {
119
            if ($select) {
119
            if ($select) {
120
                if ( $select =~ /^([\d,]*).*/ ) {
120
                if ( $select =~ /^([\d,]*).*/ ) {
Lines 130-136 if ( $total_paid and $total_paid ne '0.00' ) { Link Here
130
# recordpayment does not return success or failure so lets redisplay the boraccount
130
# recordpayment does not return success or failure so lets redisplay the boraccount
131
131
132
            print $input->redirect(
132
            print $input->redirect(
133
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
133
"/cgi-bin/koha/members/account.pl?borrowernumber=$borrowernumber"
134
            );
134
            );
135
        }
135
        }
136
    }
136
    }
(-)a/members/printfeercpt.pl (-1 / +1 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
3
4
#writen 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
4
#writen 3rd May 2010 by kmkale@anantcorp.com adapted from account.pl by chris@katipo.oc.nz
5
#script to print fee receipts
5
#script to print fee receipts
6
6
7
7
(-)a/members/printinvoice.pl (-1 / +1 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
#writen 3rd May 2010 by kmkale@anantcorp.com adapted from boraccount.pl by chris@katipo.oc.nz
3
#writen 3rd May 2010 by kmkale@anantcorp.com adapted from account.pl by chris@katipo.oc.nz
4
#script to print fee receipts
4
#script to print fee receipts
5
5
6
# Copyright Koustubha Kale
6
# Copyright Koustubha Kale
(-)a/misc/cronjobs/create_koc_db.pl (-40 / +1 lines)
Lines 256-265 SELECT borrowernumber, Link Here
256
       city,
256
       city,
257
       phone,
257
       phone,
258
       dateofbirth,
258
       dateofbirth,
259
       sum( accountlines.amountoutstanding ) as total_fines
259
       account_balance as total_fines
260
FROM borrowers
260
FROM borrowers
261
LEFT JOIN accountlines USING (borrowernumber)
262
GROUP BY borrowernumber;
263
END_SQL
261
END_SQL
264
262
265
    my $fields_count = $sth_mysql->execute();
263
    my $fields_count = $sth_mysql->execute();
Lines 278-320 END_SQL Link Here
278
    }
276
    }
279
    $dbh_sqlite->commit();
277
    $dbh_sqlite->commit();
280
    print "inserted $count borrowers\n" if $verbose;
278
    print "inserted $count borrowers\n" if $verbose;
281
    # add_fines_to_borrowers_table();
282
}
283
284
=head2 add_fines_to_borrowers_table
285
286
Import the fines from koha.accountlines into the sqlite db
287
288
=cut
289
290
sub add_fines_to_borrowers_table {
291
292
    print "preparing to update borrowers\n" if $verbose;
293
    my $sth_mysql = $dbh_mysql->prepare(
294
        "SELECT DISTINCT borrowernumber, SUM( amountoutstanding ) AS total_fines
295
                                    FROM accountlines
296
                                    GROUP BY borrowernumber"
297
    );
298
    $sth_mysql->execute();
299
    my $count;
300
    while ( my $result = $sth_mysql->fetchrow_hashref() ) {
301
        $count++;
302
        if ( $verbose ) {
303
            print '.' unless ( $count % 10 );
304
            print "$count\n" unless ( $count % 1000 );
305
        }
306
307
        my $borrowernumber = $result->{'borrowernumber'};
308
        my $total_fines    = $result->{'total_fines'};
309
310
        # warn "Fines for Borrower # $borrowernumber are \$ $total_fines \n" if $verbose;
311
        my $sql = "UPDATE borrowers SET total_fines = ? WHERE borrowernumber = ?";
312
313
        my $sth_sqlite = $dbh_sqlite->prepare($sql);
314
        $sth_sqlite->execute( $total_fines, $borrowernumber );
315
        $sth_sqlite->finish();
316
    }
317
    print "updated $count borrowers\n" if ( $verbose && $count );
318
}
279
}
319
280
320
=head2 create_issue_table
281
=head2 create_issue_table
(-)a/misc/cronjobs/fines.pl (-3 / +7 lines)
Lines 127-135 for my $overdue ( @{$overdues} ) { Link Here
127
    if ( $mode eq 'production' && !$is_holiday{$branchcode} ) {
127
    if ( $mode eq 'production' && !$is_holiday{$branchcode} ) {
128
        if ( $amount > 0 ) {
128
        if ( $amount > 0 ) {
129
            UpdateFine(
129
            UpdateFine(
130
                $overdue->{itemnumber},
130
                {
131
                $overdue->{borrowernumber},
131
                    itemnumber     => $overdue->{itemnumber},
132
                $amount, $type, output_pref($datedue)
132
                    borrowernumber => $overdue->{borrowernumber},
133
                    amount         => $amount,
134
                    due            => output_pref($datedue),
135
                    issue_id       => $overdue->{issue_id}
136
                }
133
            );
137
            );
134
        }
138
        }
135
    }
139
    }
(-)a/misc/release_notes/release_notes_3_10_0.txt (-1 / +1 lines)
Lines 1762-1768 Staff Client Link Here
1762
	8996	normal	In result page items with negative notforloan are available
1762
	8996	normal	In result page items with negative notforloan are available
1763
	9017	normal	Quote of the day: Table footer not translated
1763
	9017	normal	Quote of the day: Table footer not translated
1764
	5312	minor	XHTML correction in authority summary
1764
	5312	minor	XHTML correction in authority summary
1765
	8009	minor	Item descriptive data not populated on pay.pl
1765
  8009	minor	Item descriptive data not populated on account_payment.pl
1766
	8593	minor	Add unique IDs to pending approval markup on staff client home page
1766
	8593	minor	Add unique IDs to pending approval markup on staff client home page
1767
	8646	minor	Certain search terms cause browser "script taking too long" error
1767
	8646	minor	Certain search terms cause browser "script taking too long" error
1768
	8793	minor	Fix materialTypeCode/typeOf008 icons for NORMARC XSLT
1768
	8793	minor	Fix materialTypeCode/typeOf008 icons for NORMARC XSLT
(-)a/misc/release_notes/release_notes_3_12_0.txt (-1 / +1 lines)
Lines 579-585 Architecture, internals, and plumbing Link Here
579
	8429	minor	Unnecessary use of Exporter in SIP/ILS objects
579
	8429	minor	Unnecessary use of Exporter in SIP/ILS objects
580
	9292	minor	Remove dead code related to 'publictype'
580
	9292	minor	Remove dead code related to 'publictype'
581
	9401	minor	Javascript used for tags handling wants access to CGISESSID cookie
581
	9401	minor	Javascript used for tags handling wants access to CGISESSID cookie
582
	9582	minor	Unused code in members/pay.pl
582
 9582	minor	Unused code in members/account_payment.pl
583
	10054	minor	When SingleBranchMode is enabled, allow superlibrarians to set logged in library
583
	10054	minor	When SingleBranchMode is enabled, allow superlibrarians to set logged in library
584
	10143	minor	Fix FSF address in license headers
584
	10143	minor	Fix FSF address in license headers
585
	9609	trivial	Rebuild zebra reports double numbers for exported records with -z option
585
	9609	trivial	Rebuild zebra reports double numbers for exported records with -z option
(-)a/t/db_dependent/Accounts.t (-3 / +186 lines)
Lines 1-16 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
2
#
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 1;
9
use Test::More tests => 19;
10
11
use C4::Context;
10
12
11
BEGIN {
13
BEGIN {
12
        use_ok('C4::Accounts');
14
    use_ok('Koha::Database');
15
    use_ok('Koha::Accounts');
16
    use_ok('Koha::Accounts::DebitTypes');
17
    use_ok('Koha::Accounts::CreditTypes');
13
}
18
}
14
19
20
## Intial Setup ##
21
my $borrower = Koha::Database->new()->schema->resultset('Borrower')->create(
22
    {
23
        surname         => 'Test',
24
        categorycode    => 'S',
25
        branchcode      => 'MPL',
26
        account_balance => 0,
27
    }
28
);
29
30
my $biblio =
31
  Koha::Database->new()->schema->resultset('Biblio')
32
  ->create( { title => "Test Record" } );
33
my $biblioitem =
34
  Koha::Database->new()->schema->resultset('Biblioitem')
35
  ->create( { biblionumber => $biblio->biblionumber() } );
36
my $item = Koha::Database->new()->schema->resultset('Item')->create(
37
    {
38
        biblionumber     => $biblio->biblionumber(),
39
        biblioitemnumber => $biblioitem->biblioitemnumber(),
40
        replacementprice => 25.00,
41
        barcode          => q{TEST_ITEM_BARCODE}
42
    }
43
);
44
45
my $issue = Koha::Database->new()->schema->resultset('Issue')->create(
46
    {
47
        borrowernumber => $borrower->borrowernumber(),
48
        itemnumber     => $item->itemnumber(),
49
    }
50
);
51
## END initial setup
52
53
ok( Koha::Accounts::DebitTypes::Fine eq 'FINE', 'Test DebitTypes::Fine' );
54
ok( Koha::Accounts::DebitTypes::Lost eq 'LOST', 'Test DebitTypes::Lost' );
55
ok(
56
    Koha::Accounts::DebitTypes::IsValid('FINE'),
57
    'Test DebitTypes::IsValid with valid debit type'
58
);
59
ok(
60
    !Koha::Accounts::DebitTypes::IsValid('Not A Valid Fee Type'),
61
    'Test DebitTypes::IsValid with an invalid debit type'
62
);
63
my $authorised_value =
64
  Koha::Database->new()->schema->resultset('AuthorisedValue')->create(
65
    {
66
        category         => 'MANUAL_INV',
67
        authorised_value => 'TEST',
68
        lib              => 'Test',
69
    }
70
  );
71
ok( Koha::Accounts::DebitTypes::IsValid('TEST'),
72
    'Test DebitTypes::IsValid with valid authorised value debit type' );
73
$authorised_value->delete();
74
75
my $debit = AddDebit(
76
    {
77
        borrower   => $borrower,
78
        amount     => 5.00,
79
        type       => Koha::Accounts::DebitTypes::Fine,
80
        branchcode => 'MPL',
81
    }
82
);
83
ok( $debit, "AddDebit returned a valid debit id " . $debit->id() );
84
85
ok(
86
    $borrower->account_balance() == 5.00,
87
    "Borrower's account balance updated correctly"
88
);
89
90
my $debit2 = AddDebit(
91
    {
92
        borrower   => $borrower,
93
        amount     => 7.00,
94
        type       => Koha::Accounts::DebitTypes::Fine,
95
        branchcode => 'MPL',
96
    }
97
);
98
99
my $credit = AddCredit(
100
    {
101
        borrower   => $borrower,
102
        type       => Koha::Accounts::CreditTypes::Payment,
103
        amount     => 9.00,
104
        branchcode => 'MPL',
105
    }
106
);
107
108
RecalculateAccountBalance( { borrower => $borrower } );
109
ok(
110
    sprintf( "%.2f", $borrower->account_balance() ) eq "3.00",
111
    "RecalculateAccountBalance updated balance correctly."
112
);
113
114
Koha::Database->new()->schema->resultset('AccountCredit')->create(
115
    {
116
        borrowernumber   => $borrower->borrowernumber(),
117
        type             => Koha::Accounts::CreditTypes::Payment,
118
        amount_paid      => 3.00,
119
        amount_remaining => 3.00,
120
    }
121
);
122
NormalizeBalances( { borrower => $borrower } );
123
ok(
124
    $borrower->account_balance() == 0.00,
125
    "NormalizeBalances updated balance correctly."
126
);
127
128
# Adding advance credit with no balance due
129
$credit = AddCredit(
130
    {
131
        borrower   => $borrower,
132
        type       => Koha::Accounts::CreditTypes::Payment,
133
        amount     => 9.00,
134
        branchcode => 'MPL',
135
    }
136
);
137
ok(
138
    $borrower->account_balance() == -9,
139
'Adding a $9 credit for borrower with 0 balance results in a -9 dollar account balance'
140
);
141
142
my $debit3 = AddDebit(
143
    {
144
        borrower   => $borrower,
145
        amount     => 5.00,
146
        type       => Koha::Accounts::DebitTypes::Fine,
147
        branchcode => 'MPL',
148
    }
149
);
150
ok(
151
    $borrower->account_balance() == -4,
152
'Adding a $5 debit when the balance is negative results in the debit being automatically paid, resulting in a balance of -4'
153
);
154
155
my $debit4 = AddDebit(
156
    {
157
        borrower   => $borrower,
158
        amount     => 6.00,
159
        type       => Koha::Accounts::DebitTypes::Fine,
160
        branchcode => 'MPL',
161
    }
162
);
163
ok(
164
    $borrower->account_balance() == 2,
165
'Adding another debit ( 6.00 ) more than the negative account balance results in a partial credit and a balance due of 2.00'
166
);
167
$credit = AddCredit(
168
    {
169
        borrower   => $borrower,
170
        type       => Koha::Accounts::CreditTypes::WriteOff,
171
        amount     => 2.00,
172
        branchcode => 'MPL',
173
        debit_id   => $debit4->debit_id(),
174
    }
175
);
176
ok( $borrower->account_balance() == 0,
177
    'WriteOff of remaining 2.00 balance succeeds' );
178
179
my $debit5 = DebitLostItem(
180
    {
181
        borrower => $borrower,
182
        issue    => $issue,
183
    }
184
);
185
ok( $borrower->account_balance() == 25,
186
    'DebitLostItem adds debit for replacement price of item' );
15
187
188
my $lost_credit =
189
  CreditLostItem( { borrower => $borrower, debit => $debit5 } );
190
ok(
191
    $borrower->account_balance() == 0,
192
    'CreditLostItem adds credit for same about as the debit for the lost tiem'
193
);
16
194
195
## Post test cleanup ##
196
$issue->delete();
197
$item->delete();
198
$biblio->delete();
199
$borrower->delete();
(-)a/t/db_dependent/Circulation.t (-5 / +18 lines)
Lines 302-309 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
302
    C4::Context->set_preference('WhenLostForgiveFine','1');
302
    C4::Context->set_preference('WhenLostForgiveFine','1');
303
    C4::Context->set_preference('WhenLostChargeReplacementFee','1');
303
    C4::Context->set_preference('WhenLostChargeReplacementFee','1');
304
304
305
    C4::Overdues::UpdateFine( $itemnumber, $renewing_borrower->{borrowernumber},
305
    C4::Overdues::UpdateFine(
306
        15.00, q{}, Koha::DateUtils::output_pref($datedue) );
306
        {
307
            itemnumber     => $itemnumber,
308
            borrowernumber => $renewing_borrower->{borrowernumber},
309
            amount         => 15.00,
310
            due            => Koha::DateUtils::output_pref($datedue),
311
            issue_id       => GetItemIssue($itemnumber)->{issue_id}
312
        }
313
    );
307
314
308
    LostItem( $itemnumber, 1 );
315
    LostItem( $itemnumber, 1 );
309
316
Lines 319-326 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
319
    C4::Context->set_preference('WhenLostForgiveFine','0');
326
    C4::Context->set_preference('WhenLostForgiveFine','0');
320
    C4::Context->set_preference('WhenLostChargeReplacementFee','0');
327
    C4::Context->set_preference('WhenLostChargeReplacementFee','0');
321
328
322
    C4::Overdues::UpdateFine( $itemnumber2, $renewing_borrower->{borrowernumber},
329
    C4::Overdues::UpdateFine(
323
        15.00, q{}, Koha::DateUtils::output_pref($datedue) );
330
        {
331
            itemnumber     => $itemnumber2,
332
            borrowernumber => $renewing_borrower->{borrowernumber},
333
            amount         => 15.00,
334
            due            => Koha::DateUtils::output_pref($datedue),
335
            issue_id       => GetItemIssue($itemnumber2)->{issue_id},
336
        }
337
    );
324
338
325
    LostItem( $itemnumber2, 1 );
339
    LostItem( $itemnumber2, 1 );
326
340
327
- 

Return to bug 6427