Company.php 3.3 KB

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