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







class DBWorkHLErmaessigungen extends DBWorkHLBasis
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, nr, text, prozente, kurz ';
    $this->orderby = 'sort, nr, text';
  }

  
  public function getNewObject()
  {
    return new Ermaessigung();
  }

  public function getTableName(): string
  {
    return 'ermaess';
  }

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $tmp = $this->getNewObject();
    $tmp->id = $this->getDatamodulValue('id');
    $tmp->nr = $this->getDatamodulValue('nr');
    $tmp->text = $this->getDatamodulValue('text');
    $tmp->prozente = $this->getDatamodulValue('prozente');
    $tmp->kurz = $this->getDatamodulValue('kurz');

    return $tmp;
  }

  
  public function getAll()
  {
    
    
    $sql = 'SELECT ' . $this->select . ' FROM ermaess';
    $sql .= ' WHERE ' . $this->dboperation->dbparser->isNull('ungueltig', '\'F\'') . '<> \'W\' '
    . 'and (gueltigbis > ' . $this->datetimeop->getFormateDate4ServerNow()
          . ' OR gueltigbis = ' . $this->datetimeop->getFormatDate4Server(DEFAULTDATE) . ' OR gueltigbis is null)';
    $sql .= ' ORDER BY ' . $this->orderby;
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }

  
  public function getOne($pId)
  {
    $id = $this->dboperation->getInt4Sql($pId);
    $sql = 'SELECT ' . $this->select . "FROM ermaess WHERE id='" . $id . "'";
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getFirstRow();
  }

  
  public function getOneByNr($pNr)
  {
    $nr = $this->dboperation->getInt4Sql($pNr);
    $sql = 'SELECT ' . $this->select . "FROM ermaess WHERE nr='" . $nr . "'";
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getFirstRow();
  }
}