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 (
{error}
++ {error} +
)}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} | -
Sebagian
+ ) : ( +Penuh
+ )} ++ 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 + )} + | +
Sebagian
+ ) : ( +Penuh
+ )} +