Bug 11844: Use additional fields for order lines
[koha.git] / Koha / Schema / Result / Aqorder.pm
1 use utf8;
2 package Koha::Schema::Result::Aqorder;
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::Aqorder
10
11 =cut
12
13 use strict;
14 use warnings;
15
16 use base 'DBIx::Class::Core';
17
18 =head1 TABLE: C<aqorders>
19
20 =cut
21
22 __PACKAGE__->table("aqorders");
23
24 =head1 ACCESSORS
25
26 =head2 ordernumber
27
28   data_type: 'integer'
29   is_auto_increment: 1
30   is_nullable: 0
31
32 primary key and unique identifier assigned by Koha to each line
33
34 =head2 biblionumber
35
36   data_type: 'integer'
37   is_foreign_key: 1
38   is_nullable: 1
39
40 links the order to the biblio being ordered (biblio.biblionumber)
41
42 =head2 deleted_biblionumber
43
44   data_type: 'integer'
45   is_nullable: 1
46
47 links the order to the deleted bibliographic record (deletedbiblio.biblionumber)
48
49 =head2 entrydate
50
51   data_type: 'date'
52   datetime_undef_if_invalid: 1
53   is_nullable: 1
54
55 the date the bib was added to the basket
56
57 =head2 quantity
58
59   data_type: 'smallint'
60   is_nullable: 1
61
62 the quantity ordered
63
64 =head2 currency
65
66   data_type: 'varchar'
67   is_foreign_key: 1
68   is_nullable: 1
69   size: 10
70
71 the currency used for the purchase
72
73 =head2 listprice
74
75   data_type: 'decimal'
76   is_nullable: 1
77   size: [28,6]
78
79 the vendor price for this line item
80
81 =head2 datereceived
82
83   data_type: 'date'
84   datetime_undef_if_invalid: 1
85   is_nullable: 1
86
87 the date this order was received
88
89 =head2 invoiceid
90
91   data_type: 'integer'
92   is_foreign_key: 1
93   is_nullable: 1
94
95 id of invoice
96
97 =head2 freight
98
99   data_type: 'decimal'
100   is_nullable: 1
101   size: [28,6]
102
103 shipping costs (not used)
104
105 =head2 unitprice
106
107   data_type: 'decimal'
108   is_nullable: 1
109   size: [28,6]
110
111 the actual cost entered when receiving this line item
112
113 =head2 unitprice_tax_excluded
114
115   data_type: 'decimal'
116   is_nullable: 1
117   size: [28,6]
118
119 the unit price excluding tax (on receiving)
120
121 =head2 unitprice_tax_included
122
123   data_type: 'decimal'
124   is_nullable: 1
125   size: [28,6]
126
127 the unit price including tax (on receiving)
128
129 =head2 quantityreceived
130
131   data_type: 'smallint'
132   default_value: 0
133   is_nullable: 0
134
135 the quantity that have been received so far
136
137 =head2 created_by
138
139   data_type: 'integer'
140   is_foreign_key: 1
141   is_nullable: 1
142
143 the borrowernumber of order line's creator
144
145 =head2 datecancellationprinted
146
147   data_type: 'date'
148   datetime_undef_if_invalid: 1
149   is_nullable: 1
150
151 the date the line item was deleted
152
153 =head2 cancellationreason
154
155   data_type: 'mediumtext'
156   is_nullable: 1
157
158 reason of cancellation
159
160 =head2 order_internalnote
161
162   data_type: 'longtext'
163   is_nullable: 1
164
165 notes related to this order line, made for staff
166
167 =head2 order_vendornote
168
169   data_type: 'longtext'
170   is_nullable: 1
171
172 notes related to this order line, made for vendor
173
174 =head2 purchaseordernumber
175
176   data_type: 'longtext'
177   is_nullable: 1
178
179 not used? always NULL
180
181 =head2 basketno
182
183   data_type: 'integer'
184   is_foreign_key: 1
185   is_nullable: 1
186
187 links this order line to a specific basket (aqbasket.basketno)
188
189 =head2 timestamp
190
191   data_type: 'timestamp'
192   datetime_undef_if_invalid: 1
193   default_value: current_timestamp
194   is_nullable: 0
195
196 the date and time this order line was last modified
197
198 =head2 rrp
199
200   data_type: 'decimal'
201   is_nullable: 1
202   size: [13,2]
203
204 the retail cost for this line item
205
206 =head2 replacementprice
207
208   data_type: 'decimal'
209   is_nullable: 1
210   size: [28,6]
211
212 the replacement cost for this line item
213
214 =head2 rrp_tax_excluded
215
216   data_type: 'decimal'
217   is_nullable: 1
218   size: [28,6]
219
220 the replacement cost excluding tax
221
222 =head2 rrp_tax_included
223
224   data_type: 'decimal'
225   is_nullable: 1
226   size: [28,6]
227
228 the replacement cost including tax
229
230 =head2 ecost
231
232   data_type: 'decimal'
233   is_nullable: 1
234   size: [13,2]
235
236 the replacement cost for this line item
237
238 =head2 ecost_tax_excluded
239
240   data_type: 'decimal'
241   is_nullable: 1
242   size: [28,6]
243
244 the estimated cost excluding tax
245
246 =head2 ecost_tax_included
247
248   data_type: 'decimal'
249   is_nullable: 1
250   size: [28,6]
251
252 the estimated cost including tax
253
254 =head2 tax_rate_bak
255
256   data_type: 'decimal'
257   is_nullable: 1
258   size: [6,4]
259
260 the tax rate for this line item (%)
261
262 =head2 tax_rate_on_ordering
263
264   data_type: 'decimal'
265   is_nullable: 1
266   size: [6,4]
267
268 the tax rate on ordering for this line item (%)
269
270 =head2 tax_rate_on_receiving
271
272   data_type: 'decimal'
273   is_nullable: 1
274   size: [6,4]
275
276 the tax rate on receiving for this line item (%)
277
278 =head2 tax_value_bak
279
280   data_type: 'decimal'
281   is_nullable: 1
282   size: [28,6]
283
284 the tax value for this line item
285
286 =head2 tax_value_on_ordering
287
288   data_type: 'decimal'
289   is_nullable: 1
290   size: [28,6]
291
292 the tax value on ordering for this line item
293
294 =head2 tax_value_on_receiving
295
296   data_type: 'decimal'
297   is_nullable: 1
298   size: [28,6]
299
300 the tax value on receiving for this line item
301
302 =head2 discount
303
304   data_type: 'float'
305   is_nullable: 1
306   size: [6,4]
307
308 the discount for this line item (%)
309
310 =head2 budget_id
311
312   data_type: 'integer'
313   is_foreign_key: 1
314   is_nullable: 0
315
316 the fund this order goes against (aqbudgets.budget_id)
317
318 =head2 budgetdate
319
320   data_type: 'date'
321   datetime_undef_if_invalid: 1
322   is_nullable: 1
323
324 not used? always NULL
325
326 =head2 sort1
327
328   data_type: 'varchar'
329   is_nullable: 1
330   size: 80
331
332 statistical field
333
334 =head2 sort2
335
336   data_type: 'varchar'
337   is_nullable: 1
338   size: 80
339
340 second statistical field
341
342 =head2 sort1_authcat
343
344   data_type: 'varchar'
345   is_nullable: 1
346   size: 10
347
348 =head2 sort2_authcat
349
350   data_type: 'varchar'
351   is_nullable: 1
352   size: 10
353
354 =head2 uncertainprice
355
356   data_type: 'tinyint'
357   is_nullable: 1
358
359 was this price uncertain (1 for yes, 0 for no)
360
361 =head2 subscriptionid
362
363   data_type: 'integer'
364   is_foreign_key: 1
365   is_nullable: 1
366
367 links this order line to a subscription (subscription.subscriptionid)
368
369 =head2 parent_ordernumber
370
371   data_type: 'integer'
372   is_nullable: 1
373
374 ordernumber of parent order line, or same as ordernumber if no parent
375
376 =head2 orderstatus
377
378   data_type: 'varchar'
379   default_value: 'new'
380   is_nullable: 1
381   size: 16
382
383 the current status for this line item. Can be 'new', 'ordered', 'partial', 'complete' or 'cancelled'
384
385 =head2 line_item_id
386
387   data_type: 'varchar'
388   is_nullable: 1
389   size: 35
390
391 Supplier's article id for Edifact orderline
392
393 =head2 suppliers_reference_number
394
395   data_type: 'varchar'
396   is_nullable: 1
397   size: 35
398
399 Suppliers unique edifact quote ref
400
401 =head2 suppliers_reference_qualifier
402
403   data_type: 'varchar'
404   is_nullable: 1
405   size: 3
406
407 Type of number above usually 'QLI'
408
409 =head2 suppliers_report
410
411   data_type: 'mediumtext'
412   is_nullable: 1
413
414 reports received from suppliers
415
416 =head2 estimated_delivery_date
417
418   data_type: 'date'
419   datetime_undef_if_invalid: 1
420   is_nullable: 1
421
422 Estimated delivery date
423
424 =head2 invoice_unitprice
425
426   data_type: 'decimal'
427   is_nullable: 1
428   size: [28,6]
429
430 the unit price in foreign currency
431
432 =head2 invoice_currency
433
434   data_type: 'varchar'
435   is_foreign_key: 1
436   is_nullable: 1
437   size: 10
438
439 the currency of the invoice_unitprice
440
441 =cut
442
443 __PACKAGE__->add_columns(
444   "ordernumber",
445   { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
446   "biblionumber",
447   { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
448   "deleted_biblionumber",
449   { data_type => "integer", is_nullable => 1 },
450   "entrydate",
451   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
452   "quantity",
453   { data_type => "smallint", is_nullable => 1 },
454   "currency",
455   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
456   "listprice",
457   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
458   "datereceived",
459   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
460   "invoiceid",
461   { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
462   "freight",
463   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
464   "unitprice",
465   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
466   "unitprice_tax_excluded",
467   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
468   "unitprice_tax_included",
469   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
470   "quantityreceived",
471   { data_type => "smallint", default_value => 0, is_nullable => 0 },
472   "created_by",
473   { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
474   "datecancellationprinted",
475   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
476   "cancellationreason",
477   { data_type => "mediumtext", is_nullable => 1 },
478   "order_internalnote",
479   { data_type => "longtext", is_nullable => 1 },
480   "order_vendornote",
481   { data_type => "longtext", is_nullable => 1 },
482   "purchaseordernumber",
483   { data_type => "longtext", is_nullable => 1 },
484   "basketno",
485   { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
486   "timestamp",
487   {
488     data_type => "timestamp",
489     datetime_undef_if_invalid => 1,
490     default_value => \"current_timestamp",
491     is_nullable => 0,
492   },
493   "rrp",
494   { data_type => "decimal", is_nullable => 1, size => [13, 2] },
495   "replacementprice",
496   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
497   "rrp_tax_excluded",
498   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
499   "rrp_tax_included",
500   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
501   "ecost",
502   { data_type => "decimal", is_nullable => 1, size => [13, 2] },
503   "ecost_tax_excluded",
504   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
505   "ecost_tax_included",
506   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
507   "tax_rate_bak",
508   { data_type => "decimal", is_nullable => 1, size => [6, 4] },
509   "tax_rate_on_ordering",
510   { data_type => "decimal", is_nullable => 1, size => [6, 4] },
511   "tax_rate_on_receiving",
512   { data_type => "decimal", is_nullable => 1, size => [6, 4] },
513   "tax_value_bak",
514   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
515   "tax_value_on_ordering",
516   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
517   "tax_value_on_receiving",
518   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
519   "discount",
520   { data_type => "float", is_nullable => 1, size => [6, 4] },
521   "budget_id",
522   { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
523   "budgetdate",
524   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
525   "sort1",
526   { data_type => "varchar", is_nullable => 1, size => 80 },
527   "sort2",
528   { data_type => "varchar", is_nullable => 1, size => 80 },
529   "sort1_authcat",
530   { data_type => "varchar", is_nullable => 1, size => 10 },
531   "sort2_authcat",
532   { data_type => "varchar", is_nullable => 1, size => 10 },
533   "uncertainprice",
534   { data_type => "tinyint", is_nullable => 1 },
535   "subscriptionid",
536   { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
537   "parent_ordernumber",
538   { data_type => "integer", is_nullable => 1 },
539   "orderstatus",
540   {
541     data_type => "varchar",
542     default_value => "new",
543     is_nullable => 1,
544     size => 16,
545   },
546   "line_item_id",
547   { data_type => "varchar", is_nullable => 1, size => 35 },
548   "suppliers_reference_number",
549   { data_type => "varchar", is_nullable => 1, size => 35 },
550   "suppliers_reference_qualifier",
551   { data_type => "varchar", is_nullable => 1, size => 3 },
552   "suppliers_report",
553   { data_type => "mediumtext", is_nullable => 1 },
554   "estimated_delivery_date",
555   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
556   "invoice_unitprice",
557   { data_type => "decimal", is_nullable => 1, size => [28, 6] },
558   "invoice_currency",
559   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
560 );
561
562 =head1 PRIMARY KEY
563
564 =over 4
565
566 =item * L</ordernumber>
567
568 =back
569
570 =cut
571
572 __PACKAGE__->set_primary_key("ordernumber");
573
574 =head1 RELATIONS
575
576 =head2 aqorder_users
577
578 Type: has_many
579
580 Related object: L<Koha::Schema::Result::AqorderUser>
581
582 =cut
583
584 __PACKAGE__->has_many(
585   "aqorder_users",
586   "Koha::Schema::Result::AqorderUser",
587   { "foreign.ordernumber" => "self.ordernumber" },
588   { cascade_copy => 0, cascade_delete => 0 },
589 );
590
591 =head2 aqorders_claims
592
593 Type: has_many
594
595 Related object: L<Koha::Schema::Result::AqordersClaim>
596
597 =cut
598
599 __PACKAGE__->has_many(
600   "aqorders_claims",
601   "Koha::Schema::Result::AqordersClaim",
602   { "foreign.ordernumber" => "self.ordernumber" },
603   { cascade_copy => 0, cascade_delete => 0 },
604 );
605
606 =head2 aqorders_items
607
608 Type: has_many
609
610 Related object: L<Koha::Schema::Result::AqordersItem>
611
612 =cut
613
614 __PACKAGE__->has_many(
615   "aqorders_items",
616   "Koha::Schema::Result::AqordersItem",
617   { "foreign.ordernumber" => "self.ordernumber" },
618   { cascade_copy => 0, cascade_delete => 0 },
619 );
620
621 =head2 aqorders_transfers_ordernumber_from
622
623 Type: might_have
624
625 Related object: L<Koha::Schema::Result::AqordersTransfer>
626
627 =cut
628
629 __PACKAGE__->might_have(
630   "aqorders_transfers_ordernumber_from",
631   "Koha::Schema::Result::AqordersTransfer",
632   { "foreign.ordernumber_from" => "self.ordernumber" },
633   { cascade_copy => 0, cascade_delete => 0 },
634 );
635
636 =head2 aqorders_transfers_ordernumber_to
637
638 Type: might_have
639
640 Related object: L<Koha::Schema::Result::AqordersTransfer>
641
642 =cut
643
644 __PACKAGE__->might_have(
645   "aqorders_transfers_ordernumber_to",
646   "Koha::Schema::Result::AqordersTransfer",
647   { "foreign.ordernumber_to" => "self.ordernumber" },
648   { cascade_copy => 0, cascade_delete => 0 },
649 );
650
651 =head2 basketno
652
653 Type: belongs_to
654
655 Related object: L<Koha::Schema::Result::Aqbasket>
656
657 =cut
658
659 __PACKAGE__->belongs_to(
660   "basketno",
661   "Koha::Schema::Result::Aqbasket",
662   { basketno => "basketno" },
663   {
664     is_deferrable => 1,
665     join_type     => "LEFT",
666     on_delete     => "CASCADE",
667     on_update     => "CASCADE",
668   },
669 );
670
671 =head2 biblionumber
672
673 Type: belongs_to
674
675 Related object: L<Koha::Schema::Result::Biblio>
676
677 =cut
678
679 __PACKAGE__->belongs_to(
680   "biblionumber",
681   "Koha::Schema::Result::Biblio",
682   { biblionumber => "biblionumber" },
683   {
684     is_deferrable => 1,
685     join_type     => "LEFT",
686     on_delete     => "SET NULL",
687     on_update     => "CASCADE",
688   },
689 );
690
691 =head2 budget
692
693 Type: belongs_to
694
695 Related object: L<Koha::Schema::Result::Aqbudget>
696
697 =cut
698
699 __PACKAGE__->belongs_to(
700   "budget",
701   "Koha::Schema::Result::Aqbudget",
702   { budget_id => "budget_id" },
703   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
704 );
705
706 =head2 created_by
707
708 Type: belongs_to
709
710 Related object: L<Koha::Schema::Result::Borrower>
711
712 =cut
713
714 __PACKAGE__->belongs_to(
715   "created_by",
716   "Koha::Schema::Result::Borrower",
717   { borrowernumber => "created_by" },
718   {
719     is_deferrable => 1,
720     join_type     => "LEFT",
721     on_delete     => "SET NULL",
722     on_update     => "CASCADE",
723   },
724 );
725
726 =head2 currency
727
728 Type: belongs_to
729
730 Related object: L<Koha::Schema::Result::Currency>
731
732 =cut
733
734 __PACKAGE__->belongs_to(
735   "currency",
736   "Koha::Schema::Result::Currency",
737   { currency => "currency" },
738   {
739     is_deferrable => 1,
740     join_type     => "LEFT",
741     on_delete     => "SET NULL",
742     on_update     => "SET NULL",
743   },
744 );
745
746 =head2 invoice_currency
747
748 Type: belongs_to
749
750 Related object: L<Koha::Schema::Result::Currency>
751
752 =cut
753
754 __PACKAGE__->belongs_to(
755   "invoice_currency",
756   "Koha::Schema::Result::Currency",
757   { currency => "invoice_currency" },
758   {
759     is_deferrable => 1,
760     join_type     => "LEFT",
761     on_delete     => "SET NULL",
762     on_update     => "SET NULL",
763   },
764 );
765
766 =head2 invoiceid
767
768 Type: belongs_to
769
770 Related object: L<Koha::Schema::Result::Aqinvoice>
771
772 =cut
773
774 __PACKAGE__->belongs_to(
775   "invoiceid",
776   "Koha::Schema::Result::Aqinvoice",
777   { invoiceid => "invoiceid" },
778   {
779     is_deferrable => 1,
780     join_type     => "LEFT",
781     on_delete     => "SET NULL",
782     on_update     => "CASCADE",
783   },
784 );
785
786 =head2 subscriptionid
787
788 Type: belongs_to
789
790 Related object: L<Koha::Schema::Result::Subscription>
791
792 =cut
793
794 __PACKAGE__->belongs_to(
795   "subscriptionid",
796   "Koha::Schema::Result::Subscription",
797   { subscriptionid => "subscriptionid" },
798   {
799     is_deferrable => 1,
800     join_type     => "LEFT",
801     on_delete     => "CASCADE",
802     on_update     => "CASCADE",
803   },
804 );
805
806 =head2 borrowernumbers
807
808 Type: many_to_many
809
810 Composing rels: L</aqorder_users> -> borrowernumber
811
812 =cut
813
814 __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber");
815
816
817 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-05-05 12:31:38
818 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Bt8GMBWcWja5oa7r+8Vbig
819
820 __PACKAGE__->belongs_to(
821   "basket",
822   "Koha::Schema::Result::Aqbasket",
823   { "foreign.basketno" => "self.basketno" },
824   {
825     is_deferrable => 1,
826     join_type     => "LEFT",
827     on_delete     => "CASCADE",
828     on_update     => "CASCADE",
829   },
830 );
831
832 __PACKAGE__->belongs_to(
833   "biblio",
834   "Koha::Schema::Result::Biblio",
835   { 'foreign.biblionumber' => "self.biblionumber" },
836   {
837     is_deferrable => 1,
838     join_type     => "LEFT",
839     on_delete     => "SET NULL",
840     on_update     => "CASCADE",
841   },
842 );
843
844 __PACKAGE__->belongs_to(
845   "fund",
846   "Koha::Schema::Result::Aqbudget",
847   { "foreign.budget_id" => "self.budget_id" },
848   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
849 );
850
851 __PACKAGE__->belongs_to(
852   "invoice",
853   "Koha::Schema::Result::Aqinvoice",
854   { "foreign.invoiceid" => "self.invoiceid" },
855   {
856     is_deferrable => 1,
857     join_type     => "LEFT",
858     on_delete     => "SET NULL",
859     on_update     => "CASCADE",
860   },
861 );
862
863 =head2 creator
864
865 Type: belongs_to
866
867 Related object: L<Koha::Schema::Result::Borrower>
868
869 =cut
870
871 __PACKAGE__->belongs_to(
872   "creator",
873   "Koha::Schema::Result::Borrower",
874   { borrowernumber => "created_by" },
875   {
876     is_deferrable => 1,
877     join_type     => "LEFT",
878     on_delete     => "SET NULL",
879     on_update     => "CASCADE",
880   },
881 );
882
883 __PACKAGE__->belongs_to(
884   "subscription",
885   "Koha::Schema::Result::Subscription",
886   { "foreign.subscriptionid" => "self.subscriptionid" },
887   {
888     is_deferrable => 1,
889     join_type     => "LEFT",
890     on_delete     => "CASCADE",
891     on_update     => "CASCADE",
892   },
893 );
894
895 __PACKAGE__->has_many(
896   "additional_field_values",
897   "Koha::Schema::Result::AdditionalFieldValue",
898   sub {
899     my ($args) = @_;
900
901     return {
902         "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.ordernumber" },
903
904         # TODO Add column additional_field_values.tablename to avoid subquery ?
905         "$args->{foreign_alias}.field_id" =>
906             { -in => \'(SELECT id FROM additional_fields WHERE tablename = "aqorders")' },
907     };
908   },
909   { cascade_copy => 0, cascade_delete => 0 },
910 );
911
912 sub koha_objects_class {
913     'Koha::Acquisition::Orders';
914 }
915
916 sub koha_object_class {
917     'Koha::Acquisition::Order';
918 }
919
920 __PACKAGE__->add_columns(
921     '+uncertainprice' => { is_boolean => 1 }
922 );
923
924 1;