diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 2617ebf1f270..313038e34a30 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -274,6 +274,7 @@ class TaskController extends BaseController $old_task = json_decode(json_encode($task)); $task = $this->task_repo->save($request->all(), $task); + $task = $this->task_repo->triggeredActions($request, $task); if ($task->status_order != $old_task->status_order) { diff --git a/app/Http/Requests/Task/UpdateTaskRequest.php b/app/Http/Requests/Task/UpdateTaskRequest.php index e8b5deb52f3c..bdf3d653a6e9 100644 --- a/app/Http/Requests/Task/UpdateTaskRequest.php +++ b/app/Http/Requests/Task/UpdateTaskRequest.php @@ -84,7 +84,7 @@ class UpdateTaskRequest extends Request public function prepareForValidation() { $input = $this->decodePrimaryKeys($this->all()); - + if (array_key_exists('status_id', $input) && is_string($input['status_id'])) { $input['status_id'] = $this->decodePrimaryKey($input['status_id']); } diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index cdd3e3efe1de..1b289f344bd2 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -148,8 +148,8 @@ class CompanyExport implements ShouldQueue $this->export_data['clients'] = $this->company->clients()->orderBy('number', 'DESC')->cursor()->map(function ($client) { $client = $this->transformArrayOfKeys($client, ['company_id', 'user_id', 'assigned_user_id', 'group_settings_id']); - - return $client->makeVisible(['id','private_notes','user_id','company_id','last_login','hashed_id']); + $client->tax_data = ''; + return $client->makeVisible(['id','private_notes','user_id','company_id','last_login','hashed_id'])->makeHidden(['is_tax_exempt','has_valid_vat_number']); })->all(); @@ -229,6 +229,7 @@ class CompanyExport implements ShouldQueue $this->export_data['invoices'] = $this->company->invoices()->orderBy('number', 'DESC')->cursor()->map(function ($invoice) { $invoice = $this->transformBasicEntities($invoice); $invoice = $this->transformArrayOfKeys($invoice, ['recurring_id','client_id', 'vendor_id', 'project_id', 'design_id', 'subscription_id','project_id']); + $invoice->tax_data = ''; return $invoice->makeVisible(['id', 'private_notes', diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 562a7a7c3d36..07ce92aa16f6 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -35,7 +35,7 @@ class TaskRepository extends BaseRepository * * @return task|null task Object */ - public function save(array $data, Task $task) : ?Task + public function save(array $data, Task $task): ?Task { if ($task->id) { $this->new_task = false; @@ -98,7 +98,8 @@ class TaskRepository extends BaseRepository $time_log = []; } - array_multisort($time_log); + // array_multisort($time_log); + ksort($time_log); if (isset($data['action'])) { if ($data['action'] == 'start') { @@ -118,8 +119,6 @@ class TaskRepository extends BaseRepository } $task->time_log = json_encode($time_log); - // $task->start_time = $task->start_time ?: $task->calcStartTime(); - // $task->duration = $task->calcDuration(); $task->saveQuietly(); @@ -206,10 +205,12 @@ class TaskRepository extends BaseRepository $last = end($log); - if (is_array($last) && $last[1] !== 0) { + if (is_array($last) && $last[1] !== 0) { // this line is a disaster $new = [time(), 0]; + $log = array_merge($log, [$new]); $task->time_log = json_encode($log); + $task->saveQuietly(); } @@ -226,7 +227,7 @@ class TaskRepository extends BaseRepository $last[1] = time(); array_pop($log); - $log = array_merge($log, [$last]); + $log = array_merge($log, [$last]);//check at this point, it may be prepending here. $task->time_log = json_encode($log); $task->saveQuietly(); diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index ae396b069577..f60cc23189c7 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -99,6 +99,89 @@ class TaskApiTest extends TestCase } } + public function testStartStopSanity() + { + + $task = Task::factory()->create([ + '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, + ])->putJson("/api/v1/tasks/{$task->hashed_id}?stop=true"); + + $response->assertStatus(200); + + } + + public function testStoppingTaskWithDescription() + { + $task = Task::factory()->create([ + '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]]', + ]); + + $task_repo = new \App\Repositories\TaskRepository(); + + $task = $task_repo->stop($task); + + $log = json_decode($task->time_log); + + $last = end($log); + + $this->assertNotEquals(0, $last[1]); + $this->assertCount(2, $last); + } + + public function testMultiDimensionArrayOfTimes() + { + $logs = [ + '[[1680302433,1680387960,"",true]]', + '[[1680715620,1680722820,"",true],[1680729660,1680737460,"",true]]', + '[[1681156840,1681158000,"",true]]', + '[[1680035007,1680036807,"",true]]', + ]; + + foreach($logs as $log) + { + $this->assertTrue($this->checkTimeLog(json_decode($log))); + } + + } + + public function testArrayOfTimes() + { + $logs = [ + "[[1675275148,1675277829]]", + "[[1675375200,1675384200],[1676074247,1676074266]]", + "[[1675443600,1675461600],[1676053305,1676055950],[1676063112,1676067834]]", + "[[1676068200,1676070900]]", + "[[1678134638,1678156238]]", + "[[1678132800,1678134582],[1678134727,1678136801]]", + "[[1678343569,1678344469]]", + "[[1678744339,1678755139]]", + "[[1678894860,1678906620]]", + "[[1679339870,1679341672]]", + "[[1680547478,1680547482]]", + "[[1681156881,0]]", + ]; + + foreach($logs as $log) + { + $this->assertTrue($this->checkTimeLog(json_decode($log))); + } + + } + + public function testTimeLogChecker1() { $log = [