Skip to content

Commit

Permalink
Fix #2796
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Nov 9, 2019
1 parent adc4b00 commit 97c8594
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions app/Helpers/Collector/GroupCollector.php
Expand Up @@ -70,6 +70,8 @@ class GroupCollector implements GroupCollectorInterface
private $total;
/** @var User The user object. */
private $user;
/** @var array */
private $integerFields;

/**
* Group collector constructor.
Expand All @@ -84,7 +86,23 @@ public function __construct()
$this->hasBudgetInformation = false;
$this->hasBillInformation = false;
$this->hasJoinedTagTables = false;

$this->integerFields = [
'transaction_group_id',
'user_id',
'transaction_journal_id',
'transaction_type_id',
'order',
'source_transaction_id',
'source_account_id',
'currency_id',
'currency_decimal_places',
'foreign_currency_id',
'foreign_currency_decimal_places',
'destination_transaction_id',
'destination_account_id',
'category_id',
'budget_id'
];
$this->total = 0;
$this->fields = [
# group
Expand Down Expand Up @@ -903,6 +921,22 @@ function (EloquentBuilder $q) {
return $this;
}

/**
* Convert a selected set of fields to arrays.
*
* @param array $array
*
* @return array
*/
private function convertToInteger(array $array): array
{
foreach ($this->integerFields as $field) {
$array[$field] = isset($array[$field]) ? (int)$array[$field] : null;
}

return $array;
}

/**
* Join table to get tag information.
*/
Expand Down Expand Up @@ -965,9 +999,9 @@ private function parseArray(Collection $collection): Collection
// make new array
$parsedGroup = $this->parseAugmentedGroup($augumentedJournal);
$groupArray = [
'id' => $augumentedJournal->transaction_group_id,
'user_id' => $augumentedJournal->user_id,
'title' => $augumentedJournal->transaction_group_title,
'id' => (int)$augumentedJournal->transaction_group_id,
'user_id' => (int)$augumentedJournal->user_id,
'title' => (int)$augumentedJournal->transaction_group_title,
'transaction_type' => $parsedGroup['transaction_type_type'],
'count' => 1,
'sums' => [],
Expand Down Expand Up @@ -1014,6 +1048,10 @@ private function parseAugmentedGroup(TransactionJournal $augumentedJournal): arr
} catch (Exception $e) {
Log::error($e->getMessage());
}

// convert values to integers:
$result = $this->convertToInteger($result);

$result['reconciled'] = 1 === (int)$result['reconciled'];
if (isset($augumentedJournal['tag_id'])) { // assume the other fields are present as well.
$tagId = (int)$augumentedJournal['tag_id'];
Expand Down

0 comments on commit 97c8594

Please sign in to comment.