@php $establishment = $document->establishment; $customer = $document->customer; if (!$customer && method_exists($document, 'relationLoaded') && $document->relationLoaded('patient')) { $customer = $document->getRelation('patient'); } $left = ($document->series) ? $document->series : $document->prefix; $tittle = $left.'-'.str_pad($document->number ?? 0, 8, '0', STR_PAD_LEFT); $payments = collect(); if (method_exists($document, 'payments')) { try { if (\Illuminate\Support\Facades\Schema::hasTable('sale_note_payments')) { $payments = $document->relationLoaded('payments') ? $document->getRelation('payments') : $document->payments()->get(); } } catch (\Throwable $e) { $payments = collect(); } } $currencySymbol = optional($document->currency_type)->symbol ?? ''; $balance = (float) (Session::get('difference') ?? 0); // 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; } $logo_t80_base64 = null; $logo_t80_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_t80_base64 = base64_encode($raw); if (strtolower(pathinfo($logo['full_path'], PATHINFO_EXTENSION)) === 'png') { $logo_t80_mime = 'image/png'; } } } if (!$logo_t80_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_t80_base64 = base64_encode($raw); $logo_t80_mime = (strtolower(pathinfo($path, PATHINFO_EXTENSION)) === 'png') ? 'image/png' : 'image/jpeg'; break; } } } } @endphp
{{--