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

(-)a/Koha/MarcOrderAccount.pm (+63 lines)
Line 0 Link Here
1
package Koha::MarcOrderAccount;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
22
use base qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::MarcOrderAccount - Koha Marc Ordering Account Object class
27
28
=head1 API
29
30
=head2 Class Methods
31
32
=cut
33
34
=head3 vendor
35
36
=cut
37
38
sub vendor {
39
    my ($self) = @_;
40
    my $vendor_rs = $self->_result->vendor;
41
    return unless $vendor_rs;
42
    return Koha::Acquisition::Bookseller->_new_from_dbic($vendor_rs);
43
}
44
45
=head3 budget
46
47
=cut
48
49
sub budget {
50
    my ($self) = @_;
51
    my $budget_rs = $self->_result->budget;
52
    return Koha::Acquisition::Fund->_new_from_dbic($budget_rs);
53
}
54
55
=head3 _type
56
57
=cut
58
59
sub _type {
60
    return 'MarcOrderAccount';
61
}
62
63
1;
(-)a/Koha/MarcOrderAccounts.pm (+51 lines)
Line 0 Link Here
1
package Koha::MarcOrderAccounts;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::MarcOrderAccount;
22
23
use base qw(Koha::Objects);
24
25
=head1 NAME
26
27
Koha::MarcOrderAccount - Koha Marc Ordering Account Object class
28
29
=head1 API
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 type
36
37
=cut
38
39
sub _type {
40
    return 'MarcOrderAccount';
41
}
42
43
=head3 object_class
44
45
=cut
46
47
sub object_class {
48
    return 'Koha::MarcOrderAccount';
49
}
50
51
1;
(-)a/admin/marc_order_accounts.pl (+131 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# A script that allows the user to create an account and profile for auto-creating orders from imported marc files
4
# The script displays account details and allows account creation/editing in the first instance
5
# If the "run" operation is passed then the script will run the process of creating orders
6
7
# Copyright 2023 PTFS Europe Ltd
8
#
9
# This file is part of Koha.
10
#
11
# Koha is free software; you can redistribute it and/or modify it
12
# under the terms of the GNU General Public License as published by
13
# the Free Software Foundation; either version 3 of the License, or
14
# (at your option) any later version.
15
#
16
# Koha is distributed in the hope that it will be useful, but
17
# WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU General Public License for more details.
20
#
21
# You should have received a copy of the GNU General Public License
22
# along with Koha; if not, see <http://www.gnu.org/licenses>.
23
24
use Modern::Perl;
25
use CGI qw ( -utf8 );
26
27
use C4::Context;
28
use C4::Auth    qw( get_template_and_user );
29
use C4::Budgets qw( GetBudgets );
30
use C4::Output  qw( output_html_with_http_headers );
31
use C4::Matcher;
32
33
use Koha::UploadedFiles;
34
use Koha::ImportBatchProfiles;
35
use Koha::MarcOrder;
36
use Koha::Acquisition::Booksellers;
37
use Koha::MarcOrderAccount;
38
use Koha::MarcOrderAccounts;
39
40
my $input = CGI->new;
41
42
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43
    {
44
        template_name => "admin/marc_order_accounts.tt",
45
        query         => $input,
46
        type          => "intranet",
47
    }
48
);
49
50
my $crypt = Koha::Encryption->new;
51
52
my $op = $input->param('op');
53
$op ||= 'display';
54
55
if ( $op eq 'acct_form' ) {
56
    $template->param( acct_form => 1 );
57
    my @vendors = Koha::Acquisition::Booksellers->search(
58
        undef,
59
        {
60
            columns  => [ 'name', 'id' ],
61
            order_by => { -asc => 'name' }
62
        }
63
    )->as_list;
64
    my $budgets = GetBudgets();
65
    $template->param(
66
        vendors => \@vendors,
67
        budgets => $budgets
68
    );
69
    my @matchers = C4::Matcher::GetMatcherList();
70
    $template->param( available_matchers => \@matchers );
71
72
    show_account( $input, $template );
73
} elsif ( $op eq 'delete_acct' ) {
74
    show_account( $input, $template );
75
    $template->param( delete_acct => 1 );
76
} else {
77
    if ( $op eq 'cud-save' ) {
78
        my $fields = {
79
            id                 => scalar $input->param('id'),
80
            description        => scalar $input->param('description'),
81
            vendor_id          => scalar $input->param('vendor_id'),
82
            budget_id          => scalar $input->param('budget_id'),
83
            download_directory => scalar $input->param('download_directory'),
84
            matcher_id         => scalar $input->param('matcher'),
85
            overlay_action     => scalar $input->param('overlay_action'),
86
            nomatch_action     => scalar $input->param('nomatch_action'),
87
            parse_items        => scalar $input->param('parse_items'),
88
            item_action        => scalar $input->param('item_action'),
89
            record_type        => scalar $input->param('record_type'),
90
            encoding           => scalar $input->param('encoding') || 'UTF-8',
91
        };
92
93
        if ( scalar $input->param('id') ) {
94
95
            # Update existing account
96
            my $account = Koha::MarcOrderAccounts->find( scalar $input->param('id') );
97
            $account->update($fields);
98
        } else {
99
100
            # Add new account
101
            my $new_account = Koha::MarcOrderAccount->new($fields);
102
            $new_account->store;
103
        }
104
    } elsif ( $op eq 'cud-delete_acct' ) {
105
        my $acct_id = $input->param('id');
106
        my $acct    = Koha::MarcOrderAccounts->find($acct_id);
107
        $acct->delete;
108
    }
109
110
    $template->param( display => 1 );
111
    my @accounts = Koha::MarcOrderAccounts->search(
112
        {},
113
        { join => [ 'vendor', 'budget' ] }
114
    )->as_list;
115
    $template->param( accounts => \@accounts );
116
117
}
118
119
output_html_with_http_headers $input, $cookie, $template->output;
120
121
sub show_account {
122
    my ( $input, $template ) = @_;
123
    my $acct_id = $input->param('id');
124
    if ($acct_id) {
125
        my $acct = Koha::MarcOrderAccounts->find($acct_id);
126
        if ($acct) {
127
            $template->param( account => $acct );
128
        }
129
    }
130
    return;
131
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt (-1 / +246 lines)
Line 0 Link Here
0
- 
1
[% USE raw %]
2
[% USE Koha %]
3
[% USE Asset %]
4
[% PROCESS 'i18n.inc' %]
5
[% SET footerjs = 1 %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>
8
MARC Order Accounts
9
</title>
10
<style>
11
    #fileuploadstatus,#fileuploadfailed,#fileuploadcancel { display : none; }
12
</style>
13
[% INCLUDE 'doc-head-close.inc' %]
14
</head>
15
<body id="admin_marc_order_acct" class="admin">
16
[% WRAPPER 'header.inc' %]
17
    [% INCLUDE 'prefs-admin-search.inc' %]
18
[% END %]
19
20
[% WRAPPER 'sub-header.inc' %]
21
    [% WRAPPER breadcrumbs %]
22
        [% WRAPPER breadcrumb_item %]
23
            <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
24
        [% END %]
25
26
        [% IF acct_form || delete_confirm %]
27
            [% WRAPPER breadcrumb_item %]
28
                <a href="/cgi-bin/koha/admin/marc_order_accounts.pl">MARC Order Accounts</a>
29
            [% END %]
30
        [% ELSE %]
31
            [% WRAPPER breadcrumb_item bc_active= 1 %]
32
                <span>MARC Order Accounts</span>
33
            [% END %]
34
        [% END %]
35
    [% END #/ WRAPPER breadcrumbs %]
36
[% END #/ WRAPPER sub-header.inc %]
37
38
<div class="main container-fluid">
39
    <div class="row">
40
        <div class="col-sm-10 col-sm-push-2">
41
            <main>
42
                [% IF display %]
43
                    <div id="toolbar" class="btn-toolbar">
44
                    <a class="btn btn-default" id="newmarcorderacct" href="/cgi-bin/koha/admin/marc_order_accounts.pl?op=acct_form">
45
                        <i class="fa fa-plus"></i>
46
                        New account
47
                    </a>
48
                    </div>
49
                    [% IF ( accounts ) %]
50
                        <h1>Marc Ordering Accounts</h1>
51
                        <div class="page-section">
52
                            <table>
53
                                <tr>
54
                                    <th>ID</th>
55
                                    <th>Vendor</th>
56
                                    <th>Budget</th>
57
                                    <th>Description</th>
58
                                    <th>Download directory</th>
59
                                    <th>Actions</th>
60
                                </tr>
61
                                [% FOREACH account IN accounts %]
62
                                    <tr>
63
                                        <td>[% account.id | html %]</td>
64
                                        <td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% account.vendor_id | uri %]">[% account.vendor.name | html %]</a></td>
65
                                        <td><a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% account.budget.budget_period_id | uri %]">[% account.budget.budget_name | html %]</a></td>
66
                                        <td>[% account.description | html %]</td>
67
                                        <td>[% account.download_directory | html %]</td>
68
                                        <td class="actions">
69
                                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/marc_order_accounts.pl?op=acct_form&id=[% account.id | html %]"><i class="fa fa-pencil-alt"></i> Edit</a>
70
                                            <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/marc_order_accounts.pl?op=delete_acct&id=[% account.id | html %]"><i class="fa fa-trash-can"></i> Delete</a>
71
                                        </td>
72
                                    </tr>
73
                                [% END %]
74
                            </table>
75
                        </div>
76
                    [% ELSE %]
77
                        <div class="dialog message">
78
                            There are no MARC Order accounts.
79
                        </div>
80
                    [% END %]
81
                [% END %]
82
                [% IF acct_form %]
83
                    <h1>
84
                        [% IF account %]
85
                            Modify account
86
                        [% ELSE %]
87
                            New account
88
                        [% END %]
89
                    </h1>
90
                    <form action="/cgi-bin/koha/admin/marc_order_accounts.pl" name="Actform" method="post">
91
                        [% INCLUDE 'csrf-token.inc' %]
92
                        <input type="hidden" name="op" value="cud-save" />
93
                        [% IF account %]
94
                        <input type="hidden" name="id" value="[% account.id | html %]" />
95
                        [% END %]
96
                        <fieldset class="rows">
97
                            <legend>Account details</legend>
98
                            <ol>
99
                                <li>
100
                                    <label for="vendor_id">Vendor: </label>
101
                                    <select name="vendor_id" id="vendor_id">
102
                                        [% FOREACH vendor IN vendors %]
103
                                            [% IF account.vendor_id == vendor.id %]
104
                                                <option value="[% vendor.id | html %]" selected="selected">[% vendor.name | html %]</option>
105
                                            [% ELSE %]
106
                                                <option value="[% vendor.id | html %]">[% vendor.name | html %]</option>
107
                                            [% END %]
108
                                        [% END %]
109
                                    </select>
110
                                </li>
111
                                <li>
112
                                    <label for="budget_id">Budget: </label>
113
                                    <select name="budget_id" id="budget_id">
114
                                        [% FOREACH budget IN budgets %]
115
                                            [% IF account.budget_id == budget.budget_id %]
116
                                                <option value="[% budget.budget_id | html %]" selected="selected">[% budget.budget_name | html %]</option>
117
                                            [% ELSE %]
118
                                                <option value="[% budget.budget_id | html %]">[% budget.budget_name | html %]</option>
119
                                            [% END %]
120
                                        [% END %]
121
                                    </select>
122
                                    <div class="hint">This budget will be used as the fallback value if the MARC records do not contain a mapped value for a budget code.</div>
123
                                </li>
124
                                <li>
125
                                    <label for="description">Description: </label>
126
                                    <input type="text" name="description" id="description" size="20" value="[% account.description | html %]" />
127
                                </li>
128
                                <li>
129
                                    <label for="download_directory">Download directory: </label>
130
                                    <input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
131
                                    <div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
132
                                </li>
133
                            </ol>
134
                        </fieldset>
135
                        <fieldset class="rows">
136
                            <legend>File import settings</legend>
137
                            <ol>
138
                                <li>
139
                                        <label for='record_type'>Record type:</label>
140
                                        <select name='record_type' id='record_type'>
141
                                            <option value='biblio' selected='selected'>Bibliographic</option>
142
                                            <option value='auth'>Authority</option>
143
                                        </select>
144
                                    </li>
145
                                    <li>
146
                                        <label for="encoding">Character encoding: </label>
147
                                        <select name="encoding" id="encoding">
148
                                            <option value="UTF-8" selected="selected">UTF-8 (Default)</option>
149
                                            <option value="MARC-8">MARC 8</option>
150
                                            <option value="ISO_5426">ISO 5426</option>
151
                                            <option value="ISO_6937">ISO 6937</option>
152
                                            <option value="ISO_8859-1">ISO 8859-1</option>
153
                                            <option value="EUC-KR">EUC-KR</option>
154
                                        </select>
155
                                    </li>
156
                            </ol>
157
                        </fieldset>
158
                        <fieldset class="rows">
159
                            <legend>Record matching settings</legend>
160
                            <ol>
161
                                <li>
162
                                    <label for="matcher">Record matching rule:</label>
163
                                    <select name="matcher" id="matcher">
164
                                        [% FOREACH available_matcher IN available_matchers %]
165
                                            [% IF available_matcher.id == account.matcher_id %]
166
                                                <option value="[% available_matcher.matcher_id | html %]" selected="selected">[% available_matcher.code | html %] ([% available_matcher.description | html %])</option>
167
                                            [% ELSE %]
168
                                                <option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])</option>
169
                                            [% END %]
170
                                        [% END %]
171
                                    </select>
172
                                </li>
173
                                <li>
174
                                    <label for="overlay_action">Action if matching record found: </label>
175
                                    [% INCLUDE 'tools-overlay-action.inc' %]
176
                                </li>
177
                                <li>
178
                                    <label for="nomatch_action">Action if no match is found: </label>
179
                                    [% INCLUDE 'tools-nomatch-action.inc' %]
180
                                </li>
181
                            </ol>
182
                        </fieldset>
183
                        <fieldset class="rows" id="items">
184
                            <legend>Check for embedded item record data?</legend>
185
                            <ol>
186
                                <li class="radio">
187
                                    <input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
188
                                    <label for="parse_itemsyes">Yes</label>
189
                                </li>
190
                                <li class="radio">
191
                                    <input type="radio" id="parse_itemsno" name="parse_items" value="0" />
192
                                    <label for="parse_itemsno">No</label>
193
                                </li>
194
                            </ol>
195
                            <ol>
196
                                <li><label for="item_action">How to process items: </label>
197
                                    [% INCLUDE 'tools-item-action.inc' %]
198
                                </li>
199
                            </ol>
200
                        </fieldset>
201
202
                        <fieldset class="action">
203
                            <input type="submit" class="btn btn-primary" value="Submit" />
204
                            <a href="/cgi-bin/koha/admin/marc_order_accounts.pl" class="cancel">Cancel</a>
205
                        </fieldset>
206
                    </form>
207
                [% END %]
208
                [% IF delete_acct %]
209
                    <div class="dialog alert">
210
                        <h1>Delete this account?</h1>
211
                        <table>
212
                            <tr>
213
                                <th>Vendor</th>
214
                                <th>Description</th>
215
                            </tr>
216
                            <tr>
217
                                <td>[% account.vendor.name | html %]</td>
218
                                <td>[% account.description | html %]</td>
219
                            </tr>
220
                            <tr>
221
                        </table>
222
                        <form action="/cgi-bin/koha/admin/marc_order_accounts.pl" method="post">
223
                            [% INCLUDE 'csrf-token.inc' %]
224
                            <input type="hidden" name="op" value="cud-delete_acct" />
225
                            <input type="hidden" name="id" value="[% account.id | html %]" />
226
                            <button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
227
                        </form>
228
                        <form action="/cgi-bin/koha/admin/marc_order_accounts.pl" method="get">
229
                            <button type="submit" class="deny"><i class="fa fa-fw fa-times"></i> No, do not delete</button>
230
                        </form>
231
                    </div>
232
                [% END %]
233
            </main>
234
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
235
236
        <div class="col-sm-2 col-sm-pull-10">
237
            <aside>
238
                [% INCLUDE 'admin-menu.inc' %]
239
            </aside>
240
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
241
     </div> <!-- /.row -->
242
243
[% MACRO jsinclude BLOCK %]
244
    [% Asset.js("js/admin-menu.js") | $raw %]
245
[% END %]
246
[% INCLUDE 'intranet-bottom.inc' %]

Return to bug 34355