@php $establishment = $cash->user->establishment; $final_balance = 0; $cash_income = 0; // Calcular el total de egresos (gastos) $cashEgress = $cash->cash_documents->sum(function ($cashDocument) { return $cashDocument->expense_payment ? $cashDocument->expense_payment->payment : 0; }); $cash_final_balance = 0; $document_count = 0; $cash_taxes = 0; $cash_documents = $cash->cash_documents; // dd($cash_documents); $is_complete = $only_head === 'resumido' ? false : true; $first_document = ''; $last_document = ''; $list = $cash_documents->filter(function ($item) { return $item->document_pos_id !== null; }); if ($list->count() > 0) { $first_document = $list->first()->document_pos->series . '-' . $list->first()->document_pos->number; $last_document = $list->last()->document_pos->series . '-' . $list->last()->document_pos->number; } foreach ($methods_payment as $method) { $method->transaction_count = 0; // Se Incializa el contador de transacciones } foreach ($cash_documents as $cash_document) { if ($cash_document->document_pos) { $cash_income += $cash_document->document_pos->getTotalCash(); $final_balance += $cash_document->document_pos->getTotalCash(); $cash_taxes += $cash_document->document_pos->total_tax; $document_count = $cash_document->document_pos->count(); if (count($cash_document->document_pos->payments) > 0) { $pays = $cash_document->document_pos->state_type_id === '11' ? collect() : $cash_document->document_pos->payments; foreach ($methods_payment as $record) { $record->sum = $record->sum + $pays->where('payment_method_type_id', $record->id)->sum('payment'); } foreach ($cash_document->document_pos->payments as $payment) { $paymentMethod = $methods_payment->firstWhere('id', $payment->payment_method_type_id); if ($paymentMethod) { $paymentMethod->transaction_count++; // Se incrementa el contador de transacciones } } } } } $cash_final_balance = $final_balance + $cash->beginning_balance - $cashEgress; @endphp < Reporte POS - {{ $cash->user->name }} - {{ $cash->date_opening }} {{ $cash->time_opening }}

COMPROBANTE INFORME DIARIO

Empresa: {{ $company->name }}
N° Documento: {{ $company->number }}
Establecimiento: {{ $establishment->description }}
Fecha reporte: {{ date('Y-m-d') }}
Vendedor: {{ $cash->user->name }} Fecha y hora apertura: {{ $cash->date_opening }} {{ $cash->time_opening }} Estado de caja: {{ $cash->state ? 'Aperturada' : 'Cerrada' }} @if (!$cash->state)
Fecha y hora cierre: {{ $cash->date_closed }} {{ $cash->time_closed }} @endif

@php $is_complete = $only_head === 'resumido' ? false : true; @endphp Reporte POS - {{ $cash->user->name }} - {{ $cash->date_opening }} {{ $cash->time_opening }}
@php $tipoComprobante = 'Factura POS'; $numeroInicial = null; $numeroFinal = null; foreach ($cash_documents as $cash_document) { if ($cash_document->document_pos) { $numeroActual = $cash_document->document_pos->number_full; if (!$numeroInicial || $numeroActual < $numeroInicial) { $numeroInicial = $numeroActual; } if (!$numeroFinal || $numeroActual > $numeroFinal) { $numeroFinal = $numeroActual; } } } @endphp
Tipo de comprobante Comprobante Número inicial Número final
{{ $tipoComprobante }} {{ $numeroInicial }} {{ $numeroFinal }}
@if (!$cash->state) @endif
Empresa: {{ $company->name }} Fecha reporte: {{ date('Y-m-d') }}
Establecimiento: {{ $establishment->description }} Vendedor: {{ $cash->user->name }}
Fecha y hora apertura: {{ $cash->date_opening }} {{ $cash->time_opening }} Estado de caja: {{ $cash->state ? 'Aperturada' : 'Cerrada' }}
Fecha y hora cierre: {{ $cash->date_closed }} {{ $cash->time_closed }}
@if (!$is_complete)
Saldo inicial Ingreso Egreso Saldo final
${{ number_format($cash->beginning_balance, 2, '.', ',') }} ${{ number_format($cash_income, 2, '.', ',') }} ${{ number_format($cashEgress, 2, '.', ',') }} ${{ number_format($cash->beginning_balance + $cash_income - $cashEgress, 2, '.', ',') }}
@if ($cash_documents->count())

Totales por medio de pago

@php $totalSum = 0; @endphp @php $totalTransactions = 0; @endphp @foreach ($methods_payment as $item) @php $totalSum += $item->sum; $totalTransactions += $item->transaction_count; @endphp @endforeach
# Medio de Pago Número de Transacciones Valor Transacción
{{ $loop->iteration }} {{ $item->name }} {{ $item->transaction_count }} ${{ number_format($item->sum, 2, '.', ',') }}
Total: ${{ number_format($totalSum, 2, '.', ',') }}
@else

No se encontraron registros de documentos.

@endif @else
Saldo inicial Ingreso Egreso Saldo final
${{ number_format($cash->beginning_balance, 2, '.', ',') }} ${{ number_format($cash_income, 2, '.', ',') }} ${{ number_format($cashEgress, 2, '.', ',') }} ${{ number_format($cash->beginning_balance + $cash_income - $cashEgress, 2, '.', ',') }}
@if ($cash_documents->count())

Totales por medio de pago

@php $totalSum = 0; @endphp @php $totalTransactions = 0; @endphp @foreach ($methods_payment as $item) @php $totalSum += $item->sum; $totalTransactions += $item->transaction_count; @endphp @endforeach
# Medio de Pago Número de Transacciones Valor Transacción
{{ $loop->iteration }} {{ $item->name }} {{ $item->transaction_count }} ${{ number_format($item->sum, 2, '.', ',') }}
Total: ${{ number_format($totalSum, 2, '.', ',') }}
@else

No se encontraron registros de documentos.

@endif @php $all_documents = []; $totalsByCategory = []; $ivaTotalsByCategory = []; // Para almacenar los totales de IVA por categoría foreach ($cash_documents as $cash_document) { if ($cash_document->document_pos) { $all_documents[] = $cash_document; } } foreach ($all_documents as $document) { foreach ($document->document_pos->items as $item) { if ($item->refund == 0) { $categoryId = $item->item->category_id ?? 'Categoría no especificada'; if (!isset($totalsByCategory[$categoryId])) { $totalsByCategory[$categoryId] = [ 'subtotal' => 0, 'discount' => 0, 'otherTaxes' => 0, 'iva' => [], 'total' => 0, ]; } $itemIvaRate = $item->tax->name ?? ""; // "IVA19", "IVA5", etc. $itemIvaValue = $item->total_tax ?? 0; // Total de IVA para ese ítem if (!isset($totalsByCategory[$categoryId]['iva'][$itemIvaRate])) { $totalsByCategory[$categoryId]['iva'][$itemIvaRate] = 0; } // Acumular el IVA por tasa dentro de cada categoría $totalsByCategory[$categoryId]['iva'][$itemIvaRate] += $itemIvaValue; // Sumar los otros valores al total por categoría $totalsByCategory[$categoryId]['subtotal'] += $item->subtotal ?? 0; $totalsByCategory[$categoryId]['discount'] += $item->discount ?? 0; $totalsByCategory[$categoryId]['otherTaxes'] += $item->other_taxes ?? 0; $totalsByCategory[$categoryId]['total'] += $item->total ?? 0; } } } // Ahora, se calcula el total de IVA por categoría foreach ($totalsByCategory as $categoryId => &$categoryTotals) { $categoryTotals['totalIva'] = array_sum($categoryTotals['iva']); // Se Suma todos los valores de IVA } unset($categoryTotals); // Se Quita referencia @endphp

Relación de Gastos

@if ($expensePayments->isNotEmpty()) @foreach ($expensePayments as $index => $expensePayment) @endforeach
# Referencia Total
{{ $index + 1 }} {{ $expensePayment->reference ?? 'Sin referencia' }} {{ number_format($expensePayment->payment, 2) }}
@else

No se encontraron gastos.

@endif

Totales por Categorías

@php $grandTotalSubtotal = 0; $grandTotalDiscount = 0; $grandTotalOtherTaxes = 0; $grandTotalIva = 0; $grandTotal = 0; @endphp @foreach ($totalsByCategory as $categoryId => $totals) @php // Se Suma los totales de cada columna para el gran total $grandTotalSubtotal += $totals['subtotal'] - $totals['totalIva']; $grandTotalDiscount += $totals['discount']; $grandTotalIva += $totals['totalIva']; $grandTotal += $totals['total']; @endphp @php $categoryName = $categories[$categoryId] ?? 'Categoría no especificada'; @endphp @endforeach
Categoría/IVA Tarifa Base Gravable Descuento Valor IVA Valor neto
{{ $categoryName }} @foreach ($totals['iva'] as $ivaName => $ivaValue) @if ($ivaValue) {{ $ivaName }}
@endif @endforeach
{{ number_format($totals['subtotal'] - $totals['totalIva'], 2) }} {{ number_format($totals['discount'], 2) }} {{ number_format($totals['totalIva'], 2) }} {{ number_format($totals['total'], 2) }}
Totales: {{ number_format($grandTotalSubtotal, 2) }} {{ number_format($grandTotalDiscount, 2) }} {{ number_format($grandTotalIva, 2) }} {{ number_format($grandTotal, 2) }}
@php $all_documents = []; $totalsByCategory = []; $ivaTotalsByCategory = []; //Almacenar los totales de IVA por categoría foreach ($cash_documents as $cash_document) { if ($cash_document->document_pos) { $all_documents[] = $cash_document; } } foreach ($all_documents as $document) { foreach ($document->document_pos->items as $item) { // Filtrar solo los items que son reembolsos (refund == 1) if ($item->refund == 1) { $categoryId = $item->item->category_id ?? 'Categoría no especificada'; if (!isset($totalsByCategory[$categoryId])) { $totalsByCategory[$categoryId] = [ 'subtotal' => 0, 'discount' => 0, 'otherTaxes' => 0, 'iva' => [], 'total' => 0, ]; } $itemIvaRate = $item->tax->name ?? ""; // "IVA19", "IVA5", etc. $itemIvaValue = $item->total_tax ?? 0; // Total de IVA para ese ítem if (!isset($totalsByCategory[$categoryId]['iva'][$itemIvaRate])) { $totalsByCategory[$categoryId]['iva'][$itemIvaRate] = 0; } // Se Acumula el IVA por tasa dentro de cada categoría $totalsByCategory[$categoryId]['iva'][$itemIvaRate] += $itemIvaValue; // Se Suman los otros valores al total por categoría $totalsByCategory[$categoryId]['subtotal'] += $item->subtotal ?? 0; $totalsByCategory[$categoryId]['discount'] += $item->discount ?? 0; $totalsByCategory[$categoryId]['otherTaxes'] += $item->other_taxes ?? 0; $totalsByCategory[$categoryId]['total'] += $item->total ?? 0; } } } // Ahora, calcular el total de IVA por categoría foreach ($totalsByCategory as $categoryId => &$categoryTotals) { $categoryTotals['totalIva'] = array_sum($categoryTotals['iva']); // Sumar todos los valores de IVA } unset($categoryTotals); // Quitar referencia @endphp

Totales por Categorías devoluciones en ventas

@php $grandTotalSubtotal = 0; $grandTotalDiscount = 0; $grandTotalOtherTaxes = 0; $grandTotalIva = 0; $grandTotal = 0; @endphp @foreach ($totalsByCategory as $categoryId => $totals) @php $grandTotalSubtotal += $totals['subtotal'] - $totals['totalIva']; $grandTotalDiscount += $totals['discount']; $grandTotalIva += $totals['totalIva']; $grandTotal += $totals['total']; @endphp @php $categoryName = $categories[$categoryId] ?? 'Categoría no especificada'; @endphp @endforeach
Categoría/IVA Tarifa Base Gravable Descuento Valor IVA Valor neto
{{ $categoryName }} @foreach ($totals['iva'] as $ivaName => $ivaValue) @if ($ivaValue) {{ $ivaName }}
@endif @endforeach
{{ number_format($totals['subtotal'] - $totals['totalIva'], 2) }} {{ number_format($totals['discount'], 2) }} {{ number_format($totals['totalIva'], 2) }} {{ number_format($totals['total'], 2) }}
Totales: {{ number_format($grandTotalSubtotal, 2) }} {{ number_format($grandTotalDiscount, 2) }} {{ number_format($grandTotalIva, 2) }} {{ number_format($grandTotal, 2) }}
@php $all_documents = []; $totalsByIvaRate = []; $totalValorAntesIva = 0; $totalValorIva = 0; $totalGeneral = 0; foreach ($cash_documents as $cash_document) { if ($cash_document->document_pos) { foreach ($cash_document->document_pos->items as $item) { $ivaName = $item->tax->name ?? ""; $ivaRate = $item->tax->rate ?? 0; $ivaTotal = $item->total_tax ?? 0; $subtotal = $item->subtotal ?? 0; if (!isset($totalsByIvaRate[$ivaName])) { $totalsByIvaRate[$ivaName] = [ 'rate' => $ivaRate, 'base_gravable' => 0, 'valor_iva' => 0, 'total' => 0, ]; } $subtotalSinIva = $subtotal / (1 + $ivaRate / 100); $ivaCalculado = $subtotalSinIva * ($ivaRate / 100); // Acumular los subtotales y el IVA por cada tarifa $totalsByIvaRate[$ivaName]['base_gravable'] += $subtotalSinIva; $totalsByIvaRate[$ivaName]['valor_iva'] += $ivaCalculado; $totalsByIvaRate[$ivaName]['total'] += $subtotal; // Total ya incluye IVA // Acumular totales $totalValorAntesIva += $subtotalSinIva; $totalValorIva += $ivaCalculado; $totalGeneral += $subtotal; // Total ya incluye IVA } } } @endphp

Totales por tarifa de IVA

@foreach ($totalsByIvaRate as $ivaName => $totals) @endforeach
Tarifa Base Gravable Valor IVA Total Incluido IVA
{{ $ivaName }} ({{ $totals['rate'] }}%) {{ number_format($totals['base_gravable'], 2, '.', ',') }} {{ number_format($totals['valor_iva'], 2, '.', ',') }} {{ number_format($totals['total'], 2, '.', ',') }}
Total {{ number_format($totalValorAntesIva, 2, '.', ',') }} {{ number_format($totalValorIva, 2, '.', ',') }} {{ number_format($totalGeneral, 2, '.', ',') }}

Inventario de máquinas

@forelse($resolutions_maquinas as $resolution) @empty @endforelse
Tipo de caja Número de Caja o Serial
{{ $resolution->cash_type ?? 'N/A' }} {{ $resolution->plate_number ?? 'N/A' }}
No se encontraron máquinas.
@endif