接上 注意 if else 对映 看{},
else if($leave_type==2) // off process
{
if($total<0){
return $this->addreturn_off_balance($user_id,$total);
}
$items_1=$this->get_user_balance_with_flag($user_id,$applicationstart_date,1,$leave_type); // get 11-12 method of last year off
if($items_1["balance"]>0)
{
if($items_1["balance"]>= $total)
{
// reduce 11-12 month of last year off
$main = array($total,$total,$user_id,$applicationatart_date,$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}else
{
$day_temp=$total-$items_1["balance"];
// reduce 11-12 month of last year off
$main = array($items_1["balance"],$items_1["balance"],$user_id,$applicationstart_date,$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
// reduce 1-11 month of current year off
$main = array($day_temp,$day_temp,$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}
}else
{
$items_2=$this->get_user_balance_with_flag($user_id,$applicationend_date,0,$leave_type); // get 1-11 method of current year off
if($items_2["balance"]>= $total)
{
// reduce 1-11 month of current year off
$main = array($total,$total,$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}else
{
$day_temp=$total-$items_2["balance"];
// reduce 1-11 month of current year off
$main = array($items_2["balance"],$items_2["balance"],$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
// reduce 11-12 month of current year off
$main = array($day_temp,$day_temp,$user_id,intval($applicationstart_date+1),$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}
}
}
else
{
$items_balance=$this->get_user_balance_with_flag($user_id,$applicationend_date-1,0,$leave_type);
if(count($items_balance)>0){
// the leave balance is minors at last year, reset it to zero.
if($items_balance['balance']<0){
$main = array($items_balance['balance'],0,$user_id,$applicationend_date-1,$leave_type);
$sql="update leave_balance set used=used+?, balance=? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
if(isset($ret)){
$main = array($items_balance['balance'],$items_balance['balance'],$user_id,$applicationstart_date,$leave_type);
$sql="update leave_balance set used=used-?, balance=balance+? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
}
}
}
$main = array($total,$total,$user_id,$applicationend_date,$leave_type);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
}
}
}
else if($leave_type==2) // off process
{
if($total<0){
return $this->addreturn_off_balance($user_id,$total);
}
$items_1=$this->get_user_balance_with_flag($user_id,$applicationstart_date,1,$leave_type); // get 11-12 method of last year off
if($items_1["balance"]>0)
{
if($items_1["balance"]>= $total)
{
// reduce 11-12 month of last year off
$main = array($total,$total,$user_id,$applicationatart_date,$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}else
{
$day_temp=$total-$items_1["balance"];
// reduce 11-12 month of last year off
$main = array($items_1["balance"],$items_1["balance"],$user_id,$applicationstart_date,$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
// reduce 1-11 month of current year off
$main = array($day_temp,$day_temp,$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}
}else
{
$items_2=$this->get_user_balance_with_flag($user_id,$applicationend_date,0,$leave_type); // get 1-11 method of current year off
if($items_2["balance"]>= $total)
{
// reduce 1-11 month of current year off
$main = array($total,$total,$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}else
{
$day_temp=$total-$items_2["balance"];
// reduce 1-11 month of current year off
$main = array($items_2["balance"],$items_2["balance"],$user_id,$applicationend_date,$leave_type,0);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
// reduce 11-12 month of current year off
$main = array($day_temp,$day_temp,$user_id,intval($applicationstart_date+1),$leave_type,1);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=? and flag=?";
$ret = $this->db->execute($sql,$main);
}
}
}
else
{
$items_balance=$this->get_user_balance_with_flag($user_id,$applicationend_date-1,0,$leave_type);
if(count($items_balance)>0){
// the leave balance is minors at last year, reset it to zero.
if($items_balance['balance']<0){
$main = array($items_balance['balance'],0,$user_id,$applicationend_date-1,$leave_type);
$sql="update leave_balance set used=used+?, balance=? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
if(isset($ret)){
$main = array($items_balance['balance'],$items_balance['balance'],$user_id,$applicationstart_date,$leave_type);
$sql="update leave_balance set used=used-?, balance=balance+? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
}
}
}
$main = array($total,$total,$user_id,$applicationend_date,$leave_type);
$sql="update leave_balance set used=used+?, balance=balance-? where user_id=? and year=? and leave_type=?";
$ret = $this->db->execute($sql,$main);
}
}
}
可能看起来不便,
要是这样看不明白的,
可以加我MSN
[email protected]发文件给你看,
谢谢,
急。