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

$formname = "Bill Print";
$action = "bill_print_fr.php";
$fuser = $_SESSION["usertype"];
$society = $_SESSION["society_" . $dbname];
$custcode = $_SESSION["custcode_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];
//browse("2022");

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

$usercond = '';
if (!empty($custcode)) {
    $usercond = "and `accode` = '$custcode' ";
}

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

$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');
$zroot = $_SESSION["zdbroot"];

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

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

include("includes/linkshead.php");
?>
<style>
    select[multiple]{
        height: 160px;
    }
</style>
<script src="MyScript/bill_print.js" type="text/javascript"></script>
</head>
<body>
    <form method='POST' action="<?= $action; ?>" target="_blank">
        <!-- Default box -->
        <div class="col-lg-6 col-md-62 col-sm-12 col-xs-12  pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title" style="color:#0098DA;"><?php Echo $formname; ?></h3>
                    <div class="actions pull-right">
                    </div>
                </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">Billing Period</label>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-5 col-xs-5 pad">
                            <select class='billcycle form-control select2' name='billcode' required>
                                <option value=''></option>
                                <?php
                                $getbill = mysqli_query($conn, "SELECT `code`,`descrip` FROM $zroot.`billingcycle` Where `billcycle` = '$billcycle' ORDER BY `orderby`") or die(mysqli_error($conn));
                                while ($fetbill = mysqli_fetch_array($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>
                    <?php if ($usertype == 1) { ?>
                        <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">Flat No.</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <select class='flatno form-control select2' name='flatno[]' multiple>
                                    <!--<option value=''></option>-->
                                    <?php
                                    $getflatno = mysqli_query($conn, "SELECT `accode`,`flatno` FROM `accmast` where `grpcode`='010' 
                                                             and `active`='1' and `series` = '$society'  ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($fetflatno = mysqli_fetch_array($getflatno)) {
                                        Echo "<option value='$fetflatno[accode]'>$fetflatno[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-6 col-md-6 col-sm-6 col-xs-6 pad">
                                <select class='member form-control select2' name='acname[]' multiple>
                                    <!--<option value=''></option>-->
                                    <?php
                                    $getmem = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` where `grpcode`='010' 
                                                           and `active`='1'  and `series` = '$society'  ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($fetmem = mysqli_fetch_array($getmem)) {
                                        Echo "<option value='$fetmem[accode]'>$fetmem[name]</option>";
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                    <?php } else { ?>
                        <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">Flat No.</label>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 pad">
                                <select class='flatno form-control select2' name='flatno'>
                                    <option value=''></option>
                                    <?php
                                    $getflatno = mysqli_query($conn, "SELECT `accode`,`flatno` FROM `accmast` where `grpcode`='010' 
                                                             and `series` = '$society'  ORDER BY `flatno`") or die(mysqli_error($conn));
                                    while ($fetflatno = mysqli_fetch_array($getflatno)) {
                                        Echo "<option value='$fetflatno[accode]'>$fetflatno[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-6 col-md-6 col-sm-6 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 `accmast` WHERE 
                                                           `grpcode`='010' and `series`='$society' $usercond ORDER BY `name`") or die(mysqli_error($conn));
                                    while ($fetmem = mysqli_fetch_array($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">Page Type</label>
                        </div>
                        <div class="col-lg-2 col-md-6 col-sm-6 col-xs-6 pad">
                            <select class='pgtype form-control select2' name='pgtype'>
                                <option value='2'>Double</option>
                                <option value='1'>Single</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">Print Zero</label>
                        </div>
                        <div class="col-lg-2 col-md-6 col-sm-6 col-xs-6 pad">
                            <select class='pzero form-control select2' name='pzero'>
                                <option value='N'>No</option>
                                <option value='Y'>Yes</option>
                            </select>
                        </div>
                    </div>
                </div>

                <div class="panel-footer text-center">
<!--                    <button id='subpdf' type='submit' name='subpdf' formtarget="_blank" name='pdf' class="btn btn-pad btn-square" style="background-color:white;border: 1px solid red">
                        <i class="fa fa-file-pdf-o" style="color:red; font-size: 15px;"></i>
                    </button>-->

                    <input type="submit" name="view" value="Proceed" class="btn btn-pad btn-square" style="background-color:#0098DA;color: white">
                    <button id='cancel' type="reset" class="btn btn-pad btn-square" style="background-color:red;color: white;" onclick="window.location.href = 'default.php'">
                        Exit
                    </button>

                    <?php // include("includes/but_rep.php"); ?>
                </div>

            </div>
        </div>

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