From 1a8d3802f76dd5b51f4d3694aa54ad7cb883ee4d Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 24 Jul 2023 13:52:41 +0000 Subject: [PATCH] Bug 34355: Add account creation --- Koha/MarcOrderAccount.pm | 63 +++++ Koha/MarcOrderAccounts.pm | 51 ++++ admin/marc_order_accounts.pl | 132 ++++++++++ .../en/modules/admin/marc_order_accounts.tt | 246 ++++++++++++++++++ 4 files changed, 492 insertions(+) create mode 100644 Koha/MarcOrderAccount.pm create mode 100644 Koha/MarcOrderAccounts.pm create mode 100644 admin/marc_order_accounts.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt diff --git a/Koha/MarcOrderAccount.pm b/Koha/MarcOrderAccount.pm new file mode 100644 index 0000000000..9b8c8fa359 --- /dev/null +++ b/Koha/MarcOrderAccount.pm @@ -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 . + +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; \ No newline at end of file diff --git a/Koha/MarcOrderAccounts.pm b/Koha/MarcOrderAccounts.pm new file mode 100644 index 0000000000..f6ee407d65 --- /dev/null +++ b/Koha/MarcOrderAccounts.pm @@ -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 . + +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; diff --git a/admin/marc_order_accounts.pl b/admin/marc_order_accounts.pl new file mode 100644 index 0000000000..e8938e0c6c --- /dev/null +++ b/admin/marc_order_accounts.pl @@ -0,0 +1,132 @@ +#!/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 . + +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 '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 'delete_confirmed') { + 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; +} \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt new file mode 100644 index 0000000000..c5e68e92fc --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_order_accounts.tt @@ -0,0 +1,246 @@ +[% USE raw %] +[% USE Koha %] +[% USE Asset %] +[% PROCESS 'i18n.inc' %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] + +MARC Order Accounts + + +[% INCLUDE 'doc-head-close.inc' %] + + +[% WRAPPER 'header.inc' %] + [% INCLUDE 'prefs-admin-search.inc' %] +[% END %] + +[% WRAPPER 'sub-header.inc' %] + [% WRAPPER breadcrumbs %] + [% WRAPPER breadcrumb_item %] + Administration + [% END %] + + [% IF acct_form || delete_confirm %] + [% WRAPPER breadcrumb_item %] + MARC Order Accounts + [% END %] + [% ELSE %] + [% WRAPPER breadcrumb_item bc_active= 1 %] + MARC Order Accounts + [% END %] + [% END %] + [% END #/ WRAPPER breadcrumbs %] +[% END #/ WRAPPER sub-header.inc %] + +
+
+
+
+ [% IF display %] + + [% IF ( accounts ) %] +

Marc Ordering Accounts

+
+ + + + + + + + + + [% FOREACH account IN accounts %] + + + + + + + + + [% END %] +
IDVendorBudgetDescriptionDownload directoryActions
[% account.id | html %][% account.vendor.name | html %][% account.budget.budget_name | html %][% account.description | html %][% account.download_directory | html %] + Edit + Delete +
+
+ [% ELSE %] +
+ There are no MARC Order accounts. +
+ [% END %] + [% END %] + [% IF acct_form %] +

+ [% IF account %] + Modify account + [% ELSE %] + New account + [% END %] +

+
+ + [% IF account %] + + [% END %] +
+ Account details +
    +
  1. + + +
  2. +
  3. + + +
    This budget will be used as the fallback value if the MARC records do not contain a mapped value for a budget code.
    +
  4. +
  5. + + +
  6. +
  7. + + +
    The download directory specifies the directory in your koha installation that should be searched for new files.
    +
  8. +
+
+
+ File import settings +
    +
  1. + + +
  2. +
  3. + + +
  4. +
+
+
+ Record matching settings +
    +
  1. + + +
  2. +
  3. + + [% INCLUDE 'tools-overlay-action.inc' %] +
  4. +
  5. + + [% INCLUDE 'tools-nomatch-action.inc' %] +
  6. +
+
+
+ Check for embedded item record data? +
    +
  1. + + +
  2. +
  3. + + +
  4. +
+
    +
  1. + [% INCLUDE 'tools-item-action.inc' %] +
  2. +
+
+ +
+ + Cancel +
+
+ [% END %] + [% IF delete_acct %] +
+

Delete this account?

+ + + + + + + + + + +
VendorDescription
[% account.vendor.name | html %][% account.description | html %]
+
+ +
+ + + +
+
+ +
+
+ [% END %] +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/admin-menu.js") | $raw %] +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] \ No newline at end of file -- 2.37.1 (Apple Git-137.1)