2 package Koha::Schema::Result::Item;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
9 Koha::Schema::Result::Item
16 use base 'DBIx::Class::Core';
18 =head1 TABLE: C<items>
22 __PACKAGE__->table("items");
32 primary key and unique identifier added by Koha
41 foreign key from biblio table used to link this item to the right bib record
43 =head2 biblioitemnumber
50 foreign key from the biblioitems table to link to item to additional information
58 item barcode (MARC21 952$p)
60 =head2 dateaccessioned
63 datetime_undef_if_invalid: 1
66 date the item was acquired or added to Koha (MARC21 952$d)
73 where the item was purchased (MARC21 952$e)
82 foreign key from the branches table for the library that owns this item (MARC21 952$a)
90 purchase price (MARC21 952$g)
92 =head2 replacementprice
98 cost the library charges to replace the item if it has been marked lost (MARC21 952$v)
100 =head2 replacementpricedate
103 datetime_undef_if_invalid: 1
106 the date the price is effective from (MARC21 952$w)
108 =head2 datelastborrowed
111 datetime_undef_if_invalid: 1
114 the date the item was last checked out/issued
118 data_type: 'datetime'
119 datetime_undef_if_invalid: 1
122 the date the item was last see (usually the last time the barcode was scanned or inventory was done)
135 authorized value defining why this item is not for loan (MARC21 952$7)
143 authorized value defining this item as damaged (MARC21 952$4)
147 data_type: 'datetime'
148 datetime_undef_if_invalid: 1
151 the date and time an item was last marked as damaged, NULL if not damaged
159 authorized value defining this item as lost (MARC21 952$1)
163 data_type: 'datetime'
164 datetime_undef_if_invalid: 1
167 the date and time an item was last marked as lost, NULL if not lost
175 authorized value defining this item as withdrawn (MARC21 952$0)
179 data_type: 'datetime'
180 datetime_undef_if_invalid: 1
183 the date and time an item was last marked as withdrawn, NULL if not withdrawn
185 =head2 itemcallnumber
191 call number for this item (MARC21 952$o)
193 =head2 coded_location_qualifier
199 coded location qualifier(MARC21 952$f)
203 data_type: 'smallint'
207 number of times this item has been checked out/issued
211 data_type: 'smallint'
214 number of times this item has been renewed
218 data_type: 'smallint'
221 number of times this item has been placed on hold/reserved
228 authorized value defining use restrictions for this item (MARC21 952$5)
232 data_type: 'longtext'
235 public notes on this item (MARC21 952$z)
237 =head2 itemnotes_nonpublic
239 data_type: 'longtext'
242 non-public notes on this item (MARC21 952$x)
251 foreign key from the branches table for the library that is currently in possession item (MARC21 952$b)
255 data_type: 'timestamp'
256 datetime_undef_if_invalid: 1
257 default_value: current_timestamp
260 date and time this item was last altered
264 data_type: 'datetime'
265 datetime_undef_if_invalid: 1
268 date/time of deletion
276 authorized value for the shelving location for this item (MARC21 952$c)
278 =head2 permanent_location
284 linked to the CART and PROC temporary locations feature, stores the permanent shelving location
289 datetime_undef_if_invalid: 1
292 defines if item is checked out (NULL for not checked out, and due date for checked out)
300 classification source used on this item (MARC21 952$2)
308 normalized form of the call number (MARC21 952$o) used for sorting
316 authorized value for the collection code associated with this item (MARC21 952$8)
320 data_type: 'mediumtext'
323 materials specified (MARC21 952$3)
327 data_type: 'mediumtext'
330 URL for the item (MARC21 952$u)
338 foreign key from the itemtypes table defining the type for this item (MARC21 952$y)
340 =head2 more_subfields_xml
342 data_type: 'longtext'
345 additional 952 subfields in XML format
349 data_type: 'mediumtext'
352 serial enumeration/chronology for the item (MARC21 952$h)
360 copy number (MARC21 952$t)
368 inventory number (MARC21 952$i)
376 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob.
378 =head2 exclude_from_local_holds_priority
383 Exclude this item from local holds priority
387 __PACKAGE__->add_columns(
389 { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
392 data_type => "integer",
399 data_type => "integer",
405 { data_type => "varchar", is_nullable => 1, size => 20 },
407 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
409 { data_type => "longtext", is_nullable => 1 },
411 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
413 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
415 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
416 "replacementpricedate",
417 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
419 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
422 data_type => "datetime",
423 datetime_undef_if_invalid => 1,
427 { data_type => "tinyint", is_nullable => 1 },
429 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
431 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
434 data_type => "datetime",
435 datetime_undef_if_invalid => 1,
439 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
442 data_type => "datetime",
443 datetime_undef_if_invalid => 1,
447 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
450 data_type => "datetime",
451 datetime_undef_if_invalid => 1,
455 { data_type => "varchar", is_nullable => 1, size => 255 },
456 "coded_location_qualifier",
457 { data_type => "varchar", is_nullable => 1, size => 10 },
459 { data_type => "smallint", default_value => 0, is_nullable => 1 },
461 { data_type => "smallint", is_nullable => 1 },
463 { data_type => "smallint", is_nullable => 1 },
465 { data_type => "tinyint", is_nullable => 1 },
467 { data_type => "longtext", is_nullable => 1 },
468 "itemnotes_nonpublic",
469 { data_type => "longtext", is_nullable => 1 },
471 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
474 data_type => "timestamp",
475 datetime_undef_if_invalid => 1,
476 default_value => \"current_timestamp",
481 data_type => "datetime",
482 datetime_undef_if_invalid => 1,
486 { data_type => "varchar", is_nullable => 1, size => 80 },
487 "permanent_location",
488 { data_type => "varchar", is_nullable => 1, size => 80 },
490 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
492 { data_type => "varchar", is_nullable => 1, size => 10 },
494 { data_type => "varchar", is_nullable => 1, size => 255 },
496 { data_type => "varchar", is_nullable => 1, size => 80 },
498 { data_type => "mediumtext", is_nullable => 1 },
500 { data_type => "mediumtext", is_nullable => 1 },
502 { data_type => "varchar", is_nullable => 1, size => 10 },
503 "more_subfields_xml",
504 { data_type => "longtext", is_nullable => 1 },
506 { data_type => "mediumtext", is_nullable => 1 },
508 { data_type => "varchar", is_nullable => 1, size => 32 },
510 { data_type => "varchar", is_nullable => 1, size => 32 },
512 { data_type => "varchar", is_nullable => 1, size => 32 },
513 "exclude_from_local_holds_priority",
514 { data_type => "tinyint", is_nullable => 1 },
521 =item * L</itemnumber>
527 __PACKAGE__->set_primary_key("itemnumber");
529 =head1 UNIQUE CONSTRAINTS
531 =head2 C<itembarcodeidx>
541 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
549 Related object: L<Koha::Schema::Result::Accountline>
553 __PACKAGE__->has_many(
555 "Koha::Schema::Result::Accountline",
556 { "foreign.itemnumber" => "self.itemnumber" },
557 { cascade_copy => 0, cascade_delete => 0 },
560 =head2 article_requests
564 Related object: L<Koha::Schema::Result::ArticleRequest>
568 __PACKAGE__->has_many(
570 "Koha::Schema::Result::ArticleRequest",
571 { "foreign.itemnumber" => "self.itemnumber" },
572 { cascade_copy => 0, cascade_delete => 0 },
575 =head2 biblioitemnumber
579 Related object: L<Koha::Schema::Result::Biblioitem>
583 __PACKAGE__->belongs_to(
585 "Koha::Schema::Result::Biblioitem",
586 { biblioitemnumber => "biblioitemnumber" },
587 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
594 Related object: L<Koha::Schema::Result::Biblio>
598 __PACKAGE__->belongs_to(
600 "Koha::Schema::Result::Biblio",
601 { biblionumber => "biblionumber" },
602 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
605 =head2 branchtransfers
609 Related object: L<Koha::Schema::Result::Branchtransfer>
613 __PACKAGE__->has_many(
615 "Koha::Schema::Result::Branchtransfer",
616 { "foreign.itemnumber" => "self.itemnumber" },
617 { cascade_copy => 0, cascade_delete => 0 },
624 Related object: L<Koha::Schema::Result::ClubHold>
628 __PACKAGE__->has_many(
630 "Koha::Schema::Result::ClubHold",
631 { "foreign.item_id" => "self.itemnumber" },
632 { cascade_copy => 0, cascade_delete => 0 },
639 Related object: L<Koha::Schema::Result::CourseItem>
643 __PACKAGE__->might_have(
645 "Koha::Schema::Result::CourseItem",
646 { "foreign.itemnumber" => "self.itemnumber" },
647 { cascade_copy => 0, cascade_delete => 0 },
654 Related object: L<Koha::Schema::Result::CoverImage>
658 __PACKAGE__->has_many(
660 "Koha::Schema::Result::CoverImage",
661 { "foreign.itemnumber" => "self.itemnumber" },
662 { cascade_copy => 0, cascade_delete => 0 },
665 =head2 creator_batches
669 Related object: L<Koha::Schema::Result::CreatorBatch>
673 __PACKAGE__->has_many(
675 "Koha::Schema::Result::CreatorBatch",
676 { "foreign.item_number" => "self.itemnumber" },
677 { cascade_copy => 0, cascade_delete => 0 },
680 =head2 hold_fill_target
684 Related object: L<Koha::Schema::Result::HoldFillTarget>
688 __PACKAGE__->might_have(
690 "Koha::Schema::Result::HoldFillTarget",
691 { "foreign.itemnumber" => "self.itemnumber" },
692 { cascade_copy => 0, cascade_delete => 0 },
699 Related object: L<Koha::Schema::Result::Branch>
703 __PACKAGE__->belongs_to(
705 "Koha::Schema::Result::Branch",
706 { branchcode => "holdingbranch" },
710 on_delete => "RESTRICT",
711 on_update => "CASCADE",
719 Related object: L<Koha::Schema::Result::Branch>
723 __PACKAGE__->belongs_to(
725 "Koha::Schema::Result::Branch",
726 { branchcode => "homebranch" },
730 on_delete => "RESTRICT",
731 on_update => "CASCADE",
739 Related object: L<Koha::Schema::Result::Issue>
743 __PACKAGE__->might_have(
745 "Koha::Schema::Result::Issue",
746 { "foreign.itemnumber" => "self.itemnumber" },
747 { cascade_copy => 0, cascade_delete => 0 },
750 =head2 item_bundles_hosts
754 Related object: L<Koha::Schema::Result::ItemBundle>
758 __PACKAGE__->has_many(
759 "item_bundles_hosts",
760 "Koha::Schema::Result::ItemBundle",
761 { "foreign.host" => "self.itemnumber" },
762 { cascade_copy => 0, cascade_delete => 0 },
765 =head2 item_bundles_item
769 Related object: L<Koha::Schema::Result::ItemBundle>
773 __PACKAGE__->might_have(
775 "Koha::Schema::Result::ItemBundle",
776 { "foreign.item" => "self.itemnumber" },
777 { cascade_copy => 0, cascade_delete => 0 },
780 =head2 item_group_item
784 Related object: L<Koha::Schema::Result::ItemGroupItem>
788 __PACKAGE__->might_have(
790 "Koha::Schema::Result::ItemGroupItem",
791 { "foreign.item_id" => "self.itemnumber" },
792 { cascade_copy => 0, cascade_delete => 0 },
795 =head2 items_last_borrower
799 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
803 __PACKAGE__->might_have(
804 "items_last_borrower",
805 "Koha::Schema::Result::ItemsLastBorrower",
806 { "foreign.itemnumber" => "self.itemnumber" },
807 { cascade_copy => 0, cascade_delete => 0 },
814 Related object: L<Koha::Schema::Result::Linktracker>
818 __PACKAGE__->has_many(
820 "Koha::Schema::Result::Linktracker",
821 { "foreign.itemnumber" => "self.itemnumber" },
822 { cascade_copy => 0, cascade_delete => 0 },
829 Related object: L<Koha::Schema::Result::OldIssue>
833 __PACKAGE__->has_many(
835 "Koha::Schema::Result::OldIssue",
836 { "foreign.itemnumber" => "self.itemnumber" },
837 { cascade_copy => 0, cascade_delete => 0 },
844 Related object: L<Koha::Schema::Result::OldReserve>
848 __PACKAGE__->has_many(
850 "Koha::Schema::Result::OldReserve",
851 { "foreign.itemnumber" => "self.itemnumber" },
852 { cascade_copy => 0, cascade_delete => 0 },
859 Related object: L<Koha::Schema::Result::Recall>
863 __PACKAGE__->has_many(
865 "Koha::Schema::Result::Recall",
866 { "foreign.item_id" => "self.itemnumber" },
867 { cascade_copy => 0, cascade_delete => 0 },
874 Related object: L<Koha::Schema::Result::Reserve>
878 __PACKAGE__->has_many(
880 "Koha::Schema::Result::Reserve",
881 { "foreign.itemnumber" => "self.itemnumber" },
882 { cascade_copy => 0, cascade_delete => 0 },
889 Related object: L<Koha::Schema::Result::ReturnClaim>
893 __PACKAGE__->has_many(
895 "Koha::Schema::Result::ReturnClaim",
896 { "foreign.itemnumber" => "self.itemnumber" },
897 { cascade_copy => 0, cascade_delete => 0 },
904 Related object: L<Koha::Schema::Result::Serialitem>
908 __PACKAGE__->might_have(
910 "Koha::Schema::Result::Serialitem",
911 { "foreign.itemnumber" => "self.itemnumber" },
912 { cascade_copy => 0, cascade_delete => 0 },
915 =head2 stockrotationitem
919 Related object: L<Koha::Schema::Result::Stockrotationitem>
923 __PACKAGE__->might_have(
925 "Koha::Schema::Result::Stockrotationitem",
926 { "foreign.itemnumber_id" => "self.itemnumber" },
927 { cascade_copy => 0, cascade_delete => 0 },
930 =head2 tmp_holdsqueues
934 Related object: L<Koha::Schema::Result::TmpHoldsqueue>
938 __PACKAGE__->has_many(
940 "Koha::Schema::Result::TmpHoldsqueue",
941 { "foreign.itemnumber" => "self.itemnumber" },
942 { cascade_copy => 0, cascade_delete => 0 },
946 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-05-12 18:18:47
947 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HMU2tnuIRypuatz/J5683A
949 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
951 __PACKAGE__->belongs_to(
953 "Koha::Schema::Result::Biblio",
954 { biblionumber => "biblionumber" },
955 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
958 __PACKAGE__->add_columns(
959 '+exclude_from_local_holds_priority' => { is_boolean => 1 },
962 # Relationship with orders via the aqorders_item table that not have foreign keys
963 __PACKAGE__->has_many(
965 "Koha::Schema::Result::AqordersItem",
966 { "foreign.itemnumber" => "self.itemnumber" },
967 { cascade_copy => 0, cascade_delete => 0 },
969 __PACKAGE__->many_to_many(
975 __PACKAGE__->has_many(
976 "current_branchtransfers",
977 "Koha::Schema::Result::Branchtransfer",
978 { 'foreign.itemnumber' => 'self.itemnumber' },
980 where => { datearrived => undef, datecancelled => undef },
981 order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ]
985 __PACKAGE__->might_have(
987 "Koha::Schema::Result::ItemsLastBorrower",
988 { "foreign.itemnumber" => "self.itemnumber" },
989 { cascade_copy => 0, cascade_delete => 0 },
993 sub effective_itemtype {
996 my $pref = C4::Context->preference('item-level_itypes');
997 if ( $pref && $self->itype() ) {
998 return $self->itype();
1000 warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
1002 return $self->biblioitemnumber()->itemtype();