mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Updates for projects
This commit is contained in:
parent
1d5e121422
commit
2dd1dd6da6
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Laracasts\Presenter\PresentableTrait;
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
|
|
||||||
@ -121,6 +122,22 @@ class Project extends BaseModel
|
|||||||
return $this->hasMany(Task::class);
|
return $this->hasMany(Task::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function expenses(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Expense::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invoices(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Invoice::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function quotes(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Quote::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function translate_entity()
|
public function translate_entity()
|
||||||
{
|
{
|
||||||
return ctrans('texts.project');
|
return ctrans('texts.project');
|
||||||
|
@ -12,10 +12,13 @@
|
|||||||
|
|
||||||
namespace App\Transformers;
|
namespace App\Transformers;
|
||||||
|
|
||||||
use App\Models\Client;
|
|
||||||
use App\Models\Document;
|
|
||||||
use App\Models\Project;
|
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
|
use App\Models\Quote;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Project;
|
||||||
|
use App\Models\Document;
|
||||||
|
use App\Models\Expense;
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,6 +38,9 @@ class ProjectTransformer extends EntityTransformer
|
|||||||
protected array $availableIncludes = [
|
protected array $availableIncludes = [
|
||||||
'client',
|
'client',
|
||||||
'tasks',
|
'tasks',
|
||||||
|
'invoices',
|
||||||
|
'expenses',
|
||||||
|
'quotes',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function includeDocuments(Project $project)
|
public function includeDocuments(Project $project)
|
||||||
@ -67,6 +73,39 @@ class ProjectTransformer extends EntityTransformer
|
|||||||
return $this->includeCollection($project->tasks, $transformer, Task::class);
|
return $this->includeCollection($project->tasks, $transformer, Task::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeInvoices(Project $project): \League\Fractal\Resource\Collection
|
||||||
|
{
|
||||||
|
$transformer = new InvoiceTransformer($this->serializer);
|
||||||
|
|
||||||
|
if(!$project->invoices)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return $this->includeCollection($project->invoices, $transformer, Invoice::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeExpenses(Project $project): \League\Fractal\Resource\Collection
|
||||||
|
{
|
||||||
|
$transformer = new ExpenseTransformer($this->serializer);
|
||||||
|
|
||||||
|
if(!$project->expenses) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->includeCollection($project->expenses, $transformer, Expense::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function includeQuotes(Project $project): \League\Fractal\Resource\Collection
|
||||||
|
{
|
||||||
|
$transformer = new QuoteTransformer($this->serializer);
|
||||||
|
|
||||||
|
if(!$project->quotes) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->includeCollection($project->quotes, $transformer, Quote::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function transform(Project $project)
|
public function transform(Project $project)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -11,13 +11,16 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Expense;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Quote;
|
||||||
|
use Tests\MockAccountData;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Tests\MockAccountData;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -44,6 +47,47 @@ class ProjectApiTest extends TestCase
|
|||||||
Model::reguard();
|
Model::reguard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProjectIncludes()
|
||||||
|
{
|
||||||
|
$i = Invoice::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->project->client_id,
|
||||||
|
'project_id' => $this->project->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$e = Expense::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->project->client_id,
|
||||||
|
'project_id' => $this->project->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$q = Quote::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->project->client_id,
|
||||||
|
'project_id' => $this->project->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->putJson("/api/v1/projects/{$this->project->hashed_id}?include=expenses,invoices,quotes");
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals(1, count($arr['data']['invoices']));
|
||||||
|
$this->assertEquals(1, count($arr['data']['expenses']));
|
||||||
|
$this->assertEquals(1, count($arr['data']['quotes']));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testProjectValidationForBudgetedHoursPut()
|
public function testProjectValidationForBudgetedHoursPut()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user