有一种情况是,如果员工自join_date以来已经工作了一年,他将获得12个leave_balance,但如何确定明年?因为它不能乘以年份的差异。例如
我所想的只是这样 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);
}
}
for ilustration
$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)
}
}
答案 0 :(得分:3)
您不需要cron作业。您可以在mysql上运行存储过程,或者在下次登录时运行一些php代码。 JUst在向他们展示页面之前做到了。
答案 1 :(得分:1)
你的第二个问题的答案。如果我这样做,我会有一个交易表。这将确保即使代码运行两次也不会使事情变得更加复杂。如果员工发生争议,它还会为您提供准确的跟踪信息。像这样:
table employee_holidays
employee_ref (index into employee table)
trn_date (the date that these holidays were added or taken)
holidays (integer)
然后
您可以在年底之后的任何时间申请12年假,并使用年终作为日期。如果该条目已经存在于该日期,那么您不会添加它。
每次员工休假时,都会为该日期添加一个否定条目。
要了解他们剩下多少假期,请总结一下。
如果你真的想要一个现成的总数,那么我会有一个总计表(或使用employee_table.leave_balance)。 但是我会在事务表中使用触发器来更新此数字。
我认为,一旦你将它们放在一起并且无法获得某些工作,那么你应该问一个新问题。