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

(-)a/Koha/MarcOrder.pm (+47 lines)
Lines 658-663 sub create_order_lines { Link Here
658
    return;
658
    return;
659
}
659
}
660
660
661
662
=head3 match_file_to_account
663
664
    my $file_match = Koha::MarcOrder->match_file_to_account({
665
        filename => $filename,
666
        filepath => $filepath,
667
        profile  => $profile
668
    });
669
670
    Used by the cronjob to detect whether a file matches the account and should be processed
671
672
=cut
673
674
675
sub match_file_to_account {
676
    my ($self, $args) = @_;
677
678
    my $match       = 0;
679
    my $filename    = $args->{filename};
680
    my $filepath    = $args->{filepath};
681
    my $profile     = $args->{profile};
682
    my $format      = index($filename, '.mrc') != -1 ? 'ISO2709' : 'MARCXML';
683
684
    my ( $errors, $marcrecords );
685
    if ( $format eq 'MARCXML' ) {
686
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding );
687
    } elsif ( $format eq 'ISO2709' ) {
688
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File(
689
            $filepath, $profile->record_type,
690
            $profile->encoding
691
        );
692
    }
693
694
    my $match_record = @{ $marcrecords }[0];
695
    my ( $field, $subfield ) = split /\$/, $profile->match_field;
696
697
    my $field_value = $match_record->subfield( $field, $subfield );
698
    my $match_value = $profile->match_value;
699
700
    if($field_value eq $match_value) {
701
        $match = 1;
702
    }
703
704
    return $match;
705
}
706
707
661
=head3 import_batches_list
708
=head3 import_batches_list
662
709
663
Fetches import batches matching the batch to be added to the basket and returns these to the template
710
Fetches import batches matching the batch to be added to the basket and returns these to the template
(-)a/Koha/Schema/Result/MarcOrderAccount.pm (-2 / +22 lines)
Lines 116-121 type of record in the file Link Here
116
116
117
file encoding
117
file encoding
118
118
119
=head2 match_field
120
121
  data_type: 'varchar'
122
  is_nullable: 1
123
  size: 10
124
125
the field that a vendor account has been mapped to in a marc record
126
127
=head2 match_value
128
129
  data_type: 'varchar'
130
  is_nullable: 1
131
  size: 50
132
133
the value to be matched against the marc record
134
119
=cut
135
=cut
120
136
121
__PACKAGE__->add_columns(
137
__PACKAGE__->add_columns(
Lines 143-148 __PACKAGE__->add_columns( Link Here
143
  { data_type => "varchar", is_nullable => 1, size => 50 },
159
  { data_type => "varchar", is_nullable => 1, size => 50 },
144
  "encoding",
160
  "encoding",
145
  { data_type => "varchar", is_nullable => 1, size => 50 },
161
  { data_type => "varchar", is_nullable => 1, size => 50 },
162
  "match_field",
163
  { data_type => "varchar", is_nullable => 1, size => 10 },
164
  "match_value",
165
  { data_type => "varchar", is_nullable => 1, size => 50 },
146
);
166
);
147
167
148
=head1 PRIMARY KEY
168
=head1 PRIMARY KEY
Lines 200-207 __PACKAGE__->belongs_to( Link Here
200
);
220
);
201
221
202
222
203
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-07-18 16:31:16
223
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-07 08:55:26
204
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vMLrmisXQnn2e60qW7ppnA
224
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6pN1TLuqkf9rQaeQ7Wf26A
205
225
206
226
207
# You can replace this text with custom code or comments, and it will be preserved on regeneration
227
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/admin/marc_order_accounts.pl (+2 lines)
Lines 89-94 if( $op eq 'acct_form') { Link Here
89
            item_action        => scalar $input->param('item_action'),
89
            item_action        => scalar $input->param('item_action'),
90
            record_type        => scalar $input->param('record_type'),
90
            record_type        => scalar $input->param('record_type'),
91
            encoding           => scalar $input->param('encoding') || 'UTF-8',
91
            encoding           => scalar $input->param('encoding') || 'UTF-8',
92
            match_field        => scalar $input->param('match_field'),
93
            match_value        => scalar $input->param('match_value'),
92
        };
94
        };
93
95
94
        if(scalar $input->param('id')) {
96
        if(scalar $input->param('id')) {
(-)a/installer/data/mysql/atomicupdate/bug_34355-add_marc_order_accounts.pl (-6 / +10 lines)
Lines 1-14 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "34355",
4
    bug_number  => "34355",
5
    description => "Add a table to allow creation of MARC order accounts and a syspref to activate it.",
5
    description => "Add a table to allow creation of MARC order accounts and a syspref to activate it.",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        unless( TableExists('marc_order_accounts') ) {
10
        unless ( TableExists('marc_order_accounts') ) {
11
            $dbh->do(q{
11
            $dbh->do(
12
                q{
12
                CREATE TABLE `marc_order_accounts` (
13
                CREATE TABLE `marc_order_accounts` (
13
                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier and primary key',
14
                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier and primary key',
14
                `description` varchar(250) NOT NULL COMMENT 'description of this account',
15
                `description` varchar(250) NOT NULL COMMENT 'description of this account',
Lines 22-32 return { Link Here
22
                `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
23
                `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
23
                `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
24
                `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
24
                `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
25
                `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
26
                `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record',
27
                `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record',
25
                PRIMARY KEY (`id`),
28
                PRIMARY KEY (`id`),
26
                CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
29
                CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
27
                CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
30
                CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
28
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
31
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
29
            });
32
            }
33
            );
30
34
31
            say $out "Added new table 'marc_order_accounts'";
35
            say $out "Added new table 'marc_order_accounts'";
32
        } else {
36
        } else {
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 4449-4454 CREATE TABLE `marc_order_accounts` ( Link Here
4449
  `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
4449
  `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
4450
  `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
4450
  `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
4451
  `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
4451
  `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
4452
  `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record',
4453
  `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record',
4452
  PRIMARY KEY (`id`),
4454
  PRIMARY KEY (`id`),
4453
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4455
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4454
  CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
4456
  CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt (+10 lines)
Lines 126-131 MARC Order Accounts Link Here
126
                                    <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
126
                                    <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
127
                                    <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
127
                                    <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
128
                                </li>
128
                                </li>
129
                                <li>
130
                                    <label for="match_field">Match field: </label>
131
                                    <input type="text" name="match_field" id="match_field" size="20" value="[% account.match_field | html %]" />
132
                                    <div class="hint">(Optional): If you have files from multiple vendors in the same file directory, the match field is the field in the marc record that will be checked to see if the file should be processed by this account.</div>
133
                                </li>
134
                                <li>
135
                                    <label for="match_value">Match value: </label>
136
                                    <input type="text" name="match_value" id="match_value" size="20" value="[% account.match_value | html %]" />
137
                                    <div class="hint">(Optional): This is the value that will be checked against the match field to see if the file matches this account. If it does it will be processed by this account, if not it will be skipped.</div>
138
                                </li>
129
                            </ol>
139
                            </ol>
130
                        </fieldset>
140
                        </fieldset>
131
                        <fieldset class="rows">
141
                        <fieldset class="rows">
(-)a/misc/cronjobs/marc_ordering_process.pl (-9 / +12 lines)
Lines 106-119 foreach my $acct ( @accounts ) { Link Here
106
106
107
    foreach my $filename ( @files ) {
107
    foreach my $filename ( @files ) {
108
        say sprintf "Creating order lines from file %s", $filename if $verbose;
108
        say sprintf "Creating order lines from file %s", $filename if $verbose;
109
        my $full_path = "$working_dir/$filename";
110
        my $args = {
111
            filename => $filename,
112
            filepath => $full_path,
113
            profile  => $acct,
114
            agent    => 'cron'
115
        };
116
        if($acct->match_field && $acct->match_value) {
117
            my $file_match = Koha::MarcOrder->match_file_to_account($args);
118
            next if !$file_match;
119
        }
109
        if($confirm) {
120
        if($confirm) {
110
            my $full_path = "$working_dir/$filename";
111
            my $args = {
112
                filename => $filename,
113
                filepath => $full_path,
114
                profile  => $acct,
115
                agent    => 'cron'
116
            };
117
            my $result = Koha::MarcOrder->create_order_lines_from_file($args);
121
            my $result = Koha::MarcOrder->create_order_lines_from_file($args);
118
            if($result->{success}) {
122
            if($result->{success}) {
119
                $files_processed++;
123
                $files_processed++;
Lines 125-131 foreach my $acct ( @accounts ) { Link Here
125
            };
129
            };
126
        }
130
        }
127
    }
131
    }
128
    say sprintf "%s files processed", $files_processed unless $files_processed == 0;
132
    say sprintf "%s file(s) processed", $files_processed unless $files_processed == 0;
129
    print "Moving to next account\n\n";
133
    print "Moving to next account\n\n";
130
}
134
}
131
print "Process complete\n";
135
print "Process complete\n";
132
- 

Return to bug 34355