<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class AbweichendeLieferadresse extends Datamodul
{
  
  public $verwenden;
  
  public $name;
  
  public $vorname;
  
  public $nurstrasse;
  
  public $nurhausnr;
  
  public $strasse;
  
  public $nurort;
  
  public $nurplz;
  
  public $ort;
  
  public $zusatz1;
  
  public $zusatz2;
  
  public $geschlecht;
  
  public $nation;

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'verwenden':
        return \DatamodulVarType::TYPE_BOOL;
    }
  }

  
  public function getPortoRegion()
  {
    return ArtikelPorto::getRegionByNation($this->nation);
  }

  public function getVarValue($pName)
  {
    switch ($pName) {
      default:
        return parent::getVarValue($pName);
      case 'nurstrasse':
      case 'nurhausnr':
        $tmp = $this->ort != '' ? parent::getVarValue($pName) : $this->{$pName};

        return is_null($tmp) ? '' : $tmp;
      case 'nurort':
      case 'nurplz':
        $tmp = $this->ort != '' ? parent::getVarValue($pName) : $this->{$pName};

        return is_null($tmp) ? '' : trim($tmp);
    }
  }

  
  public function gleicheMehrfacheInfosAb()
  {
    $nation = $this->nation != '' ? $this->nation : '';
    
    $this->ort = \Kufer\Web\Classes\Addfunctions\PlzOperations::getOrtStrFromPlzOrt($nation, $this->getVarValue('nurplz'), $this->getVarValue('nurort'));
    $this->nurort = \Kufer\Web\Classes\Addfunctions\PlzOperations::getOrtFromPlzOrtStr($nation, $this->ort);
    $this->nurplz = \Kufer\Web\Classes\Addfunctions\PlzOperations::getPlzFromPlzOrtStr($nation, $this->ort);

    
    if (trim($this->strasse) === '') {
      $this->strasse = trim(trim($this->nurstrasse) . ' ' . trim($this->nurhausnr));
    } elseif (trim($this->nurstrasse) === '' && trim($this->nurhausnr) === '') {
      $found = array();
      preg_match('/(\\D*)(.*)/', $this->strasse, $found);
      if (isset($found[1])) {
        $this->nurstrasse = trim($found[1]);
      }
      if (isset($found[2])) {
        $this->nurhausnr = trim($found[2]);
      }
    }
  }
}