mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 23:44:28 -04:00
Expense category filters
This commit is contained in:
parent
19cfee10a0
commit
6fa753a149
@ -158,6 +158,18 @@ class ExpenseFilters extends QueryFilters
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
public function categories(string $categories = ''): Builder
|
||||
{
|
||||
$categories_exploded = explode(",", $categories);
|
||||
|
||||
if(empty($categories) || count(array_filter($categories_exploded)) == 0)
|
||||
return $this->builder;
|
||||
|
||||
$categories_keys = $this->transformKeys($categories_exploded);
|
||||
|
||||
return $this->builder->whereIn('category_id', $categories_keys);
|
||||
}
|
||||
|
||||
public function number(string $number = ''): Builder
|
||||
{
|
||||
if (strlen($number) == 0) {
|
||||
|
@ -85,6 +85,10 @@ class TaskFilters extends QueryFilters
|
||||
$this->builder->whereNull('invoice_id');
|
||||
}
|
||||
|
||||
if (in_array('is_running', $status_parameters)) {
|
||||
$this->builder->where('is_running', true);
|
||||
}
|
||||
|
||||
return $this->builder;
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,10 @@ class TaskRepository extends BaseRepository
|
||||
|
||||
$task->calculated_start_date = $this->harvestStartDate($time_log, $task);
|
||||
|
||||
if(isset(end($time_log)[1])){
|
||||
$task->is_running = end($time_log)[1] == 0;
|
||||
}
|
||||
|
||||
$task->time_log = json_encode($time_log);
|
||||
|
||||
$task->saveQuietly();
|
||||
@ -259,7 +263,7 @@ class TaskRepository extends BaseRepository
|
||||
|
||||
$log = array_merge($log, [$new]);
|
||||
$task->time_log = json_encode($log);
|
||||
|
||||
$task->is_running = true;
|
||||
$task->saveQuietly();
|
||||
}
|
||||
|
||||
@ -303,6 +307,7 @@ class TaskRepository extends BaseRepository
|
||||
$log = array_merge($log, [$last]);//check at this point, it may be prepending here.
|
||||
|
||||
$task->time_log = json_encode($log);
|
||||
$task->is_running = false;
|
||||
$task->saveQuietly();
|
||||
}
|
||||
|
||||
@ -418,4 +423,4 @@ class TaskRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5311,6 +5311,7 @@ $lang = array(
|
||||
'customer_type' => 'Customer Type',
|
||||
'process_date' => 'Process Date',
|
||||
'forever_free' => 'Forever Free',
|
||||
'comments_only' => 'Comments Only',
|
||||
);
|
||||
|
||||
return $lang;
|
||||
|
@ -314,21 +314,23 @@ class ExpenseApiTest extends TestCase
|
||||
public function testExpenseBulkCategorize()
|
||||
{
|
||||
|
||||
$eXX = Expense::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
|
||||
$e = Expense::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
]);
|
||||
|
||||
|
||||
$ec = ExpenseCategory::factory()->create([
|
||||
'company_id' => $this->company->id,
|
||||
'user_id' => $this->user->id,
|
||||
'name' => 'Test Category',
|
||||
]);
|
||||
|
||||
nlog("expense category id = {$ec->hashed_id}");
|
||||
|
||||
$data = [
|
||||
'category_id' => $ec->hashed_id,
|
||||
'action' => 'bulk_categorize',
|
||||
@ -341,11 +343,32 @@ class ExpenseApiTest extends TestCase
|
||||
])->post('/api/v1/expenses/bulk', $data);
|
||||
|
||||
$arr = $response->json();
|
||||
nlog($arr);
|
||||
|
||||
|
||||
$this->assertEquals($ec->hashed_id, $arr['data'][0]['category_id']);
|
||||
}
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get("/api/v1/expenses");
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertGreaterThan(1, count($arr['data']));
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get("/api/v1/expenses?categories={$ec->hashed_id}");
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertCount(1, $arr['data']);
|
||||
|
||||
}
|
||||
|
||||
public function testAddingExpense()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user