mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-02 19:04:33 -04:00
Fixes for task time_logs
This commit is contained in:
parent
15676a3683
commit
fabf02ace0
@ -274,6 +274,7 @@ class TaskController extends BaseController
|
|||||||
$old_task = json_decode(json_encode($task));
|
$old_task = json_decode(json_encode($task));
|
||||||
|
|
||||||
$task = $this->task_repo->save($request->all(), $task);
|
$task = $this->task_repo->save($request->all(), $task);
|
||||||
|
|
||||||
$task = $this->task_repo->triggeredActions($request, $task);
|
$task = $this->task_repo->triggeredActions($request, $task);
|
||||||
|
|
||||||
if ($task->status_order != $old_task->status_order) {
|
if ($task->status_order != $old_task->status_order) {
|
||||||
|
@ -148,8 +148,8 @@ class CompanyExport implements ShouldQueue
|
|||||||
|
|
||||||
$this->export_data['clients'] = $this->company->clients()->orderBy('number', 'DESC')->cursor()->map(function ($client) {
|
$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']);
|
$client = $this->transformArrayOfKeys($client, ['company_id', 'user_id', 'assigned_user_id', 'group_settings_id']);
|
||||||
|
$client->tax_data = '';
|
||||||
return $client->makeVisible(['id','private_notes','user_id','company_id','last_login','hashed_id']);
|
return $client->makeVisible(['id','private_notes','user_id','company_id','last_login','hashed_id'])->makeHidden(['is_tax_exempt','has_valid_vat_number']);
|
||||||
})->all();
|
})->all();
|
||||||
|
|
||||||
|
|
||||||
@ -229,6 +229,7 @@ class CompanyExport implements ShouldQueue
|
|||||||
$this->export_data['invoices'] = $this->company->invoices()->orderBy('number', 'DESC')->cursor()->map(function ($invoice) {
|
$this->export_data['invoices'] = $this->company->invoices()->orderBy('number', 'DESC')->cursor()->map(function ($invoice) {
|
||||||
$invoice = $this->transformBasicEntities($invoice);
|
$invoice = $this->transformBasicEntities($invoice);
|
||||||
$invoice = $this->transformArrayOfKeys($invoice, ['recurring_id','client_id', 'vendor_id', 'project_id', 'design_id', 'subscription_id','project_id']);
|
$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',
|
return $invoice->makeVisible(['id',
|
||||||
'private_notes',
|
'private_notes',
|
||||||
|
@ -35,7 +35,7 @@ class TaskRepository extends BaseRepository
|
|||||||
*
|
*
|
||||||
* @return task|null task Object
|
* @return task|null task Object
|
||||||
*/
|
*/
|
||||||
public function save(array $data, Task $task) : ?Task
|
public function save(array $data, Task $task): ?Task
|
||||||
{
|
{
|
||||||
if ($task->id) {
|
if ($task->id) {
|
||||||
$this->new_task = false;
|
$this->new_task = false;
|
||||||
@ -98,7 +98,8 @@ class TaskRepository extends BaseRepository
|
|||||||
$time_log = [];
|
$time_log = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($time_log);
|
// array_multisort($time_log);
|
||||||
|
ksort($time_log);
|
||||||
|
|
||||||
if (isset($data['action'])) {
|
if (isset($data['action'])) {
|
||||||
if ($data['action'] == 'start') {
|
if ($data['action'] == 'start') {
|
||||||
@ -118,8 +119,6 @@ class TaskRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$task->time_log = json_encode($time_log);
|
$task->time_log = json_encode($time_log);
|
||||||
// $task->start_time = $task->start_time ?: $task->calcStartTime();
|
|
||||||
// $task->duration = $task->calcDuration();
|
|
||||||
|
|
||||||
$task->saveQuietly();
|
$task->saveQuietly();
|
||||||
|
|
||||||
@ -206,10 +205,12 @@ class TaskRepository extends BaseRepository
|
|||||||
|
|
||||||
$last = end($log);
|
$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];
|
$new = [time(), 0];
|
||||||
|
|
||||||
$log = array_merge($log, [$new]);
|
$log = array_merge($log, [$new]);
|
||||||
$task->time_log = json_encode($log);
|
$task->time_log = json_encode($log);
|
||||||
|
|
||||||
$task->saveQuietly();
|
$task->saveQuietly();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +227,7 @@ class TaskRepository extends BaseRepository
|
|||||||
$last[1] = time();
|
$last[1] = time();
|
||||||
|
|
||||||
array_pop($log);
|
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->time_log = json_encode($log);
|
||||||
$task->saveQuietly();
|
$task->saveQuietly();
|
||||||
|
@ -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()
|
public function testTimeLogChecker1()
|
||||||
{
|
{
|
||||||
$log = [
|
$log = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user