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