Compare commits

...

28 Commits

Author SHA1 Message Date
nurafrinaalimi16 162f246acc function wtd baru 2026-08-03 12:43:55 +08:00
nurafrinaalimi16 95997841cf Merge remote-tracking branch 'origin/rebate-anggota' into rebate-anggota 2026-06-14 15:58:31 +08:00
nurafrinaalimi16 9ff4393313 include kplama on report marhun 2026-06-14 15:38:38 +08:00
nurafrinaalimi16 5bc5d286b4 fix figure on laporan terkumpul 2026-06-14 15:37:58 +08:00
nurafrinaalimi16 5826f92661 pdpa for koperasi 2026-06-14 15:37:25 +08:00
nurafrinaalimi16 6961697298 include lahad datu on report stok audit 2026-06-14 15:36:33 +08:00
nurafrinaalimi16 482fbbd17e fix bilangan pelanggan baru on report terkumpul 2026-06-14 15:36:33 +08:00
nurafrinaalimi16 cd83999045 disable logs kadar anggota 2026-06-14 15:36:33 +08:00
nurafrinaalimi16 e8da816f35 put excpetion if kadar upah = 0 2026-06-14 15:36:33 +08:00
nurafrinaalimi16 39a2f9a5ef fix kadar upah return 0 2026-06-14 15:36:33 +08:00
nurafrinaalimi16 2fa36eabf7 include kplama on report marhun 2026-06-14 15:06:24 +08:00
nurafrinaalimi16 237a5aa44b fix figure on laporan terkumpul 2026-06-14 15:05:02 +08:00
nurafrinaalimi16 e1878e31e4 pdpa for koperasi 2026-06-14 15:02:45 +08:00
nurafrinaalimi16 043c1fa83b include lahad datu on report stok audit 2025-12-23 10:21:02 +08:00
nurafrinaalimi16 b8cf2a172d fix bilangan pelanggan baru on report terkumpul 2025-12-18 10:54:32 +08:00
nurafrinaalimi16 2451969c88 disable logs kadar anggota 2025-12-14 10:37:29 +08:00
nurafrinaalimi16 bc95a60009 put excpetion if kadar upah = 0 2025-11-18 00:30:36 +08:00
nurafrinaalimi16 cb0b80428b fix kadar upah return 0 2025-11-13 23:33:11 +08:00
nurafrinaalimi16 da7883919e add column name on operasi approval 2025-11-11 22:23:37 +08:00
nurafrinaalimi16 f998d6e7dc fix error url lelong 2025-11-11 00:08:26 +08:00
nurafrinaalimi16 0aaf81f1cb fix url lelong 2025-11-11 00:05:33 +08:00
nurafrinaalimi16 42c2c80726 comment command import csv 2025-11-10 23:02:30 +08:00
nurafrinaalimi16 600cd753f0 import csv anggota koperasi 2025-11-10 19:14:29 +08:00
nurafrinaalimi16 6898a78506 route for kadar anggota 2025-11-10 19:13:29 +08:00
nurafrinaalimi16 2ebeae54ea database migration for kadar anggota koperasi 2025-11-10 19:12:26 +08:00
nurafrinaalimi16 dde4d910bb calculation for kadar anggota koperasi 2025-11-10 19:11:13 +08:00
nurafrinaalimi16 4f5edb69fb update all controllers for kadar anggota koperasi 2025-11-10 18:55:17 +08:00
nurafrinaalimi16 1075d7d585 models for kadar anggota koperasi 2025-11-10 18:51:01 +08:00
10 changed files with 402 additions and 389 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!']);
}
}
@@ -396,6 +396,7 @@ class CustomerController extends Controller
// 'nota_arcc'=>$request->nota_arcc,
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2,
'telefon2' => $request->telefon2,
));
return response()->json($customer_update, 200);
@@ -420,6 +421,33 @@ class CustomerController extends Controller
$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.',
@@ -861,6 +889,14 @@ class CustomerController extends Controller
}
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();
@@ -1102,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);
// }
}
+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'],
+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','=','')
+4 -35
View File
@@ -3,7 +3,6 @@
namespace App\Services;
use App\KadarUpah;
use App\Customer;
class OnePercentServices
{
@@ -80,43 +79,13 @@ class OnePercentServices
return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar];
}
public function getKadarUjrah(float $nilaimarhun = 0.0, $groupid, $nokp = null): float
{
//Semak status pelanggan dalam table customer
if ($nokp) {
$customer = Customer::on('mysql7')
->select('tag_anggota')
->where(function($q) use ($nokp) {
$q->where('kpbaru', $nokp)
->orWhere('kplama', $nokp);
})
->first();
public function getKadarUjrah(float $nilaimarhun = 0.0, $groupid) : Float{
// Jika anggota koperasi → kadar tetap
if ($customer && (int)$customer->tag_anggota === 1) {
return 0.16; // kadar ujrah tetap untuk anggota
}
$kadarujrah = KadarUpah::on('mysql7')->select('kadarujrah')->where([['min','<=',$nilaimarhun],['max','>=',$nilaimarhun]])->where('group_id',1)->get()->toArray();
return isset($kadarujrah[0]) ? $kadarujrah[0]['kadarujrah'] : 0;
}
//Jika bukan anggota → ambil dari jadual kadar_upah
$kadar = KadarUpah::on('mysql7')
->select('kadarujrah')
->where([
['min', '<=', $nilaimarhun],
['max', '>=', $nilaimarhun],
])
->where('group_id', $groupid)
->first();
//Jika jumpa kadar dalam jadual
if ($kadar && isset($kadar->kadarujrah)) {
return (float) $kadar->kadarujrah;
}
//Default fallback
return 0.0;
}
public function getRoundedMethod(float $number = 0.0) : Float{
$number_string = number_format(floor($number * 100)/100,2);
+5 -5
View File
@@ -65,11 +65,11 @@ class OnePercent extends MasterServices
public function getKadarUjrah(HttpRequest $request)
{
Log::info('[DEBUG-CONTROLLER] Data request', [
'nokp' => $request->nokp,
'kodcaw' => $request->kodcaw,
'nilaimarhun' => $request->nilaimarhun
]);
// Log::info('[DEBUG-CONTROLLER] Data request', [
// 'nokp' => $request->nokp,
// 'kodcaw' => $request->kodcaw,
// 'nilaimarhun' => $request->nilaimarhun
// ]);
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $request->kodcaw)->first();
$onePercentServices = new Calculation();
+5 -54
View File
@@ -3,9 +3,6 @@
namespace App\Support\v2;
use App\KadarUpah;
use App\Customer;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
class Calculation
@@ -61,6 +58,7 @@ class Calculation
public function kiraanKeuntunganRebet(float $pembiayaan = 0.0,float $nilaimarhun = 0.0,float $kadarujrah = 0.0,float $margin = 0.0){
$this->one_percent = $this->getKadarUpah($nilaimarhun);
$onepercent = $this->kiraanOnePercent($pembiayaan);
$ujrah_sebenar = $this->kiraanUjrahSebenar($nilaimarhun,$kadarujrah,$margin);
@@ -85,60 +83,13 @@ class Calculation
return ['keuntungan' => $keuntungan,'onepercent' => $onepercent, 'ujrah' => $ujrah_sebenar];
}
public function getKadarUjrah(float $nilaimarhun = 0.0, $groupid, $nokp = null): float
{
// 1️⃣ Semak status pelanggan dalam table customer
if ($nokp) {
$customer = Customer::on('mysql7')
->select('tag_anggota')
->where(function($q) use ($nokp) {
$q->where('kpbaru', $nokp)
->orWhere('kplama', $nokp);
})
->first();
public function getKadarUjrah(float $nilaimarhun = 0.0, $groupid) : Float{
// 2️⃣ Jika anggota koperasi → kadar tetap
if ($customer && (int)$customer->tag_anggota === 1) {
Log::info('[DEBUG-UJRAH] Anggota koperasi', [
'nokp' => $nokp,
'kadarujrah' => 0.16,
'groupid' => $groupid,
'nilaimarhun' => $nilaimarhun,
]);
return 0.16;
}
$kadarujrah = KadarUpah::on('mysql7')->select('kadarujrah')->where([['min','<=',$nilaimarhun],['max','>=',$nilaimarhun]])->where('group_id',$groupid)->get()->toArray();
return isset($kadarujrah[0]) ? $kadarujrah[0]['kadarujrah'] : 0;
}
// 3️⃣ Jika bukan anggota → ambil dari jadual kadar_upah
$kadar = KadarUpah::on('mysql7')
->select('kadarujrah')
->where([
['min', '<=', $nilaimarhun],
['max', '>=', $nilaimarhun],
])
->where('group_id', $groupid)
->first();
if ($kadar && isset($kadar->kadarujrah)) {
Log::info('[DEBUG-UJRAH] Bukan anggota - dari jadual kadar_upah', [
'nokp' => $nokp,
'kadarujrah' => (float)$kadar->kadarujrah,
'groupid' => $groupid,
'nilaimarhun' => $nilaimarhun,
]);
return (float) $kadar->kadarujrah;
}
// 4️⃣ Default fallback
Log::info('[DEBUG-UJRAH] Tiada kadar ditemui', [
'nokp' => $nokp,
'groupid' => $groupid,
'nilaimarhun' => $nilaimarhun,
]);
return 0.0;
}
public function getKadarUpah(float $nilaimarhun = 0.0){
$kadarupah = KadarUpah::on('mysql7')->where([['min','<=',$nilaimarhun],['max','>=',$nilaimarhun]])->where('group_id',1)->first();
+14 -3
View File
@@ -59,7 +59,7 @@ class GadaiV2
}
private function getKadarUpahAnggota($nokp,$total_nilai_marhun = 0,$groupid = 2) : Float{
Log::info('DEBUG NOKP:' . $nokp);
//Log::info('DEBUG NOKP:' . $nokp);
if($nokp){
$customer = Customer::on('mysql7')
->select('tag_anggota')
@@ -108,8 +108,19 @@ class GadaiV2
$total_nilai_marhun = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('n_marhun');
$total_berat = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->sum('berat');
//query kadar upah baru
$kadar_raw = $this->getKadarUpahAnggota($request->nokp,$total_nilai_marhun,$cawangan['group_id']);
$kadar_raw = $this->getKadarUpahAnggota($request->nokp, $total_nilai_marhun, $cawangan['group_id']);
if (empty($kadar_raw) || $kadar_raw == 0) {
Log::error('[BLOCKED] Kadar upah kosong / 0', [
'nokp' => $request->nokp,
'total_nilai_marhun' => $total_nilai_marhun,
'group_id' => $cawangan['group_id'],
]);
throw new \Exception("Kadar upah kosong / 0, transaksi dibatalkan!");
}
// query kadar upah lama
// $kadar_raw = KadarUpah::where('min','<=',$total_nilai_marhun)->where('max','>=',$total_nilai_marhun)->first();
+1 -3
View File
@@ -1,7 +1,5 @@
<?php
return [
'excluded_cawangan' => [
'lahad datu',
]
'excluded_cawangan' => []
];
+1
View File
@@ -62,6 +62,7 @@ $router->group(['prefix'=>'api'], function () use ($router){
$router->get('customer/anggota',['uses'=>'CustomerController@anggotaKoperasi']);
$router->get('customer/eachcawangan/{ic}',['uses'=>'CustomerController@showCustomerByEachCawangan']);
$router->put('customers/{noic}/assign-anggota', ['uses' => 'CustomerController@assignAnggota']);
$router->post('/customers/update-tag-pdpa', ['uses' => 'CustomerController@updateTagPdpa']);
//arcc
$router->get('customer/searchbyname',['uses'=>'CustomerController@searchByName']);