add laporan lelong keseluruhan
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<?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\LelonganExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class LelonganController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$current = new Carbon();
|
||||
|
||||
$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/lelongan', [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
// dd($lelongan);
|
||||
|
||||
$startDate = $getReportDate($request->startDate);
|
||||
$endDate = $getReportDate($request->endDate);
|
||||
|
||||
return view('reports.laporan-lelong.index', compact('lelongan', 'startDate', 'endDate'));
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$validated = $request->validate(
|
||||
['monthYear' => 'required'],
|
||||
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
|
||||
]);
|
||||
|
||||
$current = Carbon::now();
|
||||
$tarikh_cetak = $current->toDateString();
|
||||
$tokens = explode('-', $validated['monthYear']);
|
||||
$month = ltrim($tokens[0], '0');
|
||||
$year = $tokens[1];
|
||||
|
||||
// Set the locale to Malaysian
|
||||
App::setLocale('ms');
|
||||
|
||||
// Create a Carbon instance representing the date
|
||||
$date = Carbon::createFromDate($year, $month, 1); // Set the day to 1st of the month
|
||||
|
||||
// Get the name of the month in Malaysian local
|
||||
$monthName = $date->translatedFormat('F');
|
||||
|
||||
$request->hostname = config('api.url');
|
||||
|
||||
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
|
||||
'month' => $month,
|
||||
'year' => $year,
|
||||
])->json();
|
||||
|
||||
$tebus_date = $monthName . ' ' . $year;
|
||||
$file_title = sprintf("Laporan-StokAudit %s (%s - %s).xlsx", 'Semua cawanangan', $monthName, $year);
|
||||
|
||||
if ($request->generateType === 'pdf') {
|
||||
return view('reports.stok-audit.show', compact('tebus_date', 'tarikh_cetak', 'stokAudit', 'month', 'year'));
|
||||
} else {
|
||||
return Excel::download(new StokAuditExport($stokAudit), $file_title);
|
||||
}
|
||||
|
||||
}
|
||||
public function downloadLelonganCawanganExcel(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/lelongan/' . $kod_cawangan, [
|
||||
'startDate' => $getReportDate($request->startDate),
|
||||
'endDate' => $getReportDate($request->endDate),
|
||||
])->json();
|
||||
// dd($data);
|
||||
|
||||
|
||||
$file_title = sprintf("LaporanLelongan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
||||
return Excel::download(new LelonganExport($data), $file_title);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user