diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index f292c7e4f230..430ab1f1055b 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -76,6 +76,10 @@ class StoreRecurringInvoiceRequest extends Request $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); } + if (array_key_exists('vendor_id', $input) && is_string($input['vendor_id'])) { + $input['vendor_id'] = $this->decodePrimaryKey($input['vendor_id']); + } + if (isset($input['client_contacts'])) { foreach ($input['client_contacts'] as $key => $contact) { if (! array_key_exists('send_email', $contact) || ! array_key_exists('id', $contact)) { diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index bbb80d4b9369..689abc16d45a 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -107,6 +107,7 @@ class RecurringInvoice extends BaseModel 'design_id', 'assigned_user_id', 'exchange_rate', + 'vendor_id', ]; protected $casts = [ @@ -157,6 +158,11 @@ class RecurringInvoice extends BaseModel return $value; } + public function vendor() + { + return $this->belongsTo(Vendor::class); + } + public function activities() { return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50); diff --git a/tests/Feature/VendorApiTest.php b/tests/Feature/VendorApiTest.php index 0f5b8e942f2a..259f82a8a680 100644 --- a/tests/Feature/VendorApiTest.php +++ b/tests/Feature/VendorApiTest.php @@ -75,6 +75,42 @@ class VendorApiTest extends TestCase } + + public function testAddVendorToRecurringInvoice() + { + $data = [ + 'name' => $this->faker->firstName, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/vendors', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + $vendor_id = $arr['data']['id']; + + $data = [ + 'vendor_id' => $vendor_id, + 'client_id' => $this->client->hashed_id, + 'frequency_id' => 1, + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/recurring_invoices', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($arr['data']['vendor_id'], $vendor_id); + + } + public function testAddVendorToQuote() { $data = [