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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$curdate = date("Y-m-d");

$olddate = date('Y-m-d', strtotime($curdate . ' - 1 months'));

mysqli_query($conn, "Create temporary table slmn SELECT a.*,b.date FROM `accmast` a, actran b WHERE a.grpcode = '010' and LENGTH(a.mobile) = 10 and 
                    a.accode=b.accode group by a.accode") or die(mysqli_error($conn));

//print table($result);
$result = mysqli_query($conn, "SELECT *,date_format(`date`,'%d-%m-%Y') as mydt FROM `slmn` WHERE accode not in 
                              (select accode from actran where date >= '$olddate' and date <= '$curdate') ORDER BY name") or die(mysqli_error($conn));
include("includes/linkshead.php");
include("searchrow.php");
?>


<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>
<!--<fieldset style="border: 1px solid #CDCDCD; padding: 8px; padding-bottom:0px; margin: 8px; width:50%; height:50%;">-->
    <!--<legend><strong>SMS Address</strong></legend>-->
<!--<strong>SMS To Customer</strong>-->
<form name="myform" id="devel-generate-content-form" action="smswhatmulti.php" method="post">
    <!--<div style="float:left;">-->
<!--            <table cellpadding="4" cellspacing="4" border="0" width="100% height='50%' ">-->
    <!--         <div class="form-item form-type-checkbox form-item-node-types-webform">
                        <input type="checkbox" id="edit-node-types-webform" name="node_types[webform]"
                        value="webform" class="form-checkbox" />
                        <input type="text" id="edit-count-checked-checkboxes" name="count-checked-checkboxes" value="0" size="60" maxlength="50" class="form-text required" />-->
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">

            <div id="" style='float:left;width:60%;height:200%;'>
                <div id="table-scroll" class="body">
                    <table  class="table-bordered table-condensed table-striped myTable" style="width:100%;" >
                        <thead style="background-color:cadetblue">
                            <tr style="font-size: 20px;"> 
                                <th style='text-align: left;width:50%;'>
                                    Party
                                </th>
<!--                                <th  style='text-align: left;width:30%;'>
                                    Station
                                </th>-->
                                <th  style='text-align: left;width:20%;'>
                                    Mobile
                                </th>
                                <th  style='text-align: left;width:20%;'>
                                    Last Bill Date
                                </th>
                                <th  style='text-align: left;width:10%;'>
                                    Mark
                                </th>
                                <!--<th><input name="selectall" id="selectall" value="1" type="checkbox" /></th>-->
                            </tr>
                        </thead>
                        <tr class='filters noPrint'>
                            <th class='filter-container'><input type ='text' style="color:black" class='filter' name='party' placeholder='party' data-col='party'> </th>
                            <th class='filter-container'><input type ='text' style="color:black" class='filter' name='mobile' placeholder='mobile' data-col='mobile' ></th>
<!--                            <th class='filter-container'><input type ='text' style="color:black" class='filter' name='amount' placeholder='amount' data-col='amount' ></th>-->
                            <!--<th class='filter-container'><input type ='text' style="color:black" class='filter' name='amount' placeholder='amount' data-col='amount' ></th>-->
                        </tr>
                        <tbody>
                            <?php
                            $i = 0;
                            while ($row = mysqli_fetch_array($result)) {
                                $maccode = $row['accode'];

                                $getbal = mysqli_query($conn, "SELECT date_format(`date`,'%d-%m-%Y') as mydt FROM `actran` WHERE
                                                               accode='$maccode' and (source != 'CR' or source != 'BR') order by date DESC limit 1 ") or die(mysqli_error($conn));
                                $getamt1 = mysqli_fetch_array($getbal);
                                if (mysqli_num_rows($getbal) > 0) {
                                    $dt = $getamt1["mydt"];
                                } else {
                                    $dt = "No bill this Year";
                                }

                                $party = $row['name'];


                                echo "<tr style='font-weight:900;font-size:16px;'>";
                                echo "<td style='font-size:16px;' align='left'>$party</td>";
//                                echo "<td align='left'>$row[station]</td>";
                                echo "<td style='font-size:16px;' align='left'>$row[mobile]</td>";
                                echo "<td style='font-size:16px;' align='left'>$dt</td>";
                                ?>
                            <td>
                                <input type="checkbox" value="<? echo $row['mobile']; ?>" id="check_list" class="chk" name="check_list[]" style="height:20px;width:20px"/>
                            </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>

                </div>
            </div>
        </div>
        <div class="col-lg-1 col-md-1 col-sm-12 col-xs-12">
        </div>

        <div  class="col-lg-5 col-md-5 col-sm-12 col-xs-12">
            <h4><b style="color:red">No Sale Last 30 Days</b></h4>

            <!--<div style='width:40%;'>-->

            <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;">
                            <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: cadetblue;color: white"/>
                        </p>
                    </td>
                </tr>  
            </table>                
        </div> 
        <!--</div>-->
    </div>

    <div style="clear:both"></div>
</form>
<!--</fieldset>-->
<script type="text/javascript">
    $(function () {
        $("body").on("keyup", "#sms", countWords);
//        $("#sms").keypress(function () {
        function countWords() {
            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>
<?php // include("includes/linksfoot.php");
?>
</body>
</html> 