Formatted Table with Dynamic Columns

I am working on School Fees Payment by Students and I have these two(2) Model Classes for the table.

1. fee_payment_transaction

    public function attributeLabels()
{
    return [
        'fee_pay_tran_id' => Yii::t('fees', 'Receipt No.'),
        'fee_pay_student' => Yii::t('fees', 'Student ID'),
        'fee_pay_class' => Yii::t('fees', 'Class'),
        'fee_pay_class_assign_id' => Yii::t('fees', 'Payable Amount'),
        'payment_mode' => Yii::t('fees', 'Payment Mode'),
        'transaction_date' => Yii::t('fees', 'Payment Date'),
        'transaction_amount' => Yii::t('fees', 'Amount Paid'),          
    ];
}

2. fee_assign

    public function attributeLabels()
{
    return [
        'fee_assign_id' => Yii::t('fees', 'Fee Assign ID'),
        'fee_assign_class_id' => Yii::t('fees', 'Class'),
        'fee_assign_amount' => Yii::t('fees', 'Payable Amount'),
    ];
}

fee_pay_class_assign_id is a foreign key that is related to fee_assign_id in fee_assign. It picks the fee_assign_amount.

The students are allowed to pay in installments in n. So, it will be First Payment, Second Payment … n Payment.

The FeePayment result is generated based on Students Class. I want the result to be as shown in the diagram below:

Controller

    public function actionFeePayment()
{
    $model = new FeePaymentTransaction();

return $this->render('collect', [
	'model' => $model,
]);       
}

I was trying to do it as shown below, but don’t know how to continue:

   <div class="box-body table-responsive no-padding">
 <?php
if(!empty($model)) {
	echo '<table class="table table-striped">';
	echo '<tr>';
	echo '<th class="text-center">'.Yii::t('fees', 'SI No.').'</th>';
	echo '<th>'.Yii::t('fees', 'Student ID').'</th>';
	echo '<th>'.Yii::t('fees', 'Class').'</th>';
	echo '<th>'.Yii::t('fees', 'Payable Amount').'</th>';
	echo '</tr>';
	$sr = 1;
	foreach($model as $key=>$value) {

Kindly assist. Thanks

Hi Folumikeidowu,

If I am not wrong the concept is the model fee_assign => fee_payment_transaction relation is One to Many

Define your one to may relation in your FeeAssign class as follows

/**
 * 
 * @return Active Records of Array
 */
public function getTransactions() {
    return $this->hasMany(FeePaymentTransaction::className(), ['fee_assign_id' => 'fee_pay_class_assign_id']);
}

Then in the view file you can loop through all fees payments from FeePaymentTransaction !!!

$feeAssignModel = new FeeAssign();
foreach($feeAssignModel->transactions as $feeData){
    //Do your table Looping
}