<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<style>
    .ajaxeditspan{color: red;font-size: 6px;}
</style>
<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <!--<section>-->
                    <!--    <div class="container-fluid">-->
                    <!--        <div class="row">-->
                    <!--            <div class="col-sm-12">-->
                    <!--                <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".addaccountmoney">添加支付账单</button>-->
                    <!--            </div>-->
                    <!--        </div>-->
                    <!--    </div>-->
                    <!--</section>-->
                    <section style="margin-top: 10px;">
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                  <?php foreach($channelList as $id => $name){?>
                                    <a href="<?php echo base_url('#payment/checking/'.$id);?>" role="button" class="btn btn-success <?php if($channeltype == $id){echo 'active';}?>"><?php echo $name;?></a>
                                  <?php } ?>
                                </div>
                            </div>
                        </div>
                    </section>
                    <section style="margin-top: 10px;">
                      <div class="container-fluid">
                        <div class="row">
                          <div class="col-sm-12">
                            <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
                          </div>
                        </div>
                      </div>
                    </section>
                </aside>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="table-responsive">
                          <table class="table table-striped table-bordered table-hover">
                            <thead>
                              <tr>
                                <!--<th>货币</th>-->
                                <th>本地金额(美元)</th>
                                <!--<th>本地金额(港币)</th>-->
                                <th>平台费率(30%)<span class="ajaxeditspan">(双击编辑)</span></th>
                                <th>汇率<span class="ajaxeditspan">(双击编辑)</span></th>
                                <th>理论收入(港币)</th>
                                <!--<th><?php echo $channelname;?>汇总金额(港币)</th>-->
                                <th><?php echo $channelname;?>结算收入(港币)<span class="ajaxeditspan">(双击编辑)</span></th>
                                <!--<th>本地订单数</th>-->
                                <!--<th><?php echo $channelname;?>订单数</th>-->
                                <!--<th>相差金额(第三方-本地)</th>-->
                                <!--<th>相差比例(第三方-本地)/第三方</th>-->
                                <th>结算相差金额</th>
                                <th>结算相差比例</th>
                                <!--<th>本地财务收入<span class="ajaxeditspan"></span></th>-->
                                <!--<th>财务相差金额(第三方-本地)</th>-->
                                <th>时间</th>
                                <th>操作</th>
                              </tr>
                            </thead>
                            <tbody>
                              <?php foreach ($list as $val) {?>
                              <tr>
                                <!--<td><?php echo $currencyname[$val['other_currency']];?></td>-->
                                <td><?php echo $val['local_totalmoney'];?></td>
                                <!--本地金额(港币)-->
                                <!--<td><?php echo round($val['local_totalmoney'] * $val['exchange_rate'],2);?></td>-->
                                <td class="ajaxedit" mid="<?php echo $val['id'];?>" field="other_fee"><?php echo $val['other_fee'];?></td>
                                <td class="ajaxedit" mid="<?php echo $val['id'];?>" field="exchange_rate"><?php echo $val['exchange_rate'];?></td>
                                <!--理论收入(港币)-->
                                <td><?php echo round($val['local_totalmoney'] * $val['exchange_rate'] * (1-$val['other_fee']),2);?></td>
                                <!--汇总金额(港币)-->
                                <!--<td><?php echo number_format($val['other_totalmoney'], 2, '.', '');?></td>-->
                                <td class="ajaxedit" mid="<?php echo $val['id'];?>" field="other_income"><?php echo $val['other_income'];?></td>
                                <!--<td><?php echo $val['local_ordernum'];?></td>-->
                                <!--<td><?php echo $val['other_ordernum'];?></td>-->
                                <!--<th>相差金额(第三方-本地)</th>-->
                                <!--<td><?php echo round($val['other_totalmoney'] - $val['local_totalmoney']*$val['exchange_rate'],2);?></td>-->
                                <!--<th>相差比例(第三方-本地)/第三方</th>-->
                                <!--<td><?php echo round(($val['other_totalmoney'] - $val['local_totalmoney']*$val['exchange_rate'])/$val['other_totalmoney'], 4)*100;?>%</td>-->
                                <!--结算相差金额-->
                                <td><?php echo round($val['other_income'] - $val['local_totalmoney']*$val['exchange_rate']*(1-$val['other_fee']), 2);?></td>
                                <!--结算相差比例-->
                                <td><?php echo round(($val['other_income'] - $val['local_totalmoney']*$val['exchange_rate']*(1-$val['other_fee']) )/$val['other_income'], 4)*100;?>%</td>
                                <!--<td  mid="<?php echo $val['id'];?>" field="local_income"><?php echo $val['local_income'];?></td>-->
                                <!--<td><?php echo $val['other_income'] - $val['local_income'];?></td>-->
                                <td class="ajaxedit" mid="<?php echo $val['id'];?>"><?php echo date('Y-m', $val['check_time']);?></td>
                                <td>
                                   <input type="button" mid="<?php echo $val['id'];?>" class="btn btn-primary btn-sm commit-btn" field="confirm_btn" <?php if($val['confirm_btn']){echo 'disabled';}?>  value="<?php if($val['confirm_btn']){echo '已确认';}else{echo '是否确认';}?>"/>&nbsp;&nbsp;&nbsp;&nbsp;
                                    <input type="button" mid="<?php echo $val['id'];?>" class="btn btn-success btn-sm commit-btn" field="received_btn"  <?php if($val['received_btn']){echo 'disabled';}?>  value="<?php if($val['received_btn']){echo '已收款';}else{echo '是否收款';}?>"/></td>
                              </tr>
                              <?php } ?>
                            </tbody>
                          </table> 
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<div class="modal fade addaccountmoney" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">支付渠道账单</h4>
      </div>
    <form action="<?php echo base_url('payment/actionChecking');?>" method="post" class="form-horizontal" data-sendingText="提交中">
      <div class="modal-body">
            <div class="form-group">
                <label class="col-sm-3 control-label">支付渠道:</label>
                <div class="col-sm-9">
                    <label class="select-inline">
                        <select class="form-control" name="pay_channel">
                          <option value="1">GooglePlay</option>
                          <option value="2">IOS</option>
                        </select>
                    </label>
                </div>
            </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">收入:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="pay_money">
                </label>
            </div>
          </div>
          <div class="form-group">
            <label for="message-text" class="col-sm-3 control-label">订单数量:</label>
            <div class="col-sm-9">
                <label class="input-inline">
                    <input type="text" class="form-control" name="pay_ordernum">
                </label>
            </div>
          </div>
          <div class="form-group">
              <label for="message-text" class="col-sm-3 control-label">财务收入:</label>
              <div class="col-sm-9">
                  <label class="input-inline">
                      <input type="text" class="form-control" name="other_income">
                  </label>
              </div>
          </div>
          <div class="form-group">
                <label class="col-sm-3 control-label">货币:</label>
                <div class="col-sm-9">
                    <label class="select-inline">
                        <select class="form-control" name="pay_currency" id="pay_currency">
                          <option value="1">美元</option>
                          <option value="2">港币</option>
                        </select>
                    </label>
                </div>
          </div>
          <div class="form-group">
              <label for="message-text" class="col-sm-3 control-label">汇率:</label>
              <div class="col-sm-9">
                  <label class="input-inline">
                      <input type="text" class="form-control" name="exchange_rate" value="1">  本地货币 对 对账货币汇率
                  </label>
              </div>
          </div>
          <div class="form-group">
                <label class="col-sm-3 control-label">日期:</label>
                <div class="col-sm-9">
                    <label class="select-inline">
                        <input type="input" name="pay_time" class="form-control datetimepicker">
                    </label>
                </div>
          </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
      </div>
    </form>
    </div>
  </div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript">
Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: '<?php echo $channelname?>与本地金额对比'
    },
    xAxis: {
        categories: [<?php echo "'".implode("','", $dateList)."'";?>],
        crosshair: true
    },
    yAxis: {
        min: 0,
        title: {
            text: '金额总数'
        }
    },
    tooltip: {
        headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
        pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
            '<td style="padding:0"><b>{point.y:.1f} </b></td></tr>',
        footerFormat: '</table>',
        shared: true,
        useHTML: true
    },
    plotOptions: {
        column: {
            pointPadding: 0.2,
            borderWidth: 0
        }
    },
    series: [{
        name: '<?php echo $channelname?>总额',
        data: [<?php echo implode(',', $other_totalmoney);?>]

    },{
        name: '本地总额(港币)',
        data: [<?php echo implode(',', $local_totalmoney);?>]

    }]
});
</script>
<script>
    //选择日期
    $('.datetimepicker').datepicker({
        language:'zh-CN',
        format:'yyyy-mm',
        zIndexOffset:906  //控制z-index
    });

    //ajax编辑
    $('.ajaxedit').dblclick(function(){
        var id = $(this).attr('mid');
        var field = $(this).attr('field');

        var td = $(this);
        var tbVal = td.text();
        var txt = $("<input type='text'>").val(tbVal);
        txt.blur(function(){
            var newText = $(this).val();
            $.post(
                "<?php echo base_url('payment/ajaxEditIncome');?>",
                {id:id, field:field, val:newText}
            );
            // 移除文本框,显示新值
            $(this).remove();
            td.text(newText);

            //输入第三方后刷新
            if(field == 'other_income' || field == 'other_fee' || field == 'exchange_rate'){
                location.reload();
            }
        });
        td.text("");
        td.append(txt);

    });

    //是否确认或者收款
    $('.commit-btn').click(function () {
        var id = $(this).attr('mid');
        var field = $(this).attr('field'),
            msg;
        if(field == 'confirm_btn') {
            msg = '确认';
        }else{
            msg = '收款';
        }
        if( confirm('是否进行'+ msg + '操作?')){
            console.log('aaaaa');
            $.post(
                "<?php echo base_url('payment/ajaxEditIncome');?>",
                {id:id, field:field, val:1}
            );
            location.reload();
        }

    });

	
	//默认汇率
	$("body").on("change","#pay_currency",function(){
		if($(this).val() == '1'){
			$("input[name='exchange_rate']").val(1);
		}else if($(this).val() == '2'){
			$("input[name='exchange_rate']").val(7.7919);
		}
	})
</script>