<?php
ob_start();
session_start();
include_once("../config.php");
if(!check_login()){
	header("Location: ".WEB_URL."logout.php");
	die();
}

include_once(ROOT_PATH.'partial/report_top_common.php');
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_rented_r_all_info.php');
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_common.php');
include_once(ROOT_PATH.'library/helper.php');
$ams_helper = new ams_helper();

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $building_name; ?></title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<?php include_once(ROOT_PATH.'/partial/header_script.php'); ?>
<script type="text/javascript">
function printContent(area,title){
	$("#"+area).printThis({
		 pageTitle: title
	});
}
</script>
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<section class="content">
<!-- Main content -->
<div id="printable">
  <div align="center" style="margin:50px;">
    <input type="hidden" id="web_url" value="<?= WEB_URL; ?>" />
    <div class="row">
      <div class="col-xs-12">
        <?php include_once(ROOT_PATH.'partial/report_top_title.php'); ?>
        <div class="box box-success">
          <div class="box-header">
            <h3 style="text-decoration:underline;font-weight:bold;color:black" class="box-title"><?= $_data['text_1'];?></h3>
          </div>
          <div class="box-body">
            <table style="font-size:13px;" class="table sakotable table-bordered table-striped dt-responsive">
              <thead>
                <tr>
                  <th><?= $_data['text_22'];?></th>
				  <th><?= $_data['text_2'];?></th>
                  <th><?= $_data['text_3'];?></th>
                  <!--<th><?php //echo $_data['text_4'];?></th>-->
                  <th><?= $_data['text_5'];?></th>
                  <th><?= $_data['text_6'];?></th>
                  <th><?= $_data['text_7'];?></th>
                  <th><?= $_data['text_77'];?></th>
                  <th><?= $_data['text_8'];?></th>
                  <th><?= $_data['text_9'];?></th>
                  <th><?= $_data['text_10'];?></th>
                  <th><?= $_data['text_11'];?></th>
                  <th><?= $_data['text_12'];?></th>
                  <th><?= $_data['text_13'];?></th>
                  <th><?= $_data['text_14'];?></th>
                  <th><?= $_data['text_15'];?></th>
                </tr>
              </thead>
              <tbody>
                <?php
				$rent_per_month_sub_total = 0;
				$gas_per_month_sub_total = 0;
				$electric_per_month_sub_total = 0;
				$water_per_month_sub_total = 0;
				$security_per_month_sub_total = 0;
				$utility_per_month_sub_total = 0;
				$other_per_month_sub_total = 0;
				$total_per_month_sub_total = 0;
				//
				$strQuery = "select *,r.r_name,o.o_name,fl.b_name,u.unit_no,m.month_name,r.r_unit_no from rent f left join tenants r on r.tid = f.tid left join tbl_add_owner o on o.ownid = f.tid inner join blocks fl on fl.bid = f.b_name inner join units u on u.uid = f.unit_no inner join tbl_add_month_setup m on m.m_id = f.month_id where r.tid = '". (int)$_SESSION['objLogin']['tid'] . "'";
				if(!empty($_GET['mid'])){
					$strQuery .= " and f.month_id='".$_GET['mid']."'";
				}
				if(!empty($_GET['yid'])){
					$strQuery .= " and f.xyear='".$_GET['yid']."'";
				}
				if($_GET['ps'] != ''){
					$strQuery .= " and f.bill_status='".$_GET['ps']."'";
				}
				//
				$result = mysqli_query($link,$strQuery);
				while($row = mysqli_fetch_array($result)){
				$rent_per_month_sub_total +=(float)$row['rent'];
				$gas_per_month_sub_total +=(float)$row['gas_bill'];
				$electric_per_month_sub_total +=(float)$row['electric_bill'];
				$water_per_month_sub_total +=(float)$row['water_bill'];
				$security_per_month_sub_total +=(float)$row['security_bill'];
				$utility_per_month_sub_total +=(float)$row['utility_bill'];
				$other_per_month_sub_total +=(float)$row['other_bill'];
				$total_per_month_sub_total +=(float)$row['total_rent'];
				?>
                <tr>
                  <td><?= $row['f_id']; ?></td>
				  <td><?= $row['issue_date']; ?></td>
                  <td><?php if($row['type']=='Rented'){echo $row['r_name'];} else{echo $row['o_name'];} ?></td>
                  <!--<td><?php //echo $row['type']; ?></td>-->
                  <td><?= $row['b_name']; ?></td>
                  <td><?= $row['unit_no']; ?></td>
                  <td><?= $row['month_name']; ?></td>
                  <td><?= $row['xyear']; ?></td>
                  <td><?= $ams_helper->currency($localization, $row['rent']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['gas_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['electric_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['water_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['security_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['utility_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['other_bill']); ?></td>
                  <td><?= $ams_helper->currency($localization, $row['total_rent']); ?></td>
                </tr>
                <?php } mysqli_close($link);$link = NULL; ?>
              </tbody>
              <tfoot>
                <tr>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $rent_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $gas_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $electric_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $water_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $security_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $utility_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $other_per_month_sub_total); ?></th>
                  <th style="color:red;"><?= $ams_helper->currency($localization, $total_per_month_sub_total); ?></th>
                </tr>
              </tfoot>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- /.row -->
<div align="center" style="position:fixed;top:0;right:0;margin:10px;"><a class="btn btn-success btn_save" title="<?= $_data['text_16'];?>" onClick="javascript:printContent('printable','Fair Collection Report');" href="javascript:void(0);"><i class="fa fa-print"></i> </a></div>
</body>
</html>
