From 9c78dadae2a978260feb661daee8c2147d69ba53 Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Mon, 3 Jul 2023 01:04:16 +0700 Subject: [PATCH] fix pembayaran --- .../Admin/CustomerHistoryController.php | 2 +- .../Controllers/Admin/PaylaterController.php | 8 +- .../Customer/DepositController.php | 45 ++- .../Customer/PaylaterController.php | 12 +- app/Models/PaylaterHistory.php | 8 +- ...033734_create_paylater_histories_table.php | 2 + resources/js/Components/FormInputDate.jsx | 36 ++- resources/js/Customer/Paylater/Repay.jsx | 29 +- resources/js/Layouts/Partials/routes.js | 4 +- .../Pages/CustomerHistory/PaylaterHistory.jsx | 2 +- resources/js/Pages/DepositHistory/Form.jsx | 2 +- resources/js/Pages/Paylater/Detail.jsx | 281 +++++++++++++++--- resources/js/Pages/Paylater/Form.jsx | 42 ++- resources/js/Pages/Paylater/Index.jsx | 2 +- routes/admin.php | 8 +- 15 files changed, 398 insertions(+), 85 deletions(-) diff --git a/app/Http/Controllers/Admin/CustomerHistoryController.php b/app/Http/Controllers/Admin/CustomerHistoryController.php index e74dc54..2d68dcf 100644 --- a/app/Http/Controllers/Admin/CustomerHistoryController.php +++ b/app/Http/Controllers/Admin/CustomerHistoryController.php @@ -39,7 +39,7 @@ class CustomerHistoryController extends Controller { $query = PaylaterHistory::with(['editor']) ->where('customer_id', $customer->id) - // ->where('type', PaylaterHistory::TYPE_REPAYMENT) + ->where('type', PaylaterHistory::TYPE_REPAYMENT) ->orderBy('created_at', 'desc'); return inertia('CustomerHistory/PaylaterHistory', [ diff --git a/app/Http/Controllers/Admin/PaylaterController.php b/app/Http/Controllers/Admin/PaylaterController.php index 51d1cad..d789a5d 100644 --- a/app/Http/Controllers/Admin/PaylaterController.php +++ b/app/Http/Controllers/Admin/PaylaterController.php @@ -54,15 +54,18 @@ class PaylaterController extends Controller public function show(PaylaterHistory $paylater) { + $deposit = DepositHistory::where('related_id', $paylater->id)->first(); + return inertia('Paylater/Detail', [ 'paylater' => $paylater->load(['customer']), + 'deposit' => $deposit->load(['customer', 'account', 'depositLocation', 'editor', 'paylater']), ]); } public function edit(DepositHistory $deposit) { return inertia('Paylater/Form', [ - 'deposit' => $deposit->load(['customer', 'account', 'depositLocation', 'editor']), + 'deposit' => $deposit->load(['customer', 'account', 'depositLocation', 'paylater', 'editor']), ]); } @@ -91,7 +94,6 @@ class PaylaterController extends Controller $paylater->update([ 'credit' => $request->debit, 'is_valid' => $request->is_valid, - 'note' => $request->reject_reason, ]); if ($request->is_valid == DepositHistory::STATUS_VALID) { @@ -101,7 +103,7 @@ class PaylaterController extends Controller DB::commit(); - return redirect()->route('paylater.index') + return redirect()->route('paylater.repay.index') ->with('message', ['type' => 'success', 'message' => 'Item has beed updated']); } diff --git a/app/Http/Controllers/Customer/DepositController.php b/app/Http/Controllers/Customer/DepositController.php index a6827a6..3f3ece7 100644 --- a/app/Http/Controllers/Customer/DepositController.php +++ b/app/Http/Controllers/Customer/DepositController.php @@ -42,7 +42,7 @@ class DepositController extends Controller public function create(Request $request) { $customer = $request->user('customer'); - if (! $customer->allow_transaction) { + if (!$customer->allow_transaction) { return redirect()->back() ->with('message', ['type' => 'error', 'message' => 'akun anda dibekukan tidak dapat melakukan transaksi']); } @@ -148,6 +148,10 @@ class DepositController extends Controller $is_valid = DepositHistory::STATUS_INVALID; } + if ($deposit->is_valid == DepositHistory::STATUS_VALID) { + return redirect()->route('transactions.deposit.show', ['deposit' => $deposit->id]); + } + $deposit->update([ 'is_valid' => $is_valid, 'payment_response' => json_encode($request->result), @@ -155,9 +159,19 @@ class DepositController extends Controller ]); if ($is_valid == DepositHistory::STATUS_VALID) { - $deposit->update_customer_balance(); + if ($deposit->type == DepositHistory::TYPE_REPAYMENT) { + $paylater = $deposit->paylater; + $paylater->update([ + 'credit' => $deposit->debit, + 'is_valid' => $deposit->is_valid, + ]); + $paylater->update_customer_paylater(); + } + + if ($deposit->type == DepositHistory::TYPE_DEPOSIT) { + $deposit->update_customer_balance(); + } } - // TODO: update for paylater DB::commit(); @@ -178,19 +192,30 @@ class DepositController extends Controller ]); if ($request->transaction_status == 'settlement' || $request->transaction_status == 'capture') { - $deposit->fill(['payment_status' => DepositHistory::STATUS_VALID]); - $deposit->update_customer_balance(); - $deposit->create_notification(); - $deposit->create_notification_user(); + $deposit->fill(['is_valid' => DepositHistory::STATUS_VALID]); + + if ($deposit->type == DepositHistory::TYPE_REPAYMENT) { + $paylater = $deposit->paylater; + $paylater->update([ + 'credit' => $deposit->debit, + 'is_valid' => $deposit->is_valid, + ]); + $paylater->update_customer_paylater(); + } + + if ($deposit->type == DepositHistory::TYPE_DEPOSIT) { + $deposit->update_customer_balance(); + $deposit->create_notification(); + $deposit->create_notification_user(); + } } elseif ($request->transaction_status == 'pending') { - $deposit->fill(['payment_status' => DepositHistory::STATUS_WAIT_PAYMENT]); + $deposit->fill(['is_valid' => DepositHistory::STATUS_WAIT_PAYMENT]); } else { - $deposit->fill(['payment_status' => DepositHistory::STATUS_INVALID]); + $deposit->fill(['is_valid' => DepositHistory::STATUS_INVALID]); } $deposit->save(); } - // TODO: update for paylater DB::commit(); diff --git a/app/Http/Controllers/Customer/PaylaterController.php b/app/Http/Controllers/Customer/PaylaterController.php index 9c1c319..d5b8701 100644 --- a/app/Http/Controllers/Customer/PaylaterController.php +++ b/app/Http/Controllers/Customer/PaylaterController.php @@ -29,7 +29,7 @@ class PaylaterController extends Controller if ($paylater->type == PaylaterHistory::TYPE_REPAYMENT) { $deposit = DepositHistory::where('related_id', $paylater->id)->first(); - if (! in_array($deposit->is_valid, [DepositHistory::STATUS_VALID])) { + if (!in_array($deposit->is_valid, [DepositHistory::STATUS_VALID])) { return redirect()->route('transactions.deposit.show', [ 'deposit' => $deposit, 'back' => 'customer.paylater.index', @@ -68,6 +68,14 @@ class PaylaterController extends Controller ->with('message', ['type' => 'error', 'message' => 'Nominal Tagihan tidak boleh lebih dari tagihan']); } + // alasan pembayaran tidak full + if ($customer->paylater->usage != $request->amount) { + $request->validate([ + 'not_fullpayment_reason' => 'required|string', + 'next_payment' => 'required|date', + ]); + } + // only 1 repayment at a time $repayment = DepositHistory::query() ->where([ @@ -89,6 +97,8 @@ class PaylaterController extends Controller $paylater = $customer->paylaterHistories()->create([ 'credit' => $request->amount, 'description' => $code, + 'not_fullpayment_reason' => $request->not_fullpayment_reason, + 'next_payment' => $request->next_payment, 'type' => PaylaterHistory::TYPE_REPAYMENT, ]); diff --git a/app/Models/PaylaterHistory.php b/app/Models/PaylaterHistory.php index dedf62a..355e721 100644 --- a/app/Models/PaylaterHistory.php +++ b/app/Models/PaylaterHistory.php @@ -38,6 +38,8 @@ class PaylaterHistory extends Model 'type', 'is_valid', 'image_prove', + 'next_payment', + 'not_fullpayment_reason', ]; protected $appends = [ @@ -71,10 +73,10 @@ class PaylaterHistory extends Model { return Attribute::make(get: function () { if ($this->credit == 0) { - return 'Rp '.number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.'); + return 'Rp ' . number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.'); } - return '-Rp '.number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.'); + return '-Rp ' . number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.'); }); } @@ -116,7 +118,7 @@ class PaylaterHistory extends Model { Notification::create([ 'entity_id' => $this->customer_id, - 'description' => 'Pembayaran '.$this->description.' sebesar '.$this->amount.' sudah sukses diterima', + 'description' => 'Pembayaran ' . $this->description . ' sebesar ' . $this->amount . ' sudah sukses diterima', ]); } diff --git a/database/migrations/2023_06_03_033734_create_paylater_histories_table.php b/database/migrations/2023_06_03_033734_create_paylater_histories_table.php index 72a5677..035c7c5 100644 --- a/database/migrations/2023_06_03_033734_create_paylater_histories_table.php +++ b/database/migrations/2023_06_03_033734_create_paylater_histories_table.php @@ -18,6 +18,8 @@ return new class extends Migration $table->decimal('credit', 20, 2)->default(0); $table->string('description')->nullable(); $table->text('note')->nullable(); + $table->timestamp('next_payment')->nullable(); + $table->string('not_fullpayment_reason')->nullable(); $table->ulid('customer_id')->nullable(); $table->smallInteger('type')->default(0); $table->smallInteger('is_valid')->default(0); diff --git a/resources/js/Components/FormInputDate.jsx b/resources/js/Components/FormInputDate.jsx index c7c3be8..e658cd9 100644 --- a/resources/js/Components/FormInputDate.jsx +++ b/resources/js/Components/FormInputDate.jsx @@ -1,28 +1,46 @@ -import React from "react"; -import DatePicker from "react-datepicker"; -import { converToDate, dateToString } from "@/utils"; +import React from 'react' +import DatePicker from 'react-datepicker' +import { converToDate, dateToString } from '@/utils' -export default function FormInputDate({ selected, onChange, label = '', error }) { +export default function FormInputDate({ + selected, + onChange, + label = '', + error, + placeholder = '', +}) { return (
{label !== '' && ( - + )} onChange(dateToString(date))} + onChange={(date) => onChange(dateToString(date))} closeOnScroll={true} shouldCloseOnSelect={true} dateFormat="dd/MM/yyyy" - className={`mb-2 bg-gray-50 border text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:placeholder-gray-400 dark:text-white ${error ? "border-red-500 dark:border-red-500 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500" : "border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500"}`} + className={`mb-2 bg-gray-50 border text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:placeholder-gray-400 dark:text-white ${ + error + ? 'border-red-500 dark:border-red-500 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500' + : 'border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500' + }`} nextMonthButtonLabel=">" previousMonthButtonLabel="<" nextYearButtonLabel=">" previousYearButtonLabel="<" + placeholderText={placeholder} /> {error && ( -

{error}

+

+ {error} +

)}
) -} \ No newline at end of file +} diff --git a/resources/js/Customer/Paylater/Repay.jsx b/resources/js/Customer/Paylater/Repay.jsx index 052185b..e886ed3 100644 --- a/resources/js/Customer/Paylater/Repay.jsx +++ b/resources/js/Customer/Paylater/Repay.jsx @@ -7,11 +7,15 @@ import { CASH_DEPOSIT } from '@/Customer/utils' import CustomerLayout from '@/Layouts/CustomerLayout' import Alert from '@/Components/Alert' import FormInputNumeric from '@/Components/FormInputNumeric' +import FormInput from '@/Components/FormInput' +import FormInputDate from '@/Components/FormInputDate' -export default function Repay({ payments, amount }) { +export default function Repay({ payments, amount, auth: { user } }) { const { data, setData, post, processing, errors } = useForm({ amount: amount, payment: '', + not_fullpayment_reason: '', + next_payment: '', }) const amounts = [amount] @@ -42,6 +46,8 @@ export default function Repay({ payments, amount }) { setData('payment', payment.name) } + const isNotFullPayment = +user.paylater.usage !== +data.amount + const handleSubmit = () => { if (processing) { return @@ -88,6 +94,27 @@ export default function Repay({ payments, amount }) { error={errors.amount} /> + {isNotFullPayment && ( +
+ + setData( + 'not_fullpayment_reason', + e.target.value + ) + } + error={errors.not_fullpayment_reason} + /> + setData('next_payment', date)} + error={errors.next_payment} + /> +
+ )}
Metode Pembayaran
{errors.payment && ( diff --git a/resources/js/Layouts/Partials/routes.js b/resources/js/Layouts/Partials/routes.js index da8e600..a1e4dbc 100644 --- a/resources/js/Layouts/Partials/routes.js +++ b/resources/js/Layouts/Partials/routes.js @@ -164,8 +164,8 @@ export default [ name: 'Pembayaran Hutang', // daftar pembayaran hutang yang perlu di konfirmasi , dan ada tombol add untuk pembayaran hutang oleh admin show: true, icon: HiCash, - route: route('paylater.index'), - active: 'paylater.*', + route: route('paylater.repay.index'), + active: 'paylater.repay.*', permission: 'view-paylater-repayment', }, { diff --git a/resources/js/Pages/CustomerHistory/PaylaterHistory.jsx b/resources/js/Pages/CustomerHistory/PaylaterHistory.jsx index 3ebf8d8..71b1500 100644 --- a/resources/js/Pages/CustomerHistory/PaylaterHistory.jsx +++ b/resources/js/Pages/CustomerHistory/PaylaterHistory.jsx @@ -146,7 +146,7 @@ export default function PaylaterHistory(props) { : - {deposit.reject_reason} + {deposit.note} {isEmpty(deposit.editor) === false && ( diff --git a/resources/js/Pages/Paylater/Detail.jsx b/resources/js/Pages/Paylater/Detail.jsx index 5b55b49..eabe058 100644 --- a/resources/js/Pages/Paylater/Detail.jsx +++ b/resources/js/Pages/Paylater/Detail.jsx @@ -2,63 +2,260 @@ import React from 'react' import { Head, Link } from '@inertiajs/react' import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' +import { isEmpty } from 'lodash' +import { formatIDDate, formatIDR } from '@/utils' export default function Detail(props) { - const { paylater } = props + const { paylater, deposit } = props return (
-
- {paylater.description} +
+
+ {paylater.description} +
- - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - -
Customer: - +
Customer: + + {paylater.customer.name} + +
Jumlah:{paylater.amount}
Status: - {paylater.customer.name} - -
Jumlah:{paylater.amount}
Status: - {paylater.status_text.text} -
Tanggal:{paylater.format_created_at}
+ {paylater.status_text.text} + + + + Tanggal + : + {paylater.format_created_at} + + + + Pembayaran Hutang + + : + + {isEmpty( + paylater.not_fullpayment_reason + ) === false ? ( +

Sebagian

+ ) : ( +

Penuh

+ )} + + + {isEmpty(paylater.next_payment) === + false && ( + + + Tanggal Pemenuhan + + : + + {formatIDDate( + paylater.next_payment + )} + + + )} + + + )} + {isEmpty(deposit) === false && ( + <> + + + + + + + + + + + + + {deposit.account !== null && ( + + + + + + )} + {deposit.deposit_location !== null && ( + + + + + + )} + + + + + + + + + + + + + + + + + + + + + {isEmpty(deposit.editor) === false && ( + + + + + + )} + + + + + + + + + + + {isEmpty( + deposit.paylater.next_payment + ) === false && ( + + + + + + )} + +
+ Customer + : + + {deposit.customer.name} + +
+ Metode Pembayaran + :{deposit.payment_channel}
+ Bank Akun + : + {deposit.account.name} ( + {deposit.account.bank_name}) +
+ Lokasi Cash / Setor Tunai + : + { + deposit.deposit_location + .name + } +
+ Jumlah + :{deposit.amount}
+ Admin Fee + : + Rp{' '} + {formatIDR(+deposit.admin_fee)} +
+ Status + : + {deposit.status.text} +
+ Alasan Penolakan + :{deposit.note}
+ Approver + :{deposit.editor.name}
+ Tanggal + :{deposit.format_created_at}
+ Pembayaran Hutang + : + {isEmpty( + deposit.paylater + .not_fullpayment_reason + ) === false ? ( +

Sebagian

+ ) : ( +

Penuh

+ )} +
+ Tanggal Pemenuhan + : + {formatIDDate( + deposit.paylater + .next_payment + )} +
+
+ {isEmpty(deposit.image_prove_url) === + false && ( +
+ + + +
+ )} +
+ + )}
diff --git a/resources/js/Pages/Paylater/Form.jsx b/resources/js/Pages/Paylater/Form.jsx index c7e5bd3..d4b1fe7 100644 --- a/resources/js/Pages/Paylater/Form.jsx +++ b/resources/js/Pages/Paylater/Form.jsx @@ -12,7 +12,7 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' import FormInput from '@/Components/FormInput' import Button from '@/Components/Button' import FormInputNumeric from '@/Components/FormInputNumeric' -import { formatIDR } from '@/utils' +import { formatIDDate, formatIDR } from '@/utils' export default function Form(props) { const { deposit } = props @@ -39,7 +39,7 @@ export default function Form(props) { +deposit.is_valid === STATUS_WAIT_UPLOAD const handleSubmit = () => { - post(route('paylater.update', deposit)) + post(route('paylater.repay.update', deposit)) } useEffect(() => { @@ -57,7 +57,7 @@ export default function Form(props) { @@ -74,7 +74,7 @@ export default function Form(props) { : : - {deposit.reject_reason} + {deposit.note} {isEmpty(deposit.editor) === false && ( @@ -145,6 +145,36 @@ export default function Form(props) { : {deposit.format_created_at} + + + Pembayaran Hutang + + : + + {isEmpty( + deposit.paylater + .not_fullpayment_reason + ) === false ? ( +

Sebagian

+ ) : ( +

Penuh

+ )} + + + {isEmpty(deposit.paylater.next_payment) === + false && ( + + + Tanggal Pemenuhan + + : + + {formatIDDate( + deposit.paylater.next_payment + )} + + + )} @@ -167,7 +197,7 @@ export default function Form(props) {
name('deposit.update'); // repayment - Route::get('/paylater', [PaylaterController::class, 'index'])->name('paylater.index'); - Route::get('/paylater/{paylater}', [PaylaterController::class, 'show'])->name('paylater.show'); - Route::get('/paylater/{deposit}/edit', [PaylaterController::class, 'edit'])->name('paylater.edit'); - Route::post('/paylater/{deposit}', [PaylaterController::class, 'update'])->name('paylater.update'); + Route::get('/paylater', [PaylaterController::class, 'index'])->name('paylater.repay.index'); + Route::get('/paylater/{paylater}', [PaylaterController::class, 'show'])->name('paylater.repay.show'); + Route::get('/paylater/{deposit}/edit', [PaylaterController::class, 'edit'])->name('paylater.repay.edit'); + Route::post('/paylater/{deposit}', [PaylaterController::class, 'update'])->name('paylater.repay.update'); // poin rewared Route::get('/bonus-poin', [PoinRewardController::class, 'index'])->name('poin-reward.index');