Koha/admin/edi_accounts.pl
Colin Campbell e2e9916348 Bug 7736: Support Ordering via Edifact EDI messages
Add support for processing incoming Edifact Quotes, Invoices
and order responses and generating and transmission of
Edifact Orders.
Basic workflow is that an incoming quote generates an aquisition
basket in Koha, with each line corresponding to an order record

The user can then generate an edifact order from this (or another)
basket, which is transferred to the vendor's site

The supplier generates an invoice on despatch and this will
result in corresponding invoices being generated in Koha
The orderlines on the invoice are receipted automatically.

We also support order response messages. This may include
simple order acknowledgements, supplier reports/amendments
on availability. Cancellation messages cause the koha order
to be cancelled, other messages are recorded against the order

Which messages are to be supported/processed is specifiable on a
vendor by vendor basis via the admin screens

You can also specify auto order i.e. to generate orders from quotes
without user intervention - This reflects existing
workflows where most work is done on the suppliers website
then generating a dummy quote

Received messages are stored in the edifact_messages table
and the original can be viewed via the online

Database changes are in installer/data/mysql/atomicchanges/edifact.sql
Note new perl dependencies:
    Net::SFTP:Foreign
    Text::Unidecode

Signed-off-by: Paul Johnson <p.johnson@staffs.ac.uk>

Signed-off-by: Sally Healey <sally.healey@cheshiresharedservices.gov.uk>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
2016-04-01 20:03:17 +00:00

155 lines
4.6 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2011,2014 Mark Gavillet & PTFS Europe Ltd
#
# 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 3 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.
use strict;
use warnings;
use CGI;
use C4::Auth;
use C4::Output;
use Koha::Database;
my $input = CGI->new();
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => 'admin/edi_accounts.tt',
query => $input,
type => 'intranet',
authnotrequired => 0,
flagsrequired => { acquisition => 'edi_manage' },
}
);
my $op = $input->param('op');
$op ||= 'display';
my $schema = Koha::Database->new()->schema();
if ( $op eq 'acct_form' ) {
show_account();
$template->param( acct_form => 1 );
my @vendors = $schema->resultset('Aqbookseller')->search(
undef,
{
columns => [ 'name', 'id' ],
order_by => { -asc => 'name' }
}
);
$template->param( vendors => \@vendors );
$template->param(
code_qualifiers => [
{
code => '14',
description => 'EAN International',
},
{
code => '31B',
description => 'US SAN Agency',
},
{
code => '91',
description => 'Assigned by supplier',
},
{
code => '92',
description => 'Assigned by buyer',
},
]
);
}
elsif ( $op eq 'delete_confirm' ) {
show_account();
$template->param( delete_confirm => 1 );
}
else {
if ( $op eq 'save' ) {
# validate & display
my $id = $input->param('id');
my $fields = {
description => $input->param('description'),
host => $input->param('host'),
username => $input->param('username'),
password => $input->param('password'),
vendor_id => $input->param('vendor_id'),
upload_directory => $input->param('upload_directory'),
download_directory => $input->param('download_directory'),
san => $input->param('san'),
transport => $input->param('transport'),
quotes_enabled => defined $input->param('quotes_enabled'),
invoices_enabled => defined $input->param('invoices_enabled'),
orders_enabled => defined $input->param('orders_enabled'),
responses_enabled => defined $input->param('responses_enabled'),
auto_orders => defined $input->param('auto_orders'),
id_code_qualifier => $input->param('id_code_qualifier'),
};
if ($id) {
$schema->resultset('VendorEdiAccount')->search(
{
id => $id,
}
)->update_all($fields);
}
else { # new record
$schema->resultset('VendorEdiAccount')->create($fields);
}
}
elsif ( $op eq 'delete_confirmed' ) {
$schema->resultset('VendorEdiAccount')
->search( { id => $input->param('id'), } )->delete_all;
}
# we do a default dispaly after deletes and saves
# as well as when thats all you want
$template->param( display => 1 );
my @ediaccounts = $schema->resultset('VendorEdiAccount')->search(
{},
{
join => 'vendor',
}
);
$template->param( ediaccounts => \@ediaccounts );
}
output_html_with_http_headers( $input, $cookie, $template->output );
sub get_account {
my $id = shift;
my $account = $schema->resultset('VendorEdiAccount')->find($id);
if ($account) {
return $account;
}
# passing undef will default to add
return;
}
sub show_account {
my $acct_id = $input->param('id');
if ($acct_id) {
my $acct = $schema->resultset('VendorEdiAccount')->find($acct_id);
if ($acct) {
$template->param( account => $acct );
}
}
return;
}