DONE: drop table shoraka financings, and improve UI checking on shoraka order status

This commit is contained in:
2026-10-26 15:04:43 +08:00
parent e3e7694b54
commit 8dd8def358
10 changed files with 95 additions and 368 deletions
@@ -12,6 +12,61 @@ use Throwable;
class ShorakaController extends Controller
{
public function index(Request $request)
{
$this->validate($request, [
'kodcaw' => 'nullable|string|max:30',
'norujukan' => 'nullable|string|max:100',
'status' => 'nullable|string|max:30',
'date_from' => 'nullable|date_format:Y-m-d',
'date_to' => 'nullable|date_format:Y-m-d',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
'branch_scope' => 'nullable|string|max:30',
]);
$query = ShorakaTransaction::query();
foreach (['kodcaw', 'norujukan', 'status'] as $field) {
if ($request->filled($field)) {
$query->where($field, $request->input($field));
}
}
if ($request->filled('date_from')) {
$query->where('created_at', '>=', $request->input('date_from') . ' 00:00:00');
}
if ($request->filled('date_to')) {
$query->where('created_at', '<', Carbon::parse($request->input('date_to'))->addDay()->format('Y-m-d') . ' 00:00:00');
}
$records = $query->orderByDesc('created_at')->orderByDesc('id')
->paginate(min(100, max(1, (int) $request->input('per_page', 25))));
$payload = [
'data' => $records->getCollection()->map(function (ShorakaTransaction $record) {
return [
'id' => $record->id,
'kodcaw' => $record->kodcaw,
'norujukan' => $record->norujukan,
'teller' => $record->teller,
'status' => $record->status,
'order_id' => $record->order_id,
'created_at' => optional($record->created_at)->toDateTimeString(),
'updated_at' => optional($record->updated_at)->toDateTimeString(),
];
})->values(),
'total' => $records->total(),
'current_page' => $records->currentPage(),
'per_page' => $records->perPage(),
'last_page' => $records->lastPage(),
];
if ($request->input('with_branches')) {
$branches = ShorakaTransaction::query()->whereNotNull('kodcaw');
if ($request->filled('branch_scope')) {
$branches->where('kodcaw', $request->input('branch_scope'));
}
$payload['branches'] = $branches->distinct()->orderBy('kodcaw')->pluck('kodcaw')->values();
}
return response()->json($payload);
}
public function submit(Request $request, ShorakaService $shoraka)
{
$validated = $this->validate($request, [
@@ -20,6 +75,7 @@ class ShorakaController extends Controller
'order_amount' => 'required|numeric|min:0.01|max:9999999999999.99',
'murabaha_amount' => 'required|numeric|min:0.01|max:9999999999999.99',
'tenor_other' => 'required|integer|min:1',
'teller' => 'nullable|string|max:255',
]);
if (!$shoraka->configured()) {
return $this->unconfigured();
@@ -51,6 +107,7 @@ class ShorakaController extends Controller
$attributes = [
'norujukan' => $validated['norujukan'],
'kodcaw' => $request->attributes->get('shoraka_kodcaw'),
'teller' => $validated['teller'] ?? null,
'status' => 'PENDING',
'product_type' => $payload['product_type'],
'commodity_type' => $payload['commodity_type'],
@@ -185,6 +242,7 @@ class ShorakaController extends Controller
return [
'norujukan' => $transaction->norujukan,
'kodcaw' => $transaction->kodcaw,
'teller' => $transaction->teller,
'order_id' => $transaction->order_id,
'status' => $transaction->status,
'certificate_url' => $transaction->certificate_url,