Merge branch 'main' of https://bitbucket.org/arrahn-pkb/admin-portal into feature/nisha/wtd-new
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class GadaianDetailExport implements FromView
|
||||
{
|
||||
protected $kodcaw;
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($kodcaw, $startDate, $endDate)
|
||||
{
|
||||
$this->kodcaw = $kodcaw;
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$generatedAt = now()->format('d-m-Y');
|
||||
|
||||
$data = Http::get(config('api.url') . '/api/reports/saringan/gadaian', [
|
||||
'startDate' => $this->startDate,
|
||||
'endDate' => $this->endDate,
|
||||
])->json();
|
||||
|
||||
$branch = collect($data)->firstWhere('kodcaw', $this->kodcaw);
|
||||
$details = collect($branch['details'] ?? []);
|
||||
|
||||
$tgb_lelong = $details->where('jenis', 'TGB_LELONG')->values();
|
||||
$tgb_biasa = $details->where('jenis', 'TGB_BIASA')->values();
|
||||
$gadai_biasa = $details->where('jenis', 'GADAI_BIASA')->values();
|
||||
|
||||
$subtotal = [
|
||||
'tgb_lelong' => [
|
||||
'berat' => $tgb_lelong->sum('berat'),
|
||||
'nilai' => $tgb_lelong->sum('nilaimarhun'),
|
||||
'pinjaman' => $tgb_lelong->sum('pinjaman'),
|
||||
],
|
||||
'tgb_biasa' => [
|
||||
'berat' => $tgb_biasa->sum('berat'),
|
||||
'nilai' => $tgb_biasa->sum('nilaimarhun'),
|
||||
'pinjaman' => $tgb_biasa->sum('pinjaman'),
|
||||
],
|
||||
'gadai_biasa' => [
|
||||
'berat' => $gadai_biasa->sum('berat'),
|
||||
'nilai' => $gadai_biasa->sum('nilaimarhun'),
|
||||
'pinjaman' => $gadai_biasa->sum('pinjaman'),
|
||||
],
|
||||
];
|
||||
|
||||
$grandTotal = [
|
||||
'berat' => $subtotal['tgb_lelong']['berat']
|
||||
+ $subtotal['tgb_biasa']['berat']
|
||||
+ $subtotal['gadai_biasa']['berat'],
|
||||
|
||||
'nilai' => $subtotal['tgb_lelong']['nilai']
|
||||
+ $subtotal['tgb_biasa']['nilai']
|
||||
+ $subtotal['gadai_biasa']['nilai'],
|
||||
|
||||
'pinjaman' => $subtotal['tgb_lelong']['pinjaman']
|
||||
+ $subtotal['tgb_biasa']['pinjaman']
|
||||
+ $subtotal['gadai_biasa']['pinjaman'],
|
||||
];
|
||||
|
||||
return view('reports.saringan-gadaian.excel', compact(
|
||||
'branch',
|
||||
'generatedAt',
|
||||
'tgb_lelong',
|
||||
'tgb_biasa',
|
||||
'gadai_biasa',
|
||||
'subtotal',
|
||||
'grandTotal'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\GadaianDetailExport;
|
||||
|
||||
class SaringanGadaianController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ? $date_string : $current->toDateString();
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
|
||||
$gadaian = Http::get($request->hostname . '/api/reports/saringan/gadaian', [
|
||||
'startDate' => $startDate,
|
||||
'endDate' => $endDate,
|
||||
])->json();
|
||||
|
||||
return view('reports.saringan-gadaian.index', compact('gadaian', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function exportExcel(Request $request, $kodcaw)
|
||||
{
|
||||
return Excel::download(
|
||||
new GadaianDetailExport(
|
||||
$kodcaw,
|
||||
$request->startDate,
|
||||
$request->endDate
|
||||
),
|
||||
"Saringan_Gadaian_{$kodcaw}.xlsx"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user