diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 291a815baebb..dedb6bb67970 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -78,6 +78,7 @@ class Credit extends BaseModel 'assigned_user_id', 'exchange_rate', 'subscription_id', + 'vendor_id', ]; protected $casts = [ @@ -123,6 +124,11 @@ class Credit extends BaseModel return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); } + public function vendor() + { + return $this->belongsTo(Vendor::class); + } + public function history() { return $this->hasManyThrough(Backup::class, Activity::class); diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 451c73f69d5a..b627cb5a267c 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -76,6 +76,7 @@ class Quote extends BaseModel 'exchange_rate', 'subscription_id', 'uses_inclusive_taxes', + 'vendor_id', ]; protected $casts = [ @@ -133,6 +134,11 @@ class Quote extends BaseModel return $this->belongsTo(Company::class); } + public function vendor() + { + return $this->belongsTo(Vendor::class); + } + public function history() { return $this->hasManyThrough(Backup::class, Activity::class); diff --git a/app/Transformers/CreditTransformer.php b/app/Transformers/CreditTransformer.php index 2ebb5849d369..47b2a920d4a3 100644 --- a/app/Transformers/CreditTransformer.php +++ b/app/Transformers/CreditTransformer.php @@ -89,6 +89,7 @@ class CreditTransformer extends EntityTransformer 'user_id' => $this->encodePrimaryKey($credit->user_id), 'project_id' => $this->encodePrimaryKey($credit->project_id), 'assigned_user_id' => $this->encodePrimaryKey($credit->assigned_user_id), + 'vendor_id' => (string) $this->encodePrimaryKey($credit->vendor_id), 'amount' => (float) $credit->amount, 'balance' => (float) $credit->balance, 'client_id' => (string) $this->encodePrimaryKey($credit->client_id), diff --git a/app/Transformers/QuoteTransformer.php b/app/Transformers/QuoteTransformer.php index ccc46f55f7ff..c752fabcd6c2 100644 --- a/app/Transformers/QuoteTransformer.php +++ b/app/Transformers/QuoteTransformer.php @@ -95,6 +95,7 @@ class QuoteTransformer extends EntityTransformer 'status_id' => (string) $quote->status_id, 'design_id' => (string) $this->encodePrimaryKey($quote->design_id), 'invoice_id' => (string) $this->encodePrimaryKey($quote->invoice_id), + 'vendor_id' => (string) $this->encodePrimaryKey($quote->vendor_id), 'updated_at' => (int) $quote->updated_at, 'archived_at' => (int) $quote->deleted_at, 'created_at' => (int) $quote->created_at, diff --git a/tests/Feature/VendorApiTest.php b/tests/Feature/VendorApiTest.php index d4288c8b5f3c..0f5b8e942f2a 100644 --- a/tests/Feature/VendorApiTest.php +++ b/tests/Feature/VendorApiTest.php @@ -41,6 +41,111 @@ class VendorApiTest extends TestCase Model::reguard(); } + public function testAddVendorToInvoice() + { + $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 + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/invoices', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($arr['data']['vendor_id'], $vendor_id); + + } + + public function testAddVendorToQuote() + { + $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 + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/quotes', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($arr['data']['vendor_id'], $vendor_id); + + } + + + public function testAddVendorToCredit() + { + $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 + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/credits', $data); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertEquals($arr['data']['vendor_id'], $vendor_id); + + } + + + public function testVendorPost() { $data = [