1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| $parts = ['C:', 'Users', 'Master', 'Desktop', 'quotidien', 'CDRs'];
$dir = implode(DIRECTORY_SEPARATOR, $parts);
$files = scandir($dir, 1);
$sums = [
'day' => [],
'month' => [],
'year' => [],
'all' => []
];
if ($files !== false)
{
// only keep csv files
$files = array_filter($files, function($p) { return (substr($p, -3) === 'csv'); });
foreach ($files as $file)
{
$date = substr($file, -18, 8);
$year = substr($date, 0, 4);
$month = $year.substr($date, 4, 2);
$path = $dir.DIRECTORY_SEPARATOR.$file;
if (($handle = fopen($path, 'r')) !== false)
{
while ($row = fgetcsv($handle, null, ';'))
{
if (is_numeric($row[2])) // client phone number
{
$phone_number = $row[2];
$price = $row[8];
if ( ! isset($sums['day'][$phone_number][$date]))
$sums['day'][$phone_number][$date] = 0;
if ( ! isset($sums['month'][$phone_number][$month]))
$sums['month'][$phone_number][$month] = 0;
if ( ! isset($sums['year'][$phone_number]))
$sums['year'][$phone_number][$year] = 0;
if ( ! isset($sums['all'][$phone_number]))
$sums['all'][$phone_number] = 0;
$sums['day'] [$phone_number][$date] += $price;
$sums['month'][$phone_number][$month] += $price;
$sums['year'] [$phone_number][$year] += $price;
$sums['all'] [$phone_number] += $price;
}
}
fclose($handle);
}
}
} |