Skip to content

Commit 860ebaa

Browse files
committed
Add account creation
1 parent 4787034 commit 860ebaa

File tree

4 files changed

+492
-0
lines changed

4 files changed

+492
-0
lines changed

Koha/MarcOrderAccount.pm

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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;

Koha/MarcOrderAccounts.pm

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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;

admin/marc_order_accounts.pl

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 'save' ) {
78+
79+
my $fields = {
80+
id => scalar $input->param('id'),
81+
description => scalar $input->param('description'),
82+
vendor_id => scalar $input->param('vendor_id'),
83+
budget_id => scalar $input->param('budget_id'),
84+
download_directory => scalar $input->param('download_directory'),
85+
matcher_id => scalar $input->param('matcher'),
86+
overlay_action => scalar $input->param('overlay_action'),
87+
nomatch_action => scalar $input->param('nomatch_action'),
88+
parse_items => scalar $input->param('parse_items'),
89+
item_action => scalar $input->param('item_action'),
90+
record_type => scalar $input->param('record_type'),
91+
encoding => scalar $input->param('encoding') || 'UTF-8',
92+
};
93+
94+
if(scalar $input->param('id')) {
95+
# Update existing account
96+
my $account = Koha::MarcOrderAccounts->find(scalar $input->param('id'));
97+
$account->update($fields);
98+
} else {
99+
# Add new account
100+
my $new_account = Koha::MarcOrderAccount->new($fields);
101+
$new_account->store;
102+
}
103+
} elsif ($op eq 'delete_confirmed') {
104+
my $acct_id = $input->param('id');
105+
my $acct = Koha::MarcOrderAccounts->find($acct_id);
106+
$acct->delete;
107+
}
108+
109+
$template->param( display => 1 );
110+
my @accounts = Koha::MarcOrderAccounts->search(
111+
{},
112+
{
113+
join => ['vendor', 'budget']
114+
}
115+
)->as_list;
116+
$template->param( accounts => \@accounts );
117+
118+
}
119+
120+
output_html_with_http_headers $input, $cookie, $template->output;
121+
122+
sub show_account {
123+
my ($input, $template) = @_;
124+
my $acct_id = $input->param('id');
125+
if ($acct_id) {
126+
my $acct = Koha::MarcOrderAccounts->find($acct_id);
127+
if ($acct) {
128+
$template->param( account => $acct );
129+
}
130+
}
131+
return;
132+
}

0 commit comments

Comments
 (0)