<?php
$cs = Yii::app()->getClientScript();
?>

<section class="panel">
    <header class="panel-heading clearfix panel-theame">
        <i class="fa fa-calculator"></i> Expense Settlement

        <div class="pull-right">
              <a class="ad-btn" onclick="loadPopupModal('expensesettlement/create','Add New Settlement','lg')">
                <svg width="30" height="30" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" class="pluss-ad">
                    <circle cx="12" cy="12" r="11" stroke="white" stroke-width="2" fill="none"></circle>
                    <line x1="12" y1="7" x2="12" y2="17" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"></line>
                    <line x1="7" y1="12" x2="17" y2="12" stroke="#5db5a4" stroke-width="2" stroke-linecap="round"></line>
                </svg>
              </a>
          <!--   <button class="btn btn-sm btn-theme"
                    onclick="loadPopupModal('expensesettlement/create', 'Add New Settlement', 'lg')">
                <i class="fa fa-plus"></i> ADD
            </button> -->
        </div>
    </header>

    <div class="panel-body">
        <div class="custom-data-table">
            <table class="table table-hover table-bordered personal-task" id="tbl_expense_settlement" style="font-size:13px;">
                <thead>
                    <tr>
                        <th>SI No</th>
                        <th>Settlement Date</th>
                        <th>User</th>
                        <th>Unsettled Expenses</th>
                        <th>Balance</th>
                        <th>Amount Returned</th>
                        <th>Amount Dispersed</th>
                        <th>New Balance</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</section>

<script>
$(document).ready(function () {

    var table = $("#tbl_expense_settlement").DataTable({
        scrollY: "645px",
        pageLength: 50,
        processing: true,
        serverSide: true,
        ajax: {
            url: "<?php echo Yii::app()->createUrl('expensesettlement/GetList'); ?>",
            type: "POST"
        },
        columnDefs: [
            { className: "text-right", targets: [3, 4, 5, 6, 7] } 
        ],
        fnCreatedRow: function (nRow, aData, iDataIndex) {
            $(nRow).addClass("context-menu");
            AddContextMenu(nRow, aData);
        }
    });

});

// Context Menu
function AddContextMenu(row, datas) {

    $(row).contextMenu({
        selector: 'td',
        items: {
            "edit": {
                name: "Edit",
                icon: "edit",
                callback: function () {
                    loadPopupModal(
                        "expensesettlement/create&id=" + datas[8],
                        "Edit Settlement",
                        "lg"
                    );
                }
            },
            "view": {
                name: "View",
                icon: "fa fa-eye",
                callback: function () {
                    loadPopupModal(
                        "expensesettlement/ExpenseDetails&id=" + datas[8],
                        "View Expense Details",
                        "xl"
                    );
                }
            },
            "print": {
                name: "Print",
                icon: "fa-pdf",
                callback: function () {
                    window.open($('#liveSite').val() + "/index.php?r=expensesettlement/Print&id=" + datas[8], "_blank");
                }
            }
        }
    });
}
</script>
