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


class StammBv extends Datamodul
{
  public $id;
  public $typ;
  public $nr;
  public $blz;
  public $konto;
  public $bankbez;
  public $iban;
  public $bic;
  public $lfd;
  public $ls_jn;
  public $ls_von;
  public $ls_bis;
  public $bemerkung;
  public $inhaber;
  public $sepa;
  public $mandatam;
  public $mandatid;
  public $mandatbem;

  public function getTyp($pFieldName)
  {
    switch ($pFieldName) {
      default:
        return parent::getTyp($pFieldName);
      case 'ls_von':
      case 'ls_bis':
        return \DatamodulVarType::TYPE_DATE;
      case 'mandatam':
        return \DatamodulVarType::TYPE_DATETIME;
      case 'nr':
      case 'lfd':
        return \DatamodulVarType::TYPE_INT;
    }
  }

  public function getVarValue($fieldname)
  {
    switch ($fieldname) {
      default:
        return parent::getVarValue($fieldname);
      case 'sepa_text':
        
        if (\System::isKuferSQL5()) {
          return 'SEPA';
        }
        switch ($this->sepa) {
          case 'S':
            return 'SEPA';
          case 'D':
            return 'DTA';
          default:
            return '';
        }
        
      case 'mandatam':
        $mandatamParts = explode(' ', $this->mandatam ?? '');
        $wert = DateTimeOperations::getValidDateString($mandatamParts[0], true);
        if (DateTimeOperations::isDateTimeDefault($wert)) {
          return '';
        } else {
          return $wert;
        }
    }
  }

  
  public function getDMZValue($fieldname)
  {
    if ($fieldname == 'nr') {
      return $this->nr;
    }
    if ($fieldname == 'mandatam') {
      return DateTimeOperations::getValidDateTimeString($this->mandatam, true);
    }

    return parent::getDMZValue($fieldname);
  }
}