/** displayFleetKmsTable($fleet_id, array $conf) * display a fleet kms table correctly * @param int $fleet_id * @param array $conf * @return string $html */ function displayFleetKmsTable($fleet_id, array $conf) { /* print '<pre style="color:#FFF">'; print_r($conf); print '</pre>'; */ $mtddays = getFleetBudgetDays((int) $fleet_id, NULL, NULL); $monthenddays = getFleetBudgetDays((int) $fleet_id, NULL, mktime(0, 0, 0, date("m"), date("t"), date("Y"))); $manager = new TableManager("fleet_scores"); $sql = (string) "SELECT * FROM `fleet_scores` WHERE "; $sql .= $manager->quoteString("`fleetid`=?", (int) $fleet_id); $sql .= $manager->quoteString(" AND `date`>=?", mktime(0, 0, 0, date("m"), 1, date("Y"))); $sql .= $manager->quoteString(" AND `date`<=?", mktime(0, 0, 0, date("m"), date("t"), date("Y"))); if (($results = $manager->runSql($sql)) === FALSE) { return FALSE; } $monthendbudget = (int) 0; foreach ($results as $val) { if (isset($val["budget"]) && $val["budget"] > 0) { $monthendbudget += $val["budkms"]; } } unset($results); $data = array("cd_actual" => array_key_exists("kms", $conf) ? $conf["kms"] : 0, "cd_budget" => array_key_exists("budkms", $conf) ? $conf["budkms"] : 0); $data["cd_variance"] = array_key_exists("cd_actual", $data) && array_key_exists("cd_budget", $data) ? (string) round($data["cd_actual"] - $data["cd_budget"], 0) : "-"; $data["cd_percent"] = array_key_exists("cd_actual", $data) && array_key_exists("cd_budget", $data) && $data["cd_budget"] > 0 ? (string) round($data["cd_actual"] / $data["cd_budget"] * 100, 0) : "-"; $data["mtd_actual"] = array_key_exists("totkms", $conf) && $conf["truck_count"] && $mtddays > 0 ? (string) round($conf["totkms"] / $mtddays / $conf["truck_count"], 0) : "-"; $data["mtd_budget"] = array_key_exists("totbudkms", $conf) && $conf["truck_count"] && $mtddays > 0 ? (string) round($conf["totbudkms"] / $mtddays / $conf["truck_count"], 0) : "-"; $data["mtd_variance"] = array_key_exists("mtd_actual", $data) && array_key_exists("mtd_budget", $data) ? (string) round($data["mtd_actual"] - $data["mtd_budget"], 0) : "-"; $data["mtd_percent"] = array_key_exists("mtd_actual", $data) && array_key_exists("mtd_budget", $data) && $data["mtd_budget"] > 0 ? (string) round($data["mtd_actual"] / $data["mtd_budget"] * 100, 0) : "-"; $data["mef_actual"] = array_key_exists("mtd_actual", $data) && $mtddays > 0 && $monthenddays > 0 ? (string) round($data["mtd_actual"] * $monthenddays, 0) : "-"; if (isset($monthendbudget) && $monthendbudget > 0) { $data["mef_budget"] = array_key_exists("truck_count", $conf) && $conf["truck_count"] > 0 ? (string) round($monthendbudget / $conf["truck_count"], 0) : "-"; } else { $data["mef_budget"] = array_key_exists("mtd_budget", $data) && $mtddays > 0 && $monthenddays > 0 ? (string) round($data["mtd_budget"] * $monthenddays, 0) : "-"; } $data["mef_variance"] = array_key_exists("mef_actual", $data) && array_key_exists("mef_budget", $data) ? (string) round($data["mef_actual"] - $data["mef_budget"], 0) : "-"; $data["mef_percent"] = array_key_exists("mef_actual", $data) && array_key_exists("mef_budget", $data) && $data["mef_budget"] > 0 ? (string) round($data["mef_actual"] / $data["mef_budget"] * 100, 0) : "-"; /* print '<pre style="color:#FFF">'; print_r($data); print '</pre>'; */ $vars = (string) ""; foreach ($data as $key => $val) { $vars .= $key . "=" . $val . "&"; } $vars = substr($vars, 0, -1); $object = embedObject("/images/kms_table.swf", array("FlashVars" => $vars, "height" => round(164 * $conf["factor"], 0), "name" => "kms_table", "width" => round(850 * $conf["factor"], 0)), TRUE); //return $object; return $data; }
/** displayFleetKmsTable($fleet_id, array $conf) * display a fleet kms table correctly * @param int $fleet_id * @param array $conf * @return string $html */ function displayFleetKmsTable($fleet_id, array $conf) { $mtddays = getFleetBudgetDays((int) $fleet_id, NULL, NULL); $monthenddays = getFleetBudgetDays((int) $fleet_id, NULL, mktime(0, 0, 0, date("m"), date("t"), date("Y"))); $data = array("cd_actual" => array_key_exists("kms", $conf) ? $conf["kms"] : 0, "cd_budget" => array_key_exists("budkms", $conf) ? $conf["budkms"] : 0); $data["cd_variance"] = array_key_exists("cd_actual", $data) && array_key_exists("cd_budget", $data) ? (string) round($data["cd_actual"] - $data["cd_budget"], 0) : "-"; $data["cd_percent"] = array_key_exists("cd_actual", $data) && array_key_exists("cd_budget", $data) && $data["cd_budget"] > 0 ? (string) round($data["cd_actual"] / $data["cd_budget"] * 100, 0) : "-"; $data["mtd_actual"] = array_key_exists("totkms", $conf) && $conf["truck_count"] && $mtddays > 0 ? (string) round($conf["totkms"] / $mtddays / $conf["truck_count"], 0) : "-"; $data["mtd_budget"] = array_key_exists("totbudkms", $conf) && $conf["truck_count"] && $mtddays > 0 ? (string) round($conf["totbudkms"] / $mtddays / $conf["truck_count"], 0) : "-"; $data["mtd_variance"] = array_key_exists("mtd_actual", $data) && array_key_exists("mtd_budget", $data) ? (string) round($data["mtd_actual"] - $data["mtd_budget"], 0) : "-"; $data["mtd_percent"] = array_key_exists("mtd_actual", $data) && array_key_exists("mtd_budget", $data) && $data["mtd_budget"] > 0 ? (string) round($data["mtd_actual"] / $data["mtd_budget"] * 100, 0) : "-"; $data["mef_actual"] = array_key_exists("mtd_actual", $data) && $mtddays > 0 && $monthenddays > 0 ? (string) round($data["mtd_actual"] * $monthenddays, 0) : "-"; $data["mef_budget"] = array_key_exists("mtd_budget", $data) && $mtddays > 0 && $monthenddays > 0 ? (string) round($data["mtd_budget"] * $monthenddays, 0) : "-"; $data["mef_variance"] = array_key_exists("mef_actual", $data) && array_key_exists("mef_budget", $data) ? (string) round($data["mef_actual"] - $data["mef_budget"], 0) : "-"; $data["mef_percent"] = array_key_exists("mef_actual", $data) && array_key_exists("mef_budget", $data) && $data["mef_budget"] > 0 ? (string) round($data["mef_actual"] / $data["mef_budget"] * 100, 0) : "-"; $vars = (string) ""; foreach ($data as $key => $val) { $vars .= $key . "=" . $val . "&"; } $vars = substr($vars, 0, -1); $object = embedObject("/images/kms_table.swf", array("FlashVars" => $vars, "height" => round(164 * $conf["factor"], 0), "name" => "kms_table", "width" => round(850 * $conf["factor"], 0)), TRUE); return $object; }