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

$getdata = $db->get_row ( "salaryslipdata", array ("emp_id" => $getid [1] ) );
$companydata = $db->get_row ( "setting", array ("id" => 1 ) );
// get the data of particular employee
$query = $db->get_row ( "payslip", array ("empname" => $getid [1] ) );
// geth the name of particular employee
$empname = $db->get_col ( "employees", array ("e_id" => $getid [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 .= '	</b>
		</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 .= '</b>
					</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 .= '</b>
					</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 .= '</b>
			</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>
<style>
@media print {
	tr.vendorListHeading {
		background-color: darkseagreen !important;
		-webkit-print-color-adjust: exact;
	}
}
</style>
</head>
<body>
	<div style="margin-left: 10%; width: 80%;">
		<table style="float:left;width: 40%;">
			<tr>
				<td rowspan="6" style="width: 100px;"><img
					src="<?php echo SITE_URL.'/uploads/image/'.$companydata['c_logo'];?>"
					style="width: 93px; height: 93px"></td>
			</tr>
			<tr>
				<td><p><?php echo $companydata['c_name'];?></b></td>
			</tr>
			<tr>
				<td><p><?php echo $companydata['address'];?></b></td>
			</tr>
			<tr>
				<td><p>
						<span><?php
						
if ($companydata ['telephone'] != '') {
							echo $companydata ['telephone'];
						}
						if ($companydata ['telephone'] != '' && $companydata ['telephone2'] != '') {
							echo $companydata ['telephone'] . '&nbsp;' . ',' . $companydata ['telephone2'] . '&nbsp;';
						}
						if ($companydata ['telephone2'] != '') {
							echo $companydata ['telephone2'];
						}
						?></span><!-- , <span> <?php //echo $companydata['fax'];?></span> -->
					</b></td>
			</tr>
			<tr>
				<td><p><?php echo $companydata['c_email'];?></b></td>
			</tr>
			<tr>
				<td><p><?php echo $companydata['website'];?></b></td>
			</tr>
		</table>
		<table style="width: 40%; height: 18%; float: right;">
			<tr>
				<td><p><span>Salary Slip For The Month Of:</span><span><?php 
				$current_month = date ( "F", strtotime ( "-1 Months" ) );
				echo substr ( $current_month, 0, 3 );
				echo "&nbsp;-" . date ( Y );
				?></span></b></td>
			</tr>
		</table>
	</div>




	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td colspan="6"><hr></td>
		</tr>
	</table>
	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td style="width:25%;"><b>&nbsp;Name Of Employer</b></td>
			<td style="width:25%;"><p><?php echo $companydata['c_name'];?></p></td>
			<td style="width:40%;"><b>&nbsp;Name Of Employee</b></td>
			<td style="width:10%;"><p><?php echo $empname[0];?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Department</b></td>
			<td style="width:25%;"><p><?php echo $query['department'];?></p></td>
			<td style="width:40%;"><b>&nbsp;Emp Code</b></td>
			<td style="width:10%;"><p><?php echo $query['empcode'];?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Employee Income</b></td>
			<td style="width:25%;"><p><?php echo $query['employment_income'];?></p></td>
			<td style="width:40%;"><b>&nbsp;Employee Expenses</b></td>
			<td style="width:10%;"><p><?php echo $query['employment_expences'];?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Net Employment Income</b></td>
			<td style="width:25%;"><p><?php echo $companydata['currency'].'&nbsp;'.$query['net_employment_income'];?></p></td>
			<td style="width:40%;"><b>&nbsp;Trade, Business, Profession Or Vacation</b></td>
			<td style="width:10%;"><p><?php echo $companydata['currency'].'&nbsp;'.$query['trade_income'];?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Num Of Days(<?php echo substr ( $current_month, 0, 3 );?>)</b></td>
			<td style="width:25%;"><p><?php echo $query['paidday'].'&nbsp;days';?></p></td>
			<td style="width:40%;"><b>&nbsp;Num Of Days(Present)</b></td>
			<td style="width:10%;"><p><?php echo $query['presentday'].'&nbsp;days';?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Total Leaves</b></td>
			<td style="width:25%;"><p><?php echo $query['total_leaves'].'&nbsp;days';?></p></td>
			<td style="width:40%;"><b>&nbsp;Num Of Weekend Presents</b></td>
			<td style="width:10%;"><p><?php echo $query['extrawork'].'&nbsp;days';?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		<tr>
			<td style="width:25%;"><b>&nbsp;Weeks Off</b></td>
			<td style="width:25%;"><p><?php echo $query['weekoff'].'&nbsp;days';?></p></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
	</table>
	<br>
	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td></td>
		</tr>
		<tr>
			<td><b style="color:red;">&nbsp;INCOME</b></td>
		</tr>
		<tr>
			<td>
				<hr>
			</td>
		</tr>
	</table>
	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td style="width:25%;"><b>&nbsp;Dividends</b></td>
			<td style="width:25%;"><p><?php echo $companydata['currency'].'&nbsp;'.$query['dividends'];?></p></td>
			<td style="width:40%;"><b>&nbsp;Interest</b></td>
			<td style="width:10%;"><p><?php echo $companydata['currency'].'&nbsp;'.$query['interest'];?></p></td>
		</tr>
		<tr>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
			<td style="width:25%;"></td>
		</tr>
		
	</table>	
	<table style="margin-left: 10%; width: 80%;">
		<tr>
			<td style="width: 40%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900; color: aqua;">
					</b>
			</td>
			<td style="width: 10%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900;">
					
				</b>
			</td>
			<td style="width: 40%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900; color: aqua;">
					</b>
			</td>
			<td style="width: 10%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900;">
					
				</b>
			</td>
		</tr>
		<tr>
			<td colspan="4"></td>
		</tr>
		<tr>
			<td style="width: 40%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900; color: aqua;">
					</b>
			</td>
			<td style="width: 10%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900;">
					
				</b>
			</td>
			<td style="width: 40%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900; color: aqua;">
					Handicapped brother/sister relief</b>
			</td>
			<td style="width: 10%;">
				<p
					style="font-family: cursive; font-style: oblique; font-weight: 900;">
					<?php echo $companydata['currency'].'&nbsp;'.$query['brosis_relief'];?>
				</b>
			</td>
		</tr>
	</table>
</body>
</html>
