mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 03:54:36 -04:00
Working on conversion of quotes to projects
This commit is contained in:
parent
b47e31e23a
commit
b9457d72e2
@ -84,9 +84,9 @@ class StoreTaskRequest extends Request
|
|||||||
|
|
||||||
public function prepareForValidation()
|
public function prepareForValidation()
|
||||||
{
|
{
|
||||||
$input = $this->all();
|
|
||||||
$input = $this->decodePrimaryKeys($this->all());
|
|
||||||
|
|
||||||
|
$input = $this->decodePrimaryKeys($this->all());
|
||||||
|
|
||||||
if (array_key_exists('status_id', $input) && is_string($input['status_id'])) {
|
if (array_key_exists('status_id', $input) && is_string($input['status_id'])) {
|
||||||
$input['status_id'] = $this->decodePrimaryKey($input['status_id']);
|
$input['status_id'] = $this->decodePrimaryKey($input['status_id']);
|
||||||
}
|
}
|
||||||
|
@ -226,4 +226,15 @@ class Task extends BaseModel
|
|||||||
{
|
{
|
||||||
return ctrans('texts.task');
|
return ctrans('texts.task');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRate(): float
|
||||||
|
{
|
||||||
|
if($this->project && $this->project->task_rate > 0)
|
||||||
|
return $this->project->task_rate;
|
||||||
|
|
||||||
|
if($this->client)
|
||||||
|
return $this->client->getSetting('default_task_rate');
|
||||||
|
|
||||||
|
return $this->company->settings->default_task_rate ?? 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ class TaskRepository extends BaseRepository
|
|||||||
if ($task->id) {
|
if ($task->id) {
|
||||||
$this->new_task = false;
|
$this->new_task = false;
|
||||||
}
|
}
|
||||||
|
nlog($data);
|
||||||
$task->fill($data);
|
$task->fill($data);
|
||||||
$task->saveQuietly();
|
$task->saveQuietly();
|
||||||
|
|
||||||
@ -48,12 +48,17 @@ class TaskRepository extends BaseRepository
|
|||||||
$task->status_id = $this->setDefaultStatus($task);
|
$task->status_id = $this->setDefaultStatus($task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->new_task && (!$task->rate || $task->rate <= 0)) {
|
||||||
|
nlog($task->getRate());
|
||||||
|
$task->rate = $task->getRate();
|
||||||
|
}
|
||||||
|
|
||||||
$task->number = empty($task->number) || ! array_key_exists('number', $data) ? $this->trySaving($task) : $data['number'];
|
$task->number = empty($task->number) || ! array_key_exists('number', $data) ? $this->trySaving($task) : $data['number'];
|
||||||
|
|
||||||
if (isset($data['description'])) {
|
if (isset($data['description'])) {
|
||||||
$task->description = trim($data['description']);
|
$task->description = trim($data['description']);
|
||||||
}
|
}
|
||||||
|
nlog($task->toArray());
|
||||||
//todo i can't set it - i need to calculate it.
|
//todo i can't set it - i need to calculate it.
|
||||||
if (isset($data['status_order'])) {
|
if (isset($data['status_order'])) {
|
||||||
$task->status_order = $data['status_order'];
|
$task->status_order = $data['status_order'];
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use Tests\MockAccountData;
|
use Tests\MockAccountData;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -101,8 +103,93 @@ class TaskApiTest extends TestCase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStatusSets()
|
public function testTaskCompanyRateSet()
|
||||||
|
{
|
||||||
|
$settings = $this->company->settings;
|
||||||
|
$settings->default_task_rate = 31;
|
||||||
|
|
||||||
|
$this->company->saveSettings((array)$settings, $this->company);
|
||||||
|
$this->company->push();
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'client_id' => $this->client->hashed_id,
|
||||||
|
'description' => 'Test Task',
|
||||||
|
'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,0]]',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson("/api/v1/tasks", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals(31, $arr['data']['rate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTaskClientRateSet()
|
||||||
|
{
|
||||||
|
$settings = ClientSettings::defaults();
|
||||||
|
$settings->default_task_rate = 41;
|
||||||
|
|
||||||
|
$c = Client::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'settings' => $settings,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'client_id' => $c->hashed_id,
|
||||||
|
'description' => 'Test Task',
|
||||||
|
'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,0]]',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson("/api/v1/tasks", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals(41, $arr['data']['rate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTaskProjectRateSet()
|
||||||
|
{
|
||||||
|
|
||||||
|
$p = Project::factory()->create([
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'name' => 'proggy',
|
||||||
|
'task_rate' => 101,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'project_id' => $p->hashed_id,
|
||||||
|
'client_id' => $this->client->id,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'company_id' => $this->company->id,
|
||||||
|
'description' => 'Test Task',
|
||||||
|
'time_log' => '[[1681165417,1681165432,"sumtin",true],[1681165446,0]]',
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = $this->withHeaders([
|
||||||
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
|
'X-API-TOKEN' => $this->token,
|
||||||
|
])->postJson("/api/v1/tasks", $data);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals(101, $arr['data']['rate']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStatusSet()
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user