

<?php $__env->startSection('title', 'Purchase Order Details'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Purchase Order: <?php echo e($purchaseOrder->po_number); ?></h3>
                    <div class="card-tools">
                        <?php if($purchaseOrder->status === \App\Models\PurchaseOrder::STATUS_DRAFT): ?>
                            <a href="<?php echo e(route('purchase-orders.edit', $purchaseOrder)); ?>" class="btn btn-warning btn-sm">
                                <i class="fas fa-edit"></i> Edit
                            </a>
                        <?php endif; ?>
                        <a href="<?php echo e(route('purchase-orders.index')); ?>" class="btn btn-secondary btn-sm">
                            <i class="fas fa-arrow-left"></i> Back to Purchase Orders
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <h5>Purchase Order Information</h5>
                            <table class="table table-sm">
                                <tr>
                                    <td><strong>PO Number:</strong></td>
                                    <td><?php echo e($purchaseOrder->po_number); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Status:</strong></td>
                                    <td><?php echo $purchaseOrder->status_badge; ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Payment Status:</strong></td>
                                    <td><?php echo $purchaseOrder->payment_status_badge; ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Vendor:</strong></td>
                                    <td><?php echo e($purchaseOrder->supplier ? $purchaseOrder->supplier->name : 'N/A'); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Purchase Request:</strong></td>
                                    <td>
                                        <?php if($purchaseOrder->purchaseRequest): ?>
                                            <a href="<?php echo e(route('purchase-requests.show', $purchaseOrder->purchaseRequest)); ?>">
                                                <?php echo e($purchaseOrder->purchaseRequest->pr_number); ?>

                                            </a>
                                        <?php else: ?>
                                            N/A
                                        <?php endif; ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td><strong>Expected Date:</strong></td>
                                    <td><?php echo e($purchaseOrder->expected_date ? $purchaseOrder->expected_date->format('M d, Y') : 'N/A'); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Total Amount:</strong></td>
                                    <td><?php echo e(format_currency($purchaseOrder->total_amount)); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Created At:</strong></td>
                                    <td><?php echo e($purchaseOrder->created_at->format('M d, Y H:i')); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Remarks:</strong></td>
                                    <td><?php echo e($purchaseOrder->remarks ?: 'N/A'); ?></td>
                                </tr>
                            </table>
                        </div>

                        <div class="col-md-6">
                            <h5>Progress & Statistics</h5>
                            <table class="table table-sm">
                                <tr>
                                    <td><strong>Total Ordered Qty:</strong></td>
                                    <td><?php echo e(number_format($purchaseOrder->total_ordered_qty, 2)); ?></td>
                                </tr>
                                <!-- <tr>
                                    <td><strong>Total Received Qty:</strong></td>
                                    <td><?php echo e(number_format($purchaseOrder->total_received_qty, 2)); ?></td>
                                </tr> -->
                                
                                
                                <tr>
                                    <td><strong>Gate Passes Count:</strong></td>
                                    <td><?php echo e($purchaseOrder->gatePasses->count()); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Payments Count:</strong></td>
                                    <td><?php echo e($purchaseOrder->all_payment_transactions->count() > 0 ? $purchaseOrder->all_payment_transactions->where('transaction_type', 'debit')->count() : 0); ?></td>
                                </tr>
                                <tr>
                                    <td><strong>Total Paid amount:</strong></td>
                                    <td><?php echo e(format_currency($purchaseOrder->all_payment_transactions->where('transaction_type', 'debit')->sum('amount'))); ?></td>
                                </tr>
                                
                            </table>
                        </div>
                    </div>

                    <!-- Purchase Order Items -->
                    <div class="row mt-4">
                        <div class="col-12">
                            <h5>Purchase Order Items</h5>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>Item</th>
                                            <th>Quantity</th>
                                            <th>Unit</th>
                                            <th>Rate</th>
                                            <th>Amount</th>
                                            <th>Received Qty</th>
                                            <th>Pending Qty</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__empty_1 = true; $__currentLoopData = $purchaseOrder->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <tr>
                                            <td><?php echo e($item->item ? $item->item->name : 'N/A'); ?></td>
                                            <td><?php echo e(number_format($item->quantity, 2)); ?></td>
                                            <td><?php echo e($item->item && $item->item->uom ? $item->item->uom->name : 'N/A'); ?></td>
                                            <td><?php echo e(format_currency($item->unit_price)); ?></td>
                                            <td><?php echo e(format_currency($item->total_price)); ?></td>
                                            <td><?php echo e(number_format($item->received_qty ?? 0, 2)); ?></td>
                                            <td><?php echo e(number_format(($item->quantity - ($item->received_qty ?? 0)), 2)); ?></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        <tr>
                                            <td colspan="7" class="text-center">No items found</td>
                                        </tr>
                                        <?php endif; ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>

                    <!-- Related GRNs -->
                    

                    <!-- Related Gate Passes -->
                    <?php if($purchaseOrder->gatePasses->count() > 0): ?>
                    <div class="row mt-4">
                        <div class="col-12">
                            <h5>Gate Passes </h5>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>GP Number</th>
                                            <th>Status</th>
                                            <th>Vehicle No</th>
                                            <th>Created At</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $purchaseOrder->gatePasses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $gatePass): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            
                                            <td><?php echo e($gatePass->gate_pass_number); ?></td>
                                            <td><?php echo $gatePass->status; ?></td>
                                            <td><?php echo e($gatePass->vehicle_no ?: 'N/A'); ?></td>
                                            <td><?php echo e($gatePass->created_at->format('M d, Y H:i')); ?></td>
                                            <td>
                                                <a href="<?php echo e(route('gatepasses.show', $gatePass)); ?>" class="btn btn-sm btn-info">
                                                    <i class="fas fa-eye"></i> View
                                                </a>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>

                    <!-- Related Payments -->
                    <?php if($purchaseOrder->all_payment_transactions->count() > 0): ?>
                    <div class="row mt-4">
                        <div class="col-12">
                            <h5>Payments</h5>
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                        <tr>
                                            <th>Transaction Number</th>
                                            <th>Type</th>
                                            <th>Amount</th>
                                            <th>Created At</th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $purchaseOrder->all_payment_transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            
                                            <td><?php echo e($payment->transaction_number); ?></td>

                                            <td>
                                                <span class="badge <?php echo e($payment->transaction_type == 'debit' ? 'bg-success' : 'bg-danger'); ?>"><?php echo e(ucfirst($payment->transaction_type)); ?></span>
                                            </td>
                                            <td><?php echo e(format_currency($payment->amount)); ?></td>
                                            <td><?php echo e($payment->created_at->format('M d, Y H:i')); ?></td>
                                            
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\purchase_orders\show.blade.php ENDPATH**/ ?>