MemberArchive.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Illuminate\Support\Facades\Log;
  5. use App\Http\Middleware\TenantMiddleware;
  6. use DateTime;
  7. class MemberArchive extends Component
  8. {
  9. public $categories = [];
  10. public function boot(){
  11. app(abstract: TenantMiddleware::class)->setupTenantConnection();
  12. }
  13. public function mount()
  14. {
  15. $this->categories = [];
  16. $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->orderBy('name')->get(), 0);
  17. }
  18. public function render()
  19. {
  20. return view('livewire.member_archive');
  21. }
  22. public function getCategories($records, $indentation)
  23. {
  24. foreach ($records as $record) {
  25. $this->categories[] = array('id' => $record->id, 'name' => $record->getTree());
  26. if (count($record->childs))
  27. $this->getCategories($record->childs, $indentation + 1);
  28. }
  29. }
  30. public function restore($id)
  31. {
  32. try {
  33. $member = \App\Models\Member::findOrFail($id);
  34. $member->update([
  35. 'is_archived' => false,
  36. 'archived_date' => null,
  37. 'status' => '',
  38. 'enabled' => true
  39. ]);
  40. updateMemberData($id);
  41. session()->flash('success', 'Membro riattivato con successo');
  42. $this->emit('reload');
  43. } catch (\Exception $e) {
  44. session()->flash('error', 'Errore durante la riattivazione: ' . $e->getMessage());
  45. Log::error('Restore member error', [
  46. 'member_id' => $id,
  47. 'error' => $e->getMessage(),
  48. 'trace' => $e->getTraceAsString()
  49. ]);
  50. }
  51. }
  52. public function archive($id)
  53. {
  54. try {
  55. $member = \App\Models\Member::findOrFail($id);
  56. $member->update([
  57. 'is_deleted' => true,
  58. 'deleted_date' => now(),
  59. 'first_name' => 'Nome Archiviato',
  60. 'last_name' => 'Cognome Archiviato',
  61. 'fiscal_code' => null,
  62. 'email' => null,
  63. 'phone' => null,
  64. 'phone2' => null,
  65. 'phone3' => null,
  66. 'address' => null,
  67. 'zip_code' => null,
  68. 'birth_place' => null,
  69. 'birth_date' => null,
  70. 'birth_city_id' => null,
  71. 'birth_province_id' => null,
  72. 'birth_nation_id' => null,
  73. 'nation_id' => null,
  74. 'province_id' => null,
  75. 'city_id' => null,
  76. 'document_type' => null,
  77. 'document_number' => null,
  78. 'document_from' => null,
  79. 'document_expire_date' => null,
  80. 'document_files' => null,
  81. 'father_name' => null,
  82. 'mother_name' => null,
  83. 'father_email' => null,
  84. 'mother_email' => null,
  85. 'father_phone' => null,
  86. 'mother_phone' => null,
  87. 'father_fiscal_code' => null,
  88. 'mother_fiscal_code' => null,
  89. 'father_doc_number' => null,
  90. 'father_doc_type' => null,
  91. 'mother_doc_number' => null,
  92. 'mother_doc_type' => null,
  93. 'father_document_files' => null,
  94. 'mother_document_files' => null,
  95. 'image' => null,
  96. 'gender' => null,
  97. 'status' => 'archived',
  98. 'enabled' => false
  99. ]);
  100. updateMemberData($id);
  101. session()->flash('success', 'Membro archiviato con successo');
  102. $this->emit('reload');
  103. } catch (\Exception $e) {
  104. session()->flash('error', 'Errore durante l\'archiviazione: ' . $e->getMessage());
  105. Log::error('Archive member error', [
  106. 'member_id' => $id,
  107. 'error' => $e->getMessage(),
  108. 'trace' => $e->getTraceAsString()
  109. ]);
  110. }
  111. }
  112. }