=cut
-use strict;
-use warnings;
+use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth;
use Koha::Acquisition::Currencies;
use Koha::DateUtils;
use Koha::Misc::Files;
+use Koha::Acquisition::Invoice::Adjustments;
my $input = new CGI;
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
exit 0;
}
}
+elsif ( $op && $op eq 'del_adj' ) {
+ my $adjustment_id = $input->param('adjustment_id');
+ my $del_adj = Koha::Acquisition::Invoice::Adjustments->find( $adjustment_id );
+ $del_adj->delete() if ($del_adj);
+}
+elsif ( $op && $op eq 'mod_adj' ) {
+ my @adjustment_id = $input->multi_param('adjustment_id');
+ my @adjustment = $input->multi_param('adjustment');
+ my @reason = $input->multi_param('reason');
+ my @note = $input->multi_param('note');
+ my @budget_id = $input->multi_param('budget_id');
+ my @encumber_open = $input->multi_param('encumber_open');
+ my %e_open = map { $_ => 1 } @encumber_open;
+ for( my $i=0; $i < scalar @adjustment; $i++ ){
+ if( $adjustment_id[$i] eq 'new' ){
+ next unless ( $adjustment[$i] || $reason[$i] );
+ my $new_adj = Koha::Acquisition::Invoice::Adjustment->new({
+ invoiceid => $invoiceid,
+ adjustment => $adjustment[$i],
+ reason => $reason[$i],
+ note => $note[$i],
+ budget_id => $budget_id[$i] || undef,
+ encumber_open => defined $e_open{ $adjustment_id[$i] } ? 1 : 0,
+ });
+ $new_adj->store();
+ }
+ else {
+ 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] );
+ $old_adj->reason( $reason[$i] );
+ $old_adj->note( $note[$i] );
+ $old_adj->budget_id( $budget_id[$i] || undef );
+ $old_adj->encumber_open( $e_open{$adjustment_id[$i]} ? 1 : 0 );
+ $old_adj->update();
+ }
+ }
+ }
+}
my $details = GetInvoiceDetails($invoiceid);
my $bookseller = Koha::Acquisition::Booksellers->find( $details->{booksellerid} );
my $orders = $details->{'orders'};
my @foot_loop;
my %foot;
+my $shipmentcost = $details->{shipmentcost} || 0;
my $total_quantity = 0;
my $total_tax_excluded = 0;
my $total_tax_included = 0;
push @budgets_loop, \%line;
}
+my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({ invoiceid => $details->{'invoiceid'} });
+if ( $adjustments ) { $template->param( adjustments => $adjustments ); }
+
$template->param(
invoiceid => $details->{'invoiceid'},
invoicenumber => $details->{'invoicenumber'},
shipmentdate => $details->{'shipmentdate'},
billingdate => $details->{'billingdate'},
invoiceclosedate => $details->{'closedate'},
- shipmentcost => $details->{'shipmentcost'},
+ shipmentcost => $shipmentcost,
orders_loop => \@orders_loop,
foot_loop => \@foot_loop,
total_quantity => $total_quantity,
total_tax_excluded => $total_tax_excluded,
total_tax_included => $total_tax_included,
total_tax_value => $total_tax_value,
- total_tax_excluded_shipment => $total_tax_excluded + $details->{shipmentcost},
- total_tax_included_shipment => $total_tax_included + $details->{shipmentcost},
+ total_tax_excluded_shipment => $total_tax_excluded + $shipmentcost,
+ total_tax_included_shipment => $total_tax_included + $shipmentcost,
invoiceincgst => $bookseller->invoiceincgst,
currency => Koha::Acquisition::Currencies->get_active,
budgets_loop => \@budgets_loop,
$line{budget_name} = $budget->{budget_name};
if ( $line{uncertainprice} ) {
- $template->param( uncertainprices => 1 );
$line{rrp} .= ' (Uncertain)';
}
if ( $line{'title'} ) {