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

(-)a/Koha/Accountline.pm (+30 lines)
Line 0 Link Here
1
package Koha::Accountline;
2
3
# Copyright 2015 BibLibre
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 3 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
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
sub type {
27
    return 'Accountline';
28
}
29
30
1;
(-)a/Koha/Accountlines.pm (+35 lines)
Line 0 Link Here
1
package Koha::Accountlines;
2
3
# Copyright 2015 BibLibre
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 3 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
use Koha::Database;
23
use Koha::Accountline;
24
25
use base qw(Koha::Objects);
26
27
sub type {
28
    return 'Accountline';
29
}
30
31
sub object_class {
32
    return 'Koha::Accountline';
33
}
34
35
1;
(-)a/Koha/REST/V1/Borrowers/Accountlines.pm (+30 lines)
Line 0 Link Here
1
package Koha::REST::V1::Borrowers::Accountlines;
2
3
use Modern::Perl;
4
5
use Mojo::Base 'Mojolicious::Controller';
6
7
use Koha::Borrowers;
8
use Koha::Accountlines;
9
10
use C4::Accounts;
11
12
sub get_borrower_accountlines {
13
    my ($c, $args, $cb) = @_;
14
15
    my $borrower = Koha::Borrowers->find($args->{borrowernumber});
16
17
    unless ($borrower) {
18
        return $c->$cb({error => "Borrower not found"}, 404);
19
    }
20
21
    my $search_params = { borrowernumber => $borrower->borrowernumber };
22
    if (defined $args->{accounttype}) {
23
        $search_params->{accounttype} = $args->{accounttype};
24
    }
25
    my $accountlines = Koha::Accountlines->search($search_params);
26
27
    return $c->$cb($accountlines->unblessed, 200);
28
}
29
30
1;
(-)a/api/v1/swagger.json (+93 lines)
Lines 63-68 Link Here
63
          }
63
          }
64
        }
64
        }
65
      }
65
      }
66
    },
67
    "/borrowers/{borrowernumber}/accountlines": {
68
      "get": {
69
        "x-mojo-controller": "Koha::REST::V1::Borrowers::Accountlines",
70
        "operationId": "getBorrowerAccountlines",
71
        "tags": ["borrowers", "accountlines"],
72
        "parameters": [
73
          { "$ref": "#/parameters/borrowernumberPathParam" },
74
          {
75
            "name": "accounttype",
76
            "in": "query",
77
            "description": "Filter by accountline type",
78
            "type": "string"
79
          }
80
        ],
81
        "produces": [
82
          "application/json"
83
        ],
84
        "responses": {
85
          "200": {
86
            "description": "A list of borrower accountlines",
87
            "schema": {
88
              "$ref": "#/definitions/accountlines"
89
            }
90
          },
91
          "404": {
92
            "description": "Borrower not found",
93
            "schema": {
94
              "$ref": "#/definitions/error"
95
            }
96
          }
97
        }
98
      }
66
    }
99
    }
67
  },
100
  },
68
  "definitions": {
101
  "definitions": {
Lines 86-91 Link Here
86
    "borrowernumber": {
119
    "borrowernumber": {
87
      "description": "Borrower internal identifier"
120
      "description": "Borrower internal identifier"
88
    },
121
    },
122
    "accountlines": {
123
      "type": "array",
124
      "items": { "$ref": "#/definitions/accountline" }
125
    },
126
    "accountline": {
127
      "type": "object",
128
      "properties": {
129
        "accountlines_id": {
130
          "description": "Internal account line identifier"
131
        },
132
        "borrowernumber": {
133
          "description": "Internal borrower identifier"
134
        },
135
        "accountno": {
136
          "description": "?"
137
        },
138
        "itemnumber": {
139
          "description": "Internal item identifier"
140
        },
141
        "date": {
142
          "description": "Date when the account line was created"
143
        },
144
        "time": {
145
          "description": "Time when the account line was created"
146
        },
147
        "amount": {
148
          "description": "Amount"
149
        },
150
        "description": {
151
          "description": "Description of account line"
152
        },
153
        "accounttype": {
154
          "description": "Type of accountline"
155
        },
156
        "amountoutstanding": {
157
          "description": "Amount outstanding"
158
        },
159
        "lastincrement": {
160
          "description": "?"
161
        },
162
        "timestamp": {
163
          "description": "When the account line was last updated"
164
        },
165
        "notify_id": {
166
          "description": "?"
167
        },
168
        "notify_level": {
169
          "description": "?"
170
        },
171
        "note": {
172
          "description": "Accountline note"
173
        },
174
        "manager_id": {
175
          "description": "Borrowernumber of user that created the account line"
176
        },
177
        "meansofpayment": {
178
          "description": "Means of payment"
179
        }
180
      }
181
    },
89
    "error": {
182
    "error": {
90
      "type": "object",
183
      "type": "object",
91
      "properties": {
184
      "properties": {
(-)a/t/db_dependent/api/v1/borrowers/accountlines.t (-1 / +60 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 17;
6
use Test::Mojo;
7
8
use C4::Context;
9
10
use Koha::Database;
11
use Koha::Borrower;
12
13
my $dbh = C4::Context->dbh;
14
$dbh->{AutoCommit} = 0;
15
$dbh->{RaiseError} = 1;
16
17
my $t = Test::Mojo->new('Koha::REST::V1');
18
19
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode();
20
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
21
22
my $borrower = Koha::Borrower->new;
23
$borrower->categorycode( $categorycode );
24
$borrower->branchcode( $branchcode );
25
$borrower->surname("Test Surname");
26
$borrower->store;
27
my $borrowernumber = $borrower->borrowernumber;
28
29
$dbh->do(q| DELETE FROM accountlines |);
30
$dbh->do(q|
31
    INSERT INTO accountlines (borrowernumber, amount, accounttype)
32
    VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F')
33
|, undef, $borrowernumber, $borrowernumber, $borrowernumber);
34
35
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines")
36
  ->status_is(200);
37
my $json = $t->tx->res->json;
38
ok(ref $json eq 'ARRAY', 'response is a JSON array');
39
ok(scalar @$json == 3, 'response array contains 3 elements');
40
41
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=A")
42
  ->status_is(200);
43
$json = $t->tx->res->json;
44
ok(ref $json eq 'ARRAY', 'response is a JSON array');
45
ok(scalar @$json == 1, 'response array contains 1 element');
46
is($json->[0]->{amount}, '20.000000', 'right amount returned');
47
48
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=F")
49
  ->status_is(200);
50
$json = $t->tx->res->json;
51
ok(ref $json eq 'ARRAY', 'response is a JSON array');
52
ok(scalar @$json == 2, 'response array contains 2 elements');
53
54
$t->get_ok("/v1/borrowers/$borrowernumber/accountlines?accounttype=Pay")
55
  ->status_is(200);
56
$json = $t->tx->res->json;
57
ok(ref $json eq 'ARRAY', 'response is a JSON array');
58
ok(scalar @$json == 0, 'response array is empty');
59
60
$dbh->rollback;

Return to bug 13935