Skip to content

Commit 1e9ed76

Browse files
committed
Approve fixes
1 parent f35c300 commit 1e9ed76

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/FuturePlanner.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,17 @@ public function plan(array $attributes)
6666
* @param boolean $needed
6767
* Set to false to remove the approval need from the future
6868
*
69-
* @return \Dixie\EloquentModelFuture\Models\Future
69+
* @return \Dixie\EloquentModelFuture\FuturePlanner
7070
*/
7171
public function needsApproval($needed=true)
7272
{
7373
if($needed) {
74-
$this->newFuture->needs_approve = true;
74+
$this->newFuture->needs_approval = true;
7575
} else {
76-
$this->newFuture->needs_approve = null;
76+
$this->newFuture->needs_approval = null;
7777
}
7878

79-
$this->newFuture->save();
80-
81-
return $this->newFuture;
79+
return $this;
8280
}
8381

8482
/**

src/Traits/HasFuture.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ public function commitFuturePlan(Future $futurePlan)
8383
/**
8484
* Approve to the presented result of the model
8585
*
86+
* @param Carbon Until what date should futures be approved
8687
* @return boolean
8788
*/
88-
public function approve()
89+
public function approveUntil(Carbon $date = null)
8990
{
90-
$this->future()->getPlansUntil(Carbon::now())
91+
if (is_null($date)) {
92+
$date = Carbon::now();
93+
}
94+
$this->future()->getPlansUntil($date)
9195
->each([$this, 'approveFuturePlan']);
9296

9397
return $this->save();
@@ -100,9 +104,10 @@ public function approve()
100104
*/
101105
public function approveFuturePlan(Future $futurePlan)
102106
{
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+
}
106111
return $futurePlan->save();
107112
}
108113
}

0 commit comments

Comments
 (0)