mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Various optimisations.
This commit is contained in:
@@ -24,25 +24,19 @@ class ChartJsBillChartGenerator implements BillChartGenerator
|
|||||||
*/
|
*/
|
||||||
public function frontpage(Collection $paid, Collection $unpaid)
|
public function frontpage(Collection $paid, Collection $unpaid)
|
||||||
{
|
{
|
||||||
|
|
||||||
// loop paid and create single entry:
|
|
||||||
$paidDescriptions = [];
|
$paidDescriptions = [];
|
||||||
$paidAmount = 0;
|
$paidAmount = 0;
|
||||||
$unpaidDescriptions = [];
|
$unpaidDescriptions = [];
|
||||||
$unpaidAmount = 0;
|
$unpaidAmount = 0;
|
||||||
|
|
||||||
bcscale(2);
|
bcscale(2);
|
||||||
|
|
||||||
/** @var TransactionJournal $entry */
|
/** @var TransactionJournal $entry */
|
||||||
foreach ($paid as $entry) {
|
foreach ($paid as $entry) { // loop paid and create single entry:
|
||||||
|
|
||||||
$paidDescriptions[] = $entry->description;
|
$paidDescriptions[] = $entry->description;
|
||||||
$paidAmount = bcadd($paidAmount, $entry->amount);
|
$paidAmount = bcadd($paidAmount, $entry->amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop unpaid:
|
|
||||||
/** @var Bill $entry */
|
/** @var Bill $entry */
|
||||||
foreach ($unpaid as $entry) {
|
foreach ($unpaid as $entry) { // loop unpaid:
|
||||||
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
$description = $entry[0]->name . ' (' . $entry[1]->format('jS M Y') . ')';
|
||||||
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
$amount = ($entry[0]->amount_max + $entry[0]->amount_min) / 2;
|
||||||
$unpaidDescriptions[] = $description;
|
$unpaidDescriptions[] = $description;
|
||||||
|
@@ -3,6 +3,11 @@
|
|||||||
namespace FireflyIII\Helpers\Csv\Converter;
|
namespace FireflyIII\Helpers\Csv\Converter;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RabobankDebetCredit
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Helpers\Csv\Converter
|
||||||
|
*/
|
||||||
class RabobankDebetCredit extends BasicConverter implements ConverterInterface
|
class RabobankDebetCredit extends BasicConverter implements ConverterInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -119,7 +119,7 @@ class Data
|
|||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getHasHeaders()
|
public function hasHeaders()
|
||||||
{
|
{
|
||||||
return $this->hasHeaders;
|
return $this->hasHeaders;
|
||||||
}
|
}
|
||||||
|
@@ -107,7 +107,7 @@ class Importer
|
|||||||
*/
|
*/
|
||||||
protected function parseRow($index)
|
protected function parseRow($index)
|
||||||
{
|
{
|
||||||
return (($this->data->getHasHeaders() && $index > 1) || !$this->data->getHasHeaders());
|
return (($this->data->hasHeaders() && $index > 1) || !$this->data->hasHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,26 +24,20 @@ class OpposingAccount implements PostProcessorInterface
|
|||||||
*/
|
*/
|
||||||
public function process()
|
public function process()
|
||||||
{
|
{
|
||||||
// first priority. try to find the account based on ID, if any.
|
if ($this->data['opposing-account-id'] instanceof Account) { // first priority. try to find the account based on ID, if any
|
||||||
if ($this->data['opposing-account-id'] instanceof Account) {
|
|
||||||
$this->data['opposing-account-object'] = $this->data['opposing-account-id'];
|
$this->data['opposing-account-object'] = $this->data['opposing-account-id'];
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
if ($this->data['opposing-account-iban'] instanceof Account) { // second: try to find the account based on IBAN, if any.
|
||||||
// second: try to find the account based on IBAN, if any.
|
|
||||||
if ($this->data['opposing-account-iban'] instanceof Account) {
|
|
||||||
$this->data['opposing-account-object'] = $this->data['opposing-account-iban'];
|
$this->data['opposing-account-object'] = $this->data['opposing-account-iban'];
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rules = ['iban' => 'iban'];
|
$rules = ['iban' => 'iban'];
|
||||||
$check = ['iban' => $this->data['opposing-account-iban']];
|
$check = ['iban' => $this->data['opposing-account-iban']];
|
||||||
$validator = Validator::make($check, $rules);
|
$validator = Validator::make($check, $rules);
|
||||||
$result = !$validator->fails();
|
$result = !$validator->fails();
|
||||||
|
|
||||||
|
|
||||||
if (is_string($this->data['opposing-account-iban']) && strlen($this->data['opposing-account-iban']) > 0) {
|
if (is_string($this->data['opposing-account-iban']) && strlen($this->data['opposing-account-iban']) > 0) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->data['opposing-account-object'] = $this->parseIbanString();
|
$this->data['opposing-account-object'] = $this->parseIbanString();
|
||||||
@@ -51,14 +45,11 @@ class OpposingAccount implements PostProcessorInterface
|
|||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($this->data['opposing-account-name'] instanceof Account) { // third: try to find account based on name, if any.
|
||||||
// third: try to find account based on name, if any.
|
|
||||||
if ($this->data['opposing-account-name'] instanceof Account) {
|
|
||||||
$this->data['opposing-account-object'] = $this->data['opposing-account-name'];
|
$this->data['opposing-account-object'] = $this->data['opposing-account-name'];
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_string($this->data['opposing-account-name'])) {
|
if (is_string($this->data['opposing-account-name'])) {
|
||||||
$this->data['opposing-account-object'] = $this->parseNameString();
|
$this->data['opposing-account-object'] = $this->parseNameString();
|
||||||
|
|
||||||
|
@@ -202,11 +202,10 @@ class ReportHelper implements ReportHelperInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
* @param boolean $shared
|
|
||||||
*
|
*
|
||||||
* @return BillCollection
|
* @return BillCollection
|
||||||
*/
|
*/
|
||||||
public function getBillReport(Carbon $start, Carbon $end, $shared)
|
public function getBillReport(Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
/** @var \FireflyIII\Repositories\Bill\BillRepositoryInterface $repository */
|
||||||
$repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
$repository = App::make('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
@@ -37,11 +37,10 @@ interface ReportHelperInterface
|
|||||||
*
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
* @param boolean $shared
|
|
||||||
*
|
*
|
||||||
* @return BillCollection
|
* @return BillCollection
|
||||||
*/
|
*/
|
||||||
public function getBillReport(Carbon $start, Carbon $end, $shared);
|
public function getBillReport(Carbon $start, Carbon $end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
|
@@ -176,9 +176,7 @@ class CategoryController extends Controller
|
|||||||
$start = new Carbon($year . '-01-01');
|
$start = new Carbon($year . '-01-01');
|
||||||
$end = new Carbon($year . '-12-31');
|
$end = new Carbon($year . '-12-31');
|
||||||
|
|
||||||
|
$cache = new CacheProperties; // chart properties for cache:
|
||||||
// chart properties for cache:
|
|
||||||
$cache = new CacheProperties;
|
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty('category');
|
$cache->addProperty('category');
|
||||||
@@ -192,14 +190,11 @@ class CategoryController extends Controller
|
|||||||
$entries = new Collection;
|
$entries = new Collection;
|
||||||
|
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
// month is the current end of the period:
|
$month = clone $start; // month is the current end of the period
|
||||||
$month = clone $start;
|
|
||||||
$month->endOfMonth();
|
$month->endOfMonth();
|
||||||
// make a row:
|
$row = [clone $start]; // make a row:
|
||||||
$row = [clone $start];
|
|
||||||
|
|
||||||
// each budget, fill the row:
|
foreach ($categories as $category) { // each budget, fill the row
|
||||||
foreach ($categories as $category) {
|
|
||||||
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
|
||||||
$row[] = $spent;
|
$row[] = $spent;
|
||||||
}
|
}
|
||||||
|
@@ -75,7 +75,7 @@ class CsvController extends Controller
|
|||||||
for ($i = 1; $i <= $count; $i++) {
|
for ($i = 1; $i <= $count; $i++) {
|
||||||
$headers[] = trans('firefly.csv_column') . ' #' . $i;
|
$headers[] = trans('firefly.csv_column') . ' #' . $i;
|
||||||
}
|
}
|
||||||
if ($this->data->getHasHeaders()) {
|
if ($this->data->hasHeaders()) {
|
||||||
$headers = $firstRow;
|
$headers = $firstRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,6 @@ class CsvController extends Controller
|
|||||||
return redirect(route('csv.index'));
|
return redirect(route('csv.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// process given roles and mapping:
|
// process given roles and mapping:
|
||||||
$roles = $this->wizard->processSelectedRoles(Input::get('role'));
|
$roles = $this->wizard->processSelectedRoles(Input::get('role'));
|
||||||
$maps = $this->wizard->processSelectedMapping($roles, Input::get('map'));
|
$maps = $this->wizard->processSelectedMapping($roles, Input::get('map'));
|
||||||
@@ -192,9 +191,7 @@ class CsvController extends Controller
|
|||||||
Session::put('csv-map', $maps);
|
Session::put('csv-map', $maps);
|
||||||
Session::put('csv-roles', $roles);
|
Session::put('csv-roles', $roles);
|
||||||
|
|
||||||
/*
|
// Go back when no roles defined:
|
||||||
* Go back when no roles defined:
|
|
||||||
*/
|
|
||||||
if (count($roles) === 0) {
|
if (count($roles) === 0) {
|
||||||
Session::flash('warning', 'Please select some roles.');
|
Session::flash('warning', 'Please select some roles.');
|
||||||
|
|
||||||
@@ -256,7 +253,7 @@ class CsvController extends Controller
|
|||||||
// After these values are prepped, read the actual CSV file
|
// After these values are prepped, read the actual CSV file
|
||||||
$reader = $this->data->getReader();
|
$reader = $this->data->getReader();
|
||||||
$map = $this->data->getMap();
|
$map = $this->data->getMap();
|
||||||
$hasHeaders = $this->data->getHasHeaders();
|
$hasHeaders = $this->data->hasHeaders();
|
||||||
$values = $this->wizard->getMappableValues($reader, $map, $hasHeaders);
|
$values = $this->wizard->getMappableValues($reader, $map, $hasHeaders);
|
||||||
$map = $this->data->getMap();
|
$map = $this->data->getMap();
|
||||||
$mapped = $this->data->getMapped();
|
$mapped = $this->data->getMapped();
|
||||||
|
@@ -566,7 +566,6 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
);
|
);
|
||||||
$journal->save();
|
$journal->save();
|
||||||
|
|
||||||
|
|
||||||
if ($data['openingBalance'] < 0) {
|
if ($data['openingBalance'] < 0) {
|
||||||
$firstAccount = $opposing;
|
$firstAccount = $opposing;
|
||||||
$secondAccount = $account;
|
$secondAccount = $account;
|
||||||
@@ -578,26 +577,11 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
$firstAmount = $data['openingBalance'];
|
$firstAmount = $data['openingBalance'];
|
||||||
$secondAmount = $data['openingBalance'] * -1;
|
$secondAmount = $data['openingBalance'] * -1;
|
||||||
}
|
}
|
||||||
|
$one = new Transaction(['account_id' => $firstAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $firstAmount]);
|
||||||
|
$one->save();// first transaction: from
|
||||||
|
|
||||||
// first transaction: from
|
$two = new Transaction(['account_id' => $secondAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $secondAmount]);
|
||||||
$one = new Transaction(
|
$two->save(); // second transaction: to
|
||||||
[
|
|
||||||
'account_id' => $firstAccount->id,
|
|
||||||
'transaction_journal_id' => $journal->id,
|
|
||||||
'amount' => $firstAmount
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$one->save();
|
|
||||||
|
|
||||||
// second transaction: to
|
|
||||||
$two = new Transaction(
|
|
||||||
[
|
|
||||||
'account_id' => $secondAccount->id,
|
|
||||||
'transaction_journal_id' => $journal->id,
|
|
||||||
'amount' => $secondAmount
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$two->save();
|
|
||||||
|
|
||||||
return $journal;
|
return $journal;
|
||||||
|
|
||||||
@@ -606,6 +590,8 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
*/
|
*/
|
||||||
protected function updateMetadata(Account $account, array $data)
|
protected function updateMetadata(Account $account, array $data)
|
||||||
{
|
{
|
||||||
|
@@ -115,14 +115,14 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param int $journalId
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return TransactionJournal
|
* @return TransactionJournal
|
||||||
*/
|
*/
|
||||||
public function getWithDate($id, Carbon $date)
|
public function getWithDate($journalId, Carbon $date)
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()->where('id', $id)->where('date', $date->format('Y-m-d 00:00:00'))->first();
|
return Auth::user()->transactionjournals()->where('id', $journalId)->where('date', $date->format('Y-m-d 00:00:00'))->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -62,12 +62,12 @@ interface JournalRepositoryInterface
|
|||||||
public function getTransactionType($type);
|
public function getTransactionType($type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id
|
* @param int $journalId
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
*
|
*
|
||||||
* @return TransactionJournal
|
* @return TransactionJournal
|
||||||
*/
|
*/
|
||||||
public function getWithDate($id, Carbon $date);
|
public function getWithDate($journalId, Carbon $date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
|
@@ -57,7 +57,8 @@ class FireflyValidator extends Validator
|
|||||||
/**
|
/**
|
||||||
* @param $attribute
|
* @param $attribute
|
||||||
* @param $value
|
* @param $value
|
||||||
* @param $parameters
|
*
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function validateIban($attribute, $value)
|
public function validateIban($attribute, $value)
|
||||||
{
|
{
|
||||||
@@ -200,9 +201,10 @@ class FireflyValidator extends Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
* @param $parameters
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @internal param $parameters
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected function validateByAccountId($value)
|
protected function validateByAccountId($value)
|
||||||
{
|
{
|
||||||
|
@@ -3,6 +3,11 @@ namespace Helper;
|
|||||||
// here you can define custom actions
|
// here you can define custom actions
|
||||||
// all public methods declared in helper class will be available in $I
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Acceptance
|
||||||
|
*
|
||||||
|
* @package Helper
|
||||||
|
*/
|
||||||
class Acceptance extends \Codeception\Module
|
class Acceptance extends \Codeception\Module
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -3,6 +3,11 @@ namespace Helper;
|
|||||||
// here you can define custom actions
|
// here you can define custom actions
|
||||||
// all public methods declared in helper class will be available in $I
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Functional
|
||||||
|
*
|
||||||
|
* @package Helper
|
||||||
|
*/
|
||||||
class Functional extends \Codeception\Module
|
class Functional extends \Codeception\Module
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -3,6 +3,11 @@ namespace Helper;
|
|||||||
// here you can define custom actions
|
// here you can define custom actions
|
||||||
// all public methods declared in helper class will be available in $I
|
// all public methods declared in helper class will be available in $I
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Unit
|
||||||
|
*
|
||||||
|
* @package Helper
|
||||||
|
*/
|
||||||
class Unit extends \Codeception\Module
|
class Unit extends \Codeception\Module
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@@ -8,6 +8,11 @@ namespace _generated;
|
|||||||
use Codeception\Module\PhpBrowser;
|
use Codeception\Module\PhpBrowser;
|
||||||
use Helper\Acceptance;
|
use Helper\Acceptance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AcceptanceTesterActions
|
||||||
|
*
|
||||||
|
* @package _generated
|
||||||
|
*/
|
||||||
trait AcceptanceTesterActions
|
trait AcceptanceTesterActions
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@@ -7,6 +7,11 @@ namespace _generated;
|
|||||||
|
|
||||||
use Helper\Functional;
|
use Helper\Functional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FunctionalTesterActions
|
||||||
|
*
|
||||||
|
* @package _generated
|
||||||
|
*/
|
||||||
trait FunctionalTesterActions
|
trait FunctionalTesterActions
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@@ -9,6 +9,11 @@ use Codeception\Module\Laravel5;
|
|||||||
use Codeception\Module\Asserts;
|
use Codeception\Module\Asserts;
|
||||||
use Helper\Unit;
|
use Helper\Unit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class UnitTesterActions
|
||||||
|
*
|
||||||
|
* @package _generated
|
||||||
|
*/
|
||||||
trait UnitTesterActions
|
trait UnitTesterActions
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user