Move method to correct repository.

This commit is contained in:
James Cole
2019-08-30 09:19:29 +02:00
parent 134d1b2746
commit 717b9d21fd
12 changed files with 291 additions and 312 deletions

View File

@@ -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;
}
}