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


class ArtikelPorto extends Datamodul
{
  public $porto;
  public $von;
  public $bis;
  public $typ;
  
  public $prio;
  
  public $region;

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'von':
      case 'bis':
      case 'prio':
      case 'region':
        return \DatamodulVarType::TYPE_INT;
      case 'porto':
        return \DatamodulVarType::TYPE_FLOAT;
    }
  }

  public function getVarValue($name)
  {
    switch ($name) {
      default:
        return parent::getVarValue($name);
      case 'von_anzeige':
        return $this->berechneAnzeige($this->von);
      case 'bis_anzeige':
        return $this->berechneAnzeige($this->bis);
      case 'von_kg':
        return MathOperations::grammToKilo($this->von);
      case 'bis_kg':
        return MathOperations::grammToKilo($this->bis);
    }
  }

  private function berechneAnzeige($pGewicht)
  {
    if ($this->typ == 'G') {
      return MathOperations::gewichtAnzeige($pGewicht);
    } else {
      return $pGewicht . ' ' . CURRENCY;
    }
  }

  public static function getRegionByNation($pNation)
  {
    if ($pNation != '' && $pNation === 'Schweiz') {
      return 2;
    }
    if ($pNation != '' && $pNation !== 'Deutschland') {
      return 1;
    } else {
      return 0;
    }
  }
}