@extends('layouts.app')

@section('title', __('manufacturing::lang.transfer_note_details'))

@section('content')

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>@lang('manufacturing::lang.transfer_note_details')</h1>
</section>

<!-- Main content -->
<section class="content">
    @component('components.widget', ['class' => 'box-primary'])
        <div class="row">
            <div class="col-md-6">
                <table class="table table-bordered">
                    <tr>
                        <th>@lang('manufacturing::lang.tn_number')</th>
                        <td>{{ $transfer_note->formatted_tn_number }}</td>
                    </tr>
                    <tr>
                        <th>@lang('manufacturing::lang.transfer_date')</th>
                        <td>{{ $transfer_note->transfer_date->format('Y-m-d') }}</td>
                    </tr>
                    <tr>
                        <th>@lang('manufacturing::lang.from_location')</th>
                        <td>{{ $transfer_note->fromLocation ? $transfer_note->fromLocation->name : '-' }}</td>
                    </tr>
                    <tr>
                        <th>@lang('manufacturing::lang.to_location')</th>
                        <td>{{ $transfer_note->toLocation ? $transfer_note->toLocation->name : '-' }}</td>
                    </tr>
                    <tr>
                        <th>@lang('manufacturing::lang.status')</th>
                        <td>{!! $transfer_note->status_badge !!}</td>
                    </tr>
                    <tr>
                        <th>@lang('manufacturing::lang.created_by')</th>
                        <td>{{ $transfer_note->creator ? $transfer_note->creator->first_name . ' ' . $transfer_note->creator->last_name : '-' }}</td>
                    </tr>
                    @if($transfer_note->notes)
                    <tr>
                        <th>@lang('manufacturing::lang.notes')</th>
                        <td>{{ $transfer_note->notes }}</td>
                    </tr>
                    @endif
                </table>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <h4>@lang('manufacturing::lang.products')</h4>
                <div class="table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>@lang('manufacturing::lang.product')</th>
                                <th>@lang('manufacturing::lang.quantity')</th>
                                <th>@lang('manufacturing::lang.unit')</th>
                                <th>@lang('manufacturing::lang.unit_price')</th>
                                <th>@lang('manufacturing::lang.total_price')</th>
                                @if($transfer_note->transferNoteLines->where('notes', '!=', null)->count() > 0)
                                <th>@lang('manufacturing::lang.notes')</th>
                                @endif
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($transfer_note->transferNoteLines as $line)
                            <tr>
                                <td>{{ $line->product->name }} @if($line->variation->name != 'Default') ({{ $line->variation->name }}) @endif</td>
                                <td>{{ number_format($line->quantity, 2) }}</td>
                                <td>{{ $line->unit ?? '-' }}</td>
                                <td>{{ number_format($line->unit_price, 2) }}</td>
                                <td>{{ number_format($line->total_price, 2) }}</td>
                                @if($transfer_note->transferNoteLines->where('notes', '!=', null)->count() > 0)
                                <td>{{ $line->notes ?? '-' }}</td>
                                @endif
                            </tr>
                            @endforeach
                        </tbody>
                        <tfoot>
                            <tr>
                                <th colspan="4">@lang('manufacturing::lang.total')</th>
                                <th>{{ number_format($transfer_note->transferNoteLines->sum('total_price'), 2) }}</th>
                                @if($transfer_note->transferNoteLines->where('notes', '!=', null)->count() > 0)
                                <th></th>
                                @endif
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <a href="{{action([\Modules\Manufacturing\Http\Controllers\TransferNoteController::class, 'index'])}}" class="btn btn-default">
                    <i class="fa fa-arrow-left"></i> @lang('manufacturing::lang.back')
                </a>
                {{-- EDIT BUTTON REMOVED - Transfer notes cannot be edited once created --}}
            </div>
        </div>
    @endcomponent
</section>
<!-- /.content -->

@endsection
