mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 08:12:17 +01:00
Compare commits
4 Commits
7e993a9249
...
v0.15.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab9f6e6afb | ||
|
|
2a40bb7edb | ||
|
|
365f672cfc | ||
|
|
25f30fa820 |
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Service\Import\Importers;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Csv\Exception as CsvException;
|
||||
use League\Csv\Reader;
|
||||
@@ -24,6 +25,7 @@ class ClockifyProjectsImporter extends DefaultImporter
|
||||
$header = $reader->getHeader();
|
||||
$this->validateHeader($header);
|
||||
$billableRateKey = $this->getBillableRateKey($header);
|
||||
$tasksKey = $this->getTasksKey($header);
|
||||
$records = $reader->getRecords();
|
||||
foreach ($records as $record) {
|
||||
$clientId = null;
|
||||
@@ -44,11 +46,12 @@ class ClockifyProjectsImporter extends DefaultImporter
|
||||
'is_billable' => $record['Billability'] === 'Yes',
|
||||
'billable_rate' => $billableRateKey !== null && $record[$billableRateKey] !== '' ? (int) (((float) $record[$billableRateKey]) * 100) : null,
|
||||
'estimated_time' => $record['Estimated (h)'] !== '' && is_numeric($record['Estimated (h)']) ? (int) ($record['Estimated (h)'] * 3600) : null,
|
||||
'archived_at' => $record['Status'] === 'Archived' ? Carbon::now() : null,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($record['Task'] !== '') {
|
||||
$tasks = explode(', ', $record['Task']);
|
||||
if ($record[$tasksKey] !== '') {
|
||||
$tasks = explode(', ', $record[$tasksKey]);
|
||||
foreach ($tasks as $task) {
|
||||
$this->taskImportHelper->getKey([
|
||||
'name' => $task,
|
||||
@@ -81,13 +84,26 @@ class ClockifyProjectsImporter extends DefaultImporter
|
||||
'Status',
|
||||
'Visibility',
|
||||
'Billability',
|
||||
'Task',
|
||||
];
|
||||
foreach ($requiredFields as $requiredField) {
|
||||
if (! in_array($requiredField, $header, true)) {
|
||||
throw new ImportException('Invalid CSV header, missing field: '.$requiredField);
|
||||
}
|
||||
}
|
||||
// Clockify renamed the "Task" column to "Tasks" in newer exports; accept either.
|
||||
if (! in_array('Task', $header, true) && ! in_array('Tasks', $header, true)) {
|
||||
throw new ImportException('Invalid CSV header, missing field: Tasks');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clockify renamed the "Task" column to "Tasks" in newer exports.
|
||||
*
|
||||
* @param array<string> $header
|
||||
*/
|
||||
private function getTasksKey(array $header): string
|
||||
{
|
||||
return in_array('Tasks', $header, true) ? 'Tasks' : 'Task';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,8 @@ declare(strict_types=1);
|
||||
return [
|
||||
'clockify_time_entries' => [
|
||||
'name' => 'Clockify Time Entries',
|
||||
'description' => '1. First make sure that you set the Date format to "MM/DD/YYYY" and the Time format to "12-hour" in the user settings.<br>'.
|
||||
'description' => '<strong>Important:</strong> If you also want to import your projects use the "Clockify Projects" importer before this one, since that export contains more details such as billable status, billable rates and estimated time.<br><br>'.
|
||||
'1. First make sure that you set the Date format to "MM/DD/YYYY" and the Time format to "12-hour" in the user settings.<br>'.
|
||||
'2. In the same preferences page change the language of Clockfiy to English.<br>'.
|
||||
'3. Go to REPORTS -> TIME -> Detailed in the navigation on the left. <br>'.
|
||||
'4. Now select the date range that you want to export in the right top. '.
|
||||
@@ -61,7 +62,8 @@ return [
|
||||
],
|
||||
'harvest_time_entries' => [
|
||||
'name' => 'Harvest Time Entries',
|
||||
'description' => '1. Go to Settings (right top corner)<br>2. Click on "Import/Export" in the left navigation'.
|
||||
'description' => '<strong>Important:</strong> If you also want to import your projects use the "Harvest Projects" importer before this one, since that export contains more details such as billable status and estimated time.<br><br>'.
|
||||
'1. Go to Settings (right top corner)<br>2. Click on "Import/Export" in the left navigation'.
|
||||
'<br>3. Now click on "Export all time" '.
|
||||
'<br><br>Before you import make sure that the Timezone settings in Harvest are the same as in solidtime.',
|
||||
],
|
||||
|
||||
@@ -199,7 +199,7 @@ body {
|
||||
--muted-foreground: var(--color-text-tertiary);
|
||||
--accent: var(--color-bg-tertiary);
|
||||
--accent-foreground: var(--color-text-primary);
|
||||
--destructive: 0 62.8% 30.6%;
|
||||
--destructive: 0 72% 60%;
|
||||
--destructive-foreground: var(--color-text-primary);
|
||||
--border: var(--color-border-primary);
|
||||
--input: var(--color-border-tertiary);
|
||||
|
||||
3
resources/testfiles/clockify_projects_import_test_2.csv
Normal file
3
resources/testfiles/clockify_projects_import_test_2.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
"Project","Client","Status","Visibility","Billability","Tasks","Tracked (h)","Estimated (h)","Remaining (h)","Overage (h)","Tracked (USD)","Estimated (USD)","Remaining (USD)","Overage (USD)","Progress(%)","Recurring estimate","Billable (h)","Non-billable (h)","Billable Rate (USD)","Amount (USD)","Cost Rate (USD)","Expenses (USD)","Billable expenses (USD)","Non-billable expenses (USD)","Additional fields","Project members","Project manager","Note"
|
||||
"Active Project","Big Company","Active","Public","Yes","Task 1, Task 2","0.00","100.00","","","","","","","","","0.00","0.00","100.01","0.00","","0.00","0.00","0.00","","Constantin Graf","",""
|
||||
"Archived Project","","Archived","Public","Yes","","0.00","","","","","","","","","","0.00","0.00","","0.00","","0.00","0.00","0.00","","Constantin Graf","",""
|
||||
|
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Service\Import\Importers;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Project;
|
||||
use App\Models\Task;
|
||||
use App\Service\Import\Importers\ClockifyProjectsImporter;
|
||||
use App\Service\Import\Importers\DefaultImporter;
|
||||
use App\Service\Import\Importers\ImportException;
|
||||
@@ -50,4 +52,47 @@ class ClockifyProjectsImporterTest extends ImporterTestAbstract
|
||||
// Assert
|
||||
$this->checkTestScenarioProjectsOnlyAfterImport();
|
||||
}
|
||||
|
||||
public function test_import_sets_archived_at_based_on_status_column(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new ClockifyProjectsImporter;
|
||||
$importer->init($organization);
|
||||
$data = Storage::disk('testfiles')->get('clockify_projects_import_test_2.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$activeProject = Project::query()->where('organization_id', $organization->id)->where('name', 'Active Project')->firstOrFail();
|
||||
$this->assertNull($activeProject->archived_at);
|
||||
$this->assertFalse($activeProject->is_archived);
|
||||
|
||||
$archivedProject = Project::query()->where('organization_id', $organization->id)->where('name', 'Archived Project')->firstOrFail();
|
||||
$this->assertNotNull($archivedProject->archived_at);
|
||||
$this->assertTrue($archivedProject->is_archived);
|
||||
}
|
||||
|
||||
public function test_import_supports_renamed_tasks_column(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$timezone = 'Europe/Vienna';
|
||||
$importer = new ClockifyProjectsImporter;
|
||||
$importer->init($organization);
|
||||
// Newer Clockify exports rename the "Task" column to "Tasks".
|
||||
$data = Storage::disk('testfiles')->get('clockify_projects_import_test_2.csv');
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
|
||||
// Assert
|
||||
$activeProject = Project::query()->where('organization_id', $organization->id)->where('name', 'Active Project')->firstOrFail();
|
||||
$this->assertEqualsCanonicalizing(
|
||||
['Task 1', 'Task 2'],
|
||||
Task::query()->where('project_id', $activeProject->id)->pluck('name')->all(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user