Fixed Voicenumber and Updated Voiceplan
This commit is contained in:
@@ -7,11 +7,15 @@ class Voiceplan extends mfBaseModel {
|
||||
private $zones;
|
||||
private $destinations;
|
||||
|
||||
public $import_errors;
|
||||
|
||||
public function importDestinationsFromCsv(File $file) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$errors = [];
|
||||
|
||||
$i = 0;
|
||||
$filename = $file->getFullPath();
|
||||
$input = fopen($filename, "r");
|
||||
@@ -23,39 +27,57 @@ class Voiceplan extends mfBaseModel {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = trim($csv[0]);
|
||||
$prefix = trim($csv[1]);
|
||||
$price_ek = str_replace(",",".", trim($csv[2]));
|
||||
$price_vk = str_replace(",",".", trim($csv[3]));
|
||||
$zone_extref = trim($csv[0]);
|
||||
$name = trim($csv[1]);
|
||||
$prefix = trim($csv[2]);
|
||||
|
||||
if(!$name || !$prefix || !$price_ek || !$price_vk) {
|
||||
$this->log->warning("not Importing Voiceplandestination with empty value: destination: $name | prefix: $prefix | ek: $price_ek | vk: $price_vk");
|
||||
if(!$zone_extref|| !$prefix || !$name) {
|
||||
$this->log->warning("not Importing Voiceplandestination with empty value: destination: $name | extref: $zone_extref | prefix: $prefix");
|
||||
continue;
|
||||
}
|
||||
|
||||
$destination = VoiceplandestinationModel::getFirst(["voiceplan_id" => $this->id, "destination" => $name, "prefix" => $prefix]);
|
||||
$zone = VoiceplanzoneModel::getFirst(["extref" => $zone_extref, "voiceplan_id" => $this->id]);
|
||||
if(!$zone) {
|
||||
$this->log->error(__METHOD__.": Zone nicht gefunden: $zone_extref | $name | $prefix");
|
||||
$errors[] = "Keine Zone für Destination +$prefix $name (Zone ID: $zone_extref)";
|
||||
continue;
|
||||
}
|
||||
|
||||
$destination = VoiceplandestinationModel::getFirst(["voiceplanzone_id" => $zone->id, "prefix" => $prefix]);
|
||||
|
||||
if($destination) {
|
||||
$this->log->warning("Destination gibts schon, updateing prices: voiceplan_id: ".$this->id." | destination: $name | prefix: $prefix");
|
||||
|
||||
$destination->purchase_price = $price_ek;
|
||||
$destination->price = $price_vk;
|
||||
$destination->save();
|
||||
$this->log->warning(__METHOD__. ": Destination gibts schon: voiceplanzone_id: ".$zone->id." | destination: $name | prefix: $prefix");
|
||||
continue;
|
||||
}
|
||||
|
||||
$destination = VoiceplandestinationModel::create([
|
||||
'voiceplan_id' => $this->id,
|
||||
'voiceplanzone_id' => $zone->id,
|
||||
'destination' => $name,
|
||||
'prefix' => $prefix,
|
||||
'increment_first' => $this->increment_first,
|
||||
'increment' => $this->increment,
|
||||
'purchase_price' => $price_ek,
|
||||
'price' => $price_vk
|
||||
'prefix' => $prefix
|
||||
]);
|
||||
$destination->save();
|
||||
|
||||
}
|
||||
|
||||
// check if there is a destination for 43 (Österreich), otherwise create it
|
||||
$austria_zone = VoiceplanzoneModel::getFirst(["voiceplan_id" => $this->id, "name" => "Österreich"]);
|
||||
if($austria_zone) {
|
||||
$austria_destination = VoiceplandestinationModel::getFirst(["voiceplanzone_id" => $austria_zone->id, "prefix" => "43"]);
|
||||
if(!$austria_destination) {
|
||||
$this->log->debug(__METHOD__.": Creating Austria zone (43)");
|
||||
$austria_destination = VoiceplandestinationModel::create([
|
||||
'voiceplanzone_id' => $austria_zone->id,
|
||||
'destination' => "Österreich",
|
||||
'prefix' => "43"
|
||||
]);
|
||||
$austria_destination->save();
|
||||
}
|
||||
}
|
||||
|
||||
if($errors) {
|
||||
$this->import_errors = $errors;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
@@ -82,16 +104,32 @@ class Voiceplan extends mfBaseModel {
|
||||
}
|
||||
|
||||
$name = trim($csv[0]);
|
||||
$prefix = trim($csv[1]);
|
||||
$price_ek = str_replace(",",".", trim($csv[2]));
|
||||
$price_vk = str_replace(",",".", trim($csv[3]));
|
||||
$extref = trim($csv[1]);
|
||||
$price_default = trim($csv[4]);
|
||||
$price_special = trim($csv[7]);
|
||||
|
||||
if(!$name || !$prefix || !$price_ek || !$price_vk) {
|
||||
$this->log->warning("not Importing Voiceplandestination with empty value: destination: $name | prefix: $prefix | ek: $price_ek | vk: $price_vk");
|
||||
$price_ek = $price_default;
|
||||
if(is_numeric($price_special) && $price_special) {
|
||||
$price_ek = $price_special;
|
||||
}
|
||||
|
||||
if(!$name || !$price_ek) {
|
||||
$this->log->warning(__METHOD__.": not importing Voiceplanzone with empty value: name: $name | ek: $price_ek");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$zone = VoiceplanzoneModel::create([
|
||||
"voiceplan_id" => $this->id,
|
||||
"extref" => $extref,
|
||||
"name" => $name,
|
||||
"purchase_price" => $price_ek,
|
||||
"price" => 0,
|
||||
"increment_first" => $this->increment_first,
|
||||
"increment" => $this->increment
|
||||
]);
|
||||
if(!$zone->save()) {
|
||||
$this->log->error(__METHOD__.": Fehler beim speichern der Voip zone: name: $name | extref: $extref | ek: $price_ek");
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
@@ -107,10 +145,7 @@ class Voiceplan extends mfBaseModel {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "destinations") {
|
||||
$this->destinations = [];
|
||||
foreach($this->getProperty("zones") as $zone) {
|
||||
$this->destinations[] = $zone->destinations;
|
||||
}
|
||||
$this->destinations = VoiceplandestinationModel::search(["voiceplan_id" => $this->id]);
|
||||
return $this->destinations;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user