@@ -, +, @@ a/ no AV category, a MARC field not linked to AV category b/ no AV category, a MARC field linked to AV category c/ a AV category, no MARC field d/ a AV category, a MARC field not linked to AV category e/ a AV category, a MARC field linked to another AV category In case of (e), the additional AV category should be used, not the AV category linked to MARC field (supplier, basket, ...) additional fields, with authorised values dropdrown list for fields (c), (d) and (e) (check this is the right AV category for (e)) (d) and (e) correctly retrieved. line. check that values are correctly retrieved from biblio --- Koha/Template/Plugin/AuthorisedValues.pm | 5 + acqui/add_order_fields.pl | 123 +++++++++++++++ acqui/addorder.pl | 29 ++++ acqui/neworderempty.pl | 24 +++ .../prog/en/includes/acquisitions-menu.inc | 1 + .../prog/en/modules/acqui/add_order_fields.tt | 164 ++++++++++++++++++++ .../prog/en/modules/acqui/neworderempty.tt | 30 ++++ 7 files changed, 376 insertions(+) create mode 100755 acqui/add_order_fields.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt --- a/Koha/Template/Plugin/AuthorisedValues.pm +++ a/Koha/Template/Plugin/AuthorisedValues.pm @@ -43,4 +43,9 @@ sub GetByCode { return encode( 'UTF-8', GetAuthorisedValueByCode( $category, $code, $opac ) ); } +sub GetValues { + my ( $self, $category ) = @_; + return GetAuthorisedValues($category); +} + 1; --- a/acqui/add_order_fields.pl +++ a/acqui/add_order_fields.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2014 BibLibre +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, see . + +use Modern::Perl; +use CGI; +use C4::Auth; +use C4::Koha; +use C4::Output; +use Koha::AdditionalField; + +my $input = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "acqui/add_order_fields.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { acquisition => '*' }, + debug => 1, + } +); + +my $op = $input->param('op') // 'list'; +my $field_id = $input->param('field_id'); +my @messages; + +if ( $op eq 'add' ) { + my $name = $input->param('name') // q{}; + my $authorised_value_category = $input->param('authorised_value_category') // q{}; + my $marcfield = $input->param('marcfield') // q{}; + if ( $field_id and $name ) { + my $updated = 0; + eval { + my $af = Koha::AdditionalField->new({ + id => $field_id, + name => $name, + authorised_value_category => $authorised_value_category, + marcfield => $marcfield, + }); + $updated = $af->update; + }; + push @messages, { + code => 'update', + number => $updated, + }; + } elsif ( $name ) { + my $inserted = 0; + eval { + my $af = Koha::AdditionalField->new({ + tablename => 'aqorders', + name => $name, + authorised_value_category => $authorised_value_category, + marcfield => $marcfield, + }); + $inserted = $af->insert; + }; + push @messages, { + code => 'insert', + number => $inserted, + }; + } else { + push @messages, { + code => 'insert', + number => 0, + }; + } + $op = 'list'; +} + +if ( $op eq 'delete' ) { + my $deleted = 0; + eval { + my $af = Koha::AdditionalField->new( { id => $field_id } ); + $deleted = $af->delete; + $deleted = 0 if $deleted eq '0E0'; + }; + push @messages, { + code => 'delete', + number => $deleted, + }; + $op = 'list'; +} + +if ( $op eq 'add_form' ) { + my $categories = C4::Koha::GetAuthorisedValueCategories(); + my $field; + if ( $field_id ) { + $field = Koha::AdditionalField->new( { id => $field_id } )->fetch; + } + + $template->param( + field => $field, + categories => $categories, + ); +} + +if ( $op eq 'list' ) { + my $fields = Koha::AdditionalField->all( { tablename => 'aqorders' } ); + $template->param( fields => $fields ); +} + +$template->param( + op => $op, + messages => \@messages, +); + +output_html_with_http_headers $input, $cookie, $template->output; --- a/acqui/addorder.pl +++ a/acqui/addorder.pl @@ -130,6 +130,8 @@ use C4::Budgets; use C4::Items; use C4::Output; +use Koha::AdditionalField; + ### "-------------------- addorder.pl ----------" # FIXME: This needs to do actual error checking and possibly return user to the same form, @@ -278,6 +280,33 @@ if ( $orderinfo->{quantity} ne '0' ) { @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo); } + # Retrieve and save additional fields values + my $record = GetMarcBiblio($orderinfo->{biblionumber}); + my $record_updated = 0; + my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'}); + foreach my $af (@$additional_fields) { + my $id = $af->{id}; + my $value = $input->param("additional_field_$id"); + $af->{values}->{$orderinfo->{ordernumber}} = $value; + $af->insert_values; + + # Save value in biblio record, if marcfield is set + if ($af->{marcfield}) { + my ($fieldtag, $subfieldtag) = split /\$/, $af->{marcfield}; + my $field = $record->field($fieldtag); + if ($field) { + $field->update($subfieldtag => $value); + } else { + $field = new MARC::Field($fieldtag, '', '', $subfieldtag => $value); + $record->append_fields($field); + } + $record_updated = 1; + } + } + if ($record_updated) { + ModBiblio($record, $orderinfo->{biblionumber}); + } + # now, add items if applicable if (C4::Context->preference('AcqCreateItem') eq 'ordering') { --- a/acqui/neworderempty.pl +++ a/acqui/neworderempty.pl @@ -91,6 +91,8 @@ use C4::Search qw/FindDuplicate/; #needed for z3950 import: use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; +use Koha::AdditionalField; + our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! my $budget_id = $input->param('budget_id') || 0; @@ -346,6 +348,28 @@ if ( defined $subscriptionid ) { # Find the items.barcode subfield for barcode validations my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', ''); +# Get additional fields +my $record; +my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'}); +foreach my $af (@$additional_fields) { + if (!$af->{authorised_value_category} && $af->{marcfield}) { + # Try to retrieve authorised values category from MARC framework + my ($field, $subfield) = split /\$/, $af->{marcfield}; + my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield); + if ($category) { + $af->{authorised_value_category} = $category; + } + } + if ($ordernumber) { + $af->fetch_values({record_id => $ordernumber}); + } elsif ($biblionumber && $af->{marcfield}) { + $record //= GetMarcBiblio($biblionumber); + my ($field, $subfield) = split /\$/, $af->{marcfield}; + $af->{values}->{'new'} = $record->subfield($field, $subfield); + } +} +$template->param(additional_fields => $additional_fields); + # fill template $template->param( close => $close, --- a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc @@ -9,4 +9,5 @@ [% IF ( CAN_user_parameters ) %]
  • Currencies
  • [% END %] +
  • Add order line fields
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt @@ -0,0 +1,164 @@ +[% INCLUDE 'doc-head-open.inc' %] +Koha › Acquisitions › Manage new fields for order lines + [% IF op == "list" %] › List of fields + [% ELSIF op == "add_form" %] + [% IF field %] › Modify field + [% ELSE %] › Add field + [% END %] + [% END %] + +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE "datatables.inc" %] + + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'acquisitions-search.inc' %] + + + +
    +
    +
    +
    + [% IF op == 'list' %] + + [% END %] + + [% IF messages %] + [% FOR message IN messages %] + [% IF message.code == 'insert' %] + [% IF message.number > 0 %] +
    The field has been inserted
    + [% ELSE %] +
    The field has not been inserted (name still exist?)
    + [% END %] + [% ELSIF message.code == 'update' %] + [% IF message.number > 0 %] +
    The field has been updated
    + [% ELSE %] +
    The field has not been updated (name still exist?)
    + [% END %] + [% ELSIF message.code == 'delete' %] + [% IF message.number > 0 %] +
    The field has been deleted
    + [% ELSE %] +
    The field has not been deleted
    + [% END %] + [% END %] + [% END %] + [% END %] + + [% IF op == 'list' %] +

    Additional fields for order lines

    + [% IF fields %] + + + + + + + + + + + [% FOR field IN fields %] + + + + + + + [% END %] + +
    NameAuthorised value categoryMarc fieldActions
    [% field.name %][% field.authorised_value_category %][% field.marcfield %] + Edit + Delete +
    + [% ELSE %] + There is no field defined. + [% END %] + [% ELSIF op == 'add_form' %] + [% IF field %] +

    Modify field

    + [% ELSE %] +

    Add field

    + [% END %] +
    +
    +
      +
    1. + + +
    2. +
    3. + + +
    4. +
    5. + + +
    6. +
    +
    +
    + [% IF field %] + + [% END %] + + + Cancel +
    +
    + [% END %] + +
    +
    + +
    +[% INCLUDE 'acquisitions-menu.inc' %] +
    +
    +[% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -1,4 +1,5 @@ [% USE KohaDates %] +[% USE AuthorisedValues %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › Basket [% basketno %] › [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -574,6 +575,35 @@ $(document).ready(function() [% END %] + [% FOREACH af IN additional_fields %] +
  • + + [% value = '' %] + [% IF ordernumber %] + [% value = af.values.$ordernumber %] + [% ELSE %] + [% value = af.values.new %] + [% END %] + [% authorised_values = [] %] + [% IF af.authorised_value_category %] + [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %] + [% END %] + [% IF authorised_values.size > 0 %] + + [% ELSE %] + + [% END %] +
  • + [% END %]
    --