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

(-)a/C4/ImportBatch.pm (-1 / +26 lines)
Lines 77-82 BEGIN { Link Here
77
    SetImportRecordStatus
77
    SetImportRecordStatus
78
    GetImportRecordMatches
78
    GetImportRecordMatches
79
    SetImportRecordMatches
79
    SetImportRecordMatches
80
    SetImportRecordBiblioMatch
80
	);
81
	);
81
}
82
}
82
83
Lines 1050-1056 sub GetImportRecordsRange { Link Here
1050
    my @params;
1051
    my @params;
1051
    push(@params, $batch_id);
1052
    push(@params, $batch_id);
1052
    if ($status) {
1053
    if ($status) {
1053
        $query .= " AND status=?";
1054
        $query .= " AND status=? OR status='imported'";
1054
        push(@params,$status);
1055
        push(@params,$status);
1055
    }
1056
    }
1056
1057
Lines 1400-1405 sub SetImportRecordMatches { Link Here
1400
    }
1401
    }
1401
}
1402
}
1402
1403
1404
=head SetImportRecordBiblioMatch
1405
1406
    SetImportRecordBiblioMatch( $import_record_id, $biblionumber, [$score] );
1407
1408
This sets the given Koha Biblio as a strong match for the given $import_record_id.
1409
This is useful for ex. when you add an item from a staged file. The old import_record persist
1410
and a new Biblio is created as a clone of the import_record. This function stores the strong
1411
relationship between import_record and Biblio.
1412
1413
@PARAM1 $import_record_id, the koha.import_record.import_record_id
1414
@PARAM2 $biblionumber, the new koha.biblio.biblionumber
1415
@PARAM3 $score, OPTIONAL, the matching score, higher is better. Defaults to 2000000000
1416
        Don't set it unless you have to.
1417
=cut
1418
1419
sub SetImportRecordBiblioMatch {
1420
    my ($import_record_id, $biblionumber, $score) = @_;
1421
1422
    my $matchedBiblioStub;
1423
    $matchedBiblioStub->{record_id} = $biblionumber;
1424
    $matchedBiblioStub->{score}     = ($score) ? $score : 2000000000; #koha.import_record_matches.score int(11) --so (almost) max it!
1425
    SetImportRecordMatches( $import_record_id, $matchedBiblioStub );
1426
}
1427
1403
1428
1404
# internal functions
1429
# internal functions
1405
1430
(-)a/C4/Items.pm (+25 lines)
Lines 64-69 BEGIN { Link Here
64
        GetLostItems
64
        GetLostItems
65
        GetItemsForInventory
65
        GetItemsForInventory
66
        GetItemsCount
66
        GetItemsCount
67
        GetItemsCountByBranch
67
        GetItemInfosOf
68
        GetItemInfosOf
68
        GetItemsByBiblioitemnumber
69
        GetItemsByBiblioitemnumber
69
        GetItemsInfo
70
        GetItemsInfo
Lines 1161-1166 sub GetItemsCount { Link Here
1161
    return ($count);
1162
    return ($count);
1162
}
1163
}
1163
1164
1165
=head GetItemsCountByBranch
1166
1167
    my $itemcountsByBranch = GetItemsCountByBranch( $biblionumber ); #GROUPS BY the homebranch
1168
    my $itemcountsByBranch = GetItemsCountByBranch( $biblionumber, 1 ); #GROUPS BY the holdingbranch
1169
    print $itemcountsByBranch->{ $branchcode }->{'count'}; # prints the count as an integer.
1170
1171
@PARAM1 $biblionumber, koha.biblio.biblionumber of the Biblios whose Items count is desired
1172
@PARAM2 OPTIONAL, Boolean, should we group the counts by homebranch (DEFAULT/FALSE) or the holdingbranch (TRUE)
1173
RETURNS hash of branchcodes with keys homebranch and count
1174
=cut
1175
1176
sub GetItemsCountByBranch {
1177
    my ( $biblionumber, $homeOrHoldingbranch ) = @_;
1178
    $homeOrHoldingbranch = ($homeOrHoldingbranch) ? 'holdingbranch' : 'homebranch';
1179
    my $dbh = C4::Context->dbh;
1180
    my $query = "SELECT $homeOrHoldingbranch, count(*) AS count
1181
          FROM  items 
1182
          WHERE biblionumber=? GROUP BY $homeOrHoldingbranch";
1183
    my $sth = $dbh->prepare($query);
1184
    $sth->execute($biblionumber);
1185
    my $count = $sth->fetchall_hashref($homeOrHoldingbranch);
1186
    return ($count);
1187
}
1188
1164
=head2 GetItemInfosOf
1189
=head2 GetItemInfosOf
1165
1190
1166
  GetItemInfosOf(@itemnumbers);
1191
  GetItemInfosOf(@itemnumbers);
(-)a/acqui/addorderiso2709.pl (-6 / +42 lines)
Lines 48-53 use C4::Members; Link Here
48
use Koha::Number::Price;
48
use Koha::Number::Price;
49
use Koha::Acquisition::Order;
49
use Koha::Acquisition::Order;
50
50
51
#my $batches = GetAllImportBatches();
52
#foreach my $b (@$batches) {
53
#    BatchFindDuplicates($b->{import_batch_id}, C4::Matcher->fetch(1), 1000, 1000, undef);
54
#}
55
51
my $input = new CGI;
56
my $input = new CGI;
52
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
57
my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
53
    template_name => "acqui/addorderiso2709.tt",
58
    template_name => "acqui/addorderiso2709.tt",
Lines 159-164 if ($op eq ""){ Link Here
159
    my $import_batch_id = $cgiparams->{'import_batch_id'};
164
    my $import_batch_id = $cgiparams->{'import_batch_id'};
160
    my $biblios = GetImportRecordsRange($import_batch_id);
165
    my $biblios = GetImportRecordsRange($import_batch_id);
161
    my @import_record_id_selected = $input->param("import_record_id");
166
    my @import_record_id_selected = $input->param("import_record_id");
167
    my @overlay = $input->param("overlay");
162
    my @quantities = $input->param('quantity');
168
    my @quantities = $input->param('quantity');
163
    my @prices = $input->param('price');
169
    my @prices = $input->param('price');
164
    my @budgets_id = $input->param('budget_id');
170
    my @budgets_id = $input->param('budget_id');
Lines 173-187 if ($op eq ""){ Link Here
173
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
179
        my $marcrecord = MARC::Record->new_from_usmarc($marcblob) || die "couldn't translate marc information";
174
        my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 );
180
        my $match = GetImportRecordMatches( $biblio->{'import_record_id'}, 1 );
175
        my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0;
181
        my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0;
182
        my $c_overlay = shift @overlay;
176
        my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
183
        my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
177
        my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
184
        my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
178
        my $c_discount = shift ( @discount);
185
        my $c_discount = shift ( @discount);
179
        $c_discount = $c_discount / 100 if $c_discount > 1;
186
        $c_discount = $c_discount / 100 if $c_discount && $c_discount > 1;
180
        my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
187
        my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
181
        my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
188
        my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
182
189
183
        # 1st insert the biblio, or find it through matcher
190
        # INSERT the biblio if no match found, or if we want to overlay the existing match
184
        unless ( $biblionumber ) {
191
        if ( not($biblionumber) || $c_overlay ) {
185
            # add the biblio
192
            # add the biblio
186
            my $bibitemnum;
193
            my $bibitemnum;
187
194
Lines 196-203 if ($op eq ""){ Link Here
196
                    }
203
                    }
197
                }
204
                }
198
            }
205
            }
199
            ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' );
206
            ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' ) unless $c_overlay;
207
            ModBiblio( $marcrecord, $biblionumber, $cgiparams->{'frameworkcode'} || '' ) if $c_overlay;
200
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
208
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
209
            
210
            #We need to provide information to koha.import_record_matches to tell Koha that this import_record matches the
211
            #just AddBiblio'd biblio. This is necessary to prevent adding the same import_record to koha.biblio many times.
212
            SetImportRecordBiblioMatch($biblio->{'import_record_id'}, $biblionumber);
213
            
201
            # 2nd add authorities if applicable
214
            # 2nd add authorities if applicable
202
            if (C4::Context->preference("BiblioAddsAuthorities")){
215
            if (C4::Context->preference("BiblioAddsAuthorities")){
203
                my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'});
216
                my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'});
Lines 270-277 if ($op eq ""){ Link Here
270
            my @serials      = $input->param('serial');
283
            my @serials      = $input->param('serial');
271
            my @indicator   = $input->param('indicator'); #Passing the imaginary empty "  " -indicators from the templates, to stop C4::Biblio::TransformHtmlToXml() to warn the bejesus out of my koha-error.log
284
            my @indicator   = $input->param('indicator'); #Passing the imaginary empty "  " -indicators from the templates, to stop C4::Biblio::TransformHtmlToXml() to warn the bejesus out of my koha-error.log
272
            my @ind_tag   = $input->param('ind_tag');
285
            my @ind_tag   = $input->param('ind_tag');
273
            my @indicator = $input->param('indicator');
286
            my $item; #WHAT IS THIS MADNESS??
274
            my $item;
275
            push @{ $item->{tags} },         $tags[0];
287
            push @{ $item->{tags} },         $tags[0];
276
            push @{ $item->{subfields} },    $subfields[0];
288
            push @{ $item->{subfields} },    $subfields[0];
277
            push @{ $item->{field_values} }, $field_values[0];
289
            push @{ $item->{field_values} }, $field_values[0];
Lines 403-408 sub import_biblios_list { Link Here
403
        $cellrecord{discount} = $discount || '';
415
        $cellrecord{discount} = $discount || '';
404
        $cellrecord{sort1} = $sort1 || '';
416
        $cellrecord{sort1} = $sort1 || '';
405
        $cellrecord{sort2} = $sort2 || '';
417
        $cellrecord{sort2} = $sort2 || '';
418
        
419
        get_matched_cellrecord_items( \%cellrecord );
420
        
406
421
407
        push @list, \%cellrecord;
422
        push @list, \%cellrecord;
408
    }
423
    }
Lines 464-469 sub add_matcher_list { Link Here
464
    $template->param(available_matchers => \@matchers);
479
    $template->param(available_matchers => \@matchers);
465
}
480
}
466
481
482
#Get the Items already in Koha for this import_record.
483
#A summary of them is displayed for the user.
484
sub get_matched_cellrecord_items {
485
    my $cellrecord = shift;
486
    
487
    if ($cellrecord->{match_biblionumber}) {
488
        my $itemsCountByBranch = C4::Items::GetItemsCountByBranch( $cellrecord->{match_biblionumber} );
489
        my $loginBranchcode = $template->{VARS}->{LoginBranchcode};
490
        my $totalItemsCount = 0;
491
        my @availabilityMap;
492
        foreach my $homebranch (sort keys %$itemsCountByBranch) {
493
            push (@availabilityMap, $homebranch.' = '.$itemsCountByBranch->{ $homebranch }->{ count });
494
            $totalItemsCount += $itemsCountByBranch->{ $homebranch }->{ count };
495
        }
496
        my $loginBranchcount = $itemsCountByBranch->{ $loginBranchcode }->{ count };
497
        $cellrecord->{loginBranchItemsCount} = $loginBranchcount || '0';
498
        $cellrecord->{totalItemsCount} = $totalItemsCount;
499
        $cellrecord->{availabilityMap} = join("\n", @availabilityMap);
500
    }
501
}
502
467
sub get_infos_syspref {
503
sub get_infos_syspref {
468
    my ($record, $field_list) = @_;
504
    my ($record, $field_list) = @_;
469
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
505
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
(-)a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css (+4 lines)
Lines 2714-2716 span.browse-button { Link Here
2714
#i18nMenu .dropdown-menu a:focus {
2714
#i18nMenu .dropdown-menu a:focus {
2715
    color : #FFF;
2715
    color : #FFF;
2716
}
2716
}
2717
2718
.matched_orderline {
2719
	background-color: #F0E8F9;
2720
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt (-7 / +10 lines)
Lines 187-195 Link Here
187
187
188
                        [% FOREACH biblio IN biblio_list %]
188
                        [% FOREACH biblio IN biblio_list %]
189
                        <fieldset class="biblio unselected rows" style="float:none;">
189
                        <fieldset class="biblio unselected rows" style="float:none;">
190
                          <legend>
190
                          <legend [% IF biblio.match_biblionumber %]class="matched_orderline"[% END %]>
191
                            <label for="record_[% biblio.import_record_id %]" style="width:auto;">
191
                            <label [% IF biblio.match_biblionumber %]title="[% biblio.availabilityMap %]"[% END %] for="record_[% biblio.import_record_id %]" style="width:auto;">
192
                              <input type="checkbox" name="import_record_id" id="record_[% biblio.import_record_id %]" value="[% biblio.import_record_id %]" />
192
                              <input type="checkbox" name="import_record_id" id="record_[% biblio.import_record_id %]" value="[% biblio.import_record_id %]" />
193
                              [% IF ( biblio.match_biblionumber ) %]
194
                                <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.match_biblionumber %]">[[% biblio.loginBranchItemsCount %]/[% biblio.totalItemsCount %]]</a>
195
                              [% END %]
193
                              <span class="citation">[% biblio.citation %]</span>
196
                              <span class="citation">[% biblio.citation %]</span>
194
                            </label>
197
                            </label>
195
                            <span class="links" style="font-weight: normal;">
198
                            <span class="links" style="font-weight: normal;">
Lines 199-215 Link Here
199
                          <ol>
202
                          <ol>
200
                            <li class="status">
203
                            <li class="status">
201
                              <span class="match">
204
                              <span class="match">
202
                                [% IF ( biblio_lis.overlay_status == 'no_match' ) %]
205
                                [% IF ( biblio.overlay_status == 'no_match' ) %]
203
                                    No match
206
                                    No match
204
                                [% ELSIF ( biblio_lis.overlay_status == 'match_applied' ) %]
207
                                [% ELSIF ( biblio.overlay_status == 'match_applied' ) %]
205
                                    Match applied
208
                                    Match applied
206
                                [% ELSIF ( biblio_lis.overlay_status == 'auto_match' ) %]
209
                                [% ELSIF ( biblio.overlay_status == 'auto_match' ) %]
207
                                    Match found
210
                                    Match found
208
                                [% ELSE %]
211
                                [% ELSE %]
209
                                    [% biblio_lis.overlay_status %]
212
                                    [% biblio.overlay_status %]
210
                                [% END %]
213
                                [% END %]
211
                                [% IF ( biblio.match_biblionumber ) %]
214
                                [% IF ( biblio.match_biblionumber ) %]
212
                                  Matches biblio [% biblio.match_biblionumber %] (score = [% biblio.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.match_biblionumber %]">[% biblio.match_citation %]</a>
215
                                  Matches biblio [% biblio.match_biblionumber %] (score = [% biblio.match_score %]): <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.match_biblionumber %]">[% biblio.match_citation %]</a>
216
                                  Overlay? <input type="checkbox" name="overlay" id="overlay_record_[% biblio.import_record_id %]" value="[% biblio.import_record_id %]" />
213
                                [% END %]
217
                                [% END %]
214
                              </span>
218
                              </span>
215
                            </li>
219
                            </li>
216
- 

Return to bug 13182