@@ -, +, @@ 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 | 7 + acqui/add_order_fields.pl | 123 +++++++++++++++ acqui/addorder.pl | 29 ++++ acqui/neworderempty.pl | 47 ++++-- .../prog/en/includes/acquisitions-menu.inc | 1 + .../prog/en/modules/acqui/add_order_fields.tt | 165 ++++++++++++++++++++ .../prog/en/modules/acqui/neworderempty.tt | 30 ++++ 7 files changed, 388 insertions(+), 14 deletions(-) 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 @@ -38,6 +38,11 @@ sub GetAuthValueDropbox { return C4::Koha::GetAuthvalueDropbox($category, $default); } +sub GetValues { + my ( $self, $category ) = @_; + return GetAuthorisedValues($category); +} + 1; =head1 NAME @@ -77,3 +82,5 @@ Kyle M Hall Jonathan Druart =cut + +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, @@ -276,6 +278,33 @@ if ( $orderinfo->{quantity} ne '0' ) { $order->insert; } + # 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 @@ -66,29 +66,26 @@ the item's id in the breeding reservoir =cut -use warnings; -use strict; +use Modern::Perl; + use CGI qw ( -utf8 ); -use C4::Context; +use C4::Acquisition; use C4::Auth; +use C4::Biblio; # GetBiblioData GetMarcPrice +use C4::Branch; # GetBranches use C4::Budgets; - -use C4::Acquisition; +use C4::Context; use C4::Contract; -use C4::Suggestions; # GetSuggestion -use C4::Biblio; # GetBiblioData GetMarcPrice -use C4::Items; #PrepareItemRecord -use C4::Output; +use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; #needed for z3950 import: +use C4::Items; #PrepareItemRecord use C4::Koha; -use C4::Branch; # GetBranches use C4::Members; +use C4::Output; +use C4::Suggestions; # GetSuggestion use C4::Search qw/FindDuplicate/; - -#needed for z3950 import: -use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/; - use Koha::Acquisition::Bookseller; +use Koha::AdditionalField; our $input = new CGI; my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! @@ -329,6 +326,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,165 @@ +[% 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. + + + Use this syntax: XXX$y +
    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' %] @@ -625,6 +626,35 @@ $(document).ready(function() + [% 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 %]
    --