Leska Import / workflow script
This commit is contained in:
@@ -17,9 +17,8 @@ define("INTERNAL_USER_USERNAME", $me->username);
|
||||
define("MFBASE_BYPASS_LOGIN", true);
|
||||
|
||||
$folder = __DIR__."/source";
|
||||
$filename = "$folder/Leska-fixed.csv";
|
||||
$filename = "$folder/Export Ly 04022025.csv";
|
||||
|
||||
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
|
||||
$log = mfLoghandler::singleton();
|
||||
|
||||
$input = fopen($filename, "r");
|
||||
@@ -30,6 +29,67 @@ $lineworker_id = 1;
|
||||
$zip = 8160;
|
||||
$city = "Mortantsch";
|
||||
|
||||
$buildingtypes = [
|
||||
1 => 1, // Einfamilienhaus
|
||||
2 => 2 // Zweifamilienhaus
|
||||
];
|
||||
|
||||
$buildingstatus = [
|
||||
"geplant" => 2,
|
||||
"Rohr am Grundstück" => 4,
|
||||
"Rohr im Haus" => 5,
|
||||
"Kabel eingeblasen" => 5,
|
||||
];
|
||||
|
||||
$terminationstatus = [
|
||||
"geplant" => 1,
|
||||
"Rohr am Grundstück" => 1,
|
||||
"Rohr im Haus" => 1,
|
||||
"Kabel eingeblasen" => 4,
|
||||
];
|
||||
|
||||
$colors = [
|
||||
"rt" => "rot",
|
||||
"gn" => "gruen",
|
||||
"bl" => "blau",
|
||||
"ge" => "gelb",
|
||||
"ws" => "weiss",
|
||||
"natur" => "natur",
|
||||
"gr" => "grau",
|
||||
"br" => "braun",
|
||||
"vi" => "violett",
|
||||
"tr" => "tuerkis",
|
||||
"sw" => "schwarz",
|
||||
"or" => "orange",
|
||||
"rs" => "rosa",
|
||||
"rt|ge" => "Rot-Gelb",
|
||||
"rt|gn" => "Rot-Gruen",
|
||||
"rt|bl" => "Rot-Blau",
|
||||
"rt|vi" => "Rot-Violett",
|
||||
"rt|gr" => "Rot-Grau",
|
||||
"ge|bl" => "Gelb-Blau",
|
||||
"ge|vi" => "Gelb-Violett",
|
||||
"ge|gr" => "Gelb-Grau",
|
||||
"gn|bl" => "Gruen-Blau",
|
||||
"gn|vi" => "Gruen-Violett",
|
||||
"gn|gr" => "Gruen-Grau",
|
||||
"br|bl" => "Braun-Blau",
|
||||
"br|vi" => "Braun-Violett",
|
||||
"br|gr" => "Braun-Grau",
|
||||
"br|gn" => "Braun-Gruen",
|
||||
"br|ge" => "Braun-Gelb",
|
||||
"br|rt" => "Braun-Rot",
|
||||
"sw|rt" => "Schwarz-Rot",
|
||||
"sw|ge" => "Schwarz-Gelb",
|
||||
"sw|gn" => "Schwarz-Gruen",
|
||||
"sw|bl" => "Schwarz-Blau",
|
||||
"sw|vi" => "Schwarz-Violett",
|
||||
"sw|gr" => "Schwarz-Grau",
|
||||
"sw|br" => "Schwarz-Braun",
|
||||
];
|
||||
|
||||
$existing_count = 0;
|
||||
|
||||
$l = 0;
|
||||
while($csv = fgetcsv($input, 0)) {
|
||||
$l++;
|
||||
@@ -39,8 +99,6 @@ while($csv = fgetcsv($input, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//var_dump($csv);exit;
|
||||
|
||||
$address = trim($csv[0]);
|
||||
$unit_count = trim($csv[1]);
|
||||
$status = trim($csv[2]);
|
||||
@@ -48,6 +106,7 @@ while($csv = fgetcsv($input, 0)) {
|
||||
$rohrname = trim($csv[4]);
|
||||
$gps_long = trim($csv[11]);
|
||||
$gps_lat = trim($csv[12]);
|
||||
$contact_name = trim($csv[14]);
|
||||
$farbe2 = trim($csv[18]);
|
||||
$farbe3 = trim($csv[20]);
|
||||
$fcp_name = trim($csv[22]);
|
||||
@@ -59,7 +118,6 @@ while($csv = fgetcsv($input, 0)) {
|
||||
if($address == "Leska 25 Haus 25a Altbau") continue;
|
||||
|
||||
$m = [];
|
||||
//
|
||||
if(!preg_match('/(.+)\s+(\.?\d+[a-z0-9\/&#._-]*|Ost)(.+)?/', $address, $m)) {
|
||||
echo "adresse nicht gefunden\n";
|
||||
continue;
|
||||
@@ -79,62 +137,127 @@ while($csv = fgetcsv($input, 0)) {
|
||||
|
||||
echo "$address => $street - $housenumber\n";
|
||||
|
||||
$existing_building = BuildingModel::getFirst(["street" => $address ]);
|
||||
$existing_building = BuildingModel::getFirst(["=street" => $address ]);
|
||||
if($existing_building) {
|
||||
|
||||
echo "===========FOUND $address: ".$existing_building->street.", ".$existing_building->zip." ".$existing_building->city."\n";
|
||||
$existing_count++;
|
||||
$building = $existing_building;
|
||||
$building_id = $existing_building->id;
|
||||
//var_dump($existing_building);exit;
|
||||
}
|
||||
|
||||
$buildingtypes = [
|
||||
1 => 1, // Einfamilienhaus
|
||||
2 => 2 // Zweifamilienhaus
|
||||
];
|
||||
|
||||
$buildingstatus = [
|
||||
"geplant" => 2,
|
||||
"Rohr am Grundstück" => 4,
|
||||
"Rohr im Haus" => 5,
|
||||
"Kabel eingeblasen" => 5,
|
||||
];
|
||||
if(!$existing_building) {
|
||||
$building_data = [
|
||||
"network_id" => $network_id,
|
||||
"pop_id" => $pop_id,
|
||||
"type_id" => $buildingtypes[$unit_count],
|
||||
"status_id" => $buildingstatus[$status],
|
||||
"lineworker_id" => $lineworker_id,
|
||||
"street" => $address,
|
||||
"zip" => $zip,
|
||||
"city" => $city,
|
||||
"gps_lat" => $gps_lat,
|
||||
"gps_long" => $gps_long,
|
||||
"oaid" => "",
|
||||
"contact" => "",
|
||||
"phone" => "",
|
||||
"email" => "",
|
||||
"units" => 0,
|
||||
"note" => "",
|
||||
];
|
||||
|
||||
$terminationstatus = [
|
||||
"geplant" => 1,
|
||||
"Rohr am Grundstück" => 1,
|
||||
"Rohr im Haus" => 1,
|
||||
"Kabel eingeblasen" => 4,
|
||||
];
|
||||
$building = BuildingModel::create($building_data);
|
||||
$building->code = $building->getNewObjectCode();
|
||||
|
||||
$building_data = [
|
||||
"network_id" => $network_id,
|
||||
"pop_id" => $pop_id,
|
||||
"type_id" => $buildingtypes[$unit_count],
|
||||
"status_id" => $buildingstatus[$status],
|
||||
"lineworker_id" => $lineworker_id,
|
||||
"street" => $address,
|
||||
"zip" => $zip,
|
||||
"city" => $city,
|
||||
"gps_lat" => $gps_lat,
|
||||
"gps_long" => $gps_long,
|
||||
"oaid" => "",
|
||||
"contact" => "",
|
||||
"phone" => "",
|
||||
"email" => "",
|
||||
"units" => "hallo",
|
||||
"note" => "",
|
||||
];
|
||||
|
||||
$building = BuildingModel::create($building_data);
|
||||
|
||||
$building_id = $building->save();
|
||||
if(!$building_id) {
|
||||
//var_dump($building);
|
||||
//var_dump($building_id);
|
||||
die("Error saving building");
|
||||
if(!$building->save()) {
|
||||
var_dump($building);
|
||||
die("Error saving building\n");
|
||||
}
|
||||
$building_id = $building->id;
|
||||
}
|
||||
|
||||
// workflow stuff
|
||||
foreach($building->workflowitems as $wftype => $wfitem) {
|
||||
if($wfitem->value && ($wfitem->value->value_string || $wfitem->value->value_int)) continue;
|
||||
$wfitem->value->create_by = $me->id;
|
||||
$wfitem->value->edit_by = $me->id;
|
||||
|
||||
if($wftype == "rohrfarbe") {
|
||||
if(!$farbe1 && !$farbe2 && !$farbe3) continue;
|
||||
if($farbe3) {
|
||||
$farbe = $farbe3;
|
||||
} elseif($farbe2) {
|
||||
$farbe = $farbe2;
|
||||
} else {
|
||||
$farbe = $farbe1;
|
||||
}
|
||||
|
||||
$m = [];
|
||||
if(preg_match('/^\d+-(.+)$/', $farbe, $m)) {
|
||||
$fb_code = $m[1];
|
||||
}
|
||||
|
||||
if(!$fb_code) {
|
||||
echo "Keine Farbe\n";
|
||||
continue;
|
||||
}
|
||||
if(!array_key_exists($fb_code, $colors)) {
|
||||
echo "Unbekannter Farbcode\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$wfitem->value->setValue($colors[$fb_code]);
|
||||
}
|
||||
|
||||
if($wftype == "rohrverband_name") {
|
||||
$wfitem->value->setValue($rohrname);
|
||||
/*$wfvalue = WorkflowvalueModel::create([
|
||||
"value_string" => $rohrname,
|
||||
]);*/
|
||||
}
|
||||
|
||||
|
||||
if($wftype == "anschlusspunkt_typ") {
|
||||
$wfitem->value->setValue("Verteiler");
|
||||
}
|
||||
|
||||
if($wftype == "anschlusspunkt_name") {
|
||||
$wfitem->value->setValue($fcp_name);
|
||||
}
|
||||
|
||||
if($wftype == "rohrtype") {
|
||||
$wfitem->value->setValue("MR7/4");
|
||||
}
|
||||
|
||||
|
||||
if($wfitem->value && ($wfitem->value->value_string || $wfitem->value->value_int || $wfitem->value->value_text)) {
|
||||
//var_dump($wfitem->value);
|
||||
$wfitem->value->save();
|
||||
}
|
||||
|
||||
}
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
if(!$unit_count || $existing_building) continue;
|
||||
|
||||
for($i = 0; $i < $unit_count; $i++) {
|
||||
$unit_data = [
|
||||
"building_id" => $building->id,
|
||||
"status_id" => $terminationstatus[$status],
|
||||
"contact" => ($contact_name) ?: null
|
||||
];
|
||||
|
||||
$unit = TerminationModel::create($unit_data);
|
||||
$unit->code = $unit->getNewObjectCode();
|
||||
//var_dump($unit);exit;
|
||||
if(!$unit->save()) {
|
||||
var_dump($unit);
|
||||
die("Error saving unit\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user