<?php
$getid = $link->hrefquery ();

$getdata = $db->get_row ( "salaryslipdata", array ("emp_id" => $getid [1] ) );
$companydata = $db->get_row ( "setting", array ("id" => 1 ) );

$unserialize_arr = unserialize ( $getdata ['metavalue'] );
$upper_part = $unserialize_arr [0] [0];
$earning_part = $unserialize_arr [0] [1];
$deduction_part = $unserialize_arr [0] [2];
$footer_part = $unserialize_arr [0] [3];

// echo '<pre>'; print_r ( $footer_part ); echo '</pre>';

// $array_count_upper= array_co
//
$total_firstkey = count ( $upper_part );
$total_secondkey = count ( $earning_part );
$total_fourthkey = count ( $footer_part );
$html = '<html>
<title>' . $companydata ['c_name'] . '</title>
<head></head>
<body>
<table style="margin-left: 10%; width: 80%;">
<tr>
<td style="width: 30%;">
<h1 style="font-size: 24px; font-weight: lighter; color: #2679B5;">
Salary Slip</h1>
</td>

<td colspan="4"><img
src="' . SITE_URL . '/uploads/image/' . $companydata ['c_logo'] . '"
style="width: 100px; height: 100px; margin-left: 15%;"></td>
</tr>
<tr>
<td colspan="6"><hr></td>
</tr>
<tr>
<td colspan="6" style="text-align: center;">';
?>
			
				<?php
				
				if ($companydata ['c_name'] != '') {
					$html .= '<h1 style="color: #C09853; font-size: 33px; font-weight: lighter; font-family: MS Reference Sans Serif;">' . $companydata ["c_name"] . '</h1>';
				}
				?>
			<?php
			
			$html .= '</td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">
				<h5 style="color: #999; font-size: 16px;">' . $companydata ['address'] . '</h5>
			</td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">
				<h5>
					<span style="color: #3A87AD; font-size: 16px;">Ph:</span> <span
						style="color: #999; font-size: 16px;">';
			?>
				 <?php
					if ($companydata ['telephone'] != '') {
						$html .= $companydata ['telephone'];
					}
					if ($companydata ['telephone'] != '' && $companydata ['telephone2'] != '') {
						$html .= '&nbsp;' . $companydata ['telephone'] . ',' . $companydata ['telephone2'] . '&nbsp;';
					}
					if ($companydata ['telephone2'] != '') {
						$html .= $companydata ['telephone2'];
					}
					
					$html .= '</span>';
					
					if ($companydata ['fax'] != '') {
						$html .= ', <span style="color: #3A87AD; font-size: 16px;">Fax:</span> <span
						style="color: #999; font-size: 16px;">' . $companydata ["fax"] . '</span>';
					}
					if ($companydata ['c_email'] != '') {
						$html .= ', <span style="color: #3A87AD; font-size: 16px;">Email:</span> <span
						style="color: #999; font-size: 16px;">' . $companydata ["c_email"] . '</span>';
					}
					if ($companydata ['website'] != '') {
						$html .= ', <span style="color: #3A87AD; font-size: 16px;">Website:</span> <span
						style="color: #999; font-size: 16px;">' . $companydata ["website"] . '</span>';
					}
					$html .= ', <span style="color: #3A87AD; font-size: 16px;">Salary Slip For
						The Month Of:</span> <span style="color: #999; font-size: 16px;">';
					?><?php

					$current_month = date ( "F", strtotime ( "-1 Months" ) );
					$month = substr ( $current_month, 0, 3 );
					$date = "&nbsp;-" . date ( Y );
					$html .= $month . $date . '
						</span>
				</h5>
			</td>
		</tr>
		<tr>
			<td colspan="6">
				<h3 style="color: #999; font-size: 18px;">Employee Salary Slip</h3>
			</td>		
		</tr>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
		<tr>
			<td colspan="6">
				<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">Employees
					Details</h3>
			</td>
		</tr>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
	</table>
	<table style="margin-left: 10%; width: 80%;">';
					?>	
		<?php
		$firstvar = 1;
		foreach ( $upper_part as $key => $row ) {
			if ($firstvar == 1 || $firstvar % 2 == 1) {
				$html .= '<tr>';
				$html .= '<td></td>';
			}
			
			$html .= '<td ';
			?><?php

			if ($firstvar == 1 || $firstvar % 2 == 1) {
				$html .= 'style="width: 36%;"';
			} else {
				$html .= 'style="margin-left:20%;"';
			}
			$html .= '>'?>
		<?php
			
			$html .= '
			<b style="color: #B94A48;">' . $feature->textstyler ( $key, 1 ) . '</b>
		</td>';
			?><?php

			$html .= '<td';
			if ($firstvar == 1 || $firstvar % 2 == 1) {
				'style="width: 21%;"';
			}
			?>
		<?php
			
			$html .= '>';
			$html .= '<p style="color: #999;">';
			?>
			<?php
			if ($firstvar == 1) {
				$empname = $db->get_col ( "employees", array ("e_id" => $row ), "e_name" );
				$html .= $feature->textstyler ( $empname [0], 1 );
			} else {
				if ($key == 'basic_salary') {
					$html .= "Rs " . $feature->textstyler ( $row, 1 );
				} else {
					$html .= $feature->textstyler ( $row, 1 );
				}
			}
			$html .= '	</p>
		</td>';
			?>
					
					
					<?php
			if ($firstvar % 2 == 0 || $firstvar == $total_firstkey) {
				$html .= '<td></td>';
				$html .= '</tr>';
			}
			?>
							
		<?php
			
			$firstvar ++;
		}
		$html .= '
	<tr>
			<td colspan="6"><hr></td>
		</tr>
		<tr>
			<td colspan="6">
				<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">
					Earning And Deduction Details</h3>
			</td>
		</tr>
		<tr>
			<td colspan="6">
				<hr>
			</td>
		</tr>
	</table>
	<div class="earning" style="float: left; margin-left: 10%; width: 80%;">
		<div class="earningtable"
			style="float: left; margin: 0px; padding: 0px; width: 50%;">
			<table style="margin-left: 0px; width: 100%;">';
		?>
			<?php
			
			foreach ( $earning_part as $key => $row ) {
				$html .= '<tr>
					<td style="width: 74%;"><b style="color: #B94A48;">' . $feature->textstyler ( $key, 1 ) . '</b>
					</td>
					<td style="width: 26%;">
						<p style="color: #999;">';
				?>
							<?php
				if (strpos ( $row, '%' ) !== false) {
					// PERCENT SIGN FOUND
					$html .= $row;
				} else {
					$html .= "Rs " . $row;
				}
				$html .= '</p>
					</td>
				</tr>';
				?>
			
							
		<?php
			
			}
			$html .= '</table>
		</div>
		<div class="deductiontable"
			style="float: left; margin: 0px; padding: 0px; width: 50%;">
			<table style="margin-left: 80px; width: 85%;">';
			?>
		<?php
		
		foreach ( $deduction_part as $key => $row ) {
			$html .= '<tr>
					<td style="width: 53%;"><b style="color: #B94A48;">
						' . $feature->textstyler ( $key, 1 ) . '</b>
					</td>
					<td style="width: 47%;">
						<p style="color: #999;">';
			?>
							<?php
			if (strpos ( $row, '%' ) !== false) {
				// PERCENT SIGN FOUND
				$html .= $row;
			} else {
				$html .= "Rs " . $row;
			}
			$html .= '</p>
					</td>
				</tr>';
			?>
			
							
		<?php
		
		}
		$html .= '
			</table>
		</div>
	</div>
	<div class="earning" style="float: left; margin-left: 10%; width: 80%;">
		<table style="width: 100%;">
			<tr>
				<td colspan="6">
					<hr>
				</td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6">
					<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">
						Salary Details</h3>
				</td>
			</tr>
			<tr>
				<td colspan="6">
					<hr>
				</td>
			</tr>';
		?>
			<?php
			$lastvar = 1;
			foreach ( $footer_part as $key => $row3 ) {
				if ($lastvar == 1 || $lastvar % 2 == 1) {
					$html .= '<tr>';
				}
				
				$html .= '<td>';
				
				$getkey = explode ( "a_", $key );
				$html .= '<b style="color: #B94A48;">';
				$html .= $feature->textstyler ( $getkey [1], 1 );
				$html .= '</b>
			</td>
			<td>
				<p style="color: #999;">';
				?>
				<?php if(is_numeric($row3)){?><?php $html .= "Rs ";} $html .= $feature->textstyler($row3,1);?>
				<?php
				
				$html .= '</p>
			</td>';
				?>
				<?php
				
				if ($lastvar % 2 == 0 || $lastvar == $total_fourthkey) {
					$html .= '<td></td>';
					$html .= '<td></td>';
					$html .= '</tr>';
				}
				$lastvar ++;
			}
			$html .= '
		</table>
	</div>		
</body> 
</html>';
			?>

<?php
$filename = SERVER_ROOT . '/uploads/pdf/' . $getid [1] . "invoice.html";
file_put_contents ( $filename, $html );
?>

<html>
<title><?php echo $companydata['c_name'];?></title>
<head></head>
<body>
	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td style="width: 20%;">
				<h1 style="font-size: 24px; font-weight: lighter; color: #2679B5;">
					Salary Slip</h1>
			</td>

			<td colspan="4"><img
				src="<?php echo SITE_URL.'/uploads/image/'.$companydata['c_logo'];?>"
				style="width: 100px; height: 100px; margin-left: 35%;"></td>
		</tr>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">
				<?php if($companydata['c_name'] !=''){?>
						<h1
					style="color: #C09853; font-size: 33px; font-weight: lighter; font-family: MS Reference Sans Serif;"><?php echo $companydata['c_name'];?></h1><?php }?>
			</td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">
				<h5 style="color: #999; font-size: 16px;"><?php echo $companydata['address'];?></h5>
			</td>
		</tr>
		<tr>
			<td colspan="6" style="text-align: center;">
				<h5>
					<span style="color: #3A87AD; font-size: 16px;">Ph:</span> <span
						style="color: #999; font-size: 16px;"><?php
						if ($companydata ['telephone'] != '') {
							echo $companydata ['telephone'];
						}
						if ($companydata ['telephone'] != '' && $companydata ['telephone2'] != '') {
							echo '&nbsp;' . ',' . '&nbsp;';
						}
						if ($companydata ['telephone2'] != '') {
							echo $companydata ['telephone2'];
						}
						?></span>
						
					<?php if($companydata['fax'] !=''){?>
						, <span style="color: #3A87AD; font-size: 16px;">Fax:</span> <span
						style="color: #999; font-size: 16px;"><?php echo $companydata['fax'];?></span>
					<?php }if($companydata['c_email'] !=''){?>
						, <span style="color: #3A87AD; font-size: 16px;">Email:</span> <span
						style="color: #999; font-size: 16px;"><?php echo $companydata['c_email'];?></span>
					<?php }if($companydata['website'] !=''){?>
						, <span style="color: #3A87AD; font-size: 16px;">Website:</span> <span
						style="color: #999; font-size: 16px;"><?php echo $companydata['website'];?></span>
					<?php }?>				
						, <span style="color: #3A87AD; font-size: 16px;">Salary Slip For
						The Month Of:</span> <span style="color: #999; font-size: 16px;"><?php
						$current_month = date ( "F", strtotime ( "-1 Months" ) );
						echo substr ( $current_month, 0, 3 );
						echo "&nbsp;-" . date ( Y );
						?></span>
				</h5>
			</td>
		</tr>
		<tr>
			<td colspan="4">
				<h3 style="color: #999; font-size: 18px;">Employee Salary Slip</h3>
			</td>
			<td style="text-align: right;"><p
					style="color: #82AF6F; cursor: pointer;" onclick="window.print();">Print,
				</p></td>
			<td style="text-align: left;"><p style="color: #B94A48;">
					<a
						href="<?php echo $link->link("pdfgenerate",Admin,"?id=".$getid[1]);?>"
						id="pdf" style="text-decoration: none; color: #82AF6F;">PDF
						Generate</a>
				</p></td>
		</tr>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
		<tr>
			<td colspan="6">
				<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">Employees
					Details</h3>
			</td>
		</tr>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
	</table>
	<table style="margin-left: 10%; width: 80%;">	
		<?php
		$firstvar = 1;
		foreach ( $upper_part as $key => $row ) {
			if ($firstvar == 1 || $firstvar % 2 == 1) {
				echo '<tr>';
				echo '<td></td>';
			}
			?>
					
		<td <?php if ($firstvar == 1 || $firstvar % 2 == 1) {?>
			style="width: 36%;" <?php }else{?> style="margin-left:20%;" <?php }?>>
			<b style="color: #B94A48;"><?php  echo $feature->textstyler($key,1);?></b>
		</td>
		<td <?php if ($firstvar == 1 || $firstvar % 2 == 1) {?>
			style="width: 21%;" <?php } ?>>
			<p style="color: #999;"><?php
			if ($firstvar == 1) {
				$empname = $db->get_col ( "employees", array ("e_id" => $row ), "e_name" );
				echo $feature->textstyler ( $empname [0], 1 );
			} else {
				if ($key == 'basic_salary') {
					echo "Rs " . $feature->textstyler ( $row, 1 );
				} else {
					echo $feature->textstyler ( $row, 1 );
				}
			}
			?>
						</p>
		</td>
					
					<?php
			if ($firstvar % 2 == 0 || $firstvar == $total_firstkey) {
				echo '<td></td>';
				echo '</tr>';
			}
			?>
							
		<?php $firstvar++;}?>
		<tr>
			<td colspan="6"><hr></td>
		</tr>
		<tr>
			<td colspan="6">
				<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">
					Earning And Deduction Details</h3>
			</td>
		</tr>
		<tr>
			<td colspan="6">
				<hr>
			</td>
		</tr>
	</table>
	<div class="earning" style="float: left; margin-left: 10%; width: 80%;">
		<div class="earningtable"
			style="float: left; margin: 0px; padding: 0px; width: 50%;">
			<table style="margin-left: 0px; width: 100%;">

				
		<?php
		foreach ( $earning_part as $key => $row ) {
			/*
			 * if ($secondvar == 1 || $secondvar % 2 == 1) { echo '<tr>'; echo
			 * '<td></td>'; }
			 */
			?>
				<tr>
					<td style="width: 74%;"><b style="color: #B94A48;"><?php  echo $feature->textstyler($key,1);?></b>
					</td>
					<td style="width: 26%;">
						<p style="color: #999;">
							<?php
			if (strpos ( $row, '%' ) !== false) {
				// PERCENT SIGN FOUND
				echo $row;
			} else {
				echo "Rs " . $row;
			}
			?>
						</p>
					</td>
				</tr>
			
							
		<?php }?>
			</table>
		</div>
		<div class="deductiontable"
			style="float: left; margin: 0px; padding: 0px; width: 50%;">
			<table style="margin-left: 80px; width: 85%;">

				
		<?php
		
		foreach ( $deduction_part as $key => $row ) {
			/*
			 * if ($secondvar == 1 || $secondvar % 2 == 1) { echo '<tr>'; echo
			 * '<td></td>'; }
			 */
			?>
					<tr>
					<td style="width: 53%;"><b style="color: #B94A48;"><?php  echo $feature->textstyler($key,1);?></b>
					</td>
					<td style="width: 47%;">
						<p style="color: #999;">
							<?php
			if (strpos ( $row, '%' ) !== false) {
				// PERCENT SIGN FOUND
				echo $row;
			} else {
				echo "Rs " . $row;
			}
			?>
						</p>
					</td>
				</tr>
			
							
		<?php }?>
			</table>
		</div>
	</div>

	<div class="earning" style="float: left; margin-left: 10%; width: 80%;">
		<table style="width: 100%;">
			<tr>
				<td colspan="6">
					<hr>
				</td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6"></td>
			</tr>
			<tr>
				<td colspan="6">
					<h3 style="color: #3A87AD; font-family: MS Reference Sans Serif;">
						Salary Details</h3>
				</td>
			</tr>
			<tr>
				<td colspan="6">
					<hr>
				</td>
			</tr>
			<?php
			$lastvar = 1;
			foreach ( $footer_part as $key => $row3 ) {
				if ($lastvar == 1 || $lastvar % 2 == 1) {
					echo '<tr>';
				}
				?>
			<td>
				<?php
				$getkey = explode ( "a_", $key );
				?>
				<b style="color: #B94A48;"><?php  echo $feature->textstyler($getkey[1],1);?></b>
			</td>
			<td>
				<p style="color: #999;"><?php if(is_numeric($row3)){echo "Rs ";} echo $feature->textstyler($row3,1);?></p>
			</td>
										<?php
				
				if ($lastvar % 2 == 0 || $lastvar == $total_fourthkey) {
					echo '<td></td>';
					echo '<td></td>';
					echo '</tr>';
				}
				$lastvar ++;
			}
			?>
		</table>
	</div>

</body>
</html>