use Koha::Edifact;
use Log::Log4perl;
use Text::Unidecode;
+use Koha::Plugins::Handler;
our $VERSION = 1.1;
our @EXPORT_OK =
);
my $response = @{$arr_ref} ? 1 : 0;
- my $edifact = Koha::Edifact::Order->new(
- {
- orderlines => \@orderlines,
- vendor => $vendor,
- ean => $ean_obj,
- is_response => $response,
- }
- );
- if ( !$edifact ) {
- return;
+ my $edifact_order_params = {
+ orderlines => \@orderlines,
+ vendor => $vendor,
+ ean => $ean_obj,
+ is_response => $response,
+ };
+
+ my $edifact;
+ if ( $vendor->plugin ) {
+ $edifact = Koha::Plugins::Handler->run(
+ {
+ class => $vendor->plugin,
+ method => 'edifact_order',
+ params => {
+ params => $edifact_order_params,
+ }
+ }
+ );
+ }
+ else {
+ $edifact = Koha::Edifact::Order->new($edifact_order_params);
}
+ return unless $edifact;
+
my $order_file = $edifact->encode();
# ingest result
my $schema = Koha::Database->new()->schema();
my $logger = Log::Log4perl->get_logger();
my $vendor_acct;
- my $edi =
+
+ my $plugin = $invoice_message->edi_acct()->plugin();
+ my $edi_plugin;
+ if ( $plugin ) {
+ $edi_plugin = Koha::Plugins::Handler->run(
+ {
+ class => $plugin,
+ method => 'edifact',
+ params => {
+ invoice_message => $invoice_message,
+ transmission => $invoice_message->raw_msg,
+ }
+ }
+ );
+ }
+
+ my $edi = $edi_plugin ||
Koha::Edifact->new( { transmission => $invoice_message->raw_msg, } );
+
my $messages = $edi->message_array();
if ( @{$messages} ) {
use Modern::Perl;
use Module::Load::Conditional qw(can_load);
-use Module::Pluggable search_path => ['Koha::Plugin'];
+use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
use C4::Context;
use C4::Output;
is_foreign_key: 1
is_nullable: 1
+=head2 plugin
+
+ data_type: 'varchar'
+ default_value: (empty string)
+ is_nullable: 0
+ size: 256
+
=cut
__PACKAGE__->add_columns(
{ data_type => "tinyint", default_value => 0, is_nullable => 0 },
"shipment_budget",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+ "plugin",
+ { data_type => "varchar", default_value => "", is_nullable => 0, size => 256 },
);
=head1 PRIMARY KEY
{
is_deferrable => 1,
join_type => "LEFT",
- on_delete => "RESTRICT",
- on_update => "RESTRICT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
},
);
{
is_deferrable => 1,
join_type => "LEFT",
- on_delete => "RESTRICT",
- on_update => "RESTRICT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
},
);
-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-08-19 11:41:15
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0CgJuFAItI71dfSG88NWhg
+# Created by DBIx::Class::Schema::Loader v0.07025 @ 2015-12-21 12:59:02
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xPfUnPxnQOmWWX3shkTVRA
# You can replace this text with custom code or comments, and it will be preserved on regeneration
use C4::Auth;
use C4::Output;
use Koha::Database;
+use Koha::Plugins;
my $input = CGI->new();
}
);
$template->param( vendors => \@vendors );
+
+ my @plugins = Koha::Plugins->new()->GetPlugins('edifact');
+ $template->param( plugins => \@plugins );
}
elsif ( $op eq 'delete_confirm' ) {
show_account();
responses_enabled => defined $input->param('responses_enabled'),
auto_orders => defined $input->param('auto_orders'),
id_code_qualifier => $input->param('id_code_qualifier'),
+ plugin => $input->param('plugin'),
};
if ($id) {
responses_enabled TINYINT(1) not null default 0,
auto_orders TINYINT(1) not null default 0,
shipment_budget INTEGER(11) REFERENCES aqbudgets( budget_id ),
+ plugin varchar(256) NOT NULL DEFAULT "",
PRIMARY KEY (id),
KEY vendorid (vendor_id),
KEY shipmentbudget (shipment_budget),
[% END %]
</select>
</li>
+ <li>
+ <label for="plugin">Plugin: </label>
+ <select name="plugin" id="plugin">
+ <option value="">Do not use plugin</option>
+ [% FOREACH plugin IN plugins %]
+ [% IF account.plugin == plugin.class %]
+ <option value="[% plugin.class %]" selected="selected">[% plugin.metadata.name %]</option>
+ [% ELSE %]
+ <option value="[% plugin.class %]">[% plugin.metadata.name %]</option>
+ [% END %]
+ [% END %]
+ </select>
+ </li>
<li>
<label for="description">Description: </label>
<input type="text" name="description" id="description" size="20" maxlength="90" value="[% account.description %]" />
}
if ( $acct->invoices_enabled ) {
- my $downloader = Koha::Edifact::Transport->new( $acct->id );
+ my $downloader;
+
+ if ( $acct->plugin ) {
+ $downloader = Koha::Plugins::Handler->run(
+ {
+ class => $acct->plugin,
+ method => 'edifact_transport',
+ params => {
+ vendor_edi_account_id => $acct->id,
+ }
+ }
+ );
+ }
+
+ $downloader ||= Koha::Edifact::Transport->new( $acct->id );
+
$downloader->download_messages('INVOICE');
}
foreach my $invoice (@downloaded_invoices) {
my $filename = $invoice->filename();
$logger->trace("Processing invoice $filename");
- process_invoice($invoice);
+
+ my $plugin_used = 0;
+ if ( my $plugin_class = $invoice->edi_acct->plugin ) {
+ my $plugin = $plugin_class->new();
+ if ( $plugin->can('edifact_process_invoice') ) {
+ $plugin_used = 1;
+ Koha::Plugins::Handler->run(
+ {
+ class => $plugin_class,
+ method => 'edifact_process_invoice',
+ params => {
+ invoice => $invoice,
+ }
+ }
+ );
+ }
+ }
+
+ process_invoice($invoice) unless $plugin_used;
}
my @downloaded_responses = $schema->resultset('EdifactMessage')->search(