mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Small adjustments to fix tests.
This commit is contained in:
parent
d804093f8b
commit
6591fa9fb4
@ -424,7 +424,7 @@ class ReconcileController extends Controller
|
||||
'interest_date' => null,
|
||||
'book_date' => null,
|
||||
'transactions' => [[
|
||||
'currency_id' => $journal->transaction_currency_id,
|
||||
'currency_id' => intval($journal->transaction_currency_id),
|
||||
'currency_code' => null,
|
||||
'description' => null,
|
||||
'amount' => app('steam')->positive($submitted['amount']),
|
||||
|
@ -150,23 +150,22 @@ class BulkController extends Controller
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journal = $repository->find(intval($journalId));
|
||||
if (!is_null($journal)) {
|
||||
// TODO need to move this to update service.
|
||||
$count++;
|
||||
Log::debug(sprintf('Found journal #%d', $journal->id));
|
||||
// update category if not told to ignore
|
||||
if ($ignoreCategory === false) {
|
||||
Log::debug(sprintf('Set category to %s', $request->string('category')));
|
||||
|
||||
$service->updateCategory($journal, $request->string('category'));
|
||||
$repository->updateCategory($journal, $request->string('category'));
|
||||
}
|
||||
// update budget if not told to ignore (and is withdrawal)
|
||||
if ($ignoreBudget === false) {
|
||||
Log::debug(sprintf('Set budget to %d', $request->integer('budget_id')));
|
||||
$service->updateBudget($journal, $request->integer('budget_id'));
|
||||
$repository->updateBudget($journal, $request->integer('budget_id'));
|
||||
}
|
||||
if ($ignoreTags === false) {
|
||||
Log::debug(sprintf('Set tags to %s', $request->string('budget_id')));
|
||||
$service->updateTags($journal, explode(',', $request->string('tags')));
|
||||
$repository->updateTags($journal, explode(',', $request->string('tags')));
|
||||
}
|
||||
// update tags if not told to ignore (and is withdrawal)
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Events\StoredTransactionJournal;
|
||||
use FireflyIII\Events\UpdatedTransactionJournal;
|
||||
use FireflyIII\Factory\TransactionJournalFactory;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\JournalFormRequest;
|
||||
@ -366,13 +365,7 @@ class SingleController extends Controller
|
||||
'foreign_amount' => null,
|
||||
],
|
||||
];
|
||||
var_dump($data);exit;
|
||||
// todo call factory instead of repository
|
||||
/** @var TransactionJournalFactory $factory */
|
||||
$factory = app(TransactionJournalFactory::class);
|
||||
$factory->setUser(auth()->user());
|
||||
$journal = $factory->create($data);
|
||||
//$journal = $repository->store($data);
|
||||
$journal = $repository->store($data);
|
||||
if (null === $journal->id) {
|
||||
// error!
|
||||
Log::error('Could not store transaction journal: ', $journal->getErrors()->toArray());
|
||||
|
@ -61,13 +61,13 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $moveTo
|
||||
* @param Account|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Account $account, Account $moveTo): bool
|
||||
public function destroy(Account $account, ?Account $moveTo): bool
|
||||
{
|
||||
/** @var AccountDestroyService $service */
|
||||
$service = app(AccountDestroyService::class);
|
||||
|
@ -48,11 +48,11 @@ interface AccountRepositoryInterface
|
||||
* Moved here from account CRUD.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Account $moveTo
|
||||
* @param Account|null $moveTo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Account $account, Account $moveTo): bool;
|
||||
public function destroy(Account $account, ?Account $moveTo): bool;
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
|
@ -106,8 +106,8 @@ class BillRepository implements BillRepositoryInterface
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->bills()
|
||||
->where('active', 1)
|
||||
->sortBy('name')
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
|
||||
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),])
|
||||
->sortBy('name');
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
@ -195,6 +195,18 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account of transaction that is more than zero. Only works with unsplit journals.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||
{
|
||||
return $journal->transactions()->where('amount', '<', 0)->first()->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
@ -205,6 +217,18 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $journal->notes()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account of transaction that is less than zero. Only works with unsplit journals.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function getSourceAccount(TransactionJournal $journal): Account
|
||||
{
|
||||
return $journal->transactions()->where('amount', '>', 0)->first()->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@ -318,26 +342,55 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account of transaction that is more than zero. Only works with unsplit journals.
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return Account
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||
public function updateBudget(TransactionJournal $journal, int $budgetId): TransactionJournal
|
||||
{
|
||||
return $journal->transactions()->where('amount','<',0)->first()->account;
|
||||
/** @var JournalUpdateService $service */
|
||||
$service = app(JournalUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
|
||||
return $service->updateBudget($journal, $budgetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account of transaction that is less than zero. Only works with unsplit journals.
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
*
|
||||
* @return Account
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getSourceAccount(TransactionJournal $journal): Account
|
||||
public function updateCategory(TransactionJournal $journal, string $category): TransactionJournal
|
||||
{
|
||||
return $journal->transactions()->where('amount','>',0)->first()->account;
|
||||
/** @var JournalUpdateService $service */
|
||||
$service = app(JournalUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
|
||||
return $service->updateCategory($journal, $category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update tag(s) for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateTags(TransactionJournal $journal, array $tags): TransactionJournal
|
||||
{
|
||||
/** @var JournalUpdateService $service */
|
||||
$service = app(JournalUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
$service->connectTags($journal, $tags);
|
||||
|
||||
return $journal;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -171,4 +171,34 @@ interface JournalRepositoryInterface
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function update(TransactionJournal $journal, array $data): TransactionJournal;
|
||||
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateBudget(TransactionJournal $journal, int $budgetId): TransactionJournal;
|
||||
|
||||
/**
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateCategory(TransactionJournal $journal, string $category): TransactionJournal;
|
||||
|
||||
/**
|
||||
* Update tag(s) for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateTags(TransactionJournal $journal, array $tags): TransactionJournal;
|
||||
}
|
||||
|
@ -73,6 +73,9 @@ trait JournalServiceTrait
|
||||
$factory = app(TagFactory::class);
|
||||
$factory->setUser($journal->user);
|
||||
$set = [];
|
||||
if (!is_array($data['tags'])) {
|
||||
return;
|
||||
}
|
||||
foreach ($data['tags'] as $string) {
|
||||
if (strlen($string) > 0) {
|
||||
$tag = $factory->findOrCreate($string);
|
||||
|
@ -23,10 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Factory\BillFactory;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Factory\TransactionFactory;
|
||||
use FireflyIII\Factory\TransactionJournalMetaFactory;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Services\Internal\Support\JournalServiceTrait;
|
||||
@ -128,4 +125,48 @@ class JournalUpdateService
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateBudget(TransactionJournal $journal, int $budgetId): TransactionJournal
|
||||
{
|
||||
/** @var TransactionUpdateService $service */
|
||||
$service = app(TransactionUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$service->updateBudget($transaction, $budgetId);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateCategory(TransactionJournal $journal, string $category): TransactionJournal
|
||||
{
|
||||
/** @var TransactionUpdateService $service */
|
||||
$service = app(TransactionUpdateService::class);
|
||||
$service->setUser($this->user);
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($journal->transactions as $transaction) {
|
||||
$service->updateCategory($transaction, $category);
|
||||
}
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,6 @@ class TransactionUpdateService
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
|
||||
/**
|
||||
* @param int $transactionId
|
||||
*
|
||||
@ -130,5 +129,36 @@ class TransactionUpdateService
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public function updateBudget(Transaction $transaction, int $budgetId): Transaction
|
||||
{
|
||||
$budget = $this->findBudget($budgetId, null);
|
||||
$this->setBudget($transaction, $budget);
|
||||
|
||||
return $transaction;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param Transaction $transaction
|
||||
* @param string $category
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public function updateCategory(Transaction $transaction, string $category): Transaction
|
||||
{
|
||||
$category = $this->findCategory(0, $category);
|
||||
$this->setCategory($transaction, $category);
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
@ -137,11 +137,12 @@ class SetDestinationAccount implements ActionInterface
|
||||
if (null === $account) {
|
||||
// create new revenue account with this name:
|
||||
$data = [
|
||||
'name' => $this->action->action_value,
|
||||
'accountType' => 'expense',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
'name' => $this->action->action_value,
|
||||
'accountType' => 'expense',
|
||||
'account_type_id' => null,
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
];
|
||||
$account = $this->repository->store($data);
|
||||
}
|
||||
|
@ -136,11 +136,12 @@ class SetSourceAccount implements ActionInterface
|
||||
if (null === $account) {
|
||||
// create new revenue account with this name:
|
||||
$data = [
|
||||
'name' => $this->action->action_value,
|
||||
'accountType' => 'revenue',
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
'name' => $this->action->action_value,
|
||||
'accountType' => 'revenue',
|
||||
'account_type_id' => null,
|
||||
'virtualBalance' => 0,
|
||||
'active' => true,
|
||||
'iban' => null,
|
||||
];
|
||||
$account = $this->repository->store($data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user