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 <martin.renvoize@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
5bd7acfbb0
commit
7d7cd25f4c
12 changed files with 78 additions and 48 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -212,6 +212,21 @@ __PACKAGE__->has_many(
|
|||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
=head2 aqinvoice_adjustments
|
||||
|
||||
Type: has_many
|
||||
|
||||
Related object: L<Koha::Schema::Result::AqinvoiceAdjustment>
|
||||
|
||||
=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</aqbudgetborrowers> -> 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
|
||||
|
|
|
@ -113,6 +113,21 @@ __PACKAGE__->set_primary_key("invoiceid");
|
|||
|
||||
=head1 RELATIONS
|
||||
|
||||
=head2 aqinvoice_adjustments
|
||||
|
||||
Type: has_many
|
||||
|
||||
Related object: L<Koha::Schema::Result::AqinvoiceAdjustment>
|
||||
|
||||
=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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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')");
|
||||
|
|
|
@ -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`
|
||||
--
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
<form action="/cgi-bin/koha/acqui/invoice.pl" method="post" class="validated">
|
||||
<fieldset class="rows">
|
||||
<input type="hidden" name="invoiceid" value="[% invoiceid %]" />
|
||||
[% IF (adjustments.count > 0) %]
|
||||
[% IF (adjustments && adjustments.count > 0) %]
|
||||
<table id="invoice_adj_table">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
[% END %]
|
||||
</tbody>
|
||||
<tfoot>
|
||||
[% IF ( adjustments.count > 0 ) %]
|
||||
[% IF ( adjustments && adjustments.count > 0 ) %]
|
||||
[% FOREACH adjustment IN adjustments %]
|
||||
<tr>
|
||||
<td></td>
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
[% END %]
|
||||
|
||||
<tfoot>
|
||||
[% IF shipmentcosts.size || ( adjustments.count > 0 ) %]
|
||||
[% IF shipmentcosts.size || ( adjustments && adjustments.count > 0 ) %]
|
||||
<tr valign="top">
|
||||
<td colspan="9"> Sub total </td>
|
||||
<td class="data"> [% subtotal %] </td>
|
||||
|
@ -92,7 +92,7 @@
|
|||
</tr>
|
||||
[% END %]
|
||||
[% END %]
|
||||
[% IF ( adjustments.count > 0 ) %]
|
||||
[% IF ( adjustments && adjustments.count > 0 ) %]
|
||||
[% FOREACH adjustment IN adjustments %]
|
||||
<tr>
|
||||
<td></td>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue