mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Some issues fixed for scrutiniser.
This commit is contained in:
@@ -39,31 +39,31 @@ class JournalFormRequest extends Request
|
|||||||
*/
|
*/
|
||||||
public function getJournalData()
|
public function getJournalData()
|
||||||
{
|
{
|
||||||
$tags = $this->get('tags') ?? '';
|
$tags = $this->getFieldOrEmptyString('tags');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'what' => $this->get('what'),
|
'what' => $this->get('what'),
|
||||||
'description' => $this->get('description'),
|
'description' => $this->get('description'),
|
||||||
'source_account_id' => intval($this->get('source_account_id')),
|
'source_account_id' => intval($this->get('source_account_id')),
|
||||||
'source_account_name' => $this->get('source_account_name') ?? '',
|
'source_account_name' => $this->getFieldOrEmptyString('source_account_name'),
|
||||||
'destination_account_id' => intval($this->get('destination_account_id')),
|
'destination_account_id' => intval($this->get('destination_account_id')),
|
||||||
'destination_account_name' => $this->get('destination_account_name') ?? '',
|
'destination_account_name' => $this->getFieldOrEmptyString('destination_account_name'),
|
||||||
'amount' => round($this->get('amount'), 2),
|
'amount' => round($this->get('amount'), 2),
|
||||||
'user' => auth()->user()->id,
|
'user' => auth()->user()->id,
|
||||||
'amount_currency_id_amount' => intval($this->get('amount_currency_id_amount')),
|
'amount_currency_id_amount' => intval($this->get('amount_currency_id_amount')),
|
||||||
'date' => new Carbon($this->get('date')),
|
'date' => new Carbon($this->get('date')),
|
||||||
'interest_date' => $this->get('interest_date') ? new Carbon($this->get('interest_date')) : null,
|
'interest_date' => $this->getDateOrNull('interest_date'),
|
||||||
'book_date' => $this->get('book_date') ? new Carbon($this->get('book_date')) : null,
|
'book_date' => $this->getDateOrNull('book_date'),
|
||||||
'process_date' => $this->get('process_date') ? new Carbon($this->get('process_date')) : null,
|
'process_date' => $this->getDateOrNull('process_date'),
|
||||||
'budget_id' => intval($this->get('budget_id')),
|
'budget_id' => intval($this->get('budget_id')),
|
||||||
'category' => $this->get('category') ?? '',
|
'category' => $this->getFieldOrEmptyString('category'),
|
||||||
'tags' => explode(',', $tags),
|
'tags' => explode(',', $tags),
|
||||||
'piggy_bank_id' => $this->get('piggy_bank_id') ? intval($this->get('piggy_bank_id')) : 0,
|
'piggy_bank_id' => intval($this->get('piggy_bank_id')),
|
||||||
|
|
||||||
// new custom fields here:
|
// new custom fields here:
|
||||||
'due_date' => $this->get('due_date') ? new Carbon($this->get('due_date')) : null,
|
'due_date' => $this->getDateOrNull('due_date'),
|
||||||
'payment_date' => $this->get('payment_date') ? new Carbon($this->get('payment_date')) : null,
|
'payment_date' => $this->getDateOrNull('payment_date'),
|
||||||
'invoice_date' => $this->get('invoice_date') ? new Carbon($this->get('invoice_date')) : null,
|
'invoice_date' => $this->getDateOrNull('invoice_date'),
|
||||||
'internal_reference' => $this->get('internal_reference'),
|
'internal_reference' => $this->get('internal_reference'),
|
||||||
'notes' => $this->get('notes'),
|
'notes' => $this->get('notes'),
|
||||||
|
|
||||||
@@ -119,4 +119,24 @@ class JournalFormRequest extends Request
|
|||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return Carbon|null
|
||||||
|
*/
|
||||||
|
private function getDateOrNull(string $field)
|
||||||
|
{
|
||||||
|
return $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getFieldOrEmptyString(string $field): string
|
||||||
|
{
|
||||||
|
return $this->get($field) ?? '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,6 @@ use Symfony\Component\HttpFoundation\FileBag;
|
|||||||
*/
|
*/
|
||||||
class CsvSetup implements SetupInterface
|
class CsvSetup implements SetupInterface
|
||||||
{
|
{
|
||||||
const EXAMPLE_ROWS = 5;
|
|
||||||
/** @var Account */
|
/** @var Account */
|
||||||
public $defaultImportAccount;
|
public $defaultImportAccount;
|
||||||
/** @var ImportJob */
|
/** @var ImportJob */
|
||||||
@@ -50,29 +49,13 @@ class CsvSetup implements SetupInterface
|
|||||||
/**
|
/**
|
||||||
* Create initial (empty) configuration array.
|
* Create initial (empty) configuration array.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function configure(): bool
|
public function configure(): bool
|
||||||
{
|
{
|
||||||
if (is_null($this->job->configuration) || (is_array($this->job->configuration) && count($this->job->configuration) === 0)) {
|
if (is_null($this->job->configuration) || (is_array($this->job->configuration) && count($this->job->configuration) === 0)) {
|
||||||
Log::debug('No config detected, will create empty one.');
|
Log::debug('No config detected, will create empty one.');
|
||||||
|
$this->job->configuration = config('csv.default_config');
|
||||||
$config = [
|
|
||||||
'has-headers' => false, // assume
|
|
||||||
'date-format' => 'Ymd', // assume
|
|
||||||
'delimiter' => ',', // assume
|
|
||||||
'import-account' => 0, // none,
|
|
||||||
'specifics' => [], // none
|
|
||||||
'column-count' => 0, // unknown
|
|
||||||
'column-roles' => [], // unknown
|
|
||||||
'column-do-mapping' => [], // not yet set which columns must be mapped
|
|
||||||
'column-roles-complete' => false, // not yet configured roles for columns
|
|
||||||
'column-mapping-config' => [], // no mapping made yet.
|
|
||||||
'column-mapping-complete' => false, // so mapping is not complete.
|
|
||||||
];
|
|
||||||
$this->job->configuration = $config;
|
|
||||||
$this->job->save();
|
$this->job->save();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -149,6 +132,7 @@ class CsvSetup implements SetupInterface
|
|||||||
* the import job.
|
* the import job.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function getViewForSettings(): string
|
public function getViewForSettings(): string
|
||||||
{
|
{
|
||||||
@@ -159,9 +143,7 @@ class CsvSetup implements SetupInterface
|
|||||||
if ($this->doColumnMapping()) {
|
if ($this->doColumnMapping()) {
|
||||||
return 'import.csv.map';
|
return 'import.csv.map';
|
||||||
}
|
}
|
||||||
|
throw new FireflyException('There is no view for the current CSV import step.');
|
||||||
echo 'no view for settings';
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,8 +154,8 @@ class CsvSetup implements SetupInterface
|
|||||||
*/
|
*/
|
||||||
public function requireUserSettings(): bool
|
public function requireUserSettings(): bool
|
||||||
{
|
{
|
||||||
Log::debug('doColumnMapping is ' . ($this->doColumnMapping() ? 'true' : 'false'));
|
Log::debug(sprintf('doColumnMapping is %s', $this->doColumnMapping()));
|
||||||
Log::debug('doColumnRoles is ' . ($this->doColumnRoles() ? 'true' : 'false'));
|
Log::debug(sprintf('doColumnRoles is %s', $this->doColumnRoles()));
|
||||||
if ($this->doColumnMapping() || $this->doColumnRoles()) {
|
if ($this->doColumnMapping() || $this->doColumnRoles()) {
|
||||||
Log::debug('Return true');
|
Log::debug('Return true');
|
||||||
|
|
||||||
@@ -448,7 +430,7 @@ class CsvSetup implements SetupInterface
|
|||||||
$reader = Reader::createFromString($content);
|
$reader = Reader::createFromString($content);
|
||||||
$reader->setDelimiter($config['delimiter']);
|
$reader->setDelimiter($config['delimiter']);
|
||||||
$start = $config['has-headers'] ? 1 : 0;
|
$start = $config['has-headers'] ? 1 : 0;
|
||||||
$end = $start + self::EXAMPLE_ROWS; // first X rows
|
$end = $start + config('csv.example_rows');
|
||||||
|
|
||||||
// collect example data in $data['columns']
|
// collect example data in $data['columns']
|
||||||
while ($start < $end) {
|
while ($start < $end) {
|
||||||
|
@@ -276,4 +276,20 @@ return [
|
|||||||
'field' => 'description',
|
'field' => 'description',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// number of example rows:
|
||||||
|
'example_rows' => 5,
|
||||||
|
'default_config' => [
|
||||||
|
'has-headers' => false, // assume
|
||||||
|
'date-format' => 'Ymd', // assume
|
||||||
|
'delimiter' => ',', // assume
|
||||||
|
'import-account' => 0, // none,
|
||||||
|
'specifics' => [], // none
|
||||||
|
'column-count' => 0, // unknown
|
||||||
|
'column-roles' => [], // unknown
|
||||||
|
'column-do-mapping' => [], // not yet set which columns must be mapped
|
||||||
|
'column-roles-complete' => false, // not yet configured roles for columns
|
||||||
|
'column-mapping-config' => [], // no mapping made yet.
|
||||||
|
'column-mapping-complete' => false, // so mapping is not complete.
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user