有一种情况,如果员工从 join_date 起已经工作了一年,他将获得 12 个 Leave_balance,但下一年如何确定?因为它不能乘以年份差。例如
- join_date 2015年1月15日,今天日期是2016年1月15日,则更新leave_balance = Leave_balance + 12;
- 但是,在 2016 年 1 月 15 日至 2017 年 1 月 15 日之间,他使用了 5 天假期,因此他的 Leave_balance 将为 8,
- 2017 年 1 月 15 日,他将收到另一个休假余额配额 12,因此 Leave_balance 必须更新为 8 + 12 = 20。
我想的只是这样 if(join_date = 今年同一日期) 然后更新leave_balance
请帮忙
需要的表很简单,status_employee、join_date和leave_balance
$q = "select * from employee";
$r = mysql-query($q);
while($result = mysql_fetch_array($r))
{
$datetime1 = new DateTime($result['join_date']);
$interval = $datetime1->diff(new DateTime());
$year= $interval->y;
if($year > 0 && status_employee = 'Permanent Staff')
{
$leave_balance = $result['leave_balance'] + (12 * $year);
}
}
仅供引用
$q = "SELECT * FROM employee WHERE employee_type = 'Permanent' && DATEDIFF(.join_date , CURDATE()) >= 365";
$r = mysql_query($q);
while($res = mysql_fetch_array($r))
{
$q = "SELECT * FROM holiday_transaction WHERE id_employee='".$res['id_employee']."'";
$r = mysql_query($r);
$res = mysql_fetch_array($r);
$check = mysql_num_rows($r);
$id_employee = $res['id_employee'];
if($check > 0) //employee is on the transaction_table
{
//check latest renewal date
$q = "SELECT * FROM holiday_transaction WHERE id_employee = '$id_employee' && transaction_type='Renewal' && DATEDIFF(CURDATE() ,trn_date) >= 365";
$r = mysql_query($q);
$check = mysql_num_rows($r);
if($check == 0) //0 means he qualify with conditions above that his latest renewal is already more than a year
{
$q = "INSERT INTO holiday_transaction(id_employee,holiday,transaction_type) VALUES('$id_employee','12','Renewal')";
mysql_query($q)
}
else
{
//don't insert because it is not yet 365days since his latest renewal
}
}
else //never been on the table and give 12 quota
{
$q = "INSERT INTO holiday_transaction(id_employee,holiday,transaction_type) VALUES('$id_employee','12','Renewal')";
mysql_query($q)
}
}
最佳答案
您不需要 cron 作业。当有人下次登录时,您可以只在 mysql 上运行存储过程或运行一些 php 代码。只需在向他们展示页面之前执行此操作即可。
关于php - PHP逻辑每日更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31737401/