mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	Fixes for rounding
This commit is contained in:
		
							parent
							
								
									a18806f986
								
							
						
					
					
						commit
						01dde73e95
					
				@ -537,16 +537,6 @@ class TaskController extends BaseController
 | 
				
			|||||||
        return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids)));
 | 
					        return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * Returns a client statement.
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @return void [type] [description]
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    public function statement()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        //todo
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Update the specified resource in storage.
 | 
					     * Update the specified resource in storage.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
@ -254,7 +254,7 @@ class TaskRepository extends BaseRepository
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function roundTimeLog(int $start_time, int $end_time): int
 | 
					    public function roundTimeLog(int $start_time, int $end_time): int
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if($this->task_round_to_nearest == 1)
 | 
					        if($this->task_round_to_nearest == 1 || $end_time == 0)
 | 
				
			||||||
            return $end_time;
 | 
					            return $end_time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $interval = $end_time - $start_time;
 | 
					        $interval = $end_time - $start_time;
 | 
				
			||||||
@ -266,17 +266,6 @@ class TaskRepository extends BaseRepository
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // public function roundTimeLog(int $end_time): int
 | 
					 | 
				
			||||||
    // {
 | 
					 | 
				
			||||||
    //     if($this->task_round_to_nearest == 1)
 | 
					 | 
				
			||||||
    //         return $end_time;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //     if($this->task_round_up)
 | 
					 | 
				
			||||||
    //         return (int)ceil($end_time/$this->task_round_to_nearest)*$this->task_round_to_nearest;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    //     return (int)floor($end_time/$this->task_round_to_nearest) * $this->task_round_to_nearest;
 | 
					 | 
				
			||||||
    // }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function stop(Task $task)
 | 
					    public function stop(Task $task)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->init($task);
 | 
					        $this->init($task);
 | 
				
			||||||
 | 
				
			|||||||
@ -12,6 +12,14 @@
 | 
				
			|||||||
namespace Tests\Unit;
 | 
					namespace Tests\Unit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Tests\TestCase;
 | 
					use Tests\TestCase;
 | 
				
			||||||
 | 
					use App\Models\Task;
 | 
				
			||||||
 | 
					use App\Models\Client;
 | 
				
			||||||
 | 
					use Tests\MockAccountData;
 | 
				
			||||||
 | 
					use App\Utils\Traits\MakesHash;
 | 
				
			||||||
 | 
					use App\DataMapper\ClientSettings;
 | 
				
			||||||
 | 
					use Illuminate\Database\Eloquent\Model;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Session;
 | 
				
			||||||
 | 
					use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @test
 | 
					 * @test
 | 
				
			||||||
@ -23,10 +31,23 @@ class TaskRoundingTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public bool $task_round_up = true;
 | 
					    public bool $task_round_up = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function setUp(): void
 | 
					    use MakesHash;
 | 
				
			||||||
 | 
					    use DatabaseTransactions;
 | 
				
			||||||
 | 
					    use MockAccountData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private $faker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function setUp() :void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        parent::setUp();
 | 
					        parent::setUp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->makeTestData();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Session::start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->faker = \Faker\Factory::create();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Model::reguard();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testRoundUp()
 | 
					    public function testRoundUp()
 | 
				
			||||||
@ -70,50 +91,94 @@ class TaskRoundingTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
 | 
					        $this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $s = \Carbon\Carbon::createFromTimestamp($start_time);
 | 
				
			||||||
 | 
					        // $e = \Carbon\Carbon::createFromTimestamp($end_time);
 | 
				
			||||||
 | 
					        // $x = \Carbon\Carbon::createFromTimestamp($rounded);
 | 
				
			||||||
 | 
					        // echo $s->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					        // echo $e->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					        // echo $x->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$s = \Carbon\Carbon::createFromTimestamp($start_time);
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$e = \Carbon\Carbon::createFromTimestamp($end_time);
 | 
					    public function testRoundUp4()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        $x = \Carbon\Carbon::createFromTimestamp($rounded);
 | 
					        $start_time = 1715238000;
 | 
				
			||||||
 | 
					        $end_time = 1715238900;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->task_round_to_nearest = 900;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $rounded = $start_time + 60*15;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // $s = \Carbon\Carbon::createFromTimestamp($start_time);
 | 
				
			||||||
 | 
					        // $e = \Carbon\Carbon::createFromTimestamp($end_time);
 | 
				
			||||||
 | 
					        // $x = \Carbon\Carbon::createFromTimestamp($rounded);
 | 
				
			||||||
 | 
					        // echo $s->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					        // echo $e->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					        // echo $x->format('Y-m-d H:i:s').PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// echo $s->format('Y-m-d H:i:s').PHP_EOL;
 | 
					$this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
 | 
				
			||||||
// echo $e->format('Y-m-d H:i:s').PHP_EOL;
 | 
					 | 
				
			||||||
// echo $x->format('Y-m-d H:i:s').PHP_EOL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//     public function testRoundUp4()
 | 
					    public function testRoundingViaBulkAction()
 | 
				
			||||||
//     {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->company->settings->default_task_rate = 41;
 | 
				
			||||||
 | 
					        $this->company->settings->task_round_to_nearest = 900;
 | 
				
			||||||
 | 
					        $this->company->settings->task_round_up = true;
 | 
				
			||||||
 | 
					        $this->company->saveSettings($this->company->settings, $this->company);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $settings = ClientSettings::defaults();
 | 
				
			||||||
 | 
					        $settings->default_task_rate = 41;
 | 
				
			||||||
 | 
					        $settings->task_round_to_nearest = 900;
 | 
				
			||||||
 | 
					        $settings->task_round_up = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $c = Client::factory()->create([
 | 
				
			||||||
 | 
					            'user_id' => $this->user->id,
 | 
				
			||||||
 | 
					            'company_id' => $this->company->id,
 | 
				
			||||||
 | 
					            // 'settings' => $settings,
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $var = time()-800;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $start_time = 1715238900;
 | 
					        $data = [
 | 
				
			||||||
//         $end_time = 1715238000;
 | 
					            'client_id' => $c->hashed_id,
 | 
				
			||||||
//         // $end_time = $start_time + 60*15; 
 | 
					            'description' => 'Test Task',
 | 
				
			||||||
//         $this->task_round_to_nearest = 900;
 | 
					            'time_log' => '[[1681165417,1681165432,"sumtin",true],['.$var.',0]]',
 | 
				
			||||||
 | 
					            'assigned_user' => [],
 | 
				
			||||||
 | 
					            'project' => [],
 | 
				
			||||||
 | 
					            'user' => [],
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $rounded = $start_time + 60*15;
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
 | 
					            'X-API-SECRET' => config('ninja.api_secret'),
 | 
				
			||||||
 | 
					            'X-API-TOKEN' => $this->token,
 | 
				
			||||||
 | 
					        ])->postJson("/api/v1/tasks/", $data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
 | 
					        $response->assertStatus(200);
 | 
				
			||||||
 | 
					        $arr = $response->json();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $i = $arr['data']['id'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $s = \Carbon\Carbon::createFromTimestamp($start_time);
 | 
					        $data = [
 | 
				
			||||||
 | 
					            'ids' => [$i],
 | 
				
			||||||
 | 
					            'action' => 'stop'
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $e = \Carbon\Carbon::createFromTimestamp($end_time);
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
 | 
					            'X-API-SECRET' => config('ninja.api_secret'),
 | 
				
			||||||
 | 
					            'X-API-TOKEN' => $this->token,
 | 
				
			||||||
 | 
					        ])->postJson("/api/v1/tasks/bulk", $data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//         $x = \Carbon\Carbon::createFromTimestamp($rounded);
 | 
					        $response->assertStatus(200);
 | 
				
			||||||
 | 
					        $arr = $response->json();
 | 
				
			||||||
 | 
					 | 
				
			||||||
// echo $s->format('Y-m-d H:i:s').PHP_EOL;
 | 
					 | 
				
			||||||
// echo $e->format('Y-m-d H:i:s').PHP_EOL;
 | 
					 | 
				
			||||||
// echo $x->format('Y-m-d H:i:s').PHP_EOL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//     }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = Task::find($this->decodePrimaryKey($i));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testRoundDown()
 | 
					    public function testRoundDown()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user