  
<?php

  include 'DBConnection.php';



    $sql       = 'select * from records where emp_id =19702';

    $results   = mysqli_query($connection, $sql);

    while ($row = mysqli_fetch_array($results)) {
    
    $name =$row['lname'].", ".$row['fname'];
    $emp_id =$row['emp_id'];
    $bu = $row['bu'];
    $jdate = $row['jdate'];
    $position = $row['position'];
    $division = $row['division'];
    $rank = $row['ee_level'];
    $salary1 = $row['basic_pay'];
    $jdate = $row['jdate'];


    }

$conn = @mysqli_connect('localhost', 'root', '');
  if (!$conn)
  {
    die("Database Connection Failed" . mysql_error());
  }

  $select_db = mysqli_select_db($conn,'p2');
  if (!$select_db)
  {
    die("Database Selection Failed" . mysql_error());
  }


  
  $query1  = mysqli_query($conn,"SELECT * from records");
  

  
    while($row1=mysqli_fetch_array($query1))
  {

    $jdate1 = date('Y',strtotime($jdate));
    $nextyear = $jdate1 + 1;
    $j1 = "01-01";
    $newdate = $j1."-".$nextyear;


    $int =date('m',strtotime($jdate1) - strtotime($newdate));


    $s1 = ($salary1 * $int) / 12;

    $gross_income = $salary1 * 12;

 
    



    $sql = "SELECT * FROM ot WHERE userid =11002";
    $query  = mysqli_query($conn,$sql);


    $salary  = $row1['basic_pay'];
    $emp_lastname = $row1['lname'];
    $fname = $row1['fname'];
    
  if(($salary1 >=1000) && ($salary1 <=1249.99)) {
 //pagibig, philhealth, sss
     $totaldeductions = (100 + 137.50 + 36.30);
      $sss = 36.30;
  $pagibig = 100;
  $ph = 137.50;

  } else if (($salary1 >=1250) && ($salary1 <=1749.99)) {
  $totaldeductions = (100 + 137.50 + 54.50);
  $sss = 54.50;
  $pagibig = 100;
  $ph = 137.50;
  } else if (($salary1 >=1750) && ($salary1 <=2249.99)) {
   $totaldeductions = (100 + 137.50 + 72.70);
   $sss = 72.70;
  $pagibig = 100;
  $ph = 137.50;
  }else if (($salary1 >=2250) && ($salary1 <=2749.99)) {
    $totaldeductions = (100 + 137.50 + 90.80);
      $sss = 90.80;
  $pagibig = 100;
  $ph = 137.50;
  }else if (($salary1 >=2750) && ($salary1 <=3249.99)) {
    $totaldeductions = (100 + 137.50 + 109.00);
      $sss = 109.00;
  $pagibig = 100;
  $ph = 137.50;
  } else if (($salary1 >=3250) && ($salary1 <=3749.99)) {
    $totaldeductions = (100 + 137.50 + 127.20);
      $sss = 127.20;
  $pagibig = 100;
  $ph = 137.50;
  } else if (($salary1 >=3750) && ($salary1 <=4249.99)) {
    $totaldeductions = (100 + 137.50 + 145.30);
      $sss = 145.30;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=4250) && ($salary1 <=4749.99)) {
    $totaldeductions = (100 + 137.50 + 163.50);
      $sss = 163.50;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=4750) && ($salary1 <=5249.99)) {
    $totaldeductions = (100 + 137.50 + 181.70);
      $sss = 181.70;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=5250) && ($salary1 <=5749.99)) {
    $totaldeductions = (100 + 137.50 + 199.80);
      $sss = 199.80;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=5750) && ($salary1 <=6249.99)) {
    $totaldeductions = (100 + 137.50 + 218.00);
      $sss = 218.00;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=6250) && ($salary1 <=6749.99)) {
    $totaldeductions = (100 + 137.50 + 236.20);
      $sss = 236.20;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=6750) && ($salary1 <=7249.99)) {
    $totaldeductions = (100 + 137.50 + 254.30);
      $sss = 254.30;
  $pagibig = 100;
  $ph = 137.50;
  } else if (($salary1 >=7250) && ($salary1 <=7749.99)) {
    $totaldeductions = (100 + 137.50 + 272.50);
      $sss = 272.50;
  $pagibig = 100;
  $ph = 137.50;
  }   else if (($salary1 >=7750) && ($salary1 <=8249.99)) {
    $totaldeductions = (100 + 137.50 + 290.70);
      $sss = 290.70;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=8250) && ($salary1 <=8749.99)) {
    $totaldeductions = (100 + 137.50 + 308.08);
      $sss = 308.08;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=8750) && ($salary1 <=9249.99)) {
    $totaldeductions = (100 + 137.50 + 327.00);
      $sss = 327.00;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=9250) && ($salary1 <=9749.99)) {
    $totaldeductions = (100 + 137.50 + 345.20);
      $sss = 345.20;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=9750) && ($salary1 <=10249.99)) {
    $totaldeductions = (100 + 137.50 + 363.30);
     $sss = 363.30;
  $pagibig = 100;
  $ph = 137.50;
  }  else if (($salary1 >=10250) && ($salary1 <=10749.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 381.50);
       $sss = 381.50;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=10750) && ($salary1 <=11249.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 399.70);
     $sss = 399.70;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  }  else if (($salary1 >=11250) && ($salary1 <=11749.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 417.80);
        $sss = 417.80;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=11750) && ($salary1 <=12249.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) +  436.00);
        $sss = 436.00;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=12450) && ($salary1 <=12949.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 454.20);
        $sss = 454.20;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=12950) && ($salary1 <=13449.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 472.30);
        $sss = 472.30;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=13450) && ($salary1 <=13949.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 490.50);
        $sss = 490.50;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=13950) && ($salary1 <=14449.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 508.70);
        $sss = 508.70;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  }  else if (($salary1 >=14450) && ($salary1 <=14949.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 526.80);
        $sss = 526.80;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=14950) && ($salary1 <=15249.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 545.00);
        $sss = 545.00;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if (($salary1 >=15250) && ($salary1 <=15749.99)) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 563.20);
        $sss = 563.20;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } else if ($salary1 >= 15750) {
    $totaldeductions = (100 + (($salary1*0.0275)/2) + 581.30);
        $sss = 581.30;
  $pagibig = 100;
  $ph = ($salary1*0.0275)/2;
  } 
 else {
    $totaldeductions = 0;
        $sss = 0;
  $pagibig = 0;
  $ph = 0;
  }

    $dailyrate = $salary1/26.16;
      $hour_rate = $dailyrate / 8;
      $temp = $hour_rate  * 0.25;
      $temp1 = $temp + $hour_rate;
      $ot = $temp1 ; 



      $hrate = number_format($hour_rate,2);

      $div_sal = $salary1  /2;
      $div_totald = $totaldeductions /2;

  $netpay = $div_sal - $div_totald;
  $fnetpay = number_format($netpay,2);
  $fsalary = number_format($salary1,2);

    $netpay_year = $netpay *12;
    $year_deduction = $totaldeductions * 12;

    if($netpay <= 10417){
    	$tax = 0;
    } else if (($netpay >= 10417) || ($netpay <=16666)){
        $tax = (($netpay-10417) * 0.20);
    } else if (($netpay >= 16667) || ($netpay <=33332)){
        $tax = ((($netpay-16667) * 0.20) + 1250);
    } else if (($netpay >= 33333) || ($netpay <=83332)){
        $tax = ((($netpay-33333) * 0.30) + 5416.67);
    } else if (($netpay >= 383333) || ($netpay <=333332)){
        $tax = ((($netpay-83333) * 0.32) + 20416.67);
    } else if ($netpay >= 333333){
        $tax = ((($netpay-333333) * 0.35) + 0.35);
    } else {
    	$tax = 0;
    } 

}
?>
		
<head>
  <link rel="stylesheet" type="text/css" href="payslip.css">
 </head>

 <body>
 	
		<div id="payslip">
	<center> <div id="title">ALC HOLDINGS INC. PAYSLIP</div> </center>
	<div id="scope">
		<div class="scope-entry">
			<div class="title">PAY RUN</div>
			<div class="value">Mar 15, 2015</div>
		</div>
		<div class="scope-entry">
			<div class="title">PAY PERIOD</div>
			<div class="value">Mar 1 - Mar 15, 2015</div>
		</div>
	</div>
	<div class="content">
		<div class="left-panel">
			<div id="employee">
				<div id="name">
					<?php echo $name; ?>
				</div>
				
			</div>
			<div class="details">
				<div class="entry">
					<div class="label">Employee ID</div>
					<div class="value"><?php echo $emp_id; ?></div>
				</div>
				
				<div class="entry">
					<div class="label">Hourly Rate</div>
					<div class="value"><?php echo $hrate; ?></div>
				</div>
				<div class="entry">
					<div class="label">Business Unit</div>
					<div class="value"><?php echo $bu; ?></div>
				</div>
				<div class="entry">
					<div class="label">Date Hired</div>
					<div class="value"><?php echo $jdate; ?></div>
				</div>
				<div class="entry">
					<div class="label">Position</div>
					<div class="value"><?php echo $position; 
					?></div>
				</div>
				<div class="entry">
					<div class="label">Department</div>
					<div class="value"><?php echo $division; 
					?></div>
				</div>
				<div class="entry">
					<div class="label">Rank</div>
					<div class="value"><?php echo $rank; 
					?></div>
				</div>

				<div class="entry">
					<div class="label">Payroll Cycle</div>
					<div class="value">Semi-Monthly</div>
				</div>

				<div class="entry">
					<div class="label">Payroll</div>
					<div class="value">13th Month Pay</div>
				</div>
				
				
				
				<div class="entry">
					<div class="label">Prepared by</div>
					<div class="value">Accounting Department</div>
				</div>
			</div>
			<div class="gross">
				<div class="title">Gross Income</div>
				<div class="entry">
					<div class="label"></div>
					<div class="value"><?php echo $salary1; 
					?></div>
				</div>
			</div>
			<div class="contributions">
				<div class="title">Employer Contribution</div>
				<div class="entry">
					<div class="label">SSS</div>
					<div class="value">1,178.70</div>
				</div>
				<div class="entry">
					<div class="label">SSS EC</div>
					<div class="value">30.00</div>
				</div>
				<div class="entry">
					<div class="label">HDMF</div>
					<div class="value">100.00</div>
				</div>
				<div class="entry">
					<div class="label">PhilHealth</div>
					<div class="value">437.50</div>
				</div>
			</div>
			<div class="ytd">
				<div class="title">Year To Date Figures</div>
				<div class="entry">
					<div class="label">Gross Income</div>
					<div class="value"><?php echo $gross_income;?></div>
				</div>
				<div class="entry">
					<div class="label">Taxable Income</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Withholding Tax</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Net Pay</div>
					<div class="value"><?php echo $netpay_year; ?></div>
				</div>
				<div class="entry">
					<div class="label">Allowance</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Bonus</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Commission</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Deduction</div>
					<div class="value"><?php echo $year_deduction; ?></div>
				</div>
				<div class="entry">
					<div class="label">SSS Employer</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">SSS EC Employer</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">PhilHealth Employer</div>
					<div class="value">0</div>
				</div>
				<div class="entry">
					<div class="label">Pag-ibig Employer</div>
					<div class="value">0</div>
				</div>
			</div>
		</div>
		<div class="right-panel">
			<div class="details">
				<div class="basic-pay">
					<div class="entry">
						<div class="label">Basic Pay</div>
						<div class="detail"></div>
						<div class="rate"><?php echo $salary1."/Month"; ?></div>
						<div class="amount"><?php echo $salary1; ?></div>
					</div>
				</div>
				<div class="salary1">
					<div class="entry">
						<div class="label"></div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Undertime</div>
						<div class="rate">128hrs@259.62/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Unworked Holiday</div>
						<div class="rate">16hrs@259.62/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Regular Holiday Regular Holiday</div>
						<div class="rate">9hrs@778.85/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Regular Holiday Regular Holiday Night</div>
						<div class="rate">7hrs@856.73/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Night</div>
						<div class="rate">56hrs@285.582/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Regular Holiday</div>
						<div class="rate">9hrs@519.23/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Regular Holiday Night</div>
						<div class="rate">7hrs@571.15/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Regular Holiday Night Overtime</div>
						<div class="rate">2hrs@742.50/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Special Holiday</div>
						<div class="rate">9hrs@337.50/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Special Holiday Night</div>
						<div class="rate">7hrs@371.25/hr</div>
						<div class="amount">0</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Rest Day</div>
						<div class="rate">8hrs@337.50/hr</div>
						<div class="amount">0</div>
					</div>
				</div>
				<div class="leaves">
					<div class="entry">
						<div class="label">Leaves</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry paid">
						<div class="label"></div>
						<div class="detail">Paid Leave</div>
						<div class="rate">8hrs@259.62/hr</div>
						<div class="amount">2,076.92</div>
					</div>
					<div class="entry unpaid">
						<div class="label"></div>
						<div class="detail">Unpaid Leave</div>
						<div class="rate">8hrs@259.62/hr</div>
						<div class="amount">(2076.96)</div>
					</div>
				</div>
				
				
				
				<div class="taxable_commission"></div>
				<div class="contributions">
					<div class="entry">
						<div class="label">Contributions</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">SSS</div>
						<div class="rate"></div>
						<div class="amount"><?php echo $sss; ?></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">HDMF</div>
						<div class="rate"></div>
						<div class="amount"><?php echo $pagibig; ?></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">PhilHealth</div>
						<div class="rate"></div>
						<div class="amount"><?php echo $ph; ?></div>
					</div>
				</div>
				<div class="nti">
					<div class="entry">
						<div class="label">TAXABLE INCOME</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount">82,705.06</div>
					</div>
				</div>
				<div class="withholding_tax">
					<div class="entry">
						<div class="label">Withholding Tax</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"><?php echo $tax;?></div>
					</div>
				</div>
				<div class="non_taxable_allowance">
					<div class="entry">
						<div class="label">Non-Taxable Allowance</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Allowance Name</div>
						<div class="rate"></div>
						<div class="amount">0</div>
					</div>
				</div>
				<div class="non_taxable_bonus">
					<div class="entry">
						<div class="label">Non-Taxable Bonus</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Bonus Name</div>
						<div class="rate"></div>
						<div class="amount">0</div>
					</div>
				</div>
				<div class="non_taxable_commission">
					<div class="entry">
						<div class="label">Non-Taxable Commission</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Commission Name 1</div>
						<div class="rate"></div>
						<div class="amount">3,000.00</div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">Commission Name 2</div>
						<div class="rate"></div>
						<div class="amount">2,500.00</div>
					</div>
				</div>
				<div class="deductions">
					<div class="entry">
						<div class="label">Deductions</div>
						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"></div>
					</div>
					<div class="entry">
						<div class="label"></div>
						<div class="detail">HMO</div>
						<div class="rate"></div>
						<div class="amount">(500.00)</div>
					</div>
				</div>
				<div class="net_pay">
					<div class="entry">
						<div class="label">NET PAY</div>

						<div class="detail"></div>
						<div class="rate"></div>
						<div class="amount"><?php echo $netpay; ?></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>