Files
firefly-iii/app/lib/FireflyIII/Database/Transaction/Transaction.php

147 lines
3.5 KiB
PHP
Raw Normal View History

<?php
2014-12-13 22:11:51 +01:00
namespace FireflyIII\Database\Transaction;
2014-12-13 22:11:51 +01:00
use FireflyIII\Database\CommonDatabaseCalls;
use FireflyIII\Database\CUD;
use FireflyIII\Database\SwitchUser;
2014-12-06 12:12:55 +01:00
use FireflyIII\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
2014-12-06 12:12:55 +01:00
2014-11-12 22:21:48 +01:00
/**
* Class Transaction
*
* @package FireflyIII\Database
*/
class Transaction implements CUD, CommonDatabaseCalls
{
use SwitchUser;
2014-11-12 22:37:09 +01:00
/**
2014-12-06 12:12:55 +01:00
* @param \Eloquent $model
2014-11-12 22:37:09 +01:00
*
* @return bool
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
2014-11-12 22:37:09 +01:00
*/
2014-12-06 12:12:55 +01:00
public function destroy(\Eloquent $model)
2014-11-12 22:37:09 +01:00
{
// TODO: Implement destroy() method.
throw new NotImplementedException;
}
/**
* @param array $data
*
2014-12-06 12:12:55 +01:00
* @return \Eloquent
2014-12-13 21:59:02 +01:00
* @throws FireflyException
2014-11-12 22:37:09 +01:00
*/
public function store(array $data)
{
$transaction = new \Transaction;
$transaction->account()->associate($data['account']);
$transaction->transactionJournal()->associate($data['transaction_journal']);
$transaction->amount = floatval($data['amount']);
if (isset($data['piggybank'])) {
$transaction->piggybank()->associate($data['piggybank']);
}
if (isset($data['description'])) {
$transaction->description = $data['description'];
}
2014-12-06 12:12:55 +01:00
if ($transaction->isValid()) {
2014-11-12 22:37:09 +01:00
$transaction->save();
} else {
2014-12-06 12:12:55 +01:00
throw new FireflyException($transaction->getErrors()->first());
2014-11-12 22:37:09 +01:00
}
return $transaction;
}
/**
2014-12-06 12:12:55 +01:00
* @param \Eloquent $model
2014-12-13 21:59:02 +01:00
* @param array $data
2014-11-12 22:37:09 +01:00
*
* @return bool
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
2014-11-12 22:37:09 +01:00
*/
2014-12-06 12:12:55 +01:00
public function update(\Eloquent $model, array $data)
2014-11-12 22:37:09 +01:00
{
// TODO: Implement update() method.
throw new NotImplementedException;
}
/**
* Validates an array. Returns an array containing MessageBags
* errors/warnings/successes.
*
* @param array $model
*
2014-12-14 20:40:02 +01:00
* @return MessageBag
*/
public function validate(array $model)
{
2014-12-14 20:40:02 +01:00
$errors = new MessageBag;
if (is_null($model['account'])) {
$errors->add('account', 'No account present');
}
2014-12-14 20:40:02 +01:00
if (is_null($model['transaction_journal'])) {
$errors->add('transaction_journal', 'No valid transaction journal present');
}
2014-12-14 20:40:02 +01:00
return $errors;
2014-11-12 22:21:48 +01:00
}
/**
2014-11-12 22:37:09 +01:00
* Returns an object with id $id.
*
2014-12-19 21:18:42 +01:00
* @param int $objectId
2014-11-12 22:37:09 +01:00
*
2014-12-06 12:12:55 +01:00
* @return \Eloquent
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
*/
2014-12-19 21:18:42 +01:00
public function find($objectId)
{
2014-11-12 22:37:09 +01:00
// TODO: Implement find() method.
2014-11-12 22:21:48 +01:00
throw new NotImplementedException;
}
/**
2014-11-12 22:37:09 +01:00
* Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc.
*
2014-11-12 22:37:09 +01:00
* @param $what
*
2014-11-12 22:37:09 +01:00
* @return \AccountType|null
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
*/
2014-11-12 22:37:09 +01:00
public function findByWhat($what)
{
2014-11-12 22:37:09 +01:00
// TODO: Implement findByWhat() method.
2014-11-12 22:21:48 +01:00
throw new NotImplementedException;
}
/**
2014-11-12 22:21:48 +01:00
* Returns all objects.
*
2014-11-12 22:21:48 +01:00
* @return Collection
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
*/
2014-11-12 22:21:48 +01:00
public function get()
{
2014-11-12 22:21:48 +01:00
// TODO: Implement get() method.
throw new NotImplementedException;
}
/**
* @param array $ids
*
* @return Collection
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
*/
public function getByIds(array $ids)
{
// TODO: Implement getByIds() method.
2014-11-12 22:21:48 +01:00
throw new NotImplementedException;
}
}