mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update source account detection.
This commit is contained in:
parent
9222c82af0
commit
2564470197
@ -83,7 +83,7 @@ class TransactionController extends Controller
|
||||
|
||||
// collect transactions:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUserGroup(auth()->user()->userGroup)
|
||||
->withAPIInformation()
|
||||
->setStartRow($request->getStartRow())
|
||||
@ -92,8 +92,8 @@ class TransactionController extends Controller
|
||||
->setSorting($instructions)
|
||||
;
|
||||
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
if (null !== $start) {
|
||||
$collector->setStart($start);
|
||||
}
|
||||
@ -101,8 +101,8 @@ class TransactionController extends Controller
|
||||
$collector->setEnd($end);
|
||||
}
|
||||
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$params = $request->buildParams();
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$params = $request->buildParams();
|
||||
$paginator->setPath(
|
||||
sprintf(
|
||||
'%s?%s',
|
||||
|
@ -88,26 +88,28 @@ class InfiniteListRequest extends FormRequest
|
||||
return 0 === $page || $page > 65536 ? 1 : $page;
|
||||
}
|
||||
|
||||
public function getSortInstructions(): array {
|
||||
public function getSortInstructions(): array
|
||||
{
|
||||
$allowed = config('firefly.sorting.allowed.transactions');
|
||||
$set = $this->get('sorting', []);
|
||||
$result= [];
|
||||
if(0 === count($set)) {
|
||||
$set = $this->get('sorting', []);
|
||||
$result = [];
|
||||
if (0 === count($set)) {
|
||||
return [];
|
||||
}
|
||||
foreach($set as $info) {
|
||||
$column = $info['column'] ?? 'NOPE';
|
||||
$direction = $info['direction'] ?? 'NOPE';
|
||||
if('asc' !== $direction && 'desc' !== $direction) {
|
||||
foreach ($set as $info) {
|
||||
$column = $info['column'] ?? 'NOPE';
|
||||
$direction = $info['direction'] ?? 'NOPE';
|
||||
if ('asc' !== $direction && 'desc' !== $direction) {
|
||||
// skip invalid direction
|
||||
continue;
|
||||
}
|
||||
if(in_array($column, $allowed, true) === false) {
|
||||
if (false === in_array($column, $allowed, true)) {
|
||||
// skip invalid column
|
||||
continue;
|
||||
}
|
||||
$result[$column] = $direction;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
*/
|
||||
trait CollectorProperties
|
||||
{
|
||||
|
||||
public array $sorting;
|
||||
public const string TEST = 'Test';
|
||||
private ?int $endRow;
|
||||
|
@ -61,15 +61,15 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->sorting = [];
|
||||
$this->postFilters = [];
|
||||
$this->tags = [];
|
||||
$this->user = null;
|
||||
$this->userGroup = null;
|
||||
$this->limit = null;
|
||||
$this->page = null;
|
||||
$this->startRow = null;
|
||||
$this->endRow = null;
|
||||
$this->sorting = [];
|
||||
$this->postFilters = [];
|
||||
$this->tags = [];
|
||||
$this->user = null;
|
||||
$this->userGroup = null;
|
||||
$this->limit = null;
|
||||
$this->page = null;
|
||||
$this->startRow = null;
|
||||
$this->endRow = null;
|
||||
|
||||
$this->hasAccountInfo = false;
|
||||
$this->hasCatInformation = false;
|
||||
@ -291,7 +291,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
if (is_int($param)) {
|
||||
$replace = (string)$param;
|
||||
}
|
||||
$pos = strpos($query, '?');
|
||||
$pos = strpos($query, '?');
|
||||
if (false !== $pos) {
|
||||
$query = substr_replace($query, $replace, $pos, 1);
|
||||
}
|
||||
@ -459,16 +459,16 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// add to query:
|
||||
$this->query->orWhereIn('transaction_journals.transaction_group_id', $groupIds);
|
||||
}
|
||||
$result = $this->query->get($this->fields);
|
||||
$result = $this->query->get($this->fields);
|
||||
|
||||
// now to parse this into an array.
|
||||
$collection = $this->parseArray($result);
|
||||
$collection = $this->parseArray($result);
|
||||
|
||||
// filter the array using all available post filters:
|
||||
$collection = $this->postFilterCollection($collection);
|
||||
$collection = $this->postFilterCollection($collection);
|
||||
|
||||
// sort the collection, if sort instructions are present.
|
||||
$collection = $this->sortCollection($collection);
|
||||
$collection = $this->sortCollection($collection);
|
||||
|
||||
// count it and continue:
|
||||
$this->total = $collection->count();
|
||||
@ -501,12 +501,12 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
/** @var TransactionJournal $augumentedJournal */
|
||||
foreach ($collection as $augumentedJournal) {
|
||||
$groupId = (int)$augumentedJournal->transaction_group_id;
|
||||
$groupId = (int)$augumentedJournal->transaction_group_id;
|
||||
|
||||
if (!array_key_exists($groupId, $groups)) {
|
||||
// make new array
|
||||
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
||||
$groupArray = [
|
||||
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
||||
$groupArray = [
|
||||
'id' => (int)$augumentedJournal->transaction_group_id,
|
||||
'user_id' => $augumentedJournal->user_id,
|
||||
'user_group_id' => $augumentedJournal->user_group_id,
|
||||
@ -578,7 +578,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
// try to process meta date value (if present)
|
||||
$dates = ['interest_date', 'payment_date', 'invoice_date', 'book_date', 'due_date', 'process_date'];
|
||||
$dates = ['interest_date', 'payment_date', 'invoice_date', 'book_date', 'due_date', 'process_date'];
|
||||
if (array_key_exists('meta_name', $result) && in_array($result['meta_name'], $dates, true)) {
|
||||
$name = $result['meta_name'];
|
||||
if (array_key_exists('meta_data', $result) && '' !== (string)$result['meta_data']) {
|
||||
@ -587,15 +587,15 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
// convert values to integers:
|
||||
$result = $this->convertToInteger($result);
|
||||
$result = $this->convertToInteger($result);
|
||||
|
||||
// convert back to strings because SQLite is dumb like that.
|
||||
$result = $this->convertToStrings($result);
|
||||
$result = $this->convertToStrings($result);
|
||||
|
||||
$result['reconciled'] = 1 === (int)$result['reconciled'];
|
||||
$result['reconciled'] = 1 === (int)$result['reconciled'];
|
||||
if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well.
|
||||
$tagId = (int)$augumentedJournal['tag_id'];
|
||||
$tagDate = null;
|
||||
$tagId = (int)$augumentedJournal['tag_id'];
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
|
||||
@ -659,9 +659,9 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
if (array_key_exists('tag_id', $newArray)) { // assume the other fields are present as well.
|
||||
$tagId = (int)$newJournal['tag_id'];
|
||||
$tagId = (int)$newJournal['tag_id'];
|
||||
|
||||
$tagDate = null;
|
||||
$tagDate = null;
|
||||
|
||||
try {
|
||||
$tagDate = Carbon::parse($newArray['tag_date']);
|
||||
@ -684,7 +684,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
{
|
||||
$newArray = $newJournal->toArray();
|
||||
if (array_key_exists('attachment_id', $newArray)) {
|
||||
$attachmentId = (int)$newJournal['attachment_id'];
|
||||
$attachmentId = (int)$newJournal['attachment_id'];
|
||||
|
||||
$existingJournal['attachments'][$attachmentId] = [
|
||||
'id' => $attachmentId,
|
||||
@ -703,7 +703,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
foreach ($groups as $groudId => $group) {
|
||||
/** @var array $transaction */
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$currencyId = (int)$transaction['currency_id'];
|
||||
$currencyId = (int)$transaction['currency_id'];
|
||||
if (null === $transaction['amount']) {
|
||||
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId));
|
||||
}
|
||||
@ -719,7 +719,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
|
||||
|
||||
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
|
||||
$currencyId = (int)$transaction['foreign_currency_id'];
|
||||
$currencyId = (int)$transaction['foreign_currency_id'];
|
||||
|
||||
// set default:
|
||||
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
|
||||
@ -752,7 +752,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
foreach ($this->postFilters as $function) {
|
||||
app('log')->debug('Applying filter...');
|
||||
$nextCollection = new Collection();
|
||||
$nextCollection = new Collection();
|
||||
|
||||
// loop everything in the current collection
|
||||
// and save it (or not) in the new collection.
|
||||
@ -988,7 +988,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0);
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@ -996,7 +997,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0);
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@ -1011,7 +1013,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC');
|
||||
->orderBy('source.amount', 'DESC')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1042,7 +1045,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as source',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source.amount', '<', 0);
|
||||
->where('source.amount', '<', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// join destination transaction
|
||||
@ -1050,7 +1054,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
'transactions as destination',
|
||||
static function (JoinClause $join): void {
|
||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination.amount', '>', 0);
|
||||
->where('destination.amount', '>', 0)
|
||||
;
|
||||
}
|
||||
)
|
||||
// left join transaction type.
|
||||
@ -1065,7 +1070,8 @@ class GroupCollector implements GroupCollectorInterface
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->orderBy('transaction_journals.description', 'DESC')
|
||||
->orderBy('source.amount', 'DESC');
|
||||
->orderBy('source.amount', 'DESC')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1076,23 +1082,22 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// include source + destination account name and type.
|
||||
$this->withAccountInformation()
|
||||
// include category ID + name (if any)
|
||||
->withCategoryInformation()
|
||||
->withCategoryInformation()
|
||||
// include budget ID + name (if any)
|
||||
->withBudgetInformation()
|
||||
->withBudgetInformation()
|
||||
// include bill ID + name (if any)
|
||||
->withBillInformation();
|
||||
->withBillInformation()
|
||||
;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
#[\Override] public function sortCollection(Collection $collection): Collection
|
||||
#[\Override]
|
||||
public function sortCollection(Collection $collection): Collection
|
||||
{
|
||||
foreach ($this->sorting as $field => $direction) {
|
||||
$func = $direction === 'ASC' ? 'sortBy' : 'sortByDesc';
|
||||
$collection = $collection->$func(function (array $product, int $key) use ($field, $direction) {
|
||||
$func = 'ASC' === $direction ? 'sortBy' : 'sortByDesc';
|
||||
$collection = $collection->{$func}(function (array $product, int $key) use ($field) {
|
||||
// depends on $field:
|
||||
if ('description' === $field) {
|
||||
if (1 === count($product['transactions'])) {
|
||||
@ -1101,22 +1106,22 @@ class GroupCollector implements GroupCollectorInterface
|
||||
if (count($product['transactions']) > 1) {
|
||||
return $product['title'];
|
||||
}
|
||||
|
||||
return 'zzz';
|
||||
}
|
||||
die('here we are');
|
||||
|
||||
exit('here we are');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
#[\Override] public function setSorting(array $instructions): GroupCollectorInterface
|
||||
#[\Override]
|
||||
public function setSorting(array $instructions): GroupCollectorInterface
|
||||
{
|
||||
$this->sorting = $instructions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -285,22 +285,10 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function getPaginatedGroups(): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param array $instructions
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setSorting(array $instructions): self;
|
||||
|
||||
|
||||
/**
|
||||
* Sort the collection on a column.
|
||||
*
|
||||
* @param Collection $collection
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function sortCollection(Collection $collection): Collection;
|
||||
|
||||
|
@ -115,12 +115,12 @@ class DebugController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$table = $this->generateTable();
|
||||
$table = str_replace(["\n", "\t", ' '], '', $table);
|
||||
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
|
||||
$table = $this->generateTable();
|
||||
$table = str_replace(["\n", "\t", ' '], '', $table);
|
||||
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
|
||||
|
||||
// get latest log file:
|
||||
$logger = Log::driver();
|
||||
$logger = Log::driver();
|
||||
// PHPstan doesn't recognize the method because of its polymorphic nature.
|
||||
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
|
||||
$logContent = '';
|
||||
@ -134,7 +134,7 @@ class DebugController extends Controller
|
||||
}
|
||||
if ('' !== $logContent) {
|
||||
// last few lines
|
||||
$logContent = 'Truncated from this point <----|' . substr((string)$logContent, -16384);
|
||||
$logContent = 'Truncated from this point <----|'.substr((string)$logContent, -16384);
|
||||
}
|
||||
|
||||
return view('debug', compact('table', 'now', 'logContent'));
|
||||
@ -214,7 +214,7 @@ class DebugController extends Controller
|
||||
|
||||
private function getAppInfo(): array
|
||||
{
|
||||
$userGuard = config('auth.defaults.guard');
|
||||
$userGuard = config('auth.defaults.guard');
|
||||
|
||||
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
||||
$lastTime = (int)$config->data;
|
||||
@ -239,24 +239,24 @@ class DebugController extends Controller
|
||||
// any of the cron jobs will do, they always run at the same time.
|
||||
// but this job is the oldest, so the biggest chance it ran once
|
||||
|
||||
'last_cronjob' => $lastCronjob,
|
||||
'last_cronjob_ago' => $lastCronjobAgo,
|
||||
'last_cronjob' => $lastCronjob,
|
||||
'last_cronjob_ago' => $lastCronjobAgo,
|
||||
];
|
||||
}
|
||||
|
||||
private function getuserInfo(): array
|
||||
{
|
||||
$userFlags = $this->getUserFlags();
|
||||
$userFlags = $this->getUserFlags();
|
||||
|
||||
// user info
|
||||
$userAgent = request()->header('user-agent');
|
||||
$userAgent = request()->header('user-agent');
|
||||
|
||||
// set languages, see what happens:
|
||||
$original = setlocale(LC_ALL, '0');
|
||||
$localeAttempts = [];
|
||||
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
|
||||
foreach ($parts as $code) {
|
||||
$code = trim($code);
|
||||
$code = trim($code);
|
||||
app('log')->debug(sprintf('Trying to set %s', $code));
|
||||
$result = setlocale(LC_ALL, $code);
|
||||
$localeAttempts[$code] = $result === $code;
|
||||
@ -280,7 +280,7 @@ class DebugController extends Controller
|
||||
$flags = [];
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
// has liabilities
|
||||
if ($user->accounts()->accountTypeIn([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->count() > 0) {
|
||||
@ -293,7 +293,7 @@ class DebugController extends Controller
|
||||
}
|
||||
|
||||
// has stored reconciliations
|
||||
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
|
||||
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
|
||||
if ($user->transactionJournals()->where('transaction_type_id', $type->id)->count() > 0) {
|
||||
$flags[] = '<span title="Has reconciled">:ledger:</span>';
|
||||
}
|
||||
|
@ -914,9 +914,9 @@ return [
|
||||
'preselected_accounts' => ['all', 'assets', 'liabilities'],
|
||||
|
||||
// allowed sort columns for API's
|
||||
'sorting' => [
|
||||
'sorting' => [
|
||||
'allowed' => [
|
||||
'transactions' => ['description','amount'],
|
||||
'transactions' => ['description', 'amount'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
1
public/build/assets/create-0e590bfb.js
Normal file
1
public/build/assets/create-0e590bfb.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -121,7 +121,7 @@
|
||||
"integrity": "sha384-ptHLIPXakGRWe8dWim7Qxgub4wolfi5rktBj2EjNw5tyt8hLq+8p+lTsBKZe5Vay"
|
||||
},
|
||||
"resources/assets/v2/pages/transactions/create.js": {
|
||||
"file": "assets/create-6dc4ec8c.js",
|
||||
"file": "assets/create-0e590bfb.js",
|
||||
"imports": [
|
||||
"_format-money-2cbd3c32.js",
|
||||
"_create-empty-split-c1e678fd.js",
|
||||
@ -131,7 +131,7 @@
|
||||
],
|
||||
"isEntry": true,
|
||||
"src": "resources/assets/v2/pages/transactions/create.js",
|
||||
"integrity": "sha384-OUiIH870uiZ8Y+/Gl2WLNSLwS8bi6mFgbixL18oCvpeSSN3pLbbmO9M+kzLlXNc9"
|
||||
"integrity": "sha384-E0yymaxo99O2vsNgsuJ2KZD4tBnB+ly/ZlpuS9gJakCJIWWHGxK5z7G1wayhnrK3"
|
||||
},
|
||||
"resources/assets/v2/pages/transactions/edit.js": {
|
||||
"file": "assets/edit-0910e359.js",
|
||||
|
@ -180,6 +180,12 @@ let transactions = function () {
|
||||
console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
|
||||
return;
|
||||
}
|
||||
if ('Expense account' === sourceType && ['Asset account', 'Debt', 'Loan', 'Mortgage'].includes(destType)) {
|
||||
this.groupProperties.transactionType = 'deposit';
|
||||
console.warn('FORCE transaction type to be "' + this.groupProperties.transactionType + '".');
|
||||
this.entries[0].source_account.id = null;
|
||||
return;
|
||||
}
|
||||
if (['Debt', 'Loan', 'Mortgage'].includes(sourceType) && 'Asset account' === destType) {
|
||||
this.groupProperties.transactionType = 'deposit';
|
||||
console.log('Transaction type is detected to be "' + this.groupProperties.transactionType + '".');
|
||||
|
Loading…
Reference in New Issue
Block a user