protected function assembleAccountBalancesWithTXID($results, $in_satoshis = false) { $sums = array_fill_keys(LedgerEntry::allTypeStrings(), []); foreach ($results as $result) { $txid = $result['txid']; if (!$txid) { $txid = 'none'; } if ($in_satoshis) { $sums[LedgerEntry::typeIntegerToString($result['type'])][$txid][$result['asset']] = $result['total_amount']; } else { $sums[LedgerEntry::typeIntegerToString($result['type'])][$txid][$result['asset']] = CurrencyUtil::satoshisToValue($result['total_amount']); } } return $sums; }
protected function showAccount(Account $account, $show_ledger = false) { $ledger = app('App\\Repositories\\LedgerEntryRepository'); $all_account_balances = $ledger->accountBalancesByAsset($account, null); $sep = str_repeat('-', 60) . "\n"; $out = ''; $out .= "{$sep}{$account['name']} ({$account['id']}, {$account['uuid']})\n{$sep}"; if ($show_ledger) { $out .= "\n"; $rows = []; $all_entries = $ledger->findByAccount($account); foreach ($all_entries as $entry) { $row = []; $row['date'] = $entry['created_at']->setTimezone('America/Chicago')->format('Y-m-d H:i:s T'); $row['amount'] = CurrencyUtil::satoshisToFormattedString($entry['amount']); $row['asset'] = $entry['asset']; $row['type'] = LedgerEntry::typeIntegerToString($entry['type']); $row['txid'] = $entry['txid']; $rows[] = $row; } $renderer = new ArrayToTextTable($rows); $renderer->showHeaders(true); $out .= $renderer->render(true) . "\n"; } // $out .= "BALANCES\n"; $out .= "\n"; foreach (LedgerEntry::allTypeStrings() as $type_string) { $out .= "{$type_string}:\n"; if (isset($all_account_balances[$type_string]) and $all_account_balances[$type_string]) { foreach ($all_account_balances[$type_string] as $asset => $balance) { $out .= " {$asset}: " . CurrencyUtil::valueToFormattedString($balance) . "\n"; } } else { $out .= " [empty]\n"; } } $out .= "\n{$sep}\n"; return $out; }