179 lines
5.9 KiB
PHP
179 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Reports;
|
|
|
|
use App\Exports\GadaianExport;
|
|
use App\Helper;
|
|
use App\Http\Controllers\Controller;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\LaporanKeseluruhan\GadaiTebusAllExportExcel;
|
|
use App\Exports\GadaiTebusMasaExport;
|
|
|
|
class GadaianController 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');
|
|
|
|
$gadaian = Http::get($request->hostname . '/api/reports/gadaian', [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
|
|
$startDate = $getReportDate($request->startDate);
|
|
$endDate = $getReportDate($request->endDate);
|
|
|
|
return view('reports.gadaian.index', compact('gadaian', 'startDate', 'endDate'));
|
|
}
|
|
|
|
public function downloadGadaianCawanganExcel(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;
|
|
|
|
$data = Http::get($request->hostname . '/api/reports/gadaian/' . $kod_cawangan, [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
|
|
|
|
$file_title = sprintf("LaporanGadaian %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new GadaianExport($data), $file_title);
|
|
}
|
|
|
|
public function gadaitebus(Request $request)
|
|
{
|
|
$current = new Carbon();
|
|
$action = $request->input('action', 'search');
|
|
$kod_cawangan = $request->kod_cawangan;
|
|
|
|
$getReportDate = function ($date_string) use ($current) {
|
|
if ($date_string == null) {
|
|
return $current->toDateString();
|
|
}
|
|
|
|
return $date_string;
|
|
};
|
|
|
|
$request->hostname = config('api.url');
|
|
|
|
$gadaian = Http::get($request->hostname . '/api/reports/gadaitebus', [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
|
|
$startDate = $getReportDate($request->startDate);
|
|
$endDate = $getReportDate($request->endDate);
|
|
|
|
if ($action === 'excel') {
|
|
$file_title = sprintf("LaporanGadaiTebus %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new GadaiTebusAllExportExcel($gadaian), $file_title);
|
|
}
|
|
|
|
return view('reports.gadaitebus.index', compact('gadaian', 'startDate', 'endDate'));
|
|
}
|
|
|
|
public function gadaitebusmasa(Request $request)
|
|
{
|
|
$current = new Carbon();
|
|
$action = $request->input('action', 'search');
|
|
$kod_cawangan = $request->kod_cawangan;
|
|
|
|
$getReportDate = function ($date_string) use ($current) {
|
|
if ($date_string == null) {
|
|
return $current->toDateString();
|
|
}
|
|
|
|
return $date_string;
|
|
};
|
|
|
|
$request->hostname = config('api.url');
|
|
|
|
$gadaian = Http::get($request->hostname . '/api/reports/gadaitebus', [
|
|
'startDate' => $getReportDate($request->startDate),
|
|
'endDate' => $getReportDate($request->endDate),
|
|
])->json();
|
|
|
|
$startDate = $getReportDate($request->startDate);
|
|
$endDate = $getReportDate($request->endDate);
|
|
|
|
if ($action === 'excel') {
|
|
$file_title = sprintf("LaporanGadaiTebusMasa %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new GadaiTebusMasaAllExportExcel($gadaian), $file_title);
|
|
}
|
|
|
|
return view('reports.gadaitebusmasa.index', compact('gadaian', 'startDate', 'endDate'));
|
|
}
|
|
|
|
public function downloadGadaiTebusMasaCawanganExcel(Request $request)
|
|
{
|
|
$api_url = $request->hostname;
|
|
$auth_user = Auth::user();
|
|
$current = Carbon::now();
|
|
$tarikh_cetak = $current->toDateString();
|
|
|
|
$getReportDate = function ($date_string) use ($current) {
|
|
return $date_string ?? $current->toDateString();
|
|
};
|
|
|
|
$request->hostname = config('api.url');
|
|
$kod_cawangan = $request->kod_cawangan;
|
|
// dd($kod_cawangan);
|
|
|
|
$data = Http::get($request->hostname . '/api/reports/gadaitebusmasa/' . $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("LaporanGadaiTebusMasaCawangan %s (%s - %s).xlsx", $kod_cawangan, $request->startDate, $request->endDate);
|
|
return Excel::download(new GadaiTebusMasaExport($data), $file_title);
|
|
}
|
|
}
|