/** * @param Budget $budget * * @return Carbon */ public function firstActivity(Budget $budget) { $first = $budget->transactionjournals()->orderBy('date', 'ASC')->first(); if ($first) { return $first->date; } return new Carbon(); }
/** * @param Budget $budget * @param Carbon $date * * @return float */ public function expensesOnDayCorrected(Budget $budget, Carbon $date) { bcscale(2); $sum = $budget->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount'); return bcmul($sum, -1); }
/** * @param Budget $budget * @param Carbon $date * * @return float */ public function expensesOnDay(Budget $budget, Carbon $date) { bcscale(2); $sum = $budget->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->onDate($date)->get(['transaction_journals.*'])->sum('amount'); return $sum; }
/** * @param Budget $budget * @param Carbon $date * * @return float */ public function expensesOnDayCorrected(Budget $budget, Carbon $date) { $sum = floatval($budget->transactionjournals()->transactionTypes(['Withdrawal'])->onDate($date)->get(['transaction_journals.*'])->sum('amount')); return $sum * -1; }