<?php
session_start();
if ( $_SESSION[ invcox ] == "" ) {
	header( "location:login.php?action=need" );
} else {

	include( "config.php" );
	?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Arnim Holidays Accounting Software</title>

<style>
    body{
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        color:#000;
    }

    .section{
        display:flex;
        justify-content:space-between;
        align-items:flex-start;
        margin-bottom:15px;
        border-bottom:2px solid #000;
        padding-bottom:10px;
    }

    .logo img{
        max-height:80px;
    }

    table{
        width:100%;
        border-collapse:collapse;
        margin-top:10px;
    }

    th, td{
        border:1px solid #000;
        padding:6px;
        text-align:center;
    }

    th{
        background:#f0f0f0;
        font-weight:bold;
    }

    .print-btn{
        margin-bottom:10px;
    }

    /* -------- PRINT SETTINGS -------- */
    @media print{
        .print-btn{ display:none; }
        a{ text-decoration:none; color:#000; }
        body{ margin:10mm; }
    }
</style>
</head>

<body>

<?php 
if($_POST[ds]!=""){$ds=$_POST[ds];}
if($_POST[de]!=""){$de=$_POST[de];}
if($_GET[ds]!=""){$ds=$_GET[ds];}
if($_GET[de]!=""){$de=$_GET[de];}
if($ds == ""){

$ds=date('d-m-Y');
}
if($de == ""){$de=date("d-m-Y");}
	
		  if($ds!=""){
		  $ds=$ds;
		  $de=$de;
		  $d="and  check_in BETWEEN '$ds' AND '$de'";}else{$d="";}

	
						?>

<div class="section">
    <div class="logo">
        <img src="images/wlogo.png" alt="Hotel Logo">
    </div>

    <div>
        <strong>ARNIM RESORT - COX'S BAZAR</strong><br>
        <strong>Address :</strong> 92, Marine Drive Road, Kolatoli, Cox's Bazar.<br>
        <strong>Phone :</strong> 01758-383938, 01866-000640, 0197-2288-526<br>
        <strong>E-mail :</strong> rsv@arnimresort.com |
        <strong>Web :</strong> arnimresort.com
    </div>
</div>

<h3 style="text-align:center">Salary Register from <?php echo $ds;  ?> to <?php echo $de;  ?></h3>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
  <tr>
    <th height="30">ID</th>
    <th height="30">Employee  Name </th>
    <th width="205" height="30" align="center"> Salary (Monthly)</th>
    <th align="center">Previous Due/Advance </th>
    <th height="30" align="left">Total Salary (This Month)</th>
    <th height="30" align="left">Salary Paid (This Month)</th>
    <th height="30" align="left">Salary Due  (Total)</th>
    <th height="30" align="center">Salary Advance  (Total)</th>
  </tr>
  <?php 
$ds=dtformat($ds);
$de=dtformat($de);
 

 

$result=mysql_query("select * from hr_employee order by id desc");

$row=mysql_fetch_array($result);

$sr=0;

																					  
																					  
		  if($ds!=""){

 
		  $d="and cdate>='$ds' and cdate<='$de' ";}else{$d="";}
																					  
do{

							

							$sr++;?>
  <tr>
    <td width="42" align="center" valign="top" class="link">      <?php    echo $row[id];?>    </td>
    <td width="309" align="center" valign="top" class="link"><?php    echo $row[customer_name];

            ?>
    </td>
    <td align="center" valign="top" class="link "><?php echo $row[contact_person];
$salary_total=$salary_total+$row[contact_person];
   ?></td>
    <td width="179" align="center" valign="top"><?php 
 
$bresult=mysql_query("select sum(salary)as salary from hr_salary where employee='$row[id]' and   cdate<'$ds'  ");
$brow=mysql_fetch_array($bresult);
$cresult=mysql_query("select sum(salary)as salary from hr_salary_paid where employee='$row[id]' and   cdate<'$ds' ");
$crow=mysql_fetch_array($cresult);			 

$opening=$brow[salary]-$crow[salary]; 

echo $opening; 
	$opening_total=$opening_total+$opening;	  
								  ?></td>
    <td width="230" align="left" valign="top" class="link "><?php 
 

	
$bresult=mysql_query("select sum(salary)as salary from hr_salary where employee='$row[id]' $d ");
$brow=mysql_fetch_array($bresult);
$cresult=mysql_query("select sum(salary)as salary from hr_salary_paid where employee='$row[id]' $d");
$crow=mysql_fetch_array($cresult);	
	
echo $brow[salary]; 

$this_salary=$this_salary+$brow[salary]; 
?></td>
    <td width="268" align="left" valign="top" class="link "><?php 
	
 echo $crow[salary]; 
	$this_salaryp=$this_salaryp+$crow[salary]; 
 ?></td>
    <td width="212" align="left" valign="top" class="link "><?php
$balance=($opening+$brow[salary])-$crow[salary];  	if($balance>"0"){echo $balance;  $total_due=$total_due+$balance;  }
?></td>
    <td width="285" align="center" valign="top" class="link "><?php  
		if($balance<"0"){echo $balance; $total_adv=$total_adv+$balance;  }


 ?></td>
  </tr>
  <?php }while($row=mysql_fetch_array($result));

?>
  <tr>
    <td align="center" valign="top" class="link">&nbsp;</td>
    <td align="center" valign="top" class="link">Total</td>
    <td align="center" valign="top" class="link "><?php echo number_format($salary_total);?></td>
    <td align="center" valign="top" class="link "><?php echo number_format($opening_total);?></td>
    <td align="left" valign="top" class="link "><?php echo number_format($this_salary);?></td>
    <td align="left" valign="top" class="link "><?php echo number_format($this_salaryp);?></td>
    <td align="left" valign="top" class="link "><?php echo number_format($total_due);?></td>
    <td align="center" valign="top" class="link "><?php echo number_format($total_adv);?></td>
  </tr>
</table>
</body>
</html><?php }?>
