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

(-)a/C4/EDI.pm (+1095 lines)
Line 0 Link Here
1
package C4::EDI;
2
3
# Copyright 2011 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 Business::Edifact::Interchange;
26
use C4::Biblio;
27
use C4::Items;
28
use Business::ISBN;
29
use Carp;
30
use parent qw(Exporter);
31
32
our $VERSION = 3.09.00.53;
33
our @EXPORT  = qw(
34
  GetEDIAccounts
35
  GetEDIAccountDetails
36
  CreateEDIDetails
37
  UpdateEDIDetails
38
  LogEDIFactOrder
39
  LogEDIFactQuote
40
  DeleteEDIDetails
41
  GetVendorList
42
  GetEDIfactMessageList
43
  GetEDIFTPAccounts
44
  LogEDITransaction
45
  GetVendorSAN
46
  CreateEDIOrder
47
  SendEDIOrder
48
  SendQueuedEDIOrders
49
  ParseEDIQuote
50
  GetDiscountedPrice
51
  GetBudgetID
52
  CheckOrderItemExists
53
  GetBranchCode
54
  string35escape
55
  GetOrderItemInfo
56
  CheckVendorFTPAccountExists
57
);
58
59
=head1 NAME
60
61
C4::EDI - Perl Module containing functions for Vendor EDI accounts and EDIfact messages
62
63
=head1 VERSION
64
65
Version 0.01
66
67
=head1 SYNOPSIS
68
69
use C4::EDI;
70
71
=head1 DESCRIPTION
72
73
This module contains routines for adding, modifying and deleting EDI account details for vendors, interacting with vendor FTP sites to send/retrieve quote and order messages, formatting EDIfact orders, and parsing EDIfact quotes to baskets
74
75
=head2 GetVendorList
76
77
Returns a list of vendors from aqbooksellers to populate drop down select menu
78
79
=cut
80
81
sub GetVendorList {
82
    my $dbh = C4::Context->dbh;
83
    my $sth;
84
    $sth =
85
      $dbh->prepare("select id, name from aqbooksellers order by name asc");
86
    $sth->execute();
87
    my $vendorlist = $sth->fetchall_arrayref( {} );
88
    return $vendorlist;
89
}
90
91
=head2 CreateEDIDetails
92
93
Inserts a new EDI vendor FTP account
94
95
=cut
96
97
sub CreateEDIDetails {
98
    my ( $provider, $description, $host, $user, $pass, $in_dir, $san ) = @_;
99
    my $dbh = C4::Context->dbh;
100
    my $sth;
101
    if ($provider) {
102
        $sth = $dbh->prepare(
103
"insert into vendor_edi_accounts (description, host, username, password, provider, in_dir, san) values (?,?,?,?,?,?,?)"
104
        );
105
        $sth->execute( $description, $host, $user,
106
            $pass, $provider, $in_dir, $san );
107
    }
108
    return;
109
}
110
111
=head2 GetEDIAccounts
112
113
Returns all vendor FTP accounts
114
115
=cut
116
117
sub GetEDIAccounts {
118
    my $dbh = C4::Context->dbh;
119
    my $sth;
120
    $sth = $dbh->prepare(
121
"select vendor_edi_accounts.id, aqbooksellers.id as providerid, aqbooksellers.name as vendor, vendor_edi_accounts.description, vendor_edi_accounts.last_activity from vendor_edi_accounts inner join aqbooksellers on vendor_edi_accounts.provider = aqbooksellers.id order by aqbooksellers.name asc"
122
    );
123
    $sth->execute();
124
    my $ediaccounts = $sth->fetchall_arrayref( {} );
125
    return $ediaccounts;
126
}
127
128
=head2 DeleteEDIDetails
129
130
Remove a vendor's FTP account
131
132
=cut
133
134
sub DeleteEDIDetails {
135
    my ($id) = @_;
136
    my $dbh = C4::Context->dbh;
137
    my $sth;
138
    if ($id) {
139
        $sth = $dbh->prepare("delete from vendor_edi_accounts where id=?");
140
        $sth->execute($id);
141
    }
142
    return;
143
}
144
145
=head2 UpdateEDIDetails
146
147
Update a vendor's FTP account
148
149
=cut
150
151
sub UpdateEDIDetails {
152
    my ( $editid, $description, $host, $user, $pass, $provider, $in_dir, $san )
153
      = @_;
154
    my $dbh = C4::Context->dbh;
155
    if ($editid) {
156
        my $sth = $dbh->prepare(
157
"update vendor_edi_accounts set description=?, host=?, username=?, password=?, provider=?, in_dir=?, san=? where id=?"
158
        );
159
        $sth->execute( $description, $host, $user, $pass, $provider, $in_dir,
160
            $san, $editid );
161
    }
162
    return;
163
}
164
165
=head2 LogEDIFactOrder
166
167
Updates or inserts to the edifact_messages table when processing an order and assigns a status and basket number
168
169
=cut
170
171
sub LogEDIFactOrder {
172
    my ( $provider, $status, $basketno ) = @_;
173
    my $dbh = C4::Context->dbh;
174
    my $key;
175
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
176
    $year += 1900;
177
    $mon  += 1;
178
    my $date_sent = $year . '-' . $mon . "-$mday";
179
    my $sth       = $dbh->prepare(
180
"select edifact_messages.key from edifact_messages where basketno=? and provider=?"
181
    );
182
    $sth->execute( $basketno, $provider );
183
184
    #my $key=$sth->fetchrow_array();
185
    while ( my @row = $sth->fetchrow_array() ) {
186
        $key = $row[0];
187
    }
188
    if ($key) {
189
        $sth = $dbh->prepare(
190
"update edifact_messages set date_sent=?, status=? where edifact_messages.key=?"
191
        );
192
        $sth->execute( $date_sent, $status, $key );
193
    }
194
    else {
195
        $sth = $dbh->prepare(
196
"insert into edifact_messages (message_type,date_sent,provider,status,basketno) values (?,?,?,?,?)"
197
        );
198
        $sth->execute( 'ORDER', $date_sent, $provider, $status, $basketno );
199
    }
200
    return;
201
}
202
203
=head2 LogEDIFactOrder
204
205
Updates or inserts to the edifact_messages table when processing a quote and assigns a status and basket number
206
207
=cut
208
209
sub LogEDIFactQuote {
210
    my ( $provider, $status, $basketno, $key ) = @_;
211
    my $dbh = C4::Context->dbh;
212
    my $sth;
213
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
214
    $year = 1900 + $year;
215
    $mon  = 1 + $mon;
216
    my $date_sent = $year . "-" . $mon . "-$mday";
217
    if ( $key != 0 ) {
218
        $sth = $dbh->prepare(
219
"update edifact_messages set date_sent=?, status=?, basketno=? where edifact_messages.key=?"
220
        );
221
        $sth->execute( $date_sent, $status, $basketno, $key );
222
    }
223
    else {
224
        $sth = $dbh->prepare(
225
"insert into edifact_messages (message_type,date_sent,provider,status,basketno) values (?,?,?,?,?)"
226
        );
227
        $sth->execute( 'QUOTE', $date_sent, $provider, $status, $basketno );
228
        $key =
229
          $dbh->last_insert_id( undef, undef, qw(edifact_messages key), undef );
230
    }
231
    return $key;
232
}
233
234
=head2 GetEDIAccountDetails
235
236
Returns FTP account details for a given vendor
237
238
=cut
239
240
sub GetEDIAccountDetails {
241
    my ($id) = @_;
242
    my $dbh = C4::Context->dbh;
243
    my $sth;
244
    if ($id) {
245
        $sth = $dbh->prepare("select * from vendor_edi_accounts where id=?");
246
        $sth->execute($id);
247
        my $edi_details = $sth->fetchrow_hashref;
248
        return $edi_details;
249
    }
250
    return;
251
}
252
253
=head2 GetEDIfactMessageList
254
255
Returns a list of edifact_messages that have been processed, including the type (quote/order) and status
256
257
=cut
258
259
sub GetEDIfactMessageList {
260
    my $dbh = C4::Context->dbh;
261
    my $sth;
262
    $sth = $dbh->prepare(
263
"select edifact_messages.key, edifact_messages.message_type, DATE_FORMAT(edifact_messages.date_sent,'%d/%m/%Y') as date_sent, aqbooksellers.id as providerid, aqbooksellers.name as providername, edifact_messages.status, edifact_messages.basketno from edifact_messages inner join aqbooksellers on edifact_messages.provider = aqbooksellers.id order by edifact_messages.date_sent desc, edifact_messages.key desc"
264
    );
265
    $sth->execute();
266
    my $messagelist = $sth->fetchall_arrayref( {} );
267
    return $messagelist;
268
}
269
270
=head2 GetEDIFTPAccounts
271
272
Returns all vendor FTP accounts. Used when retrieving quotes messages overnight
273
274
=cut
275
276
sub GetEDIFTPAccounts {
277
    my $dbh = C4::Context->dbh;
278
    my $sth;
279
    $sth = $dbh->prepare(
280
"select id, host, username, password, provider, in_dir from vendor_edi_accounts order by id asc"
281
    );
282
    $sth->execute();
283
    my $ftpaccounts = $sth->fetchall_arrayref( {} );
284
    return $ftpaccounts;
285
}
286
287
=head2 LogEDITransaction
288
289
Updates the timestamp for a given vendor FTP account whenever there is activity
290
291
=cut
292
293
sub LogEDITransaction {
294
    my $id = shift;
295
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
296
    $year = 1900 + $year;
297
    $mon  = 1 + $mon;
298
    my $datestamp = $year . "/" . $mon . "/$mday";
299
    my $dbh       = C4::Context->dbh;
300
    my $sth;
301
    $sth = $dbh->prepare(
302
        "update vendor_edi_accounts set last_activity=? where id=?");
303
    $sth->execute( $datestamp, $id );
304
    return;
305
}
306
307
=head2 GetVendorSAN
308
309
Returns the stored SAN number for a given vendor
310
311
=cut
312
313
sub GetVendorSAN {
314
    my $booksellerid = shift;
315
    my $dbh          = C4::Context->dbh;
316
    my $san;
317
    my $sth =
318
      $dbh->prepare("select san from vendor_edi_accounts where provider=?");
319
    $sth->execute($booksellerid);
320
    while ( my @result = $sth->fetchrow_array() ) {
321
        $san = $result[0];
322
    }
323
    return $san;
324
}
325
326
=head2 CreateEDIOrder
327
328
Formats an EDIfact order message from a given basket and stores as a file on the server
329
330
=cut
331
332
sub CreateEDIOrder {
333
    my ( $basketno, $booksellerid ) = @_;
334
    my @datetime     = localtime(time);
335
    my $longyear     = $datetime[5] + 1900;
336
    my $shortyear    = sprintf '%02d', $datetime[5] - 100;
337
    my $date         = sprintf '%02d%02d', $datetime[4] + 1, $datetime[3];
338
    my $hourmin      = sprintf '%02d%02d', $datetime[2], $datetime[1];
339
    my $year         = $datetime[5] - 100;
340
    my $month        = sprintf '%02d', $datetime[4] + 1;
341
    my $linecount    = 0;
342
    my $filename     = "ediorder_$basketno.CEP";
343
    my $exchange     = int( rand(99999999999999) );
344
    my $ref          = int( rand(99999999999999) );
345
    my $san          = GetVendorSAN($booksellerid);
346
    my $message_type = GetMessageType($basketno);
347
    my $output_file  = C4::Context->config('intranetdir');
348
    $output_file .= "/misc/edi_files/$filename";
349
350
    open my $fh, '>', $output_file
351
      or croak "Unable to create $output_file : $!";
352
353
    print $fh "UNA:+.? '";    # print opening header
354
    print $fh "UNB+UNOC:2+"
355
      . C4::Context->preference("EDIfactEAN")
356
      . ":14+$san:31B+$shortyear$date:$hourmin+"
357
      . $exchange
358
      . "++ORDERS+++EANCOM'"
359
      ;    # print identifying EANs/SANs, date/time, exchange reference number
360
    print $fh "UNH+" . $ref
361
      . "+ORDERS:D:96A:UN:EAN008'";    # print message reference number
362
363
    if ( $message_type eq 'QUOTE' ) {
364
        print $fh "BGM+22V+"
365
          . $basketno
366
          . "+9'";    # print order number and quote confirmation ref
367
    }
368
    else {
369
        print $fh "BGM+220+" . $basketno . "+9'";    # print order number
370
    }
371
    print $fh "DTM+137:$longyear$date:102'";         # print date of message
372
    print $fh "NAD+BY+"
373
      . C4::Context->preference("EDIfactEAN")
374
      . "::9'";                                      # print buyer EAN
375
    print $fh "NAD+SU+" . $san . "::31B'";           # print vendor SAN
376
    print $fh "NAD+SU+" . $booksellerid . "::92'";   # print internal ID
377
378
    # get items from basket
379
    my @results = GetOrders($basketno);
380
    foreach my $item (@results) {
381
        $linecount++;
382
        my $price;
383
        my $title     = string35escape( escape( $item->{title} ) );
384
        my $author    = string35escape( escape( $item->{author} ) );
385
        my $publisher = string35escape( escape( $item->{publishercode} ) );
386
        $price = sprintf "%.2f", $item->{listprice};
387
        my $isbn;
388
        if (   length( $item->{isbn} ) == 10
389
            || substr( $item->{isbn}, 0, 3 ) eq "978"
390
            || index( $item->{isbn}, "|" ) != -1 )
391
        {
392
            $isbn = cleanisbn( $item->{isbn} );
393
            $isbn = Business::ISBN->new($isbn);
394
            if ($isbn) {
395
                if ( $isbn->is_valid ) {
396
                    $isbn = ( $isbn->as_isbn13 )->isbn;
397
                }
398
                else {
399
                    $isbn = "0";
400
                }
401
            }
402
            else {
403
                $isbn = 0;
404
            }
405
        }
406
        else {
407
            $isbn = $item->{isbn};
408
        }
409
        my $copyrightdate = escape( $item->{publicationyear} );
410
        my $quantity      = escape( $item->{quantity} );
411
        my $ordernumber   = escape( $item->{ordernumber} );
412
        my $notes;
413
        if ( $item->{notes} ) {
414
            $notes = $item->{notes};
415
            $notes =~ s/[\r\n]+//g;
416
            $notes = string35escape( escape($notes) );
417
        }
418
419
        my ( $branchcode, $callnumber, $itype, $lsqccode, $fund ) =
420
          GetOrderItemInfo( $item->{'ordernumber'} );
421
        $callnumber = escape($callnumber);
422
423
        print $fh "LIN+$linecount++" . $isbn . ":EN'";    # line number, isbn
424
        print $fh "PIA+5+" . $isbn
425
          . ":IB'";                        # isbn as main product identification
426
        print $fh "IMD+L+050+:::$title'";  # title
427
        print $fh "IMD+L+009+:::$author'"; # full name of author
428
        print $fh "IMD+L+109+:::$publisher'";        # publisher
429
        print $fh "IMD+L+170+:::$copyrightdate'";    # date of publication
430
        print $fh "IMD+L+220+:::O'";    # binding (e.g. PB) (O if not specified)
431
        if ( $callnumber ne '' ) {
432
            print $fh "IMD+L+230+:::$callnumber'";    # shelfmark
433
        }
434
        print $fh "QTY+21:$quantity'";                # quantity
435
        if ( $message_type ne 'QUOTE' && $quantity > 1 ) {
436
            print $fh "GIR+001+$quantity:LQT+$branchcode:LLO+$fund:LFN+"
437
              ;                                       # branchcode, fund code
438
        }
439
        else {
440
            print $fh
441
              "GIR+001+$branchcode:LLO+$fund:LFN+";    # branchcode, fund code
442
        }
443
        if ( $callnumber ne '' ) {
444
            print $fh "$callnumber:LCL+";              # shelfmark
445
        }
446
        print $fh $itype . ":LST+$lsqccode:LSQ'";    # stock category, sequence
447
        if ($notes) {
448
            print $fh "FTX+LIN+++:::$notes'";
449
        }
450
        ###REQUEST ORDERS TO REVISIT
451
#if ($message_type ne 'QUOTE')
452
#{
453
#	print $fh "FTX+LIN++$linecount:10B:28'";													# freetext ** used for request orders to denote priority (to revisit)
454
#}
455
        print $fh "PRI+AAB:$price'";         # price per item
456
        print $fh "CUX+2:GBP:9'";            # currency (GBP)
457
        print $fh "RFF+LI:$ordernumber'";    # Local order number
458
        if ( $message_type eq 'QUOTE' ) {
459
            print $fh "RFF+QLI:"
460
              . $item->{booksellerinvoicenumber}
461
              . q{'};    # If QUOTE confirmation, include booksellerinvoicenumber
462
        }
463
    }
464
    print $fh "UNS+S'";              # print summary section header
465
    print $fh "CNT+2:$linecount'";   # print number of line items in the message
466
    my $segments = ( ( $linecount * 13 ) + 9 );
467
    print $fh "UNT+$segments+"
468
      . $ref . "'"
469
      ; # No. of segments in message (UNH+UNT elements included, UNA, UNB, UNZ excluded)
470
        # Message ref number
471
    print $fh "UNZ+1+" . $exchange . "'\n";    # Exchange ref number
472
473
    close $fh;
474
475
    LogEDIFactOrder( $booksellerid, 'Queued', $basketno );
476
477
    return $filename;
478
479
}
480
481
sub GetMessageType {
482
    my $basketno = shift;
483
    my $dbh      = C4::Context->dbh;
484
    my $sth;
485
    my $message_type;
486
    my @row;
487
    $sth = $dbh->prepare(
488
        "select message_type from edifact_messages where basketno=?");
489
    $sth->execute($basketno);
490
    while ( @row = $sth->fetchrow_array() ) {
491
        $message_type = $row[0];
492
    }
493
    return $message_type;
494
}
495
496
sub cleanisbn {
497
    my $isbn = shift;
498
    if ($isbn) {
499
        my $i = index( $isbn, '(' );
500
        if ( $i > 1 ) {
501
            $isbn = substr( $isbn, 0, ( $i - 1 ) );
502
        }
503
        if ( index( $isbn, "|" ) != -1 ) {
504
            my @isbns = split( /\|/, $isbn );
505
            $isbn = $isbns[0];
506
507
            #print "0: ".$isbns[0]."\n";
508
        }
509
        $isbn = escape($isbn);
510
        $isbn =~ s/^\s+//;
511
        $isbn =~ s/\s+$//;
512
        return $isbn;
513
    }
514
    return;
515
}
516
517
sub escape {
518
    my $string = shift;
519
    if ($string) {
520
        $string =~ s/\?/\?\?/g;
521
        $string =~ s/\'/\?\'/g;
522
        $string =~ s/\:/\?\:/g;
523
        $string =~ s/\+/\?\+/g;
524
        return $string;
525
    }
526
    return;
527
}
528
529
=head2 GetBranchCode
530
531
Return branchcode for an order when formatting an EDIfact order message
532
533
=cut
534
535
sub GetBranchCode {
536
    my $biblioitemnumber = shift;
537
    my $dbh              = C4::Context->dbh;
538
    my $sth;
539
    my $branchcode;
540
    my @row;
541
    $sth =
542
      $dbh->prepare("select homebranch from items where biblioitemnumber=?");
543
    $sth->execute($biblioitemnumber);
544
    while ( @row = $sth->fetchrow_array() ) {
545
        $branchcode = $row[0];
546
    }
547
    return $branchcode;
548
}
549
550
=head2 SendEDIOrder
551
552
Transfers an EDIfact order message to the relevant vendor's FTP site
553
554
=cut
555
556
sub SendEDIOrder {
557
    my ( $basketno, $booksellerid ) = @_;
558
    my $newerr;
559
    my $result;
560
561
    # check edi order file exists
562
    my $edi_files = C4::Context->config('intranetdir');
563
    $edi_files .= '/misc/edi_files/';
564
    if ( -e "${edi_files}ediorder_$basketno.CEP" ) {
565
        my $dbh = C4::Context->dbh;
566
        my $sth;
567
        $sth = $dbh->prepare(
568
"select id, host, username, password, provider, in_dir from vendor_edi_accounts where provider=?"
569
        );
570
        $sth->execute($booksellerid);
571
        my $ftpaccount = $sth->fetchrow_hashref;
572
573
        #check vendor edi account exists
574
        if ($ftpaccount) {
575
576
            # connect to ftp account
577
            my $ftp = Net::FTP->new( $ftpaccount->{host}, Timeout => 10 )
578
              or $newerr = 1;
579
            if ( !$newerr ) {
580
                $newerr = 0;
581
582
                # login
583
                $ftp->login( "$ftpaccount->{username}",
584
                    "$ftpaccount->{password}" )
585
                  or $newerr = 1;
586
                $ftp->quit if $newerr;
587
                if ( !$newerr ) {
588
589
                    # cd to directory
590
                    $ftp->cwd("$ftpaccount->{in_dir}") or $newerr = 1;
591
                    $ftp->quit if $newerr;
592
593
                    # put file
594
                    if ( !$newerr ) {
595
                        $newerr = 0;
596
                        $ftp->put("${edi_files}ediorder_$basketno.CEP")
597
                          or $newerr = 1;
598
                        $ftp->quit if $newerr;
599
                        if ( !$newerr ) {
600
                            $result =
601
"File: ediorder_$basketno.CEP transferred successfully";
602
                            $ftp->quit;
603
                            unlink "${edi_files}ediorder_$basketno.CEP";
604
                            LogEDITransaction( $ftpaccount->{id} );
605
                            LogEDIFactOrder( $booksellerid, 'Sent', $basketno );
606
                            return $result;
607
                        }
608
                        else {
609
                            $result =
610
"Could not transfer the file ${edi_files}ediorder_$basketno.CEP to $ftpaccount->{host}: $_";
611
                            FTPError($result);
612
                            LogEDIFactOrder( $booksellerid, 'Failed',
613
                                $basketno );
614
                            return $result;
615
                        }
616
                    }
617
                    else {
618
                        $result =
619
"Cannot get remote directory ($ftpaccount->{in_dir}) on $ftpaccount->{host}";
620
                        FTPError($result);
621
                        LogEDIFactOrder( $booksellerid, 'Failed', $basketno );
622
                        return $result;
623
                    }
624
                }
625
                else {
626
                    $result = "Cannot log in to $ftpaccount->{host}: $!";
627
                    FTPError($result);
628
                    LogEDIFactOrder( $booksellerid, 'Failed', $basketno );
629
                    return $result;
630
                }
631
            }
632
            else {
633
                $result =
634
                  "Cannot make an FTP connection to $ftpaccount->{host}: $!";
635
                FTPError($result);
636
                LogEDIFactOrder( $booksellerid, 'Failed', $basketno );
637
                return $result;
638
            }
639
        }
640
        else {
641
            $result =
642
"Vendor ID: $booksellerid does not have a current EDIfact FTP account";
643
            FTPError($result);
644
            LogEDIFactOrder( $booksellerid, 'Failed', $basketno );
645
            return $result;
646
        }
647
    }
648
    else {
649
        $result = "There is no EDIfact order for this basket";
650
        return $result;
651
    }
652
}
653
654
sub FTPError {
655
    my $error    = shift;
656
    my $log_file = C4::Context->config('intranetdir');
657
    $log_file .= '/misc/edi_files/edi_ftp_error.log';
658
    open my $log_fh, '>>', $log_file
659
      or croak "Could not open $log_file: $!";
660
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
661
    printf $log_fh "%4d-%02d-%02d %02d:%02d:%02d\n-----\n",
662
      $year + 1900, $mon + 1, $mday, $hour, $min, $sec;
663
    print $log_fh "$error\n\n";
664
    close $log_fh;
665
    return;
666
}
667
668
=head2 SendQueuedEDIOrders
669
670
Sends all EDIfact orders that are held in the Queued
671
672
=cut
673
674
sub SendQueuedEDIOrders {
675
    my $dbh = C4::Context->dbh;
676
    my @orders;
677
    my $sth = $dbh->prepare(
678
        q|select basketno, provider from edifact_messages where status='Queued'|
679
    );
680
    $sth->execute();
681
    while ( @orders = $sth->fetchrow_array() ) {
682
        SendEDIOrder( $orders[0], $orders[1] );
683
    }
684
    return;
685
}
686
687
=head2 ParseEDIQuote
688
689
Uses Business::Edifact::Interchange to parse a stored EDIfact quote message, creates basket, biblios, biblioitems, and items
690
691
=cut
692
693
sub ParseEDIQuote {
694
    my ( $filename, $booksellerid ) = @_;
695
    my $ordernumber;
696
    my $basketno;
697
    my $ParseEDIQuoteItem;
698
699
    #print "file: $filename\n";
700
    my $edi  = Business::Edifact::Interchange->new;
701
    my $path = C4::Context->config('intranetdir');
702
    $path .= '/misc/edi_files/';
703
    $edi->parse_file("$path$filename");
704
    my $messages = $edi->messages();
705
    my $msg_cnt  = @{$messages};
706
707
    #print "messages: $msg_cnt\n";
708
    #print "type: ".$messages->[0]->type()."\n";
709
    #print "date: ".$messages->[0]->date_of_message()."\n";
710
711
    # create default edifact_messages entry
712
    my $messagekey = LogEDIFactQuote( $booksellerid, 'Failed', 0, 0 );
713
714
    #create basket
715
    if ( $msg_cnt > 0 && $booksellerid ) {
716
        $basketno = NewBasket( $booksellerid, 0, $filename, '', '', '' );
717
    }
718
719
    $ParseEDIQuoteItem = sub {
720
        my ( $item, $gir, $bookseller_id ) = @_;
721
        my $relnos = $item->{related_numbers};
722
        my $author = $item->author_surname . ", " . $item->author_firstname;
723
724
        my $ecost =
725
          GetDiscountedPrice( $bookseller_id, $item->{price}->{price} );
726
727
        my $ftxlin;
728
        my $ftxlno;
729
        if ( $item->{free_text}->{qualifier} eq "LIN" ) {
730
            $ftxlin = $item->{free_text}->{text};
731
        }
732
        if ( $item->{free_text}->{qualifier} eq "LNO" ) {
733
            $ftxlno = $item->{free_text}->{text};
734
        }
735
736
        my ( $llo, $lfn, $lsq, $lst, $lfs, $lcl, $id );
737
        my $relcount = 0;
738
        foreach my $rel ( @{$relnos} ) {
739
            if ( $rel->{id} == ( $gir + 1 ) ) {
740
                if ( $item->{related_numbers}->[$relcount]->{LLO}->[0] ) {
741
                    $llo = $item->{related_numbers}->[$relcount]->{LLO}->[0];
742
                }
743
                if ( $item->{related_numbers}->[$relcount]->{LFN}->[0] ) {
744
                    $lfn = $item->{related_numbers}->[$relcount]->{LFN}->[0];
745
                }
746
                if ( $item->{related_numbers}->[$relcount]->{LSQ}->[0] ) {
747
                    $lsq = $item->{related_numbers}->[$relcount]->{LSQ}->[0];
748
                }
749
                if ( $item->{related_numbers}->[$relcount]->{LST}->[0] ) {
750
                    $lst = $item->{related_numbers}->[$relcount]->{LST}->[0];
751
                }
752
                if ( $item->{related_numbers}->[$relcount]->{LFS}->[0] ) {
753
                    $lfs = $item->{related_numbers}->[$relcount]->{LFS}->[0];
754
                }
755
                if ( $item->{related_numbers}->[$relcount]->{LCL}->[0] ) {
756
                    $lcl = $item->{related_numbers}->[$relcount]->{LCL}->[0];
757
                }
758
                if ( $item->{related_numbers}->[$relcount]->{id} ) {
759
                    $id = $item->{related_numbers}->[$relcount]->{id};
760
                }
761
            }
762
            $relcount++;
763
        }
764
765
        my $lclnote;
766
        if ( !$lst ) {
767
            $lst = uc( $item->item_format );
768
        }
769
        if ( !$lcl ) {
770
            $lcl = $item->shelfmark;
771
        }
772
        else {
773
            ( $lcl, $lclnote ) = DawsonsLCL($lcl);
774
        }
775
        if ($lfs) {
776
            $lcl .= " $lfs";
777
        }
778
779
        my $budget_id = GetBudgetID($lfn);
780
781
     #Uncomment section below to define a default budget_id if there is no match
782
     #if (!defined $budget_id)
783
     #{
784
     #	$budget_id=0;
785
     #}
786
787
        # create biblio record
788
        my $bib_record = TransformKohaToMarc(
789
            {
790
                'biblio.title'       => $item->title,
791
                'biblio.author'      => $author ? $author : q{},
792
                'biblio.seriestitle' => q{},
793
                'biblioitems.isbn'   => $item->{item_number}
794
                ? $item->{item_number}
795
                : q{},
796
                'biblioitems.publishercode' => $item->publisher
797
                ? $item->publisher
798
                : q{},
799
                'biblioitems.publicationyear' => $item->date_of_publication
800
                ? $item->date_of_publication
801
                : q{},
802
                'biblio.copyrightdate' => $item->date_of_publication
803
                ? $item->date_of_publication
804
                : q{},
805
                'biblioitems.itemtype'  => uc( $item->item_format ),
806
                'biblioitems.cn_source' => 'ddc',
807
                'items.cn_source'       => 'ddc',
808
                'items.notforloan'      => -1,
809
810
                #"items.ccode"				  => $lsq,
811
                'items.location'         => $lsq,
812
                'items.homebranch'       => $llo,
813
                'items.holdingbranch'    => $llo,
814
                'items.booksellerid'     => $bookseller_id,
815
                'items.price'            => $item->{price}->{price},
816
                'items.replacementprice' => $item->{price}->{price},
817
                'items.itemcallnumber'   => $lcl,
818
                'items.itype'            => $lst,
819
                'items.cn_sort'          => q{},
820
            }
821
        );
822
823
        #check if item already exists in catalogue
824
        my $biblionumber;
825
        my $bibitemnumber;
826
        ( $biblionumber, $bibitemnumber ) =
827
          CheckOrderItemExists( $item->{item_number} );
828
829
        if ( !defined $biblionumber ) {
830
831
            # create the record in catalogue, with framework ''
832
            ( $biblionumber, $bibitemnumber ) = AddBiblio( $bib_record, q{} );
833
        }
834
835
        my $ordernote;
836
        if ($lclnote) {
837
            $ordernote = $lclnote;
838
        }
839
        if ($ftxlno) {
840
            $ordernote = $ftxlno;
841
        }
842
        if ($ftxlin) {
843
            $ordernote = $ftxlin;
844
        }
845
846
        my %orderinfo = (
847
            basketno                => $basketno,
848
            ordernumber             => q{},
849
            subscription            => 'no',
850
            uncertainprice          => 0,
851
            biblionumber            => $biblionumber,
852
            title                   => $item->title,
853
            quantity                => 1,
854
            biblioitemnumber        => $bibitemnumber,
855
            rrp                     => $item->{price}->{price},
856
            ecost                   => $ecost,
857
            sort1                   => q{},
858
            sort2                   => q{},
859
            booksellerinvoicenumber => $item->{item_reference}[0][1],
860
            listprice               => $item->{price}->{price},
861
            branchcode              => $llo,
862
            budget_id               => $budget_id,
863
            notes                   => $ordernote,
864
        );
865
866
        my $orderinfo = \%orderinfo;
867
868
        my ( $retbasketno, $ordernumber ) = NewOrder($orderinfo);
869
870
        # now, add items if applicable
871
        if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
872
            my $itemnumber;
873
            ( $biblionumber, $bibitemnumber, $itemnumber ) =
874
              AddItemFromMarc( $bib_record, $biblionumber );
875
            NewOrderItem( $itemnumber, $ordernumber );
876
        }
877
    };
878
879
    for ( my $count = 0 ; $count < $msg_cnt ; $count++ ) {
880
        my $items   = $messages->[$count]->items();
881
        my $ref_num = $messages->[$count]->{ref_num};
882
883
        foreach my $item ( @{$items} ) {
884
            for ( my $i = 0 ; $i < $item->{quantity} ; $i++ ) {
885
                &$ParseEDIQuoteItem( $item, $i, $booksellerid, $basketno );
886
            }
887
        }
888
    }
889
890
    # update edifact_messages entry
891
    $messagekey =
892
      LogEDIFactQuote( $booksellerid, 'Received', $basketno, $messagekey );
893
    return 1;
894
895
}
896
897
=head2 GetDiscountedPrice
898
899
Returns the discounted price for an order based on the discount rate for a given vendor
900
901
=cut
902
903
sub GetDiscountedPrice {
904
    my ( $booksellerid, $price ) = @_;
905
    my $dbh = C4::Context->dbh;
906
    my $sth;
907
    my @discount;
908
    my $ecost;
909
    my $percentage;
910
    $sth = $dbh->prepare(q|select discount from aqbooksellers where id=?|);
911
    $sth->execute($booksellerid);
912
913
    while ( @discount = $sth->fetchrow_array() ) {
914
        $percentage = $discount[0];
915
    }
916
    $ecost = ( $price - ( ( $percentage * $price ) / 100 ) );
917
    return $ecost;
918
}
919
920
=head2 DawsonsLCL
921
922
Checks for a call number encased by asterisks. If found, returns call number as $lcl and string with
923
asterisks as $lclnote to go into FTX field enabling spine label creation by Dawsons bookseller
924
925
=cut
926
927
sub DawsonsLCL {
928
    my $lcl = shift;
929
    my $lclnote;
930
    my $f = index( $lcl, '*' );
931
    my $l = rindex( $lcl, '*' );
932
    if ( $f == 0 && $l == ( length($lcl) - 1 ) ) {
933
        $lclnote = $lcl;
934
        $lcl =~ s/\*//g;
935
    }
936
    return ( $lcl, $lclnote );
937
}
938
939
=head2 GetBudgetID
940
941
Returns the budget_id for a given budget_code
942
943
=cut
944
945
sub GetBudgetID {
946
    my $fundcode = shift;
947
    my $dbh      = C4::Context->dbh;
948
    my $sth;
949
    my @funds;
950
    my $ecost;
951
    my $budget_id;
952
    $sth = $dbh->prepare("select budget_id from aqbudgets where budget_code=?");
953
    $sth->execute($fundcode);
954
955
    while ( @funds = $sth->fetchrow_array() ) {
956
        $budget_id = $funds[0];
957
    }
958
    return $budget_id;
959
}
960
961
=head2 CheckOrderItemExists
962
963
Checks to see if a biblio record already exists in the catalogue when parsing a quotes message
964
Converts 10-13 digit ISBNs and vice-versa if an initial match is not found
965
966
=cut
967
968
sub CheckOrderItemExists {
969
    my $isbn = shift;
970
    my $dbh  = C4::Context->dbh;
971
    my $sth;
972
    my @matches;
973
    my $biblionumber;
974
    my $bibitemnumber;
975
    $sth = $dbh->prepare(
976
        "select biblionumber, biblioitemnumber from biblioitems where isbn=?");
977
    $sth->execute($isbn);
978
979
    while ( @matches = $sth->fetchrow_array() ) {
980
        $biblionumber  = $matches[0];
981
        $bibitemnumber = $matches[1];
982
    }
983
    if ($biblionumber) {
984
        return $biblionumber, $bibitemnumber;
985
    }
986
    else {
987
        $isbn = cleanisbn($isbn);
988
        if ( length($isbn) == 10 ) {
989
            $isbn = Business::ISBN->new($isbn);
990
            if ($isbn) {
991
                if ( $isbn->is_valid ) {
992
                    $isbn = ( $isbn->as_isbn13 )->isbn;
993
                    $sth->execute($isbn);
994
                    while ( @matches = $sth->fetchrow_array() ) {
995
                        $biblionumber  = $matches[0];
996
                        $bibitemnumber = $matches[1];
997
                    }
998
                }
999
            }
1000
        }
1001
        elsif ( length($isbn) == 13 ) {
1002
            $isbn = Business::ISBN->new($isbn);
1003
            if ($isbn) {
1004
                if ( $isbn->is_valid ) {
1005
                    $isbn = ( $isbn->as_isbn10 )->isbn;
1006
                    $sth->execute($isbn);
1007
                    while ( @matches = $sth->fetchrow_array() ) {
1008
                        $biblionumber  = $matches[0];
1009
                        $bibitemnumber = $matches[1];
1010
                    }
1011
                }
1012
            }
1013
        }
1014
        return $biblionumber, $bibitemnumber;
1015
    }
1016
}
1017
1018
sub string35escape {
1019
    my $string = shift;
1020
    my $colon_string;
1021
    my @sections;
1022
    if ( length($string) > 35 ) {
1023
        my ( $chunk, $stringlength ) = ( 35, length($string) );
1024
        for ( my $counter = 0 ; $counter < $stringlength ; $counter += $chunk )
1025
        {
1026
            push @sections, substr( $string, $counter, $chunk );
1027
        }
1028
        foreach my $section (@sections) {
1029
            $colon_string .= $section . ":";
1030
        }
1031
        chop $colon_string;
1032
    }
1033
    else {
1034
        $colon_string = $string;
1035
    }
1036
    return $colon_string;
1037
}
1038
1039
sub GetOrderItemInfo {
1040
    my $ordernumber = shift;
1041
    my $dbh         = C4::Context->dbh;
1042
    my $sth;
1043
    my @rows;
1044
    my $homebranch;
1045
    my $callnumber;
1046
    my $itype;
1047
    my $ccode;
1048
    my $fund;
1049
    $sth = $dbh->prepare(
1050
q|select items.homebranch, items.itemcallnumber, items.itype, items.location from items
1051
 inner join aqorders_items on aqorders_items.itemnumber=items.itemnumber
1052
 where aqorders_items.ordernumber=?|
1053
    );
1054
    $sth->execute($ordernumber);
1055
1056
    while ( @rows = $sth->fetchrow_array() ) {
1057
        $homebranch = $rows[0];
1058
        $callnumber = $rows[1];
1059
        $itype      = $rows[2];
1060
        $ccode      = $rows[3];
1061
    }
1062
    $sth = $dbh->prepare(
1063
        q|select aqbudgets.budget_code from aqbudgets inner join aqorders on
1064
 aqorders.budget_id=aqbudgets.budget_id where aqorders.ordernumber=?|
1065
    );
1066
    $sth->execute($ordernumber);
1067
    while ( @rows = $sth->fetchrow_array() ) {
1068
        $fund = $rows[0];
1069
    }
1070
    return $homebranch, $callnumber, $itype, $ccode, $fund;
1071
}
1072
1073
sub CheckVendorFTPAccountExists {
1074
    my $booksellerid = shift;
1075
    my $dbh          = C4::Context->dbh;
1076
    my $sth          = $dbh->prepare(
1077
        q|select count(id) from vendor_edi_accounts where provider=?|);
1078
    $sth->execute($booksellerid);
1079
    while ( my @rows = $sth->fetchrow_array() ) {
1080
        if ( $rows[0] > 0 ) {
1081
            return 1;
1082
        }
1083
    }
1084
    return;
1085
}
1086
1087
1;
1088
1089
__END__
1090
1091
=head1 AUTHOR
1092
1093
Mark Gavillet
1094
1095
=cut
(-)a/acqui/basket.pl (+12 lines)
Lines 28-33 use C4::Output; Link Here
28
use CGI;
28
use CGI;
29
use C4::Acquisition;
29
use C4::Acquisition;
30
use C4::Budgets;
30
use C4::Budgets;
31
use C4::EDI;
31
use C4::Bookseller qw( GetBookSellerFromId);
32
use C4::Bookseller qw( GetBookSellerFromId);
32
use C4::Debug;
33
use C4::Debug;
33
use C4::Biblio;
34
use C4::Biblio;
Lines 86-91 my $basket = GetBasket($basketno); Link Here
86
# if no booksellerid in parameter, get it from basket
87
# if no booksellerid in parameter, get it from basket
87
# warn "=>".$basket->{booksellerid};
88
# warn "=>".$basket->{booksellerid};
88
$booksellerid = $basket->{booksellerid} unless $booksellerid;
89
$booksellerid = $basket->{booksellerid} unless $booksellerid;
90
my $ediaccount = CheckVendorFTPAccountExists($booksellerid);
91
$template->param(ediaccount=>$ediaccount);
89
my ($bookseller) = GetBookSellerFromId($booksellerid);
92
my ($bookseller) = GetBookSellerFromId($booksellerid);
90
my $op = $query->param('op');
93
my $op = $query->param('op');
91
if (!defined $op) {
94
if (!defined $op) {
Lines 95-100 if (!defined $op) { Link Here
95
my $confirm_pref= C4::Context->preference("BasketConfirmations") || '1';
98
my $confirm_pref= C4::Context->preference("BasketConfirmations") || '1';
96
$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
99
$template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
97
100
101
if ( $op eq 'ediorder') {
102
	my $edifile=CreateEDIOrder($basketno,$booksellerid);
103
	$template->param(edifile => $edifile);
104
}
105
if ( $op eq 'edisend') {
106
	my $edisend=SendEDIOrder($basketno,$booksellerid);
107
	$template->param(edisend => $edisend);
108
}
109
98
if ( $op eq 'delete_confirm' ) {
110
if ( $op eq 'delete_confirm' ) {
99
    my $basketno = $query->param('basketno');
111
    my $basketno = $query->param('basketno');
100
    DelBasket($basketno);
112
    DelBasket($basketno);
(-)a/admin/edi-accounts.pl (+71 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011,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::EDI;
26
27
my $input = CGI->new();
28
29
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
    {
31
        template_name   => "admin/edi-accounts.tmpl",
32
        query           => $input,
33
        type            => "intranet",
34
        authnotrequired => 0,
35
        flagsrequired   => { borrowers => 1 },
36
    }
37
);
38
39
my $op = $input->param('op');
40
$template->param( op => $op );
41
42
if ( $op eq "delsubmit" ) {
43
    my $del = C4::EDI::DeleteEDIDetails( $input->param('id') );
44
    $template->param( opdelsubmit => 1 );
45
}
46
47
if ( $op eq "addsubmit" ) {
48
    CreateEDIDetails(
49
        $input->param('provider'), $input->param('description'),
50
        $input->param('host'),     $input->param('user'),
51
        $input->param('pass'),     $input->param('path'),
52
        $input->param('in_dir'),   $input->param('san')
53
    );
54
    $template->param( opaddsubmit => 1 );
55
}
56
57
if ( $op eq "editsubmit" ) {
58
    UpdateEDIDetails(
59
        $input->param('editid'), $input->param('description'),
60
        $input->param('host'),   $input->param('user'),
61
        $input->param('pass'),   $input->param('provider'),
62
        $input->param('path'),   $input->param('in_dir'),
63
        $input->param('san')
64
    );
65
    $template->param( opeditsubmit => 1 );
66
}
67
68
my $ediaccounts = C4::EDI::GetEDIAccounts;
69
$template->param( ediaccounts => $ediaccounts );
70
71
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/admin/edi-edit.pl (+73 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::EDI;
26
27
my $input = CGI->new();
28
29
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
    {
31
        template_name   => "admin/edi-edit.tmpl",
32
        query           => $input,
33
        type            => "intranet",
34
        authnotrequired => 0,
35
        flagsrequired   => { borrowers => 1 },
36
    }
37
);
38
my $vendorlist = C4::EDI::GetVendorList;
39
40
my $op = $input->param('op');
41
$template->param( op => $op );
42
43
if ( $op eq "add" ) {
44
    $template->param( opaddsubmit => "addsubmit" );
45
}
46
if ( $op eq "edit" ) {
47
    $template->param( opeditsubmit => "editsubmit" );
48
    my $edi_details      = C4::EDI::GetEDIAccountDetails( $input->param('id') );
49
    my $selectedprovider = $edi_details->{'provider'};
50
    foreach my $prov (@$vendorlist) {
51
        $prov->{selected} = 'selected'
52
          if $prov->{'id'} == $selectedprovider;
53
    }
54
    $template->param(
55
        editid      => $edi_details->{'id'},
56
        description => $edi_details->{'description'},
57
        host        => $edi_details->{'host'},
58
        user        => $edi_details->{'username'},
59
        pass        => $edi_details->{'password'},
60
        provider    => $edi_details->{'provider'},
61
        in_dir      => $edi_details->{'in_dir'},
62
        san         => $edi_details->{'san'}
63
    );
64
}
65
if ( $op eq "del" ) {
66
    $template->param( opdelsubmit => "delsubmit" );
67
    $template->param( opdel       => 1 );
68
    $template->param( id          => $input->param('id') );
69
}
70
71
$template->param( vendorlist => $vendorlist );
72
73
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/atomicupdate/edifact.sql (+27 lines)
Line 0 Link Here
1
CREATE TABLE IF NOT EXISTS `vendor_edi_accounts` (
2
  `id` int(11) NOT NULL auto_increment,
3
  `description` text NOT NULL,
4
  `host` text,
5
  `username` text,
6
  `password` text,
7
  `last_activity` date default NULL,
8
  `provider` int(11) default NULL,
9
  `in_dir` text,
10
  `san` varchar(10) default NULL,
11
  PRIMARY KEY  (`id`)
12
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
13
14
CREATE TABLE IF NOT EXISTS `edifact_messages` (
15
  `key` int(11) NOT NULL auto_increment,
16
  `message_type` text NOT NULL,
17
  `date_sent` date default NULL,
18
  `provider` int(11) default NULL,
19
  `status` text,
20
  `basketno` int(11) NOT NULL default '0',
21
  PRIMARY KEY  (`key`)
22
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
23
24
insert into permissions (module_bit, code, description) values (13, 'edi_manage', 'Manage EDIFACT transmissions');
25
26
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES 
27
('EDIfactEAN', '56781234', '', 'EAN identifier for the library used in EDIfact messages', 'Textarea');
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc (-1 / +2 lines)
Lines 61-67 Link Here
61
<ul>
61
<ul>
62
    [% IF ( NoZebra ) %]<li><a href="/cgi-bin/koha/admin/stopwords.pl">Stop words</a></li>[% END %]
62
    [% IF ( NoZebra ) %]<li><a href="/cgi-bin/koha/admin/stopwords.pl">Stop words</a></li>[% END %]
63
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
63
	<!-- <li><a href="/cgi-bin/koha/admin/printers.pl">Network Printers</a></li> -->
64
    <li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></li>
64
	<li><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 Client Targets</a></li>
65
	<li><a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></li>
65
</ul>
66
</ul>
66
</div>
67
</div>
67
</div>
68
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (-1 / +4 lines)
Lines 23-29 Link Here
23
    [% IF ( CAN_user_tools_import_patrons ) %]
23
    [% IF ( CAN_user_tools_import_patrons ) %]
24
	<li><a href="/cgi-bin/koha/tools/import_borrowers.pl">Import patrons</a></li>
24
	<li><a href="/cgi-bin/koha/tools/import_borrowers.pl">Import patrons</a></li>
25
    [% END %]
25
    [% END %]
26
    [% IF ( CAN_user_tools_edit_notices ) %]
26
    [% IF CAN_user_tools_edit_notices %]
27
    <li><a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; slips</a></li>
27
    <li><a href="/cgi-bin/koha/tools/letter.pl">Notices &amp; slips</a></li>
28
    [% END %]
28
    [% END %]
29
    [% IF ( CAN_user_tools_edit_notice_status_triggers ) %]
29
    [% IF ( CAN_user_tools_edit_notice_status_triggers ) %]
Lines 98-101 Link Here
98
    [% IF ( CAN_user_tools_edit_quotes ) %]
98
    [% IF ( CAN_user_tools_edit_quotes ) %]
99
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
99
       <li><a href="/cgi-bin/koha/tools/quotes.pl">Quote editor</a></li>
100
    [% END %]
100
    [% END %]
101
    [% IF ( CAN_user_tools_edi_manage ) %]
102
	<li><a href="/cgi-bin/koha/tools/edi.pl">EDIfact messages</a></li>
103
    [% END %]
101
</ul></div></div>
104
</ul></div></div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-1 / +10 lines)
Lines 120-125 Link Here
120
                            new YAHOO.widget.Button("basketheadbutton");
120
                            new YAHOO.widget.Button("basketheadbutton");
121
                            new YAHOO.widget.Button("exportbutton");
121
                            new YAHOO.widget.Button("exportbutton");
122
                            new YAHOO.widget.Button("delbasketbutton");
122
                            new YAHOO.widget.Button("delbasketbutton");
123
                            new YAHOO.widget.Button("ediorderbutton");
123
                        }
124
                        }
124
                        //]]>
125
                        //]]>
125
                    </script>
126
                    </script>
Lines 134-139 Link Here
134
                        <li><a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="closebutton">Close this basket</a></li>
135
                        <li><a href="[% script_name %]?op=close&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="closebutton">Close this basket</a></li>
135
                    [% END %]
136
                    [% END %]
136
                        <li><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="exportbutton">Export this basket as CSV</a></li>
137
                        <li><a href="[% script_name %]?op=export&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="exportbutton">Export this basket as CSV</a></li>
138
                    [% IF ediaccount %]
139
                        <li><a href="[% script_name %]?op=ediorder&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" class="button" id="ediorderbutton">EDIfact order</a></li>
140
                    [% END %]
137
                    </ul>
141
                    </ul>
138
142
139
                </div>
143
                </div>
Lines 159-165 Link Here
159
                [% END %]
163
                [% END %]
160
            [% END %]
164
            [% END %]
161
            [% END %]
165
            [% END %]
162
166
	[% IF ( edifile ) %]
167
	<div id="edifile" class="dialog alert">EDIfact order created and will be sent overnight. Filename: <strong>[% edifile %]</strong> - <a href="/cgi-bin/koha/acqui/basket.pl?op=edisend&basketno=[% basketno %]&booksellerid=[% booksellerid %]">Send this order now?</a></div>
168
	[% END %]
169
	[% IF ( edisend ) %]
170
	<div id="edisend" class="dialog alert"><strong>[% edisend %]</strong></div>
171
	[% END %]
163
    [% IF ( NO_BOOKSELLER ) %]
172
    [% IF ( NO_BOOKSELLER ) %]
164
    <h2>Vendor not found</h2>
173
    <h2>Vendor not found</h2>
165
    [% ELSE %]
174
    [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 107-112 Link Here
107
	<dd>Printers (UNIX paths).</dd> -->
107
	<dd>Printers (UNIX paths).</dd> -->
108
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
108
    <dt><a href="/cgi-bin/koha/admin/z3950servers.pl">Z39.50 client targets</a></dt>
109
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
109
	<dd>Define which servers to query for MARC data in the integrated Z39.50 client.</dd>
110
	<dt><a href="/cgi-bin/koha/admin/edi-accounts.pl">EDI Accounts</a></dt>
111
	<dd>Manage vendor EDI accounts for import/export</dd>
110
</dl>
112
</dl>
111
</div>
113
</div>
112
114
(-)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:</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/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 (+5 lines)
Lines 97-102 Link Here
97
    <dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
97
    <dd>Quote editor for Quote-of-the-day feature in OPAC</dd>
98
    [% END %]
98
    [% END %]
99
99
100
    [% IF ( CAN_user_tools_edi_manage ) %]
101
    <dt><a href="/cgi-bin/koha/tools/edi.pl">EDIfact messages</a></dt>
102
    <dd>Manage EDIfact transmissions</dd>
103
    [% END %]
104
100
</dl>
105
</dl>
101
</div>
106
</div>
102
<div class="yui-u">
107
<div class="yui-u">
(-)a/misc/cronjobs/clean_edifiles.pl (+43 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 C4::Context;
23
my $edidir = C4::Context->config('intranetdir');
24
25
$edidir .= '/misc/edi_files';
26
opendir( my $dh, $edidir );
27
my @files = readdir($dh);
28
close $dh;
29
30
foreach my $file (@files) {
31
    my $now  = time;
32
    my @stat = stat("$edidir/$file");
33
    if (
34
        $stat[9] < ( $now - 2592000 )
35
        && (   ( index lc($file), '.ceq' ) > -1
36
            || ( index lc($file), '.cep' ) > -1 )
37
      )
38
    {
39
        print "Deleting file $edidir/$file...";
40
        unlink("$edidir/$file");
41
        print "Done.\n";
42
    }
43
}
(-)a/misc/cronjobs/edifact_order_ftp_transfer.pl (+132 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2011,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::Context;
24
use C4::Auth;
25
use C4::Output;
26
use C4::EDI;
27
use Net::FTP;
28
29
my $ftpaccounts = C4::EDI::GetEDIFTPAccounts;
30
31
my @ERRORS;
32
my @putdirlist;
33
my $newerr;
34
my @files;
35
my $putdir = C4::Context->config('intranetdir');
36
$putdir .= '/misc/edi_files/';
37
my $ediparse;
38
opendir( my $dh, $putdir );
39
@putdirlist = readdir $dh;
40
closedir $dh;
41
42
foreach my $accounts (@$ftpaccounts) {
43
    my $ftp = Net::FTP->new( $accounts->{host}, Timeout => 10, Passive => 1 )
44
      or $newerr = 1;
45
    $ftp->binary();
46
    push @ERRORS, "Can't ftp to $accounts->{host}: $!\n" if $newerr;
47
    myerr() if $newerr;
48
    if ( !$newerr ) {
49
        $newerr = 0;
50
        print "Connected to $accounts->{host}\n";
51
52
        $ftp->login( "$accounts->{username}", "$accounts->{password}" )
53
          or $newerr = 1;
54
        print "Getting file list\n";
55
        push @ERRORS, "Can't login to $accounts->{host}: $!\n" if $newerr;
56
        $ftp->quit if $newerr;
57
        myerr() if $newerr;
58
        if ( !$newerr ) {
59
            print "Logged in\n";
60
            $ftp->cwd( $accounts->{in_dir} ) or $newerr = 1;
61
            push @ERRORS, "Can't cd in server $accounts->{host} $!\n"
62
              if $newerr;
63
            myerr() if $newerr;
64
            $ftp->quit if $newerr;
65
66
            @files = $ftp->ls or $newerr = 1;
67
            push @ERRORS,
68
              "Can't get file list from server $accounts->{host} $!\n"
69
              if $newerr;
70
            myerr() if $newerr;
71
            if ( !$newerr ) {
72
                print "Got  file list\n";
73
                foreach my $file (@files) {
74
                    if ( ( index lc($_), '.ceq' ) > -1 ) {
75
                        my $match;
76
                        foreach my $f (@putdirlist) {
77
                            if ( $f eq $file ) {
78
                                $match = 1;
79
                                last;
80
                            }
81
                        }
82
                        if ( $match != 1 ) {
83
                            chdir $putdir;
84
                            $ftp->get($_) or $newerr = 1;
85
                            push @ERRORS,
86
"Can't transfer file ($_) from $accounts->{host} $!\n"
87
                              if $newerr;
88
                            $ftp->quit if $newerr;
89
                            myerr() if $newerr;
90
                            if ( !$newerr ) {
91
                                $ediparse =
92
                                  ParseEDIQuote( $_, $accounts->{provider} );
93
                            }
94
                            if ( $ediparse == 1 ) {
95
                                my $qext    = '.ceq';
96
                                my $rext    = '.eeq';
97
                                my $renamed = lc($_);
98
                                $renamed =~ s/$qext/$rext/g;
99
                                $ftp->rename( $_, $renamed );
100
                            }
101
                        }
102
                    }
103
                }
104
            }
105
        }
106
        if ( !$newerr ) {
107
            LogEDITransaction("$accounts->{id}");
108
        }
109
        $ftp->quit;
110
    }
111
    $newerr = 0;
112
}
113
114
print "\n@ERRORS\n";
115
116
if (@ERRORS) {
117
    my $logfile = C4::Context->config('intranetdir');
118
    $logfile .= '/misc/edi_files/edi_ftp_error.log';
119
    open my $fh, '>>', $logfile;
120
    my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime(time);
121
    printf $fh "%4d-%02d-%02d %02d:%02d:%02d\n-----\n", $year + 1900,
122
      $mon + 1, $mday, $hour, $min, $sec;
123
    print $fh "@ERRORS\n";
124
    close $fh;
125
}
126
127
sub myerr {
128
    print 'Error: ';
129
    print @ERRORS;
130
    return;
131
}
132
(-)a/misc/cronjobs/send_queued_edi_orders.pl (+28 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::EDI;
26
27
28
SendQueuedEDIOrders();
(-)a/tools/edi.pl (-1 / +43 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::EDI;
26
27
my $input = CGI->new();
28
29
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30
    {
31
        template_name   => "tools/edi.tmpl",
32
        query           => $input,
33
        type            => "intranet",
34
        authnotrequired => 0,
35
        flagsrequired   => { borrowers => 1 },
36
    }
37
);
38
39
my $messagelist = C4::EDI::GetEDIfactMessageList();
40
41
$template->param( messagelist => $messagelist );
42
43
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 7736