Bug 34355: Add account creation

Signed-off-by: Andrew Fuerste Henry <andrewfh@dubcolib.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2023-07-24 13:52:41 +00:00 committed by Katrin Fischer
parent 456b31067a
commit 143570a848
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
4 changed files with 491 additions and 0 deletions

63
Koha/MarcOrderAccount.pm Normal file
View File

@ -0,0 +1,63 @@
package Koha::MarcOrderAccount;
# This file is part of Koha.
#
# 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 <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Database;
use base qw(Koha::Object);
=head1 NAME
Koha::MarcOrderAccount - Koha Marc Ordering Account Object class
=head1 API
=head2 Class Methods
=cut
=head3 vendor
=cut
sub vendor {
my ($self) = @_;
my $vendor_rs = $self->_result->vendor;
return unless $vendor_rs;
return Koha::Acquisition::Bookseller->_new_from_dbic($vendor_rs);
}
=head3 budget
=cut
sub budget {
my ($self) = @_;
my $budget_rs = $self->_result->budget;
return Koha::Acquisition::Fund->_new_from_dbic($budget_rs);
}
=head3 _type
=cut
sub _type {
return 'MarcOrderAccount';
}
1;

51
Koha/MarcOrderAccounts.pm Normal file
View File

@ -0,0 +1,51 @@
package Koha::MarcOrderAccounts;
# This file is part of Koha.
#
# 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 <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Database;
use Koha::MarcOrderAccount;
use base qw(Koha::Objects);
=head1 NAME
Koha::MarcOrderAccount - Koha Marc Ordering Account Object class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub _type {
return 'MarcOrderAccount';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::MarcOrderAccount';
}
1;

View File

@ -0,0 +1,131 @@
#!/usr/bin/perl
# A script that allows the user to create an account and profile for auto-creating orders from imported marc files
# The script displays account details and allows account creation/editing in the first instance
# If the "run" operation is passed then the script will run the process of creating orders
# Copyright 2023 PTFS Europe Ltd
#
# This file is part of Koha.
#
# 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 <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Context;
use C4::Auth qw( get_template_and_user );
use C4::Budgets qw( GetBudgets );
use C4::Output qw( output_html_with_http_headers );
use C4::Matcher;
use Koha::UploadedFiles;
use Koha::ImportBatchProfiles;
use Koha::MarcOrder;
use Koha::Acquisition::Booksellers;
use Koha::MarcOrderAccount;
use Koha::MarcOrderAccounts;
my $input = CGI->new;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "admin/marc_order_accounts.tt",
query => $input,
type => "intranet",
}
);
my $crypt = Koha::Encryption->new;
my $op = $input->param('op');
$op ||= 'display';
if ( $op eq 'acct_form' ) {
$template->param( acct_form => 1 );
my @vendors = Koha::Acquisition::Booksellers->search(
undef,
{
columns => [ 'name', 'id' ],
order_by => { -asc => 'name' }
}
)->as_list;
my $budgets = GetBudgets();
$template->param(
vendors => \@vendors,
budgets => $budgets
);
my @matchers = C4::Matcher::GetMatcherList();
$template->param( available_matchers => \@matchers );
show_account( $input, $template );
} elsif ( $op eq 'delete_acct' ) {
show_account( $input, $template );
$template->param( delete_acct => 1 );
} else {
if ( $op eq 'cud-save' ) {
my $fields = {
id => scalar $input->param('id'),
description => scalar $input->param('description'),
vendor_id => scalar $input->param('vendor_id'),
budget_id => scalar $input->param('budget_id'),
download_directory => scalar $input->param('download_directory'),
matcher_id => scalar $input->param('matcher'),
overlay_action => scalar $input->param('overlay_action'),
nomatch_action => scalar $input->param('nomatch_action'),
parse_items => scalar $input->param('parse_items'),
item_action => scalar $input->param('item_action'),
record_type => scalar $input->param('record_type'),
encoding => scalar $input->param('encoding') || 'UTF-8',
};
if ( scalar $input->param('id') ) {
# Update existing account
my $account = Koha::MarcOrderAccounts->find( scalar $input->param('id') );
$account->update($fields);
} else {
# Add new account
my $new_account = Koha::MarcOrderAccount->new($fields);
$new_account->store;
}
} elsif ( $op eq 'cud-delete_acct' ) {
my $acct_id = $input->param('id');
my $acct = Koha::MarcOrderAccounts->find($acct_id);
$acct->delete;
}
$template->param( display => 1 );
my @accounts = Koha::MarcOrderAccounts->search(
{},
{ join => [ 'vendor', 'budget' ] }
)->as_list;
$template->param( accounts => \@accounts );
}
output_html_with_http_headers $input, $cookie, $template->output;
sub show_account {
my ( $input, $template ) = @_;
my $acct_id = $input->param('id');
if ($acct_id) {
my $acct = Koha::MarcOrderAccounts->find($acct_id);
if ($acct) {
$template->param( account => $acct );
}
}
return;
}

View File

@ -0,0 +1,246 @@
[% USE raw %]
[% USE Koha %]
[% USE Asset %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>
MARC Order Accounts
</title>
<style>
#fileuploadstatus,#fileuploadfailed,#fileuploadcancel { display : none; }
</style>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body id="admin_marc_order_acct" class="admin">
[% WRAPPER 'header.inc' %]
[% INCLUDE 'prefs-admin-search.inc' %]
[% END %]
[% WRAPPER 'sub-header.inc' %]
[% WRAPPER breadcrumbs %]
[% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
[% END %]
[% IF acct_form || delete_confirm %]
[% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/admin/marc_order_accounts.pl">MARC Order Accounts</a>
[% END %]
[% ELSE %]
[% WRAPPER breadcrumb_item bc_active= 1 %]
<span>MARC Order Accounts</span>
[% END %]
[% END %]
[% END #/ WRAPPER breadcrumbs %]
[% END #/ WRAPPER sub-header.inc %]
<div class="main container-fluid">
<div class="row">
<div class="col-sm-10 col-sm-push-2">
<main>
[% IF display %]
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-default" id="newmarcorderacct" href="/cgi-bin/koha/admin/marc_order_accounts.pl?op=acct_form">
<i class="fa fa-plus"></i>
New account
</a>
</div>
[% IF ( accounts ) %]
<h1>Marc Ordering Accounts</h1>
<div class="page-section">
<table>
<tr>
<th>ID</th>
<th>Vendor</th>
<th>Budget</th>
<th>Description</th>
<th>Download directory</th>
<th>Actions</th>
</tr>
[% FOREACH account IN accounts %]
<tr>
<td>[% account.id | html %]</td>
<td><a href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% account.vendor_id | uri %]">[% account.vendor.name | html %]</a></td>
<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>
<td>[% account.description | html %]</td>
<td>[% account.download_directory | html %]</td>
<td class="actions">
<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>
<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>
</td>
</tr>
[% END %]
</table>
</div>
[% ELSE %]
<div class="dialog message">
There are no MARC Order accounts.
</div>
[% END %]
[% END %]
[% IF acct_form %]
<h1>
[% IF account %]
Modify account
[% ELSE %]
New account
[% END %]
</h1>
<form action="/cgi-bin/koha/admin/marc_order_accounts.pl" name="Actform" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-save" />
[% IF account %]
<input type="hidden" name="id" value="[% account.id | html %]" />
[% END %]
<fieldset class="rows">
<legend>Account details</legend>
<ol>
<li>
<label for="vendor_id">Vendor: </label>
<select name="vendor_id" id="vendor_id">
[% FOREACH vendor IN vendors %]
[% IF account.vendor_id == vendor.id %]
<option value="[% vendor.id | html %]" selected="selected">[% vendor.name | html %]</option>
[% ELSE %]
<option value="[% vendor.id | html %]">[% vendor.name | html %]</option>
[% END %]
[% END %]
</select>
</li>
<li>
<label for="budget_id">Budget: </label>
<select name="budget_id" id="budget_id">
[% FOREACH budget IN budgets %]
[% IF account.budget_id == budget.budget_id %]
<option value="[% budget.budget_id | html %]" selected="selected">[% budget.budget_name | html %]</option>
[% ELSE %]
<option value="[% budget.budget_id | html %]">[% budget.budget_name | html %]</option>
[% END %]
[% END %]
</select>
<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>
</li>
<li>
<label for="description">Description: </label>
<input type="text" name="description" id="description" size="20" value="[% account.description | html %]" />
</li>
<li>
<label for="download_directory">Download directory: </label>
<input type="text" name="download_directory" id="download_directory" size="20" value="[% account.download_directory | html %]" />
<div class="hint">The download directory specifies the directory in your koha installation that should be searched for new files.</div>
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>File import settings</legend>
<ol>
<li>
<label for='record_type'>Record type:</label>
<select name='record_type' id='record_type'>
<option value='biblio' selected='selected'>Bibliographic</option>
<option value='auth'>Authority</option>
</select>
</li>
<li>
<label for="encoding">Character encoding: </label>
<select name="encoding" id="encoding">
<option value="UTF-8" selected="selected">UTF-8 (Default)</option>
<option value="MARC-8">MARC 8</option>
<option value="ISO_5426">ISO 5426</option>
<option value="ISO_6937">ISO 6937</option>
<option value="ISO_8859-1">ISO 8859-1</option>
<option value="EUC-KR">EUC-KR</option>
</select>
</li>
</ol>
</fieldset>
<fieldset class="rows">
<legend>Record matching settings</legend>
<ol>
<li>
<label for="matcher">Record matching rule:</label>
<select name="matcher" id="matcher">
[% FOREACH available_matcher IN available_matchers %]
[% IF available_matcher.id == account.matcher_id %]
<option value="[% available_matcher.matcher_id | html %]" selected="selected">[% available_matcher.code | html %] ([% available_matcher.description | html %])</option>
[% ELSE %]
<option value="[% available_matcher.matcher_id | html %]">[% available_matcher.code | html %] ([% available_matcher.description | html %])</option>
[% END %]
[% END %]
</select>
</li>
<li>
<label for="overlay_action">Action if matching record found: </label>
[% INCLUDE 'tools-overlay-action.inc' %]
</li>
<li>
<label for="nomatch_action">Action if no match is found: </label>
[% INCLUDE 'tools-nomatch-action.inc' %]
</li>
</ol>
</fieldset>
<fieldset class="rows" id="items">
<legend>Check for embedded item record data?</legend>
<ol>
<li class="radio">
<input type="radio" id="parse_itemsyes" name="parse_items" value="1" checked="checked" />
<label for="parse_itemsyes">Yes</label>
</li>
<li class="radio">
<input type="radio" id="parse_itemsno" name="parse_items" value="0" />
<label for="parse_itemsno">No</label>
</li>
</ol>
<ol>
<li><label for="item_action">How to process items: </label>
[% INCLUDE 'tools-item-action.inc' %]
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" class="btn btn-primary" value="Submit" />
<a href="/cgi-bin/koha/admin/marc_order_accounts.pl" class="cancel">Cancel</a>
</fieldset>
</form>
[% END %]
[% IF delete_acct %]
<div class="dialog alert">
<h1>Delete this account?</h1>
<table>
<tr>
<th>Vendor</th>
<th>Description</th>
</tr>
<tr>
<td>[% account.vendor.name | html %]</td>
<td>[% account.description | html %]</td>
</tr>
<tr>
</table>
<form action="/cgi-bin/koha/admin/marc_order_accounts.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="op" value="cud-delete_acct" />
<input type="hidden" name="id" value="[% account.id | html %]" />
<button type="submit" class="approve"><i class="fa fa-fw fa-check"></i> Yes, delete</button>
</form>
<form action="/cgi-bin/koha/admin/marc_order_accounts.pl" method="get">
<button type="submit" class="deny"><i class="fa fa-fw fa-times"></i> No, do not delete</button>
</form>
</div>
[% END %]
</main>
</div> <!-- /.col-sm-10.col-sm-push-2 -->
<div class="col-sm-2 col-sm-pull-10">
<aside>
[% INCLUDE 'admin-menu.inc' %]
</aside>
</div> <!-- /.col-sm-2.col-sm-pull-10 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/admin-menu.js") | $raw %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]