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

(-)a/Koha/Account.pm (+39 lines)
Lines 30-35 use C4::Stats qw( UpdateStats ); Link Here
30
use C4::Overdues qw(GetFine);
30
use C4::Overdues qw(GetFine);
31
31
32
use Koha::Patrons;
32
use Koha::Patrons;
33
use Koha::Account::Credits;
34
use Koha::Account::Debits;
33
use Koha::Account::Lines;
35
use Koha::Account::Lines;
34
use Koha::Account::Offsets;
36
use Koha::Account::Offsets;
35
use Koha::Account::DebitTypes;
37
use Koha::Account::DebitTypes;
Lines 749-754 sub lines { Link Here
749
    );
751
    );
750
}
752
}
751
753
754
755
=head3 credits
756
757
  my $credits = $self->credits;
758
759
Return all credits for the user
760
761
=cut
762
763
sub credits {
764
    my ($self) = @_;
765
766
    return Koha::Account::Credits->search(
767
        {
768
            borrowernumber => $self->{patron_id}
769
        }
770
    );
771
}
772
773
=head3 debits
774
775
  my $debits = $self->debits;
776
777
Return all debits for the user
778
779
=cut
780
781
sub debits {
782
    my ($self) = @_;
783
784
    return Koha::Account::Debits->search(
785
        {
786
            borrowernumber   => $self->{patron_id},
787
        }
788
    );
789
}
790
752
=head3 reconcile_balance
791
=head3 reconcile_balance
753
792
754
$account->reconcile_balance();
793
$account->reconcile_balance();
(-)a/Koha/Account/Credit.pm (+64 lines)
Line 0 Link Here
1
package Koha::Account::Credit;
2
3
# Copyright PTFS Europe 2021
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Account::Line);
23
24
=head1 NAME
25
26
Koha::Credit - Koha Credit object class
27
28
This object represents a credit account line
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=head3 to_api_mapping
35
36
This method returns the mapping for representing a Koha::Account::Credit object
37
on the API.
38
39
=cut
40
41
sub to_api_mapping {
42
    return {
43
        accountlines_id   => 'account_line_id',
44
        credit_number     => undef,
45
        credit_type_code  => 'credit_type',
46
        debit_type_code   => undef,
47
        amountoutstanding => 'amount_outstanding',
48
        borrowernumber    => 'patron_id',
49
        branchcode        => 'library_id',
50
        issue_id          => 'checkout_id',
51
        itemnumber        => 'item_id',
52
        manager_id        => 'user_id',
53
        note              => 'internal_note',
54
        register_id       => 'cash_register_id',
55
    };
56
}
57
58
=head1 AUTHOR
59
60
Martin Renvoize <martin.renvoize@ptfs-europe.com>
61
62
=cut
63
64
1;
(-)a/Koha/Account/Credits.pm (+56 lines)
Line 0 Link Here
1
package Koha::Account::Credits;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::Account::Credit;
22
23
use base qw(Koha::Account::Lines);
24
25
=head1 NAME
26
27
Koha::Account::Credits - Koha Cash Register Action Object set class
28
29
=head1 API
30
31
=head2 Class methods
32
33
=head3 search
34
35
  my $credits = Koha::Account::Credits->search( $where, $attr );
36
37
Returns a list of credit lines.
38
39
=cut
40
41
sub search {
42
    my ( $self, $where, $attr ) = @_;
43
44
    my $rs = $self->SUPER::search({ debit_type_code => undef });
45
    return $rs->SUPER::search( $where, $attr );
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Account::Credit';
54
}
55
56
1;
(-)a/Koha/Account/Debit.pm (+65 lines)
Line 0 Link Here
1
package Koha::Account::Debit;
2
3
# Copyright PTFS Europe 2021
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Account::Line);
23
24
=head1 NAME
25
26
Koha::Debit - Koha Debit object class
27
28
This object represents a debit account line
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=head3 to_api_mapping
35
36
This method returns the mapping for representing a Koha::Account::Debit object
37
on the API.
38
39
=cut
40
41
sub to_api_mapping {
42
    return {
43
        accountlines_id   => 'account_line_id',
44
        credit_number     => undef,
45
        credit_type_code  => undef,
46
        debit_type_code   => 'debit_type',
47
        amountoutstanding => 'amount_outstanding',
48
        borrowernumber    => 'patron_id',
49
        branchcode        => 'library_id',
50
        issue_id          => 'checkout_id',
51
        itemnumber        => 'item_id',
52
        manager_id        => 'user_id',
53
        note              => 'internal_note',
54
        register_id       => 'cash_register_id',
55
        payment_type      => undef
56
    };
57
}
58
59
=head1 AUTHOR
60
61
Martin Renvoize <martin.renvoize@ptfs-europe.com>
62
63
=cut
64
65
1;
(-)a/Koha/Account/Debits.pm (+56 lines)
Line 0 Link Here
1
package Koha::Account::Debits;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
use Koha::Account::Debit;
22
23
use base qw(Koha::Account::Lines);
24
25
=head1 NAME
26
27
Koha::Account::Debits - Koha Cash Register Action Object set class
28
29
=head1 API
30
31
=head2 Class methods
32
33
=head3 search
34
35
  my $debits = Koha::Account::Debits->search( $where, $attr );
36
37
Returns a list of debit lines.
38
39
=cut
40
41
sub search {
42
    my ( $self, $where, $attr ) = @_;
43
44
    my $rs = $self->SUPER::search({ credit_type_code => undef });
45
    return $rs->SUPER::search( $where, $attr );
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Account::Debit';
54
}
55
56
1;
(-)a/Koha/REST/V1/Patrons/Account.pm (+52 lines)
Lines 74-79 sub get { Link Here
74
    };
74
    };
75
}
75
}
76
76
77
=head3 list_credits
78
79
=cut
80
81
sub list_credits {
82
    my $c = shift->openapi->valid_input or return;
83
84
    my $patron_id = $c->validation->param('patron_id');
85
    my $patron    = Koha::Patrons->find($patron_id);
86
87
    unless ($patron) {
88
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
89
    }
90
91
    return try {
92
        my $account = $patron->account;
93
94
        my $credits_set = $account->credits;
95
        my $credits = $c->objects->search( $credits_set );
96
        return $c->render( status => 200, openapi => $credits );
97
    }
98
    catch {
99
        $c->unhandled_exception($_);
100
    };
101
}
102
77
=head3 add_credit
103
=head3 add_credit
78
104
79
Controller function that handles adding a credit to a patron's account
105
Controller function that handles adding a credit to a patron's account
Lines 153-156 sub add_credit { Link Here
153
    };
179
    };
154
}
180
}
155
181
182
=head3 list_debits
183
184
=cut
185
186
sub list_debits {
187
    my $c = shift->openapi->valid_input or return;
188
189
    my $patron_id = $c->validation->param('patron_id');
190
    my $patron    = Koha::Patrons->find($patron_id);
191
192
    unless ($patron) {
193
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
194
    }
195
196
    return try {
197
        my $account = $patron->account;
198
199
        my $debits_set = $account->debits;
200
        my $debits = $c->objects->search( $debits_set );
201
        return $c->render( status => 200, openapi => $debits );
202
    }
203
    catch {
204
        $c->unhandled_exception($_);
205
    };
206
}
207
156
1;
208
1;
(-)a/api/v1/swagger/definitions/credit.yaml (+91 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  account_line_id:
5
    type:
6
      - integer
7
      - "null"
8
    readOnly: true
9
    description: Internal account line identifier
10
  amount:
11
    type: number
12
    minimum: 0
13
    description: Credit amount
14
  amount_outstanding:
15
    type: number
16
    readOnly: true
17
    description: Outstanding amount
18
  cash_register_id:
19
    type:
20
      - integer
21
      - "null"
22
    description: Internal identifier for the cash register used for the payment (if any)
23
  checkout_id:
24
    type:
25
      - integer
26
      - "null"
27
    description: Internal identifier for the checkout the account line is related to
28
  credit_type:
29
    type:
30
      - string
31
      - "null"
32
    description: Account line credit type
33
  date:
34
    type: string
35
    format: date-time
36
    readOnly: true
37
    description: Date the account line was created
38
  description:
39
    type:
40
      - string
41
      - "null"
42
    readOnly: true
43
    description: Account line description
44
  interface:
45
    type:
46
      - string
47
      - "null"
48
    description: 'Interface in which the account line was generated (values can be: api, cron, commandline, intranet, opac and sip)'
49
  internal_note:
50
    type:
51
      - string
52
      - "null"
53
    description: Internal note
54
  item_id:
55
    type:
56
      - integer
57
      - "null"
58
    description: Internal identifier for the item the account line is related to
59
  library_id:
60
    type:
61
      - string
62
      - "null"
63
    description: Internal identifier for the library in which the transaction took place
64
  patron_id:
65
    type: integer
66
    readOnly: true
67
    description: Internal identifier for the patron the account line belongs to
68
  payment_type:
69
    type:
70
      - string
71
      - "null"
72
    description: Payment type
73
  status:
74
    type:
75
      - string
76
      - "null"
77
    readOnly: true
78
    description: The credit/debit status
79
  timestamp:
80
    type: string
81
    format: date-time
82
    readOnly: true
83
    description: Timestamp for the latest line update
84
  user_id:
85
    type:
86
      - integer
87
      - "null"
88
    description: Internal patron identifier for the staff member that introduced the account line
89
required:
90
  - amount
91
additionalProperties: false
(-)a/api/v1/swagger/definitions/debit.yaml (+94 lines)
Line 0 Link Here
1
type: object
2
properties:
3
  account_line_id:
4
    type:
5
      - integer
6
      - "null"
7
    readOnly: true
8
    description: Internal account line identifier
9
  checkout_id:
10
    type:
11
      - integer
12
      - "null"
13
    description: Internal identifier for the checkout the account line is related to
14
  patron_id:
15
    type: integer
16
    readOnly: true
17
    description: Internal identifier for the patron the account line belongs to
18
  item_id:
19
    type:
20
      - integer
21
      - "null"
22
    description: Internal identifier for the item the account line is related to
23
  date:
24
    type: string
25
    format: date-time
26
    readOnly: true
27
    description: Date the account line was created
28
  amount:
29
    type: number
30
    description: Account line amount
31
  description:
32
    type:
33
      - string
34
      - "null"
35
    readOnly: true
36
    description: Account line description
37
  account_type:
38
    type:
39
      - string
40
      - "null"
41
    description: Account line type
42
  debit_type:
43
    type:
44
      - string
45
      - "null"
46
    description: Account line debit type
47
  payout_type:
48
    type:
49
      - string
50
      - "null"
51
    description: Payout type
52
  amount_outstanding:
53
    type: number
54
    readOnly: true
55
    description: Outstanding amount
56
  timestamp:
57
    type: string
58
    format: date-time
59
    readOnly: true
60
    description: Timestamp for the latest line update
61
  internal_note:
62
    type:
63
      - string
64
      - "null"
65
    description: Internal note
66
  user_id:
67
    type:
68
      - integer
69
      - "null"
70
    description: Internal patron identifier for the staff member that introduced the account line
71
  library_id:
72
    type:
73
      - string
74
      - "null"
75
    description: Internal identifier for the library in which the transaction took place
76
  interface:
77
    type:
78
      - string
79
      - "null"
80
    description: 'Interface in which the account line was generated (values can be: api, cron, commandline, intranet, opac and sip)'
81
  status:
82
    type:
83
      - string
84
      - "null"
85
    readOnly: true
86
    description: The credit/debit status
87
  cash_register_id:
88
    type:
89
      - integer
90
      - "null"
91
    description: Internal identifier for the cash register used for the payment (if any)
92
required:
93
  - amount
94
additionalProperties: false
(-)a/api/v1/swagger/paths/patrons_account.yaml (+87 lines)
Lines 43-48 Link Here
43
        borrowers: edit_borrowers
43
        borrowers: edit_borrowers
44
        updatecharges: remaining_permissions
44
        updatecharges: remaining_permissions
45
"/patrons/{patron_id}/account/credits":
45
"/patrons/{patron_id}/account/credits":
46
  get:
47
    x-mojo-to: Patrons::Account#list_credits
48
    operationId: listPatronCredits
49
    tags:
50
      - patrons
51
      - credits
52
    summary: List patron credits
53
    produces:
54
      - application/json
55
    parameters:
56
      - $ref: ../parameters.yaml#/patron_id_pp
57
      - $ref: ../parameters.yaml#/match
58
      - $ref: ../parameters.yaml#/order_by
59
      - $ref: ../parameters.yaml#/page
60
      - $ref: ../parameters.yaml#/per_page
61
      - $ref: ../parameters.yaml#/q_param
62
      - $ref: ../parameters.yaml#/q_body
63
      - $ref: ../parameters.yaml#/q_header
64
    responses:
65
      "200":
66
        description: A list of credits
67
        schema:
68
          type: array
69
          items:
70
            $ref: ../definitions.yaml#/credit
71
      "403":
72
        description: Access forbidden
73
        schema:
74
          $ref: ../definitions.yaml#/error
75
      "500":
76
        description: Internal error
77
        schema:
78
          $ref: ../definitions.yaml#/error
79
      "503":
80
        description: Under maintenance
81
        schema:
82
          $ref: ../definitions.yaml#/error
83
    x-koha-authorization:
84
      permissions:
85
        borrowers: edit_borrowers
86
        updatecharges: remaining_permissions
46
  post:
87
  post:
47
    x-mojo-to: Patrons::Account#add_credit
88
    x-mojo-to: Patrons::Account#add_credit
48
    operationId: addPatronCredit
89
    operationId: addPatronCredit
Lines 90-92 Link Here
90
    x-koha-authorization:
131
    x-koha-authorization:
91
      permissions:
132
      permissions:
92
        updatecharges: remaining_permissions
133
        updatecharges: remaining_permissions
134
"/patrons/{patron_id}/account/debits":
135
  get:
136
    x-mojo-to: Patrons::Account#list_debits
137
    operationId: listPatronDebits
138
    tags:
139
      - patrons
140
      - debits
141
    summary: List patron debits
142
    produces:
143
      - application/json
144
    parameters:
145
      - $ref: ../parameters.yaml#/patron_id_pp
146
      - $ref: ../parameters.yaml#/match
147
      - $ref: ../parameters.yaml#/order_by
148
      - $ref: ../parameters.yaml#/page
149
      - $ref: ../parameters.yaml#/per_page
150
      - $ref: ../parameters.yaml#/q_param
151
      - $ref: ../parameters.yaml#/q_body
152
      - $ref: ../parameters.yaml#/q_header
153
    responses:
154
      "200":
155
        description: A list of debits
156
        schema:
157
          type: array
158
          items:
159
            $ref: ../definitions.yaml#/debit
160
      "403":
161
        description: Access forbidden
162
        schema:
163
          $ref: ../definitions.yaml#/error
164
      "404":
165
        description: Patron not found
166
        schema:
167
          $ref: ../definitions.yaml#/error
168
      "500":
169
        description: Internal error
170
        schema:
171
          $ref: ../definitions.yaml#/error
172
      "503":
173
        description: Under maintenance
174
        schema:
175
          $ref: ../definitions.yaml#/error
176
    x-koha-authorization:
177
      permissions:
178
        borrowers: edit_borrowers
179
        updatecharges: remaining_permissions
(-)a/api/v1/swagger/swagger.yaml (-1 / +6 lines)
Lines 26-31 definitions: Link Here
26
    $ref: ./definitions/circ-rule-kind.yaml
26
    $ref: ./definitions/circ-rule-kind.yaml
27
  city:
27
  city:
28
    $ref: ./definitions/city.yaml
28
    $ref: ./definitions/city.yaml
29
  credit:
30
    $ref: ./definitions/credit.yaml
31
  debit:
32
    $ref: ./definitions/debit.yaml
29
  erm_agreement:
33
  erm_agreement:
30
    $ref: ./definitions/erm_agreement.yaml
34
    $ref: ./definitions/erm_agreement.yaml
31
  erm_eholdings_title:
35
  erm_eholdings_title:
Lines 261-266 paths: Link Here
261
    $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account"
265
    $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account"
262
  "/patrons/{patron_id}/account/credits":
266
  "/patrons/{patron_id}/account/credits":
263
    $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1credits"
267
    $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1credits"
268
  "/patrons/{patron_id}/account/debits":
269
    $ref: "./paths/patrons_account.yaml#/~1patrons~1{patron_id}~1account~1debits"
264
  "/patrons/{patron_id}/extended_attributes":
270
  "/patrons/{patron_id}/extended_attributes":
265
    $ref: "./paths/patrons_extended_attributes.yaml#/~1patrons~1{patron_id}~1extended_attributes"
271
    $ref: "./paths/patrons_extended_attributes.yaml#/~1patrons~1{patron_id}~1extended_attributes"
266
  "/patrons/{patron_id}/extended_attributes/{extended_attribute_id}":
272
  "/patrons/{patron_id}/extended_attributes/{extended_attribute_id}":
267
- 

Return to bug 29453