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

(-)a/acqui/addorderiso2709.pl (-84 / +327 lines)
Lines 25-30 use Modern::Perl; Link Here
25
use CGI qw ( -utf8 );
25
use CGI qw ( -utf8 );
26
use Carp;
26
use Carp;
27
use YAML qw/Load/;
27
use YAML qw/Load/;
28
use List::MoreUtils qw/uniq/;
28
29
29
use C4::Context;
30
use C4::Context;
30
use C4::Auth;
31
use C4::Auth;
Lines 181-265 if ($op eq ""){ Link Here
181
        } else {
182
        } else {
182
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
183
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
183
        }
184
        }
184
        # 3rd add order
185
185
        my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser );
186
        # Add items from MarcItemFieldsToOrder
186
        # get quantity in the MARC record (1 if none)
187
        my @homebranches = $input->multi_param('homebranch');
187
        my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1;
188
        my $count = scalar @homebranches;
188
        my %orderinfo = (
189
        my @holdingbranches = $input->multi_param('holdingbranch');
189
            biblionumber       => $biblionumber,
190
        my @itypes = $input->multi_param('itype');
190
            basketno           => $cgiparams->{'basketno'},
191
        my @nonpublic_notes = $input->multi_param('nonpublic_note');
191
            quantity           => $c_quantity,
192
        my @public_notes = $input->multi_param('public_note');
192
            branchcode         => $patron->{branchcode},
193
        my @locs = $input->multi_param('loc');
193
            budget_id          => $c_budget_id,
194
        my @ccodes = $input->multi_param('ccodes');
194
            uncertainprice     => 1,
195
        my @notforloans = $input->multi_param('notforloans');
195
            sort1              => $c_sort1,
196
        my @uris = $input->multi_param('uri');
196
            sort2              => $c_sort2,
197
        my @copynos = $input->multi_param('copyno');
197
            order_internalnote => $cgiparams->{'all_order_internalnote'},
198
        my @budget_codes = $input->multi_param('budget_code');
198
            order_vendornote   => $cgiparams->{'all_order_vendornote'},
199
        my @itemprices = $input->multi_param('itemprice');
199
            currency           => $cgiparams->{'all_currency'},
200
        my $itemcreation = 0;
200
        );
201
        for (my $i = 0; $i < $count; $i++) {
201
        # get the price if there is one.
202
            $itemcreation = 1;
202
        my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
203
            my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({
203
        if ($price){
204
                homebranch => $homebranches[$i],
204
            # in France, the cents separator is the , but sometimes, ppl use a .
205
                holdingbranch => $holdingbranches[$i],
205
            # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
206
                itemnotes_nonpublic => $nonpublic_notes[$i],
206
            $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
207
                itemnotes => $public_notes[$i],
207
            $price = Koha::Number::Price->new($price)->unformat;
208
                location => $locs[$i],
208
            $orderinfo{gstrate} = $bookseller->{gstrate};
209
                ccode => $ccodes[$i],
209
            my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
210
                notforloan => $notforloans[$i],
210
            if ( $bookseller->{listincgst} ) {
211
                uri => $uris[$i],
211
                if ( $c_discount ) {
212
                copynumber => $copynos[$i],
212
                    $orderinfo{ecost} = $price;
213
                price => $itemprices[$i],
213
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
214
            }, $biblionumber);
214
                } else {
215
        }
215
                    $orderinfo{ecost} = $price * ( 1 - $c );
216
        if ($itemcreation == 1) {
216
                    $orderinfo{rrp}   = $price;
217
            # Group orderlines from MarcItemFieldsToOrder
218
            my $budget_hash;
219
            for (my $i = 0; $i < $count; $i++) {
220
                $budget_hash->{$budget_codes[$i]}->{quantity} += 1;
221
                $budget_hash->{$budget_codes[$i]}->{price} = $itemprices[$i];
222
            }
223
224
            # Create orderlines from MarcItemFieldsToOrder
225
            while(my ($budget_id, $infos) = each $budget_hash) {
226
                if ($budget_id) {
227
                    my %orderinfo = (
228
                        biblionumber       => $biblionumber,
229
                        basketno           => $cgiparams->{'basketno'},
230
                        quantity           => $infos->{quantity},
231
                        budget_id          => $budget_id,
232
                        currency           => $cgiparams->{'all_currency'},
233
                    );
234
235
                    my $price = $infos->{price};
236
                    if ($price){
237
                        # in France, the cents separator is the , but sometimes, ppl use a .
238
                        # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
239
                        $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
240
                        $price = Koha::Number::Price->new($price)->unformat;
241
                        $orderinfo{gstrate} = $bookseller->{gstrate};
242
                        my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
243
                        if ( $bookseller->{listincgst} ) {
244
                            if ( $c_discount ) {
245
                                $orderinfo{ecost} = $price;
246
                                $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
247
                            } else {
248
                                $orderinfo{ecost} = $price * ( 1 - $c );
249
                                $orderinfo{rrp}   = $price;
250
                            }
251
                        } else {
252
                            if ( $c_discount ) {
253
                                $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
254
                                $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
255
                            } else {
256
                                $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
257
                                $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
258
                            }
259
                        }
260
                        $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
261
                        $orderinfo{unitprice} = $orderinfo{ecost};
262
                        $orderinfo{total} = $orderinfo{ecost} * $infos->{quantity};
263
                    } else {
264
                        $orderinfo{listprice} = 0;
265
                    }
266
267
                    # remove uncertainprice flag if we have found a price in the MARC record
268
                    $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
269
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
217
                }
270
                }
218
            } else {
271
            }
219
                if ( $c_discount ) {
272
        } else {
220
                    $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
273
            # 3rd add order
221
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
274
            my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser );
275
            # get quantity in the MARC record (1 if none)
276
            my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1;
277
            my %orderinfo = (
278
                biblionumber       => $biblionumber,
279
                basketno           => $cgiparams->{'basketno'},
280
                quantity           => $c_quantity,
281
                branchcode         => $patron->{branchcode},
282
                budget_id          => $c_budget_id,
283
                uncertainprice     => 1,
284
                sort1              => $c_sort1,
285
                sort2              => $c_sort2,
286
                order_internalnote => $cgiparams->{'all_order_internalnote'},
287
                order_vendornote   => $cgiparams->{'all_order_vendornote'},
288
                currency           => $cgiparams->{'all_currency'},
289
            );
290
            # get the price if there is one.
291
            my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
292
            if ($price){
293
                # in France, the cents separator is the , but sometimes, ppl use a .
294
                # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
295
                $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
296
                $price = Koha::Number::Price->new($price)->unformat;
297
                $orderinfo{gstrate} = $bookseller->{gstrate};
298
                my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
299
                if ( $bookseller->{listincgst} ) {
300
                    if ( $c_discount ) {
301
                        $orderinfo{ecost} = $price;
302
                        $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
303
                    } else {
304
                        $orderinfo{ecost} = $price * ( 1 - $c );
305
                        $orderinfo{rrp}   = $price;
306
                    }
222
                } else {
307
                } else {
223
                    $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
308
                    if ( $c_discount ) {
224
                    $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
309
                        $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
310
                        $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
311
                    } else {
312
                        $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
313
                        $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
314
                    }
225
                }
315
                }
316
                $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
317
                $orderinfo{unitprice} = $orderinfo{ecost};
318
                $orderinfo{total} = $orderinfo{ecost} * $c_quantity;
319
            } else {
320
                $orderinfo{listprice} = 0;
226
            }
321
            }
227
            $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
228
            $orderinfo{unitprice} = $orderinfo{ecost};
229
            $orderinfo{total} = $orderinfo{ecost} * $c_quantity;
230
        } else {
231
            $orderinfo{listprice} = 0;
232
        }
233
322
234
        # remove uncertainprice flag if we have found a price in the MARC record
323
            # remove uncertainprice flag if we have found a price in the MARC record
235
        $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
324
            $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
236
        my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
325
            my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
237
326
238
        # 4th, add items if applicable
327
239
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
328
            # 4th, add items if applicable
240
        # this is not optimised, but it's working !
329
            # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
241
        my $basket = GetBasket($cgiparams->{basketno});
330
            # this is not optimised, but it's working !
242
        if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) {
331
            my $basket = GetBasket($cgiparams->{basketno});
243
            my @tags         = $input->multi_param('tag');
332
            if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) {
244
            my @subfields    = $input->multi_param('subfield');
333
                my @tags         = $input->multi_param('tag');
245
            my @field_values = $input->multi_param('field_value');
334
                my @subfields    = $input->multi_param('subfield');
246
            my @serials      = $input->multi_param('serial');
335
                my @field_values = $input->multi_param('field_value');
247
            my @ind_tag   = $input->multi_param('ind_tag');
336
                my @serials      = $input->multi_param('serial');
248
            my @indicator = $input->multi_param('indicator');
337
                my @ind_tag   = $input->multi_param('ind_tag');
249
            my $item;
338
                my @indicator = $input->multi_param('indicator');
250
            push @{ $item->{tags} },         $tags[0];
339
                my $item;
251
            push @{ $item->{subfields} },    $subfields[0];
340
                push @{ $item->{tags} },         $tags[0];
252
            push @{ $item->{field_values} }, $field_values[0];
341
                push @{ $item->{subfields} },    $subfields[0];
253
            push @{ $item->{ind_tag} },      $ind_tag[0];
342
                push @{ $item->{field_values} }, $field_values[0];
254
            push @{ $item->{indicator} },    $indicator[0];
343
                push @{ $item->{ind_tag} },      $ind_tag[0];
255
            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag );
344
                push @{ $item->{indicator} },    $indicator[0];
256
            my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
345
                my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag );
257
            for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
346
                my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
258
                my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
347
                for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
259
                $order->add_item( $itemnumber );
348
                    my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
349
                    $order->add_item( $itemnumber );
350
                }
351
            } else {
352
                SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
260
            }
353
            }
261
        } else {
262
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
263
        }
354
        }
264
        $imported++;
355
        $imported++;
265
    }
356
    }
Lines 290-295 foreach my $r ( @{$budgets_hierarchy} ) { Link Here
290
    push @{$budget_loop},
381
    push @{$budget_loop},
291
      { b_id  => $r->{budget_id},
382
      { b_id  => $r->{budget_id},
292
        b_txt => $r->{budget_name},
383
        b_txt => $r->{budget_name},
384
        b_code => $r->{budget_code},
293
        b_sort1_authcat => $r->{'sort1_authcat'},
385
        b_sort1_authcat => $r->{'sort1_authcat'},
294
        b_sort2_authcat => $r->{'sort2_authcat'},
386
        b_sort2_authcat => $r->{'sort2_authcat'},
295
        b_active => $r->{budget_period_active},
387
        b_active => $r->{budget_period_active},
Lines 341-346 sub import_biblios_list { Link Here
341
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
433
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
342
    my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status});
434
    my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status});
343
    my @list = ();
435
    my @list = ();
436
    my $item_id = 1;
437
    my $item_error = 0;
438
439
    my $ccodes    = GetKohaAuthorisedValues("items.ccode");
440
    my $locations = GetKohaAuthorisedValues("items.location");
441
    # location list
442
    my @locations;
443
    foreach (sort keys %$locations) {
444
        push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
445
    }
446
    my @ccodes;
447
    foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
448
        push @ccodes, { code => $_, description => $ccodes->{$_} };
449
    }
450
451
344
452
345
    foreach my $biblio (@$biblios) {
453
    foreach my $biblio (@$biblios) {
346
        my $citation = $biblio->{'title'};
454
        my $citation = $biblio->{'title'};
Lines 364-370 sub import_biblios_list { Link Here
364
        );
472
        );
365
        my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} );
473
        my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} );
366
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
474
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
367
        my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
475
476
        my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
368
        my $price = $infos->{price};
477
        my $price = $infos->{price};
369
        my $quantity = $infos->{quantity};
478
        my $quantity = $infos->{quantity};
370
        my $budget_code = $infos->{budget_code};
479
        my $budget_code = $infos->{budget_code};
Lines 378-396 sub import_biblios_list { Link Here
378
                $budget_id = $biblio_budget->{budget_id};
487
                $budget_id = $biblio_budget->{budget_id};
379
            }
488
            }
380
        }
489
        }
381
        $cellrecord{price} = $price || '';
382
        $cellrecord{quantity} = $quantity || '';
383
        $cellrecord{budget_id} = $budget_id || '';
384
        $cellrecord{discount} = $discount || '';
385
        $cellrecord{sort1} = $sort1 || '';
386
        $cellrecord{sort2} = $sort2 || '';
387
490
491
        # Items
492
        my @itemlist = ();
493
        my $all_items_quantity = 0;
494
        my $alliteminfos = get_infos_syspref_on_item('MarcItemFieldsToOrder', $marcrecord, ['homebranch', 'holdingbranch', 'itype', 'nonpublic_note', 'public_note', 'loc', 'ccode', 'notforloan', 'uri', 'copyno', 'price', 'quantity', 'budget_code']);
495
        if ($alliteminfos != -1) {
496
            foreach my $iteminfos (@$alliteminfos) {
497
                my $item_homebranch = $iteminfos->{homebranch};
498
                my $item_holdingbranch = $iteminfos->{holdingbranch};
499
                my $item_itype = $iteminfos->{itype};
500
                my $item_nonpublic_note = $iteminfos->{nonpublic_note};
501
                my $item_public_note = $iteminfos->{public_note};
502
                my $item_loc = $iteminfos->{loc};
503
                my $item_ccode = $iteminfos->{ccode};
504
                my $item_notforloan = $iteminfos->{notforloan};
505
                my $item_uri = $iteminfos->{uri};
506
                my $item_copyno = $iteminfos->{copyno};
507
                my $item_quantity = $iteminfos->{quantity} || 1;
508
                my $item_budget_code = $iteminfos->{budget_code};
509
                my $item_price = $iteminfos->{price};
510
511
                for (my $i = 0; $i < $item_quantity; $i++) {
512
513
                    my %itemrecord = (
514
                        'item_id' => $item_id++,
515
                        'homebranch' => $item_homebranch,
516
                        'holdingbranch' => $item_holdingbranch,
517
                        'itype' => $item_itype,
518
                        'nonpublic_note' => $item_nonpublic_note,
519
                        'public_note' => $item_public_note,
520
                        'loc' => $item_loc,
521
                        'ccode' => $item_ccode,
522
                        'notforloan' => $item_notforloan,
523
                        'uri' => $item_uri,
524
                        'copyno' => $item_copyno,
525
                        'quantity' => $item_quantity,
526
                        'budget_code' => $item_budget_code || $budget_code,
527
                        'itemprice' => $item_price || $price,
528
                    );
529
                    $all_items_quantity++;
530
                    push @itemlist, \%itemrecord;
531
532
                }
533
            }
534
535
            $cellrecord{'iteminfos'} = \@itemlist;
536
        } else {
537
            $item_error = 1;
538
        }
388
        push @list, \%cellrecord;
539
        push @list, \%cellrecord;
540
541
        if ($alliteminfos == -1 || scalar(@$alliteminfos) == 0) {
542
            $cellrecord{price} = $price || '';
543
            $cellrecord{quantity} = $quantity || '';
544
            $cellrecord{budget_id} = $budget_id || '';
545
            $cellrecord{discount} = $discount || '';
546
            $cellrecord{sort1} = $sort1 || '';
547
            $cellrecord{sort2} = $sort2 || '';
548
        } else {
549
            $cellrecord{quantity} = $all_items_quantity;
550
        }
551
389
    }
552
    }
390
    my $num_records = $batch->{'num_records'};
553
    my $num_records = $batch->{'num_records'};
391
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
554
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
392
    my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
555
    my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
393
    my $item_action = GetImportBatchItemAction($import_batch_id);
556
    my $item_action = GetImportBatchItemAction($import_batch_id);
557
    my @itypes = Koha::ItemTypes->search;
394
    $template->param(biblio_list => \@list,
558
    $template->param(biblio_list => \@list,
395
                        num_results => $num_records,
559
                        num_results => $num_records,
396
                        import_batch_id => $import_batch_id,
560
                        import_batch_id => $import_batch_id,
Lines 399-405 sub import_biblios_list { Link Here
399
                        "nomatch_action_${nomatch_action}" => 1,
563
                        "nomatch_action_${nomatch_action}" => 1,
400
                        nomatch_action => $nomatch_action,
564
                        nomatch_action => $nomatch_action,
401
                        "item_action_${item_action}" => 1,
565
                        "item_action_${item_action}" => 1,
402
                        item_action => $item_action
566
                        item_action => $item_action,
567
                        item_error => $item_error,
568
                        branchloop => GetBranchesLoop(),
569
                        locationloop => \@locations,
570
                        itypeloop => \@itypes,
571
                        ccodeloop => \@ccodes,
403
                    );
572
                    );
404
    batch_info($template, $batch);
573
    batch_info($template, $batch);
405
}
574
}
Lines 446-459 sub add_matcher_list { Link Here
446
}
615
}
447
616
448
sub get_infos_syspref {
617
sub get_infos_syspref {
449
    my ($record, $field_list) = @_;
618
    my ($syspref_name, $record, $field_list) = @_;
450
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
619
    my $syspref = C4::Context->preference($syspref_name);
451
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
620
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
452
    my $yaml = eval {
621
    my $yaml = eval {
453
        YAML::Load($syspref);
622
        YAML::Load($syspref);
454
    };
623
    };
455
    if ( $@ ) {
624
    if ( $@ ) {
456
        warn "Unable to parse MarcFieldsToOrder syspref : $@";
625
        warn "Unable to parse $syspref syspref : $@";
457
        return ();
626
        return ();
458
    }
627
    }
459
    my $r;
628
    my $r;
Lines 471-473 sub get_infos_syspref { Link Here
471
    }
640
    }
472
    return $r;
641
    return $r;
473
}
642
}
643
644
sub equal_number_of_fields {
645
    my ($tags_list, $record) = @_;
646
    my $refcount = 0;
647
    my $count = 0;
648
    for my $tag (@$tags_list) {
649
        return -1 if $count != $refcount;
650
        $count = 0;
651
        for my $field ($record->field($tag)) {
652
            $count++;
653
        }
654
        $refcount = $count if ($refcount == 0);
655
    }
656
    return -1 if $count != $refcount;
657
    return $count;
658
}
659
660
sub get_infos_syspref_on_item {
661
    my ($syspref_name, $record, $field_list) = @_;
662
    my $syspref = C4::Context->preference($syspref_name);
663
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
664
    my $yaml = eval {
665
        YAML::Load($syspref);
666
    };
667
    if ( $@ ) {
668
        warn "Unable to parse $syspref syspref : $@";
669
        return ();
670
    }
671
    my @result;
672
    my @tags_list;
673
674
    # Check tags in syspref definition
675
    for my $field_name ( @$field_list ) {
676
        next unless exists $yaml->{$field_name};
677
        my @fields = split /\|/, $yaml->{$field_name};
678
        for my $field ( @fields ) {
679
            my ( $f, $sf ) = split /\$/, $field;
680
            next unless $f and $sf;
681
            push @tags_list, $f;
682
        }
683
    }
684
    @tags_list = List::MoreUtils::uniq(@tags_list);
685
686
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
687
    # Return if the number of theses fields in the record is not the same.
688
    return -1 if $tags_count == -1;
689
690
    # Gather the fields
691
    my $fields_hash;
692
    foreach my $tag (@tags_list) {
693
        my @tmp_fields;
694
        foreach my $field ($record->field($tag)) {
695
            push @tmp_fields, $field;
696
        }
697
        $fields_hash->{$tag} = \@tmp_fields;
698
    }
699
700
    for (my $i = 0; $i < $tags_count; $i++) {
701
        my $r;
702
        for my $field_name ( @$field_list ) {
703
            next unless exists $yaml->{$field_name};
704
            my @fields = split /\|/, $yaml->{$field_name};
705
            for my $field ( @fields ) {
706
                my ( $f, $sf ) = split /\$/, $field;
707
                next unless $f and $sf;
708
                my $v = $fields_hash->{$f}[$i]->subfield( $sf );
709
                $r->{$field_name} = $v if (defined $v);
710
                last if $yaml->{$field};
711
            }
712
        }
713
        push @result, $r;
714
    }
715
    return \@result;
716
}
(-)a/installer/data/mysql/atomicupdate/Bug_15503_MarcItemFieldsToOrder.sql (+1 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('MarcItemFieldsToOrder','','Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.', NULL, 'textarea');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 233-238 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
233
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
233
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
234
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
234
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
235
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
235
('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'),
236
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
236
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
237
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
237
('MaxFine',NULL,'','Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.','Integer'),
238
('MaxFine',NULL,'','Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.','Integer'),
238
('MaxItemsToDisplayForBatchDel','1000',NULL,'Display up to a given number of items in a single item deletionbatch.','Integer'),
239
('MaxItemsToDisplayForBatchDel','1000',NULL,'Display up to a given number of items in a single item deletionbatch.','Integer'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt (-3 / +89 lines)
Lines 90-106 Link Here
90
90
91
        $("select[name='all_budget_id']").change();
91
        $("select[name='all_budget_id']").change();
92
92
93
        $("#records_to_import fieldset.rows ol").hide();
93
        $("#records_to_import fieldset.rows div").hide();
94
        $('input:checkbox[name="import_record_id"]').change(function(){
94
        $('input:checkbox[name="import_record_id"]').change(function(){
95
            var container = $(this).parents("fieldset");
95
            var container = $(this).parents("fieldset");
96
            if ( $(this).is(':checked') ) {
96
            if ( $(this).is(':checked') ) {
97
                $(container).addClass("selected");
97
                $(container).addClass("selected");
98
                $(container).removeClass("unselected");
98
                $(container).removeClass("unselected");
99
                $(container).find("ol").toggle(true);
99
                $(container).find("div").toggle(true);
100
            } else {
100
            } else {
101
                $(container).addClass("unselected");
101
                $(container).addClass("unselected");
102
                $(container).removeClass("selected");
102
                $(container).removeClass("selected");
103
                $(container).find("ol").toggle(false);
103
                $(container).find("div").toggle(false);
104
            }
104
            }
105
        } );
105
        } );
106
106
Lines 134-139 Link Here
134
            if ( error > 0 ) {
134
            if ( error > 0 ) {
135
                alert(error + " " + _("quantity values are not filled in or are not numbers"));
135
                alert(error + " " + _("quantity values are not filled in or are not numbers"));
136
                return false;
136
                return false;
137
138
            }
139
            var error = 0;
140
            $("select[name='budget_code']").each(function() {
141
                if (!$(this).val()) {
142
                    error++;
143
                }
144
            });
145
            if ( error > 0 ) {
146
                alert(_("Some budgets are not defined in item records"));
147
                return false;
137
            }
148
            }
138
149
139
            return disableUnchecked($(this));
150
            return disableUnchecked($(this));
Lines 210-215 Link Here
210
                              ( <a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% biblio.import_record_id %]" class="previewData">MARC</a> | <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;importid=[% biblio.import_record_id %]" class="previewData">Card</a> | <a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]&amp;breedingid=[% biblio.import_record_id %]&amp;import_batch_id=[% biblio.import_batch_id %]&amp;biblionumber=[% biblio.match_biblionumber %]">Add order</a> )
221
                              ( <a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=[% biblio.import_record_id %]" class="previewData">MARC</a> | <a href="/cgi-bin/koha/catalogue/showmarc.pl?viewas=card&amp;importid=[% biblio.import_record_id %]" class="previewData">Card</a> | <a href="/cgi-bin/koha/acqui/neworderempty.pl?booksellerid=[% booksellerid %]&amp;basketno=[% basketno %]&amp;breedingid=[% biblio.import_record_id %]&amp;import_batch_id=[% biblio.import_batch_id %]&amp;biblionumber=[% biblio.match_biblionumber %]">Add order</a> )
211
                            </span>
222
                            </span>
212
                          </legend>
223
                          </legend>
224
                          <div style="float:left">
213
                          <ol>
225
                          <ol>
214
                            <li class="status">
226
                            <li class="status">
215
                              <span class="match">
227
                              <span class="match">
Lines 272-277 Link Here
272
                                <input id="sort2_record_[% biblio.import_record_id %]" type="text" id="sort2" size="20" name="sort2" value="[% biblio.sort2 %]" />
284
                                <input id="sort2_record_[% biblio.import_record_id %]" type="text" id="sort2" size="20" name="sort2" value="[% biblio.sort2 %]" />
273
                            </li>
285
                            </li>
274
                          </ol>
286
                          </ol>
287
                        </div>
288
                        <div style="float:right">
289
                        [% IF item_error %]Item records could not be processed because the number of item fields was uneven.[% END %]
290
                        [% FOREACH item IN biblio.iteminfos %]
291
                        <fieldset>
292
                        <legend>Item Record [% item.item_id %]</legend>
293
                        <ol>
294
                        <li>
295
                        <label for="homebranch_item_[% item.item_id %]">homebranch</label><select id="homebranch_item_[% item.item_id %]" name="homebranch">
296
                        [% FOREACH branchloo IN branchloop %]
297
                          [% IF ( branchloo.value ) == ( item.homebranch )  %]
298
                            <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
299
                          [% ELSE %]
300
                            <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
301
                          [% END %]
302
                        [% END %]
303
                        </select>
304
                        </li>
305
306
                        <li><label for="holdingbranch_item_[% item.item_id %]">holdingbranch</label><select id="holdingbranch_item_[% item.item_id %]" name="holdingbranch">
307
                        [% FOREACH branchloo IN branchloop %]
308
                          [% IF ( branchloo.value ) == ( item.holdingbranch ) %]
309
                            <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
310
                          [% ELSE %]
311
                            <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
312
                          [% END %]
313
                        [% END %]
314
                        </select>
315
                        </li>
316
                        <li><label for="itype_item_[% item.item_id %]">itype</label><select id="itype_item_[% item.item_id %]" name="itype">
317
                        [% FOREACH itypeloo IN itypeloop %]
318
                          [% IF ( itypeloo.value ) == ( item.itype ) %]
319
                            <option value="[% itypeloo.itemtype %]" selected="selected">[% itypeloo.description |html %]</option>
320
                          [% ELSE %]
321
                            <option value="[% itypeloo.itemtype %]">[% itypeloo.description |html %]</option>
322
                          [% END %]
323
                        [% END %]
324
                        </select>
325
                        </li>
326
327
                        <li><label for="nonpublic_note_item_[% item.item_id %]">nonpublic_note</label><input type="text" id="nonpublic_note_item_[% item.item_id %]" name="nonpublic_note" value="[% item.nonpublic_note %]"></li>
328
                        <li><label for="public_note_item_[% item.item_id %]">public_note</label><input type="text" id="public_note_item_[% item.item_id %]" name="public_note" value="[% item.public_note %]"></li>
329
                        <li><label for="loc_item_[% item.item_id %]">loc</label><select id="loc_item_[% item.item_id %]" name="loc">
330
                        <option value=""> </option>
331
                        [% FOREACH locationloo IN locationloop %]
332
                            [% IF ( locationloo.code ) == (item.loc) %]<option value="[% locationloo.code %]" selected="selected">[% locationloo.description %]</option>[% ELSE %]<option value="[% locationloo.code %]">[% locationloo.description %]</option>[% END %]
333
                        [% END %]
334
                       </select>
335
                        </li>
336
337
                        <li><label for="ccode_item_[% item.item_id %]">ccode</label><select id="ccode_item_[% item.item_id %]" name="ccode">
338
                        [% FOREACH ccodeloo IN ccodeloop %]
339
                            [% IF ( ccodeloo.code ) == (item.ccode) %]<option value="[% ccodeloo.code %]" selected="selected">[% ccodeloo.description %]</option>[% ELSE %]<option value="[% ccodeloo.code %]">[% ccodeloo.description %]</option>[% END %]
340
                        [% END %]
341
                        </select>
342
                        </li>
343
344
                        <li><label for="notforloan_item_[% item.item_id %]">notforloan</label><input type="text" id="notforloan_item_[% item.item_id %]" name="notforloan" value="[% item.notforloan %]"></li>
345
                        <li><label for="uri_item_[% item.item_id %]">uri</label><input type="text" id="uri_item_[% item.item_id %]" name="uri" value="[% item.uri %]"></li>
346
                        <li><label for="copyno_item_[% item.item_id %]">copyno</label><input type="text" id="copyno_item_[% item.item_id %]" name="copyno" value="[% item.copyno %]"></li>
347
                        <li><label for="budget_code_item_[% item.item_id %]">budget_code</label><select id="budget_code_item_[% item.item_id %]" name="budget_code">
348
                        <option value="">Select a fund</option>
349
                        [% FOREACH budget_loo IN budget_loop %]
350
                            [% IF ( budget_loo.b_code ) == ( item.budget_code ) %]<option value="[% budget_loo.b_id %]" selected="selected">[% budget_loo.b_txt %]</option>
351
                            [% ELSE %]<option value="[% budget_loo.b_id %]">[% budget_loo.b_txt %]</option>
352
                            [% END %]
353
                        [% END %]
354
                        </select>
355
                        </li>
356
                        <li><label for="price_item_[% item.item_id %]">price</label><input type="text" id="price_item_[% item.item_id %]" name="itemprice" value="[% item.itemprice %]"></li>
357
                        </ol>
358
                        </fieldset>
359
                        [% END %]
360
                        </div>
275
                        </fieldset>
361
                        </fieldset>
276
                            <div id="dataPreview" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
362
                            <div id="dataPreview" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
277
                                <div class="modal-header">
363
                                <div class="modal-header">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-1 / +6 lines)
Lines 62-67 Acquisitions: Link Here
62
            - "You can use the following fields: price, quantity, budget_code, discount, sort1, sort2"
62
            - "You can use the following fields: price, quantity, budget_code, discount, sort1, sort2"
63
            - "<br/>For example:<br/>price: 947$a|947$c<br/>quantity: 969$h<br/>budget_code: 922$a"
63
            - "<br/>For example:<br/>price: 947$a|947$c<br/>quantity: 969$h<br/>budget_code: 922$a"
64
        -
64
        -
65
            - Set the mapping values for new item records created from a MARC record in a staged file.
66
            - pref: MarcItemFieldsToOrder
67
              type: textarea
68
            - "You can use the following fields: homebranch, holdingbranch, itype, nonpublic_note, public_note, loc, ccode, notforloan, uri, copyno and price. Special fields: quantity and budget_code"
69
            - "<br/>For example:<br/>holdingbranch: 975$b<br/>itype: 975$9|975$z"
70
        -
65
            - pref: ClaimsBccCopy
71
            - pref: ClaimsBccCopy
66
              default: no
72
              default: no
67
              choices:
73
              choices:
68
- 

Return to bug 15503