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

(-)a/Koha/Template/Plugin/AuthorisedValues.pm (+5 lines)
Lines 43-46 sub GetByCode { Link Here
43
    return encode( 'UTF-8', GetAuthorisedValueByCode( $category, $code, $opac ) );
43
    return encode( 'UTF-8', GetAuthorisedValueByCode( $category, $code, $opac ) );
44
}
44
}
45
45
46
sub GetValues {
47
    my ( $self, $category ) = @_;
48
    return GetAuthorisedValues($category);
49
}
50
46
1;
51
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 278-283 if ( $orderinfo->{quantity} ne '0' ) { Link Here
278
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
280
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
279
    }
281
    }
280
282
283
    # Retrieve and save additional fields values
284
    my $record = GetMarcBiblio($orderinfo->{biblionumber});
285
    my $record_updated = 0;
286
    my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
287
    foreach my $af (@$additional_fields) {
288
        my $id = $af->{id};
289
        my $value = $input->param("additional_field_$id");
290
        $af->{values}->{$orderinfo->{ordernumber}} = $value;
291
        $af->insert_values;
292
293
        # Save value in biblio record, if marcfield is set
294
        if ($af->{marcfield}) {
295
            my ($fieldtag, $subfieldtag) = split /\$/, $af->{marcfield};
296
            my $field = $record->field($fieldtag);
297
            if ($field) {
298
                $field->update($subfieldtag => $value);
299
            } else {
300
                $field = new MARC::Field($fieldtag, '', '', $subfieldtag => $value);
301
                $record->append_fields($field);
302
            }
303
            $record_updated = 1;
304
        }
305
    }
306
    if ($record_updated) {
307
        ModBiblio($record, $orderinfo->{biblionumber});
308
    }
309
281
    # now, add items if applicable
310
    # now, add items if applicable
282
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
311
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
283
312
(-)a/acqui/neworderempty.pl (+24 lines)
Lines 91-96 use C4::Search qw/FindDuplicate/; Link Here
91
#needed for z3950 import:
91
#needed for z3950 import:
92
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
92
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
93
93
94
use Koha::AdditionalField;
95
94
our $input           = new CGI;
96
our $input           = new CGI;
95
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
97
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
96
my $budget_id       = $input->param('budget_id') || 0;
98
my $budget_id       = $input->param('budget_id') || 0;
Lines 346-351 if ( defined $subscriptionid ) { Link Here
346
# Find the items.barcode subfield for barcode validations
348
# Find the items.barcode subfield for barcode validations
347
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
349
my (undef, $barcode_subfield) = GetMarcFromKohaField('items.barcode', '');
348
350
351
# Get additional fields
352
my $record;
353
my $additional_fields = Koha::AdditionalField->all({tablename => 'aqorders'});
354
foreach my $af (@$additional_fields) {
355
    if (!$af->{authorised_value_category} && $af->{marcfield}) {
356
        # Try to retrieve authorised values category from MARC framework
357
        my ($field, $subfield) = split /\$/, $af->{marcfield};
358
        my $category = C4::Koha::GetAuthValCodeFromField($field, $subfield);
359
        if ($category) {
360
            $af->{authorised_value_category} = $category;
361
        }
362
    }
363
    if ($ordernumber) {
364
        $af->fetch_values({record_id => $ordernumber});
365
    } elsif ($biblionumber && $af->{marcfield}) {
366
        $record //= GetMarcBiblio($biblionumber);
367
        my ($field, $subfield) = split /\$/, $af->{marcfield};
368
        $af->{values}->{'new'} = $record->subfield($field, $subfield);
369
    }
370
}
371
$template->param(additional_fields => $additional_fields);
372
349
# fill template
373
# fill template
350
$template->param(
374
$template->param(
351
    close        => $close,
375
    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 (+164 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
          </li>
144
        </ol>
145
      </fieldset>
146
      <fieldset class="action">
147
        [% IF field %]
148
          <input type="hidden" name="field_id" value="[% field.id %]" />
149
        [% END %]
150
        <input type="hidden" name="op" value="add" />
151
        <input type="submit" value="Save" />
152
        <a href="/cgi-bin/koha/acqui/add_order_fields.pl" class="cancel">Cancel</a>
153
      </fieldset>
154
    </form>
155
  [% END %]
156
157
  </div>
158
  </div>
159
160
<div class="yui-b">
161
[% INCLUDE 'acquisitions-menu.inc' %]
162
</div>
163
</div>
164
[% 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 574-579 $(document).ready(function() Link Here
574
                [% END %]
575
                [% END %]
575
                </span>
576
                </span>
576
            </li>
577
            </li>
578
            [% FOREACH af IN additional_fields %]
579
              <li>
580
                <label for="additional_field_[% af.id %]">[% af.name %]</label>
581
                [% value = '' %]
582
                [% IF ordernumber %]
583
                  [% value = af.values.$ordernumber %]
584
                [% ELSE %]
585
                  [% value = af.values.new %]
586
                [% END %]
587
                [% authorised_values = [] %]
588
                [% IF af.authorised_value_category %]
589
                  [% authorised_values = AuthorisedValues.GetValues(af.authorised_value_category) %]
590
                [% END %]
591
                [% IF authorised_values.size > 0 %]
592
                  <select name="additional_field_[% af.id %]" id="additional_field_[% af.id %]">
593
                    <option value=""></option>
594
                    [% FOREACH av IN authorised_values %]
595
                      [% IF value == av.authorised_value %]
596
                        <option value="[% av.authorised_value %]" selected="selected">[% av.lib %]</option>
597
                      [% ELSE %]
598
                        <option value="[% av.authorised_value %]">[% av.lib %]</option>
599
                      [% END %]
600
                    [% END %]
601
                  </select>
602
                [% ELSE %]
603
                  <input type="text" name="additional_field_[% af.id %]" id="additional_field_[% af.id %]" value="[% value %]" />
604
                [% END %]
605
              </li>
606
            [% END %]
577
        </ol>
607
        </ol>
578
    </fieldset>
608
    </fieldset>
579
    <fieldset class="action">
609
    <fieldset class="action">
580
- 

Return to bug 11844