<?php
use home\assets\MainAsset;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use common\widgets\Editor;
use common\widgets\DatePicker;
use yii\helpers\ArrayHelper;
use yii\helpers\StringHelper;
use home\modules\reimbursement\models\Reimbursement;
use home\modules\reimbursement\models\Category;
use home\modules\reimbursement\models\Verify;
use home\modules\reimbursement\models\Application;

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

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

$this->title = '报销详情';
?>

<!--container-->
<div class="container manage-project fix">
  <?= $this->render('@home/views/site/_left-menu') ?>

    <!--manage-left -->
    <div class="manage-right">
        <div class="tab-column tab-manage">
            <div class="tab-right">
                <?php if (Reimbursement::checkAccess('view', $model->reim_id)) : ?>
                    <button title="编辑" type="button" data-url='<?= Url::to([$this->context->id . '/view', 'id' => $model->reim_id]) ?>' data-title="报销编辑" data-width="600" data-height="380" class="btn btn-default btn-task open-dialog">
                        <i class="icon-edit"></i>
                    </button>
                <?php endif; ?>

                <?php if (Reimbursement::checkAccess('delete', $model->reim_id)) : ?>
                    <button title="删除" type="button" onclick="if (!confirm('确认删除?'))
                                return false;
                            javascript:window.location.href = '<?= Url::to(['delete', 'id' => $model['reim_id'], 'from' => (isset($_GET['from'])) ? $_GET['from'] : '']) ?>'" class="btn btn-default btn-task">
                        <i class="icon-trash"></i>
                    </button>
                <?php endif; ?>

                <button title="我要报销" 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">
                    <i class="icon-dollar"></i>
                </button>
            </div>
            <p class="caption">报销详情</p>
        </div>
        <div class="task-title">
            <p class="lefttitle" title="<?= $model['name'] ?>"><span>用途：</span><?= StringHelper::truncate($model['name'], 30) ?>&nbsp;&nbsp;
            	<span>状态：</span>
            	<?php 
                    if ($model->isverify == Reimbursement::ISVERIFY_WAIT) {
                        echo '<font color="green">待审核</font>';
                    } elseif ($model->isverify == Reimbursement::ISVERIFY_ENABLE) {
                        echo '<font color="green">通过</font>';
                    } else {
                        echo '<font color="red">否决</font>';
                    }
                ?>
                &nbsp;&nbsp;
                <span>结算状态：</span>
                <?php 
                    if ($model->isclearing == Reimbursement::ISCLEARING_WAIT) {
                        echo '<font color="red">未结算</font>';
                    } else {
                        echo '<font color="green">已结算</font>';
                    }
                ?>
            </p>
            <?php if (Reimbursement::checkAccess('set-status', $model->reim_id)) : ?>
            <select class="form-control tasklist-form change-status-select" data-set-url="<?= Url::to(['set-status', 'id' => $model['reim_id']]) ?>">
                <option value="" >请审核</option>
                <option value="<?= Reimbursement::ISVERIFY_ENABLE ?>">通过</option>
                <option value="<?= Reimbursement::ISVERIFY_DISABLE ?>">否决</option>
            </select>
            <?php endif; ?>

            <?php if (Reimbursement::checkAccess('set-isclearing', $model->reim_id)) : ?>
            <select class="form-control tasklist-form change-isclearing-select" data-set-url="<?= Url::to(['set-isclearing', 'id' => $model['reim_id']]) ?>">
                <option value="" >请更改结算状态</option>
                <option value="<?= Reimbursement::ISCLEARING_WAIT ?>">未结算</option>
                <option value="<?= Reimbursement::ISCLEARING_ENABLE ?>">已结算</option>
            </select>
            <?php endif; ?>

        </div>
        <div class="mgt10">
            <table class="table task-table taskdetail-table">
                <tr>
                    <td width="20%" class="table-blue">用途</td>  
                    <td colspan="3"><?= $model->name ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">关联信息</td>  
                    <td colspan="3">
                        <?php $data = common\models\Common::getLinkData($model->link_type, $model->link_id); ?>
                        <a target="_blank" href="<?= Url::to([ArrayHelper::getValue($data,'link_type')['view_url'][0], 'id' => ArrayHelper::getValue($data, ArrayHelper::getValue($data,'link_type')['pk'])]) ?>">
                            [<?= common\models\Common::getLinkTypeData($model->link_type)['name'] ?>]
                            <?= ArrayHelper::getValue($data, 'name'); ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">产生日期</td>  
                    <td width="30%"><?= date('Y-m-d', $model->reim_time) ?></td>
                    <td width="20%" class="table-blue">报销人</td>
                    <td width="30%"><?= $model->reim_people ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">金额</td>  
                    <td width="30%"><?= $model->reim_money ?></td>
                    <td width="20%" class="table-blue">票据张数</td>
                    <td width="30%"><?= $model->bill_amount ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">类别</td>  
                    <td width="30%"><?= Category::getNameWithAllParents($model['category_id']) ?></td>
                    <td width="20%" class="table-blue">审核人</td>
                    <td width="30%"><?= implode(',', ArrayHelper::getColumn(\common\models\User::getUserByDot($model->verify_ids), 'realname')) ?></td>
                </tr>
                <?php if (!empty($model->application)) : ?>
                <tr>
                    <td width="20%" class="table-blue">申请单名称</td>  
                    <td width="30%">
                        <a target="_blank" href="<?= Url::to(['/reimbursement/application/detail', 'id' => $model->appli_id]) ?>">
                            <?= $model->application->name ?>
                        </a>
                    </td>
                    <td width="20%" class="table-blue">申请单状态</td>
                    <td width="30%">
                    	<?php 
                    	if (isset($model->application)) {
                            if ($model->application->isverify == Application::ISVERIFY_WAIT) {
                                echo '<font color="green">待审核</font>';
                            } elseif ($model->application->isverify == Application::ISVERIFY_ENABLE) {
                                echo '<font color="green">通过</font>';
                            } elseif ($model->application->isverify == Application::ISVERIFY_DISABLE) {
                                echo '<font color="red">否决</font>';
                            }
                        }
                        ?>
                    </td>
                </tr>
                <?php endif; ?>
                <tr>
                    <td width="20%" class="table-blue">备注</td>  
                    <td colspan="3"><?= $model->remark ?></td>
                </tr>
            </table>
        </div>
        <div class="task-title">
            <p class="lefttitle">审批记录：</p>
        </div>
        <div class="mgt10">
            <table class="table task-table taskdetail-table-min">
                <?php if (empty($verifys)) : ?>
                <tr><td colspan="6" style="text-align: center;">还没有任何审批记录...</td></tr>
                <?php else : ?>
                    <?php foreach ($verifys as $key =>$verify) : ?>
                        <tr>
                            <td width="10%" class="table-blue" >审批人</td>
                            <td width="15%" > <?= $verify->user->realname ?> </td>
                            <td width="20%" rowspan="2" class="table-blue">审批意见</td>
                            <td width="30%" rowspan="2"> <?= $verify->remark ?> </td>
                            <td width="10%" rowspan="2" class="table-blue">审核状态</td>
                            <td width="10%" rowspan="2">
                                <?php 
                                    if ($verify->status == Verify::STATUS_WAIT) {
                                        echo '<font color="green">待审核</font>';
                                    } elseif ($verify->status == Verify::STATUS_ENABLE) {
                                        echo '<font color="green">通过</font>';
                                    } else {
                                        echo '<font color="red">否决</font>';
                                    }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="10%" class="table-blue">批示时间</td>
                            <td width="15%" > <?= date('Y-m-d H:m:s', $verify->verify_time) ?> </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </table>
        </div>
    <!--manage-right--> 
</div>
<!--container-->
</div>
<script>
    var detail = "<?= Url::to(['detail', 'id' => $model->reim_id]) ?>";
    var enable = <?= Reimbursement::ISVERIFY_ENABLE ?>;
    var disable = <?= Reimbursement::ISVERIFY_DISABLE ?>;
</script>