From 0dc188b083b0cd887975417aedd8f6bee77fb8bf Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 21 Oct 2016 21:41:50 +0200 Subject: [PATCH] Removed old code --- app/Crud/Split/Journal.php | 221 ---------------------------- app/Crud/Split/JournalInterface.php | 50 ------- 2 files changed, 271 deletions(-) delete mode 100644 app/Crud/Split/Journal.php delete mode 100644 app/Crud/Split/JournalInterface.php diff --git a/app/Crud/Split/Journal.php b/app/Crud/Split/Journal.php deleted file mode 100644 index 6fdc6b33ab..0000000000 --- a/app/Crud/Split/Journal.php +++ /dev/null @@ -1,221 +0,0 @@ -user = $user; - } - - /** - * @param $journal - * - * @return bool - */ - public function markAsComplete(TransactionJournal $journal) - { - $journal->completed = 1; - $journal->save(); - - return true; - } - - /** - * @param TransactionJournal $journal - * @param array $transaction - * @param int $identifier - * - * @return Collection - */ - public function storeTransaction(TransactionJournal $journal, array $transaction, int $identifier): Collection - { - // store accounts (depends on type) - list($sourceAccount, $destinationAccount) = $this->storeAccounts($journal->transactionType->type, $transaction); - - // store transaction one way: - /** @var Transaction $one */ - $one = Transaction::create( - ['account_id' => $sourceAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'] * -1, - 'description' => $transaction['description'], 'identifier' => $identifier] - ); - $two = Transaction::create( - ['account_id' => $destinationAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $transaction['amount'], - 'description' => $transaction['description'], 'identifier' => $identifier] - ); - - if (strlen($transaction['category']) > 0) { - $category = Category::firstOrCreateEncrypted(['name' => $transaction['category'], 'user_id' => $journal->user_id]); - $one->categories()->save($category); - $two->categories()->save($category); - } - if (intval($transaction['budget_id']) > 0) { - $budget = Budget::find($transaction['budget_id']); - $one->budgets()->save($budget); - $two->budgets()->save($budget); - } - - if ($transaction['piggy_bank_id'] > 0) { - $transaction['date'] = $journal->date->format('Y-m-d'); - event(new TransactionStored($transaction)); - } - - return new Collection([$one, $two]); - } - - /** - * @param TransactionJournal $journal - * @param array $data - * - * @return TransactionJournal - */ - public function updateJournal(TransactionJournal $journal, array $data): TransactionJournal - { - $journal->description = $data['journal_description']; - $journal->transaction_currency_id = $data['journal_currency_id']; - $journal->date = $data['date']; - $journal->interest_date = $data['interest_date']; - $journal->book_date = $data['book_date']; - $journal->process_date = $data['process_date']; - $journal->save(); - - // delete original transactions, and recreate them. - $journal->transactions()->delete(); - - $identifier = 0; - foreach ($data['transactions'] as $transaction) { - $this->storeTransaction($journal, $transaction, $identifier); - $identifier++; - } - - $journal->completed = true; - $journal->save(); - - return $journal; - } - - /** - * @param string $type - * @param array $transaction - * - * @return array - * @throws FireflyException - */ - private function storeAccounts(string $type, array $transaction): array - { - $sourceAccount = null; - $destinationAccount = null; - switch ($type) { - case TransactionType::WITHDRAWAL: - list($sourceAccount, $destinationAccount) = $this->storeWithdrawalAccounts($transaction); - break; - case TransactionType::DEPOSIT: - list($sourceAccount, $destinationAccount) = $this->storeDepositAccounts($transaction); - break; - case TransactionType::TRANSFER: - $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['source_account_id'])->first(); - $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $transaction['destination_account_id'])->first(); - break; - default: - throw new FireflyException('Cannot handle ' . e($type)); - } - - return [$sourceAccount, $destinationAccount]; - } - - /** - * @param array $data - * - * @return array - */ - private function storeDepositAccounts(array $data): array - { - $destinationAccount = Account::where('user_id', $this->user->id)->where('id', $data['destination_account_id'])->first(['accounts.*']); - - - if (isset($data['source_account_name']) && strlen($data['source_account_name']) > 0) { - $sourceType = AccountType::where('type', 'Revenue account')->first(); - $sourceAccount = Account::firstOrCreateEncrypted( - ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => $data['source_account_name'], 'active' => 1] - ); - - return [$sourceAccount, $destinationAccount]; - } - - $sourceType = AccountType::where('type', 'Cash account')->first(); - $sourceAccount = Account::firstOrCreateEncrypted( - ['user_id' => $this->user->id, 'account_type_id' => $sourceType->id, 'name' => 'Cash account', 'active' => 1] - ); - - return [$sourceAccount, $destinationAccount]; - } - - /** - * @param array $data - * - * @return array - */ - private function storeWithdrawalAccounts(array $data): array - { - $sourceAccount = Account::where('user_id', $this->user->id)->where('id', $data['source_account_id'])->first(['accounts.*']); - - if (strlen($data['destination_account_name']) > 0) { - $destinationType = AccountType::where('type', 'Expense account')->first(); - $destinationAccount = Account::firstOrCreateEncrypted( - [ - 'user_id' => $this->user->id, - 'account_type_id' => $destinationType->id, - 'name' => $data['destination_account_name'], - 'active' => 1, - ] - ); - - return [$sourceAccount, $destinationAccount]; - } - $destinationType = AccountType::where('type', 'Cash account')->first(); - $destinationAccount = Account::firstOrCreateEncrypted( - ['user_id' => $this->user->id, 'account_type_id' => $destinationType->id, 'name' => 'Cash account', 'active' => 1] - ); - - return [$sourceAccount, $destinationAccount]; - - - } -} diff --git a/app/Crud/Split/JournalInterface.php b/app/Crud/Split/JournalInterface.php deleted file mode 100644 index e296a1114c..0000000000 --- a/app/Crud/Split/JournalInterface.php +++ /dev/null @@ -1,50 +0,0 @@ -