Add Excel export to Billplz Transaction Summary
This commit is contained in:
@@ -5,14 +5,58 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\BillplzTransactionSummaryExport;
|
||||
use App\Exports\BillplzTransactionSummarySheet;
|
||||
|
||||
|
||||
class BillplzTransactionSummaryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$date = $request->selectedDate ?? Carbon::now()->toDateString();
|
||||
|
||||
$transactionDataPKB = collect( Http::arrahn()->get('/api/transaction/online/query', ['date' => $date, 'status' => 'paid'])->json() );
|
||||
|
||||
[$billPlzTransactionSummaryPKB, $billPlzTransactionSummaryKOOP] = $this->getSummaryData($date);
|
||||
|
||||
return view('online.billplz-transaction-summary.index', compact('billPlzTransactionSummaryPKB', 'billPlzTransactionSummaryKOOP', 'date'));
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$date = $request->selectedDate ?? Carbon::now()->toDateString();
|
||||
$tab = $request->tab ?? 'all';
|
||||
|
||||
[$billPlzTransactionSummaryPKB, $billPlzTransactionSummaryKOOP] = $this->getSummaryData($date);
|
||||
|
||||
if ($tab === 'kopkb') {
|
||||
$file_name = 'billplz_transaction_summary_kopkb_' . $date . '.xlsx';
|
||||
|
||||
return Excel::download(
|
||||
new BillplzTransactionSummarySheet($billPlzTransactionSummaryKOOP, 'KOPKB (v3)', $date),
|
||||
$file_name
|
||||
);
|
||||
}
|
||||
|
||||
if ($tab === 'pkb') {
|
||||
$file_name = 'billplz_transaction_summary_pkb_' . $date . '.xlsx';
|
||||
|
||||
return Excel::download(
|
||||
new BillplzTransactionSummarySheet($billPlzTransactionSummaryPKB, 'PKB (v2)', $date),
|
||||
$file_name
|
||||
);
|
||||
}
|
||||
|
||||
$file_name = 'billplz_transaction_summary_' . $date . '.xlsx';
|
||||
|
||||
return Excel::download(
|
||||
new BillplzTransactionSummaryExport($billPlzTransactionSummaryPKB, $billPlzTransactionSummaryKOOP, $date),
|
||||
$file_name
|
||||
);
|
||||
}
|
||||
|
||||
private function getSummaryData($date)
|
||||
{
|
||||
$transactionDataPKB = collect( Http::arrahn()->get('/api/transaction/online/query', ['date' => $date, 'status' => 'paid'])->json() );
|
||||
$transactionDataPKB = $transactionDataPKB->map(function($x){
|
||||
$x['account_own_by'] = 'PKB';
|
||||
return $x;
|
||||
@@ -60,14 +104,14 @@ class BillplzTransactionSummaryController extends Controller
|
||||
abort( response('Portal ArrahnPay kemungkinan tidak beroperasi. Waktu Operasi Portal ArrahnPay adalah dari 7.30 AM hingga 11.30 PM', 503) );
|
||||
}
|
||||
|
||||
return $billplzBillsPromise;
|
||||
return $billplzBillsPromise;
|
||||
};
|
||||
|
||||
|
||||
$mergeBillplzResponse = function($externalArray) {
|
||||
$merged = [];
|
||||
$merged = [];
|
||||
|
||||
foreach ($externalArray as $key => $subArray) {
|
||||
foreach ($externalArray as $key => $subArray) {
|
||||
foreach (['KOPKB', 'PKB'] as $type) {
|
||||
if (!isset($merged[$type])) {
|
||||
$merged[$type] = [];
|
||||
@@ -75,9 +119,9 @@ class BillplzTransactionSummaryController extends Controller
|
||||
|
||||
$merged[$type] = array_merge($merged[$type], $subArray[$type]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_map('array_values', $merged);
|
||||
return array_map('array_values', $merged);
|
||||
};
|
||||
|
||||
$billplzBillsResponse = $queryBillIdsURL->map(fn($x) => $getBillplzPromise($x))
|
||||
@@ -88,9 +132,11 @@ class BillplzTransactionSummaryController extends Controller
|
||||
|
||||
$data = array_map(fn($x, $y) => $this->processBillplzBills($x, $y), $billplzBills, [$transactionDataKOOP, $transactionDataPKB]);
|
||||
|
||||
|
||||
|
||||
[$billPlzTransactionSummaryKOOP, $billPlzTransactionSummaryPKB] = $data;
|
||||
|
||||
return view('online.billplz-transaction-summary.index', compact('billPlzTransactionSummaryPKB' ,'billPlzTransactionSummaryKOOP', 'date'));
|
||||
return [$billPlzTransactionSummaryPKB, $billPlzTransactionSummaryKOOP];
|
||||
}
|
||||
|
||||
public function processArrahnTransactions($transactionData)
|
||||
|
||||
Reference in New Issue
Block a user