<?php
use home\assets\MainAsset;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use home\modules\receivable\models\Billing;
use home\modules\receivable\models\BillingCategory;
use common\widgets\DatePicker;

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

$attrLabels = $model->attributeLabels();
$ContractBilling = Billing::getContractBilling($model->contract_no);
$form = ActiveForm::begin([
        'id' => 'main-form',
		'options' => ['class' => 'informationform f14'],
        'action' => $action,
		'fieldConfig' => [
			'options' => ['tag' => 'td'],
			'template' => "{input}{hint}{error}",
			'errorOptions' => ["class" => "error" ]
		]
    ]);
?>

<?php if(!empty($model->isNewRecord) && !empty($model->contract_no)) : ?>
	<table class="table task-table">
	    <tr>
	        <th width="22%">开票时间</th>
	        <th width="15%">开票金额</th>
	    </tr>
	    <?php if (empty($ContractBilling)) : ?>
        	<tr><td colspan="2" class="tac red">还没有任何开票记录...</td></tr>
       	<?php else : ?>
	        <?php foreach($ContractBilling as $v): ?>
	        	<tr>
		        <td><?= date('Y-m-d', $v['invoice_time']) ?></td>
		        <td><?= number_format($v['invoice_money'], 2 , '.' , ' ,') ?></td>
		        </tr>
		    <?php endforeach; ?>
	    <?php endif; ?>
	</table>
	<div class="ticket-rest">未开票金额：<span><?= Billing::getContractMoney($model->contract_no) ?></span></div>
<?php endif; ?>

<table cellpadding="0" cellspacing="10" width="100%">
	<tbody>
		<tr>
			<td align="right" width="80"><?= $model->getAttributeLabel('contract_no') ?>：</td>
			<input type="hidden" name="Billing[contract_no]" id="contract-id" value="<?= $model->contract_no ?>"/>
            <?php if(!empty($model->isNewRecord) && !empty($model->contract_no)) : ?>
                <?= $form
                    ->field($model, 'contract_name')
                    ->textInput([
                        'class' => 'form-control',
                        'readonly' => 'readonly'
                    ])
                ?>
            <?php else : ?>
                <?= $form
                    ->field($model, 'contract_name')
                    ->textInput([
                        'class' => 'form-control select-contract',
                        'placeholder' => '点击选择',
                        'data-hidden-id' => 'contract-id',
                        'data-url' => Url::to(['/link/contract']),
                        'data-title' => '选择合同'
                    ])
                 ?>
            <?php endif; ?>
			<td><span class="redstar">*</span></td>

			<td align="right"><?= $model->getAttributeLabel('category_id') ?>：</td>
			<td><select class="form-control" name="Billing[category_id]">
                    <?php echo BillingCategory::getDropDownTree($model->category_id, 0, true, 'cat_id'); ?>
                </select>
                <div class="error"></div>
            </td>
			<td><span class="redstar">*</span></td>
		</tr>
		<tr>
			<td align="right"><?= $model->getAttributeLabel('invoice_no') ?>：</td>
			<?= $form->field($model, 'invoice_no')->textInput(['class' => 'form-control', 'readonly' => ($model->isNewRecord) ? false : true]) ?>
			<td><span class="redstar">*</span></td>
			<td align="right"><?= $model->getAttributeLabel('invoice_name') ?>：</td>
			<?= $form->field($model, 'invoice_name')->textInput(['class' => 'form-control project_name']) ?>
			<td><span class="redstar">*</span></td>
		</tr>
		<tr>
			<td align="right"><?= $model->getAttributeLabel('invoice_money') ?>：</td>
			<?= $form->field($model, 'invoice_money')->textInput(['class' => 'form-control']) ?>
			<td><span class="redstar">*</span></td>
			<td align="right"><?= $model->getAttributeLabel('invoice_time') ?>：</td>
			<?= DatePicker::widget(['model' => $model, 'form' => $form, 'attribute' => 'invoice_time', 'inputConfig' => ['class' => 'form-control'], 'dateConfig' => ['maxDate' => '%y-%M-%d']]) ?>
			<td><span class="redstar">*</span></td>
		</tr>
		<tr>
			<td align="right"><?= $model->getAttributeLabel('vbrk') ?>：</td>
			<?= $form->field($model, 'vbrk')->textInput(['class' => 'form-control']) ?>
			<td><span class="redstar">*</span></td>
			<td align="right"><?= $model->getAttributeLabel('drawer') ?>：</td>
			<?= $form->field($model, 'drawer')->textInput(['class' => 'form-control', 'disabled'=>'true']) ?>
			<td><span class="redstar">*</span></td>
		</tr>
	</tbody>
</table>
<?= ($model->isNewRecord) ? '' : Html::hiddenInput('id' ,$model->record_id); ?>
<?php ActiveForm::end(); ?>
