Skip to content

Instantly share code, notes, and snippets.

@cygeorgel
Created July 16, 2018 08:40
Show Gist options
  • Save cygeorgel/3304ee4edc5c392797885ec17c956080 to your computer and use it in GitHub Desktop.
Save cygeorgel/3304ee4edc5c392797885ec17c956080 to your computer and use it in GitHub Desktop.
Import calls from Gentel
if($service == 'gentel') {
// locally:
$dir = storage_path('app/cdr/gentel');
$files = scandir($dir);
foreach($files as $file) {
if($file != '.' && $file != '..') {
$control = \DB::table('telco_cdr_gentel_calls')->select('id')->where('origin', $file)->count();
if($control == 0) {
$data = file_get_contents(storage_path('app/cdr/gentel/' . $file));
$lines = explode("\n", $data);
foreach($lines as $line) {
$values = explode(';', $line);
if(isset($values[3]) && is_numeric($values[3])) {
TelcoCdrGentelCall::create([
'origin' => $file,
'NoFacture' => $values[0],
'IdCdr' => $values[1],
'NoClient' => $values[2],
'DateHeureAppel' => $values[3],
'DureeEnS' => $values[4],
'NumeroAppele' => $values[5],
'NoLigneAppelante' => $values[6],
'TypeCom' => utf8_encode($values[7]),
'VolumeDonneesEnKo' => $values[8],
'Destination' => utf8_encode($values[9]),
'TypeAppel' => utf8_encode($values[10]),
'UnitesAppel' => $values[11],
'UnitesDecomptees' => $values[12],
'coutEtablissementHt' => $values[13],
'coutValoriseHt' => $values[14],
'PrefixeForce' => $values[15],
]);
print 'insert call: ok' . PHP_EOL;
}
}
}
else {
print 'This file has already been imported' . PHP_EOL;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment