laporan_rumusan_wtd

This commit is contained in:
Nisha Muhd
2026-01-06 12:44:24 +08:00
parent 3089817d4a
commit 6719edaa97
6 changed files with 345 additions and 2 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Support\Facades\Http;
class WTDDetailExport 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
{
$data = Http::get(config('api.url') . '/admin/wtd/summaryWtd', [
'startDate' => $this->startDate,
'endDate' => $this->endDate,
])->json();
$branch = collect($data)->firstWhere('kodcaw', $this->kodcaw);
$details = collect($branch['details'] ?? []);
return view('reports.wtd.excel', [
'details' => $details, // data WTD
'branch' => $branch,
'generatedAt' => now()->format('d/m/Y H:i'),
'startDate' => $this->startDate,
'endDate' => $this->endDate,
]);
}
}
+48 -2
View File
@@ -2,7 +2,6 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
@@ -10,7 +9,8 @@ use Illuminate\Support\Facades\Http;
use Carbon\Carbon;
use PDF;
use Maatwebsite\Excel\Excel;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\WTDDetailExport;
class WTDController extends Controller
{
@@ -178,4 +178,50 @@ class WTDController extends Controller
dd($response);
}
public function summaryWtd(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);
// $summarywtd = Http::get($request->hostname . '/admin/wtd/summaryWtd', [
// 'startDate' => $startDate,
// 'endDate' => $endDate,
// ])->effectiveUri()->__toString();
// dd($summarywtd);
$summarywtd = Http::get($request->hostname . '/admin/wtd/summaryWtd', [
'startDate' => $startDate,
'endDate' => $endDate,
])->json();
if (!is_array($summarywtd)) {
$summarywtd = [];
}
return view('reports.wtd.index', compact('summarywtd', 'startDate', 'endDate'));
}
public function exportExcel(Request $request, $kodcaw)
{
return Excel::download(
new WTDDetailExport(
$kodcaw,
$request->startDate,
$request->endDate
),"Detail_Laporan_WTD_{$kodcaw}.xlsx");
}
}