diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 9bc5bacfb0a6..2855457d0248 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -361,6 +361,16 @@ class CreateTestData extends Command } + private function createTask($client) + { + + } + + private function createProject($client) + { + + } + private function createInvoice($client) { $faker = \Faker\Factory::create(); diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index c677d053e042..6d5cbd8b69ef 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -88,6 +88,8 @@ class BaseController extends Controller 'company.quotes', 'company.vendors', 'company.expenses', + 'company.tasks', + 'company.projects', ]; } else { $include = [ diff --git a/app/Models/Company.php b/app/Models/Company.php index 756ebd93b4ad..4842a2593957 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -114,6 +114,22 @@ class Company extends BaseModel return $this->hasMany(Client::class)->withTrashed(); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function tasks() + { + return $this->hasMany(Task::class)->withTrashed(); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function projects() + { + return $this->hasMany(Project::class)->withTrashed(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/Project.php b/app/Models/Project.php index 78b390e2bf26..6b1d0488a413 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -31,7 +31,11 @@ class Project extends BaseModel 'custom_value1', 'custom_value2', ]; - + + protected $casts = [ + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + ]; /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/Models/Task.php b/app/Models/Task.php index 797af7f02051..0a4e5d53d7de 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -28,6 +28,10 @@ class Task extends BaseModel 'time_log', ]; + protected $casts = [ + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + ]; public function documents() { diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 1212e17f1405..e14cbca3ff5c 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -21,7 +21,9 @@ use App\Models\Expense; use App\Models\GroupSetting; use App\Models\Payment; use App\Models\Product; +use App\Models\Project; use App\Models\Quote; +use App\Models\Task; use App\Models\TaxRate; use App\Models\User; use App\Utils\Traits\MakesHash; @@ -61,6 +63,8 @@ class CompanyTransformer extends EntityTransformer 'company_gateways', 'activities', 'quotes', + 'projects', + 'tasks', ]; @@ -139,6 +143,20 @@ class CompanyTransformer extends EntityTransformer return $this->includeCollection($company->clients, $transformer, Client::class); } + public function includeProjects(Company $company) + { + $transformer = new ProjectTransformer($this->serializer); + + return $this->includeCollection($company->projects, $transformer, Project::class); + } + + public function includeClients(Company $company) + { + $transformer = new TaskTransformer($this->serializer); + + return $this->includeCollection($company->tasks, $transformer, Task::class); + } + public function includeExpenses(Company $company) { $transformer = new ExpenseTransformer($this->serializer); diff --git a/app/Transformers/ProjectTransformer.php b/app/Transformers/ProjectTransformer.php new file mode 100644 index 000000000000..34d626f04114 --- /dev/null +++ b/app/Transformers/ProjectTransformer.php @@ -0,0 +1,54 @@ + (string) $this->encodePrimaryKey($project->id), + 'name' => $project->name ?: '', + 'client_id' => (string) $this->encodePrimaryKey($project->client_id), + 'updated_at' => (int)$project->updated_at, + 'archived_at' => (int)$project->deleted_at, + 'is_deleted' => (bool) $project->is_deleted, + 'task_rate' => (float) $project->task_rate, + 'due_date' => $project->due_date ?: '', + 'private_notes' => $project->private_notes ?: '', + 'budgeted_hours' => (float) $project->budgeted_hours, + 'custom_value1' => $project->custom_value1 ?: '', + 'custom_value2' => $project->custom_value2 ?: '', + 'custom_value3' => $project->custom_value3 ?: '', + 'custom_value4' => $project->custom_value4 ?: '', + ]; + } + +} + diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php new file mode 100644 index 000000000000..6b9352b453e3 --- /dev/null +++ b/app/Transformers/TaskTransformer.php @@ -0,0 +1,55 @@ + (string) $this->encodePrimaryKey($task->id), + 'description' => $task->description ?: '', + 'duration' => $task->getDuration() ?: 0, + 'updated_at' => (int)$task->updated_at, + 'archived_at' => (int)$task->deleted_at, + 'invoice_id' => $this->encodePrimaryKey($task->invoice_id), + 'client_id' => $this->encodePrimaryKey($task->client_id), + 'project_id' => $this->encodePrimaryKey($task->project_id), + 'is_deleted' => (bool) $task->is_deleted, + 'time_log' => $task->time_log ?: '', + 'is_running' => (bool) $task->is_running, + 'custom_value1' => $task->custom_value1 ?: '', + 'custom_value2' => $task->custom_value2 ?: '', + 'custom_value3' => $task->custom_value3 ?: '', + 'custom_value4' => $task->custom_value4 ?: '', + 'task_status_id' => $this->encodePrimaryKey($task->task_status_id), + 'task_status_sort_order' => (int) $task->task_status_sort_order, + ]; + } +}