{% extends 'base.html' %}

{% block title %}Purchase Order - {{ purchase_order.order_number }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3 mb-0">
        <i class="bi bi-cart-plus me-2"></i>
        Purchase Order
    </h1>
    <div>
        <a href="{% url 'purchase:purchase_list' %}" class="btn btn-outline-secondary me-2">
            <i class="bi bi-arrow-left me-2"></i>
            Back to List
        </a>
        <a href="#" class="btn btn-primary">
            <i class="bi bi-pencil me-2"></i>
            Edit
        </a>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">Order Details</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <p><strong>Order Number:</strong> {{ purchase_order.order_number }}</p>
                        <p><strong>Date:</strong> {{ purchase_order.date|date:"d/m/Y" }}</p>
                        <p><strong>Status:</strong> 
                            <span class="badge bg-{% if purchase_order.status == 'received' %}success{% elif purchase_order.status == 'confirmed' %}info{% elif purchase_order.status == 'sent' %}warning{% else %}secondary{% endif %}">
                                {{ purchase_order.get_status_display }}
                            </span>
                        </p>
                    </div>
                    <div class="col-md-6">
                        <p><strong>Supplier:</strong> {{ purchase_order.supplier.name }}</p>
                        <p><strong>Expected Delivery:</strong> {{ purchase_order.expected_delivery_date|date:"d/m/Y"|default:"Not set" }}</p>
                        <p><strong>Created By:</strong> {{ purchase_order.created_by.get_full_name|default:"N/A" }}</p>
                    </div>
                </div>
                
                {% if purchase_order.notes %}
                <div class="mt-3">
                    <strong>Notes:</strong>
                    <p class="mt-2">{{ purchase_order.notes }}</p>
                </div>
                {% endif %}
            </div>
        </div>
        
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Financial Information</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3">
                        <div class="text-center">
                            <h6 class="text-muted">Subtotal</h6>
                            <h4 class="text-primary">Rp {{ purchase_order.subtotal|floatformat:0 }}</h4>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="text-center">
                            <h6 class="text-muted">Tax</h6>
                            <h4 class="text-warning">Rp {{ purchase_order.tax_amount|floatformat:0 }}</h4>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="text-center">
                            <h6 class="text-muted">Shipping</h6>
                            <h4 class="text-info">Rp {{ purchase_order.shipping_cost|floatformat:0 }}</h4>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="text-center">
                            <h6 class="text-muted">Total</h6>
                            <h4 class="text-success">Rp {{ purchase_order.total_amount|floatformat:0 }}</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">Supplier Information</h5>
            </div>
            <div class="card-body">
                <p><strong>Supplier Code:</strong> {{ purchase_order.supplier.code }}</p>
                <p><strong>Contact:</strong> {{ purchase_order.supplier.contact_person|default:"N/A" }}</p>
                <p><strong>Email:</strong> {{ purchase_order.supplier.email|default:"N/A" }}</p>
                <p><strong>Phone:</strong> {{ purchase_order.supplier.phone|default:"N/A" }}</p>
                <p><strong>Rating:</strong> 
                    <span class="badge bg-{% if purchase_order.supplier.rating >= 4 %}success{% elif purchase_order.supplier.rating >= 3 %}warning{% else %}danger{% endif %}">
                        {{ purchase_order.supplier.rating }}/5
                    </span>
                </p>
                <p><strong>Credit Limit:</strong> Rp {{ purchase_order.supplier.credit_limit|floatformat:0 }}</p>
            </div>
        </div>
        
        <div class="card mt-3">
            <div class="card-header">
                <h5 class="card-title mb-0">Timestamps</h5>
            </div>
            <div class="card-body">
                <p><strong>Created:</strong> {{ purchase_order.created_at|date:"d/m/Y H:i" }}</p>
                <p><strong>Updated:</strong> {{ purchase_order.updated_at|date:"d/m/Y H:i" }}</p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
