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

$formname = 'MEMBER';
$maindb = 'accmast';
$trandb = 'memtran';
$passdb = 'passmain';
$printfile = "member_print.php";
$file = 'member.php';
$trandbexist = 0;
$grid = '';
$keyfld = "accode";

$focusfield = "name";
$mgrpcode = '010';
$usertype = $_SESSION["usertype_" . $dbname];

//$series = $_SESSION["society_" . $dbname];
$series = 1;

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

$custcode = $_GET['custcode'];

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

//$getcomp = mysqli_query($conn, "SELECT `cono`, `compname` FROM `society` WHERE `cono`='$series' ") or die(mysqli_error($conn));
//$comp = mysqli_fetch_array($getcomp);
//$compname = $comp['compname'];
$zroot = $_SESSION["zdbroot"];
$keycond = " AND `grpcode`='010' and `series`='$series' $cond";

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
include("includes/accode_generate.php");
include("includes/prev&next.php");


if (isset($_POST["submit"])) {

    $a = 1;
    $name = mysqli_real_escape_string($conn, $_POST["name"]);
    $name2 = mysqli_real_escape_string($conn, $_POST["name2"]);
    $add1 = mysqli_real_escape_string($conn, $_POST["add1"]);
    $add2 = mysqli_real_escape_string($conn, $_POST["add2"]);
    $add3 = mysqli_real_escape_string($conn, $_POST["add3"]);
    $city = $_POST["city"];
    $pin = $_POST["pin"];
    $coun = $_POST["country"];
    $station = $_POST["station"];
    $mob = $_POST["mobile"];
    $mob2 = $_POST["mobile2"];
    $tel = $_POST["tel"];
    $gstno = $_POST["gstno"];
    $email = $_POST["email"];
    $openbal = $_POST["openbal"];
    $shop = $_POST["shop"];
    $house = $_POST["house"];
    $opendc = $_POST["opendc"];
    $username = $_POST["username"];
    $password = $_POST["password"];
    $confpass = $_POST["confpass"];
    $prinamt = $_POST["prinamt"];
    $latefee = $_POST["latefee"];
    $block = $_POST["block"];
    $wing = $_POST["wing"];
    $floor = $_POST["floor"];
    $flattype = $_POST["flattype"];
    $flatno = $_POST["flatno"];
    $consumerno = $_POST["consumerno"];
    $area = $_POST["area"];
    $unit = $_POST["unit"];
    $advance = $_POST["advance"];
    $interest = $_POST["interest"];
    $totalmaint = $_POST["totalmaint"];

    $count = $_POST["items"];

    if ($name == "") {
        $a = 0;
        browse("Name Cannot Be Empty");
        if ($addflag == 1) {
            header("location:javascript://history.go(-1)");
        } else {
            header("refresh: ; $file?mode=last");
        }
    }

    if (isset($_POST["flatno"])) {
        $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `flatno`= '$flatno'  AND accode != '$qvouch' and `series`='$series'") or die(mysqli_error($conn));
        if (mysqli_num_rows($result) > 0) {
            $a = 0;
            browse("Flat No. Already Exist");
            header("refresh: 1; $file?mode=last");
        }
    }

    if ($a == 1) {
        mysqli_query($conn, "LOCK TABLES `$maindb` WRITE,  $trandb WRITE, $zroot.`passmain` WRITE") or die(mysqli_error($conn));

        if ($addflag == 1) {

            $gen1 = mysqli_query($conn, "SELECT MAX($keyfld) AS maxcode FROM `$maindb` WHERE $keyfld !=''  LIMIT 0,1 ") or die(mysqli_error($conn));

            if (mysqli_num_rows($gen1) > 0) {
                $vvouch = mysqli_fetch_assoc($gen1);
                $increvouch = $vvouch["maxcode"] + 1;
            } else {
                $increvouch = '51';
            }
            $qvouch = $increvouch;
        }

        mysqli_query($conn, "DELETE FROM `$trandb` WHERE accode = '$qvouch' and `cono`='$series'") or die(mysqli_error($conn));
        $ctr = 0;
        for ($i = 0; $i <= $count; $i++) {
            $ctr++;
            $msrno = $_POST["srno_$i"];
            $maintype = $_POST["maintype_$i"];
            $mcode = $_POST["mcode_$i"];
            $amount = $_POST["amount_$i"];

            if (!empty($mcode)) {

                mysqli_query($conn, "INSERT INTO `$trandb`(`cono`, `accode`, `srno`, `maintype`, `amount`)
                                            VALUES('$series', '$qvouch', '$ctr', '$mcode', '$amount')") or die(mysqli_error($conn));
            }
        }

        if ($addflag == 1) {

            //Member Only Active in Add Mode as per Fairoz
            mysqli_query($conn, "INSERT INTO `$maindb`(accode, `increcode`, `name`, `add1`, `add2`, `add3`, `city`, `pin`, `station`, `country`, mobile,
                                               `mobile2`, `tel`, `email`,  `gstno`,`openbal`, `dc`, `grpcode`, `username`, `password`, 
                                               `confpass`,`series`,`passcode`,`prinamt`,`latefee`, `block`, `name2`, `house`,
                                               `wing`, `floor`, `flattype`, `flatno`, `consumerno`, `area`, `unit`, `totalmaint`,`advance`,`interest`,`mancode`,`shop`, `active`)
                                        VALUES('$qvouch', '$increvouch', '$name', '$add1', '$add2', '$add3', '$city', '$pin', '$station',
                                               '$coun', '$mob' , '$mob2' , '$tel', '$email', '$gstno','$openbal', '$opendc', '$mgrpcode',
                                               '$username', '$password', '$confpass', '$series', '$passcode','$prinamt','$latefee', '$block', '$name2', '$house',
                                               '$wing', '$floor', '$flattype', '$flatno', '$consumerno', '$area', '$unit', '$totalmaint','$advance','$interest','$flatno','$shop', '1')") or die(mysqli_error($conn));

            insmess();
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn, "UPDATE `$maindb` SET `name`='$name', `add1`='$add1', `add2`='$add2', `add3`='$add3', `city`='$city', `pin`='$pin',`name2`='$name2',
                        `station`='$station', `country`='$coun', mobile= '$mob', mobile2= '$mob2',tel='$tel',  mobile='$mob', `email`='$email',
                        `gstno`='$gstno',`openbal`='$openbal', `dc`='$opendc', `username`='$username', `password`='$password', `confpass`='$confpass',`prinamt`='$prinamt',
                        `latefee`='$latefee', `block`='$block', `house`='$house', `wing`='$wing', `floor`='$floor', `flatno`='$flatno', `consumerno`='$consumerno', `mancode`='$flatno', `area`='$area', `unit`='$unit',
                        `totalmaint`='$totalmaint', `advance`='$advance',`interest`='$interest', `shop`='$shop' where accode = '$mvouch' and `series`='$series' ") or die(mysqli_error($conn));




            updmess();
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        }

//        if ($addflag != 1) {
//            if (empty($password) && empty($email)) {
//                mysqli_query($conn, "DELETE FROM passmain WHERE `custcode` = '$mvouch' and `series` = '$series'") or die(mysqli_error($conn));
//            }
//        }
//
//        $chkpass = mysqli_query($conn, "SELECT code,user FROM $zroot.`passmain` WHERE  `custcode` = '$mvouch' and `series` = '$series'") or die(mysqli_error($conn));
//        if (mysqli_num_rows($chkpass) > 0) {
//
//            mysqli_query($conn, "UPDATE $zroot.`passmain` SET `user`='$email',`password`='$password', `member`='1'
//                        where custcode = '$mvouch' and `series`='$series'") or die(mysqli_error($conn));
//        } else {
//
//            $gen1 = mysqli_query($conn, "SELECT MAX(code) AS maxcode FROM $zroot.`passmain` WHERE code !='' LIMIT 0,1 ") or die(mysqli_error($conn));
//            if (mysqli_num_rows($gen1) > 0) {
//                $vcode = mysqli_fetch_assoc($gen1);
//                $passcode = $vcode["maxcode"] + 1;
//            } else {
//                $passcode = '1';
//            }
//
//            if (!empty($password)) {
//                mysqli_query($conn, "INSERT INTO $zroot.`passmain`(`code`, `user`, `usertype`, `series`, `custcode`, `password`, `member`)
//                                        VALUES($passcode, '$email', '3', '$series', '$mvouch', '$password', '1')") or die(mysqli_error($conn));
//            }
//        }

        mysqli_query($conn, "UNLOCK TABLES");
    }
}
if ($addflag != 1) {

    $getvouch = '';
    if ($addflag == 0) {
        $getvouch = $_GET[$keyfld];
    } else {
        $getvouch = $qvouch;
    }

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld='$getvouch' AND `grpcode`='$mgrpcode' and `series`='$series' $cond") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
    $rd = "readonly";
}

$senable = "";
$cenable = "";


if (isset($_GET["delete"])) {

    $result = mysqli_query($conn, "SELECT accode FROM `billmain` WHERE `accode`='$_GET[$keyfld]'  and `society` = '$series'") or die(mysqli_error($conn));
    $num = mysqli_num_rows($result);
    if ($num > 0) {
        browse('BILL GENERATED FOR THIS MEMBER');
        header("refresh: 1; $file?mode=last");
    } else {
        delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
        delete($zdb, "$trandb", "$keyfld", $_GET[$keyfld], "$file?mode=last");

//        mysqli_query($conn, "Delete From $zroot.`passmain`  WHERE `custcode` = '$_GET[$keyfld]' and series = '$series' and usertype=3") or die(mysqli_error($conn));
    }
}

include("includes/linkshead.php");
?>
<script>
    $(document).ready(function () {
        $("body").on('blur keyup', '.cpass', checkPass);
        $("body").on('blur', '.cpass', checkReturn);
        $("body").on('keyup blur focus', '.amount', calmaint);
//        $("body").on('click', '.CMail', sendMail);
        $("body").on('blur', '#email', getUser);
        $("body").on('keyup change', '.prinamt,.latefee,.interest,.advance', calopenbal);
        $("body").on('blur change', '.phase,.wing,.house', getflatno);
        $("body").off('click').on("click", '.remove', remove);
        $("body").on("change blur", '.maintype', chkrepeat);

        function chkrepeat() {
            var tr = $(this).closest('tr'),
                    maintype = tr.find('.mcode').val(),
                    srno = tr.find('.srno').val();
            $(".tbody").find('tr').each(function () {
                var row = $(this),
                        lmaintype = row.find('.mcode').val(),
                        loopsrno = row.find('.srno').val();

                if (lmaintype == maintype && loopsrno != srno) {
                    alert('MAINTENANCE CANNOT BE SAME !!!');
                    tr.find('.maintype').val('').trigger("change");
                    return false;
                }
            });
        }

        function getflatno() {
            var phase = $(".phase").val(),
                    wing = $(".wing").val(),
                    house = $(".house").val(),
                    flatno = $(".flatno").val();

            var alpha = '' ;
            if (phase > 0) {
                if (phase == 1) {
                    alpha = 'A' ;
                }
                if (phase == 2) {
                    alpha = 'B' ;
                }
                if (phase == 3) {
                    alpha = 'C' ;
                }
                if (phase == 4) {
                    alpha = 'D' ;
                }
            }
            
           
            
            flatno = alpha + wing + '-' + house;
                    
            $('.flatno').val(flatno);
        }
        
        function calopenbal() {
            var prinamt = $(".prinamt").val(),
                    interest = $(".interest").val(),
                    advance = $(".advance").val(),
//                    latefee = $(".latefee").val(),
                    openbal = parseFloat(prinamt) + parseFloat(interest) - parseFloat(advance),
                    openamt = Math.abs(openbal);
            $(".openbal").val(openamt);

            if (latefee > 0) {
                $('.advance').attr("readonly", true);
                $('.advance').val(0);
            } else {
                $('.advance').removeAttr("readonly");
            }

            if (openbal > 0) {
                $('.dc').val('D');
            } else {
                $('.dc').val('C');
            }
        }

        function checkPass() {
            var pass = $(".password").val(),
                    cpass = $(".cpass").val();
            var check = "";
            if (pass != cpass) {
                var check = "<label class='label-control' style='color:red'>Password Not Matched</label>";
            } else {
                var check = "<label class='label-control' style='color:green'>Password Matched</label>";
            }

            $(".checkdiv").html(check);
        }

        function getUser() {
            var email = $("#email").val();

            $(".username").val(email);
        }

        function checkReturn() {
            var pass = $(".password").val(),
                    cpass = $(".cpass").val();
            if (pass != cpass) {
                alert("Password Did Not Match");
                $(".cpass").val("");
                $(".pass").val("");
            }
        }

        function calmaint() {
            var tr = $(this).closest("tr"),
                    val = 0;
            $(".amount").each(function () {
                if (!isNaN(this.value) && this.value.length != 0) {
                    val += parseFloat(this.value);
                }
            });
            $(".totalbill").val(val);
        }

        $('.CMail').click(function () {
            var user = $(".username").val(), pass = $(".password").val(), email = $("#email").val();
            $.post('customer_SendMail.php', {user: user, pass: pass, email: email}, function (data) {
                if (data == "success") {
                    alert("Username & Password Are Send To The Member");
                }
            });
        });

        $('#addnew').click(function () {
            AddRows();
        });

        function remove() {
            $(this).closest("tr").remove();
        }

        function AddRows() {
            var ctr = $('#items').val();

            var hide_check = "";
            if ($("#del_all").prop("checked")) {
                hide_check = 0;
            } else {
                hide_check = 1;
            }
            var detail = ".detailpart_" + ctr;
            var detail = ".fetchpart_" + ctr;
            $.post('member_add.php', {ctr: ctr, hide: hide_check}, function (data) {
                $(data).appendTo('.tbody');
                ctr++;
                $('#items').val(ctr);
                $(detail).select2();
            });
        }
    });

</script>
<style>
    .tab{
        border: 1px solid #6082BF;
        color: black;
        background-color:  white;
    }
</style>
<script src="MyScript/member_search.js" type="text/javascript"></script>
</head>
<body>
    <!--    <div id="preloader" class="col-lg-12 text-center">
            <h3 class="text-center">Loading</h3>
            <div id="status">&nbsp;</div>
        </div>-->
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-6 pad">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><?php Echo $formname; ?></h3>
                        <div class="actions pull-right">
                            <!--<i class="fa fa-chevron-down"></i>-->
                            <!--<i class="fa fa-times"></i>-->
                        </div>
                    </div>
                    <div class="panel-body">
                        <div style="border: 2px solid #e1eff8;background-color: #cccccc">
                            <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">Phase</label>
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                                    <input type="number" maxlength="2" class="form-control form focusfield phase" id="phase" name="block" value="<?php Echo ($addflag != 1) ? $get["block"] : "0"; ?>" autofocus <?= $rd ?>>
                                </div>
                                <div class="col-lg-2 col-md-2 col-sm-4 col-xs-4 text-right pad">
                                    <label class="label-control marg">Building No.</label>
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                                    <input type="text" maxlength="2" class="form-control form wing" id="wing" name="wing" value="<?php Echo ($addflag != 1) ? $get["wing"] : ""; ?>" <?= $rd ?>>
                                </div>
                                <div class="col-lg-2 col-md-2 col-sm-4 col-xs-4 text-right pad">
                                    <label class="label-control marg">House No.</label>
                                </div>
                                <div class="col-lg-1 col-md-1 col-sm-2 col-xs-2 pad">
                                    <input type="text" maxlength="4" class="form-control form house" id="house" name="house" value="<?php Echo ($addflag != 1) ? $get["house"] : ""; ?>" <?= $rd ?>>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4 text-right pad">
                                <label class="label-control marg" style="color:#FF0000">Flat No.</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" class="form-control form flatno" id="flatno" name="flatno"  value="<?php Echo ($addflag != 1) ? $get["flatno"] : ""; ?>" readonly=""required <?= $rd ?>>
                            </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">Name</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control text-uppercase form " name="name" value="<?php Echo ($addflag != 1) ? $get["name"] : ""; ?>" required>
                                <input type="text" class="form-control text-uppercase form " name="name2" value="<?php Echo ($addflag != 1) ? $get["name2"] : ""; ?>">
                            </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">Floor</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text" class="form-control form" name="floor" value="<?php Echo ($addflag != 1) ? $get["floor"] : ""; ?>" >
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right pad">
                                <label class="label-control marg">Flat Type</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 pad">
                                <input type="text"  class="form-control form" name="flattype" value="<?php Echo ($addflag != 1) ? $get["flattype"] : ""; ?>" >
                            </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">Area</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2  pad">
                                <input type="text" class="form-control form text-right" name="area" value="<?php Echo ($addflag != 1) ? $get["area"] : ""; ?>" required>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right pad">
                                <label class="label-control marg">Unit</label>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <select name="unit" class="form-control form">
                                    <option></option>
                                    <option value="F" <?php
                                    if ($get['unit'] == 'F') {
                                        echo 'selected="selected"';
                                    }
                                    ?>>Sq. Ft.</option>
                                    <option value="M"  <?php
                                    if ($get['unit'] == 'M') {
                                        echo 'selected="selected"';
                                    }
                                    ?>>Sq. Mtr.</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">Mobile 1</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control form mobile " name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : ""; ?>" required>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right pad">
                                <label class="label-control marg">Mobile 2</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control form " name="mobile2" value="<?php Echo ($addflag != 1) ? $get["mobile2"] : ""; ?>" >
                            </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">PAN No. / GST No.</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="gstno" value="<?php Echo ($addflag != 1) ? $get["gstno"] : ""; ?>" >
                            </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">Consumer No.</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" class="form-control form " name="consumerno" value="<?php Echo ($addflag != 1) ? $get["consumerno"] : ""; ?>" >
                            </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">Principle Amount</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" size="40" name="prinamt" class="form-control form text-right prinamt" value="<?php echo ($addflag != 1) ? $get['prinamt'] : "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">Late Fees</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" size="40" name="interest" class="form-control form text-right interest" value="<?php echo ($addflag != 1) ? $get['interest'] : "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">Advance</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" size="40" name="advance" class="form-control form text-right advance" value="<?php echo ($addflag != 1) ? $get['advance'] : "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">Opening Balance</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text" size="40" name="openbal" class="form-control form numeric text-right openbal" value="<?php echo ($addflag != 1) ? $get['openbal'] : "0"; ?>" readonly>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" size="1" maxlength="1" id="opendc" name="opendc" class="form-control form dc" value="<?php echo ($addflag != 1) ? $get['dc'] : ""; ?>" >
                            </div>
                            <div class="col-lg-2 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Shop</label>
                            </div>

                            <div class="col-lg-3 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="checkbox" id="shop" name="shop" class="form-control form shop"
                                       value="1"<?php
                                       if ($get['shop'] == '1') {
                                           echo 'checked="checked"';
                                       }
                                       ?>>
                            </div>

                        </div>
                    </div>
                    <div class="panel-footer">
                        <?php
                        if ($usertype != 3) {
                            include("includes/buttons.php");
                        }
                        ?>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 pad">
                <!--                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <h3 class="panel-title">MEMBER RIGHTS</h3>
                                        <div class="actions pull-right">
                                            <i class="fa fa-chevron-down"></i>
                                            <i class="fa fa-times"></i>
                                        </div>
                                    </div>
                                    <div class="panel-body" style="background-color: #cccccc">
                                        <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">Email</label>
                                            </div>
                                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                                <input type="text" class="form-control form" id="email" name="email" value="<?php Echo ($addflag != 1) ? $get["email"] : ""; ?>" >
                                            </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">Password</label>
                                            </div>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                <input type="password"  name="password" class="form-control form password" value="<?php echo ($addflag != 1) ? $get['password'] : ""; ?>"/>
                                            </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">Confirm Password</label>
                                            </div>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                                <input type="password"  name="confpass" class="form-control form cpass" value="<?php echo ($addflag != 1) ? $get['confpass'] : ""; ?>"/>
                                            </div>
                
                                            <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pad text-right">
                <?php if ($usertype == 1) { ?>
                                                            <button type="button" class="btn btn-primary CMail" style="margin-right: 20px"><i class="fa fa-envelope"></i> Send Mail To Customer</button>
                <? } ?>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 text-right pad"></div>
                                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad checkdiv"></div>
                                        </div>
                                    </div>
                                </div>-->
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">MAINTENANCE DETAILS</h3>
                        <div class="actions pull-right">
                        </div>
                    </div>
                    <div class="panel-body">
                        <table class="table table-bordered" width="40%">
                            <tr class="tab mySearchTr">
                                <td width="3%" class="tab"></td>
                                <td width="5%" class='tab numeric'>Sr.</td>
                                <td width="20%" class="tab">Maintenance</td>
                                <td width="10%" class='tab text-right'>Amount</td>
                            </tr>
                            <tbody class="tbody">
                                <?php
                                if ($addflag != 1) {
                                    $ctr = 0;
                                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `accode` = '$qvouch' and `cono`='$series' ORDER BY `srno`")or die(mysqli_error($conn));
                                    while ($tran = mysqli_fetch_array($gettran)) {
                                        $getmain = mysqli_query($conn, "SELECT * FROM `accmast` where `type`='I' and `series`='$series' and `accode`='$tran[maintype]'") or die(mysqli_error($conn));
                                        $gmain = mysqli_fetch_array($getmain);

                                        Echo "<tr>";
                                        Echo "<td><i class='fa fa-close form remove' style='display:none;'></i></td>";
                                        Echo "<td><input type='text' class='form-control form numeric srno' name='srno_$ctr' value='$tran[srno]'></td>";
                                        Echo "<td><input type='text' class='form-control form  maintype' name='maintype_$ctr' value='$gmain[name]' readonly>
                                             <input type='hidden' class='form-control form mcode' name='mcode_$ctr' value='$tran[maintype]' >    
                                             </td>";
                                        Echo "<td><input type='text' class='form-control form text-right numeric amount' name='amount_$ctr' value='$tran[amount]'></td>";
                                        Echo "</tr>";
                                        $ctr++;
                                    }
                                } else {
                                    $getrec = mysqli_query($conn, "SELECT * FROM $zroot.`soctran` where `cono`='$series' order by srno") or die(mysqli_error($conn));
                                    $mctr = 1;
                                    $pctr = 0;
                                    while ($get = mysqli_fetch_array($getrec)) {
                                        $gtmatt = mysqli_query($conn, "SELECT accode,name FROM `accmast` where `type`='I' and `series`='$series' and `accode` = '$get[maintype]' ")or die(mysqli_error($conn));
                                        $matt = mysqli_fetch_array($gtmatt);
                                        Echo "<tr>";
                                        Echo "<td><i class='fa fa-close form remove'></i></td>";
                                        Echo "<td><input type='text' class='form-control form numeric srno' name='srno_$pctr' value='$mctr'></td>";
                                        Echo "<td><input type='text' class='form-control form  maintype' name='maintype_$pctr' value='$matt[name]' readonly>
                                            <input type='hidden' class='form-control form mcode' name='mcode_$pctr' value='$get[maintype]'>
                                              </td>";
                                        Echo "<td><input type='text' class='form-control form numeric text-right amount' name='amount_$pctr' value='0'></td>";
                                        Echo "</tr>";
                                        $mctr++;
                                        $pctr++;
                                    }
                                }
                                ?>
                            </tbody>
                        </table>
                        <div class="col-lg-12 pad">
                            <!--<input type="button" style="height: 30px; width: 30px; padding: 0px" id="addnew" class="btn btn-success btn-lg form" accode="addnew2" value="+" />-->
                            <button type="button" class="btn btn-success btn-square form"  id="addnew">
                                <i class="fa fa-plus" style="color:#ffffff" data-toggle='tooltip' title='Add Row'></i>    
                            </button>
                            <input type="hidden" id="items" name="items" value="<?php echo ($addflag != 1) ? $ctr : $pctr; ?>" />  
                        </div>
                        <div class="col-lg-12 text-right pad">
                            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 text-right pad">
                                <label class="label-control marg">Total</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 pad">
                                <input type="text"  class="form form-control text-right totalbill" name="totalmaint"  value="<?php echo ($addflag != 1) ? $get['totalmaint'] : ""; ?>" readonly>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div class="modal fade bs-example-modal-lg searchModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title" id="myLargeModalLabel">Search <? Echo $formname; ?></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Flat No.</option>
                                <option value="2">Name</option>
                                <option value="3">Phase</option>
                                <option value="4">Building</option>
                                <option value="5">Floor</option>
                                <option value="6">Mobile</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control soperator">
                                <option value="">Type of Search</option>
                                <option value="%">Like</option>
                                <option value="=">Exactly</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control sortBy">
                                <option value="">Sort By</option>
                                <option value="1">Flat No.</option>
                                <option value="2">Name</option>
                                <option value="3">Phase</option>
                                <option value="4">Building</option>
                                <option value="5">Floor</option>
                                <option value="6">Mobile</option>
                            </select> 
                        </div>
                        <div class="col-lg-2">
                            <select class="form-control orderAs">
                                <option value="desc">Desc</option>
                                <option value="asc">Asc</option>
                            </select>
                        </div>
                        <div class="col-lg-2">
                            <input type="text" value="" class="form-control ssearch" placeholder="Search Here">
                        </div>
                        <div class="col-lg-2">
                            <input type="button" style="color: black; background-color:#F17B25;" class="btn btn-primary sload" value="Search" >
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                        <!--<img src="images/search.gif" alt="loading">-->       
                    </div>
                    <div class="col-lg-12 snoRecord text-center">
                        <h3>NO RECORDS FOUND</h3>
                    </div>
                    <div class="table-responsive" style="max-height: 400px;overflow: auto;">
                        <table id="" class="table table-striped table-condensed table-bordered" width="100%">
                            <thead>
                                <tr style="background-color:#EFE4B0;">
                                    <th style="color: black;" width="15%">Flat No.</th>
                                    <th style="color: black;" width="30%">Name</th>
                                    <th style="color: black;" width="15%">Phase</th>
                                    <th style="color: black;" width="15%">Building</th>
                                    <th style="color: black;" width="15%">Floor</th>
                                    <th style="color: black;" width="15%">Mobile</th>
                                    <th style="color: black;" width="10%">Action</th>

                                </tr>
                            </thead>
                            <tbody class="sTbody">
                            </tbody>
                        </table>
                    </div>
                    <div class="row">
                        <div class="col-xs-12 text-right search-action-bar">
                            <input type="button"  class="btn btn-primary sprev" style="color: black; background-color:#EFE4B0;" value="Previous">
                            <input type="button"  class="btn btn-primary snext" style="color: black; background-color:#EFE4B0;" value="Next">
                        </div>
                    </div>

                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
