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

$zdb = $_SESSION["zdbyear_" . $dbname];
$zyear = right($zdb, 4);
$mfrdate = getzdates($zyear, 'S');
$mtodate = getzdates($zyear, 'E');
$zroot = $_SESSION["zdir"];
$zcomp = $_SESSION["comp_" . $dbname];

$para = $_GET['para'];

if ($para == "M") {
    $formname = "Invoice - Multiple";
} else {
    $formname = "Invoice - Single";
}

$action = "invoice_fr.php?para=$para";

mysqli_select_db($conn, $zdb);


//$cmpname = mysqli_query($conn, "SELECT * From $zroot.`month` where `code`='1'")or die(mysqli_error($conn));
//$getcmpname = mysqli_fetch_array($cmpname);

include("includes/linkshead.php");
?>

<!--<script src="MyScript/rgbill_reg.js"  type="text/javascript"></script>-->   
</head>
<script>
    $(document).ready(function () {
        $('body').on('change', '.frmcode, .tocode', chngeval);
        $('body').on('change', '.period', chngeper);

        $('.daydate').hide();
        $('.lbldate').hide();

        function chngeval() {
            var frmcode = $('.frmcode').val();
            var tocode = $('.tocode').val();

            if (frmcode == tocode) {
                $.post('getcustname.php', {custcode: frmcode}, function (data) {
                    if (data != 0) {
                        $('.account').val(data).trigger("change");
                    }
                });
            }
        }

        function chngeper() {
            var period = $('.period').val();

            if (period == 8) {
                $('.daydate').show();
                $('.lbldate').show();
            } else {
                $('.daydate').hide();
                $('.lbldate').hide();
            }
        }

    });


</script>
<body>
    <form method='POST' action="<?= $action; ?>">
        <!-- Default box -->

        <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12  pad">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php Echo $formname; ?></h3>

                </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">Month</label>
                        </div>
                        <div class="col-lg-4 col-md-4 col-sm-8 col-xs-8 pad">
                            <select name="month" class="form-control select2" required="">
                                <option value=""></option>
                                <?php
                                $month = mysqli_query($conn, "SELECT moncode, monname FROM $zroot.`month` ") or die(mysqli_error($conn));
                                while ($mon = mysqli_fetch_array($month)) {
                                    echo "<option value='$mon[moncode]'>$mon[monname]</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">Period Month</label>
                        </div>
                        <div class="col-lg-4 col-md-4 col-sm-8 col-xs-8 pad">
                            <select name="period" class="form-control select2 period">
                                <option value="1">Full Month</option>
                                <option value="2">1st Half</option>
                                <option value="3">2nd Half</option>
                                <option value="4">1st Week(01-07)</option>
                                <option value="5">2nd Week(08-15)</option>
                                <option value="6">3rd Week(16-22)</option>
                                <option value="7">4th Week(23-31)</option>
                                <option value="8">Daily</option>
                                <option value="9">1st Ten Days(01-10)</option>
                                <option value="10">Mid Ten Days(11-20)</option>
                                <option value="11">Last Ten Days(21-EOM)</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 lbldate">Date</label>
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="date" id="daydate" name="daydate" class="form-control daydate" value="<?php echo $mfrdate; ?>" >   
                        </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">From Code</label>
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="text" id="frmcode" name="frmcode" class="form-control frmcode" value="" > 
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">To Code</label>
                        </div>
                        <div class="col-lg-2 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="text" id="tocode" name="tocode" class="form-control tocode" value="" > 
                        </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">Account Name</label>
                        </div>
                        <div class="col-lg-7 col-md-7 col-sm-8 col-xs-8 pad">
                            <select name="account" class="form-control select2 account">
                                <option value=""></option>
                                <?php
                                $acc = mysqli_query($conn, "SELECT accode,name FROM accmast where grpcode='010'") or die(mysqli_error($conn));
                                while ($arow = mysqli_fetch_array($acc)) {
                                    echo "<option value='$arow[accode]'>$arow[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">Vehicle No.</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="text" id="vehno" name="vehno" class="form-control" value="" > 
                        </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">Invoice No.</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="number" id="invno" name="invno" class="form-control" value="0" > 
                        </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">Invoice Date</label>
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                            <input type="date" id="todate" name="todate" class="form-control" value="" required="">   
                        </div>
                        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                            <label class="label-control marg">Summary For All A/c.</label>
                        </div>
                        <div class="col-lg-2 col-md-2 col-sm-3 col-xs-3  pad">
                            <input type="checkbox" name="summ" class="form-control summ" id="summ" value="" >
                        </div>
                    </div>    

                </div>
                <div class="panel-footer text-center">
                    <?php include("includes/but_rep.php"); ?>
                </div>
            </div>
        </div>
    </form>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>