<?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\Verify;
use home\modules\reimbursement\models\Application;
use home\modules\reimbursement\models\ApplicationCategory;

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

$assetUrl = $this->getAssetManager()->getBundle(MainAsset::className())->baseUrl;
$this->registerJsFile($assetUrl . '/js/reim.index.js', ['depends' => MainAsset::className()]);
$this->registerJsFile($assetUrl . '/js/application.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 (Application::checkAccess('view', $model->appli_id)) : ?>
                    <button title="编辑" type="button" data-url='<?= Url::to([$this->context->id . '/view', 'id' => $model->appli_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 (Application::checkAccess('delete', $model->appli_id)) : ?>
                    <button title="删除" type="button" onclick="if (!confirm('确认删除?'))
                                return false;
                            javascript:window.location.href = '<?= Url::to(['delete', 'id' => $model['appli_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-height="300" data-width='600' data-url='<?= Url::to([$this->context->id . '/create']) ?>' data-title='新增申请' class="btn btn-default btn-task open-dialog">
                        <i class="icon-plus"></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'] == Application::ISVERIFY_WAIT) {
                        echo '<font color="green">待审核</font>';
                    } elseif ($model['isverify'] == Application::ISVERIFY_ENABLE) {
                        echo '<font color="green">通过</font>';
                    } else {
                        echo '<font color="red">否决</font>';
                    }
                ?>
            </p>
            
            <?php if (Application::checkAccess('set-status', $model->appli_id)) : ?>
            <select class="form-control tasklist-form change-status-select" data-set-url="<?= Url::to(['set-status', 'id' => $model['appli_id']]) ?>">
                <option value="" >请审核</option>
                <option value="<?= Application::ISVERIFY_ENABLE ?>">通过</option>
                <option value="<?= Application::ISVERIFY_DISABLE ?>">否决</option>
            </select>
            <?php endif; ?>

            <?php if (Application::readAccess('reimbursement/reimbursement/change-isused')) : ?>
            <select class="form-control tasklist-form change-isused-select" data-set-url="<?= Url::to(['set-isused', 'id' => $model['appli_id']]) ?>">
                <option value="" >使用状态</option>
                <option <?= (isset($model['isused']) && ($model['isused'] == Application::ISUSED_ENABLE)) ? 'selected="selected"' : ''; ?> value="<?= Application::ISUSED_ENABLE ?>">未使用</option>
                <option <?= (isset($model['isused']) && ($model['isused'] == Application::ISUSED_DISABLE)) ? 'selected="selected"' : ''; ?> value="<?= Application::ISUSED_DISABLE ?>">已使用</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'])]) ?>">
                            <?= ArrayHelper::getValue($data, 'name'); ?>
                        </a>
                    </td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">申请金额</td>  
                    <td width="30%"><?= $model['money'] ?></td>
                    <td width="20%" class="table-blue">创建时间</td>  
                    <td width="30%"><?= date('Y-m-d', $model['create_time']) ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">使用状态</td>  
                    <td width="30%"><?= ($model['isused'] == Application::ISUSED_ENABLE) ? '<font color="green">未使用</font>' : '<font color="red">已使用</font>' ?></td>
                    <td width="20%" class="table-blue">类别</td>  
                    <td width="30%"><?= ApplicationCategory::getNameWithAllParents($model['category_id']) ?></td>
                </tr>
                <tr>
                    <td width="20%" class="table-blue">审核人</td>
                    <td colspan="3"><?= implode(',', ArrayHelper::getColumn(\common\models\User::getUserByDot($model['verify_ids']), 'realname')) ?></td>
                </tr>
                <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 fix">
            <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->appli_id]) ?>";
    var enable = <?= Application::ISVERIFY_ENABLE ?>;
    var disable = <?= Application::ISVERIFY_DISABLE ?>;
</script>