mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Code optimalization
This commit is contained in:
parent
ffb699cb06
commit
99b3e24836
@ -59,7 +59,7 @@ class EncryptFile extends Command
|
|||||||
}
|
}
|
||||||
$content = file_get_contents($file);
|
$content = file_get_contents($file);
|
||||||
$content = Crypt::encrypt($content);
|
$content = Crypt::encrypt($content);
|
||||||
$newName = e($this->argument('key')) . '.upload';
|
$newName = e(strval($this->argument('key'))) . '.upload';
|
||||||
|
|
||||||
$path = storage_path('upload') . '/' . $newName;
|
$path = storage_path('upload') . '/' . $newName;
|
||||||
file_put_contents($path, $content);
|
file_put_contents($path, $content);
|
||||||
|
@ -49,25 +49,9 @@ class SplitJournalFormRequest extends Request
|
|||||||
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
||||||
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
|
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
|
||||||
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
||||||
'transactions' => [],
|
'transactions' => $this->getTransactionData(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// description is leading because it is one of the mandatory fields.
|
|
||||||
foreach ($this->get('description') as $index => $description) {
|
|
||||||
$transaction = [
|
|
||||||
'description' => $description,
|
|
||||||
'amount' => round($this->get('amount')[$index], 2),
|
|
||||||
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
|
|
||||||
'category' => $this->get('category')[$index] ?? '',
|
|
||||||
'source_account_id' => isset($this->get('source_account_id')[$index]) ? intval($this->get('source_account_id')[$index]) : intval($this->get('journal_source_account_id')),
|
|
||||||
'source_account_name' => $this->get('source_account_name')[$index] ?? '',
|
|
||||||
'piggy_bank_id' => isset($this->get('piggy_bank_id')[$index]) ? intval($this->get('piggy_bank_id')[$index]) : 0,
|
|
||||||
'destination_account_id' => isset($this->get('destination_account_id')[$index]) ? intval($this->get('destination_account_id')[$index]) : intval($this->get('journal_destination_account_id')),
|
|
||||||
'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',
|
|
||||||
];
|
|
||||||
$data['transactions'][] = $transaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,14 +71,46 @@ class SplitJournalFormRequest extends Request
|
|||||||
'interest_date' => 'date',
|
'interest_date' => 'date',
|
||||||
'book_date' => 'date',
|
'book_date' => 'date',
|
||||||
'process_date' => 'date',
|
'process_date' => 'date',
|
||||||
|
'description.*' => 'required|between:1,255',
|
||||||
'description.*' => 'required|between:1,255',
|
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
|
||||||
'destination_account_id.*' => 'numeric|belongsToUser:accounts,id',
|
'destination_account_name.*' => 'between:1,255',
|
||||||
'destination_account_name.*' => 'between:1,255',
|
'amount.*' => 'required|numeric',
|
||||||
'amount.*' => 'required|numeric',
|
'budget_id.*' => 'belongsToUser:budgets,id',
|
||||||
'budget_id.*' => 'belongsToUser:budgets,id',
|
'category.*' => 'between:1,255',
|
||||||
'category.*' => 'between:1,255',
|
'piggy_bank_id.*' => 'between:1,255',
|
||||||
'piggy_bank_id.*' => 'between:1,255',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getTransactionData(): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// description is leading because it is one of the mandatory fields.
|
||||||
|
foreach ($this->get('description') as $index => $description) {
|
||||||
|
$transaction = [
|
||||||
|
'description' => $description,
|
||||||
|
'amount' => round($this->get('amount')[$index], 2),
|
||||||
|
'budget_id' => $this->get('budget_id')[$index] ? intval($this->get('budget_id')[$index]) : 0,
|
||||||
|
'category' => $this->get('category')[$index] ?? '',
|
||||||
|
'source_account_id' => isset($this->get('source_account_id')[$index])
|
||||||
|
? intval($this->get('source_account_id')[$index])
|
||||||
|
: intval(
|
||||||
|
$this->get('journal_source_account_id')
|
||||||
|
),
|
||||||
|
'source_account_name' => $this->get('source_account_name')[$index] ?? '',
|
||||||
|
'piggy_bank_id' => isset($this->get('piggy_bank_id')[$index]) ? intval($this->get('piggy_bank_id')[$index]) : 0,
|
||||||
|
'destination_account_id' => isset($this->get('destination_account_id')[$index])
|
||||||
|
? intval($this->get('destination_account_id')[$index])
|
||||||
|
: intval(
|
||||||
|
$this->get('journal_destination_account_id')
|
||||||
|
),
|
||||||
|
'destination_account_name' => $this->get('destination_account_name')[$index] ?? '',
|
||||||
|
];
|
||||||
|
$return[] = $transaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ class ImportStorage
|
|||||||
$one = Transaction::create($sourceData);
|
$one = Transaction::create($sourceData);
|
||||||
$two = Transaction::create($destinationData);
|
$two = Transaction::create($destinationData);
|
||||||
Log::debug('Created transaction 1', ['id' => $one->id, 'account' => $one->account_id, 'account_name' => $accounts['source']->name]);
|
Log::debug('Created transaction 1', ['id' => $one->id, 'account' => $one->account_id, 'account_name' => $accounts['source']->name]);
|
||||||
Log::debug('Created transaction 2', ['id' => $two->id, 'account' => $two->account_id, 'account_name' => $destination->name]);
|
Log::debug('Created transaction 2', ['id' => $two->id, 'account' => $two->account_id, 'account_name' => $accounts['destination']->name]);
|
||||||
|
|
||||||
$journal->completed = 1;
|
$journal->completed = 1;
|
||||||
$journal->save();
|
$journal->save();
|
||||||
|
Loading…
Reference in New Issue
Block a user