<?php
use home\assets\MainAsset;
use home\assets\MenuAsset;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use home\modules\reimbursement\models\reimbursement;
use yii\widgets\ActiveForm;
use yii\helpers\StringHelper;
use common\assets\ZTreeAsset;
use common\assets\My97DatePickerAsset;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\reimbursement\models\Reimbursement */

My97DatePickerAsset::register($this);
MenuAsset::register($this);
ZTreeAsset::register($this);

$assetUrl = $this->getAssetManager()->getBundle(MenuAsset::className())->baseUrl;
$this->registerJsFile($assetUrl . '/js/reim.list.tree.js', ['depends' => ZTreeAsset::className()]);

$this->title = '报销统计';
?>

<!--container-->
<div class="container container-project">
    <div class="tab-column">
        <div class="tab-right">
            <button type="button" data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-title="我要报销" data-width="600" data-height="380" class="btn btn-default btn-task open-dialog">
                <a href="javascript:;" >我要报销</a>
            </button>
        </div>
        <p class="caption">报销统计</p>
    </div>

    <?php
        $action = isset($action) ? $action : $this->context->id . '/statistics';
        $searchForm = ActiveForm::begin([ 'id' => 'search-form', 'action' => [$action, 'id' => $id], 'method' => 'get']);
    ?>
    <div class="task-title-date">
        <p class="lefttitle" style="margin-right: 25px;">
            视图：<a href="<?= Url::to([$this->context->id . '/statistics', 'map' => 'month', 'id' => $id]) ?>">本月</a>
            <a href="<?= Url::to([$this->context->id . '/statistics', 'map' => 'week', 'id' => $id]) ?>">本周</a>
            <a href="<?= Url::to([$this->context->id . '/statistics', 'type' => 'reim', 'id' => $id]) ?>">我的报销</a>
            <a href="<?= Url::to([$this->context->id . '/statistics', 'type' => 'verify', 'id' => $id]) ?>">我的审核</a>

            <p class="searchfl">
                <span class="fl">&nbsp;从</span>
                <input type="text" id="reimbursement-begin_time" value="<?= isset($get['begin_time'])?$get['begin_time']:'' ?>" class="form-control fl date-form-control search-form" style="width: 10%" name="begin_time" 
                    onfocus="WdatePicker({&quot;maxDate&quot;:&quot;#F{$dp.$D(\'reimbursement-end_time\')}&quot;,&quot;readOnly&quot;:true,&quot;dateFmt&quot;:&quot;yyyy-MM-dd&quot;})">

                <span class="fl">&nbsp;至</span>
                <input type="text" id="reimbursement-end_time" value="<?= isset($get['end_time'])?$get['end_time']:'' ?>" class="form-control fl date-form-control search-form" style="width: 10%" name="end_time" 
                    onfocus="WdatePicker({&quot;minDate&quot;:&quot;#F{$dp.$D(\'reimbursement-begin_time\')}&quot;,&quot;readOnly&quot;:true,&quot;dateFmt&quot;:&quot;yyyy-MM-dd&quot;})">

                <button type="submit" class="btn btn-primary task-sou fl">搜索</button>
                <button type="button" class="btn  fl task-sou btn-default reset_search">重置</button>
            </p>
        </p>
    </div>
    <?php ActiveForm::end(); ?>
    
    <?= \home\widgets\Alert::widget(); ?>
    
    <!--mainbody-->
    <div class="mainbody fix">
        <div class="mainleft">
            <div class="labellink fix"> 
                <a href="javascript:;" id="labelLink">人员</a>
                <!-- <a href="javascript:;" id="labelLink">任务</a>  -->
                <a href="javascript:;" id="labelLink" class="labelfocus">类别</a> 
            </div>
            <div class="lefttree-user"  style="display: none;">
                <ul id="tree"  class="ztree"></ul>
            </div>
            <div class="lefttree-task" style="display: none;">
                <ul id="task-tree" class="ztree" data-tree-list-url="<? Url::to(['/task/task/ajax-get-tree-data']) ?>" ></ul>
            </div>
            <div class="lefttree-category">
                <ul id="category-tree"  class="ztree"  ></ul>
            </div>
        </div>
        <div class="mainright">
            <table class="table task-table">
                <tr>
                    <th width="20%">报销类别</th>
                    <th width="10%">报销数量</th>
                    <th width="15%">总金额</th>
                    <th width="10%">总张数</th>
                    <th width="10%">未审核</th>
                    <th width="10%">通过</th>
                    <th width="10%">否决</th>
                    <!-- <th width="10%">操作</th> -->
                </tr>
                <?php if (empty($categorys)) : ?>
                    <tr><td colspan="5" class="tac red">还没有任何数据...</td></tr>
                <?php else : ?>
                    <?php $allCount = $allMoney = $allBill = $allWait = $allEnable = $allDisable = 0; ?>
                    <?php foreach ($categorys as $key =>$category) : ?>
                        <?php 
                            $allCount += $category['count'];
                            $allMoney += $category['money'];
                            $allBill += $category['bill'];
                            $allWait += $category['wait'];
                            $allEnable += $category['enable'];
                            $allDisable += $category['disable'];
                        ?>
                        <tr>
                            <td class='theleft-min'><?= $category['name'] ?></td>
                            <td><?= $category['count'] ?></td>
                            <td class='theright-min'><?= number_format($category['money'], 2 , '.' , ' ,') ?></td>
                            <td><?= $category['bill'] ?></td>
                            <td><?= $category['wait'] ?></td>
                            <td><?= $category['enable'] ?></td>
                            <td><?= $category['disable'] ?></td>
                            <!-- <td><a href="javascript:;">展开</a></td> -->
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>

                <tr>
                    <td class='theleft-min'>总计</td>
                    <td><?= $allCount ?></td>
                    <td class='theright-min'><?= number_format($allMoney, 2 , '.' , ' ,') ?></td>
                    <td><?= $allBill ?></td>
                    <td><?= $allWait ?></td>
                    <td><?= $allEnable ?></td>
                    <td><?= $allDisable ?></td>
                </tr>
            </table>
        </div>
    </div>
    <!--mainbody-->
</div>
<script>
    var default_date = "<?= date('Y-m-d') ?>";
    var CSRF = "<?= Yii::$app->request->getCsrfToken() ?>";
    var getTreeDataUrl = "<?= Url::to(['/blog/blog/get-treedata', '_csrf' => Yii::$app->request->getCsrfToken()]) ?>";
    var index = "<?= Url::to(['index']) ?>";
    var getCategory = "<?= Url::to(['get-category']) ?>";

    function zTreeOnClick(event, treeId, treeNode) {
        window.location.href="<?= Url::to([$this->context->id.'/index']) ?>"+"&ids="+treeNode.user_ids;
    }

    function categoryOnClick(event, treeId, treeNode) {
        window.location.href="<?= Url::to([$this->context->id.'/statistics']) ?>"+"&id="+treeNode.cat_id;
    }
</script>