From 4180114d918e93b46569be82a83c979b997cdef8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 10 Oct 2019 17:15:10 +0100 Subject: [PATCH] Bug 23049: Update existing code to use debit_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update C4::Accounts::chargelostitem * Update C4::Accounts::manualinvoice * Update C4::Circulation::_FixOverduesOnReturn * Update C4::Circulation::_FixAccountForLostAndReturned * Update C4::Overdues::UpdateFine * Update C4::Overdues::GetFine * Update C4::Overdues::GetOverduesForBranch * Update Koha::Account->pay * Update Koha::Account->add_debit * Update Koha::Account->non_issues_charges * Update Koha::Account::Line->apply * Update Koha::Account::Line->adjust * Update controller scripts * Update reports scripts * Update tests Test Plan 1) Run the test suit and ensure everything still passes 2) Test reports/cash_register_stats still works 3) Test that adding manual invoices still works 4) Test that making payments still works 5) Test that lost item fee handling still works 6) Test that invoice printing still works 7) Test that the sco still works Signed-off-by: Séverine QUEUNE --- C4/Accounts.pm | 10 +- C4/Circulation.pm | 14 +-- C4/Overdues.pm | 6 +- Koha/Account.pm | 81 ++++++++-------- Koha/Account/Line.pm | 18 ++-- Koha/Schema/Result/AcDebitTypesBranch.pm | 8 +- Koha/Schema/Result/AccountDebitType.pm | 34 ++++--- Koha/Schema/Result/Accountline.pm | 18 ++-- catalogue/moredetail.pl | 2 +- .../mysql/atomicupdate/bug_23049_debit.perl | 46 +++++---- installer/data/mysql/kohastructure.sql | 8 +- .../en/modules/members/moremember-print.tt | 2 +- .../prog/en/modules/members/pay.tt | 2 +- .../prog/en/modules/members/paycollect.tt | 8 +- .../en/modules/reports/cash_register_stats.tt | 72 ++------------ .../bootstrap/en/includes/account-table.inc | 55 ++++++----- members/pay.pl | 4 +- members/paycollect.pl | 6 +- members/printinvoice.pl | 4 +- misc/cronjobs/staticfines.pl | 2 +- opac/opac-user.pl | 4 +- opac/sco/sco-main.pl | 8 +- reports/cash_register_stats.pl | 24 +++-- t/db_dependent/Accounts.t | 93 ++++++++++--------- t/db_dependent/Circulation.t | 42 ++++----- .../Circulation/NoIssuesChargeGuarantees.t | 2 +- t/db_dependent/Circulation/Returns.t | 2 +- t/db_dependent/Koha/Account.t | 10 +- t/db_dependent/Koha/Account/DebitTypes.t | 2 - t/db_dependent/Koha/Account/Lines.t | 30 +++--- t/db_dependent/Koha/Patron.t | 6 +- t/db_dependent/Reserves.t | 2 +- t/db_dependent/api/v1/patrons_accounts.t | 10 +- 33 files changed, 303 insertions(+), 332 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 34a3ef91a9..6aa1bb4a6e 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -90,9 +90,9 @@ sub chargelostitem { # first make sure the borrower hasn't already been charged for this item (for this issuance) my $existing_charges = $account->lines->search( { - itemnumber => $itemnumber, - accounttype => 'LOST', - issue_id => $issue_id + itemnumber => $itemnumber, + debit_type_code => 'LOST', + issue_id => $issue_id } )->count(); @@ -174,7 +174,7 @@ sub manualinvoice { date => \'NOW()', amount => $amount, description => $desc, - accounttype => $type, + debit_type_code => $type, amountoutstanding => $amountleft, itemnumber => $itemnum || undef, issue_id => $issue_id, @@ -199,7 +199,7 @@ sub manualinvoice { borrowernumber => $borrowernumber, amount => $amount, description => $desc, - accounttype => $type, + debit_type_code => $type, amountoutstanding => $amountleft, note => $note, itemnumber => $itemnum, diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 014c018628..befdc3e986 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2347,10 +2347,10 @@ sub _FixOverduesOnReturn { # check for overdue fine my $accountlines = Koha::Account::Lines->search( { - borrowernumber => $borrowernumber, - itemnumber => $item, - accounttype => 'OVERDUE', - status => 'UNRETURNED' + borrowernumber => $borrowernumber, + itemnumber => $item, + debit_type_code => 'OVERDUE', + status => 'UNRETURNED' } ); return 0 unless $accountlines->count; # no warning, there's just nothing to fix @@ -2411,9 +2411,9 @@ sub _FixAccountForLostAndReturned { # check for charge made for lost book my $accountlines = Koha::Account::Lines->search( { - itemnumber => $itemnumber, - accounttype => 'LOST', - status => [ undef, { '<>' => 'RETURNED' } ] + itemnumber => $itemnumber, + debit_type_code => 'LOST', + status => [ undef, { '<>' => 'RETURNED' } ] }, { order_by => { -desc => [ 'date', 'accountlines_id' ] } diff --git a/C4/Overdues.pm b/C4/Overdues.pm index fa8d6e648a..d97cde98de 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -523,7 +523,7 @@ sub UpdateFine { my $overdues = Koha::Account::Lines->search( { borrowernumber => $borrowernumber, - accounttype => [ 'OVERDUE', 'M' ], + debit_type_code => [ 'OVERDUE', 'M' ], amountoutstanding => { '<>' => 0 } } ); @@ -637,7 +637,7 @@ sub GetFine { my ( $itemnum, $borrowernumber ) = @_; my $dbh = C4::Context->dbh(); my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines - where accounttype like 'OVERDUE' + WHERE debit_type_code LIKE 'OVERDUE' AND amountoutstanding > 0 AND borrowernumber=?|; my @query_param; push @query_param, $borrowernumber; @@ -728,7 +728,7 @@ sub GetOverduesForBranch { LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link LEFT JOIN branches ON branches.branchcode = issues.branchcode WHERE (accountlines.amountoutstanding != '0.000000') - AND (accountlines.accounttype = 'OVERDUE' ) + AND (accountlines.debit_type_code = 'OVERDUE' ) AND (accountlines.status = 'UNRETURNED' ) AND (issues.branchcode = ? ) AND (issues.date_due < NOW()) diff --git a/Koha/Account.pm b/Koha/Account.pm index 743b4b7d04..61b08db92c 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -115,8 +115,8 @@ sub pay { # Same logic exists in Koha::Account::Line::apply if ( $new_amountoutstanding == 0 && $fine->itemnumber - && $fine->accounttype - && ( $fine->accounttype eq 'LOST' ) ) + && $fine->debit_type_code + && ( $fine->debit_type_code eq 'LOST' ) ) { C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber ); } @@ -174,8 +174,8 @@ sub pay { if ( $fine->amountoutstanding == 0 && $fine->itemnumber - && $fine->accounttype - && ( $fine->accounttype eq 'LOST' ) ) + && $fine->debit_type_code + && ( $fine->debit_type_code eq 'LOST' ) ) { C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber ); } @@ -444,19 +444,20 @@ my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( ); $debit_type can be any of: - - overdue - - lost_item - - new_card - account - account_renew + - hold_expired + - lost_item - sundry + - new_card + - overdue - processing - rent - rent_daily - - rent_renewal - - rent_daily_renewal + - rent_renew + - rent_daily_renew - reserve - - manual + - manual_debit =cut @@ -465,27 +466,25 @@ sub add_debit { my ( $self, $params ) = @_; # amount should always be a positive value - my $amount = $params->{amount}; + my $amount = $params->{amount}; unless ( $amount > 0 ) { Koha::Exceptions::Account::AmountNotPositive->throw( - error => 'Debit amount passed is not positive' - ); + error => 'Debit amount passed is not positive' ); } - my $description = $params->{description} // q{}; - my $note = $params->{note} // q{}; - my $user_id = $params->{user_id}; - my $interface = $params->{interface}; - my $library_id = $params->{library_id}; - my $type = $params->{type}; - my $item_id = $params->{item_id}; - my $issue_id = $params->{issue_id}; + my $description = $params->{description} // q{}; + my $note = $params->{note} // q{}; + my $user_id = $params->{user_id}; + my $interface = $params->{interface}; + my $library_id = $params->{library_id}; + my $type = $params->{type}; + my $item_id = $params->{item_id}; + my $issue_id = $params->{issue_id}; - unless ( $interface ) { + unless ($interface) { Koha::Exceptions::MissingParameter->throw( - error => 'The interface parameter is mandatory' - ); + error => 'The interface parameter is mandatory' ); } my $schema = Koha::Database->new->schema; @@ -496,20 +495,20 @@ sub add_debit { ); } - my $account_type = $Koha::Account::account_type_debit->{$type}; + my $debit_type_code = $Koha::Account::account_type_debit->{$type}; my $line; - $schema->txn_do( sub { # Insert the account line $line = Koha::Account::Line->new( - { borrowernumber => $self->{patron_id}, + { + borrowernumber => $self->{patron_id}, date => \'NOW()', amount => $amount, description => $description, - accounttype => $account_type, + debit_type_code => $debit_type_code, amountoutstanding => $amount, payment_type => undef, note => $note, @@ -518,15 +517,16 @@ sub add_debit { itemnumber => $item_id, issue_id => $issue_id, branchcode => $library_id, - ( $type eq 'overdue' ? ( status => 'UNRETURNED' ) : ()), + ( $type eq 'overdue' ? ( status => 'UNRETURNED' ) : () ), } )->store(); # Record the account offset my $account_offset = Koha::Account::Offset->new( - { debit_id => $line->id, - type => $Koha::Account::offset_type->{$type}, - amount => $amount + { + debit_id => $line->id, + type => $Koha::Account::offset_type->{$type}, + amount => $amount } )->store(); @@ -535,12 +535,13 @@ sub add_debit { "FINES", 'CREATE', $self->{patron_id}, Dumper( - { action => "create_$type", + { + action => "create_$type", borrowernumber => $self->{patron_id}, amount => $amount, description => $description, amountoutstanding => $amount, - accounttype => $account_type, + debit_type_code => $debit_type_code, note => $note, itemnumber => $item_id, manager_id => $user_id, @@ -636,13 +637,13 @@ sub non_issues_charges { push @not_fines, ( 'RENT', 'RENT_DAILY', 'RENT_RENEW', 'RENT_DAILY_RENEW' ) unless C4::Context->preference('RentalsInNoissuesCharge'); unless ( C4::Context->preference('ManInvInNoissuesCharge') ) { - my @man_inv = Koha::Account::DebitTypes->search({ system => 0 })->get_column('code'); + my @man_inv = Koha::Account::DebitTypes->search({ is_system => 0 })->get_column('code'); push @not_fines, @man_inv; } return $self->lines->search( { - debit_type => { -not_in => \@not_fines } + debit_type_code => { -not_in => \@not_fines } }, )->total_outstanding; } @@ -741,18 +742,18 @@ our $account_type_credit = { our $account_type_debit = { 'account' => 'ACCOUNT', 'account_renew' => 'ACCOUNT_RENEW', - 'overdue' => 'OVERDUE', + 'hold_expired' => 'HE', 'lost_item' => 'LOST', - 'new_card' => 'N', 'sundry' => 'M', + 'new_card' => 'N', + 'overdue' => 'OVERDUE', 'processing' => 'PF', 'rent' => 'RENT', 'rent_daily' => 'RENT_DAILY', 'rent_renew' => 'RENT_RENEW', 'rent_daily_renew' => 'RENT_DAILY_RENEW', 'reserve' => 'Res', - 'manual_debit' => 'M', - 'hold_expired' => 'HE' + 'manual_debit' => 'M' }; =head1 AUTHORS diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 1f70bb1312..8911813040 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -252,8 +252,8 @@ sub apply { # Same logic exists in Koha::Account::pay if ( $debit->amountoutstanding == 0 && $debit->itemnumber - && $debit->accounttype - && $debit->accounttype eq 'LOST' ) + && $debit->debit_type_code + && $debit->debit_type_code eq 'LOST' ) { C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber ); } @@ -300,21 +300,21 @@ sub adjust { ); } - my $account_type = $self->accounttype; - my $account_status = $self->status; + my $debit_type_code = $self->debit_type_code; + my $account_status = $self->status; unless ( ( exists( $Koha::Account::Line::allowed_update->{$update_type} - ->{$account_type} + ->{$debit_type_code} ) && ( $Koha::Account::Line::allowed_update->{$update_type} - ->{$account_type} eq $account_status ) + ->{$debit_type_code} eq $account_status ) ) ) { Koha::Exceptions::Account::UnrecognisedType->throw( - error => 'Update type not allowed on this accounttype' ); + error => 'Update type not allowed on this debit_type' ); } my $schema = Koha::Database->new->schema; @@ -327,7 +327,7 @@ sub adjust { my $difference = $amount - $amount_before; my $new_outstanding = $amount_outstanding_before + $difference; - my $offset_type = $account_type; + my $offset_type = $debit_type_code; $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE"; # Catch cases that require patron refunds @@ -374,7 +374,7 @@ sub adjust { amount => $amount, description => undef, amountoutstanding => $new_outstanding, - accounttype => $self->accounttype, + debit_type_code => $self->debit_type_code, note => undef, itemnumber => $self->itemnumber, manager_id => undef, diff --git a/Koha/Schema/Result/AcDebitTypesBranch.pm b/Koha/Schema/Result/AcDebitTypesBranch.pm index 3a9f4e36fe..26e5825171 100644 --- a/Koha/Schema/Result/AcDebitTypesBranch.pm +++ b/Koha/Schema/Result/AcDebitTypesBranch.pm @@ -28,7 +28,7 @@ __PACKAGE__->table("ac_debit_types_branches"); data_type: 'varchar' is_foreign_key: 1 is_nullable: 1 - size: 16 + size: 64 =head2 branchcode @@ -41,7 +41,7 @@ __PACKAGE__->table("ac_debit_types_branches"); __PACKAGE__->add_columns( "debit_type_code", - { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 }, + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 64 }, "branchcode", { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, ); @@ -89,8 +89,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 10:47:58 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a4VtzV3gLrij1s0Czant2Q +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-04 07:57:30 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uVA4axnWjQjFOPqvM0hqyw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/AccountDebitType.pm b/Koha/Schema/Result/AccountDebitType.pm index 43b8583a41..69f49dabeb 100644 --- a/Koha/Schema/Result/AccountDebitType.pm +++ b/Koha/Schema/Result/AccountDebitType.pm @@ -27,13 +27,7 @@ __PACKAGE__->table("account_debit_types"); data_type: 'varchar' is_nullable: 0 - size: 16 - -=head2 default_amount - - data_type: 'decimal' - is_nullable: 1 - size: [28,6] + size: 64 =head2 description @@ -47,17 +41,31 @@ __PACKAGE__->table("account_debit_types"); default_value: 1 is_nullable: 0 +=head2 default_amount + + data_type: 'decimal' + is_nullable: 1 + size: [28,6] + +=head2 is_system + + data_type: 'tinyint' + default_value: 0 + is_nullable: 0 + =cut __PACKAGE__->add_columns( "code", - { data_type => "varchar", is_nullable => 0, size => 16 }, - "default_amount", - { data_type => "decimal", is_nullable => 1, size => [28, 6] }, + { data_type => "varchar", is_nullable => 0, size => 64 }, "description", { data_type => "varchar", is_nullable => 1, size => 200 }, "can_be_added_manually", { data_type => "tinyint", default_value => 1, is_nullable => 0 }, + "default_amount", + { data_type => "decimal", is_nullable => 1, size => [28, 6] }, + "is_system", + { data_type => "tinyint", default_value => 0, is_nullable => 0 }, ); =head1 PRIMARY KEY @@ -100,13 +108,13 @@ Related object: L __PACKAGE__->has_many( "accountlines", "Koha::Schema::Result::Accountline", - { "foreign.debit_type" => "self.code" }, + { "foreign.debit_type_code" => "self.code" }, { cascade_copy => 0, cascade_delete => 0 }, ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 10:47:58 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7DG78TAnHRei3U434Vuz9w +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-08 11:15:31 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:a3+iyqpi4NVpNjDkr9HM/w __PACKAGE__->add_columns( '+is_system' => { is_boolean => 1 } diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index 5082443f64..48b3dca958 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -69,12 +69,12 @@ __PACKAGE__->table("accountlines"); is_nullable: 1 size: 80 -=head2 debit_type +=head2 debit_type_code data_type: 'varchar' is_foreign_key: 1 is_nullable: 1 - size: 16 + size: 64 =head2 status @@ -150,8 +150,8 @@ __PACKAGE__->add_columns( { data_type => "longtext", is_nullable => 1 }, "accounttype", { data_type => "varchar", is_nullable => 1, size => 80 }, - "debit_type", - { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 16 }, + "debit_type_code", + { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 64 }, "status", { data_type => "varchar", is_nullable => 1, size => 16 }, "payment_type", @@ -261,7 +261,7 @@ __PACKAGE__->belongs_to( }, ); -=head2 debit_type +=head2 debit_type_code Type: belongs_to @@ -270,9 +270,9 @@ Related object: L =cut __PACKAGE__->belongs_to( - "debit_type", + "debit_type_code", "Koha::Schema::Result::AccountDebitType", - { code => "debit_type" }, + { code => "debit_type_code" }, { is_deferrable => 1, join_type => "LEFT", @@ -342,8 +342,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-11 10:47:58 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RKg4gDSu0WwJ1C9YmDv3pw +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-08 11:15:31 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1Vgkg0JR7RqmkniOmUoUhQ sub koha_objects_class { 'Koha::Account::Lines'; diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index c55c72bfc4..f74bc85aa0 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -179,7 +179,7 @@ foreach my $item (@items){ my $accountlines = Koha::Account::Lines->search( { itemnumber => $item->{itemnumber}, - accounttype => 'LOST', + debit_type_code => 'LOST', status => [ undef, { '<>' => 'RETURNED' } ], amountoutstanding => 0 }, diff --git a/installer/data/mysql/atomicupdate/bug_23049_debit.perl b/installer/data/mysql/atomicupdate/bug_23049_debit.perl index e59fdd936d..bc37c3e253 100644 --- a/installer/data/mysql/atomicupdate/bug_23049_debit.perl +++ b/installer/data/mysql/atomicupdate/bug_23049_debit.perl @@ -1,6 +1,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if ( CheckVersion($DBversion) ) { + # Adding account_debit_types $dbh->do( qq{ CREATE TABLE IF NOT EXISTS account_debit_types ( @@ -14,6 +15,7 @@ if ( CheckVersion($DBversion) ) { } ); + # Adding ac_debit_types_branches $dbh->do( qq{ CREATE TABLE IF NOT EXISTS ac_debit_types_branches ( @@ -25,6 +27,7 @@ if ( CheckVersion($DBversion) ) { } ); + # Populating account_debit_types $dbh->do( qq{ INSERT IGNORE INTO account_debit_types ( @@ -51,6 +54,7 @@ if ( CheckVersion($DBversion) ) { } ); + # Moving MANUAL_INV to account_debit_types $dbh->do( qq{ INSERT IGNORE INTO account_debit_types ( @@ -73,35 +77,43 @@ if ( CheckVersion($DBversion) ) { } ); - $dbh->do( - qq{ - ALTER IGNORE TABLE accountlines - ADD - debit_type varchar(64) DEFAULT NULL - AFTER - accounttype - } - ); + # Adding debit_type_code to accountlines + unless ( column_exists('accountlines', 'debit_type_code') ) { + $dbh->do( + qq{ + ALTER IGNORE TABLE accountlines + ADD + debit_type_code varchar(64) DEFAULT NULL + AFTER + accounttype + } + ); + } - $dbh->do( - qq{ - ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE - } - ); + # Linking debit_type_code in accountlines to code in account_debit_types + unless ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_debit_type' ) ) { + $dbh->do( + qq{ + ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE + } + ); + } + # Adding a check constraints to accountlines $dbh->do( qq{ - ALTER TABLE accountlines ADD CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type IS NOT NULL) + ALTER TABLE accountlines ADD CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type_code IS NOT NULL) } ); + # Populating debit_type_code $dbh->do( qq{ - UPDATE accountlines SET debit_type = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types) + UPDATE accountlines SET debit_type_code = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types) } ); - # Clean up MANUAL_INV + # Remove MANUAL_INV $dbh->do( qq{ DELETE FROM authorised_values WHERE category = 'MANUAL_INV' diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index b9466080dc..7ff520decc 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2661,7 +2661,7 @@ CREATE TABLE `accountlines` ( `amount` decimal(28,6) default NULL, `description` LONGTEXT, `accounttype` varchar(80) default NULL, - `debit_type` varchar(64) default NULL, + `debit_type_code` varchar(64) default NULL, `status` varchar(16) default NULL, `payment_type` varchar(80) default NULL, -- optional authorised value PAYMENT_TYPE `amountoutstanding` decimal(28,6) default NULL, @@ -2674,17 +2674,17 @@ CREATE TABLE `accountlines` ( PRIMARY KEY (`accountlines_id`), KEY `acctsborridx` (`borrowernumber`), KEY `timeidx` (`timestamp`), - KEY `debit_type` (`debit_type`), + KEY `debit_type_code` (`debit_type_code`), KEY `itemnumber` (`itemnumber`), KEY `branchcode` (`branchcode`), KEY `manager_id` (`manager_id`), - CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type IS NOT NULL), + CONSTRAINT `accountlines_check_type` CHECK (accounttype IS NOT NULL OR debit_type_code IS NOT NULL), CONSTRAINT `accountlines_ibfk_borrowers` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `accountlines_ibfk_items` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `accountlines_ibfk_borrowers_2` FOREIGN KEY (`manager_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `accountlines_ibfk_branches` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `accountlines_ibfk_registers` FOREIGN KEY (`register_id`) REFERENCES `cash_registers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt index 4c722d2542..8bfc483c34 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember-print.tt @@ -121,7 +121,7 @@ , [% account.description | html %] [% END %]   - [% IF ( account.itemnumber AND account.accounttype != 'OVERDUE' ) %] + [% IF ( account.itemnumber AND account.debit_type_code != 'OVERDUE' ) %] [% account.item.biblio.title | html %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt index 8dec77b827..e2883b371a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tt @@ -74,7 +74,7 @@ [% END %] - + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index 6ede0640b0..bc0cefa0d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -73,7 +73,7 @@ - + @@ -97,7 +97,7 @@ [% individual_description | html %] - [% accounttype | html %] + [% debit_type_code | html %] [% amount | format('%.2f') %] [% amountoutstanding | format('%.2f') %] @@ -161,7 +161,7 @@ - + @@ -179,7 +179,7 @@ Total amount outstanding:[% amountoutstanding | format('%.2f') %] [% description | html %] [% title | html %] - [% accounttype | html %] + [% debit_type_code | html %] [% amount | format('%.2f') %] [% amountoutstanding | format('%.2f') %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cash_register_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cash_register_stats.tt index 88f6a8dc73..1003d802d7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cash_register_stats.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cash_register_stats.tt @@ -4,6 +4,7 @@ [% USE Price %] [% USE ItemTypes %] [% SET footerjs = 1 %] +[% PROCESS 'accounts.inc' %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports [% IF ( do_it ) %]› Cash register statistics › Results[% ELSE %]› Cash register statistics[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -78,54 +79,17 @@ [% END %] - [% IF transaction_type == "F" %] - - [% ELSE %] - - [% END %] - - [% IF transaction_type == "FU" %] - - [% ELSE %] - - [% END %] - [% IF transaction_type == "PAY" %] [% ELSE %] [% END %] - [% IF transaction_type == "A" %] - - [% ELSE %] - - [% END %] - - [% IF transaction_type == "M" %] - - [% ELSE %] - - [% END %] - - [% IF transaction_type == "L" %] - - [% ELSE %] - - [% END %] - - [% IF transaction_type == "N" %] - - [% ELSE %] - - [% END %] - - [% FOREACH manualinv IN manualinv_types %] - [% value_manualinv = manualinv.authorised_value|truncate(5, '') %] - [% IF transaction_type == value_manualinv %] - + [% FOREACH debit_type IN debit_types %] + [% IF transaction_type == debit_type.code %] + [% ELSE %] - + [% END %] [% END %] @@ -197,32 +161,8 @@ [% IF loopresul.accounttype == "ACT" %] All payments to the library - [% ELSIF loopresul.accounttype == "C" || loopresul.accounttype == "CR" %] - Credit - [% ELSIF loopresul.accounttype == "FORW" || loopresul.accounttype == "W" %] - Write off - [% ELSIF loopresul.accounttype == "F" %] - Fine - [% ELSIF loopresul.accounttype == "FU" %] - Accruing fine - [% ELSIF loopresul.accounttype == "Pay" %] - Payment - [% ELSIF loopresul.accounttype == "A" %] - Account management fee - [% ELSIF loopresul.accounttype == "M" %] - Sundry - [% ELSIF loopresul.accounttype == "LOST" %] - Lost item - [% ELSIF loopresul.accounttype == "N" %] - New card [% ELSE %] - [% FOREACH manualinv IN manualinv_types %] - [% value_manualinv = manualinv.authorised_value|truncate(5, '') %] - [% IF loopresul.accounttype == value_manualinv %] - [% manualinv.authorised_value | html %] - [% LAST %] - [% END %] - [% END %] + [%- PROCESS account_type_description account=loopresul -%] [% END %] [% loopresul.note | html %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc index cdc23e46da..3e634215e6 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc @@ -170,31 +170,38 @@ [%- BLOCK account_type_description -%] - [%- SWITCH account.accounttype -%] - [%- CASE 'Pay' -%]Payment - [%- CASE 'VOID' -%]Voided - [%- CASE 'N' -%]New card - [%- CASE 'OVERDUE' -%]Fine - [%- CASE 'ACCOUNT' -%]Account creation fee - [%- CASE 'ACCOUNT_RENEW' -%]Account renewal fee - [%- CASE 'M' -%]Sundry - [%- CASE 'LOST' -%]Lost item - [%- CASE 'W' -%]Writeoff - [%- CASE 'HE' -%]Hold waiting too long - [%- CASE 'RENT' -%]Rental fee - [%- CASE 'RENT_DAILY' -%]Daily rental fee - [%- CASE 'RENT_RENEW' -%]Renewal of rental item - [%- CASE 'RENT_DAILT_RENEW' -%]Renewal of dailt rental item - [%- CASE 'FOR' -%]Forgiven - [%- CASE 'PF' -%]Lost item processing fee - [%- CASE 'PAY' -%]Payment - [%- CASE 'WO' -%]Writeoff - [%- CASE 'C' -%]Credit - [%- CASE 'LOST_RETURN' -%]Lost item fee refund - [%- CASE 'Res' -%]Hold fee - [%- CASE -%][% account.accounttype | html %] + + [%- IF account.accounttype -%] + [%- SWITCH account.accounttype -%] + [%- CASE 'Pay' -%]Payment + [%- CASE 'W' -%]Writeoff + [%- CASE 'FOR' -%]Forgiven + [%- CASE 'PAY' -%]Payment + [%- CASE 'WO' -%]Writeoff + [%- CASE 'C' -%]Credit + [%- CASE 'LOST_RETURN' -%]Lost item fee refund + [%- CASE -%][% account.accounttype | html %] + [%- END -%] + [%- ELSIF account.debit_type -%] + [%- SWITCH account.debit_type -%] + [%- CASE 'ACCOUNT' -%]Account creation fee + [%- CASE 'ACCOUNT_RENEW' -%]Account renewal fee + [%- CASE 'HE' -%]Hold waiting too long + [%- CASE 'LOST' -%]Lost item + [%- CASE 'M' -%]Sundry + [%- CASE 'N' -%]New card + [%- CASE 'OVERDUE' -%]Fine + [%- CASE 'PF' -%]Lost item processing fee + [%- CASE 'RENT' -%]Rental fee + [%- CASE 'RENT_DAILY' -%]Daily rental fee + [%- CASE 'RENT_RENEW' -%]Renewal of rental item + [%- CASE 'RENT_DAILY_RENEW' -%]Rewewal of daily rental item + [%- CASE 'Res' -%]Hold fee + [%- CASE -%][% account.debit_type.description | html %] + [%- END -%] [%- END -%] - [%- PROCESS account_status_description account=account -%] + [%- PROCESS account_status_description account=account -%] + [%- END -%] [%- BLOCK account_status_description -%] diff --git a/members/pay.pl b/members/pay.pl index ee2d5f23ff..a5467b2676 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -105,7 +105,7 @@ elsif ( $input->param('confirm_writeoff') ) { . "borrowernumber=$borrowernumber" . "&amount=" . $accountline->amount . "&amountoutstanding=" . $accountline->amountoutstanding - . "&accounttype=" . $accountline->accounttype + . "&debit_type_code=" . $accountline->debit_type_code . "&accountlines_id=" . $accountlines_id . "&change_given=" . $change_given . "&writeoff_individual=1" @@ -192,7 +192,7 @@ sub redirect_to_paycollect { "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"; $redirect .= q{&}; $redirect .= "$action=1"; - $redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 ); + $redirect .= get_for_redirect( 'debit_type_code', "debit_type_code$line_no", 0 ); $redirect .= get_for_redirect( 'amount', "amount$line_no", 1 ); $redirect .= get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 ); diff --git a/members/paycollect.pl b/members/paycollect.pl index bbd4b5a322..33be232e67 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -109,8 +109,8 @@ if ( $pay_individual || $writeoff_individual ) { } elsif ($writeoff_individual) { $template->param( writeoff_individual => 1 ); } - my $accounttype = $input->param('accounttype'); - $accountlines_id = $input->param('accountlines_id'); + my $debit_type_code = $input->param('debit_type_code'); + $accountlines_id = $input->param('accountlines_id'); my $amount = $input->param('amount'); my $amountoutstanding = $input->param('amountoutstanding'); my $itemnumber = $input->param('itemnumber'); @@ -118,7 +118,7 @@ if ( $pay_individual || $writeoff_individual ) { my $title = $input->param('title'); $total_due = $amountoutstanding; $template->param( - accounttype => $accounttype, + debit_type_code => $debit_type_code, accountlines_id => $accountlines_id, amount => $amount, amountoutstanding => $amountoutstanding, diff --git a/members/printinvoice.pl b/members/printinvoice.pl index 98ff1c50fd..ce16cea217 100755 --- a/members/printinvoice.pl +++ b/members/printinvoice.pl @@ -82,8 +82,8 @@ my %row = ( 'amount' => sprintf( "%.2f", $accountline->{'amount'} ), 'amountoutstanding' => sprintf( "%.2f", $accountline->{'amountoutstanding'} ), - accounttype => $accountline->{accounttype}, - 'note' => $accountline->{'note'}, + 'debit_type_code' => $accountline->{'debit_type_code'}, + 'note' => $accountline->{'note'}, ); my @account_offsets = Koha::Account::Offsets->search( { debit_id => $accountline_object->id } ); diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index 774c3b0e56..40407c686b 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -229,7 +229,7 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { my $desc = "staticfine"; my $query = "INSERT INTO accountlines - (borrowernumber,itemnumber,date,amount,description,accounttype,status,amountoutstanding) + (borrowernumber,itemnumber,date,amount,description,debit_type_code,status,amountoutstanding) VALUES (?,?,now(),?,?,'OVERDUE','RETURNED',?)"; my $sth2 = $dbh->prepare($query); $bigdebug and warn "query: $query\nw/ args: $borrowernumber, $itemnumber, $amount, $desc, $amount\n"; diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 8eac2478a6..30ef6c18c9 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -186,7 +186,7 @@ if ( $pending_checkouts->count ) { # Useless test { borrowernumber => $patron->borrowernumber, amountoutstanding => { '>' => 0 }, - accounttype => [ 'OVERDUE', 'LOST' ], + debit_type_code => [ 'OVERDUE', 'LOST' ], itemnumber => $issue->{itemnumber} }, ); @@ -196,7 +196,7 @@ if ( $pending_checkouts->count ) { # Useless test { borrowernumber => $patron->borrowernumber, amountoutstanding => { '>' => 0 }, - accounttype => { 'LIKE' => 'RENT_%' }, + debit_type_code => { 'LIKE' => 'RENT_%' }, itemnumber => $issue->{itemnumber} } ); diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index a41971d802..cbf54ff693 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -240,10 +240,10 @@ elsif ( $patron && ( $op eq 'checkout' || $op eq 'renew' ) ) { # Note that this should not be needed but since we do not have proper exception handling here we do it this way patron_has_hold_fee => Koha::Account::Lines->search( { - borrowernumber => $borrower->{borrowernumber}, - accounttype => 'Res', - description => $item->biblio->title, - date => $dtf->format_date(dt_from_string) + borrowernumber => $borrower->{borrowernumber}, + debit_type_code => 'Res', + description => $item->biblio->title, + date => $dtf->format_date(dt_from_string) } )->count, ); diff --git a/reports/cash_register_stats.pl b/reports/cash_register_stats.pl index 33922b803f..b4340c9f62 100755 --- a/reports/cash_register_stats.pl +++ b/reports/cash_register_stats.pl @@ -25,6 +25,9 @@ use C4::Circulation; use DateTime; use Koha::DateUtils; use Text::CSV::Encoded; +use List::Util qw/any/; + +use Koha::Account::DebitTypes; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -53,11 +56,8 @@ $template->param( my $fromDate = dt_from_string; my $toDate = dt_from_string; -my $query_manualinv = "SELECT id, authorised_value FROM authorised_values WHERE category = 'MANUAL_INV'"; -my $sth_manualinv = $dbh->prepare($query_manualinv) or die "Unable to prepare query" . $dbh->errstr; -$sth_manualinv->execute() or die "Unable to execute query " . $sth_manualinv->errstr; -my $manualinv_types = $sth_manualinv->fetchall_arrayref({}); - +my @debit_types = + Koha::Account::DebitTypes->search()->as_list; if ($do_it) { @@ -73,9 +73,12 @@ if ($do_it) { $whereTType = q{}; } elsif ($transaction_type eq 'ACT') { #Active $whereTType = q{ AND accounttype IN ('Pay','C') }; - } else { #Single transac type - if ($transaction_type eq 'FORW') { - $whereTType = q{ AND accounttype IN ('FOR','W') }; + } elsif ($transaction_type eq 'FORW') { + $whereTType = q{ AND accounttype IN ('FOR','W') }; + } else { + if ( any { $transaction_type eq $_->code } @debit_types ) { + $whereTType = q{ AND debit_type_code = ? }; + push @extra_params, $transaction_type; } else { $whereTType = q{ AND accounttype = ? }; push @extra_params, $transaction_type; @@ -93,7 +96,7 @@ if ($do_it) { SELECT round(amount,2) AS amount, description, bo.surname AS bsurname, bo.firstname AS bfirstname, m.surname AS msurname, m.firstname AS mfirstname, bo.cardnumber, br.branchname, bo.borrowernumber, - al.borrowernumber, DATE(al.date) as date, al.accounttype, al.amountoutstanding, al.note, + al.borrowernumber, DATE(al.date) as date, al.accounttype, al.debit_type_code, al.amountoutstanding, al.note, bi.title, bi.biblionumber, i.barcode, i.itype FROM accountlines al LEFT JOIN borrowers bo ON (al.borrowernumber = bo.borrowernumber) @@ -153,6 +156,7 @@ if ($do_it) { $row->{branchname}, $row->{date}, $row->{accounttype}, + $row->{debit_type}, $row->{note}, $row->{amount}, $row->{title}, @@ -182,7 +186,7 @@ $template->param( endDate => $toDate, transaction_type => $transaction_type, branchloop => Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed, - manualinv_types => $manualinv_types, + debit_types => \@debit_types, CGIsepChoice => GetDelimiterChoices, ); diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index d6fd47524d..8d91d22f85 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -26,6 +26,7 @@ use t::lib::TestBuilder; use t::lib::Mocks; use Koha::Account; +use Koha::Account::DebitTypes; use Koha::Account::Lines; use Koha::Account::Offsets; use Koha::Notice::Messages; @@ -92,7 +93,7 @@ my ($accountline) = Koha::Account::Lines->search( borrowernumber => $patron->{borrowernumber} } ); -is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' ); +is( $accountline->debit_type_code, $type, 'Debit type set correctly for manualinvoice' ); is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' ); ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' ); is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' ); @@ -373,7 +374,7 @@ subtest "Koha::Account::pay writeoff tests" => sub { my $writeoff = Koha::Account::Lines->find( $id ); - is( $writeoff->accounttype, 'W', 'Type is correct' ); + is( $writeoff->accounttype, 'W', 'Type is correct for writeoff' ); is( $writeoff->description, 'Writeoff', 'Description is correct' ); is( $writeoff->amount, '-42.000000', 'Amount is correct' ); }; @@ -583,39 +584,39 @@ subtest "C4::Accounts::chargelostitem tests" => sub { t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0'); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost or default when pref off"); ok( !$procfee, "No processing fee if no processing fee"); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' }); ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set"); ok( !$procfee, "No processing fee if no processing fee"); $lostfine->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); ok( !$procfee, "No processing fee if no processing fee"); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' }); ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); ok( !$procfee, "No processing fee if no processing fee"); $lostfine->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off"); ok( $procfee->amount == 8.16, "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" ); $procfee->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' }); ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set"); ok( $procfee->amount == 8.16, "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" ); @@ -623,15 +624,15 @@ subtest "C4::Accounts::chargelostitem tests" => sub { $procfee->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); ok( $procfee->amount == 2.04, "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" ); $procfee->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); ok( $procfee->amount == 2.04, "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" ); @@ -641,66 +642,66 @@ subtest "C4::Accounts::chargelostitem tests" => sub { t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost or default when pref on"); ok( !$procfee, "No processing fee if no processing fee"); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, debit_type_code => 'PF' }); is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); ok( !$procfee, "No processing fee if no processing fee"); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' }); is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on"); ok( !$procfee, "No processing fee if no processing fee"); $lostfine->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, debit_type_code => 'PF' }); is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set"); ok( !$procfee, "No processing fee if no processing fee"); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' }); ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on"); is( $procfee->amount, "8.160000", "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" ); $procfee->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, debit_type_code => 'PF' }); is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); is( $procfee->amount, "8.160000", "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_3, "Processing fee issue id is correct" ); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on"); is( $procfee->amount, "2.040000", "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" ); $lostfine->delete(); $procfee->delete(); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set"); is( $procfee->amount, "2.040000", "Processing fee if processing fee"); is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" ); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); - my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - my $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + my $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); ok( $lostfines->count == 1 , "Lost fine cannot be double charged for the same issue_id"); ok( $procfees->count == 1, "Processing fee cannot be double charged for the same issue_id"); MarkIssueReturned($cli_borrowernumber, $cli_itemnumber4); $cli_issue_id_4X = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id}; C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); - $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfees = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); ok( $lostfines->count == 2 , "Lost fine can be charged twice for the same item if they are distinct issue_id's"); ok( $procfees->count == 2, "Processing fee can be charged twice for the same item if they are distinct issue_id's"); $lostfines->delete(); @@ -714,7 +715,7 @@ subtest "C4::Accounts::chargelostitem tests" => sub { C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, '1.99', "Perdedor"); # Lost Item Fee - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); ok($lostfine, "Lost fine created"); is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly"); is($lostfine->issue_id, $cli_issue_id_4X, "Lost fine issue_id set correctly"); @@ -723,7 +724,7 @@ subtest "C4::Accounts::chargelostitem tests" => sub { is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly"); # Processing Fee - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); ok($procfee, "Processing fee created"); is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly"); is($procfee->issue_id, $cli_issue_id_4X, "Processing fee issue_id set correctly"); @@ -741,16 +742,16 @@ subtest "C4::Accounts::chargelostitem tests" => sub { t::lib::Mocks::mock_preference( 'FinesLog', 0 ); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No logs were added' ); $lostfine->delete(); $procfee->delete(); t::lib::Mocks::mock_preference( 'FinesLog', 1 ); C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); - $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' }); - $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); + $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'LOST' }); + $procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, debit_type_code => 'PF' }); is( $schema->resultset('ActionLog')->count(), $action_logs + 2, 'Logs were added' ); $lostfine->delete(); $procfee->delete(); @@ -786,7 +787,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub { interface => 'commandline' } ); - Koha::Account::DebitTypes->new( + Koha::Account::DebitTypes->find_or_create( { code => 'Copie', description => 'Fee for copie', @@ -798,7 +799,7 @@ subtest "Koha::Account::non_issues_charges tests" => sub { borrowernumber => $patron->borrowernumber, date => $today, description => 'a Manual invoice fee', - debit_type => 'Copie', + debit_type_code => 'Copie', amountoutstanding => $manual, interface => 'commandline' } diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index b7dca93851..5705e8ec13 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -911,7 +911,7 @@ subtest "CanBookBeRenewed tests" => sub { ); my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next(); - is( $line->accounttype, 'OVERDUE', 'Account line type is OVERDUE' ); + is( $line->debit_type_code, 'OVERDUE', 'Account line type is OVERDUE' ); is( $line->status, 'UNRETURNED', 'Account line status is UNRETURNED' ); is( $line->amountoutstanding, '15.000000', 'Account line amount outstanding is 15.00' ); is( $line->amount, '15.000000', 'Account line amount is 15.00' ); @@ -927,7 +927,7 @@ subtest "CanBookBeRenewed tests" => sub { LostItem( $item_1->itemnumber, 'test', 1 ); $line = Koha::Account::Lines->find($line->id); - is( $line->accounttype, 'OVERDUE', 'Account type remains as OVERDUE' ); + is( $line->debit_type_code, 'OVERDUE', 'Account type remains as OVERDUE' ); isnt( $line->status, 'UNRETURNED', 'Account status correctly changed from UNRETURNED to RETURNED' ); my $item = Koha::Items->find($item_1->itemnumber); @@ -2124,7 +2124,7 @@ subtest '_FixAccountForLostAndReturned' => sub { LostItem( $item->itemnumber, 1 ); my $processing_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } ); is( $processing_fee_lines->count, 1, 'Only one processing fee produced' ); my $processing_fee_line = $processing_fee_lines->next; is( $processing_fee_line->amount + 0, @@ -2133,7 +2133,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $processfee_amount, 'The right PF amountoutstanding is generated' ); my $lost_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } ); is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); my $lost_fee_line = $lost_fee_lines->next; is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); @@ -2159,7 +2159,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $lost_fee_line->discard_changes; # reload from DB is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); - is( $lost_fee_line->accounttype, + is( $lost_fee_line->debit_type_code, 'LOST', 'Lost fee now still has account type of LOST' ); is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); @@ -2188,7 +2188,7 @@ subtest '_FixAccountForLostAndReturned' => sub { LostItem( $item->itemnumber, 1 ); my $processing_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } ); is( $processing_fee_lines->count, 1, 'Only one processing fee produced' ); my $processing_fee_line = $processing_fee_lines->next; is( $processing_fee_line->amount + 0, @@ -2197,7 +2197,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $processfee_amount, 'The right PF amountoutstanding is generated' ); my $lost_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } ); is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); my $lost_fee_line = $lost_fee_lines->next; is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); @@ -2227,7 +2227,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $lost_fee_line->discard_changes; is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); - is( $lost_fee_line->accounttype, + is( $lost_fee_line->debit_type_code, 'LOST', 'Lost fee now still has account type of LOST' ); is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); @@ -2258,7 +2258,7 @@ subtest '_FixAccountForLostAndReturned' => sub { LostItem( $item->itemnumber, 1 ); my $processing_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } ); is( $processing_fee_lines->count, 1, 'Only one processing fee produced' ); my $processing_fee_line = $processing_fee_lines->next; is( $processing_fee_line->amount + 0, @@ -2267,7 +2267,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $processfee_amount, 'The right PF amountoutstanding is generated' ); my $lost_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } ); is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); my $lost_fee_line = $lost_fee_lines->next; is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); @@ -2283,7 +2283,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $lost_fee_line->discard_changes; is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); - is( $lost_fee_line->accounttype, + is( $lost_fee_line->debit_type_code, 'LOST', 'Lost fee now still has account type of LOST' ); is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); @@ -2311,7 +2311,7 @@ subtest '_FixAccountForLostAndReturned' => sub { LostItem( $item->itemnumber, 1 ); my $processing_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'PF' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'PF' } ); is( $processing_fee_lines->count, 1, 'Only one processing fee produced' ); my $processing_fee_line = $processing_fee_lines->next; is( $processing_fee_line->amount + 0, @@ -2320,7 +2320,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $processfee_amount, 'The right PF amountoutstanding is generated' ); my $lost_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); + { borrowernumber => $patron->id, itemnumber => $item->itemnumber, debit_type_code => 'LOST' } ); is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); my $lost_fee_line = $lost_fee_lines->next; is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); @@ -2367,7 +2367,7 @@ subtest '_FixAccountForLostAndReturned' => sub { $lost_fee_line->discard_changes; is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); - is( $lost_fee_line->accounttype, + is( $lost_fee_line->debit_type_code, 'LOST', 'Lost fee now still has account type of LOST' ); is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); @@ -2424,7 +2424,7 @@ subtest '_FixAccountForLostAndReturned' => sub { LostItem( $item_id, 1 ); my $lost_fee_lines = Koha::Account::Lines->search( - { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); + { borrowernumber => $patron->id, itemnumber => $item_id, debit_type_code => 'LOST' } ); is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); my $lost_fee_line = $lost_fee_lines->next; is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); @@ -2461,7 +2461,7 @@ subtest '_FixAccountForLostAndReturned' => sub { is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (LOST_RETURN)' ); - my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'OVERDUE', status => 'UNRETURNED' })->next; + my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, debit_type_code => 'OVERDUE', status => 'UNRETURNED' })->next; is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' ); }; }; @@ -2491,7 +2491,7 @@ subtest '_FixOverduesOnReturn' => sub { my $accountline = Koha::Account::Line->new( { borrowernumber => $patron->{borrowernumber}, - accounttype => 'OVERDUE', + debit_type_code => 'OVERDUE', status => 'UNRETURNED', itemnumber => $item->itemnumber, amount => 99.00, @@ -2511,7 +2511,7 @@ subtest '_FixOverduesOnReturn' => sub { ## Run again, with exemptfine enabled $accountline->set( { - accounttype => 'OVERDUE', + debit_type_code => 'OVERDUE', status => 'UNRETURNED', amountoutstanding => 99.00, } @@ -2558,7 +2558,7 @@ subtest '_FixAccountForLostAndReturned returns undef if patron is deleted' => su my $accountline = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => 'L', + debit_type_code => 'LOST', status => undef, itemnumber => $item->itemnumber, amount => 99.00, @@ -3033,12 +3033,12 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { is( $lines->count, 2 ); my $line = $lines->next; - is( $line->accounttype, 'RENT', 'The issue of item with issuing charge generates an accountline of the correct type' ); + is( $line->debit_type_code, 'RENT', 'The issue of item with issuing charge generates an accountline of the correct type' ); is( $line->branchcode, $library->id, 'AddIssuingCharge correctly sets branchcode' ); is( $line->description, '', 'AddIssue does not set a hardcoded description for the accountline' ); $line = $lines->next; - is( $line->accounttype, 'RENT_RENEW', 'The renewal of item with issuing charge generates an accountline of the correct type' ); + is( $line->debit_type_code, 'RENT_RENEW', 'The renewal of item with issuing charge generates an accountline of the correct type' ); is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); is( $line->description, '', 'AddRenewal does not set a hardcoded description for the accountline' ); diff --git a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t index 84868efc88..ed15c4fd18 100644 --- a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t +++ b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t @@ -87,7 +87,7 @@ is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->id })->next(); is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" ); -is( $accountline->accounttype, "LOST", "Account type is LOST" ); +is( $accountline->debit_type_code, "LOST", "Debit type is LOST" ); my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next(); is( $offset->type, 'Lost Item', 'Got correct offset type' ); diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t index f50638a789..41f7736bec 100644 --- a/t/db_dependent/Circulation/Returns.t +++ b/t/db_dependent/Circulation/Returns.t @@ -277,7 +277,7 @@ subtest 'Handle ids duplication' => sub { my $issue_id = $original_checkout->issue_id; my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id }); is( $account_lines->count, 1, '1 account line should exist for this issue_id' ); - is( $account_lines->next->accounttype, 'RENT', 'patron has been charged the rentalcharge' ); + is( $account_lines->next->debit_type_code, 'RENT', 'patron has been charged the rentalcharge' ); $account_lines->delete; # Create an existing entry in old_issue diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index a757f5247a..dad70d445e 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -343,7 +343,7 @@ subtest 'add_debit() tests' => sub { 'No log was added' ); is( - $line_1->accounttype, + $line_1->debit_type_code, $Koha::Account::account_type_debit->{'rent'}, 'Account type is correctly set' ); @@ -370,7 +370,7 @@ subtest 'add_debit() tests' => sub { 'Log was added' ); is( - $line_2->accounttype, + $line_2->debit_type_code, $Koha::Account::account_type_debit->{'rent'}, 'Account type is correctly set' ); @@ -657,7 +657,7 @@ subtest 'pay() handles lost items when paying a specific lost fee' => sub { borrowernumber => $patron->id, itemnumber => $item->id, date => \'NOW()', - accounttype => 'LOST', + debit_type_code => 'LOST', interface => 'cli', amount => '1', amountoutstanding => '1', @@ -730,7 +730,7 @@ subtest 'pay() handles lost items when paying by amount ( not specifying the los borrowernumber => $patron->id, itemnumber => $item->id, date => \'NOW()', - accounttype => 'LOST', + debit_type_code => 'LOST', interface => 'cli', amount => '1', amountoutstanding => '1', @@ -801,7 +801,7 @@ subtest 'Koha::Account::Line::apply() handles lost items' => sub { borrowernumber => $patron->id, itemnumber => $item->id, date => \'NOW()', - accounttype => 'LOST', + debit_type_code => 'LOST', interface => 'cli', amount => '1', amountoutstanding => '1', diff --git a/t/db_dependent/Koha/Account/DebitTypes.t b/t/db_dependent/Koha/Account/DebitTypes.t index fee8eadb04..c6b63be54a 100644 --- a/t/db_dependent/Koha/Account/DebitTypes.t +++ b/t/db_dependent/Koha/Account/DebitTypes.t @@ -52,8 +52,6 @@ my $new_debit_type_2 = Koha::Account::DebitType->new( } )->store; -my $defaults = Koha::Account::DebitType::defaults; -my $number_of_system_types = scalar @{$defaults}; my $retrieved_debit_types_all = Koha::Account::DebitTypes->search(); try { $retrieved_debit_types_all->delete; diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 7f9dcf01e2..9a0a101eef 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -46,7 +46,7 @@ subtest 'patron() tests' => sub { my $line = Koha::Account::Line->new( { borrowernumber => $patron->{borrowernumber}, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, interface => 'commandline', @@ -86,7 +86,7 @@ subtest 'item() tests' => sub { { borrowernumber => $patron->{borrowernumber}, itemnumber => $item->itemnumber, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, interface => 'commandline', @@ -115,7 +115,7 @@ subtest 'total_outstanding() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, amountoutstanding => 10, @@ -125,7 +125,7 @@ subtest 'total_outstanding() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, amountoutstanding => 10, @@ -138,7 +138,7 @@ subtest 'total_outstanding() tests' => sub { my $credit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => -10, amountoutstanding => -10, @@ -151,7 +151,7 @@ subtest 'total_outstanding() tests' => sub { my $credit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => -10, amountoutstanding => -10, @@ -164,7 +164,7 @@ subtest 'total_outstanding() tests' => sub { my $credit_3 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => -100, amountoutstanding => -100, @@ -195,7 +195,7 @@ subtest 'is_credit() and is_debit() tests' => sub { my $debit = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, interface => 'commandline', @@ -220,7 +220,7 @@ subtest 'apply() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, amountoutstanding => 10, @@ -230,7 +230,7 @@ subtest 'apply() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 100, amountoutstanding => 100, @@ -293,7 +293,7 @@ subtest 'apply() tests' => sub { my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' }); my $debit_3 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 100, amountoutstanding => 100, @@ -343,7 +343,7 @@ subtest 'Keep account info when related patron, staff or item is deleted' => sub borrowernumber => $patron->borrowernumber, manager_id => $staff->borrowernumber, itemnumber => $item->itemnumber, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, interface => 'commandline', @@ -382,7 +382,7 @@ subtest 'adjust() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "RETURNED", amount => 10, amountoutstanding => 10, @@ -392,7 +392,7 @@ subtest 'adjust() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "OVERDUE", + debit_type_code => "OVERDUE", status => "UNRETURNED", amount => 100, amountoutstanding => 100, @@ -406,7 +406,7 @@ subtest 'adjust() tests' => sub { qr/Update type not recognised/, 'Exception thrown for unrecognised type'; throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) } - qr/Update type not allowed on this accounttype/, + qr/Update type not allowed on this debit_type/, 'Exception thrown for type conflict'; # Increment an unpaid fine diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index eea40c382d..adfcb60898 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -112,9 +112,9 @@ subtest 'add_enrolment_fee_if_needed() tests' => sub { my @debits = $account->outstanding_debits; is( scalar @debits, 3, '3 enrolment fees' ); - is( $debits[0]->accounttype, 'ACCOUNT', 'Account type set correctly' ); - is( $debits[1]->accounttype, 'ACCOUNT', 'Account type set correctly' ); - is( $debits[2]->accounttype, 'ACCOUNT_RENEW', 'Account type set correctly' ); + is( $debits[0]->debit_type_code, 'ACCOUNT', 'Account type set correctly' ); + is( $debits[1]->debit_type_code, 'ACCOUNT', 'Account type set correctly' ); + is( $debits[2]->debit_type_code, 'ACCOUNT_RENEW', 'Account type set correctly' ); $schema->storage->txn_rollback; }; diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 33aa3d9f76..804d2c061b 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -739,7 +739,7 @@ subtest 'ChargeReserveFee tests' => sub { is( ref($line), 'Koha::Account::Line' , 'Returns a Koha::Account::Line object'); ok( $line->is_debit, 'Generates a debit line' ); - is( $line->accounttype, 'Res' , 'generates Res accounttype'); + is( $line->debit_type_code, 'Res' , 'generates Res debit_type'); is( $line->borrowernumber, $patron->id , 'generated line belongs to the passed patron'); is( $line->amount, $fee , 'amount set correctly'); is( $line->amountoutstanding, $fee , 'amountoutstanding set correctly'); diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t index e4a8f4d09c..53cebb3e25 100644 --- a/t/db_dependent/api/v1/patrons_accounts.t +++ b/t/db_dependent/api/v1/patrons_accounts.t @@ -65,7 +65,7 @@ subtest 'get_balance() tests' => sub { date => \'NOW()', amount => 50, description => "A description", - accounttype => "N", # New card + debit_type_code => "N", # New card amountoutstanding => 50, manager_id => $patron->borrowernumber, branchcode => $library->id, @@ -80,7 +80,7 @@ subtest 'get_balance() tests' => sub { date => \'NOW()', amount => 50.01, description => "A description", - accounttype => "N", # New card + debit_type_code => "N", # New card amountoutstanding => 50.01, manager_id => $patron->borrowernumber, branchcode => $library->id, @@ -183,7 +183,7 @@ subtest 'add_credit() tests' => sub { date => \'NOW()', amount => 10, description => "A description", - accounttype => "N", # New card + debit_type_code => "N", # New card amountoutstanding => 10, manager_id => $patron->borrowernumber, interface => 'test', @@ -194,7 +194,7 @@ subtest 'add_credit() tests' => sub { date => \'NOW()', amount => 15, description => "A description", - accounttype => "N", # New card + debit_type_code => "N", # New card amountoutstanding => 15, manager_id => $patron->borrowernumber, interface => 'test', @@ -221,7 +221,7 @@ subtest 'add_credit() tests' => sub { date => \'NOW()', amount => 100, description => "A description", - accounttype => "N", # New card + debit_type_code => "N", # New card amountoutstanding => 100, manager_id => $patron->borrowernumber, interface => 'test', -- 2.20.1