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

(-)a/Koha/REST/V1/Accountline.pm (+34 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::Account::Lines;
24
25
sub list {
26
    my ($c, $args, $cb) = @_;
27
28
    my $params  = $c->req->params->to_hash;
29
    my $accountlines = Koha::Account::Lines->search($params);
30
31
    return $c->$cb($accountlines->unblessed, 200);
32
}
33
34
1;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 2-7 Link Here
2
  "city": {
2
  "city": {
3
    "$ref": "definitions/city.json"
3
    "$ref": "definitions/city.json"
4
  },
4
  },
5
  "accountline": {
6
    "$ref": "definitions/accountline.json"
7
  },
5
  "patron": {
8
  "patron": {
6
    "$ref": "definitions/patron.json"
9
    "$ref": "definitions/patron.json"
7
  },
10
  },
(-)a/api/v1/swagger/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/swagger/paths.json (+3 lines)
Lines 5-10 Link Here
5
  "/cities/{cityid}": {
5
  "/cities/{cityid}": {
6
    "$ref": "paths/cities.json#/~1cities~1{cityid}"
6
    "$ref": "paths/cities.json#/~1cities~1{cityid}"
7
  },
7
  },
8
  "/accountlines": {
9
    "$ref": "paths/accountlines.json#/~1accountlines"
10
  },
8
  "/holds": {
11
  "/holds": {
9
    "$ref": "paths/holds.json#/~1holds"
12
    "$ref": "paths/holds.json#/~1holds"
10
  },
13
  },
(-)a/api/v1/swagger/paths/accountlines.json (+35 lines)
Line 0 Link Here
1
{
2
  "/accountlines": {
3
    "get": {
4
      "operationId": "listAccountlines",
5
      "tags": ["accountlines"],
6
      "produces": [
7
        "application/json"
8
      ],
9
      "responses": {
10
        "200": {
11
          "description": "A list of accountlines",
12
          "schema": {
13
            "type": "array",
14
            "items": {
15
              "$ref": "../definitions.json#/accountline"
16
            }
17
          }
18
        },
19
        "403": {
20
          "description": "Access forbidden",
21
          "schema": {
22
            "$ref": "../definitions.json#/error"
23
          }
24
        }
25
      },
26
      "x-koha-authorization": {
27
        "allow-owner": true,
28
        "allow-guarantor": true,
29
        "permissions": {
30
            "updatecharges": "1"
31
        }
32
      }
33
    }
34
  }
35
}
(-)a/t/db_dependent/api/v1/accountlines.t (-1 / +118 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 => 12;
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(401);
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
        flags        => 0,
59
    }
60
});
61
62
my $borrower2 = $builder->build({
63
    source => 'Borrower',
64
    value => {
65
        branchcode   => $branchcode,
66
        categorycode => $categorycode,
67
    }
68
});
69
my $borrowernumber = $borrower->{borrowernumber};
70
my $borrowernumber2 = $borrower2->{borrowernumber};
71
72
$dbh->do(q| DELETE FROM accountlines |);
73
$dbh->do(q|
74
    INSERT INTO accountlines (borrowernumber, amount, accounttype)
75
    VALUES (?, 20, 'A'), (?, 40, 'F'), (?, 80, 'F'), (?, 10, 'F')
76
    |, undef, $borrowernumber, $borrowernumber, $borrowernumber, $borrowernumber2);
77
78
my $session = C4::Auth::get_session('');
79
$session->param('number', $loggedinuser->{ borrowernumber });
80
$session->param('id', $loggedinuser->{ userid });
81
$session->param('ip', '127.0.0.1');
82
$session->param('lasttime', time());
83
$session->flush;
84
85
my $borrowersession = C4::Auth::get_session('');
86
$borrowersession->param('number', $borrower->{ borrowernumber });
87
$borrowersession->param('id', $borrower->{ userid });
88
$borrowersession->param('ip', '127.0.0.1');
89
$borrowersession->param('lasttime', time());
90
$borrowersession->flush;
91
92
my $tx = $t->ua->build_tx(GET => "/api/v1/accountlines?borrowernumber=$borrowernumber2");
93
$tx->req->cookies({name => 'CGISESSID', value => $borrowersession->id});
94
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
95
$t->request_ok($tx)
96
  ->status_is(403);
97
98
$tx = $t->ua->build_tx(GET => "/api/v1/accountlines?borrowernumber=$borrowernumber");
99
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
100
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
101
$t->request_ok($tx)
102
  ->status_is(200);
103
104
my $json = $t->tx->res->json;
105
ok(ref $json eq 'ARRAY', 'response is a JSON array');
106
ok(scalar @$json == 3, 'response array contains 3 elements');
107
108
$tx = $t->ua->build_tx(GET => "/api/v1/accountlines");
109
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
110
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
111
$t->request_ok($tx)
112
  ->status_is(200);
113
114
$json = $t->tx->res->json;
115
ok(ref $json eq 'ARRAY', 'response is a JSON array');
116
ok(scalar @$json == 4, 'response array contains 3 elements');
117
118
$dbh->rollback;

Return to bug 15165