From 6de08330cb8a7c63a66433319761d9bbed60e46e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 21 Mar 2019 12:29:08 +0000 Subject: [PATCH] Bug 22541: Use invoicenumber and link to invoice on spent and ordered pages To test: 1 - Find a vendor in acquisitions 2 - Click 'receive shipment' 3 - Create an invoice 4 - Click 'Finish receiving' 5 - Add an adjustment that encumbers while open and update adjustments 6 - Go to acqui-home and click on the ordered total for the fund with the adjustment 7 - Note the invoice adjustment shows the invoice id and does not link 8 - Add another invoice and another adjustment, but close the invoice this time 9 - Go to acqui-home and click on the spent total for the fund with the adjustment 10 - Note the invoice adjustment shows the invoice id and does not link 11 - Apply patch 12 - Visit the spent and ordered pages and note the adjustments show invoicenumber and are links 13 - prove -v t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t Signed-off-by: Liz Rea --- C4/Acquisition.pm | 1 - Koha/Acquisition/Invoice/Adjustment.pm | 15 +++++++++++++++ acqui/ordered.pl | 4 ++-- acqui/spent.pl | 4 ++-- circ/ysearch.pl | 1 + koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt | 6 +++++- koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt | 12 ++++++++++-- t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t | 10 +++++++++- 8 files changed, 44 insertions(+), 9 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4bf8c17ae7..771aa0e4c9 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1889,7 +1889,6 @@ cancelled. sub DelOrder { my ( $bibnum, $ordernumber, $delete_biblio, $reason ) = @_; - my $error; my $dbh = C4::Context->dbh; my $query = " diff --git a/Koha/Acquisition/Invoice/Adjustment.pm b/Koha/Acquisition/Invoice/Adjustment.pm index e3d0bc206c..4d87a94ad9 100644 --- a/Koha/Acquisition/Invoice/Adjustment.pm +++ b/Koha/Acquisition/Invoice/Adjustment.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Acquisition::Invoice; use base qw(Koha::Object); @@ -33,6 +34,20 @@ Koha::Acquisition::Invoice::Adjustment - Koha Invoice Adjustment class =cut +=head3 invoice + +my $invoice = $adjustment->invoice; + +Return the invoice for this adjustment + +=cut + +sub invoice { + my ( $self ) = @_; + my $invoice_rs = $self->_result->invoiceid; + return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs ); +} + =head3 type =cut diff --git a/acqui/ordered.pl b/acqui/ordered.pl index 3eb0519c65..ebf89e86d0 100755 --- a/acqui/ordered.pl +++ b/acqui/ordered.pl @@ -77,7 +77,7 @@ WHERE (quantity > quantityreceived OR quantityreceived IS NULL) GROUP BY aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber, tleft, - ecost, budgetdate, entrydate, + ecost_tax_included, budgetdate, entrydate, aqbasket.booksellerid, aqbooksellers.name, itype, @@ -107,7 +107,7 @@ while ( my $data = $sth->fetchrow_hashref ) { } } -my $adjustments = Koha::Acquisition::Invoice::Adjustments->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 }, { prefetch => 'invoiceid' } ); while ( my $adj = $adjustments->next ){ $total += $adj->adjustment; } diff --git a/acqui/spent.pl b/acqui/spent.pl index 80d93617e2..7a9454343d 100755 --- a/acqui/spent.pl +++ b/acqui/spent.pl @@ -93,7 +93,7 @@ WHERE aqorders.invoiceid, aqinvoices.invoicenumber, quantityreceived, - unitprice, + unitprice_tax_included, datereceived, aqbooksellers.name @@ -135,7 +135,7 @@ while (my $data = $sth->fetchrow_hashref) { } $sth->finish; -my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { join => 'invoiceid' } ); +my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $bookfund, closedate => { '!=' => undef } }, { prefetch => 'invoiceid' }, ); while ( my $adj = $adjustments->next ){ $total += $adj->adjustment; } diff --git a/circ/ysearch.pl b/circ/ysearch.pl index b9e75d0d4d..5527e52184 100755 --- a/circ/ysearch.pl +++ b/circ/ysearch.pl @@ -40,6 +40,7 @@ binmode STDOUT, ":encoding(UTF-8)"; print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { catalogue => '1' } ); +warn "$auth_status is what?"; if ( $auth_status ne "ok" ) { exit 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 6e20dfb250..5685d7e07f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/ordered.tt @@ -77,7 +77,11 @@ [% FOREACH adjustment IN adjustments %] - Adjustment cost for invoice [% adjustment.invoiceid | html %] + Adjustment cost for invoice + + [% adjustment.invoice.invoicenumber | html %] + + [% adjustment.adjustment | $Price %] [% END %] 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 78cf32e573..2e5ca3f830 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/spent.tt @@ -87,7 +87,11 @@ [% FOREACH shipmentcost IN shipmentcosts %] - Shipping cost for invoice [% shipmentcost.invoicenumber | html %] + Shipping cost for invoice + + [% shipmentcost.invoicenumber | html %] + + [% shipmentcost.shipmentcost | $Price %] [% END %] @@ -96,7 +100,11 @@ [% FOREACH adjustment IN adjustments %] - Adjustment cost for invoice [% adjustment.invoiceid | html %] + Adjustment cost for invoice + + [% adjustment.invoice.invoicenumber | html %] + + [% adjustment.adjustment | $Price %] [% END %] diff --git a/t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t b/t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t index 4c970e2dbf..d5e2309eb0 100644 --- a/t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t +++ b/t/db_dependent/Koha/Acquisition/Invoice/Adjustments.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Koha::Database; @@ -64,4 +64,12 @@ is( $retrieved_adj->reason, $new_adj->reason, 'Find an adjustment by id should r $retrieved_adj->delete; is( Koha::Acquisition::Invoice::Adjustments->search->count, $nb_of_adjs + 1, 'Delete should have deleted the adjustment' ); +subtest 'invoice' => sub { + plan tests => 2; + + my $invoice = $retrieved_adj->invoice; + is( ref( $invoice ), 'Koha::Acquisition::Invoice', 'Koha::Acquisition::Invoice::Adjustment->invoice should return a Koha::Acquisition::Invoice' ); + is( $invoice->invoiceid, $retrieved_adj->invoiceid, 'Koha::Acquisition::Invoice::Adjustment->invoice should return the correct invoice' ); +}; + $schema->storage->txn_rollback; -- 2.11.0