Skip to content

Commit

Permalink
Approve fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pakomp committed Nov 24, 2017
1 parent f35c300 commit 1e9ed76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/FuturePlanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,17 @@ public function plan(array $attributes)
* @param boolean $needed
* Set to false to remove the approval need from the future
*
* @return \Dixie\EloquentModelFuture\Models\Future
* @return \Dixie\EloquentModelFuture\FuturePlanner
*/
public function needsApproval($needed=true)
{
if($needed) {
$this->newFuture->needs_approve = true;
$this->newFuture->needs_approval = true;
} else {
$this->newFuture->needs_approve = null;
$this->newFuture->needs_approval = null;
}

$this->newFuture->save();

return $this->newFuture;
return $this;
}

/**
Expand Down
15 changes: 10 additions & 5 deletions src/Traits/HasFuture.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ public function commitFuturePlan(Future $futurePlan)
/**
* Approve to the presented result of the model
*
* @param Carbon Until what date should futures be approved
* @return boolean
*/
public function approve()
public function approveUntil(Carbon $date = null)
{
$this->future()->getPlansUntil(Carbon::now())
if (is_null($date)) {
$date = Carbon::now();
}
$this->future()->getPlansUntil($date)
->each([$this, 'approveFuturePlan']);

return $this->save();
Expand All @@ -100,9 +104,10 @@ public function approve()
*/
public function approveFuturePlan(Future $futurePlan)
{
$futurePlan->approved_at = Carbon::now();
$futurePlan->approver()->associate(Auth::user());

if ($futurePlan->needs_approval && is_null($futurePlan->approved_at)) {
$futurePlan->approved_at = Carbon::now();
$futurePlan->approver()->associate(Auth::user());
}
return $futurePlan->save();
}
}

0 comments on commit 1e9ed76

Please sign in to comment.