<?php
class MYPDF extends TCPDF {
    public function Footer() {
        $this->SetY(-10);
        $this->SetFont('helvetica', 'N', 7);
        $this->Cell(0, 15, "Oprogramowanie dostarcza: www.technix.pl", 0, false, 'L', 0, '', 0, false, 'T', 'M');
        $this->Cell(0, 15, 'Strona '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
    }
}

class EmployeeController extends Zend_Controller_Action {








			
			
		
	function generatepdf($save = false){
	
		$db = Zend_Registry::get('db');		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		$this->_helper->viewRenderer->setNoRender();
		
		$config_colspan = 2;
		$config_button = 6;
		$config_note_width = 120;
		
		
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$Employee = new Employee();	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = null;
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";
	
	
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
		if( $searchData != '' ) $select->where($searchData);
		if( $searchProject != '' ) $select->where($searchProject);
		$select->where($searchEmployee);					
		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$dataTable = $stmt->fetchAll();	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$employeeData = $Employee->fetchRow($select);
		
		
		
		
		
		
		
		
		
		
		
		
		$html = '
		<h4 style="font-size: x-large;">'.$employeeData['employee_firstname'].' '.$employeeData['employee_secondname'].'</h4>
		';
		
		
		




		 if( $v['employee_settlement_date_start'] OR $v['employee_settlement_date_stop'] ){ 

		$html = $html.'<h5 style="font-size: large;">'.@LANG_header_title_printdate; 
			
		 if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - '. Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");
			
		 }elseif( $v['employee_settlement_date_start'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - ...';

		 }elseif( $v['employee_settlement_date_stop'] ){ 

			$html = $html.'... -  '.Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");

		 } 
			
		$html = $html.'</h5>';


		 } 
		
		
		
		if( $v['project_id'] != 'all' ){ 
		
		$config_colspan = 1; 
		$config_button = 6; 	
		$config_note_width = 380;	
		
			$html = $html.'<h5 style="font-size: large;">'.$dataTable[0]['company_name'].' / '.$dataTable[0]['project_name'].'</h5>';
		
		}
		
		
		
		
		
		
		
		
		
		
		$html = $html.'
<table border="1" cellpadding="5" cellspacing="0">
	<thead>
		<tr style="font-weight: bold;">
			<th width="30">'.@LANG_employee_settlement_list_lp.'</th>
			<th width="70">'.@LANG_employee_settlement_list_date.'</th>
			<th width="80">'.@LANG_employee_settlement_list_ss.'</th>
			<th width="60">'.@LANG_employee_settlement_list_time.'</th>		
			<th width="80">'.(($v['rate'])?@LANG_employee_settlement_list_rate:"").'</th>
		
		';
		
		
		
		if( $v['project_id'] == 'all' ){
		
		
		$html = $html.'
			<th width="260">'.@LANG_employee_settlement_list_compro.'</th>
		';
		
		
		
		}
		
		
		
		$html = $html.'


			<th width="'.$config_note_width.'">'.@LANG_employee_settlement_list_note.'</th>		
		</tr>
	</thead>
	<tbody>
		';
		
		

	$i=0; 
	$sumt = 0; 
	$sumAll = 0;
	foreach ($dataTable as $key => $val){ 
		$i=$i+1;

		$timeVar = Lib_Date::convertDate($val['employee_settlement_time'],'H:i:s','H:i'); 
		$tr = explode(":",$timeVar);
		$sumt = $sumt + $tr[0]*60 + $tr[1];
		
		$stylebg = '';
		if( $val['employee_settlement_datecount'] > 1 ) $stylebg = ' bgcolor="#f6cece"';
		
		$tV = explode(":",$timeVar);
		$rateSum = number_format($tV[0]*$val['employee_settlement_rate'] + $tV[1]*$val['employee_settlement_rate']/60, 2, ',', ' ');
		
		$sumAll = $sumAll + number_format($tV[0]*$val['employee_settlement_rate'] + $tV[1]*$val['employee_settlement_rate']/60, 2);
		
		$html = $html.'
		<tr '.$stylebg.'>
			<td width="30">'.$i.'</td>
			<td width="70">'.Lib_Date::convertDate($val['employee_settlement_date']).'</td>
			<td width="80">
				'.Lib_Date::convertDate($val['employee_settlement_start'],'H:i:s','H:i').'
				-
				'.Lib_Date::convertDate($val['employee_settlement_stop'],'H:i:s','H:i').'
			</td>
			<td width="60">'.$timeVar.'
			</td>
			<td width="80">'.(($v['rate'])?number_format($val['employee_settlement_rate'], 2, ',', ' ').' &euro;<br />'.@LANG_employee_settlement_list_ratesum.' '.$rateSum.' &euro;':"").'
			</td>
		';
		
		
		if( $v['project_id'] == 'all' ){			
			$html = $html.'<td width="260">'.$val['company_name'].' / '.$val['project_name'].'</td>';
		}
		
		
		$html = $html.'
			<td width="'.$config_note_width.'">'.$val['employee_settlement_note'].'</td>
		</tr>
		';
		
	}
	
	
	

		
		$html = $html.'	
		<tr>
			<td align="right" colspan="3" bgcolor="#cef6ce">'.@LANG_employee_settlement_sum.' / '.@LANG_employee_settlement_sumrate.'</td>
			<td>
			'.Lib_Date::convertToHoursMins($sumt).'
			</td>
			<td>
			<span color="#aaa">'.(($v['sum'])?number_format($sumAll, 2, ',', ' ').' &euro;':"").'</span><br />
			'.(($v['sum'])?number_format(Lib_Data::roundSpecialPrice($sumAll), 2, ',', ' ').' &euro;':"").'
			</td>
			<td colspan="'.$config_colspan.'">
			</td>
		</tr>
		';	
	
	

	/*	
		$html = $html.'	
		<tr>
			<td align="right" colspan="3" bgcolor="#cef6ce">'.@LANG_employee_settlement_avg.' / '.@LANG_employee_settlement_avgrate.'</td>
			<td>
			'.Lib_Date::convertToHoursMins(round($sumt/$i)).'
			</td>
			<td>
			'.number_format($sumAll/$i, 2, ',', ' ').' &euro;
			</td>
			<td colspan="'.$config_colspan.'">
			</td>
		</tr>
		';	
	*/
	

	
		
		
		$html = $html.'

	</tbody>
</table>
		';
		
		
		
		
		
		
		
		
		
		
		
		
		
		
			
			$name = mb_strtolower($employeeData['employee_firstname'].' '.$employeeData['employee_secondname'], 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
			$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			
			// set document information
			$pdf->SetCreator(PDF_CREATOR);
			$pdf->SetAuthor('www.TECHNIX.pl');
			$pdf->SetTitle($nameFile);
			$pdf->SetSubject($nameFile);
			$pdf->SetKeywords($nameFile);
			$pdf->setPrintHeader(false);
			
			// set default header data
			$pdf->setFooterData(array(0,64,0), array(0,64,128));

			// set header and footer fonts
			$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

			// set default monospaced font
			$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

			// set margins
			$pdf->SetMargins(5, 5, 5);

			// set auto page breaks
			$pdf->SetAutoPageBreak(TRUE, 0);

			// set image scale factor
			$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

			// ---------------------------------------------------------

			// set default font subsetting mode
			$pdf->setFontSubsetting(true);

			// Set font
			// dejavusans is a UTF-8 Unicode font, if you only need to
			// print standard ASCII chars, you can use core fonts like
			// helvetica or times to reduce file size.
			$pdf->SetFont('dejavusans', '', 7, '', true);

			// Add a page
			// This method has several options, check the source code documentation for more information.
			$pdf->AddPage();
			
			
			
			
			$pdf->writeHTML($html, true, 0, true, true);
			
			ob_end_clean();
			if( $save == false ) $pdf->Output($nameFile.'.pdf', 'I');
			else{
				$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
				$pdf->Output($file, 'F');
				return $file;
			}

		
	}





	
	
	

		
		
		
		
		
		
		
		
		
		
		
			
			
		
	function generateindexpdf($save = false){	
		$this->_helper->viewRenderer->setNoRender();
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		$db = Zend_Registry::get('db');		
				
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		$searchEmployeeName = null;
		
		// filtr nazwa pracownika - poczatek		
		if( $filtremployee->employee_name ){	
			$filtremployee->employee_name = str_replace("\\",'',$filtremployee->employee_name);
			
			$searchEmployee = explode(" ",$filtremployee->employee_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa pracownika - koniec
		// ==========================================================
		
		if( $filtremployee->employee_status ){
			$status = $filtremployee->employee_status - 1;
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName.' AND employee_activ='.$status;
			else $searchEmployeeName = 'employee_activ='.$status;
		}
		
		
		
		
		
		if( $filtremployee->filtr_alert ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			
		}
		
		
		if( $filtremployee->filtr_clarify ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			
		}
		
		
		if( $filtremployee->filtr_notice ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND employee_note NOT LIKE ''";
			else $searchEmployeeName = "employee_note NOT LIKE ''";
		}
		
		
		if( $filtremployee->filtr_newemp ){
		
			// AND DATE_ADD(CURDATE(), INTERVAL -30 DAY) < employee_date
			// if( $_GET['ask'] == true ) echo$ask;
			
			
			if( $filtremployee->filtr_newempval == 31 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
				else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
			
			}
			
			
			if( $filtremployee->filtr_newempval == 61 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
				else $searchEmployeeName = "(DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
			
			}
		}
		
		
		
		if( $filtremployee->filtr_noworkemp ){	
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";
			else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";

		}
		
		
		
		if( $filtremployee->filtr_nh ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
			else $searchEmployeeName = "(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
		}
		
		
		
		if( $filtremployee->filtr_employeegroup_id ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
			else $searchEmployeeName = "(SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
		}
		
		
		
		if( $filtremployee->filtr_residence_date_start ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		if( $filtremployee->filtr_residence_date_stop ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		// opcje dodatkowe - zapytanie - początek
		
		if( $filtremployee->filtr_option_order ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '0' )";
			}else{
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = "( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = "( e.employee_activ_order = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order2 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '0' )";
			}else{
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = "( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = "( e.employee_activ_order2 = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order3 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '0' )";
			}else{
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = "( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = "( e.employee_activ_analysis = '0' )";
			}
		}
		
		if( $filtremployee->filtr_employee_check ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '0' )";
			}else{
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = "( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = "( e.employee_check = '0' )";
			}
		}
		
		// opcje dodatkowe - zapytanie - koniec
		
		
		$search = '';
		if( $searchEmployeeName != null ){
			$search = ' WHERE '.$searchEmployeeName;
		}
			
		$order = " ORDER BY employee_secondname ASC, employee_firstname ASC";
			
		$ask = "SELECT 
			*, 
			(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
				
			(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

			(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
			WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

			(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR  
				
			FROM `employee` e  LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id ".$search.$order;	
			
			
		$dataTable = $db->query($ask)->fetchAll();		

		
		
		
		$pxTab = array(30,200,70,200,100,100);
		
		$html = $html.'
<table border="1" cellpadding="5" cellspacing="0">
	<thead>
		<tr style="font-weight: bold;">
			<th width="'.$pxTab[0].'">'.@LANG_employee_list_lp.'</th>
			<th width="'.$pxTab[1].'">'.@LANG_employee_list_name.'</th>
			<th width="'.$pxTab[2].'">'.@LANG_employee_list_status.'</th>
			<th width="'.$pxTab[3].'">'.@LANG_employee_list_residence.'</th>		
			<th width="'.$pxTab[4].'">'.@LANG_employee_list_residence_start.'</th>		
			<th width="'.$pxTab[5].'">'.@LANG_employee_list_residence_stop.'</th>	
		</tr>
	</thead>
	<tbody>
		';
		
	foreach ($dataTable as $key => $val){ 
		$i=$i+1;

		$dataEmployeeGroupEAll = Lib_Employee::EmployeeGroupEAll($val['employee_id'],'employeegroup.employeegroup_type_id = 2');
		$emgr = '';
		foreach($dataEmployeeGroupEAll as $k1 => $v1){								
			$emgr = $emgr.$v1['employeegroup_name'].', ';
		}
		
		if( $val['employee_residence_date_start'] == '0000-00-00' ){
			$d1 = '-';
		}else{
			$d1 = Lib_Date::convertDate($val['employee_residence_date_start'],"Y-m-d","d-m-Y");
		}
		
		if( $val['employee_residence_date_stop'] == '0000-00-00' ){
			$d2 = '-';
		}else{
			$d2 = Lib_Date::convertDate($val['employee_residence_date_stop'],"Y-m-d","d-m-Y");
		}
		
		
		$html = $html.'
		<tr>
			<td width="'.$pxTab[0].'">'.$i.'.</td>
			<td width="'.$pxTab[1].'">'.$val['employee_secondname'].' '.$val['employee_firstname'].'</td>
			<td width="'.$pxTab[2].'">'.(($val['employee_activ']==0)?@LANG_employee_list_status0:@LANG_employee_list_status1).'</td>
			<td width="'.$pxTab[3].'">'.$emgr.'</td>		
			<td width="'.$pxTab[4].'">'.$d1.'</td>		
			<td width="'.$pxTab[5].'">'.$d2.'</td>	
		</tr>
		';
	}
		
		
		$html = $html.'
	</tbody>
</table>
		';
		
		
		
			$name = mb_strtolower (@LANG_header_title_pdf, 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
			$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			
			// set document information
			$pdf->SetCreator(PDF_CREATOR);
			$pdf->SetAuthor('www.TECHNIX.pl');
			$pdf->SetTitle($nameFile);
			$pdf->SetSubject($nameFile);
			$pdf->SetKeywords($nameFile);
			$pdf->setPrintHeader(false);
			
			// set default header data
			$pdf->setFooterData(array(0,64,0), array(0,64,128));

			// set header and footer fonts
			$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

			// set default monospaced font
			$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

			// set margins
			$pdf->SetMargins(5, 5, 5);

			// set auto page breaks
			$pdf->SetAutoPageBreak(TRUE, 5);

			// set image scale factor
			$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

			// ---------------------------------------------------------

			// set default font subsetting mode
			$pdf->setFontSubsetting(true);

			// Set font
			// dejavusans is a UTF-8 Unicode font, if you only need to
			// print standard ASCII chars, you can use core fonts like
			// helvetica or times to reduce file size.
			$pdf->SetFont('dejavusans', '', 7, '', true);

			// Add a page
			// This method has several options, check the source code documentation for more information.
			$pdf->AddPage();
			
			
			
			
			$pdf->writeHTML($html, true, 0, true, true);
			
			ob_end_clean();
			if( $save == false ){
				$pdf->Output($nameFile.'.pdf', 'I');
			}else{
				$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
				$pdf->Output($file, 'F');
				return $file;
			}

		
	}	
	
	
	
	
	
	
	
	
	

	function generateprojectsummarypdf($save = false){
	
		$db = Zend_Registry::get('db');		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		$this->_helper->viewRenderer->setNoRender();
				
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Project = new Project();	
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);	
		$projectData = $Project->fetchRow($select);
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}	
	
		$search = 'AND employee_settlement.project_id = '.$v['id'];
		
		$order = "employee_plwgroup, employee_secondname, employee_firstname";
		
		if( $v['filtr_split'] == 2 ){
		
			$order = "
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		if( $v['filtr_split'] == 3 ){
		
			$order = "
				ISNULL(groupcompany_name), 
				groupcompany_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		/*
		$ask = "
			SELECT * FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id WHERE employee_settlement.employee_id = e.employee_id $search $searchData GROUP BY employee_settlement.employee_id ORDER BY $order
		";
		*/
		$ask = "
			SELECT 
			
			*,
			(
				SELECT GROUP_CONCAT(employeegroup.employeegroup_name ORDER BY employeegroup.employeegroup_name ASC SEPARATOR \", \") FROM 
				employee_employeegroup, employeegroup, employeegroup_type 
				WHERE
				employeegroup.employeegroup_type_id = employeegroup_type.employeegroup_type_id
				AND
				employee_employeegroup.employeegroup_id = employeegroup.employeegroup_id
				AND
				employeegroup.employeegroup_type_id = 3
				AND
				employee_employeegroup.employee_id = e.employee_id
			) AS groupcompany_name
			
			FROM 
			employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id 
			WHERE 
			employee_settlement.employee_id = e.employee_id 
			$search 
			$searchData 
			GROUP BY 
			employee_settlement.employee_id 
			ORDER BY $order
		";
		$data = $db->query($ask)->fetchAll();	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		$company = Lib_Project::CompanyName($projectData['company_id']);
		
		$html = '
		<h4 style="font-size: x-large;">'.$company['company_name'].' / '.$projectData['project_name'].'</h4>
		';
		
		
		if( $projectData['project_nr'] != '' ){
			$html = $html.@LANG_project_list_nrproj.' '.$projectData['project_nr'].', '; 
		}

		
		
					if( $projectData['project_date_start'] != '0000-00-00' OR $projectData['project_date_stop'] != '0000-00-00' ){
					
						$html = $html.''.@LANG_project_list_date_a.' ';	
						
						if( $projectData['project_date_start'] != '0000-00-00' ){
							$html = $html. Lib_Date::convertDate($projectData['project_date_start']).' - ';
						}else{
							$html = $html. '... - ';
						}
						
						if( $projectData['project_date_stop'] != '0000-00-00' ){
							$html = $html. Lib_Date::convertDate($projectData['project_date_stop']);
						}else{
							$html = $html. '...';
						}
					
						$html = $html.', ';
					}
		
		
		if( $projectData['project_employee_name'] != '' ){
			$html = $html.@LANG_project_list_emp.' '.$projectData['project_employee_name'].', '; 
		}
		
		

		
		$html = $html.'<br />';

				
					$rowPro = Lib_Employee::Project($projectData['project_id']);
				
					if( $projectData['project_m2'] != -1 ){
						$html = $html.@LANG_project_list_m2_a.'&nbsp;<b>'.number_format($projectData['project_m2'], 0, ',', '&nbsp;').'&nbsp;m<sup>2</sup></b>, ';
					}else{
						
					}
					
					if( $projectData['project_h'] != -1 ){
						$html = $html.''.@LANG_project_list_h_a.'&nbsp;<b>'.number_format($projectData['project_h'], 0, ',', '&nbsp;').'</b>, ';
					}else{
						
					}
					
					if( $projectData['project_h'] != -1 OR $rowPro > 0 ){
						$class = 'green';
					
						if( $projectData['project_h'] != -1 AND $rowPro > $projectData['project_h'] ){
							$class="red";
						}
					
						$html = $html.''.@LANG_project_list_m2_b.'&nbsp;<b color="'.$class.'">'.number_format($rowPro, 1, ',', '&nbsp;').'</b>, ';
					
						if( $projectData['project_h'] != -1 ){
						
							$roz = $projectData['project_h'] - $rowPro;
						
							$html = $html.''.@LANG_project_list_m2_c.'&nbsp;<b color="'.$class.'">'.number_format($roz, 1, ',', '&nbsp;').'</b>, ';
						}
					}
		
		
		


		 if( $v['employee_settlement_date_start'] OR $v['employee_settlement_date_stop'] ){ 

		$html = $html.'<h5 style="font-size: large;">'.@LANG_header_title_printdate; 
			
		 if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - '. Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");
			
		 }elseif( $v['employee_settlement_date_start'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - ...';

		 }elseif( $v['employee_settlement_date_stop'] ){ 

			$html = $html.'... -  '.Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");

		 } 
			
		$html = $html.'</h5>';


		 } 
		
		
		
		
		$html = $html.'<br /><br />';
		

	$pxTab = array(30,300,90,120,120);
		
		
		
		$html = $html.'
<table border="1" cellpadding="5" cellspacing="0">
	<thead>
		<tr style="font-weight: bold;">
			<th width="'.$pxTab[0].'">'.@LANG_employee_summary_lp.'</th>
			<th width="'.$pxTab[1].'">'.@LANG_employee_summary_name.'</th>
			<th width="'.$pxTab[2].'">'.@LANG_employee_summary_time.'</th>
			<th width="'.$pxTab[3].'">'.(($v['rate'])?@LANG_employee_summary_rate:"").'</th>
			<th width="'.$pxTab[4].'">'.(($v['rate'])?@LANG_employee_summary_rsum:"").'</th>
		</tr>
	</thead>
	<tbody>
		';		

$colspan = 5;
$nnn = '';		
		

	$i = 0;
	$sumh = 0;
	$rek = 0;
	$sumEur = 0;
	
	$sumhTeam = 0;
	$sumEurTeam = 0;
	
	foreach ($data as $key => $val): $i++;
	
	if( $rek == 0 AND $val['employee_plwgroup'] == 1 AND $v['filtr_split'] == 1 ){
		$class = ' style="border:1px solid #000;border-top:5px;border-top-color:red;"';
		
	/*	$html = $html.'
		<tr>
			<td colspan="5"'.$class.'></td>
		</tr>
		';*/
	}else{
		$class = '';
	}		
	
	
	
	/*
	if( $nnn != $val['employeeteam_name'] ){
		$vteam = 1;
		$nnn = $val['employeeteam_name'];
	}else $vteam = 0;	
	*/
	
	if( $v['filtr_split'] == 2 ){
		if( $nnn != $val['employeeteam_name'] ){
			$vteam = 1;
			$nnn = $val['employeeteam_name'];
		}else $vteam = 0;
	}
	
	if( $v['filtr_split'] == 3 ){
		if( $nnn != $val['groupcompany_name'] ){
			$vteam = 1;
			$nnn = $val['groupcompany_name'];
		}else $vteam = 0;
	}




	if( $vteam == 1 AND ( $v['filtr_split'] == 2 OR $v['filtr_split'] == 3 ) ){
	
	
	
		if( $i != 1 ){
	 
		$pxTab2 = $pxTab[0]+$pxTab[1];
	 
		if( $v['filtr_split'] == 2 ){
			$html = $html.'
	<tr>	
		<td colspan="2" width="'.$pxTab2.'" align="right">'.@LANG_employee_summary_sumTeam.'</td>
		<td width="'.$pxTab[2].'">
			'.$sumhTeam.'h
		</td>	
		
		<td width="'.$pxTab[3].'" align="right">'.(($v['rate'])?@LANG_employee_summary_sum2Team:"").'</td>
		<td width="'.$pxTab[4].'">'.(($v['rate'])?number_format($sumEurTeam, 2, ',', ' ').'&euro;':"").'</td>	
	</tr>	
			';
		}
	 
		if( $v['filtr_split'] == 3 ){
			$html = $html.'
	<tr>	
		<td colspan="2" width="'.$pxTab2.'" align="right">'.@LANG_employee_summarycompany_sumTeam.'</td>
		<td width="'.$pxTab[2].'">
			'.$sumhTeam.'h
		</td>	
		
		<td width="'.$pxTab[3].'" align="right">'.(($v['rate'])?@LANG_employee_summarycompany_sum2Team:"").'</td>
		<td width="'.$pxTab[4].'">'.(($v['rate'])?number_format($sumEurTeam, 2, ',', ' ').'&euro;':"").'</td>	
	</tr>	
			';
		}
			
			$sumhTeam = 0;
			$sumEurTeam = 0;
		}
		
		

		$sumPX = $pxTab[0]+$pxTab[1]+$pxTab[2]+$pxTab[3]+$pxTab[4];
		
		
		if( $v['filtr_split'] == 2 ){
			if( $val['employeeteam_name'] != null ) 
				$html = $html.'
					<tr style="font-weight:bold;font-size:12px;">
						<td colspan="'.$colspan.'" width="'.$sumPX.'">
							'.$val['employeeteam_name'].'
						</td>
					</tr>
				';
			else
				$html = $html.'
					<tr style="font-weight:bold;font-size:12px;">
						<td colspan="'.$colspan.'" width="'.$sumPX.'">
							'.@LANG_employee_list_team_np.'
						</td>
					</tr>
				';
		}
		
		
		if( $v['filtr_split'] == 3 ){
			if( $val['groupcompany_name'] != null ) 
				$html = $html.'
					<tr style="font-weight:bold;font-size:12px;">
						<td colspan="'.$colspan.'" width="'.$sumPX.'">
							'.$val['groupcompany_name'].'
						</td>
					</tr>
				';
			else
				$html = $html.'
					<tr style="font-weight:bold;font-size:12px;">
						<td colspan="'.$colspan.'" width="'.$sumPX.'">
							'.@LANG_employee_list_groupcompany_np.'
						</td>
					</tr>
				';
		}
		
		
		
	}
	
	
	
	
	$dataInfo = Lib_Employee::InfoRaportProject($projectData['project_id'], $val['employee_id'],  Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d"), Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d"));
	$sumh = $sumh+$dataInfo['time'];
	$sumhTeam = $sumhTeam+$dataInfo['time'];	
		
		
		
				if( $dataInfo['min'] == $dataInfo['max'] ){ 
				
					$col3 = number_format($dataInfo['min'], 2, ',', ' ');
				
				}else{
				
					$col3 = number_format($dataInfo['min'], 2, ',', ' ').'-'.number_format($dataInfo['max'], 2, ',', ' ');
				}
				
			$sumEur = $sumEur + $dataInfo['sum'];
			$sumEurTeam = $sumEurTeam + $dataInfo['sum'];
		
	$html = $html.'
	<tr>
		<td width="'.$pxTab[0].'"'.$class.'>'.$i.'.</td>
		<td width="'.$pxTab[1].'"'.$class.'>'.$val['employee_secondname'].' '.$val['employee_firstname'];
		
		if( $val['employee_date'] != '0000-00-00' ){
					$html = $html.' ('.@LANG_employee_date.' '.Lib_Date::convertDate($val['employee_date']).')';
		}
	$html = $html.'</td>
		<td width="'.$pxTab[2].'"'.$class.'>'.$dataInfo['time'].'h</td>
		<td width="'.$pxTab[3].'"'.$class.'>'.(($v['rate'])?$col3.'&euro;':"").'</td>
		<td width="'.$pxTab[4].'"'.$class.'>'.(($v['rate'])?number_format($dataInfo['sum'], 2, ',', ' ').'&euro;':"").'</td>
	</tr>
	';
	
	
	
	
	
	if( $v['filtr_split'] == 2 ){
	
		if( $i == count($data) ){
	 
		$pxTab2 = $pxTab[0]+$pxTab[1];
	 
			$html = $html.'
	<tr>	
		<td colspan="2" width="'.$pxTab2.'" align="right">'.@LANG_employee_summary_sumTeam.'</td>
		<td width="'.$pxTab[2].'">
			'.$sumhTeam.'h
		</td>	
		
		<td width="'.$pxTab[3].'" align="right">'.(($v['rate'])?@LANG_employee_summary_sum2Team:"").'</td>
		<td width="'.$pxTab[4].'">'.(($v['rate'])?number_format($sumEurTeam, 2, ',', ' ').'&euro;':"").'</td>	
	</tr>	
			';
	
			$sumhTeam = 0;
			$sumEurTeam = 0;
		}
	}
	
	
	
	
	if( $v['filtr_split'] == 3 ){
	
		if( $i == count($data) ){
	 
		$pxTab2 = $pxTab[0]+$pxTab[1];
	 
			$html = $html.'
	<tr>	
		<td colspan="2" width="'.$pxTab2.'" align="right">'.@LANG_employee_summarycompany_sumTeam.'</td>
		<td width="'.$pxTab[2].'">
			'.$sumhTeam.'h
		</td>	
		
		<td width="'.$pxTab[3].'" align="right">'.(($v['rate'])?@LANG_employee_summarycompany_sum2Team:"").'</td>
		<td width="'.$pxTab[4].'">'.(($v['rate'])?number_format($sumEurTeam, 2, ',', ' ').'&euro;':"").'</td>	
	</tr>	
			';
	
			$sumhTeam = 0;
			$sumEurTeam = 0;
		}
	}
	
	

	$rek = $val['employee_plwgroup'];
	endforeach;
	
		
	$pxTab2 = $pxTab[0]+$pxTab[1];
		
	$html = $html.'
	<tr>
		<td colspan="2" width="'.$pxTab2.'" align="right" bgcolor="#cef6ce">'.@LANG_employee_summary_sum.'</td>
		<td width="'.$pxTab[2].'">'.$sumh.'h</td>
		<td width="'.$pxTab[3].'" align="right" bgcolor="#cef6ce">'.(($v['rate'])?@LANG_employee_summary_sum2:"").'</td>
		<td width="'.$pxTab[4].'">'.(($v['rate'])?number_format($sumEur, 2, ',', ' ').'&euro;':"").'</td>
	</tr>
	';
		
		
		$html = $html.'

	</tbody>
</table>
		';
		
		
			
			$name = mb_strtolower ($projectData['project_name'], 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
			$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			
			// set document information
			$pdf->SetCreator(PDF_CREATOR);
			$pdf->SetAuthor('www.TECHNIX.pl');
			$pdf->SetTitle($nameFile);
			$pdf->SetSubject($nameFile);
			$pdf->SetKeywords($nameFile);
			$pdf->setPrintHeader(false);
			
			// set default header data
			$pdf->setFooterData(array(0,64,0), array(0,64,128));

			// set header and footer fonts
			$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

			// set default monospaced font
			$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

			// set margins
			$pdf->SetMargins(5, 5, 5);

			// set auto page breaks
			$pdf->SetAutoPageBreak(TRUE, 5);

			// set image scale factor
			$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

			// ---------------------------------------------------------

			// set default font subsetting mode
			$pdf->setFontSubsetting(true);

			// Set font
			// dejavusans is a UTF-8 Unicode font, if you only need to
			// print standard ASCII chars, you can use core fonts like
			// helvetica or times to reduce file size.
			$pdf->SetFont('dejavusans', '', 7, '', true);

			// Add a page
			// This method has several options, check the source code documentation for more information.
			$pdf->AddPage();
			
			
			
			
			$pdf->writeHTML($html, true, 0, true, true);
			
			ob_end_clean();
			if( $save == false ) $pdf->Output($nameFile.'.pdf', 'I');
			else{
				$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
				$pdf->Output($file, 'F');
				return $file;
			}

		
	}	
	
	
	
	
	
	
	
	
	
	







	public function init() {
		$information = new Zend_Session_Namespace('information');	
		if( Lib_Permission::CheckPermission('employee') != true ){
			$information->permissionError = true;
			$this->_helper->redirector('index','index');		
		}
		
		$admin = new Zend_Session_Namespace('admin');
		if( $admin->admin_auth != true ){
			$this->_helper->redirector('index','login');
		}								
	}	
	
	
	public function indexAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		$db = Zend_Registry::get('db');
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrStatusRemove ){
			$this->view->addFiltrStatusRemove = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$searchEmployeeName = null;
		
		if( isset($vPost['filtr_employeegroup_id']) AND isset($filtremployee->filtr_employeegroup_id) AND $filtremployee->filtr_employeegroup_id == $vPost['filtr_employeegroup_id'] ){	
			unset($filtremployee->filtr_employeegroup_id);
			$this->_helper->redirector('index','employee');	
		}
		
		if( isset($vPost['filtr_employeegroup_id']) ){		
			$filtremployee->filtr_employeegroup_id = $vPost['filtr_employeegroup_id'];
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_employeegroup_id ){
			$this->view->filtr_employeegroup_id =  $filtremployee->filtr_employeegroup_id;
		}
		
		if( isset($vPost['filtrEmployeeProjectCheck']) ){
			if( isset($vPost['filtrEmployeeProjectSplit']) ) $filtremployee->project_split = $vPost['filtrEmployeeProjectSplit'];
			else unset($filtremployee->project_split);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->project_split ){
			$this->view->project_split =  $filtremployee->project_split;
		}
		
		if( isset($vPost['filtrEmployeeTeamCheck']) ){
			if( isset($vPost['filtrEmployeeTeam']) ) $filtremployee->team_split = $vPost['filtrEmployeeTeam'];
			else unset($filtremployee->team_split);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->team_split ){
			$this->view->team_split =  $filtremployee->team_split;
		}
		
		if( isset($vPost['filtrEmployeeAlertCheck']) ){
			if( isset($vPost['filtr_alert']) ) $filtremployee->filtr_alert = $vPost['filtr_alert'];
			else unset($filtremployee->filtr_alert);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_alert ){
			$this->view->filtr_alert =  $filtremployee->filtr_alert;
		}
		
		if( isset($vPost['filtrEmployeeClarifyCheck']) ){
			if( isset($vPost['filtr_clarify']) ) $filtremployee->filtr_clarify = $vPost['filtr_clarify'];
			else unset($filtremployee->filtr_clarify);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_clarify ){
			$this->view->filtr_clarify =  $filtremployee->filtr_clarify;
		}
		
		if( isset($vPost['filtrEmployeeNHCheck']) ){
			if( isset($vPost['filtr_nh']) ) $filtremployee->filtr_nh = $vPost['filtr_nh'];
			else unset($filtremployee->filtr_nh);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_nh ){
			$this->view->filtr_nh =  $filtremployee->filtr_nh;
		}
		
		if( isset($vPost['filtrEmployeeNoticeCheck']) ){
			if( isset($vPost['filtr_notice']) ) $filtremployee->filtr_notice = $vPost['filtr_notice'];
			else unset($filtremployee->filtr_notice);
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_notice ){
			$this->view->filtr_notice =  $filtremployee->filtr_notice;
		}
		
		if( isset($vPost['filtrEmployeeNewEmpCheck']) ){
			if( isset($vPost['filtr_newemp']) ){
				$filtremployee->filtr_newemp = $vPost['filtr_newemp'];
				$filtremployee->filtr_newempval = $vPost['filtr_newempval'];
			}
			else{
				unset($filtremployee->filtr_newemp);
				unset($filtremployee->filtr_newempval);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_newemp ){
			$this->view->filtr_newemp =  $filtremployee->filtr_newemp;
			$this->view->filtr_newempval =  $filtremployee->filtr_newempval;
		}
		
		if( isset($vPost['filtrEmployeeNoWorkEmpCheck']) ){
			if( isset($vPost['filtr_noworkemp']) ){
				$filtremployee->filtr_noworkemp = $vPost['filtr_noworkemp'];
				$filtremployee->filtr_noworkempval = $vPost['filtr_noworkempval'];
			}
			else{
				unset($filtremployee->filtr_noworkemp);
				unset($filtremployee->filtr_noworkempval);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_noworkemp ){
			$this->view->filtr_noworkemp =  $filtremployee->filtr_noworkemp;
			$this->view->filtr_noworkempval =  $filtremployee->filtr_noworkempval;
		}
		
		
		
		if( isset($vPost['removeEmployeeResigenceDate']) ){
			unset($filtremployee->filtr_residence_date_start);
			unset($filtremployee->filtr_residence_date_stop);
			$this->_helper->redirector('index','employee');	
		}
		if( isset($vPost['filtrEmployeeResigenceDateStart']) OR isset($vPost['filtrEmployeeResigenceDateStop']) ){
		
			if( isset($vPost['filtrEmployeeResigenceDateStart']) ){
				$filtremployee->filtr_residence_date_start = $vPost['filtrEmployeeResigenceDateStart'];
			}else{
				unset($filtremployee->filtr_residence_date_start);			
			}
			
			if( isset($vPost['filtrEmployeeResigenceDateStop']) ){
				$filtremployee->filtr_residence_date_stop = $vPost['filtrEmployeeResigenceDateStop'];
			}else{
				unset($filtremployee->filtr_residence_date_stop);			
			}
			
			$this->_helper->redirector('index','employee');	
		}
			
		if( $filtremployee->filtr_residence_date_start ){
			$this->view->filtr_residence_date_start =  $filtremployee->filtr_residence_date_start;
		}
			
		if( $filtremployee->filtr_residence_date_stop ){
			$this->view->filtr_residence_date_stop =  $filtremployee->filtr_residence_date_stop;
		}
		
		
		// filtr nazwa pracownika - poczatek
		if( isset($vPost['removeEmployeeName']) ){
			unset($filtremployee->employee_name);
			$this->_helper->redirector('index','employee');	
		}
		if( isset($vPost['filtrEmployeeName']) ){
			$filtremployee->employee_name = $vPost['filtrEmployeeName'];
			$information->addFiltrEmployeeNameSuccess = true;
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->employee_name ){	
			$filtremployee->employee_name = str_replace("\\",'',$filtremployee->employee_name);
			$this->view->filtr_name_employee = $filtremployee->employee_name;
			
		//	$searchEmployeeName = "employee_secondname LIKE '".str_replace("*","%",$filtremployee->employee_name)."'";
			
			$searchEmployee = explode(" ",$filtremployee->employee_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa pracownika - koniec
		// ==========================================================
		
		
		if( isset($vPost['filtrEmployeeStatus']) ){
			if( $vPost['filtrEmployeeStatus'] != 'all' ){
				$filtremployee->employee_status = $vPost['filtrEmployeeStatus'];
				$information->addFiltrStatusSuccess = true;
			}else{
				//Zend_Session::namespaceUnset('filtremployee');
				unset($filtremployee->employee_status);
				$information->addFiltrStatusRemove = true;
			}
			$this->_helper->redirector('index','employee');	
		}
		
		if( $filtremployee->employee_status ){
			$this->view->filtr_employee_status =  $filtremployee->employee_status;
			$status = $filtremployee->employee_status - 1;
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName.' AND employee_activ='.$status;
			else $searchEmployeeName = 'employee_activ='.$status;
		}
		
		
		
		
		
		
		
		// opcje dodatkowe - początek
		
		if( isset($vPost['filtrOption1_Check']) ){
			if( $vPost['filtr_option_order'] != 0 ){
				$filtremployee->filtr_option_order = $vPost['filtr_option_order'];
			}
			else{
				unset($filtremployee->filtr_option_order);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_option_order ){
			$this->view->filtr_option_order =  $filtremployee->filtr_option_order;
		}	

		
		if( isset($vPost['filtrOption2_Check']) ){
			if( $vPost['filtr_option_order2'] != 0 ){
				$filtremployee->filtr_option_order2 = $vPost['filtr_option_order2'];
			}
			else{
				unset($filtremployee->filtr_option_order2);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_option_order2 ){
			$this->view->filtr_option_order2 =  $filtremployee->filtr_option_order2;
		}

		
		if( isset($vPost['filtrOption3_Check']) ){
			if( $vPost['filtr_option_order3'] != 0 ){
				$filtremployee->filtr_option_order3 = $vPost['filtr_option_order3'];
			}
			else{
				unset($filtremployee->filtr_option_order3);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_option_order3 ){
			$this->view->filtr_option_order3 =  $filtremployee->filtr_option_order3;
		}		

		
		if( isset($vPost['filtrEmployeeCheck_Check']) ){
			if( $vPost['filtr_employee_check'] != 0 ){
				$filtremployee->filtr_employee_check = $vPost['filtr_employee_check'];
			}
			else{
				unset($filtremployee->filtr_employee_check);
			}
			$this->_helper->redirector('index','employee');	
		}		
		if( $filtremployee->filtr_employee_check ){
			$this->view->filtr_employee_check =  $filtremployee->filtr_employee_check;
		}		
		
		// opcje dodatkowe - koniec
		
		
		
		
		
		
		
		
		
		
		
		
		if( $filtremployee->filtr_alert ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			
		}
		
		
		if( $filtremployee->filtr_clarify ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			
		}
		
		
		if( $filtremployee->filtr_notice ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND employee_note NOT LIKE ''";
			else $searchEmployeeName = "employee_note NOT LIKE ''";
		}
		
		
		if( $filtremployee->filtr_newemp ){
		
			// AND DATE_ADD(CURDATE(), INTERVAL -30 DAY) < employee_date
			// if( $_GET['ask'] == true ) echo$ask;
			
			
			if( $filtremployee->filtr_newempval == 31 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
				else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
			
			}
			
			
			if( $filtremployee->filtr_newempval == 61 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
				else $searchEmployeeName = "(DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
			
			}
		}
		
		
		
		if( $filtremployee->filtr_noworkemp ){	
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";
			else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";

		}
		
		
		
		if( $filtremployee->filtr_nh ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
			else $searchEmployeeName = "(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
		}
		
		
		
		if( $filtremployee->filtr_employeegroup_id ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
			else $searchEmployeeName = "(SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
		}
		
		
		
		if( $filtremployee->filtr_residence_date_start ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		if( $filtremployee->filtr_residence_date_stop ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		// opcje dodatkowe - zapytanie - początek
		
		if( $filtremployee->filtr_option_order ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '0' )";
			}else{
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = "( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = "( e.employee_activ_order = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order2 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '0' )";
			}else{
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = "( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = "( e.employee_activ_order2 = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order3 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '0' )";
			}else{
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = "( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = "( e.employee_activ_analysis = '0' )";
			}
		}
		
		if( $filtremployee->filtr_employee_check ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '0' )";
			}else{
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = "( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = "( e.employee_check = '0' )";
			}
		}
		
		// opcje dodatkowe - zapytanie - koniec
		
		
		
		if( $filtremployee->project_split == 1 ){
		
		
			$search = '';
			if( $searchEmployeeName != null ){
				$search = ' AND '.$searchEmployeeName;
			}
		
		
			$ask = "
				SELECT *
				FROM project p, company c
				WHERE 
				p.company_id = c.company_id
				AND
				p.project_status = 0
				AND 
				p.project_activ_employee = 1	
				ORDER BY
				c.company_name ASC,
				p.project_name ASC
			";
			
		
			$data = $db->query($ask)->fetchAll();
			
			
			
			$order = " ORDER BY employee_secondname ASC, employee_firstname ASC";
			
			if( $filtremployee->team_split ){
				$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, employee_secondname ASC, employee_firstname ASC";
			}
			
			
			
		
			foreach( $data as $key => $val ){

				$ask = "SELECT 
					*, 
					(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
					
					(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

				(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

				(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR, 

				(SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) AS countClarify  
					
					FROM `employee` e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, `employee_project` ep WHERE e.employee_id = ep.employee_id AND ep.project_id = '".$val['project_id']."'  ".$search.$order;		
				$dataEmp = $db->query($ask)->fetchAll();			
			
				$data[$key]['emp'] = $dataEmp;
			
			}
				
			$this->view->dataTable = $data;	
			
			
			
			$search = '';
			if( $searchEmployeeName != null ){
				$search = ' WHERE '.$searchEmployeeName;
			}
			
			$ask = "
				SELECT *,
				(SELECT COUNT(*) AS i FROM employee_project ep, project p WHERE ep.project_id = p.project_id AND
				p.project_status = 0 AND p.project_activ_employee = 1 AND ep.employee_id = e.employee_id
				) AS i, 
				(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
				(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

				(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

				(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR, 

				(SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) AS countClarify    
				
				FROM 
				`employee` e  LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id ".$search.$order;
				
			$dataEmpNP = $db->query($ask)->fetchAll();
			
			$this->view->dataTableNP = $dataEmpNP;	
			
		
		}else{
		
			$search = '';
			if( $searchEmployeeName != null ){
				$search = ' WHERE '.$searchEmployeeName;
			}
			
			$order = " ORDER BY employee_secondname ASC, employee_firstname ASC";
			
			if( $filtremployee->team_split ){
				$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, employee_secondname ASC, employee_firstname ASC";
			}
			
			$ask = "SELECT 
				*, 
				(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
				
				(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

				(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

				(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR, 

				(SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) AS countClarify    
				
				FROM `employee` e  LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id ".$search.$order;	
			
			
			$data = $db->query($ask)->fetchAll();		
			$this->view->dataTable = $data;	
			
		}
			
			
		if( $_GET['ask'] == true ) echo$ask;
		
		
		
		
		
		$EmployeeGroup = new EmployeeGroup();	
		$orderEmployeeGroup = array('employeegroup_name ASC');
		$data = $EmployeeGroup->fetchAll('employeegroup_desktop = 1' , $orderEmployeeGroup); 		
		$this->view->dataTableEmployeeGroup = $data;
		
		
		if( $filtremployee->project_split OR $filtremployee->team_split ){
			$this->view->split = true;	
		}else{
			$this->view->split = false;			
		}
	}
	
	
	
	
	
	
	
	
	
		
	
	
	public function indexprintAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		$db = Zend_Registry::get('db');		
		
		if( $filtremployee->project_split OR $filtremployee->team_split ){
			$this->_helper->redirector('index','employee');	
		}
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		$searchEmployeeName = null;
		
		if( $filtremployee->filtr_employeegroup_id ){
			$this->view->filtr_employeegroup_id =  $filtremployee->filtr_employeegroup_id;
		}

		if( $filtremployee->project_split ){
			$this->view->project_split =  $filtremployee->project_split;
		}
	
		if( $filtremployee->team_split ){
			$this->view->team_split =  $filtremployee->team_split;
		}

		if( $filtremployee->filtr_alert ){
			$this->view->filtr_alert =  $filtremployee->filtr_alert;
		}
			
		if( $filtremployee->filtr_nh ){
			$this->view->filtr_nh =  $filtremployee->filtr_nh;
		}
			
		if( $filtremployee->filtr_notice ){
			$this->view->filtr_notice =  $filtremployee->filtr_notice;
		}		
	
		if( $filtremployee->filtr_newemp ){
			$this->view->filtr_newemp =  $filtremployee->filtr_newemp;
			$this->view->filtr_newempval =  $filtremployee->filtr_newempval;
		}
		
	
		if( $filtremployee->filtr_noworkemp ){
			$this->view->filtr_noworkemp =  $filtremployee->filtr_noworkemp;
			$this->view->filtr_noworkempval =  $filtremployee->filtr_noworkempval;
		}
		
		// filtr nazwa pracownika - poczatek		
		if( $filtremployee->employee_name ){	
			$filtremployee->employee_name = str_replace("\\",'',$filtremployee->employee_name);
			$this->view->filtr_name_employee = $filtremployee->employee_name;
			
			$searchEmployee = explode(" ",$filtremployee->employee_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa pracownika - koniec
		// ==========================================================
		
		if( $filtremployee->employee_status ){
			$this->view->filtr_employee_status =  $filtremployee->employee_status;
			$status = $filtremployee->employee_status - 1;
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName.' AND employee_activ='.$status;
			else $searchEmployeeName = 'employee_activ='.$status;
		}
		
		
		
		
		
		if( $filtremployee->filtr_alert ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			
		}
		
		
		if( $filtremployee->filtr_clarify ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			
		}
		
		
		if( $filtremployee->filtr_notice ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND employee_note NOT LIKE ''";
			else $searchEmployeeName = "employee_note NOT LIKE ''";
		}
		
		
		if( $filtremployee->filtr_newemp ){
		
			// AND DATE_ADD(CURDATE(), INTERVAL -30 DAY) < employee_date
			// if( $_GET['ask'] == true ) echo$ask;
			
			
			if( $filtremployee->filtr_newempval == 31 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
				else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
			
			}
			
			
			if( $filtremployee->filtr_newempval == 61 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
				else $searchEmployeeName = "(DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
			
			}
		}
		
		
		
		if( $filtremployee->filtr_noworkemp ){	
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";
			else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";

		}
		
		
		
		if( $filtremployee->filtr_nh ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
			else $searchEmployeeName = "(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
		}
		
		
		
		if( $filtremployee->filtr_employeegroup_id ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
			else $searchEmployeeName = "(SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
		}
		
		
		
		if( $filtremployee->filtr_residence_date_start ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		if( $filtremployee->filtr_residence_date_stop ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		// opcje dodatkowe - zapytanie - początek
		
		if( $filtremployee->filtr_option_order ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '0' )";
			}else{
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = "( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = "( e.employee_activ_order = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order2 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '0' )";
			}else{
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = "( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = "( e.employee_activ_order2 = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order3 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '0' )";
			}else{
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = "( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = "( e.employee_activ_analysis = '0' )";
			}
		}
		
		if( $filtremployee->filtr_employee_check ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '0' )";
			}else{
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = "( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = "( e.employee_check = '0' )";
			}
		}
		
		// opcje dodatkowe - zapytanie - koniec
		
		
		$search = '';
		if( $searchEmployeeName != null ){
			$search = ' WHERE '.$searchEmployeeName;
		}
			
		$order = " ORDER BY employee_secondname ASC, employee_firstname ASC";
			
		$ask = "SELECT 
			*, 
			(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
				
			(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

			(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
			WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

			(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR  
				
			FROM `employee` e  LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id ".$search.$order;	
			
			
		$data = $db->query($ask)->fetchAll();		
		$this->view->dataTable = $data;	
		
		
		if( $filtremployee->project_split OR $filtremployee->team_split ){
			$this->view->split = true;	
		}else{
			$this->view->split = false;			
		}
	}
	
	
	public function indexpdfAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		
		if( $filtremployee->project_split OR $filtremployee->team_split ){
			$this->_helper->redirector('index','employee');	
		}
			
		$this->generateindexpdf();	
	
	}
	
	
	public function indexxlsAction() {		
		$this->_helper->viewRenderer->setNoRender();
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		$db = Zend_Registry::get('db');		
				
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		$searchEmployeeName = null;
		
		// filtr nazwa pracownika - poczatek		
		if( $filtremployee->employee_name ){	
			$filtremployee->employee_name = str_replace("\\",'',$filtremployee->employee_name);
			
			$searchEmployee = explode(" ",$filtremployee->employee_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa pracownika - koniec
		// ==========================================================
		
		if( $filtremployee->employee_status ){
			$status = $filtremployee->employee_status - 1;
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName.' AND employee_activ='.$status;
			else $searchEmployeeName = 'employee_activ='.$status;
		}
		
		
		
		
		
		if( $filtremployee->filtr_alert ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
				WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') > 0";
			
		}
		
		
		if( $filtremployee->filtr_clarify ){
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			else $searchEmployeeName = " (SELECT COUNT( `employee_settlement_id` ) AS countClarify FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_clarify = 1) > 0";
			
		}
		
		
		if( $filtremployee->filtr_notice ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND employee_note NOT LIKE ''";
			else $searchEmployeeName = "employee_note NOT LIKE ''";
		}
		
		
		if( $filtremployee->filtr_newemp ){
		
			// AND DATE_ADD(CURDATE(), INTERVAL -30 DAY) < employee_date
			// if( $_GET['ask'] == true ) echo$ask;
			
			
			if( $filtremployee->filtr_newempval == 31 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
				else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`";
			
			}
			
			
			if( $filtremployee->filtr_newempval == 61 ){	
				
				if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
				else $searchEmployeeName = "(DATE_ADD(CURDATE(), INTERVAL -30 DAY) > `employee_date` AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_newempval." DAY) < `employee_date`)";
			
			}
		}
		
		
		
		if( $filtremployee->filtr_noworkemp ){	
		
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";
			else $searchEmployeeName = "DATE_ADD(CURDATE(), INTERVAL -".$filtremployee->filtr_noworkempval." DAY) >= (SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id)";

		}
		
		
		
		if( $filtremployee->filtr_nh ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
			else $searchEmployeeName = "(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) > 0";
		}
		
		
		
		if( $filtremployee->filtr_employeegroup_id ){
			if( $searchEmployeeName != null ) $searchEmployeeName = $searchEmployeeName." AND (SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
			else $searchEmployeeName = "(SELECT employeegroup_id AS employeegroup_id FROM employee_employeegroup eeg WHERE eeg.employeegroup_id = ".$filtremployee->filtr_employeegroup_id." AND e.employee_id = eeg.employee_id) = ".$filtremployee->filtr_employeegroup_id;
		}
		
		
		
		if( $filtremployee->filtr_residence_date_start ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_start = '0000-00-00' OR e.employee_residence_date_start >= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_start,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		if( $filtremployee->filtr_residence_date_stop ){
			if( $searchEmployeeName != null ){
				$searchEmployeeName = $searchEmployeeName." AND ( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}else{
				$searchEmployeeName = "( e.employee_residence_date_stop = '0000-00-00' OR e.employee_residence_date_stop <= '".Lib_Date::convertDate($filtremployee->filtr_residence_date_stop,"d-m-Y","Y-m-d")."' )";
			}
		}
		
		
		// opcje dodatkowe - zapytanie - początek
		
		if( $filtremployee->filtr_option_order ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order = '0' )";
			}else{
				if( $filtremployee->filtr_option_order == 1 ) $searchEmployeeName = "( e.employee_activ_order = '1' )";
				if( $filtremployee->filtr_option_order == 2 ) $searchEmployeeName = "( e.employee_activ_order = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order2 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_order2 = '0' )";
			}else{
				if( $filtremployee->filtr_option_order2 == 1 ) $searchEmployeeName = "( e.employee_activ_order2 = '1' )";
				if( $filtremployee->filtr_option_order2 == 2 ) $searchEmployeeName = "( e.employee_activ_order2 = '0' )";
			}
		}
		
		if( $filtremployee->filtr_option_order3 ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_activ_analysis = '0' )";
			}else{
				if( $filtremployee->filtr_option_order3 == 1 ) $searchEmployeeName = "( e.employee_activ_analysis = '1' )";
				if( $filtremployee->filtr_option_order3 == 2 ) $searchEmployeeName = "( e.employee_activ_analysis = '0' )";
			}
		}
		
		if( $filtremployee->filtr_employee_check ){
			if( $searchEmployeeName != null ){
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = $searchEmployeeName." AND ( e.employee_check = '0' )";
			}else{
				if( $filtremployee->filtr_employee_check == 1 ) $searchEmployeeName = "( e.employee_check = '1' )";
				if( $filtremployee->filtr_employee_check == 2 ) $searchEmployeeName = "( e.employee_check = '0' )";
			}
		}
		
		// opcje dodatkowe - zapytanie - koniec
		
		
		$search = '';
		if( $searchEmployeeName != null ){
			$search = ' WHERE '.$searchEmployeeName;
		}
			
		$order = " ORDER BY employee_secondname ASC, employee_firstname ASC";
			
		$ask = "SELECT 
			*, 
			(SELECT  SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".date('Y-m-01')."' AND e.employee_id = es.employee_id) AS timeSum,
				
			(SELECT  MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, 

			(SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea 
			WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".date('Y-m-d')."' AND ea.employee_alert_stop >= '".date('Y-m-d')."') AS countAlert, 

			(SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR  
				
			FROM `employee` e  LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id ".$search.$order;	
			
			
		$dataTable = $db->query($ask)->fetchAll();	
		
		
		
		
		
			
		
			
			$name = mb_strtolower (@LANG_header_title_xls, 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
			
			
		
			$objPHPExcel = new PHPExcel();
			$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(35);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(35);
			$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
			$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
		
		//	$objPHPExcel->getActiveSheet()->freezePane("A2");
		
			$i = 0;
			$i++;
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, @LANG_employee_list_lp)	
					->setCellValue('B'.$i, @LANG_employee_list_name)		
					->setCellValue('C'.$i, @LANG_employee_list_status)
					->setCellValue('D'.$i, @LANG_employee_list_residence)						
					->setCellValue('E'.$i, @LANG_employee_list_residence_start)
					->setCellValue('F'.$i, @LANG_employee_list_residence_stop);
		
			$objPHPExcel->getActiveSheet()->getStyle("A1:F1")->getFont()->setSize(14)->setBold(true);
			
			$objPHPExcel->getActiveSheet()->getStyle("A1:F1")->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					 'rgb' => 'cef6ce'
				)
			));
			
			$j = 0;
			foreach($dataTable as $key => $val){
				$i++;
				$j++;
				
				$dataEmployeeGroupEAll = Lib_Employee::EmployeeGroupEAll($val['employee_id'],'employeegroup.employeegroup_type_id = 2');
				$emgr = '';
				foreach($dataEmployeeGroupEAll as $k1 => $v1){								
					$emgr = $emgr.$v1['employeegroup_name'].', ';
				}
				
				if( $val['employee_residence_date_start'] == '0000-00-00' ){
					$d1 = '-';
				}else{
					$d1 = Lib_Date::convertDate($val['employee_residence_date_start'],"Y-m-d","d-m-Y");
				}
				
				if( $val['employee_residence_date_stop'] == '0000-00-00' ){
					$d2 = '-';
				}else{
					$d2 = Lib_Date::convertDate($val['employee_residence_date_stop'],"Y-m-d","d-m-Y");
				}
				
				$objPHPExcel->setActiveSheetIndex(0)
						->setCellValue('A'.$i, $j.'.')	
						->setCellValue('B'.$i, $val['employee_secondname'].' '.$val['employee_firstname'])		
						->setCellValue('C'.$i, (($val['employee_activ']==0)?@LANG_employee_list_status0:@LANG_employee_list_status1))
						->setCellValue('D'.$i, $emgr)						
						->setCellValue('E'.$i, $d1)
						->setCellValue('F'.$i, $d2);
			}
			
			$objPHPExcel->getActiveSheet()
                ->getStyle('A1:F'.$i)
                ->getBorders()
                ->getAllBorders()
                ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
                ->getColor()
                ->setRGB('888');

			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);

			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');

			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0

			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');	
		
		
	
	}
	
	
	
	
	
	
	
	
	
	
	/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	
		
	/*	
		$limit = 10;
		$limitpage = 10;
		
		$orderEmployee = array('employee_secondname ASC','employee_firstname ASC');

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Employee = new Employee();	
		$dataCount = count($Employee->fetchAll($searchEmployeeName , $orderEmployee)); 
			$p = ($page-1)*$limit;		
		$data = $Employee->fetchAll($searchEmployeeName , $orderEmployee);//, $limit,$p); 		
		$this->view->dataTable = $data;		
	*/	
	
	/*
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('index');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
	*/	
	
	/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	
	
	
	public function groupemployeeAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployeegroup'.$v['id']);
		$db = Zend_Registry::get('db');

		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$searchEmployeeName = null;
		
		
		// filtr nazwa pracownika - poczatek
		if( isset($vPost['removeEmployeeName']) ){
			unset($filtremployee->employee_name);
			$this->_helper->redirector('groupemployee','employee',null,array('id' => $v['id']));	
		}
		if( isset($vPost['filtrEmployeeName']) ){
			$filtremployee->employee_name = $vPost['filtrEmployeeName'];
			$information->addFiltrEmployeeNameSuccess = true;
			$this->_helper->redirector('groupemployee','employee',null,array('id' => $v['id']));	
		}		
		if( $filtremployee->employee_name ){
			$this->view->filtr_name_employee =  $filtremployee->employee_name;
			
		//	$searchEmployeeName = "employee_secondname LIKE '".str_replace("*","%",$filtremployee->employee_name)."'";
			
			$searchEmployee = explode(" ",$filtremployee->employee_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employee_firstname LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							employee_secondname LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa pracownika - koniec
		// ==========================================================
		
		$limit = 10;
		$limitpage = 10;
		
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
		
		$p = ($page-1)*$limit;	
		

	/*
		$Employee = new Employee();	
		$dataCount = count($Employee->fetchAll($searchEmployeeName , $orderEmployee)); 
			$p = ($page-1)*$limit;		
		$data = $Employee->fetchAll($searchEmployeeName , $orderEmployee, $limit,$p); 		
	*/	
		
		$select = $db->select();
		$select->from('employee',array('COUNT(employee.employee_id) as count', 'employee.employee_id'))->join('employee_employeegroup', 'employee.employee_id = employee_employeegroup.employee_id');
		$select->where('employeegroup_id = '.$v['id']);	 
		$select->where('employee_activ = 0');	 
		if( $searchEmployeeName != null ) $select->where($searchEmployeeName);	 
		$select->order($orderEmployee);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$dataCount = $data[0]['count'];		
		
		$select = $db->select();
		$select->from('employee')->join('employee_employeegroup', 'employee.employee_id = employee_employeegroup.employee_id');
		$select->where('employeegroup_id = '.$v['id']);	 
		$select->where('employee_activ = 0');	 
		if( $searchEmployeeName != null ) $select->where($searchEmployeeName);	 
		$select->order($orderEmployee);//->limit($limit,$p);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();			
		$this->view->dataTable = $data;		
	/*
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('groupemployee');
		$Lib_Page->setGet('/id/'.$v['id']);
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
	*/	
		$EmployeeGroup = new EmployeeGroup();	
		$select = $EmployeeGroup->select();
		$select->where('employeegroup_id = ?', $v['id']);	
		$row = $EmployeeGroup->fetchRow($select);
		$this->view->employeeGroupData = $row;
	}
	
	
	public function addAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();		
		$EmployeeGroup = new EmployeeGroup();	
		$EmployeeEmployeeGroup = new EmployeeEmployeeGroup();		
		$EmployeeRateHistory = new EmployeeRateHistory();		
		$EmployeeEmployeeteamHistory = new EmployeeEmployeeteamHistory();
		$EmploymentType = new EmploymentType();
		$EmployeeEmploymentTypeHistory = new EmployeeEmploymentTypeHistory();
		
		$v = $this->_request->getPost();
		
		if( isset($v['admin_addemployee']) ){
		
			if( $v['employee_rate'] == '' ) $v['employee_rate'] = 0;
			
			if( $v['employee_date'] == '' ) $v['employee_date'] = '0000-00-00';
			else $v['employee_date'] = Lib_Date::convertDate($v['employee_date'],"d-m-Y","Y-m-d");
			
			if( $v['employee_residence_date_start'] == '' ) $v['employee_residence_date_start'] = '0000-00-00';
			else $v['employee_residence_date_start'] = Lib_Date::convertDate($v['employee_residence_date_start'],"d-m-Y","Y-m-d");
			
			if( $v['employee_residence_date_stop'] == '' ) $v['employee_residence_date_stop'] = '0000-00-00';
			else $v['employee_residence_date_stop'] = Lib_Date::convertDate($v['employee_residence_date_stop'],"d-m-Y","Y-m-d");
			
			$data = array(
				'employee_firstname' => $v['employee_firstname'],
				'employee_secondname' => $v['employee_secondname'],
				'employeeteam_id' => $v['employeeteam_id'],
				'employee_date' => $v['employee_date'],
				'employee_residence_date_start' => $v['employee_residence_date_start'],
				'employee_residence_date_stop' => $v['employee_residence_date_stop'],
				'employee_email' => isset($v['employee_email'])?$v['employee_email']:'',
				'employee_phone' => isset($v['employee_phone'])?$v['employee_phone']:'',
				'employee_rate' => isset($v['employee_rate'])?str_replace(",",".",$v['employee_rate']):'0.00',
				'employment_type_id' => $v['employment_type_id'],
				'employee_activ_order' => isset($v['employee_activ_order'])?$v['employee_activ_order']:0,
				'employee_activ_order2' => isset($v['employee_activ_order2'])?$v['employee_activ_order2']:0,
				'employee_activ_analysis' => isset($v['employee_activ_analysis'])?$v['employee_activ_analysis']:0,
				'employee_ins' => Lib_Date::datetime(),
				'employee_edit' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$idIns = $Employee->insert($data);
			
			$dataHist = array(
				'employee_id' => $idIns,
				'employee_rate_history_old' => '0.00',
				'employee_rate_history_new' => isset($v['employee_rate'])?str_replace(",",".",$v['employee_rate']):'0.00',
				'employee_rate_history_note' => '',
				'employee_rate_history_ins' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$EmployeeRateHistory->insert($dataHist);
			
			$dataHist = array(
				'employee_id' => $idIns,
				'employee_employeeteam_history_old' => '0',
				'employee_employeeteam_history_new' => $v['employeeteam_id'],
				'employee_employeeteam_history_note' => '',
				'employee_employeeteam_history_ins' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$EmployeeEmployeeteamHistory->insert($dataHist);
			
			$dataHist = array(
				'employee_id' => $idIns,
				'employee_employment_type_history_old' => $v['employment_type_id'],
				'employee_employment_type_history_new' => $v['employment_type_id'],
				'employee_employment_type_history_note' => '',
				'employee_employment_type_history_ins' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$EmployeeEmploymentTypeHistory->insert($dataHist);
			
			
			

			foreach( $v['permissionGroup_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $idIns,
						'employeegroup_id' => $valuep
					);
					$EmployeeEmployeeGroup->insert($data);					
			}
			
			if( $v['employeegroup_name'] != '' ){				
				$data = array(
					'employeegroup_name' => $v['employeegroup_name']
				);
				$idins = $EmployeeGroup->insert($data);		
				
				$data = array(
					'employee_id' => $idIns,
					'employeegroup_id' => $idins
				);
				$EmployeeEmployeeGroup->insert($data);	
			
			}
			
			Lib_PLW::updateEmployee($idIns);
			
		//	$this->_helper->redirector('edit','employee',null,array('id' => $idIns));	
			$this->_helper->redirector('index','employee');	
			
		}		
		
		$data = $EmployeeGroup->fetchAll('employeegroup_activ = 0' , 'employeegroup_name ASC'); 		
		$this->view->dataTableEmployeeGroup = $data;

		$EmployeeTeam = new EmployeeTeam();
		$data = $EmployeeTeam->fetchAll('employeeteam_activ = 0' , 'employeeteam_name ASC'); 		
		$this->view->dataTableEmployeeTeam = $data;

		$data = $EmploymentType->fetchAll(null , 'employment_type_sort ASC'); 		
		$this->view->dataTableEmploymentType = $data;
	}
	
	
	public function addgroupAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		
		$Employee = new Employee();	
		$EmployeeGroup = new EmployeeGroup();	
		$EmployeeGroupType = new EmployeeGroupType();	
		$EmployeeEmployeeGroup = new EmployeeEmployeeGroup();		
		
		$v = $this->_request->getPost();
		if( isset($v['admin_addemployeegroup']) ){
		
			$data = array(
				'employeegroup_name' => $v['employeegroup_name'],
				'employeegroup_type_id' => $v['employeegroup_type_id'],
				'employeegroup_desktop' => isset($v['employeegroup_desktop'])?1:0
			);
			$idIns = $EmployeeGroup->insert($data);

			foreach( $v['permissionEmployee_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $valuep,
						'employeegroup_id' => $idIns
					);
					$EmployeeEmployeeGroup->insert($data);					
			}
			
			$this->_helper->redirector('group','employee');	
			
		}	
		
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');
		$data = $Employee->fetchAll(null , $orderEmployee); 		
		$this->view->dataTableEmployee = $data;	
		
		$orderEmployeeGroupType = array('employeegroup_type_id ASC');
		$data = $EmployeeGroupType->fetchAll(null , $orderEmployeeGroupType); 		
		$this->view->dataTableEmployeeGroupType = $data;	
		

	}
	
	
	public function editgroupAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		
		$Employee = new Employee();	
		$EmployeeGroup = new EmployeeGroup();	
		$EmployeeGroupType = new EmployeeGroupType();	
		$EmployeeEmployeeGroup = new EmployeeEmployeeGroup();		
		
		$v = $this->_request->getParams();	
		
		if( isset($v['admin_addemployeegroup']) ){
		
		if( $v['id'] == 6 ){ 
			$data = array(
				'employee_plwgroup' => 0
			);
			$Employee->update( $data );	
		}
		
			$data = array(
				'employeegroup_name' => $v['employeegroup_name'],
				'employeegroup_type_id' => $v['employeegroup_type_id'],
				'employeegroup_activ' => $v['employeegroup_activ'],
				'employeegroup_desktop' => isset($v['employeegroup_desktop'])?1:0
			);
			$EmployeeGroup->update( $data , 'employeegroup_id='.$v['id'] );	
		
			
			$where = array(
				'employeegroup_id = ?' => $v['id']
			);
			$EmployeeEmployeeGroup->delete($where);

			foreach( $v['permissionEmployee_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $valuep,
						'employeegroup_id' => $v['id']
					);
					$EmployeeEmployeeGroup->insert($data);

				if( $v['id'] == 6 ) Lib_PLW::updateEmployee($valuep);					
			}

			foreach( $v['employee_rate'] as $keyp => $valuep ){	
		
				$data = array(
					'employee_rate' => isset($valuep)?str_replace(",",".",$valuep):'0.00',
					'employee_edit' => Lib_Date::datetime()
				);
				$Employee->update( $data , 'employee_id='.$keyp );
			
			}
			
			$this->_helper->redirector('group','employee');	
			
		}	
		
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');
		$data = $Employee->fetchAll(null , $orderEmployee); 		
		$this->view->dataTableEmployee = $data;	
		
		$select = $EmployeeGroup->select();
		$select->where('employeegroup_id = ?', $v['id']);	
		$row = $EmployeeGroup->fetchRow($select);
		$this->view->employeeGroupData = $row;
		
		$orderEmployeeGroupType = array('employeegroup_type_id ASC');
		$data = $EmployeeGroupType->fetchAll(null , $orderEmployeeGroupType); 		
		$this->view->dataTableEmployeeGroupType = $data;	

	}
	
	
	public function editAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();	
		$EmployeeRateHistory = new EmployeeRateHistory();	
		$EmployeeEmployeeteamHistory = new EmployeeEmployeeteamHistory();	
		$EmploymentType = new EmploymentType();
		$EmployeeEmploymentTypeHistory = new EmployeeEmploymentTypeHistory();
		
		if( $information->editEmployeeSuccess ){
			$this->view->editEmployeeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['admin_editemployee']) ){	

			$select = $Employee->select();
			$select->where('employee_id = ?', $v['id']);	
			$row = $Employee->fetchRow($select);		
		
			if( $v['employee_rate'] == '' ) $v['employee_rate'] = 0;
			
			if( $v['employee_date'] == '' ) $v['employee_date'] = '0000-00-00';
			else $v['employee_date'] = Lib_Date::convertDate($v['employee_date'],"d-m-Y","Y-m-d");
			
			if( $v['employee_residence_date_start'] == '' ) $v['employee_residence_date_start'] = '0000-00-00';
			else $v['employee_residence_date_start'] = Lib_Date::convertDate($v['employee_residence_date_start'],"d-m-Y","Y-m-d");
			
			if( $v['employee_residence_date_stop'] == '' ) $v['employee_residence_date_stop'] = '0000-00-00';
			else $v['employee_residence_date_stop'] = Lib_Date::convertDate($v['employee_residence_date_stop'],"d-m-Y","Y-m-d");
		
		//	var_dump($v);
		//	die();
			$data = array(
				'employee_firstname' => $v['employee_firstname'],
				'employee_secondname' => $v['employee_secondname'],
				'employeeteam_id' => $v['employeeteam_id'],
				'employee_date' => $v['employee_date'],
				'employee_residence_date_start' => $v['employee_residence_date_start'],
				'employee_residence_date_stop' => $v['employee_residence_date_stop'],
				'employee_email' => isset($v['employee_email'])?$v['employee_email']:'',
				'employee_phone' => isset($v['employee_phone'])?$v['employee_phone']:'',
				'employee_rate' => isset($v['employee_rate'])?str_replace(",",".",$v['employee_rate']):'0.00',
				'employment_type_id' => $v['employment_type_id'],
				'employee_activ_order' => isset($v['employee_activ_order'])?$v['employee_activ_order']:0,
				'employee_activ_order2' => isset($v['employee_activ_order2'])?$v['employee_activ_order2']:0,
				'employee_activ_analysis' => isset($v['employee_activ_analysis'])?$v['employee_activ_analysis']:0,
				'employee_note' => isset($v['employee_note'])?$v['employee_note']:'',
				'employee_activ' => $v['employee_activ'],
				'employee_edit' => Lib_Date::datetime()
			);
			$Employee->update( $data , 'employee_id='.$v['id'] );
			
			if( $row['employee_rate'] != $v['employee_rate'] ){
				$dataHist = array(
					'employee_id' => $v['id'],
					'employee_rate_history_old' => $row['employee_rate'],
					'employee_rate_history_new' => isset($v['employee_rate'])?str_replace(",",".",$v['employee_rate']):'0.00',
					'employee_rate_history_note' => $v['employee_rate_history_note'],
					'employee_rate_history_ins' => Lib_Date::datetime(),
					'admin_id' => $admin->admin_id
				);
				$EmployeeRateHistory->insert($dataHist);
			}
			
			if( $row['employeeteam_id'] != $v['employeeteam_id'] ){
				$dataHist = array(
					'employee_id' => $v['id'],
					'employee_employeeteam_history_old' => $row['employeeteam_id'],
					'employee_employeeteam_history_new' => $v['employeeteam_id'],
					'employee_employeeteam_history_note' => $v['employee_employeeteam_history_note'],
					'employee_employeeteam_history_ins' => Lib_Date::datetime(),
					'admin_id' => $admin->admin_id
				);
				$EmployeeEmployeeteamHistory->insert($dataHist);
			}
			
			if( $row['employment_type_id'] != $v['employment_type_id'] ){
				$dataHist = array(
					'employee_id' => $v['id'],
					'employee_employment_type_history_old' => $row['employment_type_id'],
					'employee_employment_type_history_new' => $v['employment_type_id'],
					'employee_employment_type_history_note' => $v['employee_employment_type_history_note'],
					'employee_employment_type_history_ins' => Lib_Date::datetime(),
					'admin_id' => $admin->admin_id
				);
				$EmployeeEmploymentTypeHistory->insert($dataHist);
			}

			if( !$v['return'] ){
				$information->editEmployeeSuccess = true;
				$this->_helper->redirector('edit','employee',null,array('id' => $v['id']));
			}
			if( $v['return'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));	
		}
		
		
		
		
		if( isset($v['admin_editemployeerate']) ){	
			$EmployeeSettlement = new EmployeeSettlement();	
					
					
			$data = array(
				'employee_settlement_rate' => isset($v['employee_rate_edit_rate'])?str_replace(",",".",$v['employee_rate_edit_rate']):'0.00'
			);
			$EmployeeSettlement->update($data, 
				"employee_id = ".$v['id']." AND 
				employee_settlement_date >= '".Lib_Date::convertDate($v['employee_rate_edit_start'],"d-m-Y","Y-m-d")."' AND 
				employee_settlement_date <= '".Lib_Date::convertDate($v['employee_rate_edit_stop'],"d-m-Y","Y-m-d")."'
				");	
			
			$information->editEmployeeSuccess = true; 
			$this->_helper->redirector('edit','employee',null,array('id' => $v['id']));	
		}
		
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	
		$this->view->employeeeditmenu = 1;
		
		$EmployeeTeam = new EmployeeTeam();
		$data = $EmployeeTeam->fetchAll('employeeteam_activ = 0 OR employeeteam_activ = '.$row['employeeteam_id'] , 'employeeteam_name ASC'); 		
		$this->view->dataTableEmployeeTeam = $data;

		$data = $EmploymentType->fetchAll(null , 'employment_type_sort ASC'); 		
		$this->view->dataTableEmploymentType = $data;
	}
	
	
	public function employeeprojectAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();	
		$EmployeeProject = new EmployeeProject();			
		
		if( $information->editEmployeeSuccess ){
			$this->view->editEmployeeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		
		
		
		
		if( isset($v['admin_editemployee']) ){		
		
			$where = array(
				'employee_id = ?' => $v['id']
			);
			$EmployeeProject->delete($where);	

			foreach( $v['permissionProject_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $v['id'],
						'project_id' => $valuep
					);
					$EmployeeProject->insert($data);					
			}
						
			$information->editEmployeeSuccess = true; 
			$this->_helper->redirector('employeeproject','employee',null,array('id' => $v['id']));			
		}
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$Company = new Company();
		$data = $Company->fetchAll(null , 'company_name ASC'); 		
		$this->view->dataTableCompany = $data;

		$dataProject[] = array();		
		$Project = new Project();
		foreach($data as $key => $value){
			$dataProject[$value['company_id']] = $Project->fetchAll('project_activ_employee = 1 AND company_id = '.$value['company_id'], " project_name ASC ");		
		}
		$this->view->dataTableProject = $dataProject;
	
		$this->view->employeeeditmenu = 2;
	}
	
	
	public function employeegroupAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();	
		$EmployeeGroup = new EmployeeGroup();		
		$EmployeeEmployeeGroup = new EmployeeEmployeeGroup();
		
		if( $information->editEmployeeSuccess ){
			$this->view->editEmployeeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['admin_editemployee']) ){		
		
			$where = array(
				'employee_id = ?' => $v['id']
			);
			$EmployeeEmployeeGroup->delete($where);	

			foreach( $v['permissionGroup_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $v['id'],
						'employeegroup_id' => $valuep
					);
					$EmployeeEmployeeGroup->insert($data);					
			}
			
			if( $v['employeegroup_name'] != '' ){				
				$data = array(
					'employeegroup_name' => $v['employeegroup_name']
				);
				$idins = $EmployeeGroup->insert($data);		
				
				$data = array(
					'employee_id' => $v['id'],
					'employeegroup_id' => $idins
				);
				$EmployeeEmployeeGroup->insert($data);	
			
			}
			
			
			Lib_PLW::updateEmployee($v['id']);
					
			$information->editEmployeeSuccess = true; 
			$this->_helper->redirector('employeegroup','employee',null,array('id' => $v['id']));			
		}
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$data = $EmployeeGroup->fetchAll('employeegroup_activ = 0' , 'employeegroup_name ASC'); 		
		$this->view->dataTableEmployeeGroup = $data;
	
		$this->view->employeeeditmenu = 3;
	}	
	
	public function employeealertAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();	
		$EmployeeAlert = new EmployeeAlert();		
		$AlertType = new AlertType();		
		
		$db = Zend_Registry::get('db');	
		
		if( $information->editEmployeeSuccess ){
			$this->view->editEmployeeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['admin_employeealertadd']) ){		

			$data = array(
				'employee_id' => $v['id'],
				'employee_alert_start' => Lib_Date::convertDate($v['employee_alert_start'],"d-m-Y","Y-m-d"),
				'employee_alert_stop' => Lib_Date::convertDate($v['employee_alert_stop'],"d-m-Y","Y-m-d"),
				'alert_type_id' => $v['alert_type_id'],			
				'employee_alert_note' => isset($v['employee_alert_note'])?$v['employee_alert_note']:'',
				'admin_id' => $admin->admin_id
			);
			$EmployeeAlert->insert($data);	
				
			$information->editEmployeeSuccess = true; 
			if( !$v['return'] ) $this->_helper->redirector('employeealert','employee',null,array('id' => $v['id']));						
			if( $v['return'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));
		}
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		
		
		
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
		
		$p = ($page-1)*$limit;	
		
	/*	
		if( !$v['filtr_data_1'] AND !$v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id'] , array('employee_alert_start ASC','employee_alert_stop ASC')); 	
		}
		
		if( $v['filtr_data_1'] AND !$v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC')); 		
		}
		
		
		if( !$v['filtr_data_1'] AND $v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		}
		
		
		if( $v['filtr_data_1'] AND $v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."'"." AND employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		}
	*/

		$searchDataAlert = '';
		if( $v['filtr_data_1'] ){
		//	$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."')";
			$searchDataAlert = "AND (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."' OR employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."')";
		}		
		if( $v['filtr_data_2'] ){
		//	$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."')";
			$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."' OR employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."')";
		}
		if( $v['filtr_data_1'] AND $v['filtr_data_2'] ){
		
			$searchDataAlert = "AND (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."' OR employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."')";
			$searchDataAlert = $searchDataAlert."AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."' OR employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."')";
		}		
		
		$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." ".$searchDataAlert , array('employee_alert_start DESC','employee_alert_stop DESC')); 		
			
		$dataCount = count($data);
			
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('employeealert');
		$Lib_Page->setGet('/id/'.$v['id'].'?filtr_data_1='.$v['filtr_data_1'].'&filtr_data_2='.$v['filtr_data_2']);
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		/*
		if( !$v['filtr_data_1'] AND !$v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id'] , array('employee_alert_start DESC','employee_alert_stop DESC'),$limit,$p); 	
			$this->view->dataTableEmployeeAlert = $data;
		}
		
		
		if( $v['filtr_data_1'] AND !$v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC'),$limit,$p); 	
			$this->view->dataTableEmployeeAlert = $data;		
		}
		
		
		if( !$v['filtr_data_1'] AND $v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC'),$limit,$p); 	
			$this->view->dataTableEmployeeAlert = $data;		
		}
		
		
		if( $v['filtr_data_1'] AND $v['filtr_data_2'] ){
			$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." AND employee_alert_start >= '".Lib_Date::convertDate($v['filtr_data_1'],"d-m-Y","Y-m-d")."'"." AND employee_alert_stop <= '".Lib_Date::convertDate($v['filtr_data_2'],"d-m-Y","Y-m-d")."'" , array('employee_alert_start DESC','employee_alert_stop DESC'),$limit,$p); 	
			$this->view->dataTableEmployeeAlert = $data;		
		};
		*/
	//	echo$searchDataAlert;
		$data = $EmployeeAlert->fetchAll('employee_id = '.$v['id']." ".$searchDataAlert , array('employee_alert_start DESC','employee_alert_stop DESC'),$limit,$p); 
		$this->view->dataTableEmployeeAlert = $data;			
		
		$data = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 		
		$this->view->dataTableAlertType = $data;
	
		$this->view->employeeeditmenu = 4;
	
		$this->view->filtr_data_1 = $v['filtr_data_1'];
		$this->view->filtr_data_2 = $v['filtr_data_2'];
	
	}
	
	
	public function employeemobiAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		
		if( $information->editEmployeeMobiSuccess ){
			$this->view->editEmployeeMobiSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['admin_editemployee']) ){		
		
			$employee_mobilogin = $v['employee_mobilogin'];
			$employee_mobipass = $v['employee_mobipass'];
		
			$data = array(
				'employee_mobi' => isset($v['employee_mobi'])?$v['employee_mobi']:0,
				'employee_mobilogin' => $v['employee_mobilogin'],
				'employee_mobipass' => hash('sha256',$v['employee_mobipass']),
				'employee_edit' => Lib_Date::datetime()
			);
			$Employee->update( $data , 'employee_id='.$v['id'] );

			if( !$v['return'] ){
				$information->editEmployeeMobiSuccess = true;
				$this->_helper->redirector('employeemobi','employee',null,array('id' => $v['id']));
			}
			if( $v['return'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));	
		}		
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	
		$this->view->employeeeditmenu = 5;
		
		$EmployeeTeam = new EmployeeTeam();
		$data = $EmployeeTeam->fetchAll('employeeteam_activ = 0 OR employeeteam_activ = '.$row['employeeteam_id'] , 'employeeteam_name ASC'); 		
		$this->view->dataTableEmployeeTeam = $data;
	}
	
	
	public function employeedocumentsAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		
		if( $information->editEmployeeMobiSuccess ){
			$this->view->editEmployeeMobiSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	
		$this->view->employeeeditmenu = 6;
		
		$EmployeeTeam = new EmployeeTeam();
		$data = $EmployeeTeam->fetchAll('employeeteam_activ = 0 OR employeeteam_activ = '.$row['employeeteam_id'] , 'employeeteam_name ASC'); 		
		$this->view->dataTableEmployeeTeam = $data;
	}
	
	
	public function employeemobihistorylogAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		$v = $this->_request->getParams();		
		
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$EmployeeMobiHistoryLog = new EmployeeMobiHistoryLog();	
		$dataCount = count($EmployeeMobiHistoryLog->fetchAll('employee_id = '.$v['id'] , 'employee_mobi_history_log_date DESC')); 
			$p = ($page-1)*$limit;		
		$data = $EmployeeMobiHistoryLog->fetchAll('employee_id = '.$v['id'] , 'employee_mobi_history_log_date DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('employeemobihistorylog');
		$Lib_Page->setGet('/id/'.$v['id']);
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	
		$this->view->employeeeditmenu = 5;
		
		$EmployeeTeam = new EmployeeTeam();
		$data = $EmployeeTeam->fetchAll('employeeteam_activ = 0 OR employeeteam_activ = '.$row['employeeteam_id'] , 'employeeteam_name ASC'); 		
		$this->view->dataTableEmployeeTeam = $data;
	}
	
	public function employeemobicheckloginAction() {
		header("Content-Type:text/plain");
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$valid = 0;
		// $valid = 0 - nie istnieje w bazie
		// $valid = 1 - istnieje w bazie
		
		$Employee = new Employee();	
		$select = $Employee->select();		
		$select->where('employee_mobilogin = ?', $v['employee_mobilogin']);		
		$select->where('employee_id != '.$v['employee_id']);					
		$row = $Employee->fetchRow($select);
		unset($Employee);		

		if( isset($row) ) $valid = 1;
		else $valid = 0;
			
		echo $valid;
	}
	
	public function editalertAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();	
		$EmployeeAlert = new EmployeeAlert();			
		$AlertType = new AlertType();	
		
		$db = Zend_Registry::get('db');	
		
		if( $information->editEmployeeSuccess ){
			$this->view->editEmployeeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['admin_employeealertedit']) ){		

			$data = array(
				'employee_alert_start' => Lib_Date::convertDate($v['employee_alert_start'],"d-m-Y","Y-m-d"),
				'employee_alert_stop' => Lib_Date::convertDate($v['employee_alert_stop'],"d-m-Y","Y-m-d"),
				'alert_type_id' => $v['alert_type_id'],						
				'employee_alert_note' => isset($v['employee_alert_note'])?$v['employee_alert_note']:''
			);
			$EmployeeAlert->update($data, 'employee_alert_id='.$v['ida'] );
				
			$information->editEmployeeSuccess = true; 
			$this->_helper->redirector('employeealert','employee',null,array('id' => $v['id']));			
		}
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$select = $EmployeeAlert->select();
		$select->where('employee_alert_id = ?', $v['ida']);	
		$row = $EmployeeAlert->fetchRow($select);
		$this->view->employeeAlertData = $row;
		
		
		$data = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 		
		$this->view->dataTableAlertType = $data;
			
		$this->view->employeeeditmenu = 4;
	}
	
	public function removealertAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$EmployeeAlert = new EmployeeAlert();
		$where = array(
			'employee_alert_id = ?' => $v['ida']
		);
		$EmployeeAlert->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('employeealert','employee',null,array('id' => $v['id']));		
	}
	
	public function removeAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$Employee = new Employee();
		$where = array(
			'employee_id = ?' => $v['id']
		);
		$Employee->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('index','employee');		
	}
	
	
	public function groupAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployee');
		$db = Zend_Registry::get('db');

		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$searchEmployeeName = null;
		
		
		
		if( isset($v['filtrLimit']) ){
			$filtremployee->limit = $v['filtrLimit'];
			$this->_helper->redirector('group','employee');	
		}
		
		if( isset($vPost['employeegroup_activ_p']) ){
			$filtremployee->employeegroup_activ = $vPost['employeegroup_activ'];
			$this->_helper->redirector('group','employee');	
		}
		if( $filtremployee->employeegroup_activ ){
			$this->view->employeegroup_activ =  $filtremployee->employeegroup_activ;
		}
		
		// filtr nazwa grupy - poczatek
		if( isset($vPost['removeEmployeeName']) ){
			unset($filtremployee->employeegroup_name);
			$this->_helper->redirector('group','employee');	
		}
		if( isset($vPost['filtrEmployeeName']) ){
			$filtremployee->employeegroup_name = $vPost['filtrEmployeeName'];
			$information->addFiltrEmployeeNameSuccess = true;
			$this->_helper->redirector('group','employee');	
		}		
		if( $filtremployee->employeegroup_name ){
			$this->view->filtr_name_employee =  $filtremployee->employeegroup_name;
			
			
			$searchEmployee = explode(" ",$filtremployee->employeegroup_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employeegroup_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employeegroup_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		
		if( $filtremployee->employeegroup_activ != 1 ){
		
				if( !$searchEmployeeName ){
				
					$searchEmployeeName = "
						(
							employeegroup_activ = 0
						)
					";
				}else{
				
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employeegroup_activ = 0
						)
					";
				
				}
				
		}
	//	echo$searchEmployeeName;die();
		
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa grupy - koniec
		// ==========================================================
		
				
		if( !$filtremployee->limit ){
			$filtremployee->limit = 10;
		}
		
		if( !isset($search) ){
			$search = null;
		}
		
		$this->view->filtrLimit =  $filtremployee->limit;
		$limit = $filtremployee->limit;
		$limitpage = 10;
		
		$orderEmployee = array('employeegroup_name ASC');

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$EmployeeGroup = new EmployeeGroup();	
		$dataCount = count($EmployeeGroup->fetchAll($searchEmployeeName , $orderEmployee)); 
			$p = ($page-1)*$limit;		
		$data = $EmployeeGroup->fetchAll($searchEmployeeName , $orderEmployee, $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('group');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
		
	}
	
	public function removegroupAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		
		$EmployeeGroup = new EmployeeGroup();
		$where = array(
			'employeegroup_id = ?' => $v['id'],
			'employeegroup_nodel = ?' => 0
		);
	//	$EmployeeGroup->delete($where);	
		$information->removeSuccess = true; 
		$this->_helper->redirector('group','employee');		
	}
	
	
	
	
	public function checkarchiveAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployeeteam');
		$db = Zend_Registry::get('db');

		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
				
		if( !$filtremployee->limit ){
			$filtremployee->limit = 25;
		}
		
		if( !isset($search) ){
			$search = null;
		}
		
		$this->view->filtrLimit =  $filtremployee->limit;
		$limit = $filtremployee->limit;
		$limitpage = 10;
		
		$orderCheck = array('check_ins desc');

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Check = new Check();	
		$dataCount = count($Check->fetchAll(null , $orderCheck)); 
			$p = ($page-1)*$limit;		
		$data = $Check->fetchAll(null , $orderCheck, $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('checkarchive');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
		
	}
	
	public function checkarchivedetailsAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployeeteam');
		$db = Zend_Registry::get('db');

		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
	
		$Check = new Check();	
		$select = $Check->select();
		$select->where('check_id = ?', $v['id']);	
		$row = $Check->fetchRow($select);
		$this->view->employeeCheck = $row;
		
		
		$query = "SELECT * FROM employee_check ec, employee e
				WHERE 
					e.employee_id = ec.employee_id 
				AND 
					ec.check_id = ".$v['id']."
				ORDER BY 
				employee_secondname ASC, employee_firstname ASC";
		$dataEmployee = $db->query($query)->fetchAll();			
		$this->view->dataTable = $dataEmployee;		
	}
	
	
	
	
	// */*/*/*/*/*/*/*/*/*/*/*/ pracownicy w zespołach - poczatek */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
	
	
	public function teamAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtremployee = new Zend_Session_Namespace('filtremployeeteam');
		$db = Zend_Registry::get('db');

		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$searchEmployeeName = null;
		
		
		
		if( isset($v['filtrLimit']) ){
			$filtremployee->limit = $v['filtrLimit'];
			$this->_helper->redirector('team','employee');	
		}
		
		if( isset($vPost['employeegroup_activ_p']) ){
			$filtremployee->employeegroup_activ = $vPost['employeegroup_activ'];
			$this->_helper->redirector('team','employee');	
		}
		if( $filtremployee->employeegroup_activ ){
			$this->view->employeegroup_activ =  $filtremployee->employeegroup_activ;
		}
		
		// filtr nazwa grupy - poczatek
		if( isset($vPost['removeEmployeeName']) ){
			unset($filtremployee->employeegroup_name);
			$this->_helper->redirector('team','employee');	
		}
		if( isset($vPost['filtrEmployeeName']) ){
			$filtremployee->employeegroup_name = $vPost['filtrEmployeeName'];
			$information->addFiltrEmployeeNameSuccess = true;
			$this->_helper->redirector('team','employee');	
		}		
		if( $filtremployee->employeegroup_name ){
			$this->view->filtr_name_employee =  $filtremployee->employeegroup_name;
			
			
			$searchEmployee = explode(" ",$filtremployee->employeegroup_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeName ){
					$searchEmployeeName = "
						(
							employeeteam_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employeeteam_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		
		if( $filtremployee->employeegroup_activ != 1 ){
		
				if( !$searchEmployeeName ){
				
					$searchEmployeeName = "
						(
							employeeteam_activ = 0
						)
					";
				}else{
				
					$searchEmployeeName = $searchEmployeeName."
						AND (
							employeeteam_activ = 0
						)
					";
				
				}
				
		}
	//	echo$searchEmployeeName;die();
		
		if( !isset($searchEmployeeName) ){
			$searchEmployeeName = null;
		}
		// filtr nazwa grupy - koniec
		// ==========================================================
		
				
		if( !$filtremployee->limit ){
			$filtremployee->limit = 100;
		}
		
		if( !isset($search) ){
			$search = null;
		}
		
		$this->view->filtrLimit =  $filtremployee->limit;
		$limit = $filtremployee->limit;
		$limitpage = 10;
		
		$orderEmployee = array('employeeteam_name ASC');

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$EmployeeTeam = new EmployeeTeam();	
		$dataCount = count($EmployeeTeam->fetchAll($searchEmployeeName , $orderEmployee)); 
			$p = ($page-1)*$limit;		
		$data = $EmployeeTeam->fetchAll($searchEmployeeName , $orderEmployee, $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('team');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
		
	}
	
	
	public function addteamAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		
		// $Employee = new Employee();	
		$EmployeeTeam = new EmployeeTeam();		
		
		$v = $this->_request->getPost();
		if( isset($v['admin_addemployeeteam']) ){
		
			$data = array(
				'employeeteam_name' => $v['employeeteam_name']
			);
			$idIns = $EmployeeTeam->insert($data);

			/*
			foreach( $v['permissionEmployee_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $valuep,
						'employeegroup_id' => $idIns
					);
					$EmployeeEmployeeGroup->insert($data);					
			}
			*/
			$this->_helper->redirector('team','employee');	
			
		}	
		/*
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');
		$data = $Employee->fetchAll(null , $orderEmployee); 		
		$this->view->dataTableEmployee = $data;	
		*/
	}
	
	
	public function editteamAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		
	//	$Employee = new Employee();	
		$EmployeeTeam = new EmployeeTeam();	
	//	$EmployeeEmployeeGroup = new EmployeeEmployeeGroup();		
		
		$v = $this->_request->getParams();		
		
		if( isset($v['admin_addemployeeteam']) ){
		
		
			$data = array(
				'employeeteam_name' => $v['employeeteam_name'],
				'employeeteam_activ' => $v['employeeteam_activ']
			);
			$EmployeeTeam->update( $data , 'employeeteam_id='.$v['id'] );	
		
		/*
			$where = array(
				'employeegroup_id = ?' => $v['id']
			);
			$EmployeeEmployeeGroup->delete($where);

			foreach( $v['permissionEmployee_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $valuep,
						'employeegroup_id' => $v['id']
					);
					$EmployeeEmployeeGroup->insert($data);

				if( $v['id'] == 6 ) Lib_PLW::updateEmployee($valuep);					
			}

			foreach( $v['employee_rate'] as $keyp => $valuep ){	
		
				$data = array(
					'employee_rate' => isset($valuep)?str_replace(",",".",$valuep):'0.00',
					'employee_edit' => Lib_Date::datetime()
				);
				$Employee->update( $data , 'employee_id='.$keyp );
			
			}
		*/	
			$this->_helper->redirector('team','employee');	
			
		}	
	
		/*	
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');
		$data = $Employee->fetchAll(null , $orderEmployee); 		
		$this->view->dataTableEmployee = $data;	
		*/		
		
		$select = $EmployeeTeam->select();
		$select->where('employeeteam_id = ?', $v['id']);	
		$row = $EmployeeTeam->fetchRow($select);
		$this->view->employeeGroupData = $row;

	}
	
	
	
	
	
	
	
	
	
	
	
	
	// */*/*/*/*/*/*/*/*/*/*/*/ pracownicy w projektach - poczatek */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
	
	
	
	public function projectAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		if( $information->addProjectSuccess ){
			$this->view->addProjectSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrCompanySuccess ){
			$this->view->addFiltrCompanySuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrCompanyRemove ){
			$this->view->addFiltrCompanyRemove = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrStatusSuccess ){
			$this->view->addFiltrStatusSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrStatusRemove ){
			$this->view->addFiltrStatusRemove = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		
		
		
		
		
		
		if( isset($v['filtrLimit']) ){
			$filtrproject->limit = $v['filtrLimit'];
			$this->_helper->redirector('project','employee');	
		}
		
		
		if( isset($vPost['filtrCompany']) ){
			if( $vPost['filtrCompany'] != 'all' ){
				$filtrproject->company_id = $vPost['filtrCompany'];
				$information->addFiltrCompanySuccess = true;
			}else{
				//Zend_Session::namespaceUnset('filtrproject');
				unset($filtrproject->company_id);
				$information->addFiltrCompanyRemove = true;
			}
			$this->_helper->redirector('project','employee');	
		}
		
		if( isset($vPost['filtrProjectStatus']) ){
			if( $vPost['filtrProjectStatus'] != 'all' ){
				$filtrproject->project_status = $vPost['filtrProjectStatus'];
				$information->addFiltrStatusSuccess = true;
			}else{
				//Zend_Session::namespaceUnset('filtrproject');
				unset($filtrproject->project_status);
				$information->addFiltrStatusRemove = true;
			}
			$this->_helper->redirector('project','employee');	
		}
		
		if( $filtrproject->company_id ){
			$this->view->filtr_company_id =  $filtrproject->company_id;
			$search = 'company_id='.$filtrproject->company_id;
		}
		
		if( $filtrproject->project_status ){
			$this->view->filtr_project_status =  $filtrproject->project_status;
			$status = $filtrproject->project_status - 1;
			if( isset($search) ) $search = $search.' AND project_status='.$status;
			else $search = 'project_status='.$status;
		}
		
		
		// opcje dodatkowe - początek		
		if( isset($vPost['filtrAnalysis_Check']) ){
			if( $vPost['filtr_project_analysis'] != 0 ){
				$filtrproject->filtr_project_analysis = $vPost['filtr_project_analysis'];
			}
			else{
				unset($filtrproject->filtr_project_analysis);
			}
			$this->_helper->redirector('project','employee');	
		}		
		if( $filtrproject->filtr_project_analysis ){
			$this->view->filtr_project_analysis =  $filtrproject->filtr_project_analysis;

			if( $filtrproject->filtr_project_analysis == 1 ){
				$analysis_status = 1;
			}
			if( $filtrproject->filtr_project_analysis == 2 ){
				$analysis_status = 0;
			}
			if( isset($search) ) $search = $search.' AND project_activ_analysis = '.$analysis_status;
			else $search = 'project_activ_analysis = '.$analysis_status;	
		}	
		// opcje dodatkowe - koniec
		
		
		
		if( isset($search) ) $search = $search;
		else $search = null;
		
		if( !isset($search) ){
			$search = null;
		}
		
		
		
		
		
		
		$searchEmployeeProjectName = null;
		
		
		// filtr nazwa projektu - poczatek
		if( isset($vPost['removeEmployeeProjectName']) ){
			unset($filtrproject->employee_project_name);
			$information->addFiltrCompanyRemove = true;
			$this->_helper->redirector('project','employee');	
		}
		if( isset($vPost['filtrEmployeeProjectName']) ){
			$filtrproject->employee_project_name = $vPost['filtrEmployeeProjectName'];
			$information->addFiltrStatusSuccess = true;
			$this->_helper->redirector('project','employee');	
		}		
		if( $filtrproject->employee_project_name ){
			$this->view->filtr_name_employeeproject =  $filtrproject->employee_project_name;
			
			$searchEmployee = explode(" ",$filtrproject->employee_project_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeProjectName ){
					$searchEmployeeProjectName = "
						(
							project_name LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							project_nr LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeProjectName = $searchEmployeeProjectName."
						AND (
							project_name LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							project_nr LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeProjectName) ){
			$searchEmployeeProjectName = null;
		}
		// filtr nazwa projektu - koniec
		// ==========================================================
		
		
		
		
		
		
		$searchEmployeeNameName = null;
		
		
		// filtr osoba prowadzaca - poczatek
		if( isset($vPost['removeEmployeeNameName']) ){
			unset($filtrproject->employee_name_name);
			$information->addFiltrCompanyRemove = true;
			$this->_helper->redirector('project','employee');	
		}
		if( isset($vPost['filtrEmployeeNameName']) ){
			$filtrproject->employee_name_name = $vPost['filtrEmployeeNameName'];
			$information->addFiltrStatusSuccess = true;
			$this->_helper->redirector('project','employee');	
		}		
		if( $filtrproject->employee_name_name ){
			$filtrproject->employee_name_name = str_replace("\\",'',$filtrproject->employee_name_name);
			$this->view->filtr_name_employeename = $filtrproject->employee_name_name;
		/*	
			$searchEmployee = explode(" ",$filtrproject->employee_name_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeNameName ){
					$searchEmployeeNameName = "
						(
							project_employee_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeNameName = $searchEmployeeNameName."
						AND (
							project_employee_name LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}*/
			
					$searchEmployeeNameName = "
						(
							project_employee_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."' OR
							project_employee_manager_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."' OR
							project_employee_cetla_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."'
						)
					";
			
		}
		if( !isset($searchEmployeeNameName) ){
			$searchEmployeeNameName = null;
		}
		// filtr osoba prowadzaca - koniec
		// ==========================================================
		
		
		
		
		
		if( $search == null AND $searchEmployeeProjectName != null ){
			$search = $searchEmployeeProjectName;
		}
		
		if( $search != null AND $searchEmployeeProjectName != null ){
			$search = $search.' AND '.$searchEmployeeProjectName;
		}
		
		
		if( $search == null AND $searchEmployeeNameName != null ){
			$search = $searchEmployeeNameName;
		}
		
		if( $search != null AND $searchEmployeeNameName != null ){
			$search = $search.' AND '.$searchEmployeeNameName;
		}
		
		if( !$filtrproject->limit ){
			$filtrproject->limit = 10;
		}
		
		if( $search != null ){
			$search = $search.' AND project_activ_employee = 1';
		}else{
			$search = 'project_activ_employee = 1';		
		}
		
		$this->view->filtrLimit =  $filtrproject->limit;
		$limit = $filtrproject->limit;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
			
		$Project = new Project();	
		$dataCount = count($Project->fetchAll($search , 'project_ins DESC')); 
			$p = ($page-1)*$limit;		
		$data = $Project->fetchAll($search , 'project_ins DESC', $limit,$p); 		
		$this->view->dataTable = $data;		
	
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('project');
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;		
		
		$Company = new Company();
		$data = $Company->fetchAll(null, " company_name ASC "); 		
		if( count($data) > 0 ) $this->view->dataTableCompany = $data;
		
	}
	
	
	public function projectpdfAction() {
		$this->_helper->viewRenderer->setNoRender();		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();

		
		if( $filtrproject->company_id ){
			$search = 'company_id='.$filtrproject->company_id;
		}
		
		if( $filtrproject->project_status ){
			$status = $filtrproject->project_status - 1;
			if( isset($search) ) $search = $search.' AND project_status='.$status;
			else $search = 'project_status='.$status;
		}
		
		if( isset($search) ) $search = $search;
		else $search = null;
		
		if( !isset($search) ){
			$search = null;
		}
		
		$searchEmployeeProjectName = null;		
		
		// filtr nazwa projektu - poczatek
		
		if( $filtrproject->employee_project_name ){
			$searchEmployee = explode(" ",$filtrproject->employee_project_name);
			foreach($searchEmployee as $searchEmployeeKey => $searchEmployeeVal){
			
				if( !$searchEmployeeProjectName ){
					$searchEmployeeProjectName = "
						(
							project_name LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							project_nr LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";
				}else{
					$searchEmployeeProjectName = $searchEmployeeProjectName."
						AND (
							project_name LIKE '".str_replace("*","%",$searchEmployeeVal)."' OR
							project_nr LIKE '".str_replace("*","%",$searchEmployeeVal)."'
						)
					";				
				}
			
			}
		}
		if( !isset($searchEmployeeProjectName) ){
			$searchEmployeeProjectName = null;
		}
		// filtr nazwa projektu - koniec
		// ==========================================================		
		
		$searchEmployeeNameName = null;		
		
		// filtr osoba prowadzaca - poczatek
		
		if( $filtrproject->employee_name_name ){
			$filtrproject->employee_name_name = str_replace("\\",'',$filtrproject->employee_name_name);

					$searchEmployeeNameName = "
						(
							project_employee_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."' OR
							project_employee_manager_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."' OR
							project_employee_cetla_name LIKE '".str_replace("*","%",$filtrproject->employee_name_name)."'
						)
					";
			
		}
		if( !isset($searchEmployeeNameName) ){
			$searchEmployeeNameName = null;
		}
		// filtr osoba prowadzaca - koniec
		// ==========================================================		
		
		if( $search == null AND $searchEmployeeProjectName != null ){
			$search = $searchEmployeeProjectName;
		}
		
		if( $search != null AND $searchEmployeeProjectName != null ){
			$search = $search.' AND '.$searchEmployeeProjectName;
		}		
		
		if( $search == null AND $searchEmployeeNameName != null ){
			$search = $searchEmployeeNameName;
		}
		
		if( $search != null AND $searchEmployeeNameName != null ){
			$search = $search.' AND '.$searchEmployeeNameName;
		}
		
		if( !$filtrproject->limit ){
			$filtrproject->limit = 10;
		}
		
		if( $search != null ){
			$search = $search.' AND project_activ_employee = 1';
		}else{
			$search = 'project_activ_employee = 1';		
		}

			
		$Project = new Project();			
		$dataTable = $Project->fetchAll($search , 'project_ins DESC'); 	
		
		
		
		
		$pxTab = array(30,400,60,150,220,150);
		
		
		$html = $html.'
		<table border="1" cellpadding="5" cellspacing="0">
			<thead>
				<tr style="font-weight: bold;">
					<th width="'.$pxTab[0].'">'.@LANG_project_list_lp.'</th>
					<th width="'.$pxTab[1].'">'.@LANG_project_list_name.' / '.@LANG_company_list_name.'</th>
					<th width="'.$pxTab[2].'">'.@LANG_project_list_nrproj.'</th>
					<th width="'.$pxTab[3].'">'.@LANG_project_list_m2.'</th>	
					<th width="'.$pxTab[4].'"></th>		
					<th width="'.$pxTab[5].'">'.@LANG_project_list_status.'</th>			
		';		
		
		$html = $html.'
				</tr>
			</thead>
			<tbody>
		';
			
			
			
			
		$i=0; 
		$sumt = 0; 
		$sumAll = 0;
		foreach ($dataTable as $key => $val){ 
			$i=$i+1;
		
			$company = Lib_Project::CompanyName($val['company_id']);
			
			$ddd = '';
			if( $val['project_date_start'] != '0000-00-00' OR $val['project_date_stop'] != '0000-00-00' ){
					
				$ddd = '<br /><br />'.@LANG_project_list_date_a.' ';	
						
				if( $val['project_date_start'] != '0000-00-00' ){
					$ddd = $ddd.Lib_Date::convertDate($val['project_date_start']).' - ';
				}else{
					$ddd = $ddd.'... - ';
				}
	
				if( $val['project_date_stop'] != '0000-00-00' ){
					$ddd = $ddd.Lib_Date::convertDate($val['project_date_stop']);
				}else{
					$ddd = $ddd.'...';
				}
					
			}
		
			if( $val['project_percent']<=90 ){ 
				$color = 'green';
			}else{
				$color = 'red';
			}



			$rowPro = Lib_Employee::Project($val['project_id']);
				
			$stanPrac = '';
				
			// WDVS
			if( $val['project_m2'] != -1 ){
				$stanPrac = $stanPrac.''.@LANG_project_list_m2_a.'&nbsp;<b>'.number_format($val['project_m2'], 0, ',', '&nbsp;').'&nbsp;m<sup>2</sup></b><br />';
			}else{
				
			}
				
			if( $val['project_h'] != -1 ){
				$stanPrac = $stanPrac.''.@LANG_project_list_h_a.'&nbsp;<b>'.number_format($val['project_h'], 0, ',', '&nbsp;').'</b><br />';
			}else{
				
			}

			// Klinkier
			if( $val['project_m2_clinker'] != -1 ){
				$stanPrac = $stanPrac.@LANG_project_list_m2_a_clinker.'&nbsp;<b>'.number_format($val['project_m2_clinker'], 0, ',', '&nbsp;').'&nbsp;m<sup>2</sup></b><br />';
			}else{

			}
				
			if( $val['project_h_clinker'] != -1 ){
				$stanPrac = $stanPrac.@LANG_project_list_h_a_clinker.'&nbsp;<b>'.number_format($val['project_h_clinker'], 0, ',', '&nbsp;').'</b><br />';
			}else{

			}
			
			if( $val['project_h'] != -1 OR $rowPro > 0 ){
				$class = 'green';
			
				if( $val['project_h'] != -1 AND $rowPro > $val['project_h'] ){
					$class="red";
				}
			
				$stanPrac = $stanPrac.''.@LANG_project_list_m2_b.'&nbsp;<b style="color:'.$class.'">'.number_format($rowPro, 1, ',', '&nbsp;').'</b><br />';
			
				if( $val['project_h'] != -1 ){
				
					$roz = $val['project_h'] - $rowPro;
				
					$stanPrac = $stanPrac.''.@LANG_project_list_m2_c.'&nbsp;<b style="color:'.$class.'">'.number_format($roz, 1, ',', '&nbsp;').'</b><br />';
				}
			}
			
			
			$osoby = '';
	
			if( $val['project_employee_name'] != '' ){
				$osoby = $osoby. '<b>'.@LANG_project_list_emp.'</b> ';
				$osoby = $osoby.$val['project_employee_name'].' ';
				if( $val['project_employee_phone'] != '' ){
					$osoby = $osoby.'('.$val['project_employee_phone'].')';				
				}
				$osoby = $osoby.'<br />';
			}
						
			if( $val['project_employee_manager_name'] != '' ){
				$osoby = $osoby. '<b>'.@LANG_project_list_empmanager.'</b> ';
				$osoby = $osoby.$val['project_employee_manager_name'].' ';
				if( $val['project_employee_manager_phone'] != '' ){
					$osoby = $osoby.'('.$val['project_employee_manager_phone'].')';				
				}
				$osoby = $osoby.'<br />';
			}
						
			if( $val['project_employee_cetla_name'] != '' ){
				$osoby = $osoby. '<b>'.@LANG_project_list_empcetla.'</b> ';
				$osoby = $osoby.$val['project_employee_cetla_name'].' ';
				if( $val['project_employee_cetla_phone'] != '' ){
					$osoby = $osoby.'('.$val['project_employee_cetla_phone'].')';				
				}
				$osoby = $osoby.'<br />';
			}
			
			$osoby = $osoby. @LANG_project_list_employee_count1." ".Lib_Employee::EmployeeCount($val['project_id']);			
			

		
			if( $val['project_status'] == 0 ){
				$aktywny = '<font style="margin:10px;background-color:green;color:#fff;">'.@LANG_project_active.'</font>';
			}else{
				$aktywny = '<font style="margin:10px;background-color:red;color:#fff;">'.@LANG_project_inactive.'</font>';
			}		
			
			
			if( $val['project_status_finish'] == 1 ) $col1 = 'green'; else $col1 = 'red';			
			if( $val['project_status_calc'] == 1 ) $col2 = 'green'; else $col2 = 'red';
			
			
			$aktywny2 = '
				<br /><br />
				<table cellpadding="1">
				
					<tr>
						<td width="100">'.@LANG_project_list_status_1.'</td> 
						<td width="25"><font style="background-color:'.$col1.';color:'.$col1.';">&nbsp;&nbsp;&nbsp;</font></td>
					</tr>
					<tr>
						<td width="100">'.@LANG_project_list_status_2.'</td> 
						<td width="25"><font style="background-color:'.$col2.';color:'.$col2.';">&nbsp;&nbsp;&nbsp;</font></td>
					</tr>
					
				</table>
			';
			
			
			$html = $html.'
				<tr>
					<td width="'.$pxTab[0].'">'.$i.'</td>
					<td width="'.$pxTab[1].'">
						'.$val['project_name'].'
						<br />
						'.$company['company_name'].'
						'.$ddd.'
					</td>
					<td width="'.$pxTab[2].'">
						'.$val['project_nr'].'
						<br /><br />
						<font style="color:'.$color.';font-size: 15px;font-weight: bold;">'.$val['project_percent'].'%</font>
					</td>
					<td width="'.$pxTab[3].'">
						'.$stanPrac.'
					</td>
					<td width="'.$pxTab[4].'">
						'.$osoby.'
					</td>
					<td width="'.$pxTab[5].'">
						<p style="text-align:center;">'.$aktywny.'</p>
						'.$aktywny2.'
					</td>
				</tr>
			';
		
		}
	
		
		
		
		$html = $html.'

			</tbody>
		</table>
		';
		
		
		
		$name = mb_strtolower (@LANG_employeeproject_list_top, 'UTF-8');
		$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
		$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
		
		// set document information
		$pdf->SetCreator(PDF_CREATOR);
		$pdf->SetAuthor('www.TECHNIX.pl');
		$pdf->SetTitle($nameFile);
		$pdf->SetSubject($nameFile);
		$pdf->SetKeywords($nameFile);
		$pdf->setPrintHeader(false);
		
		// set default header data
		$pdf->setFooterData(array(0,64,0), array(0,64,128));

		// set header and footer fonts
		$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

		// set default monospaced font
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

		// set margins
		$pdf->SetMargins(5, 5, 5);

		// set auto page breaks
		$pdf->SetAutoPageBreak(TRUE, 5);

		// set image scale factor
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

		// ---------------------------------------------------------

		// set default font subsetting mode
		$pdf->setFontSubsetting(true);

		// Set font
		// dejavusans is a UTF-8 Unicode font, if you only need to
		// print standard ASCII chars, you can use core fonts like
		// helvetica or times to reduce file size.
		$pdf->SetFont('dejavusans', '', 7, '', true);

		// Add a page
		// This method has several options, check the source code documentation for more information.
		$pdf->AddPage('L','A4');
		
		$pdf->writeHTML($html, true, 0, true, true);
		
		ob_end_clean();
		if( $save == false ) $pdf->Output($nameFile.'.pdf', 'I');
		else{
			$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
			$pdf->Output($file, 'F');
			return $file;
		}		
	}
	
	
	
	public function projectemployeeAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
	
		$Project = new Project();
		$Employee = new Employee();	
		$EmployeeProject = new EmployeeProject();	
		
		if( isset($v['admin_addemployeeproject']) ){	
		
			$where = array(
				'project_id = ?' => $v['id']
			);
			$EmployeeProject->delete($where);

			foreach( $v['permissionEmployee_id'] as $keyp => $valuep ){						
					$data = array(
						'employee_id' => $valuep,
						'project_id' => $v['id']
					);
					$EmployeeProject->insert($data);					
			}
			
			if( !$v['return'] ) $this->_helper->redirector('project','employee');	
			
			if( $v['return'] AND $v['return_n'] AND $v['return_id'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');
		
		$orderEmployee = array('employee_activ ASC','employee_secondname ASC','employee_firstname ASC');
		$data = $Employee->fetchAll(null , $orderEmployee); 		
		$this->view->dataTableEmployee = $data;	
	
	}
	
	
	
	public function projectsettlementAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( isset($v['employee_projectsettlementadd']) ){	

			foreach( $v['employee_newsettlement'] as $idemp => $val ){						
					$data = array(
						'employee_id' => $idemp,
						'project_id' => $v['id'],
						'employee_settlement_date' => Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d"),
						'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'][$idemp],"H:i","H:i:s"),
						'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'][$idemp],"H:i","H:i:s"),			
						'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'][$idemp],"H:i","H:i:s"),
						'employee_settlement_rate' => isset($v['employee_settlement_rate'][$idemp])?str_replace(",",".",$v['employee_settlement_rate'][$idemp]):'0.00',			
						'employee_settlement_note' => isset($v['employee_settlement_note'][$idemp])?str_replace(",",".",$v['employee_settlement_note'][$idemp]):'',
						'employee_settlement_ins' => Lib_Date::datetime(),
						'employee_settlement_edit' => Lib_Date::datetime(),
						'admin_id' => $admin->admin_id
					);
					
					var_dump($data);echo'<hr />';
					
					$EmployeeSettlement->insert($data);			
			
					$select = $db->select();
					$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
					$select->where("employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'");
					$select->where('employee_id = '.$idemp); 
					$stmt = $db->query($select);
					$data = $stmt->fetchAll();	
					$dataCount = $data[0]['count'];	
					
					$data = array(
						'employee_settlement_datecount' => $dataCount
					);
					$EmployeeSettlement->update($data, "employee_id = ".$idemp." AND employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'" );
			
			}	
			
					
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('projectsettlement','employee',null,array('id' => $v['id']));	
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');

		$query = "SELECT * FROM employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_project
				WHERE 
					e.employee_id = employee_project.employee_id 
				AND 
					employee_activ = 0
				AND
					employee_project.project_id = ".$v['id']."
				ORDER BY 
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC";
		$dataEmployee = $db->query($query)->fetchAll();			
		$this->view->dataTableEmployee = $dataEmployee;		
	
		if( !isset($v['date']) ){
			$EmployeeSettlement = new EmployeeSettlement();	
			$select = $EmployeeSettlement->select();
			$select->where('project_id = ?', $v['id']);	
			$select->order('employee_settlement_date DESC');
			$row = $EmployeeSettlement->fetchRow($select);
			$this->view->employeeSettlementLast = $row;
			
			if( $row['employee_settlement_date'] ){
				$dateTime = new DateTime($row['employee_settlement_date']); 
				$newDate = $dateTime->format('U'); 
				$newDate = $newDate + 24*60*60;
				$this->view->employeeSettlementNewDate = date('d-m-Y', $newDate);
			}
		}else{
			$this->view->dateselect = Lib_Date::convertDate($v['date'], 'Y-m-d', 'd-m-Y'); 
		}
		
	}
	
	
	
	public function projectsettlementskillAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();	
		$EmployeeSettlementElement = new EmployeeSettlementElement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( isset($v['employee_projectsettlementadd']) ){	

			foreach( $v['employee_newsettlement'] as $idemp => $val ){						
					$data = array(
						'employee_id' => $idemp,
						'project_id' => $v['id'],
						'employee_settlement_date' => Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d"),
						'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'][$idemp],"H:i","H:i:s"),
						'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'][$idemp],"H:i","H:i:s"),			
						'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'][$idemp],"H:i","H:i:s"),
						'employee_settlement_rate' => isset($v['employee_settlement_rate'][$idemp])?str_replace(",",".",$v['employee_settlement_rate'][$idemp]):'0.00',			
						'employee_settlement_note' => isset($v['employee_settlement_note'][$idemp])?str_replace(",",".",$v['employee_settlement_note'][$idemp]):'',
						'employee_settlement_ins' => Lib_Date::datetime(),
						'employee_settlement_edit' => Lib_Date::datetime(),
						'admin_id' => $admin->admin_id
					);					
					
					$idInsEmpSett = $EmployeeSettlement->insert($data);			
			
					$select = $db->select();
					$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
					$select->where("employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'");
					$select->where('employee_id = '.$idemp); 
					$stmt = $db->query($select);
					$data = $stmt->fetchAll();	
					$dataCount = $data[0]['count'];	
					
					$data = array(
						'employee_settlement_datecount' => $dataCount
					);
					$EmployeeSettlement->update($data, "employee_id = ".$idemp." AND employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'" );
					
					foreach( $v['employee_settlement_element_time'][$idemp] as $keySkill => $valSkill ){
						if( $valSkill != '' ){
							$dataSkill = array(
								'employee_settlement_id' => $idInsEmpSett,
								'skill_group_element_id' => $keySkill,
								'employee_settlement_element_time' => Lib_Date::convertDate($valSkill,"H:i","H:i:s")
							);
							$EmployeeSettlementElement->insert($dataSkill);	
						}
					}
			
			}	
			
					
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('projectsettlement','employee',null,array('id' => $v['id']));	
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');

		$query = "SELECT * FROM employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_project
				WHERE 
					e.employee_id = employee_project.employee_id 
				AND 
					employee_activ = 0
				AND
					employee_project.project_id = ".$v['id']."
				ORDER BY 
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC";
		$dataEmployee = $db->query($query)->fetchAll();			
		$this->view->dataTableEmployee = $dataEmployee;		
	
		if( !isset($v['date']) ){
			$EmployeeSettlement = new EmployeeSettlement();	
			$select = $EmployeeSettlement->select();
			$select->where('project_id = ?', $v['id']);	
			$select->order('employee_settlement_date DESC');
			$row = $EmployeeSettlement->fetchRow($select);
			$this->view->employeeSettlementLast = $row;
			
			if( $row['employee_settlement_date'] ){
				$dateTime = new DateTime($row['employee_settlement_date']); 
				$newDate = $dateTime->format('U'); 
				$newDate = $newDate + 24*60*60;
				$this->view->employeeSettlementNewDate = date('d-m-Y', $newDate);
			}
		}else{
			$this->view->dateselect = Lib_Date::convertDate($v['date'], 'Y-m-d', 'd-m-Y'); 
		}
		
		
		
		
		$ask = "
			SELECT sg.*,sge.*, psge.project_skill_group_element_id, psge.project_skill_group_element_h FROM
			skill_group sg,
			skill_group_element sge,
			project_skill_group_element psge
			WHERE
			sg.skill_group_id = sge.skill_group_id
			AND
			sge.skill_group_element_id = psge.skill_group_element_id
			AND
			psge.project_id = ".$v['id']."
			ORDER BY
			sg.skill_group_sort,
			sg.skill_group_id,
			sge.skill_group_element_sort,
			sge.skill_group_element_id
		";
		$dataSkillElement = $db->query($ask)->fetchAll();			
		$this->view->dataSkillElement = $dataSkillElement;	
		
		
		
	}
	
	
	public function projectindexclonedateAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( isset($v['employee_projectsettlementadd']) ){	

			foreach( $v['employee_newsettlement'] as $idemp => $val ){						
					$data = array(
						'employee_id' => $idemp,
						'project_id' => $v['id'],
						'employee_settlement_date' => Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d"),
						'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'][$idemp],"H:i","H:i:s"),
						'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'][$idemp],"H:i","H:i:s"),			
						'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'][$idemp],"H:i","H:i:s"),
						'employee_settlement_rate' => isset($v['employee_settlement_rate'][$idemp])?str_replace(",",".",$v['employee_settlement_rate'][$idemp]):'0.00',			
						'employee_settlement_note' => isset($v['employee_settlement_note'][$idemp])?str_replace(",",".",$v['employee_settlement_note'][$idemp]):'',
						'employee_settlement_ins' => Lib_Date::datetime(),
						'employee_settlement_edit' => Lib_Date::datetime(),
						'admin_id' => $admin->admin_id
					);
					
					var_dump($data);echo'<hr />';
					
					$EmployeeSettlement->insert($data);			
			
					$select = $db->select();
					$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
					$select->where("employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'");
					$select->where('employee_id = '.$idemp); 
					$stmt = $db->query($select);
					$data = $stmt->fetchAll();	
					$dataCount = $data[0]['count'];	
					
					$data = array(
						'employee_settlement_datecount' => $dataCount
					);
					$EmployeeSettlement->update($data, "employee_id = ".$idemp." AND employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'" );
			
			}	
			
					
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('projectindex','employee',null,array('id' => $v['id']));	
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');

		$query = "SELECT * FROM employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_project
				WHERE 
					e.employee_id = employee_project.employee_id 
				AND 
					employee_activ = 0
				AND
					employee_project.project_id = ".$v['id']."
				ORDER BY
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC";
		$dataEmployee = $db->query($query)->fetchAll();			
		$this->view->dataTableEmployee = $dataEmployee;		
	
	
			$EmployeeSettlement = new EmployeeSettlement();	
			$select = $EmployeeSettlement->select();
			$select->where('project_id = ?', $v['id']);	
			$select->where("employee_settlement_date LIKE '".$v['date']."'");	
		//	$select->order('employee_settlement_date DESC');
			$row = $EmployeeSettlement->fetchRow($select);
			$this->view->employeeSettlementLast = $row;
			
			if( $row['employee_settlement_date'] ){
				$dateTime = new DateTime($row['employee_settlement_date']); 
				$newDate = $dateTime->format('U'); 
			//	$newDate = $newDate + 24*60*60;
				$this->view->employeeSettlementNewDate = date('d-m-Y', $newDate);
			}
		
	}
	
	
	public function projectindexeditdateAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		if( isset($v['employee_projectsettlementadd']) ){	
		
			$where = "project_id = '".$v['id']."' AND employee_settlement_date LIKE '".$v['date']."'";
			$EmployeeSettlement->delete($where);

			foreach( $v['employee_newsettlement'] as $idemp => $val ){						
					$data = array(
						'employee_id' => $idemp,
						'project_id' => $v['id'],
						'employee_settlement_date' => Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d"),
						'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'][$idemp],"H:i","H:i:s"),
						'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'][$idemp],"H:i","H:i:s"),			
						'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'][$idemp],"H:i","H:i:s"),
						'employee_settlement_rate' => isset($v['employee_settlement_rate'][$idemp])?str_replace(",",".",$v['employee_settlement_rate'][$idemp]):'0.00',			
						'employee_settlement_note' => $v['employee_settlement_note'][$idemp],
						'employee_settlement_ins' => Lib_Date::datetime(),
						'employee_settlement_edit' => Lib_Date::datetime(),
						'admin_id' => $admin->admin_id
					);
					
				//	var_dump($data);echo'<hr />';
					
					$EmployeeSettlement->insert($data);			
			
					$select = $db->select();
					$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
					$select->where("employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'");
					$select->where('employee_id = '.$idemp); 
					$stmt = $db->query($select);
					$data = $stmt->fetchAll();	
					$dataCount = $data[0]['count'];	
					
					$data = array(
						'employee_settlement_datecount' => $dataCount
					);
					$EmployeeSettlement->update($data, "employee_id = ".$idemp." AND employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'" );
			
			}	
			
					
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('projectindex','employee',null,array('id' => $v['id']));	
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');

		$query = "SELECT * FROM employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_project
				WHERE 
					e.employee_id = employee_project.employee_id 
				AND 
					(
					employee_activ = 0
					OR (SELECT COUNT(*) FROM employee_settlement es WHERE es.employee_id = e.employee_id AND es.employee_settlement_date = '".$v['date']."') != 0
					)
				AND
					employee_project.project_id = ".$v['id']."
				ORDER BY 
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC";
		$dataEmployee = $db->query($query)->fetchAll();			
		$this->view->dataTableEmployee = $dataEmployee;		
	
	
			$EmployeeSettlement = new EmployeeSettlement();	
			$select = $EmployeeSettlement->select();
			$select->where('project_id = ?', $v['id']);	
			$select->where("employee_settlement_date LIKE '".$v['date']."'");	
		//	$select->order('employee_settlement_date DESC');
			$row = $EmployeeSettlement->fetchRow($select);
			$this->view->employeeSettlementLast = $row;
			
			if( $row['employee_settlement_date'] ){
				$dateTime = new DateTime($row['employee_settlement_date']); 
				$newDate = $dateTime->format('U'); 
			//	$newDate = $newDate + 24*60*60;
				$this->view->employeeSettlementNewDate = date('d-m-Y', $newDate);
			}
		
	}
	
	
	
	public function projectindexAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrproject = new Zend_Session_Namespace('filtremployee');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');	
	
	}
	
	
	
	public function projectsummaryAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrraport = new Zend_Session_Namespace('filtrraport');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		if( !isset($filtrraport->filtr_split) ){
			$filtrraport->filtr_split = 1;
		}
		
		
		if( $v['projectsummary_raport'] ){
			$filtrraport->employee_settlement_date_start = $v['employee_settlement_date_start'];
			$filtrraport->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
			$filtrraport->filtr_split = $v['filtr_split'];
			$this->_helper->redirector('projectsummary','employee',null,array('id' => $v['id']));
		}	
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');
		
		
		$searchData = '';
		if( $filtrraport->employee_settlement_date_start ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($filtrraport->employee_settlement_date_start,"d-m-Y","Y-m-d")."'";
		}		
		if( $filtrraport->employee_settlement_date_stop ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($filtrraport->employee_settlement_date_stop,"d-m-Y","Y-m-d")."'";	
		}
		if( $filtrraport->employee_settlement_date_start AND $filtrraport->employee_settlement_date_stop ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($filtrraport->employee_settlement_date_start,"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($filtrraport->employee_settlement_date_stop,"d-m-Y","Y-m-d")."'";
		}	
	
		$search = 'AND employee_settlement.project_id = '.$v['id'];
		
		$order = "employee_plwgroup, employee_secondname, employee_firstname";
		
		if( $filtrraport->filtr_split == 2 ){
		
			$order = "
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		if( $filtrraport->filtr_split == 3 ){
		
			$order = "
				ISNULL(groupcompany_name), 
				groupcompany_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		$ask = "
			SELECT 
			
			*,
			(
				SELECT GROUP_CONCAT(employeegroup.employeegroup_name ORDER BY employeegroup.employeegroup_name ASC SEPARATOR \", \") FROM 
				employee_employeegroup, employeegroup, employeegroup_type 
				WHERE
				employeegroup.employeegroup_type_id = employeegroup_type.employeegroup_type_id
				AND
				employee_employeegroup.employeegroup_id = employeegroup.employeegroup_id
				AND
				employeegroup.employeegroup_type_id = 3
				AND
				employee_employeegroup.employee_id = e.employee_id
			) AS groupcompany_name
			
			FROM 
			employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id 
			WHERE 
			employee_settlement.employee_id = e.employee_id 
			$search 
			$searchData 
			GROUP BY 
			employee_settlement.employee_id 
			ORDER BY $order
		";
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
		
	//	echo$ask;
		
		$this->view->employee_settlement_date_start = $filtrraport->employee_settlement_date_start;
		$this->view->employee_settlement_date_stop = $filtrraport->employee_settlement_date_stop;
		$this->view->filtr_split = $filtrraport->filtr_split;
		
		$link = '?';		
		$link = $link.'employee_settlement_date_start='.$filtrraport->employee_settlement_date_start.'&';
		$link = $link.'employee_settlement_date_stop='.$filtrraport->employee_settlement_date_stop.'&';
		$link = $link.'filtr_split='.$filtrraport->filtr_split.'&';
		$this->view->link = $link;
	}
	
	
	
	public function projectsummaryresetAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrraport = new Zend_Session_Namespace('filtrraport');	
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		Zend_Session::namespaceUnset('filtrraport');	
		
		$this->_helper->redirector('projectsummary','employee',null,array('id' => $v['id']));
	
	}
	
	
	
	public function projectsummaryprintAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');				
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
	
		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}	
	
		$search = 'AND employee_settlement.project_id = '.$v['id'];
		
		$order = "employee_plwgroup, employee_secondname, employee_firstname";
		
		if( $v['filtr_split'] == 2 ){
		
			$order = "
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		if( $v['filtr_split'] == 3 ){
		
			$order = "
				ISNULL(groupcompany_name), 
				groupcompany_name ASC,
				employee_secondname ASC, employee_firstname ASC
			";
		
		}
		
		/*
		$ask = "
			SELECT * FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id WHERE employee_settlement.employee_id = e.employee_id $search $searchData GROUP BY employee_settlement.employee_id ORDER BY $order
		";
		*/
		
		$ask = "
			SELECT 
			
			*,
			(
				SELECT GROUP_CONCAT(employeegroup.employeegroup_name ORDER BY employeegroup.employeegroup_name ASC SEPARATOR \", \") FROM 
				employee_employeegroup, employeegroup, employeegroup_type 
				WHERE
				employeegroup.employeegroup_type_id = employeegroup_type.employeegroup_type_id
				AND
				employee_employeegroup.employeegroup_id = employeegroup.employeegroup_id
				AND
				employeegroup.employeegroup_type_id = 3
				AND
				employee_employeegroup.employee_id = e.employee_id
			) AS groupcompany_name
			
			FROM 
			employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id 
			WHERE 
			employee_settlement.employee_id = e.employee_id 
			$search 
			$searchData 
			GROUP BY 
			employee_settlement.employee_id 
			ORDER BY $order
		";
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
		
		
		$this->view->rate = $v['rate'];
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		$this->view->filtr_split = $v['filtr_split'];
		
	}
	
	
	
	public function projecteditAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');		

		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		if( $information->addEmployeeProjectSuccess ){
			$this->view->addEmployeeProjectSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		if( $information->removeEmployeeSettlementSuccess ){
			$this->view->removeEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		
		
		
		if( isset($v['projectemp_edit']) ){	
		
			if( $v['project_h'] == null ) $h = -1;
			else $h = $v['project_h'];
		
			if( $v['project_m2'] == null ) $m2 = -1;
			else $m2 = $v['project_m2'];
		
			if( $v['project_percent'] == null ) $v['project_percent'] = 0;
			else $v['project_percent'] = $v['project_percent'];
			
			if( $v['project_h_clinker'] == null ) $hclinker = -1;
			else $hclinker = $v['project_h_clinker'];
		
			if( $v['project_m2_clinker'] == null ) $m2clinker = -1;
			else $m2clinker = $v['project_m2_clinker'];
			
			$data = array(
				'project_nr' => isset($v['project_nr'])?$v['project_nr']:'',
				'project_h' => $h,
				'project_h_clinker' => $hclinker,
				'project_m2' => $m2,
				'project_m2_clinker' => $m2clinker,
				'project_percent' => $v['project_percent'],
				
				'project_employee_name' => isset($v['project_employee_name'])?$v['project_employee_name']:'',
				'project_employee_phone' => isset($v['project_employee_phone'])?$v['project_employee_phone']:'',
				
				'project_employee_manager_name' => isset($v['project_employee_manager_name'])?$v['project_employee_manager_name']:'',
				'project_employee_manager_phone' => isset($v['project_employee_manager_phone'])?$v['project_employee_manager_phone']:'',
				
				'project_employee_cetla_name' => isset($v['project_employee_cetla_name'])?$v['project_employee_cetla_name']:'',
				'project_employee_cetla_phone' => isset($v['project_employee_cetla_phone'])?$v['project_employee_cetla_phone']:'',
				
				'project_status_finish' => isset($v['project_status_finish'])?$v['project_status_finish']:0,
				'project_status_calc' => isset($v['project_status_calc'])?$v['project_status_calc']:0,
				
				'project_date_start' => Lib_Date::convertDate($v['project_date_start'],"d-m-Y","Y-m-d"),
				'project_date_stop' => Lib_Date::convertDate($v['project_date_stop'],"d-m-Y","Y-m-d"),
				
				'project_status' => $v['project_status'],
				'project_edit' => Lib_Date::datetime()
			);
			$Project->update($data, "project_id = ".$v['id']."" );
			
			$information->addEmployeeProjectSuccess = true; 
			$this->_helper->redirector('projectedit','employee',null,array('id' => $v['id']));	
		}
		
		
		
		
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');	
		
		
		$ask = "
			SELECT * FROM employee, employee_project WHERE employee.employee_id = employee_project.employee_id AND employee_project.project_id = ".$v['id']." ORDER BY employee_secondname, employee_firstname
		";
		$dataEmployee = $db->query($ask)->fetchAll();			
		$this->view->dataTableEmployee = $dataEmployee;		
		
	
	}
	
	
	
	public function projecteditskillAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');		

		$Project = new Project();
		$EmployeeSettlement = new EmployeeSettlement();		
		
		$v = $this->_request->getParams();
		$vPost = $this->_request->getPost();
		
		
		if( $information->saveSkill ){
			$this->view->saveSkill = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addSkill ){
			$this->view->addSkill = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		
		if( isset($v['projectskill_edit']) ){
		
			$ProjectSkillGroupElement = new ProjectSkillGroupElement();
				
			$where = array(
				'project_id = ?' => $v['id']
			);
			$ProjectSkillGroupElement->delete($where);
			
			foreach( $v['skill_group_element_id'] as $key => $val ){
			
				if( $v['project_skill_group_element_h'][$key] == '' ){
					$v['project_skill_group_element_h'][$key] = -1;
				}
				$data = array(
					'project_id' => $v['id'],
					'skill_group_element_id' => $key,
					'project_skill_group_element_h' => $v['project_skill_group_element_h'][$key]
				);
				$ProjectSkillGroupElement->insert($data);
			}
			
			$information->saveSkill = true; 
			$this->_helper->redirector('projecteditskill','employee',null,array('id' => $v['id']));	
		}
		
		
		if( isset($v['projectskill_add']) ){
		
			$SkillGroupElement = new SkillGroupElement();
			$ProjectSkillGroupElement = new ProjectSkillGroupElement();
			$data = array(
				'skill_group_id' => 3,
				'skill_group_element_name' => $v['skill_group_element_name']
			);
			$idIns = $SkillGroupElement->insert($data);
			$data = array(
				'project_id' => $v['id'],
				'skill_group_element_id' => $idIns
			);
			$ProjectSkillGroupElement->insert($data);
		
			$information->addSkill = true; 
			$this->_helper->redirector('projecteditskill','employee',null,array('id' => $v['id']));
			
		}
		
		
		$select = $Project->select();
		$select->where('project_id = ?', $v['id']);
		$select->where('project_activ_employee = ?', 1);	
		$row = $Project->fetchRow($select);
		$this->view->projectData = $row;
		
		if( !$row ) $this->_helper->redirector('index','index');	
		
		
		$ask = "
			SELECT sg.*,sge.*, psge.project_skill_group_element_id, psge.project_skill_group_element_h FROM
			skill_group sg,
			skill_group_element sge
			LEFT JOIN
			project_skill_group_element psge
			ON
			sge.skill_group_element_id = psge.skill_group_element_id
			AND
			psge.project_id = ".$v['id']."
			WHERE
			sg.skill_group_id = sge.skill_group_id
			ORDER BY
			sg.skill_group_sort,
			sg.skill_group_id,
			sge.skill_group_element_sort,
			sge.skill_group_element_id
		";
		$dataSkillElement = $db->query($ask)->fetchAll();			
		$this->view->dataSkillElement = $dataSkillElement;		
		
	
	}
	
	
	
	
	
	
	
	
	
	// */*/*/*/*/*/*/*/*/*/*/*/ pracownicy w projektach - koniec */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/
	
	
	
	
	
	
	
	
	
	
	
	
	public function settlementAction() {	
		
		$v = $this->_request->getParams();	
		$vPost = $this->_request->getPost();	
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrsettlement = new Zend_Session_Namespace('filtrsettlement'.$v['id']);
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();				
		$db = Zend_Registry::get('db');		
		
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}	
		
		if( $information->editEmployeeSettlementSuccess ){
			$this->view->editEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		if( $information->addFiltrFiltrDataSuccess ){
			$this->view->addFiltrFiltrDataSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		
		
		if( isset($vPost['gotHidden']) ){
			$filtrsettlement->filtrDouble = ($filtrsettlement->filtrDouble+1)%2;
			$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));
		}
		
		if( isset($filtrsettlement->filtrDouble) ){
			$this->view->filtrDouble =  $filtrsettlement->filtrDouble;
		}else{
			$filtrsettlement->filtrDouble = 0;
			$this->view->filtrDouble =  $filtrsettlement->filtrDouble;
		}
		
		
		
		if( isset($vPost['gotClarify']) ){
			$filtrsettlement->filtrClarify = ($filtrsettlement->filtrClarify+1)%2;
			$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));
		}
		
		if( isset($filtrsettlement->filtrClarify) ){
			$this->view->filtrClarify =  $filtrsettlement->filtrClarify;
		}else{
			$filtrsettlement->filtrClarify = 0;
			$this->view->filtrClarify =  $filtrsettlement->filtrClarify;
		}





		
		$datafield = array(
			'employee_settlement.employee_settlement_date' => 'all'
		);
		
		$searchFiltrData = '';
		if( isset($vPost['filtr_settlement_filtr_data_field']) ){
		//	var_dump($vPost['filtr_settlement_filtr_data_field']);
		//	var_dump($vPost['filtr_settlement_filtr_data_1']);
		//	var_dump($vPost['filtr_settlement_filtr_data_2']);
			$filtrsettlement->filtr_settlement_filtr_data_field = $vPost['filtr_settlement_filtr_data_field'];
			$filtrsettlement->filtr_settlement_filtr_data_1 = $vPost['filtr_settlement_filtr_data_1'];
			$filtrsettlement->filtr_settlement_filtr_data_2 = $vPost['filtr_settlement_filtr_data_2'];
			$information->addFiltrFiltrDataSuccess = true;
			$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));
		}		
		if( $filtrsettlement->filtr_settlement_filtr_data_field ){
			$this->view->filtr_settlement_filtr_data_field = $filtrsettlement->filtr_settlement_filtr_data_field;
			$this->view->filtr_settlement_filtr_data_1 = $filtrsettlement->filtr_settlement_filtr_data_1;
			$this->view->filtr_settlement_filtr_data_2 = $filtrsettlement->filtr_settlement_filtr_data_2;
			
			if( $filtrsettlement->filtr_settlement_filtr_data_field == 'all' ){
			
			
				foreach($datafield as $key => $val){
			
					if( $searchFiltrData == '' ) $sep = '';
					else $sep = ' OR ';
					
					if( $filtrsettlement->filtr_settlement_filtr_data_1 AND !$filtrsettlement->filtr_settlement_filtr_data_2 ) $searchFiltrData = $searchFiltrData.$sep.$key." >= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_1,"d-m-Y","Y-m-d")."'";			
					if( !$filtrsettlement->filtr_settlement_filtr_data_1 AND $filtrsettlement->filtr_settlement_filtr_data_2 ) $searchFiltrData = $searchFiltrData.$sep.$key." <= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_2,"d-m-Y","Y-m-d")."'";			
					if( $filtrsettlement->filtr_settlement_filtr_data_1 AND $filtrsettlement->filtr_settlement_filtr_data_2 ) $searchFiltrData = $searchFiltrData.$sep." (".$key." >= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_1,"d-m-Y","Y-m-d")."' AND ".$key." <= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_2,"d-m-Y","Y-m-d")."') ";
				
				}
			
			
			}else{
			
				if( $filtrsettlement->filtr_settlement_filtr_data_1 ) $searchFiltrData = $filtrsettlement->filtr_settlement_filtr_data_field." >= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_1,"d-m-Y","Y-m-d")."'";			
				if( $filtrsettlement->filtr_settlement_filtr_data_2 ) $searchFiltrData = $filtrsettlement->filtr_settlement_filtr_data_field." <= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_2,"d-m-Y","Y-m-d")."'";			
				if( $filtrsettlement->filtr_settlement_filtr_data_1 AND $filtrsettlement->filtr_settlement_filtr_data_2 ) $searchFiltrData = "(".$filtrsettlement->filtr_settlement_filtr_data_field." >= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_1,"d-m-Y","Y-m-d")."' AND ".$filtrsettlement->filtr_settlement_filtr_data_field." <= '".Lib_Date::convertDate($filtrsettlement->filtr_settlement_filtr_data_2,"d-m-Y","Y-m-d")."')";
			
			}
			
		}
		
		$searchProject = '';
		if( isset($vPost['filtrProject']) ){
			if( $vPost['filtrProject'] != 'all' ){
				$filtrsettlement->project_id = $vPost['filtrProject'];
			}else{
				unset($filtrsettlement->project_id);
			}
			$information->addFiltrFiltrDataSuccess = true;
			$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));
		}
		
		if( $filtrsettlement->project_id ){
			$this->view->filtr_settlement_project_id =  $filtrsettlement->project_id;	
			$searchProject = 'employee_settlement.project_id='.$filtrsettlement->project_id;
		}


		
		$searchFiltrDouble = '';
		if( $filtrsettlement->filtrDouble != 0 ){
			$searchFiltrDouble = 'employee_settlement.employee_settlement_datecount > 1';		
		}


		
		$searchFiltrClarify = '';
		if( $filtrsettlement->filtrClarify != 0 ){
			$searchFiltrClarify = 'employee_settlement.employee_settlement_clarify = 1';		
		}





		
		
		
		
		
		
		
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
		
		$p = ($page-1)*$limit;	
		

		$select = $db->select();
		$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'))->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');
		$select->where('employee_id = '.$v['id']);		
		if( $searchFiltrData != '' ) $select->where($searchFiltrData);
		if( $searchProject != '' ) $select->where($searchProject);
		if( $searchFiltrDouble != '' ) $select->where($searchFiltrDouble);
		if( $searchFiltrClarify != '' ) $select->where($searchFiltrClarify);
	//	$select->order(array('employee_settlement_date ASC'));  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$dataCount = $data[0]['count'];		

		$select = $db->select();
		$select->from('employee_settlement', array("*, DATE_FORMAT(employee_settlement_date, '%Y-%m') AS d1, DATE_FORMAT(employee_settlement_date, '%d') AS d2"))->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');
		$select->where('employee_id = '.$v['id']);		
		if( $searchFiltrData != '' ) $select->where($searchFiltrData);
		if( $searchProject != '' ) $select->where($searchProject);
		if( $searchFiltrDouble != '' ) $select->where($searchFiltrDouble);
		if( $searchFiltrClarify != '' ) $select->where($searchFiltrClarify);
		$select->order(array('d1 DESC','d2 ASC','employee_settlement_date ASC'))->limit($limit,$p);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		
		if( $filtrsettlement->filtrClarify != 0 ){
		
			foreach( $data as $key1 => $val1 ){
				$EmployeeSettlementClarify = new EmployeeSettlementClarify();	
				$select = $EmployeeSettlementClarify->select();
				$select->where('employee_settlement_id = ?', $val1['employee_settlement_id']);	
				$select->order(array('employee_settlement_clarify_ins DESC'));
				$row = $EmployeeSettlementClarify->fetchRow($select);	
				$data[$key1]['clarify'] = $row;
			}
		
		}
		
		$this->view->dataTable = $data;		
		
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('settlement');
		$Lib_Page->setGet('/id/'.$v['id']);
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;	
		
		
		
		
		$EmployeeAlert = new EmployeeAlert();			
		$d = date("Y-m-d");		
		$where = "employee_id = ".$v["id"]." AND employee_alert_start <= '".$d."' AND employee_alert_stop >= '".$d."'";
		$data = $EmployeeAlert->fetchAll($where , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		$this->view->dataTableEmployeeAlert = $data;
		
		
		
		$dataProject = $db->query("SELECT DISTINCT(project_id) AS project_id FROM `employee_project` WHERE employee_id = '".$v['id']."'")->fetchAll();
	
		$i = -1;
		$searchProject = '';
		foreach($dataProject as $key => $val){
			$i++;			
			if( $i == 0 ){
				$searchProject = ' project.project_id = '.$val['project_id'];
			}else{
				$searchProject = $searchProject.' OR project.project_id = '.$val['project_id'];			
			}			
		}
		
	//	echo$searchProject;
		
		if( $searchProject != '' ){
		$query = "SELECT * FROM project, company WHERE project.company_id = company.company_id AND (".$searchProject.") ORDER BY company_name ASC, project_name ASC";
		$dataProject = $db->query($query)->fetchAll();
	//	echo$query;
		$this->view->dataProject = $dataProject;
		}
		
		
		$this->view->employeeeditmenu = 1;
	}
	
	public function settlementbonusAction() {	
		
		$v = $this->_request->getParams();	
		$vPost = $this->_request->getPost();	
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrsettlement = new Zend_Session_Namespace('filtrsettlement'.$v['id']);
		
		if( $information->removeSuccess ){
			$this->view->removeSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		if( $information->addEmployeeSettlementSuccess ){
			$this->view->addEmployeeSettlementSuccess = true;
			Zend_Session::namespaceUnset('information');			
		}
		
		$Employee = new Employee();		
		$EmployeeSettlementBonus = new EmployeeSettlementBonus();				
		$db = Zend_Registry::get('db');				
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		
		$limit = 10;
		$limitpage = 10;

		$page = $this->_request->getParams();
		if( isset($page['page']) ) $page = $page['page'];
		else $page = 1;
		
		$p = ($page-1)*$limit;	
		

		$select = $db->select();
		$select->from('employee_settlement_bonus',array('COUNT(employee_settlement_bonus_id) as count', 'employee_settlement_bonus_id'))
		//->join('project', 'employee_settlement_bonus.project_id = project.project_id')
		//->join('company', 'company.company_id = project.company_id')
		->join('admin', 'employee_settlement_bonus.admin_id = admin.admin_id');
		$select->where('employee_id = '.$v['id']);		
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$dataCount = $data[0]['count'];		

		$select = $db->select();
		$select->from('employee_settlement_bonus', array("*"))
		//->join('project', 'employee_settlement_bonus.project_id = project.project_id')
		//->join('company', 'company.company_id = project.company_id')
		->join('admin', 'employee_settlement_bonus.admin_id = admin.admin_id');
		$select->where('employee_id = '.$v['id']);		
		$select->order(array('employee_settlement_bonus_year DESC','employee_settlement_bonus_month DESC'))->limit($limit,$p);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();			
		$this->view->dataTable = $data;		
		
		$Lib_Page = new Lib_Page();
		$Lib_Page->setLimit( $limit );
		$Lib_Page->setLimitPage( $limitpage );
		$Lib_Page->setMax( $dataCount );
		$Lib_Page->setActualId( $page );
		$Lib_Page->setController('employee');
		$Lib_Page->setAction('settlementbonus');
		$Lib_Page->setGet('/id/'.$v['id']);
		$Lib_Page->setPrefix('page');
		$this->view->str = $Lib_Page->result();
		$this->view->page = ($page-1)*$limit;	
		
		
		
		
		$EmployeeAlert = new EmployeeAlert();			
		$d = date("Y-m-d");		
		$where = "employee_id = ".$v["id"]." AND employee_alert_start <= '".$d."' AND employee_alert_stop >= '".$d."'";
		$data = $EmployeeAlert->fetchAll($where , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		$this->view->dataTableEmployeeAlert = $data;
		
		
		
		$dataProject = $db->query("SELECT DISTINCT(project_id) AS project_id FROM `employee_project` WHERE employee_id = '".$v['id']."'")->fetchAll();
	
		$i = -1;
		$searchProject = '';
		foreach($dataProject as $key => $val){
			$i++;			
			if( $i == 0 ){
				$searchProject = ' project.project_id = '.$val['project_id'];
			}else{
				$searchProject = $searchProject.' OR project.project_id = '.$val['project_id'];			
			}			
		}
		
		if( $searchProject != '' ){
		$query = "SELECT * FROM project, company WHERE project.company_id = company.company_id AND (".$searchProject.") ORDER BY company_name ASC, project_name ASC";
		$dataProject = $db->query($query)->fetchAll();
		$this->view->dataProject = $dataProject;
		}
		
		
		$this->view->employeeeditmenu = 2;
	}
	
	
	
	
	
	public function settlementclarifyAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();	
		
		$select = $EmployeeSettlement->select();
		$select->where('employee_settlement_id = ?', $v['id']);	
		$row = $EmployeeSettlement->fetchRow($select);
		$this->view->employeeSettlementData = $row;
			
		$query = "SELECT * FROM employee_settlement_clarify WHERE employee_settlement_id = ".$v['id']." ORDER BY employee_settlement_clarify_ins DESC";
		$data = $db->query($query)->fetchAll();
	
		$this->view->dataTable = $data;	
	
	}
	
	public function settlementclarifysaveAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$EmployeeSettlement = new EmployeeSettlement();	
		$EmployeeSettlementClarify = new EmployeeSettlementClarify();	
		
		$select = $EmployeeSettlement->select();
		$select->where('employee_settlement_id = ?', $v['id']);	
		$row = $EmployeeSettlement->fetchRow($select);
		
		$data = array(
			'employee_settlement_clarify' => $v['employee_settlement_clarify'],				
			'employee_settlement_clarify_note' => $v['employee_settlement_clarify_note'],
			'employee_settlement_edit' => Lib_Date::datetime()
		);		
		$EmployeeSettlement->update($data, 'employee_settlement_id='.$v['id'] );
		
			
		$data = array(
			'employee_settlement_id' => $v['id'],
			'employee_settlement_clarify_clarify' => $v['employee_settlement_clarify'],			
			'employee_settlement_clarify_clarify_note' => isset($v['employee_settlement_clarify_note'])?$v['employee_settlement_clarify_note']:'',
			'employee_settlement_clarify_ins' => Lib_Date::datetime(),
			'admin_id' => $admin->admin_id
		);
		$EmployeeSettlementClarify->insert($data);	
	
		$this->_helper->redirector('settlement','employee',null,array('id' => $row['employee_id']));	
	}
	
	
	
	public function settlementsetAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		
		$filtrsettlement = new Zend_Session_Namespace('filtrsettlement'.$v['id']);
		$filtrsettlement->filtr_settlement_filtr_data_field = 'all';
		$filtrsettlement->filtr_settlement_filtr_data_1 = $v['filtr_settlement_filtr_data_1'];
		$filtrsettlement->filtr_settlement_filtr_data_2 = $v['filtr_settlement_filtr_data_2'];
		unset($filtrsettlement->filtrDouble);
		unset($filtrsettlement->project_id);
		
		$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));	
	}
	
	
	
	public function settlementclarifysetAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		
		$filtrsettlement = new Zend_Session_Namespace('filtrsettlement'.$v['id']);
		$filtrsettlement->filtr_settlement_filtr_data_field = 'all';
		$filtrsettlement->filtrClarify = 1;
		unset($filtrsettlement->filtr_settlement_filtr_data_1);
		unset($filtrsettlement->filtr_settlement_filtr_data_2);
		unset($filtrsettlement->filtrDouble);
		unset($filtrsettlement->project_id);
		
		$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));	
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function raportAction() {	
		
		$v = $this->_request->getParams();	
		$vPost = $this->_request->getPost();	
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrsettlement = new Zend_Session_Namespace('filtrsettlement'.$v['id']);
		$filtrraport = new Zend_Session_Namespace('filtrraport');//.$v['id']);
		
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();				
		$db = Zend_Registry::get('db');		
	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$dataProject = $db->query("SELECT DISTINCT(project_id) AS project_id FROM `employee_project` WHERE employee_id = '".$v['id']."'")->fetchAll();
	
		$i = -1;
		$searchProject = '';
		foreach($dataProject as $key => $val){
			$i++;			
			if( $i == 0 ){
				$searchProject = ' project.project_id = '.$val['project_id'];
			}else{
				$searchProject = $searchProject.' OR project.project_id = '.$val['project_id'];			
			}			
		}
		
	//	echo$searchProject;
		
		if( $searchProject != '' ){
		$query = "SELECT * FROM project, company WHERE project.company_id = company.company_id AND (".$searchProject.") ORDER BY company_name ASC, project_name ASC";
		$dataProject = $db->query($query)->fetchAll();
	//	echo$query;
		$this->view->dataProject = $dataProject;
		}
	
		$this->view->employee_settlement_date_start = $filtrraport->employee_settlement_date_start;
		$this->view->employee_settlement_date_stop = $filtrraport->employee_settlement_date_stop;
		$this->view->project_id = $filtrraport->project_id;
		$this->view->project_separately = $filtrraport->project_separately;
	}
	
	
	
	public function raportresetAction() {	
		$v = $this->_request->getParams();	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		$filtrraport = new Zend_Session_Namespace('filtrraport'.$v['id']);
		$db = Zend_Registry::get('db');
		$this->_helper->viewRenderer->setNoRender();
		Zend_Session::namespaceUnset('filtrraport');//.$v['id']);	
		
		$this->_helper->redirector('raport','employee',null,array('id' => $v['id']));
	
	}
	
	
	public function raportgenAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
		$filtrraport = new Zend_Session_Namespace('filtrraport');//.$v['id']);
		
		$filtrraport->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$filtrraport->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		if( $v['project_nosave'] != 1 ){
			$filtrraport->project_id = $v['project_id'];
			$filtrraport->project_separately = $v['project_separately'];
		}
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = null;
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";
		
		
		
		
		
		if( $v['project_id'] == 'all' AND $v['project_separately'] == 1  ){	
		
			// rozbicie
		/*	$select = $db->select();
			$select->from('employee_settlement',array('DISTINCT(project_id) as project_id', 'project_id'));//->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');		
			if( $searchData != '' ) $select->where($searchData);
			$select->where($searchEmployee);					
			$select->order(array('company.company_name DESC' , 'project.project_name DESC'));
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();*/

	
			if( $searchData != '' ) $searchData = ' AND '.$searchData;

			$query = "SELECT DISTINCT(employee_settlement.project_id) as project_id FROM employee_settlement, project, company 
				WHERE 
					employee_settlement.project_id = project.project_id 
				AND 
					project.company_id = company.company_id 
				AND 
					".$searchEmployee."
					".$searchData."
				ORDER BY company_name ASC, project_name ASC";
			$dataProject = $db->query($query)->fetchAll();			
			$this->view->dataTableProject = $dataProject;	
		//	echo$query;
		}else{
		
			// brak rozbicia
			$select = $db->select();
			$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
			if( $searchData != '' ) $select->where($searchData);
			if( $searchProject != '' ) $select->where($searchProject);
			$select->where($searchEmployee);					
			$select->order(array('employee_settlement.employee_settlement_date ASC'));
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$this->view->dataTable = $data;				
		}
		
		
		
		$this->view->id = $v['id'];
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		$this->view->project_id = $v['project_id'];
		$this->view->project_separately = $v['project_separately'];
		
		$link = '?';		
		$link = $link.'employee_settlement_date_start='.$v['employee_settlement_date_start'].'&';
		$link = $link.'employee_settlement_date_stop='.$v['employee_settlement_date_stop'].'&';
		$link = $link.'project_id='.$v['project_id'].'&';
	//	$link = $link.'project_separately='.$v['project_separately'].'&';
		$this->view->link = $link;
		
		
		
		
		
		if( $v['project_nosave'] != 1 ){
			$periods = Lib_Date::periodsBetweenDates($v['employee_settlement_date_start'],$v['employee_settlement_date_stop']);
			
			if( $periods != -1 ){
			
				$whereAsk = '';
				
				foreach( $periods AS $key => $val ){
				
					if( $whereAsk == '' ){
						$whereAsk = "periods = '".$val."'";
					}else{
						$whereAsk = $whereAsk." OR periods = '".$val."'";				
					}
					
				}
			}
		}
		
		
		
		
		
	}
	
	
	public function printAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$Employee = new Employee();	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = null;
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";
	
	
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
		if( $searchData != '' ) $select->where($searchData);
		if( $searchProject != '' ) $select->where($searchProject);
		$select->where($searchEmployee);					
		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
		
		$this->view->id = $v['id'];
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		$this->view->project_id = $v['project_id'];
		$this->view->project_separately = $v['project_separately'];
		$this->view->rate = $v['rate'];
		$this->view->sum = $v['sum'];
		$this->view->noprint = $v['noprint'];
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	}
	
	
	public function printallAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$Employee = new Employee();	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = null;
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";
	
	
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
		if( $searchData != '' ) $select->where($searchData);
		if( $searchProject != '' ) $select->where($searchProject);
		$select->where($searchEmployee);					
		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
		
		$this->view->id = $v['id'];
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		$this->view->project_id = $v['project_id'];
		$this->view->project_separately = $v['project_separately'];
		$this->view->rate = $v['rate'];
		$this->view->sum = $v['sum'];
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
	}
	
	
	public function pdfAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
			
		$this->generatepdf();	
	
	}
	
	
	public function projectsummarypdfAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
			
		$this->generateprojectsummarypdf();	
	
	}
	
	
	public function xlsAction() {	
	
		$db = Zend_Registry::get('db');		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
			
		
		
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$Employee = new Employee();	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = null;
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";
	
	
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
		if( $searchData != '' ) $select->where($searchData);
		if( $searchProject != '' ) $select->where($searchProject);
		$select->where($searchEmployee);					
		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$dataTable = $stmt->fetchAll();	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$employeeData = $Employee->fetchRow($select);
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
			
		
			
			$name = mb_strtolower ($employeeData['employee_firstname'].' '.$employeeData['employee_secondname'], 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
			
			
		
			$objPHPExcel = new PHPExcel();
			$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
			$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
			$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
			$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
			$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
			
			$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(60);
			$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(60);
			
			$objPHPExcel->getActiveSheet()->mergeCells('A1:H1');
			$objPHPExcel->getActiveSheet()->setCellValue('A1', $employeeData['employee_firstname'].' '.$employeeData['employee_secondname']);
			
			$rowid = 1;
			$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(16);
			
			
		 if( $v['employee_settlement_date_start'] OR $v['employee_settlement_date_stop'] ){ 
			
			 if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){ 

				 $d = @LANG_header_title_printdate.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - '. Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");
				
			 }elseif( $v['employee_settlement_date_start'] ){ 

				 $d = @LANG_header_title_printdate.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - ...';

			 }elseif( $v['employee_settlement_date_stop'] ){ 

				$d = @LANG_header_title_printdate.'... -  '.Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");

			 } 

			$rowid = $rowid+1;		
		
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':H'.$rowid.'');
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $d);
			$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(12);

		 } 
		
		
		
		if( $v['project_id'] != 'all' ){ 

			$rowid = $rowid+1;		
		
			$d = $dataTable[0]['company_name'].' / '.$dataTable[0]['project_name'];
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':H'.$rowid.'');
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $d);
			$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(12);
		
		}
			
			
			
			$i = $rowid + 2;				
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, @LANG_employee_settlement_list_lp)	
					->setCellValue('B'.$i, @LANG_employee_settlement_list_date)		
					->setCellValue('C'.$i, @LANG_employee_settlement_list_ss)
					->setCellValue('D'.$i, @LANG_employee_settlement_list_time)	
					->setCellValue('E'.$i, (($v['rate'])?@LANG_employee_settlement_list_rate:""))	
					->setCellValue('F'.$i, (($v['rate'])?@LANG_employee_settlement_list_ratesum:""))					
					->setCellValue('G'.$i, @LANG_employee_settlement_list_compro)
					->setCellValue('H'.$i, @LANG_employee_settlement_list_note);
			
			$objPHPExcel->getActiveSheet()->getStyle('A'.$i.':H'.$i)->getFont()->setBold(true);
			
			$j = 0;
			$io = $i;
			foreach($dataTable as $key => $value){
				$i=$i+1;
				$j++;
				
				$t = Lib_Date::convertDate($value['employee_settlement_time'],'H:i:s','H:i'); 
				$tr = explode(":",$t);
				$sumt = $sumt + $tr[0]*60 + $tr[1];
				
					$tV = explode(":",$t);
					$rateSum = number_format($tV[0]*$value['employee_settlement_rate'] + $tV[1]*$value['employee_settlement_rate']/60, 2, ',', ' ');					
					$sumAll = $sumAll + number_format($tV[0]*$value['employee_settlement_rate'] + $tV[1]*$value['employee_settlement_rate']/60, 2);
				
				$objPHPExcel->setActiveSheetIndex(0)
						->setCellValue('A'.$i, $j)
						->setCellValue('B'.$i, Lib_Date::convertDate($value['employee_settlement_date'],"Y-m-d","d.m.Y") )
						->setCellValue('C'.$i, Lib_Date::convertDate($value['employee_settlement_start'],'H:i:s','H:i').' - '.Lib_Date::convertDate($value['employee_settlement_stop'],'H:i:s','H:i'))
						->setCellValue('D'.$i, $t)
						->setCellValue('E'.$i, (($v['rate'])?number_format($value['employee_settlement_rate'], 2, ',', ' ')." \xE2\x82\xAc":""))
						->setCellValue('F'.$i, (($v['rate'])?number_format($rateSum, 2, ',', ' ')." \xE2\x82\xAc":""))
						->setCellValue('G'.$i, $value['company_name'].' / '.$value['project_name'])
						->setCellValue('H'.$i, $value['employee_settlement_note']);
					
				if( $value['employee_settlement_datecount'] > 1 ){
			
					$objPHPExcel->getActiveSheet()->getStyle("A".$i.":H".$i)->getFill()->applyFromArray(array(
						'type' => PHPExcel_Style_Fill::FILL_SOLID,
						'startcolor' => array(
							 'rgb' => 'f6cece'
						)
					));

				}				
				
			}
			
			
			// suma godzin
			$i++;
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$i.':C'.$i.'');
			
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, @LANG_employee_settlement_sum);
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$i, @LANG_employee_settlement_sumrate);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFont()->setSize(12)->setBold(0);
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFont()->setSize(12)->setBold(0);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					 'rgb' => 'cef6ce'
				)
			));
			
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					 'rgb' => 'cef6ce'
				)
			));
			
			$objPHPExcel->getActiveSheet()->mergeCells('G'.$i.':H'.$i.'');
			
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$i, Lib_Date::convertToHoursMins($sumt));
			$objPHPExcel->getActiveSheet()->getStyle("D".$i)->getFont()->setSize(12)->setBold(0);
			
			$objPHPExcel->getActiveSheet()->setCellValue('F'.$i, (($v['sum'])?number_format($sumAll, 2, ',', ' ')."  \xE2\x82\xAc":""));
			$i++;
			$objPHPExcel->getActiveSheet()->setCellValue('F'.$i, (($v['sum'])?number_format(Lib_Data::roundSpecialPrice($sumAll), 2, ',', ' ')."  \xE2\x82\xAc":""));
			$objPHPExcel->getActiveSheet()->getStyle("F".$i)->getFont()->setSize(12)->setBold(0);
			
			
			// srednia godzin
			$i++;
			
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$i.':C'.$i.'');
			
		//	$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, @LANG_employee_settlement_avg);
		//	$objPHPExcel->getActiveSheet()->setCellValue('E'.$i, @LANG_employee_settlement_avgrate);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFont()->setSize(12)->setBold(0);
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFont()->setSize(12)->setBold(0);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
			
			$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					 'rgb' => 'cef6ce'
				)
			));
			
			$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					 'rgb' => 'cef6ce'
				)
			));
			
			$objPHPExcel->getActiveSheet()->mergeCells('G'.$i.':H'.$i.'');
		/*	
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$i, Lib_Date::convertToHoursMins(round($sumt/$j)));
			$objPHPExcel->getActiveSheet()->getStyle("D".$i)->getFont()->setSize(12)->setBold(0);
			
			$objPHPExcel->getActiveSheet()->setCellValue('F'.$i, number_format($sumAll/$j, 2, ',', ' ')." \xE2\x82\xAc");
			$objPHPExcel->getActiveSheet()->getStyle("F".$i)->getFont()->setSize(12)->setBold(0);
		*/	
			
			$objPHPExcel->getActiveSheet()
                ->getStyle('A'.$io.':H'.$i)
                ->getBorders()
                ->getAllBorders()
                ->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
                ->getColor()
                ->setRGB('888');
			

			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);

			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');

			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0

			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');				
			
			
			

			
	
	}
	
	public function settlementaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		$EmployeeSettlement = new EmployeeSettlement();			
		$db = Zend_Registry::get('db');	
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['employee_settlementadd']) ){		

			$data = array(
				'employee_id' => $v['id'],
				'project_id' => $v['project_id'],
				'employee_settlement_date' => Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d"),
				'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'],"H:i","H:i:s"),
				'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'],"H:i","H:i:s"),			
				'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'],"H:i","H:i:s"),
				'employee_settlement_rate' => isset($v['employee_settlement_rate'])?str_replace(",",".",$v['employee_settlement_rate']):'0.00',			
				'employee_settlement_note' => $v['employee_settlement_note'],
				'employee_settlement_ins' => Lib_Date::datetime(),
				'employee_settlement_edit' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$EmployeeSettlement->insert($data);				
			
			$select = $db->select();
			$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
			$select->where("employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'");
			$select->where('employee_id = '.$v['id']); 
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$dataCount = $data[0]['count'];	
			
			$data = array(
				'employee_settlement_datecount' => $dataCount
			);
			$EmployeeSettlement->update($data, "employee_id = ".$v['id']." AND employee_settlement_date LIKE '".Lib_Date::convertDate($v['employee_settlement_date'],"d-m-Y","Y-m-d")."'" );
			
			
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));			
		}	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		// lista projektów
		
		
		$select = $db->select();
		$select->from('employee_project')
			->join('project', 'project.project_id = employee_project.project_id')
			->join('company', 'project.company_id = company.company_id')
			->where('employee_id = ?', $v['id']);
			
		$select->order(array('project.project_status ASC','company.company_name ASC','project.project_name ASC'));  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		
		$this->view->employeeProjectData = $data;
		
		
		
		
		$EmployeeAlert = new EmployeeAlert();			
		$d = date("Y-m-d");		
		$where = "employee_id = ".$v["id"]." AND employee_alert_start <= '".$d."' AND employee_alert_stop >= '".$d."'";
		$data = $EmployeeAlert->fetchAll($where , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		$this->view->dataTableEmployeeAlert = $data;
	
	}
	
	public function settlementbonusaddAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		$EmployeeSettlementBonus = new EmployeeSettlementBonus();			
		$db = Zend_Registry::get('db');	
		
		$v = $this->_request->getParams();		
		
		
		if( isset($v['employee_settlementadd']) ){		

			$bonus_period = explode("/",$v['bonus_period']);
		
			$data = array(
				'bonus_type_id' => $v['bonus_type_id'],
				'employee_id' => $v['id'],
			//	'project_id' => $v['project_id'],
				
				'employee_settlement_bonus_year' => $bonus_period[1],
				'employee_settlement_bonus_month' => $bonus_period[0],
				
				'employee_settlement_bonus_amount' => isset($v['employee_settlement_bonus_amount'])?str_replace(",",".",$v['employee_settlement_bonus_amount']):'0.00',		
				
				'employee_settlement_bonus_note' => $v['employee_settlement_bonus_note'],
				
				'employee_settlement_bonus_ins' => Lib_Date::datetime(),
				'employee_settlement_bonus_edit' => Lib_Date::datetime(),
				'admin_id' => $admin->admin_id
			);
			$EmployeeSettlementBonus->insert($data);
			
			$information->addEmployeeSettlementSuccess = true; 
			$this->_helper->redirector('settlementbonus','employee',null,array('id' => $v['id']));			
		}	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		// lista projektów
		
		$select = $db->select();
		$select->from('employee_project')
			->join('project', 'project.project_id = employee_project.project_id')
			->join('company', 'project.company_id = company.company_id')
			->where('employee_id = ?', $v['id']);
			
		$select->order(array('project.project_status ASC','company.company_name ASC','project.project_name ASC'));  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		
		$this->view->employeeProjectData = $data;
		
		$EmployeeAlert = new EmployeeAlert();			
		$d = date("Y-m-d");		
		$where = "employee_id = ".$v["id"]." AND employee_alert_start <= '".$d."' AND employee_alert_stop >= '".$d."'";
		$data = $EmployeeAlert->fetchAll($where , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		$this->view->dataTableEmployeeAlert = $data;
	
		$BonusType = new BonusType();		
		$data = $BonusType->fetchAll(null , 'bonus_type_sort ASC'); 		
		$this->view->dataTableBonusType = $data;
	}
	
	public function projectsettlementremoveAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');	
		
		$EmployeeSettlement = new EmployeeSettlement();
		
		
		$select = $db->select();
		$select->from('employee_settlement')->where('project_id = ?', $v['id']);			 
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		
		
		$where = array(
			'project_id = ?' => $v['id']
		);
		$EmployeeSettlement->delete($where);
	
	
		foreach( $data as $key => $val ){
					
			$select = $db->select();
			$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
			$select->where("employee_settlement_date LIKE '".$val['employee_settlement_date']."'");
			$select->where('employee_id = '.$val['employee_id']); 
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$dataCount = $data[0]['count'];	
			
			$data = array(
				'employee_settlement_datecount' => $dataCount
			);
			$where = "employee_id = ".$val['employee_id']." AND employee_settlement_date LIKE '".$val['employee_settlement_date']."'";
			$EmployeeSettlement->update($data, $where );
			
		//	var_dump($data);
		//	echo'<br/><br/>'.$where.'<hr/>';
		}
	
		
		$information->removeEmployeeSettlementSuccess = true; 
		$this->_helper->redirector('projectedit','employee',null,array('id' => $v['id']));	
	}
	
	
	
	public function settlementremoveAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');	
		
		$EmployeeSettlement = new EmployeeSettlement();
		
		
		
		$select = $EmployeeSettlement->select();
		$select->where('employee_settlement_id = ?', $v['ids']);	
		$rowEmployeeSettlement = $EmployeeSettlement->fetchRow($select);
		
		
		
		
		
		
		
		
		
		
		
		
		
		$where = array(
			'employee_settlement_id = ?' => $v['ids']
		);
		$EmployeeSettlement->delete($where);





			
			$select = $db->select();
			$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
			$select->where("employee_settlement_date LIKE '".$rowEmployeeSettlement['employee_settlement_date']."'");
			$select->where('employee_id = '.$rowEmployeeSettlement['employee_id']); 
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$dataCount = $data[0]['count'];	
			
			$data = array(
				'employee_settlement_datecount' => $dataCount
			);
			$EmployeeSettlement->update($data, "employee_id = ".$rowEmployeeSettlement['employee_id']." AND employee_settlement_date LIKE '".$rowEmployeeSettlement['employee_settlement_date']."'" );







		
		$information->removeSuccess = true; 
		if( !$v['return'] ) $this->_helper->redirector('settlement','employee',null,array('id' => $v['id']));	
		
		if( $v['return'] AND $v['return_n'] AND $v['return_id'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id']));			
	}
	
	
	
	public function settlementbonusremoveAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');	
		
		$EmployeeSettlementBonus = new EmployeeSettlementBonus();		
		
		$where = array(
			'employee_settlement_bonus_id = ?' => $v['ids']
		);
		$EmployeeSettlementBonus->delete($where);
		
		$information->removeSuccess = true; 
		if( !$v['return'] ) $this->_helper->redirector('settlementbonus','employee',null,array('id' => $v['id']));	
		
		if( $v['return'] AND $v['return_n'] AND $v['return_id'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id']));			
	}
	
	public function projectindexremovedateAction() {	
		$v = $this->_request->getParams();		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$db = Zend_Registry::get('db');	
		
		$EmployeeSettlement = new EmployeeSettlement();
		$where = "
			project_id = ".$v['id']." AND
			employee_settlement_date LIKE '".$v['date']."'
		";
		$data = $EmployeeSettlement->fetchAll($where ); 	
				
		
		
		$EmployeeSettlement->delete($where);
		
		foreach($data as $key => $val){
			echo$val['employee_settlement_id'].', ';
			$select = $db->select();
			$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
			$select->where("employee_settlement_date LIKE '".$val['employee_settlement_date']."'");
			$select->where('employee_id = '.$val['employee_id']); 
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$dataCount = $data[0]['count'];	
			
			$data = array(
				'employee_settlement_datecount' => $dataCount
			);
			$EmployeeSettlement->update($data, "employee_id = ".$val['employee_id']." AND employee_settlement_date LIKE '".$val['employee_settlement_date']."'" );
			
		}

		$this->_helper->redirector('projectindex','employee',null,array('id' => $v['id']));				
	}
	
	public function settlementcheckdateAction() {
		header("Content-Type:text/plain");
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$valid = 0;
		// $valid = 0 - nie istnieje w bazie
		// $valid = 1 - istnieje w bazie
		
		$EmployeeSettlement = new EmployeeSettlement();	
		$select = $EmployeeSettlement->select();		
		$select->where('employee_id = ?', $v['id']);
		$select->where("employee_settlement_date = '".Lib_Date::convertDate($v['d'],"d-m-Y","Y-m-d")."'");					
		$row = $EmployeeSettlement->fetchRow($select);
		unset($EmployeeSettlement);		

		if( isset($row) ) $valid = 1;
		else $valid = 0;
			
		echo $valid;
	}
	
	public function settlementchecknameAction() {
		header("Content-Type:text/plain");
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$valid = 0;
		// $valid = 0 - nie istnieje w bazie
		// $valid = 1 - istnieje w bazie
		
		$Employee = new Employee();	
		$select = $Employee->select();		
		$select->where("employee_secondname LIKE '".$v['d']."'");					
		$row = $Employee->fetchRow($select);
		unset($Employee);		

		if( isset($row) ){
			if( $row['employee_activ'] == 0 ) $valid = 1;
			if( $row['employee_activ'] == 1 ) $valid = 2;
		}else $valid = 0;
			
		echo $valid;
	}
	
	public function projectsettlementcheckdateAction() {
		header("Content-Type:text/plain");
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$valid = 0;
		// $valid = 0 - nie istnieje w bazie
		// $valid = 1 - istnieje w bazie
		
		$EmployeeSettlement = new EmployeeSettlement();	
		
		foreach( $v['employee_id'] as $key => $val ){		
		
			$select = $EmployeeSettlement->select();		
			$select->where('employee_id = ?', $val);
			$select->where("employee_settlement_date = '".Lib_Date::convertDate($v['d'],"d-m-Y","Y-m-d")."'");				
			$row = $EmployeeSettlement->fetchRow($select);
			
			if( isset($row) ) $ret[$val] = 1;
			else $ret[$val] = 0;
		
		}		
		
		unset($EmployeeSettlement);		
		if($v['employee_id']) echo json_encode($ret);
	}
	
	public function settlementeditAction() {	
		
		$v = $this->_request->getParams();	
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		$EmployeeSettlement = new EmployeeSettlement();			
		$db = Zend_Registry::get('db');		
		
		
		if( isset($v['employee_settlementedit']) ){		

			$data = array(
				'employee_id' => $v['id'],
				'employee_settlement_start' => Lib_Date::convertDate($v['employee_settlement_start'],"H:i","H:i:s"),
				'employee_settlement_stop' => Lib_Date::convertDate($v['employee_settlement_stop'],"H:i","H:i:s"),			
				'employee_settlement_time' => Lib_Date::convertDate($v['employee_settlement_time'],"H:i","H:i:s"),
				'employee_settlement_rate' => isset($v['employee_settlement_rate'])?str_replace(",",".",$v['employee_settlement_rate']):'0.00',					
				'employee_settlement_note' => $v['employee_settlement_note'],
				'employee_settlement_edit' => Lib_Date::datetime()
			);
			$EmployeeSettlement->update($data, 'employee_settlement_id='.$v['ids'] );

		
			$select = $db->select();
			$select->from('employee_settlement')
				->join('project', 'employee_settlement.project_id = project.project_id')
				->join('company', 'company.company_id = project.company_id');  
			$select->where('employee_settlement.employee_id = ?', $v['id']);
			$select->where("employee_settlement.employee_settlement_id = ?", $v['ids']);
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$v['employee_settlement_date'] = $data[0]['employee_settlement_date'];
			
			$select = $db->select();
			$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
			$select->where("employee_settlement_date LIKE '".$v['employee_settlement_date']."'");
			$select->where('employee_id = '.$v['id']); 
			$stmt = $db->query($select);
			$data = $stmt->fetchAll();	
			$dataCount = $data[0]['count'];	
			
			
			$data = array(
				'employee_settlement_datecount' => $dataCount
			);
			$EmployeeSettlement->update($data, "employee_id = ".$v['id']." AND employee_settlement_date LIKE '".$v['employee_settlement_date']."'" );
			
		//	echo$dataCount.' '.$v['employee_settlement_date'];
			
			$return = 'settlement';	
			
			if( isset($v['return']) ) $return = $v['return'];	
			
			if($return == 'settlement') $information->addEmployeeSettlementSuccess = true;
			
			if( !$v['return'] ) $this->_helper->redirector($return,'employee',null,array('id' => $v['id']));	
			if( $v['return'] AND $v['return_n'] AND $v['return_id'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id']));			
			
		}	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$select = $db->select();
		$select->from('employee_settlement')
			->join('project', 'employee_settlement.project_id = project.project_id')
			->join('company', 'company.company_id = project.company_id');  
		$select->where('employee_settlement.employee_id = ?', $v['id']);
		$select->where("employee_settlement.employee_settlement_id = ?", $v['ids']);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->employeeSettlementData = $data[0];
	}
	
	public function settlementbonuseditAction() {	
		
		$v = $this->_request->getParams();	
		
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');
		
		$Employee = new Employee();			
		$EmployeeSettlementBonus = new EmployeeSettlementBonus();		
		$db = Zend_Registry::get('db');		
		
		
		if( isset($v['employee_settlementedit']) ){		

			$data = array(		
				'bonus_type_id' => $v['bonus_type_id'],		
				
				'employee_settlement_bonus_amount' => isset($v['employee_settlement_bonus_amount'])?str_replace(",",".",$v['employee_settlement_bonus_amount']):'0.00',		
				
				'employee_settlement_bonus_note' => $v['employee_settlement_bonus_note'],
				
				'employee_settlement_bonus_edit' => Lib_Date::datetime()
			);
			$EmployeeSettlementBonus->update($data, 'employee_settlement_bonus_id='.$v['ids'] );

			$return = 'settlementbonus';	
			
			if( isset($v['return']) ) $return = $v['return'];	
			
			if($return == 'settlementbonus') $information->addEmployeeSettlementSuccess = true;
			
			if( !$v['return'] ) $this->_helper->redirector($return,'employee',null,array('id' => $v['id']));	
			if( $v['return'] AND $v['return_n'] AND $v['return_id'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id']));			
			
		}	
		
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$select = $db->select();
		$select->from('employee_settlement_bonus');
		//	->join('project', 'employee_settlement_bonus.project_id = project.project_id')
		//	->join('company', 'company.company_id = project.company_id');  
		$select->where('employee_settlement_bonus.employee_id = ?', $v['id']);
		$select->where("employee_settlement_bonus.employee_settlement_bonus_id = ?", $v['ids']);
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->employeeSettlementData = $data[0];
		
		$EmployeeAlert = new EmployeeAlert();			
		$d = date("Y-m-d");		
		$where = "employee_id = ".$v["id"]." AND employee_alert_start <= '".$d."' AND employee_alert_stop >= '".$d."'";
		$data = $EmployeeAlert->fetchAll($where , array('employee_alert_start DESC','employee_alert_stop DESC')); 	
		$this->view->dataTableEmployeeAlert = $data;
	
		$BonusType = new BonusType();		
		$data = $BonusType->fetchAll(null , 'bonus_type_sort ASC'); 		
		$this->view->dataTableBonusType = $data;
	}
	
	
	
	
	
	
	
	public function employeecalendarAction() {
		$v = $this->_request->getParams();
		
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();				
		$db = Zend_Registry::get('db');				
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
	}
	
	
	
	
	
	
	
	public function employeecalendarchAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();				
		$db = Zend_Registry::get('db');				
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		
	/*	
		$output_arrays[0]['title'] = $v['dStart'];
		$output_arrays[0]['start'] = '2016-11-19';
		
		$output_arrays[1]['title'] = '2';
		$output_arrays[1]['start'] = '2016-11-18';
		
		$output_arrays[2]['title'] = '3';
		$output_arrays[2]['start'] = '2016-11-17';
	*/	

		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');
		$select->where('employee_id = '.$v['id']);	

		$searchFiltrData = "
		(employee_settlement.employee_settlement_date >= '".$v['dStart']."' AND employee_settlement.employee_settlement_date <= '".$v['dStop']."')
		";
		
		$select->where($searchFiltrData);
		$select->order(array('employee_settlement_date DESC'))->limit($limit,$p);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
	
		$i = -1;
		foreach($data AS $key => $val){
			$i++;
			$output_arrays[$i]['title'] = $val['project_name'];
			
			$output_arrays[$i]['description'] =  $val['project_name'];
			
			$output_arrays[$i]['start'] = $val['employee_settlement_date']."T".$val['employee_settlement_start'];
			$output_arrays[$i]['end'] = $val['employee_settlement_date']."T".$val['employee_settlement_stop'];
		//	$output_arrays[$i]['url'] = $this->_helper->url(array('controller' => 'employee', 'action' => 'settlementedit', 'id' => $v['id'], 'ids' => $val['employee_settlement_id']));
			$output_arrays[$i]['url'] = $this->_helper->url->url(array('controller' => 'employee', 'action' => 'settlementedit', 'id' => $v['id'], 'ids' => $val['employee_settlement_id']));
		}
	
	
		echo json_encode($output_arrays);		
	}
	
	
	
	
	
	
	
	
	public function projectindexcheckcountAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
				
		$db = Zend_Registry::get('db');	

		$select = $db->select();
		$select->from('employee_settlement',array('COUNT(employee_settlement_id) as count', 'employee_settlement_id'));
		$select->where('project_id = '.$v['id']);	
		$select->where("employee_settlement_date LIKE '".$v['d']."'");	
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$dataCount = $data[0]['count'];	
		echo$dataCount;
	}
	
	
	
	
	
	
	
	
	public function projectindexcheckcountallAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
				
		$db = Zend_Registry::get('db');	
		
		$ask = "SELECT `employee_settlement_date` AS date, COUNT(`employee_settlement_id`) AS count FROM `employee_settlement` WHERE 
		project_id = ".$v['id']." AND 
		(employee_settlement.employee_settlement_date >= '".$v['dStart']."' AND employee_settlement.employee_settlement_date <= '".$v['dStop']."')
		GROUP BY `employee_settlement_date`";
		$data = $db->query($ask)->fetchAll();
		
		echo json_encode($data);
	}
	
	
	
	
	public function projectcalendarchAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		
		$Employee = new Employee();		
		$EmployeeSettlement = new EmployeeSettlement();				
		$db = Zend_Registry::get('db');		
		
		
	/*	
		$output_arrays[0]['title'] = $v['dStart'];
		$output_arrays[0]['start'] = '2016-11-19';
		
		$output_arrays[1]['title'] = '2';
		$output_arrays[1]['start'] = '2016-11-18';
		
		$output_arrays[2]['title'] = '3';
		$output_arrays[2]['start'] = '2016-11-17';
	*/	

	
	/*
		$select = $db->select();
		$select->from('employee_settlement')->join('employee', 'employee.employee_id = employee_settlement.employee_id');
		$select->where('project_id = '.$v['id']);	

		$searchFiltrData = "
		(employee_settlement.employee_settlement_date >= '".$v['dStart']."' AND employee_settlement.employee_settlement_date <= '".$v['dStop']."')
		";
		
		$select->where($searchFiltrData);
		$select->order(array('employee_settlement_date DESC'))->limit($limit,$p);  
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
	*/

		$searchFiltrData = "
		AND (es.employee_settlement_date >= '".$v['dStart']."' AND es.employee_settlement_date <= '".$v['dStop']."')
		";

		$query = "SELECT * FROM employee_settlement es, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id
				WHERE 
					e.employee_id = es.employee_id
				AND
					es.project_id = ".$v['id']."
					".$searchFiltrData."
				ORDER BY 
				employee_settlement_date ASC,
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				employee_secondname ASC, employee_firstname ASC";
		$data = $db->query($query)->fetchAll();		
		if( $_GET['view_query'] == true )echo$query;
	
	
		$i = -1;
		foreach($data AS $key => $val){
			$i++;
			
			$sort = $i;			
			if( strlen($sort) == 1 ) $sort = '00000'.$sort;
			if( strlen($sort) == 2 ) $sort = '0000'.$sort;
			if( strlen($sort) == 3 ) $sort = '000'.$sort;
			if( strlen($sort) == 4 ) $sort = '00'.$sort;
			if( strlen($sort) == 5 ) $sort = '0'.$sort;
			
			$output_arrays[$i]['sort'] = $sort;
			
			$output_arrays[$i]['title'] = $val['employee_secondname'].' '.$val['employee_firstname'].' ('.Lib_Date::convertDate($val['employee_settlement_time'],'H:i:s','H:i').'h)';
			
		//	$output_arrays[$i]['team'] = $val['employeeteam_name'];
			
			$output_arrays[$i]['description'] = $val['employee_secondname'].' '.$val['employee_firstname'].' ('.Lib_Date::convertDate($val['employee_settlement_time'],'H:i:s','H:i').'h), '.@LANG_cal_time.': '.Lib_Date::convertDate($val['employee_settlement_start'],'H:i:s','H:i').' - '.Lib_Date::convertDate($val['employee_settlement_stop'],'H:i:s','H:i').', '.@LANG_cal_rate.': '.$val['employee_settlement_rate']." \xE2\x82\xAc";			
			
			$output_arrays[$i]['start'] = $val['employee_settlement_date'];//."T".$val['employee_settlement_start'];
			$output_arrays[$i]['end'] = $val['employee_settlement_date'];//."T".$val['employee_settlement_stop'];
			$output_arrays[$i]['date'] = $val['employee_settlement_date'];
			$output_arrays[$i]['url'] = $this->_helper->url->url(array('controller' => 'employee', 'action' => 'settlementedit', 'id' => $val['employee_id'], 'ids' => $val['employee_settlement_id'], 'return' => 'projectindex', 'return_n' => 'id', 'return_id' => $v['id']));
			
			$output_arrays[$i]['linkrem'] = $this->_helper->url->url(array('controller' => 'employee', 'action' => 'settlementremove', 'id' => $val['employee_id'], 'ids' => $val['employee_settlement_id'], 'return' => 'projectindex', 'return_n' => 'id', 'return_id' => $v['id']));
		}
	
	
		echo json_encode($output_arrays);		
	}
	
	
	
	
	
	public function employeedayAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
			
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');
		
		$searchEmployee = "employee_settlement.employee_id = ".$v['id']."";	
		$select->where($searchEmployee);	
		
		$searchData = "employee_settlement.employee_settlement_date LIKE '".Lib_Date::convertDate($v['date'],"d-m-Y","Y-m-d")."'";	
		$select->where($searchData);					
		
		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
	
	}
	
	
	
	
	
	public function employeehistoryrateAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
			
		$select = $db->select();
		$select->from('employee_rate_history');
		
		$searchEmployee = "employee_rate_history.employee_id = ".$v['id']."";	
		$select->where($searchEmployee);					
		
		$select->order(array('employee_rate_history.employee_rate_history_ins DESC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
	
	}
	
	
	
	
	
	public function employeehistoryemployeeteamAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$db = Zend_Registry::get('db');	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
			
		$select = $db->select();
		$select->from('employee_employeeteam_history');
		
		$searchEmployee = "employee_employeeteam_history.employee_id = ".$v['id']."";	
		$select->where($searchEmployee);					
		
		$select->order(array('employee_employeeteam_history.employee_employeeteam_history_ins DESC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
	
		$ask = "
			SELECT * FROM employeeteam";
	
		$data = $db->query($ask)->fetchAll();			
		foreach( $data as $key => $val ){		
			$d[$val['employeeteam_id']] = $val['employeeteam_name'];		
		}	
		$d[0] = '-';	
	
		$this->view->employeeteamData = $d;	
	}
	
	
	
	
	
	public function employeehistoryemploymenttypeAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$db = Zend_Registry::get('db');	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
			
		$select = $db->select();
		$select->from('employee_employment_type_history');
		
		$searchEmployee = "employee_employment_type_history.employee_id = ".$v['id']."";	
		$select->where($searchEmployee);					
		
		$select->order(array('employee_employment_type_history.employee_employment_type_history_ins DESC'));
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();	
		$this->view->dataTable = $data;	
	
	}
	
	
	public function addalertdateAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();		
		
		$Employee = new Employee();	
		$select = $Employee->select();
		$select->where('employee_id = ?', $v['id']);	
		$row = $Employee->fetchRow($select);
		$this->view->employeeData = $row;
		
		$this->view->dateAlert = $v['date'];	
		$AlertType = new AlertType();		
		
		
		
		
		
		$data = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 		
		$this->view->dataTableAlertType = $data;
	}
	
	public function addalertdatefinishAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		$this->_helper->viewRenderer->setNoRender();		
		
		$EmployeeAlert = new EmployeeAlert();		
		$data = array(
			'employee_id' => $v['id'],
			'employee_alert_start' => Lib_Date::convertDate($v['employee_alert_start'],"d-m-Y","Y-m-d"),
			'employee_alert_stop' => Lib_Date::convertDate($v['employee_alert_stop'],"d-m-Y","Y-m-d"),
			'alert_type_id' => $v['alert_type_id'],			
			'employee_alert_note' => isset($v['employee_alert_note'])?$v['employee_alert_note']:'',
			'admin_id' => $admin->admin_id
		);
		$EmployeeAlert->insert($data);	
		
		$alerts = Lib_Employee::EmployeeAlert($v['id']);				
		$alert = '';		
		
		$i=0; 
		foreach ($alerts as $key => $val){
			$i=$i+1;
			$alert = $alert.@LANG_employee_settlement_alert.' '.$i.': '.@constant(@LANG_alert_type_.$val['alert_type_id']).': '.$val['employee_alert_note'].' ('.Lib_Date::convertDate($val['employee_alert_start']).' - '.Lib_Date::convertDate($val['employee_alert_stop']).")<br /> ";
		}
		echo$alert;
	}
	
	
	
	public function projectraportAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
		$EmployeeGroup = new EmployeeGroup();		
		$data = $EmployeeGroup->fetchAll('employeegroup_activ = 0' , 'employeegroup_name ASC'); 		
		$this->view->dataTableEmployeeGroup = $data;	
	
		$this->view->employeegroup_id = $v['employeegroup_id'];
		
	}
	
	
	
	
	
	public function projectraportgenAction() {		
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		
		Zend_Session::namespaceUnset('massSum');
		$massSum = new Zend_Session_Namespace('massSum');	
		$massSum->sum = 0;
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		

		
		
		if( $v['employeegroup_id'] == 'all' ){ 
			$ask = "
				SELECT * FROM employee_settlement, employee WHERE employee_settlement.employee_id = employee.employee_id $searchData GROUP BY employee_settlement.employee_id ORDER BY employee_secondname, employee_firstname
			";
		}else{
			$ask = "
				SELECT * FROM employee_settlement, employee, employee_employeegroup WHERE employee_settlement.employee_id = employee.employee_id AND employee_employeegroup.employee_id = employee.employee_id AND employee_employeegroup.employeegroup_id = '".$v['employeegroup_id']."' $searchData GROUP BY employee_settlement.employee_id ORDER BY employee_secondname, employee_firstname
			";		
		}
		
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
		
		
		$sumt = 0;
		$sumAll = 0;
		foreach( $data as $key => $val ){
		
			$select = $db->select();
			$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
			$select->where('employee_id = '.$val['employee_id'].' '.$searchData);
			$select->order(array('employee_settlement.employee_settlement_date ASC'));
			$stmt = $db->query($select);
			$dataE = $stmt->fetchAll();	
			
			$rateSum = 0;
			foreach( $dataE as $keyE => $valE ){				
				$timeVar = Lib_Date::convertDate($valE['employee_settlement_time'],'H:i:s','H:i'); 					
				$tr = explode(":",$timeVar);
				$sumt = $sumt + $tr[0]*60 + $tr[1];	
				$tV = explode(":",$timeVar);
				$rateSum = $rateSum + number_format($tV[0]*$val['employee_settlement_rate'] + $tV[1]*$val['employee_settlement_rate']/60, 2);
			}
			
			$sumAll = $sumAll + $rateSum;
		
		}
		
		$this->view->sumAll = $sumAll;
		
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];
		$this->view->project_separately = $v['project_separately'];
		$this->view->rate = $v['rate'];
		$this->view->sum = $v['sum'];
	}
	
	
	
	
	
	public function projectraportgensumAction() {	
		$massSum = new Zend_Session_Namespace('massSum');
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
	
		echo number_format($massSum->sum, 2, ',', ' ').' &euro;';
	}
	
	
	
	
	
	public function employeeraportAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$filtr = new Zend_Session_Namespace('filtrraportday');		
	//	$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
	
		$orderEmployee = array('employeegroup_name ASC');
		$searchEmployeeName = 'employeegroup_activ = 0';
		$EmployeeGroup = new EmployeeGroup();	
		$data = $EmployeeGroup->fetchAll($searchEmployeeName , $orderEmployee); 		
		$this->view->dataTableEG = $data;	
			
		$this->view->filtr_team = $filtr->team;	
	}
	
	
	
	
	
	public function employeeraportgenAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$filtr = new Zend_Session_Namespace('filtrraportday');		
		$db = Zend_Registry::get('db');	
		
		$searchData = '';
		$searchDataAlert = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."')";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."')";
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
			
			
			$searchDataAlert = "AND ( (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."') OR (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'))";
		}			
		
		
		$askAlert = "(SELECT COUNT(*) AS iA FROM employee_alert WHERE 
			e.employee_id = employee_alert.employee_id
			$searchDataAlert
			) AS iA";
	
		$askFlatGroup = "
			(SELECT GROUP_CONCAT(employeegroup_name SEPARATOR ', ') FROM employeegroup eg, employee_employeegroup eeg WHERE eeg.employee_id = e.employee_id AND eg.employeegroup_id = eeg.employeegroup_id AND eg.employeegroup_type_id = 2 ORDER BY employeegroup_name) AS employeegroup_flat
		";
			
		$order = " ORDER BY employee_secondname, employee_firstname";
			
		if( $v['team'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, employee_secondname, employee_firstname";
		}
			
		if( $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
			
		if( $v['team'] == 1 AND $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
		
		if( $v['employeegroup_id'] == 'all' ){
			$ask = "
				SELECT *, $askAlert, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id WHERE employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}else{		
			$ask = "
				SELECT *, $askAlert, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_employeegroup WHERE employee_employeegroup.employee_id = e.employee_id AND employee_employeegroup.employeegroup_id = ".$v['employeegroup_id']." AND employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}
		
	//	echo$ask; die();
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
		
		$this->view->dataTableCount = count($data);	
		
		
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];		
		$this->view->employeegroup_id = $v['employeegroup_id'];		
		
		$this->view->rate = $v['rate'];
		$this->view->sum = $v['sum'];
		$this->view->ns = $v['ns'];
		$this->view->team = $v['team'];
		$this->view->flat = $v['flat'];
		$this->view->residence = $v['residence'];
		
		$filtr->team = $v['team'];
			
		$order = "
			ORDER BY
			iA ASC,
			`employee_secondname` ASC,
			`employee_firstname`ASC";
			
		if( $v['team'] == 1 ){
			$order = "
				ORDER BY
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				iA ASC,
				`employee_secondname` ASC,
				`employee_firstname`ASC";
		}
	
	
	
	
	
	
	
	
		
		$askAlert = "(SELECT COUNT(*) AS iA FROM employee_alert WHERE 
			e.employee_id = employee_alert.employee_id
			$searchDataAlert
			) AS iA";
			
if( $v['employeegroup_id'] == 'all' ){		
		$ask = "
			SELECT 
			e.*,
			et.*,

			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			$searchData
			) AS i,
			
			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			) AS iOg,
			
			$askAlert
			 
			FROM `employee` e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id
			WHERE
			`employee_activ` = 0
			AND
			employee_activ_order2 = 0		
		".$order;
}else{
		$ask = "
			SELECT 
			e.*,
			et.*,
			
			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			$searchData
			) AS i,
			
			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			) AS iOg,
			
			$askAlert
			 
			FROM `employee` e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_employeegroup
			WHERE
			employee_employeegroup.employee_id = e.employee_id AND employee_employeegroup.employeegroup_id = ".$v['employeegroup_id']." AND 
			`employee_activ` = 0
			AND
			employee_activ_order2 = 0		
		".$order;
}		
//echo$ask;
		$data = $db->query($ask)->fetchAll();	
	
		$dataCount = 0;
		$dataCountNew = 0;
		foreach ($data as $key => $val){
			if( $val['i'] == 0 ){
				$dataCount++;
			}
			if( $val['iOg'] == 1 ){
				$dataCountNew++;
			}
		}
			
		$this->view->dataTableNSCount = $dataCount;	
		$this->view->dataTableNewCount = $dataCountNew;	
	
	
		if( $v['ns'] == 1 ){		
			$this->view->dataTableNS = $data;			
		}
		
		
		
		
/*		$ask = "
SELECT 
*
FROM
`employee` e
LEFT JOIN
employee_settlement
ON 
(e.employee_id = employee_settlement.employee_id)
WHERE
`employee_activ` = 0 $searchData AND employee_settlement.employee_settlement_id IS NULL

GROUP BY
e.employee_id
ORDER BY
`employee_secondname` ASC,
`employee_firstname`ASC			
		";
*/		
		$link = '?';		
		$link = $link.'employee_settlement_date_start='.$v['employee_settlement_date_start'].'&';
		$link = $link.'employee_settlement_date_stop='.$v['employee_settlement_date_stop'].'&';
		$link = $link.'employeegroup_id='.$v['employeegroup_id'].'&';
		$link = $link.'rate='.$v['rate'].'&';
		$link = $link.'sum='.$v['sum'].'&';
		$link = $link.'ns='.$v['ns'].'&';
		$link = $link.'team='.$v['team'].'&';
		$link = $link.'flat='.$v['flat'].'&';
		$link = $link.'residence='.$v['residence'].'&';
		$this->view->link = $link;
	}
	
	
	
	
	
	public function employeeraportgenxlsAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');	
		$filtr = new Zend_Session_Namespace('filtrraportday');		
		$db = Zend_Registry::get('db');	
		
		$searchData = '';
		$searchDataAlert = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."')";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."')";
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
			
			
			$searchDataAlert = "AND ( (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."') OR (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'))";
		}			
		
		
		$askAlert = "(SELECT COUNT(*) AS iA FROM employee_alert WHERE 
			e.employee_id = employee_alert.employee_id
			$searchDataAlert
			) AS iA";
	
		$askFlatGroup = "
			(SELECT GROUP_CONCAT(employeegroup_name SEPARATOR ', ') FROM employeegroup eg, employee_employeegroup eeg WHERE eeg.employee_id = e.employee_id AND eg.employeegroup_id = eeg.employeegroup_id AND eg.employeegroup_type_id = 2 ORDER BY employeegroup_name) AS employeegroup_flat
		";
			
		$order = " ORDER BY employee_secondname, employee_firstname";
			
		if( $v['team'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, employee_secondname, employee_firstname";
		}
			
		if( $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
			
		if( $v['team'] == 1 AND $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
		
		if( $v['employeegroup_id'] == 'all' ){
			$ask = "
				SELECT *, $askAlert, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id WHERE employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}else{		
			$ask = "
				SELECT *, $askAlert, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_employeegroup WHERE employee_employeegroup.employee_id = e.employee_id AND employee_employeegroup.employeegroup_id = ".$v['employeegroup_id']." AND employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}
		
		
		$dataTable = $db->query($ask)->fetchAll();			


		

		$name = mb_strtolower ('raport', 'UTF-8');
		$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');	
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(45);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(45);
		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
		
		$i = 0;
		$i++;
		$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('A'.$i, @LANG_employee_rap_lp)	
				->setCellValue('B'.$i, @LANG_employee_rap_name)		
				->setCellValue('C'.$i, @LANG_employee_rap_time)
				->setCellValue('D'.$i, @LANG_employee_rap_rate)						
				->setCellValue('E'.$i, @LANG_employee_rap_sum)
				->setCellValue('F'.$i, @LANG_employee_rap_flat)
				->setCellValue('G'.$i, @LANG_employee_rap_residence);
		
		$objPHPExcel->getActiveSheet()->getStyle("A1:G1")->getFont()->setSize(14)->setBold(true);
			
		$objPHPExcel->getActiveSheet()->getStyle("A1:G1")->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				 'rgb' => 'cef6ce'
			)
		));
			
		$j = 0;
	
		$nnn = '';

		$massSum = new Zend_Session_Namespace('massSum');
		unset($massSum->sum);
		$massSum->sum = 0;
		$sumtimeh = 0;
		$sumEur = 0;
		foreach ($dataTable as $key => $val): $i++;
			
			if( $nnn != $val['employeeteam_name'] ){
				$vteam = 1;
				$nnn = $val['employeeteam_name'];
			}else $vteam = 0;	


			if( $v['team'] == 1 && $vteam == 1 ){
				if( $val['employeeteam_name'] != null ) $etn = $val['employeeteam_name']; 
				else $etn =@LANG_employee_list_team_np;				
				$objPHPExcel->getActiveSheet()->mergeCells('A'.$i.':G'.$i.'');
				$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $etn);
				$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFill()->applyFromArray(array(
					'type' => PHPExcel_Style_Fill::FILL_SOLID,
					'startcolor' => array(
						 'rgb' => 'FBCD68'
					)
				));
				$objPHPExcel->getActiveSheet()->getStyle("A".$i)->getFont()->setSize(12)->setBold(1);
				$i++;				
			}
			
			
			unset($dataInfo);
			$dataInfo = Lib_Employee::InfoRaport($val['employee_id'], Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d"), Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d"));
			$sumtimeh = $sumtimeh +$dataInfo['time'];			
			
			if( $dataInfo['min'] == $dataInfo['max'] ){ 
				$dtval = number_format($dataInfo['min'], 2, ',', ' ');				
			}else{				
				$dtval = number_format($dataInfo['min'], 2, ',', ' ').'-'.number_format($dataInfo['max'], 2, ',', ' ');
			}
			$datreval = '';
			if( $val['employee_residence_date_start'] != '0000-00-00' ) $datreval = $val['employee_residence_date_start'];
			
			$dataInfo['sum'] = Lib_Data::roundSpecialPrice($dataInfo['sum']);
			$sumEur = $sumEur + $dataInfo['sum'];
			
			$j++;			
			$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i, $j.'.')	
					->setCellValue('B'.$i, $val['employee_secondname'].' '.$val['employee_firstname'])		
					->setCellValue('C'.$i, $dataInfo['time'].'h')
					->setCellValue('D'.$i, $dtval." \xE2\x82\xAc")						
					->setCellValue('E'.$i, number_format($dataInfo['sum'], 2, ',', ' ')." \xE2\x82\xAc")				
					->setCellValue('F'.$i, $val['employeegroup_flat'])
					->setCellValue('G'.$i, $datreval);			

		endforeach;
		
		
		$i++;
		$objPHPExcel->setActiveSheetIndex(0)		
				->setCellValue('C'.$i, $sumtimeh.'h')
				->setCellValue('E'.$i, number_format($sumEur, 2, ',', ' ')." \xE2\x82\xAc");	
		$objPHPExcel->getActiveSheet()->getStyle("C".$i)->getFont()->setSize(12)->setBold(1);
		$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFont()->setSize(12)->setBold(1);			
		$objPHPExcel->getActiveSheet()->getStyle("C".$i)->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				 'rgb' => 'cef6ce'
			)
		));			
		$objPHPExcel->getActiveSheet()->getStyle("E".$i)->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				 'rgb' => 'cef6ce'
			)
		));
	
	

		if( $v['residence'] != 1 ){
			$objPHPExcel->getActiveSheet()->removeColumn('G');
		}
		if( $v['flat'] != 1 ){
			$objPHPExcel->getActiveSheet()->removeColumn('F');
		}
		if( $v['sum'] != 1 ){
			$objPHPExcel->getActiveSheet()->removeColumn('E');
		}
		if( $v['rate'] != 1 ){
			$objPHPExcel->getActiveSheet()->removeColumn('D');
		}	
		
	
	
		$objPHPExcel->setActiveSheetIndex(0);

		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
		header('Cache-Control: max-age=0');
		header('Cache-Control: max-age=1');

		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
		header ('Cache-Control: cache, must-revalidate');
		header ('Pragma: public');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');	
	}
	
	
	
	
	
	
	
	
	
	
	public function employeeraportalertAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$d = date('Y-m-d');
		
		$ask = "
SELECT *, (SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '2017-05-01' AND e.employee_id = es.employee_id) AS timeSum, (SELECT MAX( `employee_settlement_date` ) AS maxDate FROM employee_settlement es WHERE e.employee_id = es.employee_id) AS maxDate, (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".$d."' AND ea.employee_alert_stop >= '".$d."') AS countAlert, (SELECT COUNT( `employee_settlement_id` ) AS countR FROM employee_settlement es WHERE e.employee_id = es.employee_id AND es.employee_settlement_rate = 0) AS countR FROM `employee` e WHERE employee_activ=0 AND (SELECT COUNT( `employee_alert_id` ) AS countAlert FROM employee_alert ea WHERE e.employee_id = ea.employee_id AND ea.employee_alert_start <= '".$d."' AND ea.employee_alert_stop >= '".$d."') > 0 ORDER BY employee_secondname ASC, employee_firstname ASC	
		";
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
		
		$this->view->noprint = $v['noprint'];
	}
	
	
	
	
	
	public function employeeraportgroupalertAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$d = date('Y-m');
		
// AND (SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum FROM employee_settlement es WHERE es.employee_settlement_date >= '".$d."-01' AND e.employee_id = es.employee_id) > 0 
		$ask = "
SELECT * FROM employee e, employeeteam et 
WHERE 
e.employeeteam_id = et.employeeteam_id
AND e.employee_activ = 0 
ORDER BY et.employeeteam_name, e.employee_secondname, e.employee_firstname;	
		";
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	

		$AlertType = new AlertType();	
		$data = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 		
		$this->view->dataTableAlertType = $data;
		
		$this->view->noprint = $v['noprint'];
	}
	
	
	
	
	
	public function employeeraportgroupxlsalertAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$d = date('Y-m');
		
		$ask = "
SELECT * FROM employee e, employeeteam et 
WHERE 
e.employeeteam_id = et.employeeteam_id
AND e.employee_activ = 0 
ORDER BY et.employeeteam_name, e.employee_secondname, e.employee_firstname;	
		";
		
		$dataTable = $db->query($ask)->fetchAll();	

		$AlertType = new AlertType();	
		$dataTableAlertType = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 	
		
		
		
		

		

		$name = mb_strtolower ('alert', 'UTF-8');
		$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');	
		
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(40);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(125);
		
		$objPHPExcel->getActiveSheet()->mergeCells('A1:C1');
		$objPHPExcel->getActiveSheet()->setCellValue('A1', @LANG_header_title_printalert.' - '.date('d-m-Y'));
		$rowid = 1;
		$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(16);
		
		$rowid++;				
		$objPHPExcel->setActiveSheetIndex(0)
			->setCellValue('A'.$rowid, @LANG_employee_rap_lp)	
			->setCellValue('B'.$rowid, @LANG_employee_rap_name)		
			->setCellValue('C'.$rowid, @LANG_employee_rap_alert);
			
		$objPHPExcel->getActiveSheet()->getStyle('A'.$rowid.':C'.$rowid)->getFont()->setBold(true);
		
		$objPHPExcel->getActiveSheet()->getStyle('A'.$rowid.':C'.$rowid)->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				'rgb' => 'f6cece'
			)
		));

		$i = 0;
		$sumtimeh = 0;
		$team = '';
		
		$alertALL_i_0 = 0;
		$alertALL_i_1 = 0;
		$alertALL_iIF_1 = 0;
		$alertALL_type = array();
		
		$dataTable1 = $dataTable;
		foreach ($dataTable1 as $key => $val):
		
		if( $team != $val['employeeteam_name'] ){
			
			$rowid++;
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':C'.$rowid);
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $val['employeeteam_name']);
			$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(14);
			$objPHPExcel->getActiveSheet()->getStyle('A'.$rowid)->getFill()->applyFromArray(array(
				'type' => PHPExcel_Style_Fill::FILL_SOLID,
				'startcolor' => array(
					'rgb' => 'c9fff7'
				)
			));
		
			$team = $val['employeeteam_name'];
			$i = 0;
			$alert_i_0 = 0;
			$alert_i_1 = 0;
			$alert_iIF_1 = 0;
			
		}	
		$i++;
		
		$rowid++;
		$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $i);
		$objPHPExcel->getActiveSheet()->setCellValue('B'.$rowid, $val['employee_secondname'].' '.$val['employee_firstname']);


		$a_xls = '';
		$alerts = Lib_Employee::EmployeeAlert($val['employee_id']);
		if( count($alerts) > 0 ){ 
			$alert_i_1++;		
			$alertALL_i_1++;					
			$alert = '';
			$i2=0; foreach ($alerts as $key1 => $val1): $i2=$i2+1;
			if( $i2 > 1 )$alert = $alert."\n";
			$alert = $alert.''.@constant(@LANG_alert_type_.$val1['alert_type_id']).' ('.Lib_Date::convertDate($val1['employee_alert_start']).' - '.Lib_Date::convertDate($val1['employee_alert_stop']).'): '.$val1['employee_alert_note'];		
			$alertALL_type[$val1['alert_type_id']]++; 
			endforeach;

			$a_xls = $alert; 

		}else{
			$alert_i_0++;
			$alertALL_i_0++;
		}	
		
		$alerts = Lib_Employee::EmployeeAlertInFuture($val['employee_id']);
		if( count($alerts) > 0 ){ 
			$alert_iIF_1++;		
			$alertALL_iIF_1++;					
			$alert = '';
			foreach ($alerts as $key1 => $val1): $i2=$i2+1;
			if( $i2 > 2 )$alert = $alert."\n";
			$alert = $alert.''.@constant(@LANG_alert_type_.$val1['alert_type_id']).' ('.Lib_Date::convertDate($val1['employee_alert_start']).' - '.Lib_Date::convertDate($val1['employee_alert_stop']).'): '.$val1['employee_alert_note'];
			endforeach;

			$a_xls = $a_xls.$alert; 
		}
		
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$rowid, $a_xls);
		
		
		
		$nextval = next($dataTable1);
		if( $team != $nextval['employeeteam_name'] ){
			$rowid++;
			$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':C'.$rowid);
			
			$nval = @LANG_employee_rap_alert_0." ".$alert_i_0."\n".@LANG_employee_rap_alert_1." ".$alert_i_1."\n".@LANG_employee_rap_alertIF_1." ".$alert_iIF_1;//."\n";
			
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $nval);
		}
		

		endforeach;
	

		$rowid++;
		$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':C'.$rowid);
		
		$nval = @LANG_employee_rap_alert_0." ".$alertALL_i_0."\n".@LANG_employee_rap_alert_1." ".$alertALL_i_1."\n".@LANG_employee_rap_alertIF_1." ".$alertALL_iIF_1."\n";
		foreach ($dataTableAlertType as $key => $val):
			$nval = $nval.@constant(@LANG_alert_type_.$val['alert_type_id']).": ".(($alertALL_type[$val['alert_type_id']])?$alertALL_type[$val['alert_type_id']]:0)."\n";
		endforeach;
		
		$objPHPExcel->getActiveSheet()->setCellValue('A'.$rowid, $nval);
		$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				'rgb' => 'f6cece'
			)
		));	
		
		$objPHPExcel->setActiveSheetIndex(0);

		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
		header('Cache-Control: max-age=0');
		header('Cache-Control: max-age=1');

		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
		header ('Cache-Control: cache, must-revalidate');
		header ('Pragma: public');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');	
	}
	
	
	public function employeeraportsummaryAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$day = Lib_Date::convertDate($v['day'],"d-m-Y","Y-m-d");
		
		$searchOP = '';
		
		if( $v['op'] != '' ){
		
			$searchOP = " AND p.project_employee_name LIKE '".str_replace("*","%",$v['op'])."'";
			
		}
		
		$ask = "
SELECT * FROM 
employee_settlement es, project p, company c 
WHERE 
p.project_id = es.project_id 
AND
p.company_id = c.company_id
AND
es.employee_settlement_date LIKE '".$day."'
$searchOP
GROUP BY es.project_id
ORDER BY
p.project_employee_name ASC,
c.company_name ASC,
p.project_name ASC		
		";
		
		$data = $db->query($ask)->fetchAll();		



		foreach( $data as $key => $val ){
		
		
		if( $v['o1'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee_settlement es, employee e LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = e.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				e.employee_id = es.employee_id
				AND
				es.project_id = '".$val['project_id']."'
				AND
				es.employee_settlement_date LIKE '".$day."'
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
			
			$data[$key]['employeeo1'] = $db->query($ask)->fetchAll();
		}
		
		
		if( $v['o2'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' ),
				employee_project ep LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = ep.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NOT NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				e.employee_id = ep.employee_id
				AND
				ep.project_id = '".$val['project_id']."'
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
		//	echo$ask.'<br />';
			$data[$key]['employeeo2'] = $db->query($ask)->fetchAll();
		}
		
		
		if( $v['o3'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' ),
				employee_project ep LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = ep.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				e.employee_id = ep.employee_id
				AND
				ep.project_id = '".$val['project_id']."'
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
		//	echo$ask.'<br />';
			$data[$key]['employeeo3'] = $db->query($ask)->fetchAll();
		}
		
		}
		
		$this->view->dataTable = $data;	
		
		
		
		
		if( $v['o4'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' )
				LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = e.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NULL
				AND
				es.employee_settlement_id IS NULL
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC		
			
			";
		//	echo$ask.'<br />';
			$dataemployeeo4 = $db->query($ask)->fetchAll();
			$this->view->employeeo4 = $dataemployeeo4;	
		}
		
		
		
		
		
				
		$this->view->day = $v['day'];	
		$this->view->o1 = $v['o1'];	
		$this->view->o2 = $v['o2'];	
		$this->view->o3 = $v['o3'];	
		$this->view->o4 = $v['o4'];	
	}
	
	
	public function employeeraportsummarysystemAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$day = Lib_Date::convertDate($v['day'],"d-m-Y","Y-m-d");
		
		$searchOP = '';
		
		if( $v['op'] != '' ){
		
			$searchOP = " AND p.project_employee_name LIKE '".str_replace("*","%",$v['op'])."'";
			
		}
		
		$ask = "
SELECT * FROM 
employee_settlement es, project p, company c 
WHERE 
p.project_id = es.project_id 
AND
p.company_id = c.company_id
AND
es.employee_settlement_date LIKE '".$day."'
$searchOP
GROUP BY es.project_id
ORDER BY
p.project_employee_name ASC,
c.company_name ASC,
p.project_name ASC		
		";
		
		$data = $db->query($ask)->fetchAll();		



		foreach( $data as $key => $val ){
		
		
		if( $v['o1'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee_settlement es, employee e LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = e.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				e.employee_id = es.employee_id
				AND
				es.project_id = '".$val['project_id']."'
				AND
				es.employee_settlement_date LIKE '".$day."'
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
			
			$data[$key]['employeeo1'] = $db->query($ask)->fetchAll();
		}
		
		
		if( $v['o2'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' ),
				employee_project ep LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = ep.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NOT NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				e.employee_id = ep.employee_id
				AND
				ep.project_id = '".$val['project_id']."'
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
		//	echo$ask.'<br />';
			$data[$key]['employeeo2'] = $db->query($ask)->fetchAll();
		}
		
		
		if( $v['o3'] == 1 ){
			/*
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' ),
				employee_project ep LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = ep.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				e.employee_id = ep.employee_id
				AND
				ep.project_id = '".$val['project_id']."'
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
			*/
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' ),
				employee_project ep LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = ep.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				WHERE
				ea.employee_alert_id IS NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				e.employee_id = ep.employee_id
				AND
				ep.project_id = '".$val['project_id']."'
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC			
			
			";
		//	echo$ask.'<br />';
			$data[$key]['employeeo3'] = $db->query($ask)->fetchAll();
		}
		
		}
		
		$this->view->dataTable = $data;	
		
		
		
		
		if( $v['o4'] == 1 ){
			$ask = "
			
				SELECT * FROM 
				employee e 
				LEFT JOIN employee_settlement es
				ON ( es.employee_id = e.employee_id AND es.employee_settlement_date LIKE '".$day."' )
				LEFT JOIN employee_alert ea 
				ON
				( ea.employee_id = e.employee_id AND ea.employee_alert_start <= '".$day."' AND ea.employee_alert_stop >= '".$day."' )
				LEFT JOIN employee_project ep 
				ON
				( ep.employee_id = e.employee_id )
				WHERE
				ea.employee_alert_id IS NULL
				AND
				es.employee_settlement_id IS NULL
				AND
				ep.employee_project_id IS NULL
				AND  
				e.employee_activ = 0
				ORDER BY
				employee_secondname ASC,
				employee_firstname ASC		
			
			";
		//	echo$ask.'<br />';
			$dataemployeeo4 = $db->query($ask)->fetchAll();
			$this->view->employeeo4 = $dataemployeeo4;	
		}
		
		
		
		
		
				
		$this->view->day = $v['day'];	
		$this->view->o1 = $v['o1'];	
		$this->view->o2 = $v['o2'];	
		$this->view->o3 = $v['o3'];	
		$this->view->o4 = $v['o4'];	
		$this->view->op = $v['op'];	
		
		$this->view->link = '?day='.$v['day'].'&o1='.$v['o1'].'&o2='.$v['o2'].'&o3='.$v['o3'].'&o4='.$v['o4'].'&op='.$v['op'];	
	}
	
	
	public function employeeraportgenprintAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');
		
		$searchData = '';
		$searchDataAlert = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."')";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
			
			$searchDataAlert = "AND (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."')";
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
			
			
			$searchDataAlert = "AND ( (employee_alert.employee_alert_start >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop <= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."') OR (employee_alert.employee_alert_start <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' AND employee_alert.employee_alert_stop >= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'))";
		}			
	
			
			
			
			
		$order = " ORDER BY employee_secondname, employee_firstname";
			
		if( $v['team'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC,employee_secondname, employee_firstname";
		}
			
		if( $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
			
		if( $v['team'] == 1 AND $v['flat'] == 1 ){
			$order = " ORDER BY ISNULL(employeeteam_name), employeeteam_name ASC, ISNULL(employeegroup_flat), employeegroup_flat ASC, employee_secondname, employee_firstname";
		}
		
		
	
		$askFlatGroup = "
			(SELECT GROUP_CONCAT(employeegroup_name SEPARATOR ', ') FROM employeegroup eg, employee_employeegroup eeg WHERE eeg.employee_id = e.employee_id AND eg.employeegroup_id = eeg.employeegroup_id AND eg.employeegroup_type_id = 2 ORDER BY employeegroup_name) AS employeegroup_flat
		";
		
		
		if( $v['employeegroup_id'] == 'all' ){
			$ask = "
				SELECT *, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id WHERE employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}else{		
			$ask = "
				SELECT *, $askFlatGroup FROM employee_settlement, employee e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_employeegroup WHERE employee_employeegroup.employee_id = e.employee_id AND employee_employeegroup.employeegroup_id = ".$v['employeegroup_id']." AND employee_settlement.employee_id = e.employee_id $searchData GROUP BY employee_settlement.employee_id
			".$order;
		}
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTable = $data;	
	
			
		$order = "
			ORDER BY
			iA ASC,
			`employee_secondname` ASC,
			`employee_firstname`ASC";
			
		if( $v['team'] == 1 ){
			$order = "
				ORDER BY
				ISNULL(employeeteam_name), 
				employeeteam_name ASC,
				iA ASC,
				`employee_secondname` ASC,
				`employee_firstname`ASC";
		}
	
	
		if( $v['ns'] == 1 ){
		
		$askAlert = "(SELECT COUNT(*) AS iA FROM employee_alert WHERE 
			e.employee_id = employee_alert.employee_id
			$searchDataAlert
			) AS iA";
		
		
if( $v['employeegroup_id'] == 'all' ){	
		$ask = "
			SELECT 
			e.*,
			et.*,

			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			$searchData
			) AS i,
			
			$askAlert
			 
			FROM `employee` e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id
			WHERE
			`employee_activ` = 0
			AND
			employee_activ_order2 = 0
		".$order;
}else{
		$ask = "
			SELECT 
			e.*,
			et.*,

			(SELECT COUNT(*) AS i FROM employee_settlement WHERE 
			e.employee_id = employee_settlement.employee_id
			$searchData
			) AS i,
			
			$askAlert
			 
			FROM `employee` e LEFT JOIN employeeteam et ON e.employeeteam_id = et.employeeteam_id, employee_employeegroup
			WHERE
			employee_employeegroup.employee_id = e.employee_id AND employee_employeegroup.employeegroup_id = ".$v['employeegroup_id']." AND 
			`employee_activ` = 0
			AND
			employee_activ_order2 = 0
		".$order;
}	
		
		
		$data = $db->query($ask)->fetchAll();			
		$this->view->dataTableNS = $data;	
		
		}
		
		
		$this->view->employee_settlement_date_start = $v['employee_settlement_date_start'];
		$this->view->employee_settlement_date_stop = $v['employee_settlement_date_stop'];	
		$this->view->rate = $v['rate'];
		$this->view->sum = $v['sum'];
		$this->view->ns = $v['ns'];
		$this->view->team = $v['team'];
		$this->view->flat = $v['flat'];
		$this->view->residence = $v['residence'];
	}
	
	
	
	
	
	public function settlementupdateAction() {	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
	
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');		
		
		$EmployeeSettlement = new EmployeeSettlement();	
		$select = $EmployeeSettlement->select();
		$select->where('employee_settlement_id = ?', $v['id']);	
		$row = $EmployeeSettlement->fetchRow($select);	

		
		$dStart = explode(":",$row['employee_settlement_start']);		
		$dStartMin = $dStart[1] + $dStart[0]*60;
		$newTime = explode(":",$v['time']);
		$newTimeMin = $newTime[1] + $newTime[0]*60;
		
		$dStopMin = $dStartMin + $newTimeMin;
		
		if( $dStopMin > 24*60 ) $dStopMin = $dStopMin - 24*60;
		
		$dStopMin0 = $dStopMin%60;
		if( strlen($dStopMin0) == 1 ) $dStopMin0 = '0'.$dStopMin0;
		$dStopH0 = floor($dStopMin/60);
		if( strlen($dStopH0) == 1 ) $dStopH0 = '0'.$dStopH0;
		$dStop = $dStopH0.':'.$dStopMin0;
	
		$rateSum = number_format($newTime[0]*$row['employee_settlement_rate'] + $newTime[1]*$row['employee_settlement_rate']/60, 2, ',', ' ');
		
		$data = array(
			'employee_settlement_stop' => $dStop.':00',
			'employee_settlement_time' => $v['time'].':00'
		);
		$EmployeeSettlement->update($data, "employee_settlement_id = ".$v['id'] );
	
		$response['time'] = Lib_Date::convertDate($row['employee_settlement_start'],'H:i:s','H:i').' - '.$dStop;
		$response['ratesum'] = @LANG_employee_settlement_list_ratesum.' '.$rateSum.' &euro;';

		echo json_encode($response);
	}
	





















	function generateprojectraportgenpdf($save = false){	
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
		$this->_helper->viewRenderer->setNoRender();
		
		Zend_Session::namespaceUnset('massSum');
		$massSum = new Zend_Session_Namespace('massSum');	
		$massSum->sum = 0;
		$admin = new Zend_Session_Namespace('admin');
		$information = new Zend_Session_Namespace('information');		
		$db = Zend_Registry::get('db');	
		
		$config_colspan = 2;
		$config_button = 6;
		$config_note_width = 120;
		
		$Employee = new Employee();
		
		$v['project_id'] = 'all';
		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "AND employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		

		
		
		if( $v['employeegroup_id'] == 'all' ){ 
			$ask = "
				SELECT * FROM employee_settlement, employee WHERE employee_settlement.employee_id = employee.employee_id $searchData GROUP BY employee_settlement.employee_id ORDER BY employee_secondname, employee_firstname
			";
		}else{
			$ask = "
				SELECT * FROM employee_settlement, employee, employee_employeegroup WHERE employee_settlement.employee_id = employee.employee_id AND employee_employeegroup.employee_id = employee.employee_id AND employee_employeegroup.employeegroup_id = '".$v['employeegroup_id']."' $searchData GROUP BY employee_settlement.employee_id ORDER BY employee_secondname, employee_firstname
			";		
		}
		
		
		$data = $db->query($ask)->fetchAll();			
	//	$this->view->dataTable = $data;	
		
		
		$sumt = 0;
		$sumAll = 0;
		foreach( $data as $key => $val ){
		
			$select = $db->select();
			$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
			$select->where('employee_id = '.$val['employee_id'].' '.$searchData);
			$select->order(array('employee_settlement.employee_settlement_date ASC'));
			$stmt = $db->query($select);
			$dataE = $stmt->fetchAll();	
			
			$rateSum = 0;
			foreach( $dataE as $keyE => $valE ){				
				$timeVar = Lib_Date::convertDate($valE['employee_settlement_time'],'H:i:s','H:i'); 					
				$tr = explode(":",$timeVar);
				$sumt = $sumt + $tr[0]*60 + $tr[1];	
				$tV = explode(":",$timeVar);
				$rateSum = $rateSum + number_format($tV[0]*$val['employee_settlement_rate'] + $tV[1]*$val['employee_settlement_rate']/60, 2);
			}
			
			$sumAll = $sumAll + $rateSum;
		
		}
		
		
	

			
			$name = mb_strtolower (@LANG_header_title_printall, 'UTF-8');
			$nameFile = str_replace(" ","-",$name).'_'.date('d-m-Y_H-i-s');
		
			$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			
			// set document information
			$pdf->SetCreator(PDF_CREATOR);
			$pdf->SetAuthor('www.TECHNIX.pl');
			$pdf->SetTitle($nameFile);
			$pdf->SetSubject($nameFile);
			$pdf->SetKeywords($nameFile);
			$pdf->setPrintHeader(false);
			
			// set default header data
			$pdf->setFooterData(array(0,64,0), array(0,64,128));

			// set header and footer fonts
			$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

			// set default monospaced font
			$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

			// set margins
			$pdf->SetMargins(5, 5, 5);

			// set auto page breaks
			$pdf->SetAutoPageBreak(TRUE, 0);

			// set image scale factor
			$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

			// ---------------------------------------------------------

			// set default font subsetting mode
			$pdf->setFontSubsetting(true);

			// Set font
			// dejavusans is a UTF-8 Unicode font, if you only need to
			// print standard ASCII chars, you can use core fonts like
			// helvetica or times to reduce file size.
			$pdf->SetFont('dejavusans', '', 7, '', true);

			
		
		
		$i=0;
		foreach ($data as $key => $val):
		$i++;		

		
		$searchData = '';
		if( $v['employee_settlement_date_start'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
		}		
		if( $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";	
		}
		if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){
			$searchData = "employee_settlement.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'";
			$searchData = $searchData." AND employee_settlement.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'";
		}		
		
		
		$searchProject = '';
		if( $v['project_id'] != 'all' ){
			$searchProject = "employee_settlement.project_id = ".$v['project_id']."";
		}			
		
		$searchEmployee = "employee_settlement.employee_id = ".$val['employee_id']."";
	
	
		$select = $db->select();
		$select->from('employee_settlement')->join('project', 'employee_settlement.project_id = project.project_id')->join('company', 'company.company_id = project.company_id')->join('admin', 'employee_settlement.admin_id = admin.admin_id');			
		if( $searchData != '' ) $select->where($searchData);
		if( $searchProject != '' ) $select->where($searchProject);	
		$select->where($searchEmployee);				

		$select->order(array('employee_settlement.employee_settlement_date ASC'));
		$stmt = $db->query($select);
		$data1 = $stmt->fetchAll();	
		
		$select = $Employee->select();
		$select->where('employee_id = ?', $val['employee_id']);	
		$employeeData = $Employee->fetchRow($select);


if( $v['project_id'] == 'all' AND $v['project_separately'] == 1  ){

}else{

if( count($data1) > 0 ){

	$html = '<h4 style="font-size: x-large;">';
	$html = $html.$employeeData['employee_secondname'].' '.$employeeData['employee_firstname'];
	
	$dataEmployeeGroupEAll = Lib_Employee::EmployeeGroupEAll($employeeData['employee_id']);
	foreach($dataEmployeeGroupEAll as $k1 => $v1){							
		$html = $html.' <span bgcolor="#f0ad4e" color="#fff" style="font-size: large;">'.$v1['employeegroup_name'].'</span>, ';
	}
	
	$html = $html.'</h4>';
	
	
	
	
	if( $v['employee_settlement_date_start'] OR $v['employee_settlement_date_stop'] ){
	
	$html = $html.'<h5 style="font-size: large;">'.@LANG_header_title_printdate;
	
		 if( $v['employee_settlement_date_start'] AND $v['employee_settlement_date_stop'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - '. Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");
			
		 }elseif( $v['employee_settlement_date_start'] ){ 

			 $html = $html.Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","d-m-Y").' - ...';

		 }elseif( $v['employee_settlement_date_stop'] ){ 

			$html = $html.'... -  '.Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","d-m-Y");

		 } 
		 
	$html = $html.'</h5>';
	
	}

		
		
		
		
		
		$html = $html.'
<table border="1" cellpadding="5" cellspacing="0">
	<thead>
		<tr style="font-weight: bold;">
			<th width="30">'.@LANG_employee_settlement_list_lp.'</th>
			<th width="70">'.@LANG_employee_settlement_list_date.'</th>
			<th width="80">'.@LANG_employee_settlement_list_ss.'</th>
			<th width="60">'.@LANG_employee_settlement_list_time.'</th>		
			<th width="80">'.(($v['rate'])?@LANG_employee_settlement_list_rate:"").'</th>
		
		';
		
		
		$config_colspan = 1; 
		$config_button = 6; 	
	//	$config_note_width = 380;	
		
	//	if( $v['project_id'] == 'all' ){
		
		
		$html = $html.'
			<th width="260">'.@LANG_employee_settlement_list_compro.'</th>
		';
		
		
		
	//	}
		
		
		
		$html = $html.'


			<th width="'.$config_note_width.'">'.@LANG_employee_settlement_list_note.'</th>		
		</tr>
	</thead>
	<tbody>
		';	
		
		

	$i=0; 
	$sumt = 0; 
	$sumAll2 = 0;
	foreach ($data1 as $key2 => $val2){ 
		$i=$i+1;

		$timeVar = Lib_Date::convertDate($val2['employee_settlement_time'],'H:i:s','H:i'); 
		$tr = explode(":",$timeVar);
		$sumt = $sumt + $tr[0]*60 + $tr[1];
		
		$stylebg = '';
		if( $val2['employee_settlement_datecount'] > 1 ) $stylebg = ' bgcolor="#f6cece"';
		
		$tV = explode(":",$timeVar);
		$rateSum = number_format($tV[0]*$val2['employee_settlement_rate'] + $tV[1]*$val2['employee_settlement_rate']/60, 2, ',', ' ');
		
		$sumAll2 = $sumAll2 + number_format($tV[0]*$val2['employee_settlement_rate'] + $tV[1]*$val2['employee_settlement_rate']/60, 2);
		
		$html = $html.'
		<tr '.$stylebg.'>
			<td width="30">'.$i.'</td>
			<td width="70">'.Lib_Date::convertDate($val2['employee_settlement_date']).'</td>
			<td width="80">
				'.Lib_Date::convertDate($val2['employee_settlement_start'],'H:i:s','H:i').'
				-
				'.Lib_Date::convertDate($val2['employee_settlement_stop'],'H:i:s','H:i').'
			</td>
			<td width="60">'.$timeVar.'
			</td>
			<td width="80">'.(($v['rate'])?number_format($val2['employee_settlement_rate'], 2, ',', ' ').' &euro;<br />'.@LANG_employee_settlement_list_ratesum.' '.$rateSum.' &euro;':"").'
			</td>
		';
		
		
		if( $v['project_id'] == 'all' ){			
			$html = $html.'<td width="260">'.$val2['company_name'].' / '.$val2['project_name'].'</td>';
		}
		
		
		$html = $html.'
			<td width="'.$config_note_width.'">'.$val2['employee_settlement_note'].'</td>
		</tr>
		';
		
	}
	
	
	

		
		$html = $html.'	
		<tr>
			<td align="right" colspan="3" bgcolor="#cef6ce">'.@LANG_employee_settlement_sum.' / '.@LANG_employee_settlement_sumrate.'</td>
			<td>
			'.Lib_Date::convertToHoursMins($sumt).'
			</td>
			<td>
			
			<span color="#aaa">'.(($v['sum'])?number_format($sumAll2, 2, ',', ' ').' &euro;':"").'</span>
			<br />
			'.(($v['sum'])?number_format(Lib_Data::roundSpecialPrice($sumAll2), 2, ',', ' ').' &euro;':"").'
			
			</td>
			<td colspan="'.$config_colspan.'">
			</td>
		</tr>
		';		
		
		
		$html = $html.'

	</tbody>
</table>
		';
		
		
	

}else{
	$html = @LANG_employee_settlement_data0;
}

}


			
			$pdf->AddPage();			
			$pdf->writeHTML($html, true, 0, true, true);
		
		
		
		endforeach;
		
		
		
		
		
		
		
		
		
		
		if( $v['sum'] == 1 ){
			$html = '<h3>'.@LANG_header_title_sumall.' '.number_format($sumAll, 2, ',', ' ').' &euro;'.'</h3>';
			// Add a page
			// This method has several options, check the source code documentation for more information.
			$pdf->AddPage();			
			$pdf->writeHTML($html, true, 0, true, true);
		}

			
			ob_end_clean();
			if( $save == false ) $pdf->Output($nameFile.'.pdf', 'I');
			else{
				$file = $_SERVER['DOCUMENT_ROOT'].'raport/'.$nameFile.'.pdf';
				$pdf->Output($file, 'F');
				return $file;
			}
		

	}


	public function projectraportgenpdfAction() {	

		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();	
		$this->_helper->viewRenderer->setNoRender();
			
		$this->generateprojectraportgenpdf();	
		
	}
	
	
	
	
	
	
	
	public function employeecheckAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		
		$Employee = new Employee();	
		
		$data = array(
			'employee_check' => $v['employee_check']
		);
		$Employee->update( $data , 'employee_id='.$v['employee_id'] );	
	}
	
	
	
	
	
	
	
	public function employeecheckresetallAction() {
		$admin = new Zend_Session_Namespace('admin');
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$db = Zend_Registry::get('db');		
		
		$Employee = new Employee();	
		$Check = new Check();	
		$EmployeeCheck = new EmployeeCheck();	
		
		
		$year = date('Y', strtotime(date('Y-m')." -1 month"));
		$month = date('m', strtotime(date('Y-m')." -1 month"));
		
		$data = array(
			'check_year' => $year,
			'check_month' => $month,
			'check_ins' => Lib_Date::datetime(),
			'admin_id' => $admin->admin_id
		);
		$idIns = $Check->insert($data);
		
		$ask = "SELECT * FROM `employee` e WHERE employee_activ = 0";				
		$data = $db->query($ask)->fetchAll();	
		
		foreach( $data as $key => $val ){
		
			$data = array(
				'check_id' => $idIns,
				'employee_id' => $val['employee_id'],
				'employee_check_status' => $val['employee_check']
			);
			$EmployeeCheck->insert($data);
		
		}
		
		
		$data = array(
			'employee_check' => 0
		);
		$Employee->update( $data );	
		
		if( !$v['return'] ) $this->_helper->redirector('index','employee');
		
		if( $v['return'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));
		
	}
	
	
	
	
	
	
	
	public function employeeprojectdeleteAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		$db = Zend_Registry::get('db');			
		
		$EmployeeProject = new EmployeeProject();
		
		$ask = "
			SELECT * FROM employee_settlement WHERE employee_id = ".$v['id']." ORDER BY employee_settlement_date DESC LIMIT 1
		";
		$data = $db->query($ask)->fetchAll();	
	
		$where = array(
			'employee_id = ?' => $v['id']
		);
		$EmployeeProject->delete($where);	
		
		if( count($data) > 0 ){
			$dataE = array(
				'employee_id' => $v['id'],
				'project_id' => $data[0]['project_id']
			);
			$EmployeeProject->insert($dataE);	
		}
	
	
	//	$this->_helper->redirector('index','employee');
	}
	
	
	

	
	
	public function alertsAction() {	
		$admin = new Zend_Session_Namespace('admin');
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
		$vPost = $this->_request->getPost();
	
		$EmployeeAlert = new EmployeeAlert();	
		$AlertType = new AlertType();			
		
		
		if( isset($v['admin_employeealertadd']) ){		

			foreach( $v['employee_check'] as $key => $empid){
			
				$data = array(
					'employee_id' => $key,
					'employee_alert_start' => Lib_Date::convertDate($v['employee_alert_start'],"d-m-Y","Y-m-d"),
					'employee_alert_stop' => Lib_Date::convertDate($v['employee_alert_stop'],"d-m-Y","Y-m-d"),
					'alert_type_id' => $v['alert_type_id'],			
					'employee_alert_note' => isset($v['employee_alert_note'])?$v['employee_alert_note']:'',
					'admin_id' => $admin->admin_id
				);
			
				$EmployeeAlert->insert($data);	
				
			//	var_dump($data); echo'<hr />';
			}
				
				
			if( !$v['return'] ) $this->_helper->redirector('index','index');
			
			if( $v['return'] ) $this->_helper->redirector($v['return'],'employee',null,array($v['return_n'] => $v['return_id'], $v['return2_n'] => $v['return2_id']));
		}
		
		
		
		$data = $AlertType->fetchAll(null , 'alert_type_sort ASC'); 		
		$this->view->dataTableAlertType = $data;
		
		$emp = explode(',', $v['aem']);
		
		$que = '';
		$i=0;
		foreach( $emp as $k => $val ){
			if( $val ){
			if( $i == 0 ) $que = 'employee_id = '.$val;
			else $que = $que.' OR employee_id = '.$val;
			$i++;
			}
		}
		
		$ask = 'SELECT * FROM employee WHERE '.$que.' ORDER BY employee_secondname ASC, employee_firstname ASC';
		$data = $db->query($ask)->fetchAll();		
		$this->view->dataTable = $data;	
		
	}	
	
	
	

	
	
	public function raportdayAction() {	
	
	
		$admin = new Zend_Session_Namespace('admin');
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();		
	
		$ask = "SELECT project_id, company_name, project_name FROM project p, company c WHERE p.company_id = c.company_id AND c.company_status = 0 AND p.project_status = 0 AND p.project_activ_employee = 1 ORDER BY company_name, project_name";
		$data = $db->query($ask)->fetchAll();		
		$this->view->dataTable = $data;	
	
	}
	
	
	
	public function projectcheckAction() {
		$this->_helper->viewRenderer->setNoRender();
		$v = $this->_request->getParams();
		
		$Project = new Project();	
		
		$data = array(
			'project_activ_analysis' => $v['project_check']
		);
		$Project->update( $data , 'project_id='.$v['project_id'] );	
	}
	
	

	
	
	public function raportdaygenAction() {	
	
		
		$this->_helper->viewRenderer->setNoRender();
		$admin = new Zend_Session_Namespace('admin');
		$db = Zend_Registry::get('db');
		$v = $this->_request->getParams();	
	
		$ask = "
		
			SELECT 
				employee_settlement_date, 
				project_id,
				COUNT(employee_id) AS employee_count,
				SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum,
				
				(
					SELECT GROUP_CONCAT(CONCAT(employee_secondname,' ',employee_firstname) SEPARATOR '\n')
					FROM employee e, employee_settlement es2 
					WHERE 
					e.employee_id = es2.employee_id
					AND es2.project_id = ".$v['project_id']."
					AND es2.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'
					AND es2.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' 
					AND es.employee_settlement_date = es2.employee_settlement_date				
				) AS employee_list
                
				
			FROM employee_settlement es 
			WHERE 
				project_id = ".$v['project_id']."
				AND es.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'
				AND es.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'
			GROUP BY es.employee_settlement_date
			ORDER BY es.employee_settlement_date ASC
		
		";
		$data = $db->query($ask)->fetchAll();
	//	var_dump($ask);die();
	
	//  SELECT employee_settlement_date, project_id, COUNT(employee_id) AS employee_count, SEC_TO_TIME( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum, ( SELECT GROUP_CONCAT(CONCAT(employee_secondname,' ',employee_firstname) SEPARATOR ' ') FROM employee e, employee_settlement es2 WHERE e.employee_id = es2.employee_id AND es2.project_id = 604 AND es2.employee_settlement_date >= '2019-12-01' AND es2.employee_settlement_date <= '2020-05-17' AND es.employee_settlement_date = es2.employee_settlement_date ) AS employee_list FROM employee_settlement es WHERE project_id = 604 AND es.employee_settlement_date >= '2019-12-01' AND es.employee_settlement_date <= '2020-05-17' GROUP BY es.employee_settlement_date ORDER BY es.employee_settlement_date ASC
	
		//SEC_TO_TIME
		$ask = "
		
			SELECT 
				COUNT(employee_id) AS employee_count,
				( SUM( TIME_TO_SEC( `employee_settlement_time` ) ) ) AS timeSum
			FROM employee_settlement es 
			WHERE 
				project_id = ".$v['project_id']."
				AND es.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'
				AND es.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."'		
		";
		$data1 = $db->query($ask)->fetchAll();
		$data1 = $data1[0];
		
		$dataConvert = $data1['timeSum']/60;
		$data1['timeSum'] = Lib_Date::convertToHoursMins($dataConvert);
		
		
		
		$Project = new Project();
		$select = $Project->select();
		$select->where('project_id = ?', $v['project_id']);	
		$rowProject = $Project->fetchRow($select);
		
		
		
	//	echo$ask;die();
	
/*	
		header('Content-Type: text/plain');
		foreach( $data as $key => $val ){
		
			echo $val['employee_settlement_date']."\t";
			echo $val['employee_count']."\t";
			echo Lib_Date::tCon($val['timeSum'])."\t";
			echo "\n";
		
		}
		echo "\t\t";
		echo $data1['employee_count']."\t";
		echo Lib_Date::tCon($data1['timeSum']);
*/

		$nameFile = date('Y-m-d H:i:s');
		
		$colMax = "D";
		
		if( $v['employee_list'] == 1 ){
			$colMax = "F";
		}

		$objPHPExcel = new PHPExcel();
		
		$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(30); 
		
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
		$objPHPExcel->getActiveSheet()->getColumnDimension($colMax)->setWidth(20);
		
		if( $v['employee_list'] == 1 ){
			$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
			$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(50);
		}
		

		$rowid = 1;
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('A'.$rowid.':'.$colMax.$rowid.'');		
		$objPHPExcel->getActiveSheet()->getStyle("A".$rowid)->getFont()->setSize(18);
		$objPHPExcel->getActiveSheet()->getStyle('A'.$rowid)->getFont()->setBold(true);
		$objPHPExcel->setActiveSheetIndex(0)
			->setCellValue('A'.$rowid, $rowProject->project_name);	

			
		
		$rowid = $rowid + 1;
		$objPHPExcel->setActiveSheetIndex(0)
			->setCellValue('A'.$rowid, @LANG_raportdaygen_lp)	
			->setCellValue('B'.$rowid, @LANG_raportdaygen_date)		
			->setCellValue('C'.$rowid, @LANG_raportdaygen_count)
			->setCellValue($colMax.$rowid, @LANG_raportdaygen_time);
			
		if( $v['employee_list'] == 1 ){
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('D'.$rowid, @LANG_raportdaygen_employeelist);
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('E'.$rowid, @LANG_raportdaygen_employeelistgroup);
		}
			
		$objPHPExcel->getActiveSheet()->getStyle("A".$rowid.':'.$colMax.$rowid)->getFont()->setSize(14);
		$objPHPExcel->getActiveSheet()->getStyle('A'.$rowid.':'.$colMax.$rowid)->getFont()->setBold(true);
	
		$j = 0;
		foreach($data as $key => $val){
			$j++;
			$rowid = $rowid + 1;
			
			$objPHPExcel->setActiveSheetIndex(0)
				->setCellValue('A'.$rowid, $j)
				->setCellValue('B'.$rowid, $val['employee_settlement_date'])		
				->setCellValue('C'.$rowid, $val['employee_count'])
				->setCellValue($colMax.$rowid, Lib_Date::tCon($val['timeSum']));
			//	->setCellValue('AR'.$rowid, $val['employee_list']);
			
			if( $v['employee_list'] == 1 ){
			
				$askEmployee = "				
					SELECT * FROM employee e, employee_settlement es2, employeeteam et 
					WHERE 
					e.employee_id = es2.employee_id
					AND es2.project_id = ".$v['project_id']."
					AND es2.employee_settlement_date >= '".Lib_Date::convertDate($v['employee_settlement_date_start'],"d-m-Y","Y-m-d")."'
					AND es2.employee_settlement_date <= '".Lib_Date::convertDate($v['employee_settlement_date_stop'],"d-m-Y","Y-m-d")."' 
					AND es2.employee_settlement_date = '".$val['employee_settlement_date']."'
					AND et.employeeteam_id = e.employeeteam_id
					ORDER BY employeeteam_name, employee_secondname, employee_firstname
				";		
				//echo$askEmployee;die();				
				$dataEmployee = $db->query($askEmployee)->fetchAll();
				
				$employeeList = '';
				$employeeListGroup = '';
				$team = '';
				$dataEmployee1 = $dataEmployee;
				foreach( $dataEmployee1 as $keyEmployee => $valEmployee ){
				
					if( $team != $valEmployee['employeeteam_name'] ){
						$team = $valEmployee['employeeteam_name'];
						$group = $team;
						$groupTimeSum = 0;
					}
				
					if( $employeeList != '' ) $employeeList = $employeeList."\n";
					
					$employeeList = $employeeList.$valEmployee['employee_secondname'].' '.$valEmployee['employee_firstname'].': '.Lib_Date::convertDate($valEmployee['employee_settlement_time'],"H:i:s","H:i");
					
					$empTime = explode(":",$valEmployee['employee_settlement_time']);
					$groupTimeSum = $groupTimeSum + $empTime[0]*3600 + $empTime[1]*60;
					
					$nextval = next($dataEmployee1);
					if( $team != $nextval['employeeteam_name'] ){
					
						$groupTimeSumFormatH  = floor($groupTimeSum/3600);
						$groupTimeSumFormatM  = floor(($groupTimeSum-$groupTimeSumFormatH*3600)/60);
						if( strlen($groupTimeSumFormatM) == 1 ) $groupTimeSumFormatM = "0".$groupTimeSumFormatM;
						
						$groupTimeSumFormat = $groupTimeSumFormatH.":".$groupTimeSumFormatM;
						
						$employeeListGroup = $employeeListGroup."\n".@LANG_raportdaygen_team." \"".$team."\": ".$groupTimeSumFormat;
					}
				}
			//	$employeeList = preg_replace("/[\r\n]+/", PHP_EOL, $employeeList);

				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('D'.$rowid, trim($employeeList));
				$objPHPExcel->setActiveSheetIndex(0)
					->setCellValue('E'.$rowid, trim($employeeListGroup));
					/*$val['employee_list']."\n\n".*/
			}
		}
		
		
		$rowid = $rowid + 1;
			
		$objPHPExcel->setActiveSheetIndex(0)	
			->setCellValue('C'.$rowid, $data1['employee_count'])
			->setCellValue($colMax.$rowid, Lib_Date::tCon($data1['timeSum']));		
		
		$objPHPExcel->getActiveSheet()->getStyle("A".$rowid.":".$colMax.$rowid)->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				'rgb' => 'f6cece'
			)
		));
		
		$objPHPExcel->getActiveSheet()->getStyle("A1:".$colMax."2")->getFill()->applyFromArray(array(
			'type' => PHPExcel_Style_Fill::FILL_SOLID,
			'startcolor' => array(
				'rgb' => 'cef6ce'
			)
		));
		
		$objPHPExcel->getActiveSheet()
			->getStyle('A1'.':'.$colMax.$rowid)
			->getBorders()
			->getAllBorders()
			->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN)
			->getColor()
			->setRGB('888');
		
		
		$objPHPExcel->getActiveSheet()
			->getStyle($colMax.'2'.':'.$colMax.$rowid)
			->getAlignment()
			->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
		$objPHPExcel->getActiveSheet()->getStyle('A1'.':'.$colMax.$rowid)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
		
		$objPHPExcel->getActiveSheet()->getStyle('A1'.':'.$colMax.$rowid)->getAlignment()->setWrapText(true);

		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);

		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.$nameFile.'.xls"');
		header('Cache-Control: max-age=0');
		// If you're serving to IE 9, then the following may be needed
		header('Cache-Control: max-age=1');

		// If you're serving to IE over SSL, then the following may be needed
		header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
		header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
		header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
		header ('Pragma: public'); // HTTP/1.0
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		
	}	
	
	
	
	

}
