« first day    last day (21 days later) » 

4:18 AM
You need to save annualleave model also which you find using above query.
 
4:30 AM
Annualleave::find()
->where(['staffNo'=>$model->staffNo])
->one();

$leaveAllo = $annualleave->leaveAllocation;
$leave_Allo = $leaveAllo - $workDay;
$model->leaveAllocation = $leave_Allo;
$model->save();
$annualleave->save();

it should be like this?
 
4:54 AM
Why $model->leaveAllocation = $leave_Allo;? You want to update leave allocation of staff then you need to update leaveallocation table which is AnnualLeave model.
Don't get confused your task is to Save LeaveApplication and Deduct Applied leave from LeaveAllocation which AnnualLeave model. Just save both of them with their respected data.
 
 
2 hours later…
7:25 AM
$annualleave = Annualleave::find()
->select('LeaveAllo')
->where(['staffNo'=>$model1->staffNo])
->one();


$annualleave = ($model1->LeaveAllo) - ($model->no_of_days);
$annualleave->save();


is this correct sir?
honestly, im pretty confused right now
for LeaveApplication, i already save it above this code
 
 
2 hours later…
9:08 AM
Forget leaveapplication model you already saved it.
What is your goal for AnnualLeave model? Deduct LeaveDays from Total Leaves Allocated? Correct?
 $annualleave = Annualleave::find()
           ->where(['staffNo'=>$model1->staffNo])
           ->one();

            $remainig = $annualleave->leaveBalance - $workDay;
            $annualleave->leaveBalance = $remainig;
            $annualleave->save();
 
i have tried this before
i got error trying to get property 'leaveBalance' of non-object
 
check $annualleave variable is empty or not.
 
i checked using exit() . its appear a blank page
 
9:23 AM
your query returns empty result. Check query and db that record actually exists and matches your query.
 
'30' AS leaveBalance
this is from my query
and its exactly same at the db
 
Result of this query `$annualleave = Annualleave::find()
->where(['staffNo'=>$model1->staffNo])
->one(); ??`
 
its a blank page
 
9:39 AM
No. it is not supposed to be a blank page. You must get AnnualLeave model of staffNo. Check your query.
Add whole code what you tried so far.
 

« first day    last day (21 days later) »