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 182-266 if ($op eq ""){ Link Here
182
        } else {
183
        } else {
183
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
184
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
184
        }
185
        }
185
        # 3rd add order
186
186
        my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser );
187
        # Add items from MarcItemFieldsToOrder
187
        # get quantity in the MARC record (1 if none)
188
        my @homebranches = $input->multi_param('homebranch');
188
        my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1;
189
        my $count = scalar @homebranches;
189
        my %orderinfo = (
190
        my @holdingbranches = $input->multi_param('holdingbranch');
190
            biblionumber       => $biblionumber,
191
        my @itypes = $input->multi_param('itype');
191
            basketno           => $cgiparams->{'basketno'},
192
        my @nonpublic_notes = $input->multi_param('nonpublic_note');
192
            quantity           => $c_quantity,
193
        my @public_notes = $input->multi_param('public_note');
193
            branchcode         => $patron->{branchcode},
194
        my @locs = $input->multi_param('loc');
194
            budget_id          => $c_budget_id,
195
        my @ccodes = $input->multi_param('ccodes');
195
            uncertainprice     => 1,
196
        my @notforloans = $input->multi_param('notforloans');
196
            sort1              => $c_sort1,
197
        my @uris = $input->multi_param('uri');
197
            sort2              => $c_sort2,
198
        my @copynos = $input->multi_param('copyno');
198
            order_internalnote => $cgiparams->{'all_order_internalnote'},
199
        my @budget_codes = $input->multi_param('budget_code');
199
            order_vendornote   => $cgiparams->{'all_order_vendornote'},
200
        my @itemprices = $input->multi_param('itemprice');
200
            currency           => $cgiparams->{'all_currency'},
201
        my $itemcreation = 0;
201
        );
202
        for (my $i = 0; $i < $count; $i++) {
202
        # get the price if there is one.
203
            $itemcreation = 1;
203
        my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
204
            my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({
204
        if ($price){
205
                homebranch => $homebranches[$i], 
205
            # in France, the cents separator is the , but sometimes, ppl use a .
206
                holdingbranch => $holdingbranches[$i],
206
            # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
207
                itemnotes_nonpublic => $nonpublic_notes[$i],
207
            $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
208
                itemnotes => $public_notes[$i],
208
            $price = Koha::Number::Price->new($price)->unformat;
209
                location => $locs[$i],
209
            $orderinfo{gstrate} = $bookseller->{gstrate};
210
                ccode => $ccodes[$i],
210
            my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
211
                notforloan => $notforloans[$i],
211
            if ( $bookseller->{listincgst} ) {
212
                uri => $uris[$i],
212
                if ( $c_discount ) {
213
                copynumber => $copynos[$i],
213
                    $orderinfo{ecost} = $price;
214
                price => $itemprices[$i],
214
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
215
            }, $biblionumber); 
215
                } else {
216
        }
216
                    $orderinfo{ecost} = $price * ( 1 - $c );
217
        if ($itemcreation == 1) {
217
                    $orderinfo{rrp}   = $price;
218
            # Group orderlines from MarcItemFieldsToOrder
219
            my $budget_hash; 
220
            for (my $i = 0; $i < $count; $i++) {
221
                $budget_hash->{$budget_codes[$i]}->{quantity} += 1; 
222
                $budget_hash->{$budget_codes[$i]}->{price} = $itemprices[$i]; 
223
            }
224
225
            # Create orderlines from MarcItemFieldsToOrder
226
            while(my ($budget_id, $infos) = each $budget_hash) {
227
                if ($budget_id) {
228
                    my %orderinfo = (
229
                        biblionumber       => $biblionumber,
230
                        basketno           => $cgiparams->{'basketno'},
231
                        quantity           => $infos->{quantity},
232
                        budget_id          => $budget_id,
233
                        currency           => $cgiparams->{'all_currency'},
234
                    );
235
236
                    my $price = $infos->{price};
237
                    if ($price){
238
                        # in France, the cents separator is the , but sometimes, ppl use a .
239
                        # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
240
                        $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
241
                        $price = Koha::Number::Price->new($price)->unformat;
242
                        $orderinfo{gstrate} = $bookseller->{gstrate};
243
                        my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
244
                        if ( $bookseller->{listincgst} ) {
245
                            if ( $c_discount ) {
246
                                $orderinfo{ecost} = $price;
247
                                $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
248
                            } else {
249
                                $orderinfo{ecost} = $price * ( 1 - $c );
250
                                $orderinfo{rrp}   = $price;
251
                            }
252
                        } else {
253
                            if ( $c_discount ) {
254
                                $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
255
                                $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
256
                            } else {
257
                                $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
258
                                $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
259
                            }
260
                        }
261
                        $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
262
                        $orderinfo{unitprice} = $orderinfo{ecost};
263
                        $orderinfo{total} = $orderinfo{ecost} * $infos->{quantity};
264
                    } else {
265
                        $orderinfo{listprice} = 0;
266
                    }
267
268
                    # remove uncertainprice flag if we have found a price in the MARC record
269
                    $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
270
                    my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
218
                }
271
                }
219
            } else {
272
            }
220
                if ( $c_discount ) {
273
        } else {
221
                    $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
274
            # 3rd add order
222
                    $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
275
            my $patron = C4::Members::GetMember( borrowernumber => $loggedinuser );
276
            # get quantity in the MARC record (1 if none)
277
            my $quantity = GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour')) || 1;
278
            my %orderinfo = (
279
                biblionumber       => $biblionumber,
280
                basketno           => $cgiparams->{'basketno'},
281
                quantity           => $c_quantity,
282
                branchcode         => $patron->{branchcode},
283
                budget_id          => $c_budget_id,
284
                uncertainprice     => 1,
285
                sort1              => $c_sort1,
286
                sort2              => $c_sort2,
287
                order_internalnote => $cgiparams->{'all_order_internalnote'},
288
                order_vendornote   => $cgiparams->{'all_order_vendornote'},
289
                currency           => $cgiparams->{'all_currency'},
290
            );
291
            # get the price if there is one.
292
            my $price= shift( @prices ) || GetMarcPrice($marcrecord, C4::Context->preference('marcflavour'));
293
            if ($price){
294
                # in France, the cents separator is the , but sometimes, ppl use a .
295
                # in this case, the price will be x100 when unformatted ! Replace the . by a , to get a proper price calculation
296
                $price =~ s/\./,/ if C4::Context->preference("CurrencyFormat") eq "FR";
297
                $price = Koha::Number::Price->new($price)->unformat;
298
                $orderinfo{gstrate} = $bookseller->{gstrate};
299
                my $c = $c_discount ? $c_discount : $bookseller->{discount} / 100;
300
                if ( $bookseller->{listincgst} ) {
301
                    if ( $c_discount ) {
302
                        $orderinfo{ecost} = $price;
303
                        $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
304
                    } else {
305
                        $orderinfo{ecost} = $price * ( 1 - $c );
306
                        $orderinfo{rrp}   = $price;
307
                    }
223
                } else {
308
                } else {
224
                    $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
309
                    if ( $c_discount ) {
225
                    $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
310
                        $orderinfo{ecost} = $price / ( 1 + $orderinfo{gstrate} );
311
                        $orderinfo{rrp}   = $orderinfo{ecost} / ( 1 - $c );
312
                    } else {
313
                        $orderinfo{rrp}   = $price / ( 1 + $orderinfo{gstrate} );
314
                        $orderinfo{ecost} = $orderinfo{rrp} * ( 1 - $c );
315
                    }
226
                }
316
                }
317
                $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
318
                $orderinfo{unitprice} = $orderinfo{ecost};
319
                $orderinfo{total} = $orderinfo{ecost} * $c_quantity;
320
            } else {
321
                $orderinfo{listprice} = 0;
227
            }
322
            }
228
            $orderinfo{listprice} = $orderinfo{rrp} / $active_currency->rate;
229
            $orderinfo{unitprice} = $orderinfo{ecost};
230
            $orderinfo{total} = $orderinfo{ecost} * $c_quantity;
231
        } else {
232
            $orderinfo{listprice} = 0;
233
        }
234
323
235
        # remove uncertainprice flag if we have found a price in the MARC record
324
            # remove uncertainprice flag if we have found a price in the MARC record
236
        $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
325
            $orderinfo{uncertainprice} = 0 if $orderinfo{listprice};
237
        my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
326
            my $order = Koha::Acquisition::Order->new( \%orderinfo )->insert;
238
327
239
        # 4th, add items if applicable
328
240
        # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
329
            # 4th, add items if applicable
241
        # this is not optimised, but it's working !
330
            # parse the item sent by the form, and create an item just for the import_record_id we are dealing with
242
        my $basket = GetBasket($cgiparams->{basketno});
331
            # this is not optimised, but it's working !
243
        if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) {
332
            my $basket = GetBasket($cgiparams->{basketno});
244
            my @tags         = $input->multi_param('tag');
333
            if ( C4::Context->preference('AcqCreateItem') eq 'ordering' && !$basket->{is_standing} ) {
245
            my @subfields    = $input->multi_param('subfield');
334
                my @tags         = $input->multi_param('tag');
246
            my @field_values = $input->multi_param('field_value');
335
                my @subfields    = $input->multi_param('subfield');
247
            my @serials      = $input->multi_param('serial');
336
                my @field_values = $input->multi_param('field_value');
248
            my @ind_tag   = $input->multi_param('ind_tag');
337
                my @serials      = $input->multi_param('serial');
249
            my @indicator = $input->multi_param('indicator');
338
                my @ind_tag   = $input->multi_param('ind_tag');
250
            my $item;
339
                my @indicator = $input->multi_param('indicator');
251
            push @{ $item->{tags} },         $tags[0];
340
                my $item;
252
            push @{ $item->{subfields} },    $subfields[0];
341
                push @{ $item->{tags} },         $tags[0];
253
            push @{ $item->{field_values} }, $field_values[0];
342
                push @{ $item->{subfields} },    $subfields[0];
254
            push @{ $item->{ind_tag} },      $ind_tag[0];
343
                push @{ $item->{field_values} }, $field_values[0];
255
            push @{ $item->{indicator} },    $indicator[0];
344
                push @{ $item->{ind_tag} },      $ind_tag[0];
256
            my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag );
345
                push @{ $item->{indicator} },    $indicator[0];
257
            my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
346
                my $xml = TransformHtmlToXml( \@tags, \@subfields, \@field_values, \@indicator, \@ind_tag );
258
            for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
347
                my $record = MARC::Record::new_from_xml( $xml, 'UTF-8' );
259
                my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
348
                for (my $qtyloop=1;$qtyloop <= $c_quantity;$qtyloop++) {
260
                $order->add_item( $itemnumber );
349
                    my ( $biblionumber, $bibitemnum, $itemnumber ) = AddItemFromMarc( $record, $biblionumber );
350
                    $order->add_item( $itemnumber );
351
                }
352
            } else {
353
                SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
261
            }
354
            }
262
        } else {
263
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
264
        }
355
        }
265
        $imported++;
356
        $imported++;
266
    }
357
    }
Lines 291-296 foreach my $r ( @{$budgets_hierarchy} ) { Link Here
291
    push @{$budget_loop},
382
    push @{$budget_loop},
292
      { b_id  => $r->{budget_id},
383
      { b_id  => $r->{budget_id},
293
        b_txt => $r->{budget_name},
384
        b_txt => $r->{budget_name},
385
        b_code => $r->{budget_code},
294
        b_sort1_authcat => $r->{'sort1_authcat'},
386
        b_sort1_authcat => $r->{'sort1_authcat'},
295
        b_sort2_authcat => $r->{'sort2_authcat'},
387
        b_sort2_authcat => $r->{'sort2_authcat'},
296
        b_active => $r->{budget_period_active},
388
        b_active => $r->{budget_period_active},
Lines 342-347 sub import_biblios_list { Link Here
342
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
434
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
343
    my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status});
435
    my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status});
344
    my @list = ();
436
    my @list = ();
437
    my $item_id = 1;
438
    my $item_error = 0;
439
440
    my $ccodes    = GetKohaAuthorisedValues("items.ccode");
441
    my $locations = GetKohaAuthorisedValues("items.location");
442
    # location list
443
    my @locations;
444
    foreach (sort keys %$locations) {
445
        push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
446
    }
447
    my @ccodes;
448
    foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
449
        push @ccodes, { code => $_, description => $ccodes->{$_} };
450
    }
451
452
345
453
346
    foreach my $biblio (@$biblios) {
454
    foreach my $biblio (@$biblios) {
347
        my $citation = $biblio->{'title'};
455
        my $citation = $biblio->{'title'};
Lines 365-371 sub import_biblios_list { Link Here
365
        );
473
        );
366
        my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} );
474
        my ( $marcblob, $encoding ) = GetImportRecordMarc( $biblio->{'import_record_id'} );
367
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
475
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
368
        my $infos = get_infos_syspref($marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
476
477
        my $infos = get_infos_syspref('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
369
        my $price = $infos->{price};
478
        my $price = $infos->{price};
370
        my $quantity = $infos->{quantity};
479
        my $quantity = $infos->{quantity};
371
        my $budget_code = $infos->{budget_code};
480
        my $budget_code = $infos->{budget_code};
Lines 379-397 sub import_biblios_list { Link Here
379
                $budget_id = $biblio_budget->{budget_id};
488
                $budget_id = $biblio_budget->{budget_id};
380
            }
489
            }
381
        }
490
        }
382
        $cellrecord{price} = $price || '';
383
        $cellrecord{quantity} = $quantity || '';
384
        $cellrecord{budget_id} = $budget_id || '';
385
        $cellrecord{discount} = $discount || '';
386
        $cellrecord{sort1} = $sort1 || '';
387
        $cellrecord{sort2} = $sort2 || '';
388
491
492
        # Items
493
        my @itemlist = ();
494
        my $all_items_quantity = 0;
495
        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']);
496
        if ($alliteminfos != -1) {
497
            foreach my $iteminfos (@$alliteminfos) {
498
                my $item_homebranch = $iteminfos->{homebranch};
499
                my $item_holdingbranch = $iteminfos->{holdingbranch};
500
                my $item_itype = $iteminfos->{itype};
501
                my $item_nonpublic_note = $iteminfos->{nonpublic_note};
502
                my $item_public_note = $iteminfos->{public_note};
503
                my $item_loc = $iteminfos->{loc};
504
                my $item_ccode = $iteminfos->{ccode};
505
                my $item_notforloan = $iteminfos->{notforloan};
506
                my $item_uri = $iteminfos->{uri};
507
                my $item_copyno = $iteminfos->{copyno};
508
                my $item_quantity = $iteminfos->{quantity} || 1;
509
                my $item_budget_code = $iteminfos->{budget_code};
510
                my $item_price = $iteminfos->{price};
511
512
                for (my $i = 0; $i < $item_quantity; $i++) {
513
514
                    my %itemrecord = (
515
                        'item_id' => $item_id++,
516
                        'homebranch' => $item_homebranch,
517
                        'holdingbranch' => $item_holdingbranch,
518
                        'itype' => $item_itype,
519
                        'nonpublic_note' => $item_nonpublic_note,
520
                        'public_note' => $item_public_note,
521
                        'loc' => $item_loc,
522
                        'ccode' => $item_ccode,
523
                        'notforloan' => $item_notforloan,
524
                        'uri' => $item_uri,
525
                        'copyno' => $item_copyno,
526
                        'quantity' => $item_quantity,
527
                        'budget_code' => $item_budget_code || $budget_code,
528
                        'itemprice' => $item_price || $price,
529
                    );
530
                    $all_items_quantity++;
531
                    push @itemlist, \%itemrecord;
532
533
                }
534
            }
535
536
            $cellrecord{'iteminfos'} = \@itemlist;
537
        } else {
538
            $item_error = 1;
539
        }
389
        push @list, \%cellrecord;
540
        push @list, \%cellrecord;
541
542
        if ($alliteminfos == -1 || scalar(@$alliteminfos) == 0) {
543
            $cellrecord{price} = $price || '';
544
            $cellrecord{quantity} = $quantity || '';
545
            $cellrecord{budget_id} = $budget_id || '';
546
            $cellrecord{discount} = $discount || '';
547
            $cellrecord{sort1} = $sort1 || '';
548
            $cellrecord{sort2} = $sort2 || '';
549
        } else {
550
            $cellrecord{quantity} = $all_items_quantity;
551
        }
552
390
    }
553
    }
391
    my $num_records = $batch->{'num_records'};
554
    my $num_records = $batch->{'num_records'};
392
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
555
    my $overlay_action = GetImportBatchOverlayAction($import_batch_id);
393
    my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
556
    my $nomatch_action = GetImportBatchNoMatchAction($import_batch_id);
394
    my $item_action = GetImportBatchItemAction($import_batch_id);
557
    my $item_action = GetImportBatchItemAction($import_batch_id);
558
    my @itypes = Koha::ItemTypes->search;
395
    $template->param(biblio_list => \@list,
559
    $template->param(biblio_list => \@list,
396
                        num_results => $num_records,
560
                        num_results => $num_records,
397
                        import_batch_id => $import_batch_id,
561
                        import_batch_id => $import_batch_id,
Lines 400-406 sub import_biblios_list { Link Here
400
                        "nomatch_action_${nomatch_action}" => 1,
564
                        "nomatch_action_${nomatch_action}" => 1,
401
                        nomatch_action => $nomatch_action,
565
                        nomatch_action => $nomatch_action,
402
                        "item_action_${item_action}" => 1,
566
                        "item_action_${item_action}" => 1,
403
                        item_action => $item_action
567
                        item_action => $item_action,
568
                        item_error => $item_error,
569
                        branchloop => GetBranchesLoop(),
570
                        locationloop => \@locations,
571
                        itypeloop => \@itypes,
572
                        ccodeloop => \@ccodes,
404
                    );
573
                    );
405
    batch_info($template, $batch);
574
    batch_info($template, $batch);
406
}
575
}
Lines 447-460 sub add_matcher_list { Link Here
447
}
616
}
448
617
449
sub get_infos_syspref {
618
sub get_infos_syspref {
450
    my ($record, $field_list) = @_;
619
    my ($syspref_name, $record, $field_list) = @_;
451
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
620
    my $syspref = C4::Context->preference($syspref_name);
452
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
621
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
453
    my $yaml = eval {
622
    my $yaml = eval {
454
        YAML::Load($syspref);
623
        YAML::Load($syspref);
455
    };
624
    };
456
    if ( $@ ) {
625
    if ( $@ ) {
457
        warn "Unable to parse MarcFieldsToOrder syspref : $@";
626
        warn "Unable to parse $syspref syspref : $@";
458
        return ();
627
        return ();
459
    }
628
    }
460
    my $r;
629
    my $r;
Lines 472-474 sub get_infos_syspref { Link Here
472
    }
641
    }
473
    return $r;
642
    return $r;
474
}
643
}
644
645
sub equal_number_of_fields {
646
    my ($tags_list, $record) = @_;
647
    my $refcount = 0;
648
    my $count = 0;
649
    for my $tag (@$tags_list) {
650
        return -1 if $count != $refcount;
651
        $count = 0;
652
        for my $field ($record->field($tag)) {
653
            $count++;
654
        }
655
        $refcount = $count if ($refcount == 0);
656
    }
657
    return -1 if $count != $refcount;
658
    return $count;
659
}
660
661
sub get_infos_syspref_on_item {
662
    my ($syspref_name, $record, $field_list) = @_;
663
    my $syspref = C4::Context->preference($syspref_name);
664
    $syspref = "$syspref\n\n"; # YAML is anal on ending \n. Surplus does not hurt
665
    my $yaml = eval {
666
        YAML::Load($syspref);
667
    };
668
    if ( $@ ) {
669
        warn "Unable to parse $syspref syspref : $@";
670
        return ();
671
    }
672
    my @result;
673
    my @tags_list;
674
675
    # Check tags in syspref definition
676
    for my $field_name ( @$field_list ) {
677
        next unless exists $yaml->{$field_name};
678
        my @fields = split /\|/, $yaml->{$field_name};
679
        for my $field ( @fields ) {
680
            my ( $f, $sf ) = split /\$/, $field;
681
            next unless $f and $sf;
682
            push @tags_list, $f;
683
        }
684
    }
685
    @tags_list = List::MoreUtils::uniq(@tags_list);
686
    
687
    my $tags_count = equal_number_of_fields(\@tags_list, $record);
688
    # Return if the number of theses fields in the record is not the same.
689
    return -1 if $tags_count == -1;
690
    
691
    # Gather the fields
692
    my $fields_hash;
693
    foreach my $tag (@tags_list) {
694
        my @tmp_fields;
695
        foreach my $field ($record->field($tag)) {
696
            push @tmp_fields, $field;    
697
        }
698
        $fields_hash->{$tag} = \@tmp_fields;
699
    }
700
    
701
    for (my $i = 0; $i < $tags_count; $i++) {
702
        my $r;
703
        for my $field_name ( @$field_list ) {
704
            next unless exists $yaml->{$field_name};
705
            my @fields = split /\|/, $yaml->{$field_name};
706
            for my $field ( @fields ) {
707
                my ( $f, $sf ) = split /\$/, $field;
708
                next unless $f and $sf;
709
                my $v = $fields_hash->{$f}[$i]->subfield( $sf );
710
                $r->{$field_name} = $v if (defined $v);
711
                last if $yaml->{$field};
712
            }
713
        }
714
        push @result, $r;
715
    }
716
    return \@result;
717
}
(-)a/installer/data/mysql/atomicupdate/Bug_15503_MarcItemFieldsToOrder.sql (+2 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');
2
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 231-236 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
231
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
231
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
232
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
232
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
233
('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'),
233
('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'),
234
('MarcItemFieldsToOrder','',NULL,'Set the mapping values for new item records created from a MARC record in a staged file. In a YAML format.','textarea'),
234
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
235
('MARCOrgCode','OSt','','Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html','free'),
235
('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'),
236
('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'),
236
('MaxItemsToDisplayForBatchDel','1000',NULL,'Display up to a given number of items in a single item deletionbatch.','Integer'),
237
('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