if (isset($_GET['task']) && $_GET['task'] == 'Compute') { $tempArr = array(); $SDate = DateModules::shamsi_to_miladi($_REQUEST['pay_year'] . "/01/01"); $EDate = DateModules::shamsi_to_miladi($_REQUEST['pay_year'] . "/12/29"); $query = " select s.PersonID , sum(wsi.value) sv\n\n\t\t\t from staff s inner join (\n SELECT w.staff_id,\n SUBSTRING_INDEX(SUBSTRING(max(CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver)),11),'.',1) writ_id,\n SUBSTRING_INDEX(max(CONCAT(w.execute_date,w.writ_id,'.',w.writ_ver)),'.',-1) writ_ver\n\n FROM writs w\n INNER JOIN staff ls ON(w.staff_id = ls.staff_id)\n\n WHERE w.person_type in (1,2,3,5) and w.execute_date <= '" . $EDate . "'\n\n GROUP BY w.staff_id\n\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t) w\t\n\t\t\t\t\t\t\t\t\ton s.staff_id = w.staff_id \n\t\t\t\t\t\t\tinner join writs wr \n\t\t\t\t\t\t\t\t\ton wr.staff_id = w.staff_id and wr.writ_id = w.writ_id and wr.writ_ver = w.writ_ver\t\t\t\n\t\t\t\t\t\t\tinner join writ_salary_items wsi\n\t\t\t\t\t\t\t\t\ton w.staff_id = wsi.staff_id and w.writ_id = wsi.writ_id and w.writ_ver = wsi.writ_ver\n\t\t\t\t\t\t\tinner join salary_item_types sit \n\t\t\t\t\t\t\t\t\ton sit.salary_item_type_id = wsi.salary_item_type_id\n\t\t\t\t\t\t\t\t\t\n\n\t\t\t\t\t\t\t\t\twhere wr.person_type in (1,2,3,5) and if(( wr.person_type =2 or wr.person_type =1 ) ,sit.retired_include =1 , sit.insure_include =1 ) and \n\t\t\t\t\t\t\t\t\t\t wr.execute_date >= '" . $SDate . "' and wr.execute_date <= '" . $EDate . "' /* AND s.PersonID = 201424*/\n\t\t\t\tgroup by s.PersonID \n\t\t\t "; $res = PdoDataAccess::runquery($query); for ($i = 0; $i < count($res); $i++) { $total_year = 0; $total_month = 0; $total_day = 0; $Tyear = $Tmonth = $Tday = 0; $qry = " select execute_date , annual_effect , writ_id , writ_ver , w.onduty_year ,w.onduty_month ,\n w.onduty_day , w.person_type ,cc.AccUnitID\n\t\t\t\n\t\t\t\t from writs w inner join staff s \n\t\t\t\t on w.staff_id = s.staff_id \n\t\t\t\t\t\t\t inner join CostCenterPlan cc \n\t\t\t\t\t\t\t\ton cc.CostCenterID = w.CostCenterID \n\t\t\t\t\t\t\t\t\n\t\t\t\t where s.PersonID = " . $res[$i]['PersonID'] . " and w.execute_date <= '" . $EDate . "'\n\t\t\t\t order by execute_date "; $res2 = PdoDataAccess::runquery($qry); $cn = count($res2) - 1; if ($res2[$cn]['person_type'] != 1) { $DayToEnd = DateModules::CalculateDuration($res2[$cn]['execute_date'], DateModules::shamsi_to_miladi($_REQUEST['pay_year'] . "/12/30")); $TotalDay = $res2[$cn]['onduty_year'] * 360 + $res2[$cn]['onduty_month'] * 30 + $res2[$cn]['onduty_day']; $TotalDay += $DayToEnd; //................ ذخیره مقدارنهایی $query = " insert into YearRedemption (PersonID,duration,value,year,writ_id,writ_ver) values \n\t\t\t (" . $res[$i]['PersonID'] . "," . round($TotalDay / 360, 2) . "," . $res[$i]['sv'] . " ," . $_REQUEST['pay_year'] . "," . $res2[$cn]['writ_id'] . "," . $res2[$cn]['writ_ver'] . "); "; } else { //....................... $j = 0; for ($j = 0; $j < count($res2); $j++) { $first_date = $res2[$j]['execute_date']; $last_date = $j + 1 < count($res2) ? $res2[$j + 1]['execute_date'] : $EDate; $diff = strtotime($last_date) - strtotime($first_date); $diff = floor($diff / (60 * 60 * 24)); $year = floor($diff / 365.25); $month = floor(($diff - floor($diff / 365.25) * 365.25) / 30.4375); $day = floor($diff - floor($diff / 365.25) * 365.25 - floor(($diff - floor($diff / 365.25) * 365.25) / 30.4375) * 30.4375);