Merge remote-tracking branch 'origin/rebate-anggota' into explore/ismail

DONE: pull latest changes from rebate-anggota into explore/ismail
This commit is contained in:
ISMAIL MASSERAN
2026-08-09 10:37:59 +08:00
20 changed files with 1398 additions and 309 deletions
+254 -264
View File
@@ -30,6 +30,7 @@ use App\Status;
use App\LookupStatus;
use App\ARFiles;
use App\WTDDraft;
use App\WTDSimulasi;
use App\SerahBaki;
use App\WTD;
use App\StokAudit1;
@@ -62,7 +63,6 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use App\Jobs\AccountCheckJob;
use App\Penyelarasan;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Cache;
@@ -2365,7 +2365,6 @@ class AdminPageController extends Controller
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
//$latestbatch = SerahBaki::on($cawangan['mysql'])->where('norujukan','baru')->get()->toArray();
//new added
$serahBaki = SerahBaki::on($cawangan['mysql'])
->where('norujukan', 'baru')
@@ -2374,28 +2373,28 @@ class AdminPageController extends Controller
$allBatchNo = $serahBaki->pluck('batchno')->unique()->toArray();
$wtddraftData = WTDDraft::on('mysql7')
->selectRaw("
batchno_serah,
YEAR(t_jual) as tahun,
GROUP_CONCAT(
DISTINCT MONTH(t_jual)
ORDER BY MONTH(t_jual)
SEPARATOR ','
) as bulan
")
->where('kodcaw', $request->kodcaw)
->whereIn('batchno_serah', $allBatchNo)
->groupBy('batchno_serah', DB::raw('YEAR(t_jual)'))
->get()
->groupBy('batchno_serah')
->map(function ($rows) {
return $rows->map(function ($row) {
return [
'tahun' => $row->tahun,
'bulan' => $row->bulan
];
})->values();
});
->selectRaw("
batchno_serah,
YEAR(t_jual) as tahun,
GROUP_CONCAT(
DISTINCT MONTH(t_jual)
ORDER BY MONTH(t_jual)
SEPARATOR ','
) as bulan
")
->where('kodcaw', $request->kodcaw)
->whereIn('batchno_serah', $allBatchNo)
->groupBy('batchno_serah', DB::raw('YEAR(t_jual)'))
->get()
->groupBy('batchno_serah')
->map(function ($rows) {
return $rows->map(function ($row) {
return [
'tahun' => $row->tahun,
'bulan' => $row->bulan
];
})->values();
});
$finalData = $serahBaki->map(function ($item) use ($wtddraftData) {
$batchno = $item->batchno;
@@ -2427,29 +2426,27 @@ class AdminPageController extends Controller
$finalDataArray = $finalData->toArray();
//end new added
$batch_old = WTDDraft::on('mysql7')->select('kodcaw')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)
->groupBy('kodcaw')->get();
$batch_old_noruj = WTDDraft::on('mysql7')->where('batchno_serah',0)->where('kodcaw',$request->kodcaw)->pluck('norujukan');
$lelong_data = Lelong::on($cawangan['mysql'])->whereIn('norujukan',$batch_old_noruj)->get();
foreach($batch_old as $index=>$bo)
{
//array_push($latestbatch,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
array_push($finalDataArray,['recno' => 0,'norujukan' => 'lama','batchno' => 0,'baki' => $lelong_data->sum('baki'),'aktif' => 1]);
}
//$data = $this->paginate($latestbatch,8);
$data = $this->paginate($finalDataArray,8);
//dd($data);
return response()->json($data,200);
}
public function rekodWTDByBatchNo($batchno,Request $request){
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
@@ -2727,7 +2724,7 @@ class AdminPageController extends Controller
'prkod' => "01",
'teller' => "DM",
'bakipjm' => ($lel['bakipjm']) ? $lel['bakipjm'] : 0,
'bakiupah' => ($lel['bakiupah']) ? $lel['bakiupah'] : 0,
'bakiupah' => $lel['bakiupah'],
'cajlain' => '0.00',
'cajlelong' => $lel['cajlelong'],
'kodgl' => '',
@@ -2749,7 +2746,7 @@ class AdminPageController extends Controller
't_jual' => $lel['t_jual'],
'hargajual' => $lel['hargajual'],
'pinjaman' => $lel['pinjaman'],
'bakiupah' => ($lel['bakiupah']) ? $lel['bakiupah'] : 0,
'bakiupah' => $lel['bakiupah'],
'cajlelong' => $lel['cajlelong'],
'gst_cl' => $lel['gst_cl'],
'baki' => $lel['baki'],
@@ -2779,222 +2776,6 @@ class AdminPageController extends Controller
}
public function janaSimulasiWTD(Request $request)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
//listing sag belum tuntut cwgn
$sag_cwgn = collect(
Lelong::on($cawangan['mysql'])
->selectRaw('norujukan')
->whereYear('t_jual', $request->tahun)
->whereNull('trkhtuntut')
->where('baki', '>', 0)
->pluck('norujukan') // lebih bersih
);
//listing sag blocked
$sag_online = collect(
WTDDraft::on('mysql7')
->selectRaw('norujukan')
->where('kodcaw', '=', $request->kodcaw)
->pluck('norujukan')
);
//dd($sag_online);
//filter sag yg tk wujud dlm wtd_draft
$filtersag = $sag_cwgn->diff($sag_online);
//query baru
$tarikh_belum_tuntut = Lelong::on($cawangan['mysql'])
->selectRaw('
MONTH(t_jual) as bulan,
SUM(pinjaman) as pembiayaan,
ABS(SUM(baki)) as baki,
COUNT(DISTINCT norujukan) as jumlah_norujukan,
kodcaw
')
->whereIn('norujukan', $filtersag)
->groupBy('bulan', 'kodcaw')
->orderBy('bulan')
->get();
$tarikh_belum_tuntut = $tarikh_belum_tuntut->map(function ($item) {
$item->bulan = \Carbon\Carbon::create()->month($item->bulan)->format('F');
return $item;
});
return response()->json($tarikh_belum_tuntut);
}
public function RekodSimulasiWTD(Request $request)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
$rekod_simulasi = Lelong::on($cawangan['mysql'])
->join('gadai','lelong.norujukan','=','gadai.norujukan')
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp')
->whereMonth('lelong.t_jual', $request->month)
->whereYear('lelong.t_jual', $request->year)
->whereNull('lelong.trkhtuntut')
->where('lelong.baki', '>', 0)
->get();
return response()->json($rekod_simulasi);
}
public function prosesSimulasiWTD(Request $request)
{
$proses = $request->input;
// dd($proses, $cawangan);
$baki = 0;
$jumlahPembiayaan = 0;
$simulasi = WTDSimulasi::max('simulasi')+1;
foreach ($proses as $item) {
WTDSimulasi::create([
'bulan' => $item['bulan'],
'tahun' => $item['tahun'],
'kodcaw' => $item['kodcaw'],
'jumlah_sag' => $item['jumlah_sag'],
'pembiayaan'=> $item['pembiayaan'],
'baki'=> $item['baki'],
'simulasi' => $simulasi,
]);
$baki += $item['baki'];
$jumlahPembiayaan = $item['pembiayaan'];
}
return response()->json(['status' => 'success','simulasi' => $simulasi,'baki' => $baki,'pinjaman' => $jumlahPembiayaan]);
}
public function pengesahanSimulasiWTD(Request $request)
{
// Decode the JSON records from the request
$records = json_decode($request->records, true);
// Retrieve and clean 'kodcaw' from the request
$kodcaw = $request->kodcaw;
$kodcaw_clean = str_replace('"', '', $kodcaw);
// Get the database connection for the branch (cawangan)
$cawangan = Cawangan::where('kodcaw', $kodcaw_clean)->first();
// Check if 'Cawangan' exists
if (!$cawangan) {
return response()->json(['status' => 'error', 'message' => 'Invalid branch code (kodcaw).'], 404);
}
$cawangan_connection = $cawangan->mysql;
// Get the latest batch number and increment it
$latestBatch = SerahBaki::on($cawangan_connection)->max('batchno') + 1;
// Initialize total variables
$totalPembiayaan = 0;
$totalBaki = 0;
try {
// Iterate through the records and save them to the WTDDraft table
foreach ($records as $record) {
// Check if 'bulan' and 'tahun' exist in the record
if (!isset($record['bulan']) || !isset($record['tahun'])) {
return response()->json(['status' => 'error', 'message' => 'Missing bulan or tahun in records.'], 400);
}
$month = DateTime::createFromFormat('F', $record["bulan"])->format('n');
// Query norujukan records from the database
$query_norujukan = Lelong::on($cawangan_connection)
->join('gadai', 'lelong.norujukan', '=', 'gadai.norujukan')
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp, lelong.t_jual')
->whereMonth('lelong.t_jual', $month)
->whereYear('lelong.t_jual', $record["tahun"])
->whereNull('lelong.trkhtuntut')
->where('lelong.baki', '>', 0)
->get();
// Save each record to the WTDDraft table
foreach ($query_norujukan as $query) {
$wtddraft = new WTDDraft();
$wtddraft->nokp = $query['nokp'];
$wtddraft->kodcaw = $kodcaw_clean;
$wtddraft->norujukan = $query['norujukan'];
$wtddraft->t_jual = $query['t_jual'];
$wtddraft->t_gadai = $query['t_gadai'] ?? null; // Optional: ensure 't_gadai' exists
$wtddraft->t_lelong = $query['t_lelong'];
$wtddraft->batchno_serah = $latestBatch;
$wtddraft->save();
}
// Accumulate totals
$totalPembiayaan += $record['pembiayaan'] ?? 0;
$totalBaki += $record['baki'] ?? 0;
}
// Create a new record in the SerahBaki table
SerahBaki::on($cawangan_connection)->create([
'norujukan' => 'baru',
'batchno' => $latestBatch,
'hargajual' => 0.00,
'pinjaman' => $totalPembiayaan,
'upah' => 0.00,
'cajlel' => 0.00,
'gst_cl' => 0.00,
'gst_hj' => 0.00,
'baki' => $totalBaki,
'tarikh' => Carbon::now()->toDateString(),
't_jual' => Carbon::now()->toDateString(),
'nopelanggan' => '',
'aktif' => 0,
]);
// Return a success response with the new batch number
return response()->json(['status' => 'success', 'batchno' => $latestBatch], 200);
} catch (\Throwable $e) {
// Log the error and return a failure response
Log::error($e->getMessage());
Log::error($e->getLine());
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
}
}
public function simulasiToDraft(Request $request)
{
$bulan = $request->bulan;
if (!$bulan || count($bulan) === 0) {
return response()->json(['error' => 'Sila pilih sekurang-kurangnya satu bulan.'], 400);
}
$simulasi = WTDSimulasi::whereIn('bulan', $bulan)->get();
if ($simulasi->isEmpty()) {
return response()->json(['error' => 'Tiada data untuk bulan yang dipilih.'], 404);
}
// foreach ($simulasi as $data) {
// WTDDraft::create([
// 'nokp' => $data->nokp ?? null,
// 'kodcaw' => $data->kodcaw ?? null,
// 'norujukan' => $data->norujukan ?? null,
// 't_jual' => $data->t_jual ?? null,
// 't_gadai' => $data->t_gadai ?? null,
// 't_lelong' => $data->t_lelong ?? null,
// 'batchno_serah' => $data->simulasi, // Simpan sebagai rujukan
// ]);
// }
dd($bulan, $simulasi);
return response()->json(['message' => 'Data berjaya dipindahkan ke WTD Draft!']);
}
public function PenjanaanPC(Request $request){
$timeloni = Carbon::now();
@@ -3445,8 +3226,6 @@ class AdminPageController extends Controller
return response()->json($customers);
}
public function AkruKeuntunganSebenar(Request $request){
@@ -4045,13 +3824,13 @@ class AdminPageController extends Controller
$get_imbangduga = imbangdugabackup::on($cawangan['mysql'])->where('tarikh', $lastDayOfYear)->first();
$get_imbangduga = optional($get_imbangduga)->toArray() ?? [];
if(empty($get_imbangduga)){
$requestData = new Request([
'tarikh' => $request->tarikh,
'kodcaw' => $kodcaw,
]);
$exception_case = $this->AkruKeuntunganSebenar($requestData)->getData();
}
// if(empty($get_imbangduga)){
// $requestData = new Request([
// 'tarikh' => $request->tarikh,
// 'kodcaw' => $kodcaw,
// ]);
// $exception_case = $this->AkruKeuntunganSebenar($requestData);
// }
$backdate_keun_sebenar += isset($get_imbangduga['keun_sebenar']) ? $get_imbangduga['keun_sebenar'] : 0;
$backdate_keun_sebenar += (float) ($exception_case ?? 0);
@@ -4070,14 +3849,7 @@ class AdminPageController extends Controller
$total = ($utgrugilama + $lelong + $upahsimpantebus + $upahsimpanlelong + $upahsimpanansur + $gstcajlelong + $keuntungansebenar + $upahsimpankeuntungansebelumtawarruq + $available_akru + $total_keuntungan_sebenar + $akru_ujrah + $akru_1percent) + $parameter;
if($kodcaw == '011229')
$total -= 45390.37;
if($kodcaw == 'KB2')
$total -= 64.8;
$total += Penyelarasan::on('mysql7')
->where('kodcaw', $kodcaw)
->sum(DB::raw('rugilelong + bakilelong + `lain-lain`'));
$total -= 45390.37;
return response()->json($total,200);
}
@@ -4250,4 +4022,222 @@ class AdminPageController extends Controller
'result' => $status === 'completed' ? $result : null,
]);
}
//function wtd baru
public function janaSimulasiWTD(Request $request)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
//listing sag belum tuntut cwgn
$sag_cwgn = collect(
Lelong::on($cawangan['mysql'])
->selectRaw('norujukan')
->whereYear('t_jual', $request->tahun)
->whereNull('trkhtuntut')
->where('baki', '>', 0)
->pluck('norujukan') // lebih bersih
);
//listing sag blocked
$sag_online = collect(
WTDDraft::on('mysql7')
->selectRaw('norujukan')
->where('kodcaw', '=', $request->kodcaw)
->pluck('norujukan')
);
//dd($sag_online);
//filter sag yg tk wujud dlm wtd_draft
$filtersag = $sag_cwgn->diff($sag_online);
//query baru
$tarikh_belum_tuntut = Lelong::on($cawangan['mysql'])
->selectRaw('
MONTH(t_jual) as bulan,
SUM(pinjaman) as pembiayaan,
ABS(SUM(baki)) as baki,
COUNT(DISTINCT norujukan) as jumlah_norujukan,
kodcaw
')
->whereIn('norujukan', $filtersag)
->groupBy('bulan', 'kodcaw')
->orderBy('bulan')
->get();
$tarikh_belum_tuntut = $tarikh_belum_tuntut->map(function ($item) {
$item->bulan = \Carbon\Carbon::create()->month($item->bulan)->format('F');
return $item;
});
return response()->json($tarikh_belum_tuntut);
}
public function RekodSimulasiWTD(Request $request)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw', '=', $request->kodcaw)->first();
$rekod_simulasi = Lelong::on($cawangan['mysql'])
->join('gadai','lelong.norujukan','=','gadai.norujukan')
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp')
->whereMonth('lelong.t_jual', $request->month)
->whereYear('lelong.t_jual', $request->year)
->whereNull('lelong.trkhtuntut')
->where('lelong.baki', '>', 0)
->get();
return response()->json($rekod_simulasi);
}
public function prosesSimulasiWTD(Request $request)
{
$proses = $request->input;
// dd($proses, $cawangan);
$baki = 0;
$jumlahPembiayaan = 0;
$simulasi = WTDSimulasi::max('simulasi')+1;
foreach ($proses as $item) {
WTDSimulasi::create([
'bulan' => $item['bulan'],
'tahun' => $item['tahun'],
'kodcaw' => $item['kodcaw'],
'jumlah_sag' => $item['jumlah_sag'],
'pembiayaan'=> $item['pembiayaan'],
'baki'=> $item['baki'],
'simulasi' => $simulasi,
]);
$baki += $item['baki'];
$jumlahPembiayaan = $item['pembiayaan'];
}
return response()->json(['status' => 'success','simulasi' => $simulasi,'baki' => $baki,'pinjaman' => $jumlahPembiayaan]);
}
public function pengesahanSimulasiWTD(Request $request)
{
// Decode the JSON records from the request
$records = json_decode($request->records, true);
// Retrieve and clean 'kodcaw' from the request
$kodcaw = $request->kodcaw;
$kodcaw_clean = str_replace('"', '', $kodcaw);
// Get the database connection for the branch (cawangan)
$cawangan = Cawangan::where('kodcaw', $kodcaw_clean)->first();
// Check if 'Cawangan' exists
if (!$cawangan) {
return response()->json(['status' => 'error', 'message' => 'Invalid branch code (kodcaw).'], 404);
}
$cawangan_connection = $cawangan->mysql;
// Get the latest batch number and increment it
$latestBatch = SerahBaki::on($cawangan_connection)->max('batchno') + 1;
// Initialize total variables
$totalPembiayaan = 0;
$totalBaki = 0;
try {
// Iterate through the records and save them to the WTDDraft table
foreach ($records as $record) {
// Check if 'bulan' and 'tahun' exist in the record
if (!isset($record['bulan']) || !isset($record['tahun'])) {
return response()->json(['status' => 'error', 'message' => 'Missing bulan or tahun in records.'], 400);
}
$month = DateTime::createFromFormat('F', $record["bulan"])->format('n');
// Query norujukan records from the database
$query_norujukan = Lelong::on($cawangan_connection)
->join('gadai', 'lelong.norujukan', '=', 'gadai.norujukan')
->selectRaw('ABS(lelong.baki) as baki, lelong.t_lelong, lelong.pinjaman, lelong.norujukan, gadai.nokp, lelong.t_jual')
->whereMonth('lelong.t_jual', $month)
->whereYear('lelong.t_jual', $record["tahun"])
->whereNull('lelong.trkhtuntut')
->where('lelong.baki', '>', 0)
->get();
// Save each record to the WTDDraft table
foreach ($query_norujukan as $query) {
$wtddraft = new WTDDraft();
$wtddraft->nokp = $query['nokp'];
$wtddraft->kodcaw = $kodcaw_clean;
$wtddraft->norujukan = $query['norujukan'];
$wtddraft->t_jual = $query['t_jual'];
$wtddraft->t_gadai = $query['t_gadai'] ?? null; // Optional: ensure 't_gadai' exists
$wtddraft->t_lelong = $query['t_lelong'];
$wtddraft->batchno_serah = $latestBatch;
$wtddraft->save();
}
// Accumulate totals
$totalPembiayaan += $record['pembiayaan'] ?? 0;
$totalBaki += $record['baki'] ?? 0;
}
// Create a new record in the SerahBaki table
SerahBaki::on($cawangan_connection)->create([
'norujukan' => 'baru',
'batchno' => $latestBatch,
'hargajual' => 0.00,
'pinjaman' => $totalPembiayaan,
'upah' => 0.00,
'cajlel' => 0.00,
'gst_cl' => 0.00,
'gst_hj' => 0.00,
'baki' => $totalBaki,
'tarikh' => Carbon::now()->toDateString(),
't_jual' => Carbon::now()->toDateString(),
'nopelanggan' => '',
'aktif' => 0,
]);
// Return a success response with the new batch number
return response()->json(['status' => 'success', 'batchno' => $latestBatch], 200);
} catch (\Throwable $e) {
// Log the error and return a failure response
Log::error($e->getMessage());
Log::error($e->getLine());
return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
}
}
public function simulasiToDraft(Request $request)
{
$bulan = $request->bulan;
if (!$bulan || count($bulan) === 0) {
return response()->json(['error' => 'Sila pilih sekurang-kurangnya satu bulan.'], 400);
}
$simulasi = WTDSimulasi::whereIn('bulan', $bulan)->get();
if ($simulasi->isEmpty()) {
return response()->json(['error' => 'Tiada data untuk bulan yang dipilih.'], 404);
}
// foreach ($simulasi as $data) {
// WTDDraft::create([
// 'nokp' => $data->nokp ?? null,
// 'kodcaw' => $data->kodcaw ?? null,
// 'norujukan' => $data->norujukan ?? null,
// 't_jual' => $data->t_jual ?? null,
// 't_gadai' => $data->t_gadai ?? null,
// 't_lelong' => $data->t_lelong ?? null,
// 'batchno_serah' => $data->simulasi, // Simpan sebagai rujukan
// ]);
// }
//dd($bulan, $simulasi);
return response()->json(['message' => 'Data berjaya dipindahkan ke WTD Draft!']);
}
}
+109 -1
View File
@@ -15,6 +15,7 @@ use App\AuditCustomer;
use Illuminate\Http\Request;
use App\TuntutBaki;
use Illuminate\Support\Facades\Auth;
use App\Anggota;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
@@ -394,12 +395,66 @@ class CustomerController extends Controller
'nota_pekerjaan'=>$request->nota_pekerjaan,
// 'nota_arcc'=>$request->nota_arcc,
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2
'telefon2' => $request->telefon2,
'telefon2' => $request->telefon2,
));
return response()->json($customer_update, 200);
}
public function assignAnggota($noic, Request $request)
{
// Semak sama ada pelanggan wujud
$customer = Customer::on('mysql7')
->where('kpbaru', $noic)
->orWhere('kplama', $noic)
->first();
if (!$customer) {
return response()->json([
'success' => false,
'message' => 'Pelanggan tidak dijumpai.'
], 404);
}
// Kemaskini tag_anggota
$customer->tag_anggota = 1;
$customer->save();
return response()->json([
'success' => true,
'message' => 'Tag anggota berjaya dikemaskini.',
'data' => $customer
], 200);
}
}
public function assignAnggota($noic, Request $request)
{
// Semak sama ada pelanggan wujud
$customer = Customer::on('mysql7')
->where('kpbaru', $noic)
->orWhere('kplama', $noic)
->first();
if (!$customer) {
return response()->json([
'success' => false,
'message' => 'Pelanggan tidak dijumpai.'
], 404);
}
// Kemaskini tag_anggota
$customer->tag_anggota = 1;
$customer->save();
return response()->json([
'success' => true,
'message' => 'Tag anggota berjaya dikemaskini.',
'data' => $customer
], 200);
}
public function customerUpdateKaunter($nokp,$kodcaw, Request $request){
$current = Carbon::now();
@@ -826,6 +881,22 @@ class CustomerController extends Controller
return response()->json($blacklist);
}
public function anggotaKoperasi(Request $request){
$anggota = Anggota::where('noic',$request->noic)->first();
return response()->json($anggota);
}
public function anggotaKoperasi(Request $request){
$anggota = Anggota::where('noic',$request->noic)->first();
return response()->json($anggota);
}
public function showCustomerByEachCawangan($ic)
{
$cawangan_all = Cawangan::on('mysql7')->get();
@@ -1067,4 +1138,41 @@ public function AdminsearchCustomerBySAG(Request $request)
return response()->json($results);
}
public function updateTagPdpa(Request $request)
{
$tarikh_cetak_pdpa = Carbon::now()->toDateString();
$no_ic = $request->input('no_ic');
$customer = Customer::where('kplama', $no_ic)
->orWhere('kpbaru', $no_ic)
->first();
if (!$customer) {
return response()->json(['error' => 'Customer not found.'], 404);
}
$customer->tag_pdpa = $request->input('tag_pdpa');
$customer->tarikh_cetak_pdpa = $tarikh_cetak_pdpa;
$customer->save();
return response()->json(['message' => 'Customer PDPA updated successfully.'], 200);
}
// public function createNotaArcc($kodcaw, Request $request)
// {
// $current = Carbon::now();
// $customer = Customer::on('mysql7')->create([
// 'kodcaw' => $kodcaw,
// 'tarikhdaftar' => $current->toDateString(),
// 'nota_arcc' => $request->nota_arcc,
// 'teller' => $request->teller,
// 'aktif' => 'A'
// ]);
// return response()->json($customer, 201);
// }
}
+201 -1
View File
@@ -6,6 +6,8 @@ use App\Audit;
use App\Mohon;
use App\Cawangan;
use App\Mohonid;
use App\MohonAnggota;
use App\Customer;
use Carbon\Carbon;
@@ -229,6 +231,98 @@ class KelulusanController extends Controller
return response()->json($kelulusan,201);
}
public function updateAnggota($kodcaw, Request $request)
{
$harini = Carbon::now();
// Dapatkan sambungan database cawangan
$cawangan = Cawangan::on('mysql7')
->where('kodcaw', '=', $kodcaw)
->first();
if (!$cawangan) {
return response()->json(['success' => false, 'message' => 'Kod cawangan tidak sah'], 404);
}
$nokp = $request->nokp;
$komen = $request->komenkelulusan;
$namaoperasi = $request->namaoperasi;
$status = $request->sahkan; // 1 = Lulus, 2 = Batal
// Debug log masuk
Log::info('UpdateKelulusanAnggota triggered', [
'kodcaw' => $kodcaw,
'nokp' => $nokp,
'status' => $status,
'komen' => $komen,
'namaoperasi' => $namaoperasi
]);
// Kalau LULUS
if ($status == 1) {
$kelulusan = MohonAnggota::on($cawangan['mysql'])
->where('nokp', '=', $nokp)
->update([
'status' => 'DILULUSKAN',
'komen' => $komen,
'peloperasi' => $namaoperasi,
'datetime_pelulus' => $harini,
'updated_at' => $harini,
]);
// Update CUSTOMER di pusat (mysql7)
Customer::on('mysql7')
->where('kpbaru', '=', $nokp)
->update([
'tag_anggota' => 1,
]);
}
// Kalau BATAL / TOLAK
else if ($status == 2) {
$kelulusan = MohonAnggota::on($cawangan['mysql'])
->where('nokp', '=', $nokp)
->update([
'status' => 'DITOLAK',
'komen' => $komen,
'peloperasi' => $namaoperasi,
'datetime_pelulus' => $harini,
'updated_at' => $harini,
]);
} else {
return response()->json(['success' => false, 'message' => 'Status tidak sah'], 400);
}
// 🧾 Simpan audit log
$audit = new Audit();
$audit->users = $namaoperasi;
$audit->actions = ($status == 1)
? "Kelulusan anggota oleh operasi (tag_anggota=1)"
: "Pembatalan / tolak anggota oleh operasi";
$audit->new_data = json_encode([
'nokp' => $nokp,
'status' => $status,
'komen' => $komen,
]);
$audit->kodcaw = $kodcaw;
$audit->created_at = $harini;
$audit->updated_at = $harini;
$audit->save();
Log::info('Kelulusan anggota dikemas kini', [
'nokp' => $nokp,
'status' => $status,
'updated_tag_anggota' => ($status == 1) ? 1 : 0
]);
return response()->json([
'success' => true,
'status' => ($status == 1) ? 'DILULUSKAN' : 'DITOLAK',
'updated_rows' => $kelulusan
], 200);
}
public function updatekomen($kodcaw,$norujukan,Request $request)
{
$harini = Carbon::now();
@@ -314,6 +408,64 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
return response()->json($kelulusan);
}
public function createKelulusanAnggota(Request $request, $kodcaw)
{
try {
$harini = Carbon::now();
// ✅ Dapatkan maklumat cawangan (database connection)
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
if (!$cawangan) {
return response()->json(['success' => false, 'message' => 'Cawangan tidak dijumpai'], 404);
}
// ✅ Simpan ke dalam model MohonAnggota
$kelulusan = new MohonAnggota();
$kelulusan->setConnection($cawangan['mysql']); // guna connection cawangan dinamik
$kelulusan->tarikh = $harini->toDateString();
$kelulusan->nokp = $request->nokp;
$kelulusan->nama = $request->nama ?? null;
$kelulusan->status = 'MENUNGGU OPERASI';
$kelulusan->komen = $request->komen;
$kelulusan->teller = $request->teller;
$kelulusan->peloperasi = null;
$kelulusan->created_at = $harini;
$kelulusan->updated_at = $harini;
$kelulusan->save();
// ✅ Simpan audit trail
$audit = new Audit();
$audit->users = $request->teller;
$audit->actions = 'Mohon kelulusan anggota';
$audit->new_data = json_encode(['mohon_anggota_id' => $kelulusan->id]);
$audit->kodcaw = $kodcaw;
$audit->created_at = $harini;
$audit->updated_at = $harini;
$audit->save();
// ✅ Return JSON response ke frontend
return response()->json([
'success' => true,
'message' => 'Permohonan kelulusan anggota berjaya dihantar kepada operasi.',
'data' => [
'id' => $kelulusan->id,
'nokp' => $kelulusan->nokp,
'status' => $kelulusan->status,
'komen' => $kelulusan->komen,
'teller' => $kelulusan->teller,
],
], 201);
} catch (\Throwable $th) {
Log::error('❌ createKelulusanAnggota error: ' . $th->getMessage());
return response()->json([
'success' => false,
'message' => $th->getMessage(),
], 500);
}
}
//KEPOHONAN EDIT DAN HAPUS
public function kepohonancreate(REQUEST $request,$kodcaw,$norujukan)
@@ -526,7 +678,7 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
return response()->json($kelulusan, 200);
}
public function getApprovalLaporan(Request $request){
public function getApprovalLaporan(Request $request){
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
$kelulusan = Mohonid::on($cawangan['mysql'])
->selectRaw('recno, benar, tarikh, onlineid, mohon, norujukan, id, katalaluan, benar, operasi, pinjaman, ansuran, nilaimarhun, berat, margin, teller ,masa, timestamp_approved_by_pc, timestamp_approved_by_operasi')
@@ -540,6 +692,54 @@ public function create(REQUEST $request,$kodcaw,$norujukan,$roles)
return response()->json($kelulusan, 200);
}
public function listKelulusanAnggota(Request $request)
{
$harini = Carbon::now();
Log::info($request->all());
$cawangan = Cawangan::on('mysql7')->get();
$array_kelulusan = [];
foreach ($cawangan as $caw) {
$kelulusan = MohonAnggota::on($caw['mysql'])
->whereDate('tarikh', $harini->toDateString())
->where(function ($query) {
$query->where('peloperasi', '=', 0)
->orWhereNull('peloperasi');
})
->orderBy('id', 'desc')
->get();
if ($kelulusan->isNotEmpty()) {
// Kumpul semua nokp daripada senarai kelulusan
$nokpList = $kelulusan->pluck('nokp')->unique()->toArray();
// Ambil semua nama daripada table customer (main DB)
$customers = Customer::whereIn('kpbaru', $nokpList)
->pluck('nama', 'kpbaru')
->toArray();
// Masukkan nama ke dalam setiap item kelulusan
$kelulusan = $kelulusan->map(function ($item) use ($customers) {
$item->nama = $customers[$item->nokp] ?? '-';
return $item;
});
// Tambah ke array utama
$array_kelulusan[] = [
"kelulusanall" => $kelulusan,
"cawangan" => $caw['details_caw'],
"cawangankod" => $caw['kodcaw']
];
}
}
return response()->json($array_kelulusan, 200);
}
}
+37 -23
View File
@@ -804,7 +804,8 @@ $date = new Carbon($request->tarikh);
$tebus = Tebus::on($cawangan['mysql'])
->join('gadai as gad','gad.norujukan','=','tebus.norujukan')
->where([['t_tebus','>=',$request->mula],['t_tebus','<=',$request->akhir],['tebus.jenistebus','=','T']]);
->where([['t_tebus','>=',$request->mula],['t_tebus','<=',$request->akhir]]);
->where([['t_tebus','>=',$request->mula],['t_tebus','<=',$request->akhir]]);
$ansuran = Transaction::on('mysql7')->whereDate('created_at','>=',$request->mula)->whereDate('created_at','<=',$request->akhir)->where([['trans_type','=','A'],['kodcaw','=',$request->kodcaw]]);
$bayaranonlinequery = Transaction::on('mysql7')->whereDate('created_at','>=',$request->mula)->whereDate('created_at','<=',$request->akhir)->where('teller','=','Online')->where('kodcaw',$request->kodcaw);
@@ -834,19 +835,28 @@ $date = new Carbon($request->tarikh);
->whereDate('trans.created_at','<=',$request->akhir)
->where('trans.trans_type','=','A')
->where('trans.kodcaw','=',$request->kodcaw)
// ->pluck('trans.norujukan');
// ->pluck('trans.norujukan');
// ->groupBy('trans.id')
->sum('bayaran_keuntungan');
// dd($total_keuntunganansuran);
// dd($total_keuntunganansuran);
// $total_ansuran = number_format($total_ansuran,2);
$total_keuntungan = floatval($total_upah) + floatval($total_keuntunganansuran) + floatval($total_keuntungantebus);
//b
$bilangan_gadai = $gadai->count();
$bilangan_tebus = $tebus->count();
// $bilangan_ansuran = $ansuran->count();
$bilangan_customer_baru = Customer::on($cawangan['mysql'])->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
//$bilangan_customer_baru = Customer::on('mysql7')->where([['tarikhdaftar','=',$request->tarikh],['kodcaw',$request->kodcaw]])->count()
//$bilangan_customer_baru = Customer::on('mysql7')->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
$bilangan_customer_baru = Customer::on('mysql7')->whereBetween('tarikhdaftar', [$request->mula, $request->akhir])->where('kodcaw', $request->kodcaw)->count();
//$bilangan_customer_baru = Customer::on('mysql7')->where([['tarikhdaftar','=',$request->tarikh],['kodcaw',$request->kodcaw]])->count()
//$bilangan_customer_baru = Customer::on('mysql7')->where([['tarikhdaftar','>=',$request->mula],['tarikhdaftar','<=',$request->akhir]])->count();
$bilangan_customer_baru = Customer::on('mysql7')->whereBetween('tarikhdaftar', [$request->mula, $request->akhir])->where('kodcaw', $request->kodcaw)->count();
//f
$data_lelong = Lelong::on($cawangan['mysql'])->where([['t_jual','>=',$request->mula],['t_jual','<=',$request->akhir]])->get();
@@ -969,33 +979,36 @@ $date = new Carbon($request->tarikh);
->whereDate('trans.created_at','<=',$request->akhir)
->where('trans.teller','<>','Online')
->where('trans.trans_type','=','A')
->where('trans.kodcaw',$request->kodcaw)
->pluck('transaksi_keuntungan.norujukan');
->where('trans.kodcaw',$request->kodcaw);
// ->pluck('transaksi_keuntungan.norujukan');
->where('trans.kodcaw',$request->kodcaw);
// ->pluck('transaksi_keuntungan.norujukan');
$gadaiDataKaunter = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$total_keuntunganansuran_data_kaunter)->whereNotNull('hargajualan')->pluck('norujukan');
// $gadaiDataKaunter = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$total_keuntunganansuran_data_kaunter)->whereNotNull('hargajualan')->pluck('norujukan');
// $gadaiDataKaunter = Gadai::on($cawangan['mysql'])->whereIn('norujukan',$total_keuntunganansuran_data_kaunter)->whereNotNull('hargajualan')->pluck('norujukan');
// $keuntunganansuran_kaunter_query = TransaksiKeuntungan::on('mysql7')
// ->whereIn('norujukan',$gadaiDataKaunter)
// ->where('kodcaw',$request->kodcaw)
// ->whereDate('tarikh_bayaran','>=',$request->mula)
// ->whereDate('tarikh_bayaran','<=',$request->akhir);
// //new update
$keuntunganansuran_kaunter_query = TransaksiKeuntungan::on('mysql7')
->leftJoin('transaction as trans', function($join)
{
$join->on('transaksi_keuntungan.norujukan', '=', 'trans.norujukan');
$join->on('transaksi_keuntungan.tarikh_bayaran', '=', 'trans.created_at');
})
->whereDate('trans.created_at','>=',$request->mula)
->whereDate('trans.created_at','<=',$request->akhir)
->where('trans.teller','<>','Online')
->where('trans.trans_type','=','A')
->where('trans.kodcaw',$request->kodcaw)
->pluck('transaksi_keuntungan.norujukan');
//dd($keuntunganansuran_kaunter_query->get()->toArray());
// $keuntunganansuran_kaunter_query = TransaksiKeuntungan::on('mysql7')
// ->whereIn('norujukan',$gadaiDataKaunter)
// ->where('kodcaw',$request->kodcaw)
// ->whereDate('tarikh_bayaran','>=',$request->mula)
// ->whereDate('tarikh_bayaran','<=',$request->akhir);
//dd($keuntunganansuran_kaunter_query->get()->toArray());
$total_keuntunganansuran_kaunter = $keuntunganansuran_kaunter_query->sum('bayaran_keuntungan');
$bil_keuntunganansuran_kaunter = $keuntunganansuran_kaunter_query->count();
$total_keuntunganansuran_kaunter = $total_keuntunganansuran_data_kaunter->sum('bayaran_keuntungan');
//dd($total_keuntunganansuran_kaunter);
$bil_keuntunganansuran_kaunter = $total_keuntunganansuran_data_kaunter->count();
$total_keuntunganansuran_kaunter = $total_keuntunganansuran_data_kaunter->sum('bayaran_keuntungan');
//dd($total_keuntunganansuran_kaunter);
$bil_keuntunganansuran_kaunter = $total_keuntunganansuran_data_kaunter->count();
$total_keuntunganansuran_data_online = TransaksiKeuntungan::on('mysql7')
->leftJoin('transaction as trans', function($join)
{
@@ -1257,6 +1270,7 @@ $date = new Carbon($request->tarikh);
'tarikh' => $tarikh,
'masa' => $masa,
'users' => isset($at['users']) && $at['users'] !== '' ? $at['users'] : '-',
'users' => isset($at['users']) && $at['users'] !== '' ? $at['users'] : '-',
'pelulus' => isset($atnewdata['namapelulus']) ? $atnewdata['namapelulus'] : '-',
'actions' => $at['actions'],
'norujukan' => $at['norujukan'],
+1 -1
View File
@@ -607,7 +607,7 @@ class LelongController extends Controller
if(env('APP_ENV') != 'production'){
$link = 'http://niklah.arrahn.com.my/api/portalApi';
}else{
$link = 'http://adminbid.arrahn/api/portalApi';
$link = 'https://adminbid-kopkb.erahn.com.my/api/portalApi';
}
$lelong = Http::withOptions(['verify' => true])->get($link,[
+8 -2
View File
@@ -203,7 +203,10 @@ class MarhunController extends Controller
$marhun = Marhun::on($cawangan['mysql'])
->select('marhun.norujukan','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai','marhun.tag_permata', 'marhun.berat_batu_permata')
->rightJoin('gadai', 'gadai.norujukan', '=', 'marhun.norujukan')
->rightJoin(config('tennant_database.master_db') . '.customer as customer', 'customer.kpbaru','=','gadai.nokp')
->rightJoin('master_erahn.customer as customer', function($join) {
$join->on('customer.kpbaru', '=', 'gadai.nokp')
->orOn('customer.kplama', '=', 'gadai.nokp');
})
->where('marhun.t_gadai','=',$tarikh)
->orderBy('marhun.t_gadai')
->get();
@@ -221,7 +224,10 @@ class MarhunController extends Controller
$marhun = Marhun::on($cawangan['mysql'])
->select('marhun.norujukan','gadai.sttebus','gadai.pinjaman','gadai.nokp','customer.nama','marhun.marhun','marhun.nota','marhun.berat','marhun.karat','marhun.harga','marhun.n_marhun','marhun.t_gadai')
->rightJoin('gadai', 'gadai.norujukan', '=', 'marhun.norujukan')
->rightJoin(config('tennant_database.master_db') . '.customer as customer', 'customer.kpbaru','=','gadai.nokp')
->rightJoin('master_erahn.customer as customer', function($join) {
$join->on('customer.kpbaru', '=', 'gadai.nokp')
->orOn('customer.kplama', '=', 'gadai.nokp');
})
->where('marhun.t_gadai','<=',$tarikh)
->whereYear('marhun.t_gadai','=',$current->year)
->where('gadai.sttebus','=','')