last day (22 days later) » 

8:55 AM
1
Q: how to minus leave allocated when leave applied? yii2

AechI have stuck in this problem for a week. How can I deduct the Leave Allocated when someone have apply the leave. the picture below is the output from Leaveapplication.php And output below is from Annualleave.php I want to deduct that Leave Allo with the value from Days Leave which is both of ...

 
i've already tried this code $leaveAllo = $model1->LeaveAllo; $leaveAllo = $leaveAllo - $workDay; $model1->LeaveAllo = $leaveAllo; $model1->save(); in Leaveapplication.php
@AmanjotKaur i also try to call the data using sql, but my knowledge about sql is limited, so the error come up
i got this error Invalid validation rule: a rule must specify both attribute names and validator type.
@AmanjotKaur i have edited my question to make the question clearer
im sorry, the error in the answer is from the second trial of my code. i have figured it out
i already share my code @MAZ
 
Does your $model1 is Annualleave model?
 
@InsaneSkull Yes sir
 
What is the output of $leaveAllo after $leaveAllo = $leaveAllo - $workDay;? Check using var_dump($leaveAllo); or exit($leaveAllo);
 
i have calculation inside Annualleave.php. After the user enter the input inside the leave application, instead of replacing an existing data of $leaveAllo, its create a new data in Annualleave.php
i edited my question to explain what is the real problem that im facing right now
 
8:55 AM
Use _ as separator instead of UpperCase Letters for field names in db. Currently lt looks like you were accessing relation from model and not fields. Where is the query to find LeaveAllocation of Staff who have leave application?
 
Oh im sorry, my bad for that. Im not pretty sure how to find the LeaveAllocation and that's the reason why im asking this question. Im really sorry. im not very familiar with sql and php
 
$annulaLeave = Annualleave::find()
->where(['staffNo' => $model->staffNo)
->one();
 
this is for find the LeaveAllocation of staff?
 
9:08 AM
yes
correct field names if incorrect
 
then i calculate LeaveAllocation as usual?
 
yes
This is your personal project or professional project?
 
both
 
Intern?
 
yes indeed
 
9:15 AM
great
 
its bit difficult because im not very familiar with php and sql
btw sir, how can we get LeaveAllocation with the code that you gave?
 
9:45 AM
Leave Application have staffNo from which you can find LeaveAllocation
 
 
4 hours later…
1:16 PM
Annualleave::find() -> where (['staffNo'=>$model=>staffNo]) ->one(); $leaveAllo = $model -> leaveAllocation; $leave_Allo= $leaveAllo - $workday;. $model->leaveAllocation = $leave_Allo; $model->save();
Is this correct sir?
sorry for that
Annualleave::find()
->where(['staffNo'=>$model->staffNo])
->one();

$leaveAllo = $annualleave->leaveAllocation;
$leave_Allo = $leaveAllo - $workDay;
$model->leaveAllocation = $leave_Allo;
$model->save();
like this sir?
 

  last day (22 days later) »