Skip to content

Commit a8ed753

Browse files
author
Addin Gama Bertaqwa
committed
Tmoney history transaction
1 parent 2c5b808 commit a8ed753

File tree

9 files changed

+232
-25
lines changed

9 files changed

+232
-25
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Api\TMoney;
4+
5+
use App\Http\Controllers\Controller;
6+
use GuzzleHttp\Client;
7+
use GuzzleHttp\Exception\BadResponseException;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\Config;
11+
use Illuminate\Support\Facades\Log;
12+
13+
class ReportController extends Controller
14+
{
15+
private $client;
16+
17+
public function __construct()
18+
{
19+
$this->middleware('auth:api');
20+
$this->client = new Client();
21+
}
22+
23+
public function transactionReport(Request $request)
24+
{
25+
try {
26+
$user = Auth::user();
27+
$params = [
28+
'idTmoney' => $user->idTmoney,
29+
'idFusion' => $user->idFusion,
30+
'token' => $request['token'],
31+
'startDate' => $request['startDate'],
32+
'stopDate' => $request['stopDate'],
33+
'limit' => $request['limit'],
34+
'terminal' => Config::get('tmoney.terminal'),
35+
'apiKey' => Config::get('tmoney.api_key'),
36+
];
37+
Log::info($params);
38+
$response = $this->client->post(Config::get('tmoney.base_url') . '/transaction-report', [
39+
'headers' => [
40+
'Authorization' => Config::get('tmoney.authorization'),
41+
'Accept' => 'application/json'
42+
],
43+
'form_params' => $params
44+
]);
45+
$body = $response->getBody();
46+
$json = json_decode($body);
47+
return $this->responseSuccess($request, $json);
48+
} catch (BadResponseException $e) {
49+
return $this->responseError($request, $e);
50+
}
51+
}
52+
}

app/Http/Controllers/Controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function responseError(Request $request, Exception $e)
2323
return response()->json([
2424
'error' => true,
2525
'code' => $e->getCode(),
26-
'url' => $request->url(),
26+
'url' => $request->fullUrl(),
2727
'message' => $e->getMessage()
2828
], $e->getCode());
2929
}
@@ -38,7 +38,7 @@ public function responseSuccess(Request $request, $response)
3838
{
3939
return response()->json([
4040
'error' => false,
41-
'url' => $request->url(),
41+
'url' => $request->fullUrl(),
4242
'response' => $response
4343
]);
4444

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\TMoney;
4+
5+
use Illuminate\Http\Request;
6+
use App\Http\Controllers\Controller;
7+
8+
class ReportController extends Controller
9+
{
10+
public function transactionReport() {
11+
return view('reports.transaction');
12+
}
13+
}

resources/views/donation/inquiry.blade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
</div>
2929
</div>
3030
<div class="panel-footer">
31-
3231
<button>Send Inquiry</button>
3332
</div>
3433
</div>
@@ -154,7 +153,7 @@
154153
})
155154
.catch(function (error) {
156155
console.log(error);
157-
window.swal.close();
156+
showError(error.toString());
158157
});
159158
// stop the form from submitting the normal way and refreshing the page
160159
event.preventDefault();
@@ -203,7 +202,7 @@
203202
})
204203
.catch(function (error) {
205204
console.log(error);
206-
window.swal.close();
205+
showError(error.toString());
207206
});
208207
// stop the form from submitting the normal way and refreshing the page
209208
event.preventDefault();

resources/views/home.blade.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="row">
77
<div class="col-md-10 col-md-offset-1">
88
<div class="row">
9-
<div class="col-md-3">
9+
<div class="col-md-4">
1010
<div class="panel panel-default ">
1111
<a href="#" class="no-hover">
1212
<div class="panel-body">
@@ -16,7 +16,17 @@
1616
</a>
1717
</div>
1818
</div>
19-
<div class="col-md-3">
19+
<div class="col-md-4">
20+
<div class="panel panel-default ">
21+
<a href="{{ url('/transaction-report') }}" class="no-hover">
22+
<div class="panel-body">
23+
<h3>Transaction Report</h3>
24+
<i class="fa fa-exchange" aria-hidden="true"></i>
25+
</div>
26+
</a>
27+
</div>
28+
</div>
29+
<div class="col-md-4">
2030
<div class="panel panel-default ">
2131
<a href="{{ url('/donation') }}" class="no-hover">
2232
<div class="panel-body">
@@ -59,24 +69,6 @@
5969
localStorage.setItem('idFusion', window.idFusion);
6070
localStorage.setItem('authorization', 'Bearer ' + window.authorization);
6171
62-
// setting numeral
63-
numeral.register('locale', 'id', {
64-
delimiters: {
65-
thousands: '.',
66-
decimal: ','
67-
},
68-
abbreviations: {
69-
thousand: 'rb',
70-
million: 'jt',
71-
billion: 'm',
72-
trillion: 't'
73-
},
74-
currency: {
75-
symbol: 'Rp.'
76-
}
77-
});
78-
numeral.locale('id');
79-
8072
// update dashboard
8173
$('#balance-value').text(localStorage.getItem('balance'));
8274

resources/views/layouts/app.blade.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@
8888
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.min.js"></script>
8989
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
9090
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
91+
92+
<script>
93+
// setting numeral
94+
numeral.register('locale', 'id', {
95+
delimiters: {
96+
thousands: '.',
97+
decimal: ','
98+
},
99+
abbreviations: {
100+
thousand: 'rb',
101+
million: 'jt',
102+
billion: 'm',
103+
trillion: 't'
104+
},
105+
currency: {
106+
symbol: 'Rp.'
107+
}
108+
});
109+
numeral.locale('id');
110+
</script>
91111
@include ('partials.footer')
92112
@stack('scripts')
93113
</body>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
6+
<div class="row">
7+
<div class="col-md-12">
8+
<div class="panel panel-default">
9+
<div class="panel-heading">Transaction Report</div>
10+
<div class="panel-body table-responsive ">
11+
<table class="table table-bordered">
12+
<thead>
13+
<tr>
14+
<td>No</td>
15+
<td>Tanggal</td>
16+
<td>Transaksi</td>
17+
<td>Info</td>
18+
<td>Jumlah</td>
19+
<td>Fee</td>
20+
<td>Total</td>
21+
<td>Status</td>
22+
</tr>
23+
</thead>
24+
<tbody>
25+
26+
</tbody>
27+
</table>
28+
</div>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
34+
@endsection
35+
36+
@push('styles')
37+
38+
@endpush
39+
40+
@push('scripts')
41+
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
42+
<script>
43+
$(document).ready(function () {
44+
getTransactionReport();
45+
46+
function getTransactionReport() {
47+
showProgress("Fetching");
48+
const params = {
49+
token: localStorage.getItem('token'),
50+
limit: 10000,
51+
startDate: '2000-01-01',
52+
endDate: moment().format('YYYY-MM-DD')
53+
};
54+
55+
// this different from donation because the header not passed on get request
56+
axios({
57+
method: 'get',
58+
url: '/api/transaction-report?' + $.param(params),
59+
headers: {
60+
'Authorization': localStorage.getItem('authorization')
61+
}
62+
}).then(function (res) {
63+
console.log(res);
64+
window.swal.close();
65+
if (!res.data.error) {
66+
const response = res.data.response;
67+
console.log(response);
68+
if (response.resultCode === 0) {
69+
$('table tbody').html('');
70+
const format = '$0,0.00';
71+
response.record.forEach(function(item, index) {
72+
$('table tbody').append('<tr>');
73+
$('table tbody').append('<td class="text-center">'+ (index + 1) +'</td>');
74+
$('table tbody').append('<td>'+ item.trans_time +'</td>');
75+
$('table tbody').append('<td>'+ item.trans_title +'</td>');
76+
// traverse through
77+
var info = '';
78+
var counter = 1;
79+
$.each(item.detitle, function(key, value) {
80+
if (value !== '') {
81+
info += value + ': ' + item.detail['detail_'+(counter)] + '<br>';
82+
}
83+
counter++;
84+
});
85+
$('table tbody').append('<td><p>' + info +'</p></td>');
86+
$('table tbody').append('<td class="text-right">'+ numeral(item.amount).format(format) +'</td>');
87+
$('table tbody').append('<td class="text-right">'+ numeral(item.fee).format(format) +'</td>');
88+
$('table tbody').append('<td class="text-right">'+ numeral(item.eup).format(format) +'</td>');
89+
$('table tbody').append('<td class="text-center">'+ item.status +'</td>');
90+
$('table tbody').append('</tr>');
91+
})
92+
} else {
93+
showError(response.resultDesc);
94+
}
95+
96+
} else {
97+
showError(res.data.message);
98+
}
99+
100+
101+
})
102+
.catch(function (error) {
103+
console.log(error.toString());
104+
showError(error.toString());
105+
});
106+
}
107+
108+
function showProgress(title) {
109+
window.swal({
110+
title: title,
111+
text: "Please wait",
112+
icon: "info",
113+
button: false,
114+
closeOnClickOutside: false,
115+
closeOnEsc: false
116+
});
117+
}
118+
119+
function showError(message) {
120+
window.swal({
121+
title: "Error",
122+
text: message,
123+
icon: "error"
124+
})
125+
}
126+
});
127+
128+
</script>
129+
@endpush

routes/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
Route::group(['middleware' => 'auth:api', 'namespace' => 'Api\\TMoney'], function() {
2929
Route::post('/my_profile', 'GeneralController@myProfile');
3030
Route::post('/donation', 'DonationController@donation');
31+
Route::get('/transaction-report', 'ReportController@transactionReport');
3132
});

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323

2424
Route::group(['middleware' => 'auth', 'namespace' => 'TMoney'], function() {
2525
Route::get('donation', 'DonationController@inquiry');
26+
Route::get('transaction-report', 'ReportController@transactionReport');
2627
});

0 commit comments

Comments
 (0)