Koha/acqui/invoice.pl
Owen Leonard 81c90ba3bf Bug 8913 [Revised] Improve acquisitions navigation
This patch adds a new menu for vendor-related pages in which
vendor related "views" can be linked to: baskets, basket groups,
contracts, invoices, uncertain prices.

The acquisitions toolbar is pared down to vendor-related actions:
New basket, contract, or vendor; edit vendor, delete vendor,
receive shipment.

Other small improvements have been made to other pages: corrections
to breadcrumbs and title tags, adding useful links betweeen pages.

Vendor menu and toolbar are added to booksellers.pl
when there is only one "search result" (i.e. a vendor id is passed).

- Menu appears when booksellerid variable is present
- Redundant heading removed
- Additional variables added to enable proper display of the toolbar

- Revision corrects broken links pointed out by QA.
- Revision adds check of existing baskets and subscriptions as a
  condition on display of the vendor delete button.

TODO: Add coverage of Basket groups page.

To test, navigate Acquisitions pages and test as many links and buttons
as you can, confirming that nothing is broken on vendor pages, invoice
pages, contract pages, uncertain price pages, etc.

Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>

All tests pass - I like this very much!

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
All tests and QA script pass.

Tests done:
1) New toolbar - vendor search
  - no results = button to create new vendor shows
  - 1 result = additional new options show
  - more than one result = button to create new vendor shows

2) Vendor views
  - acq toolbar consistent with 1 result in vendor search
  - new tabs on the left
  - checked all links have the needed parameters and work correctly

3) New toolbar - different pages
  - Toolbar is formatted consistently
  - Delete vendor shows only up when it should - no baskets or
    subscriptions
  - Links work correctly

Works nicely, great groundwork for further improvements.

TODO Add new toolbar to (new) invoices page.
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
2013-02-20 09:17:21 -05:00

231 lines
7.2 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2011 BibLibre SARL
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
=head1 NAME
invoice.pl
=head1 DESCRIPTION
Invoice details
=cut
use strict;
use warnings;
use CGI;
use C4::Auth;
use C4::Output;
use C4::Acquisition;
use C4::Bookseller qw/GetBookSellerFromId/;
use C4::Budgets;
my $input = new CGI;
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
{
template_name => 'acqui/invoice.tmpl',
query => $input,
type => 'intranet',
authnotrequired => 0,
flagsrequired => { 'acquisition' => '*' },
debug => 1,
}
);
my $invoiceid = $input->param('invoiceid');
my $op = $input->param('op');
if ( $op && $op eq 'close' ) {
CloseInvoice($invoiceid);
my $referer = $input->param('referer');
if ($referer) {
print $input->redirect($referer);
exit 0;
}
}
elsif ( $op && $op eq 'reopen' ) {
ReopenInvoice($invoiceid);
my $referer = $input->param('referer');
if ($referer) {
print $input->redirect($referer);
exit 0;
}
}
elsif ( $op && $op eq 'mod' ) {
my $shipmentdate = $input->param('shipmentdate');
my $billingdate = $input->param('billingdate');
my $shipmentcost = $input->param('shipmentcost');
my $shipment_budget_id = $input->param('shipment_budget_id');
ModInvoice(
invoiceid => $invoiceid,
shipmentdate => C4::Dates->new($shipmentdate)->output("iso"),
billingdate => C4::Dates->new($billingdate)->output("iso"),
shipmentcost => $shipmentcost,
shipmentcost_budgetid => $shipment_budget_id
);
if ($input->param('reopen')) {
ReopenInvoice($invoiceid);
} elsif ($input->param('close')) {
CloseInvoice($invoiceid);
}
$template->param( modified => 1 );
}
my $details = GetInvoiceDetails($invoiceid);
my $bookseller = GetBookSellerFromId( $details->{booksellerid} );
my @orders_loop = ();
my $orders = $details->{'orders'};
my $qty_total;
my @books_loop;
my @book_foot_loop;
my %foot;
my $total_quantity = 0;
my $total_rrp = 0;
my $total_est = 0;
foreach my $order (@$orders) {
my $line = get_infos( $order, $bookseller );
$total_quantity += $$line{quantity};
$total_rrp += $order->{quantity} * $order->{rrp};
$total_est += $order->{quantity} * $order->{'ecost'};
my %row = ( %$order, %$line );
push @orders_loop, \%row;
}
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
my $discount =
$bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0;
my $total_est_gste;
my $total_est_gsti;
my $total_rrp_gsti; # RRP Total, GST included
my $total_rrp_gste; # RRP Total, GST excluded
my $gist_est;
my $gist_rrp;
if ($gist) {
# if we have GST
if ( $bookseller->{'listincgst'} ) {
# if prices already includes GST
# we know $total_rrp_gsti
$total_rrp_gsti = $total_rrp;
# and can reverse compute other values
$total_rrp_gste = $total_rrp_gsti / ( $gist + 1 );
$gist_rrp = $total_rrp_gsti - $total_rrp_gste;
$total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount );
$total_est_gsti = $total_est;
}
else {
# if prices does not include GST
# then we use the common way to compute other values
$total_rrp_gste = $total_rrp;
$gist_rrp = $total_rrp_gste * $gist;
$total_rrp_gsti = $total_rrp_gste + $gist_rrp;
$total_est_gste = $total_est;
$total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount );
}
$gist_est = $gist_rrp - ( $gist_rrp * $discount );
}
else {
$total_rrp_gste = $total_rrp_gsti = $total_rrp;
$total_est_gste = $total_est_gsti = $total_est;
$gist_rrp = $gist_est = 0;
}
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost};
my $format = "%.2f";
$template->param(
total_rrp_gste => sprintf( $format, $total_rrp_gste ),
total_rrp_gsti => sprintf( $format, $total_rrp_gsti ),
total_est_gste => sprintf( $format, $total_est_gste ),
total_est_gsti => sprintf( $format, $total_est_gsti ),
gist_rrp => sprintf( $format, $gist_rrp ),
gist_est => sprintf( $format, $gist_est ),
total_gsti_shipment => sprintf( $format, $total_gsti_shipment ),
gist => sprintf( $format, $gist * 100 ),
);
my $budgets = GetBudgets();
my @budgets_loop;
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
foreach my $budget (@$budgets) {
next unless CanUserUseBudget( $loggedinuser, $budget, $flags );
my %line = %{$budget};
if ( $shipmentcost_budgetid
and $budget->{budget_id} == $shipmentcost_budgetid )
{
$line{selected} = 1;
}
push @budgets_loop, \%line;
}
$template->param(
invoiceid => $details->{'invoiceid'},
invoicenumber => $details->{'invoicenumber'},
suppliername => $details->{'suppliername'},
booksellerid => $details->{'booksellerid'},
datereceived => $details->{'datereceived'},
shipmentdate => $details->{'shipmentdate'},
billingdate => $details->{'billingdate'},
invoiceclosedate => $details->{'closedate'},
shipmentcost => sprintf( $format, $details->{'shipmentcost'} || 0 ),
orders_loop => \@orders_loop,
total_quantity => $total_quantity,
invoiceincgst => $bookseller->{invoiceincgst},
currency => $bookseller->{listprice},
budgets_loop => \@budgets_loop,
);
sub get_infos {
my $order = shift;
my $bookseller = shift;
my $qty = $order->{'quantity'} || 0;
if ( !defined $order->{quantityreceived} ) {
$order->{quantityreceived} = 0;
}
my $budget = GetBudget( $order->{'budget_id'} );
my %line = %{$order};
$line{order_received} = ( $qty == $order->{'quantityreceived'} );
$line{budget_name} = $budget->{budget_name};
$line{total} = $qty * $order->{ecost};
if ( $line{uncertainprice} ) {
$line{rrp} .= ' (Uncertain)';
}
if ( $line{'title'} ) {
my $volume = $order->{'volume'};
my $seriestitle = $order->{'seriestitle'};
$line{'title'} .= " / $seriestitle" if $seriestitle;
$line{'title'} .= " / $volume" if $volume;
}
else {
$line{'title'} = "Deleted bibliographic notice, can't find title.";
}
return \%line;
}
output_html_with_http_headers $input, $cookie, $template->output;