<?php $__env->startSection('title', $transfer->transfer_number); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">

    <div class="page-title-head d-flex align-items-center">
        <div class="flex-grow-1">
            <h4 class="page-main-title m-0">
                Transfer <?php echo e($transfer->transfer_number); ?>

                <span class="badge <?php echo e($transfer->statusBadgeClass()); ?> ms-2"><?php echo e($transfer->statusLabel()); ?></span>
            </h4>
        </div>
        <div class="text-end">
            <ol class="breadcrumb m-0 py-0">
                <li class="breadcrumb-item"><a href="<?php echo e(url('/')); ?>">Dashboard</a></li>
                <li class="breadcrumb-item"><a href="<?php echo e(route('stock-transfers.index')); ?>">Transfers</a></li>
                <li class="breadcrumb-item active"><?php echo e($transfer->transfer_number); ?></li>
            </ol>
        </div>
    </div>

    
    <div class="card">
        <div class="card-body d-flex flex-wrap gap-2">
            <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'stock-transfers.edit')): ?>
                <?php if($transfer->isEditable()): ?>
                    <a href="<?php echo e(route('stock-transfers.edit', $transfer)); ?>" class="btn btn-primary">
                        <i class="ti ti-edit me-1"></i> Edit
                    </a>
                <?php endif; ?>
            <?php endif; ?>

            <?php if (\Illuminate\Support\Facades\Blade::check('permission', 'stock-transfers.post')): ?>
                <?php if($transfer->isDraft()): ?>
                    <button class="btn btn-info js-status-action"
                        data-url="<?php echo e(route('stock-transfers.post', $transfer)); ?>"
                        data-confirm="Post this transfer? Stock will leave the source location.">
                        <i class="ti ti-send me-1"></i> Post
                    </button>
                <?php endif; ?>
                <?php if($transfer->isInTransit()): ?>
                    <button class="btn btn-success js-status-action"
                        data-url="<?php echo e(route('stock-transfers.receive', $transfer)); ?>"
                        data-confirm="Mark this transfer as received? Stock will arrive at the destination.">
                        <i class="ti ti-check me-1"></i> Receive
                    </button>
                <?php endif; ?>
                <?php if($transfer->isDraft() || $transfer->isInTransit()): ?>
                    <button class="btn btn-soft-danger js-status-action"
                        data-url="<?php echo e(route('stock-transfers.cancel', $transfer)); ?>"
                        data-confirm="Cancel this transfer? In-transit stock will return to the source.">
                        <i class="ti ti-ban me-1"></i> Cancel
                    </button>
                <?php endif; ?>
            <?php endif; ?>

            <button class="btn btn-light ms-auto" onclick="window.print()">
                <i class="ti ti-printer me-1"></i> Print
            </button>
        </div>
    </div>

    <div class="row">
        
        <div class="col-lg-8">
            <div class="card">
                <div class="card-body">
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <h6 class="text-muted text-uppercase small">From</h6>
                            <?php if($transfer->fromLocation): ?>
                                <div class="fw-semibold"><?php echo e($transfer->fromLocation->name); ?></div>
                                <small class="text-muted"><?php echo e($transfer->fromLocation->location_code); ?></small>
                            <?php endif; ?>
                        </div>
                        <div class="col-md-6">
                            <h6 class="text-muted text-uppercase small">To</h6>
                            <?php if($transfer->toLocation): ?>
                                <div class="fw-semibold"><?php echo e($transfer->toLocation->name); ?></div>
                                <small class="text-muted"><?php echo e($transfer->toLocation->location_code); ?></small>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="table-responsive">
                        <table class="table table-custom align-middle mb-0">
                            <thead class="bg-light bg-opacity-25 thead-sm">
                                <tr class="text-uppercase fs-xxs">
                                    <th>#</th>
                                    <th>Product</th>
                                    <th>Barcode</th>
                                    <th class="text-end">Qty</th>
                                    <th>Notes</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $transfer->lines; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $line): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e($loop->iteration); ?></td>
                                        <td>
                                            <div class="fw-semibold"><?php echo e($line->product?->title); ?></div>
                                            <small class="text-muted">SKU: <?php echo e($line->product?->sku); ?></small>
                                        </td>
                                        <td>
                                            <code class="small">
                                                <a href="<?php echo e(route('stock.piece', $line->purchase_product_id)); ?>">
                                                    <?php echo e(optional($line->purchaseProduct)->barcode ?? optional($line->purchaseProduct)->lot_code ?? '#' . $line->purchase_product_id); ?>

                                                </a>
                                            </code>
                                        </td>
                                        <td class="text-end fw-semibold"><?php echo e((int) $line->qty); ?></td>
                                        <td><small><?php echo e($line->notes); ?></small></td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr><td colspan="5" class="text-center text-muted py-4">No lines.</td></tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <?php if($transfer->note): ?>
                <div class="card">
                    <div class="card-header border-light"><h5 class="card-title mb-0">Note</h5></div>
                    <div class="card-body">
                        <p class="mb-0" style="white-space: pre-wrap;"><?php echo e($transfer->note); ?></p>
                    </div>
                </div>
            <?php endif; ?>
        </div>

        
        <div class="col-lg-4">
            <div class="card">
                <div class="card-header border-light"><h5 class="card-title mb-0">Timeline</h5></div>
                <div class="card-body">
                    <dl class="row mb-0 small">
                        <dt class="col-5 text-muted">Transfer Date</dt>
                        <dd class="col-7"><?php echo e(optional($transfer->transfer_date)->format('d M Y')); ?></dd>

                        <dt class="col-5 text-muted">Created</dt>
                        <dd class="col-7"><?php echo e(optional($transfer->created_at)->format('d M Y, h:i A')); ?></dd>

                        <?php if($transfer->posted_at): ?>
                            <dt class="col-5 text-muted">Posted</dt>
                            <dd class="col-7"><?php echo e($transfer->posted_at->format('d M Y, h:i A')); ?></dd>
                        <?php endif; ?>

                        <?php if($transfer->received_at): ?>
                            <dt class="col-5 text-muted">Received</dt>
                            <dd class="col-7"><?php echo e($transfer->received_at->format('d M Y, h:i A')); ?></dd>
                        <?php endif; ?>

                        <?php if($transfer->cancelled_at): ?>
                            <dt class="col-5 text-muted">Cancelled</dt>
                            <dd class="col-7"><?php echo e($transfer->cancelled_at->format('d M Y, h:i A')); ?></dd>
                        <?php endif; ?>
                    </dl>
                </div>
            </div>

            <div class="card">
                <div class="card-header border-light"><h5 class="card-title mb-0">Summary</h5></div>
                <div class="card-body">
                    <dl class="row mb-0 small">
                        <dt class="col-7 text-muted">Lines</dt>
                        <dd class="col-5 text-end"><?php echo e($transfer->lines->count()); ?></dd>
                        <dt class="col-7 text-muted">Total pieces</dt>
                        <dd class="col-5 text-end"><?php echo e((int) $transfer->lines->sum('qty')); ?></dd>
                    </dl>
                </div>
            </div>

            <div class="card">
                <div class="card-header border-light"><h5 class="card-title mb-0">Audit</h5></div>
                <div class="card-body">
                    <dl class="row mb-0 small">
                        <?php if($transfer->creator): ?>
                            <dt class="col-5 text-muted">Created by</dt>
                            <dd class="col-7"><?php echo e($transfer->creator->name); ?></dd>
                        <?php endif; ?>
                        <?php if($transfer->updater): ?>
                            <dt class="col-5 text-muted">Last update by</dt>
                            <dd class="col-7"><?php echo e($transfer->updater->name); ?></dd>
                        <?php endif; ?>
                    </dl>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(function () {
    const csrfToken = $('meta[name="csrf-token"]').attr('content');
    $('.js-status-action').on('click', function () {
        const url     = $(this).data('url');
        const confirm = $(this).data('confirm');
        if (confirm && !window.confirm(confirm)) return;
        $.ajax({
            url, type: 'POST',
            headers: { 'X-CSRF-TOKEN': csrfToken, 'Accept': 'application/json' },
            success: function (res) {
                if (res.ok) window.location.reload();
                else alert(res.message || 'Action failed.');
            },
            error: function (xhr) {
                alert((xhr.responseJSON && xhr.responseJSON.message) || 'Action failed.');
            },
        });
    });
});
</script>
<style>
    @media print {
        .breadcrumb, .page-title-head .text-end,
        .js-status-action, .btn { display: none !important; }
    }
</style>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layout.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH F:\VScode LIve ftp\paces\resources\views/stock-transfers/show.blade.php ENDPATH**/ ?>