main.njk 8.38 KB
{% extends "template.sbadmin2.njk" %}

{% block content %}

<table class="table">
    <thead>
        <tr>
            <th style="white-space: nowrap; width: 1%;">Produk</th>
            <th class="text-right">Sisa</th>
            <th style="white-space: nowrap; width: 1%;">&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        {% for item in limitedList %}
        <tr>
            <td style="white-space: nowrap; width: 1%;">
                <strong>{{ item.product }}</strong>
            </td>

            <td class="text-right">
                {% set maxValue = maxValues[item.product] %}
                {% if maxValue %}    
                <div class="progress">
                    <div class="progress-bar" role="progressbar" style="width: {{ 100 * item.value / (maxValue or item.value) }}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="{{ maxValue }}"></div>
                </div>
                <br>
                {% endif %}

                <a href="#" title="klik untuk edit nilai maksimal pada grafik indikator" data-toggle="modal" data-target="#editMaxValueModal" data-product="{{ item.product }}" data-maxvalue="{{ maxValue or item.value }}">
                {{ item.value }}
                {% if maxValue %} dari {{ maxValue }} {% endif %}
                </a>
            </td>

            <td style="white-space: nowrap; width: 1%;">
                <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#editQuotaModal" data-product="{{ item.product }}">
                    Edit
                </button>

                <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#addQuotaModal" data-product="{{ item.product }}">
                    Tambah
                </button>

                <a href="{{ baseUrl }}/delete/{{ item.supplier | urlencode }}/{{ item.product | urlencode }}"
                    class="btn btn-danger btn-sm"
                    onclick="return confirm('Apakah anda yakin ingin menghapus kuota &#8220{{ item.product }}&#8220 pada supplier &#8220{{ item.supplier }}&#8220?');"
                >
                    Hapus
                </a>
            </td>
        </tr>
        {% endfor %}
    </tbody>
</table>

<div class="card border-left-primary">
    <div class="card-header align-items-center">
        <h5 class="m0 font-weight-bold text-primary">Penambahan Produk Terlimit</h5>
    </div>

    <div class="card-body">
        <form method="POST" action="{{ baseUrl }}/add-product">
            <div class="form-group">
                <label for="inputProduct">Kode Produk di Supplier</label>
                <input name="product" type="text" class="form-control" id="inputProduct" aria-describedby="inputProductHelp">
                <small id="inputProductHelp" class="form-text text-muted">Masukkan kode produk di supplier.</small>
            </div>

            <div class="form-group">
                <label for="inputLimit">Batas limit</label>
                <input name="newLimit" type="text" class="form-control" id="inputLimit" aria-describedby="inputLimitHelp">
                <small id="inputLimitHelp" class="form-text text-muted">Masukkan batas limit.</small>
            </div>

            <button type="submit" class="btn btn-primary">Submit</button>
        </form>
    </div>
</div>

<form method="POST" action="{{ baseUrl }}/edit-product">
<div class="modal fade" id="editQuotaModal" tabindex="-1" role="dialog" aria-labelledby="editQuotaModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editQuotaModalLabel">Edit Kuota</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <input type="hidden" name="product" id="inputProduct" value="-999">
                <div class="form-group">
                    <label for="inputLimit">Batas limit</label>
                    <input name="newLimit" type="number" class="form-control" id="inputLimit" aria-describedby="inputLimitHelp" required>
                    <small id="inputLimitHelp" class="form-text text-muted">Masukkan batas limit baru.</small>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <input type="submit" class="btn btn-primary" value="Simpan">
            </div>
        </div>
    </div>
</div>
</form>

<form method="POST" action="{{ baseUrl }}/add-quota">
<div class="modal fade" id="addQuotaModal" tabindex="-1" role="dialog" aria-labelledby="addQuotaModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editQuotaModalLabel">Tambah Kuota</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <input type="hidden" name="product" id="inputProduct">
                <div class="form-group">
                    <label for="raiseValue">Kuota yang ingin ditambahkan</label>
                    <input name="raiseValue" type="number" class="form-control" id="raiseValue" aria-describedby="raiseValueHelp" required>
                    <small id="raiseValue" class="form-text text-muted">Masukkan tambahan kuota.</small>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <input type="submit" class="btn btn-primary" value="Simpan">
            </div>
        </div>
    </div>
</div>
</form>

<form method="POST" action="{{ baseUrl }}/edit-max-value-for-indicator">
<div class="modal fade" id="editMaxValueModal" tabindex="-1" role="dialog" aria-labelledby="editMaxValueModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editMaxValueModalLabel">Edit nilai maksimal pada indikator</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <input type="hidden" name="product" id="inputProduct">
                <div class="form-group">
                    <label for="raiseValue">Nilai maksimal</label>
                    <input name="maxValue" type="number" class="form-control" id="maxValue" aria-describedby="maxValueHelp" required>
                    <small id="maxValueHelp" class="form-text text-muted">Masukkan nilai maksimal (untuk tampilan grafik).</small>
                </div>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <input type="submit" class="btn btn-primary" value="Simpan">
            </div>
        </div>
    </div>
</div>
</form>

{% endblock %}

{% block postScriptOnBody %}

<script>
$('#editQuotaModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget);
    var product = button.data('product');

    var modal = $(this)
    modal.find('.modal-title').text(`Edit Kuota ${product}`);
    modal.find('.modal-body #inputProduct').val(product);
});

$('#addQuotaModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget);
    var product = button.data('product');

    var modal = $(this)
    modal.find('.modal-title').text(`Tambah Kuota ${product}`);
    modal.find('.modal-body #inputProduct').val(product);
});

$('#editMaxValueModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget);
    var product = button.data('product');
    var maxvalue = button.data('maxvalue');

    var modal = $(this)
    modal.find('.modal-title').text(`Edit nilai maksimal ${product}`);
    modal.find('.modal-body #inputProduct').val(product);
    modal.find('.modal-body #maxValue').val(maxvalue);
});
</script>

{% endblock %}