View | Details | Raw Unified | Return to bug 15165
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/Accountline.pm (+39 lines)
Line 0 Link Here
1
package Koha::REST::V1::Accountline;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use C4::Auth qw( haspermission );
23
use Koha::Accountlines;
24
25
sub list {
26
    my ($c, $args, $cb) = @_;
27
28
    my $user = $c->stash('koha.user');
29
    unless ($user && haspermission($user->userid, {updatecharges => 1})) {
30
        return $c->$cb({error => "You don't have the required permission"}, 403);
31
    }
32
33
    my $params  = $c->req->params->to_hash;
34
    my $accountlines = Koha::Accountlines->search($params);
35
36
    return $c->$cb($accountlines->unblessed, 200);
37
}
38
39
1;
(-)a/api/v1/definitions/accountline.json (+56 lines)
Line 0 Link Here
1
{
2
    "type": "object",
3
        "properties": {
4
            "accountlines_id": {
5
                "description": "Internal account line identifier"
6
            },
7
            "borrowernumber": {
8
                "description": "Internal borrower identifier"
9
            },
10
            "accountno": {
11
                "description": "?"
12
            },
13
            "itemnumber": {
14
                "description": "Internal item identifier"
15
            },
16
            "date": {
17
                "description": "Date when the account line was created"
18
            },
19
            "time": {
20
                "description": "Time when the account line was created"
21
            },
22
            "amount": {
23
                "description": "Amount"
24
            },
25
            "description": {
26
                "description": "Description of account line"
27
            },
28
            "accounttype": {
29
                "description": "Type of accountline"
30
            },
31
            "amountoutstanding": {
32
                "description": "Amount outstanding"
33
            },
34
            "lastincrement": {
35
                "description": "?"
36
            },
37
            "timestamp": {
38
                "description": "When the account line was last updated"
39
            },
40
            "notify_id": {
41
                "description": "?"
42
            },
43
            "notify_level": {
44
                "description": "?"
45
            },
46
            "note": {
47
                "description": "Accountline note"
48
            },
49
            "manager_id": {
50
                "description": "Borrowernumber of user that created the account line"
51
            },
52
            "meansofpayment": {
53
                "description": "Means of payment"
54
            }
55
      }
56
}
(-)a/api/v1/definitions/index.json (+1 lines)
Lines 1-4 Link Here
1
{
1
{
2
    "patron": { "$ref": "patron.json" },
2
    "patron": { "$ref": "patron.json" },
3
    "accountline": { "$ref": "accountline.json" },
3
    "error": { "$ref": "error.json" }
4
    "error": { "$ref": "error.json" }
4
}
5
}
(-)a/api/v1/swagger.json (+26 lines)
Lines 73-78 Link Here
73
          }
73
          }
74
        }
74
        }
75
      }
75
      }
76
    },
77
    "/accountlines": {
78
      "get": {
79
        "operationId": "listAccountlines",
80
        "tags": ["accountlines"],
81
        "produces": [
82
          "application/json"
83
        ],
84
        "responses": {
85
          "200": {
86
            "description": "A list of accountlines",
87
            "schema": {
88
              "type": "array",
89
              "items": {
90
                "$ref": "#/definitions/accountline"
91
              }
92
            }
93
          },
94
          "403": {
95
            "description": "Access forbidden",
96
            "schema": {
97
              "$ref": "#/definitions/error"
98
            }
99
          }
100
        }
101
      }
76
    }
102
    }
77
  },
103
  },
78
  "definitions": {
104
  "definitions": {
(-)a/t/db_dependent/api/v1/accountlines.t (-1 / +104 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Test::More tests => 10;
21
use Test::Mojo;
22
use t::lib::TestBuilder;
23
24
use C4::Auth;
25
use C4::Context;
26
27
use Koha::Database;
28
29
my $builder = t::lib::TestBuilder->new();
30
31
my $dbh = C4::Context->dbh;
32
$dbh->{AutoCommit} = 0;
33
$dbh->{RaiseError} = 1;
34
35
$ENV{REMOTE_ADDR} = '127.0.0.1';
36
my $t = Test::Mojo->new('Koha::REST::V1');
37
38
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
39
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
40
41
$t->get_ok('/api/v1/accountlines')
42
  ->status_is(403);
43
44
my $loggedinuser = $builder->build({
45
    source => 'Borrower',
46
    value => {
47
        branchcode   => $branchcode,
48
        categorycode => $categorycode,
49
        flags        => 1024
50
    }
51
});
52
53
my $borrower = $builder->build({
54
    source => 'Borrower',
55
    value => {
56
        branchcode   => $branchcode,
57
        categorycode => $categorycode,
58
    }
59
});
60
61
my $borrower2 = $builder->build({
62
    source => 'Borrower',
63
    value => {
64
        branchcode   => $branchcode,
65
        categorycode => $categorycode,
66
    }
67
});
68
my $borrowernumber = $borrower->{borrowernumber};
69
my $borrowernumber2 = $borrower2->{borrowernumber};
70
71
$dbh->do(q| DELETE FROM accountlines |);
72
$dbh->do(q|
73
    INSERT INTO accountlines (borrowernumber, amount, accounttype)
74
    VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F'), (?, 10, 'F')
75
    |, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2);
76
77
my $session = C4::Auth::get_session('');
78
$session->param('number', $loggedinuser->{ borrowernumber });
79
$session->param('id', $loggedinuser->{ userid });
80
$session->param('ip', '127.0.0.1');
81
$session->param('lasttime', time());
82
$session->flush;
83
84
my $tx = $t->ua->build_tx(GET => "/api/v1/accountlines?borrowernumber=$borrowernumber");
85
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
86
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
87
$t->request_ok($tx)
88
  ->status_is(200);
89
90
my $json = $t->tx->res->json;
91
ok(ref $json eq 'ARRAY', 'response is a JSON array');
92
ok(scalar @$json == 3, 'response array contains 3 elements');
93
94
$tx = $t->ua->build_tx(GET => "/api/v1/accountlines");
95
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
96
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
97
$t->request_ok($tx)
98
  ->status_is(200);
99
100
$json = $t->tx->res->json;
101
ok(ref $json eq 'ARRAY', 'response is a JSON array');
102
ok(scalar @$json == 4, 'response array contains 3 elements');
103
104
$dbh->rollback;

Return to bug 15165