对于一个项目,我需要Invoice Taxes
根据表单生成一个表格Purchase order details
形式Invoice
。当我选择该po_number
字段时,它将在 url 上附加值并刷新名为paticular
. 我已经成功地生成了表单,并且为表格表单部分生成了行,并被插入到Invoice Taxes
表中,但只有invoice_id
andinvoice_amt
被插入。
这是我的表格Invoice
<div class="invoice-form">
<?php $form = ActiveForm::begin(['id' => 'dynamic-form','options' => ['enctype' => 'multipart/form-data']]);
<div class="col-md-12">
<div class="col-md-4">
<?= $form->field($model, 'po_number')->textInput(['readonly' => true,'maxlength' => true]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model,'po_number')->dropDownList(
ArrayHelper::map(purchaseorder::find()->where(['type'=> 2])->all(),'id','po'),
['prompt'=>'Select PO ', 'onchange' => '
var poid;
poid=$(this).val();
//alert(poid);
var url = "index.php?r=invoice/create&pod="+poid;
$.pjax({url: url, container: "#particular"});
'
]);
?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'invoice_no')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'net_amt')->textInput() ?>
</div>
</div>
<div class="col-md-12">
<div class="col-md-4">
<?php
if (isset(Yii::$app->request->queryParams['customer'])) {
$customer= Yii::$app->request->queryParams['customer'];
$customers = customer::find()->where(['id'=>$customer])->all();
$listdata =ArrayHelper::map($customers,'id','name');
?>
<?=
$form->field($model,'customerid')->widget(Select2::classname(),
[
'data' => $listdata,
//'data' => ArrayHelper::map(customer::find()->where(['id'=>$customer])->One(),'id','name'),
'language' => 'english',
'options' => ['placeholder' => 'Customer','id'=>'customer'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
<?php
$serviceid= Yii::$app->request->queryParams['service'];
$servi = service::find()->where(['id'=>$serviceid])->all();
$listdata =ArrayHelper::map($servi,'id','name');
?>
<?php
}
else
{
$cust = new customer();
$customers = customer::find()->where(['id'=>$cust->id])->all();
$listdata =ArrayHelper::map($customers,'id','name');
?>
<?php
}
?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'po_desc')->textInput(['readonly' => true,'maxlength' => true]) ?>
<?= $form->field($model, 'status')->dropDownList(['Sent'=>'Sent','On hold'=>'On hold', 'Partially Recieved'=>'Partially Recieved','Fully Paid'=>'Fully Paid']); ?>
</div>
</div>
<div class='clearfix'></div>
<?php Pjax::begin(['id' => 'particular']) ?>
<div id=''>
<?php
// **********************************
// * Here the tabular form part start
// **********************************
if ( isset($_GET['pod']) ) {
$id = $_GET['pod'];
$modelPods = purchaseorderdetails::findAll(['purchaseorderid' => $id]);
/* $length = purchaseorderdetails::find()->where(['purchaseorderid' => $id])->count();
$x = 0;
foreach ( $modelPods as $pod ) {
$tempNet[$x] = $pod->net_amt;
$x++;
} */
foreach ( $modelPods as $pod ) {
//for ( $i = 0; $i < $length; $i++ ) {
echo '<div class="" style="border: 1px solid #ccc; border-radius: 2px; padding-top: 5px; margin-bottom:10px;">';
foreach ( $modelTaxes as $i => $data ) {
?>
<div class='col-md-2'>
<?= $form->field($data, '[$i]net_amt')->textInput(['value' => $pod->net_amt]) ?>
</div>
<div class='col-md-1'>
<?= $form->field($data, '[$i]ST')->textInput() ?>
</div>
<div class='col-md-2'>
<?= $form->field($data, '[$i]SBC')->textInput(['maxlength' => true]) ?>
</div>
<div class='col-md-2'>
<?= $form->field($data, '[$i]KKC')->textInput(['maxlength' => true]) ?>
</div>
<div class='col-md-1'>
<?= $form->field($data, '[$i]Vat')->textInput() ?>
</div>
<div class='col-md-2'>
<?= $form->field($data, '[$i]total')->textInput() ?>
</div>
<div class='col-md-2'>
<?= $form->field($data, '[$i]invoice_amt')->textInput() ?>
</div>
<?php // $form->field($data, '[]invoice_id')->hiddenInput()->label(false) ?>
<?php
}
echo '<div class="clearfix"></div>';
echo '</div>';
}
}
?>
</div>
<?php Pjax::end() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
这是控制器
$model = new invoice();
// $model_po = new purchaseorder();
$modelTaxes = [new InvoiceTaxes];
if ($model->load(Yii::$app->request->post())) {
$modelTaxes = Model::createMultiple(InvoiceTaxes::classname());
Model::loadMultiple($modelTaxes, Yii::$app->request->post());
$p =purchaseorder::find()->where(['id'=>$model->abc])->one();
$poid = $model->abc;
$model->poid =$poid;
$model->type ='External';
$model->po_date = $p->orderdate;
$po_noo = purchaseorder::find()->where(['id'=>$model->poid])->One();
$model->po_number =$po_noo->po;
$valid = $model->validate();
$valid = Model::validateMultiple($modelTaxes) && $valid;
$count = invoice::find()->where(['invoice_no' => $model->invoice_no])->count();
if($count > 0) {
Yii::$app->getSession()->setFlash("error", "Same Invoice No. is already in used, please use another one");
return $this->render('create', [
'model' => $model,
]);
}
if ($flag = $model->save(false)) {
foreach ($modelTaxes as $data) {
$data->invoice_id = $model->id;
if (! ($flag = $data->save(false))) {
$transaction->rollBack();
break;
}
}
}
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
'modelTaxes' => (empty($modelTaxes)) ? [new InvoiceTaxes] : $modelTaxes,
]);
}