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

$formname = 'Pers. Expense Party';
$maindb = 'accmast';
$printfile = "narrmast_print.php";
$file = 'narrmast.php';

$keyfld = "accode";
$focusfield = "name";

$keycond = " AND `grpcode`='015' and `type` != 'P'";
$mgrpcode = '015';

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

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

    $a = 1;

    $name = $_POST["name"];
    $add1 = $_POST["add1"];
    $add2 = $_POST["add2"];
    $add3 = $_POST["add3"];
    $area = $_POST["area"];
    $pin = $_POST["pin"];
    $mobile = $_POST["mobile"];
    $tel = $_POST["tel"];
    $email = $_POST["email"];
    $owner = $_POST["owner"];
    $openbal = $_POST["openbal"];
    $dc = $_POST["dc"];

    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["name"])) {
//        $result = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE `name`= '$name'") or die(mysqli_error($conn));
//        if (mysqli_num_rows($result) > 0) {
//            $a = 0;
//            browse("Name Already Exist");
//            header("refresh: 1; $file?mode=last");
//        }
//    }

    if ($a == 1) {
        if ($addflag == 1) {
            mysqli_query($conn,"INSERT INTO `$maindb`(`$keyfld`, grpcode,  `name`, init, `add1`, `add2`, `add3`,    `area`, `pin`, `mobile`, `tel`,     `email`, `owner`, `openbal`, `dc` )
                                     VALUES($qvouch, '015', '$name', 'EPP', '$add1', '$add2', '$add3',   '$area', '$pin', '$mobile', '$tel', '$email', '$owner', '$openbal', '$dc')") or die(mysqli_error($conn));
            insmess();
//            $mvouch = $_GET["vouchno"];
            $mvouch = $qvouch;
            header("refresh: 1; $file?$keyfld=$mvouch&mode=edit");
        } else {
            $mvouch = $qvouch;
            mysqli_query($conn,"UPDATE `$maindb` SET `name`='$name', init='EPP', grpcode='015', `add1` = '$add1',  `add2`='$add2', `add3`='$add3', `area`='$area', `pin`='$pin', `mobile`='$mobile',`tel`='$tel', 
                                            `email`='$email', `owner`='$owner', `openbal`='$openbal', `dc`='$dc'  where `$keyfld` = '$qvouch' ") or die(mysqli_error($conn));

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

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='015'") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}

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


if (isset($_GET["delete"])) {
    delete($zdb, "$maindb", "$keyfld", $_GET[$keyfld], "$file?mode=last");
}

include("includes/linkshead.php");
?>
<script src="MyScript/narrmast_search.js" type="text/javascript"> </script>
<script>
    $(document).ready(function () {
        $("body").on("keyup ", ".dc", validation);


        function validation() {
            var dc = $(".dc").val();
            var actdc = dc.trim();

            if (actdc.length > 0) {
                if (actdc == 'C' || actdc == 'D') {
                } else {
                    alert("Only D or C should be entered");
                    $(".openbal").focus();
                    $(".dc").val("");
                }
            }
        }
    });



</script>
</head>
<body>
    <form action='' method='POST'>
        <!-- Default box -->
        <div class="row">
            <div class="col-lg-6">
                <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 class="row">
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="hidden" class="form-control form " name="code" value="<?php Echo ($addflag != 1) ? $get["$keyfld"] : "$qvouch"; ?>"  readonly="">
                            </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">Party Name</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control  form focusfield" name="name" value="<?php Echo ($addflag != 1) ? $get["name"] : ""; ?>" required>
                            </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">Address</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="add1" value="<?php Echo ($addflag != 1) ? $get["add1"] : ""; ?>" >
                                <input type="text" class="form-control  form " name="add2" value="<?php Echo ($addflag != 1) ? $get["add2"] : ""; ?>" >
                                <input type="text" class="form-control  form " name="add3" value="<?php Echo ($addflag != 1) ? $get["add3"] : ""; ?>" >
                            </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">Area</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="area" value="<?php Echo ($addflag != 1) ? $get["area"] : ""; ?>" >
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-4 col-xs-4 text-right pad">
                                <label class="label-control marg">Pin</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="pin" value="<?php Echo ($addflag != 1) ? $get["pin"] : ""; ?>" >
                            </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">Mobile</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="mobile" value="<?php Echo ($addflag != 1) ? $get["mobile"] : ""; ?>" >
                            </div>

                            <div class="col-lg-2 col-md-32 col-sm-4 col-xs-4 text-right pad">
                                <label class="label-control marg">Tel</label>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="tel" value="<?php Echo ($addflag != 1) ? $get["tel"] : ""; ?>" >
                            </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">Owner</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="owner" value="<?php Echo ($addflag != 1) ? $get["owner"] : ""; ?>" >
                            </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">Email</label>
                            </div>
                            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="email" class="form-control  form " 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">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  text-right form openbal" value="<?php echo ($addflag != 1) ? $get['openbal'] : ""; ?>"/>
                            </div>
                            <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 pad">
                                <input type="text" size="1" id="opendc" name="dc"  class="form-control form dc" maxlength="2"   value="<?php echo ($addflag != 1) ? $get['dc'] : " "; ?>"/>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer">
                        <?php include("includes/buttons.php"); ?>
                    </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 <?= $formname; ?></h4>
                </div>
                <div class="modal-body">
<!--                    <input type="hidden" value="<?php // Echo $zseries  ?>" class="form-control series">
                    <input type="hidden" value="<?php // Echo $get[code];  ?>" class="form-control vouchno">
                    <input type="hidden" value="<?php // Echo $file  ?>" class="form-control file">
                    <input type="hidden" value="<?php // Echo $para  ?>" class="form-control para">-->
                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Name</option>
                                <option value="2">Address</option>
                                <option value="3">Area</option>
                                <option value="4">Pin</option>
                                <option value="5">Mobile</option>
                                <option value="6">Tel</option>
                                <option value="7">Owner</option>
                                <option value="8">Email</option>
                                <option value="9">Opening Balance</option>
                                <!--<option value="10">Action</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">Name</option>
                                <option value="2">Address</option>
                                <option value="3">Area</option>
                                <option value="4">Pin</option>
                                <option value="5">Mobile</option>
                                <option value="6">Tel</option>
                                <option value="7">Owner</option>
                                <option value="8">Email</option>
                                <option value="9">Opening Balance</option>
                                <!--<option value="10">Action</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" class="btn btn-primary sload" value="Search" >
                        </div>
                    </div>
                    <div class="col-lg-12 sloader text-center">
                    </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 class="mySearchTr" style="background-color: #64CCFC">
                                    <th style="width:20%">Name</th>
                                    <th style="width:35%">Address</th>
                                    <th style="width:10%">Area</th>
                                    <th style="width:10%">Pin</th>
                                    <th style="width:10%">Mobile</th>
                                    <th style="width:10%">Tel</th>
                                    <th style="width:10%">Owner</th>
                                    <th style="width:10%">Email</th>
                                    <th style="width:10%">Opening Balance</th>
                                    <th style="width:5%">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" value="Previous">
                            <input type="button"  class="btn btn-primary snext" value="Next">
                        </div>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>
    </div>
    <?php include("includes/linksfoot.php"); ?>
</body>
</html>
