<?php

Lib::loadClass('RouteToolBase');
Lib::loadClass('UI');
Lib::loadClass('Response');

// index.php?_route=UrlAction_BiAuditRaport  - uruchamia defaultAction
class Bocian extends RouteToolBase {

	public function defaultAction() {
		UI::gora();
		echo UI::h('script', ['src'=>"static/sweetalert2.min.js"]);
		echo UI::h('link', ['rel'=>"stylesheet", 'type'=>"text/css", 'href'=>"static/sweetalert2.min.css"]);
		Theme::top();
		//echo '<div id="smad-wrapper">'; // todo: sprawdzi  czy można usunać
		echo '<div class="container-bi_audit_form_pracownicy_raport" style="display: none;"></div>';
		echo '<div class="container-bi_audit_form_kontrahenci_raport" style="display: none;"></div>';
		echo '<div class="container-bi_audit_form_raport_data" style="display: none;"></div>';

		UI::inlineJS(__FILE__ . '.view.js', [
			'URL_FETCH_KONTRAHENCI_POWIAZANIA' => $this->getLink('fetchEnergaRumKontrahenciPowiazaniaAjax'),
			'URL_FETCH_TEST_KRS' => $this->getLink('fetchTestKrsAjax'),
			'URL_FETCH_TEST_CEIDG' => $this->getLink('fetchTestCeidgAjax'),
			'URL_FETCH_PRACOWNICY' => $this->getLink('fetchPracownicyAjax'),
			'URL_FETCH_KONTRAHENCI' => $this->getLink('fetchKontrahenciAjax'),
			'URL_CREATE_PRACOWNICY_GROUP' => $this->getLink('createPracownicyGroupAjax'),
			'URL_CREATE_KONTRAHENCIS_GROUP' => $this->getLink('createKontrahenciGroupAjax'),
			'URL_ADD_PRACOWNICY_TO_GROUP' => $this->getLink('addPracownicyToGroupAjax'),
			'URL_ADD_KONTRAHENCI_TO_GROUP' => $this->getLink('addKontrahenciToGroupAjax'),
			'URL_FETCH_GROUP_PRACOWNICY' => $this->getLink('fetchGroupPracownicyAjax'),
			'URL_FETCH_GROUP_KONTRAHENCI' => $this->getLink('fetchGroupKontrahenciAjax'),
			'URL_GENERATE_BI_AUDIT_RAPORT_AJAX' => $this->getLink('generateBiAuditRaportAjax'),
			'DBG' => V::get('DBG', 0, $_GET),
			'VIEW_KONTRAHENCI' => $this->defaultViewFormBiAudit([], 'KONTRAHENCI'),
			'VIEW_PRACOWNICY' => $this->defaultViewFormBiAudit([], 'PRACOWNICY'),
			'VIEW_TREE_REAPORT' => $this->showViewTreeReaport('REAPORT_TREE'),
		]);

		echo '</div>'; // #smad-wrapper
		UI::dol();
	}

	public function fetchEnergaRumKontrahenciPowiazaniaAjaxAction() {
		Response::sendTryCatchJson(array($this, 'fetchEnergaRumKontrahenciPowiazaniaAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
	}
	public function fetchEnergaRumKontrahenciPowiazaniaAjax($args) {
		$id = V::get('ID', 26, $_REQUEST, 'int');

		$items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'A_ADM_COMPANY',
				'L_APPOITMENT_USER',
				'A_CLASSIFIED',
				'A_STATUS',
				'A_STATUS_INFO',
				'BI_analiza_depth',
				'BI_analiza_reloadCache',
				'FILE_STATUS',
				'FILE_STATUS_info',
				'L_APPOITMENT_USER',
				'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
				'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI',
				'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
				'default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person',
			],
			'f_ID' => "{$id}",
		])->getItems([
			'limit' => 10
		]);

		// $items = [
		// 	[ 'ID' => 1, 'L_APPOITMENT_INFO' => 'x', 'BI_analiza_depth' => 'a', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test1'],
		// 	[ 'ID' => 2, 'L_APPOITMENT_INFO' => 'y', 'BI_analiza_depth' => 'b', 'FILE_STATUS' => 0, 'FILE_STATUS_info' => 'test2'],
		// 	[ 'ID' => 3, 'L_APPOITMENT_INFO' => 'z',  'BI_analiza_depth' => 'c', 'FILE_STATUS' => 1, 'FILE_STATUS_info' => 'test3'],
		// ];

		return [
			'type' => 'success',
			'msg' => 'OK',
			'__req_args' => $_REQUEST,
			'__args' => $args,
			'body' => [
				'items' => $items,
				'view' => $this->showPowiazaniaEnergaRumKontrahenciPowiazania($items),
			]
		];
	}


public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {

	$view = '<form class="form-horizontal" method="post">
						<table class="table table-bordered table-hover table-striped" height=5>
									 <thead>
										 <tr style="">
										 		<td width=1><input type="checkbox" name="checkAll" id="checkAll" /></td>
											 <td width=1>ID</td>
											 <td>Adnotacje</td>
											 <td>Głębokość analizy</td>
											 <td>Status raportu</td>
											 <td>Status raportu - informacje</td>
										 </tr>
									 </thead>
									 <tbody>
					';

		foreach ($items as $key => $row) {
				$view .= '<tr>
				<td><input type="checkbox" name="prID[]" value="'.$row['ID'].'" onClick="checkAll()"/></td>
								<td align="right">'.$row["ID"].'</td>
								<td align="right">'.$row["L_APPOITMENT_INFO"].'</td>
								<td align="right">'.$row["BI_analiza_depth"].'</td>
								<td align="right">'.$row["FILE_STATUS"].'</td>
								<td align="right">'.$row["FILE_STATUS_info"].'</td>';
		}
		$view .= '</tbody></table></form>';


		return $view;
}




	public function fetchTestKrsAjaxAction() {
		Response::sendTryCatchJson(array($this, 'fetchTestKrsAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
	}
	public function fetchTestKrsAjax($args) {
		$id = V::get('ID', 1, $_REQUEST, 'int');
		$items = ACL::getAclByNamespace('default_db/BI_audit_KRS/BI_audit_KRS')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'A_kod',
				'A_kraj',
				'A_miejscowosc',
				'A_nrDomu',
				'A_nrLokalu',
				'A_poczta',
				'A_ulica',
				'ID',
				'S_gmina',
				'S_kraj',
				'S_miejscowosc',
				'S_powiat',
				'S_wojewodztwo',
				'dataDokumentu',
				'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/ID',
				'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/krs',
				'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/nazwa',
				'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company/regon',
				'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/ID',
				'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/imiona',
				'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/nazwisko',
				'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person/pesel',
				'krs',
				'nazwa',
				'nip',
				'regon',
			],
			'f_ID' => "{$id}",
		])->getItems([
			'limit' => 10
		]);

		return [
			'type' => 'success',
			'msg' => 'KRS',
			'__req_args' => $_REQUEST,
			'__args' => $args,
			'body' => [
				'items' => $items,
			]
		];
	}

	public function fetchTestCeidgAjaxAction() {
		Response::sendTryCatchJson(array($this, 'fetchTestCeidgAjax')); // , $args = 'JSON_FROM_REQUEST_BODY');
	}
	public function fetchTestCeidgAjax($args) {
		$id = V::get('ID', 0, $_REQUEST, 'int');
		$items = ACL::getAclByNamespace('default_db/BI_audit_CEIDG/BI_audit_CEIDG')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'budynek',
				'firma',
				'gmina',
				'identyfikatorWpisu',
				'imie',
				'kodPocztowy',
				'kraj',
				'lokal',
				'miejscowosc',
				'nazwisko',
				'nip',
				'poczta',
				'powiat',
				'regon',
				'ulica',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ID',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/budynek',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/gmina',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/kodPocztowy',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/lokal',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/miejscowosc',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nazwa',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/nip',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/poczta',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/powiat',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/ulica',
				'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy/wojewodztwo',
				'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/ID',
				'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/nip',
				'default_db__x3A__BI_audit_CEIDG_powiazania:BI_audit_CEIDG_powiazania/regon',
			],
			// 'f_ID' => $id,
		])->getItems([
			'limit' => 10
		]);

		return [
			'type' => 'success',
			'msg' => 'CEIDG',
			'__req_args' => $_REQUEST,
			'__args' => $args,
			'body' => [
				'items' => $items,
			]
		];
	}

/**
 * KONTRAHENCI
 */
public function fetchKontrahenciAjaxAction() {
	Response::sendTryCatchJson(array($this, 'fetchKontrahenciAjax'));
}

public function fetchKontrahenciAjax($args) {

			$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
			if ($idGroup < 0) $idGroup = 0;

			$limit = 5;

			$limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
			if ($limitstart < 0) $limitstart = 0;

			$page = V::get('page', 0, $_REQUEST, 'int');
			$limitstart = ($page - 1) * $limit;

			$search = V::get('search', '', $_REQUEST);
			$searchParams = [];
			if (!empty($search)) {
				$ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
				$searchParams['ogc:Filter'] = '
					<ogc:Filter>
				    <ogc:Or>
				      <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
				        <ogc:PropertyName>NIP</ogc:PropertyName>
				        <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
				      </ogc:PropertyIsLike>
				      <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
				        <ogc:PropertyName>Nazwa_grupy_kapitalowej</ogc:PropertyName>
								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
				      </ogc:PropertyIsLike>
				      <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
				        <ogc:PropertyName>Pelna_nazwa_kontrahenta</ogc:PropertyName>
								<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
				      </ogc:PropertyIsLike>
				    </ogc:Or>
				  </ogc:Filter>
				';
			}

			$backRefFilter = [];
			if ($idGroup > 0) {
				$backRefFilter['__backRef'] = [
					'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_KONTRAHENCIS_GRUPY', // TODO: nowy rejetr na grupy / filty KONTRAHENCI
					'primaryKey' => $idGroup,
					'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_KONTRAHENCIS',
				];
				// TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY:
				// - ID
				// - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
				// - NAZWA - nazwa grupy
				// - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_KONTRAHENCI' minOccurs="0" maxOccurs="unbounded"
			}

			$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI');
			$query = $acl->buildQuery(array_merge([
				'cols' => [ // TODO:? propertyName = []
									'ID',
									'Nazwa_grupy_kapitalowej',
									'Pelna_nazwa_kontrahenta',
									'Numer_kontrahenta',
									'Skrocona_Nazwa_Kontrahenta',
									'Typ_kontrahenta',
									'NIP',
									'KRS',
									'REGON',
									'PESEL',
						 			'Forma_prawna_dzialalnosci',
						 			'Ulica',
						 			'Numer_budynku',
						 			'Numer_mieszkania_lokalu',
						 			'Miejscowosc',
									'Kod_pocztowy',
									'Kraj',
									'Telefon',
									'Fax',
									'Mail',
									'A_ADM_COMPANY',
									'A_CLASSIFIED',
									'A_STATUS',
									'A_STATUS_INFO',
									'Dodano',
									'L_APPOITMENT_USER',
									'Podmiot_dominujacy',
									'Tytul_dokumentu',
									'ownCompany',
									'uwagi',
				],
				//'f_ID' => $id,
				'limit' => $limit,
				'limitstart' => $limitstart, // offset
			], $searchParams, $backRefFilter));
			$total = $query->getTotal();
			$items = $query->getItems();

			$pagination = array();
			$pagination['total_items'] = $total;
			$pagination['size'] = ceil($total/$limit); // pages size
			$pagination['current'] = $page;
			$pagination['limit'] = $limit;

			return [
				'type' => 'success',
				'msg' => 'showKontrajenci',
				'__req_args' => $_REQUEST,
				'__args' => $args,
				'body' => [
					'items' => $items,
					//'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI'),
					'pagination' => $pagination
				]
			];
		}
//
// public function fetchKontrahenciAjaxOld($args) {
// 	//$id = V::get('ID', 1, $_REQUEST, 'int');
// 	$items = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI/BI_audit_ENERGA_RUM_KONTRAHENCI')->buildQuery([
// 		'cols' => [ // TODO:? propertyName = []
// 				'ID',
// 				'Nazwa_grupy_kapitalowej',
// 				'Pelna_nazwa_kontrahenta',
// 				'NIP',
// 				'KRS',
// 				'REGON',
// 	 			'Miejscowosc',
// 				'Kod_pocztowy',
// 				'Telefon'
// 		],
// 		//'f_ID' => $id,
// 	])->getItems([
// 		'limit' => 10
// 	]);
//
// 	return [
// 		'type' => 'success',
// 		'msg' => 'showKontrahenci',
// 		'__req_args' => $_REQUEST,
// 		'__args' => $args,
// 		'body' => [
// 			'items' => $items,
// 			'view' => $this->htmlViewFormBiAudit($items, 'KONTRAHENCI')
// 		]
// 	];
// }

public function showTableKontrahenci($items) {
	$view = '<form class="form-horizontal" method="post">
					<table class="table table-bordered table-hover table-striped" height=5>
								 <thead>
									 <tr>
											<td width=1><input type="checkbox" name="checkAll" id="checkAll-KONTRAHENCI" /></td>
										 <td width=1>ID</td>
										 <td>Nazwa grupy kapitalowej</td>
										 <td>Pelna nazwa kontrahenta</td>
										 <td>Numer kontrahenta</td>
										 <td>Skrócona nazwa kontrahenta</td>
										 <td>Typ_kontrahenta</td>
										 <td>NIP</td>
										 <td>KRS</td>
										 <td>Regon</td>
										 <td>PESEL</td>
										 <td>Forma prawna działalności</td>
										 <td>Ulica</td>
										 <td>Numer budynku</td>
										 <td>Numer mieszkania lokalu</td>
										 <td>Miejscowosc</td>
										 <td>Kod pocztowy</td>
										 <td>Kraj</td>
										 <td>Telefon</td>
										 <td>Fax</td>
										 <td>Mail</td>
										 <td>A_ADM_COMPANY</td>
										 <td>A_CLASSIFIED</td>
										 <td>A_STATUS</td>
										 <td>A_STATUS_INFO</td>
										 <td>Dodano</td>
										 <td>L_APPOITMENT_USER</td>
										 <td>Podmiot dominujacy</td>
										 <td>Tytul dokumentu</td>
										 <td>ownCompany</td>
										 <td>uwagi</td>
									 </tr>
									 </thead>
									 <tbody id="body-kontrahenci">
									 </tbody></table>
									 </form>
				';

	return $view;
}

// tworzenie grupy kontrahentów
public function createKontrahenciGroupAjaxAction() {
	Response::sendTryCatchJson(array($this, 'createKontrahenciGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
}

public function createKontrahenciGroupAjax($args) {
	$nazwa = V::get('NAZWA', '', $args);
	// TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje

	$idGroup = DB::getPDO()->insert('BI_audit_ENERGA_KONTRAHENCI_GRUPY', [
		'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
		'A_RECORD_CREATE_DATE' => 'NOW()',
		'NAZWA' => $nazwa,
	]);

	return [
		'msg' => "Utworzona grupę {$idGroup}",
		'type' => "success",
		'body' => [
			'id' => $idGroup,
		]
	];
}



	// Dodanie do grupy filtra kontrahentów
	public function addKontrahenciToGroupAjaxAction() {
		// Response::sendTryCatchJson(array($this, 'addKontrahenciToGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
		Response::sendTryCatchJson(array($this, 'addKontrahenciToGroupAjax'));
	}
	public function addKontrahenciToGroupAjax($args) {
		$idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
		$kontrahenciIds = V::get('kontrahenciIds', [], $_REQUEST, 'array');

		// validate
		if (!$idGroup) throw new Exception("Nie wybrano grupa");
		if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");

		$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'ID_USER',
				'NAZWA',
			],
			// 'f_ID_USER' => User::getID()
		])->getItem($idGroup);
		if (!$group) throw new Exception("Grupa nie istnieje");
		if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");

		// $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
		$refGrupyToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY',
			'default_db__x3A__BI_audit_ENERGA_KONTRAHENCI:BI_audit_ENERGA_KONTRAHENCI');
		foreach ($kontrahenciIds as $kontrahentIds) {
			DB::getPDO()->insert($refGrupyToKontrahenci, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $kontrahentIds]);
		}

		return [
			'msg' => "Powiązano kontrahentów z grupą {$idGroup}",
			'type' => "success",
		];
	}


public function fetchGroupKontrahenciAjaxAction() {
	Response::sendTryCatchJson(array($this, 'fetchGroupKontrahenciAjax'));
}

public function fetchGroupKontrahenciAjax() {
// TODO: odkomentować jak zostanie dodana tabela default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY
	/*$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_KONTRAHENCI_GRUPY/BI_audit_ENERGA_KONTRAHENCI_GRUPY')->buildQuery([
		'cols' => [ // TODO:? propertyName = []
			'ID',
			'ID_USER',
			'NAZWA',
		],
		'f_ID_USER' => User::getID()
	])->getItem($idGroup);
	if (!$group) throw new Exception("Grupa nie istnieje");
	if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");

	$itemsKontrahenci = $query->getItems();

	$arrayGroupKontrahenci = array();
	foreach ($itemsKontrahenci as $key => $value) {
		$arrayGroupKontrahenci[$value['ID']] = $value['NAZWA'];
	}
*/
	//TODO: USUNAĆ listę grup wpisane na sztywno
	$arrayGroupKontrahenci = array();
	$arrayGroupKontrahenci[0]["ID"] = 1;
	$arrayGroupKontrahenci[0]["NAZWA"] = "Grupa 1";
	$arrayGroupKontrahenci[1]["ID"] = 2;
	$arrayGroupKontrahenci[1]["NAZWA"] = "Grupa 2";
	$arrayGroupKontrahenci[2]["ID"] = 3;
	$arrayGroupKontrahenci[2]["NAZWA"] = "Grupa 3";
	$arrayGroupKontrahenci[3]["ID"] = 4;
	$arrayGroupKontrahenci[3]["NAZWA"] = "Grupa 4";
	$arrayGroupKontrahenci[4]["ID"] = 5;
	$arrayGroupKontrahenci[4]["NAZWA"] = "Grupa 5";
	$arrayGroupKontrahenci[5]["ID"] = 6;
	$arrayGroupKontrahenci[5]["NAZWA"] = "Grupa 6";
	$arrayGroupKontrahenci[6]["ID"] = 7;
	$arrayGroupKontrahenci[6]["NAZWA"] = "Grupa 7";
	$arrayGroupKontrahenci[7]["ID"] = 8;
	$arrayGroupKontrahenci[7]["NAZWA"] = "Grupa 8";
	$arrayGroupKontrahenci[8]["ID"] = 9;
	$arrayGroupKontrahenci[8]["NAZWA"] = "Grupa 9";
	$arrayGroupKontrahenci[9]["ID"] = 10;
	$arrayGroupKontrahenci[9]["NAZWA"] = "Grupa 10";
	$arrayGroupKontrahenci[9]["ID"] = 11;
	$arrayGroupKontrahenci[9]["NAZWA"] = "Grupa 11";

	return [
		'type' => 'success',
		'msg' => 'fetchKontrahenciToGroup',
		'__req_args' => $_REQUEST,
		'__args' => $args,
		'body' => [
			'itemsGroupKontrahenci' => $arrayGroupKontrahenci
		]
	];
}


/*
 * PRACOWNICY
 */
	public function fetchPracownicyAjaxAction() {
		// sleep(2);
		Response::sendTryCatchJson(array($this, 'fetchPracownicyAjax'));
	}

	public function fetchPracownicyAjax($args) {

		$idGroup = V::get('filterIdGroup', 0, $_REQUEST, 'int'); // TODO: dla filtrów "Wysokiego ryzyka" - przekazywany ID rekodu
		if ($idGroup < 0) $idGroup = 0;

		$limit = 2;

		$limitstart = V::get('limitstart', 0, $_REQUEST, 'int');
		if ($limitstart < 0) $limitstart = 0;


		$page = V::get('page', 0, $_REQUEST, 'int');
		$limitstart = ($page - 1) * $limit;


		$search = V::get('search', '', $_REQUEST);
		$searchParams = [];
		if (!empty($search)) {
			$ogcSearch = "*{$search}*"; // wildCard="*" -> mysql '%'
			$searchParams['ogc:Filter'] = '
				<ogc:Filter>
			    <ogc:Or>
			      <ogc:PropertyIsLike wildCard="" singleChar="%23" escapeChar="!">
			        <ogc:PropertyName>nip</ogc:PropertyName>
			        <ogc:Literal>' . $ogcSearch . '</ogc:Literal>
			      </ogc:PropertyIsLike>
			      <ogc:PropertyIsLike wildCard="*" singleChar="%23" escapeChar="!">
			        <ogc:PropertyName>nazwisko</ogc:PropertyName>
							<ogc:Literal>' . $ogcSearch . '</ogc:Literal>
			      </ogc:PropertyIsLike>
			    </ogc:Or>
			  </ogc:Filter>
			';
		}

		$backRefFilter = [];
		if ($idGroup > 0) {
			$backRefFilter['__backRef'] = [
				'namespace' => 'default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY', // TODO: nowy rejetr na grupy / filty pracowników
				'primaryKey' => $idGroup,
				'fieldName' => 'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY',
			];
			// TODO: Storage dodać obiekt xsd default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY:
			// - ID
			// - ID_USER - id usera który stworzył grupę (tylko dla niego będzie widoczna)
			// - NAZWA - nazwa grupy
			// - 'default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY' minOccurs="0" maxOccurs="unbounded"
		}

		$acl = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY');
		$query = $acl->buildQuery(array_merge([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'imiona',
				'nazwisko',
				'nip',
				'pesel',
				'regon',
				'source',
				'A_ADM_COMPANY',
				'A_CLASSIFIED',
				'A_STATUS',
				'A_STATUS_INFO',
				'L_APPOITMENT_USER',
				'default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy:BI_audit_ENERGA_PRACOWNICY_adresy/*'
			],
			//'f_ID' => $id,
			'limit' => $limit,
			'limitstart' => $limitstart, // offset
			// 'order_by' => 'ID', // sortowanie po kolumnie
			// 'order_dir' => 'DESC', // kierunek sortowania
			// 'f_nip' = "=12345", // szukamy dokładnie tej wartości - mysql: where nip = "12345"
			// 'f_nip' = "12345", // szukamy dokładnie tej wartości - mysql: where nip like "%12345%"
			// 'f_nip' = "12345%", // szukamy dokładnie tej wartości - mysql: where nip like "12345%"
			// 'f_ID' = "=12345", // szukamy dokładnie tej wartości - mysql: where ID = "12345"
		], $searchParams, $backRefFilter));
		$total = $query->getTotal();
		$items = $query->getItems();

		$pagination = array();
		$pagination['total_items'] = $total;
		$pagination['size'] = ceil($total/$limit); // pages size
		$pagination['current'] = $page;
		$pagination['limit'] = $limit;

		// { // tworzenie własnego zapytanie mysql
		// 	$rootTableName = $acl->getRootTableName();
		// 	DB::getPDO()->fetchAll("
		// 		select t.*
		// 		from {$rootTableName} t
		// 		where t.ID in (
		// 			select x.ID
		// 			from ... x
		// 			where
		// 		)
		// 	");
		// }

		return [
			'type' => 'success',
			'msg' => 'showPracownicy',
			'__req_args' => $_REQUEST,
			'__args' => $args,
			'body' => [
				'items' => $items,
				//'view' => $this->htmlViewFormBiAudit($items, 'PRACOWNICY'),
				'pagination' => $pagination
			]
		];
	}



	public function showTablePracownicy() {
			$view = '<form class="form-horizontal" method="post">
							<table class="table table-responsive table-bordered table-hover table-striped" height=5>
										 <thead>
											 <tr>
											 		<td width=1><input type="checkbox" name="checkAll" id="checkAll-PRACOWNICY" /></td>
												 <td width=1>ID</td>
												 <td>Imię/Imiona</td>
												 <td>Nazwisko</td>
												 <td>NIP</td>
												 <td>Pesel</td>
												 <td>Regon</td>
												 <td>source</td>
												 <td>A_ADM_COMPANY</td>
												 <td>A_CLASSIFIED</td>
												 <td>A_STATUS</td>
												 <td>A_STATUS_INFO</td>
												 <td>L_APPOITMENT_USER</td>
												 <td>Adresy</td>
											 </tr>
										 </thead>
										 <tbody id="body-pracownicy">
										 </tbody></table>
										 </form>';

						return $view;

	}


	// tworzenie grupy pracowników
	public function createPracownicyGroupAjaxAction() {
		Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
		// Response::sendTryCatchJson(array($this, 'createPracownicyGroupAjax'));
	}
	public function createPracownicyGroupAjax($args) {
		$nazwa = V::get('NAZWA', '', $args);
		// TODO: vlaidacja nazwy - sprawdzenie czy już nie występuje

		// validate
		if (!$nazwa) throw new Exception("Nie wybrano grupa");
		if (!$kontrahenciIds || count($kontrahenciIds) == 0 ) throw new Exception("Proszę wybrać kontrahentów");

		$idGroup = DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_GRUPY', [
			'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
			'A_RECORD_CREATE_DATE' => 'NOW()',
			// 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
			'NAZWA' => $nazwa,
		]);
		// DB::getPDO()->insert('BI_audit_ENERGA_PRACOWNICY_GRUPY_HIST', [
		// 	'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
		// 	'A_RECORD_CREATE_DATE' => 'NOW()',
		// 	'ID_USERS2' => $idRaport,
		// 	// 'A_STATUS' => 'WAITING', // jeśli trzeba to ustawić
		// 	'NAZWA' => $nazwa,
		// ]);
		return [
			'msg' => "Utworzona grupę {$idGroup}",
			'type' => "success",
			'body' => [
				'id' => $idGroup,
			]
		];
	}

	// Dodanie do grupy filtra pracowników
	public function addPracownicyToGroupAjaxAction() {
		// Response::sendTryCatchJson(array($this, 'addPracownicyToGroupAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
		Response::sendTryCatchJson(array($this, 'addPracownicyToGroupAjax'));
	}
	public function addPracownicyToGroupAjax($args) {
		$idGroup = V::get('idGroup', 0, $_REQUEST, 'int');
		$pracownicyIds = V::get('pracownicyIds', [], $_REQUEST, 'array');

		// validate
		if (!$nazwa) throw new Exception("Nie wybrano grupa");
		if (!$pracownicyIds || count($pracownicyIds) == 0 ) throw new Exception("Proszę wybrać pracowników");

		// TODO: SPRWADZENIE  CZY NIE DODANOU JUZ PRACOWNIKAS
		// default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY
		// default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY

		$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'ID_USER',
				'NAZWA',
			],
			// 'f_ID_USER' => User::getID()
		])->getItem($idGroup);
		if (!$group) throw new Exception("Grupa nie istnieje");
		if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");

		// $refGrupyToPracownicy = ACL::getRefTable('obiekt główny', 'nazwa pola - powiązane rekordy');
		$refGrupyToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY',
			'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
		foreach ($pracownicyIds as $idPracownik) {
			DB::getPDO()->insert($refGrupyToPracownicy, ['PRIMARY_KEY' => $idGroup, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
		}

		return [
			'msg' => "Powiązano pracowników z grupą {$idGroup}",
			'type' => "success",
		];
	}


	public function fetchGroupPracownicyAjaxAction() {
		Response::sendTryCatchJson(array($this, 'fetchGroupPracownicyAjax'));
	}

	public function fetchGroupPracownicyAjax() {

// TODO: odkomentować jak zostanie dodana tabela default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY
		/*$group = ACL::getAclByNamespace('default_db/BI_audit_ENERGA_PRACOWNICY_GRUPY/BI_audit_ENERGA_PRACOWNICY_GRUPY')->buildQuery([
			'cols' => [ // TODO:? propertyName = []
				'ID',
				'ID_USER',
				'NAZWA',
			],
			'f_ID_USER' => User::getID()
		])->getItem($idGroup);
		if (!$group) throw new Exception("Grupa nie istnieje");
		if (User::getID() != $group['ID_USER']) throw new Exception("Brak uprawnień do grupy");

		$items = $query->getItems();

		$arrayGroupPracownicy = array();
		foreach ($items as $key => $value) {
			$arrayGroupPracownicy[$value['ID']] = $value['NAZWA'];
 		}
*/
		//TODO: USUNAĆ listę grup wpisane na sztywno
		$arrayGroupPracownicy = array();
		$arrayGroupPracownicy[0]["ID"] = 1;
		$arrayGroupPracownicy[0]["NAZWA"] = "Grupa 1";
		$arrayGroupPracownicy[1]["ID"] = 2;
		$arrayGroupPracownicy[1]["NAZWA"] = "Grupa 2";
		$arrayGroupPracownicy[2]["ID"] = 3;
		$arrayGroupPracownicy[2]["NAZWA"] = "Grupa 3";
		$arrayGroupPracownicy[3]["ID"] = 4;
		$arrayGroupPracownicy[3]["NAZWA"] = "Grupa 4";
		$arrayGroupPracownicy[4]["ID"] = 5;
		$arrayGroupPracownicy[4]["NAZWA"] = "Grupa 5";


		return [
			'type' => 'success',
			'msg' => 'fetchGroupPracownicyAjax',
			'__req_args' => $_REQUEST,
			'__args' => $args,
			'body' => [
				'itmesGroupPracownicy' => $arrayGroupPracownicy
			]
		];
	}


	// link do ackji w php: $saveFormUrl = $this->getLink('saveRaportAjax');
	// przekazać link do JavaScript i tam:
	// window.fetch('{$saveFormUrl}', { ... }).then(...) - dokumentacja: https://github.com/github/fetch
	public function generateBiAuditRaportAjaxAction() {
		 //Response::sendTryCatchJson(array($this, 'saveRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // użyj tej wersji jeśli chcesz wysyłać z przelgądarki JSON-a post-em
		Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'), $args = 'JSON_FROM_REQUEST_BODY');
		//Response::sendTryCatchJson(array($this, 'generateBiAuditRaportAjax'));
	}
	public function generateBiAuditRaportAjax($args) {

		// głebokość powiazan
		$depthValue = V::get('depthValue', '', $args);
		if (!$depthValue) {
			throw new Exception("Nie podano wartości dla głębokości powiązań");
		}

		// Tworzenie relacji Raport do Pracownicy
		$pracownicyIds = []; // array z nr ID na podstawie wysłanego formularza
		$pracownicyIds = V::get('pracownicyIds', '', $args);
		// walidacja id pracowników
		if (!$pracownicyIds) {
			throw new Exception("Nie wybrano pracowników");
		}

		$kontrahenciIds = []; // array z nr ID na podstawie wysłanego formularza
		$kontrahenciIds = V::get('kontrahenciIds', '', $args);
		// walidacja id kontrahetów
		if (!$kontrahenciIds) {
			throw new Exception("Nie wybrano kontrahentów");
		}

		// Tworzenie rekrodu w bazie - Raport -
		$idRaport = DB::getPDO()->insert('BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA', [
			'A_RECORD_CREATE_AUTHOR' => User::getLogin(),
			'A_RECORD_CREATE_DATE' => 'NOW()',
			 'A_STATUS' => 'WAITING', // TODO: czy  trzeba to ustawić (pytanie do Mariusza)
			 'FILE_STATUS' => "TO_GENERATE",
			 'BI_analiza_minDepth' => 1,
			 'BI_analiza_maxDepth' => $depthValue
		]);


		// Tworzenie relacji Raport do Pracownicy
		$refPowiazaniaToPracownicy = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
			'default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY');
		foreach ($pracownicyIds as $idPracownik) {
			DB::getPDO()->insert($refPowiazaniaToPracownicy, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idPracownik]);
		}


		// Tworzenie relacji Raport do Kontrahenci - analogicznie jak wyżej
		$refPowiazaniaToKontrahenci = ACL::getRefTable('default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
			'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI');
		foreach ($kontrahenciIds as $idKontrahent) {
			DB::getPDO()->insert($refPowiazaniaToKontrahenci, ['PRIMARY_KEY' => $idRaport, 'REMOTE_PRIMARY_KEY' => $idKontrahent ]);
		}

		// ...

		return [
			'msg' => "Zadanie do wygnerowania raportu zostało zapisane.",
			'type' => "success",
			'body' => [
				'id' => $idRaport,
			]
		];
	}


		/**
		* Widok formularza dodawania pracowników i kontrahentów
		*/
		public function defaultViewFormBiAudit($items, $type) {

	$activeFormSteps = '';

		switch($type) {
				case 'KONTRAHENCI':
					$activeFormStepsKontrahent = 'complete';
					$titleHeader = 'KONTRAHENCI';
					$groupFilterList = '
					<div class="menu-item">
							<ul class="padding-0">
									<li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupKontrahenci(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
							</ul>
					</div>
					<div id="group-kontrahenci" class="btn-group">
							<button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
					</div>';
					$showButtonNextStep = '<button type="button" class="btn btn-primary" onClick="generateBiAuditRaport(event)" id="button-generate-reaport">SZUKAJ POWIĄZAŃ</button>';
					$pagination_form = '<div id="pagination-kontrahenci"></div>';
				break;

				case 'PRACOWNICY':
					$titleHeader = 'PRACOWNICY';
					$groupFilterList = '
					<div class="menu-item">
							<ul class="padding-0">
									<li><a href="#" title="STWÓRZ GRUPĘ" class="btn btn-default" onClick="createGroupPracownicy(event)" data-color-noactive="">+ STWÓRZ GRUPĘ</a></li>
							</ul>
					</div>
					<div id="group-pracownicy" class="btn-group">
							<button class="btn btn-default active" title="Wszyscy" data-group-filter="0">Wszyscy</button>
					</div>';
					$showButtonNextStep = '<a href="index.php?_route=UrlAction_BiAuditRaport#KONTRAHENCI"  title="DODAJ DO ANALIZY" class="btn btn-primary">DODAJ DO ANALIZY</a>';
					$pagination_form = '<div id="pagination-pracownicy"></div>';

					break;
		}


			$view = '
			<!-- start:employees-section-->
			<div id="smad-employees-section" class="smad-form-' . $type . '" >
				<div class="container-fluid">
					<div>
							<div class="padding-lr-0">
									<div id="smad-menu-section">
											<div class="col-sm-12 col-md-6 padding-lr-0">
													<div class="menu-items">
															<div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> ' . $titleHeader . ' </div>
													</div>
											</div>
											<div class="col-sm-12 col-md-6 padding-lr-0">
													<div class="form-steps">
															<!-- start:form steps wizard -->
															<div class="row smad-wizard" style="border-bottom:0;">
																	<div class="col-xs-4 col-md-4 smad-wizard-step complete"><!-- complited line -->
																			<div class="text-center smad-wizard-stepnum">&nbsp;</div>
																			<div class="progress"><div class="progress-bar"></div></div>
																			<a href="https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_BiAuditRaport#PRACOWNICY" class="smad-wizard-dot"></a>
																			<div class="smad-wizard-info complete text-center">
																					<div class="step-item">Krok 1</div>
																					<div class="step-title ">PRACOWNICY</div>
																			</div>
																	</div>

																	<div class="col-xs-4 col-md-4 smad-wizard-step ' . $activeFormStepsKontrahent . ' ">
																			<div class="text-center smad-wizard-stepnum">&nbsp;</div>
																			<div class="progress"><div class="progress-bar"></div></div>
																			<a href="https://bravecom.yellowgroup.pl/SE/index.php?_route=UrlAction_BiAuditRaport#KONTRAHENCI" class="smad-wizard-dot"></a>
																			<div class="smad-wizard-info  text-center">
																					<div class="step-item">Krok 2</div>
																					<div class="step-title ">KONTRAHENCI</div>
																			</div>
																	</div>

																	<div class="col-xs-4 col-md-4 smad-wizard-step ">
																			<div class="text-center smad-wizard-stepnum">&nbsp;</div>
																			<div class="progress"><div class="progress-bar"></div></div>
																			<a href="#" class="smad-wizard-dot"></a>
																			<div class="smad-wizard-info  text-center">
																					<div class="step-item">Krok 3</div>
																					<div class="step-title ">SZUKANIE POWIĄZAŃ</div>
																			</div>
																	</div>
															</div>
															<!-- end:form steps wizard -->
													</div>
											</div>
									</div>
							</div>
					</div>
			</div>

			<div class="container-fluid">
					<div class=" padding-lr-0">
							<div class="smad-divider"></div>
					</div>
			</div>
			<!-- start:filters -->
			<div class="container-fluid">
					<div class="row">
							<div>
									<div class="smad-employees-form-section" class="border-top-grey">
											<div class="col-md-9 smad-border-col">
													<div class="menu-items">
														'.$groupFilterList.'
														</div>
											</div>
											<div class="col-md-3">
													<div class="form-input">
															<div class="form-item col-md-6 smad-heder-title">głębokość powiązań:</div>
															<div class="form-item col-md-6">
																	<input type="text" class="form-control smad-depth" placeholder="1-16" value="" />
															</div>
													</div>
											</div>
									</div>
							</div>
					</div>
			</div>
			<!-- end:filters -->

			<!-- start:list employees -->
			<div class="container-fluid">

							<div class="padding-0 smad-employees-list-head">
									<div class="col-md-6">
											<header>
													<h2 class="title">Wszyscy</h2>
											</header>
											<div class="desc">
													Lorem Ipsum jest tekstem stosowanym jako przykładowy wypełniacz w przemyśle poligraficznym.
											</div>
									</div>
									<div class="col-md-6">
											<div class="menu-items">
													<div class="menu-item">
															<ul class="padding-0">
																	<li><a href="#" title="IMPORT PRACOWNIKÓW" class="btn btn-info data-color-noactive="">IMPORT PRACOWNIKÓW</a></li>
																	<li><a href="#" title="DODAJ PRACOWNIKÓW" class="btn btn-info" data-color-noactive="">+ DODAJ PRACOWNIKÓW</a></li>
															</ul>
													</div>
											</div>
									</div>
							</div>

			</div>
			<div class="container-fluid">
					<div class="table-responsive padding-0" id="smad-table-' . $type . '">
							' . $this->showListDataByType($items, $type) . '
					</div>
			</div>
			<!-- end:list employees -->
			<!-- start:list paginations employees -->
			<div class="container-fluid ">
				<div>
					'. $pagination_form .'
				</div>
			</div>
			<!-- end:list paginations employees -->

			<!-- start:bottom buttons -->
			<div class="container-fluid smad-employees-bottom-navigation">
					<div class="padding-0">
							<div class="col-lg-6 ">
									<a href="#" title="PRZENIEŚ DO GRUPY" onClick="addPracownikToGroup(event)" class="btn btn-info">PRZENIEŚ DO GRUPY</a>
							</div>
							<div class="col-lg-6 text-right">
									' . $showButtonNextStep . '
							</div>
					</div>
			</div>
			<!-- end:bottom buttons -->
	</div>
	<!-- start:employees-section -->
			';
			return $view;
		}


	public function showListDataByType($items, $type='PRACOWNICY') {

			switch ($type) {
				case 'PRACOWNICY':
					return $this->showTablePracownicy();
					break;
				case 'KONTRAHENCI':
					return $this->showTableKontrahenci($items);
					break;
			}
	}




	/**
	* Raport - wyświetlenie danych zwiazanych z raportem
	*/
	public function showViewTreeReaport($type) {
		$view = '';

		$view = '
			<!-- start:reaport-section-->
<div id="smad-reaport-section">
    <div class="container-fluid">
        <div>
            <div id="smad-menu-section">
                <div class="col-sm-12 col-md-8 padding-lr-0 padding-top-bottom-25">
                    <div class="menu-items">
                        <div class="smad-heder-title menu-item"><span class="smad-line-red">|</span> RAPORT</div>
                    </div>
                </div>
                <div class="col-sm-12 col-md-4 padding-lr-0  padding-top-bottom-25">
                    <div class="form-steps">
                        <!-- start:form list raports -->
                        <div class="form-group">
                            <label class="control-label col-md-5" for="reaport-item">Wybierz raport</label>
                            <div class="col-md-7">
                                <select id="reaport-item" class="form-control">
                                    <option><a href="#">Raport 1</a></option>
                                    <option><a href="#">Raport 2</a></option>
                                    <option><a href="#">Raport 3</a></option>
                                    <option><a href="#">Raport 4</a></option>
                                </select>
                            </div>
                        </div>
                        <!-- end:form list raports -->
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- start:list employees -->
    <div class="container-fluid">
        <div class="padding-0 smad-form-list-head">
            <div class="col-md-6">
                <header>
                    <h2 class="title">Wszyscy</h2>
                </header>
                <div class="desc">
                    Lorem Ipsum jest tekstem stosowanym jako przykładowy wypełniacz w przemyśle poligraficznym.
                </div>
            </div>
            <div class="col-md-6">

            </div>
        </div>
    </div>
    <div class="container-fluid">
        <div id="body-reaport-kontrahenci-powiazani-tree">

        </div>
        <div id="body-reaport-kontrahenci-powiazani-content">

        </div>
    </div>
    <!-- end:list employees -->

    <!-- start:bottom buttons -->
    <div class="container-fluid smad-employees-bottom-navigation">

        <div class="col-sm-12 col-md-12 col-md-1 padding-lr-0 col-lg-12 padding-top-bottom-25">

                <!-- start:form list raports -->
                <div class="form-group">
                    <div class="col-md-7 col-lg-8"></div>
                    <div class="col-md-3 col-lg-2">
                        <select id="reaport-item-merge" class="form-control">
                            <option><a href="#">Raport 1</a></option>
                            <option><a href="#">Raport 2</a></option>
                            <option><a href="#">Raport 3</a></option>
                            <option><a href="#">Raport 4</a></option>
                        </select>
                    </div>
                    <div class="col-md-2 col-lg-2">
                        <a href="#" title="DODAJ DO RAPORTU" class="btn btn-default">DODAJ DO RAPORTU</a>
                    </div>
                </div>
                <!-- end:form list raports -->

        </div>

    </div>
    <!-- end:bottom buttons -->
</div>
<!-- start:reaport-section -->
					';

					return $view;
				}

			}