Add a debug view for transactions.

This commit is contained in:
James Cole 2020-02-08 06:42:07 +01:00
parent d5cfc12bf3
commit cebc0d7568
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 127 additions and 19 deletions

View File

@ -61,6 +61,16 @@ class ShowController extends Controller
);
}
/**
* @param TransactionGroup $transactionGroup
*
* @return \Illuminate\Http\JsonResponse
*/
public function debugShow(TransactionGroup $transactionGroup)
{
return response()->json($this->repository->expandGroup($transactionGroup));
}
/**
* @param TransactionGroup $transactionGroup
*
@ -105,6 +115,7 @@ class ShowController extends Controller
/**
* @param array $group
*
* @return array
*/
private function getAmounts(array $group): array

View File

@ -346,6 +346,15 @@ class TransactionJournal extends Model
return $this->hasMany(TransactionJournalLink::class, 'source_id');
}
/**
* @codeCoverageIgnore
* @return HasMany
*/
public function destJournalLinks(): HasMany
{
return $this->hasMany(TransactionJournalLink::class, 'destination_id');
}
/**
* @codeCoverageIgnore
* @return BelongsToMany

View File

@ -74,6 +74,21 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
$service->destroy($group);
}
/**
* @inheritDoc
*/
public function expandGroup(TransactionGroup $group): array
{
$result = $group->toArray();
$result['transaction_journals'] = [];
/** @var TransactionJournal $journal */
foreach ($group->transactionJournals as $journal) {
$result['transaction_journals'][] = $this->expandJournal($journal);
}
return $result;
}
/**
* Find a transaction group by its ID.
*
@ -342,6 +357,88 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface
return $service->update($transactionGroup, $data);
}
/**
* @param TransactionJournal $journal
*
* @return array
*/
private function expandJournal(TransactionJournal $journal): array
{
$array = $journal->toArray();
$array['transactions'] = [];
$array['meta'] = [];
$array['tags'] = [];
$array['categories'] = [];
$array['budgets'] = [];
$array['notes'] = [];
$array['locations'] = [];
$array['attachments'] = [];
$array['links'] = [];
$array['piggy_bank_events'] = [];
/** @var Transaction $transaction */
foreach ($journal->transactions as $transaction) {
$array['transactions'][] = $this->expandTransaction($transaction);
}
foreach ($journal->transactionJournalMeta as $meta) {
$array['meta'][] = $meta->toArray();
}
foreach ($journal->tags as $tag) {
$array['tags'][] = $tag->toArray();
}
foreach ($journal->categories as $category) {
$array['categories'][] = $category->toArray();
}
foreach ($journal->budgets as $budget) {
$array['budgets'][] = $budget->toArray();
}
foreach ($journal->notes as $note) {
$array['notes'][] = $note->toArray();
}
foreach ($journal->attachments as $attachment) {
$array['attachments'][] = $attachment->toArray();
}
// TODO apparantly this doesnt work.
foreach ($journal->sourceJournalLinks as $link) {
$array['links'][] = $link->toArray();
}
foreach ($journal->destJournalLinks as $link) {
$array['links'][] = $link->toArray();
}
foreach ($journal->piggyBankEvents as $event) {
$array['piggy_bank_events'][] = $event->toArray();
}
return $array;
}
/**
* @param Transaction $transaction
*
* @return array
*/
private function expandTransaction(Transaction $transaction): array
{
$array = $transaction->toArray();
$array['account'] = $transaction->account->toArray();
$array['budgets'] = [];
$array['categories'] = [];
foreach ($transaction->categories as $category) {
$array['categories'][] = $category->toArray();
}
foreach ($transaction->budgets as $budget) {
$array['budgets'][] = $budget->toArray();
}
return $array;
}
/**
* @param TransactionJournal $journal
*

View File

@ -33,12 +33,20 @@ use FireflyIII\User;
*/
interface TransactionGroupRepositoryInterface
{
/**
* @param TransactionGroup $group
*/
public function destroy(TransactionGroup $group): void;
/**
* Return a group and expand all meta data etc.
*
* @param TransactionGroup $group
*
* @return array
*/
public function expandGroup(TransactionGroup $group): array;
/**
* Find a transaction group by its ID.
*

View File

@ -975,27 +975,10 @@ Route::group(
Route::post('destroy/{transactionGroup}', ['uses' => 'Transaction\DeleteController@destroy', 'as' => 'destroy']);
Route::get('show/{transactionGroup}', ['uses' => 'Transaction\ShowController@show', 'as' => 'show']);
Route::get('debug/{transactionGroup}', ['uses' => 'Transaction\ShowController@debugShow', 'as' => 'debug']);
}
);
/**
* Transaction Single Controller
*/
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Transaction', 'prefix' => 'transactions', 'as' => 'transactions.'],
function () {
// TODO improve these routes
//Route::get('edit/{tj}', ['uses' => 'SingleController@edit', 'as' => 'edit']);
//
//Route::post('store', ['uses' => 'SingleController@store', 'as' => 'store'])->where(['what' => 'withdrawal|deposit|transfer']);
//Route::post('update/{tj}', ['uses' => 'SingleController@update', 'as' => 'update']);
//
//Route::get('clone/{tj}', ['uses' => 'SingleController@cloneTransaction', 'as' => 'clone']);
//Route::get('{tj}/{type}', ['uses' => 'ConvertController@index', 'as' => 'convert']);
// TODO end of improvement.
}
);
/**
* Transaction Mass Controller