diff --git a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php index 92abc7bb90..c795f89570 100644 --- a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php +++ b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php @@ -41,34 +41,24 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator */ public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end) { - // language: - $data = [ 'count' => 1, - 'labels' => [], - 'datasets' => [ - [ - 'label' => trans('firefly.spent'), - 'data' => [] - ] - ], - ]; - $ids = []; + 'labels' => [], 'datasets' => [[ + 'label' => trans('firefly.spent'), + 'data' => []]]]; - foreach ($accounts as $account) { - $ids[] = $account->id; - } + bcscale(2); $start->subDay(); - + $ids = $this->getIdsFromCollection($accounts); $startBalances = Steam::balancesById($ids, $start); $endBalances = Steam::balancesById($ids, $end); $accounts->each( function (Account $account) use ($startBalances, $endBalances) { $id = $account->id; - $startBalance = isset($startBalances[$id]) ? $startBalances[$id] : 0; - $endBalance = isset($endBalances[$id]) ? $endBalances[$id] : 0; - $diff = $endBalance - $startBalance; + $startBalance = $this->isInArray($startBalances, $id); + $endBalance = $this->isInArray($endBalances, $id); + $diff = bcsub($endBalance, $startBalance); $account->difference = round($diff, 2); } ); @@ -86,10 +76,24 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator } } - return $data; } + /** + * @param $array + * @param $entryId + * + * @return string + */ + protected function isInArray($array, $entryId) + { + if (isset($array[$entryId])) { + return $array[$entryId]; + } + + return '0'; + } + /** * @param Collection $accounts @@ -171,4 +175,20 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator return $data; } + + /** + * @param Collection $collection + * + * @return array + */ + protected function getIdsFromCollection(Collection $collection) + { + $ids = []; + foreach ($collection as $entry) { + $ids[] = $entry->id; + } + + return array_unique($ids); + + } } diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 5e8a4be655..b5494c5dcf 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -78,15 +78,15 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito ->transactionTypes(['Withdrawal']) ->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']); + bcscale(2); $result = []; foreach ($set as $entry) { $categoryId = intval($entry->category_id); if (isset($result[$categoryId])) { - bcscale(2); $result[$categoryId]['sum'] = bcadd($result[$categoryId]['sum'], $entry->amount); } else { - $isEncrypted = intval($entry->category_encrypted) == 1 ? true : false; - $name = strlen($entry->name) == 0 ? trans('firefly.no_category') : $entry->name; + $isEncrypted = intval($entry->category_encrypted) === 1 ? true : false; + $name = strlen($entry->name) === 0 ? trans('firefly.no_category') : $entry->name; $name = $isEncrypted ? Crypt::decrypt($name) : $name; $result[$categoryId] = [ 'name' => $name, diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index c878a6fd82..ad79b25c05 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -62,21 +62,11 @@ class FireflyValidator extends Validator */ public function validateIban($attribute, $value) { - if (!is_string($value)) { - return false; - } - if (is_null($value)) { - return false; - } - - if (strlen($value) === 0) { + if (!is_string($value) || is_null($value) || strlen($value) < 6) { return false; } $value = strtoupper($value); - if (strlen($value) < 6) { - return false; - } $search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; $replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31',