@include('admin.layouts.header')
@include('admin.layouts.sidebar')
<style>
    .hidden{
        display: none;
    }
    .font-weight{
        font-weight: 600;
    }
    table{
        width: 100%;
        font-family: Arial;
    }
    .emi-form > thead > tr > th{
        font-weight: 600 !important;
    }
    .payable-amt{
        border-top-style: solid;
        border-bottom-style: solid;
    }
    .interest_rate{
        text-transform: capitalize;
    }
    .datepicker tbody tr > td[class='day']{
        color: black;
        border: 1px dashed #34b9c3;
    }
    .panel-group{
        padding-top: 8px;
    }
    .panel-default{
        padding-bottom: 4px;
    }
    .panel-collapse{
        background-color: #ffffff;
        padding: 10px;
        border: 1px solid #dedada;
    }
    h4.panel-title > a{
        font-size: 14px;
        color: #5f5a5a !important;
    }
    .panel-heading {
        background-color: #f1f1f1;
        border: 1px solid #e0dfe0;
        padding-left: 10px;
        padding-top: 6px;
        cursor: pointer;
    }
    .panel-heading {
        background-color: #f1f1f1;
        border: 1px solid #e0dfe0;
        padding-left: 10px;
        padding-top: 6px;
        cursor: pointer;
    }
    .panel-default{
        padding-bottom: 4px;
    }
    .panel-collapse{
        background-color: #ffffff;
        padding: 10px;
        border: 1px solid #dedada;
    }
    .error-view{
        position: absolute;
        top: 37px;
        background-color: red;
        padding-left: 10px;
        padding-right: 10px;
        color: white;
        font-size: 11px;
    }
</style>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
    <!-- BEGIN: Subheader -->
    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    Finance
                </h3>
            </div>

        </div>
    </div>
<?php setlocale(LC_MONETARY, 'en_IN.UTF-8'); ?>
<!-- END: Subheader -->
    <div class="m-content">
        @if(Session::has('success'))
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('success') }}
            </div>
        @endif
        @if(Session::has('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
                {{ Session::get('error') }}
            </div>
        @endif
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__head">
                <div class="m-portlet__head-caption">
                    <div class="m-portlet__head-title">
                        <span class="m-portlet__head-icon">
                            <i class="fa fa-file-text-o"></i>
                        </span>
                        <h3 class="m-portlet__head-text">
                            Accounting Reports
                        </h3>
                    </div>
                </div>
            </div>
            <div class="m-portlet__body">
                <div class="m-section">
                    <div class="m-section__content">
                        <div class="col-md-12">
                            <form id="accounting-reports" class="form-horizontal" action="/admin/accounting-reports" method="POST">
                                <input name="_token" value="{{ csrf_token() }}" type="hidden">
                                <input name="search" value="search" type="hidden">
                                <div class="row" style="padding-bottom: 10px;margin-left: -32px;padding-top: 10px;">
                                    <div class="col-md-2">
                                        <select class="form-control" name="selectedReportType" id="selectedReportType" required>
                                            <option value="">Type of Report</option>
                                            @foreach($reportTypes as $reportType)
                                                <option value="{!! $reportType !!}" @if(isset($selectedReportType) && $selectedReportType == $reportType) selected="selected" @endif>{!! $reportType !!}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-2">
                                        <select class="form-control" name="lender_id" id="lender_id" required>
                                            <option value="">Select Lender</option>
                                            @foreach($lenders as $lender)
                                                <option value="{!! $lender->id !!}" @if(isset($lender_id) && $lender_id == $lender->id) selected="selected" @endif>{!! $lender->name !!}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-2" id="select_from_date" @if(empty($from_date))style="display: none;"@endif>
                                        <input type="text" name="from_date" id="fl_from_date" class="form-control" placeholder="From Date" value="{{Request::old('from_date', $from_date)}}" autocomplete="off"/>
                                    </div>
                                    <div class="col-md-2" id="select_to_date" @if(empty($to_date))style="display: none;"@endif>
                                        <input type="text" name="to_date" id="fl_to_date" class="form-control" placeholder="To Date" value="{{Request::old('to_date', $to_date)}}" autocomplete="off"/>
                                    </div>
                                    <div class="col-md-2" id="select_month" @if(empty($month))style="display: none;"@endif>
                                        <select class="form-control" name="month">
                                            <option value="">Select Month</option>
                                            <?php for ($month = 1; $month <= 12; $month++) {
                                            $monthName = date('F', mktime(0,0,0,$month, 1, date('Y')));  ?>
                                            <option value="{!! $month !!}">{!! $monthName !!}</option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <div class="col-md-2" id="select_year" @if(empty($year))style="display: none;"@endif>
                                        <select class="form-control" name="year">
                                            <option value="">Select Year</option>
                                            <?php for ($year = 2018; $year <= date('Y'); $year++) {
                                            $yearName = date('Y', mktime(0,0,0,1, 1, $year));  ?>
                                            <option value="{!! $year !!}">{!! $yearName !!}</option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <div class="col-md-4">
                                        <input type="submit" class="btn btn-accent" value="Export Report in Excel"/>
                                        <div class="btn btn-primary" onclick="return window.location = '/admin/accounting-reports';">Clear Filter</div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    const typeOfSettlement = document.querySelector('select[name="selectedReportType"]');
    typeOfSettlement.addEventListener('change', function(event) {
        const selectedValue = event.target.value;

        if (selectedValue === "Subvention Interest" || selectedValue === "Accrued Revenue") {
            $('#select_from_date').css('display', 'none').attr('disabled', 'disabled').removeAttr('required', 'required');
            $('#select_to_date').css('display', 'none').attr('disabled', 'disabled').removeAttr('required', 'required');
            $('#select_lender').css('display', 'block');
            $('#select_month').css('display', 'block').removeAttr('disabled', 'disabled').attr('required', 'required');
            $('#select_year').css('display', 'block').removeAttr('disabled', 'disabled').attr('required', 'required');
        } else{
            $('#select_from_date').css('display', 'block').removeAttr('disabled', 'disabled').attr('required', 'required');
            $('#select_to_date').css('display', 'block').removeAttr('disabled', 'disabled').attr('required', 'required');
            $('#select_lender').css('display', 'block');
            $('#select_month').css('display', 'none').attr('disabled', 'disabled').removeAttr('required', 'required');
            $('#select_year').css('display', 'none').attr('disabled', 'disabled').removeAttr('required', 'required');
        }
    });
</script>
@include("admin.layouts.footer")
