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
@ -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)) {
|
||||
$result = [];
|
||||
if (0 === count($set)) {
|
||||
return [];
|
||||
}
|
||||
foreach($set as $info) {
|
||||
foreach ($set as $info) {
|
||||
$column = $info['column'] ?? 'NOPE';
|
||||
$direction = $info['direction'] ?? 'NOPE';
|
||||
if('asc' !== $direction && 'desc' !== $direction) {
|
||||
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;
|
||||
|
@ -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')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1080,19 +1086,18 @@ class GroupCollector implements GroupCollectorInterface
|
||||
// include budget ID + name (if any)
|
||||
->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;
|
||||
|
||||
|
@ -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'));
|
||||
|
@ -916,7 +916,7 @@ return [
|
||||
// allowed sort columns for API's
|
||||
'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