Changeset View
Changeset View
Standalone View
Standalone View
src/app/Wallet.php
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | public function chargeEntitlements($apply = true) | ||||
if ($entitlement->created_at > Carbon::now()->subDays(14)) { | if ($entitlement->created_at > Carbon::now()->subDays(14)) { | ||||
continue; | continue; | ||||
} | } | ||||
// This entitlement was created, or billed last, less than a month ago. | // This entitlement was created, or billed last, less than a month ago. | ||||
if ($entitlement->updated_at > Carbon::now()->subMonthsWithoutOverflow(1)) { | if ($entitlement->updated_at > Carbon::now()->subMonthsWithoutOverflow(1)) { | ||||
continue; | continue; | ||||
} | } | ||||
machniak: Removed line that should not be removed. | |||||
// updated last more than a month ago -- was it billed? | // updated last more than a month ago -- was it billed? | ||||
if ($entitlement->updated_at <= Carbon::now()->subMonthsWithoutOverflow(1)) { | if ($entitlement->updated_at <= Carbon::now()->subMonthsWithoutOverflow(1)) { | ||||
$diff = $entitlement->updated_at->diffInMonths(Carbon::now()); | $diff = $entitlement->updated_at->diffInMonths(Carbon::now()); | ||||
$cost = (int) ($entitlement->cost * $discount * $diff); | $cost = (int) ($entitlement->cost * $discount * $diff); | ||||
$charges += $cost; | $charges += $cost; | ||||
// if we're in dry-run, you know... | // if we're in dry-run, you know... | ||||
if (!$apply) { | if (!$apply) { | ||||
continue; | continue; | ||||
} | } | ||||
$period_start = $entitlement->updated_at->copy(); | |||||
$entitlement->updated_at = $entitlement->updated_at->copy() | $entitlement->updated_at = $entitlement->updated_at->copy() | ||||
->addMonthsWithoutOverflow($diff); | ->addMonthsWithoutOverflow($diff); | ||||
$period_end = $entitlement->updated_at->copy(); | |||||
$entitlement->save(); | $entitlement->save(); | ||||
if ($cost == 0) { | if ($cost == 0) { | ||||
continue; | continue; | ||||
} | } | ||||
$entitlementTransactions[] = $entitlement->createTransaction( | $entitlementTransactions[] = $entitlement->createTransaction( | ||||
\App\Transaction::ENTITLEMENT_BILLED, | \App\Transaction::ENTITLEMENT_BILLED, | ||||
$cost | $cost, | ||||
$period_start, | |||||
$period_end | |||||
); | ); | ||||
} | } | ||||
} | } | ||||
if ($apply) { | if ($apply) { | ||||
$this->debit($charges, $entitlementTransactions); | $this->debit($charges, $entitlementTransactions); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines |
Removed line that should not be removed.