<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Mitarbeiter\KursUebersicht\Detailsreiter\Teilnehmer\HandleBarzahlung;

class BarzahlungDialogUseCase extends \Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new BarzahlungDialogResponse());
  }

  public function action()
  {
    $dbwBelegung = new \DBWorkBelegung(1, true);
    $belegungen = $dbwBelegung->getBelegungenByIds($this->request->belegungIds);

    
    
    $kurs = $this->getKurs($this->request->knr);

    return $this->getResponse($belegungen, $kurs);
  }

  protected function getResponse($belegungen, $kurs)
  {
    $this->response->columns = $this->getBarzahlungColumns();
    $this->response->belegungen = $belegungen;
    $this->response->kurs = $kurs;
    $this->response->toolSettings = $this->toolSettings;
    $this->response->toolSection = $this->toToolSection();

    return $this->response;
  }

  protected function getKurs($knr)
  {
    $dbwKurse = new \DBWorkKurseWT();

    return $dbwKurse->getKurs($knr, true);
  }

  
  private function getBarzahlungColumns()
  {
    $columnsArray = array();

    $column = new \Column();
    $column->fieldname = 'name';
    $column->fieldgroup = 'Teilnehmer Adresse';
    $column->datamodul = 'teilnehmer';
    $column->canedit = false;
    $column->responsive = 'W';
    $column->title = 'Name';
    array_push($columnsArray, $column);

    $column = new \Column();
    $column->fieldname = 'vorname';
    $column->fieldgroup = 'Teilnehmer Adresse';
    $column->datamodul = 'teilnehmer';
    $column->canedit = false;
    $column->responsive = 'W';
    $column->title = 'Vorname';
    array_push($columnsArray, $column);

    $column = new \Column();
    $column->fieldname = 'status';
    $column->fieldgroup = 'Belegung Allgemeines';
    $column->datamodul = 'belegung';
    $column->canedit = false;
    $column->responsive = 'W';
    $column->title = 'Status';
    array_push($columnsArray, $column);

    $column = new \Column();
    $column->fieldname = 'zahlart';
    $column->fieldgroup = 'Belegung Allgemeines';
    $column->datamodul = 'belegung';
    $column->canedit = false;
    $column->responsive = 'W';
    $column->title = 'Zahlart';
    array_push($columnsArray, $column);

    
    $column = new \Column();
    $column->fieldname = 'entgelt';
    $column->fieldgroup = 'Belegung Allgemeines';
    $column->datamodul = 'belegung';
    $column->canedit = true;
    $column->responsive = 'W';
    $column->title = 'Entgelt';
    array_push($columnsArray, $column);
    

    
    $column = new \Column();
    $column->fieldname = 'bet_offen';
    $column->fieldgroup = 'Belegung Allgemeines';
    $column->datamodul = 'belegung';
    $column->canedit = true;
    $column->responsive = 'W';
    $column->title = 'Saldo';
    array_push($columnsArray, $column);

    return $columnsArray;
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_KURSPLANUNG_MA;
  }

  public static function getToolSectionId()
  {
    return 242;
  }

  protected function getMainReiterId()
  {
    return 377;
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!\Kufer\Web\KuferTools\Basis\UseCase\ToolUseCase::hasAccess(377)) {
      return false;
    }
    if (!$this->isRechtAllowed($this->getToolSectionId() . '.0.8')) {
      return false;
    }

    return true;
  }
}

class BarzahlungDialogRequest
{
  public $belegungIds;
  public $knr;
}

class BarzahlungDialogResponse extends \Kufer\Web\KuferTools\Basis\UseCase\ToolResponse
{
  public $kurs;
  public $columns;
  public $belegungen;
  public $toolSection;
  public $toolSettings;
}