61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?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
|
|
{
|
|
$hostname = config('api.url');
|
|
$gadaian = Http::get($hostname . '/api/reports/saringan/gadaian', [
|
|
'startDate' => $this->startDate,
|
|
'endDate' => $this->endDate,
|
|
])->json();
|
|
|
|
$branch = collect($gadaian)->firstWhere('kodcaw', $this->kodcaw);
|
|
|
|
$details = collect($branch['details'] ?? [])
|
|
->sort(function ($a, $b) {
|
|
$aTag = isset($a['taglel_lama']) && $a['taglel_lama'] == 1 ? 0 : 1;
|
|
$bTag = isset($b['taglel_lama']) && $b['taglel_lama'] == 1 ? 0 : 1;
|
|
|
|
if ($aTag !== $bTag) {
|
|
return $aTag <=> $bTag;
|
|
}
|
|
|
|
|
|
return ($a['t_gadai'] ?? '') <=> ($b['t_gadai'] ?? '');
|
|
})
|
|
->values()
|
|
->all();
|
|
|
|
|
|
$total_berat = collect($details)->sum('berat');
|
|
$total_nm = collect($details)->sum('nilaimarhun');
|
|
$total_pinjam = collect($details)->sum('pinjaman');
|
|
|
|
return view('reports.saringan-gadaian.excel', compact(
|
|
'details',
|
|
'total_berat',
|
|
'total_nm',
|
|
'total_pinjam',
|
|
'branch'
|
|
));
|
|
}
|
|
}
|