MemberArchive.php 3.9 KB

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