Merge pull request #8 from alealien666/manualPay
cek denda with update index manual payment
This commit is contained in:
commit
312eb6d4ea
|
@ -6,17 +6,17 @@
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Santri;
|
use App\Models\Santri;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
|
use App\Services\cekDenda;
|
||||||
|
|
||||||
class PaymentController extends Controller
|
class PaymentController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*/
|
|
||||||
public function index() {}
|
|
||||||
|
|
||||||
public function indexManualPayment()
|
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', [
|
return Inertia::render('list-admin/payment/ManualPayment', [
|
||||||
'santri' => $santri,
|
'santri' => $santri,
|
||||||
|
@ -25,9 +25,11 @@ public function indexManualPayment()
|
||||||
'nama' => 'text',
|
'nama' => 'text',
|
||||||
'status_santri' => 'text',
|
'status_santri' => 'text',
|
||||||
'role_santri' => 'text',
|
'role_santri' => 'text',
|
||||||
'penalty' => 'text',
|
'total_penalty' => 'text',
|
||||||
'amount' => 'text'
|
'amount' => 'text',
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function manualPayment() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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'];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue