Bug 14045: DBIC 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_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 =cut
277
278 __PACKAGE__->add_columns(
279   "itemnumber",
280   { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
281   "biblionumber",
282   { data_type => "integer", default_value => 0, is_nullable => 0 },
283   "biblioitemnumber",
284   {
285     data_type      => "integer",
286     default_value  => 0,
287     is_foreign_key => 1,
288     is_nullable    => 0,
289   },
290   "barcode",
291   { data_type => "varchar", is_nullable => 1, size => 20 },
292   "dateaccessioned",
293   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
294   "booksellerid",
295   { data_type => "mediumtext", is_nullable => 1 },
296   "homebranch",
297   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
298   "price",
299   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
300   "replacementprice",
301   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
302   "replacementpricedate",
303   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
304   "datelastborrowed",
305   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
306   "datelastseen",
307   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
308   "stack",
309   { data_type => "tinyint", is_nullable => 1 },
310   "notforloan",
311   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
312   "damaged",
313   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
314   "itemlost",
315   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
316   "itemlost_on",
317   {
318     data_type => "datetime",
319     datetime_undef_if_invalid => 1,
320     is_nullable => 1,
321   },
322   "withdrawn",
323   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
324   "withdrawn_on",
325   {
326     data_type => "datetime",
327     datetime_undef_if_invalid => 1,
328     is_nullable => 1,
329   },
330   "itemcallnumber",
331   { data_type => "varchar", is_nullable => 1, size => 255 },
332   "coded_location_qualifier",
333   { data_type => "varchar", is_nullable => 1, size => 10 },
334   "issues",
335   { data_type => "smallint", is_nullable => 1 },
336   "renewals",
337   { data_type => "smallint", is_nullable => 1 },
338   "reserves",
339   { data_type => "smallint", is_nullable => 1 },
340   "restricted",
341   { data_type => "tinyint", is_nullable => 1 },
342   "itemnotes",
343   { data_type => "mediumtext", is_nullable => 1 },
344   "itemnotes_nonpublic",
345   { data_type => "mediumtext", is_nullable => 1 },
346   "holdingbranch",
347   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
348   "paidfor",
349   { data_type => "mediumtext", is_nullable => 1 },
350   "timestamp",
351   {
352     data_type => "timestamp",
353     datetime_undef_if_invalid => 1,
354     default_value => \"current_timestamp",
355     is_nullable => 0,
356   },
357   "location",
358   { data_type => "varchar", is_nullable => 1, size => 80 },
359   "permanent_location",
360   { data_type => "varchar", is_nullable => 1, size => 80 },
361   "onloan",
362   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
363   "cn_source",
364   { data_type => "varchar", is_nullable => 1, size => 10 },
365   "cn_sort",
366   { data_type => "varchar", is_nullable => 1, size => 255 },
367   "ccode",
368   { data_type => "varchar", is_nullable => 1, size => 10 },
369   "materials",
370   { data_type => "text", is_nullable => 1 },
371   "uri",
372   { data_type => "varchar", is_nullable => 1, size => 255 },
373   "itype",
374   { data_type => "varchar", is_nullable => 1, size => 10 },
375   "more_subfields_xml",
376   { data_type => "longtext", is_nullable => 1 },
377   "enumchron",
378   { data_type => "text", is_nullable => 1 },
379   "copynumber",
380   { data_type => "varchar", is_nullable => 1, size => 32 },
381   "stocknumber",
382   { data_type => "varchar", is_nullable => 1, size => 32 },
383 );
384
385 =head1 PRIMARY KEY
386
387 =over 4
388
389 =item * L</itemnumber>
390
391 =back
392
393 =cut
394
395 __PACKAGE__->set_primary_key("itemnumber");
396
397 =head1 UNIQUE CONSTRAINTS
398
399 =head2 C<itembarcodeidx>
400
401 =over 4
402
403 =item * L</barcode>
404
405 =back
406
407 =cut
408
409 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
410
411 =head1 RELATIONS
412
413 =head2 accountlines
414
415 Type: has_many
416
417 Related object: L<Koha::Schema::Result::Accountline>
418
419 =cut
420
421 __PACKAGE__->has_many(
422   "accountlines",
423   "Koha::Schema::Result::Accountline",
424   { "foreign.itemnumber" => "self.itemnumber" },
425   { cascade_copy => 0, cascade_delete => 0 },
426 );
427
428 =head2 biblioitemnumber
429
430 Type: belongs_to
431
432 Related object: L<Koha::Schema::Result::Biblioitem>
433
434 =cut
435
436 __PACKAGE__->belongs_to(
437   "biblioitemnumber",
438   "Koha::Schema::Result::Biblioitem",
439   { biblioitemnumber => "biblioitemnumber" },
440   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
441 );
442
443 =head2 branchtransfers
444
445 Type: has_many
446
447 Related object: L<Koha::Schema::Result::Branchtransfer>
448
449 =cut
450
451 __PACKAGE__->has_many(
452   "branchtransfers",
453   "Koha::Schema::Result::Branchtransfer",
454   { "foreign.itemnumber" => "self.itemnumber" },
455   { cascade_copy => 0, cascade_delete => 0 },
456 );
457
458 =head2 course_item
459
460 Type: might_have
461
462 Related object: L<Koha::Schema::Result::CourseItem>
463
464 =cut
465
466 __PACKAGE__->might_have(
467   "course_item",
468   "Koha::Schema::Result::CourseItem",
469   { "foreign.itemnumber" => "self.itemnumber" },
470   { cascade_copy => 0, cascade_delete => 0 },
471 );
472
473 =head2 creator_batches
474
475 Type: has_many
476
477 Related object: L<Koha::Schema::Result::CreatorBatch>
478
479 =cut
480
481 __PACKAGE__->has_many(
482   "creator_batches",
483   "Koha::Schema::Result::CreatorBatch",
484   { "foreign.item_number" => "self.itemnumber" },
485   { cascade_copy => 0, cascade_delete => 0 },
486 );
487
488 =head2 hold_fill_target
489
490 Type: might_have
491
492 Related object: L<Koha::Schema::Result::HoldFillTarget>
493
494 =cut
495
496 __PACKAGE__->might_have(
497   "hold_fill_target",
498   "Koha::Schema::Result::HoldFillTarget",
499   { "foreign.itemnumber" => "self.itemnumber" },
500   { cascade_copy => 0, cascade_delete => 0 },
501 );
502
503 =head2 holdingbranch
504
505 Type: belongs_to
506
507 Related object: L<Koha::Schema::Result::Branch>
508
509 =cut
510
511 __PACKAGE__->belongs_to(
512   "holdingbranch",
513   "Koha::Schema::Result::Branch",
514   { branchcode => "holdingbranch" },
515   {
516     is_deferrable => 1,
517     join_type     => "LEFT",
518     on_delete     => "RESTRICT",
519     on_update     => "CASCADE",
520   },
521 );
522
523 =head2 homebranch
524
525 Type: belongs_to
526
527 Related object: L<Koha::Schema::Result::Branch>
528
529 =cut
530
531 __PACKAGE__->belongs_to(
532   "homebranch",
533   "Koha::Schema::Result::Branch",
534   { branchcode => "homebranch" },
535   {
536     is_deferrable => 1,
537     join_type     => "LEFT",
538     on_delete     => "RESTRICT",
539     on_update     => "CASCADE",
540   },
541 );
542
543 =head2 issues
544
545 Type: has_many
546
547 Related object: L<Koha::Schema::Result::Issue>
548
549 =cut
550
551 __PACKAGE__->has_many(
552   "issues",
553   "Koha::Schema::Result::Issue",
554   { "foreign.itemnumber" => "self.itemnumber" },
555   { cascade_copy => 0, cascade_delete => 0 },
556 );
557
558 =head2 old_issues
559
560 Type: has_many
561
562 Related object: L<Koha::Schema::Result::OldIssue>
563
564 =cut
565
566 __PACKAGE__->has_many(
567   "old_issues",
568   "Koha::Schema::Result::OldIssue",
569   { "foreign.itemnumber" => "self.itemnumber" },
570   { cascade_copy => 0, cascade_delete => 0 },
571 );
572
573 =head2 old_reserves
574
575 Type: has_many
576
577 Related object: L<Koha::Schema::Result::OldReserve>
578
579 =cut
580
581 __PACKAGE__->has_many(
582   "old_reserves",
583   "Koha::Schema::Result::OldReserve",
584   { "foreign.itemnumber" => "self.itemnumber" },
585   { cascade_copy => 0, cascade_delete => 0 },
586 );
587
588 =head2 reserves
589
590 Type: has_many
591
592 Related object: L<Koha::Schema::Result::Reserve>
593
594 =cut
595
596 __PACKAGE__->has_many(
597   "reserves",
598   "Koha::Schema::Result::Reserve",
599   { "foreign.itemnumber" => "self.itemnumber" },
600   { cascade_copy => 0, cascade_delete => 0 },
601 );
602
603 =head2 serialitem
604
605 Type: might_have
606
607 Related object: L<Koha::Schema::Result::Serialitem>
608
609 =cut
610
611 __PACKAGE__->might_have(
612   "serialitem",
613   "Koha::Schema::Result::Serialitem",
614   { "foreign.itemnumber" => "self.itemnumber" },
615   { cascade_copy => 0, cascade_delete => 0 },
616 );
617
618
619 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-04-23 12:42:12
620 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:urSpNt7LBda4T5Plhi6cPw
621
622 sub effective_itemtype {
623     my ( $self ) = @_;
624
625     my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes');
626     if ( $pref->value() && $self->itype() ) {
627         return $self->itype();
628     } else {
629         warn "item-level_itypes set but no itemtype set for item ($self->itemnumber)"
630           if $pref->value();
631         return $self->biblioitemnumber()->itemtype();
632     }
633 }
634
635 1;