File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -66,19 +66,17 @@ public function plan(array $attributes)
66
66
* @param boolean $needed
67
67
* Set to false to remove the approval need from the future
68
68
*
69
- * @return \Dixie\EloquentModelFuture\Models\Future
69
+ * @return \Dixie\EloquentModelFuture\FuturePlanner
70
70
*/
71
71
public function needsApproval ($ needed =true )
72
72
{
73
73
if ($ needed ) {
74
- $ this ->newFuture ->needs_approve = true ;
74
+ $ this ->newFuture ->needs_approval = true ;
75
75
} else {
76
- $ this ->newFuture ->needs_approve = null ;
76
+ $ this ->newFuture ->needs_approval = null ;
77
77
}
78
78
79
- $ this ->newFuture ->save ();
80
-
81
- return $ this ->newFuture ;
79
+ return $ this ;
82
80
}
83
81
84
82
/**
Original file line number Diff line number Diff line change @@ -83,11 +83,15 @@ public function commitFuturePlan(Future $futurePlan)
83
83
/**
84
84
* Approve to the presented result of the model
85
85
*
86
+ * @param Carbon Until what date should futures be approved
86
87
* @return boolean
87
88
*/
88
- public function approve ( )
89
+ public function approveUntil ( Carbon $ date = null )
89
90
{
90
- $ this ->future ()->getPlansUntil (Carbon::now ())
91
+ if (is_null ($ date )) {
92
+ $ date = Carbon::now ();
93
+ }
94
+ $ this ->future ()->getPlansUntil ($ date )
91
95
->each ([$ this , 'approveFuturePlan ' ]);
92
96
93
97
return $ this ->save ();
@@ -100,9 +104,10 @@ public function approve()
100
104
*/
101
105
public function approveFuturePlan (Future $ futurePlan )
102
106
{
103
- $ futurePlan ->approved_at = Carbon::now ();
104
- $ futurePlan ->approver ()->associate (Auth::user ());
105
-
107
+ if ($ futurePlan ->needs_approval && is_null ($ futurePlan ->approved_at )) {
108
+ $ futurePlan ->approved_at = Carbon::now ();
109
+ $ futurePlan ->approver ()->associate (Auth::user ());
110
+ }
106
111
return $ futurePlan ->save ();
107
112
}
108
113
}
You can’t perform that action at this time.
0 commit comments