From 9e9bd14a05ec5aa86a977c87e5080ed203d2742f Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Tue, 15 Jul 2014 10:39:25 -0400
Subject: [PATCH] Bug 6427 - Update schema files

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Sean McGarvey <seanm@pascolibraries.org>
---
 Koha/Schema/Result/AccountCredit.pm |  171 +++++++++++++++++++++++++++
 Koha/Schema/Result/AccountDebit.pm  |  219 +++++++++++++++++++++++++++++++++++
 Koha/Schema/Result/AccountOffset.pm |  147 +++++++++++++++++++++++
 Koha/Schema/Result/Borrower.pm      |   30 ++++--
 Koha/Schema/Result/Branch.pm        |   32 +++++-
 Koha/Schema/Result/Deleteditem.pm   |   11 ++
 Koha/Schema/Result/Issue.pm         |   13 ++-
 Koha/Schema/Result/Item.pm          |   15 ---
 Koha/Schema/Result/OldIssue.pm      |   28 +++++-
 9 files changed, 636 insertions(+), 30 deletions(-)
 create mode 100644 Koha/Schema/Result/AccountCredit.pm
 create mode 100644 Koha/Schema/Result/AccountDebit.pm
 create mode 100644 Koha/Schema/Result/AccountOffset.pm

diff --git a/Koha/Schema/Result/AccountCredit.pm b/Koha/Schema/Result/AccountCredit.pm
new file mode 100644
index 0000000..6f614dc
--- /dev/null
+++ b/Koha/Schema/Result/AccountCredit.pm
@@ -0,0 +1,171 @@
+use utf8;
+package Koha::Schema::Result::AccountCredit;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::AccountCredit
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<account_credits>
+
+=cut
+
+__PACKAGE__->table("account_credits");
+
+=head1 ACCESSORS
+
+=head2 credit_id
+
+  data_type: 'integer'
+  is_auto_increment: 1
+  is_nullable: 0
+
+=head2 borrowernumber
+
+  data_type: 'integer'
+  is_nullable: 0
+
+=head2 type
+
+  data_type: 'varchar'
+  is_nullable: 0
+  size: 255
+
+=head2 amount_received
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 amount_paid
+
+  data_type: 'decimal'
+  is_nullable: 0
+  size: [28,6]
+
+=head2 amount_remaining
+
+  data_type: 'decimal'
+  is_nullable: 0
+  size: [28,6]
+
+=head2 amount_voided
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 notes
+
+  data_type: 'text'
+  is_nullable: 1
+
+=head2 branchcode
+
+  data_type: 'varchar'
+  is_nullable: 1
+  size: 10
+
+=head2 manager_id
+
+  data_type: 'integer'
+  is_nullable: 1
+
+=head2 created_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  is_nullable: 1
+
+=head2 updated_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+  "credit_id",
+  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
+  "borrowernumber",
+  { data_type => "integer", is_nullable => 0 },
+  "type",
+  { data_type => "varchar", is_nullable => 0, size => 255 },
+  "amount_received",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "amount_paid",
+  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
+  "amount_remaining",
+  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
+  "amount_voided",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "notes",
+  { data_type => "text", is_nullable => 1 },
+  "branchcode",
+  { data_type => "varchar", is_nullable => 1, size => 10 },
+  "manager_id",
+  { data_type => "integer", is_nullable => 1 },
+  "created_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    is_nullable => 1,
+  },
+  "updated_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    is_nullable => 1,
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</credit_id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("credit_id");
+
+=head1 RELATIONS
+
+=head2 account_offsets
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AccountOffset>
+
+=cut
+
+__PACKAGE__->has_many(
+  "account_offsets",
+  "Koha::Schema::Result::AccountOffset",
+  { "foreign.credit_id" => "self.credit_id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07040 @ 2015-01-14 08:52:49
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nxB+s5t2sdcV71a+ElhYmg
+
+__PACKAGE__->belongs_to(
+  "borrower",
+  "Koha::Schema::Result::Borrower",
+  { borrowernumber => "borrowernumber" },
+);
+
+1;
diff --git a/Koha/Schema/Result/AccountDebit.pm b/Koha/Schema/Result/AccountDebit.pm
new file mode 100644
index 0000000..f9ca3d5
--- /dev/null
+++ b/Koha/Schema/Result/AccountDebit.pm
@@ -0,0 +1,219 @@
+use utf8;
+package Koha::Schema::Result::AccountDebit;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::AccountDebit
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<account_debits>
+
+=cut
+
+__PACKAGE__->table("account_debits");
+
+=head1 ACCESSORS
+
+=head2 debit_id
+
+  data_type: 'integer'
+  is_auto_increment: 1
+  is_nullable: 0
+
+=head2 borrowernumber
+
+  data_type: 'integer'
+  default_value: 0
+  is_nullable: 0
+
+=head2 itemnumber
+
+  data_type: 'integer'
+  is_nullable: 1
+
+=head2 issue_id
+
+  data_type: 'integer'
+  is_nullable: 1
+
+=head2 type
+
+  data_type: 'varchar'
+  is_nullable: 0
+  size: 255
+
+=head2 accruing
+
+  data_type: 'tinyint'
+  default_value: 0
+  is_nullable: 0
+
+=head2 amount_original
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 amount_outstanding
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 amount_last_increment
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 description
+
+  data_type: 'mediumtext'
+  is_nullable: 1
+
+=head2 notes
+
+  data_type: 'text'
+  is_nullable: 1
+
+=head2 branchcode
+
+  data_type: 'varchar'
+  is_nullable: 1
+  size: 10
+
+=head2 manager_id
+
+  data_type: 'integer'
+  is_nullable: 1
+
+=head2 created_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  is_nullable: 1
+
+=head2 updated_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  is_nullable: 1
+
+=cut
+
+__PACKAGE__->add_columns(
+  "debit_id",
+  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
+  "borrowernumber",
+  { data_type => "integer", default_value => 0, is_nullable => 0 },
+  "itemnumber",
+  { data_type => "integer", is_nullable => 1 },
+  "issue_id",
+  { data_type => "integer", is_nullable => 1 },
+  "type",
+  { data_type => "varchar", is_nullable => 0, size => 255 },
+  "accruing",
+  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
+  "amount_original",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "amount_outstanding",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "amount_last_increment",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "description",
+  { data_type => "mediumtext", is_nullable => 1 },
+  "notes",
+  { data_type => "text", is_nullable => 1 },
+  "branchcode",
+  { data_type => "varchar", is_nullable => 1, size => 10 },
+  "manager_id",
+  { data_type => "integer", is_nullable => 1 },
+  "created_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    is_nullable => 1,
+  },
+  "updated_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    is_nullable => 1,
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</debit_id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("debit_id");
+
+=head1 RELATIONS
+
+=head2 account_offsets
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AccountOffset>
+
+=cut
+
+__PACKAGE__->has_many(
+  "account_offsets",
+  "Koha::Schema::Result::AccountOffset",
+  { "foreign.debit_id" => "self.debit_id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07040 @ 2015-01-14 08:52:49
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:M6yz+EMdQ1c79RewRIXX1g
+
+__PACKAGE__->belongs_to(
+  "item",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "itemnumber" }
+);
+
+__PACKAGE__->belongs_to(
+  "deleted_item",
+  "Koha::Schema::Result::Deleteditem",
+  { itemnumber => "itemnumber" }
+);
+
+__PACKAGE__->belongs_to(
+  "issue",
+  "Koha::Schema::Result::Issue",
+  { issue_id => "issue_id" }
+);
+
+__PACKAGE__->belongs_to(
+  "old_issue",
+  "Koha::Schema::Result::OldIssue",
+  { issue_id => "issue_id" }
+);
+
+__PACKAGE__->belongs_to(
+  "borrower",
+  "Koha::Schema::Result::Borrower",
+  { borrowernumber => "borrowernumber" },
+  { on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+# You can replace this text with custom content, and it will be preserved on regeneration
+1;
diff --git a/Koha/Schema/Result/AccountOffset.pm b/Koha/Schema/Result/AccountOffset.pm
new file mode 100644
index 0000000..baabeac
--- /dev/null
+++ b/Koha/Schema/Result/AccountOffset.pm
@@ -0,0 +1,147 @@
+use utf8;
+package Koha::Schema::Result::AccountOffset;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+=head1 NAME
+
+Koha::Schema::Result::AccountOffset
+
+=cut
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+=head1 TABLE: C<account_offsets>
+
+=cut
+
+__PACKAGE__->table("account_offsets");
+
+=head1 ACCESSORS
+
+=head2 offset_id
+
+  data_type: 'integer'
+  is_auto_increment: 1
+  is_nullable: 0
+
+=head2 debit_id
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 1
+
+=head2 credit_id
+
+  data_type: 'integer'
+  is_foreign_key: 1
+  is_nullable: 1
+
+=head2 type
+
+  data_type: 'varchar'
+  is_nullable: 1
+  size: 255
+
+=head2 amount
+
+  data_type: 'decimal'
+  is_nullable: 0
+  size: [28,6]
+
+A positive number here represents a payment, a negative is a increase in a fine.
+
+=head2 created_on
+
+  data_type: 'timestamp'
+  datetime_undef_if_invalid: 1
+  default_value: current_timestamp
+  is_nullable: 0
+
+=cut
+
+__PACKAGE__->add_columns(
+  "offset_id",
+  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
+  "debit_id",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+  "credit_id",
+  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+  "type",
+  { data_type => "varchar", is_nullable => 1, size => 255 },
+  "amount",
+  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
+  "created_on",
+  {
+    data_type => "timestamp",
+    datetime_undef_if_invalid => 1,
+    default_value => \"current_timestamp",
+    is_nullable => 0,
+  },
+);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</offset_id>
+
+=back
+
+=cut
+
+__PACKAGE__->set_primary_key("offset_id");
+
+=head1 RELATIONS
+
+=head2 credit
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::AccountCredit>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "credit",
+  "Koha::Schema::Result::AccountCredit",
+  { credit_id => "credit_id" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "CASCADE",
+    on_update     => "CASCADE",
+  },
+);
+
+=head2 debit
+
+Type: belongs_to
+
+Related object: L<Koha::Schema::Result::AccountDebit>
+
+=cut
+
+__PACKAGE__->belongs_to(
+  "debit",
+  "Koha::Schema::Result::AccountDebit",
+  { debit_id => "debit_id" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "CASCADE",
+    on_update     => "CASCADE",
+  },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07040 @ 2014-07-15 10:03:45
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CQJiVGoCnQEzkVu9ssgU/Q
+
+
+# You can replace this text with custom content, and it will be preserved on regeneration
+1;
diff --git a/Koha/Schema/Result/Borrower.pm b/Koha/Schema/Result/Borrower.pm
index e9f8838..ef76dcd 100644
--- a/Koha/Schema/Result/Borrower.pm
+++ b/Koha/Schema/Result/Borrower.pm
@@ -407,6 +407,12 @@ __PACKAGE__->table("borrowers");
   default_value: 1
   is_nullable: 0
 
+=head2 account_balance
+
+  data_type: 'decimal'
+  is_nullable: 0
+  size: [28,6]
+
 =cut
 
 __PACKAGE__->add_columns(
@@ -576,6 +582,8 @@ __PACKAGE__->add_columns(
   { data_type => "varchar", is_nullable => 1, size => 50 },
   "privacy",
   { data_type => "integer", default_value => 1, is_nullable => 0 },
+  "account_balance",
+  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
 );
 
 =head1 PRIMARY KEY
@@ -618,32 +626,32 @@ __PACKAGE__->add_unique_constraint("userid", ["userid"]);
 
 =head1 RELATIONS
 
-=head2 accountlines
+=head2 account_credits
 
 Type: has_many
 
-Related object: L<Koha::Schema::Result::Accountline>
+Related object: L<Koha::Schema::Result::AccountCredit>
 
 =cut
 
 __PACKAGE__->has_many(
-  "accountlines",
-  "Koha::Schema::Result::Accountline",
+  "account_credits",
+  "Koha::Schema::Result::AccountCredit",
   { "foreign.borrowernumber" => "self.borrowernumber" },
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
-=head2 accountoffsets
+=head2 account_debits
 
 Type: has_many
 
-Related object: L<Koha::Schema::Result::Accountoffset>
+Related object: L<Koha::Schema::Result::AccountDebit>
 
 =cut
 
 __PACKAGE__->has_many(
-  "accountoffsets",
-  "Koha::Schema::Result::Accountoffset",
+  "account_debits",
+  "Koha::Schema::Result::AccountDebit",
   { "foreign.borrowernumber" => "self.borrowernumber" },
   { cascade_copy => 0, cascade_delete => 0 },
 );
@@ -1157,6 +1165,10 @@ __PACKAGE__->many_to_many("ordernumbers", "aqorder_users", "ordernumber");
 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-04-27 16:08:40
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Z50zYBD3Hqlv5/EnoLnyZw
 
+__PACKAGE__->belongs_to(
+    "branch",
+    "Koha::Schema::Result::Branch",
+    { branchcode => "branchcode" },
+);
 
-# You can replace this text with custom content, and it will be preserved on regeneration
 1;
diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm
index 106123a..608bbcf 100644
--- a/Koha/Schema/Result/Branch.pm
+++ b/Koha/Schema/Result/Branch.pm
@@ -187,6 +187,36 @@ __PACKAGE__->set_primary_key("branchcode");
 
 =head1 RELATIONS
 
+=head2 account_credits
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AccountCredit>
+
+=cut
+
+__PACKAGE__->has_many(
+  "account_credits",
+  "Koha::Schema::Result::AccountCredit",
+  { "foreign.branchcode" => "self.branchcode" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
+=head2 account_debits
+
+Type: has_many
+
+Related object: L<Koha::Schema::Result::AccountDebit>
+
+=cut
+
+__PACKAGE__->has_many(
+  "account_debits",
+  "Koha::Schema::Result::AccountDebit",
+  { "foreign.branchcode" => "self.branchcode" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 aqbaskets
 
 Type: has_many
@@ -517,5 +547,5 @@ __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode");
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CGNPB/MkGLOihDThj43/4A
 
 
-# You can replace this text with custom content, and it will be preserved on regeneration
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
 1;
diff --git a/Koha/Schema/Result/Deleteditem.pm b/Koha/Schema/Result/Deleteditem.pm
index 63ca492..c2e7a65 100644
--- a/Koha/Schema/Result/Deleteditem.pm
+++ b/Koha/Schema/Result/Deleteditem.pm
@@ -390,6 +390,17 @@ __PACKAGE__->set_primary_key("itemnumber");
 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-04-23 12:42:12
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+aDMnEj1EvLQTQPAEl1ocg
 
+__PACKAGE__->belongs_to(
+  "biblio",
+  "Koha::Schema::Result::Biblio",
+  { biblionumber => "biblionumber" }
+);
+
+__PACKAGE__->belongs_to(
+  "deleted_biblio",
+  "Koha::Schema::Result::Deletedbiblio",
+  { biblionumber => "biblionumber" }
+);
 
 # You can replace this text with custom content, and it will be preserved on regeneration
 1;
diff --git a/Koha/Schema/Result/Issue.pm b/Koha/Schema/Result/Issue.pm
index 0a0eb17..dfc48c5 100644
--- a/Koha/Schema/Result/Issue.pm
+++ b/Koha/Schema/Result/Issue.pm
@@ -212,10 +212,15 @@ __PACKAGE__->belongs_to(
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3JH0+3CuwwhPyebyt/z+uw
 
 __PACKAGE__->belongs_to(
-    "borrower",
-    "Koha::Schema::Result::Borrower",
-    { borrowernumber => "borrowernumber" },
-    { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
+  "borrower",
+  "Koha::Schema::Result::Borrower",
+  { borrowernumber => "borrowernumber" },
+  {
+    is_deferrable => 1,
+    join_type     => "LEFT",
+    on_delete     => "RESTRICT",
+    on_update     => "CASCADE",
+  },
 );
 
 __PACKAGE__->belongs_to(
diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm
index 0650c4f..7f0f1df 100644
--- a/Koha/Schema/Result/Item.pm
+++ b/Koha/Schema/Result/Item.pm
@@ -410,21 +410,6 @@ __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
 
 =head1 RELATIONS
 
-=head2 accountlines
-
-Type: has_many
-
-Related object: L<Koha::Schema::Result::Accountline>
-
-=cut
-
-__PACKAGE__->has_many(
-  "accountlines",
-  "Koha::Schema::Result::Accountline",
-  { "foreign.itemnumber" => "self.itemnumber" },
-  { cascade_copy => 0, cascade_delete => 0 },
-);
-
 =head2 biblioitemnumber
 
 Type: belongs_to
diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm
index 6daaa40..9edacf5 100644
--- a/Koha/Schema/Result/OldIssue.pm
+++ b/Koha/Schema/Result/OldIssue.pm
@@ -210,6 +210,32 @@ __PACKAGE__->belongs_to(
 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2015-04-23 13:04:51
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9GdzytyInRcFZns/q0qb3Q
 
+__PACKAGE__->belongs_to(
+  "borrower",
+  "Koha::Schema::Result::Borrower",
+  { borrowernumber => "borrowernumber" },
+  { join_type => "LEFT" },
+);
+
+__PACKAGE__->belongs_to(
+  "item",
+  "Koha::Schema::Result::Item",
+  { itemnumber => "itemnumber" },
+  { join_type => "LEFT" },
+);
+
+__PACKAGE__->belongs_to(
+  "deletedborrower",
+  "Koha::Schema::Result::Deletedborrower",
+  { borrowernumber => "borrowernumber" },
+  { join_type => "LEFT" },
+);
+
+__PACKAGE__->belongs_to(
+  "deleteditem",
+  "Koha::Schema::Result::Deleteditem",
+  { itemnumber => "itemnumber" },
+  { join_type => "LEFT" },
+);
 
-# You can replace this text with custom content, and it will be preserved on regeneration
 1;
-- 
1.7.2.5