mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Triggered actions for Recurring Expenses
This commit is contained in:
parent
ed9ac5c93d
commit
2d0c6fd0af
@ -276,7 +276,8 @@ class RecurringExpenseController extends BaseController
|
||||
}
|
||||
|
||||
$recurring_expense = $this->recurring_expense_repo->save($request->all(), $recurring_expense);
|
||||
|
||||
$recurring_expense->service()->triggeredActions($request)->save();
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $recurring_expense->company, $recurring_expense);
|
||||
|
||||
event(new RecurringExpenseWasUpdated($recurring_expense, $recurring_expense->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
@ -372,6 +373,7 @@ class RecurringExpenseController extends BaseController
|
||||
public function store(StoreRecurringExpenseRequest $request)
|
||||
{
|
||||
$recurring_expense = $this->recurring_expense_repo->save($request->all(), RecurringExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
$recurring_expense->service()->triggeredActions($request)->save();
|
||||
|
||||
event(new RecurringExpenseWasCreated($recurring_expense, $recurring_expense->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
|
@ -50,6 +50,10 @@ class TriggeredActions extends AbstractService
|
||||
$this->quote = $this->quote->service()->convert()->save();
|
||||
}
|
||||
|
||||
if ($this->request->has('approve') && $this->request->input('approve') == 'true' && in_array($this->quote->status_id, [Quote::STATUS_SENT, Quote::STATUS_DRAFT])) {
|
||||
$this->quote = $this->quote->service()->convert()->save();
|
||||
}
|
||||
|
||||
|
||||
return $this->quote;
|
||||
}
|
||||
|
@ -211,5 +211,76 @@ class RecurringExpenseApiTest extends TestCase
|
||||
$this->assertEquals(RecurringInvoice::STATUS_PAUSED, $arr['data'][0]['status_id']);
|
||||
}
|
||||
|
||||
public function testRecurringExpenseStartedWithTriggeredAction()
|
||||
{
|
||||
$data = [
|
||||
'ids' => [$this->encodePrimaryKey($this->recurring_expense->id)],
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/recurring_expenses/'.$this->recurring_expense->hashed_id.'?start=true', []);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(RecurringInvoice::STATUS_ACTIVE, $arr['data']['status_id']);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/recurring_expenses/'.$this->recurring_expense->hashed_id.'?stop=true', []);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(RecurringInvoice::STATUS_PAUSED, $arr['data']['status_id']);
|
||||
|
||||
}
|
||||
|
||||
public function testRecurringExpensePostWithStartAction()
|
||||
{
|
||||
$data = [
|
||||
'amount' => 10,
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'number' => '123321',
|
||||
'frequency_id' => 5,
|
||||
'remaining_cycles' =>5
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/recurring_expenses?start=true', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(RecurringInvoice::STATUS_ACTIVE, $arr['data']['status_id']);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testRecurringExpensePostWithStopAction()
|
||||
{
|
||||
$data = [
|
||||
'amount' => 10,
|
||||
'client_id' => $this->client->hashed_id,
|
||||
'number' => '1233x21',
|
||||
'frequency_id' => 5,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/recurring_expenses?stop=true', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals(RecurringInvoice::STATUS_PAUSED, $arr['data']['status_id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user