X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=serials%2Fserials-edit.pl;h=b80fa46f21d9e5d69ee305ca9423ca19cd6113eb;hb=9d9ecdc49b4cb71aba99a7d7ca8bc89d426f7ca1;hp=9ecd09fe91ed08e9edb885fc6e8797dc0e606bd0;hpb=481f620455d40f93a3cb37136ef2c3964497751e;p=koha-ffzg.git diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index 9ecd09fe91..b80fa46f21 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -5,18 +5,18 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . =head1 NAME @@ -61,28 +61,33 @@ op can be : =cut -use strict; -use warnings; -use CGI; -use C4::Auth; -use C4::Dates qw/format_date format_date_in_iso/; -use C4::Biblio; -use C4::Items; -use C4::Koha; -use C4::Output; +use Modern::Perl; +use CGI qw ( -utf8 ); +use Encode; +use C4::Auth qw( get_template_and_user haspermission ); +use C4::Biblio qw( GetMarcFromKohaField TransformHtmlToXml ); +use C4::Items qw( AddItemFromMarc ModItemFromMarc PrepareItemrecordDisplay ); +use C4::Output qw( output_html_with_http_headers ); use C4::Context; -use C4::Serials; -use List::MoreUtils qw/uniq/; +use C4::Serials qw( GetSerials GetSerials2 GetSerialInformation HasSubscriptionExpired GetSubscription abouttoexpire NewIssue ModSerialStatus GetPreviousSerialid AddItem2Serial ); +use C4::Search qw( enabled_staff_search_views ); + +use Koha::DateUtils qw( dt_from_string ); +use Koha::Items; +use Koha::Serial::Items; + +use List::MoreUtils qw( uniq ); my $query = CGI->new(); my $dbh = C4::Context->dbh; -my @serialids = $query->param('serialid'); -my @serialseqs = $query->param('serialseq'); -my @planneddates = $query->param('planneddate'); -my @publisheddates = $query->param('publisheddate'); -my @status = $query->param('status'); -my @notes = $query->param('notes'); -my @subscriptionids = $query->param('subscriptionid'); +my @serialids = $query->multi_param('serialid'); +my @serialseqs = $query->multi_param('serialseq'); +my @planneddates = $query->multi_param('planneddate'); +my @publisheddates = $query->multi_param('publisheddate'); +my @publisheddatetexts = $query->multi_param('publisheddatetext'); +my @status = $query->multi_param('status'); +my @notes = $query->multi_param('notes'); +my @subscriptionids = $query->multi_param('subscriptionid'); my $op = $query->param('op'); if ( scalar(@subscriptionids) == 1 && index( $subscriptionids[0], q|,| ) > 0 ) { @subscriptionids = split( /,/, $subscriptionids[0] ); @@ -93,9 +98,10 @@ my @errseq; # If user comes from subscription details unless (@serialids) { my $serstatus = $query->param('serstatus'); + my @statuses = split ',', $serstatus; if ($serstatus) { foreach my $subscriptionid (@subscriptionids) { - my @tmpser = GetSerials2( $subscriptionid, $serstatus ); + my @tmpser = GetSerials2( $subscriptionid, \@statuses ); push @serialids, map { $_->{serialid} } @tmpser; } } @@ -107,23 +113,23 @@ unless ( @serialids ) { $string =~ s/,$//; print $query->redirect($string); + exit; } my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => 'serials/serials-edit.tmpl', + template_name => 'serials/serials-edit.tt', query => $query, type => 'intranet', - authnotrequired => 0, - flagsrequired => { serials => 1 }, - debug => 1, + flagsrequired => { serials => 'receive_serials' }, } ); my @serialdatalist; my %processedserialid; -my $today = C4::Dates->new(); +my $today = dt_from_string; + foreach my $serialid (@serialids) { #filtering serialid for duplication @@ -133,15 +139,8 @@ foreach my $serialid (@serialids) { && !$processedserialid{$serialid} ) { my $serinfo = GetSerialInformation($serialid); #TODO duplicates work done by GetSerials2 above - for my $d ( qw( publisheddate planneddate )){ - if ( $serinfo->{$d} =~m/^00/ ) { - $serinfo->{$d} = q{}; - } - else { - $serinfo->{$d} = format_date( $serinfo->{$d} ); - } - } - $serinfo->{arriveddate}=$today->output('syspref'); + + $serinfo->{arriveddate} = $today; $serinfo->{'editdisable'} = ( ( @@ -150,11 +149,13 @@ foreach my $serialid (@serialids) { ) || $serinfo->{'cannotedit'} ); + $serinfo->{editdisable} = 0 if C4::Auth::haspermission( C4::Context->userenv->{id}, { serials => 'receive_serials' } ); + $serinfo->{editdisable} ||= ($serinfo->{status8} and $serinfo->{closed}); push @serialdatalist, $serinfo; $processedserialid{$serialid} = 1; } } -my $biblio = GetBiblioData( $serialdatalist[0]->{'biblionumber'} ); +my $biblio = Koha::Biblios->find( $serialdatalist[0]->{biblionumber} ); my @newserialloop; my @subscriptionloop; @@ -180,7 +181,7 @@ foreach my $subscriptionid (@subscriptionids) { $cell->{'itemid'} = 'NNEW'; $cell->{'serialid'} = 'NEW'; $cell->{'issuesatonce'} = 1; - $cell->{arriveddate}=$today->output('syspref'); + $cell->{arriveddate} = $today; push @newserialloop, $cell; push @subscriptionloop, @@ -199,7 +200,7 @@ if ( $op and $op eq 'serialchangestatus' ) { # Convert serialseqs to UTF-8 to prevent encoding problems foreach my $seq (@serialseqs) { - utf8::decode($seq) unless utf8::is_utf8($seq); + $seq = Encode::decode('UTF-8', $seq) unless Encode::is_utf8($seq); } my $newserial; @@ -207,10 +208,10 @@ if ( $op and $op eq 'serialchangestatus' ) { my ($plan_date, $pub_date); if (defined $planneddates[$i] && $planneddates[$i] ne 'XXX') { - $plan_date = format_date_in_iso( $planneddates[$i] ); + $plan_date = $planneddates[$i]; } if (defined $publisheddates[$i] && $publisheddates[$i] ne 'XXX') { - $pub_date = format_date_in_iso( $publisheddates[$i] ); + $pub_date = $publisheddates[$i]; } if ( $serialids[$i] && $serialids[$i] eq 'NEW' ) { @@ -225,7 +226,9 @@ if ( $op and $op eq 'serialchangestatus' ) { $status[$i], $plan_date, $pub_date, - $notes[$i] + $publisheddatetexts[$i], + $notes[$i], + $serialdatalist[0]->{'routingnotes'} ); } } @@ -235,26 +238,51 @@ if ( $op and $op eq 'serialchangestatus' ) { $serialseqs[$i], $plan_date, $pub_date, + $publisheddatetexts[$i], $status[$i], $notes[$i] ); } + my $makePreviousSerialAvailable = C4::Context->preference('makePreviousSerialAvailable'); + if ($makePreviousSerialAvailable && $serialids[$i] ne "NEW") { + # We already have created the new expected serial at this point, so we get the second previous serial + my $previous = GetPreviousSerialid($subscriptionids[$i]); + if ($previous) { + + my $serialitem = Koha::Serial::Items->search( {serialid => $previous} )->next; + my $itemnumber = $serialitem ? $serialitem->itemnumber : undef; + if ($itemnumber) { + + # Getting the itemtype to set from the database + my $subscriptioninfos = GetSubscription($subscriptionids[$i]); + + # Changing the status to "available" and the itemtype according to the previousitemtype db field + my $item = Koha::Items->find($itemnumber); + $item->set( + { + notforloan => 0, + itype => $subscriptioninfos->{'previousitemtype'} + } + )->store; + } + } + } + } - my @moditems = $query->param('moditem'); + my @moditems = $query->multi_param('moditem'); if ( scalar(@moditems) ) { - my @tags = $query->param('tag'); - my @subfields = $query->param('subfield'); - my @field_values = $query->param('field_value'); - my @serials = $query->param('serial'); - my @bibnums = $query->param('bibnum'); - my @itemid = $query->param('itemid'); - my @ind_tag = $query->param('ind_tag'); - my @indicator = $query->param('indicator'); + my @tags = $query->multi_param('tag'); + my @subfields = $query->multi_param('subfield'); + my @field_values = $query->multi_param('field_value'); + my @serials = $query->multi_param('serial'); + my @bibnums = $query->multi_param('bibnum'); + my @itemid = $query->multi_param('itemid'); + my @num_copies = $query->multi_param('number_of_copies'); #Rebuilding ALL the data for items into a hash # parting them on $itemid. my %itemhash; - my $countdistinct; + my $countdistinct = 0; my $range = scalar(@itemid); for ( my $i = 0 ; $i < $range ; $i++ ) { unless ( $itemhash{ $itemid[$i] } ) { @@ -268,14 +296,13 @@ if ( $op and $op eq 'serialchangestatus' ) { $itemhash{ $itemid[$i] }->{'serial'} = $newserial; } $itemhash{ $itemid[$i] }->{'bibnum'} = $bibnums[$countdistinct]; + $itemhash{ $itemid[$i] }->{'num_copies'} = $num_copies[$countdistinct]; $countdistinct++; } push @{ $itemhash{ $itemid[$i] }->{'tags'} }, $tags[$i]; push @{ $itemhash{ $itemid[$i] }->{'subfields'} }, $subfields[$i]; push @{ $itemhash{ $itemid[$i] }->{'field_values'} }, $field_values[$i]; - push @{ $itemhash{ $itemid[$i] }->{'ind_tag'} }, $ind_tag[$i]; - push @{ $itemhash{ $itemid[$i] }->{'indicator'} }, $indicator[$i]; } foreach my $item ( keys %itemhash ) { @@ -295,54 +322,56 @@ if ( $op and $op eq 'serialchangestatus' ) { $itemhash{$item}->{'tags'}, $itemhash{$item}->{'subfields'}, $itemhash{$item}->{'field_values'}, - $itemhash{$item}->{'indicator'}, - $itemhash{$item}->{'ind_tag'} + undef, + undef ); - # warn $xml; + # warn $xml; my $bib_record = MARC::Record::new_from_xml( $xml, 'UTF-8' ); if ( $item =~ /^N/ ) { - #New Item + $itemhash{$item}->{'num_copies'} //= 1; + + for (my $copy = 0; $copy < $itemhash{$item}->{'num_copies'};){ + + # New Item # if autoBarcode is set to 'incremental', calculate barcode... - my ( $barcodetagfield, $barcodetagsubfield ) = - GetMarcFromKohaField( - 'items.barcode', - GetFrameworkCode( - $serialdatalist[0]->{'biblionumber'} - ) - ); + my ( $barcodetagfield, $barcodetagsubfield ) = GetMarcFromKohaField( 'items.barcode' ); if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { - if ( !$bib_record->field($barcodetagfield) - ->subfield($barcodetagsubfield) ) + if ( + !( + $bib_record->field($barcodetagfield) + && $bib_record->field($barcodetagfield)->subfield($barcodetagsubfield) + ) + ) { my $sth_barcode = $dbh->prepare( 'select max(abs(barcode)) from items'); $sth_barcode->execute; my ($newbarcode) = $sth_barcode->fetchrow; -# OK, we have the new barcode, add the entry in MARC record # FIXME -> should be using barcode plugin here. - $bib_record->field($barcodetagfield) - ->update( $barcodetagsubfield => ++$newbarcode ); + # OK, we have the new barcode, add the entry in MARC record # FIXME -> should be using barcode plugin here. + $bib_record->field($barcodetagfield)->update( $barcodetagsubfield => ++$newbarcode ); } } # check for item barcode # being unique my $exists; - if ( - $bib_record->subfield( - $barcodetagfield, $barcodetagsubfield - ) - ) - { - $exists = GetItemnumberFromBarcode( - $bib_record->subfield( - $barcodetagfield, $barcodetagsubfield - ) - ); + if ( $bib_record->subfield( $barcodetagfield, $barcodetagsubfield ) ) { + my $barcode = $bib_record->subfield( $barcodetagfield, $barcodetagsubfield ); + + if ($copy > 0){ + use C4::Barcodes; + my $barcodeobj = C4::Barcodes->new; + my $newbarcode = $barcodeobj->next_value($barcode); + $barcode = $newbarcode; + $bib_record->field($barcodetagfield)->update($barcodetagsubfield => $barcode); + } + + $exists = Koha::Items->find({barcode => $barcode}); } # push @errors,"barcode_not_unique" if($exists); @@ -358,7 +387,11 @@ if ( $op and $op eq 'serialchangestatus' ) { AddItem2Serial( $itemhash{$item}->{serial}, $itemnumber ); } + $copy++; } + + } # if ( $item =~ /^N/ ) { + else { #modify item @@ -383,34 +416,18 @@ if ( $op and $op eq 'serialchangestatus' ) { print $query->redirect($redirect); } } -my $location = GetAuthorisedValues('LOC', $serialdatalist[0]->{'location'}); -my $locationlib; -foreach (@$location) { - $locationlib = $_->{'lib'} if $_->{'selected'}; -} -my $default_bib_view = get_default_view(); +my $location = $serialdatalist[0]->{'location'}; $template->param( + subscriptionid => $serialdatalist[0]->{subscriptionid}, serialsadditems => $serialdatalist[0]->{'serialsadditems'}, callnumber => $serialdatalist[0]->{'callnumber'}, - bibliotitle => $biblio->{'title'}, + internalnotes => $serialdatalist[0]->{'internalnotes'}, + bibliotitle => $biblio->title, biblionumber => $serialdatalist[0]->{'biblionumber'}, serialslist => \@serialdatalist, - default_bib_view => $default_bib_view, - location => $locationlib, + location => $location, + (uc(C4::Context->preference("marcflavour"))) => 1 + ); output_html_with_http_headers $query, $cookie, $template->output; - -sub get_default_view { - my $defaultview = C4::Context->preference('IntranetBiblioDefaultView'); - my $views = { C4::Search::enabled_staff_search_views }; - if ($defaultview eq 'isbd' && $views->{can_view_ISBD}) { - return 'ISBDdetail'; - } elsif ($defaultview eq 'marc' && $views->{can_view_MARC}) { - return 'MARCdetail'; - } elsif ($defaultview eq 'labeled_marc' && $views->{can_view_labeledMARC}) { - return 'labeledMARCdetail'; - } else { - return 'detail'; - } -}