/** * returns html for a date selection * * the form fields to update must have in id in the form of * ${idpfx}_day, ${idpfx}_month, ${idpfx}_year in the order day, month, year * respectively. * * @ignore * @param string idpfx prefix for form fields to update * @return string html */ function dateSelection($idpfx) { global $GWPP; /* all the different date parts with default values -> false */ $date_fields = array("day", "month", "year", "sday", "smonth", "syear"); foreach ($date_fields as $k) { if (!isset($_REQUEST[$k])) { ${$k} = false; } else { ${$k} = $_REQUEST[$k]; } } /* why check only date === false but set all of them to date() values? what if they have values you gonna overwrite? because I dont want bugs like day isset, month not, year isset causing some weird month to be shown */ if ($day === false) { $day = date("d"); $month = date("m"); $year = date("Y"); } if ($sday === false) { $sday = $day; $smonth = $month; $syear = $year; } /* forcibly fix the date */ explodeDate(date("Y-m-d", mktime(0, 0, 0, $smonth, $sday, $syear)), $syear, $smonth, $sday); /* previous year */ $pyear = extractYear(mkdatet($year - 1, $month, 1)); /* previous month */ $pmonth = extractMonth(mkdatet($year, $month - 1, 1)); $pmyear = extractYear(mkdatet($year, $month - 1, 1)); /* next month */ $nmonth = extractMonth(mkdatet($year, $month + 1, 1)); $nmyear = extractYear(mkdatet($year, $month + 1, 1)); /* next year */ $nyear = extractYear(mkdatet($year + 1, $month, 1)); /* month/year selections */ $dateselmove = "dateSelMoveBySelect(\"{$idpfx}\", \"{$day}\", \"{$sday}\", \"{$smonth}\", \"{$syear}\", \"{$GWPP}\");"; $move_month = mksel_month("datesel_move_month", $month, "onchange='{$dateselmove}'", true); $move_year = mksel_year("datesel_move_year", $year, "onchange='{$dateselmove}'"); $title_style = "onMouseUp='moveXLayer(false);' onMouseDown='moveXLayer(true);'"; $OUTPUT = "\n\t<div id='datesel_container' style='background: #fdeb89; border: 1px dashed black;' >\n\t<div id='datesel_loading' style='position: absolute; visibility: hidden;'>\n\t\t<p style='margin-left: 25px; margin-top: 60px;'>\n\t\t\t<strong>Loading. Please Wait...</strong>\n\t\t</p>\n\t</div>\n\t<div id='datesel_calender'>\n\t<table>\n\t<tr>\n\t\t<td nowrap='t' align='left'>\n\t\t\t{$move_month} {$move_year}\n\t\t\t<!--<input type='button' onclick='{$dateselmove}' value='Go'/>-->\n\t\t</td>\n\t\t<td align='right' nowrap='t' onMouseUp='moveXLayer(false);' onMouseDown='moveXLayer(true);'>\n\t\t\t<b><a id='xpopup_cls' href='javascript: XPopupHideAct()'>[X] </a></b>\n\t\t</td>\n\t</tr>\n\t<tr><td colspan='2'>\n\n\t<table width='190' cellspacing='0'>\n\t<tr>\n\t\t<td {$title_style} " . TMPL_calSmallMonthTitleStyleLeft . ">\n\t\t\t<a href='javascript: dateSelMove(\"{$idpfx}\", \"{$day}\", \"{$month}\", \"{$pyear}\", \"{$sday}\", \"{$smonth}\", \"{$syear}\", \"{$GWPP}\");'><img border='0' src='{$GWPP}/left_year.gif' /></a>\n\t\t\t<a href='javascript: dateSelMove(\"{$idpfx}\", \"{$day}\", \"{$pmonth}\", \"{$pmyear}\", \"{$sday}\", \"{$smonth}\", \"{$syear}\", \"{$GWPP}\");'><img border='0' src='{$GWPP}/left_month.gif' /></a>\n\t\t</td>\n\t\t<td {$title_style} " . TMPL_calSmallMonthTitleStyleCenter . ">\n\t\t\t" . getMonthName($month) . " {$year}\n\t\t</td>\n\t\t<td {$title_style} " . TMPL_calSmallMonthTitleStyleRight . ">\n\t\t\t<a href='javascript: dateSelMove(\"{$idpfx}\", \"{$day}\", \"{$nmonth}\", \"{$nmyear}\", \"{$sday}\", \"{$smonth}\", \"{$syear}\", \"{$GWPP}\");'><img border='0' src='{$GWPP}/right_month.gif' /></a>\n\t\t\t<a href='javascript: dateSelMove(\"{$idpfx}\", \"{$day}\", \"{$month}\", \"{$nyear}\", \"{$sday}\", \"{$smonth}\", \"{$syear}\", \"{$GWPP}\");'><img border='0' src='{$GWPP}/right_year.gif' /></a>\n\t\t</td>\n\t</tr>\n\t<tr>\n\t\t<td align='center' " . TMPL_calSmallMonthBodyStyle . " colspan='5'>"; // generate the titles of the weekdays $OUTPUT .= "\n\t\t<table width='184' cellspacing='0'>\n\t\t\t<tr>\n\t\t\t\t<td width='23'> </td>\n\t\t\t\t<td width='23' align='center'><b>M</b></td>\n\t\t\t\t<td width='23' align='center'><b>T</b></td>\n\t\t\t\t<td width='23' align='center'><b>W</b></td>\n\t\t\t\t<td width='23' align='center'><b>T</b></td>\n\t\t\t\t<td width='23' align='center'><b>F</b></td>\n\t\t\t\t<td width='23' align='center' bgcolor=" . TMPL_calFillSaturday . "><b>S</b></td>\n\t\t\t\t<td width='23' align='center' bgcolor=" . TMPL_calFillSunday . "><b>S</b></td>\n\t\t\t</tr>"; // get the weekday number of the first of this month $first_wd = getWeekdayNum(1, $month, $year); // the following code will generate the first entries on the calendar, which is for the previous month (if any) // month and year of previous month if ($month == 1) { $tmp_month = 12; $tmp_year = $year - 1; } else { $tmp_month = $month - 1; $tmp_year = $year; } // date of last monday in previous month (where the entries will start) if ($first_wd > 1) { $tmp_day = getDaysInMonth($tmp_month, $tmp_year) - ($first_wd - 2); } else { $tmp_day = 1; $tmp_month = $month; $tmp_year = $year; } // create a view variables $selected_month = $smonth; // create the previous month's entries $c_weeknum = getWeekNumber($tmp_day, $tmp_month, $tmp_year); $selected_weeknum = getWeekNumber($sday, $smonth, $syear); // if today's week number = the current generated week's number, hightlight the row, as so with the selected week, if ($c_weeknum == getTodayWeekNumber() && $tmp_year == date("Y") && $month == date("m") || getTodayWeekNumber() == 0 && $month == date("m") && $year == date("Y")) { // today's week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthCurrentWeek . "'>"; $ROW_COLORED = 1; } else { if ($year == $syear && $month == $smonth && $c_weeknum == $selected_weeknum || $c_weeknum == 52 && $selected_weeknum == 0) { // selected week, the last check is for the first week in jan $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthSelectedWeek . "'>"; $ROW_COLORED = 1; } else { // other dates $OUTPUT .= "<tr>"; $ROW_COLORED = 0; } } if ($first_wd != 1) { // only if there is a day in this week of previous month, print the week number $OUTPUT .= "<td width='23' " . TMPL_calSmallMonthWeekNumberStyle . " align='center'>{$c_weeknum}</td>"; } for ($c_wd = 1; $c_wd < $first_wd; $c_wd++, $tmp_day++) { // fill differently for saturday and sunday (only when row wasn't already highlighted) if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor='" . TMPL_calFillSaturday . "'"; } else { if ($c_wd == 7) { $dayfill = "bgcolor='" . TMPL_calFillSunday . "'"; } else { $dayfill = ""; } } $OUTPUT .= "\n\t\t\t<td {$dayfill} width='23' align='center'>\n\t\t\t\t<a id='calSmallMonthOMLink' href='javascript: dateSelUpdate(\"{$idpfx}\", \"{$tmp_day}\", \"{$tmp_month}\", \"{$tmp_year}\");'>{$tmp_day}</a>\n\t\t\t</td>"; } // start creating this month's entries $cm_days = getDaysInMonth($month, $year); for ($c_day = 1; $c_day <= $cm_days; $c_day++) { $c_weeknum = getWeekNumber($c_day, $month, $year); if ($c_wd == 1) { // start a new row (it's MONDAY!!!!!) // if today's week number = the current generated week's number, hightlight the row, as so with the selected week if ($c_weeknum == getTodayWeekNumber() && $year == date("Y") && $month == date("m")) { // today's week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthCurrentWeek . "'>"; $ROW_COLORED = 1; } else { if ($year == $syear && $month == $smonth && $c_weeknum == $selected_weeknum) { // selected week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthSelectedWeek . "'>"; $ROW_COLORED = 1; } else { // other dates $OUTPUT .= "<tr>"; $ROW_COLORED = 0; } } // attach the week number $OUTPUT .= "<td align='center' width='23' " . TMPL_calSmallMonthWeekNumberStyle . ">{$c_weeknum}</td>"; } /* change the fill color if it it 2day's date we are printing */ if ($c_day == $sday && $month == $smonth && $year == $syear) { // selected date $dayfill = "bgcolor=" . TMPL_calSmallMonthSelectedDay; $a_id = "calSmallMonthCMLinkSelected"; } else { if (date("d") == $c_day && date("m") == $month && date("Y") == $year) { // 2day's date $dayfill = "bgcolor='" . TMPL_calSmallMonthCurrentDay . "'"; $a_id = "calSmallMonthCMLinkToday"; } else { // other dates // fill differently for saturday and sunday (only when the row has not already been colored) if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor='" . TMPL_calFillSaturday . "'"; } else { if ($c_wd == 7 && !$ROW_COLORED) { $dayfill = "bgcolor='" . TMPL_calFillSunday . "'"; } else { $dayfill = ""; } } $a_id = "calSmallMonthCMLink"; } } $OUTPUT .= "\n\t\t\t<td width='23' {$dayfill} align='center'>\n\t\t\t\t<a id='{$a_id}' href='javascript: dateSelUpdate(\"{$idpfx}\", \"{$c_day}\", \"{$month}\", \"{$year}\");'>{$c_day}</a>\n\t\t\t</td>"; /* end of output */ if ($c_wd == 7) { $OUTPUT .= "</tr>"; } $c_wd = $c_wd == 7 ? 1 : $c_wd + 1; } // next month variables if ($month == 12) { $tmp_month = 1; $tmp_year = $year + 1; } else { $tmp_month = $month + 1; $tmp_year = $year; } // finish with the next months entries for ($c_day = 1; $c_wd <= 7 && $c_wd > 1; $c_wd++, $c_day++) { // fill differently for saturday and sunday if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor='" . TMPL_calFillSaturday . "'"; } else { if ($c_wd == 7 && !$ROW_COLORED) { $dayfill = "bgcolor='" . TMPL_calFillSunday . "'"; } else { $dayfill = ""; } } $OUTPUT .= "\n\t\t<td {$dayfill} width='23' align='center'>\n\t\t\t<a id='calSmallMonthOMLink' href='javascript: dateSelUpdate(\"{$idpfx}\", \"{$c_day}\", \"{$tmp_month}\", \"{$tmp_year}\");'>{$c_day}</a>\n\t\t</td>"; } /* finish the tables and return */ $OUTPUT .= "\n\t\t\t</tr>\n\t\t</table>\n\t\t</td>\n\t</tr>\n\t</table>\n\n\t</td></tr>\n\t</table>\n\t</div>\n\t</div>"; return $OUTPUT; }
function generateMonthView_small_mail($view_diary) { global $_GET; extract($_GET); $pyear = extractYear(mkdatet($year - 1, $month, 1)); $pmonth = extractMonth(mkdatet($year, $month - 1, 1)); $nyear = extractYear(mkdatet($year + 1, $month, 1)); $nmonth = extractMonth(mkdatet($year, $month + 1, 1)); $OUTPUT = "\n\t\t<table width=190 cellspacing=0>\n\t\t\t<tr>\n\t\t\t\t<td height=20 align=center " . TMPL_calSmallMonthTitleStyle . ">\n\t\t\t\t\t<a href='" . SELF . "?month={$month}&year={$pyear}'><img border='0' src='left_year.gif'></a>\n\t\t\t\t\t<a href='" . SELF . "?month={$pmonth}&year={$year}'><img border='0' src='left_month.gif'></a>\n\t\t\t\t\t<b><a class='month_text' href='javascript:ajaxLink(\"iframe.php\", \"script=diary-index.php&key=month&month={$month}&year={$year}\");'>" . getMonthName($month) . " {$year}</a></b>\n\t\t\t\t\t<a href='" . SELF . "?month={$nmonth}&year={$year}'><img border='0' src='right_month.gif'></a>\n\t\t\t\t\t<a href='" . SELF . "?month={$month}&year={$nyear}'><img border='0' src='right_year.gif'></a>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td align=center " . TMPL_calSmallMonthBodyStyle . " colspan='5'>"; // generate the titles of the weekdays $OUTPUT .= "\n\t\t\t<table width='184' cellspacing=0>\n\t\t\t\t<tr>\n\t\t\t\t\t<td width=23> </td>\n\t\t\t\t\t<td width=23 align=center><b>M</b></td>\n\t\t\t\t\t<td width=23 align=center><b>T</b></td>\n\t\t\t\t\t<td width=23 align=center><b>W</b></td>\n\t\t\t\t\t<td width=23 align=center><b>T</b></td>\n\t\t\t\t\t<td width=23 align=center><b>F</b></td>\n\t\t\t\t\t<td width=23 align=center bgcolor=" . TMPL_calFillSaturday . "><b>S</b></td>\n\t\t\t\t\t<td width=23 align=center bgcolor=" . TMPL_calFillSunday . "><b>S</b></td>\n\t\t\t\t</tr>"; // get the weekday number of the first of this month $first_wd = getWeekdayNum(1, $month, $year); // the following code will generate the first entries on the calendar, which is for the previous month (if any) // month and year of previous month if ($month == 1) { $tmp_month = 12; $tmp_year = $year - 1; } else { $tmp_month = $month - 1; $tmp_year = $year; } // date of last monday in previous month (where the entries will start) if ($first_wd > 1) { $tmp_day = getDaysInMonth($tmp_month, $tmp_year) - ($first_wd - 2); } else { $tmp_day = 1; $tmp_month = $month; $tmp_year = $year; } // create a view variables $selected_month = $smonth; // create the previous month's entries $c_weeknum = getWeekNumber($tmp_day, $tmp_month, $tmp_year); $selected_weeknum = getWeekNumber($sday, $smonth, $syear); // if today's week number = the current generated week's number, hightlight the row, as so with the selected week, if ($c_weeknum == getTodayWeekNumber() && $tmp_year == date("Y") && $month == date("m") || getTodayWeekNumber() == 0 && $month == date("m") && $year == date("Y")) { // today's week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthCurrentWeek . "'>"; $ROW_COLORED = 1; } else { if ($month == $smonth && $c_weeknum == $selected_weeknum || $c_weeknum == 52 && $selected_weeknum == 0) { // selected week, the last check is for the first week in jan $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthSelectedWeek . "'>"; $ROW_COLORED = 1; } else { // other dates $OUTPUT .= "<tr>"; $ROW_COLORED = 0; } } if ($first_wd != 1) { // only if there is a day in this week of previous month, print the week number $OUTPUT .= "<td width=23 " . TMPL_calSmallMonthWeekNumberStyle . " align=center>{$c_weeknum}</td>"; } for ($c_wd = 1; $c_wd < $first_wd; $c_wd++, $tmp_day++) { // fill differently for saturday and sunday (only when row wasn't already highlighted) if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } // ** 2006-05-08 ** // $OUTPUT.="<td $dayfill width=23 align=center> // <a id='calSmallMonthOMLink' href='#' onClick='parent.rightframe.document.location.href=\"diary-index.php?mday=$tmp_day&month=$tmp_month&year=$tmp_year\"'>$tmp_day</a> // </td>"; $OUTPUT .= "<td {$dayfill} width='23' align='center'>\n\t\t\t<a id='calSmallMonthOMLink' href='javascript:ajaxLink(\"iframe.php\", \"script=diary-index.php&mday={$tmp_day}&month={$tmp_month}&year={$tmp_year}\");'>{$tmp_day}</a></td>"; } // start creating this month's entries $cm_days = getDaysInMonth($month, $year); for ($c_day = 1; $c_day <= $cm_days; $c_day++) { $c_weeknum = getWeekNumber($c_day, $month, $year); if ($c_wd == 1) { // start a new row (it's MONDAY!!!!!) // if today's week number = the current generated week's number, hightlight the row, as so with the selected week if ($c_weeknum == getTodayWeekNumber() && $year == date("Y") && $month == date("m")) { // today's week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthCurrentWeek . "'>"; $ROW_COLORED = 1; } else { if ($month == $smonth && $c_weeknum == $selected_weeknum) { // selected week $OUTPUT .= "<tr bgcolor='" . TMPL_calSmallMonthSelectedWeek . "'>"; $ROW_COLORED = 1; } else { // other dates $OUTPUT .= "<tr>"; $ROW_COLORED = 0; } } // attach the week number $OUTPUT .= "<td align=center width=23 " . TMPL_calSmallMonthWeekNumberStyle . ">{$c_weeknum}</td>"; } // change the fill color if it it 2day's date we are printing, or the selected date if ($c_day == $sday && $month == $smonth && $year == $syear) { // selected date $dayfill = "bgcolor=" . TMPL_calSmallMonthSelectedDay; $a_id = "calSmallMonthCMLinkSelected"; } else { if (date("d") == $c_day && date("m") == $month && date("Y") == $year) { // 2day's date $dayfill = "bgcolor=" . TMPL_calSmallMonthCurrentDay; $a_id = "calSmallMonthCMLinkToday"; } else { // other dates // fill differently for saturday and sunday (only when the row has not already been colored) if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7 && !$ROW_COLORED) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } $a_id = "calSmallMonthCMLink"; } } // ** 2006-05-08 ** // $OUTPUT.="<td width=23 $dayfill align=center> // <a id='$a_id' href='#' onClick='parent.rightframe.document.location.href=\"diary-index.php?mday=$c_day&month=$month&year=$year&view_diary=$view_diary\"'>$c_day</a> // </td>"; $OUTPUT .= "<td width='23' {$dayfill} align='center'>\n\t\t\t<a id='{$a_id}' href='javascript:ajaxLink(\"iframe.php\", \"script=diary-index.php&mday={$c_day}&month={$month}&year={$year}\");'>{$c_day}</a></td>"; if ($c_wd == 7) { // end the output $OUTPUT .= "</tr>"; } $c_wd == 7 ? $c_wd = 1 : $c_wd++; } // next month variables if ($month == 12) { $tmp_month = 1; $tmp_year = $year + 1; } else { $tmp_month = $month + 1; $tmp_year = $year; } // finish with the next months entries for ($c_day = 1; $c_wd <= 7 && $c_wd > 1; $c_wd++, $c_day++) { // fill differently for saturday and sunday if ($c_wd == 6 && !$ROW_COLORED) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7 && !$ROW_COLORED) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } // ** 2006-05-08 ** // $OUTPUT.="<td $dayfill width=23 align=center> // <a id='calSmallMonthOMLink' href='#' inClick='parent.rightframe.document.location.href=\"diary-index.php?mday=$c_day&month=$tmp_month&year=$tmp_year\"'>$c_day</a> // </td>"; $OUTPUT .= "<td {$dayfill} width='23' align='center'>\n\t\t\t<a id='calSmallMonthOMLink' href='javascript:ajaxLink(\"iframe.php?script=diary-index.php\", \"mday={$c_day}&month={$tmp_month}&year={$tmp_year}\");'>{$c_day}</a>"; } // finish the tables and return $OUTPUT .= "\n\t\t\t\t</tr>\n\t\t\t</table>\n\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t</table>"; return $OUTPUT; }
/** * Calculate PAYE on salary * * @param array &$emp employee db row * @param int $prd month/week for which salary is calculated * @param float $paye_salary taxable salary * @param int $tyear periods in year (weekly emp: 52, monthly: 12, etc...) * @param int $age employee age * @return float */ function calculate_paye_old(&$emp, $prd, $paye_salary, $tyear, $age) { $empnum = $emp["empnum"]; //define("ACTUAL_EMP_YEAR",getYearOfEmpMon($prd)); payedbg("fromsal: {$paye_salary}<br />"); /* query expression for previous payments/paye */ if ($emp["payprd"] == "w" || $emp["payprd"] == "f" || $emp["payprd"] == "d") { list($month, $week) = explode(":", $prd); if ($emp["payprd"] == "d") { $day = $week; } else { $day = 1; } $mw_b = "((month::int>='3' AND month::int<'{$month}')\n\t\t\t\tOR ('{$month}' < '3' AND (month::int<'{$month}' OR month::int>='3')))\n\t\t\t\tOR (month::int='{$month}' AND week<'{$week}')"; } else { $month = $prd; $day = 1; $mw_b = "(month::int>='3' AND month::int<'{$month}')\n\t\t\t\tOR ('{$month}' < '3' AND (month::int<'{$month}' OR month::int>='3'))"; } /* determine previously paid amounts */ $sql = "SELECT 1 AS m, * FROM cubit.salamt_pay\n\t\t\tWHERE empnum='{$empnum}' AND cyear='" . EMP_YEAR . "' AND ({$mw_b})\n\t\t\tUNION\n\t\t\tSELECT -1 AS m, * FROM cubit.salamt_rev\n\t\t\tWHERE empnum='{$empnum}' AND cyear='" . EMP_YEAR . "' AND ({$mw_b})"; $qry = new dbSql($sql); $qry->run(); $prev_emp = $emp["cyear"] == EMP_YEAR && ($emp["prevemp_tax"] > 0 && $emp["prevemp_remun"] > 0); payedbg("prevemp: " . ($prev_emp ? "true" : "false") . "<br />"); if ($prev_emp) { $totpaye = $emp["prevemp_tax"]; $totgross = $paye_salary + $emp["prevemp_remun"]; } else { $totpaye = 0; $totgross = $paye_salary; } $totnetgross = 0; while ($row = $qry->fetch_array()) { $totpaye += $row["paye"] * $row["m"]; $totgross += $row["payegross"] * $row["m"]; $totnetgross += $row["netgross"] * $row["m"]; } /* calculate current year fraction */ $fday = 1; $year_fmon = getYearOfEmpMon(3); $year_month = getYearOfEmpMon($month); $fmstart = mktime(0, 0, 0, 3, $fday, $year_fmon); $tmstart = mktime(0, 0, 0, $month, $day, $year_month); /* if weekly/fortnightly, find the first friday (effective first week) and last day of selected weeks */ if ($emp["payprd"] == "w" || $emp["payprd"] == "f") { payedbg("week: {$week}<br />"); /* effective first week */ while (date("w", $fmstart) != 5) { $fmstart = mktime(0, 0, 0, 3, ++$fday, $year_fmon); } /* end of week, find first week first */ while (date("w", $tmstart) != 5) { $tmstart = mktime(0, 0, 0, $month, ++$day, $year_month); } /* move the day by "week" number of weeks */ $day += ($week - 1) * ($emp["payprd"] == "w" ? 1 : 2) * 7; $tmstart = mktime(0, 0, 0, $month, $day, $year_month); // hack(fortnightly): increase to end of 1st week if ($emp["payprd"] == "f") { $fmstart += 7 * 24 * 60 * 60; //$tmstart += 7 * 24 * 60 * 60; } } /* count the periods in the past */ $curprd = prdage($fmstart, $tmstart, $emp["payprd"]); payedbg("curprd calc: " . mkdatet($fmstart) . " - " . mkdatet($tmstart) . BR); payedbg("curprd: {$curprd}<br />"); /* determine start period from the $curprd */ $finYearStart = getYearOfEmpMon(3); $styear = extractYear($emp["hiredate"]); $stmon = extractMonth($emp["hiredate"]); if ($styear < $finYearStart || $styear == $finYearStart && $stmon < 3) { $stprd = 1; } else { //$stprd = prdage(mktimefd($emp["hiredate"]), $tmstart, $emp["payprd"]); payedbg("stprd calc: " . date("Y-m-d", mktimefd(getYearOfEmpMon(3) . "-03-01"))); payedbg(" - " . date("Y-m-d", mktimefd($emp["hiredate"])) . "<br />"); $stprd = prdage(mktimefd(getYearOfEmpMon(3) . "-03-01"), mktimefd($emp["hiredate"]), $emp["payprd"]); } if ($prev_emp) { $working_prd = $curprd; $totprd = $tyear; //$totprd = $tyear - ($stprd - 0); } else { // num of prds working $working_prd = $curprd - ($stprd - 1); // total periods should be working this year $totprd = $tyear - ($stprd - 1); } payedbg("startprd: {$stprd}<br />"); payedbg("totprd: {$totprd}<br />"); payedbg("totgross: {$totgross}<br />"); payedbg("totnetgross: {$totnetgross}<br />"); payedbg("workprd: {$working_prd}<br />"); //$working_prd = 2; //$totprd = 7; $paye_salary = $totgross / $working_prd; payedbg("payesal1: {$paye_salary}<br />"); /* scale paye to amount of periods should be working */ $paye_salary *= $totprd / $tyear; //$paye_salary *= $tyear / $curprd; payedbg("payesal2: {$paye_salary}<br />"); $paye = bracket_calcpaye_old($age, $paye_salary, $tyear); if (($amt = sprint($paye * ($working_prd / $totprd) - $totpaye)) < 0) { $amt = 0; } return $amt; }