@extends('admin/layouts/default')
{{-- Page title --}}
@section('title')
Bundle Offer Order List
@parent
@stop
{{-- page level styles --}}
@section('header_styles')
<!--page level css -->
<link href="{{ asset('assets/css/pages/tables.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('assets/vendors/select2/css/select2.min.css') }}" type="text/css" rel="stylesheet">
<link href="{{ asset('assets/vendors/select2/css/select2-bootstrap.css') }}" rel="stylesheet">
<!--end of page level css-->
@stop
{{-- Page content --}}
@section('content')
<section class="content-header">
    <!--section starts-->
    <h1>Bundle Offer Order List</h1>
    <ol class="breadcrumb">
        <li>
            <a href="{{ route('admin.dashboard') }}">
            <i class="livicon" data-name="home" data-size="18" data-loop="true"></i>
            Dashboard
            </a>
        </li>
        <li class="active">Bundle Offer Order List</li>
    </ol>
</section>
<!--section ends-->
<section class="content">
    <div class="row">
        <div class="col-md-12">

            @if ($message = Session::get('success'))
            <div class="alert alert-success alert-dismissable">
            <p>{{ $message }}</p>
            </div>
            @endif
            @if ($message = Session::get('error'))
            <div class="alert alert-danger alert-dismissable">
            <p>{{ $message }}</p>
            </div>
            @endif

            <!-- BEGIN SAMPLE TABLE PORTLET-->
            <div class="portlet box primary">
                <div class="portlet-body table-responsive">
             <form action="{{ route('bundle_offer_report') }}" method="get"  enctype="multipart/form-data">
                            @csrf            
                   
                        <div class="form-group col-md-3">
                        <label class="control-label" for="select21">Bundle Offer Name:</label>
                        <select class="form-control select2" id="bundle_id" name="bundle_id" >
                            <option selected="true" value="" disabled="disabled" hidden>Select Bundle</option>
                            @foreach($bundles as $value)
                            <option value="{{$value->bundle_id}}" @isset($param) @if($param['bundle_id'] == $value->bundle_id) selected @endif @endisset>{{$value->bundle_name}}</option>
                            @endforeach 
                        </select>
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">Allow Articles:</label>
                            <input type="text" name="article_download_allow" class="form-control" value="{{ $param['article_download_allow'] }}" />
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">Allow eBook:</label>
                            <input type="text" name="ebook_download_allow" class="form-control" value="{{  $param['ebook_download_allow'] }}" />
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">Allow Chapter:</label>
                            <input type="text" name="chapter_download_allow" class="form-control" value="{{  $param['chapter_download_allow'] }}" />
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">Price:</label>
                            <input type="text" name="price" class="form-control" value="{{ $param['price'] }}" />
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">Expiry:</label>
                        <select class="form-control select2" name="expiry" required="required">
                            <option selected="true" disabled="disabled" hidden>Select Expiry</option>
                           <option value="3" {{ $param['expiry'] == '3' ? 'selected' : '' }}>3 Months</option>
                           <option value="6" {{ $param['expiry'] == '6' ? 'selected' : '' }}>6 Months</option>
                           <option value="9" {{ $param['expiry'] == '9' ? 'selected' : '' }}>9 Months</option>
                           <option value="12" {{ $param['expiry'] == '12' ? 'selected' : '' }}>12 Months</option>
                        </select>
                        </div>

                        <div class="form-group col-md-3">
                            <label class="control-label" for="select21">User Name:</label>
                            <input type="text" name="user_name" class="form-control" value="{{ $param['user_name'] }}" />
                        </div>

                        <div class="form-group col-md-3">
                        <label class="control-label" for="select21">Action:</label><br />
                            <button type="submit" class="btn btn-primary" name="frm_search" value ="true">
                                <span class="glyphicon glyphicon-search"></span>  Search
                            </button>
                            <a href="{{ URL::to('admin/bundle_offer_report') }}"  id="btn_reset" class="btn btn-default">Reset</a>
                        </div>
                        
                    </form>
                    <br>
                    <table class="table table-striped table-bordered" id="article_table">
                        <thead>
                            <tr>
                                <th>User</th>
                                <th>Bundle Name</th>
                                <th class="text-center">Articles<br />Allow - Download</th>
                                <th class="text-center">eBook<br />Allow - Download</th>
                                <th class="text-center">Chapter<br />Allow - Download</th>
                                <th>Payment Status</th>
                                <th>Expiry</th>
                                <th>Details</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (count($bundle_order) > 0)
                            @foreach($bundle_order as $values)
                            <tr>
                                <td>@if(!empty($values->name)) {{ $values->name }} @else {{ $values->user_name }} @endif</td>
                                <td>{{ $values->bundle_name }}</td>
                                <td class="text-center">{{ $values->article_download_allow }} - {{ $values->article }}</td>
                                <td class="text-center">{{ $values->ebook_download_allow }} - {{ $values->ebook }}</td>
                                <td class="text-center">{{ $values->chapter_download_allow }} - {{ $values->chapter }}</td>
                                <td>{{ $values->payment_status }}</td>
                                <td>@if(!empty($values->bundle_offer_expiry))
                                    {{ strftime('%Y-%m-%d',$values->bundle_offer_expiry) }}
                                    @else
                                    Not Available
                                    @endif
                                </td>
                                <td>
                                    @include('admin.orders.model.bundle_order_view_details')
                                </td>
                            </tr>
                            @endforeach
                            @else
                            <tr>
                                <td colspan="8">
                                    <center>Empty</center>
                                </td>
                            </tr>
                            @endif
                        </tbody>
                    </table>
                    @if (count($bundle_order) > 0)
                    <center>{{ $bundle_order->appends(request()->input())->links() }}</center>
                    @endif
                </div>
            </div>
            <!-- END SAMPLE TABLE PORTLET-->
        </div>
    </div>
</section>
@stop

{{-- page level scripts --}}
@section('footer_scripts')
<script src="{!! asset('assets/vendors/select2/js/select2.js') !!}"></script>    
<script>

    function get_model(args)
    {
        
        var bundle_offer_order_id = args;
        
        if ( bundle_offer_order_id != '')
        {
        
          $.ajax({
                type: "GET",
                url: '',
                data: {bundle_offer_order_id: bundle_offer_order_id,ajx_search : true},
                success: function( data ) 
                {           
                //console.log(data);
                    if(data == false)
                    {
                        $('#model_body_'+args).empty();  
                        var tbl = "<table class='table table-striped border'><tr><th width='15%'>Bundle Name</th><th width='15%'>Content Type</th><th>Content Detail</th><th width='13%'>Download</th></tr>" ;

                        tbl =  tbl + "<tr><td colspan='4' class='text-center'>No Record Found</td></tr></table>";

                         $('#model_body_'+args).append(tbl);     
                    }
                    else
                    {
                         $('#model_body_'+args).empty();  

                          var tbl = "<table class='table table-striped border'><tr><th width='15%'>Bundle Name</th><th width='15%'>Content Type</th><th>Content Detail</th><th width='13%'>Download</th></tr>" ;

                        $.each(data, function(key,value) 
                        {                           
                            //console.log(value.content_title);
                            var date  = new Date(value['downloaded_on']*1000); 
                            var formattedDate = ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear();
                           tbl = tbl + "<tr><td>" + value['bundle_name'] + "</td><td>" + value['content_type'] + "</td><td>" + value['content_title'] + "</td><td>" + formattedDate + "</td></tr>";
                        }); 

                          $('#model_body_'+args).append(tbl);     
                 } 
               }                  
            }); 
        }
                    
    }; 

</script>
@stop