Some new stuff that really doesn't belong here. I'm not good at this.

This commit is contained in:
James Cole
2014-09-03 07:11:35 +02:00
parent 98612dd253
commit c3fd5c7136
11 changed files with 366 additions and 75 deletions

View File

@@ -52,6 +52,30 @@ class Import
}
/**
* @param Job $job
* @param array $payload
*/
public function cleanImportAccount(Job $job, array $payload)
{
$importAccountType = $this->_accounts->findAccountType('Import account');
$importAccounts = $this->_accounts->getByAccountType($importAccountType);
if (count($importAccounts) == 0) {
$job->delete();
} else if (count($importAccounts) == 1) {
/** @var \Account $importAccount */
$importAccount = $importAccounts[0];
$transactions = $importAccount->transactions()->get();
/** @var \Transaction $transaction */
foreach ($transactions as $transaction) {
$transaction->account()->associate($importAccount);
$transaction->save();
}
\Log::debug('Updated ' . count($transactions) . ' transactions from Import Account to cash.');
}
$job->delete();
}
/**
* @param Job $job
* @param array $payload
@@ -611,8 +635,13 @@ class Import
\Queue::push($jobFunction, ['data' => $entry, 'mapID' => $importMap->id]);
}
// queue a job to clean up the "import account", it should properly fall back
// to the cash account (which it doesn't always do for some reason).
\Queue::push('Firefly\Queue\Import@cleanImportAccount', ['mapID' => $importMap->id]);
}
\Log::debug('Done with job "start"');
// this is it, close the job:
$job->delete();

View File

@@ -101,6 +101,12 @@ interface AccountRepositoryInterface
*/
public function getDefault();
/**
* @param \AccountType $type
* @return mixed
*/
public function getByAccountType(\AccountType $type);
/**
* @param \User $user
* @return mixed

View File

@@ -209,6 +209,12 @@ class EloquentAccountRepository implements AccountRepositoryInterface
return $list;
}
public function getByAccountType(\AccountType $type)
{
return $this->_user->accounts()->with('accounttype')->orderBy('name', 'ASC')
->where('account_type_id', $type->id)->get();
}
/**
* @param $ids
*