<?php
//if (($permissions->hasPermission('addPrepaid') && !$Is_Actual) || ($permissions->hasPermission('addPrepaidActual') && $Is_Actual)) {
//    include("Views/Accounting/addPrepaid.php");
//}
//if (($permissions->hasPermission('addPrepaidIncome') && !$Is_Actual) || ($permissions->hasPermission('addPrepaidIncomeActual') && $Is_Actual)) {
//    include("Views/Accounting/addPrepaidIncome.php");
//}
?>
<style>
    .diff_class{
        width:20%!important;
    }
    .dropdown-toggle {
        background-color:#4c0870;
        border-color : #4c0870;
    }
    .dropdown-toggle:hover{
        background-color:#4c0870;
        border-color : #4c0870;
    }
    #tableWithSearch thead tr >th{
        background-color:#4c0870;
        color:#fff;
        width: 6% !important;
    }
    #tableWithSearch thead tr th[class*='sorting_'] {
        color: #fff;
    }
    .bg-master-lighter {
        border:none;
        background-color:#fff;
        border-top:1px solid #ddd;  
    }
    .btn-group {
        /*        background-color:#ed9421 !important;*/
        color:#fff;
    }
    .btn-default{
        border: none;
        background-color: #eee;
    }
    .btn-default:hover{
        background-color:#ed9421 !important;
        color:#fff;
        border: none;
    }
    .table-responsive {
        overflow-x: visible; 
    }
    .dropdown-menu>li>a:hover, .dropdown-menu>li>a:focus{
        background-color:#ed9421 !important; ;
        color:#fff;
    }
    .btn-default:hover{
        background-color:#ed9421 !important;
        color:#fff;
        border: none;
    }
    .complete ,.btn-group  .active{
        background-color:#ed9421 !important;
        color:#fff;
    }
    .MonthPicker,.YearPicker,.FromToPicker,#PrePaidList_filter{
        display:none;
    }
    #selected_entry{
        height:90px;
        color: black;
        margin-top:20px;
        font-size: 16px;
        padding-top: 2%;
    }
    .select_table td{
        padding-left: 70px;
    }
    .actionButton{
        background-color:#4c0870;
    }
</style>
<script src="<?php echo THEME_PATH; ?>/plugins/moment/moment.min.js"></script>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <div class="panel-title"><?php print CommonLanguage::getMessage('prepaid_list'); ?></div>
            <div class="input-group  col-md-3" >
                <span class="input-group-addon bg-complete"><i class="fa fa-calendar"></i></span>
                <input id="From_To_Date" type="text" class="form-control" name="From_To_Date" >
            </div> 
            <?php
//            $modal = $Income ? '#addPrepaidIncome' : '#addPrepaid';
//            $Title = $Income ? CommonLanguage::getMessage('add_prepaid_income') : CommonLanguage::getMessage('add_prepaid');
            $permission = $Is_Actual ? ($Income ? 'addPrepaidIncomeActual' : 'addPrepaidActual' ) : ($Income ? 'addPrepaidIncome' : 'addPrepaid');
            if ($permissions->hasPermission($permission)) {
//                echo Forms::FloatingAddButton('4c0870', $modal, $Title);
                ?>
                <div class="floatingContainer  pull-right">
                    <a href="ACC/addPrepaid<?php echo ($Income ? '/Income' : '') . ($Is_Actual ? '/act' : '') ?>" ><div class="actionButton">
                            <p class="floatingText"><span class="floatingTextBG"><?php echo $Income ? CommonLanguage::getMessage('add_prepaid_income') : CommonLanguage::getMessage('add_prepaid') ?></span></p>
                        </div></a>
                </div>
            <?php } ?>
        </div>
        <div class="panel-body">
            <table class="table table-bordered table-hover demo-table-search" id="tableWithSearch">
                <thead>
                    <tr>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('account'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('vendor_name'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('total_amount'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('amount_month'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('description'); ?></th>
                        <th class="text-center" ><?php print CommonLanguage::getMessage('start_date'); ?></th>
                        <th class="text-center"><?php print CommonLanguage::getMessage('end_date'); ?></th>
                        <th class="text-center no-print"><?php print CommonLanguage::getMessage('Action'); ?></th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</div>
<script>
    var CompanyLang = <?php echo json_encode(CommonLanguage::getMessage('company')); ?>,
            EmailLang = <?php echo json_encode(CommonLanguage::getMessage('Email')); ?>,
            title = <?php echo json_encode(CommonLanguage::getMessage('prepaid_list')); ?>,
            PhoneLang = <?php echo json_encode(CommonLanguage::getMessage('Phone')); ?>,
            is_actual = <?php echo json_encode($Is_Actual); ?>;
    var Income = <?php echo $Income ? "true" : "false" ?>;
    var ToEditID;
    var today = <?php echo json_encode($today) ?>;
    $(function () {
        ChangeTable()
        $("input[name=From_To_Date]").daterangepicker({
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                    window.endDate = end.format("YYYY-MM-DD")
            ChangeTable();
        });
        $("#tableWithSearch").on("click", ".delete_prepaid", function () {
            var entry_value = $(this).parents('.Action').attr('data-id');
            var data = {
                id: entry_value
            };
            common_delete_modal[1] = common_delete_modal[1]
            IncludeDeleteModal(common_delete_modal, data, function () {
                ChangeTable();
            }, "ACCAjax/delete_prepaid");
        })
//        $(".floatingContainer ").on("click", function () {
//            ToEditID = 0;
//            !Income ? enableSupplierPrepaidAutoComplete() : enableSupplierPrepaidIncomeAutoComplete()
//        })
//        $('#tableWithSearch').on('click', '.EditEntry', function () {
//            ToEditID = $(this).attr('data-id')
//
//            var dataToEdit = {
//                is_actual: is_actual,
//                ToEditID: ToEditID,
//                EditType: Income ? 'Income' : 'Expense'
//            }
//            $.ajax({
//                url: "ACCAjax/viewPrepaidExpenseAjax",
//                data: dataToEdit,
//                method: "GET",
//                dataType: 'json',
//                complete: function (v1, v2) {
//                    if (v2 == "success") {
//                        var Data = (v1.responseJSON);
//                        $('#addPrepaidIncomeSupplier_ID').val(Data[0]['Supplier_ID'])
//                        !Income ? enableSupplierPrepaidAutoComplete() : enableSupplierPrepaidIncomeAutoComplete()
//                        Income ? $('#Income_Start_Date').val(Data[0]['Start_Date']) : $('#StartDate').val(Data[0]['Start_Date'])
//                        Income ? $('#Income_End_Date').val(Data[0]['End_Date']) : $('#EndDate').val(Data[0]['End_Date'])
//                        $('#Prepaid_Currency').val(Data[0]['Currency_ID'])
//                        $(Income ? '#Income_Account_Code' : '#Account_Code').val(Data[0]['Account_ID']).attr('data-select-name', Data[0]['Main_Account']);
//                        build_select2($(Income ? '#Income_Account_Code' : '#Account_Code'), Income ? "xhr/IncAccSearch" : "xhr/ExpenseAccSearch")
//                        $(Income ? '#Prepaid_Income' : '#Prepaid_Account').val(Data[0]['Prepaid_Account_ID']).attr('data-select-name', Data[0]['Prepaid_Account_Name']);
//                        build_select2($(Income ? '#Prepaid_Income' : '#Prepaid_Account'), Income ? "xhr/PrepaidIncSearch" : "xhr/prepaidExpSearch")
//                        Income ? $('#Income_Total_Amount').val(Data[0]['Total_Amount']) : $('#Total_Amount').val(Data[0]['Total_Amount'])
//                        Income ? $('#Permonth_Income').val(Data[0]['Amount_PerMonth']) : $('#Amount_PerMonth').val(Data[0]['Amount_PerMonth'])
//                        Income ? $('#Income_Paid_Amount').val(Data[0]['Paid_Amount']) : $('#Paid_Amount').val(Data[0]['Paid_Amount'])
//                        Income ? $('#Income_Payment_ID').val(Data[0]['Payment_ID']).select2() : $('#Payment_ID').val(Data[0]['Payment_ID']).select2()
//                        Income ? $('.Income_Amount #PrepaidTotalDetails').html(Data[0]['Total_Amount']) : $('#PrepaidTotalDetails').html(Data[0]['Total_Amount'])
//                        $('.CurrencyIndicator').html(Data[0]['Currency_Symbol'])
//                        Income ? $('#Income_Desc').val(Data[0]['Description']) : $('#Prepaid_Desc').val(Data[0]['Description'])
//                        Income ? $('#Income_Desc').attr('old-desc', Data[0]['Description']) : $('#Prepaid_Desc').attr('old-desc', Data[0]['Description'])
//                        $('#CurrencyDropDown button span').html(Data[0]['Currency_Symbol'])
//                        if (Income) {
//                            $('#addPrepaidIncomeSupplierInfoContent ').html("<strong><span class=Name'>" + Data[0]['Supplier_Name'] + "</span></strong><div><strong>" + CompanyLang + ": </strong><span class='Company'>" + Data[0]['Supplier_Company'] + "</span></div><div><strong>" + EmailLang + ": </strong><span class='Email'>" + Data[0]['Supplier_Email'] + "</span></div><div><strong>" + PhoneLang + ": </strong><span class='Phone'>" + Data[0]['Supplier_Phone'] + "</span></div>")
//                            $('#addPrepaidIncome').modal('show')
//                        } else {
//                            $('#addPrepaid').modal('show')
//                        }
//                        $(Income ? "#inc_current_rate" : "#current_rate").val(Data[0]['current_rate'])
//                        $(Income ? "#inc_branch_id" : "#branch_id").val(Data[0]['branch_id']).attr("data-select-name", Data[0]['branch_name'])
//                        build_select2($(Income ? "#inc_branch_id" : "#branch_id"), "xhr/CommonSearch?col_id=branch_id&col_name=branch_name&table=tbl_organization_branches")
//                        $(Income ? "#inc_job_id" : "#job_id").val(Data[0]['job_id']).attr("data-select-name", Data[0]['job_name'])
//                        build_select2($(Income ? "#inc_job_id" : "#job_id"), "ACCAjax/JobSearch")
//                        $(Income ? "#inc_project_id" : "#project_id").val(Data[0]['project_id']).attr("data-select-name", Data[0]['project_name'])
//                        build_select2($(Income ? "#inc_project_id" : "#project_id"), "ACCAjax/projectSearch")
//
//                        $('#AddPrepaidSupplierInfoContent ').html("<strong><span class=Name'>" + Data[0]['Supplier_Name'] + "</span></strong><div><strong>" + CompanyLang + ": </strong><span class='Company'>" + Data[0]['Supplier_Company'] + "</span></div><div><strong>" + EmailLang + ": </strong><span class='Email'>" + Data[0]['Supplier_Email'] + "</span></div><div><strong>" + PhoneLang + ": </strong><span class='Phone'>" + Data[0]['Supplier_Phone'] + "</span></div>")
//                        UpdatePrepaidIncomeSubmitButtonStatus()
//                    }
//                }
//            })
//        })
    })
    function ChangeTable() {
        var MyData = {
            is_actual: is_actual,
            Income: Income ? "Income" : "Expense",
            Prepaid_Date_From: window.startDate ? window.startDate : today,
            Prepaid_Date_To: window.endDate ? window.endDate : today
        }
        RebuildDataTable(title, [0, 1, 2, 3, 4, 5, 6], 'ACCAjax/viewPrepaidExpenseRequest', MyData)
    }
//    function clear_input() {
//        $("#TableItem input").val("")
//        $("#IncomeTable input").val("")
//        $("textarea").val("")
//        $("span#PrepaidTotalDetails").html("0")
//        $("#AddPrepaidSupplierInfoContent").empty()
//        $(".CurrencyIndicator").empty()
//        $("#addPrepaidIncomeSupplierInfoContent").empty()
//    }
</script>
