<?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');

mysqli_select_db($conn, $zdb);

if ($_GET["para"] == "R") {
    $formname = " Outstanding Receiveable";
    $action = "osbill_fr.php";
    $hgrp = "R";
    $group = "010";
} else {
    $formname = " Outstanding Payable";
    $action = "osbill_fr.php";
    $group = " (`grpcode`='009' OR `grpcode`='006' OR `grpcode`='039' OR `grpcode` = '013')";
    $hgrp = "P";
}
include("includes/linkshead.php");
?>
<style>
    .align {
        margin-left: -15px;
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {

        $("body").on("change", ".acname", shwHid);
        $("body").on("change", ".agency", shwHid2);

        function shwHid2() {
            var para = $(".hiddenval").val();
            var agency = $(".agency").val();
            if (para == "R") {
                if (agency != "") {
                    $("#view").hide();
                    $("#printbut").show();
                } else {
                    $("#view").show();
                    $("#printbut").hide();
                }
            }
        }

        function shwHid() {
            var para = $(".hiddenval").val();
            var acname = $(".acname").val();
            if (para == "R") {
                if (acname != "") {
                    $("#view").show();
                    $("#printbut").hide();
                } else {
                    $("#view").hide();
                    $("#printbut").show();
                }
            }

        }


        $("#printbut").click(function () {
            var agency = $(".agency").val();
            var acname = $(".acname").val();
            var frmdt = $("#frmdt").val();
            $.post('getAgDiv.php', {
                frmdt: frmdt,
                acname: acname,
                agency: agency
            }, function (data) {
                if (data == "<h3 style='color:red'>No Record Found</h3>") {
                    $(".modview").hide();
                } else {
                    $(".modview").show();

                }
                $(".tbody").html(data);
                $("#printmodal").modal('show');

            });
        });

        $(".checkAll").click(function () {
            if ($(this).is(':checked')) {
                $(".chk").prop('checked', true);
            } else {
                $(".chk").prop('checked', false);
            }
        });
        //        $("#excel").hide();
        //        $("#subpdf").hide();
    });
</script>
</head>

<body>
    <div class="panel col-lg-6">
        <div class="forms">
            <div class="form-grids widget-shadow" data-example-id="basic-forms">
                <div class="form-title">
                    <h4><?php echo $formname ?> </h4>
                </div>
                <form name="" class="validation" action="<?= $action ?>" method="post">
                    <div class="row">
                        <div class="form-body">

                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg">A/c. Name</label></div>

                                <div class="col-lg-6 col-sm-9 pad">

                                    <select class='form-control select2 acname' name='acname' style="height:33px;">
                                        <option value=""></option>
                                        <?php
                                        $mown = mysqli_query($conn, "SELECT accode, `name` FROM `accmast`WHERE $group ORDER BY `name`") or die(mysqli_error($conn));
                                        while ($trow = mysqli_fetch_array($mown)) {
                                            echo "<option value='$trow[accode]'>$trow[name]</option>";
                                        }
                                        ?>
                                    </select>

                                </div>
                            </div>
                            <?php
                            if ($_GET["para"] == "R") {
                                ?>

                                <div class="row">
                                    <div class="col-lg-3 text-right"><label class="control-label marg">Agency</label></div>

                                    <div class="col-lg-6 col-sm-9 pad">

                                        <select class='form-control select2 agency' name='agency' style="height:33px;">
                                            <option value=""></option>
                                            <?php
                                            $magency = mysqli_query($conn, "SELECT accode, `name` FROM `accmast`WHERE grpcode = '040'  ORDER BY `name`") or die(mysqli_error($conn));
                                            while ($tagency = mysqli_fetch_array($magency)) {
                                                echo "<option value='$tagency[accode]'>$tagency[name]</option>";
                                            }
                                            ?>
                                        </select>

                                    </div>
                                </div>
                            <?php } ?>

                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg" style="color:blue">From Invoice Date</label></div>

                                <div class="col-lg-3 col-sm-3 pad">
                                    <input type="date" id="frminvdt" name="frminvdt" class="form-control frminvdt" style='height:33px;' value="<?= $mfrdate ?>" />
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg" style="color:blue">To Invoice Date</label></div>

                                <div class="col-lg-3 col-sm-3 pad">
                                    <input type="date" id="toinvdt" name="toinvdt" class="form-control toinvdt" style='height:33px;' value="<?= $mtodate ?>" />
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg">As On Date</label></div>

                                <div class="col-lg-3 col-sm-3 pad">
                                    <input type="date" id="frmdt" name="frmdt" class="form-control" style='height:33px;' value="<?php echo date("Y-m-d"); ?>" />
                                </div>
                            </div>


                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg">Report Type</label></div>
                                <div class="col-lg-3 col-sm-4 pad">
                                    <select name="dtype" class="form-control select2" style="height:33px;">
                                        <option value="1">Summary</option>
                                        <option value="2">Detail</option>
                                    </select>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg">Print Type</label></div>
                                <div class="col-lg-3 col-sm-4 pad">
                                    <select name="prntype" class="form-control select2" style="height:33px;">
                                        <option value="1">One Page</option>
                                        <option value="2">Common</option>
                                    </select>
                                </div>
                            </div>

                            <!-- <div class="row">
                                <div class="col-lg-3 text-right"><label class="control-label marg">More Than Days</label></div>
                                <div class="col-lg-2 col-sm-2 pad ">
                                    <input type="text" name="days"  class="form-control" style='height:33px;text-align: right' >
                                </div>
                            </div> -->

                            <div class="row">
                                <div class="row">
                                    <label class="col-sm-2 control-label marg"></label>
                                    <div class="col-sm-9">
                                        <div class="col-sm-3 align">
                                            <input type="hidden" name="hiddenval" class="form-control hiddenval" value="<?= $hgrp ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="row">
                        <div style="overflow: auto; ">
                            <table class="table-condensed" style="margin: 0 auto;">
                                <tr>
                                    <!--            <td class=" buttonform tooltip-bottom" id="sspdf" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Pdf">
                                        <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>
                                    </td>-->
                                    <td class=" buttonform tooltip-bottom" id="sexcel" style="display: <? echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Excel">
                                        <button id='excel' type='submit' name='excel' class="btn btn-pad btn-square" style="background-color:#34a853; ">
                                            <i class="fa fa-file-excel-o" style="color:#ffffff; font-size: 19px;" title="Excel"></i>
                                        </button>
                                    </td>
                                    <td class=" buttonform tooltip-bottom" id="ssubmit" style="display: <? echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="View">
                                        <?php
                                        //                                        $disp1 = $disp2 = "";
                                        //                                        if ($_GET["para"] == "R") {
                                        //                                            $disp1 = "display:none";
                                        //                                        } else {
                                        //                                            $disp2 = "display:none";
                                        //                                        }
                                        ?>
                                        <button type="button" id='printbut' formtarget="_blank" class="btn btn-pad btn-square" style="background-color:#05B2EA;display:none">
                                            <i class="fa fa-television" style="color:#ffffff"></i>
                                        </button>
                                        <button id='view' type='submit' formtarget="_blank" name='view' class="btn btn-pad btn-square" style="background-color:#05B2EA;">
                                            <i class="fa fa-television" style="color:#ffffff"></i>
                                        </button>
                                    </td>

                                    <!--            <td class=" buttonform tooltip-bottom" id="ssubmit" style="display: <? echo $savedisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="View Chart">
                                        <button id='graph' type='submit' formtarget="_blank" name='graph' class="btn btn-pad btn-square" style="background-color:red; ">
                                            <i class="fa fa-download" style="color:#ffffff"></i>
                                        </button>
                                    </td>-->
                                    <td class=" buttonform tooltip-bottom" id="scancel" style="display: <? echo $canceldisabled ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Close">
                                        <button id='cancel' type="reset" class="btn btn-pad btn-square " style="background-color:red;" onclick="window.location.href = '<?= 'default.php' ?>'">
                                            <i class="fa fa-power-off" style="color:#ffffff"></i>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </div>

                    </div>
                    <div class="modal fade" tabindex="-1" role="dialog" id="printmodal" aria-labelledby="myLargeModalLabel">
                        <div class="modal-dialog modal-lg" style="margin-top: 10%;width: 50%">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                                    <h4 class="modal-title" id="myLargeModalLabel"></h4>
                                </div>
                                <div class="modal-body" id="">
                                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                                        <table id="" class="table table-striped table-condensed table-bordered sizeTable" width="50%">
                                            <thead>
                                                <tr class="" style="background-color: #1ABC9C">

                                                    <th style="width:20%;" class="text-center"><input type="checkbox" name="checkAll" class="checkAll" style="width: 25px;height: 25px" checked></th>
                                                    <th style="width:40%">Party</th>
                                                    <!--<th style="width:10%">Bill Amount</th>-->
                                                </tr>
                                            </thead>

                                            <tbody class="tbody">

                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="modal-footer">

                                    <button id='view' type='submit' formtarget="_blank" name='view' class="btn btn-pad btn-square modview" style="background-color:#05B2EA;">
                                        <i class="fa fa-television" style="color:#ffffff"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!--//grids-->
    <!--<script type="text/javascript">
    
        $(document).ready(function(){
        $('.date').mask('00/00/0000');
                $('.time').mask('00:00:00');
                $('.date_time').mask('00/00/0000 00:00:00');
                $('.cep').mask('00000-000');
                $('.mobile').mask('0000-0000');
                $('.phone_with_ddd').mask('(00) 0000-0000');
                $('.phone_us').mask('(000) 000-0000');
                $('.mixed').mask('AAA 000-S0S');
                $('.cpf').mask('000.000.000-00', {reverse: true});
                $('.money').mask('000.000.000.000.000,00', {reverse: true});
                $('.money2').mask("#.##0,00", {reverse: true});
                $('.ip_address').mask('0ZZ.0ZZ.0ZZ.0ZZ', {
        translation: {
        'Z': {
        pattern: /[0-9]/, optional: true
        }
        }
        });
                $('.ip_address').mask('099.099.099.099');
                $('.percent').mask('##0,00%', {reverse: true});
                $('.clear-if-not-match').mask("00/00/0000", {clearIfNotMatch: true});
                $('.placeholder').mask("00/00/0000", {placeholder: "__/__/____"});
                $('.fallback').mask("00r00r0000", {
        translation: {
        'r': {
        pattern: /[\/]/,
                fallback: '/'
        },
                placeholder: "__/__/____"
        }
        });
                $('.selectonfocus').mask("00/00/0000", {selectOnFocus: true});
                );
    </script>-->
    <!--//validator js-->
    <?php
    include("includes/linksfoot.php");
    ?>
</body>

</html>