tambah pelanggan aktif untuk admin portal

This commit is contained in:
BTMS2
2025-05-20 12:37:19 +08:00
parent 5411917206
commit 623db125e5
2 changed files with 109 additions and 0 deletions
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Reports;
use App\Http\Controllers\Controller;
use App\Cawangan;
use App\Gadai;
use App\Customer;
use App\Tebus;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Services\Reports\GadaianService as ReportGadaianService;
@@ -61,5 +63,110 @@ class AnalisaController extends Controller
return response()->json($response);
}
// public function getSummaryLaporanPelangganAktif(Request $request)
// {
// $startDate = $request->startDate;
// $endDate = $request->endDate;
// // Dapatkan senarai cawangan aktif
// $active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
// // Dapatkan maklumat cawangan
// $cawangan_available = Cawangan::select('kodcaw', 'details_caw', 'mysql')
// ->whereIn('mysql', $active_cawangan_db_connection)
// ->get();
// $active_cawangan_detail = $cawangan_available->map(function ($c) {
// return [
// 'kodcaw' => $c->kodcaw,
// 'details_caw' => $c->details_caw,
// 'mysql' => $c->mysql,
// ];
// })->toArray();
// $response = array_map(function ($cawangan) use ($startDate, $endDate) {
// $db_connection = $cawangan['mysql'];
// $total_aktif = Gadai::on($db_connection)
// ->where(function ($query) use ($startDate) {
// $query->where('sttebus', '')
// ->where('t_update', '>=', $startDate);
// })
// ->where('t_gadai', '<=', $endDate)
// ->distinct('nokp')
// ->count('nokp');
// return [
// 'kodcaw' => $cawangan['kodcaw'],
// 'details_caw' => $cawangan['details_caw'],
// 'total_pelanggan_aktif' => $total_aktif,
// ];
// }, $active_cawangan_detail);
// return response()->json($response);
// }
public function getSummaryLaporanPelangganAktif(Request $request)
{
$startDate = $request->startDate;
$endDate = $request->endDate;
$active_cawangan = Cawangan::select('kodcaw', 'details_caw', 'mysql')
->whereIn('mysql', Helper::getActiveCawanganDbConnection())
->get();
$response = $active_cawangan->map(function ($cawangan) use ($startDate, $endDate) {
$db = $cawangan->mysql;
// Ambil nokp dari Gadai
$nokp_gadai = DB::connection($db)->table('gadai')
->whereBetween('t_gadai', [$startDate, $endDate])
->pluck('nokp')
->toArray();
// Ambil nokp dari Tebus
$nokp_tebus = DB::connection($db)->table('tebus as t')
->join('gadai as g', 't.norujukan', '=', 'g.norujukan')
->whereBetween('t.t_tebus', [$startDate, $endDate])
->pluck('g.nokp')
->toArray();
// Gabung semua nokp
$semua_nokp = collect(array_merge($nokp_gadai, $nokp_tebus))
->filter(fn($item) => !empty($item))
->unique()
->values();
if ($semua_nokp->isEmpty()) {
// Jika array kosong, kita kembalikan hasil kosong
$pelanggan_aktif = collect();
} else {
$pelanggan_aktif = Customer::on($db)
->where(function ($query) use ($semua_nokp) {
$query->whereIn('kpbaru', $semua_nokp)
->orWhereIn('kplama', $semua_nokp);
})
->get(['nama', 'kpbaru', 'kplama'])
->toArray();;
}
return [
'kodcaw' => $cawangan->kodcaw,
'details_caw' => $cawangan->details_caw,
'total_pelanggan_aktif' => count($semua_nokp),
];
});
return response()->json($response);
}
}
+2
View File
@@ -41,5 +41,7 @@ $router->group(['prefix' => 'api/reports'], function () use ($router) {
$router->get('petibesi', ['uses' => 'OutstandingController@getSummaryLaporanPetibesi']);
$router->get('pelangganbaru', ['uses' => 'AnalisaController@getSummaryLaporanPelangganBaru']);
$router->get('pelangganaktif', ['uses' => 'AnalisaController@getSummaryLaporanPelangganAktif']);
});
});