name = ''; $this->business_name = ''; $this->code = ''; $this->group_id = null; $this->address = ''; $this->zip = ''; $this->city_id = null; $this->country_id = null; $this->fiscal_code = ''; $this->vat = ''; $this->sdi = ''; $this->ateco = ''; $this->channel = ''; $this->website = ''; $this->email = ''; $this->pec = ''; $this->phone = ''; $this->referent_first_name = ''; $this->referent_last_name = ''; $this->referent_email = ''; $this->referent_phone = ''; $this->enabled = true; } public function render() { // Get Customers $this->customers = \App\Models\Customer::all(); return view('livewire.customer'); } public function add() { $this->resetFields(); $this->is_edit = true; $this->current_customer = null; } public function edit($id) { $this->resetFields(); $this->is_edit = true; $this->current_customer = \App\Models\Customer::findOrFail($id); $this->name = $this->current_customer->name; $this->business_name = $this->current_customer->business_name; $this->code = $this->current_customer->code; $this->group_id = $this->current_customer->group_id; $this->address = $this->current_customer->address; $this->zip = $this->current_customer->zip; $this->city_id = $this->current_customer->city_id; $this->country_id = $this->current_customer->country_id; $this->fiscal_code = $this->current_customer->fiscal_code; $this->vat = $this->current_customer->vat; $this->sdi = $this->current_customer->sdi; $this->ateco = $this->current_customer->ateco; $this->website = $this->current_customer->website; $this->email = $this->current_customer->email; $this->pec = $this->current_customer->pec; $this->phone = $this->current_customer->phone; $this->referent_first_name = $this->current_customer->referent_first_name; $this->referent_last_name = $this->current_customer->referent_last_name; $this->referent_email = $this->current_customer->referent_email; $this->referent_phone = $this->current_customer->referent_phone; $this->enabled = $this->current_customer->enabled; } public function save() { $this->validate(); try { if ($this->current_customer == null) { \App\Models\Customer::create([ 'name' => $this->name, 'business_name' => $this->business_name, 'code' => $this->code, 'group_id' => $this->group_id, 'address' => $this->address, 'zip' => $this->zip, 'city_id' => $this->city_id, 'country_id' => $this->country_id, 'fiscal_code' => $this->fiscal_code, 'vat' => $this->vat, 'sdi' => $this->sdi, 'ateco' => $this->ateco, 'website' => $this->website, 'email' => $this->email, 'pec' => $this->pec, 'phone' => $this->phone, 'referent_first_name' => $this->referent_first_name, 'referent_last_name' => $this->referent_last_name, 'referent_email' => $this->referent_email, 'referent_phone' => $this->referent_phone, 'enabled' => $this->enabled ]); } else { $this->current_company->update([ 'name' => $this->name, 'business_name' => $this->business_name, 'code' => $this->code, 'group_id' => $this->group_id, 'address' => $this->address, 'zip' => $this->zip, 'city_id' => $this->city_id, 'country_id' => $this->country_id, 'fiscal_code' => $this->fiscal_code, 'vat' => $this->vat, 'sdi' => $this->sdi, 'ateco' => $this->ateco, 'website' => $this->website, 'email' => $this->email, 'pec' => $this->pec, 'phone' => $this->phone, 'referent_first_name' => $this->referent_first_name, 'referent_last_name' => $this->referent_last_name, 'referent_email' => $this->referent_email, 'referent_phone' => $this->referent_phone, '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; } }