From 6c73c3b808ce8a8e26718d836add2a5dac99e75a Mon Sep 17 00:00:00 2001 From: alealien666 Date: Wed, 12 Feb 2025 19:20:50 +0700 Subject: [PATCH] update service and model manual payment --- app/Http/Controllers/PaymentController.php | 56 ++----------------- app/Models/DetailPayment.php | 9 ++- app/Service/cekDenda.php | 30 ++++++++++ .../2014_10_12_000000_create_users_table.php | 2 +- ...28_080123_create_detail_payments_table.php | 6 +- 5 files changed, 44 insertions(+), 59 deletions(-) create mode 100644 app/Service/cekDenda.php diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 5efba92..f8224d0 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -14,7 +14,7 @@ class PaymentController extends Controller */ public function index() {} - public function manualPayment() + public function indexManualPayment() { $santri = Santri::with('payments', 'payments.detailPayments', 'payments.detailPayments.paymentType')->get(); @@ -22,56 +22,12 @@ public function manualPayment() 'santri' => $santri, 'fields' => [ 'nis' => 'text', - + 'nama' => 'text', + 'status_santri' => 'text', + 'role_santri' => 'text', + 'penalty' => 'text', + 'amount' => 'text' ] ]); } - - /** - * Show the form for creating a new resource. - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - */ - public function store(Request $request) - { - // - } - - /** - * Display the specified resource. - */ - public function show(Payment $payment) - { - // - } - - /** - * Show the form for editing the specified resource. - */ - public function edit(Payment $payment) - { - // - } - - /** - * Update the specified resource in storage. - */ - public function update(Request $request, Payment $payment) - { - // - } - - /** - * Remove the specified resource from storage. - */ - public function destroy(Payment $payment) - { - // - } } diff --git a/app/Models/DetailPayment.php b/app/Models/DetailPayment.php index 4194a03..0f7a5eb 100644 --- a/app/Models/DetailPayment.php +++ b/app/Models/DetailPayment.php @@ -14,11 +14,10 @@ class DetailPayment extends Model public static function cekTunggakan($santri_id) { - return self::where('status', 'belum bayar') - ->whereHas('payment', function ($query) use ($santri_id) { - $query->where('santri_id', $santri_id); - })->orderBy('tahun_pembayaran', 'asc') - ->orderBy('bulan_pembayaran', 'asc')->first(); + + return self::where('status', 'unpaid')->whereHas('payment', function ($query) use ($santri_id) { + $query->where('santri_id', $santri_id); + })->orderBy('payment_year', 'asc')->orderBy('payment_month')->get(); } public function payment() diff --git a/app/Service/cekDenda.php b/app/Service/cekDenda.php new file mode 100644 index 0000000..29e27a7 --- /dev/null +++ b/app/Service/cekDenda.php @@ -0,0 +1,30 @@ +subMonth()->month; + $prevYear = Carbon::now()->subMonth()->year; + $now = Carbon::now()->day; + + if ($now >= 10) { + $arrears = DetailPayment::where('status', 'unpaid') + ->where('payment_month', $prevMonth) + ->where('payment_year', $prevYear)->get(); + + foreach ($arrears as $arrear) { + $arrear->update([ + 'penalty' => 20000 + ]); + } + } + + return ['message' => 'Berhasil']; + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 8cea83e..c4608e6 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id(); $table->string('nis'); $table->string('password'); - $table->string('role'); + $table->string('level'); $table->foreignId('santri_id')->constrained('santris')->onDelete('cascade'); $table->rememberToken(); $table->timestamps(); diff --git a/database/migrations/2025_01_28_080123_create_detail_payments_table.php b/database/migrations/2025_01_28_080123_create_detail_payments_table.php index 77dbac7..db9bb8e 100644 --- a/database/migrations/2025_01_28_080123_create_detail_payments_table.php +++ b/database/migrations/2025_01_28_080123_create_detail_payments_table.php @@ -14,11 +14,11 @@ public function up(): void Schema::create('detail_payments', function (Blueprint $table) { $table->id(); $table->foreignId('payment_id')->constrained('payments')->onDelete('cascade'); - $table->enum('status', ['bayar', 'belum bayar']); + $table->enum('status', ['paid', 'unpaid']); $table->float('amount'); $table->float('penalty')->nullable(); - $table->integer('bulan_pembayaran'); - $table->integer('tahun_pembayaran'); + $table->integer('payment_month'); + $table->integer('payment_year'); $table->foreignId('type_id')->constrained('payment_types')->onDelete('cascade'); $table->timestamps(); });