Bug 13178: DBIC Schema changes
[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: 'mediumtext'
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 itemlost
118
119   data_type: 'tinyint'
120   default_value: 0
121   is_nullable: 0
122
123 =head2 itemlost_on
124
125   data_type: 'datetime'
126   datetime_undef_if_invalid: 1
127   is_nullable: 1
128
129 =head2 withdrawn
130
131   data_type: 'tinyint'
132   default_value: 0
133   is_nullable: 0
134
135 =head2 withdrawn_on
136
137   data_type: 'datetime'
138   datetime_undef_if_invalid: 1
139   is_nullable: 1
140
141 =head2 itemcallnumber
142
143   data_type: 'varchar'
144   is_nullable: 1
145   size: 255
146
147 =head2 coded_location_qualifier
148
149   data_type: 'varchar'
150   is_nullable: 1
151   size: 10
152
153 =head2 issues
154
155   data_type: 'smallint'
156   is_nullable: 1
157
158 =head2 renewals
159
160   data_type: 'smallint'
161   is_nullable: 1
162
163 =head2 reserves
164
165   data_type: 'smallint'
166   is_nullable: 1
167
168 =head2 restricted
169
170   data_type: 'tinyint'
171   is_nullable: 1
172
173 =head2 itemnotes
174
175   data_type: 'mediumtext'
176   is_nullable: 1
177
178 =head2 itemnotes_nonpublic
179
180   data_type: 'mediumtext'
181   is_nullable: 1
182
183 =head2 holdingbranch
184
185   data_type: 'varchar'
186   is_foreign_key: 1
187   is_nullable: 1
188   size: 10
189
190 =head2 paidfor
191
192   data_type: 'mediumtext'
193   is_nullable: 1
194
195 =head2 timestamp
196
197   data_type: 'timestamp'
198   datetime_undef_if_invalid: 1
199   default_value: current_timestamp
200   is_nullable: 0
201
202 =head2 location
203
204   data_type: 'varchar'
205   is_nullable: 1
206   size: 80
207
208 =head2 permanent_location
209
210   data_type: 'varchar'
211   is_nullable: 1
212   size: 80
213
214 =head2 onloan
215
216   data_type: 'date'
217   datetime_undef_if_invalid: 1
218   is_nullable: 1
219
220 =head2 cn_source
221
222   data_type: 'varchar'
223   is_nullable: 1
224   size: 10
225
226 =head2 cn_sort
227
228   data_type: 'varchar'
229   is_nullable: 1
230   size: 255
231
232 =head2 ccode
233
234   data_type: 'varchar'
235   is_nullable: 1
236   size: 10
237
238 =head2 materials
239
240   data_type: 'text'
241   is_nullable: 1
242
243 =head2 uri
244
245   data_type: 'varchar'
246   is_nullable: 1
247   size: 255
248
249 =head2 itype
250
251   data_type: 'varchar'
252   is_nullable: 1
253   size: 10
254
255 =head2 more_subfields_xml
256
257   data_type: 'longtext'
258   is_nullable: 1
259
260 =head2 enumchron
261
262   data_type: 'text'
263   is_nullable: 1
264
265 =head2 copynumber
266
267   data_type: 'varchar'
268   is_nullable: 1
269   size: 32
270
271 =head2 stocknumber
272
273   data_type: 'varchar'
274   is_nullable: 1
275   size: 32
276
277 =head2 new_status
278
279   data_type: 'varchar'
280   is_nullable: 1
281   size: 32
282
283 =cut
284
285 __PACKAGE__->add_columns(
286   "itemnumber",
287   { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
288   "biblionumber",
289   {
290     data_type      => "integer",
291     default_value  => 0,
292     is_foreign_key => 1,
293     is_nullable    => 0,
294   },
295   "biblioitemnumber",
296   {
297     data_type      => "integer",
298     default_value  => 0,
299     is_foreign_key => 1,
300     is_nullable    => 0,
301   },
302   "barcode",
303   { data_type => "varchar", is_nullable => 1, size => 20 },
304   "dateaccessioned",
305   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
306   "booksellerid",
307   { data_type => "mediumtext", is_nullable => 1 },
308   "homebranch",
309   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
310   "price",
311   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
312   "replacementprice",
313   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
314   "replacementpricedate",
315   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
316   "datelastborrowed",
317   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
318   "datelastseen",
319   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
320   "stack",
321   { data_type => "tinyint", is_nullable => 1 },
322   "notforloan",
323   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
324   "damaged",
325   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
326   "itemlost",
327   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
328   "itemlost_on",
329   {
330     data_type => "datetime",
331     datetime_undef_if_invalid => 1,
332     is_nullable => 1,
333   },
334   "withdrawn",
335   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
336   "withdrawn_on",
337   {
338     data_type => "datetime",
339     datetime_undef_if_invalid => 1,
340     is_nullable => 1,
341   },
342   "itemcallnumber",
343   { data_type => "varchar", is_nullable => 1, size => 255 },
344   "coded_location_qualifier",
345   { data_type => "varchar", is_nullable => 1, size => 10 },
346   "issues",
347   { data_type => "smallint", is_nullable => 1 },
348   "renewals",
349   { data_type => "smallint", is_nullable => 1 },
350   "reserves",
351   { data_type => "smallint", is_nullable => 1 },
352   "restricted",
353   { data_type => "tinyint", is_nullable => 1 },
354   "itemnotes",
355   { data_type => "mediumtext", is_nullable => 1 },
356   "itemnotes_nonpublic",
357   { data_type => "mediumtext", is_nullable => 1 },
358   "holdingbranch",
359   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
360   "paidfor",
361   { data_type => "mediumtext", is_nullable => 1 },
362   "timestamp",
363   {
364     data_type => "timestamp",
365     datetime_undef_if_invalid => 1,
366     default_value => \"current_timestamp",
367     is_nullable => 0,
368   },
369   "location",
370   { data_type => "varchar", is_nullable => 1, size => 80 },
371   "permanent_location",
372   { data_type => "varchar", is_nullable => 1, size => 80 },
373   "onloan",
374   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
375   "cn_source",
376   { data_type => "varchar", is_nullable => 1, size => 10 },
377   "cn_sort",
378   { data_type => "varchar", is_nullable => 1, size => 255 },
379   "ccode",
380   { data_type => "varchar", is_nullable => 1, size => 10 },
381   "materials",
382   { data_type => "text", is_nullable => 1 },
383   "uri",
384   { data_type => "varchar", is_nullable => 1, size => 255 },
385   "itype",
386   { data_type => "varchar", is_nullable => 1, size => 10 },
387   "more_subfields_xml",
388   { data_type => "longtext", is_nullable => 1 },
389   "enumchron",
390   { data_type => "text", is_nullable => 1 },
391   "copynumber",
392   { data_type => "varchar", is_nullable => 1, size => 32 },
393   "stocknumber",
394   { data_type => "varchar", is_nullable => 1, size => 32 },
395   "new_status",
396   { data_type => "varchar", is_nullable => 1, size => 32 },
397 );
398
399 =head1 PRIMARY KEY
400
401 =over 4
402
403 =item * L</itemnumber>
404
405 =back
406
407 =cut
408
409 __PACKAGE__->set_primary_key("itemnumber");
410
411 =head1 UNIQUE CONSTRAINTS
412
413 =head2 C<itembarcodeidx>
414
415 =over 4
416
417 =item * L</barcode>
418
419 =back
420
421 =cut
422
423 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
424
425 =head1 RELATIONS
426
427 =head2 accountlines
428
429 Type: has_many
430
431 Related object: L<Koha::Schema::Result::Accountline>
432
433 =cut
434
435 __PACKAGE__->has_many(
436   "accountlines",
437   "Koha::Schema::Result::Accountline",
438   { "foreign.itemnumber" => "self.itemnumber" },
439   { cascade_copy => 0, cascade_delete => 0 },
440 );
441
442 =head2 article_requests
443
444 Type: has_many
445
446 Related object: L<Koha::Schema::Result::ArticleRequest>
447
448 =cut
449
450 __PACKAGE__->has_many(
451   "article_requests",
452   "Koha::Schema::Result::ArticleRequest",
453   { "foreign.itemnumber" => "self.itemnumber" },
454   { cascade_copy => 0, cascade_delete => 0 },
455 );
456
457 =head2 biblioitemnumber
458
459 Type: belongs_to
460
461 Related object: L<Koha::Schema::Result::Biblioitem>
462
463 =cut
464
465 __PACKAGE__->belongs_to(
466   "biblioitemnumber",
467   "Koha::Schema::Result::Biblioitem",
468   { biblioitemnumber => "biblioitemnumber" },
469   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
470 );
471
472 =head2 biblionumber
473
474 Type: belongs_to
475
476 Related object: L<Koha::Schema::Result::Biblio>
477
478 =cut
479
480 __PACKAGE__->belongs_to(
481   "biblionumber",
482   "Koha::Schema::Result::Biblio",
483   { biblionumber => "biblionumber" },
484   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
485 );
486
487 =head2 branchtransfers
488
489 Type: has_many
490
491 Related object: L<Koha::Schema::Result::Branchtransfer>
492
493 =cut
494
495 __PACKAGE__->has_many(
496   "branchtransfers",
497   "Koha::Schema::Result::Branchtransfer",
498   { "foreign.itemnumber" => "self.itemnumber" },
499   { cascade_copy => 0, cascade_delete => 0 },
500 );
501
502 =head2 course_item
503
504 Type: might_have
505
506 Related object: L<Koha::Schema::Result::CourseItem>
507
508 =cut
509
510 __PACKAGE__->might_have(
511   "course_item",
512   "Koha::Schema::Result::CourseItem",
513   { "foreign.itemnumber" => "self.itemnumber" },
514   { cascade_copy => 0, cascade_delete => 0 },
515 );
516
517 =head2 creator_batches
518
519 Type: has_many
520
521 Related object: L<Koha::Schema::Result::CreatorBatch>
522
523 =cut
524
525 __PACKAGE__->has_many(
526   "creator_batches",
527   "Koha::Schema::Result::CreatorBatch",
528   { "foreign.item_number" => "self.itemnumber" },
529   { cascade_copy => 0, cascade_delete => 0 },
530 );
531
532 =head2 hold_fill_target
533
534 Type: might_have
535
536 Related object: L<Koha::Schema::Result::HoldFillTarget>
537
538 =cut
539
540 __PACKAGE__->might_have(
541   "hold_fill_target",
542   "Koha::Schema::Result::HoldFillTarget",
543   { "foreign.itemnumber" => "self.itemnumber" },
544   { cascade_copy => 0, cascade_delete => 0 },
545 );
546
547 =head2 holdingbranch
548
549 Type: belongs_to
550
551 Related object: L<Koha::Schema::Result::Branch>
552
553 =cut
554
555 __PACKAGE__->belongs_to(
556   "holdingbranch",
557   "Koha::Schema::Result::Branch",
558   { branchcode => "holdingbranch" },
559   {
560     is_deferrable => 1,
561     join_type     => "LEFT",
562     on_delete     => "RESTRICT",
563     on_update     => "CASCADE",
564   },
565 );
566
567 =head2 homebranch
568
569 Type: belongs_to
570
571 Related object: L<Koha::Schema::Result::Branch>
572
573 =cut
574
575 __PACKAGE__->belongs_to(
576   "homebranch",
577   "Koha::Schema::Result::Branch",
578   { branchcode => "homebranch" },
579   {
580     is_deferrable => 1,
581     join_type     => "LEFT",
582     on_delete     => "RESTRICT",
583     on_update     => "CASCADE",
584   },
585 );
586
587 =head2 issue
588
589 Type: might_have
590
591 Related object: L<Koha::Schema::Result::Issue>
592
593 =cut
594
595 __PACKAGE__->might_have(
596   "issue",
597   "Koha::Schema::Result::Issue",
598   { "foreign.itemnumber" => "self.itemnumber" },
599   { cascade_copy => 0, cascade_delete => 0 },
600 );
601
602 =head2 items_last_borrower
603
604 Type: might_have
605
606 Related object: L<Koha::Schema::Result::ItemsLastBorrower>
607
608 =cut
609
610 __PACKAGE__->might_have(
611   "items_last_borrower",
612   "Koha::Schema::Result::ItemsLastBorrower",
613   { "foreign.itemnumber" => "self.itemnumber" },
614   { cascade_copy => 0, cascade_delete => 0 },
615 );
616
617 =head2 old_issues
618
619 Type: has_many
620
621 Related object: L<Koha::Schema::Result::OldIssue>
622
623 =cut
624
625 __PACKAGE__->has_many(
626   "old_issues",
627   "Koha::Schema::Result::OldIssue",
628   { "foreign.itemnumber" => "self.itemnumber" },
629   { cascade_copy => 0, cascade_delete => 0 },
630 );
631
632 =head2 old_reserves
633
634 Type: has_many
635
636 Related object: L<Koha::Schema::Result::OldReserve>
637
638 =cut
639
640 __PACKAGE__->has_many(
641   "old_reserves",
642   "Koha::Schema::Result::OldReserve",
643   { "foreign.itemnumber" => "self.itemnumber" },
644   { cascade_copy => 0, cascade_delete => 0 },
645 );
646
647 =head2 reserves
648
649 Type: has_many
650
651 Related object: L<Koha::Schema::Result::Reserve>
652
653 =cut
654
655 __PACKAGE__->has_many(
656   "reserves",
657   "Koha::Schema::Result::Reserve",
658   { "foreign.itemnumber" => "self.itemnumber" },
659   { cascade_copy => 0, cascade_delete => 0 },
660 );
661
662 =head2 serialitem
663
664 Type: might_have
665
666 Related object: L<Koha::Schema::Result::Serialitem>
667
668 =cut
669
670 __PACKAGE__->might_have(
671   "serialitem",
672   "Koha::Schema::Result::Serialitem",
673   { "foreign.itemnumber" => "self.itemnumber" },
674   { cascade_copy => 0, cascade_delete => 0 },
675 );
676
677
678 # Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-10-24 13:56:21
679 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Vf1sBZrpUo0Cvi896fjNuA
680
681 __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" );
682
683 __PACKAGE__->belongs_to(
684   "biblio",
685   "Koha::Schema::Result::Biblio",
686   { biblionumber => "biblionumber" },
687   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
688 );
689
690 use C4::Context;
691 sub effective_itemtype {
692     my ( $self ) = @_;
693
694     my $pref = C4::Context->preference('item-level_itypes');
695     if ( $pref && $self->itype() ) {
696         return $self->itype();
697     } else {
698         warn "item-level_itypes set but no itemtype set for item (".$self->itemnumber.")"
699           if $pref;
700         return $self->biblioitemnumber()->itemtype();
701     }
702 }
703
704 1;