From 95ec14c6d22b793963b4f6502cbf1e310517129b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 16 Jul 2018 14:08:17 +0000 Subject: [PATCH] Bug 19166: (follow-up) Adjust table and files and QA issues Move to aqinvoice_adjustment Move to Koha::Acquisition::Invoice::Adjustments Test if variable exists before count Signed-off-by: Martin Renvoize --- C4/Budgets.pm | 6 +-- Koha/Schema/Result/Aqbudget.pm | 19 +++++++++- Koha/Schema/Result/Aqinvoice.pm | 19 +++++++++- acqui/invoice.pl | 10 ++--- acqui/ordered.pl | 4 +- acqui/spent.pl | 4 +- .../data/mysql/atomicupdate/bug_19166.perl | 6 +-- installer/data/mysql/kohastructure.sql | 38 +++++++++---------- .../prog/en/modules/acqui/invoice.tt | 2 +- .../prog/en/modules/acqui/ordered.tt | 2 +- .../prog/en/modules/acqui/spent.tt | 4 +- t/db_dependent/Budgets.t | 12 +++--- 12 files changed, 78 insertions(+), 48 deletions(-) diff --git a/C4/Budgets.pm b/C4/Budgets.pm index 8e7cc8669a..e0b7dc1ee3 100644 --- a/C4/Budgets.pm +++ b/C4/Budgets.pm @@ -22,7 +22,7 @@ use strict; use C4::Context; use Koha::Database; use Koha::Patrons; -use Koha::InvoiceAdjustments; +use Koha::Acquisition::Invoice::Adjustments; use C4::Debug; use vars qw(@ISA @EXPORT); @@ -350,7 +350,7 @@ sub GetBudgetSpent { my ($shipmentcost_sum) = $sth->fetchrow_array; $sum += $shipmentcost_sum; - my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' }); + my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, closedate => { '!=' => undef } },{ join => 'invoiceid' }); while ( my $adj = $adjustments->next ){ $sum += $adj->adjustment; } @@ -371,7 +371,7 @@ sub GetBudgetOrdered { $sth->execute($budget_id); my $sum = 0 + $sth->fetchrow_array; - my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); + my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $budget_id, encumber_open => 1, closedate => undef},{ join => 'invoiceid' }); while ( my $adj = $adjustments->next ){ $sum += $adj->adjustment; } diff --git a/Koha/Schema/Result/Aqbudget.pm b/Koha/Schema/Result/Aqbudget.pm index 68a93afbb6..1cdb64c31d 100644 --- a/Koha/Schema/Result/Aqbudget.pm +++ b/Koha/Schema/Result/Aqbudget.pm @@ -212,6 +212,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 aqinvoice_adjustments + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "aqinvoice_adjustments", + "Koha::Schema::Result::AqinvoiceAdjustment", + { "foreign.budget_id" => "self.budget_id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 aqinvoices Type: has_many @@ -283,8 +298,8 @@ Composing rels: L -> borrowernumber __PACKAGE__->many_to_many("borrowernumbers", "aqbudgetborrowers", "borrowernumber"); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9MY8aD6YBjuLy8c7tDnZeg +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-16 13:50:45 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zB7ox8a4KdDGq5fsbQfLGQ # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/Koha/Schema/Result/Aqinvoice.pm b/Koha/Schema/Result/Aqinvoice.pm index 3ec1475950..b760947123 100644 --- a/Koha/Schema/Result/Aqinvoice.pm +++ b/Koha/Schema/Result/Aqinvoice.pm @@ -113,6 +113,21 @@ __PACKAGE__->set_primary_key("invoiceid"); =head1 RELATIONS +=head2 aqinvoice_adjustments + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "aqinvoice_adjustments", + "Koha::Schema::Result::AqinvoiceAdjustment", + { "foreign.invoiceid" => "self.invoiceid" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 aqorders Type: has_many @@ -184,8 +199,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SAUxWSdpMJK4atxhfgCAGg +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-16 13:50:45 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mpdxTbkz/8WInG5Wp4q7Ug # You can replace this text with custom content, and it will be preserved on regeneration diff --git a/acqui/invoice.pl b/acqui/invoice.pl index 4fe4b224d8..bdf9485a87 100755 --- a/acqui/invoice.pl +++ b/acqui/invoice.pl @@ -38,7 +38,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::DateUtils; use Koha::Misc::Files; -use Koha::InvoiceAdjustments; +use Koha::Acquisition::Invoice::Adjustments; my $input = new CGI; my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user( @@ -111,7 +111,7 @@ elsif ( $op && $op eq 'delete' ) { } elsif ( $op && $op eq 'del_adj' ) { my $adjustment_id = $input->param('adjustment_id'); - my $del_adj = Koha::InvoiceAdjustments->find( $adjustment_id ); + my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id ); $del_adj->delete() if ($del_adj); } elsif ( $op && $op eq 'mod_adj' ) { @@ -126,7 +126,7 @@ elsif ( $op && $op eq 'mod_adj' ) { for( my $i=0; $i < scalar @adjustment; $i++ ){ if( $adjustment_id[$i] eq 'new' ){ next unless ( $adjustment[$i] || $reason[$i] ); - my $new_adj = Koha::InvoiceAdjustment->new({ + my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({ invoiceid => $invoiceid, adjustment => $adjustment[$i], reason => $reason[$i], @@ -137,7 +137,7 @@ elsif ( $op && $op eq 'mod_adj' ) { $new_adj->store(); } else { - my $old_adj = Koha::InvoiceAdjustments->find( $adjustment_id[$i] ); + my $old_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id[$i] ); unless ( $old_adj->adjustment == $adjustment[$i] && $old_adj->reason eq $reason[$i] && $old_adj->budget_id == $budget_id[$i] && $old_adj->encumber_open == $e_open{$adjustment_id[$i]} && $old_adj->note eq $note[$i] ){ $old_adj->timestamp(undef); $old_adj->adjustment( $adjustment[$i] ); @@ -201,7 +201,7 @@ foreach my $budget (@$budgets) { push @budgets_loop, \%line; } -my $adjustments = Koha::InvoiceAdjustments->search({ invoiceid => $details->{'invoiceid'} }); +my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} }); if ( $adjustments ) { $template->param( adjustments => $adjustments ); } $template->param( diff --git a/acqui/ordered.pl b/acqui/ordered.pl index c78ac664b9..e39349092e 100755 --- a/acqui/ordered.pl +++ b/acqui/ordered.pl @@ -32,7 +32,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; use C4::Output; -use Koha::InvoiceAdjustments; +use Koha::Acquisition::Invoice::Adjustments; my $dbh = C4::Context->dbh; my $input = new CGI; @@ -97,7 +97,7 @@ while ( my $data = $sth->fetchrow_hashref ) { } } -my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } ); +my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } ); while ( my $adj = $adjustments->next ){ $total += $adj->adjustment; } diff --git a/acqui/spent.pl b/acqui/spent.pl index dfc5f8530f..988b8c28ee 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -34,7 +34,7 @@ use C4::Auth; use C4::Output; use Modern::Perl; use CGI qw ( -utf8 ); -use Koha::InvoiceAdjustments; +use Koha::Acquisition::Invoice::Adjustments; my $dbh = C4::Context->dbh; my $input = new CGI; @@ -119,7 +119,7 @@ while (my $data = $sth->fetchrow_hashref) { } $sth->finish; -my $adjustments = Koha::InvoiceAdjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } ); +my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } ); while ( my $adj = $adjustments->next ){ $total += $adj->adjustment; } diff --git a/installer/data/mysql/atomicupdate/bug_19166.perl b/installer/data/mysql/atomicupdate/bug_19166.perl index 6088e995ad..5a3794ebe3 100644 --- a/installer/data/mysql/atomicupdate/bug_19166.perl +++ b/installer/data/mysql/atomicupdate/bug_19166.perl @@ -1,7 +1,7 @@ $DBversion = 'XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { $dbh->do( " - CREATE TABLE IF NOT EXISTS invoice_adjustments ( + CREATE TABLE IF NOT EXISTS aqinvoice_adjustments ( adjustment_id int(11) NOT NULL AUTO_INCREMENT, invoiceid int(11) NOT NULL, adjustment decimal(28,6), @@ -11,8 +11,8 @@ if( CheckVersion( $DBversion ) ) { encumber_open smallint(1) NOT NULL default 1, timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (adjustment_id), - CONSTRAINT invoice_adjustments_fk_invoiceid FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT invoice_adjustments_fk_budget_id FOREIGN KEY (budget_id) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT aqinvoice_adjustments_fk_invoiceid FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT aqinvoice_adjustments_fk_budget_id FOREIGN KEY (budget_id) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci " ); $dbh->do("INSERT IGNORE INTO authorised_value_categories (category_name) VALUES ('ADJ_REASON')"); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 750b9494af..78fe7ff916 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -823,25 +823,6 @@ CREATE TABLE `import_items` ( KEY `branchcode` (`branchcode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; --- --- Table structure for table 'invoice_adjustments' --- - -DROP TABLE IF EXISTS invoice_adjustments; -CREATE TABLE IF NOT EXISTS invoice_adjustments ( - adjustment_id int(11) NOT NULL AUTO_INCREMENT, -- primary key for adjustments - invoiceid int(11) NOT NULL, -- foreign key to link an adjustment to an invoice - adjustment decimal(28,6), -- amount of adjustment - reason varchar(80) default NULL, -- reason for adjustment defined by authorised values in ADJ_REASON category - note mediumtext default NULL, -- text to explain adjustment - budget_id int(11) default NULL, -- optional link to budget to apply adjustment to - encumber_open smallint(1) NOT NULL default 1, -- whether or not to encumber the finds when invoice is still open, 1 = yes, 0 = no - timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- timestamp of last adjustment to adjustment - PRIMARY KEY (adjustment_id), - CONSTRAINT invoice_adjustments_fk_invoiceid FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT invoice_adjustments_fk_budget_id FOREIGN KEY (budget_id) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -- -- Table structure for table `issuingrules` -- @@ -3159,6 +3140,25 @@ CREATE TABLE aqinvoices ( CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +-- +-- Table structure for table 'aqinvoice_adjustments' +-- + +DROP TABLE IF EXISTS aqinvoice_adjustments; +CREATE TABLE IF NOT EXISTS aqinvoice_adjustments ( + adjustment_id int(11) NOT NULL AUTO_INCREMENT, -- primary key for adjustments + invoiceid int(11) NOT NULL, -- foreign key to link an adjustment to an invoice + adjustment decimal(28,6), -- amount of adjustment + reason varchar(80) default NULL, -- reason for adjustment defined by authorised values in ADJ_REASON category + note mediumtext default NULL, -- text to explain adjustment + budget_id int(11) default NULL, -- optional link to budget to apply adjustment to + encumber_open smallint(1) NOT NULL default 1, -- whether or not to encumber the finds when invoice is still open, 1 = yes, 0 = no + timestamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, -- timestamp of last adjustment to adjustment + PRIMARY KEY (adjustment_id), + CONSTRAINT aqinvoice_adjustments_fk_invoiceid FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT aqinvoice_adjustments_fk_budget_id FOREIGN KEY (budget_id) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + -- -- Table structure for table `aqorders` -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt index 16b8d0285f..85a23c59b8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt @@ -92,7 +92,7 @@
- [% IF (adjustments.count > 0) %] + [% IF (adjustments && adjustments.count > 0) %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt index 174edb84db..f1418cd343 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt @@ -73,7 +73,7 @@ [% END %] - [% IF ( adjustments.count > 0 ) %] + [% IF ( adjustments && adjustments.count > 0 ) %] [% FOREACH adjustment IN adjustments %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt index bf4113694d..b045c5324a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt @@ -77,7 +77,7 @@ [% END %] - [% IF shipmentcosts.size || ( adjustments.count > 0 ) %] + [% IF shipmentcosts.size || ( adjustments && adjustments.count > 0 ) %] @@ -92,7 +92,7 @@ [% END %] [% END %] - [% IF ( adjustments.count > 0 ) %] + [% IF ( adjustments && adjustments.count > 0 ) %] [% FOREACH adjustment IN adjustments %] diff --git a/t/db_dependent/Budgets.t b/t/db_dependent/Budgets.t index 9c748952b4..e28e20cb45 100755 --- a/t/db_dependent/Budgets.t +++ b/t/db_dependent/Budgets.t @@ -821,7 +821,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { is( $ordered, 0, "New budget, no orders/invoices, should be nothing ordered"); my $inv_adj_1 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice->{invoiceid}, adjustment => 3, @@ -836,7 +836,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { is( $ordered, 0, "After adding invoice adjustment on open invoice not encumbered, should be nothing ordered"); my $inv_adj_2 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice->{invoiceid}, adjustment => 3, @@ -857,7 +857,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { } }); my $inv_adj_3 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice_2->{invoiceid}, adjustment => 3, @@ -866,7 +866,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { } }); my $inv_adj_4 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice_2->{invoiceid}, adjustment => 3, @@ -887,7 +887,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { } }); my $inv_adj_5 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice->{invoiceid}, adjustment => 3, @@ -896,7 +896,7 @@ subtest 'GetBudgetSpent and GetBudgetOrdered' => sub { } }); my $inv_adj_6 = $builder->build({ - source => 'InvoiceAdjustment', + source => 'AqinvoiceAdjustment', value => { invoiceid => $invoice_2->{invoiceid}, adjustment => 3, -- 2.17.1
Id
Sub total [% subtotal %]