<?php
include("include/config.inc.php");
include_once("./mpdf/mpdf.php");
$mpdf = new mPDF('c', 'A4-L',0,'',$mgl=8,$mgr=8,$mgt=8,$mgb=8);
$mpdf->falseBoldWeight = 8;
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	$to       = $_REQUEST['to'];
	$from     = $_REQUEST['from'];
 
	$a = 0;
	$rojmelArray = array();
	$selectRojmel = "SELECT *,partyName FROM rojmel
						 LEFT  JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'A'
						  AND rojmelDate between '".$to."' AND '".$from."'";
	$selectRojmelRes = mysql_query($selectRojmel);
	while($rojmelRow = mysql_fetch_array($selectRojmelRes))
	{
	  $rojmelArray[$a]['rojmelId']        = $rojmelRow['rojmelId'];
	  $rojmelArray[$a]['rojmelDate']      = date('d-m-Y',strtotime($rojmelRow['rojmelDate']));
	  $rojmelArray[$a]['rojTransType']   = $rojmelRow['rojTransType'];
	  $rojmelArray[$a]['partyName']      = $rojmelRow['partyName'];
	  $rojmelArray[$a]['particular']     = $rojmelRow['particular'];
	  $rojmelArray[$a]['fine']           = $rojmelRow['fine'];
	  $rojmelArray[$a]['amount']         = $rojmelRow['amount'];
	  $rojmelArray[$a]['acc_type']       = $rojmelRow['acc_type'];
	  $rojmelArray[$a]['rate']   	     = $rojmelRow['rate'];
	  $a++;
	}
	
	$k = 0;
	$javakArray = array();
	$selectJavak = "SELECT *,partyName FROM rojmel
						LEFT JOIN party ON party.partyId = rojmel.partyId
						  WHERE rojTransType = 'J'
						   AND rojmelDate between '".$to."' AND '".$from."'";
	$selectJavakRes = mysql_query($selectJavak);
	while($javakRow = mysql_fetch_array($selectJavakRes))
	{
	  $javakArray[$k]['rojmelId']         = $javakRow['rojmelId'];
	  $javakArray[$k]['rojmelDate']       = date('d-m-Y',strtotime($javakRow['rojmelDate']));
	  $javakArray[$k]['rojTransType']    = $javakRow['rojTransType'];
	  $javakArray[$k]['partyName']       = $javakRow['partyName'];
	  $javakArray[$k]['particular']      = $javakRow['particular'];
	  $javakArray[$k]['fine']            = $javakRow['fine'];
	  $javakArray[$k]['amount']          = $javakRow['amount'];
	  $javakArray[$k]['acc_type']        = $javakRow['acc_type'];
	  $javakArray[$k]['rate']            = $javakRow['rate'];
	  $k++;
	}	
	$selectRojmel = "SELECT SUM(fine) AS afine,SUM(amount) AS aamount FROM rojmel
						WHERE rojTransType = 'A'
						AND  rojmelDate between '".$to."' AND '".$from."'";
	$selectRojmelRes = mysql_query($selectRojmel);
	if($row = mysql_fetch_array($selectRojmelRes))
	{
	  $aFine  =  $row['afine'];
	  $aAmount = $row['aamount'];
	}
	
	$selectRojmel = "SELECT SUM(fine) AS jfine,SUM(amount) AS jamount FROM rojmel
						WHERE rojTransType = 'J'
						AND  rojmelDate between '".$to."' AND '".$from."'";
	$selectRojmelRes = mysql_query($selectRojmel);
	if($row = mysql_fetch_array($selectRojmelRes))
	{
	  $jFine   = $row['jfine'];
	  $jAmount = $row['jamount'];
	}
	
	$netFine   = $aFine - $jFine;
	$netAmount = $aAmount - $jAmount;

}
ob_start();	
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Rojmel List</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="./css/bootstrap.min.css">
	    <style>
    td,
    th {
        padding: 5px;
        white-space: nowrap;
    }

    td {
        border-bottom-style: none;
        border-top-style: none;
    }

    .center {
        text-align: center;
    }

    .right {
        text-align: right;
    }

    h2 {
        font-family: "Impact", Charcoal, sans-serif;
    }
    .border1 {
        border: 1;
    }
    .border-left {
        border-left: 1px solid !important;;
    }
    .table-items thead tr th, .table-items tbody tr td {
    	padding: 10px 8px;
    }

    .divRight {
        text-align: right;
    }

    .text_bold {
        font-weight: bold;
    }

    .text_center {
        text-align: center;
    }

    .text_left {
        text-align: left;
    }

    .text_right {
        text-align: right;
    }

    .no-border-top {
        border-top: 0;
    }

    .no-border-bottom {
        border-bottom: 0 !important;
    }

    .no-border-left {
        border-left: 0;
    }

    .no-border-right {
        border-right: 0;
    }

    .no-border {
        border: 0;
    }

    .border-right {
        border-right: 1px solid black;
        border-left: 0;
        border-top: 0;
        border-bottom: 0;
    }

    .text-bold {
        font-weight: 800 !important;
    }

    .text-nowrap {
        white-space: nowrap !important;
    }
    </style>
</head>
<body>
   		<table class="border1 table-items" style="width: 100%; font-size:13px; border-collapse: all;">
				<thead>
					<tr>
						<th colspan="7" align="center">Buy</th>
						<th class="border-left" colspan="7" align="center">Sell</th>
					</tr>
					<tr>
						<th>Type</th>
						<th>Party Name</th>
						<th>Date</th>
						<th>Particular</th>
						<th>Cash Type</th>
						<th>Fine</th>
						<th>Amount</th>
						<th class="border-left">Type</th>
						<th>Party Name</th>
						<th>Date</th>
						<th>Particular</th>
						<th>Cash Type</th>
						<th>Fine</th>
						<th>Amount</th>
					</tr>
				</thead>
 	            	<tbody>
						<?php
							$max_ind = count($rojmelArray) > count($javakArray)?count($rojmelArray):count($javakArray);
							for ($i=0; $i < $max_ind; $i++) {
							// code...
						?>
						<tr>	
							<?php if(isset($rojmelArray[$i])) { ?>
    							<?php if($rojmelArray[$i]['acc_type'] == 'D') { ?>
    								<td>Direct</td>
    					 		<?php } else { ?>
    								<td>Khata</td>
    							<?php } ?>
    							<td><?php echo $rojmelArray[$i]['partyName'] ?></td>
    							<td><?php echo $rojmelArray[$i]['rojmelDate'] ?></td>
    							<td><?php echo $rojmelArray[$i]['particular'] ?></td>
    							<?php if($rojmelArray[$i]['cash_type'] == 'C') { ?>
    								<td>Cash</td>
    					 		<?php } else { ?>
    								<td>Rtgs</td>
    							<?php } ?>
    							<td><?php echo number_format((float)$rojmelArray[$i]['fine'], 3, '.', '') ?></td>
    							<td><?php echo number_format((float)$rojmelArray[$i]['amount'], 0, '.', '') ?></td>
						    <?php } else { ?>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
					        <?php } ?>
						 	<?php if(isset($javakArray[$i])) { ?>					
    							<?php if($javakArray[$i]['acc_type'] == 'D') { ?>
    								<td class="border-left">Direct</td>
    					 		<?php } else { ?>
    								<td class="border-left">Khata</td>
    							<?php } ?>
    							<td><?php echo $javakArray[$i]['partyName'] ?></td>
    							<td><?php echo $javakArray[$i]['rojmelDate'] ?></td>
    							<td><?php echo $javakArray[$i]['particular'] ?></td>
    							<?php if($javakArray[$i]['cash_type'] == 'C') { ?>
    								<td>Cash</td>
    					 		<?php } else { ?>
    								<td>Rtgs</td>
    							<?php } ?>
    							<td><?php echo number_format((float)$javakArray[$i]['fine'], 3, '.', '') ?></td>
    							<td><?php echo number_format((float)$javakArray[$i]['amount'], 0, '.', '') ?></td>
							<?php } else { ?>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
    							<td></td>
					        <?php } ?>
						</tr>
					    <?php } ?>
				</tbody>
				 
					 
					 
			
			</table>
			<br>
			<table align="center" border="">
				<tr>
					<td><h3>Aavak Fine : &nbsp;&nbsp; 	<?php echo number_format((float)$aFine, 3, '.', '') ?></h3></td>
					<td><h3>Javak Fine : &nbsp;&nbsp; 	<?php echo number_format((float)$jFine, 3, '.', '') ?></h3></td>
					<td><h3>Aavak Amount : &nbsp;&nbsp; <?php echo number_format((float)$aAmount, 0, '.', '') ?></h3></td>
					<td><h3>Javak Amount : &nbsp;&nbsp; <?php echo number_format((float)$jAmount, 0, '.', '') ?></h3></td>
				</tr>
				<tr>
					<td><h3>Fine : &nbsp;&nbsp; 	<?php echo number_format((float)$netFine, 3, '.', '') ?></h3></td>
					<td><h3>Amount : &nbsp;&nbsp; 	<?php echo number_format((float)$netAmount, 0, '.', '') ?></h3></td>
				</tr>
			</table>
</body>
</html>
<?php
$html_content = ob_get_clean();
$mpdf->WriteHTML($html_content);
$mpdf->Output("Rojmel List.pdf", 'I');
exit();
?>