From 38c017fdf85a09d697e73235785fc9d1fe7fd413 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 30 Oct 2020 22:53:50 +1100 Subject: [PATCH] Migration for projects --- .../Controllers/Migration/StepsController.php | 1 + app/Traits/GenerateMigrationResources.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index cf7be9928e6a..684b41c14c0c 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -252,6 +252,7 @@ class StepsController extends BaseController 'client_gateway_tokens' => $this->getClientGatewayTokens(), 'expense_categories' => $this->getExpenseCategories(), 'task_statuses' => $this->getTaskStatuses(), + 'projects' => $this->getProjects(), 'expenses' => $this->getExpenses(), 'tasks' => $this->getTasks(), ]; diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 1211e222735e..0b05fcb04daf 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -15,6 +15,7 @@ use App\Models\Payment; use App\Models\PaymentMethod; use App\Models\PaymentTerm; use App\Models\Product; +use App\Models\Project; use App\Models\Task; use App\Models\TaskStatus; use App\Models\TaxRate; @@ -1187,6 +1188,41 @@ trait GenerateMigrationResources return $transformed; } + private function getProjects() + { + $projects = Project::where('account_id', $this->account->id) + ->withTrashed() + ->get(); + + $transformed = []; + + foreach ($projects as $project) + { + $transformed[] = [ + 'id' => $project->id, + 'company_id' => $this->account->id, + 'client_id' => $project->client_id, + 'custom_value1' => $project->custom_value1, + 'custom_value2' => $project->custom_value2, + 'custom_value3' => $project->custom_value3, + 'custom_value4' => $project->custom_value4, + 'budgeted_hours' => $project->budgeted_hours, + 'due_date' => $project->due_date, + 'name' => $project->name, + 'private_notes' => $project->private_notes, + 'public_notes' => '', + 'task_rate' => $project->task_rate, + 'user_id' => $project->user_id, + 'is_deleted' => $project->is_deleted, + 'created_at' => $project->created_at ? $project->created_at->toDateString() : null, + 'updated_at' => $project->updated_at ? $project->updated_at->toDateString() : null, + 'deleted_at' => $project->deleted_at ? $project->deleted_at->toDateString() : null, + ]; + } + + return $transformed; + } + private function convertMeta($payment_method) { $expiry = explode('-', $payment_method->expiration);