fix report gadaian v2 not sync with v3

This commit is contained in:
Ain Izazi
2026-02-02 10:44:02 +08:00
parent 6ba62cc7f8
commit 96d70bf2a9
2 changed files with 232 additions and 32 deletions
+67 -32
View File
@@ -29,6 +29,7 @@ use App\KomuditiTransaksi;
use App\Advansur;
use App\HistoryEmasSandaran;
use App\InOutMar;
use App\Services\Miscellaneous\StatistikService;
use Illuminate\Http\Request;
@@ -587,44 +588,78 @@ class GadaiController extends Controller
public function getLaporanGadaiRangeDate($kodcaw,Request $request){
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$mula = $request->mula;
$akhir = $request->akhir;
$gadai_data = Gadai::on($cawangan['mysql'])->select('t_gadai','norujukan','nokp','semakbarcode','masa','berat','nilaimarhun','pinjaman','upah12','percentpinj','teller','nokp','ujrah','onepercent','tagbaru')
->where('t_gadai','>=',$request->mula)
->where('t_gadai','<=',$request->akhir)
->orderBy('t_gadai')
->orderBy('teller')
->orderBy('sirig')
->get();
$cawangan = Cawangan::on('mysql7')->where('kodcaw', $kodcaw)->first();
$gadai = [];
$gadai_data = Gadai::on($cawangan['mysql'])
->whereBetween('t_gadai', [$request->mula, $request->akhir])
->orderBy('t_gadai')
->orderBy('teller')
->orderBy('sirig')
->get();
if($gadai_data){
foreach($gadai_data as $index=>$gadaiData){
$customer_info = Customer::on('mysql7')->where('kplama','=',$gadaiData['nokp'])->orWhere('kpbaru','=',$gadaiData['nokp'])->first();
array_push($gadai,[
"t_gadai"=> $gadaiData['t_gadai'],
"norujukan"=> $gadaiData['norujukan'],
"nama"=> $customer_info['nama'],
"nokp"=> $gadaiData['nokp'],
"semakbarcode"=> $gadaiData['semakbarcode'],
"masa"=> $gadaiData['masa'],
"berat"=> $gadaiData['berat'],
"nilaimarhun"=> $gadaiData['nilaimarhun'],
"pinjaman"=> $gadaiData['pinjaman'],
"upah12"=> $gadaiData['upah12'],
"percentpinj"=> $gadaiData['percentpinj'],
"alamat1"=> $customer_info['alamat1'],
"teller"=> $gadaiData['teller'],
"ujrah"=> $gadaiData['ujrah'],
"onepercent"=> $gadaiData['onepercent'],
"tagbaru"=> $gadaiData['tagbaru']
$nokps = $gadai_data->pluck('nokp')->unique();
]);
$customers = Customer::on('mysql7')
->where(function($query) use ($nokps) {
$query->whereIn('kpbaru', $nokps)
->orWhereIn('kplama', $nokps);
})
->get()
->flatMap(fn($c) => [
$c->kpbaru => $c,
$c->kplama => $c
]);
$gadai = $gadai_data->map(function ($g) use ($customers) {
foreach($customers as $key=>$value){
if($g->nokp == $value->kpbaru || $g->nokp == $value->kplama){
$customer = $value;
}
}
}
return response()->json($gadai);
return [
"nama" => optional($customer)->nama,
"alamat1" => optional($customer)->alamat1,
"t_gadai" => $g->t_gadai,
"norujukan" => $g->norujukan,
"norujukan"=> $g->norujukan,
"nokp"=> $g->nokp,
"semakbarcode"=> $g->semakbarcode,
"masa"=> $g->masa,
"berat"=> $g->berat,
"nilaimarhun"=> $g->nilaimarhun,
"pinjaman"=> $g->pinjaman,
"upah12"=> $g->upah12,
"percentpinj"=> $g->percentpinj,
"alamat1"=> optional($customer)->alamat1,
"teller"=> $g->teller,
"ujrah"=> $g->ujrah,
"onepercent"=> $g->onepercent,
"tagbaru"=> $g->tagbaru,
"kodkerja"=> optional($customer)->kodkerja,
"bangsa"=> optional($customer)->bangsa,
];
});
// dd($gadai);
$statistikService = new StatistikService($kodcaw,$mula,$akhir);
$reportgadai = $statistikService->LaporanStatistik($gadai);
// dd($nokps);
return response()->json([
'gadai' => $gadai,
'kodcaw' => $kodcaw,
'mula' => $mula,
'akhir' => $akhir,
'statistik' => $reportgadai,
'jumlah' => $gadai->count(),
]);
}
public function getLaporanBatalGadai($kodcaw,$tarikh){