tambah laporan gadai tebus masa
This commit is contained in:
@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\LaporanKeseluruhan\GadaiTebusAllExportExcel;
|
||||
use App\Exports\GadaiTebusMasaExport;
|
||||
|
||||
class GadaianController extends Controller
|
||||
{
|
||||
@@ -99,4 +100,79 @@ class GadaianController extends Controller
|
||||
|
||||
return view('reports.gadaitebus.index', compact('gadaian', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function gadaitebusmasa(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$action = $request->input('action', 'search');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$gadaian = Http::get($request->hostname . '/api/reports/gadaitebus', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanGadaiTebusMasa %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new GadaiTebusMasaAllExportExcel($gadaian), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.gadaitebusmasa.index', compact('gadaian', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function downloadGadaiTebusMasaCawanganExcel(Request $request)
|
||||
{
|
||||
$api_url = $request->hostname;
|
||||
$auth_user = Auth::user();
|
||||
$current = Carbon::now();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ?? $current->toDateString();
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
// dd($kod_cawangan);
|
||||
|
||||
$data = Http::get($request->hostname . '/api/reports/gadaitebusmasa/' . $kod_cawangan, [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
|
||||
$byTeller = $request->input('by_teller', 1); // default ikut teller
|
||||
|
||||
if (!$byTeller) {
|
||||
// Gabung semua data jadi satu baris
|
||||
$gabung = [
|
||||
'teller' => 'Keseluruhan',
|
||||
'jumlah_lelongan' => 0,
|
||||
'jumlah_baki' => 0,
|
||||
];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$gabung['jumlah_lelongan'] += $item['jumlah_lelongan'] ?? 0;
|
||||
$gabung['jumlah_baki'] += $item['jumlah_baki'] ?? 0;
|
||||
}
|
||||
|
||||
$data = [$gabung];
|
||||
}
|
||||
|
||||
|
||||
$file_title = sprintf("LaporanGadaiTebusMasaCawangan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new GadaiTebusMasaExport($data), $file_title);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user