update untuk paparan detail keuntungan pada arcc
This commit is contained in:
@@ -666,11 +666,45 @@ class TebusController extends Controller
|
||||
}
|
||||
|
||||
public function listhistorypenebusan($kodcaw,Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
|
||||
|
||||
$listtebus = Tebus::on($cawangan['mysql'])
|
||||
->where('norujukan','=',$request->norujukan)
|
||||
->get();
|
||||
->where('norujukan', $request->norujukan)
|
||||
->get();
|
||||
|
||||
foreach ($listtebus as $tebus) {
|
||||
// Cari transaction padan berdasarkan norujukan dan trans_type = 'A'
|
||||
$transaction = \DB::connection('mysql7')
|
||||
->table('transaction')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereIn('trans_type', ['T', 'AT'])
|
||||
->first();
|
||||
|
||||
// Jika wujud, cari transaksi_keuntungan yang padan ikut tarikh
|
||||
if ($transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->where('norujukan', $tebus->norujukan)
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->first();
|
||||
|
||||
if ($transaction->trans_type == 'T') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->keuntungan_rebet ?? 0, 2);
|
||||
} elseif ($transaction->trans_type == 'AT') {
|
||||
$tebus->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
}
|
||||
|
||||
$tebus->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
$tebus->duit_masuk = number_format($transaction->duit_masuk ?? 0, 2);
|
||||
$tebus->trans_type = $transaction->trans_type ?? null;
|
||||
} else {
|
||||
$tebus->bayaran_keuntungan = null;
|
||||
$tebus->bayaran_pembiayaan = null;
|
||||
$tebus->duit_masuk = null;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($listtebus);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,24 @@ class TransactionController extends Controller
|
||||
|
||||
public function getTransactionByRujukan($norujukan){
|
||||
|
||||
$transaction = Transaction::on('mysql7')->where([['norujukan','=',$norujukan],['trans_type','=','A']])->get();
|
||||
$transactions = Transaction::on('mysql7')
|
||||
->where('norujukan', $norujukan)
|
||||
->where('trans_type', 'A')
|
||||
->get();
|
||||
|
||||
return response()->json($transaction);
|
||||
foreach ($transactions as $transaction) {
|
||||
$createdDate = Carbon::parse($transaction->created_at)->toDateString();
|
||||
|
||||
$keuntungan = \DB::connection('mysql7')
|
||||
->table('transaksi_keuntungan')
|
||||
->whereDate('tarikh_bayaran', $createdDate)
|
||||
->where('norujukan', $transaction->norujukan)
|
||||
->first(); // ambil seluruh rekod
|
||||
|
||||
$transaction->bayaran_keuntungan = number_format($keuntungan->bayaran_keuntungan ?? 0, 2);
|
||||
$transaction->bayaran_pembiayaan = number_format($keuntungan->bayaran_pembiayaan ?? 0, 2);
|
||||
}
|
||||
return response()->json($transactions);
|
||||
}
|
||||
|
||||
public function getTransactionByid($id){
|
||||
|
||||
Reference in New Issue
Block a user