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


class Kursdatenliste extends DruckListe
{
  public function getListID()
  {
    return 5;
  }

  public function getListTyp()
  {
    return '3';
  }

  protected function getOutputName(): string
  {
    return 'Kursdatenliste.pdf';
  }

  
  public function loadSettings()
  {
    parent::loadSettings();
    $this->settings->druckbereich->hochformat = 0; 
  }

  public function loadFactoryDefaults()
  {
    parent::loadFactoryDefaults();
    $this->setTitle1(); 
  }

  public function setTitle1()
  { 
    $this->settings->title1 = 'Kurse';
  }

  
  public function _prepare($pKnr = '')
  {
    parent::_prepare($pKnr);

    
    
    $this->spaltenbeginnary = array(3, 10.5, 27, 36.5,   42, 51.5, 56,   61,   68,   71, 74.5);
    $this->spaltenbreiteary = array(8.5,   16, 11,    4,   11,    4,  8,    6,    3,    3,   21);
  }

  
  public function getDruckbereichEnabled($optionName)
  {
    switch ($optionName) {
      case 'querformat':
        return true;
    }

    return false;
  }

  
  protected function _printDruckListe($pKurs = '')
  {
    
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', 'Kursnr.', 'B', '', '', $this->spaltenbreiteary[0] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[1] . '%', 'Titel', 'B', '', '', $this->spaltenbreiteary[1] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[2] . '%', 'Beginn', 'B', '', '', $this->spaltenbreiteary[2] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[3] . '%', 'Zeit', 'B', '', '', $this->spaltenbreiteary[3] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[4] . '%', 'Ende', 'B', '', '', $this->spaltenbreiteary[4] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[5] . '%', 'Zeit', 'B', '', '', $this->spaltenbreiteary[5] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[6] . '%', 'Dauer', 'B', '', '', $this->spaltenbreiteary[6] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[7] . '%', 'UE', 'B', 'R', '', $this->spaltenbreiteary[7] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[8] . '%', 'TN', 'B', 'R', '', $this->spaltenbreiteary[8] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', 'WL', 'B', 'R', '', $this->spaltenbreiteary[9] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[10] . '%', 'Ort', 'B', '', '', $this->spaltenbreiteary[10] . '%', 0, $this->height);
    $this->pdf->ln($this->height + 3);

    
    $summeUE = 0;
    $summeTN = 0;
    $summeWL = 0;

    foreach ($this->kursary as $kurs) {
      $this->_printKursCell($kurs);
      $summeUE += $this->mop->stringToFloat($kurs->stundenanz);
      $summeTN += $kurs->getVarValue('teil_akt');
      $summeWL += $kurs->getVarValue('teil_wart');
    }
    $this->pdf->ln(3);

    
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', 'Anzahl der Kurse:  ' . count($this->kursary), 'B', '', '', '20%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[7] - 5 . '%', $this->mop->floatToString($summeUE), '', 'R', '', $this->spaltenbreiteary[7] + 5 . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[8] . '%', $summeTN, '', 'R', '', $this->spaltenbreiteary[8] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', $summeWL, '', 'R', '', $this->spaltenbreiteary[9] . '%', 0, $this->height);
  }

  
  public function _printKursCell($pkurs)
  {
    if ($pkurs == null) {
      $pkurs = new Kurs();
    }

    
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', $pkurs->id, '', '', 10, $this->spaltenbreiteary[0] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[1] . '%', $pkurs->kurzbez, '', '', 10, $this->spaltenbreiteary[1] . '%', 0, $this->height);

    $this->pdf->CellAtX($this->spaltenbeginnary[2] . '%', $pkurs->getVarValue('beginn_dat_wotagkurz'), '', '', 10, $this->spaltenbreiteary[2] - 8 . '%', 0, $this->height);
    $this->pdf->CellAtX(2.5 + $this->spaltenbeginnary[2] . '%', $pkurs->beginn_dat, '', '', 10, $this->spaltenbreiteary[2] - 3 . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[3] . '%', $pkurs->beginn, '', '', 10, $this->spaltenbreiteary[3] . '%', 0, $this->height);

    $this->pdf->CellAtX($this->spaltenbeginnary[4] . '%', $pkurs->getVarValue('ende_dat_wotagkurz'), '', '', 10, $this->spaltenbreiteary[4] - 8 . '%', 0, $this->height);
    $this->pdf->CellAtX(2.5 + $this->spaltenbeginnary[4] . '%', $pkurs->ende_dat, '', '', 10, $this->spaltenbreiteary[4] - 3 . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[5] . '%', $pkurs->ende, '', '', 10, $this->spaltenbreiteary[5] . '%', 0, $this->height);

    $this->pdf->CellAtX($this->spaltenbeginnary[6] . '%', $pkurs->dauer, '', '', 10, $this->spaltenbreiteary[6] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[7] . '%', $this->mop->floatToString($pkurs->stundenanz), '', 'R', 10, $this->spaltenbreiteary[7] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[8] . '%', $pkurs->getVarValue('teil_akt'), '', 'R', 10, $this->spaltenbreiteary[8] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', $pkurs->getVarValue('teil_wart'), '', 'R', 10, $this->spaltenbreiteary[9] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[10] . '%', $pkurs->ort, '', '', 10, $this->spaltenbreiteary[10] . '%', 0, $this->height);
    $this->pdf->ln($this->height);
  }
}