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

(-)a/Koha/Object/Mixin/AdditionalFields.pm (+28 lines)
Lines 91-96 sub set_additional_fields { Link Here
91
    }
91
    }
92
}
92
}
93
93
94
=head3 prepare_cgi_additional_field_values
95
96
Prepares additional field values from CGI input for use in set_additional_fields
97
98
    Usage example for aqorders:
99
    my @additional_fields = $order->prepare_cgi_additional_field_values( $input, 'aqorders' );
100
101
=cut
102
103
sub prepare_cgi_additional_field_values {
104
    my ( $self, $cgi, $tablename ) = @_;
105
106
    my @additional_fields;
107
    my $table_fields = Koha::AdditionalFields->search( { tablename => $tablename } );
108
109
    while ( my $field = $table_fields->next ) {
110
        my @field_values = $cgi->multi_param( 'additional_field_' . $field->id );
111
        foreach my $value (@field_values) {
112
            push @additional_fields, {
113
                id    => $field->id,
114
                value => $value,
115
            } if $value;
116
        }
117
    }
118
119
    return @additional_fields;
120
}
121
94
=head3 add_additional_fields
122
=head3 add_additional_fields
95
123
96
Similar to set_additional_fields, but instead of overwriting existing fields, only adds new ones
124
Similar to set_additional_fields, but instead of overwriting existing fields, only adds new ones
(-)a/acqui/addorder.pl (-13 / +1 lines)
Lines 386-404 if ( $op eq 'cud-order' ) { Link Here
386
        my @order_users     = split( /:/, $order_users_ids );
386
        my @order_users     = split( /:/, $order_users_ids );
387
        ModOrderUsers( $order->ordernumber, @order_users );
387
        ModOrderUsers( $order->ordernumber, @order_users );
388
388
389
        # Retrieve and save additional fields values
389
        my @additional_fields = $order->prepare_cgi_additional_field_values( $input, 'aqorders' );
390
        my @additional_fields;
391
        my $order_fields = Koha::AdditionalFields->search( { tablename => 'aqorders' } );
392
        while ( my $field = $order_fields->next ) {
393
            my @field_values = $input->param( 'additional_field_' . $field->id );
394
            foreach my $value (@field_values){
395
                push @additional_fields,
396
                {
397
                    id    => $field->id,
398
                    value => $value,
399
                } if $value;
400
            };
401
        }
402
        $order->set_additional_fields( \@additional_fields );
390
        $order->set_additional_fields( \@additional_fields );
403
391
404
        # now, add items if applicable
392
        # now, add items if applicable
(-)a/acqui/basketheader.pl (-11 / +2 lines)
Lines 162-178 if ( $op eq 'add_form' ) { Link Here
162
        );
162
        );
163
    }
163
    }
164
164
165
    my @additional_fields;
165
    my @additional_fields =
166
    my $basket_fields = Koha::AdditionalFields->search({ tablename => 'aqbasket' });
166
        Koha::Acquisition::Baskets->find($basketno)->prepare_cgi_additional_field_values( $input, 'aqbasket' );
167
    while ( my $field = $basket_fields->next ) {
168
        my @field_values = $input->param( 'additional_field_' . $field->id );
169
        foreach my $value (@field_values) {
170
            push @additional_fields, {
171
                id    => $field->id,
172
                value => $value,
173
            } if $value;
174
        }
175
    }
176
    Koha::Acquisition::Baskets->find($basketno)->set_additional_fields(\@additional_fields);
167
    Koha::Acquisition::Baskets->find($basketno)->set_additional_fields(\@additional_fields);
177
168
178
    print $input->redirect('basket.pl?basketno='.$basketno);
169
    print $input->redirect('basket.pl?basketno='.$basketno);
(-)a/acqui/invoice.pl (-11 / +2 lines)
Lines 128-144 elsif ( $op && $op eq 'cud-mod' ) { Link Here
128
        defined($invoice_files) && $invoice_files->MergeFileRecIds(@sources);
128
        defined($invoice_files) && $invoice_files->MergeFileRecIds(@sources);
129
    }
129
    }
130
130
131
    my @additional_fields;
131
    my @additional_fields =
132
    my $invoice_fields = Koha::AdditionalFields->search({ tablename => 'aqinvoices' });
132
        Koha::Acquisition::Invoices->find($invoiceid)->prepare_cgi_additional_field_values( $input, 'aqinvoices' );
133
    while ( my $field = $invoice_fields->next ) {
134
        my @field_values = $input->param( 'additional_field_' . $field->id );
135
        foreach my $value (@field_values) {
136
            push @additional_fields, {
137
                id    => $field->id,
138
                value => $value,
139
            } if $value;
140
        }
141
    }
142
    Koha::Acquisition::Invoices->find($invoiceid)->set_additional_fields(\@additional_fields);
133
    Koha::Acquisition::Invoices->find($invoiceid)->set_additional_fields(\@additional_fields);
143
134
144
    $template->param( modified => 1 );
135
    $template->param( modified => 1 );
(-)a/acqui/parcels.pl (-11 / +2 lines)
Lines 131-147 if ($op and $op eq 'cud-confirm') { Link Here
131
    );
131
    );
132
    if (defined $invoiceid) {
132
    if (defined $invoiceid) {
133
133
134
        my @additional_fields;
134
        my @additional_fields =
135
        my $invoice_fields = Koha::AdditionalFields->search({ tablename => 'aqinvoices' });
135
            Koha::Acquisition::Invoices->find($invoiceid)->prepare_cgi_additional_field_values( $input, 'aqinvoices' );
136
        while ( my $field = $invoice_fields->next ) {
137
            my @field_values = $input->param( 'additional_field_' . $field->id );
138
            foreach my $value (@field_values) {
139
                push @additional_fields, {
140
                    id    => $field->id,
141
                    value => $value,
142
                } if $value;
143
            }
144
        }
145
        if (@additional_fields) {
136
        if (@additional_fields) {
146
            my $invoice = Koha::Acquisition::Invoices->find( $invoiceid );
137
            my $invoice = Koha::Acquisition::Invoices->find( $invoiceid );
147
            $invoice->set_additional_fields(\@additional_fields);
138
            $invoice->set_additional_fields(\@additional_fields);
(-)a/members/mancredit.pl (-11 / +1 lines)
Lines 99-115 if ( $op eq 'cud-add' ) { Link Here
99
        }
99
        }
100
    );
100
    );
101
101
102
    my @additional_fields;
102
    my @additional_fields = $line->prepare_cgi_additional_field_values( $input, 'accountlines:credit' );
103
    my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' });
104
    while ( my $field = $accountline_fields->next ) {
105
        my @field_values = $input->param( 'additional_field_' . $field->id );
106
        foreach my $value (@field_values) {
107
            push @additional_fields, {
108
                id    => $field->id,
109
                value => $value,
110
            } if $value;
111
        }
112
    }
113
    if (@additional_fields) {
103
    if (@additional_fields) {
114
        $line->set_additional_fields(\@additional_fields);
104
        $line->set_additional_fields(\@additional_fields);
115
    }
105
    }
(-)a/members/maninvoice.pl (-11 / +1 lines)
Lines 161-177 if ( $op eq 'cud-add' ) { Link Here
161
                }
161
                }
162
            );
162
            );
163
163
164
            my @additional_fields;
164
            my @additional_fields = $line->prepare_cgi_additional_field_values( $input, 'accountlines:debit' );
165
            my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:debit' });
166
            while ( my $field = $accountline_fields->next ) {
167
                my @field_values = $input->param( 'additional_field_' . $field->id );
168
                foreach my $value (@field_values) {
169
                    push @additional_fields, {
170
                        id    => $field->id,
171
                        value => $value,
172
                    } if $value;
173
                }
174
            }
175
            if (@additional_fields) {
165
            if (@additional_fields) {
176
                $line->set_additional_fields(\@additional_fields);
166
                $line->set_additional_fields(\@additional_fields);
177
            }
167
            }
(-)a/members/paycollect.pl (-24 / +4 lines)
Lines 170-188 if ( $total_paid and $total_paid ne '0.00' ) { Link Here
170
            );
170
            );
171
            $payment_id = $pay_result->{payment_id};
171
            $payment_id = $pay_result->{payment_id};
172
172
173
            my @additional_fields;
173
            my $payment = Koha::Account::Lines->find($payment_id);
174
            my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' });
174
            my @additional_fields = $payment->prepare_cgi_additional_field_values( $input, 'accountlines:credit' );
175
            while ( my $field = $accountline_fields->next ) {
176
                my @field_values = $input->param( 'additional_field_' . $field->id );
177
                foreach my $value (@field_values) {
178
                    push @additional_fields, {
179
                        id    => $field->id,
180
                        value => $value,
181
                    } if $value;
182
                }
183
            }
184
            if (@additional_fields) {
175
            if (@additional_fields) {
185
                my $payment = Koha::Account::Lines->find($payment_id);
186
                $payment->set_additional_fields(\@additional_fields);
176
                $payment->set_additional_fields(\@additional_fields);
187
            }
177
            }
188
178
Lines 248-266 if ( $total_paid and $total_paid ne '0.00' ) { Link Here
248
            }
238
            }
249
            $payment_id = $pay_result->{payment_id};
239
            $payment_id = $pay_result->{payment_id};
250
240
251
            my @additional_fields;
241
            my $payment = Koha::Account::Lines->find($payment_id);
252
            my $accountline_fields = Koha::AdditionalFields->search({ tablename => 'accountlines:credit' });
242
            my @additional_fields = $payment->prepare_cgi_additional_field_values( $input, 'accountlines:credit' );
253
            while ( my $field = $accountline_fields->next ) {
254
                my @field_values = $input->param( 'additional_field_' . $field->id );
255
                foreach my $value (@field_values) {
256
                    push @additional_fields, {
257
                        id    => $field->id,
258
                        value => $value,
259
                    } if $value;
260
                }
261
            }
262
            if (@additional_fields) {
243
            if (@additional_fields) {
263
                my $payment = Koha::Account::Lines->find($payment_id);
264
                $payment->set_additional_fields(\@additional_fields);
244
                $payment->set_additional_fields(\@additional_fields);
265
            }
245
            }
266
246
(-)a/serials/subscription-add.pl (-24 / +4 lines)
Lines 359-376 sub redirect_add_subscription { Link Here
359
        $template->param( mana_msg => $result->{msg} );
359
        $template->param( mana_msg => $result->{msg} );
360
    }
360
    }
361
361
362
    my @additional_fields;
362
    my @additional_fields = Koha::Subscriptions->find($subscriptionid)
363
    my $biblio = Koha::Biblios->find($biblionumber);
363
        ->prepare_cgi_additional_field_values( $query, 'subscription' );
364
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
365
    while ( my $field = $subscription_fields->next ) {
366
        my @field_values = $query->param( 'additional_field_' . $field->id );
367
        foreach my $value (@field_values) {
368
            push @additional_fields, {
369
                id    => $field->id,
370
                value => $value,
371
            } if $value;
372
        }
373
    }
374
    Koha::Subscriptions->find($subscriptionid)->set_additional_fields(\@additional_fields);
364
    Koha::Subscriptions->find($subscriptionid)->set_additional_fields(\@additional_fields);
375
365
376
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
366
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
Lines 475-492 sub redirect_mod_subscription { Link Here
475
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
465
        $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template
476
    );
466
    );
477
467
478
    my @additional_fields;
468
    my @additional_fields =
479
    my $biblio = Koha::Biblios->find($biblionumber);
469
        Koha::Subscriptions->find($subscriptionid)->prepare_cgi_additional_field_values( $query, 'subscription' );
480
    my $subscription_fields = Koha::AdditionalFields->search({ tablename => 'subscription' });
481
    while ( my $field = $subscription_fields->next ) {
482
        my @field_values = $query->param( 'additional_field_' . $field->id );
483
        foreach my $value (@field_values) {
484
            push @additional_fields, {
485
                id    => $field->id,
486
                value => $value,
487
            } if $value;
488
        }
489
    }
490
    Koha::Subscriptions->find($subscriptionid)->set_additional_fields(\@additional_fields);
470
    Koha::Subscriptions->find($subscriptionid)->set_additional_fields(\@additional_fields);
491
471
492
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
472
    print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
(-)a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t (-2 / +63 lines)
Lines 1-13 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 => 4;
4
use Test::More tests => 5;
5
use t::lib::TestBuilder;
5
use t::lib::TestBuilder;
6
use String::Random qw(random_string);
6
use String::Random qw(random_string);
7
use Koha::Database;
7
use Koha::Database;
8
use Koha::Subscription;
8
use Koha::Subscription;
9
use Koha::AdditionalField;
9
use Koha::AdditionalField;
10
use C4::Context;
10
use C4::Context;
11
use CGI;
11
12
12
my $builder = t::lib::TestBuilder->new;
13
my $builder = t::lib::TestBuilder->new;
13
my $schema = Koha::Database->schema;
14
my $schema = Koha::Database->schema;
Lines 218-220 subtest 'add_additional_fields' => sub { Link Here
218
219
219
    $schema->txn_rollback;
220
    $schema->txn_rollback;
220
};
221
};
221
- 
222
223
subtest 'prepare_cgi_additional_field_values' => sub {
224
    plan tests => 1;
225
226
    $schema->txn_begin;
227
228
    my $field = Koha::AdditionalField->new(
229
        {
230
            tablename => 'subscription',
231
            name      => random_string( 'c' x 100 )
232
        }
233
    );
234
    $field->store()->discard_changes();
235
236
    my $field2 = Koha::AdditionalField->new(
237
        {
238
            tablename => 'subscription',
239
            name      => random_string( 'c' x 100 )
240
        }
241
    );
242
    $field2->store()->discard_changes();
243
244
    my $q = CGI->new;
245
    $q->param(
246
        -name  => 'additional_field_' . $field->id,
247
        -value => [qw/value1 value2/],
248
    );
249
    $q->param(
250
        -name  => 'additional_field_' . $field2->id,
251
        -value => '0',
252
    );
253
    $q->param(
254
        -name  => 'irrelevant_param',
255
        -value => 'foo',
256
    );
257
258
    my @additional_fields =
259
        Koha::Object::Mixin::AdditionalFields->prepare_cgi_additional_field_values( $q, 'subscription' );
260
261
    is_deeply(
262
        \@additional_fields,
263
        [
264
            {
265
                'value' => 'value1',
266
                'id'    => $field->id
267
            },
268
            {
269
                'value' => 'value2',
270
                'id'    => $field->id
271
            },
272
            {
273
                'value' => '0',
274
                'id'    => $field2->id
275
            }
276
        ],
277
        'Return of prepare_cgi_additional_field_values should be correct'
278
    );
279
280
    $schema->txn_rollback;
281
282
};

Return to bug 35044