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

(-)a/Koha/MarcOrder.pm (-9 / +56 lines)
Lines 126-140 sub create_order_lines_from_file { Link Here
126
            }
126
            }
127
        );
127
        );
128
128
129
        while( my $import_record = $import_records->next ){
129
        while ( my $import_record = $import_records->next ) {
130
            my $result = add_biblio_from_import_record({
130
            my $result = add_biblio_from_import_record(
131
                import_batch_id => $import_batch_id,
131
                {
132
                import_record   => $import_record,
132
                    import_batch_id => $import_batch_id,
133
                matcher_id      => $params->{matcher_id},
133
                    import_record   => $import_record,
134
                overlay_action  => $params->{overlay_action},
134
                    matcher_id      => $params->{matcher_id},
135
                agent           => $agent,
135
                    overlay_action  => $params->{overlay_action},
136
            });
136
                    agent           => $agent,
137
            warn "Duplicates found in $result->{duplicates_in_batch}, record was skipped." if $result->{duplicates_in_batch};
137
                }
138
            );
139
            warn "Duplicates found in $result->{duplicates_in_batch}, record was skipped."
140
                if $result->{duplicates_in_batch};
138
            next if $result->{skip};
141
            next if $result->{skip};
139
142
140
            my $order_line_details = add_items_from_import_record(
143
            my $order_line_details = add_items_from_import_record(
Lines 595-600 sub add_items_from_import_record { Link Here
595
}
598
}
596
599
597
600
601
=head3 match_file_to_account
602
603
    my $file_match = Koha::MarcOrder->match_file_to_account({
604
        filename => $filename,
605
        filepath => $filepath,
606
        profile  => $profile
607
    });
608
609
    Used by the cronjob to detect whether a file matches the account and should be processed
610
611
=cut
612
613
sub match_file_to_account {
614
    my ( $self, $args ) = @_;
615
616
    my $match    = 0;
617
    my $filename = $args->{filename};
618
    my $filepath = $args->{filepath};
619
    my $profile  = $args->{profile};
620
    my $format   = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML';
621
622
    my ( $errors, $marcrecords );
623
    if ( $format eq 'MARCXML' ) {
624
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding );
625
    } elsif ( $format eq 'ISO2709' ) {
626
        ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File(
627
            $filepath, $profile->record_type,
628
            $profile->encoding
629
        );
630
    }
631
632
    my $match_record = @{$marcrecords}[0];
633
    my ( $field, $subfield ) = split /\$/, $profile->match_field;
634
635
    my $field_value = $match_record->subfield( $field, $subfield ) || '';
636
    my $match_value = $profile->match_value                        || '';
637
638
    if ( $field_value eq $match_value ) {
639
        $match = 1;
640
    }
641
642
    return $match;
643
}
644
598
=head3 import_batches_list
645
=head3 import_batches_list
599
646
600
Fetches import batches matching the batch to be added to the basket and returns these to the template
647
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.07051 @ 2024-07-31 13:01:54
223
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-10-21 14:34:15
204
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Fz6iYOJIQLrlYvAnmW6C4A
224
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6WEUWsxB/YuNiYoIg8TjMQ
205
225
206
__PACKAGE__->add_columns(
226
__PACKAGE__->add_columns(
207
    '+parse_items' => { is_boolean => 1 },
227
    '+parse_items' => { is_boolean => 1 },
(-)a/admin/marc_order_accounts.pl (+2 lines)
Lines 88-93 if ( $op eq 'acct_form' ) { Link Here
88
            item_action        => scalar $input->param('item_action'),
88
            item_action        => scalar $input->param('item_action'),
89
            record_type        => scalar $input->param('record_type'),
89
            record_type        => scalar $input->param('record_type'),
90
            encoding           => scalar $input->param('encoding') || 'UTF-8',
90
            encoding           => scalar $input->param('encoding') || 'UTF-8',
91
            match_field        => scalar $input->param('match_field'),
92
            match_value        => scalar $input->param('match_value'),
91
        };
93
        };
92
94
93
        if ( scalar $input->param('id') ) {
95
        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 4486-4491 CREATE TABLE `marc_order_accounts` ( Link Here
4486
  `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
4486
  `parse_items` tinyint(1) DEFAULT NULL COMMENT 'should items be parsed',
4487
  `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
4487
  `record_type` varchar(50) DEFAULT NULL COMMENT 'type of record in the file',
4488
  `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
4488
  `encoding` varchar(50) DEFAULT NULL COMMENT 'file encoding',
4489
  `match_field` varchar(10) DEFAULT NULL COMMENT 'the field that a vendor account has been mapped to in a marc record',
4490
  `match_value` varchar(50) DEFAULT NULL COMMENT 'the value to be matched against the marc record',
4489
  PRIMARY KEY (`id`),
4491
  PRIMARY KEY (`id`),
4490
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4492
  CONSTRAINT `marc_ordering_account_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
4491
  CONSTRAINT `marc_ordering_account_ibfk_2` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
4493
  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 127-132 MARC Order Accounts Link Here
127
                                    <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
127
                                    <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
128
                                    <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
128
                                    <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
129
                                </li>
129
                                </li>
130
                                <li>
131
                                    <label for="match_field">Match field: </label>
132
                                    <input type="text" name="match_field" id="match_field" size="20" value="[% account.match_field | html %]" />
133
                                    <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>
134
                                </li>
135
                                <li>
136
                                    <label for="match_value">Match value: </label>
137
                                    <input type="text" name="match_value" id="match_value" size="20" value="[% account.match_value | html %]" />
138
                                    <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>
139
                                </li>
130
                            </ol>
140
                            </ol>
131
                        </fieldset>
141
                        </fieldset>
132
                        <fieldset class="rows">
142
                        <fieldset class="rows">
(-)a/misc/cronjobs/marc_ordering_process.pl (-2 / +1 lines)
Lines 127-133 foreach my $acct (@accounts) { Link Here
127
            }
127
            }
128
        }
128
        }
129
    }
129
    }
130
    say sprintf "%s files processed", $files_processed unless $files_processed == 0;
130
    say sprintf "%s file(s) processed", $files_processed unless $files_processed == 0;
131
    print "Moving to next account\n\n";
131
    print "Moving to next account\n\n";
132
}
132
}
133
print "Process complete\n";
133
print "Process complete\n";
134
- 

Return to bug 34355