mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Covered transaction controller.
This commit is contained in:
parent
3176e54614
commit
59d2bf3f79
@ -12,12 +12,12 @@ use FireflyIII\Models\TransactionJournal;
|
|||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Input;
|
use Input;
|
||||||
use Log;
|
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
use Session;
|
||||||
use URL;
|
use URL;
|
||||||
use View;
|
use View;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TransactionController
|
* Class TransactionController
|
||||||
@ -263,7 +263,6 @@ class TransactionController extends Controller
|
|||||||
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
|
public function store(JournalFormRequest $request, JournalRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$journalData = $request->getJournalData();
|
$journalData = $request->getJournalData();
|
||||||
$journal = $repository->store($journalData);
|
$journal = $repository->store($journalData);
|
||||||
|
|
||||||
@ -272,11 +271,7 @@ class TransactionController extends Controller
|
|||||||
// ConnectJournalToPiggyBank
|
// ConnectJournalToPiggyBank
|
||||||
event(new JournalCreated($journal, intval($request->get('piggy_bank_id'))));
|
event(new JournalCreated($journal, intval($request->get('piggy_bank_id'))));
|
||||||
|
|
||||||
if (intval($request->get('reminder_id')) > 0) {
|
$repository->deactivateReminder($request->get('reminder_id'));
|
||||||
$reminder = Auth::user()->reminders()->find($request->get('reminder_id'));
|
|
||||||
$reminder->active = 0;
|
|
||||||
$reminder->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
Session::flash('success', 'New transaction "' . $journal->description . '" stored!');
|
Session::flash('success', 'New transaction "' . $journal->description . '" stored!');
|
||||||
|
|
||||||
@ -292,6 +287,8 @@ class TransactionController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param JournalFormRequest $request
|
* @param JournalFormRequest $request
|
||||||
* @param JournalRepositoryInterface $repository
|
* @param JournalRepositoryInterface $repository
|
||||||
|
@ -57,7 +57,7 @@ class JournalFormRequest extends Request
|
|||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'description' => 'required|min:1,max:255',
|
'description' => 'required|min:1,max:255',
|
||||||
'what' => 'required|in:withdrawal,deposit,transfer|exists:transaction_types,type',
|
'what' => 'required|in:withdrawal,deposit,transfer',
|
||||||
'amount' => 'numeric|required|min:0.01',
|
'amount' => 'numeric|required|min:0.01',
|
||||||
'date' => 'required|date',
|
'date' => 'required|date',
|
||||||
'reminder_id' => 'numeric|exists:reminders,id',
|
'reminder_id' => 'numeric|exists:reminders,id',
|
||||||
|
@ -26,6 +26,21 @@ use Log;
|
|||||||
class JournalRepository implements JournalRepositoryInterface
|
class JournalRepository implements JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deactivateReminder($id)
|
||||||
|
{
|
||||||
|
$reminder = Auth::user()->reminders()->find($id);
|
||||||
|
if ($reminder) {
|
||||||
|
$reminder->active = 0;
|
||||||
|
$reminder->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
@ -69,7 +84,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
->where('transaction_journals.order', '>=', $journal->order)
|
->where('transaction_journals.order', '>=', $journal->order)
|
||||||
->where('transaction_journals.id', '!=', $journal->id)
|
->where('transaction_journals.id', '!=', $journal->id)
|
||||||
->sum('transactions.amount')
|
->sum('transactions.amount')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,13 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
interface JournalRepositoryInterface
|
interface JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function deactivateReminder($id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
@ -30,14 +37,6 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function first();
|
public function first();
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $id
|
|
||||||
* @param Carbon $date
|
|
||||||
*
|
|
||||||
* @return TransactionJournal
|
|
||||||
*/
|
|
||||||
public function getWithDate($id, Carbon $date);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param Transaction $transaction
|
* @param Transaction $transaction
|
||||||
@ -69,6 +68,14 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getTransactionType($type);
|
public function getTransactionType($type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $id
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return TransactionJournal
|
||||||
|
*/
|
||||||
|
public function getWithDate($id, Carbon $date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @param array $array
|
* @param array $array
|
||||||
|
@ -15,7 +15,7 @@ class TransactionControllerTest extends TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
FactoryMuffin::create('FireflyIII\User');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -227,12 +227,92 @@ class TransactionControllerTest extends TestCase
|
|||||||
|
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
$this->be($account->user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'reminder_id' => '',
|
||||||
|
'what' => 'withdrawal',
|
||||||
|
'description' => 'Bla bla bla',
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'expense_account' => 'Bla bla',
|
||||||
|
'amount' => '100',
|
||||||
|
'amount_currency_id' => $currency->id,
|
||||||
|
'date' => '2015-05-05',
|
||||||
|
'budget_id' => '0',
|
||||||
|
'create_another' => '1',
|
||||||
|
'category' => '',
|
||||||
|
'tags' => '',
|
||||||
|
'piggy_bank_id' => '0',
|
||||||
|
'_token' => 'replaceMe',
|
||||||
|
];
|
||||||
|
|
||||||
|
// mock!
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
||||||
|
|
||||||
|
// fake!
|
||||||
|
$repository->shouldReceive('store')->andReturn($journal);
|
||||||
|
$repository->shouldReceive('deactivateReminder')->andReturnNull();
|
||||||
|
|
||||||
|
|
||||||
|
$this->call('POST', '/transactions/store/withdrawal', $data);
|
||||||
|
|
||||||
|
//$this->assertSessionHas('errors','bla');
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
|
$this->be($journal->user);
|
||||||
|
$account->user_id = $journal->user_id;
|
||||||
|
$account->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'_token' => 'replaceMe',
|
||||||
|
'id' => $journal->id,
|
||||||
|
'what' => 'withdrawal',
|
||||||
|
'description' => 'LunchX',
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'expense_account' => 'Lunch House',
|
||||||
|
'amount' => '4.72',
|
||||||
|
'amount_currency_id' => '1',
|
||||||
|
'date' => '2015-05-31',
|
||||||
|
'budget_id' => '0',
|
||||||
|
'category' => 'Lunch',
|
||||||
|
'return_to_edit' => 1,
|
||||||
|
'tags' => '',
|
||||||
|
'piggy_bank_id' => '0',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->call('POST', '/transactions/store/withdrawal', $data);
|
||||||
|
|
||||||
|
// mock!
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
||||||
|
|
||||||
|
// fake!
|
||||||
|
$repository->shouldReceive('update')->andReturn($journal);
|
||||||
|
|
||||||
|
|
||||||
|
$this->call('POST', '/transaction/update/' . $journal->id, $data);
|
||||||
|
//$this->assertSessionHas('errors','bla');
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user