Skip to content

Commit

Permalink
72. fix getting next payment date for installment
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Jan 28, 2025
1 parent 36490b9 commit 17dc00e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/Models/Payments/Installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use App\Models\Orders\Order;
use App\Models\Orders\OrderItem;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Support\Carbon;

/**
* @property int $id
Expand Down Expand Up @@ -88,8 +88,10 @@ public function order(): HasOneThrough
*/
public function getNextPaymentDate(): Carbon
{
if (empty($this->nextPaymentDate)) {
$this->nextPaymentDate = $this->created_at->copy()->setMonth(now()->month);
if (!$this->nextPaymentDate) {
$this->nextPaymentDate = $this->created_at->copy()
->setYear(now()->year)
->setMonth(now()->month);

if ($this->nextPaymentDate->isPast()) {
$this->nextPaymentDate->addMonth();
Expand Down

0 comments on commit 17dc00e

Please sign in to comment.