bit fix paylater use

dev
Aji Kamaludin 1 year ago
parent bdf416300a
commit f1ed0f8808
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -7,6 +7,7 @@ use App\Models\Customer;
use App\Models\PaylaterHistory;
use App\Services\GeneralService;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class PaylaterController extends Controller
@ -79,8 +80,15 @@ class PaylaterController extends Controller
DB::beginTransaction();
$customer = Customer::find($request->customer_id);
$customer->paylater->update([
$paylater = $customer->paylater;
if ($paylater->day_deadline_at != null) {
$paylater->day_deadline_at = Carbon::parse($paylater->day_deadline_at)
->addDays($request->day_deadline - $paylater->day_deadline);
}
$paylater->update([
'day_deadline' => $request->day_deadline,
'day_deadline_at' => $paylater->day_deadline_at,
]);
$customer->partner()->updateOrCreate([

@ -2,6 +2,9 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Carbon;
class PaylaterCustomer extends Model
{
protected $fillable = [
@ -13,8 +16,24 @@ class PaylaterCustomer extends Model
'day_deadline_at',
];
protected $appends = [
'paylater_description'
];
public function customer()
{
return $this->hasOne(Customer::class, 'customer_id', 'id');
}
public function paylaterDescription(): Attribute
{
return Attribute::make(get: function () {
if ($this->day_deadline_at != null) {
$deadlineAt = Carbon::parse($this->day_deadline_at)->translatedFormat('d F Y');
return "lunasi pinjaman kamu sebelum jatuh tempo pada {$deadlineAt}";
}
return "yuk gunakan terus saldo yang tersedia";
});
}
}

@ -50,9 +50,14 @@ class PaylaterHistory extends Model
{
$customer = Customer::find($this->customer_id);
$paylater = $customer->paylater;
if ($paylater->day_deadline_at == null) {
$paylater->day_deadline_at = now()->addDays($paylater->day_deadline);
}
$paylater->update([
'usage' => $paylater->usage + $this->debit - $this->credit,
// TODO: add day dateline
'day_deadline_at' => $paylater->day_deadline_at,
]);
}

@ -63,9 +63,7 @@ export default function Index({
className="mx-auto px-4 mt-4 py-2 text-xs text-blue-800 rounded-lg bg-blue-50 flex flex-row space-x-2 w-full items-center"
role="alert"
>
<div>
lunasi pinjaman kamu sebelum jatuh tempo pada ...
</div>
<div>{user.paylater.paylater_description}</div>
</div>
</div>
<div className="w-full">

Loading…
Cancel
Save