tambah laporan keseluruhan ansuran excel
This commit is contained in:
@@ -9,12 +9,16 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\LaporanKeseluruhan\AnsuranAllExportExcel;
|
||||
|
||||
class AnsuranController 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) {
|
||||
@@ -37,6 +41,55 @@ class AnsuranController extends Controller
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
if ($action === 'excel') {
|
||||
$file_title = sprintf("LaporanAnsuran %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new AnsuranAllExportExcel($data), $file_title);
|
||||
}
|
||||
|
||||
return view('reports.ansuran.index', compact('summary_ansuran_by_cawangan', 'summary_ansuran', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
$action = $request->input('action', 'search');
|
||||
|
||||
$getReportDate = function ($date_string) use ($current) {
|
||||
if ($date_string == null) {
|
||||
return $current->toDateString();
|
||||
}
|
||||
|
||||
return $date_string;
|
||||
};
|
||||
|
||||
$hostname = config('api.url');
|
||||
|
||||
$response = Http::get($hostname . '/api/reports/ansuran', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
]);
|
||||
|
||||
$ansuran = $response->json() ?? [];
|
||||
if (empty($ansuran)) {
|
||||
return back()->with('error', 'Failed to fetch data from API.');
|
||||
}
|
||||
|
||||
$summary_ansuran_by_cawangan = $response['summary_ansuran_by_cawangan'];
|
||||
$summary_ansuran = $response['summary_ansuran'];
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
// dd($ansuran);
|
||||
|
||||
if ($action === 'excel') {
|
||||
|
||||
$exportData = $ansuran['summary_ansuran_by_cawangan'];
|
||||
// Ensure $kod_cawangan is defined (Modify as per your data structure)
|
||||
$kod_cawangan = $request->input('kod_cawangan', 'DEFAULT');
|
||||
|
||||
$file_title = sprintf("LaporanAnsuran %s (%s - %s).xlsx", $kod_cawangan, $startDate, $endDate);
|
||||
return Excel::download(new AnsuranAllExportExcel($exportData), $file_title);
|
||||
}
|
||||
return view('reports.ansuran.index', compact('summary_ansuran_by_cawangan', 'summary_ansuran', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user