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


class Honorarliste extends DruckListe
{
  
  public $kursetage;

  
  public $summeHonorar;

  
  public $summeFahrtkosten;

  
  public $summeSpesen;

  
  public $summeZahlung;

  
  public $summeOffeneZahlung;

  
  public function getListID()
  {
    return 4;
  }

  

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

  

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

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

  

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

  

  protected function _printSubtitleWithLn()
  {
    if (trim($this->settings->title2)) {
      parent::_printSubtitleWithLn();
    }
  }

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

    return false;
  }

  

  protected function _getEinzug()
  {
    return $this->spaltenbeginnary[0] . '%';
  }

  protected function _getPositionStand()
  {
    return '83%';
  }

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

    
    
    $this->spaltenbeginnary = array(5, 14.5, 31, 35, 43, 50, 57, 63.5, 72, 87);
    $this->spaltenbreiteary = array(11, 19.5, 5.5, 8, 7, 7, 9.5, 8, 18.5, 8);
  }

  


  

  
  protected function _getZeitraumAnzeige()
  {
    return ', ausgewählte Kurse';
    
  }

  
  protected function _printDruckListe($pKurs = '')
  {

        
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', 'Kurs-Nr.', '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] . '%', 'DozArt', 'B', 'R', 10, $this->spaltenbreiteary[2] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[3] . '%', 'Honorar', 'B', 'R', '', $this->spaltenbreiteary[3] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[4] . '%', 'Fahrtk.', 'B', 'R', '', $this->spaltenbreiteary[4] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[5] . '%', 'Spesen', 'B', 'R', '', $this->spaltenbreiteary[5] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[6] . '%', 'Datum', 'B', '', '', $this->spaltenbreiteary[6] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[7] . '%', 'Zahlung', 'B', 'R', '', $this->spaltenbreiteary[7] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[8] . '%', 'wofür', 'B', '', '', $this->spaltenbreiteary[8] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', 'Offen', 'B', 'R', '', $this->spaltenbreiteary[9] . '%', 0, $this->height);

    $this->pdf->ln(4.5);
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', '', '', '', '', '90%', 1, 0);
    $this->pdf->ln(3.5);

    

    $this->summeHonorar = 0;
    $this->summeFahrtkosten = 0;
    $this->summeSpesen = 0;
    $this->summeZahlung = 0;
    $this->summeOffeneZahlung = 0;

    
    foreach ($this->kursary as $kurs) {
      $this->_printKursCell($kurs);
    }

    $this->pdf->ln(4.5);
    $this->pdf->CellAtX($this->spaltenbeginnary[0] . '%', '', '', '', '', '90%', 1, 0);
    $this->pdf->ln(1.5);

    $this->pdf->CellAtX($this->spaltenbeginnary[3] . '%', $this->mop->floatToStringWithThousandSeps($this->summeHonorar), '', 'R', '', $this->spaltenbreiteary[3] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[4] . '%', $this->mop->floatToStringWithThousandSeps($this->summeFahrtkosten), '', 'R', '', $this->spaltenbreiteary[4] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[5] . '%', $this->mop->floatToStringWithThousandSeps($this->summeSpesen), '', 'R', '', $this->spaltenbreiteary[5] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[7] . '%', $this->mop->floatToStringWithThousandSeps($this->summeZahlung), '', 'R', '', $this->spaltenbreiteary[7] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', $this->mop->floatToStringWithThousandSeps($this->summeOffeneZahlung), '', 'R', '', $this->spaltenbreiteary[9] . '%', 0, $this->height);
  }

  

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


    $dbwhonorar = new DBWorkDozentenHonorar();
    $honorar = $dbwhonorar->getHonorarbyKNRDozentNR($pKurs->id, $this->dozId);

    
    $summegesamt = 0;

    
    $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] . '%', $honorar->typ, '', 'R', 10, $this->spaltenbreiteary[2] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[3] . '%', $this->mop->floatToStringWithThousandSeps($honorar->getVarValue('honGesamtMitKomma')), '', 'R', 10, $this->spaltenbreiteary[3] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[4] . '%', $this->mop->floatToStringWithThousandSeps($honorar->getVarValue('fahrtGesamtMitKomma')), '', 'R', 10, $this->spaltenbreiteary[4] . '%', 0, $this->height);
    $this->pdf->CellAtX($this->spaltenbeginnary[5] . '%', $this->mop->floatToStringWithThousandSeps($honorar->spesen), '', 'R', 10, $this->spaltenbreiteary[5] . '%', 0, $this->height);

    
    
    $dbwzahlung = new DBWorkZahlung();
    $zahlungary = $dbwzahlung->getZahlungByDoznrKnr($this->dozId, $pKurs->id);

    
    if ($zahlungary) {
      foreach ($zahlungary as $zahlung) {
        $this->pdf->CellAtX($this->spaltenbeginnary[6] . '%', $zahlung->datum, '', '', 10, $this->spaltenbreiteary[6] . '%', 0, $this->height);
        $this->pdf->CellAtX($this->spaltenbeginnary[7] . '%', $this->mop->floatToStringWithThousandSeps($zahlung->betrag), '', 'R', 10, $this->spaltenbreiteary[7] . '%', 0, $this->height);
        $this->pdf->CellAtX($this->spaltenbeginnary[8] . '%', $zahlung->text, '', '', 10, $this->spaltenbreiteary[8] . '%', 0, $this->height);
        $this->pdf->ln($this->height);

        $this->summeZahlung += $this->mop->stringToFloat($zahlung->betrag);
        $summegesamt += $this->mop->stringToFloat($zahlung->betrag);
      }
    }


    
    if (count($zahlungary) != 0) {
      $this->pdf->ln(-$this->height * count($zahlungary));
    }
    $honoraroffen = $this->mop->stringToFloat($honorar->getVarValue('gesamtMitKomma')) - $summegesamt;
    $this->pdf->CellAtX($this->spaltenbeginnary[9] . '%', $this->mop->floatToStringWithThousandSeps($honoraroffen), '', 'R', '', $this->spaltenbreiteary[9] . '%', 0, $this->height);
    (count($zahlungary) != 0) ? $this->pdf->ln($this->height * (count($zahlungary))) : $this->pdf->ln($this->height);
    


    $this->summeHonorar += $this->mop->stringToFloat($honorar->getVarValue('honGesamtMitKomma'));
    $this->summeFahrtkosten += $this->mop->stringToFloat($honorar->getVarValue('fahrtGesamtMitKomma'));
    $this->summeSpesen += $this->mop->stringToFloat($honorar->spesen);
    $this->summeOffeneZahlung += $honoraroffen;
  }

  
}