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

(-)a/C4/Biblio.pm (-1 / +92 lines)
Lines 97-102 BEGIN { Link Here
97
      &TransformKohaToMarc
97
      &TransformKohaToMarc
98
      &PrepHostMarcField
98
      &PrepHostMarcField
99
99
100
      &UpdateDatereceived
100
      &CountItemsIssued
101
      &CountItemsIssued
101
      &CountBiblioInOrders
102
      &CountBiblioInOrders
102
      &GetSubscriptionsId
103
      &GetSubscriptionsId
Lines 2210-2215 sub GetFrameworkCode { Link Here
2210
    return $frameworkcode;
2211
    return $frameworkcode;
2211
}
2212
}
2212
2213
2214
=head UpdateDatereceived
2215
2216
    my $error = C4::Biblio::UpdateDatereceived($bibliodataOrBiblionumber, $datereceived, $record);
2217
    my $error = C4::Biblio::UpdateDatereceived({biblionumber => 1213, datereceived => '2014-12-10 10:12:33', ...}, DateTime, MARC::Record);
2218
2219
Updates the biblioitems.datereceived and the corresponding MARC-Subfield if the datereceived
2220
hasn't been set for this Biblio yet. Datereceived for the Biblio is the first moment
2221
the Biblio became available for the library and shouldn't be updated for subsequent receivals.
2222
2223
@PARAM1 MANDATORY
2224
        Integer, koha.biblio.biblionumber
2225
        OR
2226
        Hash, Like returned by C4::Biblio::GetBiblioData().
2227
              biblionumber must be a hash key!
2228
              datereceived must be present as well, otherwise the koha.biblioitems.datereceived
2229
              will be overwritten, unless this is intended.
2230
@PARAM2 OPTIONAL
2231
        DateTime-object, of the moment of receival.
2232
        Defaults to Now() if not given.
2233
@PARAM3 OPTIONAL
2234
        MARC::Record, of the biblio to be updated.
2235
        By default is fetched using the supplied biblionumber.
2236
@RETURNS String, error code:
2237
                 'NO_BIBLIODATA', couldn't find the koha.biblioitems-row
2238
                 'NO_BIBLIONUMBER', no biblionumber given as parameter or couldn't
2239
                                    find it from the Hash
2240
                 'NOT_DATETIME', $datereceived is not a DateTime-object
2241
                 'NO_RECORD', The given MARC::Record is invalid, or no MARC Record
2242
                              could be found using the supplied biblionumber.
2243
                 'MODBIBLIO_ERROR', C4::Biblio::ModBiblio() failed.
2244
2245
=cut
2246
sub UpdateDatereceived {
2247
    my ($biblionumberOrBibliodata, $datereceived, $record) = @_;
2248
2249
    my $bibdata;
2250
    unless (ref $biblionumberOrBibliodata) { #We have a SCALAR, eg. a biblionumber.
2251
        my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber($biblionumberOrBibliodata);
2252
        $bibdata = $biblioitems[0];
2253
    }
2254
    else {
2255
        $bibdata = $biblionumberOrBibliodata;
2256
    }
2257
    return 'NO_BIBLIODATA' if (not($bibdata) && $biblionumberOrBibliodata);
2258
    return 'NO_BIBLIONUMBER' if (not($bibdata->{biblionumber}));
2259
2260
    if ($datereceived && ref $datereceived ne 'DateTime') {
2261
        return 'NOT_DATETIME';
2262
    }
2263
    #Use the given DateTime or Use Now()
2264
    $datereceived = ($datereceived) ? $datereceived->iso8601() : DateTime->now( time_zone => C4::Context->tz() )->iso8601();
2265
2266
    #Make sure to only update the datereceived for the Biblio if it hasn't been set yet.
2267
    if ($bibdata->{datereceived}) {
2268
        return undef; #All is OK and we will preserve the first moment of datereceived.
2269
    }
2270
2271
    if (not($record)) {
2272
        $record = C4::Biblio::GetMarcBiblio($bibdata->{biblionumber});
2273
    }
2274
    elsif (ref($record) ne 'MARC::Record') {
2275
        return 'NO_RECORD';
2276
    }
2277
    return 'NO_RECORD' unless $record;
2278
2279
    my $frameworkcode = ($bibdata->{frameworkcode}) ? $bibdata->{frameworkcode} : C4::Biblio::GetFrameworkCode($bibdata->{biblionumber});
2280
2281
    #Get the mapped MARC-fields for items.datereceived
2282
    my ( $datereceivedFieldCode, $datereceivedSubfieldCode ) =
2283
            C4::Biblio::GetMarcFromKohaField( "biblioitems.datereceived", $frameworkcode );
2284
    ( $datereceivedFieldCode, $datereceivedSubfieldCode ) =
2285
            C4::Biblio::GetMarcFromKohaField( "biblioitems.datereceived", '' ) unless ($datereceivedFieldCode);
2286
2287
    #UPSERT the datereceived DB column to MARC
2288
    my @existingFields = $record->field($datereceivedFieldCode);
2289
    if ($existingFields[0]) {
2290
        $existingFields[0]->update($datereceivedSubfieldCode => $datereceived);
2291
    }
2292
    else {
2293
        my $newField = MARC::Field->new($datereceivedFieldCode, '', '', $datereceivedSubfieldCode => $datereceived);
2294
        $record->insert_fields_ordered($newField);
2295
    }
2296
2297
    my $ok = C4::Biblio::ModBiblio($record, $bibdata->{biblionumber}, $frameworkcode);
2298
    return 'MODBIBLIO_ERROR' unless $ok;
2299
    return undef; #All is OK!
2300
}
2301
2302
2213
=head2 TransformKohaToMarc
2303
=head2 TransformKohaToMarc
2214
2304
2215
    $record = TransformKohaToMarc( $hash )
2305
    $record = TransformKohaToMarc( $hash )
Lines 3255-3260 sub _koha_modify_biblioitem_nonmarc { Link Here
3255
        issn            = ?,
3345
        issn            = ?,
3256
        publicationyear = ?,
3346
        publicationyear = ?,
3257
        publishercode   = ?,
3347
        publishercode   = ?,
3348
        datereceived    = ?,
3258
        volumedate      = ?,
3349
        volumedate      = ?,
3259
        volumedesc      = ?,
3350
        volumedesc      = ?,
3260
        collectiontitle = ?,
3351
        collectiontitle = ?,
Lines 3282-3288 sub _koha_modify_biblioitem_nonmarc { Link Here
3282
    my $sth = $dbh->prepare($query);
3373
    my $sth = $dbh->prepare($query);
3283
    $sth->execute(
3374
    $sth->execute(
3284
        $biblioitem->{'biblionumber'},     $biblioitem->{'volume'},           $biblioitem->{'number'},                $biblioitem->{'itemtype'},
3375
        $biblioitem->{'biblionumber'},     $biblioitem->{'volume'},           $biblioitem->{'number'},                $biblioitem->{'itemtype'},
3285
        $biblioitem->{'isbn'},             $biblioitem->{'issn'},             $biblioitem->{'publicationyear'},       $biblioitem->{'publishercode'},
3376
        $biblioitem->{'isbn'},             $biblioitem->{'issn'},             $biblioitem->{'publicationyear'},       $biblioitem->{'publishercode'},  $biblioitem->{datereceived},
3286
        $biblioitem->{'volumedate'},       $biblioitem->{'volumedesc'},       $biblioitem->{'collectiontitle'},       $biblioitem->{'collectionissn'},
3377
        $biblioitem->{'volumedate'},       $biblioitem->{'volumedesc'},       $biblioitem->{'collectiontitle'},       $biblioitem->{'collectionissn'},
3287
        $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'},
3378
        $biblioitem->{'collectionvolume'}, $biblioitem->{'editionstatement'}, $biblioitem->{'editionresponsibility'}, $biblioitem->{'illus'},
3288
        $biblioitem->{'pages'},            $biblioitem->{'bnotes'},           $biblioitem->{'size'},                  $biblioitem->{'place'},
3379
        $biblioitem->{'pages'},            $biblioitem->{'bnotes'},           $biblioitem->{'size'},                  $biblioitem->{'place'},
(-)a/C4/Items.pm (+2 lines)
Lines 2131-2136 sub _koha_new_item { Link Here
2131
            biblioitemnumber    = ?,
2131
            biblioitemnumber    = ?,
2132
            barcode             = ?,
2132
            barcode             = ?,
2133
            dateaccessioned     = ?,
2133
            dateaccessioned     = ?,
2134
            datereceived        = ?,
2134
            booksellerid        = ?,
2135
            booksellerid        = ?,
2135
            homebranch          = ?,
2136
            homebranch          = ?,
2136
            price               = ?,
2137
            price               = ?,
Lines 2173-2178 sub _koha_new_item { Link Here
2173
            $item->{'biblioitemnumber'},
2174
            $item->{'biblioitemnumber'},
2174
            $barcode,
2175
            $barcode,
2175
            $item->{'dateaccessioned'},
2176
            $item->{'dateaccessioned'},
2177
            $item->{'datereceived'},
2176
            $item->{'booksellerid'},
2178
            $item->{'booksellerid'},
2177
            $item->{'homebranch'},
2179
            $item->{'homebranch'},
2178
            $item->{'price'},
2180
            $item->{'price'},
(-)a/acqui/finishreceive.pl (+2 lines)
Lines 165-173 ModItem( Link Here
165
        price                => $unitprice,
165
        price                => $unitprice,
166
        replacementprice     => $rrp,
166
        replacementprice     => $rrp,
167
        replacementpricedate => $datereceived,
167
        replacementpricedate => $datereceived,
168
        datereceived         => DateTime->now( time_zone => C4::Context->tz() )->iso8601(),
168
    },
169
    },
169
    $biblionumber,
170
    $biblionumber,
170
    $_
171
    $_
171
) foreach GetItemnumbersFromOrder($new_ordernumber);
172
) foreach GetItemnumbersFromOrder($new_ordernumber);
173
C4::Biblio::UpdateDatereceived($biblionumber);
172
174
173
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
175
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoiceid=$invoiceid&sticky_filters=1");
(-)a/cataloguing/additem.pl (-1 / +19 lines)
Lines 451-456 if ($op eq "additem") { Link Here
451
        unless ($exist_itemnumber) {
451
        unless ($exist_itemnumber) {
452
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
452
            my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = AddItemFromMarc( $record, $biblionumber );
453
            set_item_default_location($oldbibitemnum);
453
            set_item_default_location($oldbibitemnum);
454
            my $err = C4::Biblio::UpdateDatereceived($biblionumber);
455
            push @errors, $err if $err;
454
456
455
            # Pushing the last created item cookie back
457
            # Pushing the last created item cookie back
456
            if ($prefillitem && defined $record) {
458
            if ($prefillitem && defined $record) {
Lines 824-829 if($itemrecord){ Link Here
824
            }
826
            }
825
    # and now we add fields that are empty
827
    # and now we add fields that are empty
826
828
829
##Populate datereceived for new Items present in our library.
830
#Get the mapped MARC-fields for items.datereceived
831
my ( $datereceivedFieldCode, $datereceivedSubfieldCode ) =
832
            C4::Biblio::GetMarcFromKohaField( "items.datereceived", $frameworkcode );
833
( $datereceivedFieldCode, $datereceivedSubfieldCode ) =
834
            C4::Biblio::GetMarcFromKohaField( "items.datereceived", '' ) unless ($datereceivedFieldCode);
835
827
# Using last created item if it exists
836
# Using last created item if it exists
828
837
829
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
838
$itemrecord = $cookieitemrecord if ($prefillitem and not $justaddeditem and $op ne "edititem");
Lines 838-843 foreach my $tag ( keys %{$tagslib}){ Link Here
838
        my @values = (undef);
847
        my @values = (undef);
839
        @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag)));
848
        @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)) && defined($itemrecord->field($tag)->subfield($subtag)));
840
        for my $value (@values){
849
        for my $value (@values){
850
            $value = enforceDatereceived($tag, $subtag, $value);
841
            my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $restrictededition);
851
            my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $restrictededition);
842
            push (@loop_data, $subfield_data);
852
            push (@loop_data, $subfield_data);
843
            $i++;
853
            $i++;
Lines 881-883 foreach my $error (@errors) { Link Here
881
    $template->param($error => 1);
891
    $template->param($error => 1);
882
}
892
}
883
output_html_with_http_headers $input, $cookie, $template->output;
893
output_html_with_http_headers $input, $cookie, $template->output;
884
- 
894
895
sub enforceDatereceived {
896
    my ($tag, $subtag, $value) = @_;
897
    #Set the datereceived as now() if it is not defined, or it's not a timestamp.
898
    if ($tag eq $datereceivedFieldCode && $subtag eq $datereceivedSubfieldCode && (not($value) || not($value =~ /^\d\d\d\d-\d\d-\d\d/))) {
899
        $value = DateTime->now( time_zone => C4::Context->tz() )->iso8601();
900
    }
901
    return $value;
902
}

Return to bug 13707