@include('header')
<div class="container-fluid flex-grow-1 container-p-y">
    <div class="nav-tabs-top mb-4">
        <ul class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#tab1">Lense Stock Report</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab2">Stock Expiry Report</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab3">Customer Sale Report</a>
            </li>

        </ul>
        <div class="tab-content">
            <div class="tab-pane fade show active" id="tab1">
                <div class="card-body">
                    <form id="validation-form22" method="post" enctype="multipart/form-data">
                        <div class="form-row">

                            <div class="form-group col-md-3">
                                <label class="form-label">Vendor Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="VedName" id="VedName" >
                                    <option value="all" selected="">All</option>
                                    @foreach($vendorlist as $result)
                                    <option value="{{$result->VedName}}">{{$result->VedName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Company Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="IolCompName" id="IolCompName" >
                                    <option value="all" selected="">All</option>
                                    @foreach($comp_name_list as $result)
                                    <option value="{{$result->IolCompName}}">{{$result->IolCompName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Cname" id="Cname" onchange="getModel(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($companyList as $result)
                                    <option value="{{$result->Cname}}">{{$result->Cname}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Type </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Model" id="Model" onchange="getPower(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($modellist as $result)
                                    <option value="{{$result->Model}}">{{$result->Model}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Power </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Power" id="Power">
                                    <option value="all" selected="">All</option>
                                    @foreach($powerlist as $result)
                                    <option value="{{$result->Power}}">{{$result->Power}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-2">
                                <div class="form-group">
                                    <label class="form-label">From Date</label>
                                    <input type="date" class="form-control" id="FromDate" Name="FromDate" placeholder="" value="{{date('Y-m-d')}}">
                                </div>
                            </div>
                            <div class="form-group col-md-2">
                            <div class="form-group">
                                    <label class="form-label">To Date</label>
                                    <input type="date" class="form-control" id="ToDate" Name="ToDate" placeholder="" value="{{date('Y-m-d')}}">
                                </div>
                            </div>

                            <input type="hidden" name="Search" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="button" id="filter" class="btn btn-primary btn-finish">Search</button>
                            </div>
                        </div>

                    </form>

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult">


                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="tab2">
                <div class="card-body">
                    <form id="validation-form33" method="post" enctype="multipart/form-data">
                        <div class="form-row">
                            <div class="form-group col-md-3">
                                <label class="form-label">Vendor Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="VedName" id="VedName2" >
                                    <option value="all" selected="">All</option>
                                    @foreach($vendorlist as $result)
                                    <option value="{{$result->VedName}}">{{$result->VedName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Company Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="IolCompName" id="IolCompName2" >
                                    <option value="all" selected="">All</option>
                                    @foreach($comp_name_list as $result)
                                    <option value="{{$result->IolCompName}}">{{$result->IolCompName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Cname" id="Cname2" onchange="getModel2(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($companyList as $result)
                                    <option value="{{$result->Cname}}">{{$result->Cname}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Type </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Model2" id="Model2" onchange="getPower2(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($modellist as $result)
                                    <option value="{{$result->Model}}">{{$result->Model}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Power </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Power" id="Power2">
                                    <option value="all" selected="">All</option>
                                    @foreach($powerlist as $result)
                                    <option value="{{$result->Power}}">{{$result->Power}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>
                            <div class="form-group col-md-2">
                                <label class="form-label">Month </label>
                                <select class="form-control" name="ExpMonth" id="ExpMonth">
                                    <option selected value="">...</option>
                                    @for($i=1;$i<=12;$i++) <option value="{{$i}}">{{$i}}</option>
                                        @endfor
                                </select>
                            </div>
                            <div class="form-group col-md-2">
                                <label class="form-label">Year</label>
                                <select class="form-control" name="ExpYear" id="ExpYear">
                                    <option selected value="">...</option>
                                    @foreach($expyearlist as $result)
                                    <option value="{{$result->ExpYear}}">{{$result->ExpYear}}</option>
                                    @endforeach
                                </select>
                            </div>

                            <input type="hidden" name="Search" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="button" id="filter2" class="btn btn-primary btn-finish">Search</button>
                            </div>
                        </div>

                    </form>

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult2">


                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="tab-pane fade" id="tab3">
                <div class="card-body">
                    <form id="validation-form44" method="post" enctype="multipart/form-data">
                        <div class="form-row">
                            
                            <div class="form-group col-md-3">
                                <label class="form-label">Vendor Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="VedName" id="VedName3" >
                                    <option value="all" selected="">All</option>
                                    @foreach($vendorlist as $result)
                                    <option value="{{$result->VedName}}">{{$result->VedName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Company Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="IolCompName" id="IolCompName3" >
                                    <option value="all" selected="">All</option>
                                    @foreach($comp_name_list as $result)
                                    <option value="{{$result->IolCompName}}">{{$result->IolCompName}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>
                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Name </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Cname3" id="Cname3" onchange="getModel3(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($companyList as $result)
                                    <option value="{{$result->Cname}}">{{$result->Cname}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>
                            <div class="form-group col-md-3">
                                <label class="form-label">IOL Type </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Model" id="Model3" onchange="getPower3(this.value)">
                                    <option value="all" selected="">All</option>
                                    @foreach($modellist as $result)
                                    <option value="{{$result->Model}}">{{$result->Model}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>

                            <div class="form-group col-md-3">
                                <label class="form-label">Power </label>
                                <select class="select2-demo form-control" style="width: 100%;" data-allow-clear="true"
                                    name="Power" id="Power3">
                                    <option value="all" selected="">All</option>
                                    @foreach($powerlist as $result)
                                    <option value="{{$result->Power}}">{{$result->Power}}</option>
                                    @endforeach
                                </select>
                                <div class="clearfix"></div>
                            </div>
                            <div class="form-group col-md-2">
                                <div class="form-group">
                                    <label class="floating-label" for="gender">From Date</label>
                                    <input type="date" class="form-control" id="FromDate" Name="FromDate" placeholder="" value="{{date('Y-m-d')}}">
                                </div>
                            </div>
                            <div class="form-group col-md-2">
                            <div class="form-group">
                                    <label class="floating-label" for="gender">To Date</label>
                                    <input type="date" class="form-control" id="ToDate" Name="ToDate" placeholder="" value="{{date('Y-m-d')}}">
                                </div>
                            </div>

                            <input type="hidden" name="Search" value="Search">
                            <div class="form-group col-md-2" style="padding-top:20px;">
                                <button type="button" id="filter3" class="btn btn-primary btn-finish">Search</button>
                            </div>
                        </div>

                    </form>

                    <div class="card">
                        <div class="card-body">


                            <div class="table-responsive" id="custresult3">


                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>





</div>

@include('footerscript')
@include('excelscript')
<script>
    function getModel3(Cname) {
        $.ajax({
        url: "{{ url('model_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname
        },
        success: function(data) {
            console.log(data);
            $('#Model3').html(data);
        }
    });
    }
    function getPower3(Model) {
        var Cname = $('#Cname3').val();
        $.ajax({
        url: "{{ url('power_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname,
            Model: Model
        },
        success: function(data) {
            console.log(data);
            $('#Power3').html(data);
        }
    });
    }
    function getModel2(Cname) {
        $.ajax({
        url: "{{ url('model_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname
        },
        success: function(data) {
            console.log(data);
            $('#Model2').html(data);
        }
    });
    }
    function getPower2(Model) {
        var Cname = $('#Cname2').val();
        $.ajax({
        url: "{{ url('power_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname,
            Model: Model
        },
        success: function(data) {
            console.log(data);
            $('#Power2').html(data);
        }
    });
    }
    
function getModel(Cname) {
    $.ajax({
        url: "{{ url('model_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname
        },
        success: function(data) {
            console.log(data);
            $('#Model').html(data);
        }
    });
}

function getPower(Model) {
    var Cname = $('#Cname').val();
    $.ajax({
        url: "{{ url('power_list') }}",
        method: "POST",
        data: {
            _token: '{{csrf_token()}}',
            Cname: Cname,
            Model: Model
        },
        success: function(data) {
            console.log(data);
            $('#Power').html(data);
        }
    });
}
$(document).ready(function() {
    $('#filter').click(function() {
        var Cname = $('#Cname').val();
        var Model = $('#Model').val();
        var Power = $('#Power').val();
        var VedName = $('#VedName').val();
        var IolCompName = $('#IolCompName').val();
        var FromDate = $('#FromDate').val();
        var ToDate = $('#ToDate').val();

        //$('.yajra-datatable').DataTable().destroy();
        //load_data(FromDate, ToDate);
        queueList(Cname, Model, Power,VedName,IolCompName,FromDate,ToDate);

    });

    $('#refresh').click(function() {
        $('#Cname').val('all').attr("selected", true);
        $('#Model').val('all').attr("selected", true);
        $('#Power').val('all').attr("selected", true);
        $('#VedName').val('all').attr("selected", true);
        $('#IolCompName').val('all').attr("selected", true);
        queueList();
    });

    function queueList(Cname = 'all', Model = 'all', Power = 'all', VedName = 'all', IolCompName = 'all',FromDate='',ToDate='') {
        $.ajax({
            url: "{{ url('viewLenseStockReport') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                Cname: Cname,
                Model: Model,
                Power: Power,
                VedName:VedName,
                IolCompName:IolCompName,
                FromDate:FromDate,
                ToDate:ToDate
            },
            success: function(data) {
                console.log(data);
                $('#custresult').html(data);
            }
        });
    }



    $('#filter2').click(function() {
        var Cname2 = $('#Cname2').val();
        var Model2 = $('#Model2').val();
        var Power2 = $('#Power2').val();
        var VedName2 = $('#VedName2').val();
        var IolCompName2 = $('#IolCompName2').val();
        var ExpMonth = $('#ExpMonth').val();
        var ExpYear = $('#ExpYear').val();

        queueList2(ExpMonth, ExpYear, Cname2, Model2, Power2,VedName2,IolCompName2);

    });

    $('#refresh2').click(function() {
        $('#ExpYear').val('');
        $('#ExpMonth').val('');
        $('#Cname2').val('all').attr("selected", true);
        $('#Model2').val('all').attr("selected", true);
        $('#Power2').val('all').attr("selected", true);
        $('#VedName2').val('all').attr("selected", true);
        $('#IolCompName2').val('all').attr("selected", true);
        queueList2();
    });

    function queueList2(ExpMonth = '', ExpYear = '', Cname2 = 'all', Model2 = 'all', Power2 = 'all', VedName2 = 'all', IolCompName2 = 'all') {
        $.ajax({
            url: "{{ url('viewLenseStockReport2') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                ExpYear: ExpYear,
                ExpMonth: ExpMonth,
                Cname: Cname2,
                Model: Model2,
                Power: Power2,
                VedName:VedName2,
                IolCompName:IolCompName2
            },
            success: function(data) {

                $('#custresult2').html(data);
            }
        });
    }



    $('#filter3').click(function() {
        var Cname = $('#Cname3').val();
        var Model = $('#Model3').val();
        var Power = $('#Power3').val();
        var VedName = $('#VedName3').val();
        var IolCompName = $('#IolCompName3').val();
        var FromDate = $('#FromDate').val();
        var ToDate = $('#ToDate').val();
        queueList3(Cname, Model, Power,FromDate,ToDate,VedName = 'all', IolCompName = 'all');

    });

    $('#refresh3').click(function() {
        $('#Cname3').val('all').attr("selected", true);
        $('#Model3').val('all').attr("selected", true);
        $('#Power3').val('all').attr("selected", true);
        $('#VedName3').val('all').attr("selected", true);
        $('#IolCompName3').val('all').attr("selected", true);
        queueList3();
    });

    function queueList3(Cname = 'all', Model = 'all', Power = 'all',FromDate='',ToDate='', VedName = 'all', IolCompName = 'all') {
        $.ajax({
            url: "{{ url('viewLenseStockReport3') }}",
            method: "POST",
            data: {
                _token: '{{csrf_token()}}',
                Cname: Cname,
                Model: Model,
                Power: Power,
                VedName:VedName,
                IolCompName:IolCompName,
                FromDate:FromDate,
                ToDate:ToDate
            },
            success: function(data) {
                console.log(data);
                $('#custresult3').html(data);
            }
        });
    }


});
</script>