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

(-)a/C4/Edifact.pm (+280 lines)
Line 0 Link Here
1
package C4::Edifact;
2
3
# Copyright 2012 Mark Gavillet
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use C4::Context;
23
use C4::Acquisition;
24
use Net::FTP;
25
use C4::Biblio;
26
use C4::Items;
27
use Business::ISBN;
28
use parent qw(Exporter);
29
30
our $VERSION = 0.01;
31
our $debug   = $ENV{DEBUG} || 0;
32
our @EXPORT  = qw(
33
  GetVendorList
34
  DeleteEDIDetails
35
  CreateEDIDetails
36
  UpdateEDIDetails
37
  GetEDIAccounts
38
  GetEDIAccountDetails
39
  GetEDIfactMessageList
40
  CheckVendorFTPAccountExists
41
  GetEDIfactEANs
42
  GetBranchList
43
  delete_edi_ean
44
  create_edi_ean
45
  update_edi_ean
46
);
47
48
=head1 NAME
49
50
C4::Edifact - Perl Module containing functions for Vendor EDI accounts and EDIfact messages
51
52
=head1 VERSION
53
54
Version 0.01
55
56
=head1 SYNOPSIS
57
58
use C4::Edifact;
59
60
=head1 DESCRIPTION
61
62
This module contains routines for managing EDI account details for vendors
63
64
=head2 GetVendorList
65
66
Returns a list of vendors from aqbooksellers to populate drop down select menu
67
68
=cut
69
70
sub GetVendorList {
71
    my $dbh = C4::Context->dbh;
72
    my $sth;
73
    $sth =
74
      $dbh->prepare('select id, name from aqbooksellers order by name asc');
75
    $sth->execute();
76
    my $vendorlist = $sth->fetchall_arrayref( {} );
77
    return $vendorlist;
78
}
79
80
=head2 DeleteEDIDetails
81
82
Remove a vendor's FTP account
83
84
=cut
85
86
sub DeleteEDIDetails {
87
    my $id  = shift;
88
    my $dbh = C4::Context->dbh;
89
    my $sth;
90
    if ($id) {
91
        $sth = $dbh->prepare('delete from vendor_edi_accounts where id=?');
92
        $sth->execute($id);
93
    }
94
    return;
95
}
96
97
=head2 CreateEDIDetails
98
99
Inserts a new EDI vendor FTP account
100
101
=cut
102
103
sub CreateEDIDetails {
104
    my ( $provider, $description, $host, $user, $pass, $in_dir, $san ) = @_;
105
    my $dbh = C4::Context->dbh;
106
    my $sth;
107
    if ($provider) {
108
        $sth = $dbh->prepare(
109
            'insert into vendor_edi_accounts 
110
			(description, host, username, password, provider, in_dir, san) 
111
			values (?,?,?,?,?,?,?)'
112
        );
113
        $sth->execute( $description, $host, $user, $pass, $provider, $in_dir,
114
            $san );
115
    }
116
    return;
117
}
118
119
=head2 UpdateEDIDetails
120
121
Update a vendor's FTP account
122
123
=cut
124
125
sub UpdateEDIDetails {
126
    my ( $editid, $description, $host, $user, $pass, $provider, $in_dir, $san )
127
      = @_;
128
    my $dbh = C4::Context->dbh;
129
    my $sth;
130
    if ($editid) {
131
        $sth = $dbh->prepare(
132
            'update vendor_edi_accounts set description=?, host=?, 
133
			username=?, password=?, provider=?, in_dir=?, san=? where id=?'
134
        );
135
        $sth->execute( $description, $host, $user, $pass, $provider, $in_dir,
136
            $san, $editid );
137
    }
138
    return;
139
}
140
141
=head2 GetEDIAccounts
142
143
Returns all vendor FTP accounts
144
145
=cut
146
147
sub GetEDIAccounts {
148
    my $dbh = C4::Context->dbh;
149
    my $sth;
150
    $sth = $dbh->prepare(
151
        'select vendor_edi_accounts.id, aqbooksellers.id as providerid, 
152
		aqbooksellers.name as vendor, vendor_edi_accounts.description, 
153
		vendor_edi_accounts.last_activity from vendor_edi_accounts inner join 
154
		aqbooksellers on vendor_edi_accounts.provider = aqbooksellers.id 
155
		order by aqbooksellers.name asc'
156
    );
157
    $sth->execute();
158
    my $ediaccounts = $sth->fetchall_arrayref( {} );
159
    return $ediaccounts;
160
}
161
162
=head2 GetEDIAccountDetails
163
164
Returns FTP account details for a given vendor
165
166
=cut
167
168
sub GetEDIAccountDetails {
169
    my $id  = shift;
170
    my $dbh = C4::Context->dbh;
171
    my $sth;
172
    if ($id) {
173
        $sth = $dbh->prepare('select * from vendor_edi_accounts where id=?');
174
        $sth->execute($id);
175
        my $edi_details = $sth->fetchrow_hashref;
176
        return $edi_details;
177
    }
178
    return;
179
}
180
181
=head2 GetEDIfactMessageList
182
183
Returns a list of edifact_messages that have been processed, including the type (quote/order) and status
184
185
=cut
186
187
sub GetEDIfactMessageList {
188
    my $dbh = C4::Context->dbh;
189
    my $sth;
190
    $sth = $dbh->prepare(
191
        'select edifact_messages.key, edifact_messages.message_type, 
192
		DATE_FORMAT(edifact_messages.date_sent,"%d/%m/%Y") as date_sent, 
193
		aqbooksellers.id as providerid, aqbooksellers.name as providername, 
194
		edifact_messages.status, edifact_messages.basketno from aqbooksellers 
195
		inner join vendor_edi_accounts on aqbooksellers.id=vendor_edi_accounts.provider 
196
		inner join edifact_messages on edifact_messages.provider=vendor_edi_accounts.id 
197
		order by edifact_messages.date_sent desc, edifact_messages.key desc'
198
    );
199
    $sth->execute();
200
    my $messagelist = $sth->fetchall_arrayref( {} );
201
    return $messagelist;
202
}
203
204
sub CheckVendorFTPAccountExists {
205
    my $booksellerid = shift;
206
    my $dbh          = C4::Context->dbh;
207
    my $sth;
208
    my @rows;
209
    my $cnt;
210
    $sth = $dbh->prepare(
211
        'select count(id) from vendor_edi_accounts where provider=?');
212
    $sth->execute($booksellerid);
213
    if ( $sth->rows == 0 ) {
214
        return undef;
215
    }
216
    else {
217
        return 1;
218
    }
219
}
220
221
sub GetEDIfactEANs {
222
    my $dbh = C4::Context->dbh;
223
    my $sth = $dbh->prepare(
224
'select branches.branchname, edifact_ean.ean, edifact_ean.branchcode from 
225
		branches inner join edifact_ean on edifact_ean.branchcode=branches.branchcode 
226
		order by branches.branchname asc'
227
    );
228
    $sth->execute();
229
    my $eans = $sth->fetchall_arrayref( {} );
230
    return $eans;
231
}
232
233
sub GetBranchList {
234
    my $dbh = C4::Context->dbh;
235
    my $sth = $dbh->prepare(
236
        'select branches.branchname, branches.branchcode from branches
237
		order by branches.branchname asc'
238
    );
239
    $sth->execute();
240
    my $branches = $sth->fetchall_arrayref( {} );
241
    return $branches;
242
}
243
244
sub delete_edi_ean {
245
    my ( $branchcode, $ean ) = @_;
246
    my $dbh = C4::Context->dbh;
247
    my $sth =
248
      $dbh->prepare('delete from edifact_ean where branchcode=? and ean=?');
249
    $sth->execute( $branchcode, $ean );
250
    return;
251
}
252
253
sub create_edi_ean {
254
    my ( $branchcode, $ean ) = @_;
255
    my $dbh = C4::Context->dbh;
256
    my $sth =
257
      $dbh->prepare('insert into edifact_ean (branchcode,ean) values (?,?)');
258
    $sth->execute( $branchcode, $ean );
259
    return;
260
}
261
262
sub update_edi_ean {
263
    my ( $branchcode, $ean, $oldbranchcode, $oldean ) = @_;
264
    my $dbh = C4::Context->dbh;
265
    my $sth = $dbh->prepare(
266
        'update edifact_ean set branchcode=?, ean=? where branchcode=? and ean=?'
267
    );
268
    $sth->execute( $branchcode, $ean, $oldbranchcode, $oldean );
269
    return;
270
}
271
272
1;
273
274
__END__
275
276
=head1 AUTHOR
277
278
Mark Gavillet
279
280
=cut
(-)a/C4/Installer/PerlDependencies.pm (+15 lines)
Lines 484-489 our $PERL_DEPS = { Link Here
484
        'required' => '1',
484
        'required' => '1',
485
        'min_ver'  => '0.09',
485
        'min_ver'  => '0.09',
486
      },
486
      },
487
    'Business::Edifact::Interchange' => {
488
        'usage'    => 'Core',
489
        'required' => '1',
490
        'min_ver'  => '0.02',
491
      },
492
    'Net::FTP' => {
493
        'usage'    => 'Core',
494
        'required' => '1',
495
        'min_ver'  => '2.77',
496
      },
497
    'Net::FTP::File' => {
498
        'usage'    => 'Core',
499
        'required' => '1',
500
        'min_ver'  => '0.06',
501
      },
487
};
502
};
488
503
489
1;
504
1;
(-)a/Rebus/EDI.pm (+158 lines)
Line 0 Link Here
1
package Rebus::EDI;
2
3
# Copyright 2012 Mark Gavillet
4
5
use strict;
6
use warnings;
7
8
=head1 NAME
9
10
Rebus::EDI
11
12
=head1 VERSION
13
14
Version 0.01
15
16
=cut
17
18
our $VERSION = '0.01';
19
20
our @vendors = (
21
    {
22
        name   => 'Bertrams',
23
        san    => '0143731',
24
        ean    => '',
25
        module => 'Bertrams'
26
    },
27
    {
28
        name   => 'Bertrams',
29
        san    => '5013546025078',
30
        ean    => '',
31
        module => 'Bertrams'
32
    },
33
    {
34
        name   => 'Dawsons',
35
        san    => '',
36
        ean    => '5013546027856',
37
        module => 'Dawsons'
38
    },
39
    {
40
        name   => 'Coutts',
41
        san    => '',
42
        ean    => '5013546048686',
43
        module => 'Default'
44
    },
45
    {
46
        name   => 'Tomlinsons',
47
        san    => '',
48
        ean    => '5033075063552',
49
        module => 'Default'
50
    },
51
    {
52
        name   => 'PTFS Europe',
53
        san    => '',
54
        ean    => '5011234567890',
55
        module => 'Default'
56
    },
57
);
58
59
sub new {
60
    my $class  = shift;
61
    my $system = shift;
62
    my $self   = {};
63
    $self->{system} = 'koha';
64
    use Rebus::EDI::System::Koha;
65
    $self->{edi_system} = Rebus::EDI::System::Koha->new();
66
    bless $self, $class;
67
    return $self;
68
}
69
70
sub list_vendors {
71
    return @vendors;
72
}
73
74
sub retrieve_quotes {
75
    my $self                = shift;
76
    my @vendor_ftp_accounts = $self->{edi_system}->retrieve_vendor_ftp_accounts;
77
    my @downloaded_quotes =
78
      $self->{edi_system}->download_quotes( \@vendor_ftp_accounts );
79
    my $processed_quotes =
80
      $self->{edi_system}->process_quotes( \@downloaded_quotes );
81
}
82
83
sub send_orders {
84
    my ( $self, $order_id, $ean ) = @_;
85
    my $orders = $self->{edi_system}->retrieve_orders($order_id);
86
    my $order_details =
87
      $self->{edi_system}->retrieve_order_details( $orders, $ean );
88
    foreach my $order ( @{$order_details} ) {
89
        my $module = $order->{module};
90
        require "Rebus/EDI/Vendor/$module.pm";
91
        $module = "Rebus::EDI::Vendor::$module";
92
        import $module;
93
        my $vendor_module = $module->new();
94
        my $order_message = $vendor_module->create_order_message($order);
95
        my $order_file =
96
          $self->{edi_system}
97
          ->create_order_file( $order_message, $order->{order_id} );
98
    }
99
}
100
101
sub string35escape {
102
    my $string = shift;
103
    my $colon_string;
104
    my @sections;
105
    if ( length($string) > 35 ) {
106
        my ( $chunk, $stringlength ) = ( 35, length($string) );
107
        for ( my $counter = 0 ; $counter < $stringlength ; $counter += $chunk )
108
        {
109
            push @sections, substr( $string, $counter, $chunk );
110
        }
111
        foreach my $section (@sections) {
112
            $colon_string .= $section . ":";
113
        }
114
        chop($colon_string);
115
    }
116
    else {
117
        $colon_string = $string;
118
    }
119
    return $colon_string;
120
}
121
122
sub escape_reserved {
123
    my $string = shift;
124
    if ( $string ne "" ) {
125
        $string =~ s/\?/\?\?/g;
126
        $string =~ s/\'/\?\'/g;
127
        $string =~ s/\:/\?\:/g;
128
        $string =~ s/\+/\?\+/g;
129
        return $string;
130
    }
131
    else {
132
        return;
133
    }
134
}
135
136
sub cleanisbn {
137
    my $isbn = shift;
138
    if ( $isbn ne "" ) {
139
        my $i = index( $isbn, '(' );
140
        if ( $i > 1 ) {
141
            $isbn = substr( $isbn, 0, ( $i - 1 ) );
142
        }
143
        if ( index( $isbn, "|" ) != -1 ) {
144
            my @isbns = split( /\|/, $isbn );
145
            $isbn = $isbns[0];
146
        }
147
148
        #$isbn=__PACKAGE__->escape_reserved($isbn);
149
        $isbn =~ s/^\s+//;
150
        $isbn =~ s/\s+$//;
151
        return $isbn;
152
    }
153
    else {
154
        return;
155
    }
156
}
157
158
1;
(-)a/Rebus/EDI/Custom/Default.pm (+44 lines)
Line 0 Link Here
1
package Rebus::EDI::Custom::Default;
2
3
# Copyright 2012 Mark Gavillet
4
5
use strict;
6
use warnings;
7
8
use parent qw(Exporter);
9
10
=head1 NAME
11
12
Rebus::EDI::Custom::Default
13
14
=head1 VERSION
15
16
Version 0.01
17
18
=cut
19
20
our $VERSION = '0.01';
21
22
sub new {
23
    my $class = shift;
24
    my $self  = {};
25
    bless $self, $class;
26
    return $self;
27
}
28
29
sub transform_local_quote_copy {
30
    my ( $self, $item ) = @_;
31
32
    ### default - return the item without transformations
33
    return $item;
34
}
35
36
sub lsq_identifier {
37
    ### use CCODE authorised values in LSQ segment
38
    # return 'ccode';
39
40
    ### use LOC authorised values in LSQ segment
41
    return 'location';
42
}
43
44
1;
(-)a/Rebus/EDI/System/Koha.pm (+809 lines)
Line 0 Link Here
1
package Rebus::EDI::System::Koha;
2
3
# Copyright 2012 Mark Gavillet
4
5
use strict;
6
use warnings;
7
8
=head1 NAME
9
10
Rebus::EDI::System::Koha
11
12
=head1 VERSION
13
14
Version 0.01
15
16
=cut
17
18
use C4::Context;
19
20
our $VERSION = '0.01';
21
22
### Evergreen
23
#our $edidir				=	"/tmp/";
24
25
### Koha
26
our $edidir = "$ENV{'PERL5LIB'}/misc/edi_files/";
27
28
our $ftplogfile        = "$edidir/edi_ftp.log";
29
our $quoteerrorlogfile = "$edidir/edi_quote_error.log";
30
our $edi_quote_user    = 0;
31
32
sub new {
33
    my $class = shift;
34
    my $self  = {};
35
    bless $self, $class;
36
    return $self;
37
}
38
39
sub retrieve_vendor_ftp_accounts {
40
    my $self = shift;
41
    my $dbh  = C4::Context->dbh;
42
    my $sth  = $dbh->prepare(
43
        'select vendor_edi_accounts.id as edi_account_id, 
44
		aqbooksellers.id as account_id, aqbooksellers.name as vendor, 
45
		vendor_edi_accounts.host as server, vendor_edi_accounts.username as ftpuser, 
46
		vendor_edi_accounts.password as ftppass, vendor_edi_accounts.in_dir as ftpdir 
47
		from vendor_edi_accounts inner join aqbooksellers on 
48
		vendor_edi_accounts.provider = aqbooksellers.id'
49
    );
50
    $sth->execute();
51
    my $set = $sth->fetchall_arrayref( {} );
52
    my @accounts;
53
    my $new_account;
54
55
    foreach my $account (@$set) {
56
        $new_account = {
57
            account_id     => $account->{account_id},
58
            edi_account_id => $account->{edi_account_id},
59
            vendor         => $account->{vendor},
60
            server         => $account->{server},
61
            ftpuser        => $account->{ftpuser},
62
            ftppass        => $account->{ftppass},
63
            ftpdir         => $account->{ftpdir},
64
            po_org_unit    => 0,
65
        };
66
        push( @accounts, $new_account );
67
    }
68
    return @accounts;
69
}
70
71
sub download_quotes {
72
    my ( $self, $ftp_accounts ) = @_;
73
    my @local_files;
74
    foreach my $account (@$ftp_accounts) {
75
76
        #get vendor details
77
        print "server: " . $account->{server} . "\n";
78
        print "account: " . $account->{vendor} . "\n";
79
80
        #get files
81
        use Net::FTP;
82
        my $newerr;
83
        my @ERRORS;
84
        my @files;
85
        open my $ediftplog, '>>', $ftplogfile
86
          or die "Could not open $ftplogfile\n";
87
        my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
88
        printf $ediftplog "\n\n%4d-%02d-%02d %02d:%02d:%02d\n-----\n",
89
          $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
90
        print $ediftplog "Connecting to " . $account->{server} . "... ";
91
        my $ftp =
92
          Net::FTP->new( $account->{server}, Timeout => 10, Passive => 1 )
93
          or $newerr = 1;
94
        push @ERRORS, "Can't ftp to " . $account->{server} . ": $!\n"
95
          if $newerr;
96
        myerr(@ERRORS) if $newerr;
97
98
        if ( !$newerr ) {
99
            $newerr = 0;
100
            print $ediftplog "connected.\n";
101
102
            $ftp->login( $account->{ftpuser}, $account->{ftppass} )
103
              or $newerr = 1;
104
            print $ediftplog "Getting file list\n";
105
            push @ERRORS, "Can't login to " . $account->{server} . ": $!\n"
106
              if $newerr;
107
            $ftp->quit if $newerr;
108
            myerr(@ERRORS) if $newerr;
109
            if ( !$newerr ) {
110
                print $ediftplog "Logged in\n";
111
                $ftp->cwd( $account->{ftpdir} ) or $newerr = 1;
112
                push @ERRORS,
113
                  "Can't cd in server " . $account->{server} . " $!\n"
114
                  if $newerr;
115
                myerr(@ERRORS) if $newerr;
116
                $ftp->quit if $newerr;
117
118
                @files = $ftp->ls or $newerr = 1;
119
                push @ERRORS,
120
                  "Can't get file list from server "
121
                  . $account->{server} . " $!\n"
122
                  if $newerr;
123
                myerr(@ERRORS) if $newerr;
124
                if ( !$newerr ) {
125
                    print $ediftplog "Got  file list\n";
126
                    foreach (@files) {
127
                        my $filename = $_;
128
                        if ( ( index lc($filename), '.ceq' ) > -1 ) {
129
                            my $description = sprintf "%s/%s",
130
                              $account->{server}, $filename;
131
                            print $ediftplog "Found file: $description - ";
132
133
                            # deduplicate vs. acct/filenames already in DB
134
                            my $hits =
135
                              find_duplicate_quotes( $account->{edi_account_id},
136
                                $account->{ftpdir}, $filename );
137
138
                            my $match = 0;
139
                            if ( scalar(@$hits) ) {
140
                                print $ediftplog
141
                                  "File already retrieved. Skipping.\n";
142
                                $match = 1;
143
                            }
144
                            if ( $match ne 1 ) {
145
                                chdir "$edidir";
146
                                $ftp->get($filename) or $newerr = 1;
147
                                push @ERRORS,
148
                                  "Can't transfer file ($filename) from "
149
                                  . $account->{server} . " $!\n"
150
                                  if $newerr;
151
                                $ftp->quit if $newerr;
152
                                myerr(@ERRORS) if $newerr;
153
                                if ( !$newerr ) {
154
                                    print $ediftplog "File retrieved\n";
155
                                    open my $fh, '<', "$edidir/$filename"
156
                                      or die "Couldn't open file: $!\n";
157
                                    my $message_content = join( "", <$fh> );
158
                                    close $fh;
159
                                    my $logged_quote = LogQuote(
160
                                        $message_content,
161
                                        $account->{ftpdir} . "/" . $filename,
162
                                        $account->{server},
163
                                        $account->{edi_account_id}
164
                                    );
165
                                    my $quote_file = {
166
                                        filename    => $filename,
167
                                        account_id  => $account->{account_id},
168
                                        po_org_unit => $account->{po_org_unit},
169
                                        edi_quote_user  => $edi_quote_user,
170
                                        logged_quote_id => $logged_quote,
171
                                        edi_account_id =>
172
                                          $account->{edi_account_id},
173
                                    };
174
                                    push( @local_files, $quote_file );
175
                                }
176
                            }
177
                        }
178
                    }
179
                }
180
            }
181
182
            $ftp->quit;
183
        }
184
        $newerr = 0;
185
    }
186
    return @local_files;
187
}
188
189
sub myerr {
190
    my @errors = shift;
191
    open my $ediftplog, '>>', $ftplogfile or die "Could not open $ftplogfile\n";
192
    print $ediftplog "Error: ", @errors;
193
    close $ediftplog;
194
}
195
196
sub find_duplicate_quotes {
197
    my ( $edi_account_id, $ftpdir, $filename ) = @_;
198
    my $dbh = C4::Context->dbh;
199
    my $sth = $dbh->prepare(
200
        'select edifact_messages.key from edifact_messages 
201
		inner join vendor_edi_accounts on vendor_edi_accounts.provider=edifact_messages.provider 
202
		where vendor_edi_accounts.id=? and edifact_messages.remote_file=? and status<>?'
203
    );
204
    $sth->execute( $edi_account_id, $ftpdir . "/" . $filename, 'Processed' );
205
    my $hits = $sth->fetchall_arrayref( {} );
206
    return $hits;
207
}
208
209
# updates last activity in acq.edi_account and writes a new entry to acq.edi_message
210
sub LogQuote {
211
    my ( $content, $remote, $server, $account_or_id ) = @_;
212
    $content or return;
213
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
214
    my $last_activity =
215
      sprintf( "%4d-%02d-%02d", $year + 1900, $mon + 1, $mday );
216
    my $account = record_activity( $account_or_id, $last_activity );
217
    my $message_type = ( $content =~ /'UNH\+\w+\+(\S{6}):/ ) ? $1 : 'QUOTES';
218
    my $dbh          = C4::Context->dbh;
219
    my $sth          = $dbh->prepare(
220
        'insert into edifact_messages (message_type, date_sent, provider, 
221
		status, edi, remote_file) values (?,?,?,?,?,?)'
222
    );
223
    $sth->execute( $message_type, $last_activity, $account, 'Received',
224
        $content, $remote );
225
    my $insert_id =
226
      $dbh->last_insert_id( undef, undef, qw(edifact_messages key), undef );
227
228
    return $insert_id;
229
}
230
231
sub update_quote_status {
232
    my ( $quote_id, $edi_account_id, $basketno ) = @_;
233
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
234
    my $last_activity = sprintf '%4d-%02d-%02d', $year + 1900, $mon + 1, $mday;
235
    my $account = record_activity( $edi_account_id, $last_activity );
236
    my $dbh     = C4::Context->dbh;
237
    my $sth     = $dbh->prepare(
238
        'update edifact_messages set edifact_messages.status=?, 
239
		basketno=? where edifact_messages.key=?'
240
    );
241
    $sth->execute( 'Processed', $basketno, $quote_id );
242
}
243
244
sub record_activity {
245
    my ( $account_or_id, $last_activity ) = @_;
246
    $account_or_id or return;
247
    my $dbh = C4::Context->dbh;
248
    my $sth = $dbh->prepare(
249
        'update vendor_edi_accounts set last_activity=? where 
250
		id=?'
251
    );
252
    $sth->execute( $last_activity, $account_or_id );
253
    $sth = $dbh->prepare('select provider from vendor_edi_accounts where id=?');
254
    $sth->execute($account_or_id);
255
    my @result;
256
    my $provider;
257
258
    while ( @result = $sth->fetchrow_array() ) {
259
        $provider = $result[0];
260
    }
261
    return $provider;
262
}
263
264
sub process_quotes {
265
    my ( $self, $quotes ) = @_;
266
    foreach my $quote (@$quotes) {
267
        my $vendor_san = get_vendor_san( $quote->{account_id} );
268
        my $module     = get_vendor_module($vendor_san);
269
        $module or return;
270
        require "Rebus/EDI/Vendor/$module.pm";
271
        $module = "Rebus::EDI::Vendor::$module";
272
        import $module;
273
        my $vendor_module = $module->new();
274
        my @parsed_quote  = $vendor_module->parse_quote($quote);
275
        use C4::Acquisition;
276
        use C4::Biblio;
277
        use C4::Items;
278
        my $order_id =
279
          NewBasket( $quote->{account_id}, 0, $quote->{filename}, '', '', '' );
280
281
        foreach my $item (@parsed_quote) {
282
            foreach my $copy ( @{ $item->{copies} } ) {
283
                my $quote_copy = {
284
                    author => $item->{author},
285
                    price  => $item->{price},
286
                    ecost  => get_discounted_price(
287
                        $quote->{account_id}, $item->{price}
288
                    ),
289
                    llo       => $copy->{llo},
290
                    lfn       => $copy->{lfn},
291
                    lsq       => $copy->{lsq},
292
                    lst       => $copy->{lst},
293
                    lcl       => $copy->{lcl},
294
                    budget_id => get_budget_id( $copy->{lfn} ),
295
                    title     => $item->{title},
296
                    isbn      => $item->{isbn},
297
                    publisher => $item->{publisher},
298
                    year      => $item->{year},
299
                };
300
                use Rebus::EDI::Custom::Default;
301
                my $local_transform = Rebus::EDI::Custom::Default->new();
302
                my $koha_copy =
303
                  $local_transform->transform_local_quote_copy($quote_copy);
304
305
                my $lsq_identifier = $local_transform->lsq_identifier();
306
307
                # create biblio record
308
                my $record = TransformKohaToMarc(
309
                    {
310
                        "biblio.title"  => $koha_copy->{title},
311
                        "biblio.author" => $koha_copy->{author}
312
                        ? $koha_copy->{author}
313
                        : "",
314
                        "biblio.seriestitle" => "",
315
                        "biblioitems.isbn"   => $koha_copy->{isbn}
316
                        ? $koha_copy->{isbn}
317
                        : "",
318
                        "biblioitems.publishercode" => $koha_copy->{publisher}
319
                        ? $koha_copy->{publisher}
320
                        : "",
321
                        "biblioitems.publicationyear" => $koha_copy->{year}
322
                        ? $koha_copy->{year}
323
                        : "",
324
                        "biblio.copyrightdate" => $koha_copy->{year}
325
                        ? $koha_copy->{year}
326
                        : "",
327
                        "biblioitems.cn_source"  => "ddc",
328
                        "items.cn_source"        => "ddc",
329
                        "items.notforloan"       => "-1",
330
                        "items.$lsq_identifier"  => $koha_copy->{lsq},
331
                        "items.homebranch"       => $koha_copy->{llo},
332
                        "items.holdingbranch"    => $koha_copy->{llo},
333
                        "items.booksellerid"     => $quote->{account_id},
334
                        "items.price"            => $koha_copy->{price},
335
                        "items.replacementprice" => $koha_copy->{price},
336
                        "items.itemcallnumber"   => $koha_copy->{lcl},
337
                        "items.itype"            => $koha_copy->{lst},
338
                        "items.cn_sort"          => "",
339
                    }
340
                );
341
342
                #check if item already exists in catalogue
343
                my ( $biblionumber, $bibitemnumber ) =
344
                  check_order_item_exists( $item->{isbn} );
345
346
                if ( !defined $biblionumber ) {
347
348
                    # create the record in catalogue, with framework ''
349
                    ( $biblionumber, $bibitemnumber ) =
350
                      AddBiblio( $record, '' );
351
                }
352
353
                # create order line
354
                my %orderinfo = (
355
                    basketno                => $order_id,
356
                    ordernumber             => "",
357
                    subscription            => "no",
358
                    uncertainprice          => 0,
359
                    biblionumber            => $biblionumber,
360
                    title                   => $koha_copy->{title},
361
                    quantity                => 1,
362
                    biblioitemnumber        => $bibitemnumber,
363
                    rrp                     => $koha_copy->{price},
364
                    ecost                   => $koha_copy->{ecost},
365
                    sort1                   => "",
366
                    sort2                   => "",
367
                    booksellerinvoicenumber => $item->{item_reference},
368
                    listprice               => $koha_copy->{price},
369
                    branchcode              => $koha_copy->{llo},
370
                    budget_id               => $koha_copy->{budget_id},
371
                );
372
373
                my $orderinfo = \%orderinfo;
374
375
                my ( $retbasketno, $ordernumber ) = NewOrder($orderinfo);
376
377
                # now, add items if applicable
378
                if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
379
                    my $itemnumber;
380
                    ( $biblionumber, $bibitemnumber, $itemnumber ) =
381
                      AddItemFromMarc( $record, $biblionumber );
382
                    NewOrderItem( $itemnumber, $ordernumber );
383
                }
384
            }
385
        }
386
        update_quote_status( $quote->{logged_quote_id},
387
            $quote->{edi_account_id}, $order_id );
388
        ### manipulate quote file on remote server
389
        my $vendor_ftp_account =
390
          get_vendor_ftp_account( $quote->{edi_account_id} );
391
        $vendor_module->post_process_quote_file( $quote->{filename},
392
            $vendor_ftp_account );
393
        return 1;
394
395
    }
396
}
397
398
sub get_vendor_ftp_account {
399
    my $edi_account_id = shift;
400
    my $dbh            = C4::Context->dbh;
401
    my $sth            = $dbh->prepare(
402
        'select host,username,password,in_dir from vendor_edi_accounts 
403
		where id=?'
404
    );
405
    $sth->execute($edi_account_id);
406
    my @result;
407
    my $account;
408
    while ( @result = $sth->fetchrow_array() ) {
409
        $account = {
410
            host     => $result[0],
411
            username => $result[1],
412
            password => $result[2],
413
            in_dir   => $result[3],
414
        };
415
    }
416
    return $account;
417
}
418
419
sub get_discounted_price {
420
    my ( $booksellerid, $price ) = @_;
421
    my $dbh = C4::Context->dbh;
422
    my @discount;
423
    my $ecost;
424
    my $percentage;
425
    my $sth = $dbh->prepare('select discount from aqbooksellers where id=?');
426
    $sth->execute($booksellerid);
427
    while ( @discount = $sth->fetchrow_array() ) {
428
        $percentage = $discount[0];
429
    }
430
    $ecost = ( $price - ( ( $percentage * $price ) / 100 ) );
431
    return $ecost;
432
}
433
434
sub get_budget_id {
435
    my $fundcode = shift;
436
    my $dbh      = C4::Context->dbh;
437
    my @funds;
438
    my $ecost;
439
    my $budget_id;
440
    my $sth =
441
      $dbh->prepare('select budget_id from aqbudgets where budget_code=?');
442
    $sth->execute($fundcode);
443
    while ( @funds = $sth->fetchrow_array() ) {
444
        $budget_id = $funds[0];
445
    }
446
    return $budget_id;
447
}
448
449
sub get_vendor_san {
450
    my $vendor_id = shift;
451
    my $dbh       = C4::Context->dbh;
452
    my $sth =
453
      $dbh->prepare('select san from vendor_edi_accounts where provider=?');
454
    $sth->execute($vendor_id);
455
    my @result;
456
    my $san;
457
    while ( @result = $sth->fetchrow_array() ) {
458
        $san = $result[0];
459
    }
460
    return $san;
461
}
462
463
sub get_vendor_module {
464
    my $san = shift;
465
    my $module;
466
    use Rebus::EDI;
467
    my @vendor_list = Rebus::EDI::list_vendors();
468
    foreach my $vendor (@vendor_list) {
469
        if ( $san eq $vendor->{san} || $san eq $vendor->{ean} ) {
470
            $module = $vendor->{module};
471
            last;
472
        }
473
    }
474
    return $module;
475
}
476
477
sub check_order_item_exists {
478
    my $isbn = shift;
479
    my $dbh  = C4::Context->dbh;
480
    my $sth;
481
    my @matches;
482
    my $biblionumber;
483
    my $bibitemnumber;
484
    $sth = $dbh->prepare(
485
        'select biblionumber, biblioitemnumber from biblioitems where isbn=?');
486
    $sth->execute($isbn);
487
488
    while ( @matches = $sth->fetchrow_array() ) {
489
        $biblionumber  = $matches[0];
490
        $bibitemnumber = $matches[1];
491
    }
492
    if ($biblionumber) {
493
        return $biblionumber, $bibitemnumber;
494
    }
495
    else {
496
        use Rebus::EDI;
497
        use Business::ISBN;
498
        my $edi = Rebus::EDI->new();
499
        $isbn = $edi->cleanisbn($isbn);
500
        if ( length($isbn) == 10 ) {
501
            $isbn = Business::ISBN->new($isbn);
502
            if ($isbn) {
503
                if ( $isbn->is_valid ) {
504
                    $isbn = ( $isbn->as_isbn13 )->isbn;
505
                    $sth->execute($isbn);
506
                    while ( @matches = $sth->fetchrow_array() ) {
507
                        $biblionumber  = $matches[0];
508
                        $bibitemnumber = $matches[1];
509
                    }
510
                }
511
            }
512
        }
513
        elsif ( length($isbn) == 13 ) {
514
            $isbn = Business::ISBN->new($isbn);
515
            if ($isbn) {
516
                if ( $isbn->is_valid ) {
517
                    $isbn = ( $isbn->as_isbn10 )->isbn;
518
                    $sth->execute($isbn);
519
                    while ( @matches = $sth->fetchrow_array() ) {
520
                        $biblionumber  = $matches[0];
521
                        $bibitemnumber = $matches[1];
522
                    }
523
                }
524
            }
525
        }
526
        return $biblionumber, $bibitemnumber;
527
    }
528
}
529
530
sub retrieve_orders {
531
    my ( $self, $order_id ) = @_;
532
    my $dbh = C4::Context->dbh;
533
    my @active_orders;
534
535
    ## retrieve basic order details
536
    my $sth = $dbh->prepare(
537
        'select booksellerid as provider from aqbasket where basketno=?');
538
    $sth->execute($order_id);
539
    my $orders = $sth->fetchall_arrayref( {} );
540
541
    foreach my $order ( @{$orders} ) {
542
        push @active_orders,
543
          { order_id => $order_id, provider_id => $order->{provider} };
544
    }
545
    return \@active_orders;
546
}
547
548
sub retrieve_order_details {
549
    my ( $self, $orders, $ean ) = @_;
550
    my @fleshed_orders;
551
    foreach my $order ( @{$orders} ) {
552
        my $fleshed_order;
553
        $fleshed_order = {
554
            order_id    => $order->{order_id},
555
            provider_id => $order->{provider_id}
556
        };
557
558
        ## retrieve module for vendor
559
        my $dbh = C4::Context->dbh;
560
        my $sth =
561
          $dbh->prepare('select san from vendor_edi_accounts where provider=?');
562
        $sth->execute( $order->{provider_id} );
563
        my @result;
564
        my $san;
565
        while ( @result = $sth->fetchrow_array() ) {
566
            $san = $result[0];
567
        }
568
        $fleshed_order->{'module'}     = get_vendor_module($san);
569
        $fleshed_order->{'san_or_ean'} = $san;
570
        $fleshed_order->{'org_san'}    = $ean;
571
        $fleshed_order->{'quote_or_order'} =
572
          quote_or_order( $order->{order_id} );
573
        my @lineitems = get_order_lineitems( $order->{order_id} );
574
        $fleshed_order->{'lineitems'} = \@lineitems;
575
576
        push @fleshed_orders, $fleshed_order;
577
    }
578
    return \@fleshed_orders;
579
}
580
581
sub create_order_file {
582
    my ( $self, $order_message, $order_id ) = @_;
583
    my $filename = "$edidir/ediorder_$order_id.CEP";
584
    open my $ediorder, '>', $filename;
585
    print $ediorder $order_message;
586
    close $ediorder;
587
    my $vendor_ftp_account = get_vendor_ftp_account_by_order_id($order_id);
588
    my $sent_order =
589
      send_order_message( $filename, $vendor_ftp_account, $order_message,
590
        $order_id );
591
    return $filename;
592
}
593
594
sub get_vendor_ftp_account_by_order_id {
595
    my $order_id = shift;
596
    my $vendor_ftp_account;
597
    my @result;
598
    my $dbh = C4::Context->dbh;
599
    my $sth = $dbh->prepare(
600
        'select vendor_edi_accounts.* from vendor_edi_accounts, aqbasket 
601
		where vendor_edi_accounts.provider=aqbasket.booksellerid and aqbasket.basketno=?'
602
    );
603
    $sth->execute($order_id);
604
    while ( @result = $sth->fetchrow_array() ) {
605
        $vendor_ftp_account->{id}             = $result[0];
606
        $vendor_ftp_account->{label}          = $result[1];
607
        $vendor_ftp_account->{host}           = $result[2];
608
        $vendor_ftp_account->{username}       = $result[3];
609
        $vendor_ftp_account->{password}       = $result[4];
610
        $vendor_ftp_account->{path}           = $result[7];
611
        $vendor_ftp_account->{last_activity}  = $result[5];
612
        $vendor_ftp_account->{provider}       = $result[6];
613
        $vendor_ftp_account->{in_dir}         = $result[7];
614
        $vendor_ftp_account->{edi_account_id} = $result[0];
615
    }
616
    return $vendor_ftp_account;
617
}
618
619
sub send_order_message {
620
    my ( $filename, $ftpaccount, $order_message, $order_id ) = @_;
621
    my @ERRORS;
622
    my $newerr;
623
    my $result;
624
625
    open my $ediftplog, '>>', $ftplogfile or die "Could not open $ftplogfile\n";
626
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
627
    printf $ediftplog "\n\n%4d-%02d-%02d %02d:%02d:%02d\n-----\n", $year + 1900,
628
      $mon + 1, $mday, $hour, $min, $sec;
629
630
    # check edi order file exists
631
    if ( -e $filename ) {
632
        use Net::FTP;
633
634
        print $ediftplog "Connecting to " . $ftpaccount->{host} . "... ";
635
636
        # connect to ftp account
637
        my $ftp =
638
          Net::FTP->new( $ftpaccount->{host}, Timeout => 10, Passive => 1 )
639
          or $newerr = 1;
640
        push @ERRORS, "Can't ftp to " . $ftpaccount->{host} . ": $!\n"
641
          if $newerr;
642
        myerr(@ERRORS) if $newerr;
643
        if ( !$newerr ) {
644
            $newerr = 0;
645
            print $ediftplog "connected.\n";
646
647
            # login
648
            $ftp->login( "$ftpaccount->{username}", "$ftpaccount->{password}" )
649
              or $newerr = 1;
650
            $ftp->quit if $newerr;
651
            print $ediftplog "Logging in...\n";
652
            push @ERRORS, "Can't login to " . $ftpaccount->{host} . ": $!\n"
653
              if $newerr;
654
            myerr(@ERRORS) if $newerr;
655
            if ( !$newerr ) {
656
                print $ediftplog "Logged in\n";
657
658
                # cd to directory
659
                $ftp->cwd("$ftpaccount->{path}") or $newerr = 1;
660
                push @ERRORS,
661
                  "Can't cd in server " . $ftpaccount->{host} . " $!\n"
662
                  if $newerr;
663
                myerr(@ERRORS) if $newerr;
664
                $ftp->quit if $newerr;
665
666
                # put file
667
                if ( !$newerr ) {
668
                    $newerr = 0;
669
                    $ftp->put($filename) or $newerr = 1;
670
                    push @ERRORS,
671
                      "Can't write order file to server "
672
                      . $ftpaccount->{host} . " $!\n"
673
                      if $newerr;
674
                    myerr(@ERRORS) if $newerr;
675
                    $ftp->quit if $newerr;
676
                    if ( !$newerr ) {
677
                        print $ediftplog
678
                          "File: $filename transferred successfully\n";
679
                        $ftp->quit;
680
                        unlink($filename);
681
                        record_activity( $ftpaccount->{id} );
682
                        log_order(
683
                            $order_message,
684
                            $ftpaccount->{path} . substr( $filename, 4 ),
685
                            $ftpaccount->{edi_account_id},
686
                            $order_id
687
                        );
688
689
                        return $result;
690
                    }
691
                }
692
            }
693
        }
694
    }
695
    else {
696
        print $ediftplog "Order file $filename does not exist\n";
697
    }
698
}
699
700
sub log_order {
701
    my ( $content, $remote, $edi_account_id, $order_id ) = @_;
702
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
703
    my $date_sent = sprintf( "%4d-%02d-%02d", $year + 1900, $mon + 1, $mday );
704
705
    my $dbh = C4::Context->dbh;
706
    my $sth = $dbh->prepare(
707
'insert into edifact_messages (message_type,date_sent,provider,status,basketno,
708
		edi,remote_file) values (?,?,?,?,?,?,?)'
709
    );
710
    $sth->execute( 'ORDER', $date_sent, $edi_account_id, 'Sent', $order_id,
711
        $content, $remote );
712
}
713
714
sub quote_or_order {
715
    my $order_id = shift;
716
    my @result;
717
    my $quote_or_order;
718
    my $dbh = C4::Context->dbh;
719
    my $sth = $dbh->prepare(
720
        'select edifact_messages.key from edifact_messages 
721
		where basketno=? and message_type=?'
722
    );
723
    $sth->execute( $order_id, 'QUOTES' );
724
    if ( $sth->rows == 0 ) {
725
        $quote_or_order = 'o';
726
    }
727
    else {
728
        $quote_or_order = 'q';
729
    }
730
    return $quote_or_order;
731
}
732
733
sub get_order_lineitems {
734
    my $order_id = shift;
735
    use C4::Acquisition;
736
    my @lineitems = GetOrders($order_id);
737
    my @fleshed_lineitems;
738
    foreach my $lineitem (@lineitems) {
739
        use Rebus::EDI;
740
        my $clean_isbn = Rebus::EDI::cleanisbn( $lineitem->{isbn} );
741
        my $fleshed_lineitem;
742
        $fleshed_lineitem->{binding}  = 'O';
743
        $fleshed_lineitem->{currency} = 'GBP';
744
        $fleshed_lineitem->{id}       = $lineitem->{ordernumber};
745
        $fleshed_lineitem->{qli}      = $lineitem->{booksellerinvoicenumber};
746
        $fleshed_lineitem->{rff}    = $order_id . "/" . $fleshed_lineitem->{id};
747
        $fleshed_lineitem->{isbn}   = $clean_isbn;
748
        $fleshed_lineitem->{title}  = $lineitem->{title};
749
        $fleshed_lineitem->{author} = $lineitem->{author};
750
        $fleshed_lineitem->{publisher} = $lineitem->{publishercode};
751
        $fleshed_lineitem->{year}      = $lineitem->{copyrightdate};
752
        $fleshed_lineitem->{price}     = sprintf "%.2f", $lineitem->{listprice};
753
        $fleshed_lineitem->{quantity}  = '1';
754
755
        my @lineitem_copies;
756
        my $fleshed_lineitem_detail;
757
        my ( $branchcode, $callnumber, $itype, $location, $fund ) =
758
          get_lineitem_additional_info( $lineitem->{ordernumber} );
759
        $fleshed_lineitem_detail->{llo}  = $branchcode;
760
        $fleshed_lineitem_detail->{lfn}  = $fund;
761
        $fleshed_lineitem_detail->{lsq}  = $location;
762
        $fleshed_lineitem_detail->{lst}  = $itype;
763
        $fleshed_lineitem_detail->{lcl}  = $callnumber;
764
        $fleshed_lineitem_detail->{note} = $lineitem->{notes};
765
        push( @lineitem_copies, $fleshed_lineitem_detail );
766
767
        $fleshed_lineitem->{copies} = \@lineitem_copies;
768
        push( @fleshed_lineitems, $fleshed_lineitem );
769
    }
770
    return @fleshed_lineitems;
771
}
772
773
sub get_lineitem_additional_info {
774
    my $ordernumber = shift;
775
    my @rows;
776
    my $homebranch;
777
    my $callnumber;
778
    my $itype;
779
    my $location;
780
    my $fund;
781
    use Rebus::EDI::Custom::Default;
782
    my $local_transform = Rebus::EDI::Custom::Default->new();
783
    my $lsq_identifier  = $local_transform->lsq_identifier();
784
    my $dbh             = C4::Context->dbh;
785
    my $sth             = $dbh->prepare(
786
        "select items.homebranch, items.itemcallnumber, items.itype, 
787
		items.$lsq_identifier from items inner join aqorders_items on 
788
		aqorders_items.itemnumber=items.itemnumber where aqorders_items.ordernumber=?"
789
    );
790
    $sth->execute($ordernumber);
791
792
    while ( @rows = $sth->fetchrow_array() ) {
793
        $homebranch = $rows[0];
794
        $callnumber = $rows[1];
795
        $itype      = $rows[2];
796
        $location   = $rows[3];
797
    }
798
    $sth = $dbh->prepare(
799
        "select aqbudgets.budget_code from aqbudgets inner join aqorders on 
800
		aqorders.budget_id=aqbudgets.budget_id where aqorders.ordernumber=?"
801
    );
802
    $sth->execute($ordernumber);
803
    while ( @rows = $sth->fetchrow_array() ) {
804
        $fund = $rows[0];
805
    }
806
    return $homebranch, $callnumber, $itype, $location, $fund;
807
}
808
809
1;
(-)a/Rebus/EDI/Vendor/Default.pm (+384 lines)
Line 0 Link Here
1
package Rebus::EDI::Vendor::Default;
2
3
# Copyright 2012 Mark Gavillet
4
5
use strict;
6
use warnings;
7
8
use parent qw(Exporter);
9
our @EXPORT = qw(
10
  test
11
);
12
13
use Business::Edifact::Interchange;
14
### Evergreen
15
#our $edidir				=	"/tmp/";
16
17
### Koha
18
our $edidir = "$ENV{'PERL5LIB'}/misc/edi_files/";
19
20
=head1 NAME
21
22
Rebus::EDI::Vendor::Default
23
24
=head1 VERSION
25
26
Version 0.01
27
28
=cut
29
30
our $VERSION = '0.01';
31
32
sub new {
33
    my $class = shift;
34
    my $self  = {};
35
    bless $self, $class;
36
    return $self;
37
}
38
39
sub parse_quote {
40
    my ( $self, $quote ) = @_;
41
    my $edi = Business::Edifact::Interchange->new;
42
    my @parsed_quote;
43
    $edi->parse_file( $edidir . $quote->{filename} );
44
    my $messages      = $edi->messages();
45
    my $message_count = @{$messages};
46
    my $count;
47
48
    for ( $count = 0 ; $count < $message_count ; $count++ ) {
49
        my $items = $messages->[$count]->items();
50
51
        foreach my $item ( @{$items} ) {
52
            my $parsed_item = {
53
                author => $item->author_surname . ", "
54
                  . $item->author_firstname,
55
                title          => $item->title,
56
                isbn           => $item->{item_number},
57
                price          => $item->{price}->{price},
58
                publisher      => $item->publisher,
59
                year           => $item->date_of_publication,
60
                item_reference => $item->{item_reference}[0][1],
61
                copies         => '',
62
            };
63
            my $quantity = $item->{quantity};
64
            my @copies;
65
            for ( my $i = 0 ; $i < $item->{quantity} ; $i++ ) {
66
                my $llo       = $item->{related_numbers}->[$i]->{LLO}->[0];
67
                my $lfn       = $item->{related_numbers}->[$i]->{LFN}->[0];
68
                my $lsq       = $item->{related_numbers}->[$i]->{LSQ}->[0];
69
                my $lst       = $item->{related_numbers}->[$i]->{LST}->[0];
70
                my $shelfmark = $item->shelfmark;
71
                my $ftxlin;
72
                my $ftxlno;
73
                if ( $item->{free_text}->{qualifier} eq "LIN" ) {
74
                    $ftxlin = $item->{free_text}->{text};
75
                }
76
                if ( $item->{free_text}->{qualifier} eq "LNO" ) {
77
                    $ftxlno = $item->{free_text}->{text};
78
                }
79
                my $note;
80
                if ($ftxlin) {
81
                    $note = $ftxlin;
82
                }
83
                if ($ftxlno) {
84
                    $note = $ftxlno;
85
                }
86
                my $parsed_copy = {
87
                    llo       => $llo,
88
                    lfn       => $lfn,
89
                    lsq       => $lsq,
90
                    lst       => $lst,
91
                    shelfmark => $shelfmark,
92
                    note      => $note,
93
                };
94
                push( @copies, $parsed_copy );
95
            }
96
            $parsed_item->{"copies"} = \@copies;
97
            push( @parsed_quote, $parsed_item );
98
        }
99
    }
100
    return @parsed_quote;
101
}
102
103
sub create_order_message {
104
    my ( $self, $order ) = @_;
105
    my @datetime  = localtime(time);
106
    my $longyear  = ( $datetime[5] + 1900 );
107
    my $shortyear = sprintf "%02d", ( $datetime[5] - 100 );
108
    my $date      = sprintf "%02d%02d", ( $datetime[4] + 1 ), $datetime[3];
109
    my $hourmin   = sprintf "%02d%02d", $datetime[2], $datetime[1];
110
    my $year      = ( $datetime[5] - 100 );
111
    my $month     = sprintf "%02d", ( $datetime[4] + 1 );
112
    my $linecount = 0;
113
    my $segment   = 0;
114
    my $exchange  = int( rand(99999999999999) );
115
    my $ref       = int( rand(99999999999999) );
116
117
    ### opening header
118
    my $order_message = "UNA:+.? '";
119
120
    ### Library SAN or EAN
121
    $order_message .= "UNB+UNOC:2";
122
    if ( length( $order->{org_san} ) != 13 ) {
123
        $order_message .= "+" . $order->{org_san} . ":31B";  # use SAN qualifier
124
    }
125
    else {
126
        $order_message .= "+" . $order->{org_san} . ":14";   # use EAN qualifier
127
    }
128
129
    ### Vendor SAN or EAN
130
    if ( length( $order->{san_or_ean} ) != 13 ) {
131
        $order_message .=
132
          "+" . $order->{san_or_ean} . ":31B";               # use SAN qualifier
133
    }
134
    else {
135
        $order_message .=
136
          "+" . $order->{san_or_ean} . ":14";                # use EAN qualifier
137
    }
138
139
    ### date/time, exchange reference number
140
    $order_message .=
141
      "+$shortyear$date:$hourmin+" . $exchange . "++ORDERS+++EANCOM'";
142
143
    ### message reference number
144
    $order_message .= "UNH+" . $ref . "+ORDERS:D:96A:UN:EAN008'";
145
    $segment++;
146
147
    ### Order number and quote confirmation reference (if in response to quote)
148
    if ( $order->{quote_or_order} eq 'q' ) {
149
        $order_message .= "BGM+22V+" . $order->{order_id} . "+9'";
150
        $segment++;
151
    }
152
    else {
153
        $order_message .= "BGM+220+" . $order->{order_id} . "+9'";
154
        $segment++;
155
    }
156
157
    ### Date of message
158
    $order_message .= "DTM+137:$longyear$date:102'";
159
    $segment++;
160
161
    ### Library Address Identifier (SAN or EAN)
162
    if ( length( $order->{org_san} ) != 13 ) {
163
        $order_message .= "NAD+BY+" . $order->{org_san} . "::31B'";
164
        $segment++;
165
    }
166
    else {
167
        $order_message .= "NAD+BY+" . $order->{org_san} . "::9'";
168
        $segment++;
169
    }
170
171
    ### Vendor address identifier (SAN or EAN)
172
    if ( length( $order->{san_or_ean} ) != 13 ) {
173
        $order_message .= "NAD+SU+" . $order->{san_or_ean} . "::31B'";
174
        $segment++;
175
    }
176
    else {
177
        $order_message .= "NAD+SU+" . $order->{san_or_ean} . "::9'";
178
        $segment++;
179
    }
180
181
    ### Library's internal ID for Vendor
182
    $order_message .= "NAD+SU+" . $order->{provider_id} . "::92'";
183
    $segment++;
184
185
    ### Lineitems
186
    foreach my $lineitem ( @{ $order->{lineitems} } ) {
187
        use Rebus::EDI;
188
        use Business::ISBN;
189
        $linecount++;
190
        my $note;
191
        my $isbn;
192
        if (   length( $lineitem->{isbn} ) == 10
193
            || substr( $lineitem->{isbn}, 0, 3 ) eq "978"
194
            || index( $lineitem->{isbn}, "|" ) != -1 )
195
        {
196
            $isbn = Rebus::EDI::cleanisbn( $lineitem->{isbn} );
197
            $isbn = Business::ISBN->new($isbn);
198
            if ($isbn) {
199
                if ( $isbn->is_valid ) {
200
                    $isbn = ( $isbn->as_isbn13 )->isbn;
201
                }
202
                else {
203
                    $isbn = "0";
204
                }
205
            }
206
            else {
207
                $isbn = 0;
208
            }
209
        }
210
        else {
211
            $isbn = $lineitem->{isbn};
212
        }
213
214
        ### line number, isbn
215
        $order_message .= "LIN+$linecount++" . $isbn . ":EN'";
216
        $segment++;
217
218
        ### isbn as main product identification
219
        $order_message .= "PIA+5+" . $isbn . ":IB'";
220
        $segment++;
221
222
        ### title
223
        $order_message .=
224
          "IMD+L+050+:::"
225
          . Rebus::EDI::string35escape(
226
            Rebus::EDI::escape_reserved( $lineitem->{title} ) )
227
          . "'";
228
        $segment++;
229
230
        ### author
231
        $order_message .=
232
          "IMD+L+009+:::"
233
          . Rebus::EDI::string35escape(
234
            Rebus::EDI::escape_reserved( $lineitem->{author} ) )
235
          . "'";
236
        $segment++;
237
238
        ### publisher
239
        $order_message .=
240
          "IMD+L+109+:::"
241
          . Rebus::EDI::string35escape(
242
            Rebus::EDI::escape_reserved( $lineitem->{publisher} ) )
243
          . "'";
244
        $segment++;
245
246
        ### date of publication
247
        $order_message .= "IMD+L+170+:::"
248
          . Rebus::EDI::escape_reserved( $lineitem->{year} ) . "'";
249
        $segment++;
250
251
        ### binding
252
        $order_message .= "IMD+L+220+:::"
253
          . Rebus::EDI::escape_reserved( $lineitem->{binding} ) . "'";
254
        $segment++;
255
256
        ### quantity
257
        $order_message .= "QTY+21:"
258
          . Rebus::EDI::escape_reserved( $lineitem->{quantity} ) . "'";
259
        $segment++;
260
261
        ### copies
262
        my $copyno = 0;
263
        foreach my $copy ( @{ $lineitem->{copies} } ) {
264
            my $gir_cnt = 0;
265
            $copyno++;
266
            $segment++;
267
268
            ### copy number
269
            $order_message .= "GIR+" . sprintf( "%03d", $copyno );
270
271
            ### quantity
272
            $order_message .= "+1:LQT";
273
            $gir_cnt++;
274
275
            ### Library branchcode
276
            $order_message .= "+" . $copy->{llo} . ":LLO";
277
            $gir_cnt++;
278
279
            ### Fund code
280
            $order_message .= "+" . $copy->{lfn} . ":LFN";
281
            $gir_cnt++;
282
283
            ### call number
284
            if ( $copy->{lcl} ) {
285
                $order_message .= "+" . $copy->{lcl} . ":LCL";
286
                $gir_cnt++;
287
            }
288
289
            ### copy location
290
            if ( $copy->{lsq} ) {
291
                $order_message .= "+"
292
                  . Rebus::EDI::string35escape(
293
                    Rebus::EDI::escape_reserved( $copy->{lsq} ) )
294
                  . ":LSQ";
295
                $gir_cnt++;
296
            }
297
298
            ### circ modifier
299
            if ( $gir_cnt >= 5 ) {
300
                $order_message .= "'GIR+"
301
                  . sprintf( "%03d", $copyno ) . "+"
302
                  . $copy->{lst} . ":LST";
303
            }
304
            else {
305
                $order_message .= "+" . $copy->{lst} . ":LST";
306
            }
307
308
            ### close GIR segment
309
            $order_message .= "'";
310
311
            $note = $copy->{note};
312
        }
313
314
        ### Freetext item note
315
        if ($note) {
316
            $order_message .= "FTX+LIN+++:::$note'";
317
            $segment++;
318
        }
319
320
        ### price
321
        if ( $lineitem->{price} ) {
322
            $order_message .= "PRI+AAB:" . $lineitem->{price} . "'";
323
            $segment++;
324
        }
325
326
        ### currency
327
        $order_message .= "CUX+2:" . $lineitem->{currency} . ":9'";
328
        $segment++;
329
330
        ### Local order number
331
        $order_message .= "RFF+LI:" . $lineitem->{rff} . "'";
332
        $segment++;
333
334
        ### Quote reference (if in response to quote)
335
        if ( $order->{quote_or_order} eq 'q' ) {
336
            $order_message .= "RFF+QLI:" . $lineitem->{qli} . "'";
337
            $segment++;
338
        }
339
    }
340
    ### summary section header and number of lineitems contained in message
341
    $order_message .= "UNS+S'";
342
    $segment++;
343
344
    ### Number of lineitems contained in the message_count
345
    $order_message .= "CNT+2:$linecount'";
346
    $segment++;
347
348
    ### number of segments in the message (+1 to include the UNT segment itself) and reference number from UNH segment
349
    $segment++;
350
    $order_message .= "UNT+$segment+" . $ref . "'";
351
352
    ### Exchange reference number from UNB segment
353
    $order_message .= "UNZ+1+" . $exchange . "'";
354
    return $order_message;
355
}
356
357
sub post_process_quote_file {
358
    my ( $self, $remote_file, $ftp_account ) = @_;
359
360
    ### connect to vendor ftp account
361
    my $filename = substr( $remote_file, rindex( $remote_file, '/' ) + 1 );
362
    use Net::FTP::File;
363
    my $ftp = Net::FTP->new( $ftp_account->{host}, Timeout => 10 )
364
      or die "Couldn't connect";
365
    $ftp->login( $ftp_account->{username}, $ftp_account->{password} )
366
      or die "Couldn't log in";
367
    $ftp->cwd( $ftp_account->{in_dir} ) or die "Couldn't change directory";
368
369
    ### move file to another directory
370
#my $new_dir='processed';
371
#my $new_file=$new_dir."/".$filename;
372
#$ftp->copy($filename, $new_file) or die "Couldn't move remote file to $new_file ";
373
#$ftp->delete($filename);
374
#$ftp->quit;
375
376
    ### rename file
377
    my $rext = '.EEQ';
378
    my $qext = '.CEQ';
379
    $filename =~ s/$qext/$rext/g;
380
    $ftp->rename( $remote_file, $filename )
381
      or die "Couldn't rename remote file";
382
}
383
384
1;
(-)a/acqui/basket.pl (+11 lines)
Lines 35-40 use C4::Biblio; Link Here
35
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
35
use C4::Members qw/GetMember/;  #needed for permissions checking for changing basketgroup of a basket
36
use C4::Items;
36
use C4::Items;
37
use C4::Suggestions;
37
use C4::Suggestions;
38
use C4::Edifact;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 66-71 the supplier this script have to display the basket. Link Here
66
67
67
my $query        = new CGI;
68
my $query        = new CGI;
68
my $basketno     = $query->param('basketno');
69
my $basketno     = $query->param('basketno');
70
my $ean			= $query->param('ean');
69
my $booksellerid = $query->param('booksellerid');
71
my $booksellerid = $query->param('booksellerid');
70
72
71
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
73
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 86-97 my $basket = GetBasket($basketno); Link Here
86
# if no booksellerid in parameter, get it from basket
88
# if no booksellerid in parameter, get it from basket
87
# warn "=>".$basket->{booksellerid};
89
# warn "=>".$basket->{booksellerid};
88
$booksellerid = $basket->{booksellerid} unless $booksellerid;
90
$booksellerid = $basket->{booksellerid} unless $booksellerid;
91
my $ediaccount = CheckVendorFTPAccountExists($booksellerid);
92
$template->param(ediaccount=>$ediaccount);
89
my ($bookseller) = GetBookSellerFromId($booksellerid);
93
my ($bookseller) = GetBookSellerFromId($booksellerid);
90
my $op = $query->param('op');
94
my $op = $query->param('op');
91
if (!defined $op) {
95
if (!defined $op) {
92
    $op = q{};
96
    $op = q{};
93
}
97
}
94
98
99
if ( $op eq 'ediorder') {
100
	use Rebus::EDI;
101
	my $edi=Rebus::EDI->new();
102
	$edi->send_orders($basketno,$ean);
103
	$template->param(edifile => 1);
104
}
105
95
my $confirm_pref= C4::Context->preference("BasketConfirmations") || '1';
106
my $confirm_pref= C4::Context->preference("BasketConfirmations") || '1';
96
$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
107
$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
97
108
(-)a/acqui/edi_ean.pl (+56 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2012 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use C4::Auth;
24
use C4::Koha;
25
use C4::Output;
26
use CGI;
27
use C4::Edifact;
28
29
my $eans       = GetEDIfactEANs();
30
my $total_eans = scalar( @{$eans} );
31
my $query      = new CGI;
32
my $basketno   = $query->param('basketno');
33
my $ean;
34
35
if ( $total_eans == 1 ) {
36
    $ean = $eans->[0]->{ean};
37
    print $query->redirect(
38
        "/cgi-bin/koha/acqui/basket.pl?basketno=$basketno&op=ediorder&ean=$ean"
39
    );
40
}
41
else {
42
    my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
        {
44
            template_name   => "acqui/edi_ean.tt",
45
            query           => $query,
46
            type            => "intranet",
47
            authnotrequired => 0,
48
            flagsrequired   => { acquisition => 'order_manage' },
49
            debug           => 1,
50
        }
51
    );
52
    $template->param( eans     => $eans );
53
    $template->param( basketno => $basketno );
54
55
    output_html_with_http_headers $query, $cookie, $template->output;
56
}
(-)a/admin/edi-accounts.pl (+78 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Edifact;
26
27
use vars qw($debug);
28
29
BEGIN {
30
    $debug = $ENV{DEBUG} || 0;
31
}
32
33
my $input = CGI->new();
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
        template_name   => "admin/edi-accounts.tmpl",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1 },
42
        debug           => ($debug) ? 1 : 0,
43
    }
44
);
45
46
my $op = $input->param('op');
47
$template->param( op => $op );
48
49
if ( $op eq "delsubmit" ) {
50
    my $del = C4::Edifact::DeleteEDIDetails( $input->param('id') );
51
    $template->param( opdelsubmit => 1 );
52
}
53
54
if ( $op eq "addsubmit" ) {
55
    CreateEDIDetails(
56
        $input->param('provider'), $input->param('description'),
57
        $input->param('host'),     $input->param('user'),
58
        $input->param('pass'),     $input->param('path'),
59
        $input->param('in_dir'),   $input->param('san')
60
    );
61
    $template->param( opaddsubmit => 1 );
62
}
63
64
if ( $op eq "editsubmit" ) {
65
    UpdateEDIDetails(
66
        $input->param('editid'), $input->param('description'),
67
        $input->param('host'),   $input->param('user'),
68
        $input->param('pass'),   $input->param('provider'),
69
        $input->param('path'),   $input->param('in_dir'),
70
        $input->param('san')
71
    );
72
    $template->param( opeditsubmit => 1 );
73
}
74
75
my $ediaccounts = C4::Edifact::GetEDIAccounts;
76
$template->param( ediaccounts => $ediaccounts );
77
78
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/admin/edi-edit.pl (+80 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Edifact;
26
27
use vars qw($debug);
28
29
BEGIN {
30
    $debug = $ENV{DEBUG} || 0;
31
}
32
33
my $input = CGI->new();
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
        template_name   => "admin/edi-edit.tmpl",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1 },
42
        debug           => ($debug) ? 1 : 0,
43
    }
44
);
45
my $vendorlist = C4::Edifact::GetVendorList;
46
47
my $op = $input->param('op');
48
$template->param( op => $op );
49
50
if ( $op eq "add" ) {
51
    $template->param( opaddsubmit => "addsubmit" );
52
}
53
if ( $op eq "edit" ) {
54
    $template->param( opeditsubmit => "editsubmit" );
55
    my $edi_details = C4::Edifact::GetEDIAccountDetails( $input->param('id') );
56
    my $selectedprovider = $edi_details->{'provider'};
57
    foreach my $prov (@$vendorlist) {
58
        $prov->{selected} = 'selected'
59
          if $prov->{'id'} == $selectedprovider;
60
    }
61
    $template->param(
62
        editid      => $edi_details->{'id'},
63
        description => $edi_details->{'description'},
64
        host        => $edi_details->{'host'},
65
        user        => $edi_details->{'username'},
66
        pass        => $edi_details->{'password'},
67
        provider    => $edi_details->{'provider'},
68
        in_dir      => $edi_details->{'in_dir'},
69
        san         => $edi_details->{'san'}
70
    );
71
}
72
if ( $op eq "del" ) {
73
    $template->param( opdelsubmit => "delsubmit" );
74
    $template->param( opdel       => 1 );
75
    $template->param( id          => $input->param('id') );
76
}
77
78
$template->param( vendorlist => $vendorlist );
79
80
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/admin/edi_ean_accounts.pl (+71 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2012 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Edifact;
26
27
use vars qw($debug);
28
29
BEGIN {
30
    $debug = $ENV{DEBUG} || 0;
31
}
32
33
my $input = CGI->new();
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
        template_name   => "admin/edi_ean_accounts.tt",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1 },
42
        debug           => ($debug) ? 1 : 0,
43
    }
44
);
45
46
my $op = $input->param('op');
47
$template->param( op => $op );
48
49
if ( $op eq "delsubmit" ) {
50
    my $del = C4::Edifact::delete_edi_ean( $input->param('branchcode'),
51
        $input->param('ean') );
52
    $template->param( opdelsubmit => 1 );
53
}
54
55
if ( $op eq "addsubmit" ) {
56
    create_edi_ean( $input->param('branchcode'), $input->param('ean') );
57
    $template->param( opaddsubmit => 1 );
58
}
59
60
if ( $op eq "editsubmit" ) {
61
    update_edi_ean(
62
        $input->param('branchcode'),    $input->param('ean'),
63
        $input->param('oldbranchcode'), $input->param('oldean')
64
    );
65
    $template->param( opeditsubmit => 1 );
66
}
67
68
my $eans = C4::Edifact::GetEDIfactEANs;
69
$template->param( eans => $eans );
70
71
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/admin/edi_ean_edit.pl (+71 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2012 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Edifact;
26
27
use vars qw($debug);
28
29
BEGIN {
30
    $debug = $ENV{DEBUG} || 0;
31
}
32
33
my $input = CGI->new();
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
        template_name   => "admin/edi_ean_edit.tt",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1 },
42
        debug           => ($debug) ? 1 : 0,
43
    }
44
);
45
my $branchlist = C4::Edifact::GetBranchList;
46
47
my $op = $input->param('op');
48
$template->param( op => $op );
49
50
if ( $op eq "add" ) {
51
    $template->param( opaddsubmit => "addsubmit" );
52
}
53
if ( $op eq "edit" ) {
54
    $template->param( opeditsubmit => "editsubmit" );
55
56
    $template->param(
57
        ean            => $input->param('ean'),
58
        selectedbranch => $input->param('branchcode'),
59
        branchcode     => $input->param('branchcode')
60
    );
61
}
62
if ( $op eq "del" ) {
63
    $template->param( opdelsubmit => "delsubmit" );
64
    $template->param( opdel       => 1 );
65
    $template->param( ean         => $input->param('ean') );
66
    $template->param( branchcode  => $input->param('branchcode') );
67
}
68
69
$template->param( branchlist => $branchlist );
70
71
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/updatedatabase.pl (+21 lines)
Lines 4944-4949 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4944
}
4944
}
4945
4945
4946
4946
4947
$DBversion = "3.07.00.XXX";
4948
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
4949
	$dbh->do(
4950
	"CREATE TABLE IF NOT EXISTS `vendor_edi_accounts` (`id` int(11) NOT NULL auto_increment,`description` text NOT NULL,`host` text,`username` text,`password` text,`last_activity` date default NULL,`provider` int(11) default NULL,`in_dir` text,`san` varchar(20) default NULL,PRIMARY KEY  (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"
4951
	);
4952
	$dbh->do(
4953
	"CREATE TABLE IF NOT EXISTS `edifact_messages` (`key` int(11) NOT NULL auto_increment,`message_type` text NOT NULL,`date_sent` date default NULL,`provider` int(11) default NULL,`status` text,`basketno` int(11) NOT NULL default '0',PRIMARY KEY  (`key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"
4954
	);
4955
	$dbh->do(
4956
	"insert into permissions (module_bit, code, description) values (13, 'edi_manage', 'Manage EDIFACT transmissions')"
4957
	);
4958
	$dbh->do(
4959
	"ALTER TABLE edifact_messages ADD edi LONGTEXT, ADD remote_file TEXT"
4960
	);
4961
	$dbh->do(
4962
	"CREATE TABLE IF NOT EXISTS `edifact_ean` (`branchcode` varchar(10) NOT NULL default '',`ean` varchar(15) NOT NULL default '',UNIQUE KEY `edifact_ean_branchcode` (`branchcode`)) ENGINE=InnoDB DEFAULT CHARSET=utf8"
4963
	);
4964
    print "Upgrade to $DBversion done (Bug xxxx: Edifact quote and order processing.)\n";
4965
    SetVersion($DBversion);
4966
}
4967
4947
=head1 FUNCTIONS
4968
=head1 FUNCTIONS
4948
4969
4949
=head2 DropAllForeignKeys($table)
4970
=head2 DropAllForeignKeys($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (+2 lines)
Lines 61-66 Link Here
61
	[% IF ( NoZebra ) %]<li><a href="/cgi-bin/koha/admin/stopwords.pl">Stop Words</a></li>[% END %]
61
	[% IF ( NoZebra ) %]<li><a href="/cgi-bin/koha/admin/stopwords.pl">Stop Words</a></li>[% END %]
62
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
62
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
63
	<li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></li>
63
	<li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></li>
64
	<li><a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></li>
65
	<li><a href="/cgi-bin/koha/admin/edi_ean_accounts.pl">EDI EANs</a></li>
64
</ul>
66
</ul>
65
</div>
67
</div>
66
</div>
68
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (+3 lines)
Lines 91-94 Link Here
91
    [% IF ( CAN_user_tools_schedule_tasks ) %]
91
    [% IF ( CAN_user_tools_schedule_tasks ) %]
92
	<li><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></li>
92
	<li><a href="/cgi-bin/koha/tools/scheduler.pl">Task scheduler</a></li>
93
    [% END %]
93
    [% END %]
94
    [% IF ( CAN_user_tools_edi_manage ) %]
95
	<li><a href="/cgi-bin/koha/tools/edi.pl">EDIfact messages</a></li>
96
    [% END %]
94
</ul></div></div>
97
</ul></div></div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-1 / +7 lines)
Lines 105-110 Link Here
105
                            new YAHOO.widget.Button("basketheadbutton");
105
                            new YAHOO.widget.Button("basketheadbutton");
106
                            new YAHOO.widget.Button("exportbutton");
106
                            new YAHOO.widget.Button("exportbutton");
107
                            new YAHOO.widget.Button("delbasketbutton");
107
                            new YAHOO.widget.Button("delbasketbutton");
108
                            new YAHOO.widget.Button("ediorderbutton");
108
                        }
109
                        }
109
                        //]]>
110
                        //]]>
110
                    </script>
111
                    </script>
Lines 119-124 Link Here
119
                        <li><a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="closebutton">Close this basket</a></li>
120
                        <li><a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="closebutton">Close this basket</a></li>
120
                    [% END %]
121
                    [% END %]
121
                        <li><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="exportbutton">Export this basket as CSV</a></li>
122
                        <li><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="exportbutton">Export this basket as CSV</a></li>
123
                    [% IF ( ediaccount ) %]   
124
                        <li><a href="/cgi-bin/koha/acqui/edi_ean.pl?op=ediorder&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="ediorderbutton">EDIfact order</a></li>
125
                    [% END %]
122
                    </ul>
126
                    </ul>
123
127
124
                </div>
128
                </div>
Lines 144-150 Link Here
144
                [% END %]
148
                [% END %]
145
            [% END %]
149
            [% END %]
146
            [% END %]
150
            [% END %]
147
151
	[% IF ( edifile ) %]
152
	<div id="edifile" class="dialog alert">The EDIfact order was successfully transferred to the bookseller</div>
153
	[% END %]
148
    [% IF ( NO_BOOKSELLER ) %]
154
    [% IF ( NO_BOOKSELLER ) %]
149
    <h2>Vendor not found</h2>
155
    <h2>Vendor not found</h2>
150
    [% ELSE %]
156
    [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/edi_ean.tt (+40 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisitions &rsaquo; Basket ([% basketno %])</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
</head>
6
<body>
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'acquisitions-search.inc' %]
9
10
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; Basket ([% basketno %])</div>
11
12
<div id="doc3" class="yui-t2">
13
14
<div id="bd">
15
    <div id="yui-main">
16
    <div class="yui-b">
17
    
18
    <h2>Identify the branch submitting the EDI order</h2>
19
    <br />
20
    <p>
21
    	<form action="/cgi-bin/koha/acqui/basket.pl" method="get">
22
                    <p> Ordering branch: <select id="ean" name="ean">
23
                        [% FOREACH ean IN eans %]
24
                            <option value="[% ean.ean %]">[% ean.branchname %]</option>
25
                        [% END %]
26
                        </select>
27
                        <input type="hidden" id="basketno" value="[% basketno %]" name="basketno" />
28
                        <input type="hidden" value="ediorder" name="op" />
29
                        <input type="submit" value="Send EDI order" />
30
                    </p>
31
                </form>
32
    </p>
33
    
34
    </div>
35
</div>
36
<div class="yui-b">
37
[% INCLUDE 'acquisitions-menu.inc' %]
38
</div>
39
</div>
40
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+4 lines)
Lines 99-104 Link Here
99
	<dd>Printers (UNIX paths).</dd> -->
99
	<dd>Printers (UNIX paths).</dd> -->
100
	<dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></dt>
100
	<dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></dt>
101
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
101
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
102
	<dt><a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></dt>
103
	<dd>Manage vendor EDI accounts</dd>
104
	<dt><a href="/cgi-bin/koha/admin/edi_ean_accounts.pl">EDI EANs</a></dt>
105
	<dd>Manage Branch EDI EANs</dd>
102
</dl>
106
</dl>
103
</div>
107
</div>
104
108
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi-accounts.tt (+46 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration - EDI Accounts</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
</head>
6
<body>
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
9
10
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></div>
11
12
<div id="doc3" class="yui-t2">
13
    <div id="bd">
14
        <div id="yui-main">
15
            <div class="yui-b"
16
				<h1>Vendor EDI Accounts</h1>
17
				[% IF ( ediaccounts ) %]
18
                <div id="ediaccounts" class="rows">
19
                    [% IF ( opdelsubmit ) %]
20
                    <div class="dialog alert">The account was successfully deleted</div>
21
                    [% END %]
22
                    [% IF ( opaddsubmit ) %]
23
                    <div class="dialog alert">The account was successfully added</div>
24
                    [% END %]
25
                    [% IF ( opeditsubmit ) %]
26
                    <div class="dialog alert">The account was successfully updated</div>
27
                    [% END %]
28
                        <div><ul class="toolbar"><li><span class="yui-button yui-link-button"><span class="first-child"><a href="/cgi-bin/koha/admin/edi-edit.pl?op=add">Add a new account</a></span></span></li></ul></div>
29
                        <table border="0" width="100%" cellpadding="3" cellspacing="0">
30
                        <th><strong>ID</strong></th><th><strong>Vendor</strong></th><th><strong>Description</strong></th><th><strong>Last activity</strong></th><th><strong>Actions</strong></th></tr>
31
                        [% FOREACH account IN ediaccounts %]
32
                            <tr><td>[% account.id %]</td><td><a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=[% account.providerid %]">[% account.vendor %]</a></td><td>[% account.description %]</td><td>[% account.last_activity %]</td><td align="center"><a href="/cgi-bin/koha/admin/edi-edit.pl?op=edit&id=[% account.id %]&providerid=[% account.providerid %]">Edit</a> | <a href="/cgi-bin/koha/admin/edi-edit.pl?op=del&id=[% account.id %]">Delete</a></td></tr>
33
                        [% END %]
34
                        </table>
35
                </div>
36
                [% ELSE %]
37
                <p>You currently do not have any Vendor EDI Accounts. To add a new account <a href="/cgi-bin/koha/admin/edi-edit.pl?op=add">click here</a>.</p>
38
                [% END %]
39
            </div>
40
        </div>
41
        <div class="yui-b">
42
            [% INCLUDE 'admin-menu.inc' %]
43
        </div>
44
    </div>
45
</div>
46
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi-edit.tt (+102 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration - EDI Accounts</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" language="javascript">
5
$(document).ready(function() {
6
	$('#failcheck').hide();
7
});
8
function check_form_edi()
9
{
10
	if ($('#provider').val()!="" && $('#description').val()!="" && $('#host').val()!="")
11
	{
12
		$('#edi_form').submit();
13
	}
14
	else
15
	{
16
		$('#failcheck').show('fast');
17
	}
18
    
19
}
20
function deleteInstance()
21
{
22
    window.location="/cgi-bin/koha/members/houseboundinstances.pl?op=delsubmit&borrowernumber=[% borrowernumber %]&instanceid=[% delinstanceid %]&hbnumber=[% hbnumber %]";
23
}
24
function cancelInstance()
25
{
26
    window.location="/cgi-bin/koha/members/housebound.pl?borrowernumber=[% borrowernumber %]";
27
}
28
</script>
29
[% INCLUDE 'calendar.inc' %]
30
</head>
31
<body>
32
[% INCLUDE 'header.inc' %]
33
[% INCLUDE 'cat-search.inc' %]
34
35
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></div>
36
<div id="doc3" class="yui-t2">
37
    <div id="bd">
38
        <div id="yui-main">
39
            <div class="yui-b">
40
            	<h1>Vendor EDI Accounts</h1>
41
            	<div id="failcheck" class="dialog alert">You must complete all required fields</div>
42
                <form name="form" id="edi_form" method="post" action="/cgi-bin/koha/admin/edi-accounts.pl">
43
                    <input type="hidden" name="op" value="[% opeditsubmit %][% opaddsubmit %][% opdelsubmit %]" />
44
                    
45
                    <input type="hidden" name="editid" value="[% editid %]" />
46
                [% IF ( opdel ) %]
47
                    <p>Are you sure you want to delete this account?</p>
48
					<p><a href="/cgi-bin/koha/admin/edi-accounts.pl?id=[% id %]&op=delsubmit">YES</a> | <a href="/cgi-bin/koha/admin/edi-accounts.pl">NO</a></p>
49
                [% ELSE %]
50
                <fieldset class="rows" id="edi_details">
51
                    <legend>EDI Account details</legend>
52
                    <ol>
53
                        <li>
54
                            <label for="provider" class="required">Vendor:*</label>
55
                            <select id="provider" name="provider">
56
                                <option value="">Select a vendor</option>
57
                                [% FOREACH vendor IN vendorlist %]
58
                                    <option value="[% vendor.id %]" [% vendor.selected %]>[% vendor.name %]</option>
59
                                [% END %]
60
                            </select>
61
                        </li>
62
                        <li>
63
                            <label for="description" class="required">Description:* </label>
64
                            <input type="text" id="description" name="description" size="40" value="[% description %]" />
65
                        </li>
66
                        <li>
67
                            <label for="host" class="required">Server hostname:*</label>
68
                            <input type="text" id="host" name="host" size="40" value="[% host %]" />
69
                        </li>
70
                        <li>
71
                            <label for="user">Server username:</label>
72
                            <input type="text" id="user" name="user" size="40" value="[% user %]" />
73
                        </li>
74
                        <li>
75
                            <label for="pass">Server password:</label>
76
                            <input type="text" id="pass" name="pass" size="40" value="[% pass %]" />
77
                        </li>
78
                        <li>
79
                            <label for="in_dir">Server remote directory:</label>
80
                            <input type="text" id="in_dir" name="in_dir" size="40" value="[% in_dir %]" />
81
                        </li>
82
                        <li>
83
                            <label for="san">Vendor SAN/EAN:</label>
84
                            <input type="text" id="san" name="san" size="40" value="[% san %]" />
85
                        </li>
86
                    </ol>
87
                </fieldset>
88
                <fieldset class="action">
89
                    <input type="submit" value="Save" onclick="check_form_edi(); return false; " name="save">
90
                    <a class="cancel" href="/cgi-bin/koha/admin/edi-accounts.pl">Cancel</a>
91
                </fieldset>
92
                [% END %]
93
                </form>
94
95
            </div>
96
        </div>
97
        <div class="yui-b">
98
            [% INCLUDE 'admin-menu.inc' %]
99
        </div>
100
    </div>
101
</div>
102
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_ean_accounts.tt (+46 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration - EDI EANs</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
</head>
6
<body>
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
9
10
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/edi_ean_accounts.pl">EDI EANs</a></div>
11
12
<div id="doc3" class="yui-t2">
13
    <div id="bd">
14
        <div id="yui-main">
15
            <div class="yui-b"
16
				<h3>Branch EDI EANs</h3>
17
				[% IF ( eans ) %]
18
                <div id="eans" class="rows">
19
                    [% IF ( opdelsubmit ) %]
20
                    <div class="dialog alert">The EAN was successfully deleted</div>
21
                    [% END %]
22
                    [% IF ( opaddsubmit ) %]
23
                    <div class="dialog alert">The EAN was successfully added</div>
24
                    [% END %]
25
                    [% IF ( opeditsubmit ) %]
26
                    <div class="dialog alert">The EAN was successfully updated</div>
27
                    [% END %]
28
                        <div><ul class="toolbar"><li><span class="yui-button yui-link-button"><span class="first-child"><a href="/cgi-bin/koha/admin/edi_ean_edit.pl?op=add">Add a new EAN</a></span></span></li></ul></div>
29
                        <table border="0" width="100%" cellpadding="3" cellspacing="0">
30
                        <th><strong>Branch</strong></th><th><strong>EAN</strong></th><th><strong>Actions</strong></th></tr>
31
                        [% FOREACH ean IN eans %]
32
                            <tr><td>[% ean.branchname %]</td><td>[% ean.ean %]</td><td align="center"><a href="/cgi-bin/koha/admin/edi_ean_edit.pl?op=edit&branchcode=[% ean.branchcode %]&ean=[% ean.ean %]">Edit</a> | <a href="/cgi-bin/koha/admin/edi_ean_edit.pl?op=del&branchcode=[% ean.branchcode %]&ean=[% ean.ean %]">Delete</a></td></tr>
33
                        [% END %]
34
                        </table>
35
                </div>
36
                [% ELSE %]
37
                <p>You currently do not have any EANs. To add a new EAN <a href="/cgi-bin/koha/admin/edi_ean_edit.pl?op=add">click here</a>.</p>
38
                [% END %]
39
            </div>
40
        </div>
41
        <div class="yui-b">
42
            [% INCLUDE 'admin-menu.inc' %]
43
        </div>
44
    </div>
45
</div>
46
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/edi_ean_edit.tt (+74 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration - EDI EANs</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" language="javascript">
5
$(document).ready(function() {
6
	$('#failcheck').hide();
7
});
8
function check_form_ean()
9
{
10
	if ($('#branchcode').val()!="" && $('#ean').val()!="")
11
	{
12
		$('#ean_form').submit();
13
	}
14
	else
15
	{
16
		$('#failcheck').show('fast');
17
	}
18
    
19
}
20
</script>
21
</head>
22
<body>
23
[% INCLUDE 'header.inc' %]
24
[% INCLUDE 'cat-search.inc' %]
25
26
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; <a href="/cgi-bin/koha/admin/edi_ean_accounts.pl">EDI EANs</a></div>
27
<div id="doc3" class="yui-t2">
28
    <div id="bd">
29
        <div id="yui-main">
30
            <div class="yui-b">
31
            	<h1>Branch EDI EANs</h1>
32
            	<div id="failcheck" class="dialog alert">You must complete all required fields</div>
33
                <form name="form" id="ean_form" method="post" action="/cgi-bin/koha/admin/edi_ean_accounts.pl">
34
                    <input type="hidden" name="op" value="[% opeditsubmit %][% opaddsubmit %][% opdelsubmit %]" />
35
                    
36
                [% IF ( opdel ) %]
37
                    <p>Are you sure you want to delete this account?</p>
38
					<p><a href="/cgi-bin/koha/admin/edi_ean_accounts.pl?branchcode=[% branchcode %]&ean=[% ean %]&op=delsubmit">YES</a> | <a href="/cgi-bin/koha/admin/edi_ean_accounts.pl">NO</a></p>
39
                [% ELSE %]
40
                <fieldset class="rows" id="ean_details">
41
                    <legend>EAN details</legend>
42
                    <ol>
43
                        <li>
44
                            <label for="branchcode" class="required">Branch:*</label>
45
                            <select id="branchcode" name="branchcode">
46
                                <option value="">Select a branch</option>
47
                                [% FOREACH branch IN branchlist %]
48
                                    <option value="[% branch.branchcode %]" [% 'SELECTED' IF branch.branchcode==selectedbranch %]>[% branch.branchname %]</option>
49
                                [% END %]
50
                            </select>
51
                        </li>
52
                        <li>
53
                            <label for="ean" class="required">EAN:* </label>
54
                            <input type="text" id="ean" name="ean" size="40" value="[% ean %]" />
55
                        </li>
56
                        <input type="hidden" name="oldbranchcode" value="[% branchcode %]" />
57
                        <input type="hidden" name="oldean" value="[% ean %]" />
58
                    </ol>
59
                </fieldset>
60
                <fieldset class="action">
61
                    <input type="submit" value="Save" onclick="check_form_ean(); return false; " name="save">
62
                    <a class="cancel" href="/cgi-bin/koha/admin/edi_ean_accounts.pl">Cancel</a>
63
                </fieldset>
64
                [% END %]
65
                </form>
66
67
            </div>
68
        </div>
69
        <div class="yui-b">
70
            [% INCLUDE 'admin-menu.inc' %]
71
        </div>
72
    </div>
73
</div>
74
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/edi.tt (+54 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; EDIfact messages</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" language="javascript">
5
function check_sent(status,key,basketno,providerid)
6
{
7
	if (status == 'Failed' && basketno !=0)
8
	{
9
		document.write(' - (<a href="/cgi-bin/koha/acqui/basket.pl?op=edisend&basketno='+basketno+'&booksellerid='+providerid+'">Re-send</a>)');
10
	}
11
}
12
</script>
13
</head>
14
<body>
15
[% INCLUDE 'header.inc' %]
16
[% INCLUDE 'cat-search.inc' %]
17
18
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; EDIfact messages</div>
19
20
<div id="doc3" class="yui-t2">
21
    <div id="bd">
22
        <div id="yui-main">
23
            <div class="yui-b"
24
				<h1>EDIfact messages</h1>
25
				[% IF ( messagelist ) %]
26
                <div id="messagelist" class="rows">
27
                    [% IF ( opdelsubmit ) %]
28
                    <div class="dialog alert">The account was successfully deleted</div>
29
                    [% END %]
30
                    [% IF ( opaddsubmit ) %]
31
                    <div class="dialog alert">The account was successfully added</div>
32
                    [% END %]
33
                    [% IF ( opeditsubmit ) %]
34
                    <div class="dialog alert">The account was successfully updated</div>
35
                    [% END %]
36
                        <table border="0" width="100%" cellpadding="3" cellspacing="0">
37
                        <th><strong>Date</strong></th><th><strong>Message type</strong></th><th><strong>Provider</strong></th><th><strong>Status</strong></th><th>Basket</th>
38
                        [% FOREACH message IN messagelist %]
39
                        	<tr><td>[% message.date_sent %]</td><td>[% message.message_type %]</td><td><a href="/cgi-bin/koha/acqui/supplier.pl?supplierid=[% message.providerid %]">[% message.providername %]</a></td><td>[% message.status %]<script type="text/javascript" language="javascript">check_sent('[% message.status %]',[% message.key %],[% message.basketno %],[% message.providerid %]);</script></td><td>[% IF ( message.basketno ) %]<a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% message.basketno %]">View basket</a>[% END %]</td></tr>
40
                        [% END %]
41
                        </table>
42
                </div>
43
44
                [% ELSE %]
45
                <p>There are currently no EDIfact messages to display.</p>
46
                [% END %]
47
            </div>
48
        </div>
49
        <div class="yui-b">
50
            [% INCLUDE 'tools-menu.inc' %]
51
        </div>
52
    </div>
53
</div>
54
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (+4 lines)
Lines 87-92 Link Here
87
    <dd>Schedule tasks to run</dd>
87
    <dd>Schedule tasks to run</dd>
88
    [% END %]
88
    [% END %]
89
	
89
	
90
    [% IF ( CAN_user_tools_edi_manage ) %]
91
    <dt><a href="/cgi-bin/koha/tools/edi.pl">EDIfact messages</a></dt>
92
    <dd>Manage EDIfact transmissions</dd>
93
    [% END %]
90
94
91
</dl>
95
</dl>
92
</div>
96
</div>
(-)a/misc/cronjobs/clean_edifiles.pl (+41 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
my $edidir = "$ENV{'PERL5LIB'}/misc/edi_files";
24
opendir( my $dh, $edidir );
25
my @files = readdir($dh);
26
close $dh;
27
28
foreach my $file (@files) {
29
    my $now  = time;
30
    my @stat = stat("$edidir/$file");
31
    if (
32
        $stat[9] < ( $now - 2592000 )
33
        && (   ( index lc($file), '.ceq' ) > -1
34
            || ( index lc($file), '.cep' ) > -1 )
35
      )
36
    {
37
        print "Deleting file $edidir/$file...";
38
        unlink("$edidir/$file");
39
        print "Done.\n";
40
    }
41
}
(-)a/misc/cronjobs/edi_quote_cron.pl (+13 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use warnings;
4
use strict;
5
6
use Data::Dumper;
7
8
use Rebus::EDI;
9
10
my $edi = Rebus::EDI->new();
11
12
my $result = $edi->retrieve_quotes;
13
(-)a/misc/cronjobs/rotate_edi_logs.pl (+22 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
6
my $edidir = "$ENV{'PERL5LIB'}/misc/edi_files/";    # koha
7
8
#my $edidir="/tmp/";								# evergreen
9
10
my @logfiles = ( '$edidir/edi_ftp.log', '$edidir/edi_quote_error.log' );
11
my $rotate_size = 10485760;                         # 10MB
12
13
my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
14
my $currdate = sprintf "%4d%02d%02d", $year + 1900, $mon + 1, $mday;
15
16
foreach my $file (@logfiles) {
17
    my $current_size = -s $file;
18
    print "$current_size\n";
19
    if ( $current_size > $rotate_size ) {
20
        rename( $file, $file . "." . $currdate );
21
    }
22
}
(-)a/misc/edi_files/ptfs-europe-koha-community.CEQ (+1 lines)
Line 0 Link Here
1
UNA:+.? 'UNB+UNOC:2+5011234567890:14+5099876543210:31B+111205:1135+11775066594509++QUOTES'UNH+MG0011+QUOTES:D:96A:UN:EAN008'BGM+31C::28+MG0011+9'DTM+137:20111205:102'NAD+BY+5099876543210:31B'NAD+SU+5011234567890:14'LIN+1++9781844676828:EN'IMD+L+010+:::Baudrillard'IMD+L+011+:::Jean'IMD+L+050+:::America'IMD+L+109+:::Verso Books'IMD+L+120+:::Verso Books'IMD+L+170+:::2010'IMD+L+220+:::PBK'IMD+L+230+:::123.456 BAU'QTY+1:2'GIR+001+BRANCH1:LLO+FUND1:LFN+BKREF:LST+REFERENCE:LSQ'GIR+002+BRANCH2:LLO+FUND1:LFN+BK1WK:LST+STORE:LSQ'FTX+LNO++2:10B:28+Note 1'PRI+AAB:5.73'CUX+2:GBP:9'RFF+QLI:MG0011/001'LIN+2++9781846554070:EN'IMD+L+010+:::Murakami'IMD+L+011+:::Haruki'IMD+L+050+:::1Q84'IMD+L+109+:::Harvill Secker'IMD+L+120+:::Harvill Secker'IMD+L+170+:::2011'IMD+L+220+:::HBK'IMD+L+230+:::123.456 MUR'QTY+1:1'GIR+001+BRANCH2:LLO+FUND2:LFN+BK4WK:LST+SHELVES:LSQ'FTX+LNO++2:10B:28+Books 1 and 2'PRI+AAB:10.23'CUX+2:GBP:9'RFF+QLI:MG0011/002'UNS+S'CNT+2:1'UNT+39+MG0011'UNZ+1+11775066594509'
(-)a/tools/edi.pl (-1 / +50 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2011 Mark Gavillet & PTFS Europe Ltd
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use CGI;
23
use C4::Auth;
24
use C4::Output;
25
use C4::Edifact;
26
27
use vars qw($debug);
28
29
BEGIN {
30
    $debug = $ENV{DEBUG} || 0;
31
}
32
33
my $input = CGI->new();
34
35
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
36
    {
37
        template_name   => "tools/edi.tmpl",
38
        query           => $input,
39
        type            => "intranet",
40
        authnotrequired => 0,
41
        flagsrequired   => { borrowers => 1 },
42
        debug           => ($debug) ? 1 : 0,
43
    }
44
);
45
46
my $messagelist = C4::Edifact::GetEDIfactMessageList();
47
48
$template->param( messagelist => $messagelist );
49
50
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 7736