@php $receipt = $data; // $data ya es el Receipt $quotation = null; $payments = collect(); $count_payment = 0; $advancements = 0; // Cargar relaciones necesarias del receipt if ($receipt) { $receipt->load(['patient.identity_document_type', 'patient.district', 'patient.province', 'patient.department', 'user']); } if ($receipt && $receipt->quotation_id) { $quotation = App\Models\Quotation::with(['currency_type', 'items'])->where('id', $receipt->quotation_id)->first(); if ($quotation) { $payments = App\Models\QuotationPayment::where('quotation_id', $receipt->quotation_id)->get(); $i = 0; foreach ($payments as $key => $row) { $i++; if($row->id == $receipt->quotation_payments_id) { break; } } $count_payment = $i; $advancements = App\Models\QuotationPayment::where('quotation_id', $receipt->quotation_id)->sum('quotation_payments.payment'); } } // Obtener establishment_id directamente - buscar logo según sucursal $establishment_id = null; // Prioridad 1: Del receipt directamente if ($receipt && isset($receipt->establishment_id)) { $establishment_id = $receipt->establishment_id; } // Prioridad 2: Del usuario autenticado if (!$establishment_id && auth()->check()) { $user = auth()->user(); if ($user && isset($user->establishment_id)) { $establishment_id = $user->establishment_id; } } // Prioridad 3: Del establishment pasado if (!$establishment_id && $establishment) { if (is_object($establishment) && isset($establishment->id)) { $establishment_id = $establishment->id; } elseif (is_array($establishment) && isset($establishment['id'])) { $establishment_id = $establishment['id']; } } // Buscar logo específico del establecimiento $logo_full_path = null; if ($establishment_id) { // Buscar logosuc_{establishment_id}.jpg $logoSucPath = public_path("logos_de_sistema/logosuc_{$establishment_id}.jpg"); if (file_exists($logoSucPath) && is_readable($logoSucPath)) { $logo_full_path = $logoSucPath; } else { // Buscar avatar_logosuc_{establishment_id}.jpg $avatarLogoSucPathJpg = public_path("logos_de_sistema/avatar_logosuc_{$establishment_id}.jpg"); if (file_exists($avatarLogoSucPathJpg) && is_readable($avatarLogoSucPathJpg)) { $logo_full_path = $avatarLogoSucPathJpg; } else { // Buscar avatar_logosuc_{establishment_id}.png $avatarLogoSucPathPng = public_path("logos_de_sistema/avatar_logosuc_{$establishment_id}.png"); if (file_exists($avatarLogoSucPathPng) && is_readable($avatarLogoSucPathPng)) { $logo_full_path = $avatarLogoSucPathPng; } } } } // Fallback final: logo_sistema.jpg if (!$logo_full_path) { $logoSistemaPath = public_path("logos_de_sistema/logo_sistema.jpg"); if (file_exists($logoSistemaPath) && is_readable($logoSistemaPath)) { $logo_full_path = $logoSistemaPath; } } // Usar el número del recibo si está disponible, sino el pasado desde el controlador $receipt_number = $receipt->number ?? $number ?? 0; $tittle = 'ABONO-' . str_pad($receipt_number, 7, '0', STR_PAD_LEFT); $accounts = \App\Models\BankAccount::all(); $header_name = !empty($establishment->description ?? null) ? $establishment->description : 'SIN ESTABLECIMIENTO'; // Validar que existan los datos necesarios if (!$receipt) { die('Error: No se encontró el recibo'); } if (!$receipt->patient) { die('Error: No se encontró el paciente relacionado. Receipt ID: ' . ($receipt->id ?? 'N/A')); } $paperHeight = $paper_height ?? 900; @endphp
Fecha: |
{{ \Carbon\Carbon::parse($data->date)->format('d-m-Y') }} Hora: {{ strtoupper($data->hour) }} |
PACIENTE: |
{{ strtoupper($data->patient->name) }} |
N° EXPEDIENTE: |
@php $historyClinicalId = data_get($data, 'history_clinical_id') ?? data_get($data, 'history_id') ?? data_get($data, 'patient.history_clinical_id'); if (!$historyClinicalId && data_get($data, 'patient_id')) { $specialtyId = data_get($data, 'specialty_id') ?? data_get($quotation, 'specialty_id'); $historyQuery = \App\Models\History::where('patient_id', $data->patient_id); if ($specialtyId) { $historyQuery->where('specialty_id', $specialtyId); } $historyClinicalId = optional($historyQuery->first())->id; } @endphp {{ $historyClinicalId ?? '' }} |
Dirección: |
{{ $data->patient->address }} @if(isset($data->patient->district_id) && $data->patient->district_id !== '-' && $data->patient->district) , {{ $data->patient->district->description ?? '' }} @endif @if(isset($data->patient->province_id) && $data->patient->province_id !== '-' && $data->patient->province) , {{ $data->patient->province->description ?? '' }} @endif @if(isset($data->patient->department_id) && $data->patient->department_id !== '-' && $data->patient->department) - {{ $data->patient->department->description ?? '' }} @endif |
Teléfono: |
{{ $data->patient->telephone }} |
Cotización: |
{{ $quotation->identifier ?? $quotation->prefix.'-'.str_pad($quotation->id, 8, '0', STR_PAD_LEFT) }} |
Atendido por: |
{{ $data->user->name ?? '---' }} |
Detalle: |
{{ $data->detail }} |
| CANT. | DESCRIPCIÓN | P. UND | TOTAL |
|---|---|---|---|
| @if(((int)$row->quantity != $row->quantity)) {{ $row->quantity }} @else {{ number_format($row->quantity, 0) }} @endif |
@if(isset($row->item) && isset($row->item->description))
{!!$row->item->description!!}
@endif
@if(isset($row->item) && !empty($row->item->presentation) && isset($row->item->presentation->description))
{!!$row->item->presentation->description!!}
@endif
@if($row->attributes)
@foreach($row->attributes as $attr)
@if(isset($attr->description))
{!! $attr->description !!} : {{ $attr->value ?? '' }} @endif @endforeach @endif @if($row->discounts) @foreach($row->discounts as $dtos) @if(isset($dtos->description)) {{ $dtos->factor * 100 }}% {{$dtos->description }} @endif @endforeach @endif |
{{ number_format($row->unit_price, 2) }} | {{ number_format($row->total, 2) }} |
| Total Cotización: {{ $quotation->currency_type->symbol ?? '$' }} | {{ number_format($quotation->total - ($quotation->apply_discount ?? 0), 2) }} | ||
| Total Pagado: {{ $quotation->currency_type->symbol ?? '$' }} | {{ number_format($advancements - $data->amount, 2) }} | ||
| Abono Hoy: {{ $quotation->currency_type->symbol ?? '$' }} | {{ number_format($data->amount, 2) }} | ||
| Pendiente: {{ $quotation->currency_type->symbol ?? '$' }} | {{ number_format(($quotation->total - ($quotation->apply_discount ?? 0)) - $advancements, 2) }} | ||
|
@foreach($accounts as $account) {{$account->bank->description}} {{$account->currency_type->description}} N°: {{$account->number}} @if($account->cci) - CCI: {{$account->cci}} @endif @endforeach |