makeTestData(); } public function testInvoiceMarkPaidFromDraft() { $c = \App\Models\Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, ]); $item = InvoiceItemFactory::create(); $item->quantity = 1; $item->cost = 10; $item->tax_name1 = ''; $item->tax_rate1 = 0; $item->type_id = '1'; $item->tax_id = '1'; $line_items[] = $item; $i = Invoice::factory()->create([ 'discount' => 0, 'tax_name1' => '', 'tax_name2' => '', 'tax_name3' => '', 'tax_rate1' => 0, 'tax_rate2' => 0, 'tax_rate3' => 0, 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $c->id, 'line_items' => $line_items, 'status_id' => 1, 'uses_inclusive_taxes' => false, 'is_amount_discount' => false ]); $i->calc()->getInvoice(); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->putJson("/api/v1/invoices/{$i->hashed_id}?paid=true", []); $response->assertStatus(200); $this->assertEquals(0, $response->json('data.balance')); $this->assertEquals(10, $response->json('data.paid_to_date')); $this->assertEquals(4, $response->json('data.status_id')); $i = $i->fresh(); $this->assertEquals(0, $i->balance); $this->assertEquals(10, $i->paid_to_date); $this->assertEquals(4, $i->status_id); $c->forceDelete(); } public function testInvoiceMarkPaidFromDraftBulk() { $c = \App\Models\Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $this->company->id, ]); $item = InvoiceItemFactory::create(); $item->quantity = 1; $item->cost = 10; $item->tax_name1 = ''; $item->tax_rate1 = 0; $item->type_id = '1'; $item->tax_id = '1'; $line_items[] = $item; /** @var \App\Models\Invoice $i */ $i = Invoice::factory()->create([ 'discount' => 0, 'tax_name1' => '', 'tax_name2' => '', 'tax_name3' => '', 'tax_rate1' => 0, 'tax_rate2' => 0, 'tax_rate3' => 0, 'user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $c->id, 'line_items' => $line_items, 'status_id' => 1, 'uses_inclusive_taxes' => false, 'is_amount_discount' => false ]); $i->calc()->getInvoice(); $data = [ 'action' => 'mark_paid', 'ids' => [$i->hashed_id] ]; $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, ])->postJson("/api/v1/invoices/bulk", $data); $response->assertStatus(200); $this->assertEquals(0, $response->json('data.0.balance')); $this->assertEquals(10, $response->json('data.0.paid_to_date')); $this->assertEquals(4, $response->json('data.0.status_id')); $i = $i->fresh(); $this->assertEquals(0, $i->balance); $this->assertEquals(10, $i->paid_to_date); $this->assertEquals(4, $i->status_id); $c->forceDelete(); } }