<!DOCTYPE html>
<html>
<head>
    <title>GRN Management</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
    <h2>Add GRN</h2>
    <form method="POST" action="/add_grn">
        <label>GRN Date:</label>
        <input type="date" name="grn_date" required><br><br>

        <label>Purchase ID:</label>
        <input type="number" name="purchase_id" required><br><br>
{#            <label for="purchase_id">Purchase Order:</label>#}
{#   <select name="purchase_id" id="purchase_id" required>#}
{#    {% for order in purchase_orders %}#}
{#        <option value="{{ order['purchase_id'] }}">{{ order['supplier_name'] }}</option>#}
{#    {% endfor %}#}
{#</select>#}

        <label>Supplier Name:</label>
        <input type="text" name="supplier_name" required><br><br>

        <label>Item Description:</label>
        <input type="text" name="item_description" required><br><br>

        <label>Received Quantity:</label>
        <input type="number" name="received_quantity" required><br><br>

        <label>Unit:</label>
        <input type="text" name="unit" required><br><br>

        <label>Rate:</label>
        <input type="number" step="0.01" name="rate" required><br><br>

        <label>Amount:</label>
        <input type="number" step="0.01" name="amount" required><br><br>

        <label>Remarks:</label>
        <input type="text" name="remarks"><br><br>

        <input type="submit" value="Add GRN">
    </form>

    <h2>All GRNs</h2>
    <table border="1">
        <tr>
            <th>ID</th><th>Date</th><th>Purchase ID</th><th>Supplier</th><th>Item</th>
            <th>Qty</th><th>Unit</th><th>Rate</th><th>Amount</th><th>Remarks</th><th>Actions</th>
        </tr>
        {% for grn in grns %}
        <tr>
            <td>{{ grn[0] }}</td>
            <td>{{ grn[1] }}</td>
            <td>{{ grn[2] }}</td>
            <td>{{ grn[3] }}</td>
            <td>{{ grn[4] }}</td>
            <td>{{ grn[5] }}</td>
            <td>{{ grn[6] }}</td>
            <td>{{ grn[7] }}</td>
            <td>{{ grn[8] }}</td>
            <td>{{ grn[9] }}</td>
           <td style="white-space: nowrap;">
    <a href="/update_grn/{{ grn['grn_id'] }}" style="margin-right: 10px;">Edit</a>

    <form action="/delete_grn/{{ grn[0] }}" method="POST" style="display:inline;">
        <button type="submit" onclick="return confirm('Are you sure you want to delete this GRN?')" style="background:none;border:none;color:blue;cursor:pointer;text-decoration:underline;">
            Delete
        </button>
    </form>
</td>
        </tr>
        {% endfor %}
    </table>
</body>
</html>
