diff --git a/app/Http/Controllers/Mobile/LelongMobileController.php b/app/Http/Controllers/Mobile/LelongMobileController.php index f30295a5..9797f92c 100644 --- a/app/Http/Controllers/Mobile/LelongMobileController.php +++ b/app/Http/Controllers/Mobile/LelongMobileController.php @@ -634,23 +634,30 @@ class LelongMobileController extends Controller }) ->first(); if ($payment != null) { - if ($payment->status == 2) { - $checkPayMethod = Resit::find($payment->resit_id); - $date_convert = strtotime($checkPayMethod->created_at); - $checkPayMethod['pay_time'] = date("H:i:s", $date_convert); - $status_payment_cawangan['resit'] = $checkPayMethod->toArray(); - if ($checkPayMethod->billplz_id == "") { - $status_payment_cawangan['payment_method'] = "TUNAI"; - $status_payment_cawangan['payment_method_opt'] = 1; - } elseif (str_starts_with($checkPayMethod->billplz_id, 'CDM')) { - $status_payment_cawangan['payment_method'] = "CDM"; - $status_payment_cawangan['payment_method_opt'] = 3; - } else { - $status_payment_cawangan['payment_method'] = "ONLINE"; - $status_payment_cawangan['payment_method_opt'] = 2; + $checkPayMethod = Resit::find($payment->resit_id); + $date_convert = strtotime($checkPayMethod->created_at); + $checkPayMethod['pay_time'] = date("H:i:s", $date_convert); + $status_payment_cawangan['resit'] = $checkPayMethod->toArray(); + if ($checkPayMethod->billplz_id == "") { + $status_payment_cawangan['payment_method'] = "TUNAI"; + $status_payment_cawangan['payment_method_opt'] = 1; + } elseif (str_starts_with($checkPayMethod->billplz_id, 'CDM')) { + $status_payment_cawangan['payment_method'] = "CDM"; + $status_payment_cawangan['payment_method_opt'] = 3; + $file_resit = FileResit::where('user_id', $user_id)->where('lelong_id', $lelong_id)->where('kodcaw', $kodCawangan)->get(); + foreach($file_resit as $index => $resit) + { + $date_convert = strtotime($resit->created_at); + $updatedDateTime = date("H:i:s", $date_convert); + $file_resit[$index]['masa_upload'] = $updatedDateTime; } + $status_payment_cawangan['file_resit'] = $file_resit; } else { - $status_payment_cawangan['status'] = 9; // status pending tunggu pengesahan + $status_payment_cawangan['payment_method'] = "ONLINE"; + $status_payment_cawangan['payment_method_opt'] = 2; + } + if ($payment->disahkan_pada == NULL) { + $status_payment_cawangan['status'] = 9; // status pending tunggu pengesahan } } else { $status_payment_cawangan['status'] = null; @@ -1295,6 +1302,7 @@ class LelongMobileController extends Controller $addfile->user_id = $request->user_id; $addfile->lelong_id = $request->lelong_id; $addfile->file_type = $file_type; + $addfile->kodcaw = $request->kodcaw; $addfile->save(); $directory = "/{$request->user_id}/{$request->lelong_id}/"; @@ -1306,16 +1314,11 @@ class LelongMobileController extends Controller $stored_path = Storage::disk('resit')->path("{$directory}{$resitImageFileName}.${imageExtension}"); $resitPhotoService = new ResitPhotoService(); - // try { - - $convertToWebP = $resitPhotoService->optimizeImageToWebP($stored_path, $directory, $resitImageFileName); - - // } catch (\Exception $e) - - // { - // return $e; - // } - + try { + $convertToWebP = $resitPhotoService->optimizeImageToWebP($stored_path, $directory, $resitImageFileName); + } catch (\Exception $e) { + return $e; + } Storage::disk('resit')->delete("{$directory}${resitImageFileName}.${imageExtension}"); @@ -1360,4 +1363,65 @@ class LelongMobileController extends Controller return response()->json(['lelong' => $lelong]); } + public function initializeCdmPayment(Request $request) + { + $current = Carbon::now(); + $current = new Carbon(); + + $day = $current->day; + $month = $current->month; + $year = $current->format('y'); + + $this->addPhotoResit($request); + + $previous_siri = Resit::orderBy('id','desc')->first(); + if($previous_siri){ + $nosiri = $previous_siri->id + 1; + }else{ + $nosiri = 1; + } + + $reference_no = 'LPKB' . $day . $month . $year . sprintf("%08d", $nosiri); + + $cdm_reference = 'CDM' . sprintf('%06d', $nosiri); + + $add_resit = new Resit(); + $add_resit->user_id = $request->user_id; + $add_resit->lelong_id = $request->lelong_id; + $add_resit->reference_no = $reference_no; + $add_resit->invoice_id = $request->invoice_id; + $add_resit->invoice_no = $request->invoice_no; + $add_resit->billplz_id = $cdm_reference; + $add_resit->total_payment = $request->total; + $add_resit->resit_type = 2; + $add_resit->save(); + + $selectedSag = $request->sag; + foreach ($selectedSag as $index) { + $add_payment = new Payment; + $add_payment->user_id = $request->user_id; + $add_payment->lelong_id = $request->lelong_id; + $add_payment->kodcaw = $index['kodcaw']; + $add_payment->lelongbid_id = $index['lelongbid_id']; + $add_payment->norujukan = $index['norujukan']; + $add_payment->total_payment = $index['total_payment']; + $add_payment->status_payment_opt = 3; //bayar secara CDM 3 + $add_payment->status = 2; //paybidwin + $add_payment->remark = 'CDM'; + $add_payment->resit_id = $add_resit->id; + $add_payment->save(); + + $updateTagBid = LelongBid::where('norujukan', $index['norujukan'])->first(); + $updateTagBid->status_payment = 2; + $updateTagBid->save(); + + $updateTagBidder = LelongBidder::where('lelongbid_id', $updateTagBid->id) + ->where('user_id', $request->user_id)->first(); + $updateTagBidder->status_payment = 2; + $updateTagBidder->payment_id = $add_payment->id; + $updateTagBidder->save(); + } + return response()->json(['success' => true]); + } + } diff --git a/routes/api.php b/routes/api.php index 02f52478..c405e659 100644 --- a/routes/api.php +++ b/routes/api.php @@ -105,7 +105,7 @@ Route::group(['middleware' => ['auth:sanctum']], function () { //===========PAY====================== //get invoice detail Route::get('/invoice', [LelongMobileController::class, 'getInvoiceId']); - //get invoice detail + //get list photo's receipt Route::get('/listPhotoResit', [LelongMobileController::class, 'listPhotoResit']); //add photo resit Route::post('/addPhotoResit',[LelongMobileController::class, 'addPhotoResit']); @@ -113,6 +113,8 @@ Route::group(['middleware' => ['auth:sanctum']], function () { Route::get('/showPhotoResit',[LelongMobileController::class, 'showPhotoResit']); //delete photo resit Route::post('/deletePhotoResit',[LelongMobileController::class, 'deletePhotoResit']); + //BY CAWANGAN -> initializie cdm payment + Route::post('/initializeCdmPayment',[LelongMobileController::class, 'initializeCdmPayment']); // Lelong