Files
api_arrahn/app/Http/Controllers/Reports/AnalisaController.php
T
2025-05-15 14:52:55 +08:00

66 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers\Reports;
use App\Http\Controllers\Controller;
use App\Cawangan;
use App\Gadai;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Services\Reports\GadaianService as ReportGadaianService;
use App\Helper;
use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService;
class AnalisaController extends Controller
{
public function getLaporanCawangan(string $kod_cawangan, Request $request)
{
$reportGadaianService = new ReportGadaianService($kod_cawangan, $request);
return $reportGadaianService->getCawanganReport();
}
public function getSummaryLaporanPelangganBaru(Request $request)
{
$startDate = $request->startDate;
$endDate = $request->endDate;
// Get active branch DBs from helper
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
// Fetch branch details with mysql info
$cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
->whereIn('mysql', $active_cawangan_db_connection)
->get();
$active_cawangan_db_connection = array_column($cawangan_available->toArray(), 'mysql');
$active_cawangan_detail = $cawangan_available->map(function ($c) {
return [
'kodcaw' => $c->kodcaw,
'details_caw' => $c->details_caw,
];
})->values()->toArray();
// Iterate through each branch and get data
$response = array_map(function ($db_connection, $cawangan_detail) use ($request) {
// Pass the required parameters to the service constructor
$reportRingkasanHarianService = new ReportRingkasanHarianService($cawangan_detail['kodcaw'], $request);
// Get the customer count from the service
$bilangan_customer_baru = $reportRingkasanHarianService->getCustomerSummary(); // Call public method
// Return the response
return [
'kodcaw' => $cawangan_detail['kodcaw'],
'details_caw' => $cawangan_detail['details_caw'],
'total_pelanggan_baru' => $bilangan_customer_baru,
];
}, $active_cawangan_db_connection, $active_cawangan_detail);
return response()->json($response);
}
}