81 lines
2.4 KiB
PHP
81 lines
2.4 KiB
PHP
<?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\LaporanKeseluruhan\StokAuditExport;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
|
|
class StokAuditController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$request->hostname = config('api.url');
|
|
$current = new Carbon();
|
|
|
|
$month = $request->filled('month') ? $request->month : $current->month;
|
|
$year = $request->filled('year') ? $request->year : $current->year;
|
|
|
|
return view('reports.stok-audit.index', compact('month', 'year'));
|
|
}
|
|
|
|
public function show(Request $request)
|
|
{
|
|
$tarikh_cetak = Carbon::now()->toDateString(); // tarikh cetak
|
|
|
|
if ($request->dateOption === 'current') {
|
|
$date = Carbon::now();
|
|
$tebus_date = $date->format('d-m-Y'); // tarikh semasa
|
|
$monthName = $date->translatedFormat('F'); // bulan semasa
|
|
} else {
|
|
$validated = $request->validate(
|
|
['monthYear' => 'required'],
|
|
['monthYear.required' => 'Sila isi tarikh sebelum hantar',
|
|
]);
|
|
|
|
$tokens = explode('-', $validated['monthYear']);
|
|
$month = ltrim($tokens[0], '0');
|
|
$year = $tokens[1];
|
|
|
|
$date = Carbon::createFromDate($year, $month, 1); // set day = 1
|
|
$monthName = $date->translatedFormat('F');
|
|
$tebus_date = $monthName . ' ' . $year;
|
|
}
|
|
|
|
$month = $date->month;
|
|
$year = $date->year;
|
|
|
|
$request->hostname = config('api.url');
|
|
|
|
$stokAudit = Http::get($request->hostname . '/api/reports/stok-audit', [
|
|
'month' => $month,
|
|
'year' => $year,
|
|
'dateOption' => $request->dateOption
|
|
])->json();
|
|
|
|
$file_title = sprintf(
|
|
"Laporan-StokAudit %s (%s).xlsx",
|
|
'Semua cawangan',
|
|
$tebus_date
|
|
);
|
|
|
|
if ($request->generateType === 'pdf') {
|
|
return view('reports.stok-audit.show', compact(
|
|
'stokAudit',
|
|
'month',
|
|
'year',
|
|
'monthName',
|
|
'tarikh_cetak',
|
|
'tebus_date'
|
|
));
|
|
} else {
|
|
return Excel::download(new StokAuditExport($stokAudit), $file_title);
|
|
}
|
|
|
|
}
|
|
}
|