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

$formname = 'SMS O/s.';
$maindb = 'accmast';
$trandb = '';
$printfile = "";
$file = 'smsosmes.php';
$trandbexist = 0;
$grid = '';
$keyfld = "id";
$keycond = "";

$admin = $_SESSION["admin_" . $dbname];
$username = $_SESSION["username_" . $dbname];
$zroot = $_SESSION["zdbroot"];
$zroot1 = substr($zroot, 0, -4);
$myear = $_SESSION[$myyear];
$fseries = $_SESSION["society_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];
$mtodate = date("Y-m-d");
mysqli_select_db($conn, $zdb);
//$result = mysqli_query($conn, "SELECT a.accode, a.name, a.mobile, a.station, a.mobile2, sum(b.amount)as balance FROM accmast a, actran b where 
//                  a.grpcode = '010' and a.mobile !='' and a.accode=b.accode and b.chqret != 'Y' GROUP BY a.accode ORDER BY a.name  ")or die(mysqli_error($conn));

$result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `active`='1' and `series` = '$fseries' and `grpcode` = '010' and mobile != '' and `active`='1' order by name") or die(mysqli_error($conn));

include("includes/linkshead.php");
?>
<style>
    input[type = checkbox]{
        width: 20px;
        height: 20px;
    }
</style>
<!--<style type="text/css">
    #table-wrapper {
        position:relative;
    }
    #table-scroll {
        height:799px;
        width:754px;
        overflow:auto;
        margin-top:20px;
    }
    #table-wrapper table {
        width:70%;

    }
    #table-wrapper table * {
        background:palegoldenrod;
        color:black;
    }
    #table-wrapper table thead th .text {
        position:absolute;   
        top:-20px;
        z-index:2;
        height:20px;
        width:45%;
        border:1px solid red;
    }
</style>-->
<script>
    $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": true,
            "info": true,
            "autoWidth": false
        });
    });
</script>
<script>
    $(document).ready(function () {
        $("#sms").keyup(function () {
            $('input[type="text"]').val(refresh());
        });
    });
</script>
<script src="assets/plugins/dataTables/js/jquery.dataTables2.js"></script>
<script src="assets/plugins/dataTables/js/dataTables.bootstrap2.js"></script>
<link rel="stylesheet" href="assets/plugins/dataTables/css/dataTables.css">

<body>
    <!-- Default box -->
    <form name="myform" id="devel-generate-content-form" action="smsos.php" method="post">
        <!-- Default box -->
        <div class="">
            <div class="col-lg-7">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                    </div>
                    <div class="panel-body">

                        <table  id="example1" class="table-bordered table-condensed table-hover table-striped" style="width:100%;height:200%;">
                            <thead style="background-color:#EFE4B0">
                                <tr style="font-size: 20px;"> 
                                    <th style='text-align: left;width:50%;'>
                                        Name
                                    </th>
                                    <th  style='text-align: left;width:30%;'>
                                        Flat No.
                                    </th>
                                    <th  style='text-align: left;width:20%;'>
                                        Mobile
                                    </th>                            
                                    <th  style='text-align: right;width:20%;'>
                                        Balance
                                    </th>
                                    <th  style='text-align: left;width:20%;'>
                                        Mark
                                    </th>

                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $i = 0;

                                while ($row = mysqli_fetch_array($result)) {

                                    $mopbal = $row["openbal"];
                                    $mprincipal = $row["prinamt"];
                                    $mopdc = $row["dc"];
                                    $maccode = $row["accode"];


                                    if ($mopdc == "D") {
                                        $mopbal = $mopbal * - 1;
                                    }


                                    $getbal = mysqli_query($conn, "SELECT SUM(amount) as amt FROM `actran` WHERE `series`='$fseries' and `accode`='$maccode' AND  date < '$mtodate'") or die(mysqli_error($conn));
                                    $getamt = mysqli_fetch_array($getbal);
                                    $amt = $getamt["amt"];
                                    $mbal = $mopbal + $amt;

                                    if ($mbal < 0) {
                                        $mdc = "DR";
                                    } else {
                                        $mdc = "CR";
                                    }

                                    $balance = abs($mbal);


//                            $balance = $bal*-1;
                                    if ($mbal < 0) {
                                        echo "<tr>";
                                        echo "<td align='left'>$row[name]</td>";
                                        echo "<td align='left'>$row[flatno]</td>";
                                        echo "<td align='left'>$row[mobile]</td>";
                                        echo "<td align='right' style='color:red'><b>$balance </b></td>";
                                        ?>
                            <td style="padding-bottom:4%">
                                        <input type="checkbox" value="<? echo $row['mobile']; ?>" id="check_list" class="chk" name="check_list[]" />
                                    </td>
                                        <!--<input name="check_list_$i" type='checkbox' id='check_list' class='chk' value='<? echo $row['mobile']; ?>'></td>";-->
                                    <?php
                                    echo "</td>";
                                    echo "</tr>";
                                    $i++;
                                }
                            }
                            ?>

                            </tbody>
                        </table>

                        <p style="padding:4px; margin: 4px;">
                            <input type="submit" name="submit" class=" btn" id="submit" value="Send" style="width:193px;height: 40px;background-color: #EFE4B0;color: black;float:right"/>
                        </p>
                    </div>
                </div>
                <input type="hidden" style="width:20%;" name="selected" id="selected" class="selected" value="0" readonly>
                <input type="hidden" name="cnt" id="cnt" value="0" disabled="disabled" style="width: 50px; background:#66FFCC; color:red; font-weight: bold; "/>


            </div>

            <!--            <div class="col-lg-6">
                            <table align="center">
                                <tr style="height:50px;"></tr>
                                <tr align="left">
            
                                    <td align="right">
                                        <b style="font-weight:900;font-size: 16px">
                                            Select / Unselect All
                                        </b> 
                                    </td>
                                    <td align="left">
            
                                        <input type="checkbox" name="Check_ctr" onchange="checkAll(this)" id="example-select-all" class="chk" value="<?php echo $row['mobile']; ?>"
                                               onClick="Check(document.myform.check_list)" style="height:25px;width: 25px;">
                                    </td>              
                                </tr>   
                                <tr align="right">
                                    <td align="right">
                                        <b style="font-weight:900;font-size: 16px" >
                                            Selected No.
                                        </b>
                                    </td>
            
                                    <td align="left">
                                        <input type="number" style="width:20%;" name="selected" id="selected" class="selected" value="0" readonly>
                                    </td>              
                                </tr>   
            
            
                                <tr align="right">
                                    <td align="right"  style='text-align:right;'>
                                        <b style="font-weight:900;font-size: 16px">
                                            Message
                                        </b>
                                    </td>
                                    <td align="left">
                                        <p style="padding:0px; margin: 0px;font-size: 20px">
                                            <textarea rows="5" cols="50" name="sms" id="sms"></textarea>
                                            maxlength="160"
                                        </p>
                                    </td>              
                                </tr>   
            
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <p style="padding:0px; margin: 0px;">
                                            <input type="text" name="cnt" id="cnt" value="0" disabled="disabled" style="width: 50px; background:#66FFCC; color:red; font-weight: bold; "/>
                                        </p>
                                    </td>              
                                </tr>
                                <tr>
                                    <td align="right">
                                        <label  style="font-weight:900;font-size: 16px">Verification No.</label>
                                    </td>
                                    <td>
                                        <p style="padding:0px; margin: 0px;">
                                            <input type="text" name="alert" id="alert" value="" style="font-weight: bold; "/>
                                        </p>
                                    </td>              
                                </tr>
                                <tr>   
            
                                    <td colspan="2" align="center">
                                        <p style="padding:4px; margin: 4px;">
                                            <input type="submit" name="submit" class=" btn" id="submit" value="Send" style="width:193px;height: 40px;background-color: #EFE4B0;color: black"/>
                                        </p>
                                    </td>
                                </tr>  
                            </table>       
                        </div>-->

    </form>
    <script type="text/javascript">
    $(function () {
        $("#sms").keypress(function () {
            var sms = $(this).val().length;
            if (sms >= 320) {
                $(this).attr("maxlength", "320");
            }
            $("#cnt").val(sms);
        });

    });
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            var $checkboxes = $('#devel-generate-content-form td input[type="checkbox"]');
            $checkboxes.change(function () {

                var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
                $('#selected').val(countCheckedCheckboxes);
            });
        });
    </script>

    <script type="text/javascript">
        var total = 0;

        $(".chk").click(function () {

            var output = $.map($('.chk:checked'), function (n, i) {
                return n.value;
                return i.value;
            }).join(',');

            //            total = $('.chk:checked').length;
            //            $("#selected").val(total);
            //            $('#selchk').VAL(countCheckedCheckboxes);
            $("#selchk").val(output);

        });

    </script>
    <script type="text/javascript">
        function checkAll(ele) {
            var checkboxes = document.getElementsByTagName('input');
            if (ele.checked) {
                for (var j = 0; j < checkboxes.length; j++) {
                    if (checkboxes[j].type == 'checkbox') {
                        checkboxes[j].checked = true;
                    }
                }
            } else {
                for (var j = 0; j < checkboxes.length; j++) {
                    console.log(j)
                    if (checkboxes[j].type == 'checkbox') {
                        checkboxes[j].checked = false;
                    }
                }
            }
        }
    </script>
    <script>
        $(document).ready(function () {

        });
    </script>

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