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

(-)a/C4/ImportBatch.pm (+25 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 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 (-2 / +31 lines)
Lines 176-182 if ($op eq ""){ Link Here
176
        my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
176
        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;
177
        my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
178
        my $c_discount = shift ( @discount);
178
        my $c_discount = shift ( @discount);
179
        $c_discount = $c_discount / 100 if $c_discount > 1;
179
        $c_discount = $c_discount / 100 if $c_discount && $c_discount > 1;
180
        my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
180
        my $c_sort1 = shift( @sort1 ) || $input->param('all_sort1') || '';
181
        my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
181
        my $c_sort2 = shift( @sort2 ) || $input->param('all_sort2') || '';
182
182
Lines 198-203 if ($op eq ""){ Link Here
198
            }
198
            }
199
            ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' );
199
            ( $biblionumber, $bibitemnum ) = AddBiblio( $marcrecord, $cgiparams->{'frameworkcode'} || '' );
200
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
200
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
201
            
202
            #We need to provide information to koha.import_record_matches to tell Koha that this import_record matches the
203
            #just AddBiblio'd biblio. This is necessary to prevent adding the same import_record to koha.biblio many times.
204
            SetImportRecordBiblioMatch($biblio->{'import_record_id'}, $biblionumber);
205
            
201
            # 2nd add authorities if applicable
206
            # 2nd add authorities if applicable
202
            if (C4::Context->preference("BiblioAddsAuthorities")){
207
            if (C4::Context->preference("BiblioAddsAuthorities")){
203
                my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'});
208
                my $headings_linked =BiblioAutoLink($marcrecord, $cgiparams->{'frameworkcode'});
Lines 358-364 sub import_biblios_list { Link Here
358
    my ($template, $import_batch_id) = @_;
363
    my ($template, $import_batch_id) = @_;
359
    my $batch = GetImportBatch($import_batch_id,'staged');
364
    my $batch = GetImportBatch($import_batch_id,'staged');
360
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
365
    return () unless $batch and $batch->{import_status} =~ /^staged$|^reverted$/;
361
    my $biblios = GetImportRecordsRange($import_batch_id,'','',$batch->{import_status});
366
    my $biblios = GetImportRecordsRange($import_batch_id,'','',undef);
362
    my @list = ();
367
    my @list = ();
363
368
364
    foreach my $biblio (@$biblios) {
369
    foreach my $biblio (@$biblios) {
Lines 403-408 sub import_biblios_list { Link Here
403
        $cellrecord{discount} = $discount || '';
408
        $cellrecord{discount} = $discount || '';
404
        $cellrecord{sort1} = $sort1 || '';
409
        $cellrecord{sort1} = $sort1 || '';
405
        $cellrecord{sort2} = $sort2 || '';
410
        $cellrecord{sort2} = $sort2 || '';
411
        
412
        get_matched_cellrecord_items( \%cellrecord );
413
        
406
414
407
        push @list, \%cellrecord;
415
        push @list, \%cellrecord;
408
    }
416
    }
Lines 464-469 sub add_matcher_list { Link Here
464
    $template->param(available_matchers => \@matchers);
472
    $template->param(available_matchers => \@matchers);
465
}
473
}
466
474
475
#Get the Items already in Koha for this import_record.
476
#A summary of them is displayed for the user.
477
sub get_matched_cellrecord_items {
478
    my $cellrecord = shift;
479
    
480
    if ($cellrecord->{match_biblionumber}) {
481
        my $itemsCountByBranch = C4::Items::GetItemsCountByBranch( $cellrecord->{match_biblionumber} );
482
        my $loginBranchcode = $template->{VARS}->{LoginBranchcode};
483
        my $totalItemsCount = 0;
484
        my @availabilityMap;
485
        foreach my $homebranch (sort keys %$itemsCountByBranch) {
486
            push (@availabilityMap, $homebranch.' = '.$itemsCountByBranch->{ $homebranch }->{ count });
487
            $totalItemsCount += $itemsCountByBranch->{ $homebranch }->{ count };
488
        }
489
        my $loginBranchcount = $itemsCountByBranch->{ $loginBranchcode }->{ count };
490
        $cellrecord->{loginBranchItemsCount} = $loginBranchcount || '0';
491
        $cellrecord->{totalItemsCount} = $totalItemsCount;
492
        $cellrecord->{availabilityMap} = join("\n", @availabilityMap);
493
    }
494
}
495
467
sub get_infos_syspref {
496
sub get_infos_syspref {
468
    my ($record, $field_list) = @_;
497
    my ($record, $field_list) = @_;
469
    my $syspref = C4::Context->preference('MarcFieldsToOrder');
498
    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 (-6 / +9 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-212 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>
(-)a/misc/maintenance/matchAllStagedRecords.pl (-1 / +34 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Getopt::Long;
5
6
use C4::ImportBatch;
7
use C4::Matcher;
8
9
10
my ($matcherid, $help);
11
my $result = GetOptions(
12
    'matcherid'   => \$matcherid,
13
    'help|h'      => \$help,
14
);
15
16
17
sub usage {
18
    print <<HELP;
19
    
20
    --matcherid  The id of the matcher to use to match ALL imported records.
21
    --help       This scrawny help.
22
    
23
HELP
24
    exit;
25
}
26
27
unless ($matcherid) {
28
    die "--matcherid not defined. You must use a matcher to match imported records against Biblios in the Catalog.";
29
}
30
31
my $batches = GetAllImportBatches();
32
foreach my $b (@$batches) {
33
    BatchFindDuplicates($b->{import_batch_id}, C4::Matcher->fetch($matcherid), 1000, 1000, undef);
34
}

Return to bug 13182