Replace date validation of recurring transactions to make them possible at every day of month
MODIFY
README.md
README.md
@@ -37,6 +37,15 @@ php artisan serve
php artisan queue:work
```
+In addition to this you will have to create a cronjob to trigger budgets scheduling.
+(Without this, recurring transactions and weekly reports won't work)
+
+```
+* * * * * cd /path/to/budget/ && php artisan schedule:run >> 2>&1
+```
+
+It's best to make sure this command is run with the user that runs budget (eg. www-data)
+
## Contact
* [Discord](https://discord.gg/QFQdvy3)

MODIFY
app/Console/Kernel.php
app/Console/Kernel.php
@@ -29,7 +29,7 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')
// ->hourly();
- $schedule->job(new ProcessRecurrings)->everyMinute();
+ $schedule->job(new ProcessRecurrings)->daily();
$schedule->job(new SendWeeklyReports)->weekly()->fridays()->at('21:00');
}

MODIFY
app/Http/Controllers/RecurringController.php
app/Http/Controllers/RecurringController.php
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Recurring;
use Auth;
+use App\Jobs\ProcessRecurrings;
class RecurringController extends Controller {
public function index() {
@@ -32,7 +33,9 @@ class RecurringController extends Controller {
public function store(Request $request) {
$request->validate([
- 'day' => 'required|integer|between:1,28',
+ 'day' => ['required',
+ 'regex:/\b(0?[1-9]|[12][0-9]|3[01])\b/',
+ ],
'end' => 'nullable|date|date_format:Y-m-d',
'tag' => 'nullable|exists:tags,id', // TODO CHECK IF TAG BELONGS TO USER
'description' => 'required|max:255',
@@ -45,7 +48,7 @@ class RecurringController extends Controller {
$recurring->space_id = session('space')->id;
$recurring->type = 'monthly';
- $recurring->day = $request->input('day');
+ $recurring->day = ltrim($request->input('day'), '0');
$recurring->starts_on = date('Y-m-d');
$recurring->ends_on = $request->input('end');
$recurring->tag_id = $request->input('tag');
@@ -53,6 +56,7 @@ class RecurringController extends Controller {
$recurring->amount = (int) ($request->input('amount') * 100);
$recurring->save();
+ ProcessRecurrings::dispatch();
return redirect()->route('recurrings.show', ['id' => $recurring->id]);
}

MODIFY
app/Jobs/ProcessRecurrings.php
app/Jobs/ProcessRecurrings.php
@@ -18,9 +18,17 @@ class ProcessRecurrings implements ShouldQueue {
}
public function handle() {
+ $day = (int) date('j');
+
$recurrings = Recurring
::where('type', 'monthly')
- ->where('day', date('j'))
+ ->when((int) date('t') == $day,
+ function ($query) use ($day) {
+ return $query->where('day', '>=', $day);
+ },
+ function ($query) use ($day) {
+ return $query->where('day', $day);
+ })
->where('starts_on', '<=', date('Y-m-d'))
->where(function ($query) {
$query

Replace date validation of recurring transactions to make them possible at every day of month