name = ''; $this->code = ''; $this->customer_id = null; $this->company_service_id = null; $this->description = ''; $this->start_date = null; $this->end_date = null; $this->project_manager_id = null; $this->project_value = 0; $this->hours = 0; $this->status = 0; $this->billable = 0; $this->enabled = true; } public function render() { // Get Customers $this->projects = \App\Models\Project::all(); return view('livewire.project'); } public function add() { $this->resetFields(); $this->is_edit = true; $this->current_project = null; } public function edit($id) { $this->resetFields(); $this->is_edit = true; $this->current_project = \App\Models\Project::findOrFail($id); $this->name = $this->current_project->name; $this->code = $this->current_project->code; $this->customer_id = $this->current_project->customer_id; $this->company_service_id = $this->current_project->company_service_id; $this->description = $this->current_project->description; $this->start_date = $this->current_project->start_date; $this->end_date = $this->current_project->end_date; $this->project_manager_id = $this->current_project->project_manager_id; $this->project_value = $this->current_project->project_value; $this->hours = $this->current_project->hours; $this->status = $this->current_project->status; $this->billable = $this->current_project->billable; $this->enabled = $this->current_customer->enabled; } public function save() { $this->validate(); try { if ($this->current_project == null) { \App\Models\Project::create([ 'name' => $this->name, 'code' => $this->code, 'customer_id' => $this->customer_id, 'company_service_id' => $this->company_service_id, 'description' => $this->description, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'project_manager_id' => $this->project_manager_id, 'project_value' => $this->project_value, 'hours' => $this->hours, 'status' => $this->status, 'billable' => $this->billable, 'enabled' => $this->enabled ]); } else { $this->current_project->update([ 'name' => $this->name, 'code' => $this->code, 'customer_id' => $this->customer_id, 'company_service_id' => $this->company_service_id, 'description' => $this->description, 'start_date' => $this->start_date, 'end_date' => $this->end_date, 'project_manager_id' => $this->project_manager_id, 'project_value' => $this->project_value, 'hours' => $this->hours, 'status' => $this->status, 'billable' => $this->billable, 'enabled' => $this->enabled, ]); } session()->flash('success','Dati salvati con successo'); $this->resetFields(); $this->is_edit = false; } catch (\Exception $ex) { session()->flash('error','Errore (' . $ex->getMessage() . ')'); } } public function cancel() { $this->resetFields(); $this->is_edit = false; $this->current_company = null; } }