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

class JournalSight4Tab extends TabSight
{
  protected $dbwZahlung;

  public function initiate()
  {
    parent::initiate();
    $this->belegid = '';
    $this->dbwZahlung = new DBWorkZahlung();
  }

  public function getData()
  {
    $this->dataary = $this->dbwZahlung->getZahlungJournalByBelegId($this->belegid);
  }

  public function getColumns($justallowedcolumns = true)
  {
    parent::getColumns($justallowedcolumns);
    
    if (count($this->columnsary) > 0) {
      $column = new Column();
      $column->title = '';
      $column->accesslevel = 1;
      $column->name = 'invisibleDP';
      $column->fieldname = 'invisibleDP';
      $column->fieldgroup = 'Journal Allgemeines';
      $column->datamodul = 'zahlung';
      $column->fontsize = '1';
      $this->columnsary[] = $column;
    }
  }

  public function getTableRowContent($rowindex, $colindex)
  {
    $retour = parent::getTableRowContent($rowindex, $colindex);
    if ($retour == '0' || $retour === '0,0' || $retour === '0,00') {
      return '';
    } else {
      return $retour;
    }
  }

  protected function getTFooter()
  {
    
    
    $numOfCols = sizeof($this->columnsary) - 1;

    $result = '<tfoot class="journalFooter">' . "\n";
    $row1 = '<tr class="farbe_sicht_header footer_row1">' . "\n";
    $row2 = '<tr class="farbe_sicht_header footer_row2">' . "\n";

    for ($i = 0; $i < $numOfCols; $i++) {
      $bezeichner = $this->columnsary[$i]->datamodul . '_' . $this->columnsary[$i]->fieldname;
      $style = 'width: ' . CleanOperations::cleanInt($this->columnsary[$i]->width) . 'px; font-size: ' . CleanOperations::cleanInt($this->columnsary[$i]->fontsize) . 'px;';

      $row1 .= '<td style="' . $style . '" class="journalFooter_row1_' . CleanOperations::cleanStringForHtml($bezeichner);
      $row1 .= $i == 0 ? '">Summe:' : ' right">';
      $row1 .= '</td>' . "\n";


      $row2 .= '<td style="' . $style . '" class="journalFooter_row2_' . CleanOperations::cleanStringForHtml($bezeichner);
      $row2 .= $i == 0 ? '" id="nochOffenTD">noch offen:' : ' right">';
      $row2 .= '</td>' . "\n";
    }

    $row1 .= '</tr>' . "\n";
    $row2 .= '</tr>' . "\n";

    $result .= $row1 . $row2;
    $result .= '</tfoot>' . "\n";

    return $result;
  }
}