7d854ffb0a
- Translation system: lang/es/ PHP files (auth, validation, pagination, passwords)
- Rappasoft vendor translations published (lang/vendor/livewire-tables/es/)
- JSON files synced to 391 keys (EN + ES, full parity)
- APP_LOCALE changed to 'es', users.locale column default changed to 'es'
- Language switcher fixed: JS event + window.location.reload() avoids /livewire/update redirect
- SetLocale middleware fallback uses config('app.locale') instead of hardcoded 'en'
- setSortingPillsEnabled(false) on ProjectTable, CompanyTable, UserTable
- Translated 17 blade views: project-map, template-manager, layer-manager,
company-management, phase-list, media-manager, reports-dashboard,
client-projects, layer-upload, project-form, project-map-editor-tab,
admin/users, projects/media, projects/templates, layouts/client
- Navigation 'Empresas' link uses __('Companies')
- Fixed typo key 'Fases and layers' -> 'Phases and layers'
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Livewire\Attributes\Layout;
|
|
use App\Models\Company;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
#[Layout('layouts.app')]
|
|
class CompanyManagement extends Component
|
|
{
|
|
public string $search = '';
|
|
public string $filterType = '';
|
|
public string $filterEstado = '';
|
|
|
|
public function getCompaniesProperty()
|
|
{
|
|
return Company::when($this->search, function ($q) {
|
|
$s = '%' . $this->search . '%';
|
|
$q->where(fn($q2) => $q2
|
|
->where('name', 'like', $s)
|
|
->orWhere('apodo', 'like', $s)
|
|
->orWhere('tax_id', 'like', $s));
|
|
})
|
|
->when($this->filterType, fn($q) => $q->where('type', $this->filterType))
|
|
->when($this->filterEstado, fn($q) => $q->where('estado', $this->filterEstado))
|
|
->withCount('projects')
|
|
->orderBy('name')
|
|
->get();
|
|
}
|
|
|
|
public function deleteCompany(Company $company): void
|
|
{
|
|
if ($company->logo_path) {
|
|
Storage::disk('public')->delete($company->logo_path);
|
|
}
|
|
$company->delete();
|
|
$this->dispatch('notify', 'Empresa eliminada.');
|
|
}
|
|
|
|
public function exportCsv()
|
|
{
|
|
$companies = $this->getCompaniesProperty();
|
|
|
|
return response()->streamDownload(function () use ($companies) {
|
|
$handle = fopen('php://output', 'w');
|
|
fprintf($handle, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
|
fputcsv($handle, ['Nombre', 'Apodo', 'NIF/Tax ID', 'Tipo', 'Estado', 'Dirección', 'Teléfono', 'Email', 'Website', 'Proyectos', 'Creación']);
|
|
foreach ($companies as $c) {
|
|
fputcsv($handle, [
|
|
$c->name, $c->apodo ?? '', $c->tax_id ?? '',
|
|
$c->type, $c->estado, $c->address ?? '',
|
|
$c->phone ?? '', $c->email ?? '', $c->website ?? '',
|
|
$c->projects_count ?? 0,
|
|
$c->created_at?->format('d/m/Y'),
|
|
]);
|
|
}
|
|
fclose($handle);
|
|
}, 'empresas.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.company-management');
|
|
}
|
|
}
|