WIP RTR Reporting

This commit is contained in:
Frank Schubert
2024-12-06 13:45:20 +01:00
parent 3a7b356b30
commit 33d7a4e5f1
12 changed files with 604 additions and 10 deletions

View File

@@ -27,11 +27,54 @@ class Address extends mfBaseModel {
$this->generateFibuAccountNumber();
$this->syncToFibuMerge();
$this->getCoords();
$this->in_after_save--;
}
public function getCoords() {
$update_needed = false;
if($this->id) {
$changes = $this->getChangedFields();
foreach($changes as $key => $change) {
if($key == "street" || $key == "zip" || $key == "city") {
$update_needed = true;
}
}
} else {
$update_needed = true;
}
if(!$this->gps_lat || !$this->gps_long || !$this->laea) {
$update_needed = true;
}
if(!$update_needed) return true;
$gps_search = [
'country' => $this->getProperty("country")->isocode,
'city' => $this->city,
'zip' => $this->zip,
'street' => $this->street
];
$gps = Gmaps_Geocoding::getCoords($gps_search);
if(!is_array($gps) || !count($gps) == 2) return false;
$this->gps_lat = $gps[0];
$this->gps_long = $gps[1];
$this->laea = (new Building())->getLaeaCoordinates($this->gps_lat, $this->gps_long);
$this->save();
return true;
}
public function generateFibuAccountNumber() {
if($this->fibu_account_number) {
return true;