Merge pull request #8 from alealien666/manualPay

cek denda with update index manual payment
This commit is contained in:
AleAlien 2025-02-12 22:01:29 +07:00 committed by GitHub
commit 312eb6d4ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 38 deletions

View File

@ -6,17 +6,17 @@
use Illuminate\Http\Request;
use App\Models\Santri;
use Inertia\Inertia;
use App\Services\cekDenda;
class PaymentController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index() {}
public function indexManualPayment()
{
$santri = Santri::with('payments', 'payments.detailPayments', 'payments.detailPayments.paymentType')->get();
$santri = Santri::with(['payments.detailPayments.paymentType'])
->withSum(['payments.detailPayments as total_penalty' => function ($query) {
$query->whereNotNull('penalty');
}], 'penalty')
->get();
return Inertia::render('list-admin/payment/ManualPayment', [
'santri' => $santri,
@ -25,9 +25,11 @@ public function indexManualPayment()
'nama' => 'text',
'status_santri' => 'text',
'role_santri' => 'text',
'penalty' => 'text',
'amount' => 'text'
'total_penalty' => 'text',
'amount' => 'text',
]
]);
}
public function manualPayment() {}
}

View File

@ -1,30 +0,0 @@
<?php
namespace App\Services;
use App\Models\DetailPayment;
use Illuminate\Support\Carbon;
class CekDenda
{
public function cekDenda()
{
$prevMonth = Carbon::now()->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'];
}
}

44
app/Services/cekDenda.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace App\Services;
use App\Models\DetailPayment;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class cekDenda
{
public function applyPenalty()
{
$previousMonth = Carbon::now()->subMonth()->month;
$previousYear = Carbon::now()->subMonth()->year;
$currentDay = Carbon::now()->day;
$penaltyAmount = 20000;
if ($currentDay >= 10) {
DB::beginTransaction();
try {
$unpaidPayments = DetailPayment::where('status', 'unpaid')
->where('payment_month', $previousMonth)
->where('payment_year', $previousYear)
->get();
foreach ($unpaidPayments as $payment) {
if (is_null($payment->penalty)) {
$payment->update([
'penalty' => $penaltyAmount
]);
}
}
DB::commit();
return ['message' => 'Penalty applied successfully'];
} catch (\Exception $e) {
DB::rollBack();
return ['error' => $e->getMessage()];
}
}
return ['message' => 'Not yet time for penalty application'];
}
}