function cal($month, $year) { global $weekstarts, $display_day; $display_day="1111111"; if (!isset($weekstarts)) $weekstarts = 0; $s = ""; $daysInMonth = getDaysInMonth($month, $year); $date = mktime(12, 0, 0, $month, 1, $year); $first = (strftime("%w",$date) + 7 - $weekstarts) % 7; $monthName = utf8_strftime("%B",$date); $s .= "<table class=\"calendar2\" border=\"1\" cellspacing=\"3\">\n"; $s .= "<tr>\n"; $s .= "<td class=\"calendarHeader2\" colspan=\"7\">$monthName $year</td>\n"; $s .= "</tr>\n"; $d = 1 - $first; $is_ligne1 = 'y'; while ($d <= $daysInMonth) { $s .= "<tr>\n"; for ($i = 0; $i < 7; $i++) { $basetime = mktime(12,0,0,6,11+$weekstarts,2000); $show = $basetime + ($i * 24 * 60 * 60); $nameday = utf8_strftime('%A',$show); $temp = mktime(0,0,0,$month,$d,$year); if ($i==0) $s .= "<td class=\"calendar2\" style=\"vertical-align:bottom;\"><b>S".numero_semaine($temp)."</b></td>\n"; $s .= "<td class=\"calendar2\" align=\"center\" valign=\"top\">"; if ($is_ligne1 == 'y') $s .= '<b>'.ucfirst(substr($nameday,0,1)).'</b><br />'; if ($d > 0 && $d <= $daysInMonth) { $s .= $d; $day = grr_sql_query1("SELECT day FROM ".TABLE_PREFIX."_calendrier_jours_cycle WHERE day='$temp'"); $s .= "<br /><input type=\"checkbox\" name=\"$temp\" value=\"$nameday\" "; if (!($day < 0)) $s .= "checked=\"checked\" "; $s .= " />"; } else { $s .= " "; } $s .= "</td>\n"; $d++; } $s .= "</tr>\n"; $is_ligne1 = 'n'; } $s .= "</table>\n"; return $s; }
function slctDate() { db_connect(); #check what we have permission to $get_perm = "SELECT payroll_groups FROM users WHERE username = '******'USER_NAME']}' LIMIT 1"; $run_perm = db_exec($get_perm) or errDie("Unable to get payroll groups permission information."); if (pg_numrows($run_perm) > 0) { $parr = pg_fetch_array($run_perm); if (strlen($parr['payroll_groups']) > 0) { $pay_grps = explode(",", $parr['payroll_groups']); if (is_array($pay_grps)) { $egsearch = " AND (emp_group = '" . implode("' OR emp_group = '", $pay_grps) . "')"; } } else { $egsearch = "AND false"; } } $sql = "SELECT enum,empnum, sname, fnames FROM employees WHERE div = '" . USER_DIV . "' {$egsearch} ORDER BY sname"; $empRslt = db_exec($sql) or errDie("Unable to select employees from database."); if (pg_numrows($empRslt) < 1) { // return "No employees found in database.<p>" // .mkQuickLinks(); } $employees = array("0" => "All"); while ($d = pg_fetch_array($empRslt)) { $employees[$d["empnum"]] = "{$d['sname']}, {$d['fnames']} ({$d['enum']})"; } $fields = array("empnum" => 0, "from_year" => DATE_YEAR, "from_month" => DATE_MONTH, "from_day" => 1, "to_year" => DATE_YEAR, "to_month" => DATE_MONTH, "to_day" => getDaysInMonth(DATE_MONTH, DATE_YEAR)); foreach ($fields as $fname => $dflt) { if (!isset(${$fname})) { ${$fname} = $dflt; } } $OUT = "\n\t\t<h3>Select date range to view</h3>\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<input type='hidden' name='key' value='slip'>\n\t\t\t<tr>\n\t\t\t\t<th>Employee</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'>" . extlib_cpsel("empnum", $employees, $empnum) . "</td>\n\t\t\t</tr>\n\t\t\t<tr><th colspan='2'>Date Range</th></tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center' colspan='2'>\n\t\t\t\t\t" . mkDateSelect("from", $from_year, $from_month, $from_day) . "\n\t\t\t\t\t TO \n\t\t\t\t\t" . mkDateSelect("to", $to_year, $to_month, $to_day) . "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><input type='submit' value='View »'></td>\n\t\t\t</tr>\n\t\t</table>\n\t\t</form>" . mkQuickLinks(); return $OUT; }
function afterLastDayInMonth($curYear, $year, $month, $day) { $days_in_month = getDaysInMonth($month); for ($i = $days_in_month; $i > $days_in_month - 8; $i--) { if (date("D", mktime(0, 0, 0, $month, $i)) == $day) { $last_day = $i; break; } } $curDay = gmdate("d"); $curMonth = gmdate("m"); $curHour = gmdate("H"); $cur_stamp = mktime($curHour, 0, 0, $curMonth, $curDay, $curYear); $last_day_stamp = mktime(1, 0, 0, $month, $last_day, $year); if ($cur_stamp >= $last_day_stamp) { return true; } return false; }
$catFirstChildren = $oCat->getFirstChildren($cat_id); foreach ($catFirstChildren as $value) { $tabCat["{$value}"] = $oCat->getAllChildren($value); } // initialisation du tabeau pour le total de chaque année foreach ($catFirstChildren as $value) { $name = $oCat->getName($value); $cat_fils_annee["{$name}"] = 0; // total pour l'année } // Boucle sur les mois $cat_fils_mois_max = 0; for ($i = 1; $i <= 12; $i++) { // Initialisation $date_debut = mktime(0, 0, 0, "{$i}", '01', '2008'); $day = getDaysInMonth($i, 2008); $date_fin = mktime(0, 0, 0, "{$i}", "{$day}", '2008'); foreach ($catFirstChildren as $value) { $name = $oCat->getName($value); $cat_fils_mois["{$name}"][$i] = 0; } $cat_annee[$i] = 0; $query = "SELECT * FROM transactions WHERE\r\n date >= {$date_debut} AND\r\n date <= {$date_fin}"; $result = $mysql->query($query); while ($line = mysql_fetch_assoc($result)) { extract($line); if ($valeur > 0) { continue; } $valeur *= -1; foreach ($catFirstChildren as $value) {
function generateMonthView_small($month, $year, $view_diary) { global $_GET; $OUTPUT = "\r\n\t\t<table width=190 cellspacing=0>\r\n\t\t\t<tr>\r\n\t\t\t\t<td height=20 align=center " . TMPL_calSmallMonthTitleStyle . "\r\n\t\t\t\t\t\tonClick='document.location.href=\"" . SELF . "?key=month&month={$month}&year={$year}\"'>\r\n\t\t\t\t\t<b>" . getMonthText($month) . " {$year}</b>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t\t<tr>\r\n\t\t\t\t<td align=center " . TMPL_calSmallMonthBodyStyle . ">"; // generate the titles of the weekdays $OUTPUT .= "\r\n\t\t\t<table width='184' cellspacing=0>\r\n\t\t\t\t<tr>\r\n\t\t\t\t\t<td width=23> </td>\r\n\t\t\t\t\t<td width=23 align=center><b>M</b></td>\r\n\t\t\t\t\t<td width=23 align=center><b>T</b></td>\r\n\t\t\t\t\t<td width=23 align=center><b>W</b></td>\r\n\t\t\t\t\t<td width=23 align=center><b>T</b></td>\r\n\t\t\t\t\t<td width=23 align=center><b>F</b></td>\r\n\t\t\t\t\t<td width=23 align=center bgcolor=" . TMPL_calFillSaturday . "><b>S</b></td>\r\n\t\t\t\t\t<td width=23 align=center bgcolor=" . TMPL_calFillSunday . "><b>S</b></td>\r\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 = $_GET["month"]; // create the previous month's entries $c_weeknum = getWeekNumber($tmp_day, $tmp_month, $tmp_year); $selected_weeknum = getWeekNumber($_GET["mday"], $_GET["month"], $_GET["year"]); // 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 == $_GET["month"] && $c_weeknum == $selected_weeknum && $month == $_GET["month"] || $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 .= "<td {$dayfill} width=23 align=center>\r\n\t\t\t\t\t\t\t<a id='calSmallMonthOMLink' href='" . SELF . "?mday={$tmp_day}&month={$tmp_month}&year={$tmp_year}'>{$tmp_day}</a>\r\n\t\t\t\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 ($month == $_GET["month"] && $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 == $_GET["mday"] && $month == $_GET["month"] && $year == $_GET["year"]) { // 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 .= "<td width=23 {$dayfill} align=center>\r\n\t\t\t\t\t\t\t<a id='{$a_id}' href='" . SELF . "?mday={$c_day}&month={$month}&year={$year}&view_diary={$view_diary}'>{$c_day}</a>\r\n\t\t\t\t\t\t</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 = ""; } } $OUTPUT .= "<td {$dayfill} width=23 align=center>\r\n\t\t\t\t\t\t\t<a id='calSmallMonthOMLink' href='" . SELF . "?mday={$c_day}&month={$tmp_month}&year={$tmp_year}'>{$c_day}</a>\r\n\t\t\t\t\t\t</td>"; } // finish the tables and return $OUTPUT .= "\r\n\t\t\t\t</tr>\r\n\t\t\t</table>\r\n\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\t"; return $OUTPUT; }
function generateMonthView_large($month, $year, $view_diary) { global $_GET; $valid_date = mktime(0, 0, 0, $month, 1, $year); $month = date("m", $valid_date); $year = date("Y", $valid_date); $select_month = "<select name=month>"; for ($i = 1; $i <= 12; $i++) { if ($month == $i) { $sel = "selected"; } else { $sel = ""; } $select_month .= "<option {$sel} value='{$i}'>" . getMonthText($i) . "</option>"; } $select_month .= "</select>"; $select_year = "<select name=year>"; for ($i = 1971; $i <= 2028; $i++) { if ($year == $i) { $sel = "selected"; } else { $sel = ""; } $select_year .= "<option {$sel} value={$i}>{$i}</option>"; } $select_year .= "</select>"; $OUTPUT = "\r\n\t<table width=600 cellspacing=0>\r\n\t<tr>\r\n\t\t<td align=center style='font-size: 14px; color: #ffffff; font-weight: bold;' colspan=3>\r\n\t\t\t<form method=post action='" . SELF . "'>\r\n\t\t\t<input type=hidden name=key value='month'>\r\n\t\t\tGoto: {$select_month} {$select_year} <input type=submit value='Go'>\r\n\t\t\t</form>\r\n\t\t</td>\r\n\t</tr>\r\n\t<tr><td> </td></tr>\r\n <tr>\r\n \t<td colspan=3 " . TMPL_calTimeStyle2 . ">\r\n \t<table width=100%><tr>\r\n \t<td width=30% align=center valign=middle>\r\n \t\t<a href='" . SELF . "?key=month&month=" . ($month - 1) . "&year={$year}&view_diary={$view_diary}'>\r\n \t\t\t<img src='left_day.gif' border=0>\r\n\t\t\t</a>\r\n\t\t</td>\r\n\t\t<td width=40% valign=middle align=center " . TMPL_calTimeStyleHeader . ">\r\n\t\t\t<b>" . getMonthText($month) . " {$year}</b>\r\n\t\t</td>\r\n\t\t<td width=30% align=center valign=middle>\r\n\t\t\t<a href='" . SELF . "?key=month&month=" . ($month + 1) . "&year={$year}&view_diary={$view_diary}'>\r\n\t\t\t\t<img src='right_day.gif' border=0>\r\n\t\t\t</a>\r\n\t\t</td>\r\n\t\t</tr></table>\r\n\t\t</td>\r\n\t</tr>\r\n\t<tr>\r\n\t\t<td align=center " . TMPL_calLargeMonthBodyStyle . " colspan=3>\r\n\t\t<table width='600' cellspacing=0>\r\n\t\t<tr>\r\n\t\t\t<td width=75 height=60> </td>\r\n\t\t\t<td width=75 height=60 align=center><h1>M</h1></td>\r\n\t\t\t<td width=75 height=60 align=center><h1>T</h1></td>\r\n\t\t\t<td width=75 height=60 align=center><h1>W</h1></td>\r\n\t\t\t<td width=75 height=60 align=center><h1>T</h1></td>\r\n\t\t\t<td width=75 height=60 align=center><h1>F</h1></td>\r\n\t\t\t<td width=75 height=60 align=center bgcolor=" . TMPL_calFillSaturday . "><h1>S</h1></td>\r\n\t\t\t<td width=75 height=60 align=center bgcolor=" . TMPL_calFillSunday . "><h1>S</h1></td>\r\n\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) // 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 = $_GET["month"]; // create the previous month's entries $c_weeknum = getWeekNumber($tmp_day, $tmp_month, $tmp_year); $selected_weeknum = getWeekNumber($_GET["mday"], $_GET["month"], $_GET["year"]); $OUTPUT .= "<tr>"; if ($first_wd != 1) { // only if there is a day in this week of previous month, print the week number $OUTPUT .= "<td width=75 height=60 " . TMPL_calLargeMonthWeekNumberStyle . " 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) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } $OUTPUT .= "<td {$dayfill} width=75 style='border-bottom: 1px solid #000000;' height=60 align=center>\r\n\t\t\t\t<a id='calSmallMonthOMLink' href='" . SELF . "?mday={$tmp_day}&month={$tmp_month}&year={$tmp_year}'>{$tmp_day}</a>\r\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!!!!!) $OUTPUT .= "<tr>"; // attach the week number $OUTPUT .= "<td align=center width=75 height=60 " . TMPL_calLargeMonthWeekNumberStyle . ">{$c_weeknum}</td>"; } // change the fill color if it is 2day's date we are printing, or the selected date if (date("d") == $c_day && date("m") == $month && date("Y") == $year) { // 2day's date $dayfill = "bgcolor=" . TMPL_calLargeMonthSelectedDay; $a_id = "calSmallMonthCMLinkToday"; } else { // other dates // fill differently for saturday and sunday (only when the row has not already been colored) if ($c_weeknum == getTodayWeekNumber() && $year == date("Y") && $month == date("m")) { $dayfill = "bgcolor='" . TMPL_calLargeMonthCurrentWeek . "'"; } else { if ($c_wd == 6) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } } $a_id = "calSmallMonthCMLink"; } $weeknum_first = getWeekNumber(1, $month, $year); $weeknum_last = getWeekNumber(getDaysInMonth($month, $year), $month, $year); // create the borders for the days $b_top = "border-top: 1px solid #000000;"; $b_bottom = "border-bottom: 1px solid #000000;"; $b_right = "border-right: 1px solid #000000;"; $b_left = "border-left: 1px solid #000000;"; $day_style = "cursor: pointer; cursor: hand; {$b_left} {$b_bottom}"; // first_week if ($c_weeknum == $weeknum_first) { $day_style .= "{$b_top} {$b_left}"; } // sundays if ($c_wd == 7 || getDaysInMonth($month, $year) == $c_day) { $day_style .= "{$b_right}"; } // check appointment, reminders and create the day information $checkdate_start = date("Y-m-d", mktime(0, 0, 0, $month, $c_day, $year)); $checkdate_end = date("Y-m-d", mktime(0, 0, 0, $month, $c_day + 1, $year)); db_conn("cubit"); $sql = "SELECT * FROM diary_entries\r\n\t\t\tWHERE (DATE '{$checkdate_start}', DATE '{$checkdate_end}') OVERLAPS (time_start, time_end)"; $rslt = db_exec($sql) or errDie("Error checking for appointments"); $entrycount = pg_num_rows($rslt); if ($entrycount > 0) { $count_entireday = 0; $day_information = "<table width=100%>"; while ($row = pg_fetch_array($rslt)) { $appointment_url = "diary-appointment.php?entry_id={$row['entry_id']}&key=view"; $onClick = "popupOpen(\"{$appointment_url}\",\"appointment_popup\",\"scrollbars=yes,width=500,height=590\")"; $day_information .= "\r\n\t\t\t\t\t<tr><td onClick='{$onClick}' nowrap>\r\n\t\t\t\t\t\t{$row['title']}\r\n\t\t\t\t\t</td></tr>"; } $day_information .= "</table>"; } else { $day_information = " "; } $OUTPUT .= "\r\n\t\t\t<td width=75 height=60 {$dayfill} valign=top align=center style='{$day_style}'>\r\n\t\t\t\t<table width=100% height=100%>\r\n\t\t\t\t<tr><td valign=top align=right height=0% onClick='document.location.href=\"" . SELF . "?mday={$c_day}&month={$month}&year={$year}&view_diary={$view_diary}\";'>\r\n\t\t\t\t\t<font size=2 color='" . TMPL_calLargeMonthOMLink_a . "'><b>{$c_day}</b></font>\r\n\t\t\t\t</td></tr>\r\n\t\t\t\t<tr><td valign=top align=center height=100%>\r\n\t\t\t\t\t{$day_information}\r\n\t\t\t\t</td></tr>\r\n\t\t\t\t</table>\r\n\t\t\t</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) { $dayfill = "bgcolor=" . TMPL_calFillSaturday; } else { if ($c_wd == 7) { $dayfill = "bgcolor=" . TMPL_calFillSunday; } else { $dayfill = ""; } } $OUTPUT .= "<td {$dayfill} width=75 height=60 align=center>\r\n\t\t\t\t<a id='calSmallMonthOMLink' href='" . SELF . "?mday={$c_day}&month={$tmp_month}&year={$tmp_year}'>{$c_day}</a>\r\n\t\t\t</td>"; } // finish the tables and return $OUTPUT .= "\r\n\t\t\t</tr>\r\n\t\t</table>\r\n\r\n\t\t\t</td>\r\n\t\t</tr>\r\n\t</table>"; return $OUTPUT; }
function cal3($month, $year) { global $weekstarts; if (!isset($weekstarts)) { $weekstarts = 0; } $s = ""; $daysInMonth = getDaysInMonth($month, $year); $date = mktime(12, 0, 0, $month, 1, $year); $first = (strftime("%w", $date) + 7 - $weekstarts) % 7; $monthName = utf8_strftime("%B", $date); $s .= "<table class=\"calendar2\" border=\"1\" cellspacing=\"2\">\n"; $s .= "<tr>\n"; $s .= "<td class=\"calendarHeader2\" colspan=\"8\">{$monthName} {$year}</td>\n"; $s .= "</tr>\n"; $d = 1 - $first; $is_ligne1 = 'y'; while ($d <= $daysInMonth) { $s .= "<tr>\n"; for ($i = 0; $i < 7; $i++) { $basetime = mktime(12, 0, 0, 6, 11 + $weekstarts, 2000); $show = $basetime + $i * 24 * 60 * 60; $nameday = utf8_strftime('%A', $show); $temp = mktime(0, 0, 0, $month, $d, $year); if ($i == 0) { $s .= "<td class=\"calendar2\" style=\"vertical-align:bottom;\"><b>S" . getWeekNumber($temp) . "</b></td>\n"; } if ($d > 0 && $d <= $daysInMonth) { $temp = mktime(0, 0, 0, $month, $d, $year); $day = grr_sql_query1("SELECT day FROM " . TABLE_PREFIX . "_calendrier_jours_cycle WHERE day='{$temp}'"); $jour = grr_sql_query1("SELECT Jours FROM " . TABLE_PREFIX . "_calendrier_jours_cycle WHERE DAY='{$temp}'"); if (intval($jour) > 0) { $alt = get_vocab('jour_cycle') . " " . $jour; $jour = ucfirst(substr(get_vocab("rep_type_6"), 0, 1)) . $jour; } else { $alt = get_vocab('jour_cycle') . ' ' . $jour; if (strlen($jour) > 5) { $jour = substr($jour, 0, 3) . ".."; } } if (!isset($_GET["pview"])) { if ($day < 0) { $s .= "<td class=\"calendar2\" valign=\"top\" style=\"background-color:#FF8585\">"; } else { $s .= "<td class=\"calendar2\" valign=\"top\" style=\"background-color:#C0FF82\">"; } } else { $s .= "<td style=\"text-align:center;\" valign=\"top\">"; } if ($is_ligne1 == 'y') { $s .= '<b>' . ucfirst(substr($nameday, 0, 1)) . '</b><br />'; } $s .= "<b>" . $d . "</b>"; // Pour aller checher la date ainsi que son Jour cycle $s .= "<br />"; if (isset($_GET["pview"])) { if ($day < 0) { $s .= "<img src=\"../img_grr/stop.png\" class=\"image\" width=\"16\" height=\"16\" alt=\"no\"/>"; } else { $s .= "<span class=\"jour-cycle\">" . $jour . "</span>"; } } else { if ($day < 0) { $s .= "<a href=\"admin_calend_jour_cycle.php?page_calend=3&date=" . $temp . "\"><img src=\"../img_grr/stop.png\" class=\"image\" alt=\"(aucun)\" width=\"16\" height=\"16\" /></a>"; } else { $s .= "<a class=\"jour-cycle\" href=\"admin_calend_jour_cycle.php?page_calend=3&date=" . $temp . "\" title=\"" . $alt . "\" >" . $jour . "</a>"; } } } else { if (!isset($_GET["pview"])) { $s .= "<td class=\"calendar2\" valign=\"top\">"; } else { $s .= "<td style=\"text-align:center;\" valign=\"top\">"; } if ($is_ligne1 == 'y') { $s .= '<b>' . ucfirst(substr($nameday, 0, 1)) . '</b><br />'; } $s .= " "; } $s .= "</td>\n"; $d++; } $s .= "</tr>\n"; $is_ligne1 = 'n'; } $s .= "</table>\n"; return $s; }
function getHTML() { global $weekstarts, $vocab, $type_month_all, $display_day, $nb_display_day; // Calcul de la date courante $date_today = mktime(12, 0, 0, $this->month, $this->day, $this->year); // Calcul du numéro de semaine courante $week_today = numero_semaine($date_today); if (!isset($weekstarts)) $weekstarts = 0; $s = ""; $daysInMonth = getDaysInMonth($this->month, $this->year); // Calcul de la date au 1er du mois de la date courante $date = mktime(12, 0, 0, $this->month, 1, $this->year); $first = (strftime("%w",$date) + 7 - $weekstarts) % 7; $monthName = utf8_strftime("%B",$date); $prevMonth = $this->getCalendarLink($this->month - 1 > 0 ? $this->month - 1 : 12, $this->month - 1 > 0 ? $this->year : $this->year - 1); $nextMonth = $this->getCalendarLink($this->month + 1 <= 12 ? $this->month + 1 : 1, $this->month + 1 <= 12 ? $this->year : $this->year + 1); $s .= "<table border = \"0\" class=\"calendar\">\n"; $s .= "<tr><td></td>\n"; if (($this->h) and (($this->dmy=='month') or ($this->dmy=='month_all') or ($this->dmy=='month_all2') )) $bg_lign = "week"; else $bg_lign = 'calendarHeader'; $s .= "<td align=\"center\" valign=\"top\" class=\"$bg_lign\" colspan=\"".$nb_display_day."\">"; #Permet de récupérer le numéro de la 1ere semaine affichée par le mini calendrier. // $week = number_format(strftime("%W",$date),0); $week = numero_semaine($date); $weekd = $week; // on ajoute un lien vers le mois précédent if ($this->mois_precedent == 1) { $tmp = mktime(0, 0, 0, ($this->month)-1, 1, $this->year); $lastmonth = date("m",$tmp); $lastyear= date("Y",$tmp); if (($this->dmy!='day') and ($this->dmy!='week_all') and ($this->dmy!='month_all') and ($this->dmy!='month_all2')) $s .= "<a title=\"".grr_htmlSpecialChars(get_vocab("see_month_for_this_room"))."\" href=\"month.php?year=$lastyear&month=$lastmonth&day=1&area=$this->area&room=$this->room\"><<</a> "; else $s .= "<a title=\"".grr_htmlSpecialChars(get_vocab("see_all_the_rooms_for_the_month"))."\" href=\"".$type_month_all.".php?year=$lastyear&month=$lastmonth&day=1&area=$this->area\"><<</a> "; } if (($this->dmy!='day') and ($this->dmy!='week_all') and ($this->dmy!='month_all') and ($this->dmy!='month_all2')) $s .= "<a title=\"".grr_htmlSpecialChars(get_vocab("see_month_for_this_room"))."\" href=\"month.php?year=$this->year&month=$this->month&day=1&area=$this->area&room=$this->room\">$monthName $this->year</a>"; else $s .= "<a title=\"".grr_htmlSpecialChars(get_vocab("see_all_the_rooms_for_the_month"))."\" href=\"".$type_month_all.".php?year=$this->year&month=$this->month&day=1&area=$this->area\">$monthName $this->year</a>"; // on ajoute un lien vers le mois suivant if ($this->mois_suivant == 1) { $tmp = mktime(0, 0, 0, ($this->month)+1, 1, $this->year); $nextmonth = date("m",$tmp); $nextyear= date("Y",$tmp); if (($this->dmy!='day') and ($this->dmy!='week_all') and ($this->dmy!='month_all') and ($this->dmy!='month_all2')) $s .= " <a title=\"".grr_htmlSpecialChars(get_vocab("see_month_for_this_room"))."\" href=\"month.php?year=$nextyear&month=$nextmonth&day=1&area=$this->area&room=$this->room\">>></a>"; else $s .= " <a title=\"".grr_htmlSpecialChars(get_vocab("see_all_the_rooms_for_the_month"))."\" href=\"".$type_month_all.".php?year=$nextyear&month=$nextmonth&day=1&area=$this->area\">>></a>"; } $s .= "</td>\n"; $s .= "</tr>\n"; $s .= "<tr><td></td>\n"; $s .= getFirstDays(); $s .= "</tr>\n"; $d = 1 - $first; $temp = 1; while ($d <= $daysInMonth) { // if (($date_today <= $date) and ($this->h) and (($this->dmy=='week_all') or ($this->dmy=='week') )) $bg_lign = " class=\"week\""; else $bg_lign = ''; if (($week_today == $week) and ($this->h) and (($this->dmy=='week_all') or ($this->dmy=='week') )) $bg_lign = " class=\"week\""; else $bg_lign = ''; $s .= "<tr ".$bg_lign."><td class=\"calendarcol1\" align=\"right\" valign=\"top\">"; #Affichage du numéro de la semaine en cours à droite du calendrier et génère un lien sur la semaine voulue. if (($this->dmy!='day') and ($this->dmy!='week_all') and ($this->dmy!='month_all') and ($this->dmy!='month_all2')) $s .="<a title=\"".grr_htmlSpecialChars(get_vocab("see_week_for_this_room"))."\" href=\"week.php?year=$this->year&month=$this->month&day=$temp&area=$this->area&room=$this->room\">s".sprintf("%02d",$week)."</a>"; else $s .="<a title=\"".grr_htmlSpecialChars(get_vocab("see_week_for_this_area"))."\" href=\"week_all.php?year=$this->year&month=$this->month&day=$temp&area=$this->area\">s".sprintf("%02d",$week)."</a>"; $temp=$temp+7; while ((!checkdate($this->month, $temp, $this->year)) and ($temp > 0)) $temp--; #Nouveau affichage, affiche le numéro de la semaine dans l'année.Incrémentation de ce numéro à chaque nouvelle semaine. $date = mktime(12, 0, 0, $this->month, $temp, $this->year); $week = numero_semaine($date); $s .= "</td>\n"; for ($i = 0; $i < 7; $i++) { $j = ($i + 7 + $weekstarts) % 7; if ($display_day[$j] == "1") {// début condition "on n'affiche pas tous les jours de la semaine" if (($this->dmy == 'day') and ($d == $this->day) and ($this->h)) $s .= "<td class=\"week\" align=\"right\" valign=\"top\">"; else $s .= "<td class=\"calendar\" align=\"right\" valign=\"top\">"; if ($d > 0 && $d <= $daysInMonth) { $link = $this->getDateLink($d, $this->month, $this->year); if ($link == "") $s .= $d; #Permet de colorer la date affichée sur la page elseif (($d == $this->day) and ($this->h)) $s .= $link."><span class=\"cal_current_day\">$d</span></a>"; else $s .= $link.">$d</a>"; } else $s .= " "; $s .= "</td>\n"; }// fin condition "on n'affiche pas tous les jours de la semaine" $d++; } $s .= "</tr>\n"; } if ($week-$weekd<6) $s .= "<tr><td> </td></tr>"; $s .= "</table>\n"; return $s; }
function cal($month, $year) { global $weekstarts; if (!isset($weekstarts)) { $weekstarts = 0; } $s = ""; $daysInMonth = getDaysInMonth($month, $year); $date = mktime(12, 0, 0, $month, 1, $year); $first = (strftime("%w", $date) + 7 - $weekstarts) % 7; $monthName = ucfirst(utf8_strftime("%B", $date)); $s .= '<table class="table calendar2">' . PHP_EOL; $s .= '<tr>' . PHP_EOL; $s .= '<td class="calendarHeader2" colspan="8">' . $monthName . ' ' . $year . '</td>' . PHP_EOL; $s .= '</tr>' . PHP_EOL; $d = 1 - $first; $is_ligne1 = 'y'; while ($d <= $daysInMonth) { $s .= '<tr>' . PHP_EOL; for ($i = 0; $i < 7; $i++) { $basetime = mktime(12, 0, 0, 6, 11 + $weekstarts, 2000); $show = $basetime + $i * 24 * 60 * 60; $nameday = utf8_strftime('%A', $show); $temp = mktime(0, 0, 0, $month, $d, $year); if ($i == 0) { $s .= '<td class="calendar2" style="vertical-align:bottom;"><b>S' . getWeekNumber($temp) . '</b></td>' . PHP_EOL; } $s .= '<td class="calendar2" align="center" valign="top">' . PHP_EOL; if ($is_ligne1 == 'y') { $s .= '<b>' . ucfirst(substr($nameday, 0, 1)) . '</b><br />'; } if ($d > 0 && $d <= $daysInMonth) { $s .= $d; $day = grr_sql_query1("SELECT day FROM " . TABLE_PREFIX . "_calendar WHERE day='{$temp}'"); $s .= '<br><input type="checkbox" name="' . $temp . '" value="' . $nameday . '" '; if (!($day < 0)) { $s .= 'checked="checked" '; } $s .= '/>'; } else { $s .= " "; } $s .= '</td>' . PHP_EOL; $d++; } $s .= '</tr>' . PHP_EOL; $is_ligne1 = 'n'; } $s .= '</table>' . PHP_EOL; return $s; }
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; }
/** * 祝日テーブルを作成 * @param int $year 西暦年(計算開始年) * @return string 祝日の名称/FALSE=祝日ではない */ function getHoliday($year) { static $youbi = array('日', '月', '火', '水', '木', '金', '土', '日'); if ($year == FALSE) { return ''; } $holidays = array(); $flag = FALSE; //Google Calendar APIを使って祝日を取得 for ($yyyy = $year; $yyyy < $year + 3; $yyyy++) { $n = getHoliday_by_Google($yyyy, $holidays); if ($n > 0) { $flag = TRUE; } if (!$flag) { break; } } if ($flag) { $msg = "<table border=\"1\">\n"; for ($yyyy = $year; $yyyy < $year + 3; $yyyy++) { $cnt = 1; $msg .= sprintf("<tr><td colspan=\"3\">%04d年</td></tr>\n", $yyyy); for ($month = 1; $month <= 12; $month++) { $day_of_month = getDaysInMonth($yyyy, $month); for ($day = 1; $day <= $day_of_month; $day++) { $key = sprintf("%04d-%02d-%02d", $year, $month, $day); $name = isset($holidays[$key]) ? $holidays[$key] : FALSE; $ww = getWeekNumber($yyyy, $month, $day); if ($name != FALSE) { $msg .= sprintf("<tr><td>%02d</td><td>%02d月%02d日(%s)</td><td>%s</td></tr>\n", $cnt, $month, $day, $youbi[$ww], $name); $cnt++; } } } } $msg .= "</table>\n"; } else { $msg = 'error > Google Calendar APIから祝日を取得できません.'; } return $msg; }
function display($_POST) { extract($_POST); global $PRDMON; #determine the date range based on period selection if (isset($year_to_process)) { switch ($year_to_process) { case "active": $fdate_year = getYearOfFinPrd(1); $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12); $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; case "previous": $fdate_year = getYearOfFinPrd(1) - 1; $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12) - 1; $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; default: $fdate_year = getYearOfFinPrd(1); $fdate_month = "03"; $fdate_day = "01"; $tdate_year = getYearOfFinPrd(12); $tdate_month = "02"; $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year)); } } // ----------------------------------------------------------------------- // Sanity checks // ----------------------------------------------------------------------- require_lib("validate"); $v = new validate(); // Does this employee number actually exist db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'"; $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit."); if (pg_num_rows($empinf_rslt) == 0) { $v->addError(0, "Employee number not found in Cubit."); } $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)"); $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)"); $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)"); $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)"); if ($fdate_month > 12) { $v->addError(0, "Invalid from date (month)"); } if ($fdate_year < 1970 || $fdate_year > 2050) { $v->addError(0, "Invalid from date (year)"); } if ($tdate_month > 12) { $v->addError(0, "Invalid to date (month)"); } if ($tdate_year < 1970 || $tdate_year > 2050) { $v->addError(0, "Invalid to date (year)"); } if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) { $v->addError(0, "Invalid from date (day)"); } if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) { $v->addError(0, "Invalid to date (day)"); } $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year); $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year); if ($from_time > $to_time) { $v->addError(0, "Invalid date range specified."); } if (isset($income_code)) { foreach ($income_code as $id => $value) { $v->isOk($income_code[$id], "numeric", 1, 4, "Invalid income code."); $v->isOk($income_description[$id], "string", 1, 80, "Invalid income description."); $v->isOk($income_rfind[$id], "string", 1, 30, "Invalid RF IND."); $v->isOk($income_amount[$id], "float", 1, 9, "Invalid income amount."); } } // Return the errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class='err'>{$e['msg']}</li>"; } return slct($confirm); } $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}"; $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}"; $gross_taxable_annual_payments = 0.0; $gross_non_taxable_income = 0.0; $gross_retirement_funding_income = 0.0; $gross_non_retirement_funding_income = 0.0; $gross_remuneration = 0.0; db_conn("cubit"); $sql = "SELECT * FROM compinfo"; $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit."); $compinfo = pg_fetch_array($compinfo_rslt); db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'"; $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit."); $empinfo = pg_fetch_array($empinfo_rslt); $header_out = "<b>Return of payment for work & services from which no employees tax was deducted</b>"; $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}")); $employer_irp5_number_out = array(array("<b>IT 3(a) number:</b> {$irp5_number}")); $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}")); $employer_tax_year_out = array(array("<b>Tax year:</b> {$fdate_year}")); $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}")); $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}")); $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}")); $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); // Extract the employee's birth date from her id number $bd_year = 1900 + substr($empinfo["idnum"], 0, 2); $bd_month = substr($empinfo["idnum"], 2, 2); $bd_day = substr($empinfo["idnum"], 4, 2); $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}")); $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}")); $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}")); $fnames = explode(" ", $empinfo["fnames"]); $initials = ""; foreach ($fnames as $name) { $initials .= strtoupper($name[0]); } $employee_initials_out = array(array("<b>Initials:</b> {$initials}")); $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}")); $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}")); $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}")); $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}")); $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}")); $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}")); $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}")); $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}")); $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}")); $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}")); $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}")); // Income sources -------------------------------------------------------- $income_sources_out = array(); $income_taxable_total = 0; $income_reimburse_total = 0; $income_travelallowance_total = 0; $income_subsis_total = 0; $income_otherallowance_total = 0; $deduction_motorcar_total = 0; db_conn("cubit"); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_taxable_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total); #handle travel allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_travelallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total); #handle reimbursements .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_reimburse_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total); #handle subsistance allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_subsis_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total); #handle other allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_otherallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total); #handle motorcar DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB')"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_motorcar_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total); if (!empty($nincome_code) || !empty($nincome_description) || !empty($nincome_rfind) || !empty($nincome_amount)) { $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount); } if (isset($income_code)) { foreach ($income_code as $id => $value) { if ($income_code[$id] != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]); } else { $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => ""); } } } $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Gross renumeration ---------------------------------------------------- // Taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE code='3695' AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE code='3695' AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_income_sources_data["amount"]; } // Non taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_income_sources_data["amount"]; } // Gross retirement funding income db_conn("cubit"); $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit."); $emp_data = pg_fetch_array($rslt); $gross_retirement_funding_income += $gross_non_taxable_income / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"]; // Gross non retirement funding income db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code!='3603' OR code!='3604' OR code!='3610' OR code!='3615') AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code != '3603' OR code != '3604' OR code != '3610' OR code != '3615') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_income_sources_data["amount"]; } // Gross Remuneration $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income; $gross_remuneration_out = array(array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration)); $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // Deductions ------------------------------------------------------------ $deductions_out = array(); $deduction_pension_total = 0; $deduction_provident_total = 0; $deduction_medicalaid_total = 0; $deduction_retirementann_total = 0; $deduction_premiumpol_total = 0; db_conn("cubit"); #handle pension deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_pension_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total); #handle provident deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_provident_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total); #handle retirement annuity deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_retirementann_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total); $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_premiumpol_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total); // db_conn("cubit"); // $sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'"; // $empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'"); // // while ($empded_data = pg_fetch_array($empded_rslt)) { // db_conn("cubit"); // $sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit."); // $ded_data = pg_fetch_array($rslt); // // $deductions_out[] = array ( // "<b>CODE</b>"=>"$ded_data[code]", // "<b>DESCRIPTION</b>"=>"$ded_data[deduction]", // "<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2 // ); // } if (!isset($deductions_out[0])) { $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => "")); } $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Employees Tax deductions----------------------------------------------- $site_amount = 0; // Retrieve PAYE amount from Cubit db_conn("cubit"); $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit"); $paye_amount = 0; while ($empded_data = pg_fetch_array($rslt)) { $paye_amount += $empded_data["amount"]; } // Total tax deductions $tax_deductions_amount = $site_amount + $paye_amount; $non_deduction_of_tax_out = array(array("<b>CODE</b>" => "01", "<b>DESCRIPTION</b>" => "DIRECTORS REMUNERATION - PRIVATE COMPANY / CC"), array("<b>CODE</b>" => "02", "<b>DESCRIPTION</b>" => "LESS THAN THE TAX THRESHOLD"), array("<b>CODE</b>" => "03", "<b>DESCRIPTION</b>" => "INDEPENDENT CONTRACTOR"), array("<b>CODE</b>" => "04", "<b>DESCRIPTION</b>" => "NON TAXABLE EARNINGS")); $non_deduction_of_tax_cols = array("<b>CODE</b>" => array("width" => 40)); if (!isset($reason_code)) { $reason_code = ""; } $reason_out = array(array("{$reason_code}")); // ----------------------------------------------------------------------- // Do the actual rendering of the pdf // ----------------------------------------------------------------------- $pdf =& new Cezpdf(); global $set_mainFont; $pdf->selectFont($set_mainFont); $pdf->addInfo("Title", "IT 3(a) for {$empinfo['fnames']} {$empinfo['sname']}"); $pdf->addInfo("Author", USER_NAME); $irp5_pos = drawText(&$pdf, "<b>IT 3(a)</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IT 3(a)</b>"), 0); $header_pos = drawText(&$pdf, $header_out, 10, 520 - $pdf->getTextWidth(10, $header_out), $irp5_pos['y'] + 14); // Employer information -------------------------------------------------- $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14); $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1); $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1); $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1); $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1); $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1); $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4); $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols); // Employee information -------------------------------------------------- $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15); $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1); $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1); $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1); $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1); $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1); $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4); $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols); $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1); $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1); $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1); $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1); $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1); // Tax calculation information ------------------------------------------- $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15); $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1); $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); drawTable2(&$pdf, $tax_directive_number_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); // Income sources -------------------------------------------------------- $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_employed_frm_pos['y'] + 15); $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1); $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15); $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 4, $gross_remuneration_cols, 1); $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15); $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1); $non_deduction_of_tax_head = drawText(&$pdf, "<b>REASON FOR NON DEDUCTION OF EMPLOYEES TAX MUST BE STATED</b>", 8, 0, $deductions_pos['y'] + 15); $non_deduction_of_tax_pos = drawTable2(&$pdf, $non_deduction_of_tax_out, 0, $non_deduction_of_tax_head['y'] + 2, 420, 4, $non_deduction_of_tax_cols, 1); $reason_text = drawText(&$pdf, "<b>Reason Code</b>", 7, $non_deduction_of_tax_pos['x'] + 10, $non_deduction_of_tax_pos['y']); $reason_pos = drawTable2(&$pdf, $reason_out, $reason_text['x'] + 15, $non_deduction_of_tax_pos['y'] - 10, 40, 1); // Footer note ----------------------------------------------------------- $certificate_attatch = drawText(&$pdf, "Attach this copy to your form IT 3", 6, 0, $non_deduction_of_tax_pos['y'] + 10); $pdf->ezStream(); }
/** * 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 slct($errors = "") { global $_POST; extract($_POST); $fields["fdate_year"] = date("Y") - 1; $fields["fdate_month"] = "03"; $fields["fdate_day"] = "01"; $fields["tdate_year"] = date("Y"); $fields["tdate_month"] = "02"; $fields["tdate_day"] = getDaysInMonth($fields["tdate_month"], $fields["tdate_year"]); $fields["irp5_number"] = ""; $fields["directive_number"] = ""; $fields["over_deduction"] = ""; $fields["pay_periods"] = ""; $fields["pay_periods_worked"] = ""; foreach ($fields as $var_name => $value) { if (!isset(${$var_name})) { ${$var_name} = $value; } } require "irp5-codes.php"; // Income sources dropdown $nincome_codes_sel = "<select name='nincome_code' style='width: 180px'>\n\t\t<option value='0'>Please select</option>"; foreach ($income_codes as $category => $value) { foreach ($value as $code => $description) { $nincome_codes_sel .= "<option value='{$code}'>{$code} - {$description}</option>"; } } $nincome_codes_sel .= "</select>"; $income_sources_out = "<tr class='bg-odd'>\n\t\t<td>{$nincome_codes_sel}</td>\n\t\t<td align=center><input type=text name=nincome_description size=100%></td>\n\t\t<td align=center>\n\t\t\t<select name=nincome_rfind>\n\t\t\t\t<option value='N'>No</option>\n\t\t\t\t<option value='Y'>Yes</option>\n\t\t\t</select>\n\t\t</td>\n\t\t<td align=center><input type=text name=nincome_amount size=10%></td>\n\t\t<td> </td>\n\t</tr>"; // Retrieve the saved income sources from Cubit db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE empnum='{$empnum}' ORDER BY id DESC"; $rslt = db_exec($sql) or errDie("Unable to retrieve income sources from Cubit."); // Should we add the update button if (pg_num_rows($rslt) < 20) { $update_out = "<input type=submit value='Update'>"; } else { $update_out = ""; } $i = 0; while ($income_data = pg_fetch_array($rslt)) { // Income sources dropdown $income_codes_sel = "<select name='income_code[{$income_data['id']}]' style='width: 180px'>\n\t\t\t<option value='0'>Please select</option>"; foreach ($income_codes as $category => $value) { foreach ($value as $code => $description) { if ($code == $income_data["code"]) { $selected = "selected"; } else { $selected = ""; } $income_codes_sel .= "<option value='{$code}' {$selected}>{$code} - {$description}</option>"; } } $income_codes_sel .= "</select>"; // RF IND dropdown $rf_ind_vals = array("N" => "No", "Y" => "Yes"); $rf_ind_sel = "<select name='income_rfind[{$income_data['id']}]'"; foreach ($rf_ind_vals as $key => $value) { if ($key == $income_data["rf_ind"]) { $selected = "selected"; } else { $selected = ""; } $rf_ind_sel .= "<option value='{$key}' {$selected}>{$value}</option>"; } $rf_ind_sel .= "</select>"; $income_sources_out .= "<tr class='" . bg_class() . "'>\n\t\t\t<td width=20%>{$income_codes_sel}</td>\n\t\t\t<td align=center><input type=text name='income_description[{$income_data['id']}]' size=100% value='{$income_data['description']}'></td>\n\t\t\t<td align=center>{$rf_ind_sel}</td>\n\t\t\t<td align=center><input type=text name='income_amount[{$income_data['id']}]' size=10% value='{$income_data['amount']}'></td>\n\t\t\t<td><input type=checkbox name=income_rem[{$income_data['id']}] size=10%></td>\n\t\t</tr>"; } // Retrieve employee details db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit."); $empinfo = pg_fetch_array($rslt); $OUTPUT = "<center>\n\t<h3>IRP 5 Output for {$empinfo['fnames']} {$empinfo['sname']}</h3>\n\t<form method=post action='" . SELF . "'>\n\t<input type=hidden name=key value='update'>\n\t<input type=hidden name=empnum value='{$empnum}'>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr>\n\t\t\t<th colspan=5>Date Range</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td><b>From</b></td>\n\t\t\t<td>" . mkDateSelect("fdate", $fdate_year, $fdate_month, $fdate_day) . "</td>\n\t\t\t<td><b>To</b></td>\n\t\t\t<td>" . mkDateSelect("tdate", $tdate_year, $tdate_month, $tdate_day) . "</td>\n\t\t</tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "'>\n\t\t<tr>\n\t\t\t<th colspan=2>Values</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>IRP 5 Number</td>\n\t\t\t<td><input type=text name='irp5_number' value='{$irp5_number}'></td>\n\t\t</tr>\n\t\t<tr class='bg-even'>\n\t\t\t<td>Directive Number</td>\n\t\t\t<td><input type=text name='directive_number' value='{$directive_number}'></td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Voluntary over-deduction</td>\n\t\t\t<td><input type=text name='over_deduction' value='{$over_deduction}'></td>\n\t\t</tr>\n\t</table>\n\t<p>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' width=100%>\n\t\t<tr>\n\t\t\t<td colspan=5>{$errors}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan=5>Income Sources</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th align=left width=10%>Code</th>\n\t\t\t<th align=left width=70%>Description</th>\n\t\t\t<th align=left width=10%>RF IND</th>\n\t\t\t<th align=left width=10%>Amount</th>\n\t\t\t<th> </th>\n\t\t</tr>\n\t\t{$income_sources_out}\n\t</table>\n\t<p>\n\t{$update_out}\n\t<input type=submit name=display value='Done »'>\n\t</form>\n\t</center>"; return $OUTPUT; }
function slctDate() { db_connect(); #check what we have permission to $get_perm = "SELECT payroll_groups FROM users WHERE username = '******'USER_NAME']}' LIMIT 1"; $run_perm = db_exec($get_perm) or errDie("Unable to get payroll groups permission information."); if (pg_numrows($run_perm) > 0) { $parr = pg_fetch_array($run_perm); if (strlen($parr['payroll_groups']) > 0) { $pay_grps = explode(",", $parr['payroll_groups']); if (is_array($pay_grps)) { $egsearch = " AND (emp_group = '" . implode("' OR emp_group = '", $pay_grps) . "')"; } } else { $egsearch = "AND false"; } } $sql = "SELECT enum,empnum, sname, fnames FROM employees WHERE div = '" . USER_DIV . "' {$egsearch} ORDER BY sname"; $empRslt = db_exec($sql) or errDie("Unable to select employees from database."); if (pg_numrows($empRslt) < 1) { // return "No employees found in database.<p>" // .mkQuickLinks(); } $employees = array("0" => "All"); while ($d = pg_fetch_array($empRslt)) { $employees[$d["empnum"]] = "{$d['sname']}, {$d['fnames']} ({$d['enum']})"; } $fields = array("empnum" => 0, "from_year" => DATE_YEAR, "from_month" => DATE_MONTH, "from_day" => 1, "to_year" => DATE_YEAR, "to_month" => DATE_MONTH, "to_day" => getDaysInMonth(DATE_MONTH, DATE_YEAR)); foreach ($fields as $fname => $dflt) { if (!isset(${$fname})) { ${$fname} = $dflt; } } $get_egroups = "SELECT * FROM emp_groups ORDER BY emp_group"; $run_egroups = db_exec($get_egroups) or errDie("Unable to get employee group information."); if (pg_numrows($run_egroups) < 1) { $emp_group_drop = "<input type='hidden' name='emp_group[]' value='0'>No Employee Groups Found."; } else { $emp_group_drop = "<select name='emp_group[]' multiple size='5'>"; $emp_group_drop .= "<option value='0'>All</option>"; while ($garr = pg_fetch_array($run_egroups)) { $emp_group_drop .= "<option value='{$garr['id']}'>{$garr['emp_group']}</option>"; } $emp_group_drop .= "</select>"; } db_connect(); $get_years = "SELECT distinct (cyear) FROM salpaid ORDER BY cyear"; $run_years = db_exec($get_years) or errDie("Unable to get salary processed years."); if (pg_numrows($run_years) < 1) { $sal_year_drop = "<input type='hidden' name='salyear' value='" . EMP_YEAR . "'>No Previously Processed Salaries Found."; } else { $sal_year_drop = "<select name='salyear'>"; while ($sarr = pg_fetch_array($run_years)) { if ($sarr['cyear'] == EMP_YEAR) { $sal_year_drop .= "<option value='{$sarr['cyear']}' selected>{$sarr['cyear']}</option>"; } else { $sal_year_drop .= "<option value='{$sarr['cyear']}'>{$sarr['cyear']}</option>"; } } $sal_year_drop .= "</select>"; } $OUT = "\n\t\t<h3>Select date range to view</h3>\n\t\t<form action='" . SELF . "' method='POST'>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<input type='hidden' name='key' value='slip'>\n\t\t\t<tr>\n\t\t\t\t<th>Employee</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'>" . extlib_cpsel("empnum", $employees, $empnum) . "</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Employee Group</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'>{$emp_group_drop}</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th colspan='2'>Date Range</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center' colspan='2'>\n\t\t\t\t\t" . mkDateSelect("from", $from_year, $from_month, $from_day) . "\n\t\t\t\t\t TO \n\t\t\t\t\t" . mkDateSelect("to", $to_year, $to_month, $to_day) . "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<th>Select Salary Financial Year</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td align='center'>{$sal_year_drop}</td>\n\t\t\t</tr>\n\t\t <tr>\n\t\t \t<td colspan='2' align='right'><input type='submit' value='View »'></td>\n\t\t </tr>\n\t </table>\n\t </form>" . mkQuickLinks(); return $OUT; }
$day_old[$i] = $row_old[0]; } } // On vide la table ".TABLE_PREFIX."_calendar $sql = "TRUNCATE table " . TABLE_PREFIX . "_calendar"; if (grr_sql_command($sql) < 0) { fatal_error(0, "<p>" . grr_sql_error()); } $result = 0; $end_bookings = Settings::get("end_bookings"); $n = Settings::get("begin_bookings"); $month = strftime("%m", Settings::get("begin_bookings")); $year = strftime("%Y", Settings::get("begin_bookings")); $day = 1; while ($n <= $end_bookings) { $daysInMonth = getDaysInMonth($month, $year); $day = 1; while ($day <= $daysInMonth) { $n = mktime(0, 0, 0, $month, $day, $year); if (isset($_POST[$n])) { // Le jour a été selectionné dans le calendrier $starttime = mktime($morningstarts, 0, 0, $month, $day, $year); $endtime = mktime($eveningends, 0, $resolution, $month, $day, $year); // Pour toutes les dates bon précédement enregistrées, on efface toutes les résa en conflit if (!in_array($n, $day_old)) { $sql = "select id from " . TABLE_PREFIX . "_room"; $res = grr_sql_query($sql); if ($res) { for ($i = 0; $row = grr_sql_row($res, $i); $i++) { $result += grrDelEntryInConflict($row[0], $starttime, $endtime, 0, 0, 1); }
function displayDays($year, $month, $tabs = 3) { global $db, $selectedDate, $config; if (!is_numeric($month) || !is_numeric($year) || is_numeric($month) && ($month > 12 || $month < 1) || is_numeric($year) && $year < 2000) { return false; } $days = array(); $max = 0; $total = 0; $date = getdate(mktime(1, 0, 0, $month, 1, $year)); $wd = $date['wday']; $x = str_repeat("\t", $tabs); $y = str_repeat("\t", $tabs + 1); $_year = "YEAR(FROM_UNIXTIME(`time`" . DB_OFFSET . "))"; $_month = "MONTH(FROM_UNIXTIME(`time`" . DB_OFFSET . "))"; $path = s(rtrim($config['path'], "/")); $q = $db->query("SELECT DAY(FROM_UNIXTIME(`time`" . DB_OFFSET . ")) as d, " . $_month . " AS m, " . $_year . " AS y, `type`, COUNT(*) AS c FROM `" . DTP . "tweets` WHERE " . $_year . " = '" . $db->s($year) . "' AND " . $_month . " = '" . $db->s($month) . "' GROUP BY y, m, d, `type` ORDER BY y ASC, m ASC, d ASC, `type` ASC"); while ($r = $db->fetch($q)) { if (!array_key_exists($r['d'], $days)) { $days[$r['d']] = array("total" => 0); } $days[$r['d']]['total'] += $r['c']; $days[$r['d']]['c' . $r['type']] = $r['c']; if ($days[$r['d']]['total'] > $max) { $max = $days[$r['d']]['total']; } $total += $r['c']; } $daysInMonth = getDaysInMonth($month, $year); $s = "<div id=\"days\" class=\"days-" . s($daysInMonth) . "\"><div class=\"dr\">\n"; for ($i = 0; $i < $daysInMonth; $i++) { $today = $selectedDate['y'] == $year && $selectedDate['m'] == $month && $selectedDate['d'] == $i + 1; if (array_key_exists($i + 1, $days)) { $d = $days[$i + 1]; $s .= $y . "<div class=\"d\"><a title=\"" . s($d['total']) . " tweet" . ($d['total'] == 1 ? "" : "s") . (!empty($d['c1']) ? ", " . s($d['c1']) . " repl" . ($d['c1'] == 1 ? "y" : "ies") : "") . (!empty($d['c2']) ? ", " . s($d['c2']) . " retweet" . ($d['c2'] == 1 ? "" : "s") : "") . "\" href=\"" . $path . "/" . s($year) . "/" . s(pad($month)) . "/" . s(pad($i + 1)) . "\">" . "<span class=\"p\" style=\"height:" . round($d['total'] / $max * 250, 2) . "px\">" . "<span class=\"n\">" . ($d['total'] != 1 ? number_format($d['total']) : "") . "</span>" . (!empty($d['c1']) ? "<span class=\"r\" style=\"height:" . round($d['c1'] / $max * 250, 2) . "px\"></span>" : "") . (!empty($d['c2']) ? "<span class=\"rt\" style=\"height:" . round($d['c2'] / $max * 250, 2) . "px\"></span>" : "") . "</span><span class=\"m" . ($wd == 0 || $wd == 6 ? " mm" : "") . ($today ? " ms" : "") . "\">" . ($today ? "<strong>" : "") . s($i + 1) . ($today ? "</strong>" : "") . "</span></a></div>\n"; } else { $s .= $y . "<div class=\"d\"><a href=\"" . $path . "/" . s($year) . "/" . s(pad($month)) . "/" . s(pad($i + 1)) . "\">" . "<span class=\"z\">0</span><span class=\"m" . ($wd == 0 || $wd == 6 ? " mm" : "") . ($today ? " ms" : "") . "\">" . ($today ? "<strong>" : "") . s($i + 1) . ($today ? "</strong>" : "") . "</span></a></div>\n"; } $wd = $wd == 6 ? 0 : $wd + 1; } $s .= $x . "</div></div>\n"; return $s; }
function afterLastDayInMonth($curYear, $year, $month, $day, $gmt_offset) { $days_in_month = getDaysInMonth($month); for ($i = $days_in_month; $i > $days_in_month - 8; $i--) { if (date("D", mktime(0, 0, 0, $month, $i)) == $day) { $last_day = $i; break; } } $curDay = gmdate("d"); $curMonth = gmdate("m"); /* All EU countries observe the DST change at 1 am GMT */ $curHour = gmdate("H"); /* The current time stamp */ $cur_stamp = mktime($curHour, 0, 0, $curMonth, $curDay, $curYear); /* Time stamp for the first occurence for the specified day in the month */ $last_day_stamp = mktime(1, 0, 0, $month, $last_day, $year); if ($cur_stamp >= $last_day_stamp) { return true; } return false; }
function display($_POST) { extract($_POST); global $PRDMON; #determine the date range based on period selection if (isset($year_to_process)) { switch ($year_to_process) { case "active": $fdate_year = getYearOfFinPrd(1); $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12); $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; case "previous": $fdate_year = getYearOfFinPrd(1) - 1; $fdate_month = $PRDMON[1]; $fdate_day = "1"; $tdate_year = getYearOfFinPrd(12) - 1; $tdate_month = $PRDMON[12]; $tdate_day = date("d", mktime(0, 0, 0, $PRDMON[12] + 1, 0, $tdate_year)); break; default: $fdate_year = getYearOfFinPrd(1); $fdate_month = "03"; $fdate_day = "01"; $tdate_year = getYearOfFinPrd(12); $tdate_month = "02"; $tdate_day = date("d", mktime(0, 0, 0, 3, 0, $tdate_year)); } } // ----------------------------------------------------------------------- // Sanity checks // ----------------------------------------------------------------------- require_lib("validate"); $v = new validate(); // Does this employee number actually exist db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='" . (int) $empnum . "' AND div='" . USER_DIV . "'"; $empinf_rslt = db_exec($sql) or errDie("Unable to retrieve employee number from Cubit."); if (pg_num_rows($empinf_rslt) == 0) { $v->addError(0, "Employee number not found in Cubit."); } $v->isOk($fdate_month, "num", 1, 2, "Invalid from date (month)"); $v->isOk($fdate_year, "num", 4, 4, "Invalid from date (year)"); $v->isOk($tdate_month, "num", 1, 2, "Invalid to date (month)"); $v->isOk($tdate_year, "num", 4, 4, "Invalid to date (year)"); if ($fdate_month > 12) { $v->addError(0, "Invalid from date (month)"); } if ($fdate_year < 1970 || $fdate_year > 2050) { $v->addError(0, "Invalid from date (year)"); } if ($tdate_month > 12) { $v->addError(0, "Invalid to date (month)"); } if ($tdate_year < 1970 || $tdate_year > 2050) { $v->addError(0, "Invalid to date (year)"); } if ($fdate_day > getDaysInMonth((int) $fdate_month, $fdate_year)) { $v->addError(0, "Invalid from date (day)"); } if ($tdate_day > getDaysInMonth((int) $tdate_month, $tdate_year)) { $v->addError(0, "Invalid to date (day)"); } $from_time = mktime(0, 0, 0, $fdate_day, $fdate_month, $fdate_year); $to_time = mktime(0, 0, 0, $tdate_day, $tdate_month, $tdate_year); if ($from_time > $to_time) { $v->addError(0, "Invalid date range specified."); } // Return the errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class='err'>{$e['msg']}</li>"; } return slct($confirm); } $from_date = "{$fdate_year}-{$fdate_month}-{$fdate_day}"; $to_date = "{$tdate_year}-{$tdate_month}-{$tdate_day}"; $gross_taxable_annual_payments = 0.0; $gross_non_taxable_income = 0.0; $gross_retirement_funding_income = 0.0; $gross_non_retirement_funding_income = 0.0; $gross_remuneration = 0.0; db_conn("cubit"); $sql = "SELECT * FROM compinfo"; $compinfo_rslt = db_exec($sql) or errDie("Unable to retrieve company information from Cubit."); $compinfo = pg_fetch_array($compinfo_rslt); db_conn("cubit"); $sql = "SELECT * FROM employees WHERE empnum='{$empnum}'"; $empinfo_rslt = db_exec($sql) or errDie("Unable to retrieve employee information from Cubit."); $empinfo = pg_fetch_array($empinfo_rslt); $header_out = "<b>Employees tax certificate</b>"; $employer_trading_name_out = array(array("<b>Trading or other name:</b> {$compinfo['compname']}")); $employer_irp5_number_out = array(array("<b>IRP 5 number:</b> {$irp5_number}")); $employer_reference_number_out = array(array("<b>Reference number:</b> {$empinfo['taxref']}")); $employer_tax_year_out = array(array("<b>Tax year:</b> " . ($fdate_year + 1))); $employer_diplomatic_indemnity_out = array(array("<b>Diplomatic indemnity:</b> {$compinfo['diplomatic_indemnity']}")); $employer_business_address_out = array(array("<b>Employer business address:</b>"), array("{$compinfo['addr1']}"), array("{$compinfo['addr2']}"), array("{$compinfo['addr3']}")); $employer_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$compinfo['addr4']}")); $employer_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); // Extract the employee's birth date from her id number $bd_year = 1900 + substr($empinfo["idnum"], 0, 2); $bd_month = substr($empinfo["idnum"], 2, 2); $bd_day = substr($empinfo["idnum"], 4, 2); // Period employed from // strip out the dashes from the date $prd_employed_frm = explode("-", $empinfo["hiredate"]); $prd_employed_frm = implode($prd_employed_frm); // Period employed to if (empty($empinfo["firedate"])) { $prd_employed_to = getFinYear() . "0228"; } else { $prd_employed_to = explode("-", $firedate); $prd_employed_to = implode("", $prd_employed_to); } $employee_nature_out = array(array("<b>Nature of Person:</b> {$empinfo['nature']}")); $employee_surname_out = array(array("<b>Employee surname or trading name:</b> {$empinfo['sname']}")); $employee_first_names_out = array(array("<b>First two names:</b> {$empinfo['fnames']}")); $fnames = explode(" ", $empinfo["fnames"]); $initials = ""; foreach ($fnames as $name) { $initials .= strtoupper($name[0]); } $employee_initials_out = array(array("<b>Initials:</b> {$initials}")); $employee_identity_number_out = array(array("<b>Identity number:</b> {$empinfo['idnum']}")); $employee_passport_number_out = array(array("<b>Passport number:</b> {$empinfo['passport_number']}")); $employee_date_of_birth_out = array(array("<b>Date of birth:</b> {$bd_year}-{$bd_month}-{$bd_day}")); $employee_cc_number_out = array(array("<b>Company/CC/Trust number:</b> {$empinfo['cc_number']}")); $employee_tax_number_out = array(array("<b>Income Tax number:</b> {$empinfo['tax_number']}")); $employee_residential_out = array(array("<b>Employees residential address:</b>"), array("{$empinfo['res1']}"), array("{$empinfo['res2']}"), array("{$empinfo['res3']}")); $employee_postal_code_out = array(array("col1" => "<b>Postal Code:</b>", "col2" => "{$empinfo['res4']}")); $employee_postal_code_cols = array("col1" => array("width" => 200, "justification" => "right"), "col2" => array("width" => 40, "justification" => "right")); $employee_number_out = array(array("<b>Employee Number:</b> {$empinfo['empnum']}")); $tax_prd_employed_frm_out = array(array("<b>Period employed from:</b> {$prd_employed_frm}")); $tax_prd_employed_to_out = array(array("<b>Period employed to:</b> {$prd_employed_to}")); $tax_over_deduction_out = array(array("<b>Voluntary over-deduction:</b> {$over_deduction}")); switch ($empinfo["payprd"]) { case "m": $pay_periods = 12; break; case "f": $pay_periods = 24; break; case "w": $pay_periods = 48; break; } $tax_prd_in_year_out = array(array("<b>Pay periods in year:</b> {$pay_periods}")); if ($year_to_process == "active") { $cyear = EMP_YEAR; } else { $cyear = EMP_YEAR - 1; } db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE emp='{$empinfo['empnum']}' AND description='Basic Salary' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve the number of periods worked from Cubit."); $pay_periods_worked = pg_num_rows($rslt); $tax_prd_worked_out = array(array("<b>Number of periods worked:</b> {$pay_periods_worked}")); $tax_fixed_rate_income_out = array(array("<b>Fixed rate income:</b> {$empinfo['fixed_rate']}")); $tax_directive_number_out = array(array("<b>Directive number:</b> {$directive_number}")); // Income sources -------------------------------------------------------- $income_sources_out = array(); $income_taxable_total = 0; $income_commission_total = 0; $income_bonus_total = 0; $income_reimburse_total = 0; $income_travelallowance_total = 0; $income_subsis_total = 0; $income_otherallowance_total = 0; $deduction_motorcar_total = 0; $deduction_medical_total = 0; // $deduction_medicalaid_total = 0; db_conn("cubit"); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Basic Salary' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_taxable_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3601", "<b>DESCRIPTION</b>" => "Income Taxable", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_taxable_total); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Bonus' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_bonus_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3605", "<b>DESCRIPTION</b>" => "Bonus", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_bonus_total); $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description='Commission' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_commission_total += $empinc_data["amount"]; } $income_sources_out[] = array("<b>CODE</b>" => "3606", "<b>DESCRIPTION</b>" => "Commission", "<b>RF IND</b>" => "N", "<b>AMOUNT</b>" => (int) $income_commission_total); #handle travel allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description = 'Travel Allowance' AND type = 'INCT' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_travelallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3701", "<b>DESCRIPTION</b>" => "Travel Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_travelallowance_total); #handle reimbursements .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description!='Basic Salary' AND ex = 'RBS' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_reimburse_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3702", "<b>DESCRIPTION</b>" => "Reimbursements", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_reimburse_total); #handle subsistance allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND ex = 'SUBS' AND type = '2' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_subsis_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3704", "<b>DESCRIPTION</b>" => "Subsistance Allowance", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_subsis_total); #handle other allowances .... $sql = "SELECT amount FROM emp_inc WHERE emp='{$empnum}' AND description != 'Basic Salary' AND description != 'Travel Allowance' AND ex != 'SUBS' AND ex != 'RBS' AND type = '2' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $income_otherallowance_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3713", "<b>DESCRIPTION</b>" => "Other Allowances", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $income_otherallowance_total); #handle motorcar DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND (description = 'Motorcar 1 Contribution for Use' OR description = 'Motorcar 2 Contribution for Use') AND (type = 'DEDA' OR type = 'DEDB') AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_motorcar_total += $empinc_data['amount']; } $income_sources_out[] = array("<b>CODE</b>" => "3802", "<b>DESCRIPTION</b>" => "Use Of Motor Vehicle", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_motorcar_total); #handle medical DEDUCTIONS in income table ... //$sql = "SELECT amount FROM emp_com WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'"; $sql = "SELECT amount FROM emp_com WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'COMM' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_medical_total += $empinc_data['amount']; } //"<b>CODE</b>" => "3816", $income_sources_out[] = array("<b>CODE</b>" => "3810", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total); #handle medical aid DEDUCTIONS in income table ... // $sql = "SELECT amount FROM emp_ded WHERE emp='$empnum' AND description = 'Medical Contribution' AND type = 'DEDM'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); // while ($empinc_data = pg_fetch_array($rslt)) { // $deduction_medicalaid_total += $empinc_data['amount']; // } // $income_sources_out[] = array ( // "<b>CODE</b>" => "3802", // "<b>DESCRIPTION</b>" => "Medical aid contributions", // "<b>RF IND</b>" => "", // "<b>AMOUNT</b>" => (int)$deduction_medicalaid_total // ); // old // $sql = "SELECT * FROM emp_inc WHERE emp='$empnum' AND description!='Basic Salary'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); // while ($empinc_data = pg_fetch_array($rslt)) { // $income_sources_out[] = array ( // "<b>CODE</b>"=>"$empinc_data[code]", // "<b>DESCRIPTION</b>"=>"$empinc_data[description]", // "<b>RF IND</b>"=>"", // "<b>AMOUNT</b>"=>(int)$empinc_data["amount"] // ); // } if (!empty($nincome_description) || !empty($nincome_amount) && $nincome_code != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$nincome_code}", "<b>DESCRIPTION</b>" => "{$nincome_description}", "<b>RF IND</b>" => "{$nincome_rfind}", "<b>AMOUNT</b>" => (int) $nincome_amount); } if (isset($income_code)) { foreach ($income_code as $id => $value) { if ($income_code[$id] != 0) { $income_sources_out[] = array("<b>CODE</b>" => "{$income_code[$id]}", "<b>DESCRIPTION</b>" => "{$income_description[$id]}", "<b>RF IND</b>" => "{$income_rfind[$id]}", "<b>AMOUNT</b>" => (int) $income_amount[$id]); } else { $income_sources_out[] = array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => ""); } } } $income_sources_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>RF IND</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Gross renumeration ---------------------------------------------------- // Taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3695' OR code='3601' OR description='Bonus') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3695' OR code='3601') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve taxable annual payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { $gross_taxable_annual_payments += $emp_income_sources_data["amount"]; } // Non taxable annual payments db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_taxable_income += $emp_inc_data["amount"]; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code='3602' OR code='3604' OR code='3612' OR code='3703' OR code='3705' OR code='3709' OR code='3714') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve non taxable payments from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { if ($emp_income_sources_data["rf_ind"] == "Y") { $gross_non_taxable_income += $emp_income_sources_data["amount"]; } } // Gross retirement funding income db_conn("cubit"); $sql = "SELECT emp_pension, emp_ret FROM employees WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross retrirement funding from Cubit."); $emp_data = pg_fetch_array($rslt); // RF IND $rfind_y = 0; if (isset($income_rfind)) { foreach ($income_rfind as $id => $value) { if ($income_rfind[$id] == "Y") { $rfind_y += $income_amount[$id]; } } } //wth emp_pension is a PERCENTAGE, not some amount to add // $gross_retirement_funding_income += $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y; $gross_retirement_funding_income += $gross_taxable_annual_payments / 100 * $emp_data["emp_pension"] + $emp_data["emp_ret"] + $rfind_y; // Gross non retirement funding income db_conn("cubit"); $sql = "SELECT * FROM emp_inc WHERE ((code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code != '3615') OR description = 'Basic Salary') AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); // RF IND $rfind_n = 0; if (isset($income_rfind)) { foreach ($income_rfind as $id => $value) { if ($income_rfind[$id] == "N") { $rfind_n += $income_amount[$id]; } } } while ($emp_inc_data = pg_fetch_array($rslt)) { $gross_non_retirement_funding_income += $emp_inc_data["amount"] + $rfind_n; } db_conn("cubit"); $sql = "SELECT * FROM emp_income_sources WHERE (code != '3601' AND code != '3603' AND code != '3604' AND code != '3610' AND code!='3615') AND empnum = '{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve gross non retirement funding from Cubit."); while ($emp_income_sources_data = pg_fetch_array($rslt)) { if ($emp_income_sources_data["rf_ind"] == "N") { $gross_non_retirement_funding_income += $emp_income_sources_data["amount"]; } } // Gross Remuneration $gross_remuneration = $gross_retirement_funding_income + $gross_non_retirement_funding_income; $gross_remuneration_out = array(array("<b>CODE</b>" => "3695", "<b>DESCRIPTION</b>" => "GROSS TAXABLE ANNUAL PAYMENTS", "<b>AMOUNT</b>" => (int) $gross_taxable_annual_payments), array("<b>CODE</b>" => "3696", "<b>DESCRIPTION</b>" => "GROSS NON-TAXABLE INCOME", "<b>AMOUNT</b>" => (int) $gross_non_taxable_income), array("<b>CODE</b>" => "3697", "<b>DESCRIPTION</b>" => "GROSS RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_retirement_funding_income), array("<b>CODE</b>" => "3698", "<b>DESCRIPTION</b>" => "GROSS NON-RETIREMENT FUNDING INCOME", "<b>AMOUNT</b>" => (int) $gross_non_retirement_funding_income), array("<b>CODE</b>" => "3699", "<b>DESCRIPTION</b>" => "GROSS REMUNERATION", "<b>AMOUNT</b>" => (int) $gross_remuneration)); $gross_remuneration_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // Deductions ------------------------------------------------------------ $deductions_out = array(); $deduction_pension_total = 0; $deduction_provident_total = 0; $deduction_medicalaid_total = 0; $deduction_medical_total2 = 0; $deduction_retirementann_total = 0; $deduction_premiumpol_total = 0; db_conn("cubit"); $sql = "SELECT * FROM emp_deductions WHERE empnum='{$empnum}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($ded_data = pg_fetch_array($rslt)) { $deductions_out[] = array("<b>CODE</b>" => "{$ded_data['code']}", "<b>DESCRIPTION</b>" => "{$ded_data['description']}", "<b>CLEARANCE NO</b>" => "{$ded_data['clearance_no']}", "<b>AMOUNT</b>" => (int) $ded_data["amount"]); } #handle pension deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Pension' AND type = 'DEDP' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_pension_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4001", "<b>DESCRIPTION</b>" => "Current pension fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_pension_total); #handle provident deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Provident' AND type = 'DEDV' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_provident_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4003", "<b>DESCRIPTION</b>" => "Current provident fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_provident_total); #handle medical DEDUCTIONS in income table ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Medical Contribution' AND type = 'DEDM' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee income sources from Cubit."); while ($empinc_data = pg_fetch_array($rslt)) { $deduction_medical_total2 += $empinc_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4005", "<b>DESCRIPTION</b>" => "Medical Contribution", "<b>RF IND</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_medical_total2); #handle retirement annuity deduction ... $sql = "SELECT amount FROM emp_ded WHERE emp='{$empnum}' AND description = 'Retirement Annuity Fund' AND type = 'DEDR' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_retirementann_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4006", "<b>DESCRIPTION</b>" => "Current retirement annuity fund contributions", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_retirementann_total); $sql = "SELECT * FROM emp_ded WHERE emp='{$empnum}' AND description!='UIF' AND description!='SDL' AND description!='PAYE' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); while ($empded_data = pg_fetch_array($rslt)) { $deduction_premiumpol_total += $empded_data['amount']; } $deductions_out[] = array("<b>CODE</b>" => "4018", "<b>DESCRIPTION</b>" => "Premiums paid on loss of income policies", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => (int) $deduction_premiumpol_total); //old all encapsulating search ... only first to description checks were orginal ... // $sql = "SELECT * FROM emp_ded WHERE emp='$empnum' AND description!='UIF' AND description!='SDL' AND description!='Motorcar 1 Contribution for Use' AND description!='Motorcar 2 Contribution for Use' AND description!='Medical Contribution' AND description!='Pension' AND description!='Provident' AND description!='Retirement Annuity Fund'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit."); // while ($empded_data = pg_fetch_array($rslt)) { // if ($empded_data["type"] != "PAYE") { // $deductions_out[] = array ( // "<b>CODE</b>"=>"$empded_data[code]", // "<b>DESCRIPTION</b>"=>"$empded_data[description]", // "<b>CLEARANCE NO</b>"=>"", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"] // ); // } // } // cant just remove whatever deductions is on system if they havent actually been applied to salary (ie. salary processed) // this value will come from same place as the rest of the income/deductions ... wth // db_conn("cubit"); // $sql = "SELECT * FROM empdeduct WHERE empnum='$empnum'"; // $empded_rslt = db_exec($sql) or errDie("Unable to retrieve employee deductions from Cubit.'"); // // while ($empded_data = pg_fetch_array($empded_rslt)) { // db_conn("cubit"); // $sql = "SELECT deduction, code FROM salded WHERE id='$empded_data[dedid]' AND deduction!='UIF'"; // $rslt = db_exec($sql) or errDie("Unable to retrieve deduction information from Cubit."); // $ded_data = pg_fetch_array($rslt); // // $deductions_out[] = array ( // "<b>CODE</b>"=>"$ded_data[code]", // "<b>DESCRIPTION</b>"=>"$ded_data[deduction]", // "<b>CLEARANCE NO</b>"=>"$empded_data[clearance_no]", // "<b>AMOUNT</b>"=>(int)$empded_data["amount"], 2 // ); // } if (!isset($deductions_out[0])) { $deductions_out = array(array("<b>CODE</b>" => "", "<b>DESCRIPTION</b>" => "", "<b>CLEARANCE NO</b>" => "", "<b>AMOUNT</b>" => "")); } $deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 340), "<b>CLEARANCE NO</b>" => array("width" => 70), "<b>AMOUNT</b>" => array("width" => 70)); // Employees Tax deductions----------------------------------------------- $tax_amt = 0; // Retrieve PAYE amount from Cubit db_conn("cubit"); $sql = "SELECT * FROM emp_ded WHERE type='PAYE' AND emp = '{$empnum}' AND year = '{$cyear}'"; $rslt = db_exec($sql) or errDie("Unable to retrieve PAYE deductions from Cubit"); $paye_amount = 0; while ($empded_data = pg_fetch_array($rslt)) { // add 375 to site if salary, -375 if reverse salary $tax_amt += 375 * ($empded_data["amount"] > 0 ? 1 : -1); $paye_amount += $empded_data["amount"]; } if ($tax_amt > $paye_amount) { $tax_amt = $paye_amount; $paye_amount = 0; } else { $paye_amount -= $tax_amt; } $tax_deductions_amount = $paye_amount + $tax_amt; $employees_tax_deductions_out = array(array("<b>CODE</b>" => "4101", "<b>DESCRIPTION</b>" => "STANDARD INCOME TAX ON EMPLOYEES-SITE", "<b>AMOUNT</b>" => sprint($tax_amt, 2)), array("<b>CODE</b>" => "4102", "<b>DESCRIPTION</b>" => "PAY AS YOU EARN - PAYE", "<b>AMOUNT</b>" => sprint($paye_amount, 2)), array("<b>CODE</b>" => "4103", "<b>DESCRIPTION</b>" => "TOTAL EMPLOYEES TAX", "<b>AMOUNT</b>" => sprint($tax_deductions_amount, 2))); $employees_tax_deductions_cols = array("<b>CODE</b>" => array("width" => 40), "<b>DESCRIPTION</b>" => array("width" => 410), "<b>AMOUNT</b>" => array("width" => 70)); // ----------------------------------------------------------------------- // Do the actual rendering of the pdf // ----------------------------------------------------------------------- $pdf =& new Cezpdf(); global $set_mainFont; $pdf->selectFont($set_mainFont); $pdf->addInfo("Title", "IRP 5 for {$empinfo['fnames']} {$empinfo['sname']}"); $pdf->addInfo("Author", USER_NAME); $irp5_pos = drawText(&$pdf, "<b>IRP 5</b>", 14, 520 - $pdf->getTextWidth(14, "<b>IRP 5</b>"), 0); $header_pos = drawText(&$pdf, $header_out, 12, 520 - $pdf->getTextWidth(12, $header_out), $irp5_pos['y'] + 14); // Employer information -------------------------------------------------- $employer_information_head = drawText(&$pdf, "<b>EMPLOYER INFORMATION</b>", 8, 0, $irp5_pos['y'] + 14); $employer_trading_name_pos = drawTable2(&$pdf, $employer_trading_name_out, 0, $employer_information_head['y'] + 2, 520, 1); $employer_irp5_number_pos = drawTable2(&$pdf, $employer_irp5_number_out, 0, $employer_trading_name_pos['y'], 260, 1); $employer_reference_number_pos = drawTable2(&$pdf, $employer_reference_number_out, 0, $employer_irp5_number_pos['y'], 260, 1); $employer_tax_year_pos = drawTable2(&$pdf, $employer_tax_year_out, 0, $employer_reference_number_pos['y'], 260, 1); $employer_diplomatic_indemnity_pos = drawTable2(&$pdf, $employer_diplomatic_indemnity_out, 0, $employer_tax_year_pos['y'], 260, 1); $employer_business_address_pos = drawTable2(&$pdf, $employer_business_address_out, $employer_irp5_number_pos['x'] + 20, $employer_trading_name_pos['y'], 240, 4); $employer_postal_code_pos = drawTable2(&$pdf, $employer_postal_code_out, $employer_irp5_number_pos['x'] + 20, $employer_business_address_pos['y'], 240, 1, $employer_postal_code_cols); // Employee information -------------------------------------------------- $employee_information_head = drawText(&$pdf, "<b>EMPLOYEE INFORMATION</b>", 8, 0, $employer_postal_code_pos['y'] + 15); $employee_nature_pos = drawTable2(&$pdf, $employee_nature_out, 0, $employee_information_head['y'], 100, 1); $employee_surname_pos = drawTable2(&$pdf, $employee_surname_out, $employee_nature_pos['x'] + 20, $employee_information_head['y'], 400, 1); $employee_first_names_pos = drawTable2(&$pdf, $employee_first_names_out, 0, $employee_nature_pos['y'], 400, 1); $employee_initials_pos = drawTable2(&$pdf, $employee_initials_out, $employee_first_names_pos['x'] + 20, $employee_nature_pos['y'], 100, 1); $employee_identity_number_pos = drawTable2(&$pdf, $employee_identity_number_out, 0, $employee_first_names_pos['y'], 260, 1); $employee_residential_pos = drawTable2(&$pdf, $employee_residential_out, $employee_identity_number_pos['x'] + 20, $employee_first_names_pos['y'], 240, 4); $employee_postal_code_pos = drawTable2(&$pdf, $employee_postal_code_out, $employee_identity_number_pos['x'] + 20, $employee_residential_pos['y'], 240, 1, $employee_postal_code_cols); $employee_number_pos = drawTable2(&$pdf, $employee_number_out, $employee_identity_number_pos['x'] + 20, $employee_postal_code_pos['y'], 240, 1); $employee_passport_number_pos = drawTable2(&$pdf, $employee_passport_number_out, 0, $employee_identity_number_pos['y'], 260, 1); $employee_date_of_birth_pos = drawTable2(&$pdf, $employee_date_of_birth_out, 0, $employee_passport_number_pos['y'], 260, 1); $employee_cc_number_pos = drawTable2(&$pdf, $employee_cc_number_out, 0, $employee_date_of_birth_pos['y'], 260, 1); $employee_tax_number_pos = drawTable2(&$pdf, $employee_tax_number_out, 0, $employee_cc_number_pos['y'], 260, 1); // Tax calculation information ------------------------------------------- $tax_calculation_head = drawText(&$pdf, "<b>TAX CALCULATION INFORMATION</b>", 8, 0, $employee_number_pos['y'] + 15); $tax_prd_employed_frm_pos = drawTable2(&$pdf, $tax_prd_employed_frm_out, 0, $tax_calculation_head['y'], 160, 1); $tax_prd_employed_to_pos = drawTable2(&$pdf, $tax_prd_employed_to_out, $tax_prd_employed_frm_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); $tax_over_deduction_pos = drawTable2(&$pdf, $tax_over_deduction_out, $tax_prd_employed_to_pos['x'] + 20, $tax_calculation_head['y'], 160, 1); $tax_prd_in_year_pos = drawTable2(&$pdf, $tax_prd_in_year_out, 0, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_prd_worked_pos = drawTable2(&$pdf, $tax_prd_worked_out, $tax_prd_in_year_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_fixed_rate_income_pos = drawTable2(&$pdf, $tax_fixed_rate_income_out, $tax_prd_worked_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); $tax_directive_number_pos = drawTable2(&$pdf, $tax_directive_number_out, $tax_fixed_rate_income_pos['x'] + 20, $tax_prd_employed_frm_pos['y'], 115, 1); // Income sources -------------------------------------------------------- $income_sources_head = drawText(&$pdf, "<b>INCOME SOURCE</b>", 8, 0, $tax_prd_in_year_pos['y'] + 15); $income_sources_pos = drawTable2(&$pdf, $income_sources_out, 0, $income_sources_head['y'] + 2, 520, 20, $income_sources_cols, 1); $gross_remuneration_head = drawText(&$pdf, "<b>GROSS REMUNERATION</b>", 8, 0, $income_sources_pos['y'] + 15); $gross_remuneration_pos = drawTable2(&$pdf, $gross_remuneration_out, 0, $gross_remuneration_head['y'] + 2, 520, 5, $gross_remuneration_cols, 1); $deductions_head = drawText(&$pdf, "<b>DEDUCTIONS</b>", 8, 0, $gross_remuneration_pos['y'] + 15); $deductions_pos = drawTable2(&$pdf, $deductions_out, 0, $deductions_head['y'] + 2, 520, 15, $deductions_cols, 1); $employees_tax_deductions_head = drawText(&$pdf, "<b>EMPLOYEES TAX DEDUCTIONS</b>", 8, 0, $deductions_pos['y'] + 15); $employees_tax_deductions_pos = drawTable2(&$pdf, $employees_tax_deductions_out, 0, $employees_tax_deductions_head['y'] + 2, 520, 3, $employees_tax_deductions_cols, 1); // Footer note ----------------------------------------------------------- $certificate_attatch = drawText(&$pdf, "Attach this certificate to your income tax return or retain it. / ", 6, 0, $employees_tax_deductions_pos['y'] + 10); $pdf->ezStream(); }