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

(-)a/C4/Serials.pm (-2 / +3 lines)
Lines 618-625 sub SearchSubscriptions { Link Here
618
    my $matching_record_ids_for_additional_fields = [];
618
    my $matching_record_ids_for_additional_fields = [];
619
    if ( @$additional_fields ) {
619
    if ( @$additional_fields ) {
620
        $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids({
620
        $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids({
621
                fields => $args->{additional_fields},
621
                fields => $additional_fields,
622
                tablename => 'subscription',
622
                tablename => 'subscription',
623
                exact_match => 0,
623
        });
624
        });
624
        return () unless @$matching_record_ids_for_additional_fields;
625
        return () unless @$matching_record_ids_for_additional_fields;
625
    }
626
    }
Lines 718-724 sub SearchSubscriptions { Link Here
718
            record_id => $subscription->{subscriptionid},
719
            record_id => $subscription->{subscriptionid},
719
            tablename => 'subscription'
720
            tablename => 'subscription'
720
        });
721
        });
721
        $subscription->{addition_fields} = $additional_field_values->{$subscription->{subscriptionid}};
722
        $subscription->{additional_fields} = $additional_field_values->{$subscription->{subscriptionid}};
722
    }
723
    }
723
724
724
    return @$results;
725
    return @$results;
(-)a/Koha/AdditionalField.pm (-5 / +7 lines)
Lines 97-102 sub insert_values { Link Here
97
    my $dbh = C4::Context->dbh;
97
    my $dbh = C4::Context->dbh;
98
    local $dbh->{RaiseError} = 1;
98
    local $dbh->{RaiseError} = 1;
99
    while ( my ( $record_id, $value ) = each %{$self->{values}} ) {
99
    while ( my ( $record_id, $value ) = each %{$self->{values}} ) {
100
        next unless defined $value;
100
        my $updated = $dbh->do(q|
101
        my $updated = $dbh->do(q|
101
            UPDATE additional_field_values
102
            UPDATE additional_field_values
102
            SET value = ?
103
            SET value = ?
Lines 135-141 sub fetch_values { Link Here
135
136
136
sub all {
137
sub all {
137
    my ( $class, $args ) = @_;
138
    my ( $class, $args ) = @_;
138
    die "BAD CALL: Don't use fetch_all_values as a static method"
139
    die "BAD CALL: Don't use fetch_all_values as an instance method"
139
        if ref $class and UNIVERSAL::can($class,'can');
140
        if ref $class and UNIVERSAL::can($class,'can');
140
    my $tablename = $args->{tablename};
141
    my $tablename = $args->{tablename};
141
    my $searchable = $args->{searchable};
142
    my $searchable = $args->{searchable};
Lines 172-178 sub all { Link Here
172
173
173
sub fetch_all_values {
174
sub fetch_all_values {
174
    my ( $class, $args ) = @_;
175
    my ( $class, $args ) = @_;
175
    die "BAD CALL: Don't use fetch_all_values as a static method"
176
    die "BAD CALL: Don't use fetch_all_values as an instance method"
176
        if ref $class and UNIVERSAL::can($class,'can');
177
        if ref $class and UNIVERSAL::can($class,'can');
177
178
178
    my $record_id = $args->{record_id};
179
    my $record_id = $args->{record_id};
Lines 199-209 sub fetch_all_values { Link Here
199
200
200
sub get_matching_record_ids {
201
sub get_matching_record_ids {
201
    my ( $class, $args ) = @_;
202
    my ( $class, $args ) = @_;
202
    die "BAD CALL: Don't use fetch_all_values as a static method"
203
    die "BAD CALL: Don't use fetch_all_values as an instance method"
203
        if ref $class and UNIVERSAL::can($class,'can');
204
        if ref $class and UNIVERSAL::can($class,'can');
204
205
205
    my $fields = $args->{fields} // [];
206
    my $fields = $args->{fields} // [];
206
    my $tablename = $args->{tablename};
207
    my $tablename = $args->{tablename};
208
    my $exact_match = $args->{exact_match} // 1;
207
    return [] unless @$fields;
209
    return [] unless @$fields;
208
210
209
    my $dbh = C4::Context->dbh;
211
    my $dbh = C4::Context->dbh;
Lines 222-234 sub get_matching_record_ids { Link Here
222
                    WHERE afv.field_id = af.id
224
                    WHERE afv.field_id = af.id
223
                    AND af.name = ?
225
                    AND af.name = ?
224
                    AND af.tablename = ?
226
                    AND af.tablename = ?
225
                    AND value = ?
227
                    AND value LIKE ?
226
                ) AS field$i USING (id)
228
                ) AS field$i USING (id)
227
            WHERE field$i.id IS NOT NULL
229
            WHERE field$i.id IS NOT NULL
228
        ) AS values$i |;
230
        ) AS values$i |;
229
        $subquery .= ' USING (record_id)' if $i > 1;
231
        $subquery .= ' USING (record_id)' if $i > 1;
230
        push @subqueries, $subquery;
232
        push @subqueries, $subquery;
231
        push @args, $field->{name}, $tablename, $field->{value};
233
        push @args, $field->{name}, $tablename, ( $exact_match ? $field->{value} : "%$field->{value}%" );
232
    }
234
    }
233
    $query .= join( ' LEFT JOIN ', @subqueries ) . ' WHERE 1';
235
    $query .= join( ' LEFT JOIN ', @subqueries ) . ' WHERE 1';
234
    for my $j ( 1 .. $i ) {
236
    for my $j ( 1 .. $i ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt (-1 lines)
Lines 17-23 Link Here
17
    </div>
17
    </div>
18
  </div>
18
  </div>
19
  <div class="yui-b">
19
  <div class="yui-b">
20
    [% INCLUDE 'subscriptions-search.inc' %]
21
    [% INCLUDE 'serials-menu.inc' %]
20
    [% INCLUDE 'serials-menu.inc' %]
22
  </div>
21
  </div>
23
</div>
22
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt (-4 / +4 lines)
Lines 829-837 $(document).ready(function() { Link Here
829
                                  <ol>
829
                                  <ol>
830
                                    [% FOR field IN additional_fields_for_subscription %]
830
                                    [% FOR field IN additional_fields_for_subscription %]
831
                                      <li>
831
                                      <li>
832
                                        <label for="additional_fields_[% field.name %]"> [% field.name %]: </label>
832
                                        <label for="additional_field_[% field.id %]"> [% field.name %]: </label>
833
                                        [% IF field.authorised_value_choices %]
833
                                        [% IF field.authorised_value_choices %]
834
                                          <select name="additional_fields_[% field.name %]">
834
                                          <select name="additional_field_[% field.id %]" id="additional_field_[% field.id %]">
835
                                            [% FOREACH av IN field.authorised_value_choices %]
835
                                            [% FOREACH av IN field.authorised_value_choices %]
836
                                              [% IF av.authorised_value == additional_fields.${field.name} %]
836
                                              [% IF av.authorised_value == additional_fields.${field.name} %]
837
                                                <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option>
837
                                                <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option>
Lines 842-851 $(document).ready(function() { Link Here
842
                                          </select> (Authorised values for [% field.authorised_value_category %])
842
                                          </select> (Authorised values for [% field.authorised_value_category %])
843
                                        [% ELSE %]
843
                                        [% ELSE %]
844
                                          [% IF field.marcfield %]
844
                                          [% IF field.marcfield %]
845
                                            <input type="text" value="[% additional_fields.${field.name} %]" name="additional_fields_[% field.name %]" readonly="readonly" />
845
                                            <input type="text" value="[% additional_fields.${field.name} %]" id="additional_field_[% field.id %]" name="additional_field_[% field.id %]" readonly="readonly" />
846
                                            This value will be filled with the [% field.marcfield %] subfield of the selected biblio.
846
                                            This value will be filled with the [% field.marcfield %] subfield of the selected biblio.
847
                                          [% ELSE %]
847
                                          [% ELSE %]
848
                                            <input type="text" value="[% additional_fields.${field.name} %]" name="additional_fields_[% field.name %]" />
848
                                            <input type="text" value="[% additional_fields.${field.name} %]" id="additional_field_[% field.id %]" name="additional_field_[% field.id %]" />
849
                                          [% END %]
849
                                          [% END %]
850
                                        [% END %]
850
                                        [% END %]
851
                                      </li>
851
                                      </li>
(-)a/serials/claims.pl (-1 / +1 lines)
Lines 58-64 for my $s (@{$supplierlist} ) { Link Here
58
    }
58
    }
59
}
59
}
60
60
61
my $additional_fields = Koha::AdditionalField->all( { table => 'subscription', searchable => 1 } );
61
my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription', searchable => 1 } );
62
for my $field ( @$additional_fields ) {
62
for my $field ( @$additional_fields ) {
63
    if ( $field->{authorised_value_category} ) {
63
    if ( $field->{authorised_value_category} ) {
64
        $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
64
        $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
(-)a/serials/serials-search.pl (-2 / +3 lines)
Lines 78-87 if ( $op and $op eq "close" ) { Link Here
78
}
78
}
79
79
80
80
81
my $additional_fields = Koha::AdditionalField->all( { table => 'subscription', searchable => 1 } );
81
my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription', searchable => 1 } );
82
my $additional_field_filters;
82
my $additional_field_filters;
83
for my $field ( @$additional_fields ) {
83
for my $field ( @$additional_fields ) {
84
    if ( my $filter_value = $query->param('additional_field_' . $field->{name} . '_filter') ) {
84
    my $filter_value = $query->param('additional_field_' . $field->{id} . '_filter');
85
    if ( defined ( $filter_value ) ) {
85
        $additional_field_filters->{ $field->{name} } = $filter_value;
86
        $additional_field_filters->{ $field->{name} } = $filter_value;
86
    }
87
    }
87
    if ( $field->{authorised_value_category} ) {
88
    if ( $field->{authorised_value_category} ) {
(-)a/serials/subscription-add.pl (-6 / +6 lines)
Lines 156-162 $template->param(branchloop => $branchloop, Link Here
156
);
156
);
157
157
158
158
159
my $additional_fields = Koha::AdditionalField->all( { table => 'subscription' } );
159
my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
160
for my $field ( @$additional_fields ) {
160
for my $field ( @$additional_fields ) {
161
    if ( $field->{authorised_value_category} ) {
161
    if ( $field->{authorised_value_category} ) {
162
        $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
162
        $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
Lines 352-364 sub redirect_add_subscription { Link Here
352
        $skip_serialseq
352
        $skip_serialseq
353
    );
353
    );
354
354
355
    my $additional_fields = Koha::AdditionalField->all( { table => 'subscription' } );
355
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
356
    my @additional_field_values;
356
    my @additional_field_values;
357
    for my $field ( @$additional_fields ) {
357
    for my $field ( @$additional_fields ) {
358
        my $af = Koha::AdditionalField->new({ id => $field->{id} });
358
        my $af = Koha::AdditionalField->new({ id => $field->{id} });
359
        $af->{values} = {
359
        $af->{values} = {
360
            $subscriptionid => $query->param('additional_fields_' . $field->{name})
360
            $subscriptionid => $query->param('additional_field_' . $field->{id})
361
        };
361
        } if defined $query->param('additional_field_' . $field->{id});
362
        $af->insert_values;
362
        $af->insert_values;
363
    }
363
    }
364
364
Lines 437-443 sub redirect_mod_subscription { Link Here
437
        $skip_serialseq
437
        $skip_serialseq
438
    );
438
    );
439
439
440
    my $additional_fields = Koha::AdditionalField->all( { table => 'subscription' } );
440
    my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
441
    my @additional_field_values;
441
    my @additional_field_values;
442
    for my $field ( @$additional_fields ) {
442
    for my $field ( @$additional_fields ) {
443
        my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch;
443
        my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch;
Lines 451-457 sub redirect_mod_subscription { Link Here
451
            };
451
            };
452
        } else {
452
        } else {
453
            $af->{values} = {
453
            $af->{values} = {
454
                $subscriptionid => $query->param('additional_fields_' . $field->{name})
454
                $subscriptionid => $query->param('additional_field_' . $field->{id})
455
            };
455
            };
456
        }
456
        }
457
        $af->insert_values;
457
        $af->insert_values;
(-)a/t/db_dependent/AdditionalField.t (-15 / +37 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 34;
4
use Test::More tests => 37;
5
5
6
use C4::Context;
6
use C4::Context;
7
use Koha::AdditionalField;
7
use Koha::AdditionalField;
Lines 104-109 use C4::Acquisition; Link Here
104
use C4::Biblio;
104
use C4::Biblio;
105
use C4::Budgets;
105
use C4::Budgets;
106
use C4::Serials;
106
use C4::Serials;
107
use C4::Serials::Frequency;
108
use C4::Serials::Numberpattern;
107
109
108
my $booksellerid = C4::Bookseller::AddBookseller(
110
my $booksellerid = C4::Bookseller::AddBookseller(
109
    {
111
    {
Lines 118-124 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, ''); Link Here
118
my $budgetid;
120
my $budgetid;
119
my $bpid = AddBudgetPeriod({
121
my $bpid = AddBudgetPeriod({
120
    budget_period_startdate => '01-01-2015',
122
    budget_period_startdate => '01-01-2015',
121
    budget_period_enddate   => '12-31-2015',
123
    budget_period_enddate   => '01-01-2016',
122
    budget_description      => "budget desc"
124
    budget_description      => "budget desc"
123
});
125
});
124
126
Lines 132-153 my $budget_id = AddBudget({ Link Here
132
    budget_period_id   => $bpid
134
    budget_period_id   => $bpid
133
});
135
});
134
136
137
my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
138
my $pattern_id = AddSubscriptionNumberpattern({
139
    label => 'Test numberpattern 1',
140
    numberingmethod => '{X}'
141
});
142
135
my $subscriptionid1 = NewSubscription(
143
my $subscriptionid1 = NewSubscription(
136
    undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
144
    undef,      "",     undef, undef, $budget_id, $biblionumber,
137
    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
145
    '2013-01-01', $frequency_id, undef, undef,  undef,
138
    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
146
    undef,      undef,  undef, undef, undef, undef,
139
    undef,      undef,  undef, undef, undef,      undef,         undef,  1,
147
    1,          "notes",undef, '2013-01-01', undef, $pattern_id,
140
    "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
148
    undef,       undef,  0,    "intnotes",  0,
141
    "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
149
    undef, undef, 0,          undef,         '2013-01-01', 0
142
);
150
);
143
151
144
my $subscriptionid2 = NewSubscription(
152
my $subscriptionid2 = NewSubscription(
145
    undef,      "",     undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
153
    undef,      "",     undef, undef, $budget_id, $biblionumber,
146
    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
154
    '2013-01-01', $frequency_id, undef, undef,  undef,
147
    undef,      undef,  undef, undef, undef,      undef,         undef,  undef,
155
    undef,      undef,  undef, undef, undef, undef,
148
    undef,      undef,  undef, undef, undef,      undef,         undef,  1,
156
    1,          "notes",undef, '2013-01-01', undef, $pattern_id,
149
    "notes",    undef,  undef, undef, undef,      undef,         undef,  0,
157
    undef,       undef,  0,    "intnotes",  0,
150
    "intnotes", 0,      undef, undef, 0,          undef,         '31-12-2013',
158
    undef, undef, 0,          undef,         '2013-01-01', 0
151
);
159
);
152
160
153
# insert
161
# insert
Lines 268-271 is ( $exists, 1, "get_matching_record_ids: field common: common_value matches su Link Here
268
$exists = grep /not_existent_id/, @$matching_record_ids;
276
$exists = grep /not_existent_id/, @$matching_record_ids;
269
is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
277
is ( $exists, 0, "get_matching_record_ids: field common: common_value does not inexistent id" );
270
278
279
$fields = [
280
    {
281
        name => 'common',
282
        value => q|common|,
283
    }
284
];
285
$matching_record_ids = Koha::AdditionalField->get_matching_record_ids({ tablename => 'subscription', fields => $fields, exact_match => 0 });
286
$exists = grep /$subscriptionid1/, @$matching_record_ids;
287
is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription1" );
288
$exists = grep /$subscriptionid2/, @$matching_record_ids;
289
is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscription2 too" );
290
$exists = grep /not_existent_id/, @$matching_record_ids;
291
is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
292
293
271
$dbh->rollback;
294
$dbh->rollback;
272
- 

Return to bug 10855