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

$formname = 'Company Setup';
$maindb = 'company';
$printfile = "company_print.php";
$file = 'company.php';
$trandbexist = 0;
$grid = '';
$keyfld = "code";
$focusfield = "compname";
$compcode = $_SESSION["comp_" . $dbname];
$zroot = $_SESSION["zdbroot"];
$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
//mysqli_select_db($conn, $zdb);
//browse($zdb);
include("includes/vouchno_generate.php");
include("includes/prev&next.php");

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

    $a = 1;
    $name = $_POST["compname"];
    $bank = $_POST["bankname"];
    $branch = $_POST["branchname"];
    $acno = $_POST["acno"];
    $ifccode = $_POST["ifccode"];
    $gstno = $_POST["gstno"];
    $panno = $_POST["panno"];
    $hoadd1 = mysqli_real_escape_string($conn, $_POST["hoadd1"]);
    $hoadd2 = mysqli_real_escape_string($conn, $_POST["hoadd2"]);
    $hoadd3 = mysqli_real_escape_string($conn, $_POST["hoadd3"]);
    $hocity = $_POST["hocity"];
    $hopin = $_POST["hopin"];
    $hocountry = $_POST["hocountry"];
    $htel = $_POST["htel"];
    $fadd1 = mysqli_real_escape_string($conn, $_POST["fadd1"]);
    $fadd2 = mysqli_real_escape_string($conn, $_POST["fadd2"]);
    $fadd3 = mysqli_real_escape_string($conn, $_POST["fadd3"]);
    $fcity = $_POST["fcity"];
    $fpin = $_POST["fpin"];
    $fcountry = $_POST["fcountry"];
    $ftel = $_POST["ftel"];
    $sadd1 = mysqli_real_escape_string($conn, $_POST["sadd1"]);
    $sadd2 = mysqli_real_escape_string($conn, $_POST["sadd2"]);
    $sadd3 = mysqli_real_escape_string($conn, $_POST["sadd3"]);
    $scity = $_POST["scity"];
    $spin = $_POST["spin"];
    $scountry = $_POST["scountry"];
    $stel = $_POST["stel"];
    $deeminv = $_POST["deeminv"];
    $tdscode = $_POST["tdscode"];
    $tcsperc = $_POST["tcsperc"];
    $tcsmin = $_POST["tcsmin"];
    $kcname = $_POST["kcname"];
    $kcadd = $_POST["kcadd"];


    ################ ONLINE BANK DETAILS ########################

    $banknameonl = $_POST["banknameonl"];
    $branchnameonl = $_POST["branchnameonl"];
    $acnonl = $_POST["acnonl"];
    $ifccodeonl = $_POST["ifccodeonl"];

    #############################################################


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



    $mvouch = $qvouch;
    mysqli_query($conn, "UPDATE `$maindb` SET `compname`='$name',`bankname`='$bank',`branchname`='$branch',
                        `acno`='$acno',`ifccode`='$ifccode',`gstno`='$gstno',panno='$panno',
                        `hoadd1`='$hoadd1', `hoadd2`='$hoadd2', `hoadd3`='$hoadd3', `hocity`='$hocity', `hopin`='$hopin',
                        `hocountry`='$hocountry', htel='$htel', `fadd1`='$fadd1', `fadd2`='$fadd2', `fadd3`='$fadd3', `fcity`='$fcity',`fpin`='$fpin',
                        `fcountry`='$fcountry', ftel='$ftel',`tdscode`='$tdscode', `tcsperc`='$tcsperc', `tcsmin`='$tcsmin',
                        `sadd1`='$sadd1', `sadd2`='$sadd2', `sadd3`='$sadd3', `scity`='$scity', `spin`='$spin', `deeminv`='$deeminv',
                        `scountry`='$scountry', ftel='$ftel', `banknameonl`='$banknameonl', `branchnameonl`='$branchnameonl', `acnonl`='$acnonl',
                        `ifccodeonl`='$ifccodeonl', `kcname`='$kcname', `kcadd`='$kcadd' WHERE code = '$compcode' ") or die(mysqli_error($conn));

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

if ($addflag != 1) {

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

    $result = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `$keyfld`='$compcode' ") or die(mysqli_error($conn));
    $get = mysqli_fetch_array($result);
}

include("includes/linkshead.php");
?>
<!--<script src="MyScript/challan.js" type="text/javascript"></script>-->
<script src="MyScript/company_search.js" type="text/javascript"></script>
<script>
    $(document).ready(function () {
        $('#hadd').hide();
        $('#hsearch').hide();
        $('#hprint').hide();
        $('#hdelete').hide();
        $('#hprevious').hide();
        $('#hnext').hide();

    });

</script>
<style>
    .tclr {
        color: red;
        font-weight: 545;
    }


</style>
</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-3 col-md-3 col-sm-3 col-xs-3 text-right pad">
                                <label class="label-control marg">Company 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="compname" value="<?php Echo ($addflag != 1) ? $get["compname"] : ""; ?>"  required>
                            </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">Bank 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 " name="bankname" value="<?php Echo ($addflag != 1) ? $get["bankname"] : ""; ?>" >
                            </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">Branch Name</label>
                            </div>
                            <div class="col-lg-6 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="branchname" value="<?php Echo ($addflag != 1) ? $get["branchname"] : ""; ?>" >
                            </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">Account No.</label>
                            </div>
                            <div class="col-lg-6 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="acno" value="<?php Echo ($addflag != 1) ? $get["acno"] : ""; ?>" >
                            </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">IFSC Code</label>
                            </div>
                            <div class="col-lg-5 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form" name="ifccode" value="<?php Echo ($addflag != 1) ? $get["ifccode"] : ""; ?>" >
                            </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">GST No.</label>
                            </div>
                            <div class="col-lg-5 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">PAN No.</label>
                            </div>
                            <div class="col-lg-5 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form " name="panno" value="<?php Echo ($addflag != 1) ? $get["panno"] : ""; ?>" >
                            </div>
                        </div>
                        
                        <br>
                        <div class="navs-tabs-customs">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Address</a></li>
<!--                                <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Factory</a></li>
                                <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Sale</a></li>-->
                            </ul>
                            <div class="tab-content">
                                <!--#################################HEAD OFFICE########################################-->
                                <div class="tab-pane active" id="tab_1">
                                    <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">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="hoadd1" value="<?php Echo ($addflag != 1) ? $get["hoadd1"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="hoadd2" value="<?php Echo ($addflag != 1) ? $get["hoadd2"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="hoadd3" value="<?php Echo ($addflag != 1) ? $get["hoadd3"] : ""; ?>" >
                                        </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">City</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="hocity" value="<?php Echo ($addflag != 1) ? $get["hocity"] : ""; ?>">
                                        </div>
                                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                            <label class="label-control marg">Pin</label>
                                        </div>
                                        <div class="col-lg-2 col-md-2 col-sm-5 col-xs-5 text-center ">
                                            <input type="text" class="form-control form" name="hopin" value="<?php Echo ($addflag != 1) ? $get["hopin"] : ""; ?>">
                                        </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">Country</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="hocountry" value="<?php Echo ($addflag != 1) ? $get["hocountry"] : ""; ?>">
                                        </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">Telephone</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="htel" value="<?php Echo ($addflag != 1) ? $get["htel"] : ""; ?>">
                                        </div>
                                    </div>
                                </div>

                                <!--#################################FACTORY########################################-->
                                <div class="tab-pane" id="tab_2">
                                    <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">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="fadd1" value="<?php Echo ($addflag != 1) ? $get["fadd1"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="fadd2" value="<?php Echo ($addflag != 1) ? $get["fadd2"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="fadd3" value="<?php Echo ($addflag != 1) ? $get["fadd3"] : ""; ?>" >
                                        </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">City</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="fcity" value="<?php Echo ($addflag != 1) ? $get["fcity"] : ""; ?>">
                                        </div>
                                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                            <label class="label-control marg">Pin</label>
                                        </div>
                                        <div class="col-lg-2 col-md-2 col-sm-5 col-xs-5 text-center ">
                                            <input type="text" class="form-control form" name="fpin" value="<?php Echo ($addflag != 1) ? $get["fpin"] : ""; ?>">
                                        </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">Country</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="fcountry" value="<?php Echo ($addflag != 1) ? $get["fcountry"] : ""; ?>">
                                        </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">Telephone</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="ftel" value="<?php Echo ($addflag != 1) ? $get["ftel"] : ""; ?>">
                                        </div>
                                    </div>
                                </div>

                                <!--#################################SALES########################################-->
                                <div class="tab-pane" id="tab_3">
                                    <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">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="sadd1" value="<?php Echo ($addflag != 1) ? $get["sadd1"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="sadd2" value="<?php Echo ($addflag != 1) ? $get["sadd2"] : ""; ?>" >
                                            <input type="text" class="form-control form" name="sadd3" value="<?php Echo ($addflag != 1) ? $get["sadd3"] : ""; ?>" >
                                        </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">City</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="scity" value="<?php Echo ($addflag != 1) ? $get["scity"] : ""; ?>">
                                        </div>
                                        <div class="col-lg-1 col-md-1 col-sm-3 col-xs-3 text-right pad">
                                            <label class="label-control marg">Pin</label>
                                        </div>
                                        <div class="col-lg-2 col-md-2 col-sm-5 col-xs-5 text-center ">
                                            <input type="text" class="form-control form" name="spin" value="<?php Echo ($addflag != 1) ? $get["spin"] : ""; ?>">
                                        </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">Country</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="scountry" value="<?php Echo ($addflag != 1) ? $get["scountry"] : ""; ?>">
                                        </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">Telephone</label>
                                        </div>
                                        <div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 pad">
                                            <input type="text" class="form-control form" name="stel" value="<?php Echo ($addflag != 1) ? $get["stel"] : ""; ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="panel-footer">
                                <? include("includes/buttons.php"); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
           <div class="col-lg-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">KC Company Details</h3>
                    </div>
                        
                    <div class="panel-body">
                        <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 tclr">Company Name</label>
                            </div>
                            <div class="col-lg-6 col-md-8 col-sm-8 col-xs-8 pad">
                                <input type="text" class="form-control form kcname" name="kcname" maxlength="30" value="<?php Echo ($addflag != 1) ? $get["kcname"] : ""; ?>" >
                            </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 tclr">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 kcadd" name="kcadd" maxlength="60" value="<?php Echo ($addflag != 1) ? $get["kcadd"] : ""; ?>" >
                            </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">
                    <input type="hidden" value="<?php Echo $file ?>" class="form-control file">

                    <div class="row">
                        <div class="col-lg-2">
                            <select class="form-control sfield">
                                <option value="1">Code</option>
                                <option value="2">Name</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">Code</option>
                                <option value="2">Name</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">
                        <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:#1ABC9C;">
                                    <th width="20%">Code</th>
                                    <th width="40%">Name</th>
                                    <th width="20%">Group Code</th>
                                    <th width="20%">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>
