<?php
use yii\helpers\Url;
use home\assets\MainAsset;
use yii\helpers\ArrayHelper;
use home\modules\reimbursement\models\Application;

/* @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/link.js', ['depends' => MainAsset::className()]);

if (empty($form_name)) {
	$this->registerJsFile($assetUrl . '/js/application.js', ['depends' => MainAsset::className()]);
} else {
	$this->registerJsFile($assetUrl . '/js/verify.js', ['depends' => MainAsset::className()]);
}

$this->title = '费用申请编辑';

//默认值
if ($model->isNewRecord) {
	$model->create_time = date('Y-m-d', time());
	$model->isused = 0; //默认申请单为解绑状态
	//自动填充审核人信息
	$model->verify_names = Application::getDeptLeader()['leader_name'];
	$model->verify_ids = Application::getDeptLeader()['leader_id'];
} else {
	$model->link_name = ArrayHelper::getValue(common\models\Common::getLinkData($model->link_type, $model->link_id), 'name');
	$model->verify_names = implode(',', ArrayHelper::getColumn(\common\models\User::getUserByDot($model->verify_ids), 'realname'));
	$model->create_time = date('Y-m-d', $model->create_time);
	$model->verify_status = 1; //审核页面默认选择通过
}

//关联权限判断
$linkArr = [];
if (Application::readAccess('reimbursement/application/link-customer')) {
	$linkArr[] = 'customer';
}
if (Application::readAccess('reimbursement/application/link-opportunity')) {
	$linkArr[] = 'sale_opportunity';
}
?>

<div class="modal-window">
	<?= \home\widgets\Alert::widget(); ?>
	<?= !empty($form_name) ? $this->render($form_name, ['model' => $model, 'verify' => $verify, 'verifys' => $verifys, 'action' => $action]): $this->render('_form', ['model' => $model, 'action' => $action, 'linkArr' => $linkArr])?>
</div>