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