diff --git a/Modules/Murid/Http/Controllers/PembayaranController.php b/Modules/Murid/Http/Controllers/PembayaranController.php index 43d0067..b53a097 100644 --- a/Modules/Murid/Http/Controllers/PembayaranController.php +++ b/Modules/Murid/Http/Controllers/PembayaranController.php @@ -2,6 +2,8 @@ namespace Modules\Murid\Http\Controllers; +use App\Models\Bank; +use App\Models\User; use Carbon\Carbon; use ErrorException; use Illuminate\Contracts\Support\Renderable; @@ -10,6 +12,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Session; +use Modules\Murid\Http\Requests\ConfirmPaymentRequest; use Modules\SPP\Entities\DetailPaymentSpp; class PembayaranController extends Controller @@ -61,11 +64,14 @@ public function show($id) public function edit($id) { $payment = DetailPaymentSpp::with('user.muridDetail')->where('user_id', Auth::id())->findOrFail($id); + $accountbanks = User::with('banks')->first(); + $bank = Bank::all(); + if ($payment->status == 'paid') { Session::flash('error','Pembayaran Sudah Diterima.'); return redirect('murid/pembayaran'); } - return view('murid::pembayaran.edit', compact('payment')); + return view('murid::pembayaran.edit', compact('payment','accountbanks','bank')); } /** @@ -74,20 +80,25 @@ public function edit($id) * @param int $id * @return Renderable */ - public function update(Request $request, $id) + public function update(ConfirmPaymentRequest $request, $id) { try { DB::beginTransaction(); - $file = $request->file('file'); - $file_payment = 'payment-'.time().Auth::id().".".$file->getClientOriginalExtension(); - // isi dengan nama folder tempat kemana file diupload - $tujuan_upload = 'public/images/bukti_payment'; - $file->storeAs($tujuan_upload,$file_payment); + if ($request->file) { + $file = $request->file('file'); + $file_payment = 'payment-'.time().Auth::id().".".$file->getClientOriginalExtension(); + // isi dengan nama folder tempat kemana file diupload + $tujuan_upload = 'public/images/bukti_payment'; + $file->storeAs($tujuan_upload,$file_payment); + } $payment = DetailPaymentSpp::where('user_id', Auth::id())->findOrFail($id); - $payment->file = $file_payment; - $payment->date_file = Carbon::now(); + $payment->file = $file_payment ?? $payment->file; + $payment->date_file = $request->date_file; + $payment->sender = $request->sender; + $payment->bank_sender = $request->bank_sender; + $payment->destination_bank = $request->destination_bank; $payment->update(); DB::commit(); diff --git a/Modules/Murid/Http/Requests/ConfirmPaymentRequest.php b/Modules/Murid/Http/Requests/ConfirmPaymentRequest.php new file mode 100644 index 0000000..384683a --- /dev/null +++ b/Modules/Murid/Http/Requests/ConfirmPaymentRequest.php @@ -0,0 +1,46 @@ + 'required_if:file,null|mimes:jpg,jpeg,png', + 'sender' => 'required', + 'bank_sender' => 'required', + 'destination_bank' => 'required', + 'date_file' => 'required' + ]; + } + + public function messages() + { + return [ + 'file.required' => 'File Bukti Pembayaran tidak boleh kosong.', + 'file.mimes' => 'File Bukti Pembayaran tidak valid.', + 'sender.required' => 'Nama Pengirim tidak boleh kosong.', + 'bank_sender.required' => 'Bank Pengirim tidak boleh kosong.', + 'destination_bank' => 'Bank Tujuan tidak boleh kosong.', + 'date_file.required' => 'Tanggal Transfer tidak boleh kosong.' + ]; + } + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } +} diff --git a/Modules/Murid/Resources/views/pembayaran/edit.blade.php b/Modules/Murid/Resources/views/pembayaran/edit.blade.php index 5ba647c..35d793f 100644 --- a/Modules/Murid/Resources/views/pembayaran/edit.blade.php +++ b/Modules/Murid/Resources/views/pembayaran/edit.blade.php @@ -34,53 +34,126 @@