View | Details | Raw Unified | Return to bug 35026
Collapse All | Expand All

(-)a/acqui/addorderiso2709.pl (-83 / +101 lines)
Lines 28-35 use List::MoreUtils; Link Here
28
use Encode;
28
use Encode;
29
29
30
use C4::Context;
30
use C4::Context;
31
use C4::Auth qw( get_template_and_user );
31
use C4::Auth        qw( get_template_and_user );
32
use C4::Output qw( output_html_with_http_headers );
32
use C4::Output      qw( output_html_with_http_headers );
33
use C4::ImportBatch qw( SetImportBatchStatus );
33
use C4::ImportBatch qw( SetImportBatchStatus );
34
use C4::Matcher;
34
use C4::Matcher;
35
use C4::Search qw( FindDuplicate );
35
use C4::Search qw( FindDuplicate );
Lines 40-46 use C4::Biblio qw( Link Here
40
    GetMarcQuantity
40
    GetMarcQuantity
41
    TransformHtmlToXml
41
    TransformHtmlToXml
42
);
42
);
43
use C4::Items qw( PrepareItemrecordDisplay AddItemFromMarc );
43
use C4::Items   qw( PrepareItemrecordDisplay AddItemFromMarc );
44
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget );
44
use C4::Budgets qw( GetBudget GetBudgets GetBudgetHierarchy CanUserUseBudget );
45
use C4::Suggestions;    # GetSuggestion
45
use C4::Suggestions;    # GetSuggestion
46
use C4::Members;
46
use C4::Members;
Lines 57-86 use Koha::Patrons; Link Here
57
use Koha::MarcOrder;
57
use Koha::MarcOrder;
58
58
59
my $input = CGI->new;
59
my $input = CGI->new;
60
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
60
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
61
    template_name => "acqui/addorderiso2709.tt",
61
    {
62
    query => $input,
62
        template_name => "acqui/addorderiso2709.tt",
63
    type => "intranet",
63
        query         => $input,
64
    flagsrequired   => { acquisition => 'order_manage' },
64
        type          => "intranet",
65
});
65
        flagsrequired => { acquisition => 'order_manage' },
66
66
    }
67
my $cgiparams = $input->Vars;
67
);
68
my $op = $cgiparams->{'op'} || '';
68
69
my $booksellerid  = $input->param('booksellerid');
69
my $cgiparams    = $input->Vars;
70
my $allmatch = $input->param('allmatch');
70
my $op           = $cgiparams->{'op'} || '';
71
my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
71
my $booksellerid = $input->param('booksellerid');
72
72
my $allmatch     = $input->param('allmatch');
73
$template->param(scriptname => "/cgi-bin/koha/acqui/addorderiso2709.pl",
73
my $bookseller   = Koha::Acquisition::Booksellers->find($booksellerid);
74
                booksellerid => $booksellerid,
74
75
                booksellername => $bookseller->name,
75
$template->param(
76
                );
76
    scriptname     => "/cgi-bin/koha/acqui/addorderiso2709.pl",
77
77
    booksellerid   => $booksellerid,
78
if ($cgiparams->{'import_batch_id'} && $op eq ""){
78
    booksellername => $bookseller->name,
79
);
80
81
if ( $cgiparams->{'import_batch_id'} && $op eq "" ) {
79
    $op = "batch_details";
82
    $op = "batch_details";
80
}
83
}
81
84
82
#Needed parameters:
85
#Needed parameters:
83
if (! $cgiparams->{'basketno'}){
86
if ( !$cgiparams->{'basketno'} ) {
84
    die "Basketnumber required to order from iso2709 file import";
87
    die "Basketnumber required to order from iso2709 file import";
85
}
88
}
86
my $basket = Koha::Acquisition::Baskets->find( $cgiparams->{basketno} );
89
my $basket = Koha::Acquisition::Baskets->find( $cgiparams->{basketno} );
Lines 88-112 my $basket = Koha::Acquisition::Baskets->find( $cgiparams->{basketno} ); Link Here
88
#
91
#
89
# 1st step = choose the file to import into acquisition
92
# 1st step = choose the file to import into acquisition
90
#
93
#
91
if ($op eq ""){
94
if ( $op eq "" ) {
92
    $template->param("basketno" => $cgiparams->{'basketno'});
95
    $template->param( "basketno" => $cgiparams->{'basketno'} );
93
#display batches
96
97
    #display batches
94
    Koha::MarcOrder->import_batches_list($template);
98
    Koha::MarcOrder->import_batches_list($template);
95
#
99
    #
96
# 2nd step = display the content of the chosen file
100
    # 2nd step = display the content of the chosen file
97
#
101
    #
98
} elsif ($op eq "batch_details"){
102
} elsif ( $op eq "batch_details" ) {
99
#display lines inside the selected batch
103
100
104
    #display lines inside the selected batch
101
    $template->param("batch_details" => 1,
105
102
                     "basketno"      => $cgiparams->{'basketno'},
106
    $template->param(
103
                     # get currencies (for change rates calcs if needed)
107
        "batch_details" => 1,
104
                     currencies => Koha::Acquisition::Currencies->search,
108
        "basketno"      => $cgiparams->{'basketno'},
105
                     bookseller => $bookseller,
109
106
                     "allmatch" => $allmatch,
110
        # get currencies (for change rates calcs if needed)
107
                     );
111
        currencies => Koha::Acquisition::Currencies->search,
108
    Koha::MarcOrder->import_biblios_list($template, $cgiparams->{'import_batch_id'});
112
        bookseller => $bookseller,
113
        "allmatch" => $allmatch,
114
    );
115
    Koha::MarcOrder->import_biblios_list( $template, $cgiparams->{'import_batch_id'} );
109
    if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) {
116
    if ( $basket->effective_create_items eq 'ordering' && !$basket->is_standing ) {
117
110
        # prepare empty item form
118
        # prepare empty item form
111
        my $cell = PrepareItemrecordDisplay( '', '', undef, 'ACQ' );
119
        my $cell = PrepareItemrecordDisplay( '', '', undef, 'ACQ' );
112
120
Lines 120-160 if ($op eq ""){ Link Here
120
128
121
        $template->param( items => \@itemloop );
129
        $template->param( items => \@itemloop );
122
    }
130
    }
123
#
131
    #
124
# 3rd step = import the records
132
    # 3rd step = import the records
125
#
133
    #
126
} elsif ( $op eq 'import_records' ) {
134
} elsif ( $op eq 'import_records' ) {
127
#import selected lines
135
128
    $template->param('basketno' => $cgiparams->{'basketno'});
136
    #import selected lines
129
# Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
137
    $template->param( 'basketno' => $cgiparams->{'basketno'} );
138
139
    # Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
130
    my $budgets = GetBudgets();
140
    my $budgets = GetBudgets();
131
    if (scalar @$budgets == 0){
141
    if ( scalar @$budgets == 0 ) {
132
        die "No budgets defined, can't continue";
142
        die "No budgets defined, can't continue";
133
    }
143
    }
134
    my $budget_id = @$budgets[0]->{'budget_id'};
144
    my $budget_id = @$budgets[0]->{'budget_id'};
135
#get all records from a batch, and check their import status to see if they are checked.
145
136
#(default values: quantity 1, uncertainprice yes, first budget)
146
    #get all records from a batch, and check their import status to see if they are checked.
147
    #(default values: quantity 1, uncertainprice yes, first budget)
137
148
138
    # retrieve the file you want to import
149
    # retrieve the file you want to import
139
    my $import_batch_id = $cgiparams->{'import_batch_id'};
150
    my $import_batch_id = $cgiparams->{'import_batch_id'};
140
    my $import_batch = Koha::ImportBatches->find( $import_batch_id );
151
    my $import_batch    = Koha::ImportBatches->find($import_batch_id);
141
    my $overlay_action = $import_batch->overlay_action;
152
    my $overlay_action  = $import_batch->overlay_action;
142
    my $import_records = Koha::Import::Records->search({
153
    my $import_records  = Koha::Import::Records->search(
143
        import_batch_id => $import_batch_id,
154
        {
144
    });
155
            import_batch_id => $import_batch_id,
156
        }
157
    );
145
    my $duplinbatch;
158
    my $duplinbatch;
146
    my $imported = 0;
159
    my $imported                  = 0;
147
    my @import_record_id_selected = $input->multi_param("import_record_id");
160
    my @import_record_id_selected = $input->multi_param("import_record_id");
148
    my @quantities = $input->multi_param('quantity');
161
    my @quantities                = $input->multi_param('quantity');
149
    my @prices = $input->multi_param('price');
162
    my @prices                    = $input->multi_param('price');
150
    my @orderreplacementprices = $input->multi_param('replacementprice');
163
    my @orderreplacementprices    = $input->multi_param('replacementprice');
151
    my @budgets_id = $input->multi_param('budget_id');
164
    my @budgets_id                = $input->multi_param('budget_id');
152
    my @discount = $input->multi_param('discount');
165
    my @discount                  = $input->multi_param('discount');
153
    my @sort1 = $input->multi_param('sort1');
166
    my @sort1                     = $input->multi_param('sort1');
154
    my @sort2 = $input->multi_param('sort2');
167
    my @sort2                     = $input->multi_param('sort2');
155
    my $matcher_id = $input->param('matcher_id');
168
    my $matcher_id                = $input->param('matcher_id');
156
    my $active_currency = Koha::Acquisition::Currencies->get_active;
169
    my $active_currency           = Koha::Acquisition::Currencies->get_active;
157
    while( my $import_record = $import_records->next ){
170
171
    while ( my $import_record = $import_records->next ) {
158
        my $marcrecord        = $import_record->get_marc_record || die "couldn't translate marc information";
172
        my $marcrecord        = $import_record->get_marc_record || die "couldn't translate marc information";
159
        my @homebranches      = $input->multi_param( 'homebranch_' . $import_record->import_record_id );
173
        my @homebranches      = $input->multi_param( 'homebranch_' . $import_record->import_record_id );
160
        my @holdingbranches   = $input->multi_param( 'holdingbranch_' . $import_record->import_record_id );
174
        my @holdingbranches   = $input->multi_param( 'holdingbranch_' . $import_record->import_record_id );
Lines 219-261 if ($op eq ""){ Link Here
219
233
220
    # If all bibliographic records from the batch have been imported we modifying the status of the batch accordingly
234
    # If all bibliographic records from the batch have been imported we modifying the status of the batch accordingly
221
    SetImportBatchStatus( $import_batch_id, 'imported' )
235
    SetImportBatchStatus( $import_batch_id, 'imported' )
222
        if Koha::Import::Records->search({import_batch_id => $import_batch_id, status => 'imported' })->count
236
        if Koha::Import::Records->search( { import_batch_id => $import_batch_id, status => 'imported' } )->count ==
223
           == Koha::Import::Records->search({import_batch_id => $import_batch_id})->count;
237
        Koha::Import::Records->search( { import_batch_id => $import_batch_id } )->count;
224
238
225
    # go to basket page
239
    # go to basket page
226
    if ( $imported ) {
240
    if ($imported) {
227
        print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}."&duplinbatch=$duplinbatch");
241
        print $input->redirect(
242
            "/cgi-bin/koha/acqui/basket.pl?basketno=" . $cgiparams->{'basketno'} . "&duplinbatch=$duplinbatch" );
228
    } else {
243
    } else {
229
        print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=".$cgiparams->{'basketno'}."&booksellerid=$booksellerid&allmatch=1");
244
        print $input->redirect( "/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno="
245
                . $cgiparams->{'basketno'}
246
                . "&booksellerid=$booksellerid&allmatch=1" );
230
    }
247
    }
231
    exit;
248
    exit;
232
}
249
}
233
250
234
my $budgets = GetBudgets();
251
my $budgets   = GetBudgets();
235
my $budget_id = @$budgets[0]->{'budget_id'};
252
my $budget_id = @$budgets[0]->{'budget_id'};
253
236
# build bookfund list
254
# build bookfund list
237
my $patron = Koha::Patrons->find( $loggedinuser )->unblessed;
255
my $patron = Koha::Patrons->find($loggedinuser)->unblessed;
238
my $budget = GetBudget($budget_id);
256
my $budget = GetBudget($budget_id);
239
257
240
# build budget list
258
# build budget list
241
my $budget_loop = [];
259
my $budget_loop       = [];
242
my $budgets_hierarchy = GetBudgetHierarchy;
260
my $budgets_hierarchy = GetBudgetHierarchy;
243
foreach my $r ( @{$budgets_hierarchy} ) {
261
foreach my $r ( @{$budgets_hierarchy} ) {
244
    next unless (CanUserUseBudget($patron, $r, $userflags));
262
    next unless ( CanUserUseBudget( $patron, $r, $userflags ) );
245
    push @{$budget_loop},
263
    push @{$budget_loop},
246
      { b_id  => $r->{budget_id},
264
        {
247
        b_txt => $r->{budget_name},
265
        b_id            => $r->{budget_id},
248
        b_code => $r->{budget_code},
266
        b_txt           => $r->{budget_name},
267
        b_code          => $r->{budget_code},
249
        b_sort1_authcat => $r->{'sort1_authcat'},
268
        b_sort1_authcat => $r->{'sort1_authcat'},
250
        b_sort2_authcat => $r->{'sort2_authcat'},
269
        b_sort2_authcat => $r->{'sort2_authcat'},
251
        b_active => $r->{budget_period_active},
270
        b_active        => $r->{budget_period_active},
252
        b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
271
        b_sel           => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
253
      };
272
        };
254
}
273
}
255
274
256
@{$budget_loop} =
275
@{$budget_loop} =
257
  sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
276
    sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @{$budget_loop};
258
277
259
$template->param( budget_loop    => $budget_loop,);
278
$template->param( budget_loop => $budget_loop, );
260
279
261
output_html_with_http_headers $input, $cookie, $template->output;
280
output_html_with_http_headers $input, $cookie, $template->output;
262
- 

Return to bug 35026