View | Details | Raw Unified | Return to bug 6427
Collapse All | Expand All

(-)a/C4/Context.pm (-1 / +1 lines)
Lines 1037-1043 sub schema { Link Here
1037
    my $self = shift;
1037
    my $self = shift;
1038
    my $sth;
1038
    my $sth;
1039
1039
1040
    if ( defined( $context->{"schema"} ) && $context->{"schema"}->ping() ) {
1040
    if ( defined( $context->{"schema"} ) ) {
1041
        return $context->{"schema"};
1041
        return $context->{"schema"};
1042
    }
1042
    }
1043
1043
(-)a/Koha/Accounts/CreditTypes.pm (+98 lines)
Line 0 Link Here
1
package Koha::Accounts::CreditTypes;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::AccountsCreditTypes - Module representing the enumerated data types for account fees
25
26
=head1 SYNOPSIS
27
28
use Koha::Accounts::CreditTypes;
29
30
my $type = Koha::Accounts::CreditTypes::Payment;
31
32
=head1 DESCRIPTION
33
34
The subroutines in this modules act as enumerated data types for the 
35
different credit types in Koha ( i.e. payments, writeoffs, etc. )
36
37
=head1 FUNCTIONS
38
39
=head2 IsValid
40
41
This subroutine takes a given string and returns 1 if
42
the string matches one of the data types, and 0 if not.
43
44
FIXME: Perhaps we should use Class::Inspector instead of hard
45
coding the subs? It seems like it would be a major trade off
46
of speed just so we don't update something in two separate places
47
in the same file.
48
49
=cut
50
51
sub IsValid {
52
    my ($string) = @_;
53
54
    return ( $string eq Koha::Accounts::CreditTypes::Payment()
55
          || $string eq Koha::Accounts::CreditTypes::WriteOff()
56
          || $string eq Koha::Accounts::CreditTypes::Found()
57
          || $string eq Koha::Accounts::CreditTypes::Forgiven() );
58
}
59
60
=head2 Payment
61
62
=cut
63
64
sub Payment {
65
    return 'PAYMENT';
66
}
67
68
=head2 Writeoff
69
70
=cut
71
72
sub WriteOff {
73
    return 'WRITEOFF';
74
}
75
76
=head2 Writeoff
77
78
=cut
79
80
sub Found {
81
    return 'FOUND';
82
}
83
84
=head2 Forgiven
85
86
=cut
87
88
sub Forgiven {
89
    return 'FORGIVEN';
90
}
91
92
1;
93
94
=head1 AUTHOR
95
96
Kyle M Hall <kyle@bywatersolutions.com>
97
98
=cut
(-)a/Koha/Accounts/DebitTypes.pm (+138 lines)
Line 0 Link Here
1
package Koha::Accounts::DebitTypes;
2
3
# Copyright 2013 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
=head1 NAME
23
24
Koha::Accounts::DebitTypes - Module representing an enumerated data type for account fees
25
26
=head1 SYNOPSIS
27
28
use Koha::Accounts::DebitTypes;
29
30
my $type = Koha::Accounts::DebitTypes::Fine;
31
32
=head1 DESCRIPTION
33
34
The subroutines in this modules act as an enumerated data type
35
for debit types ( stored in account_debits.type ) in Koha.
36
37
=head1 FUNCTIONS
38
39
=head2 IsValid
40
41
This subroutine takes a given string and returns 1 if
42
the string matches one of the data types, and 0 if not.
43
44
=cut
45
46
sub IsValid {
47
    my ($string) = @_;
48
49
    my $is_valid =
50
      (      $string eq Koha::Accounts::DebitTypes::Fine()
51
          || $string eq Koha::Accounts::DebitTypes::AccountManagementFee()
52
          || $string eq Koha::Accounts::DebitTypes::Sundry()
53
          || $string eq Koha::Accounts::DebitTypes::Lost()
54
          || $string eq Koha::Accounts::DebitTypes::NewCard() );
55
56
    unless ($is_valid) {
57
        $is_valid =
58
          C4::Context->schema->resultset('AuthorisedValue')
59
          ->count( { category => 'MANUAL_INV', authorised_value => $string } );
60
    }
61
62
    return $is_valid;
63
}
64
65
=head2 Fine
66
67
This data type represents a standard fine within Koha.
68
69
A fine still accruing no longer needs to be differiated by type
70
from a fine done accuring. Instead, that differentication is made
71
by which table the fine exists in, account_fees_accruing vs account_fees_accrued.
72
73
In addition, fines can be checked for correctness based on the issue_id
74
they have. A fine in account_fees_accruing should always have a matching
75
issue_id in the issues table. A fine done accruing will almost always have
76
a matching issue_id in the old_issues table. However, in the case of an overdue
77
item with fines that has been renewed, and becomes overdue again, you may have
78
a case where a given issue may have a matching fine in account_fees_accruing and
79
one or more matching fines in account_fees_accrued ( one for each for the first
80
checkout and one each for any subsequent renewals )
81
82
=cut
83
84
sub Fine {
85
    return 'FINE';
86
}
87
88
=head2 AccountManagementFee
89
90
This fee type is usually reserved for payments for library cards,
91
in cases where a library must charge a patron for the ability to
92
check out items.
93
94
=cut
95
96
sub AccountManagementFee {
97
    return 'ACCOUNT_MANAGEMENT_FEE';
98
}
99
100
=head2 Sundry
101
102
This fee type is basically a 'misc' type, and should be used
103
when no other fee type is more appropriate.
104
105
=cut
106
107
sub Sundry {
108
    return 'SUNDRY';
109
}
110
111
=head2 Lost
112
113
This fee type is used when a library charges for lost items.
114
115
=cut
116
117
sub Lost {
118
    return 'LOST';
119
}
120
121
=head2 NewCard 
122
123
This fee type is used when a library charges for replacement
124
library cards.
125
126
=cut
127
128
sub NewCard {
129
    return 'NEW_CARD';
130
}
131
132
1;
133
134
=head1 AUTHOR
135
136
Kyle M Hall <kyle@bywatersolutions.com>
137
138
=cut
(-)a/Koha/DateUtils.pm (-1 / +6 lines)
Lines 21-33 use warnings; Link Here
21
use 5.010;
21
use 5.010;
22
use DateTime;
22
use DateTime;
23
use DateTime::Format::DateParse;
23
use DateTime::Format::DateParse;
24
use DateTime::Format::MySQL;
24
use C4::Context;
25
use C4::Context;
25
26
26
use base 'Exporter';
27
use base 'Exporter';
27
use version; our $VERSION = qv('1.0.0');
28
use version; our $VERSION = qv('1.0.0');
28
29
29
our @EXPORT = (
30
our @EXPORT = (
30
    qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime)
31
    qw( dt_from_string output_pref format_sqldatetime output_pref_due format_sqlduedatetime get_timestamp )
31
);
32
);
32
33
33
=head1 DateUtils
34
=head1 DateUtils
Lines 218-221 sub format_sqlduedatetime { Link Here
218
    return q{};
219
    return q{};
219
}
220
}
220
221
222
sub get_timestamp {
223
    return DateTime::Format::MySQL->format_datetime( dt_from_string() );
224
}
225
221
1;
226
1;
(-)a/Koha/Schema/Result/AccountCredit.pm (+134 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountCredit;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountCredit
15
16
=cut
17
18
__PACKAGE__->table("account_credits");
19
20
=head1 ACCESSORS
21
22
=head2 credit_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 borrowernumber
29
30
  data_type: 'integer'
31
  is_foreign_key: 1
32
  is_nullable: 0
33
34
=head2 type
35
36
  data_type: 'varchar'
37
  is_nullable: 0
38
  size: 255
39
40
=head2 amount_paid
41
42
  data_type: 'decimal'
43
  is_nullable: 0
44
  size: [28,6]
45
46
=head2 amount_remaining
47
48
  data_type: 'decimal'
49
  is_nullable: 0
50
  size: [28,6]
51
52
=head2 notes
53
54
  data_type: 'text'
55
  is_nullable: 1
56
57
=head2 manager_id
58
59
  data_type: 'integer'
60
  is_nullable: 1
61
62
=head2 created_on
63
64
  data_type: 'timestamp'
65
  is_nullable: 1
66
67
=head2 updated_on
68
69
  data_type: 'timestamp'
70
  is_nullable: 1
71
72
=cut
73
74
__PACKAGE__->add_columns(
75
  "credit_id",
76
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
77
  "borrowernumber",
78
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
79
  "type",
80
  { data_type => "varchar", is_nullable => 0, size => 255 },
81
  "amount_paid",
82
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
83
  "amount_remaining",
84
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
85
  "notes",
86
  { data_type => "text", is_nullable => 1 },
87
  "manager_id",
88
  { data_type => "integer", is_nullable => 1 },
89
  "created_on",
90
  { data_type => "timestamp", is_nullable => 1 },
91
  "updated_on",
92
  { data_type => "timestamp", is_nullable => 1 },
93
);
94
__PACKAGE__->set_primary_key("credit_id");
95
96
=head1 RELATIONS
97
98
=head2 borrowernumber
99
100
Type: belongs_to
101
102
Related object: L<Koha::Schema::Result::Borrower>
103
104
=cut
105
106
__PACKAGE__->belongs_to(
107
  "borrowernumber",
108
  "Koha::Schema::Result::Borrower",
109
  { borrowernumber => "borrowernumber" },
110
  { on_delete => "CASCADE", on_update => "CASCADE" },
111
);
112
113
=head2 account_offsets
114
115
Type: has_many
116
117
Related object: L<Koha::Schema::Result::AccountOffset>
118
119
=cut
120
121
__PACKAGE__->has_many(
122
  "account_offsets",
123
  "Koha::Schema::Result::AccountOffset",
124
  { "foreign.credit_id" => "self.credit_id" },
125
  { cascade_copy => 0, cascade_delete => 0 },
126
);
127
128
129
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-10-09 10:37:23
130
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:uvt4OuaJxv4jk08zJsKouw
131
132
133
# You can replace this text with custom content, and it will be preserved on regeneration
134
1;
(-)a/Koha/Schema/Result/AccountDebit.pm (+200 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountDebit;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountDebit
15
16
=cut
17
18
__PACKAGE__->table("account_debits");
19
20
=head1 ACCESSORS
21
22
=head2 debit_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 borrowernumber
29
30
  data_type: 'integer'
31
  default_value: 0
32
  is_foreign_key: 1
33
  is_nullable: 0
34
35
=head2 itemnumber
36
37
  data_type: 'integer'
38
  is_nullable: 1
39
40
=head2 issue_id
41
42
  data_type: 'integer'
43
  is_nullable: 1
44
45
=head2 type
46
47
  data_type: 'varchar'
48
  is_nullable: 0
49
  size: 255
50
51
=head2 accruing
52
53
  data_type: 'tinyint'
54
  default_value: 0
55
  is_nullable: 0
56
57
=head2 amount_original
58
59
  data_type: 'decimal'
60
  is_nullable: 1
61
  size: [28,6]
62
63
=head2 amount_outstanding
64
65
  data_type: 'decimal'
66
  is_nullable: 1
67
  size: [28,6]
68
69
=head2 amount_last_increment
70
71
  data_type: 'decimal'
72
  is_nullable: 1
73
  size: [28,6]
74
75
=head2 description
76
77
  data_type: 'mediumtext'
78
  is_nullable: 1
79
80
=head2 notes
81
82
  data_type: 'text'
83
  is_nullable: 1
84
85
=head2 dispute
86
87
  data_type: 'mediumtext'
88
  is_nullable: 1
89
90
=head2 notify_id
91
92
  data_type: 'integer'
93
  default_value: 0
94
  is_nullable: 0
95
96
=head2 notify_level
97
98
  data_type: 'integer'
99
  default_value: 0
100
  is_nullable: 0
101
102
=head2 manager_id
103
104
  data_type: 'integer'
105
  is_nullable: 1
106
107
=head2 created_on
108
109
  data_type: 'timestamp'
110
  is_nullable: 1
111
112
=head2 updated_on
113
114
  data_type: 'timestamp'
115
  is_nullable: 1
116
117
=cut
118
119
__PACKAGE__->add_columns(
120
  "debit_id",
121
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
122
  "borrowernumber",
123
  {
124
    data_type      => "integer",
125
    default_value  => 0,
126
    is_foreign_key => 1,
127
    is_nullable    => 0,
128
  },
129
  "itemnumber",
130
  { data_type => "integer", is_nullable => 1 },
131
  "issue_id",
132
  { data_type => "integer", is_nullable => 1 },
133
  "type",
134
  { data_type => "varchar", is_nullable => 0, size => 255 },
135
  "accruing",
136
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
137
  "amount_original",
138
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
139
  "amount_outstanding",
140
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
141
  "amount_last_increment",
142
  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
143
  "description",
144
  { data_type => "mediumtext", is_nullable => 1 },
145
  "notes",
146
  { data_type => "text", is_nullable => 1 },
147
  "dispute",
148
  { data_type => "mediumtext", is_nullable => 1 },
149
  "notify_id",
150
  { data_type => "integer", default_value => 0, is_nullable => 0 },
151
  "notify_level",
152
  { data_type => "integer", default_value => 0, is_nullable => 0 },
153
  "manager_id",
154
  { data_type => "integer", is_nullable => 1 },
155
  "created_on",
156
  { data_type => "timestamp", is_nullable => 1 },
157
  "updated_on",
158
  { data_type => "timestamp", is_nullable => 1 },
159
);
160
__PACKAGE__->set_primary_key("debit_id");
161
162
=head1 RELATIONS
163
164
=head2 borrowernumber
165
166
Type: belongs_to
167
168
Related object: L<Koha::Schema::Result::Borrower>
169
170
=cut
171
172
__PACKAGE__->belongs_to(
173
  "borrowernumber",
174
  "Koha::Schema::Result::Borrower",
175
  { borrowernumber => "borrowernumber" },
176
  { on_delete => "CASCADE", on_update => "CASCADE" },
177
);
178
179
=head2 account_offsets
180
181
Type: has_many
182
183
Related object: L<Koha::Schema::Result::AccountOffset>
184
185
=cut
186
187
__PACKAGE__->has_many(
188
  "account_offsets",
189
  "Koha::Schema::Result::AccountOffset",
190
  { "foreign.debit_id" => "self.debit_id" },
191
  { cascade_copy => 0, cascade_delete => 0 },
192
);
193
194
195
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-10-09 10:37:23
196
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LuHGHKmf3tPEWsTqE4VoMQ
197
198
199
# You can replace this text with custom content, and it will be preserved on regeneration
200
1;
(-)a/Koha/Schema/Result/AccountOffset.pm (+110 lines)
Line 0 Link Here
1
package Koha::Schema::Result::AccountOffset;
2
3
# Created by DBIx::Class::Schema::Loader
4
# DO NOT MODIFY THE FIRST PART OF THIS FILE
5
6
use strict;
7
use warnings;
8
9
use base 'DBIx::Class::Core';
10
11
12
=head1 NAME
13
14
Koha::Schema::Result::AccountOffset
15
16
=cut
17
18
__PACKAGE__->table("account_offsets");
19
20
=head1 ACCESSORS
21
22
=head2 offset_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
28
=head2 debit_id
29
30
  data_type: 'integer'
31
  is_foreign_key: 1
32
  is_nullable: 1
33
34
=head2 credit_id
35
36
  data_type: 'integer'
37
  is_foreign_key: 1
38
  is_nullable: 1
39
40
=head2 amount
41
42
  data_type: 'decimal'
43
  is_nullable: 0
44
  size: [28,6]
45
46
=head2 created_on
47
48
  data_type: 'timestamp'
49
  default_value: current_timestamp
50
  is_nullable: 0
51
52
=cut
53
54
__PACKAGE__->add_columns(
55
  "offset_id",
56
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
57
  "debit_id",
58
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
59
  "credit_id",
60
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
61
  "amount",
62
  { data_type => "decimal", is_nullable => 0, size => [28, 6] },
63
  "created_on",
64
  {
65
    data_type     => "timestamp",
66
    default_value => \"current_timestamp",
67
    is_nullable   => 0,
68
  },
69
);
70
__PACKAGE__->set_primary_key("offset_id");
71
72
=head1 RELATIONS
73
74
=head2 credit
75
76
Type: belongs_to
77
78
Related object: L<Koha::Schema::Result::AccountCredit>
79
80
=cut
81
82
__PACKAGE__->belongs_to(
83
  "credit",
84
  "Koha::Schema::Result::AccountCredit",
85
  { credit_id => "credit_id" },
86
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
87
);
88
89
=head2 debit
90
91
Type: belongs_to
92
93
Related object: L<Koha::Schema::Result::AccountDebit>
94
95
=cut
96
97
__PACKAGE__->belongs_to(
98
  "debit",
99
  "Koha::Schema::Result::AccountDebit",
100
  { debit_id => "debit_id" },
101
  { join_type => "LEFT", on_delete => "CASCADE", on_update => "CASCADE" },
102
);
103
104
105
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-09-10 14:57:34
106
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:O3cL8IVdqGD6stE30ohBxA
107
108
109
# You can replace this text with custom content, and it will be preserved on regeneration
110
1;
(-)a/Koha/Schema/Result/Borrower.pm (-2 / +76 lines)
Lines 389-394 __PACKAGE__->table("borrowers"); Link Here
389
  default_value: 1
389
  default_value: 1
390
  is_nullable: 0
390
  is_nullable: 0
391
391
392
=head2 account_balance
393
394
  data_type: 'decimal'
395
  default_value: 0.000000
396
  is_nullable: 0
397
  size: [28,6]
398
392
=cut
399
=cut
393
400
394
__PACKAGE__->add_columns(
401
__PACKAGE__->add_columns(
Lines 538-549 __PACKAGE__->add_columns( Link Here
538
  { data_type => "varchar", is_nullable => 1, size => 50 },
545
  { data_type => "varchar", is_nullable => 1, size => 50 },
539
  "privacy",
546
  "privacy",
540
  { data_type => "integer", default_value => 1, is_nullable => 0 },
547
  { data_type => "integer", default_value => 1, is_nullable => 0 },
548
  "account_balance",
549
  {
550
    data_type => "decimal",
551
    default_value => "0.000000",
552
    is_nullable => 0,
553
    size => [28, 6],
554
  },
541
);
555
);
542
__PACKAGE__->set_primary_key("borrowernumber");
556
__PACKAGE__->set_primary_key("borrowernumber");
543
__PACKAGE__->add_unique_constraint("cardnumber", ["cardnumber"]);
557
__PACKAGE__->add_unique_constraint("cardnumber", ["cardnumber"]);
544
558
545
=head1 RELATIONS
559
=head1 RELATIONS
546
560
561
=head2 account_credits
562
563
Type: has_many
564
565
Related object: L<Koha::Schema::Result::AccountCredit>
566
567
=cut
568
569
__PACKAGE__->has_many(
570
  "account_credits",
571
  "Koha::Schema::Result::AccountCredit",
572
  { "foreign.borrowernumber" => "self.borrowernumber" },
573
  { cascade_copy => 0, cascade_delete => 0 },
574
);
575
576
=head2 account_debits
577
578
Type: has_many
579
580
Related object: L<Koha::Schema::Result::AccountDebit>
581
582
=cut
583
584
__PACKAGE__->has_many(
585
  "account_debits",
586
  "Koha::Schema::Result::AccountDebit",
587
  { "foreign.borrowernumber" => "self.borrowernumber" },
588
  { cascade_copy => 0, cascade_delete => 0 },
589
);
590
547
=head2 accountlines
591
=head2 accountlines
548
592
549
Type: has_many
593
Type: has_many
Lines 604-609 __PACKAGE__->has_many( Link Here
604
  { cascade_copy => 0, cascade_delete => 0 },
648
  { cascade_copy => 0, cascade_delete => 0 },
605
);
649
);
606
650
651
=head2 borrower_files
652
653
Type: has_many
654
655
Related object: L<Koha::Schema::Result::BorrowerFile>
656
657
=cut
658
659
__PACKAGE__->has_many(
660
  "borrower_files",
661
  "Koha::Schema::Result::BorrowerFile",
662
  { "foreign.borrowernumber" => "self.borrowernumber" },
663
  { cascade_copy => 0, cascade_delete => 0 },
664
);
665
607
=head2 borrower_message_preferences
666
=head2 borrower_message_preferences
608
667
609
Type: has_many
668
Type: has_many
Lines 649-654 __PACKAGE__->belongs_to( Link Here
649
  { on_delete => "CASCADE", on_update => "CASCADE" },
708
  { on_delete => "CASCADE", on_update => "CASCADE" },
650
);
709
);
651
710
711
=head2 course_instructors
712
713
Type: has_many
714
715
Related object: L<Koha::Schema::Result::CourseInstructor>
716
717
=cut
718
719
__PACKAGE__->has_many(
720
  "course_instructors",
721
  "Koha::Schema::Result::CourseInstructor",
722
  { "foreign.borrowernumber" => "self.borrowernumber" },
723
  { cascade_copy => 0, cascade_delete => 0 },
724
);
725
652
=head2 creator_batches
726
=head2 creator_batches
653
727
654
Type: has_many
728
Type: has_many
Lines 920-927 __PACKAGE__->has_many( Link Here
920
);
994
);
921
995
922
996
923
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-04-22 08:57:05
997
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-09-10 14:57:34
924
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:x1GvKQJu/IfGrdz4QG1AfQ
998
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:0RVIm6TnhPVC3zIvXAxZKg
925
999
926
1000
927
# You can replace this text with custom content, and it will be preserved on regeneration
1001
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Issue.pm (-2 / +11 lines)
Lines 19-24 __PACKAGE__->table("issues"); Link Here
19
19
20
=head1 ACCESSORS
20
=head1 ACCESSORS
21
21
22
=head2 issue_id
23
24
  data_type: 'integer'
25
  is_auto_increment: 1
26
  is_nullable: 0
27
22
=head2 borrowernumber
28
=head2 borrowernumber
23
29
24
  data_type: 'integer'
30
  data_type: 'integer'
Lines 83-88 __PACKAGE__->table("issues"); Link Here
83
=cut
89
=cut
84
90
85
__PACKAGE__->add_columns(
91
__PACKAGE__->add_columns(
92
  "issue_id",
93
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
86
  "borrowernumber",
94
  "borrowernumber",
87
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
95
  { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
88
  "itemnumber",
96
  "itemnumber",
Lines 110-115 __PACKAGE__->add_columns( Link Here
110
  "issuedate",
118
  "issuedate",
111
  { data_type => "datetime", is_nullable => 1 },
119
  { data_type => "datetime", is_nullable => 1 },
112
);
120
);
121
__PACKAGE__->set_primary_key("issue_id");
113
122
114
=head1 RELATIONS
123
=head1 RELATIONS
115
124
Lines 144-151 __PACKAGE__->belongs_to( Link Here
144
);
153
);
145
154
146
155
147
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-04-22 08:57:05
156
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-09-10 14:57:34
148
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yGeX5Tx60Cj3S9MUj1s++g
157
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qcAHoiJvPlCgR8xNEskeMg
149
158
150
159
151
# You can replace this text with custom content, and it will be preserved on regeneration
160
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/OldIssue.pm (-2 / +2 lines)
Lines 144-151 __PACKAGE__->belongs_to( Link Here
144
);
144
);
145
145
146
146
147
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2012-09-02 08:44:15
147
# Created by DBIx::Class::Schema::Loader v0.07000 @ 2013-09-10 14:57:34
148
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OmCAF2QYzR59eHr1w51seA
148
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4bnXphmCgmRkFQRHxhWNGw
149
149
150
150
151
# You can replace this text with custom content, and it will be preserved on regeneration
151
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 7104-7109 if ( CheckVersion($DBversion) ) { Link Here
7104
    SetVersion($DBversion);
7104
    SetVersion($DBversion);
7105
}
7105
}
7106
7106
7107
$DBversion = "3.11.00.XXX";
7108
if ( CheckVersion($DBversion) ) {
7109
   $dbh->do("ALTER TABLE  `issues` ADD  `issue_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
7110
   print "Upgrade to $DBversion done (WIP: Accounts rewrite)\n";
7111
   SetVersion ($DBversion);
7112
}
7113
7107
=head1 FUNCTIONS
7114
=head1 FUNCTIONS
7108
7115
7109
=head2 TableExists($table)
7116
=head2 TableExists($table)
(-)a/t/db_dependent/Accounts.t (-4 / +185 lines)
Lines 1-16 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
2
#
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
9
use Test::More tests => 1;
9
use Test::More tests => 18;
10
11
use C4::Context;
10
12
11
BEGIN {
13
BEGIN {
12
        use_ok('C4::Accounts');
14
    use_ok('Koha::Accounts');
15
    use_ok('Koha::Accounts::DebitTypes');
16
    use_ok('Koha::Accounts::CreditTypes');
13
}
17
}
14
18
19
## Intial Setup ##
20
my $borrower = C4::Context->schema->resultset('Borrower')->create(
21
    {
22
        surname         => 'Test',
23
        categorycode    => 'S',
24
        branchcode      => 'MPL',
25
        account_balance => 0,
26
    }
27
);
28
29
my $biblio =
30
  C4::Context->schema->resultset('Biblio')
31
  ->create( { title => "Test Record" } );
32
my $biblioitem =
33
  C4::Context->schema->resultset('Biblioitem')
34
  ->create( { biblionumber => $biblio->biblionumber() } );
35
my $item = C4::Context->schema->resultset('Item')->create(
36
    {
37
        biblionumber     => $biblio->biblionumber(),
38
        biblioitemnumber => $biblioitem->biblioitemnumber(),
39
        replacementprice => 25.00,
40
        barcode          => q{TEST_ITEM_BARCODE}
41
    }
42
);
43
44
my $issue = C4::Context->schema->resultset('Issue')->create(
45
    {
46
        borrowernumber => $borrower->borrowernumber(),
47
        itemnumber     => $item->itemnumber(),
48
    }
49
);
50
## END initial setup
51
52
ok( Koha::Accounts::DebitTypes::Fine eq 'FINE', 'Test DebitTypes::Fine' );
53
ok( Koha::Accounts::DebitTypes::Lost eq 'LOST', 'Test DebitTypes::Lost' );
54
ok(
55
    Koha::Accounts::DebitTypes::IsValid('FINE'),
56
    'Test DebitTypes::IsValid with valid debit type'
57
);
58
ok(
59
    !Koha::Accounts::DebitTypes::IsValid('Not A Valid Fee Type'),
60
    'Test DebitTypes::IsValid with an invalid debit type'
61
);
62
my $authorised_value =
63
  C4::Context->schema->resultset('AuthorisedValue')->create(
64
    {
65
        category         => 'MANUAL_INV',
66
        authorised_value => 'TEST',
67
        lib              => 'Test',
68
    }
69
  );
70
ok( Koha::Accounts::DebitTypes::IsValid('TEST'),
71
    'Test DebitTypes::IsValid with valid authorised value debit type' );
72
$authorised_value->delete();
73
74
my $debit = AddDebit(
75
    {
76
        borrower   => $borrower,
77
        amount     => 5.00,
78
        type       => Koha::Accounts::DebitTypes::Fine,
79
        branchcode => 'MPL',
80
    }
81
);
82
ok( $debit, "AddDebit returned a valid debit id " . $debit->id() );
83
84
ok(
85
    $borrower->account_balance() == 5.00,
86
    "Borrower's account balance updated correctly"
87
);
88
89
my $debit2 = AddDebit(
90
    {
91
        borrower   => $borrower,
92
        amount     => 7.00,
93
        type       => Koha::Accounts::DebitTypes::Fine,
94
        branchcode => 'MPL',
95
    }
96
);
97
98
my $credit = AddCredit(
99
    {
100
        borrower   => $borrower,
101
        type       => Koha::Accounts::CreditTypes::Payment,
102
        amount     => 9.00,
103
        branchcode => 'MPL',
104
    }
105
);
106
107
RecalculateAccountBalance( { borrower => $borrower } );
108
ok(
109
    sprintf( "%.2f", $borrower->account_balance() ) eq "3.00",
110
    "RecalculateAccountBalance updated balance correctly."
111
);
112
113
C4::Context->schema->resultset('AccountCredit')->create(
114
    {
115
        borrowernumber   => $borrower->borrowernumber(),
116
        type             => Koha::Accounts::CreditTypes::Payment,
117
        amount_paid      => 3.00,
118
        amount_remaining => 3.00,
119
    }
120
);
121
NormalizeBalances( { borrower => $borrower } );
122
ok(
123
    $borrower->account_balance() == 0.00,
124
    "NormalizeBalances updated balance correctly."
125
);
126
127
# Adding advance credit with no balance due
128
$credit = AddCredit(
129
    {
130
        borrower   => $borrower,
131
        type       => Koha::Accounts::CreditTypes::Payment,
132
        amount     => 9.00,
133
        branchcode => 'MPL',
134
    }
135
);
136
ok(
137
    $borrower->account_balance() == -9,
138
'Adding a $9 credit for borrower with 0 balance results in a -9 dollar account balance'
139
);
140
141
my $debit3 = AddDebit(
142
    {
143
        borrower   => $borrower,
144
        amount     => 5.00,
145
        type       => Koha::Accounts::DebitTypes::Fine,
146
        branchcode => 'MPL',
147
    }
148
);
149
ok(
150
    $borrower->account_balance() == -4,
151
'Adding a $5 debit when the balance is negative results in the debit being automatically paid, resulting in a balance of -4'
152
);
153
154
my $debit4 = AddDebit(
155
    {
156
        borrower   => $borrower,
157
        amount     => 6.00,
158
        type       => Koha::Accounts::DebitTypes::Fine,
159
        branchcode => 'MPL',
160
    }
161
);
162
ok(
163
    $borrower->account_balance() == 2,
164
'Adding another debit ( 6.00 ) more than the negative account balance results in a partial credit and a balance due of 2.00'
165
);
166
$credit = AddCredit(
167
    {
168
        borrower   => $borrower,
169
        type       => Koha::Accounts::CreditTypes::WriteOff,
170
        amount     => 2.00,
171
        branchcode => 'MPL',
172
        debit_id   => $debit4->debit_id(),
173
    }
174
);
175
ok( $borrower->account_balance() == 0,
176
    'WriteOff of remaining 2.00 balance succeeds' );
177
178
my $debit5 = DebitLostItem(
179
    {
180
        borrower => $borrower,
181
        issue    => $issue,
182
    }
183
);
184
ok( $borrower->account_balance() == 25,
185
    'DebitLostItem adds debit for replacement price of item' );
15
186
187
my $lost_credit =
188
  CreditLostItem( { borrower => $borrower, account_debit => $debit5 } );
189
ok(
190
    $borrower->account_balance() == 0,
191
    'CreditLostItem adds credit for same about as the debit for the lost tiem'
192
);
16
193
17
- 
194
## Post test cleanup ##
195
$issue->delete();
196
$item->delete();
197
$biblio->delete();
198
$borrower->delete();

Return to bug 6427