Last active
December 15, 2017 23:49
-
-
Save masterfermin02/a3279dfbc91d4d06828f4bc4513c75a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getVar($var){ | |
return isset($_GET[$var]) ? $_GET[$var] : 0; | |
} | |
function getReportSetting($var){ | |
global $reportSetting; | |
return isset($reportSetting[$var]) ? $reportSetting[$var] : 0; | |
} | |
function isYellow($average){ | |
return $average >= getReportSetting('yellow') && $average < getReportSetting('green'); | |
} | |
function isRed($average){ | |
return $average >= 0 and $average < getReportSetting('yellow'); | |
} | |
function isGreen($average){ | |
return $average >= getReportSetting('green'); | |
} | |
function getRedRecords($records){ | |
return array_filter($records,function($record){ | |
return isRed($record['SPH']); | |
}); | |
} | |
function getYellowRecords($records){ | |
return array_filter($records,function($record){ | |
return isYellow($record['SPH']); | |
}); | |
} | |
function getGreenRecords($records){ | |
return array_filter($records,function($record){ | |
return isGreen($record['SPH']); | |
}); | |
} | |
function getCampaignRecords($records){ | |
return array_filter($records,function($record){ | |
return strtolower($record['campaign_description']) == strtolower(getReportSetting('campaign')); | |
}); | |
} | |
function leader($currentRecord, $record){ | |
return $currentRecord['SPH'] > $record['SPH'] ? $currentRecord : $record; | |
} | |
function getLeader($records){ | |
return array_reduce($records, "leader"); | |
} | |
function suma($carry, $item) | |
{ | |
$carry += $item; | |
return $carry; | |
} | |
function array_plunk($arr, $prop){ | |
return array_map(function($item) use($prop) { | |
return $item[$prop]; | |
},$arr); | |
} | |
function getHours($records){ | |
return array_plunk($records, 'total_hours'); | |
} | |
function getAmounts($records){ | |
return array_plunk($records, 'Amount Sold'); | |
} | |
function getSales($records){ | |
return array_plunk($records, 'Number of Sales'); | |
} | |
function totalHours($records){ | |
return array_reduce(getHours($records),'suma', 0); | |
} | |
function totalAmount($records){ | |
return array_reduce(getAmounts($records),'suma', 0); | |
} | |
function totalSales($records){ | |
return array_reduce(getSales($records),'suma', 0); | |
} | |
function avg($totalAmount, $totalHours){ | |
return $totalAmount / $totalHours; | |
} | |
function getTbody($records){ | |
return array_map(function($row){ | |
return "<tr class='".getClass($row['SPH'])."'>" | |
."<td><a target='_blank' href='../../user_stats.php?user=".$row['user']."' >".$row['AgentName']."</a></td>" | |
."<td><span class='text-aling-right' > $".$row['Amount Sold']."</span></td>" | |
."<td><span class='text-aling-right' >".$row['Number of Sales']."</span></td>" | |
."<td><span class='text-aling-right' >".round($row['SPH'])."</span></td>" | |
."</tr>"; | |
}, $records); | |
} | |
function renderGreen($records){ | |
return array_map(function($row){ | |
return "<tr class='text-success'>" | |
."<td><a target='_blank' href='../../user_stats.php?user=".$row['user']."' >".$row['AgentName']."</a></td>" | |
."<td><span class='text-aling-right' > $".$row['Amount Sold']."</span></td>" | |
."<td><span class='text-aling-right' >".$row['Number of Sales']."</span></td>" | |
."<td><span class='text-aling-right' >".round($row['SPH'])."</span></td>" | |
."</tr>"; | |
}, $records); | |
} | |
function renderYellow($records){ | |
return array_map(function($row){ | |
return "<tr class='text-yellow'>" | |
."<td><a target='_blank' href='../../user_stats.php?user=".$row['user']."' >".$row['AgentName']."</a></td>" | |
."<td><span class='text-aling-right' > $".$row['Amount Sold']."</span></td>" | |
."<td><span class='text-aling-right' >".$row['Number of Sales']."</span></td>" | |
."<td><span class='text-aling-right' >".round($row['SPH'])."</span></td>" | |
."</tr>"; | |
}, $records); | |
} | |
function renderRed($records){ | |
return array_map(function($row){ | |
return "<tr class='text-danger'>" | |
."<td><a target='_blank' href='../../user_stats.php?user=".$row['user']."' >".$row['AgentName']."</a></td>" | |
."<td><span class='text-aling-right' > $".$row['Amount Sold']."</span></td>" | |
."<td><span class='text-aling-right' >".$row['Number of Sales']."</span></td>" | |
."<td><span class='text-aling-right' >".round($row['SPH'])."</span></td>" | |
."</tr>"; | |
}, $records); | |
} | |
function getRecords($link){ | |
$table = getVar('campaign') == 'R' ? 'temp_live_report_by_description_card' : 'temp_live_report_by_description'; | |
$filter_user = getVar('campaign') == 'R' ? '' : "where user not in ('1108')"; | |
$stmt = "SELECT * | |
from $table | |
$filter_user | |
order by SPH desc"; | |
$result = $link->query($stmt); | |
return $result->fetch_all(MYSQLI_ASSOC); | |
} | |
function getRecord($stmt, $link){ | |
$result = $link->query($stmt); | |
return $result->fetch_ASSOC(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment