function barangkes di adminv2

This commit is contained in:
Ain Izazi
2025-10-05 11:43:15 +08:00
parent 4200b6c305
commit 233b95b2d9
4 changed files with 155 additions and 21 deletions
+64 -16
View File
@@ -14,6 +14,7 @@ use App\Blacklist;
use App\AuditCustomer;
use Illuminate\Http\Request;
use App\TuntutBaki;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
@@ -904,6 +905,69 @@ class CustomerController extends Controller
return response()->json($customer);
}
public function AdminsearchCustomerBySAG(Request $request)
{
// Ambil kodcaw dari user login
$kodcaw = $request->kodcaw;
// $norujukan = $request->input('norujukan');
// Cari connection untuk cawangan
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
if (!$cawangan) {
return response()->json([], 404);
}
$gadai = optional(Gadai::on($cawangan['mysql'])->where('norujukan',$request->norujukan)->first())->toArray() ?? [];
if(!empty($gadai)){
$customer = optional(Customer::on('mysql7')->where(function ($query) use ($gadai) {
$query->where('kpbaru',$gadai['nokp'])
->orWhere('kplama',$gadai['nokp']);
})->first())->toArray() ?? [];
}else{
return response()->json(['success' => false,'message' => 'norujukan tidak dijumpainya'], 404);
}
// cara fifi ajar
$result = [[
'id' => $customer['id'],
'kodcaw' => $gadai['kodcaw'],
'norujukan' => $gadai['norujukan'],
'teller' => $gadai['teller'],
'nota' => $customer['nota'],
'pinjaman' => $gadai['pinjaman'],
'nilaimarhun' => $gadai['nilaimarhun'],
'jbg' => $gadai['jbg'],
'tunggakan' => $gadai['tunggakan'],
'tunggakanonepercent' => $gadai['tunggakanonepercent'],
'tunggakanujrah' => $gadai['tunggakanujrah'],
'nama' => $customer['nama'],
'kplama' => $customer['kplama'],
'kpbaru' => $customer['kpbaru'],
]];
// saya buat sendiri
// Join customer + gadai ikut nokp
// $result = DB::connection($cawangan['mysql'])
// ->table('gadai')
// ->join('online_arrahn.customer as c', function($join) {
// $join->on('gadai.nokp', '=', 'c.kpbaru')
// ->orOn('gadai.nokp', '=', 'c.kplama');
// })
// ->where('norujukan', $request->norujukan)
// ->select(
// 'id',
// 'gadai.kodcaw','gadai.norujukan','gadai.teller',
// 'c.nota','gadai.pinjaman','gadai.nilaimarhun','gadai.jbg',
// 'gadai.tunggakan','gadai.tunggakanonepercent','gadai.tunggakanujrah',
// 'c.nama','c.kpbaru','c.kplama'
// )
// ->take(5)
// ->get();
return response()->json($result);
}
public function changepassword(Request $request, $kodcaw, $id) {
$current = Carbon::now();
@@ -1003,20 +1067,4 @@ class CustomerController extends Controller
return response()->json($results);
}
// 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);
// }
}