@@ -115,11 +115,11 @@ protected function checkUniqueness(string $destination, string $slug): string
115115
116116 while (
117117 self ::where ($ destination , $ slug )
118- ->where ('user_id ' , $ this ->user_id )
119- ->where ('team_id ' , $ this ->team_id )
120- ->exists ()
118+ ->where ('user_id ' , $ this ->user_id )
119+ ->where ('team_id ' , $ this ->team_id )
120+ ->exists ()
121121 ) {
122- $ slug = $ originalSlug. '- ' . $ counter ++. Str::random (6 );
122+ $ slug = $ originalSlug . '- ' . $ counter ++ . Str::random (6 );
123123 }
124124
125125 return $ slug ;
@@ -256,16 +256,6 @@ public function isPaid()
256256 return $ this ->status === 'paid ' ;
257257 }
258258
259- /**
260- * Check if the due date is upcoming.
261- *
262- * @return bool
263- */
264- public function isUpcoming ()
265- {
266- return $ this ->isUpcomingIn (7 );
267- }
268-
269259 /**
270260 * Check if the due date is upcoming.
271261 *
@@ -277,7 +267,9 @@ public function isUpcomingIn($days = 1)
277267 $ days = 0 ;
278268 }
279269
280- return $ this ->due_date ->lte (now ()->addDays (intval ($ days )));
270+ return $ this ->due_date ->lte (now ()->addDays (intval ($ days ))) &&
271+ $ this ->due_date ->gte (now ()) &&
272+ $ this ->status === 'unpaid ' ;
281273 }
282274
283275 /**
@@ -391,6 +383,20 @@ public function scopePaid($query)
391383 return $ query ->where ('status ' , 'paid ' );
392384 }
393385
386+ /**
387+ * Scope a query to only include upcoming bills.
388+ */
389+ public function scopeUpcoming ($ query , $ days = 7 )
390+ {
391+ $ now = now ();
392+
393+ return $ query ->whereBetween (
394+ 'due_date ' ,
395+ [$ now , $ now ->copy ()->addDays (intval ($ days ))]
396+ )
397+ ->where ('status ' , 'unpaid ' );
398+ }
399+
394400 /**
395401 * Get all tags
396402 *
@@ -403,7 +409,7 @@ public static function getAllTags()
403409 ->pluck ('tags ' )
404410 ->filter ()
405411 ->flatten ()
406- ->map (fn ($ tag ) => strtolower (trim ($ tag )))
412+ ->map (fn ($ tag ) => strtolower (trim ($ tag )))
407413 ->unique ()
408414 ->values ();
409415 }
@@ -415,28 +421,16 @@ public function createUniqueTags()
415421 {
416422 if ($ this ->tags ) {
417423 $ this ->tags = array_map (
418- fn ($ item ) => strtolower (trim ($ item )),
424+ fn ($ item ) => strtolower (trim ($ item )),
419425 $ this ->tags
420426 );
421427
422- $ this ->tags = array_filter ($ this ->tags , fn ($ tag ) => ! empty ($ tag ));
428+ $ this ->tags = array_filter ($ this ->tags , fn ($ tag ) => ! empty ($ tag ));
423429
424430 $ this ->tags = array_values (array_unique ($ this ->tags ));
425431 }
426432 }
427433
428- /**
429- * Scope a query to only include upcoming bills.
430- */
431- public function scopeUpcoming ($ query , $ days = 7 )
432- {
433- $ now = now ();
434-
435- return $ query ->where ('due_date ' , '>= ' , $ now )
436- ->where ('due_date ' , '<= ' , $ now ->copy ()->addDays (intval ($ days )))
437- ->where ('status ' , 'unpaid ' );
438- }
439-
440434 public function markAsPaid ()
441435 {
442436 $ this ->update ([
0 commit comments