Fix formatting and interfaces in nearly every file
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Interfaces\Repository;
|
||||
use App\Models\Journal;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Support\Money;
|
||||
@@ -15,7 +16,7 @@ use Prettus\Validator\Exceptions\ValidatorException;
|
||||
* Class JournalRepository
|
||||
* @package App\Repositories
|
||||
*/
|
||||
class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
class JournalRepository extends Repository implements CacheableInterface
|
||||
{
|
||||
use CacheableRepository;
|
||||
|
||||
@@ -32,9 +33,9 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* @param Carbon $date
|
||||
* @return string
|
||||
*/
|
||||
public function formatPostDate(Carbon $date=null)
|
||||
public function formatPostDate(Carbon $date = null)
|
||||
{
|
||||
if(!$date) {
|
||||
if (!$date) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -69,13 +70,13 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* on the transaction itself. A cron will run to reconcile the journal
|
||||
* balance nightly, since they're not atomic operations
|
||||
*
|
||||
* @param Journal $journal
|
||||
* @param Money|null $credit Amount to credit
|
||||
* @param Money|null $debit Amount to debit
|
||||
* @param Model|null $reference The object this is a reference to
|
||||
* @param string|null $memo Memo for this transaction
|
||||
* @param string|null $post_date Date of the posting
|
||||
* @param string|null $transaction_group
|
||||
* @param Journal $journal
|
||||
* @param Money|null $credit Amount to credit
|
||||
* @param Money|null $debit Amount to debit
|
||||
* @param Model|null $reference The object this is a reference to
|
||||
* @param string|null $memo Memo for this transaction
|
||||
* @param string|null $post_date Date of the posting
|
||||
* @param string|null $transaction_group
|
||||
* @param array|string|null $tags
|
||||
* @return mixed
|
||||
* @throws ValidatorException
|
||||
@@ -89,25 +90,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
$post_date = null,
|
||||
$transaction_group = null,
|
||||
$tags = null
|
||||
) {
|
||||
)
|
||||
{
|
||||
# tags can be passed in a list
|
||||
if ($tags && \is_array($tags)) {
|
||||
$tags = implode(',', $tags);
|
||||
}
|
||||
|
||||
if(!$post_date) {
|
||||
if (!$post_date) {
|
||||
$post_date = Carbon::now('UTC');
|
||||
}
|
||||
|
||||
$attrs = [
|
||||
'journal_id' => $journal->id,
|
||||
'credit' => $credit ? $credit->getAmount() : null,
|
||||
'debit' => $debit ? $debit->getAmount() : null,
|
||||
'currency' => config('phpvms.currency'),
|
||||
'memo' => $memo,
|
||||
'post_date' => $post_date,
|
||||
'journal_id' => $journal->id,
|
||||
'credit' => $credit ? $credit->getAmount() : null,
|
||||
'debit' => $debit ? $debit->getAmount() : null,
|
||||
'currency' => config('phpvms.currency'),
|
||||
'memo' => $memo,
|
||||
'post_date' => $post_date,
|
||||
'transaction_group' => $transaction_group,
|
||||
'tags' => $tags
|
||||
'tags' => $tags
|
||||
];
|
||||
|
||||
if ($reference !== null) {
|
||||
@@ -127,17 +129,17 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Journal $journal
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $date
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getBalance(Journal $journal=null, Carbon $date=null)
|
||||
public function getBalance(Journal $journal = null, Carbon $date = null)
|
||||
{
|
||||
$journal->refresh();
|
||||
|
||||
if(!$date) {
|
||||
if (!$date) {
|
||||
$date = Carbon::now();
|
||||
}
|
||||
|
||||
@@ -149,19 +151,19 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Get the credit only balance of the journal based on a given date.
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getCreditBalanceBetween(
|
||||
Carbon $date,
|
||||
Journal $journal=null,
|
||||
Carbon $start_date=null,
|
||||
$transaction_group=null
|
||||
Journal $journal = null,
|
||||
Carbon $start_date = null,
|
||||
$transaction_group = null
|
||||
): Money
|
||||
{
|
||||
$where = [];
|
||||
@@ -187,10 +189,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -226,8 +228,8 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Return all transactions for a given object
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @param Carbon|null $date
|
||||
* @return array
|
||||
* @throws \UnexpectedValueException
|
||||
@@ -236,7 +238,7 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
public function getAllForObject($object, $journal = null, Carbon $date = null)
|
||||
{
|
||||
$where = [
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class_id' => $object->id,
|
||||
];
|
||||
|
||||
@@ -251,26 +253,26 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
$transactions = $this->whereOrder($where, [
|
||||
'credit' => 'desc',
|
||||
'debit' => 'desc'
|
||||
'debit' => 'desc'
|
||||
])->get();
|
||||
|
||||
return [
|
||||
'credits' => new Money($transactions->sum('credit')),
|
||||
'debits' => new Money($transactions->sum('debit')),
|
||||
'credits' => new Money($transactions->sum('credit')),
|
||||
'debits' => new Money($transactions->sum('debit')),
|
||||
'transactions' => $transactions,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all transactions for a given object
|
||||
* @param $object
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAllForObject($object, $journal = null)
|
||||
{
|
||||
$where = [
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class_id' => $object->id,
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user