Skip to content

Commit

Permalink
fix: improve rollover service
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero committed Nov 30, 2023
1 parent a5e3edc commit 739d119
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/Console/Commands/TeamBudgetRollover.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TeamBudgetRollover extends Command
*
* @var string
*/
protected $signature = 'app:team-budget-rollover {teamId}';
protected $signature = 'app:team-budget-rollover {teamId} ?{date}';

/**
* The console command description.
Expand All @@ -31,6 +31,7 @@ public function handle(BudgetRolloverService $rolloverService)
{

$teamId = $this->argument('teamId');
$date = $this->argument('date');

$monthsWithTransactions = DB::table('transaction_lines')
->where([
Expand All @@ -41,6 +42,6 @@ public function handle(BudgetRolloverService $rolloverService)
->orderBy('date')
->first();

$rolloverService->startFrom($teamId, $monthsWithTransactions->date);
$rolloverService->startFrom($teamId, $date ?? $monthsWithTransactions->date);
}
}
4 changes: 2 additions & 2 deletions app/Domains/Budget/Services/BudgetRolloverService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private function reduceOverspent() {
// Not seeing an Underfunded Alert in your Credit Card Payment category? We're testing this new feature in stages and releasing it to everyone soon.
}

public function startFrom($teamId, $date) {
public function startFrom($teamId, $yearMonth) {
$categories = Category::where([
'team_id' => $teamId,
])
Expand All @@ -167,7 +167,7 @@ public function startFrom($teamId, $date) {
$monthsWithTransactions = DB::table('transaction_lines')
->selectRaw("date_format(transaction_lines.date, '%Y-%m') AS date")
->groupBy(DB::raw("date_format(transaction_lines.date, '%Y-%m')"))
->whereRaw("date_format(transaction_lines.date, '%Y-%m') >= ?", [$date])
->whereRaw("date_format(transaction_lines.date, '%Y-%m') >= ?", [$yearMonth])
->get()
->pluck('date');

Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/CreateBudgetMovement.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public function __construct()
public function handle(BudgetAssigned $event)
{
// BudgetMovement::registerMovement($event->monthBudget, $this->formData);
(new BudgetRolloverService(new BudgetCategoryService()))->startFrom($event->budgetMonth->team_id, $event->budgetMonth->date);
(new BudgetRolloverService(new BudgetCategoryService()))->startFrom($event->budgetMonth->team_id, substr($event->budgetMonth->date, 0, 7));
}
}
1 change: 0 additions & 1 deletion resources/js/domains/budget/useBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const BudgetState = reactive({
const availableForFunding = parseFloat(category.activity ?? 0);
const fundedSpending = parseFloat(category?.funded_spending ?? 0);
const assigned = budgetTotals.budgeted;
const isCurrentMonth = category.month == format(new Date(), 'yyyy-MM-01')
const leftOVer = parseFloat(category.left_from_last_month ?? 0)
const balance = (leftOVer + availableForFunding) - (parseFloat(category.overspending_previous_month ?? 0) + parseFloat(budgetTotals.budgeted ?? 0));

Expand Down

0 comments on commit 739d119

Please sign in to comment.