I am working on School Fee Payment Application. i want to achieve the following:
-
Allow payments of the school fees to be done and save into database.
-
Immediately after save button is clicked, it should send it as receipt directly to the printer. And also display it in PDF format.
I have successfully done No.1 (Allow payment to be save to database). Where I need help is
- Immediately after save button is clicked, it should send it as receipt directly to the printer. And also display it in PDF format.
How do I achieve this? I also want to use mPDF for this.
Controller
public function actionPayFees($sid, $fcid)
{
$model = new FeesPaymentTransaction();
$stuData = \app\modules\student\models\StuMaster::findOne($sid);
$FccModel = \app\modules\fees\models\FeesCollectCategory::findOne($fcid);
if($model->load(Yii::$app->request->post())) {
$model->created_at = new \yii\db\Expression('NOW()');
$model->created_by = Yii::$app->getid->getId();
$model->fees_pay_tran_collect_id = $fcid;
$model->fees_pay_tran_stu_id = $stuData->stu_master_id;
$model->fees_pay_tran_batch_id = $stuData->stu_master_batch_id;
$model->fees_pay_tran_course_id = $stuData->stu_master_course_id;
$model->fees_pay_tran_section_id = $stuData->stu_master_section_id;
if(!empty($model->fees_pay_tran_date)) {
$model->fees_pay_tran_date = Yii::$app->dateformatter->getDateFormat($model->fees_pay_tran_date);
}
if(!empty($model->fees_pay_tran_cheque_date)) {
$model->fees_pay_tran_cheque_date = Yii::$app->dateformatter->getDateFormat($model->fees_pay_tran_cheque_date);
}
if($model->save() && $model->validate())
return $this->redirect(['pay-fees', 'sid' => $sid, 'fcid'=>$fcid]);
}
return $this->render('create', [
'model' => $model,
'stuData' => $stuData,
'FccModel'=> $FccModel,
]);
}
Models
public function attributeLabels()
{
return [
'fees_pay_tran_id' => Yii::t('fees', 'Receipt No.'),
'fees_pay_tran_collect_id' => Yii::t('fees', 'Fees Collect Name'),
'fees_pay_tran_stu_id' => Yii::t('fees', 'Student Name'),
'fees_pay_tran_batch_id' => Yii::t('fees', 'Batch Name'),
'fees_pay_tran_course_id' => Yii::t('fees', 'Course Name'),
'fees_pay_tran_section_id' => Yii::t('fees', 'Section Name'),
'fees_pay_tran_mode' => Yii::t('fees', 'Payment Mode'),
'fees_pay_tran_cheque_no' => Yii::t('fees', 'Cheque No'),
'fees_pay_tran_cheque_date' => Yii::t('fees', 'Cheque Date'),
'fees_pay_tran_bank_id' => Yii::t('fees', 'Bank Name'),
'fees_pay_tran_bank_branch' => Yii::t('fees', 'Bank Branch'),
'fees_pay_tran_amount' => Yii::t('fees', 'Amount'),
'fees_pay_tran_date' => Yii::t('fees', 'Payment Date'),
];
}
View
<?php $form = ActiveForm::begin([
'id'=>'fees-collect-form',
'errorSummaryCssClass' => 'error-summary text-red',
'fieldConfig' => [
'template' => "{label}{input}{error}",
]]);
?>
<?= $form->errorSummary($model);?>
<!--If select payment mode cash to show this block-->
<div class="col-xs-12 col-sm-12 col-lg-12 no-padding chk-cash">
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_mode')->dropDownList(['1'=>Yii::t('fees', 'Cash'), '2'=>Yii::t('fees', 'Cheque')]);?>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_date')->widget(yii\jui\DatePicker::className(),
[
'model'=>$model,
'attribute'=>'fees_pay_tran_date',
'clientOptions' =>[
'dateFormat' => 'dd-mm-yyyy',
'changeMonth'=> true,
'yearRange'=>(date('Y')-5).':'.(date('Y')+5),
'changeYear'=> true,
'readOnly'=>true,
'autoSize'=>true,
'buttonImage'=> Yii::$app->homeUrl."images/calendar.png",
],
'options'=>[
'class'=>'form-control',
'placeholder' => $model->getAttributeLabel('fees_pay_tran_date')
],
]) ?>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_amount')->textInput(['maxlength' => 10, 'placeholder' => $model->getAttributeLabel('fees_pay_tran_amount')]) ?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12 no-padding cash-data">
<div class="col-xs-12 col-sm-4 col-lg-4">
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
</div>
</div>
<!--End payment mode cash-->
<div class="col-xs-12 col-sm-12 col-lg-12 no-padding cheque-data">
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_cheque_no')->textInput(['placeholder' => $model->getAttributeLabel('fees_pay_tran_cheque_no')]) ?>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_bank_id')->dropDownList(ArrayHelper::map(app\modules\fees\models\BankMaster::find()->where(['is_status'=>0])->all(), 'bank_master_id', 'bank_master_name'), ['prompt'=>'Select Bank']) ?>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_bank_branch')->textInput(['placeholder' => $model->getAttributeLabel('fees_pay_tran_bank_branch')]) ?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-lg-12 no-padding cheque-data">
<div class="col-xs-12 col-sm-4 col-lg-4">
<?= $form->field($model, 'fees_pay_tran_cheque_date')->widget(yii\jui\DatePicker::className(),
[
'model'=>$model,
'attribute'=>'fees_pay_tran_cheque_date',
'clientOptions' =>[
'dateFormat' => 'dd-mm-yyyy',
'changeMonth'=> true,
'yearRange'=>(date('Y')-5).':'.(date('Y')+5),
'changeYear'=> true,
'readOnly'=>true,
'autoSize'=>true,
'buttonImage'=> Yii::$app->homeUrl."images/calendar.png",
],
'options'=>[
'class'=>'form-control',
'placeholder' => $model->getAttributeLabel('fees_pay_tran_cheque_date')
],
]) ?>
</div>
<div class="col-xs-12 col-sm-4 col-lg-4"></div>
<div class="col-xs-12 col-sm-4 col-lg-4"></div>
</div>
<!--End cheque related field-->
<?php if(!$model->isNewRecord) { echo Html::a(Yii::t('fees', 'Cancel'),['pay-fees', 'sid'=>$stuData->stu_master_id, 'fcid'=>$FccModel->fees_collect_category_id], ['class' => 'btn btn-default']); } ?>
</div>
How do I achieve this? I also want to use mPDF for this.