mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 06:01:21 +00:00
This will be the first release!
This commit is contained in:
@@ -110,8 +110,8 @@ class Budget implements BudgetInterface
|
||||
// get the limits:
|
||||
if ($useSessionDates) {
|
||||
$limits = $budget->limits()->where('startdate', '>=', $sessionStart->format('Y-m-d'))->where(
|
||||
'startdate', '<=', $sessionEnd->format('Y-m-d')
|
||||
)->get();
|
||||
'startdate', '<=', $sessionEnd->format('Y-m-d')
|
||||
)->get();
|
||||
} else {
|
||||
$limits = $budget->limits;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ interface BudgetInterface
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param bool $useSessionDates
|
||||
* @param bool $useSessionDates
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function organizeRepetitions(\Budget $budget, $useSessionDates = false);
|
||||
|
||||
@@ -169,8 +169,8 @@ class Chart implements ChartInterface
|
||||
$amount = floatval($rep->amount);
|
||||
$spent = $rep->spent;
|
||||
$color = $spent > $amount ? '#FF0000' : null;
|
||||
$data['series'][0]['data'][] = ['y' => $amount, 'id' => 'def'];
|
||||
$data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'abc'];
|
||||
$data['series'][0]['data'][] = ['y' => $amount, 'id' => 'amount-' . $rep->id];
|
||||
$data['series'][1]['data'][] = ['y' => $rep->spent, 'color' => $color, 'id' => 'spent-' . $rep->id];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,29 @@ class Toolkit implements ToolkitInterface
|
||||
return [\Session::get('start'), \Session::get('end')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReminders()
|
||||
{
|
||||
// get reminders, for menu, mumble mumble:
|
||||
$today = new Carbon;
|
||||
$reminders = \Auth::user()->reminders()->where('class', 'PiggybankReminder')->validOn($today)->get();
|
||||
|
||||
/** @var \Reminder $reminder */
|
||||
foreach ($reminders as $index => $reminder) {
|
||||
if (\Session::has('dismissal-' . $reminder->id)) {
|
||||
$time = \Session::get('dismissal-' . $reminder->id);
|
||||
if ($time >= $today) {
|
||||
unset($reminders[$index]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
\Session::put('reminderCount', count($reminders));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -302,26 +325,4 @@ class Toolkit implements ToolkitInterface
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getReminders() {
|
||||
// get reminders, for menu, mumble mumble:
|
||||
$today = new Carbon;
|
||||
$reminders = \Auth::user()->reminders()->validOn($today)->get();
|
||||
|
||||
/** @var \Reminder $reminder */
|
||||
foreach($reminders as $index => $reminder) {
|
||||
if(\Session::has('dismissal-' . $reminder->id)) {
|
||||
$time = \Session::get('dismissal-' . $reminder->id);
|
||||
if($time >= $today) {
|
||||
unset($reminders[$index]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
\Session::put('reminderCount',count($reminders));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$account = $this->findByName($name, $type);
|
||||
if (!$account) {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'name' => $name,
|
||||
'account_type' => $type
|
||||
];
|
||||
|
||||
@@ -76,7 +76,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
// find the oldest transaction which also is a "Opening balance"
|
||||
$first = \Transaction::
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_journals.user_id', \Auth::user()->id)
|
||||
->where('transaction_types.type', 'Opening balance')
|
||||
@@ -101,7 +101,7 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
$journal->delete();
|
||||
}
|
||||
|
||||
if(!is_null($initialbalanceAccount)) {
|
||||
if (!is_null($initialbalanceAccount)) {
|
||||
$initialbalanceAccount->delete();
|
||||
}
|
||||
|
||||
@@ -306,8 +306,8 @@ class EloquentAccountRepository implements AccountRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $amount
|
||||
* @param Carbon $date
|
||||
* @param int $amount
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return bool
|
||||
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
|
||||
|
||||
@@ -121,7 +121,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
|
||||
$limit->repeat_freq = $data['repeat_freq'];
|
||||
if ($limit->validate()) {
|
||||
$limit->save();
|
||||
\Event::fire('limits.store',[$limit]);
|
||||
\Event::fire('limits.store', [$limit]);
|
||||
}
|
||||
}
|
||||
if ($budget->validate()) {
|
||||
|
||||
@@ -16,7 +16,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function createOrFind($name)
|
||||
{
|
||||
if(strlen($name) == 0) {
|
||||
if (strlen($name) == 0) {
|
||||
return null;
|
||||
}
|
||||
$category = $this->findByName($name);
|
||||
|
||||
@@ -28,7 +28,8 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
* @param $data
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function update(\Limit $limit, $data)
|
||||
@@ -39,6 +40,7 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
$limit->amount = floatval($data['amount']);
|
||||
|
||||
$limit->save();
|
||||
|
||||
return $limit;
|
||||
}
|
||||
|
||||
@@ -57,8 +59,8 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -113,11 +115,11 @@ class EloquentLimitRepository implements LimitRepositoryInterface
|
||||
}
|
||||
// find existing:
|
||||
$count = \Limit::
|
||||
leftJoin('components', 'components.id', '=', 'limits.component_id')->where(
|
||||
'components.user_id', \Auth::user()->id
|
||||
)->where('startdate', $date->format('Y-m-d'))->where('component_id', $data['budget_id'])->where(
|
||||
'repeat_freq', $data['period']
|
||||
)->count();
|
||||
leftJoin('components', 'components.id', '=', 'limits.component_id')->where(
|
||||
'components.user_id', \Auth::user()->id
|
||||
)->where('startdate', $date->format('Y-m-d'))->where('component_id', $data['budget_id'])->where(
|
||||
'repeat_freq', $data['period']
|
||||
)->count();
|
||||
if ($count > 0) {
|
||||
\Session::flash('error', 'There already is an entry for these parameters.');
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ interface LimitRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \Limit $limit
|
||||
* @param $data
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(\Limit $limit, $data);
|
||||
|
||||
@@ -225,7 +225,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
= isset($data['startdate']) && strlen($data['startdate']) > 0 ? new Carbon($data['startdate']) : null;
|
||||
|
||||
|
||||
|
||||
foreach ($piggy->piggybankrepetitions()->get() as $rep) {
|
||||
$rep->delete();
|
||||
}
|
||||
|
||||
@@ -68,10 +68,12 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurringTransaction
|
||||
* @param $data
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function update(\RecurringTransaction $recurringTransaction, $data) {
|
||||
public function update(\RecurringTransaction $recurringTransaction, $data)
|
||||
{
|
||||
$recurringTransaction->name = $data['name'];
|
||||
$recurringTransaction->match = join(' ', explode(',', $data['match']));
|
||||
$recurringTransaction->amount_max = floatval($data['amount_max']);
|
||||
|
||||
@@ -32,7 +32,8 @@ interface RecurringTransactionRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurringTransaction
|
||||
* @param $data
|
||||
* @param $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(\RecurringTransaction $recurringTransaction, $data);
|
||||
|
||||
@@ -45,4 +45,17 @@ class EloquentReminderRepository implements ReminderRepositoryInterface
|
||||
return \Auth::user()->reminders()->validOn($today)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getCurrentRecurringReminders()
|
||||
{
|
||||
$today = new Carbon;
|
||||
|
||||
return \Auth::user()->reminders()->with('recurringtransaction')->validOn($today)->where(
|
||||
'class', 'RecurringTransactionReminder'
|
||||
)->get();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,8 @@ namespace Firefly\Storage\Reminder;
|
||||
*
|
||||
* @package Firefly\Storage\Reminder
|
||||
*/
|
||||
interface ReminderRepositoryInterface {
|
||||
interface ReminderRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \Reminder $reminder
|
||||
@@ -35,4 +36,7 @@ interface ReminderRepositoryInterface {
|
||||
*/
|
||||
public function find($id);
|
||||
|
||||
|
||||
public function getCurrentRecurringReminders();
|
||||
|
||||
}
|
||||
@@ -34,8 +34,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
* A gains 200 (200). * -1
|
||||
* B loses 200 (-200). * 1
|
||||
*
|
||||
* @param \Account $from
|
||||
* @param \Account $toAccount
|
||||
* @param \Account $from
|
||||
* @param \Account $toAccount
|
||||
* @param $description
|
||||
* @param $amount
|
||||
* @param \Carbon\Carbon $date
|
||||
@@ -122,7 +122,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$fromTransaction->amount = $amountFrom;
|
||||
if (!$fromTransaction->validate()) {
|
||||
throw new FireflyException('Cannot create valid transaction (from): ' . $fromTransaction->errors()->first(
|
||||
));
|
||||
));
|
||||
}
|
||||
$fromTransaction->save();
|
||||
|
||||
|
||||
127
app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php
Normal file
127
app/lib/Firefly/Trigger/Recurring/EloquentRecurringTrigger.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Firefly\Trigger\Recurring;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
/**
|
||||
* Class EloquentRecurringTrigger
|
||||
*
|
||||
* @package Firefly\Trigger\Recurring
|
||||
*/
|
||||
class EloquentRecurringTrigger
|
||||
{
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
*/
|
||||
public function destroy(\RecurringTransaction $recurring)
|
||||
{
|
||||
$reminders = $recurring->recurringtransactionreminders()->get();
|
||||
/** @var \RecurringTransactionReminder $reminder */
|
||||
foreach ($reminders as $reminder) {
|
||||
$reminder->delete();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
*/
|
||||
public function store(\RecurringTransaction $recurring)
|
||||
{
|
||||
$this->createReminders();
|
||||
|
||||
}
|
||||
|
||||
public function createReminders()
|
||||
{
|
||||
$entries = \Auth::user()->recurringtransactions()->where('active', 1)->get();
|
||||
|
||||
// for each entry, check for existing reminders during their period:
|
||||
/** @var \RecurringTransaction $entry */
|
||||
foreach ($entries as $entry) {
|
||||
|
||||
$start = clone $entry->date;
|
||||
$end = clone $entry->date;
|
||||
switch ($entry->repeat_freq) {
|
||||
case 'weekly':
|
||||
$start->startOfWeek();
|
||||
$end->endOfWeek();
|
||||
break;
|
||||
case 'monthly':
|
||||
$start->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
break;
|
||||
case 'quarterly':
|
||||
$start->firstOfQuarter();
|
||||
$end->lastOfQuarter();
|
||||
break;
|
||||
case 'half-year':
|
||||
// start of half-year:
|
||||
if (intval($start->format('m')) >= 7) {
|
||||
$start->startOfYear();
|
||||
$start->addMonths(6);
|
||||
} else {
|
||||
$start->startOfYear();
|
||||
}
|
||||
$end = clone $start;
|
||||
$end->addMonths(6);
|
||||
break;
|
||||
case 'yearly':
|
||||
$start->startOfYear();
|
||||
$end->endOfYear();
|
||||
break;
|
||||
}
|
||||
// check if exists.
|
||||
$count = $entry->reminders()->where('startdate', $start->format('Y-m-d'))->where(
|
||||
'enddate', $end->format('Y-m-d')
|
||||
)->count();
|
||||
if ($count == 0) {
|
||||
// create reminder:
|
||||
$reminder = new \RecurringTransactionReminder;
|
||||
$reminder->recurringtransaction()->associate($entry);
|
||||
$reminder->startdate = $start;
|
||||
$reminder->enddate = $end;
|
||||
$reminder->active = 1;
|
||||
$reminder->user()->associate(\Auth::user());
|
||||
$reminder->save();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger!
|
||||
*
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen('recurring.destroy', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@destroy');
|
||||
$events->listen('recurring.store', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@store');
|
||||
$events->listen('recurring.update', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@update');
|
||||
$events->listen('recurring.check', 'Firefly\Trigger\Recurring\EloquentRecurringTrigger@createReminders');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurring
|
||||
*/
|
||||
public function update(\RecurringTransaction $recurring)
|
||||
{
|
||||
// remove old active reminders
|
||||
$reminders = $recurring->reminders()->validOnOrAfter(new Carbon)->get();
|
||||
foreach ($reminders as $r) {
|
||||
$r->delete();
|
||||
}
|
||||
$this->createReminders();
|
||||
// create new reminder for the current period.
|
||||
|
||||
// and now create new one(s)!
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user