<?php
use yii\helpers\Url;
use home\modules\contract\models\Contract;
use home\assets\LinkAsset;

/* @var $this \yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \home\modules\task\models\Category */
LinkAsset::register($this);

$this->title = '添加合同';

//默认值
if ($model->isNewRecord) {
    $model->contract_no = Contract::getNo();
	$model->sort = 0;
	$model->status = 1;
    $model->signing_time = date('Y-m-d',time());
    $model->due_time = date('Y-m-d',strtotime("+1 year"));
    $model->owner_name = Yii::$app->user->identity->realname;
    $model->owner_id = Yii::$app->user->identity->user_id;
    $model->collate_status = 0;
    $model->money = 0;
    $model->maint_period=0;
} else {
    $model->customer_name = empty($model['customer']['name'])?'':$model['customer']['name'];
    $model->real_customer_name = empty($model['realCustomer']['name'])?'':$model['realCustomer']['name'];
    $model->owner_name = empty($model['user']['realname'])?'':$model['user']['realname'];
    if(strtotime($model['signing_time']) == false){
        $model->signing_time = date('Y-m-d',$model['signing_time']);
    }
    if(strtotime($model['due_time']) == false){
        $model->due_time = date('Y-m-d',$model['due_time']);
    }
    if(strtotime($model['acceptance_time']) == false){
        $model->acceptance_time = date('Y-m-d',$model['acceptance_time']);
    }
    if(strtotime($model['begin_time']) == false){
        $model->begin_time = date('Y-m-d',$model['begin_time']);
    }
    if(strtotime($model['end_time']) == false){
        $model->end_time = date('Y-m-d',$model['end_time']);
    }
}
?>

<div class="modal-window" >

	<?= \home\widgets\Alert::widget(); ?>

	<?= $this->render('_form', ['model' => $model, 'action' => $action]);  ?>

</div>
