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

(-)a/Koha/Template/Plugin/AuthorisedValues.pm (+7 lines)
Lines 38-43 sub GetAuthValueDropbox { Link Here
38
    return C4::Koha::GetAuthvalueDropbox($category, $default);
38
    return C4::Koha::GetAuthvalueDropbox($category, $default);
39
}
39
}
40
40
41
sub GetValues {
42
    my ( $self, $category ) = @_;
43
    return GetAuthorisedValues($category);
44
}
45
41
1;
46
1;
42
47
43
=head1 NAME
48
=head1 NAME
Lines 77-79 Kyle M Hall <kyle@bywatersolutions.com> Link Here
77
Jonathan Druart <jonathan.druart@biblibre.com>
82
Jonathan Druart <jonathan.druart@biblibre.com>
78
83
79
=cut
84
=cut
85
86
1;
(-)a/acqui/add_order_fields.pl (+123 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2014 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use CGI;
21
use C4::Auth;
22
use C4::Koha;
23
use C4::Output;
24
use Koha::AdditionalField;
25
26
my $input = new CGI;
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
30
        template_name   => "acqui/add_order_fields.tt",
31
        query           => $input,
32
        type            => "intranet",
33
        authnotrequired => 0,
34
        flagsrequired   => { acquisition => '*' },
35
        debug           => 1,
36
    }
37
);
38
39
my $op = $input->param('op') // 'list';
40
my $field_id = $input->param('field_id');
41
my @messages;
42
43
if ( $op eq 'add' ) {
44
    my $name = $input->param('name') // q{};
45
    my $authorised_value_category = $input->param('authorised_value_category') // q{};
46
    my $marcfield = $input->param('marcfield') // q{};
47
    if ( $field_id and $name ) {
48
        my $updated = 0;
49
        eval {
50
            my $af = Koha::AdditionalField->new({
51
                id => $field_id,
52
                name => $name,
53
                authorised_value_category => $authorised_value_category,
54
                marcfield => $marcfield,
55
            });
56
            $updated = $af->update;
57
        };
58
        push @messages, {
59
            code => 'update',
60
            number => $updated,
61
        };
62
    } elsif ( $name ) {
63
        my $inserted = 0;
64
        eval {
65
            my $af = Koha::AdditionalField->new({
66
                tablename => 'aqorders',
67
                name => $name,
68
                authorised_value_category => $authorised_value_category,
69
                marcfield => $marcfield,
70
            });
71
            $inserted = $af->insert;
72
        };
73
        push @messages, {
74
            code => 'insert',
75
            number => $inserted,
76
        };
77
    } else {
78
        push @messages, {
79
            code => 'insert',
80
            number => 0,
81
        };
82
    }
83
    $op = 'list';
84
}
85
86
if ( $op eq 'delete' ) {
87
    my $deleted = 0;
88
    eval {
89
        my $af = Koha::AdditionalField->new( { id => $field_id } );
90
        $deleted = $af->delete;
91
        $deleted = 0 if $deleted eq '0E0';
92
    };
93
    push @messages, {
94
        code => 'delete',
95
        number => $deleted,
96
    };
97
    $op = 'list';
98
}
99
100
if ( $op eq 'add_form' ) {
101
    my $categories = C4::Koha::GetAuthorisedValueCategories();
102
    my $field;
103
    if ( $field_id ) {
104
        $field = Koha::AdditionalField->new( { id => $field_id } )->fetch;
105
    }
106
107
    $template->param(
108
        field => $field,
109
        categories => $categories,
110
    );
111
}
112
113
if ( $op eq 'list' ) {
114
    my $fields = Koha::AdditionalField->all( { tablename => 'aqorders' } );
115
    $template->param( fields => $fields );
116
}
117
118
$template->param(
119
    op => $op,
120
    messages => \@messages,
121
);
122
123
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/acqui/addorder.pl (+29 lines)
Lines 131-136 use C4::Items; Link Here
131
use C4::Output;
131
use C4::Output;
132
use Koha::Acquisition::Currencies;
132
use Koha::Acquisition::Currencies;
133
133
134
use Koha::AdditionalField;
135
134
### "-------------------- addorder.pl ----------"
136
### "-------------------- addorder.pl ----------"
135
137
136
# FIXME: This needs to do actual error checking and possibly return user to the same form,
138
# FIXME: This needs to do actual error checking and possibly return user to the same form,
Lines 280-285 if ( $basket->{is_standing} || $orderinfo->{quantity} ne '0' ) { Link Here
280
        $order->insert;
282
        $order->insert;
281
    }
283
    }
282
284
285
    # Retrieve and save additional fields values
286
    my $record = GetMarcBiblio($orderinfo->{biblionumber});
287
    my $record_updated = 0;
288
    my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
289
    foreach my $af (@$additional_fields) {
290
        my $id = $af->{id};
291
        my $value = $input->param("additional_field_$id");
292
        $af->{values}->{$orderinfo->{ordernumber}} = $value;
293
        $af->insert_values;
294
295
        # Save value in biblio record, if marcfield is set
296
        if ($af->{marcfield}) {
297
            my ($fieldtag, $subfieldtag) = split /\$/, $af->{marcfield};
298
            my $field = $record->field($fieldtag);
299
            if ($field) {
300
                $field->update($subfieldtag => $value);
301
            } else {
302
                $field = new MARC::Field($fieldtag, '', '', $subfieldtag => $value);
303
                $record->append_fields($field);
304
            }
305
            $record_updated = 1;
306
        }
307
    }
308
    if ($record_updated) {
309
        ModBiblio($record, $orderinfo->{biblionumber});
310
    }
311
283
    # now, add items if applicable
312
    # now, add items if applicable
284
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
313
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
285
314
(-)a/acqui/neworderempty.pl (-14 / +33 lines)
Lines 66-96 the item's id in the breeding reservoir Link Here
66
66
67
=cut
67
=cut
68
68
69
use warnings;
69
use Modern::Perl;
70
use strict;
70
71
use CGI qw ( -utf8 );
71
use CGI qw ( -utf8 );
72
use C4::Context;
73
72
73
use C4::Acquisition;
74
use C4::Auth;
74
use C4::Auth;
75
use C4::Biblio;    # GetBiblioData GetMarcPrice
76
use C4::Branch;    # GetBranches
75
use C4::Budgets;
77
use C4::Budgets;
76
78
use C4::Context;
77
use C4::Acquisition;
78
use C4::Contract;
79
use C4::Contract;
79
use C4::Suggestions;	# GetSuggestion
80
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;    #needed for z3950 import:
80
use C4::Biblio;			# GetBiblioData GetMarcPrice
81
use C4::Items;                                                        #PrepareItemRecord
81
use C4::Items; #PrepareItemRecord
82
use C4::Output;
83
use C4::Koha;
82
use C4::Koha;
84
use C4::Branch;			# GetBranches
85
use C4::Members;
83
use C4::Members;
84
use C4::Output;
85
use C4::Suggestions;                                                  # GetSuggestion
86
use C4::Search qw/FindDuplicate/;
86
use C4::Search qw/FindDuplicate/;
87
88
#needed for z3950 import:
89
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
90
91
use Koha::Acquisition::Bookseller;
87
use Koha::Acquisition::Bookseller;
92
use Koha::Acquisition::Currencies;
88
use Koha::Acquisition::Currencies;
93
use Koha::ItemTypes;
89
use Koha::ItemTypes;
90
use Koha::AdditionalField;
94
91
95
our $input           = new CGI;
92
our $input           = new CGI;
96
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
93
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
Lines 302-307 if ( defined $subscriptionid ) { Link Here
302
# Find the items.barcode subfield for barcode validations
299
# Find the items.barcode subfield for barcode validations
303
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
300
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
304
301
302
# Get additional fields
303
my $record;
304
my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
305
foreach my $af (@$additional_fields) {
306
    if (!$af->{authorised_value_category} && $af->{marcfield}) {
307
        # Try to retrieve authorised values category from MARC framework
308
        my ($field, $subfield) = split /\$/, $af->{marcfield};
309
        my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield);
310
        if ($category) {
311
            $af->{authorised_value_category} = $category;
312
        }
313
    }
314
    if ($ordernumber) {
315
        $af->fetch_values({record_id => $ordernumber});
316
    } elsif ($biblionumber && $af->{marcfield}) {
317
        $record //= GetMarcBiblio($biblionumber);
318
        my ($field, $subfield) = split /\$/, $af->{marcfield};
319
        $af->{values}->{'new'} = $record->subfield($field, $subfield);
320
    }
321
}
322
$template->param(additional_fields => $additional_fields);
323
305
# fill template
324
# fill template
306
$template->param(
325
$template->param(
307
    close        => $close,
326
    close        => $close,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_order_fields.tt (+165 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Acquisitions &rsaquo; Manage new fields for order lines
3
  [% IF op == "list" %] &rsaquo; List of fields
4
  [% ELSIF op == "add_form" %]
5
    [% IF field %] &rsaquo; Modify field
6
    [% ELSE %] &rsaquo; Add field
7
    [% END %]
8
  [% END %]
9
</title>
10
[% INCLUDE 'doc-head-close.inc' %]
11
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
12
[% INCLUDE "datatables.inc" %]
13
<script type="text/javascript">
14
//<![CDATA[
15
  $(document).ready(function(){
16
17
    $("#fieldst").dataTable($.extend(true, {}, dataTablesDefaults, {
18
        'bAutoWidth': false,
19
        'sDom': 't<"bottom pager"ilpf>',
20
        'sPaginationType': 'four_button',
21
        'aLengthMenu': [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
22
        'iDisplayLength': 20,
23
        'aaSorting': [[ 0, "asc" ]],
24
    }));
25
26
    $(".confirmdelete").click(function(){
27
      return confirm(_("Are you sure you want to delete this field?"));
28
    });
29
30
    $("#add_field").on('submit', function(){
31
        if ( $("#marcfield").val().length > 0
32
            && $("select[name='authorised_value_category']" ).val().length > 0 ) {
33
            alert("You cannot select an authorised value category and a marcfield");
34
            return false;
35
        }
36
        return true;
37
    });
38
  });
39
//]]>
40
</script>
41
</head>
42
43
<body id="acq_add_fields" class="acq">
44
  [% INCLUDE 'header.inc' %]
45
  [% INCLUDE 'acquisitions-search.inc' %]
46
47
  <div id="breadcrumbs">
48
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/acqui/acqui-home.pl">Acquisitions</a> &rsaquo; Manage new fields for order lines
49
  </div>
50
51
  <div id="doc3" class="yui-t2">
52
  <div id="bd">
53
  <div id="yui-main">
54
  <div class="yui-b">
55
  [% IF op == 'list' %]
56
    <div id="toolbar" class="btn-toolbar">
57
      <a class="btn btn-small" id="newfields" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form"><i class="icon-plus"></i> New field</a>
58
    </div>
59
  [% END %]
60
61
  [% IF messages %]
62
    [% FOR message IN messages %]
63
      [% IF message.code == 'insert' %]
64
        [% IF message.number > 0 %]
65
          <div class="dialog message">The field has been inserted</div>
66
        [% ELSE %]
67
          <div class="dialog alert">The field has not been inserted (name still exist?)</div>
68
        [% END %]
69
      [% ELSIF message.code == 'update' %]
70
        [% IF message.number > 0 %]
71
          <div class="dialog message">The field has been updated</div>
72
        [% ELSE %]
73
          <div class="dialog alert">The field has not been updated (name still exist?)</div>
74
        [% END %]
75
      [% ELSIF message.code == 'delete' %]
76
        [% IF message.number > 0 %]
77
          <div class="dialog message">The field has been deleted</div>
78
        [% ELSE %]
79
          <div class="dialog alert">The field has not been deleted</div>
80
        [% END %]
81
      [% END %]
82
    [% END %]
83
  [% END %]
84
85
  [% IF op == 'list' %]
86
    <h3>Additional fields for order lines</h3>
87
    [% IF fields %]
88
      <table id="fieldst">
89
        <thead>
90
          <tr>
91
            <th>Name</th>
92
            <th>Authorised value category</th>
93
            <th>MARC field</th>
94
            <th>Actions</th>
95
          </tr>
96
        </thead>
97
        <tbody>
98
          [% FOR field IN fields %]
99
            <tr>
100
              <td>[% field.name %]</td>
101
              <td>[% field.authorised_value_category %]</td>
102
              <td>[% field.marcfield %]</td>
103
              <td>
104
                <a href="/cgi-bin/koha/acqui/add_order_fields.pl?op=add_form&amp;field_id=[% field.id %]" title="Edit this field">Edit</a>
105
                <a class="confirmdelete" href="/cgi-bin/koha/acqui/add_order_fields.pl?op=delete&amp;field_id=[% field.id %]" title="Delete this field">Delete</a>
106
              </td>
107
            </tr>
108
          [% END %]
109
        </tbody>
110
      </table>
111
    [% ELSE %]
112
      There is no field defined.
113
    [% END %]
114
  [% ELSIF op == 'add_form' %]
115
    [% IF field %]
116
      <h3>Modify field</h3>
117
    [% ELSE %]
118
      <h3>Add field</h3>
119
    [% END %]
120
    <form action="/cgi-bin/koha/acqui/add_order_fields.pl" name="add_form" id="add_field" method="post">
121
      <fieldset class="rows">
122
        <ol>
123
          <li>
124
            <label for="name" class="required">Name: </label>
125
            <input type="text" name="name" id="name" value="[% field.name | html %]" />
126
          </li>
127
          <li>
128
            <label for="av">Authorised value category: </label>
129
            <select name="authorised_value_category">
130
              <option value="">None</option>
131
              [% FOR category IN categories %]
132
                [% IF field.authorised_value_category == category %]
133
                  <option value="[% category %]" selected="selected">[% category %]</option>
134
                [% ELSE %]
135
                  <option value="[% category %]">[% category %]</option>
136
                [% END %]
137
              [% END %]
138
            </select>
139
          </li>
140
          <li>
141
            <label for="marcfield">MARC field: </label>
142
            <input type="text" name="marcfield" id="marcfield" value="[% field.marcfield| html %]" />
143
            <span class="hint">Use this syntax: XXX$y</span>
144
          </li>
145
        </ol>
146
      </fieldset>
147
      <fieldset class="action">
148
        [% IF field %]
149
          <input type="hidden" name="field_id" value="[% field.id %]" />
150
        [% END %]
151
        <input type="hidden" name="op" value="add" />
152
        <input type="submit" value="Save" />
153
        <a href="/cgi-bin/koha/acqui/add_order_fields.pl" class="cancel">Cancel</a>
154
      </fieldset>
155
    </form>
156
  [% END %]
157
158
  </div>
159
  </div>
160
161
<div class="yui-b">
162
[% INCLUDE 'acquisitions-menu.inc' %]
163
</div>
164
</div>
165
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +30 lines)
Lines 1-4 Link Here
1
[% USE KohaDates %]
1
[% USE KohaDates %]
2
[% USE AuthorisedValues %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Acquisitions &rsaquo; Basket [% basketno %] &rsaquo; [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %]</title>
4
<title>Koha &rsaquo; Acquisitions &rsaquo; Basket [% basketno %] &rsaquo; [% IF ( ordernumber ) %]Modify order details (line #[% ordernumber %])[% ELSE %]New order[% END %]</title>
4
[% INCLUDE 'doc-head-close.inc' %]
5
[% INCLUDE 'doc-head-close.inc' %]
Lines 630-635 $(document).ready(function() Link Here
630
                <label for="sort2">Statistic 2: </label>
631
                <label for="sort2">Statistic 2: </label>
631
                <input id="sort2" type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
632
                <input id="sort2" type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
632
            </li>
633
            </li>
634
            [% FOREACH af IN additional_fields %]
635
              <li>
636
                <label for="additional_field_[% af.id %]">[% af.name %]</label>
637
                [% value = '' %]
638
                [% IF ordernumber %]
639
                  [% value = af.values.$ordernumber %]
640
                [% ELSE %]
641
                  [% value = af.values.new %]
642
                [% END %]
643
                [% authorised_values = [] %]
644
                [% IF af.authorised_value_category %]
645
                  [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %]
646
                [% END %]
647
                [% IF authorised_values.size > 0 %]
648
                  <select name="additional_field_[% af.id %]" id="additional_field_[% af.id %]">
649
                    <option value=""></option>
650
                    [% FOREACH av IN authorised_values %]
651
                      [% IF value == av.authorised_value %]
652
                        <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option>
653
                      [% ELSE %]
654
                        <option value="[% av.authorised_value %]">[% av.lib %]</option>
655
                      [% END %]
656
                    [% END %]
657
                  </select>
658
                [% ELSE %]
659
                  <input type="text" name="additional_field_[% af.id %]" id="additional_field_[% af.id %]" value="[% value %]" />
660
                [% END %]
661
              </li>
662
            [% END %]
633
        </ol>
663
        </ol>
634
    </fieldset>
664
    </fieldset>
635
    <fieldset class="action">
665
    <fieldset class="action">
636
- 

Return to bug 11844