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 130-135 use C4::Budgets; Link Here
130
use C4::Items;
130
use C4::Items;
131
use C4::Output;
131
use C4::Output;
132
132
133
use Koha::AdditionalField;
134
133
### "-------------------- addorder.pl ----------"
135
### "-------------------- addorder.pl ----------"
134
136
135
# FIXME: This needs to do actual error checking and possibly return user to the same form,
137
# FIXME: This needs to do actual error checking and possibly return user to the same form,
Lines 276-281 if ( $orderinfo->{quantity} ne '0' ) { Link Here
276
        $order->insert;
278
        $order->insert;
277
    }
279
    }
278
280
281
    # Retrieve and save additional fields values
282
    my $record = GetMarcBiblio($orderinfo->{biblionumber});
283
    my $record_updated = 0;
284
    my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
285
    foreach my $af (@$additional_fields) {
286
        my $id = $af->{id};
287
        my $value = $input->param("additional_field_$id");
288
        $af->{values}->{$orderinfo->{ordernumber}} = $value;
289
        $af->insert_values;
290
291
        # Save value in biblio record, if marcfield is set
292
        if ($af->{marcfield}) {
293
            my ($fieldtag, $subfieldtag) = split /\$/, $af->{marcfield};
294
            my $field = $record->field($fieldtag);
295
            if ($field) {
296
                $field->update($subfieldtag => $value);
297
            } else {
298
                $field = new MARC::Field($fieldtag, '', '', $subfieldtag => $value);
299
                $record->append_fields($field);
300
            }
301
            $record_updated = 1;
302
        }
303
    }
304
    if ($record_updated) {
305
        ModBiblio($record, $orderinfo->{biblionumber});
306
    }
307
279
    # now, add items if applicable
308
    # now, add items if applicable
280
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
309
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
281
310
(-)a/acqui/neworderempty.pl (-14 / +33 lines)
Lines 66-94 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;
88
use Koha::AdditionalField;
92
89
93
our $input           = new CGI;
90
our $input           = new CGI;
94
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
91
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
Lines 329-334 if ( defined $subscriptionid ) { Link Here
329
# Find the items.barcode subfield for barcode validations
326
# Find the items.barcode subfield for barcode validations
330
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
327
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
331
328
329
# Get additional fields
330
my $record;
331
my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
332
foreach my $af (@$additional_fields) {
333
    if (!$af->{authorised_value_category} && $af->{marcfield}) {
334
        # Try to retrieve authorised values category from MARC framework
335
        my ($field, $subfield) = split /\$/, $af->{marcfield};
336
        my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield);
337
        if ($category) {
338
            $af->{authorised_value_category} = $category;
339
        }
340
    }
341
    if ($ordernumber) {
342
        $af->fetch_values({record_id => $ordernumber});
343
    } elsif ($biblionumber && $af->{marcfield}) {
344
        $record //= GetMarcBiblio($biblionumber);
345
        my ($field, $subfield) = split /\$/, $af->{marcfield};
346
        $af->{values}->{'new'} = $record->subfield($field, $subfield);
347
    }
348
}
349
$template->param(additional_fields => $additional_fields);
350
332
# fill template
351
# fill template
333
$template->param(
352
$template->param(
334
    close        => $close,
353
    close        => $close,
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-menu.inc (+1 lines)
Lines 9-12 Link Here
9
    [% IF ( CAN_user_parameters ) %]
9
    [% IF ( CAN_user_parameters ) %]
10
     <li><a href="/cgi-bin/koha/admin/currency.pl">Currencies</a></li>
10
     <li><a href="/cgi-bin/koha/admin/currency.pl">Currencies</a></li>
11
    [% END %]
11
    [% END %]
12
    <li><a href="/cgi-bin/koha/acqui/add_order_fields.pl">Add order line fields</a></li>
12
</ul>
13
</ul>
(-)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 625-630 $(document).ready(function() Link Here
625
                <label for="sort2">Statistic 2: </label>
626
                <label for="sort2">Statistic 2: </label>
626
                <input id="sort2" type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
627
                <input id="sort2" type="text" id="sort2" size="20" name="sort2" value="[% sort2 %]" />
627
            </li>
628
            </li>
629
            [% FOREACH af IN additional_fields %]
630
              <li>
631
                <label for="additional_field_[% af.id %]">[% af.name %]</label>
632
                [% value = '' %]
633
                [% IF ordernumber %]
634
                  [% value = af.values.$ordernumber %]
635
                [% ELSE %]
636
                  [% value = af.values.new %]
637
                [% END %]
638
                [% authorised_values = [] %]
639
                [% IF af.authorised_value_category %]
640
                  [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %]
641
                [% END %]
642
                [% IF authorised_values.size > 0 %]
643
                  <select name="additional_field_[% af.id %]" id="additional_field_[% af.id %]">
644
                    <option value=""></option>
645
                    [% FOREACH av IN authorised_values %]
646
                      [% IF value == av.authorised_value %]
647
                        <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option>
648
                      [% ELSE %]
649
                        <option value="[% av.authorised_value %]">[% av.lib %]</option>
650
                      [% END %]
651
                    [% END %]
652
                  </select>
653
                [% ELSE %]
654
                  <input type="text" name="additional_field_[% af.id %]" id="additional_field_[% af.id %]" value="[% value %]" />
655
                [% END %]
656
              </li>
657
            [% END %]
628
        </ol>
658
        </ol>
629
    </fieldset>
659
    </fieldset>
630
    <fieldset class="action">
660
    <fieldset class="action">
631
- 

Return to bug 11844