Remove bill references.

This commit is contained in:
James Cole 2019-08-27 06:12:08 +02:00
parent e308b0f617
commit ce5fcbbda2

View File

@ -28,11 +28,9 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\CategoryFactory; use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RecurrenceTransactionMeta; use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
@ -44,8 +42,6 @@ use Log;
*/ */
class RecurrenceTransformer extends AbstractTransformer class RecurrenceTransformer extends AbstractTransformer
{ {
/** @var BillRepositoryInterface */
private $billRepos;
/** @var BudgetRepositoryInterface */ /** @var BudgetRepositoryInterface */
private $budgetRepos; private $budgetRepos;
/** @var CategoryFactory */ /** @var CategoryFactory */
@ -63,7 +59,6 @@ class RecurrenceTransformer extends AbstractTransformer
public function __construct() public function __construct()
{ {
$this->repository = app(RecurringRepositoryInterface::class); $this->repository = app(RecurringRepositoryInterface::class);
$this->billRepos = app(BillRepositoryInterface::class);
$this->piggyRepos = app(PiggyBankRepositoryInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class);
$this->factory = app(CategoryFactory::class); $this->factory = app(CategoryFactory::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class); $this->budgetRepos = app(BudgetRepositoryInterface::class);
@ -85,7 +80,6 @@ class RecurrenceTransformer extends AbstractTransformer
{ {
Log::debug('Now in Recurrence::transform()'); Log::debug('Now in Recurrence::transform()');
$this->repository->setUser($recurrence->user); $this->repository->setUser($recurrence->user);
$this->billRepos->setUser($recurrence->user);
$this->piggyRepos->setUser($recurrence->user); $this->piggyRepos->setUser($recurrence->user);
$this->factory->setUser($recurrence->user); $this->factory->setUser($recurrence->user);
$this->budgetRepos->setUser($recurrence->user); $this->budgetRepos->setUser($recurrence->user);
@ -121,48 +115,6 @@ class RecurrenceTransformer extends AbstractTransformer
return $return; return $return;
} }
/**
* @param Recurrence $recurrence
*
* @return array
*/
private function getMeta(Recurrence $recurrence): array
{
$return = [];
$collection = $recurrence->recurrenceMeta;
Log::debug(sprintf('Meta collection length = %d', $collection->count()));
/** @var RecurrenceMeta $recurrenceMeta */
foreach ($collection as $recurrenceMeta) {
$recurrenceMetaArray = [
'name' => $recurrenceMeta->name,
'value' => $recurrenceMeta->value,
];
switch ($recurrenceMeta->name) {
case 'tags':
$recurrenceMetaArray['tags'] = explode(',', $recurrenceMeta->value);
break;
case 'bill_id':
$bill = $this->billRepos->find((int)$recurrenceMeta->value);
if (null !== $bill) {
$recurrenceMetaArray['bill_id'] = $bill->id;
$recurrenceMetaArray['bill_name'] = $bill->name;
}
break;
case 'piggy_bank_id':
$piggy = $this->piggyRepos->findNull((int)$recurrenceMeta->value);
if (null !== $piggy) {
$recurrenceMetaArray['piggy_bank_id'] = $piggy->id;
$recurrenceMetaArray['piggy_bank_name'] = $piggy->name;
}
break;
}
// store meta date in recurring array
$return[] = $recurrenceMetaArray;
}
return $return;
}
/** /**
* @param Recurrence $recurrence * @param Recurrence $recurrence
* *
@ -214,8 +166,6 @@ class RecurrenceTransformer extends AbstractTransformer
private function getTransactionMeta(RecurrenceTransaction $transaction, array $array): array private function getTransactionMeta(RecurrenceTransaction $transaction, array $array): array
{ {
$array['tags'] = []; $array['tags'] = [];
$array['bill_id'] = null;
$array['bill_name'] = null;
$array['category_id'] = null; $array['category_id'] = null;
$array['category_name'] = null; $array['category_name'] = null;
$array['budget_id'] = null; $array['budget_id'] = null;
@ -231,13 +181,6 @@ class RecurrenceTransformer extends AbstractTransformer
case 'tags': case 'tags':
$array['tags'] = json_decode($transactionMeta->value); $array['tags'] = json_decode($transactionMeta->value);
break; break;
case 'bill_id':
$bill = $this->billRepos->find((int)$transactionMeta->value);
if (null !== $bill) {
$array['bill_id'] = $bill->id;
$array['bill_name'] = $bill->name;
}
break;
case 'piggy_bank_id': case 'piggy_bank_id':
$piggy = $this->piggyRepos->findNull((int)$transactionMeta->value); $piggy = $this->piggyRepos->findNull((int)$transactionMeta->value);
if (null !== $piggy) { if (null !== $piggy) {