Bug 5458: DBRev 18.05.04.001
[koha.git] / Koha / Schema / Result / Item.pm
1 use utf8;
2 package Koha::Schema::Result::Item;
3
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7 =head1 NAME
8
9 Koha::Schema::Result::Item
10
11 =cut
12
13 use strict;
14 use warnings;
15
16 use base 'DBIx::Class::Core';
17
18 =head1 TABLE: C<items>
19
20 =cut
21
22 __PACKAGE__->table("items");
23
24 =head1 ACCESSORS
25
26 =head2 itemnumber
27
28   data_type: 'integer'
29   is_auto_increment: 1
30   is_nullable: 0
31
32 =head2 biblionumber
33
34   data_type: 'integer'
35   default_value: 0
36   is_foreign_key: 1
37   is_nullable: 0
38
39 =head2 biblioitemnumber
40
41   data_type: 'integer'
42   default_value: 0
43   is_foreign_key: 1
44   is_nullable: 0
45
46 =head2 barcode
47
48   data_type: 'varchar'
49   is_nullable: 1
50   size: 20
51
52 =head2 dateaccessioned
53
54   data_type: 'date'
55   datetime_undef_if_invalid: 1
56   is_nullable: 1
57
58 =head2 booksellerid
59
60   data_type: 'longtext'
61   is_nullable: 1
62
63 =head2 homebranch
64
65   data_type: 'varchar'
66   is_foreign_key: 1
67   is_nullable: 1
68   size: 10
69
70 =head2 price
71
72   data_type: 'decimal'
73   is_nullable: 1
74   size: [8,2]
75
76 =head2 replacementprice
77
78   data_type: 'decimal'
79   is_nullable: 1
80   size: [8,2]
81
82 =head2 replacementpricedate
83
84   data_type: 'date'
85   datetime_undef_if_invalid: 1
86   is_nullable: 1
87
88 =head2 datelastborrowed
89
90   data_type: 'date'
91   datetime_undef_if_invalid: 1
92   is_nullable: 1
93
94 =head2 datelastseen
95
96   data_type: 'date'
97   datetime_undef_if_invalid: 1
98   is_nullable: 1
99
100 =head2 stack
101
102   data_type: 'tinyint'
103   is_nullable: 1
104
105 =head2 notforloan
106
107   data_type: 'tinyint'
108   default_value: 0
109   is_nullable: 0
110
111 =head2 damaged
112
113   data_type: 'tinyint'
114   default_value: 0
115   is_nullable: 0
116
117 =head2 damaged_on
118
119   data_type: 'datetime'
120   datetime_undef_if_invalid: 1
121   is_nullable: 1
122
123 =head2 itemlost
124
125   data_type: 'tinyint'
126   default_value: 0
127   is_nullable: 0
128
129 =head2 itemlost_on
130
131   data_type: 'datetime'
132   datetime_undef_if_invalid: 1
133   is_nullable: 1
134
135 =head2 withdrawn
136
137   data_type: 'tinyint'
138   default_value: 0
139   is_nullable: 0
140
141 =head2 withdrawn_on
142
143   data_type: 'datetime'
144   datetime_undef_if_invalid: 1
145   is_nullable: 1
146
147 =head2 itemcallnumber
148
149   data_type: 'varchar'
150   is_nullable: 1
151   size: 255
152
153 =head2 coded_location_qualifier
154
155   data_type: 'varchar'
156   is_nullable: 1
157   size: 10
158
159 =head2 issues
160
161   data_type: 'smallint'
162   is_nullable: 1
163
164 =head2 renewals
165
166   data_type: 'smallint'
167   is_nullable: 1
168
169 =head2 reserves
170
171   data_type: 'smallint'
172   is_nullable: 1
173
174 =head2 restricted
175
176   data_type: 'tinyint'
177   is_nullable: 1
178
179 =head2 itemnotes
180
181   data_type: 'longtext'
182   is_nullable: 1
183
184 =head2 itemnotes_nonpublic
185
186   data_type: 'longtext'
187   is_nullable: 1
188
189 =head2 holdingbranch
190
191   data_type: 'varchar'
192   is_foreign_key: 1
193   is_nullable: 1
194   size: 10
195
196 =head2 paidfor
197
198   data_type: 'longtext'
199   is_nullable: 1
200
201 =head2 timestamp
202
203   data_type: 'timestamp'
204   datetime_undef_if_invalid: 1
205   default_value: current_timestamp
206   is_nullable: 0
207
208 =head2 location
209
210   data_type: 'varchar'
211   is_nullable: 1
212   size: 80
213
214 =head2 permanent_location
215
216   data_type: 'varchar'
217   is_nullable: 1
218   size: 80
219
220 =head2 onloan
221
222   data_type: 'date'
223   datetime_undef_if_invalid: 1
224   is_nullable: 1
225
226 =head2 cn_source
227
228   data_type: 'varchar'
229   is_nullable: 1
230   size: 10
231
232 =head2 cn_sort
233
234   data_type: 'varchar'
235   is_nullable: 1
236   size: 255
237
238 =head2 ccode
239
240   data_type: 'varchar'
241   is_nullable: 1
242   size: 80
243
244 =head2 materials
245
246   data_type: 'mediumtext'
247   is_nullable: 1
248
249 =head2 uri
250
251   data_type: 'varchar'
252   is_nullable: 1
253   size: 255
254
255 =head2 itype
256
257   data_type: 'varchar'
258   is_nullable: 1
259   size: 10
260
261 =head2 more_subfields_xml
262
263   data_type: 'longtext'
264   is_nullable: 1
265
266 =head2 enumchron
267
268   data_type: 'mediumtext'
269   is_nullable: 1
270
271 =head2 copynumber
272
273   data_type: 'varchar'
274   is_nullable: 1
275   size: 32
276
277 =head2 stocknumber
278
279   data_type: 'varchar'
280   is_nullable: 1
281   size: 32
282
283 =head2 new_status
284
285   data_type: 'varchar'
286   is_nullable: 1
287   size: 32
288
289 =cut
290
291 __PACKAGE__->add_columns(
292   "itemnumber",
293   { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
294   "biblionumber",
295   {
296     data_type      => "integer",
297     default_value  => 0,
298     is_foreign_key => 1,
299     is_nullable    => 0,
300   },
301   "biblioitemnumber",
302   {
303     data_type      => "integer",
304     default_value  => 0,
305     is_foreign_key => 1,
306     is_nullable    => 0,
307   },
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",
333   {
334     data_type => "datetime",
335     datetime_undef_if_invalid => 1,
336     is_nullable => 1,
337   },
338   "itemlost",
339   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
340   "itemlost_on",
341   {
342     data_type => "datetime",
343     datetime_undef_if_invalid => 1,
344     is_nullable => 1,
345   },
346   "withdrawn",
347   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
348   "withdrawn_on",
349   {
350     data_type => "datetime",
351     datetime_undef_if_invalid => 1,
352     is_nullable => 1,
353   },
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",
375   {
376     data_type => "timestamp",
377     datetime_undef_if_invalid => 1,
378     default_value => \"current_timestamp",
379     is_nullable => 0,
380   },
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 },
409 );
410
411 =head1 PRIMARY KEY
412
413 =over 4
414
415 =item * L</itemnumber>
416
417 =back
418
419 =cut
420
421 __PACKAGE__->set_primary_key("itemnumber");
422
423 =head1 UNIQUE CONSTRAINTS
424
425 =head2 C<itembarcodeidx>
426
427 =over 4
428
429 =item * L</barcode>
430
431 =back
432
433 =cut
434
435 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
436
437 =head1 RELATIONS
438
439 =head2 accountlines
440
441 Type: has_many
442
443 Related object: L<Koha::Schema::Result::Accountline>
444
445 =cut
446
447 __PACKAGE__->has_many(
448   "accountlines",
449   "Koha::Schema::Result::Accountline",
450   { "foreign.itemnumber" => "self.itemnumber" },
451   { cascade_copy => 0, cascade_delete => 0 },
452 );
453
454 =head2 article_requests
455
456 Type: has_many
457
458 Related object: L<Koha::Schema::Result::ArticleRequest>
459
460 =cut
461
462 __PACKAGE__->has_many(
463   "article_requests",
464   "Koha::Schema::Result::ArticleRequest",
465   { "foreign.itemnumber" => "self.itemnumber" },
466   { cascade_copy => 0, cascade_delete => 0 },
467 );
468
469 =head2 biblioitemnumber
470
471 Type: belongs_to
472
473 Related object: L<Koha::Schema::Result::Biblioitem>
474
475 =cut
476
477 __PACKAGE__->belongs_to(
478   "biblioitemnumber",
479   "Koha::Schema::Result::Biblioitem",
480   { biblioitemnumber => "biblioitemnumber" },
481   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
482 );
483
484 =head2 biblionumber
485
486 Type: belongs_to
487
488 Related object: L<Koha::Schema::Result::Biblio>
489
490 =cut
491
492 __PACKAGE__->belongs_to(
493   "biblionumber",
494   "Koha::Schema::Result::Biblio",
495   { biblionumber => "biblionumber" },
496   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
497 );
498
499 =head2 branchtransfers
500
501 Type: has_many
502
503 Related object: L<Koha::Schema::Result::Branchtransfer>
504
505 =cut
506
507 __PACKAGE__->has_many(
508   "branchtransfers",
509   "Koha::Schema::Result::Branchtransfer",
510   { "foreign.itemnumber" => "self.itemnumber" },
511   { cascade_copy => 0, cascade_delete => 0 },
512 );
513
514 =head2 course_item
515
516 Type: might_have
517
518 Related object: L<Koha::Schema::Result::CourseItem>
519
520 =cut
521
522 __PACKAGE__->might_have(
523   "course_item",
524   "Koha::Schema::Result::CourseItem",
525   { "foreign.itemnumber" => "self.itemnumber" },
526   { cascade_copy => 0, cascade_delete => 0 },
527 );
528
529 =head2 creator_batches
530
531 Type: has_many
532
533 Related object: L<Koha::Schema::Result::CreatorBatch>
534
535 =cut
536
537 __PACKAGE__->has_many(
538   "creator_batches",
539   "Koha::Schema::Result::CreatorBatch",
540   { "foreign.item_number" => "self.itemnumber" },
541   { cascade_copy => 0, cascade_delete => 0 },
542 );
543
544 =head2 hold_fill_target
545
546 Type: might_have
547
548 Related object: L<Koha::Schema::Result::HoldFillTarget>
549
550 =cut
551
552 __PACKAGE__->might_have(
553   "hold_fill_target",
554   "Koha::Schema::Result::HoldFillTarget",
555   { "foreign.itemnumber" => "self.itemnumber" },
556   { cascade_copy => 0, cascade_delete => 0 },
557 );
558
559 =head2 holdingbranch
560
561 Type: belongs_to
562
563 Related object: L<Koha::Schema::Result::Branch>
564
565 =cut
566
567 __PACKAGE__->belongs_to(
568   "holdingbranch",
569   "Koha::Schema::Result::Branch",
570   { branchcode => "holdingbranch" },
571   {
572     is_deferrable => 1,
573     join_type     => "LEFT",
574     on_delete     => "RESTRICT",
575     on_update     => "CASCADE",
576   },
577 );
578
579 =head2 homebranch
580
581 Type: belongs_to
582
583 Related object: L<Koha::Schema::Result::Branch>
584
585 =cut
586
587 __PACKAGE__->belongs_to(
588   "homebranch",
589   "Koha::Schema::Result::Branch",
590   { branchcode => "homebranch" },
591   {
592     is_deferrable => 1,
593     join_type     => "LEFT",
594     on_delete     => "RESTRICT",
595     on_update     => "CASCADE",
596   },
597 );
598
599 =head2 issue
600
601 Type: might_have
602
603 Related object: L<Koha::Schema::Result::Issue>
604
605 =cut
606
607 __PACKAGE__->might_have(
608   "issue",
609   "Koha::Schema::Result::Issue",
610   { "foreign.itemnumber" => "self.itemnumber" },
611   { cascade_copy => 0, cascade_delete => 0 },
612 );
613
614 =head2 items_last_borrower
615
616 Type: might_have
617
618 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
619
620 =cut
621
622 __PACKAGE__->might_have(
623   "items_last_borrower",
624   "Koha::Schema::Result::ItemsLastBorrower",
625   { "foreign.itemnumber" => "self.itemnumber" },
626   { cascade_copy => 0, cascade_delete => 0 },
627 );
628
629 =head2 old_issues
630
631 Type: has_many
632
633 Related object: L<Koha::Schema::Result::OldIssue>
634
635 =cut
636
637 __PACKAGE__->has_many(
638   "old_issues",
639   "Koha::Schema::Result::OldIssue",
640   { "foreign.itemnumber" => "self.itemnumber" },
641   { cascade_copy => 0, cascade_delete => 0 },
642 );
643
644 =head2 old_reserves
645
646 Type: has_many
647
648 Related object: L<Koha::Schema::Result::OldReserve>
649
650 =cut
651
652 __PACKAGE__->has_many(
653   "old_reserves",
654   "Koha::Schema::Result::OldReserve",
655   { "foreign.itemnumber" => "self.itemnumber" },
656   { cascade_copy => 0, cascade_delete => 0 },
657 );
658
659 =head2 reserves
660
661 Type: has_many
662
663 Related object: L<Koha::Schema::Result::Reserve>
664
665 =cut
666
667 __PACKAGE__->has_many(
668   "reserves",
669   "Koha::Schema::Result::Reserve",
670   { "foreign.itemnumber" => "self.itemnumber" },
671   { cascade_copy => 0, cascade_delete => 0 },
672 );
673
674 =head2 serialitem
675
676 Type: might_have
677
678 Related object: L<Koha::Schema::Result::Serialitem>
679
680 =cut
681
682 __PACKAGE__->might_have(
683   "serialitem",
684   "Koha::Schema::Result::Serialitem",
685   { "foreign.itemnumber" => "self.itemnumber" },
686   { cascade_copy => 0, cascade_delete => 0 },
687 );
688
689
690 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-09-26 16:15:09
691 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d5sg0dXWdq0NkHsYchyUyw
692
693 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
694
695 __PACKAGE__->belongs_to(
696   "biblio",
697   "Koha::Schema::Result::Biblio",
698   { biblionumber => "biblionumber" },
699   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
700 );
701
702 use C4::Context;
703 sub effective_itemtype {
704     my ( $self ) = @_;
705
706     my $pref = C4::Context->preference('item-level_itypes');
707     if ( $pref && $self->itype() ) {
708         return $self->itype();
709     } else {
710         warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
711           if $pref;
712         return $self->biblioitemnumber()->itemtype();
713     }
714 }
715
716 1;