Company.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Livewire;
  3. use Livewire\Component;
  4. use Livewire\Attributes\Validate;
  5. class Company extends Component
  6. {
  7. #[Validate('required')]
  8. public $name = '';
  9. public $business_name = '';
  10. public $logo = '';
  11. public $phone = '';
  12. public $email = '';
  13. public $pec = '';
  14. public $costitution_date = null;
  15. public $address = '';
  16. public $zip = '';
  17. public $city_id = null;
  18. public $country_id = null;
  19. public $operational_headquarters = '';
  20. public $fiscal_code = '';
  21. public $vat = '';
  22. public $sdi_code = '';
  23. public $ateco_code = '';
  24. public $enabled = true;
  25. public $current_company = null;
  26. public $is_edit = false;
  27. public function render()
  28. {
  29. // Get Company
  30. $this->current_company = \App\Models\Company::first();
  31. if ($this->current_company != null)
  32. {
  33. $this->name = $this->current_company->name;
  34. $this->business_name = $this->current_company->business_name;
  35. $this->logo = $this->current_company->logo;
  36. $this->phone = $this->current_company->phone;
  37. $this->email = $this->current_company->email;
  38. $this->pec = $this->current_company->pec;
  39. $this->costitution_date = $this->current_company->pec;
  40. $this->address = $this->current_company->address;
  41. $this->zip = $this->current_company->zip;
  42. $this->city_id = $this->current_company->city_id;
  43. $this->country_id = $this->current_company->country_id;
  44. $this->operational_headquarters = $this->current_company->operational_headquarters;
  45. $this->fiscal_code = $this->current_company->fiscal_code;
  46. $this->vat = $this->current_company-> vat;
  47. $this->sdi_code = $this->current_company->sdi_code;
  48. $this->ateco_code = $this->current_company->ateco_code;
  49. $this->enabled = $this->current_company->enabled;
  50. }
  51. return view('livewire.company');
  52. }
  53. public function update()
  54. {
  55. $this->validate();
  56. try {
  57. $this->current_company->update([
  58. 'name' => $this->name,
  59. 'business_name' => $this->business_name,
  60. 'logo' => $this->logo,
  61. 'phone' => $this->phone,
  62. 'email' => $this->email,
  63. 'pec' => $this->pec,
  64. 'costitution_date' => $this->pec,
  65. 'address' => $this->address,
  66. 'zip' => $this->zip,
  67. 'city_id' => $this->city_id,
  68. 'country_id' => $this->country_id,
  69. 'operational_headquarters' => $this->operational_headquarters,
  70. 'fiscal_code' => $this->fiscal_code,
  71. 'vat' => $this-> vat,
  72. 'sdi_code' => $this->sdi_code,
  73. 'ateco_code' => $this->ateco_code,
  74. 'enabled' => $this->enabled,
  75. ]);
  76. session()->flash('success','Dato aggiornato');
  77. //$this->resetFields();
  78. $this->is_edit = false;
  79. } catch (\Exception $ex) {
  80. session()->flash('error','Errore (' . $ex->getMessage() . ')');
  81. }
  82. }
  83. }