{% extends 'base.html' %}

{% block title %}Sales Order - {{ sale_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-check me-2"></i>
        Sales Order
    </h1>
    <div>
        <a href="{% url 'sales:sales_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> {{ sale_order.order_number }}</p>
                        <p><strong>Date:</strong> {{ sale_order.date|date:"d/m/Y" }}</p>
                        <p><strong>Status:</strong> 
                            <span class="badge bg-{% if sale_order.status == 'delivered' %}success{% elif sale_order.status == 'shipped' %}info{% elif sale_order.status == 'confirmed' %}warning{% else %}secondary{% endif %}">
                                {{ sale_order.get_status_display }}
                            </span>
                        </p>
                    </div>
                    <div class="col-md-6">
                        <p><strong>Customer:</strong> {{ sale_order.customer.name }}</p>
                        <p><strong>Expected Delivery:</strong> {{ sale_order.expected_delivery_date|date:"d/m/Y"|default:"Not set" }}</p>
                        <p><strong>Created By:</strong> {{ sale_order.created_by.get_full_name|default:"N/A" }}</p>
                    </div>
                </div>
                
                {% if sale_order.notes %}
                <div class="mt-3">
                    <strong>Notes:</strong>
                    <p class="mt-2">{{ sale_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 {{ sale_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 {{ sale_order.tax_amount|floatformat:0 }}</h4>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="text-center">
                            <h6 class="text-muted">Discount</h6>
                            <h4 class="text-info">Rp {{ sale_order.discount_amount|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 {{ sale_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">Customer Information</h5>
            </div>
            <div class="card-body">
                <p><strong>Customer Code:</strong> {{ sale_order.customer.code }}</p>
                <p><strong>Type:</strong> {{ sale_order.customer.get_customer_type_display }}</p>
                <p><strong>Contact:</strong> {{ sale_order.customer.contact_person|default:"N/A" }}</p>
                <p><strong>Email:</strong> {{ sale_order.customer.email|default:"N/A" }}</p>
                <p><strong>Phone:</strong> {{ sale_order.customer.phone|default:"N/A" }}</p>
                <p><strong>Credit Limit:</strong> Rp {{ sale_order.customer.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> {{ sale_order.created_at|date:"d/m/Y H:i" }}</p>
                <p><strong>Updated:</strong> {{ sale_order.updated_at|date:"d/m/Y H:i" }}</p>
            </div>
        </div>
    </div>
</div>
{% endblock %}
