/** * Get the sum of expenses for every project. * @param int $start Time from which to take the expenses into account. * @param int $end Time until which to take the expenses into account. * @param array $users Array of user IDs to filter the expenses by. * @param array $customers Array of customer IDs to filter the expenses by. * @param array $projects Array of project IDs to filter the expenses by. * @return array Array which assigns every project (via his ID) the sum of his expenses. */ function get_arr_exp_pct($start, $end, $users = null, $customers = null, $projects = null) { global $kga, $conn; $start = MySQL::SQLValue($start, MySQL::SQLVALUE_NUMBER); $end = MySQL::SQLValue($end, MySQL::SQLVALUE_NUMBER); $p = $kga['server_prefix']; $whereClauses = exp_whereClausesFromFilters($users, $customers, $projects); $whereClauses[] = "{$p}pct.pct_trash = 0"; if ($start) { $whereClauses[] = "exp_timestamp >= {$start}"; } if ($end) { $whereClauses[] = "exp_timestamp <= {$end}"; } $query = "SELECT sum(exp_value) as expenses,exp_pctID FROM {$p}exp\n Left Join {$p}pct ON exp_pctID = pct_ID\n Left Join {$p}knd ON pct_kndID = knd_ID " . (count($whereClauses) > 0 ? " WHERE " : " ") . implode(" AND ", $whereClauses) . " GROUP BY exp_pctID;"; $result = $conn->Query($query); if (!$result) { return array(); } $rows = $conn->RecordsArray(MYSQL_ASSOC); if (!$rows) { return array(); } $arr = array(); foreach ($rows as $row) { $arr[$row['exp_pctID']] = $row['expenses']; } return $arr; }
/** * Get the sum of expenses for every project. * @param int $in Time from which to take the expenses into account. * @param int $out Time until which to take the expenses into account. * @param array $users Array of user IDs to filter the expenses by. * @param array $customers Array of customer IDs to filter the expenses by. * @param array $projects Array of project IDs to filter the expenses by. * @return array Array which assigns every project (via his ID) the sum of his expenses. */ function get_arr_exp_pct($in, $out, $users = null, $customers = null, $projects = null) { global $kga; global $pdo_conn; $p = $kga['server_prefix']; $whereClauses = exp_whereClausesFromFilters($users, $customers, $projects); $whereClauses[] = "{$p}pct.pct_trash = 0"; if ($in) { $whereClauses[] = "exp_timestamp >= {$in}"; } if ($out) { $whereClauses[] = "exp_timestamp <= {$out}"; } $pdo_query = $pdo_conn->prepare("SELECT sum(exp_value) as expenses,exp_pctID FROM {$p}exp\n Left Join {$p}pct ON exp_pctID = pct_ID\n Left Join {$p}knd ON pct_kndID = knd_ID " . (count($whereClauses) > 0 ? " WHERE " : " ") . implode(" AND ", $whereClauses) . " GROUP BY exp_pctID;"); $pdo_query->execute(); $arr = array(); while ($row = $pdo_query->fetch(PDO::FETCH_ASSOC)) { if (!isset($row['exp_pctID'])) { break; } $arr[$row['exp_pctID']] = $row['expenses']; } return $arr; }