|
Lines 25-30
use C4::Auth qw( haspermission );
Link Here
|
| 25 |
use Koha::Account::Lines; |
25 |
use Koha::Account::Lines; |
| 26 |
use Koha::Account; |
26 |
use Koha::Account; |
| 27 |
|
27 |
|
|
|
28 |
use Try::Tiny; |
| 29 |
|
| 28 |
sub list { |
30 |
sub list { |
| 29 |
my ($c, $args, $cb) = @_; |
31 |
my ($c, $args, $cb) = @_; |
| 30 |
|
32 |
|
|
Lines 55-87
sub edit {
Link Here
|
| 55 |
sub pay { |
57 |
sub pay { |
| 56 |
my ($c, $args, $cb) = @_; |
58 |
my ($c, $args, $cb) = @_; |
| 57 |
|
59 |
|
| 58 |
my $accountline = Koha::Account::Lines->find($args->{accountlines_id}); |
60 |
return try { |
| 59 |
unless ($accountline) { |
61 |
my $accountline = Koha::Account::Lines->find($args->{accountlines_id}); |
| 60 |
return $c->$cb({error => "Accountline not found"}, 404); |
62 |
unless ($accountline) { |
| 61 |
} |
63 |
return $c->$cb({error => "Accountline not found"}, 404); |
| 62 |
|
64 |
} |
| 63 |
my $body = $c->req->json; |
|
|
| 64 |
my $amount = $body->{amount}; |
| 65 |
my $note = $body->{note} || ''; |
| 66 |
|
| 67 |
if ($amount && !looks_like_number($amount)) { |
| 68 |
return $c->$cb({error => "Invalid amount"}, 400); |
| 69 |
} |
| 70 |
|
65 |
|
| 71 |
Koha::Account->new( |
66 |
my $body = $c->req->json; |
| 72 |
{ |
67 |
my $amount = $body->{amount}; |
| 73 |
patron_id => $accountline->borrowernumber, |
68 |
my $note = $body->{note} || ''; |
|
|
69 |
|
| 70 |
Koha::Account->new( |
| 71 |
{ |
| 72 |
patron_id => $accountline->borrowernumber, |
| 73 |
} |
| 74 |
)->pay( |
| 75 |
{ |
| 76 |
lines => [$accountline], |
| 77 |
amount => $amount, |
| 78 |
note => $note, |
| 79 |
} |
| 80 |
); |
| 81 |
|
| 82 |
$accountline = Koha::Account::Lines->find($args->{accountlines_id}); |
| 83 |
return $c->$cb($accountline->unblessed(), 200); |
| 84 |
} catch { |
| 85 |
if ($_->isa('DBIx::Class::Exception')) { |
| 86 |
return $c->$cb({ error => $_->msg }, 500); |
| 74 |
} |
87 |
} |
| 75 |
)->pay( |
88 |
else { |
| 76 |
{ |
89 |
return $c->$cb({ |
| 77 |
lines => [$accountline], |
90 |
error => 'Something went wrong, check the logs.' |
| 78 |
amount => $amount, |
91 |
}, 500); |
| 79 |
note => $note, |
|
|
| 80 |
} |
92 |
} |
| 81 |
); |
93 |
}; |
| 82 |
|
|
|
| 83 |
$accountline = Koha::Account::Lines->find($args->{accountlines_id}); |
| 84 |
return $c->$cb($accountline->unblessed(), 200); |
| 85 |
} |
94 |
} |
| 86 |
|
95 |
|
| 87 |
|
96 |
|