Rename various methods.

This commit is contained in:
James Cole 2018-08-11 19:21:58 +02:00
parent 95ce72fce7
commit a35c6e29b6
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
15 changed files with 79 additions and 36 deletions

View File

@ -138,12 +138,12 @@ class PopupReport implements PopupReportInterface
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
// filter for transfers and withdrawals TO the given $account
$journals = $journals->filter(
$transactions = $transactions->filter(
function (Transaction $transaction) use ($report, $repository) {
// get the destinations:
$sources = $repository->getJournalSourceAccounts($transaction->transactionJournal)->pluck('id')->toArray();
@ -153,7 +153,7 @@ class PopupReport implements PopupReportInterface
}
);
return $journals;
return $transactions;
}
/**
@ -173,11 +173,11 @@ class PopupReport implements PopupReportInterface
$collector = app(TransactionCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER]);
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
// filter the set so the destinations outside of $attributes['accounts'] are not included.
$journals = $journals->filter(
$transactions = $transactions->filter(
function (Transaction $transaction) use ($report, $repository) {
// get the destinations:
$journal = $transaction->transactionJournal;
@ -188,6 +188,6 @@ class PopupReport implements PopupReportInterface
}
);
return $journals;
return $transactions;
}
}

View File

@ -86,7 +86,7 @@ class ReportHelper implements ReportHelperInterface
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($payDate, $endOfPayPeriod)->setBills($bills);
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
$billLine = new BillLine;
$billLine->setBill($bill);
@ -95,7 +95,7 @@ class ReportHelper implements ReportHelperInterface
$billLine->setMin((string)$bill->amount_min);
$billLine->setMax((string)$bill->amount_max);
$billLine->setHit(false);
$entry = $journals->filter(
$entry = $transactions->filter(
function (Transaction $transaction) use ($bill) {
return $transaction->bill_id === $bill->id;
}

View File

@ -601,10 +601,10 @@ class BudgetController extends Controller
$collector = app(TransactionCollectorInterface::class);
$types = [TransactionType::WITHDRAWAL];
$collector->setAllAssetAccounts()->setTypes($types)->setRange($start, $end)->withoutBudget();
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
$sum = '0';
/** @var Transaction $entry */
foreach ($journals as $entry) {
foreach ($transactions as $entry) {
$sum = bcadd($entry->transaction_amount, $sum);
}

View File

@ -240,7 +240,7 @@ class TagRepository implements TagRepositoryInterface
$collector->setAllAssetAccounts()->setTag($tag)->withOpposingAccount();
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
$sums = [
TransactionType::WITHDRAWAL => '0',
@ -248,9 +248,9 @@ class TagRepository implements TagRepositoryInterface
TransactionType::TRANSFER => '0',
];
foreach ($journals as $journal) {
$amount = app('steam')->positive((string)$journal->transaction_amount);
$type = $journal->transaction_type_type;
foreach ($transactions as $transaction) {
$amount = app('steam')->positive((string)$transaction->transaction_amount);
$type = $transaction->transaction_type_type;
if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1');
}

View File

@ -26,8 +26,10 @@ namespace FireflyIII\Services\Internal\Destroy;
use DB;
use Exception;
use FireflyIII\Models\Account;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Database\Eloquent\Builder;
use Log;
/**
@ -44,8 +46,13 @@ class AccountDestroyService
*/
public function destroy(Account $account, ?Account $moveTo): void
{
if (null !== $moveTo) {
DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]);
// also update recurring transactions:
DB::table('recurrences_transactions')->where('source_id', $account->id)->update(['source_id', $moveTo->id]);
DB::table('recurrences_transactions')->where('destination_id', $account->id)->update(['destination_id', $moveTo->id]);
}
$service = app(JournalDestroyService::class);
@ -62,6 +69,24 @@ class AccountDestroyService
$service->destroy($journal);
}
}
// delete recurring transactions with this account:
if (null === $moveTo) {
$recurrences = RecurrenceTransaction::
where(
function (Builder $q) use ($account) {
$q->where('source_id', $account->id);
$q->orWhere('destination_id', $account->id);
}
)->get(['recurrence_id'])->pluck('recurrence_id')->toArray();
$destroyService = new RecurrenceDestroyService();
foreach ($recurrences as $recurrenceId) {
$destroyService->destroyById((int)$recurrenceId);
}
}
try {
$account->delete();
} catch (Exception $e) { // @codeCoverageIgnore

View File

@ -69,4 +69,19 @@ class RecurrenceDestroyService
}
}
/**
* Delete recurrence by ID
*
* @param int $recurrenceId
*/
public function destroyById(int $recurrenceId): void
{
$recurrence = Recurrence::find($recurrenceId);
if (null === $recurrence) {
return;
}
$this->destroy($recurrence);
}
}

View File

@ -346,12 +346,12 @@ trait PeriodOverview
$collector = app(TransactionCollectorInterface::class);
$collector->setAllAssetAccounts()->setRange($currentDate['start'], $currentDate['end'])->withOpposingAccount()->setTypes($types);
$collector->removeFilter(InternalTransferFilter::class);
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
if ($journals->count() > 0) {
$sums = $this->sumPerCurrency($journals);
if ($transactions->count() > 0) {
$sums = $this->sumPerCurrency($transactions);
$dateName = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
$sum = $journals->sum('transaction_amount');
$sum = $transactions->sum('transaction_amount');
/** @noinspection PhpUndefinedMethodInspection */
$entries->push(
[

View File

@ -148,8 +148,8 @@ trait RequestInformation
}
// get help content from Github:
$content = $help->getFromGitHub($route, $language);
$content = $help->getFromGitHub($route, $language);
$originalLanguage = $language;
// content will have 0 length when Github failed. Try en_US when it does:
if ('' === $content) {
$language = 'en_US';
@ -161,8 +161,11 @@ trait RequestInformation
return $content;
}
$content = $help->getFromGitHub($route, $language);
$baseHref = route('index');
$helpString = sprintf(
'<p><em><img src="%s/images/flags/%s.png" /> %s</em></p>', $baseHref, $originalLanguage, (string)trans('firefly.help_translating')
);
$content = $helpString . $help->getFromGitHub($route, $language);
}
// help still empty?

View File

@ -116,9 +116,9 @@ class AccountTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -138,9 +138,9 @@ class BillTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -87,9 +87,9 @@ class BudgetTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -87,9 +87,9 @@ class CategoryTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -87,9 +87,9 @@ class JournalMetaTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions= $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -105,9 +105,9 @@ class PiggyBankEventTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->item($journals->first(), new TransactionTransformer($this->parameters), 'transactions');
return $this->item($transactions->first(), new TransactionTransformer($this->parameters), 'transactions');
}
/**

View File

@ -86,9 +86,9 @@ class TagTransformer extends TransformerAbstract
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
$journals = $collector->getTransactions();
$transactions = $collector->getTransactions();
return $this->collection($journals, new TransactionTransformer($this->parameters), 'transactions');
return $this->collection($transactions, new TransactionTransformer($this->parameters), 'transactions');
}
/**