From c9e6962fd4e692ccb1316253a57dc842fb6b89f9 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Sat, 29 Aug 2009 01:26:13 -0400 Subject: [PATCH] [18/40] Work on label item search. --- C4/Labels/Batch.pm | 51 ++-- C4/Labels/Lib.pm | 7 +- .../prog/en/css/staff-global.css | 18 ++ .../en/includes/labels-batches-toolbar.inc | 36 +++ .../prog/en/modules/labels/result.tmpl | 269 +++++++++--------- labels/label-edit-batch.pl | 18 +- labels/label-item-search.pl | 118 ++++---- 7 files changed, 285 insertions(+), 232 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc diff --git a/C4/Labels/Batch.pm b/C4/Labels/Batch.pm index 8972032fff..56c970c053 100644 --- a/C4/Labels/Batch.pm +++ b/C4/Labels/Batch.pm @@ -78,24 +78,29 @@ C4::Labels::Batch - A class for creating and manipulating batch objects in Koha =cut sub new { - my ($invocant, %params) = @_; + my ($invocant) = shift; my $type = ref($invocant) || $invocant; my $self = { batch_id => 0, items => [], branch_code => 'NB', batch_stat => 0, # False if any data has changed and the db has not been updated + @_, }; + my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM labels_batches;"); + $sth->execute(); + my $batch_id = $sth->fetchrow_array; + $self->{'batch_id'} = ++$batch_id; bless ($self, $type); return $self; } -=head2 $batch->add_item($item_number) +=head2 $batch->add_item(item_number => $item_number, branch_code => $branch_code) Invoking the I method will add the supplied item to the batch object. example: - $batch->add_item($item_number); + $batch->add_item(item_number => $item_number, branch_code => $branch_code); =cut @@ -105,12 +110,16 @@ sub add_item { my $query = "INSERT INTO labels_batches (batch_id, item_number, branch_code) VALUES (?,?,?);"; my $sth = C4::Context->dbh->prepare($query); # $sth->{'TraceLevel'} = 3; - $sth->execute($item_number, $self->{'batch_id'}); + $sth->execute($self->{'batch_id'}, $item_number, $self->{'branch_code'}); if ($sth->err) { syslog("LOG_ERR", "C4::Labels::Batch->add_item : Database returned the following error on attempted INSERT: %s", $sth->errstr); return -1; } - push (@{$self->{'items'}}, $item_number); + $query = "SELECT max(label_id) FROM labels_batches WHERE batch_id=? AND item_number=? AND branch_code=?;"; + my $sth1 = C4::Context->dbh->prepare($query); + $sth1->execute($self->{'batch_id'}, $item_number, $self->{'branch_code'}); + my $label_id = $sth1->fetchrow_array; + push (@{$self->{'items'}}, {item_number => $item_number, label_id => $label_id}); $self->{'batch_stat'} = 0; return 0; } @@ -140,16 +149,16 @@ sub get_attr { sub remove_item { my $self = shift; - my $item_number = shift; - my $query = "DELETE FROM labels_batches WHERE item_number=? AND batch_id=?;"; + my $label_id = shift; + my $query = "DELETE FROM labels_batches WHERE label_id=? AND batch_id=?;"; my $sth = C4::Context->dbh->prepare($query); # $sth->{'TraceLevel'} = 3; - $sth->execute($item_number, $self->{'batch_id'}); + $sth->execute($label_id, $self->{'batch_id'}); if ($sth->err) { syslog("LOG_ERR", "C4::Labels::Batch->remove_item : Database returned the following error on attempted DELETE: %s", $sth->errstr); return -1; } - @{$self->{'items'}} = grep{$_ != $item_number} @{$self->{'items'}}; + @{$self->{'items'}} = grep{$_->{'label_id'} != $label_id} @{$self->{'items'}}; $self->{'batch_stat'} = 1; return 0; } @@ -167,14 +176,10 @@ sub remove_item { sub save { my $self = shift; - my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM labels_batches;"); - $sth->execute(); - my $batch_id = $sth->fetchrow_array; - $self->{'batch_id'} = $batch_id++; foreach my $item_number (@{$self->{'items'}}) { my $query = "INSERT INTO labels_batches (batch_id, item_number, branch_code) VALUES (?,?,?);"; my $sth1 = C4::Context->dbh->prepare($query); - $sth1->execute($self->{'batch_id'}, $item_number, $self->{'branch_code'}); + $sth1->execute($self->{'batch_id'}, $item_number->{'item_number'}, $self->{'branch_code'}); if ($sth1->err) { syslog("LOG_ERR", "C4::Labels::Batch->save : Database returned the following error on attempted INSERT: %s", $sth1->errstr); return -1; @@ -199,20 +204,24 @@ sub retrieve { my $invocant = shift; my %opts = @_; my $type = ref($invocant) || $invocant; + my $record_flag = 0; my $query = "SELECT * FROM labels_batches WHERE batch_id = ? ORDER BY label_id"; my $sth = C4::Context->dbh->prepare($query); +# $sth->{'TraceLevel'} = 3; $sth->execute($opts{'batch_id'}); - if ($sth->err) { - syslog("LOG_ERR", "C4::Labels::Batch->retrieve : Database returned the following error on attempted SELECT: %s", $sth->errstr); - return 1; - } my $self = { - items => [], + batch_id => $opts{'batch_id'}, + items => [], }; while (my $record = $sth->fetchrow_hashref) { - $self->{'batch_id'} = $record->{'batch_id'}; # FIXME: seems a bit wasteful to re-initialize these every trip: is there a better way? $self->{'branch_code'} = $record->{'branch_code'}; - push (@{$self->{'items'}}, $record->{'item_number'}); + push (@{$self->{'items'}}, {item_number => $record->{'item_number'}, label_id => $record->{'label_id'}}); + $record_flag = 1; + } + return -2 if $record_flag == 0; # a hackish sort of way of indicating no such record exists + if ($sth->err) { + syslog("LOG_ERR", "C4::Labels::Batch->retrieve : Database returned the following error on attempted SELECT: %s", $sth->errstr); + return -1; } $self->{'batch_stat'} = 1; bless ($self, $type); diff --git a/C4/Labels/Lib.pm b/C4/Labels/Lib.pm index 7a2139c9bc..4a918ac28b 100644 --- a/C4/Labels/Lib.pm +++ b/C4/Labels/Lib.pm @@ -276,9 +276,9 @@ sub get_label_summary { my @label_summaries = (); my $query = "SELECT b.title, b.author, bi.itemtype, i.barcode, i.biblionumber FROM biblio AS b, biblioitems AS bi ,items AS i, labels_batches AS l WHERE itemnumber=? AND l.item_number=i.itemnumber AND i.biblioitemnumber=bi.biblioitemnumber AND bi.biblionumber=b.biblionumber AND l.batch_id=?;"; my $sth = C4::Context->dbh->prepare($query); - foreach my $item_number (@{$params{'items'}}) { + foreach my $item (@{$params{'items'}}) { $label_number++; - $sth->execute($item_number, $params{'batch_id'}); + $sth->execute($item->{'item_number'}, $params{'batch_id'}); if ($sth->err) { syslog("LOG_ERR", "C4::Labels::Lib::get_label_summary : Database returned the following error on attempted SELECT: %s", $sth->errstr); return -1; @@ -291,7 +291,8 @@ sub get_label_summary { $label_summary->{'_summary'} = $record->{'title'} . " | " . ($record->{'author'} ? $record->{'author'} : 'N/A'); $label_summary->{'_item_type'} = $record->{'itemtype'}; $label_summary->{'_barcode'} = $record->{'barcode'}; - $label_summary->{'_item_number'} = $item_number; + $label_summary->{'_item_number'} = $item->{'item_number'}; + $label_summary->{'_label_id'} = $item->{'label_id'}; push (@label_summaries, $label_summary); } return \@label_summaries; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index 25461dae0b..145c2bf697 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -227,6 +227,10 @@ table { border-right : 1px solid #BCBCBC; } +#label-search-results { + width: 700px; +} + td, th { border-bottom : 1px solid #BCBCBC; border-left : 1px solid #BCBCBC; @@ -1694,3 +1698,17 @@ span.permissiondesc { color: black; } +.hintsClass { + font-family: tahoma, verdana, arial; + font-size: 12px; + background-color: #f0f0f0; + color: #000000; + border: 1px solid #808080; + padding: 5px; +} +.hintSource { + color: green; + text-decoration: underline; + cursor: pointer; +} + diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc new file mode 100644 index 0000000000..38d92e322f --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/labels-batches-toolbar.inc @@ -0,0 +1,36 @@ +
+ + +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl index cae487c665..ac2ea7d01d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/result.tmpl @@ -1,143 +1,138 @@ -Koha › Barcodes and Labels › Search Results - - - + + ]]> + - -
-
-

Search results

- - - - - - -
,''); return false" />
- -" /> - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
- by
- [], , , ISBN: ,
+
+
+

Search results

+ + + +
+ ,''); return false" /> + +
+
+ Select All + + Clear All + +
+ " /> + + + + - - - - - - - - - - - - - - - - - - - - -
+ + by
+ [], , , ISBN: ,
SelectItem Call NumberDate AccessionedBarcode


- ',, ''); return false" href="/cgi-bin/koha/barcodes/label-manager.pl?itemnumber=&batch_id=&op=add">Add
- - -
- +
"> + ',, ''); return false" href="/cgi-bin/koha/barcodes/label-edit-batch.pl?op=add&batch_id=&item_number=">Add +
+ + +
- - - + diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index 08fad3e225..1b9d2d3c9a 100755 --- a/labels/label-edit-batch.pl +++ b/labels/label-edit-batch.pl @@ -27,6 +27,7 @@ use Switch qw(Perl6); use CGI; use HTML::Template::Pro; use Data::Dumper; +use JSON; use C4::Auth; use C4::Output; @@ -55,11 +56,12 @@ my $display_columns = [ {_label_number => {label => 'Label Number', link_field {_summary => {label => 'Summary', link_field => 0}}, {_item_type => {label => 'Item Type', link_field => 0}}, {_barcode => {label => 'Barcode', link_field => 0}}, - {select => {label => 'Select', value => '_item_number'}}, + {select => {label => 'Select', value => '_label_id'}}, ]; my $op = $cgi->param('op') || undef; my $label_id = $cgi->param('label_id') || undef; my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef; +my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number'); my $branch_code = get_branch_code_from_name($template->param('LoginBranchname')); if ($op eq 'remove') { @@ -71,7 +73,19 @@ elsif ($op eq 'delete') { $err = C4::Labels::Batch::delete(batch_id => $batch_id, branch_code => $branch_code); $errstr = "batch $batch_id was not deleted." if $err; } -else{ +elsif ($op eq 'add') { + $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); + $batch = C4::Labels::Batch->new(branch_code => $branch_code) if $batch == -2; + foreach my $item_number (@item_numbers) { + $err = $batch->add_item($item_number); + } + $errstr = "item(s) not added to batch $batch_id." if $err; +} +elsif ($op eq 'new') { + $batch = C4::Labels::Batch->new(branch_code => $branch_code); + $batch_id = $batch->get_attr('batch_id'); +} +else { # display batch $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); } diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index a04a9dc03a..52851dc378 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -21,8 +21,12 @@ use strict; use warnings; use CGI; -use C4::Auth; use HTML::Template::Pro; +use List::Util qw( max min ); +use POSIX; +use Data::Dumper; + +use C4::Auth; use C4::Context; use C4::Search; use C4::Auth; @@ -33,12 +37,8 @@ use C4::Acquisition; use C4::Search; use C4::Dates; use C4::Koha; # XXX subfield_is_koha_internal_p +use C4::Labels::Lib qw(html_table); use C4::Debug; -use List::Util qw( max min ); -use POSIX; - -#use Smart::Comments; -#use Data::Dumper; BEGIN { $debug = $debug || $cgi_debug; @@ -57,7 +57,7 @@ my $query = new CGI; my $type = $query->param('type'); my $op = $query->param('op') || ''; my $batch_id = $query->param('batch_id'); -my $ccl_query = $query->param('ccl_query'); +my $ccl_query = $query->param('ccl_query') || ''; my $dbh = C4::Context->dbh; @@ -69,10 +69,17 @@ my ( ); my $resultsperpage = C4::Context->preference('numSearchResults') || '20'; - my $show_results = 0; +my $display_columns = [ {_add => {label => "Add Item", link_field => 1}}, + {_item_call_number => {label => "Call Number", link_field => 0}}, + {_date_accessioned => {label => "Accession Date", link_field => 0}}, + {_barcode => {label => "Barcode", link_field => 0}}, + {select => {label => "Select", value => "_item_number"}}, + ]; + if ( $op eq "do_search" ) { + my @params = $query->param(); $idx = $query->param('idx'); $ccl_textbox = $query->param('ccl_textbox'); if ( $ccl_textbox && $idx ) { @@ -82,18 +89,6 @@ if ( $op eq "do_search" ) { $datefrom = $query->param('datefrom'); $dateto = $query->param('dateto'); - ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "labels/result.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => { borrowers => 1 }, - flagsrequired => { catalogue => 1 }, - debug => 1, - } - ); - if ($datefrom) { $datefrom = C4::Dates->new($datefrom); $ccl_query .= ' and ' if $ccl_textbox; @@ -111,7 +106,7 @@ if ( $op eq "do_search" ) { ( $error, $marcresults, $total_hits ) = SimpleSearch( $ccl_query, $offset, $resultsperpage ); - if ($marcresults) { + if (scalar($marcresults) > 0) { $show_results = scalar @$marcresults; } else { @@ -123,71 +118,55 @@ if ( $op eq "do_search" ) { if ($show_results) { my $hits = $show_results; - my ( @results, @items ); - + my @results_set = (); + my @items =(); # This code needs to be refactored using these subs... #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' ); #my $dat = &GetBiblioData( $biblio->{biblionumber} ); for ( my $i = 0 ; $i < $hits ; $i++ ) { - + my @row_data= (); #DEBUG Notes: Decode the MARC record from each resulting MARC record... my $marcrecord = MARC::File::USMARC::decode( $marcresults->[$i] ); - #DEBUG Notes: Transform it to Koha form... my $biblio = TransformMarcToKoha( C4::Context->dbh, $marcrecord, '' ); - -# Begin building the hash for the template... -# I don't think we need this with the current template design, but I'm leaving it in place. -fbcit -#$biblio->{highlight} = ($i % 2)?(1):(0); -#DEBUG Notes: Stuff the bib into @results... - push @results, $biblio; + #DEBUG Notes: Stuff the bib into @biblio_data... + push (@results_set, $biblio); my $biblionumber = $biblio->{'biblionumber'}; - #DEBUG Notes: Grab the item numbers associated with this MARC record... my $itemnums = get_itemnumbers_of($biblionumber); - #DEBUG Notes: Retrieve the item data for each number... - my $iii = $itemnums->{$biblionumber}; - if ($iii) { + if (my $iii = $itemnums->{$biblionumber}) { my $item_results = GetItemInfosOf(@$iii); foreach my $item ( keys %$item_results ) { - -#DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data... - if ( $item_results->{$item}->{'biblionumber'} eq - $results[$i]->{'biblionumber'} ) - { - -# NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered. -# This is a real hack, but I can't think of a better way right now. -fbcit -# It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility. - push @{ $results[$i]->{'item'} }, { i_itemnumber1 => - $item_results->{$item}->{'itemnumber'} }; - push @{ $results[$i]->{'item'} }, - { - i_itemcallnumber => ( - $item_results->{$item}->{'itemcallnumber'} - ? $item_results->{$item}->{'itemcallnumber'} - : 'NA' - ) - }; - push @{ $results[$i]->{'item'} }, { i_dateaccessioned => - $item_results->{$item}->{'dateaccessioned'} }; - push @{ $results[$i]->{'item'} }, - { - i_barcode => ( - $item_results->{$item}->{'barcode'} - ? $item_results->{$item}->{'barcode'} - : 'NA' - ) - }; - push @{ $results[$i]->{'item'} }, { i_itemnumber2 => - $item_results->{$item}->{'itemnumber'} }; + #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data... + if ($item_results->{$item}->{'biblionumber'} eq $results_set[$i]->{'biblionumber'}) { + my $item_data->{'_item_number'} = $item_results->{$item}->{'itemnumber'}; + $item_data->{'_item_call_number'} = ($item_results->{$item}->{'itemcallnumber'} ? $item_results->{$item}->{'itemcallnumber'} : 'NA'); + $item_data->{'_date_accessioned'} = $item_results->{$item}->{'dateaccessioned'}; + $item_data->{'_barcode'} = ( $item_results->{$item}->{'barcode'} ? $item_results->{$item}->{'barcode'} : 'NA'); + $item_data->{'_add'} = $item_results->{$item}->{'itemnumber'}; + unshift (@row_data, $item_data); # item numbers are given to us in descending order by get_itemnumbers_of()... } } + $results_set[$i]->{'item_table'} = html_table($display_columns, \@row_data); + } + else { + # FIXME: Some error trapping code needed + syslog("LOG_ERR", "labels/label-item-search.pl : No item numbers retrieved for biblio number: %s", $biblionumber); } } - $debug and warn "**********\@results**********\n"; - $debug and warn Dumper(@results); + + ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "labels/result.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { borrowers => 1 }, + flagsrequired => { catalogue => 1 }, + debug => 1, + } + ); # build page nav stuff. my ( @field_data, @numbers ); @@ -242,7 +221,8 @@ if ($show_results) { ); $template->param( - result => \@results, + results => ($show_results ? 1 : 0), + result_set=> \@results_set, batch_id => $batch_id, type => $type, idx => $idx, -- 2.39.5