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

151 lines
3.6 KiB
PHP
Raw Normal View History

<?php
2014-12-13 22:11:51 +01:00
namespace FireflyIII\Database\Transaction;
2015-01-02 06:05:40 +01:00
use FireflyIII\Database\CommonDatabaseCallsInterface;
use FireflyIII\Database\CUDInterface;
2014-12-13 22:11:51 +01:00
use FireflyIII\Database\SwitchUser;
2014-12-06 12:12:55 +01:00
use FireflyIII\Exception\FireflyException;
use FireflyIII\Exception\NotImplementedException;
2014-12-20 15:00:53 +01:00
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
2014-12-06 12:12:55 +01:00
/**
* Class Transaction
*
* @package FireflyIII\Database
*/
2015-01-02 06:05:40 +01:00
class Transaction implements CUDInterface, CommonDatabaseCallsInterface
{
use SwitchUser;
2014-11-12 22:37:09 +01:00
/**
2014-12-20 15:00:53 +01:00
* @param Eloquent $model
2015-01-17 10:06:12 +01:00
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
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-20 15:00:53 +01:00
public function destroy(Eloquent $model)
2014-11-12 22:37:09 +01:00
{
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']);
2014-11-12 22:37:09 +01:00
}
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;
}
/**
2015-01-17 10:06:12 +01:00
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
2014-12-20 15:00:53 +01:00
* @param Eloquent $model
* @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-20 15:00:53 +01:00
public function update(Eloquent $model, array $data)
2014-11-12 22:37:09 +01:00
{
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
}
/**
2015-01-17 10:06:12 +01:00
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
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:21:48 +01:00
throw new NotImplementedException;
}
/**
2015-01-17 10:06:12 +01:00
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
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: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
throw new NotImplementedException;
}
/**
2015-01-17 10:06:12 +01:00
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param array $ids
*
* @return Collection
2014-12-13 21:59:02 +01:00
* @throws NotImplementedException
*/
public function getByIds(array $ids)
{
2014-11-12 22:21:48 +01:00
throw new NotImplementedException;
}
2015-01-02 06:16:49 +01:00
}