/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var registertable = $('#registertable').DataTable({
    responsive: {
        details: {
            display: $.fn.dataTable.Responsive.display.modal({
                header: function (row) {
                    var data = row.data();
                    return "<i class=\"far fa-money-bill-alt fa-fw\"></i> " + data[2];
                }
            }),
            renderer: $.fn.dataTable.Responsive.renderer.tableAll({
                tableClass: 'table'
            }),
            type: "column"
        }
    },
    columnDefs: [
        {
            targets: 0,
            className: 'control',
            orderable: false
        },
        {
            targets: 1,
            orderable: false
        }
    ],
    order: [
        [2, 'asc']
    ]
});

$("#registertable").on('click', '.btn-opencash', function () {
    var regid = $(this).data("register");
    bsprompt(
            "Open Cash",
            "Enter the opening amount of cash in the drawer.",
            "Open Cash",
            "Cancel",
            "number",
            function (result) {
                $("#opencashform #opencashregid").val(regid);
                $("#opencashform #opencashstart").val(result);
                $("#opencashform").submit();
            }
    );
});