@extends('cp.web.layouts.admin')

@section('content')
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">书籍列表</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="panel">
    <form action=''>
        <input type="hidden" class="btn btn-success" name='from_device' value='{{ @$from_device }}'/>
        <div class="form-group">
            <label>书名</label>
            <input class="form-control" name="book_name" value="{{ @$params['book_name'] }}">
        </div>
        <div class="form-group">
            <label>书籍id</label>
            <input class="form-control" name="book_id" value="{{ @$params['book_id'] }}">
        </div>
        @if(session('cp_manage_auth') && session('cp_manage_auth') ==1)
            <div class="form-group">
                <label>cp</label>
                <select class="form-control" name="cp_user_id" placeholder="cp" id="cp-inpt">
                    <option value=""></option>
                    @foreach($cps as $cp)
                        @if($params['cp_user_id'] && $cp->id == $params['cp_user_id'] )
                            <option value="{{$cp->id}}" selected>{{$cp->username}}</option>
                        @else
                            <option value="{{$cp->id}}">{{$cp->username}}</option>
                        @endif
                    @endforeach
                </select>
            </div>
        @endif
        <div class="form-group">
            <label>选择时间：</label>
            <input  name="start_time" onClick="WdatePicker()" onfocus="WdatePicker({dateFmt:'yyyy-MM'})" value="{{ @$params['start_time'] }}"> -
            <input name="end_time" onClick="WdatePicker()" onfocus="WdatePicker({dateFmt:'yyyy-MM'})" value="{{ @$params['end_time'] }}">
        </div>
        <button type="submit" class="btn btn-success">查询</button>
        <button type="button" class="btn btn-success" onclick="record_export()">导出</button>
                        
    </form>
</div>

<div>
<p>数据说明：</p>
<p>1、下表有个 统计时间(截止零点) 字段，代表当月1号到计算的这一天为止的“累加”数据</p>
<p>2、每个月1号会计算上一个月的汇总数据</p>
</div>

<div class="panel panel-default">
    
    <div class="panel-heading">
        列表
    </div>
    <!-- /.panel-heading -->
    <div class="panel-body">
         <div class="dataTable_wrapper">
             <table class="table table-striped table-bordered table-hover" id="dataTables-example" style="text-align: center">
                <tr>
                    <th>月份</th>
                    <th>统计时间(截止零点)</th>
                    @if(session('cp_manage_auth') && session('cp_manage_auth') ==1)
                     <th>CP</th>
                    @endif
                    <th>书名</th>
                    <th>书籍ID</th>
                    <th>本月订阅量(书币)</th>
                    <th>可分成金额</th>
                    <th>当日分成收入</th>
                    <th>累计分成金额</th>
                </tr>
                @foreach ($records as $record)
                <tr >
                    <td>{{ $record->month }}</td>
                    <td>{{ $record->calculate_date }}</td>
                    @if(session('cp_manage_auth') && session('cp_manage_auth') ==1)
                     <td>{{ $record->cp_source }}</td>
                    @endif
                    <td>{{ $record->book_name }}</td>
                    <td>{{ $record->bid }}</td>
                    <td>{{ $record->total_amount }}</td>
                    <td>{{ $record->available_amount }}</td>
                    <td>{{ sprintf('%.2f',$record->last_amount - $record->before_last_amount) }}</td>
                    <td>{{ $record->last_amount }}</td>
                </tr>
                @endforeach
            </table>
        </div>
       <div class="paging">
            总计：{{ $records->total() }}
           {{ $records->links() }}
         </div>
    </div>
</div>

<script type="text/javascript" src="{{ asset('js/My97DatePicker/WdatePicker.js') }}"></script>
<script>
	function record_export()
	{
	    $('form').attr('action',"/api/book/record_export");
	    $('form').submit().attr('action','');
	}
</script>
@endsection
