tambah laporan baki lelong belum tuntut
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Reports;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Exports\BakiLelongBelumTuntutExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Exports\LaporanKeseluruhan\BakiLelongAllExportExcel;
|
||||
|
||||
class BakiLelongController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$request->hostname = config('api.url');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$lelongan = Http::get($request->hostname . '/api/reports/bakilelongbelumtuntut', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanBakiLelongBelumTuntut %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new BakiLelongBelumTuntutAllExportExcel($data), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.bakilelongbelumtuntut.index', compact('lelongan', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$current = Carbon::now();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
return $date_string ? $date_string : $current->toDateString();
|
||||
};
|
||||
|
||||
$hostname = config('api.url');
|
||||
|
||||
$response = Http::get("$hostname/api/reports/bakilelongbelumtuntut", [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
]);
|
||||
|
||||
$lelongan = $response->json() ?? []; // Ensure it's an array
|
||||
|
||||
// Debugging: Check the response before using it
|
||||
if (empty($lelongan)) {
|
||||
return back()->with('error', 'Failed to fetch data from API.');
|
||||
}
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
// Ensure $kod_cawangan is defined (Modify as per your data structure)
|
||||
$kod_cawangan = $request->input('kod_cawangan', 'DEFAULT');
|
||||
|
||||
$file_title = sprintf("LaporanBakiLelongan %s (%s - %s).xlsx", $kod_cawangan, $startDate, $endDate);
|
||||
return Excel::download(new BakiLelonganAllExportExcel($lelongan), $file_title);
|
||||
}
|
||||
return view('reports.bakilelongbelumtuntut.index', compact('lelongan', 'startDate', 'endDate'));
|
||||
}
|
||||
public function downloadBakiLelongBelumTuntutCawanganExcel(Request $request)
|
||||
{
|
||||
$api_url = $request->hostname;
|
||||
$auth_user = Auth::user();
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
$kod_cawangan = $request->kod_cawangan;
|
||||
// dd($kod_cawangan);
|
||||
|
||||
$data = Http::get($request->hostname . '/api/reports/bakilelongbelumtuntut/' . $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("LaporanBakiLelongBelumTuntutCawangan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new BakiLelongBelumTuntutExport($data), $file_title);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user