<?php
use yii\helpers\Url;
use home\assets\MainAsset;
use home\modules\receivable\models\Billing;
use home\modules\contract\models\Contract;

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

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

$this->title = '新增开票记录';

//默认值
if ($model->isNewRecord) {
	//$model->invoice_no = Billing::getNo();
	$model->drawer =  Yii::$app->user->identity->realname;
	$model->create_time = date('Y-m-d', time());
    $contract_no = Yii::$app->request->get('contract_no');
    if (!empty($contract_no)) {
        $contract = Contract::findOne(['contract_no' => $contract_no]);
        $model->contract_no = $contract_no;
        $model->contract_name = $contract->name;
    }
} else {
	if (isset($model->contract)) {
    	$model['contract_name'] = $model->contract->name;
    } else {
        $model['contract_name'] = '';
    }
	$model->invoice_time = date('Y-m-d', $model->invoice_time);
}
?>

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