@php $establishment = $document->establishment; $customer = $document->customer; $left = ($document->series) ? $document->series : $document->prefix; $tittle = $left.'-'.str_pad($document->number, 8, '0', STR_PAD_LEFT); // N° Expediente (Historia clínica), no N° documento $number_history = null; try { $patient_id = $document->customer_id ?? ($customer && isset($customer->id) ? $customer->id : null); $specialty_id = $document->specialty_id ?? null; $est_id = $document->establishment_id ?? ($establishment && isset($establishment->id) ? $establishment->id : null); if ($patient_id) { $q = \App\Models\History::where('patient_id', $patient_id)->whereNotNull('number_history'); if ($specialty_id) $q->where('specialty_id', $specialty_id); if ($est_id) $q->where('establishment_id', $est_id); $history = $q->latest('id')->first(); if ($history && $history->number_history) $number_history = $history->number_history; } } catch (\Throwable $e) { $number_history = null; } $anulado_path = public_path('status_images'.DIRECTORY_SEPARATOR.'anulado.png'); $anulado_base64 = null; if (file_exists($anulado_path) && is_readable($anulado_path) && @filesize($anulado_path) > 0) { $raw = @file_get_contents($anulado_path); if ($raw !== false && $raw !== '') { $anulado_base64 = base64_encode($raw); } } $logo_a5_base64 = null; $logo_a5_mime = 'image/jpeg'; if (isset($logo) && is_array($logo) && !empty($logo['full_path']) && file_exists($logo['full_path']) && is_readable($logo['full_path']) && @filesize($logo['full_path']) > 0) { $raw = @file_get_contents($logo['full_path']); if ($raw !== false && $raw !== '') { $logo_a5_base64 = base64_encode($raw); if (strtolower(pathinfo($logo['full_path'], PATHINFO_EXTENSION)) === 'png') { $logo_a5_mime = 'image/png'; } } } if (!$logo_a5_base64) { $eid = isset($document->establishment_id) ? $document->establishment_id : (isset($establishment->id) ? $establishment->id : null); $candidates = $eid ? [ public_path("logos_de_sistema/logosuc_{$eid}.jpg"), public_path("logos_de_sistema/avatar_logosuc_{$eid}.jpg"), public_path("logos_de_sistema/avatar_logosuc_{$eid}.png"), ] : []; $candidates[] = public_path('logos_de_sistema/logo_sistema.jpg'); foreach ($candidates as $path) { if (is_string($path) && $path !== '' && file_exists($path) && is_readable($path) && @filesize($path) > 0) { $raw = @file_get_contents($path); if ($raw !== false && $raw !== '') { $logo_a5_base64 = base64_encode($raw); $logo_a5_mime = (strtolower(pathinfo($path, PATHINFO_EXTENSION)) === 'png') ? 'image/png' : 'image/jpeg'; break; } } } } @endphp {{--{{ $tittle }}--}} {{----}} @if(isset($document->state_type->id) && $document->state_type->id == '11' && $anulado_base64)
anulado
@endif
FACTURA

{{ $tittle }}

@if($logo_a5_base64) @else @endif

{{ $company->name }}

@isset($establishment->trade_address)
{{ ($establishment->trade_address !== '-')? ' DIRECCION: '.$establishment->trade_address : '' }} {{ ($establishment->district_id !== '-')? ', '.$establishment->district->description : '' }} {{ ($establishment->province_id !== '-')? ', '.$establishment->province->description : '' }} {{ ($establishment->department_id !== '-')? '- '.$establishment->department->description : '' }}
@endisset
{{ ($establishment->telephone !== '-')? 'TELEFONO.: '.$establishment->telephone : '' }}
{{ ($establishment->email !== '-')? 'Email: '.$establishment->email : '' }}
@if ($customer->address !== '') @endif
CLIENTE : {{ $customer->name }}
FECHA EMISIÓN : {{ $document->date_of_issue->format('d-m-Y')}} TELEFONO : {{ $customer->telephone }}
N° Expediente : {{ $number_history ? str_pad($number_history, 7, "0", STR_PAD_LEFT) : '' }}
DIRECCION: : {{ $customer->address }} {{ ($customer->district_id !== '-')? ', '.$customer->district->description : '' }} {{-- {{ ($customer->province_id !== '-')? ', '.$customer->province->description : '' }} --}} {{ ($customer->department_id !== '-')? '- '.$customer->department->description : '' }}
@if ($document->guides)
{{--Guías:--}} @foreach($document->guides as $guide) @if(isset($guide->document_type_description)) @else @endif @endforeach
{{ $guide->document_type_description }}{{ $guide->document_type_id }}: {{ $guide->number }}
@endif @foreach($document->items as $row) @endforeach @if($document->total_discount > 0) @endif
CANTIDAD DESCRIPCIÓN P. UND DTO. TOTAL
@if(((int)$row->quantity != $row->quantity)) {{ $row->quantity }} @else {{ number_format($row->quantity, 0) }} @endif {!!$row->item->description!!} @if (!empty($row->item->presentation)) {!!$row->item->presentation->description!!} @endif @if($row->attributes) @foreach($row->attributes as $attr)
{!! $attr->description !!} : {{ $attr->value }} @endforeach @endif @if($row->discounts) @foreach($row->discounts as $dtos)
{{ $dtos->factor * 100 }}% {{$dtos->description }} @endforeach @endif
{{ number_format($row->unit_price, 2) }} @if($row->discounts) @php $total_discount_line = 0; foreach ($row->discounts as $disto) { $total_discount_line = $total_discount_line + $disto->amount; } @endphp {{ number_format($total_discount_line, 2) }} @else 0 @endif {{ number_format($row->total, 2) }}
{{(($document->total_prepayment > 0) ? 'ANTICIPO':'DESCUENTO TOTAL')}}: {{ $document->currency_type->symbol }} {{ number_format($document->total_discount, 2) }}
TOTAL A PAGAR: {{ $document->currency_type->symbol }} {{ number_format($document->total, 2) }}