{{-- New-Unity ERP | purchases/costs/edit.blade.php | v2.1 | 26/07/2026 --}} {{-- v2.1 β€” Tabla comparativa y header del form muestran razΓ³n social (name) del proveedor. --}} {{-- v2.0 β€” FG redirige desde controller. 4 secciones: producto (product_number), tabla comparativa --}} {{-- de todos los proveedores (πŸ₯‡ mejor precio, ✏️ editando, ⚠️ expirado), form, historial. --}} {{-- v1.0 β€” Vista inicial de ediciΓ³n de costo. --}} @extends('layouts.vertical') @section('content')
{{-- Page Header --}}

{{ __('purchases.edit-product-cost') }}

{{ __('purchases.back') }}
@if(session('success'))
{{ session('success') }}
@endif @if(session('warning'))
{{ session('warning') }}
@endif @if($errors->any())
@endif {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- SECCIΓ“N 1 β€” Producto --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}}
{{ __('purchases.product') }}
{{ __('purchases.product-name-lbl') }} {{ $product->product_name }}
{{ __('purchases.col-sku') }} {{ $product->sku ?? 'β€”' }}
{{ __('purchases.ean-barcode') }} {{ $product->barcode ?? 'β€”' }}
{{ __('purchases.type') }} {{ $product->material_type ?? 'β€”' }}
{{ __('purchases.avg-cost') }} ${{ number_format($cost->avg_cost, 4) }}
{{ __('purchases.last-purchase') }} {{ $cost->last_purchase_cost > 0 ? '$'.number_format($cost->last_purchase_cost, 4) : 'β€”' }}
{{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- SECCIΓ“N 2 β€” Todos los proveedores de este producto --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @php $allCosts = collect([$cost])->merge($otherCosts)->sort(function ($a, $b) { if ($a->isActive() !== $b->isActive()) { return $b->isActive() ? 1 : -1; // activos primero } return $a->cost <=> $b->cost; // costo ASC dentro del grupo })->values(); $bestActiveId = $allCosts->filter(fn($c) => $c->isActive())->first()?->id; @endphp
{{ __('purchases.suppliers-comparison') }} {{ $allCosts->count() }}
@can('costs.create') {{ __('purchases.new-cost') }} @endcan
@foreach($allCosts as $c) @php $isEditing = ($c->id === $cost->id); @endphp @endforeach
{{ __('purchases.supplier') }} {{ __('purchases.col-list-cost') }} {{ __('purchases.col-curr') }} {{ __('purchases.col-iva') }} {{ __('purchases.col-total-cost') }} {{ __('purchases.valid-until') }} {{ __('purchases.col-status') }} {{ __('purchases.actions') }}
{{ $c->supplier?->name ?? $c->supplier?->commercial_name ?? __('purchases.generic-all-suppliers') }} @if($bestActiveId && $c->id === $bestActiveId) 🥇 {{ __('purchases.best-price') }} @endif ${{ number_format($c->cost, 2) }} {{ $c->currency }} {{ number_format($c->iva_perc, 0) }}% ${{ number_format($c->total_cost, 2) }} {{ $c->valid_to?->format('d/m/Y') ?? 'β€”' }} @if($c->isActive()) {{ __('purchases.js-current') }} @else ⚠ {{ __('purchases.js-expired') }} @endif @if($isEditing) ✏ {{ __('purchases.currently-editing') }} @else @can('costs.edit') {{ __('purchases.edit') }} @endcan @endif
{{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- SECCIΓ“N 3 + SECCIΓ“N 4 β€” Formulario de ediciΓ³n + Historial --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}}
@csrf @method('PUT') {{-- Cost & Taxes --}}
{{ __('purchases.cost-taxes') }} β€” {{ $cost->supplier?->name ?? $cost->supplier?->commercial_name ?? __('purchases.generic-all-suppliers') }}
$
%
%
{{-- Totales calculados --}}
{{ __('purchases.iva-amount') }} $0.00
{{ __('purchases.ieps-amount') }} $0.00
{{ __('purchases.col-total-cost') }} $0.00
{{ __('purchases.vs-previous') }} β€”
{{-- Motivo (aparece si el precio sube) --}}
{{ __('purchases.price-increase-detected') }} {{ __('purchases.reason-required') }}
@error('change_reason')
{{ $message }}
@enderror
@if($errors->has('change_reason'))
{{ __('purchases.price-increase-detected') }} {{ __('purchases.reason-required') }}
{{ $errors->first('change_reason') }}
@endif
{{-- Validity & Notes --}}
{{ __('purchases.cancel') }}
{{-- SECCIΓ“N 4 β€” Historial de precios --}}
{{ __('purchases.price-history') }}
@forelse($cost->history as $h)
{{ $h->directionLabel() }}
${{ number_format($h->cost_previous, 4) }} ${{ number_format($h->cost_new, 4) }} {{ $h->currency }}
{{ $h->costTypeLabel() }} Β· {{ $h->sourceLabel() }}
@if($h->change_reason)
{{ $h->change_reason }}
@endif
{{ $h->user?->name ?? __('purchases.system') }} β€” {{ $h->created_at->format('d-m-Y H:i') }}
@empty

{{ __('purchases.no-price-history') }}

@endforelse
@endsection @section('scripts') @parent @endsection