From d3909882c9022675ad582a890302ef0ab93d7387 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 24 Feb 2022 16:51:08 +0100 Subject: [PATCH] Bug 32030: ERM - CRUD operations for agreements [old style] Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- erm/agreements.pl | 131 ++++++ .../prog/en/includes/erm-menu.inc | 8 + .../prog/en/includes/erm-search.inc | 19 +- .../prog/en/modules/erm/agreements.tt | 386 ++++++++++++++++++ 4 files changed, 534 insertions(+), 10 deletions(-) create mode 100755 erm/agreements.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/erm-menu.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt diff --git a/erm/agreements.pl b/erm/agreements.pl new file mode 100755 index 0000000000..87c682249e --- /dev/null +++ b/erm/agreements.pl @@ -0,0 +1,131 @@ +#! /usr/bin/perl + +# 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::Output qw( output_html_with_http_headers ); + +use Koha::Acquisition::Booksellers; +use Koha::ERM::Agreements; + +my $input = CGI->new; +my $agreement_id = $input->param('agreement_id'); +my $op = $input->param('op') || 'list'; +my @messages; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "erm/agreements.tt", + query => $input, + type => "intranet", + flagsrequired => { 'erm' => '1' }, + } +); + +my $dbh = C4::Context->dbh; +if ( $op eq 'add_form' ) { + my $agreement; + if ($agreement_id) { + $agreement = Koha::ERM::Agreements->find($agreement_id); + } + + $template->param( agreement => $agreement, ); +} +elsif ( $op eq 'add_validate' ) { + my $vendor_id = $input->param('vendor_id'); + my $name = $input->param('name'); + my $description = $input->param('description'); + my $status = $input->param('status'); + my $closure_reason = $input->param('closure_reason'); + my $is_perpetual = $input->param('is_perpetual'); + my $renewal_priority = $input->param('renewal_priority'); + my $license_info = $input->param('license_info'); + + if ($agreement_id) { + my $agreement = Koha::ERM::Agreements->find($agreement_id); + $agreement->vendor_id($vendor_id); + $agreement->name($name); + $agreement->description($description); + $agreement->status($status); + $agreement->closure_reason($closure_reason); + $agreement->is_perpetual($is_perpetual); + $agreement->renewal_priority($renewal_priority); + $agreement->license_info($license_info); + + eval { $agreement->store; }; + if ($@) { + push @messages, { type => 'error', code => 'error_on_update' }; + } + else { + push @messages, { type => 'message', code => 'success_on_update' }; + } + } + else { + my $agreement = Koha::ERM::Agreement->new( + { + vendor_id => $vendor_id, + name => $name, + description => $description, + status => $status, + closure_reason => $closure_reason, + is_perpetual => $is_perpetual, + renewal_priority => $renewal_priority, + license_info => $license_info, + } + ); + eval { $agreement->store; }; + if ($@) { + push @messages, { type => 'error', code => 'error_on_insert' }; + } + else { + push @messages, { type => 'message', code => 'success_on_insert' }; + } + } + $op = 'list'; +} +elsif ( $op eq 'delete_confirm' ) { + my $agreement = Koha::ERM::Agreements->find($agreement_id); + $template->param( agreement => $agreement, ); +} +elsif ( $op eq 'delete_confirmed' ) { + my $agreement = Koha::ERM::Agreements->find($agreement_id); + my $deleted = eval { $agreement->delete; }; + + if ( $@ or not $deleted ) { + push @messages, { type => 'error', code => 'error_on_delete' }; + } + else { + push @messages, { type => 'message', code => 'success_on_delete' }; + } + $op = 'list'; +} + +if ( $op eq 'list' ) { + $template->param( + agreements_count => Koha::ERM::Agreements->search->count ); +} + +$template->param( + vendors => Koha::Acquisition::Booksellers->search, + agreement_id => $agreement_id, + messages => \@messages, + op => $op, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/erm-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-menu.inc new file mode 100644 index 0000000000..f6a0f90649 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-menu.inc @@ -0,0 +1,8 @@ + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc index 27c7f36dc3..9f6e62b04e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/erm-search.inc @@ -1,19 +1,18 @@ [% USE Koha %]
-

[% LibraryName | html %]

+

[% LibraryName | html %]

+ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt new file mode 100644 index 0000000000..2458563a60 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/erm/agreements.tt @@ -0,0 +1,386 @@ +[% USE raw %] +[% USE To %] +[% USE Asset %] +[% SET footerjs = 1 %] +[% USE TablesSettings %] +[% USE AuthorisedValues %] +[% INCLUDE 'doc-head-open.inc' %] + + [% IF op =='add_form' %] + [% IF agreement.agreement_id %] + Modify agreement + [% ELSE %] + New agreement + [% END %] › [% ELSE %] + [% IF op == 'delete_confirm' %] + Confirm deletion of agreement › [% END %] + [% END %] + Agreements › Electronic resources management › Koha + +[% INCLUDE 'doc-head-close.inc' %] + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'erm-search.inc' %] + + + +
+
+
+
+ +[% FOR m IN messages %] +
+ [% SWITCH m.code %] + [% CASE 'error_on_update' %] + An error occurred when updating this agreement. Perhaps it already exists. + [% CASE 'error_on_insert' %] + An error occurred when adding this agreement. The agreement id might already exist. + [% CASE 'error_on_delete' %] + An error occurred when deleting this agreement. Check the logs. + [% CASE 'success_on_update' %] + Agreement updated successfully. + [% CASE 'success_on_insert' %] + Agreement added successfully. + [% CASE 'success_on_delete' %] + Agreement deleted successfully. + [% CASE 'already_exists' %] + This agreement already exists. + [% CASE %] + [% m.code | html %] + [% END %] +
+[% END %] + +[% IF op == 'add_form' %] + [% IF agreement %] +

Modify a agreement

+ [% ELSE %] +

New agreement

+ [% END %] + +
+ + + +
+
    + [% IF agreement %] +
  1. Agreement ID: [% agreement.agreement_id | html %]
  2. + [% END %] + +
  3. + + +
  4. +
  5. + + Required +
  6. + + +
  7. + + + Required +
  8. +
  9. + + +
  10. +
  11. + + + +
  12. +
  13. + + +
  14. + + +
  15. +
+
+ +
+ + Cancel +
+
+[% END %] + +[% IF op == 'delete_confirm' %] +
+

Delete agreement "[% agreement.agreement_id | html %]?"

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Agreement id[% agreement.agreement_id| html %]
Vendor[% agreement.vendor_id| html %]
Name[% agreement.name| html %]
Description[% agreement.description| html %]
Status[% agreement.status| html %]
Closure_reason[% agreement.closure_reason| html %]
Is perpetual[% agreement.is_perpetual| html %]
Renewal priority[% agreement.renewal_priority| html %]
License info[% agreement.license_info| html %]
+
+ + + +
+
+ +
+
+[% END %] + +[% IF op == 'list' %] + + + +

Agreements

+ [% IF agreement_name_filter %] + Searching: [% agreement_name_filter | html %] + [% END %] + + [% IF agreements_count > 0 %] +
+ + + + + + + + + + + + + + +
IDVendorNameDescriptionStatusClosure reasonIs perpetualRenewal priorityActions
+ [% ELSE %] +
+ There are no agreements defined. Create a new agreement. +
+ [% END %] +[% END %] + +
+
+ +
+ +
+
+ +[% MACRO jsinclude BLOCK %] + [% Asset.js("js/erm-menu.js") | $raw %] + [% INCLUDE 'datatables.inc' %] + [% INCLUDE 'columns_settings.inc' %] + +[% END %] +[% INCLUDE 'intranet-bottom.inc' %] -- 2.39.5