DONE: remove cache, and remove dto financing
This commit is contained in:
@@ -55,10 +55,6 @@ class GadaiController extends Controller
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$cawangan_code)->first();
|
||||
|
||||
$gadaiTransaction = Gadai::on($cawangan['mysql'])->where('t_gadai','=',$date)->orderBy('sirig', 'desc')->first();
|
||||
$serial = app(\App\Services\ShorakaNewGadaiService::class)->latestSerial($cawangan_code, $date);
|
||||
if ($serial > (int) ($gadaiTransaction->sirig ?? 0)) {
|
||||
$gadaiTransaction = ['sirig' => $serial];
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
Log::debug($e);
|
||||
Log::debug($cawangan_code);
|
||||
@@ -115,7 +111,7 @@ class GadaiController extends Controller
|
||||
$gadai_all = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$gadai = collect(array_filter([app(\App\Services\ShorakaNewGadaiService::class)->find($cawangan->kodcaw, $norujukan)]));
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
if(sizeof($gadai) != 0){
|
||||
array_push($gadai_all,$gadai);
|
||||
}
|
||||
@@ -134,7 +130,7 @@ class GadaiController extends Controller
|
||||
$gadai_all = [];
|
||||
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$gadai = collect(array_filter([app(\App\Services\ShorakaNewGadaiService::class)->find($cawangan->kodcaw, $norujukan)]));
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
if(sizeof($gadai) != 0){
|
||||
array_push($gadai_all,$gadai);
|
||||
}
|
||||
@@ -156,22 +152,12 @@ class GadaiController extends Controller
|
||||
|
||||
public function showOneGadaibyRujukanAndCawangan($kodcaw,$norujukan){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$gadai = collect(array_filter([app(\App\Services\ShorakaNewGadaiService::class)->find($cawangan->kodcaw, $norujukan)]));
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
|
||||
return response()->json($gadai);
|
||||
}
|
||||
|
||||
public function create($kodcaw,Request $request){
|
||||
if ($request->boolean('shoraka_new')) {
|
||||
$this->validate($request, ['nokp' => 'required|string', 'nopelanggan' => 'required']);
|
||||
return response()->json(app(\App\Services\ShorakaNewGadaiService::class)->reserve(
|
||||
$kodcaw, $request->only(['nokp', 'nopelanggan'])
|
||||
), 201);
|
||||
}
|
||||
|
||||
if (app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, (string) $request->norujukan)) {
|
||||
abort(409, 'Nombor rujukan sedang digunakan. Sila dapatkan nombor baharu.');
|
||||
}
|
||||
$master = new MasterServices($kodcaw);
|
||||
$response = $master->createGadai($request);
|
||||
|
||||
@@ -246,10 +232,6 @@ class GadaiController extends Controller
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()) {
|
||||
abort(409, 'Kontrak telah dihantar ke Shoraka dan tidak boleh diubah.');
|
||||
}
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, $norujukan);
|
||||
if ($temporary && (string) $temporary['gadai']['nokp'] !== (string) $request->nokp) {
|
||||
abort(409, 'Pelanggan tidak sepadan dengan borang gadaian sementara.');
|
||||
}
|
||||
$request->merge(['kodcaw' => $kodcaw, 'norujukan' => $norujukan]);
|
||||
$master = new MasterServices($kodcaw);
|
||||
$response = $master->createMarhunGadai($norujukan, $request);
|
||||
@@ -266,13 +248,7 @@ class GadaiController extends Controller
|
||||
|
||||
public function checkNorujukan(Request $request){
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();
|
||||
$gadai = app(\App\Services\ShorakaNewGadaiService::class)->find($request->kodcaw, $request->norujukan);
|
||||
if (!$gadai && \App\ShorakaTransaction::where('norujukan', $request->norujukan)->exists()) {
|
||||
abort(409, 'Transaksi Shoraka wujud tetapi maklumat sementara tiada. Hubungi operasi; jangan daftar semula.');
|
||||
}
|
||||
if ($gadai && $gadai->nokp !== $request->nokp) {
|
||||
$gadai = null;
|
||||
}
|
||||
$gadai = Gadai::on($cawangan['mysql'])->where([['norujukan','=',$request->norujukan],['nokp','=',$request->nokp]])->first();
|
||||
|
||||
return response()->json($gadai);
|
||||
}
|
||||
@@ -395,16 +371,9 @@ class GadaiController extends Controller
|
||||
}
|
||||
|
||||
public function batalGadai($kodcaw, $norujukan,Request $request){
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class);
|
||||
$order = \App\ShorakaTransaction::where('norujukan', $norujukan)->first();
|
||||
if ($order && !empty($order->request_payload['_new_gadai'])) {
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()) {
|
||||
abort(409, 'Transaksi Shoraka telah dihantar. Semakan operasi diperlukan sebelum pembatalan.');
|
||||
}
|
||||
if ($temporary->pending($kodcaw, $norujukan)) {
|
||||
$temporary->abandon($kodcaw, $norujukan);
|
||||
return response('Batal Berjaya', 200);
|
||||
}
|
||||
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
@@ -459,8 +428,7 @@ class GadaiController extends Controller
|
||||
}
|
||||
|
||||
public function cetakSAG($kodcaw,$norujukan,Request $request){
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()
|
||||
|| app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, $norujukan)) {
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()) {
|
||||
app(\App\Services\ShorakaGadaiService::class)->assertCompleted($kodcaw, $norujukan);
|
||||
}
|
||||
|
||||
@@ -488,8 +456,7 @@ class GadaiController extends Controller
|
||||
}
|
||||
|
||||
public function serahMarhun($kodcaw,$norujukan){
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()
|
||||
|| app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, $norujukan)) {
|
||||
if (\App\ShorakaTransaction::where('norujukan', $norujukan)->exists()) {
|
||||
app(\App\Services\ShorakaGadaiService::class)->assertCompleted($kodcaw, $norujukan);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@ class MarhunController extends Controller
|
||||
$marhun_all = [];
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$marhun = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
||||
if ($marhun->isEmpty()) {
|
||||
$marhun = app(\App\Services\ShorakaNewGadaiService::class)->items($cawangan->kodcaw, $norujukan);
|
||||
}
|
||||
if(sizeof($marhun) != 0){
|
||||
array_push($marhun_all,$marhun);
|
||||
}
|
||||
@@ -43,9 +40,6 @@ class MarhunController extends Controller
|
||||
|
||||
$marhun = Marhun::on($cawangan['mysql'])->where('norujukan',$request->norujukan)->distinct()->pluck('karat')->toArray();
|
||||
|
||||
if (app(\App\Services\ShorakaNewGadaiService::class)->pending($request->kodcaw, $request->norujukan)) {
|
||||
$marhun = app(\App\Services\ShorakaNewGadaiService::class)->items($request->kodcaw, $request->norujukan)->pluck('karat')->unique()->all();
|
||||
}
|
||||
$mutu = HargaEmas::on('mysql7')->whereIn('karat',$marhun)->pluck('keterangan')->toArray();
|
||||
|
||||
return response()->json($mutu);
|
||||
@@ -66,7 +60,7 @@ class MarhunController extends Controller
|
||||
public function create($kodcaw,Request $request)
|
||||
{
|
||||
$order = \App\ShorakaTransaction::where('norujukan', $request->norujukan)->first();
|
||||
if ($order && !empty($order->request_payload['_new_gadai'])) {
|
||||
if ($order) {
|
||||
abort(409, 'Kontrak Shoraka telah dihantar dan tidak boleh diubah.');
|
||||
}
|
||||
|
||||
@@ -107,10 +101,6 @@ class MarhunController extends Controller
|
||||
};
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class);
|
||||
if ($temporary->pending($kodcaw, $request->norujukan)) {
|
||||
return response()->json($temporary->changeItem($kodcaw, $request->norujukan, $marhunToCreate), 201);
|
||||
}
|
||||
$marhun = Marhun::on($cawangan['mysql'])->create($marhunToCreate);
|
||||
|
||||
$audit = new Audit();
|
||||
@@ -143,17 +133,10 @@ class MarhunController extends Controller
|
||||
public function deletemarhun($kodcaw,$norujukan,Request $request)
|
||||
{
|
||||
$order = \App\ShorakaTransaction::where('norujukan', $norujukan)->first();
|
||||
if ($order && !empty($order->request_payload['_new_gadai'])) {
|
||||
if ($order) {
|
||||
abort(409, 'Kontrak Shoraka telah dihantar dan tidak boleh diubah.');
|
||||
}
|
||||
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class);
|
||||
if ($temporary->pending($kodcaw, $norujukan)) {
|
||||
$temporary->changeItem($kodcaw, $norujukan, [], $request->recno, true);
|
||||
return response('Deleted Successfully', 200);
|
||||
}
|
||||
|
||||
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
@@ -179,7 +162,7 @@ class MarhunController extends Controller
|
||||
public function editmarhun($kodcaw,$norujukan,Request $request)
|
||||
{
|
||||
$order = \App\ShorakaTransaction::where('norujukan', $norujukan)->first();
|
||||
if ($order && !empty($order->request_payload['_new_gadai'])) {
|
||||
if ($order) {
|
||||
abort(409, 'Kontrak Shoraka telah dihantar dan tidak boleh diubah.');
|
||||
}
|
||||
|
||||
@@ -190,17 +173,6 @@ class MarhunController extends Controller
|
||||
$harga = HargaEmas::on('mysql7')->where('karat',$request->karat)->first();
|
||||
$nilai_marhun = $request->berat * $harga['harga'];
|
||||
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class);
|
||||
if ($temporary->pending($kodcaw, $norujukan)) {
|
||||
$temporary->changeItem($kodcaw, $norujukan, [
|
||||
'karat' => $request->karat, 'marhun' => $request->marhun, 'nota' => $request->nota,
|
||||
'tag_permata' => $request->tag_permata,
|
||||
'berat_batu_permata' => $request->berat_batu_permata ?: null,
|
||||
'berat' => $request->berat, 'harga' => $harga['harga'], 'n_marhun' => $nilai_marhun,
|
||||
'bil' => $request->kuantiti,
|
||||
], $request->recno);
|
||||
return response()->json(true);
|
||||
}
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
// Lock the parent first so concurrent edits to this SAG are serialized.
|
||||
@@ -299,9 +271,6 @@ class MarhunController extends Controller
|
||||
|
||||
$marhuns = Marhun::on($cawangan['mysql'])->where('norujukan',$request->norujukan)->get();
|
||||
|
||||
if ($marhuns->isEmpty()) {
|
||||
$marhuns = app(\App\Services\ShorakaNewGadaiService::class)->items($request->kodcaw, $request->norujukan);
|
||||
}
|
||||
$totalnilaimarhun = 0;
|
||||
|
||||
foreach($marhuns as $index=>$marhun){
|
||||
@@ -315,11 +284,6 @@ class MarhunController extends Controller
|
||||
|
||||
public function getMarhunCaw($kodcaw,$norujukan)
|
||||
{
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class);
|
||||
if ($temporary->pending($kodcaw, $norujukan)) {
|
||||
return response()->json($temporary->items($kodcaw, $norujukan)->sum('n_marhun'));
|
||||
}
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$data = Marhun::on($cawangan['mysql'])
|
||||
->where('norujukan','=', $norujukan)
|
||||
|
||||
@@ -58,15 +58,10 @@ class ShorakaController extends Controller
|
||||
'ownership_doc_no' => $payload['ownership_doc_no'],
|
||||
'order_amount' => $payload['order_amount'],
|
||||
'murabaha_amount' => $payload['murabaha_amount'],
|
||||
'request_payload' => $request->attributes->get('shoraka_new')
|
||||
? array_merge($payload, ['_new_gadai' => true]) : $payload,
|
||||
'request_payload' => $payload,
|
||||
'attempt_count' => 1,
|
||||
];
|
||||
$create = function () use ($attributes) { return ShorakaTransaction::create($attributes); };
|
||||
$transaction = $request->attributes->get('shoraka_new')
|
||||
? app(\App\Services\ShorakaNewGadaiService::class)->claim(
|
||||
$request->attributes->get('shoraka_kodcaw'), $validated['norujukan'], $payload, $create
|
||||
) : $create();
|
||||
$transaction = ShorakaTransaction::create($attributes);
|
||||
} catch (QueryException $exception) {
|
||||
$existing = ShorakaTransaction::where('norujukan', $validated['norujukan'])->first();
|
||||
if ($existing) {
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\ShorakaFinancing;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ShorakaFinancingController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'kodcaw' => 'nullable|string|max:30',
|
||||
'norujukan' => 'nullable|string|max:100',
|
||||
'state' => 'nullable|in:WAITING,PROCESSING,REVIEW,DONE',
|
||||
'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',
|
||||
]);
|
||||
|
||||
try {
|
||||
$query = ShorakaFinancing::query();
|
||||
foreach (['kodcaw', 'norujukan', 'state'] 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 (ShorakaFinancing $record) {
|
||||
return $this->present($record, false);
|
||||
})->values(),
|
||||
'total' => $records->total(),
|
||||
'current_page' => $records->currentPage(),
|
||||
'per_page' => $records->perPage(),
|
||||
'last_page' => $records->lastPage(),
|
||||
];
|
||||
if ($request->input('with_branches')) {
|
||||
$branches = ShorakaFinancing::query();
|
||||
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);
|
||||
} catch (QueryException $exception) {
|
||||
return $this->unavailable();
|
||||
}
|
||||
}
|
||||
|
||||
public function show(string $kodcaw, string $norujukan)
|
||||
{
|
||||
try {
|
||||
$record = $this->find($kodcaw, $norujukan);
|
||||
} catch (QueryException $exception) {
|
||||
return $this->unavailable();
|
||||
}
|
||||
if (!$record) {
|
||||
return response()->json(['message' => 'Rekod pembiayaan tidak dijumpai.'], 404);
|
||||
}
|
||||
return response()->json(['data' => $this->present($record)]);
|
||||
}
|
||||
|
||||
public function store(string $kodcaw, string $norujukan, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'teller' => 'required|string|max:255',
|
||||
'action' => 'required|string|max:30',
|
||||
'context' => 'present|array',
|
||||
]);
|
||||
try {
|
||||
$existing = $this->find($kodcaw, $norujukan);
|
||||
if ($existing) {
|
||||
return response()->json(['created' => false, 'data' => $this->present($existing)]);
|
||||
}
|
||||
$record = ShorakaFinancing::create([
|
||||
'kodcaw' => $kodcaw,
|
||||
'norujukan' => $norujukan,
|
||||
'teller' => $request->input('teller'),
|
||||
'action' => $request->input('action'),
|
||||
'state' => 'WAITING',
|
||||
'context' => $request->input('context'),
|
||||
]);
|
||||
return response()->json(['created' => true, 'data' => $this->present($record)], 201);
|
||||
} catch (QueryException $exception) {
|
||||
try {
|
||||
$existing = $this->find($kodcaw, $norujukan);
|
||||
} catch (QueryException $again) {
|
||||
return $this->unavailable();
|
||||
}
|
||||
if ($existing) {
|
||||
return response()->json(['created' => false, 'data' => $this->present($existing)]);
|
||||
}
|
||||
return $this->unavailable();
|
||||
}
|
||||
}
|
||||
|
||||
public function update(string $kodcaw, string $norujukan, Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'state' => 'required|in:WAITING,PROCESSING,REVIEW,DONE',
|
||||
'expected_state' => 'nullable|in:WAITING,PROCESSING,REVIEW,DONE',
|
||||
'context' => 'nullable|array',
|
||||
]);
|
||||
try {
|
||||
$record = $this->find($kodcaw, $norujukan);
|
||||
if (!$record) {
|
||||
return response()->json(['message' => 'Rekod pembiayaan tidak dijumpai.'], 404);
|
||||
}
|
||||
if ($request->filled('expected_state')) {
|
||||
$claimed = ShorakaFinancing::where('id', $record->id)
|
||||
->where('state', $request->input('expected_state'))
|
||||
->update(['state' => $request->input('state'), 'updated_at' => Carbon::now()]);
|
||||
return response()->json([
|
||||
'claimed' => $claimed === 1,
|
||||
'data' => $this->present($record->fresh()),
|
||||
]);
|
||||
}
|
||||
$fields = ['state' => $request->input('state')];
|
||||
if ($request->exists('context')) {
|
||||
$fields['context'] = $request->input('context') ?? [];
|
||||
}
|
||||
$record->update($fields);
|
||||
return response()->json(['claimed' => true, 'data' => $this->present($record->fresh())]);
|
||||
} catch (QueryException $exception) {
|
||||
return $this->unavailable();
|
||||
}
|
||||
}
|
||||
|
||||
private function find(string $kodcaw, string $norujukan): ?ShorakaFinancing
|
||||
{
|
||||
return ShorakaFinancing::where('kodcaw', $kodcaw)->where('norujukan', $norujukan)->first();
|
||||
}
|
||||
|
||||
private function present(ShorakaFinancing $record, bool $withContext = true): array
|
||||
{
|
||||
$data = [
|
||||
'id' => $record->id,
|
||||
'kodcaw' => $record->kodcaw,
|
||||
'norujukan' => $record->norujukan,
|
||||
'teller' => $record->teller,
|
||||
'action' => $record->action,
|
||||
'state' => $record->state,
|
||||
'created_at' => optional($record->created_at)->toDateTimeString(),
|
||||
'updated_at' => optional($record->updated_at)->toDateTimeString(),
|
||||
];
|
||||
if ($withContext) {
|
||||
$data['context'] = $record->context ?? [];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function unavailable()
|
||||
{
|
||||
return response()->json(['message' => 'Rekod pembiayaan Shoraka tidak tersedia.'], 503);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,13 @@ class ShorakaGadaiController extends ShorakaController
|
||||
{
|
||||
public function readiness(ShorakaService $shoraka)
|
||||
{
|
||||
return response()->json(['provider' => 'shoraka', 'ready' => $shoraka->configured()]);
|
||||
try {
|
||||
\App\ShorakaFinancing::query()->limit(1)->exists();
|
||||
$storeReady = true;
|
||||
} catch (\Throwable $exception) {
|
||||
$storeReady = false;
|
||||
}
|
||||
return response()->json(['provider' => 'shoraka', 'ready' => $storeReady && $shoraka->configured()]);
|
||||
}
|
||||
|
||||
public function showGadai(string $kodcaw, string $norujukan, ShorakaGadaiService $gadaiService)
|
||||
@@ -45,16 +51,8 @@ class ShorakaGadaiController extends ShorakaController
|
||||
|| $gadai->cetak || $gadai->sttebus) {
|
||||
abort(409, 'Gadaian lama atau telah selesai tidak boleh dihantar sebagai order baharu.');
|
||||
}
|
||||
$temporary = app(\App\Services\ShorakaNewGadaiService::class)->pending($kodcaw, $norujukan);
|
||||
if ($temporary && $gadai->exists) {
|
||||
abort(409, 'Rujukan sementara bertindih dengan gadaian sedia ada. Semakan operasi diperlukan.');
|
||||
}
|
||||
if ($temporary && !$temporary['prepared']) {
|
||||
abort(409, 'Sila sahkan semula amaun gadaian selepas perubahan marhun.');
|
||||
}
|
||||
$request = new Request($gadaiService->payload($gadai));
|
||||
$request->attributes->set('shoraka_kodcaw', $kodcaw);
|
||||
$request->attributes->set('shoraka_new', !$gadai->exists);
|
||||
return $this->submit($request, $shoraka);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user