mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-06 12:45:30 +00:00
This commit is contained in:
@@ -154,6 +154,7 @@ class BudgetLimitHandler
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
$availableBudget->save();
|
$availableBudget->save();
|
||||||
|
app('log')->debug(sprintf('ID of new AB is #%d', $availableBudget->id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,12 +61,12 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->postFilters = [];
|
$this->postFilters = [];
|
||||||
$this->tags = [];
|
$this->tags = [];
|
||||||
$this->user = null;
|
$this->user = null;
|
||||||
$this->userGroup = null;
|
$this->userGroup = null;
|
||||||
$this->limit = null;
|
$this->limit = null;
|
||||||
$this->page = null;
|
$this->page = null;
|
||||||
|
|
||||||
$this->hasAccountInfo = false;
|
$this->hasAccountInfo = false;
|
||||||
$this->hasCatInformation = false;
|
$this->hasCatInformation = false;
|
||||||
@@ -288,7 +288,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
if (is_int($param)) {
|
if (is_int($param)) {
|
||||||
$replace = (string)$param;
|
$replace = (string)$param;
|
||||||
}
|
}
|
||||||
$pos = strpos($query, '?');
|
$pos = strpos($query, '?');
|
||||||
if (false !== $pos) {
|
if (false !== $pos) {
|
||||||
$query = substr_replace($query, $replace, $pos, 1);
|
$query = substr_replace($query, $replace, $pos, 1);
|
||||||
}
|
}
|
||||||
@@ -456,13 +456,13 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
// add to query:
|
// add to query:
|
||||||
$this->query->orWhereIn('transaction_journals.transaction_group_id', $groupIds);
|
$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.
|
// now to parse this into an array.
|
||||||
$collection = $this->parseArray($result);
|
$collection = $this->parseArray($result);
|
||||||
|
|
||||||
// filter the array using all available post filters:
|
// filter the array using all available post filters:
|
||||||
$collection = $this->postFilterCollection($collection);
|
$collection = $this->postFilterCollection($collection);
|
||||||
|
|
||||||
// count it and continue:
|
// count it and continue:
|
||||||
$this->total = $collection->count();
|
$this->total = $collection->count();
|
||||||
@@ -668,12 +668,11 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
// include source + destination account name and type.
|
// include source + destination account name and type.
|
||||||
$this->withAccountInformation()
|
$this->withAccountInformation()
|
||||||
// include category ID + name (if any)
|
// include category ID + name (if any)
|
||||||
->withCategoryInformation()
|
->withCategoryInformation()
|
||||||
// include budget ID + name (if any)
|
// include budget ID + name (if any)
|
||||||
->withBudgetInformation()
|
->withBudgetInformation()
|
||||||
// include bill ID + name (if any)
|
// include bill ID + name (if any)
|
||||||
->withBillInformation()
|
->withBillInformation();
|
||||||
;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -692,12 +691,12 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
|
|
||||||
/** @var TransactionJournal $augumentedJournal */
|
/** @var TransactionJournal $augumentedJournal */
|
||||||
foreach ($collection as $augumentedJournal) {
|
foreach ($collection as $augumentedJournal) {
|
||||||
$groupId = (int)$augumentedJournal->transaction_group_id;
|
$groupId = (int)$augumentedJournal->transaction_group_id;
|
||||||
|
|
||||||
if (!array_key_exists($groupId, $groups)) {
|
if (!array_key_exists($groupId, $groups)) {
|
||||||
// make new array
|
// make new array
|
||||||
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
|
||||||
$groupArray = [
|
$groupArray = [
|
||||||
'id' => (int)$augumentedJournal->transaction_group_id,
|
'id' => (int)$augumentedJournal->transaction_group_id,
|
||||||
'user_id' => $augumentedJournal->user_id,
|
'user_id' => $augumentedJournal->user_id,
|
||||||
'user_group_id' => $augumentedJournal->user_group_id,
|
'user_group_id' => $augumentedJournal->user_group_id,
|
||||||
@@ -769,7 +768,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to process meta date value (if present)
|
// 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)) {
|
if (array_key_exists('meta_name', $result) && in_array($result['meta_name'], $dates, true)) {
|
||||||
$name = $result['meta_name'];
|
$name = $result['meta_name'];
|
||||||
if (array_key_exists('meta_data', $result) && '' !== (string)$result['meta_data']) {
|
if (array_key_exists('meta_data', $result) && '' !== (string)$result['meta_data']) {
|
||||||
@@ -778,15 +777,15 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert values to integers:
|
// convert values to integers:
|
||||||
$result = $this->convertToInteger($result);
|
$result = $this->convertToInteger($result);
|
||||||
|
|
||||||
// convert back to strings because SQLite is dumb like that.
|
// 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.
|
if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well.
|
||||||
$tagId = (int)$augumentedJournal['tag_id'];
|
$tagId = (int)$augumentedJournal['tag_id'];
|
||||||
$tagDate = null;
|
$tagDate = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
|
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
|
||||||
@@ -850,9 +849,9 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
{
|
{
|
||||||
$newArray = $newJournal->toArray();
|
$newArray = $newJournal->toArray();
|
||||||
if (array_key_exists('tag_id', $newArray)) { // assume the other fields are present as well.
|
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 {
|
try {
|
||||||
$tagDate = Carbon::parse($newArray['tag_date']);
|
$tagDate = Carbon::parse($newArray['tag_date']);
|
||||||
@@ -875,7 +874,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
{
|
{
|
||||||
$newArray = $newJournal->toArray();
|
$newArray = $newJournal->toArray();
|
||||||
if (array_key_exists('attachment_id', $newArray)) {
|
if (array_key_exists('attachment_id', $newArray)) {
|
||||||
$attachmentId = (int)$newJournal['attachment_id'];
|
$attachmentId = (int)$newJournal['attachment_id'];
|
||||||
|
|
||||||
$existingJournal['attachments'][$attachmentId] = [
|
$existingJournal['attachments'][$attachmentId] = [
|
||||||
'id' => $attachmentId,
|
'id' => $attachmentId,
|
||||||
@@ -894,7 +893,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
foreach ($groups as $groudId => $group) {
|
foreach ($groups as $groudId => $group) {
|
||||||
/** @var array $transaction */
|
/** @var array $transaction */
|
||||||
foreach ($group['transactions'] as $transaction) {
|
foreach ($group['transactions'] as $transaction) {
|
||||||
$currencyId = (int)$transaction['currency_id'];
|
$currencyId = (int)$transaction['currency_id'];
|
||||||
if (null === $transaction['amount']) {
|
if (null === $transaction['amount']) {
|
||||||
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId));
|
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId));
|
||||||
}
|
}
|
||||||
@@ -910,7 +909,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
|
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
|
||||||
|
|
||||||
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
|
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
|
||||||
$currencyId = (int)$transaction['foreign_currency_id'];
|
$currencyId = (int)$transaction['foreign_currency_id'];
|
||||||
|
|
||||||
// set default:
|
// set default:
|
||||||
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
|
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
|
||||||
@@ -931,6 +930,11 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
private function postFilterCollection(Collection $collection): Collection
|
private function postFilterCollection(Collection $collection): Collection
|
||||||
{
|
{
|
||||||
$currentCollection = $collection;
|
$currentCollection = $collection;
|
||||||
|
$countFilters = count($this->postFilters);
|
||||||
|
$countCollection = count($currentCollection);
|
||||||
|
if (0 === $countFilters && 0 === $countCollection) {
|
||||||
|
return $currentCollection;
|
||||||
|
}
|
||||||
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d filter(s) and %d transaction(s).', count($this->postFilters), count($currentCollection)));
|
app('log')->debug(sprintf('GroupCollector: postFilterCollection has %d filter(s) and %d transaction(s).', count($this->postFilters), count($currentCollection)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -938,7 +942,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
foreach ($this->postFilters as $function) {
|
foreach ($this->postFilters as $function) {
|
||||||
app('log')->debug('Applying filter...');
|
app('log')->debug('Applying filter...');
|
||||||
$nextCollection = new Collection();
|
$nextCollection = new Collection();
|
||||||
|
|
||||||
// loop everything in the current collection
|
// loop everything in the current collection
|
||||||
// and save it (or not) in the new collection.
|
// and save it (or not) in the new collection.
|
||||||
@@ -985,8 +989,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
'transactions as source',
|
'transactions as source',
|
||||||
static function (JoinClause $join): void {
|
static function (JoinClause $join): void {
|
||||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('source.amount', '<', 0)
|
->where('source.amount', '<', 0);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// join destination transaction
|
// join destination transaction
|
||||||
@@ -994,8 +997,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
'transactions as destination',
|
'transactions as destination',
|
||||||
static function (JoinClause $join): void {
|
static function (JoinClause $join): void {
|
||||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('destination.amount', '>', 0)
|
->where('destination.amount', '>', 0);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// left join transaction type.
|
// left join transaction type.
|
||||||
@@ -1010,8 +1012,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC')
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
->orderBy('transaction_journals.description', 'DESC')
|
->orderBy('transaction_journals.description', 'DESC')
|
||||||
->orderBy('source.amount', 'DESC')
|
->orderBy('source.amount', 'DESC');
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1029,8 +1030,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
'transactions as source',
|
'transactions as source',
|
||||||
static function (JoinClause $join): void {
|
static function (JoinClause $join): void {
|
||||||
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('source.amount', '<', 0)
|
->where('source.amount', '<', 0);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// join destination transaction
|
// join destination transaction
|
||||||
@@ -1038,8 +1038,7 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
'transactions as destination',
|
'transactions as destination',
|
||||||
static function (JoinClause $join): void {
|
static function (JoinClause $join): void {
|
||||||
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('destination.amount', '>', 0)
|
->where('destination.amount', '>', 0);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// left join transaction type.
|
// left join transaction type.
|
||||||
@@ -1054,7 +1053,6 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC')
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
->orderBy('transaction_journals.description', 'DESC')
|
->orderBy('transaction_journals.description', 'DESC')
|
||||||
->orderBy('source.amount', 'DESC')
|
->orderBy('source.amount', 'DESC');
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,8 +66,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
if (null !== $start && null !== $end) {
|
if (null !== $start && null !== $end) {
|
||||||
$query->where(
|
$query->where(
|
||||||
static function (Builder $q1) use ($start, $end): void { // @phpstan-ignore-line
|
static function (Builder $q1) use ($start, $end): void { // @phpstan-ignore-line
|
||||||
$q1->where('start_date', '=', $start->format('Y-m-d'));
|
$q1->where('start_date', '=', $start);
|
||||||
$q1->where('end_date', '=', $end->format('Y-m-d'));
|
$q1->where('end_date', '=', $end);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -216,7 +216,6 @@ class Navigation
|
|||||||
public function endOfPeriod(Carbon $end, string $repeatFreq): Carbon
|
public function endOfPeriod(Carbon $end, string $repeatFreq): Carbon
|
||||||
{
|
{
|
||||||
$currentEnd = clone $end;
|
$currentEnd = clone $end;
|
||||||
Log::debug(sprintf('endOfPeriod("%s", "%s")', $currentEnd->format('Y-m-d'), $repeatFreq));
|
|
||||||
|
|
||||||
$functionMap = [
|
$functionMap = [
|
||||||
'1D' => 'endOfDay',
|
'1D' => 'endOfDay',
|
||||||
|
Reference in New Issue
Block a user