Skip to content

Instantly share code, notes, and snippets.

@nellytadi
Created April 25, 2019 16:16
Show Gist options
  • Save nellytadi/3b2a799089402c3e3357bda265e45bd4 to your computer and use it in GitHub Desktop.
Save nellytadi/3b2a799089402c3e3357bda265e45bd4 to your computer and use it in GitHub Desktop.
<?php
function getStatistics() {
$data = [];
$data['users'] = [];
// 65k rows
$allTptp = TariffProviderTariffMatch::all();
foreach ($allTptp->groupBy('user_id') as $each) {
$one = [];
$one['name'] = $each[0]->user->first_name . " " . $each[0]->user->last_name;
$one['valid'] = 0;
$one['pending'] = 0;
$one['invalid'] = 0;
$one['total'] = 0;
$one['cash'] = 0;
switch ($each->active_status) {
case ActiveStatus::ACTIVE: // 1
$one['valid']++;
$one['cash'] += floatval(GlobalVariable::getById(GlobalVariable::STANDARDIZATION_UNIT_PRICE)->value);
break;
case ActiveStatus::PENDING: // 2
$one['pending']++;
break;
case ActiveStatus::DELETED: // 3
$one['invalid']++;
break;
}
$one['total']++;
$one['cash'] = number_format($one['cash'],2);
array_push($data['users'], $one);
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment