mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Move method to correct repository.
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\User;
|
||||
@@ -175,5 +176,34 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
* @param array $data
|
||||
*
|
||||
* @return AvailableBudget
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function updateAvailableBudget(AvailableBudget $availableBudget, array $data): AvailableBudget
|
||||
{
|
||||
$existing = $this->user->availableBudgets()
|
||||
->where('transaction_currency_id', $data['currency_id'])
|
||||
->where('start_date', $data['start']->format('Y-m-d 00:00:00'))
|
||||
->where('end_date', $data['end']->format('Y-m-d 00:00:00'))
|
||||
->where('id', '!=', $availableBudget->id)
|
||||
->first();
|
||||
|
||||
if (null !== $existing) {
|
||||
throw new FireflyException(sprintf('An entry already exists for these parameters: available budget object with ID #%d', $existing->id));
|
||||
}
|
||||
$availableBudget->transaction_currency_id = $data['currency_id'];
|
||||
$availableBudget->start_date = $data['start'];
|
||||
$availableBudget->end_date = $data['end'];
|
||||
$availableBudget->amount = $data['amount'];
|
||||
$availableBudget->save();
|
||||
|
||||
return $availableBudget;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user