View | Details | Raw Unified | Return to bug 15630
Collapse All | Expand All

(-)a/Koha/EDI.pm (-11 / +42 lines)
Lines 35-40 use Koha::Edifact::Order; Link Here
35
use Koha::Edifact;
35
use Koha::Edifact;
36
use Log::Log4perl;
36
use Log::Log4perl;
37
use Text::Unidecode;
37
use Text::Unidecode;
38
use Koha::Plugins::Handler;
38
39
39
our $VERSION = 1.1;
40
our $VERSION = 1.1;
40
our @EXPORT_OK =
41
our @EXPORT_OK =
Lines 86-103 sub create_edi_order { Link Here
86
    );
87
    );
87
    my $response = @{$arr_ref} ? 1 : 0;
88
    my $response = @{$arr_ref} ? 1 : 0;
88
89
89
    my $edifact = Koha::Edifact::Order->new(
90
    my $edifact_order_params = {
90
        {
91
        orderlines  => \@orderlines,
91
            orderlines  => \@orderlines,
92
        vendor      => $vendor,
92
            vendor      => $vendor,
93
        ean         => $ean_obj,
93
            ean         => $ean_obj,
94
        is_response => $response,
94
            is_response => $response,
95
    };
95
        }
96
96
    );
97
    my $edifact;
97
    if ( !$edifact ) {
98
    if ( $vendor->plugin ) {
98
        return;
99
        $edifact = Koha::Plugins::Handler->run(
100
            {
101
                class  => $vendor->plugin,
102
                method => 'edifact_order',
103
                params => {
104
                    params => $edifact_order_params,
105
                }
106
            }
107
        );
108
    }
109
    else {
110
        $edifact = Koha::Edifact::Order->new($edifact_order_params);
99
    }
111
    }
100
112
113
    return unless $edifact;
114
101
    my $order_file = $edifact->encode();
115
    my $order_file = $edifact->encode();
102
116
103
    # ingest result
117
    # ingest result
Lines 185-192 sub process_invoice { Link Here
185
    my $schema = Koha::Database->new()->schema();
199
    my $schema = Koha::Database->new()->schema();
186
    my $logger = Log::Log4perl->get_logger();
200
    my $logger = Log::Log4perl->get_logger();
187
    my $vendor_acct;
201
    my $vendor_acct;
188
    my $edi =
202
203
    my $plugin = $invoice_message->edi_acct()->plugin();
204
    my $edi_plugin;
205
    if ( $plugin ) {
206
        $edi_plugin = Koha::Plugins::Handler->run(
207
            {
208
                class  => $plugin,
209
                method => 'edifact',
210
                params => {
211
                    invoice_message => $invoice_message,
212
                    transmission => $invoice_message->raw_msg,
213
                }
214
            }
215
        );
216
    }
217
218
    my $edi = $edi_plugin ||
189
      Koha::Edifact->new( { transmission => $invoice_message->raw_msg, } );
219
      Koha::Edifact->new( { transmission => $invoice_message->raw_msg, } );
220
190
    my $messages = $edi->message_array();
221
    my $messages = $edi->message_array();
191
222
192
    if ( @{$messages} ) {
223
    if ( @{$messages} ) {
(-)a/Koha/Plugins.pm (-1 / +1 lines)
Lines 20-26 package Koha::Plugins; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Module::Load::Conditional qw(can_load);
22
use Module::Load::Conditional qw(can_load);
23
use Module::Pluggable search_path => ['Koha::Plugin'];
23
use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
24
24
25
use C4::Context;
25
use C4::Context;
26
use C4::Output;
26
use C4::Output;
(-)a/Koha/Schema/Result/VendorEdiAccount.pm (-6 / +15 lines)
Lines 130-135 __PACKAGE__->table("vendor_edi_accounts"); Link Here
130
  is_foreign_key: 1
130
  is_foreign_key: 1
131
  is_nullable: 1
131
  is_nullable: 1
132
132
133
=head2 plugin
134
135
  data_type: 'varchar'
136
  default_value: (empty string)
137
  is_nullable: 0
138
  size: 256
139
133
=cut
140
=cut
134
141
135
__PACKAGE__->add_columns(
142
__PACKAGE__->add_columns(
Lines 169-174 __PACKAGE__->add_columns( Link Here
169
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
176
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
170
  "shipment_budget",
177
  "shipment_budget",
171
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
178
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
179
  "plugin",
180
  { data_type => "varchar", default_value => "", is_nullable => 0, size => 256 },
172
);
181
);
173
182
174
=head1 PRIMARY KEY
183
=head1 PRIMARY KEY
Lines 215-222 __PACKAGE__->belongs_to( Link Here
215
  {
224
  {
216
    is_deferrable => 1,
225
    is_deferrable => 1,
217
    join_type     => "LEFT",
226
    join_type     => "LEFT",
218
    on_delete     => "RESTRICT",
227
    on_delete     => "CASCADE",
219
    on_update     => "RESTRICT",
228
    on_update     => "CASCADE",
220
  },
229
  },
221
);
230
);
222
231
Lines 235-248 __PACKAGE__->belongs_to( Link Here
235
  {
244
  {
236
    is_deferrable => 1,
245
    is_deferrable => 1,
237
    join_type     => "LEFT",
246
    join_type     => "LEFT",
238
    on_delete     => "RESTRICT",
247
    on_delete     => "CASCADE",
239
    on_update     => "RESTRICT",
248
    on_update     => "CASCADE",
240
  },
249
  },
241
);
250
);
242
251
243
252
244
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-08-19 11:41:15
253
# Created by DBIx::Class::Schema::Loader v0.07025 @ 2015-12-21 12:59:02
245
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0CgJuFAItI71dfSG88NWhg
254
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xPfUnPxnQOmWWX3shkTVRA
246
255
247
256
248
# You can replace this text with custom code or comments, and it will be preserved on regeneration
257
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/admin/edi_accounts.pl (+5 lines)
Lines 23-28 use CGI; Link Here
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Output;
24
use C4::Output;
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::Plugins;
26
27
27
my $input = CGI->new();
28
my $input = CGI->new();
28
29
Lines 72-77 if ( $op eq 'acct_form' ) { Link Here
72
        ]
73
        ]
73
    );
74
    );
74
75
76
    my @plugins = Koha::Plugins->new()->GetPlugins('edifact');
77
    $template->param( plugins => \@plugins );
78
75
}
79
}
76
elsif ( $op eq 'delete_confirm' ) {
80
elsif ( $op eq 'delete_confirm' ) {
77
    show_account();
81
    show_account();
Lines 98-103 else { Link Here
98
            responses_enabled  => defined $input->param('responses_enabled'),
102
            responses_enabled  => defined $input->param('responses_enabled'),
99
            auto_orders        => defined $input->param('auto_orders'),
103
            auto_orders        => defined $input->param('auto_orders'),
100
            id_code_qualifier  => $input->param('id_code_qualifier'),
104
            id_code_qualifier  => $input->param('id_code_qualifier'),
105
            plugin             => $input->param('plugin'),
101
        };
106
        };
102
107
103
        if ($id) {
108
        if ($id) {
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 3160-3165 CREATE TABLE IF NOT EXISTS vendor_edi_accounts ( Link Here
3160
  responses_enabled tinyint(1) NOT NULL DEFAULT '0',
3160
  responses_enabled tinyint(1) NOT NULL DEFAULT '0',
3161
  auto_orders tinyint(1) NOT NULL DEFAULT '0',
3161
  auto_orders tinyint(1) NOT NULL DEFAULT '0',
3162
  shipment_budget integer(11) references aqbudgets( budget_id ),
3162
  shipment_budget integer(11) references aqbudgets( budget_id ),
3163
  plugin varchar(256) NOT NULL DEFAULT "",
3163
  PRIMARY KEY  (id),
3164
  PRIMARY KEY  (id),
3164
  KEY vendorid (vendor_id),
3165
  KEY vendorid (vendor_id),
3165
  KEY shipmentbudget (shipment_budget),
3166
  KEY shipmentbudget (shipment_budget),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_accounts.tt (+13 lines)
Lines 77-82 Link Here
77
     </select>
77
     </select>
78
  </li>
78
  </li>
79
  <li>
79
  <li>
80
     <label for="plugin">Plugin: </label>
81
     <select name="plugin" id="plugin">
82
        <option value="">Do not use plugin</option>
83
        [% FOREACH plugin IN plugins %]
84
            [% IF account.plugin == plugin.class %]
85
                <option value="[% plugin.class %]" selected="selected">[% plugin.metadata.name %]</option>
86
            [% ELSE %]
87
                <option value="[% plugin.class %]">[% plugin.metadata.name %]</option>
88
            [% END %]
89
        [% END %]
90
     </select>
91
  </li>
92
  <li>
80
     <label for="description">Description: </label>
93
     <label for="description">Description: </label>
81
     <input type="text" name="description" id="description" size="20" maxlength="90" value="[% account.description %]" />
94
     <input type="text" name="description" id="description" size="20" maxlength="90" value="[% account.description %]" />
82
  </li>
95
  </li>
(-)a/misc/cronjobs/edi_cron.pl (-4 / +36 lines)
Lines 66-72 for my $acct (@edi_accts) { Link Here
66
    }
66
    }
67
67
68
    if ( $acct->invoices_enabled ) {
68
    if ( $acct->invoices_enabled ) {
69
        my $downloader = Koha::Edifact::Transport->new( $acct->id );
69
        my $downloader;
70
71
        if ( $acct->plugin ) {
72
            $downloader = Koha::Plugins::Handler->run(
73
                {
74
                    class  => $acct->plugin,
75
                    method => 'edifact_transport',
76
                    params => {
77
                        vendor_edi_account_id => $acct->id,
78
                    }
79
                }
80
            );
81
        }
82
83
        $downloader ||= Koha::Edifact::Transport->new( $acct->id );
84
70
        $downloader->download_messages('INVOICE');
85
        $downloader->download_messages('INVOICE');
71
86
72
    }
87
    }
Lines 115-122 my @downloaded_invoices = $schema->resultset('EdifactMessage')->search( Link Here
115
130
116
foreach my $invoice (@downloaded_invoices) {
131
foreach my $invoice (@downloaded_invoices) {
117
    my $filename = $invoice->filename();
132
    my $filename = $invoice->filename();
118
    $logger->trace("Processing invoice $filename");
133
    #$logger->trace("Processing invoice $filename");
119
    process_invoice($invoice);
134
135
    my $plugin_used = 0;
136
    if ( my $plugin_class = $invoice->edi_acct->plugin ) {
137
        my $plugin = $plugin_class->new();
138
        if ( $plugin->can('edifact_process_invoice') ) {
139
            $plugin_used = 1;
140
            Koha::Plugins::Handler->run(
141
                {
142
                    class  => $plugin_class,
143
                    method => 'edifact_process_invoice',
144
                    params => {
145
                        invoice => $invoice,
146
                    }
147
                }
148
            );
149
        }
150
    }
151
152
    process_invoice($invoice) unless $plugin_used;
120
}
153
}
121
154
122
my @downloaded_responses = $schema->resultset('EdifactMessage')->search(
155
my @downloaded_responses = $schema->resultset('EdifactMessage')->search(
123
- 

Return to bug 15630