<?php
ob_start();
session_start();
include_once("../config.php");
if(!check_login()){
	header("Location: ".WEB_URL."logout.php");
	die();
}
$lang_code_global = "English";
$global_currency = "$";
$currency_position = "left";
$currency_sep = ".";

$query_ams_settings = mysqli_query($link,"SELECT * FROM settings");
while($row_query_ams_core = mysqli_fetch_array($query_ams_settings)){
	$lang_code_global = $row_query_ams_core['lang_code'];
	$global_currency = $row_query_ams_core['currency'];
	$currency_position = $row_query_ams_core['currency_position'];
	$currency_sep = $row_query_ams_core['currency_seperator'];
}
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_fair_info_all.php');
include_once(ROOT_PATH.'language/'.$lang_code_global.'/lang_common.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sako Apartment Management System</title>
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<!-- Bootstrap 3.3.4 -->
<link href="<?= WEB_URL; ?>bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<!-- Font Awesome Icons -->
<link href="<?= WEB_URL; ?>dist/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<!-- Ionicons -->
<link href="<?= WEB_URL; ?>dist/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<!-- Theme style -->
<link href="<?= WEB_URL; ?>dist/css/AdminLTE.css" rel="stylesheet" type="text/css" />
<!-- AdminLTE Skins. Choose a skin from the css/skins 
 folder instead of downloading all of them to reduce the load. -->
<link href="<?= WEB_URL; ?>dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
<!-- iCheck for checkboxes and radio inputs -->
<link href="<?= WEB_URL; ?>plugins/iCheck/all.css" rel="stylesheet" type="text/css" />
<link href="<?= WEB_URL; ?>plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="<?= WEB_URL; ?>dist/css/dataTables.responsive.css" rel="stylesheet" type="text/css" />
<link href="<?= WEB_URL; ?>dist/css/dataTables.tableTools.min.css" rel="stylesheet" type="text/css" />
<link href="<?= WEB_URL; ?>plugins/datepicker/datepicker3.css" rel="stylesheet" type="text/css" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- jQuery 2.1.4 -->
<script src="<?= WEB_URL; ?>plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="<?= WEB_URL; ?>dist/js/printThis.js"></script>
<script src="<?= WEB_URL; ?>dist/js/common.js"></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">
        <div class="box box-info">
          <div class="box-header">
            <h3 style="text-decoration:underline;font-weight:bold;color:orange" 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_2'];?></th>
                  <th><?= $_data['text_3'];?></th>
                  <th><?= $_data['text_4'];?></th>
                  <th><?= $_data['text_5'];?></th>
                  <th><?= $_data['text_6'];?></th>
                  <th><?= $_data['text_7'];?></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;
				
				$result = mysqli_query($link,"select *,r.r_name,o.o_name,fl.b_name,u.unit_no,m.month_name 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 f.month_id ='".$_GET['mid']."' and f.branch_id = '" . (int)$_SESSION['objLogin']['branch_id'] . "'");
				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['issue_date']; ?></td>
                    <td><?php if($row['type']=='Rented'){echo $row['r_name'];} else{echo $row['o_name'];} ?></td>
                    <td><?= $row['type']; ?></td>
                    <td><?= $row['b_name']; ?></td>
                    <td><?= $row['unit_no']; ?></td>
                    <td><?= $row['month_name']; ?></td>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['rent']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['rent'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['gas_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['gas_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['electric_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['electric_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['water_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['water_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['security_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['security_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['utility_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['utility_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['other_bill']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['other_bill'].$global_currency; ?></h3>
                    <?php } ?>
                    <?php if($currency_position == 'left') { ?>
                    <td><?= $global_currency.$row['total_rent']; ?></td>
                    <?php } else { ?>
                    <td><?= $row['total_rent'].$global_currency; ?></h3>
                    <?php } ?>
                </tr>
                <?php } mysqli_close($link); ?>
              </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;"><?php if($currency_position == 'left'){echo $global_currency.number_format($rent_per_month_sub_total, 2, '.', '');}else { echo number_format($rent_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($gas_per_month_sub_total, 2, '.', '');}else { echo number_format($gas_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($electric_per_month_sub_total, 2, '.', '');}else { echo number_format($electric_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($water_per_month_sub_total, 2, '.', '');}else { echo number_format($water_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($security_per_month_sub_total, 2, '.', '');}else { echo number_format($security_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($utility_per_month_sub_total, 2, '.', '');}else { echo number_format($utility_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($other_per_month_sub_total, 2, '.', '');}else { echo number_format($other_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                  <th style="color:red;"><?php if($currency_position == 'left'){echo $global_currency.number_format($total_per_month_sub_total, 2, '.', '');}else { echo number_format($total_per_month_sub_total, 2, '.', '').$global_currency;} ?></th>
                </tr>
              </tfoot>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- /.row -->
<div align="center"><a class="btn btn-primary btn_save" onClick="javascript:printContent('printable','Fair Collection Report');" href="javascript:void(0);"><?= $_data['text_16'];?></a></div>
</body>
</html>
