| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use Illuminate\Support\Facades\Log;
- use App\Http\Middleware\TenantMiddleware;
- use DateTime;
- class MemberArchive extends Component
- {
- public $categories = [];
- public function boot(){
- app(abstract: TenantMiddleware::class)->setupTenantConnection();
- }
- public function mount()
- {
- $this->categories = [];
- $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->orderBy('name')->get(), 0);
- }
- public function render()
- {
- return view('livewire.member_archive');
- }
- public function getCategories($records, $indentation)
- {
- foreach ($records as $record) {
- $this->categories[] = array('id' => $record->id, 'name' => $record->getTree());
- if (count($record->childs))
- $this->getCategories($record->childs, $indentation + 1);
- }
- }
- public function restore($id)
- {
- try {
- $member = \App\Models\Member::findOrFail($id);
- $member->update([
- 'is_archived' => false,
- 'archived_date' => null,
- 'status' => '',
- 'enabled' => true
- ]);
- updateMemberData($id);
- session()->flash('success', 'Membro riattivato con successo');
- $this->emit('reload');
- } catch (\Exception $e) {
- session()->flash('error', 'Errore durante la riattivazione: ' . $e->getMessage());
- Log::error('Restore member error', [
- 'member_id' => $id,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- }
- }
- public function archive($id)
- {
- try {
- $member = \App\Models\Member::findOrFail($id);
- $member->update([
- 'is_deleted' => true,
- 'deleted_date' => now(),
- 'first_name' => 'Nome Archiviato',
- 'last_name' => 'Cognome Archiviato',
- 'fiscal_code' => null,
- 'email' => null,
- 'phone' => null,
- 'phone2' => null,
- 'phone3' => null,
- 'address' => null,
- 'zip_code' => null,
- 'birth_place' => null,
- 'birth_date' => null,
- 'birth_city_id' => null,
- 'birth_province_id' => null,
- 'birth_nation_id' => null,
- 'nation_id' => null,
- 'province_id' => null,
- 'city_id' => null,
- 'document_type' => null,
- 'document_number' => null,
- 'document_from' => null,
- 'document_expire_date' => null,
- 'document_files' => null,
- 'father_name' => null,
- 'mother_name' => null,
- 'father_email' => null,
- 'mother_email' => null,
- 'father_phone' => null,
- 'mother_phone' => null,
- 'father_fiscal_code' => null,
- 'mother_fiscal_code' => null,
- 'father_doc_number' => null,
- 'father_doc_type' => null,
- 'mother_doc_number' => null,
- 'mother_doc_type' => null,
- 'father_document_files' => null,
- 'mother_document_files' => null,
- 'image' => null,
- 'gender' => null,
- 'status' => 'archived',
- 'enabled' => false
- ]);
- updateMemberData($id);
- session()->flash('success', 'Membro archiviato con successo');
- $this->emit('reload');
- } catch (\Exception $e) {
- session()->flash('error', 'Errore durante l\'archiviazione: ' . $e->getMessage());
- Log::error('Archive member error', [
- 'member_id' => $id,
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- }
- }
- }
|