Bug 20434: Update UNIMARC framework - auth (SAUTTIT)
[koha.git] / Koha / Schema / Result / Item.pm
blobda2a91f6ac78ae6836dda2e40a0703ed02c601c9
1 use utf8;
2 package Koha::Schema::Result::Item;
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
7 =head1 NAME
9 Koha::Schema::Result::Item
11 =cut
13 use strict;
14 use warnings;
16 use base 'DBIx::Class::Core';
18 =head1 TABLE: C<items>
20 =cut
22 __PACKAGE__->table("items");
24 =head1 ACCESSORS
26 =head2 itemnumber
28 data_type: 'integer'
29 is_auto_increment: 1
30 is_nullable: 0
32 =head2 biblionumber
34 data_type: 'integer'
35 default_value: 0
36 is_foreign_key: 1
37 is_nullable: 0
39 =head2 biblioitemnumber
41 data_type: 'integer'
42 default_value: 0
43 is_foreign_key: 1
44 is_nullable: 0
46 =head2 barcode
48 data_type: 'varchar'
49 is_nullable: 1
50 size: 20
52 =head2 dateaccessioned
54 data_type: 'date'
55 datetime_undef_if_invalid: 1
56 is_nullable: 1
58 =head2 booksellerid
60 data_type: 'longtext'
61 is_nullable: 1
63 =head2 homebranch
65 data_type: 'varchar'
66 is_foreign_key: 1
67 is_nullable: 1
68 size: 10
70 =head2 price
72 data_type: 'decimal'
73 is_nullable: 1
74 size: [8,2]
76 =head2 replacementprice
78 data_type: 'decimal'
79 is_nullable: 1
80 size: [8,2]
82 =head2 replacementpricedate
84 data_type: 'date'
85 datetime_undef_if_invalid: 1
86 is_nullable: 1
88 =head2 datelastborrowed
90 data_type: 'date'
91 datetime_undef_if_invalid: 1
92 is_nullable: 1
94 =head2 datelastseen
96 data_type: 'date'
97 datetime_undef_if_invalid: 1
98 is_nullable: 1
100 =head2 stack
102 data_type: 'tinyint'
103 is_nullable: 1
105 =head2 notforloan
107 data_type: 'tinyint'
108 default_value: 0
109 is_nullable: 0
111 =head2 damaged
113 data_type: 'tinyint'
114 default_value: 0
115 is_nullable: 0
117 =head2 damaged_on
119 data_type: 'datetime'
120 datetime_undef_if_invalid: 1
121 is_nullable: 1
123 =head2 itemlost
125 data_type: 'tinyint'
126 default_value: 0
127 is_nullable: 0
129 =head2 itemlost_on
131 data_type: 'datetime'
132 datetime_undef_if_invalid: 1
133 is_nullable: 1
135 =head2 withdrawn
137 data_type: 'tinyint'
138 default_value: 0
139 is_nullable: 0
141 =head2 withdrawn_on
143 data_type: 'datetime'
144 datetime_undef_if_invalid: 1
145 is_nullable: 1
147 =head2 itemcallnumber
149 data_type: 'varchar'
150 is_nullable: 1
151 size: 255
153 =head2 coded_location_qualifier
155 data_type: 'varchar'
156 is_nullable: 1
157 size: 10
159 =head2 issues
161 data_type: 'smallint'
162 is_nullable: 1
164 =head2 renewals
166 data_type: 'smallint'
167 is_nullable: 1
169 =head2 reserves
171 data_type: 'smallint'
172 is_nullable: 1
174 =head2 restricted
176 data_type: 'tinyint'
177 is_nullable: 1
179 =head2 itemnotes
181 data_type: 'longtext'
182 is_nullable: 1
184 =head2 itemnotes_nonpublic
186 data_type: 'longtext'
187 is_nullable: 1
189 =head2 holdingbranch
191 data_type: 'varchar'
192 is_foreign_key: 1
193 is_nullable: 1
194 size: 10
196 =head2 paidfor
198 data_type: 'longtext'
199 is_nullable: 1
201 =head2 timestamp
203 data_type: 'timestamp'
204 datetime_undef_if_invalid: 1
205 default_value: current_timestamp
206 is_nullable: 0
208 =head2 location
210 data_type: 'varchar'
211 is_nullable: 1
212 size: 80
214 =head2 permanent_location
216 data_type: 'varchar'
217 is_nullable: 1
218 size: 80
220 =head2 onloan
222 data_type: 'date'
223 datetime_undef_if_invalid: 1
224 is_nullable: 1
226 =head2 cn_source
228 data_type: 'varchar'
229 is_nullable: 1
230 size: 10
232 =head2 cn_sort
234 data_type: 'varchar'
235 is_nullable: 1
236 size: 255
238 =head2 ccode
240 data_type: 'varchar'
241 is_nullable: 1
242 size: 80
244 =head2 materials
246 data_type: 'mediumtext'
247 is_nullable: 1
249 =head2 uri
251 data_type: 'varchar'
252 is_nullable: 1
253 size: 255
255 =head2 itype
257 data_type: 'varchar'
258 is_nullable: 1
259 size: 10
261 =head2 more_subfields_xml
263 data_type: 'longtext'
264 is_nullable: 1
266 =head2 enumchron
268 data_type: 'mediumtext'
269 is_nullable: 1
271 =head2 copynumber
273 data_type: 'varchar'
274 is_nullable: 1
275 size: 32
277 =head2 stocknumber
279 data_type: 'varchar'
280 is_nullable: 1
281 size: 32
283 =head2 new_status
285 data_type: 'varchar'
286 is_nullable: 1
287 size: 32
289 =cut
291 __PACKAGE__->add_columns(
292 "itemnumber",
293 { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
294 "biblionumber",
296 data_type => "integer",
297 default_value => 0,
298 is_foreign_key => 1,
299 is_nullable => 0,
301 "biblioitemnumber",
303 data_type => "integer",
304 default_value => 0,
305 is_foreign_key => 1,
306 is_nullable => 0,
308 "barcode",
309 { data_type => "varchar", is_nullable => 1, size => 20 },
310 "dateaccessioned",
311 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
312 "booksellerid",
313 { data_type => "longtext", is_nullable => 1 },
314 "homebranch",
315 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
316 "price",
317 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
318 "replacementprice",
319 { data_type => "decimal", is_nullable => 1, size => [8, 2] },
320 "replacementpricedate",
321 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
322 "datelastborrowed",
323 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
324 "datelastseen",
325 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
326 "stack",
327 { data_type => "tinyint", is_nullable => 1 },
328 "notforloan",
329 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
330 "damaged",
331 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
332 "damaged_on",
334 data_type => "datetime",
335 datetime_undef_if_invalid => 1,
336 is_nullable => 1,
338 "itemlost",
339 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
340 "itemlost_on",
342 data_type => "datetime",
343 datetime_undef_if_invalid => 1,
344 is_nullable => 1,
346 "withdrawn",
347 { data_type => "tinyint", default_value => 0, is_nullable => 0 },
348 "withdrawn_on",
350 data_type => "datetime",
351 datetime_undef_if_invalid => 1,
352 is_nullable => 1,
354 "itemcallnumber",
355 { data_type => "varchar", is_nullable => 1, size => 255 },
356 "coded_location_qualifier",
357 { data_type => "varchar", is_nullable => 1, size => 10 },
358 "issues",
359 { data_type => "smallint", is_nullable => 1 },
360 "renewals",
361 { data_type => "smallint", is_nullable => 1 },
362 "reserves",
363 { data_type => "smallint", is_nullable => 1 },
364 "restricted",
365 { data_type => "tinyint", is_nullable => 1 },
366 "itemnotes",
367 { data_type => "longtext", is_nullable => 1 },
368 "itemnotes_nonpublic",
369 { data_type => "longtext", is_nullable => 1 },
370 "holdingbranch",
371 { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
372 "paidfor",
373 { data_type => "longtext", is_nullable => 1 },
374 "timestamp",
376 data_type => "timestamp",
377 datetime_undef_if_invalid => 1,
378 default_value => \"current_timestamp",
379 is_nullable => 0,
381 "location",
382 { data_type => "varchar", is_nullable => 1, size => 80 },
383 "permanent_location",
384 { data_type => "varchar", is_nullable => 1, size => 80 },
385 "onloan",
386 { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
387 "cn_source",
388 { data_type => "varchar", is_nullable => 1, size => 10 },
389 "cn_sort",
390 { data_type => "varchar", is_nullable => 1, size => 255 },
391 "ccode",
392 { data_type => "varchar", is_nullable => 1, size => 80 },
393 "materials",
394 { data_type => "mediumtext", is_nullable => 1 },
395 "uri",
396 { data_type => "varchar", is_nullable => 1, size => 255 },
397 "itype",
398 { data_type => "varchar", is_nullable => 1, size => 10 },
399 "more_subfields_xml",
400 { data_type => "longtext", is_nullable => 1 },
401 "enumchron",
402 { data_type => "mediumtext", is_nullable => 1 },
403 "copynumber",
404 { data_type => "varchar", is_nullable => 1, size => 32 },
405 "stocknumber",
406 { data_type => "varchar", is_nullable => 1, size => 32 },
407 "new_status",
408 { data_type => "varchar", is_nullable => 1, size => 32 },
411 =head1 PRIMARY KEY
413 =over 4
415 =item * L</itemnumber>
417 =back
419 =cut
421 __PACKAGE__->set_primary_key("itemnumber");
423 =head1 UNIQUE CONSTRAINTS
425 =head2 C<itembarcodeidx>
427 =over 4
429 =item * L</barcode>
431 =back
433 =cut
435 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
437 =head1 RELATIONS
439 =head2 accountlines
441 Type: has_many
443 Related object: L<Koha::Schema::Result::Accountline>
445 =cut
447 __PACKAGE__->has_many(
448 "accountlines",
449 "Koha::Schema::Result::Accountline",
450 { "foreign.itemnumber" => "self.itemnumber" },
451 { cascade_copy => 0, cascade_delete => 0 },
454 =head2 article_requests
456 Type: has_many
458 Related object: L<Koha::Schema::Result::ArticleRequest>
460 =cut
462 __PACKAGE__->has_many(
463 "article_requests",
464 "Koha::Schema::Result::ArticleRequest",
465 { "foreign.itemnumber" => "self.itemnumber" },
466 { cascade_copy => 0, cascade_delete => 0 },
469 =head2 biblioitemnumber
471 Type: belongs_to
473 Related object: L<Koha::Schema::Result::Biblioitem>
475 =cut
477 __PACKAGE__->belongs_to(
478 "biblioitemnumber",
479 "Koha::Schema::Result::Biblioitem",
480 { biblioitemnumber => "biblioitemnumber" },
481 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
484 =head2 biblionumber
486 Type: belongs_to
488 Related object: L<Koha::Schema::Result::Biblio>
490 =cut
492 __PACKAGE__->belongs_to(
493 "biblionumber",
494 "Koha::Schema::Result::Biblio",
495 { biblionumber => "biblionumber" },
496 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
499 =head2 branchtransfers
501 Type: has_many
503 Related object: L<Koha::Schema::Result::Branchtransfer>
505 =cut
507 __PACKAGE__->has_many(
508 "branchtransfers",
509 "Koha::Schema::Result::Branchtransfer",
510 { "foreign.itemnumber" => "self.itemnumber" },
511 { cascade_copy => 0, cascade_delete => 0 },
514 =head2 club_holds
516 Type: has_many
518 Related object: L<Koha::Schema::Result::ClubHold>
520 =cut
522 __PACKAGE__->has_many(
523 "club_holds",
524 "Koha::Schema::Result::ClubHold",
525 { "foreign.item_id" => "self.itemnumber" },
526 { cascade_copy => 0, cascade_delete => 0 },
529 =head2 course_item
531 Type: might_have
533 Related object: L<Koha::Schema::Result::CourseItem>
535 =cut
537 __PACKAGE__->might_have(
538 "course_item",
539 "Koha::Schema::Result::CourseItem",
540 { "foreign.itemnumber" => "self.itemnumber" },
541 { cascade_copy => 0, cascade_delete => 0 },
544 =head2 creator_batches
546 Type: has_many
548 Related object: L<Koha::Schema::Result::CreatorBatch>
550 =cut
552 __PACKAGE__->has_many(
553 "creator_batches",
554 "Koha::Schema::Result::CreatorBatch",
555 { "foreign.item_number" => "self.itemnumber" },
556 { cascade_copy => 0, cascade_delete => 0 },
559 =head2 hold_fill_target
561 Type: might_have
563 Related object: L<Koha::Schema::Result::HoldFillTarget>
565 =cut
567 __PACKAGE__->might_have(
568 "hold_fill_target",
569 "Koha::Schema::Result::HoldFillTarget",
570 { "foreign.itemnumber" => "self.itemnumber" },
571 { cascade_copy => 0, cascade_delete => 0 },
574 =head2 holdingbranch
576 Type: belongs_to
578 Related object: L<Koha::Schema::Result::Branch>
580 =cut
582 __PACKAGE__->belongs_to(
583 "holdingbranch",
584 "Koha::Schema::Result::Branch",
585 { branchcode => "holdingbranch" },
587 is_deferrable => 1,
588 join_type => "LEFT",
589 on_delete => "RESTRICT",
590 on_update => "CASCADE",
594 =head2 homebranch
596 Type: belongs_to
598 Related object: L<Koha::Schema::Result::Branch>
600 =cut
602 __PACKAGE__->belongs_to(
603 "homebranch",
604 "Koha::Schema::Result::Branch",
605 { branchcode => "homebranch" },
607 is_deferrable => 1,
608 join_type => "LEFT",
609 on_delete => "RESTRICT",
610 on_update => "CASCADE",
614 =head2 issue
616 Type: might_have
618 Related object: L<Koha::Schema::Result::Issue>
620 =cut
622 __PACKAGE__->might_have(
623 "issue",
624 "Koha::Schema::Result::Issue",
625 { "foreign.itemnumber" => "self.itemnumber" },
626 { cascade_copy => 0, cascade_delete => 0 },
629 =head2 items_last_borrower
631 Type: might_have
633 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
635 =cut
637 __PACKAGE__->might_have(
638 "items_last_borrower",
639 "Koha::Schema::Result::ItemsLastBorrower",
640 { "foreign.itemnumber" => "self.itemnumber" },
641 { cascade_copy => 0, cascade_delete => 0 },
644 =head2 old_issues
646 Type: has_many
648 Related object: L<Koha::Schema::Result::OldIssue>
650 =cut
652 __PACKAGE__->has_many(
653 "old_issues",
654 "Koha::Schema::Result::OldIssue",
655 { "foreign.itemnumber" => "self.itemnumber" },
656 { cascade_copy => 0, cascade_delete => 0 },
659 =head2 old_reserves
661 Type: has_many
663 Related object: L<Koha::Schema::Result::OldReserve>
665 =cut
667 __PACKAGE__->has_many(
668 "old_reserves",
669 "Koha::Schema::Result::OldReserve",
670 { "foreign.itemnumber" => "self.itemnumber" },
671 { cascade_copy => 0, cascade_delete => 0 },
674 =head2 reserves
676 Type: has_many
678 Related object: L<Koha::Schema::Result::Reserve>
680 =cut
682 __PACKAGE__->has_many(
683 "reserves",
684 "Koha::Schema::Result::Reserve",
685 { "foreign.itemnumber" => "self.itemnumber" },
686 { cascade_copy => 0, cascade_delete => 0 },
689 =head2 serialitem
691 Type: might_have
693 Related object: L<Koha::Schema::Result::Serialitem>
695 =cut
697 __PACKAGE__->might_have(
698 "serialitem",
699 "Koha::Schema::Result::Serialitem",
700 { "foreign.itemnumber" => "self.itemnumber" },
701 { cascade_copy => 0, cascade_delete => 0 },
704 =head2 stockrotationitem
706 Type: might_have
708 Related object: L<Koha::Schema::Result::Stockrotationitem>
710 =cut
712 __PACKAGE__->might_have(
713 "stockrotationitem",
714 "Koha::Schema::Result::Stockrotationitem",
715 { "foreign.itemnumber_id" => "self.itemnumber" },
716 { cascade_copy => 0, cascade_delete => 0 },
719 =head2 tmp_holdsqueues
721 Type: has_many
723 Related object: L<Koha::Schema::Result::TmpHoldsqueue>
725 =cut
727 __PACKAGE__->has_many(
728 "tmp_holdsqueues",
729 "Koha::Schema::Result::TmpHoldsqueue",
730 { "foreign.itemnumber" => "self.itemnumber" },
731 { cascade_copy => 0, cascade_delete => 0 },
735 # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-10-01 07:08:47
736 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:n/X6k+IwU4pkLS+PjKWVWA
738 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
740 __PACKAGE__->belongs_to(
741 "biblio",
742 "Koha::Schema::Result::Biblio",
743 { biblionumber => "biblionumber" },
744 { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
747 use C4::Context;
748 sub effective_itemtype {
749 my ( $self ) = @_;
751 my $pref = C4::Context->preference('item-level_itypes');
752 if ( $pref && $self->itype() ) {
753 return $self->itype();
754 } else {
755 warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
756 if $pref;
757 return $self->biblioitemnumber()->itemtype();