Fixed Voicenumber and Updated Voiceplan
This commit is contained in:
@@ -313,8 +313,7 @@ class Contract extends mfBaseModel {
|
||||
$me->loadMe();
|
||||
|
||||
$old_id = $this->id;
|
||||
$old_nummer = $this->nummer;
|
||||
unset($this->id);
|
||||
$this->id = null;
|
||||
|
||||
|
||||
// cleanup Contract daten
|
||||
@@ -336,7 +335,7 @@ class Contract extends mfBaseModel {
|
||||
//$this->save();
|
||||
|
||||
if($old_id == $this->id) {
|
||||
$this->log->error("save() of cloned Contract $old_nummer failed!");
|
||||
$this->log->error("save() of cloned Contract $old_id failed!");
|
||||
throw new Exception("Saving clone failed.");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class Voicenumber extends mfBaseModel {
|
||||
}
|
||||
|
||||
public function afterSave() {
|
||||
// XXX Move to some ContractConfig add number function
|
||||
// TODO: Move to some ContractConfig add number function
|
||||
|
||||
// if contract_id is given, add number to contract
|
||||
if($this->contract_id) {
|
||||
|
||||
@@ -93,19 +93,17 @@ class VoicenumberblockController extends mfBaseController {
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data['name'] = $r->name;
|
||||
$data['countrycode'] = $r->countrycode;
|
||||
$data['areacode'] = $r->areacode;
|
||||
$data['name'] = trim($r->name);
|
||||
$data['countrycode'] = trim($r->countrycode);
|
||||
$data['areacode'] = trim($r->areacode);
|
||||
|
||||
if(substr($r->first,0,1) === "0") {
|
||||
$data['number_prepend_zero'] = 1;
|
||||
} else {
|
||||
$data['number_prepend_zero'] = 0;
|
||||
}
|
||||
$data['first'] = $r->first;
|
||||
$data['last'] = $r->last;
|
||||
$data['first'] = $data['countrycode'].$data['areacode'].trim($r->first);
|
||||
$data['last'] = $data['countrycode'].$data['areacode'].trim($r->last);
|
||||
|
||||
$data['comment'] = $r->comment;
|
||||
$prefix_length = strlen($data['first']) - strlen($data['last'] - $data['first']);
|
||||
$data['prefix'] = substr($data['first'], 0, $prefix_length);
|
||||
|
||||
$data['comment'] = nl2br(htmlentities(trim($r->comment)));
|
||||
$data['edit_by'] = $this->me->id;
|
||||
|
||||
if($mode == "add") {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,16 +125,19 @@ class VoiceplanController extends mfBaseController {
|
||||
$data['name'] = $r->name;
|
||||
$data['description'] = $r->description;
|
||||
|
||||
/*if($r->increment) {
|
||||
if($r->increment) {
|
||||
$increments = explode("/",$r->increment);
|
||||
if(count($increments) != 2) {
|
||||
if(count($increments) != 2 || !is_numeric($increments[0]) || !is_numeric($increments[1])) {
|
||||
$this->layout()->setFlash("Ungültige Taktung", "error");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
$data["increment_first"] = $increments[0];
|
||||
$data["increment"] = $increments[1];
|
||||
}*/
|
||||
} else {
|
||||
$this->layout()->setFlash("Ungültige Taktung", "error");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
if(!$data['name']) {
|
||||
$this->layout()->setFlash("Bitte Name eingeben", "error");
|
||||
@@ -153,8 +156,36 @@ class VoiceplanController extends mfBaseController {
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
// import zones
|
||||
if(is_array($_FILES) && array_key_exists("voiceplanzonefile", $_FILES) && !$_FILES['voiceplanzonefile']['error']) {
|
||||
if($r->copy_from_plan_id) {
|
||||
// get old voiceplan, clone zones and save destinations
|
||||
$old_voiceplan = new Voiceplan($r->copy_from_plan_id);
|
||||
if(!$old_voiceplan->id) {
|
||||
$this->layout()->setFlash("Source Voiceplan nicht gefunden. Keine Zonen und Destinations kopiert!", "warning");
|
||||
$this->redirect("Voiceplan", "view", ["id" => $id]);
|
||||
}
|
||||
|
||||
foreach($old_voiceplan->zones as $old_zone) {
|
||||
$new_zone = clone($old_zone);
|
||||
$new_zone->voiceplan_id = $id;
|
||||
$new_zone->increment_first = $voiceplan->increment_first;
|
||||
$new_zone->increment = $voiceplan->increment;
|
||||
if(!$new_zone->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Kopieren der Source Zone!", "error");
|
||||
$this->redirect("Voiceplan", "view", ["id" => $id]);
|
||||
}
|
||||
|
||||
foreach($new_zone->cloned_destinations as $cd) {
|
||||
$cd->voiceplanzone_id = $new_zone->id;
|
||||
if(!$cd->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern der kopierten Destinations!", "error");
|
||||
$this->redirect("Voiceplan", "view", ["id" => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} elseif(is_array($_FILES) && array_key_exists("voiceplanzonefile", $_FILES) && !$_FILES['voiceplanzonefile']['error']) {
|
||||
// import zones
|
||||
// look for uploaded import file
|
||||
try {
|
||||
// returns File object or throws Exception on error
|
||||
@@ -199,7 +230,7 @@ class VoiceplanController extends mfBaseController {
|
||||
$this->layout()->setFlash("Fehler beim Upload des Destinationfiles: ".$ex->getMessage(), "error");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
|
||||
$vpf = VoiceplanFileModel::create([
|
||||
'voiceplan_id' => $id,
|
||||
'file_id' => $file->id,
|
||||
@@ -215,11 +246,17 @@ class VoiceplanController extends mfBaseController {
|
||||
$this->layout()->setFlash("Fehler beim Importieren!", "error");
|
||||
return $this->editAction();
|
||||
}
|
||||
|
||||
if($voiceplan->import_errors) {
|
||||
$this->layout()->setFlash(implode("<br />\n", $voiceplan->import_errors), "warning");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->layout()->setFlash("Sprachtarifpaket erfolgreich gespeichert!", "success");
|
||||
$this->redirect("Voiceplan", "view", ["id" => $id]);
|
||||
$this->redirect("Voiceplan", "Index");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
class VoiceplanModel {
|
||||
public $name;
|
||||
public $description;
|
||||
public $source;
|
||||
public $source_id;
|
||||
public $increment_first;
|
||||
public $increment;
|
||||
|
||||
public $create_by;
|
||||
public $edit_by;
|
||||
|
||||
@@ -37,4 +37,23 @@ class Voiceplandestination extends mfBaseModel {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
$me = new User;
|
||||
$me->loadMe();
|
||||
|
||||
$old_id = $this->id;
|
||||
$this->id = null;
|
||||
$this->voiceplan = null;
|
||||
|
||||
|
||||
$this->create_by = $me->id;
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
$this->create = null;
|
||||
$this->edit = null;
|
||||
$this->saved = 0;
|
||||
$this->mode = "new";
|
||||
$this->_old_data = new StdClass();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ class VoiceplandestinationModel {
|
||||
if(array_key_exists("prefix", $filter)) {
|
||||
$prefix = $db->escape($filter['prefix']);
|
||||
if($prefix) {
|
||||
$where .= " AND prefix like '%$prefix%'";
|
||||
$where .= " AND prefix like '$prefix'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,16 @@ class Voiceplanzone extends mfBaseModel {
|
||||
private $destinations;
|
||||
private $voiceplan;
|
||||
|
||||
public $cloned_destinations = [];
|
||||
|
||||
public function getDestinationCountOrPrefix() {
|
||||
$destinations = $this->getProperty("destinations");
|
||||
if(count($destinations) == 1) {
|
||||
return "+".$destinations[0]->prefix;
|
||||
}
|
||||
return count($destinations);
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -30,4 +40,32 @@ class Voiceplanzone extends mfBaseModel {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
$me = new User;
|
||||
$me->loadMe();
|
||||
|
||||
$old_id = $this->id;
|
||||
$this->id = null;
|
||||
$this->destinations = null;
|
||||
$this->voiceplan = null;
|
||||
|
||||
// cleanup data
|
||||
|
||||
$this->create_by = $me->id;
|
||||
$this->edit_by = $me->id;
|
||||
|
||||
$this->create = null;
|
||||
$this->edit = null;
|
||||
$this->saved = 0;
|
||||
$this->mode = "new";
|
||||
$this->_old_data = new StdClass();
|
||||
|
||||
// clone all destinations
|
||||
$this->cloned_destinations = [];
|
||||
foreach(VoiceplandestinationModel::search(['voiceplanzone_id' => $old_id]) as $old_destination) {
|
||||
$this->cloned_destinations[] = clone($old_destination);
|
||||
}
|
||||
|
||||
$this->log->debug("Cloned Voiceplanzone $old_id");
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
class VoiceplanzoneModel {
|
||||
public $voiceplan_id;
|
||||
public $extref;
|
||||
public $name;
|
||||
public $purchase_price;
|
||||
public $price;
|
||||
@@ -55,7 +56,7 @@ class VoiceplanzoneModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -72,7 +73,7 @@ class VoiceplanzoneModel {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
public static function count($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -88,7 +89,7 @@ class VoiceplanzoneModel {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
public static function search($filter = [], $limit = []) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
@@ -98,6 +99,14 @@ class VoiceplanzoneModel {
|
||||
WHERE $where
|
||||
ORDER BY voiceplan_id,name";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
|
||||
if($db->num_rows($res)) {
|
||||
@@ -127,6 +136,13 @@ class VoiceplanzoneModel {
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("extref", $filter)) {
|
||||
$extref = FronkDB::singleton()->escape($filter['extref']);
|
||||
if($extref) {
|
||||
$where .= " AND extref='$extref'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user