Continue dev on pampasan module
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Audit;
|
||||
use App\Polis;
|
||||
use App\Cawangan;
|
||||
use App\LookupAlasan;
|
||||
use App\Pampasan;
|
||||
use App\Palsu;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
@@ -24,7 +26,7 @@ class BarangkesController extends Controller
|
||||
return response()->json(['error' => 'Invalid kodcaw'], 403);
|
||||
}
|
||||
|
||||
$query = DB::connection($cawangan['mysql'])->table('palsu')
|
||||
$palsu_query = Palsu::on($cawangan['mysql'])
|
||||
->select([
|
||||
'tarikh',
|
||||
'norujukan',
|
||||
@@ -35,33 +37,34 @@ class BarangkesController extends Controller
|
||||
'untung',
|
||||
'untungonepercent',
|
||||
'untungcajlain'
|
||||
]);
|
||||
])
|
||||
->when($request->filled('jenis'), function($query) use($request){
|
||||
return $query->where('jenis', $request->jenis);
|
||||
})
|
||||
->when($request->filled('tarikh_mula') && $request->filled('tarikh_akhir'), function($query) use($request){
|
||||
return $query->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
})
|
||||
->with('tebus:norujukan');
|
||||
|
||||
// Only apply whereBetween if tarikh_mula and tarikh_akhir are provided
|
||||
if ($request->filled('tarikh_mula') && $request->filled('tarikh_akhir')) {
|
||||
$query->whereBetween('tarikh', [$request->tarikh_mula, $request->tarikh_akhir]);
|
||||
}
|
||||
$palsu_array = $palsu_query->get()->toArray();
|
||||
$pampasan_array = Pampasan::on($cawangan['mysql'])->where('kodcaw', $request->kodcaw)->get()->toArray();
|
||||
|
||||
$result = $query->get();
|
||||
|
||||
$pampasan = Http::get(config('app_parameter.api_v3') . "pampasan", ['kodcaw' => $request->kodcaw])
|
||||
->json()['data'];
|
||||
|
||||
$palsu_array = $result->toArray();
|
||||
|
||||
// dd($pampasan, $palsu_array);
|
||||
|
||||
$indexedArray2 = collect($pampasan)->keyBy('norujukan');
|
||||
$indexedArray2 = collect($pampasan_array)->keyBy('norujukan');
|
||||
|
||||
$merged = collect($palsu_array)->map(function ($item) use ($indexedArray2) {
|
||||
$id = $item->norujukan;
|
||||
$itemArray = (array) $item; // Convert object to array
|
||||
$id = $item['norujukan'];
|
||||
$itemArray = $item; // Already an array from toArray()
|
||||
$additional = $indexedArray2->get($id, []);
|
||||
|
||||
// Add exists_in_tebus flag based on relationship
|
||||
$itemArray['gadaian_sudah_tebus'] = !is_null($item['tebus']);
|
||||
|
||||
// Remove the tebus relationship data to keep response clean
|
||||
unset($itemArray['tebus']);
|
||||
|
||||
return array_merge($itemArray, $additional);
|
||||
})->values()->toArray();
|
||||
|
||||
// dd($merged, $status);
|
||||
|
||||
$filteredResults = [];
|
||||
|
||||
if ($status == 'dituntut') {
|
||||
@@ -78,7 +81,7 @@ class BarangkesController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($status == 'all') {
|
||||
if ($status == 'all' || $status == null) {
|
||||
$filteredResults = $merged;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Palsu;
|
||||
use App\Pampasan;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
@@ -67,6 +68,11 @@ class PampasanController extends Controller
|
||||
|
||||
$pampasan->save();
|
||||
|
||||
// Update corresponding palsu table record status to 1
|
||||
Palsu::on($cawangan['mysql'])
|
||||
->where('norujukan', $norujukan)
|
||||
->update(['status' => 1]);
|
||||
|
||||
// dd($pampasan);
|
||||
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user