<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$formname = "Generate Bill";
$action = "generate.php";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$society = $_SESSION["society_" . $dbname];

if (empty($society)) {
    browse("Invalid Society Credentials Forced Logout.");
    print '<script type="text/javascript">';
    print " top.window.location = 'index.php'";
    PRINT '</script>';
}

$year = $_SESSION[$myyear];

$getsoc = mysqli_query($conn, "SELECT * FROM `company` WHERE `code` = '$society' ") or die(mysqli_error($conn));
$fetsoc = mysqli_fetch_array($getsoc);
$billcycle = $fetsoc['billcycle'];
//$zacinterest = $fetsoc['acinterest'];

//if ($zacinterest == 0) {
//    $disabled = 'disabled';
//    browse('Please define Account For Interest in the Society Set Up !!');
//} else {
//    $disabled = '';
//}

switch ($billcycle) {

    case 'M': $byname = 'MONTHLY';
        break;
    case 'BM': $byname = 'BI - MONTHLY';
        break;
    case 'Q': $byname = 'QUARTERLY';
        break;
    case 'H': $byname = 'HALF YEARLY';
        break;
    default : $byname = '';
}

$zyear = right($zdb, 4);

$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');

$myyear = $_SESSION[$myyear];
$zroot = $_SESSION["zdbroot"];


include("includes/linkshead.php");
?>
<script src="MyScript/checkdate.js" type="text/javascript"></script>
<script src="MyScript/genbill.js" type="text/javascript"></script>
</head>
<body>
    <form id="fsubmit" method='POST' action="generate.php">
        <!-- Default box -->
        <div>
            <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12  pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                        <input type="date" value="<?= $mfrdate ?>" style="width: 1px;border: none" class="zstdate">
                        <input type="date" value="<?= $mtodate ?>" style="width: 1px;border: none" class="zenddate">
                        <input type="hidden" name="billcycle" value="<?= $billcycle; ?>"  class="billcycle form-control">
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg" style="">BILLING CYCLE</label>
                            </div>
                            <div class="col-lg-6 col-md-6 col-sm-5 col-xs-5 pad">
                                <label class="label-control marg" style="color: Red"><?php echo $byname ?></label>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Billing Period</label>
                            </div>
                            <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                <select class='form-control billcode select2' name='billcode' required>
                                    <option value=''></option>
                                    <?php
                                    $getbill = mysqli_query($conn, "SELECT `code`,`descrip` FROM `billingcycle` Where `billcycle` = '$billcycle' ORDER BY `orderby`") or die(mysqli_error($conn));
                                    while ($fetbill = mysqli_fetch_assoc($getbill)) {
                                        Echo "<option value='$fetbill[code]'>$fetbill[descrip]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Year</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-5 col-xs-5 pad">
                                <input type="text" name="yearno" class="form-control yearno">
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control">Flat No.</label>
                            </div>
                            <div class="col-lg-5 col-md-5 col-sm-8 col-xs-8 pad">
                                <select class='form-control select2 flatno' name='flatno'>
                                    <option value=""></option>
                                    <?php
                                    $ct = mysqli_query($conn, "SELECT flatno FROM $zdb.`accmast` WHERE `active`='1' and flatno != '' and 
                                           `series` = '$society' group by flatno ORDER BY `flatno`") or die(mysqli_error($conn));
                                    while ($ctro = mysqli_fetch_array($ct)) {
                                        echo "<option value='$ctro[flatno]'>$ctro[flatno]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>                        
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Member</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-6 pad">
                                <select class='member form-control select2' id="party" name='member'>
                                    <option value=''></option>
                                    <?php
                                    $getmem = mysqli_query($conn, "SELECT `accode`,`name` FROM $zdb.`accmast` Where `grpcode`='010' 
                                            and `active`='1' and `series` = '$society' ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($fetmem = mysqli_fetch_assoc($getmem)) {
                                        Echo "<option value='$fetmem[accode]'>$fetmem[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg" style="">Bill Date</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-3 col-xs-3 pad">
                                <input type="date" name="trandate" class=' form-control vouchdt' value="<?php echo date('Y-m-d'); ?>" required>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer text-center pad">
                        <!--                        <a class="btn btn-pad btn-square" style="background-color:#0098DA;color: white">
                                                    Proceed
                                                </a>-->
                        <input type="button"  value="Proceed" class="btn btn-pad btn-square proceed" style="background-color:#0098DA;color: white" <?= $disabled ?>>
                        <input type="submit" name="submit" value="" class="btn btn-pad btn-square" id="submit" style="display:none" >

                        <input type="button"  value="Delete" class="btn btn-pad btn-square delete" style="background-color:red;color: white">
                        <input type="submit" name="delete" value="" class="btn btn-pad btn-square" id="delete" style="display:none" >
                        <button  type="reset" class="btn btn-pad btn-square" style="background-color:red;color: white;" onclick="window.location.href = 'default.php'">
                            Exit
                        </button>
                        <!--                        <button  class="btn btn-pad btn-square" name="delete" style="background-color:red;color: white;"  onclick="window.location.href = 'generate.php'">
                                                    Exit
                                                </button>-->

                    </div>
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
