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

(-)a/acqui/addorderiso2709.pl (-70 / +93 lines)
Lines 28-35 use Encode; Link Here
28
use Scalar::Util qw( looks_like_number );
28
use Scalar::Util qw( looks_like_number );
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 128-153 if ($op eq ""){ Link Here
128
    $template->param('basketno' => $cgiparams->{'basketno'});
136
    $template->param('basketno' => $cgiparams->{'basketno'});
129
# Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
137
# Budget_id is mandatory for adding an order, we just add a default, the user needs to modify this aftewards
130
    my $budgets = GetBudgets();
138
    my $budgets = GetBudgets();
131
    if (scalar @$budgets == 0){
139
    if ( scalar @$budgets == 0 ) {
132
        die "No budgets defined, can't continue";
140
        die "No budgets defined, can't continue";
133
    }
141
    }
134
    my $budget_id = @$budgets[0]->{'budget_id'};
142
    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.
143
136
#(default values: quantity 1, uncertainprice yes, first budget)
144
    #get all records from a batch, and check their import status to see if they are checked.
145
    #(default values: quantity 1, uncertainprice yes, first budget)
137
146
138
    # retrieve the file you want to import
147
    # retrieve the file you want to import
139
    my $import_batch_id = $cgiparams->{'import_batch_id'};
148
    my $import_batch_id = $cgiparams->{'import_batch_id'};
140
    my $import_batch = Koha::ImportBatches->find( $import_batch_id );
149
    my $import_batch    = Koha::ImportBatches->find($import_batch_id);
141
    my $overlay_action = $import_batch->overlay_action;
150
    my $overlay_action  = $import_batch->overlay_action;
142
    my $import_records = Koha::Import::Records->search({
151
    my $import_records  = Koha::Import::Records->search(
143
        import_batch_id => $import_batch_id,
152
        {
144
    });
153
            import_batch_id => $import_batch_id,
154
        }
155
    );
145
    my $duplinbatch;
156
    my $duplinbatch;
146
    my $imported = 0;
157
    my $imported                  = 0;
147
    my @import_record_id_selected = $input->multi_param("import_record_id");
158
    my @import_record_id_selected = $input->multi_param("import_record_id");
148
    my $matcher_id = $input->param('matcher_id');
159
    my @quantities                = $input->multi_param('quantity');
149
    my $active_currency = Koha::Acquisition::Currencies->get_active;
160
    my @prices                    = $input->multi_param('price');
150
    while( my $import_record = $import_records->next ){
161
    my @orderreplacementprices    = $input->multi_param('replacementprice');
162
    my @budgets_id                = $input->multi_param('budget_id');
163
    my @discount                  = $input->multi_param('discount');
164
    my @sort1                     = $input->multi_param('sort1');
165
    my @sort2                     = $input->multi_param('sort2');
166
    my $matcher_id                = $input->param('matcher_id');
167
    my $active_currency           = Koha::Acquisition::Currencies->get_active;
168
169
    while ( my $import_record = $import_records->next ) {
151
        my $marcrecord        = $import_record->get_marc_record || die "couldn't translate marc information";
170
        my $marcrecord        = $import_record->get_marc_record || die "couldn't translate marc information";
152
        my @homebranches      = $input->multi_param( 'homebranch_' . $import_record->import_record_id );
171
        my @homebranches      = $input->multi_param( 'homebranch_' . $import_record->import_record_id );
153
        my @holdingbranches   = $input->multi_param( 'holdingbranch_' . $import_record->import_record_id );
172
        my @holdingbranches   = $input->multi_param( 'holdingbranch_' . $import_record->import_record_id );
Lines 212-254 if ($op eq ""){ Link Here
212
231
213
    # If all bibliographic records from the batch have been imported we modifying the status of the batch accordingly
232
    # If all bibliographic records from the batch have been imported we modifying the status of the batch accordingly
214
    SetImportBatchStatus( $import_batch_id, 'imported' )
233
    SetImportBatchStatus( $import_batch_id, 'imported' )
215
        if Koha::Import::Records->search({import_batch_id => $import_batch_id, status => 'imported' })->count
234
        if Koha::Import::Records->search( { import_batch_id => $import_batch_id, status => 'imported' } )->count ==
216
           == Koha::Import::Records->search({import_batch_id => $import_batch_id})->count;
235
        Koha::Import::Records->search( { import_batch_id => $import_batch_id } )->count;
217
236
218
    # go to basket page
237
    # go to basket page
219
    if ( $imported ) {
238
    if ($imported) {
220
        print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}."&duplinbatch=$duplinbatch");
239
        print $input->redirect(
240
            "/cgi-bin/koha/acqui/basket.pl?basketno=" . $cgiparams->{'basketno'} . "&duplinbatch=$duplinbatch" );
221
    } else {
241
    } else {
222
        print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno=".$cgiparams->{'basketno'}."&booksellerid=$booksellerid&allmatch=1");
242
        print $input->redirect( "/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&basketno="
243
                . $cgiparams->{'basketno'}
244
                . "&booksellerid=$booksellerid&allmatch=1" );
223
    }
245
    }
224
    exit;
246
    exit;
225
}
247
}
226
248
227
my $budgets = GetBudgets();
249
my $budgets   = GetBudgets();
228
my $budget_id = @$budgets[0]->{'budget_id'};
250
my $budget_id = @$budgets[0]->{'budget_id'};
251
229
# build bookfund list
252
# build bookfund list
230
my $patron = Koha::Patrons->find( $loggedinuser )->unblessed;
253
my $patron = Koha::Patrons->find($loggedinuser)->unblessed;
231
my $budget = GetBudget($budget_id);
254
my $budget = GetBudget($budget_id);
232
255
233
# build budget list
256
# build budget list
234
my $budget_loop = [];
257
my $budget_loop       = [];
235
my $budgets_hierarchy = GetBudgetHierarchy;
258
my $budgets_hierarchy = GetBudgetHierarchy;
236
foreach my $r ( @{$budgets_hierarchy} ) {
259
foreach my $r ( @{$budgets_hierarchy} ) {
237
    next unless (CanUserUseBudget($patron, $r, $userflags));
260
    next unless ( CanUserUseBudget( $patron, $r, $userflags ) );
238
    push @{$budget_loop},
261
    push @{$budget_loop},
239
      { b_id  => $r->{budget_id},
262
        {
240
        b_txt => $r->{budget_name},
263
        b_id            => $r->{budget_id},
241
        b_code => $r->{budget_code},
264
        b_txt           => $r->{budget_name},
265
        b_code          => $r->{budget_code},
242
        b_sort1_authcat => $r->{'sort1_authcat'},
266
        b_sort1_authcat => $r->{'sort1_authcat'},
243
        b_sort2_authcat => $r->{'sort2_authcat'},
267
        b_sort2_authcat => $r->{'sort2_authcat'},
244
        b_active => $r->{budget_period_active},
268
        b_active        => $r->{budget_period_active},
245
        b_sel => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
269
        b_sel           => ( $r->{budget_id} == $budget_id ) ? 1 : 0,
246
      };
270
        };
247
}
271
}
248
272
249
@{$budget_loop} =
273
@{$budget_loop} =
250
  sort { uc( $a->{b_txt}) cmp uc( $b->{b_txt}) } @{$budget_loop};
274
    sort { uc( $a->{b_txt} ) cmp uc( $b->{b_txt} ) } @{$budget_loop};
251
275
252
$template->param( budget_loop    => $budget_loop,);
276
$template->param( budget_loop => $budget_loop, );
253
277
254
output_html_with_http_headers $input, $cookie, $template->output;
278
output_html_with_http_headers $input, $cookie, $template->output;
255
- 

Return to bug 35026