@{
    ViewBag.Title = "About";
}

@{
    ViewBag.Title = "SalesInvoice";
}



<style>
    .tot {
        color: #004D40;
        margin-top: 1%;
        font-weight: 600;
        font-size: 120%;
    }

    .btn:hover {
        opacity: 1;
    }

    #panel1 {
        display: none;
    }

    /*.modal-xl {
        max-width: 100%;
        margin-left: 10%;
        margin-right: 3%;
    }*/

    #productpopupdiv {
        max-width: 100%;
        max-height: 35%;
        margin-left: 10%;
        margin-right: 3%;
        margin-top: 0px;
    }

    #td1 {
        width: 75%;
    }

    #td2 {
        width: 25%;
    }

    .footertable tr {
        border: 1px solid #BABFC7;
        height: 50px;
    }

    .headertable tr {
        border: 1px solid #BABFC7;
        height: 40px;
    }

    .modal-xl {
        max-width: 100%;
        margin-left: 10%;
        margin-right: 3%;
    }

    .modal-llg {
        max-width: 80%;
        margin-left: 14%;
        margin-right: 1%;
    }

    .overlay1 {
        position: fixed;
        width: 100%;
        height: 100%;
        /*top:40%;
        left: 50%;*/
        right: 0;
        bottom: 0;
        z-index: 2000;
        cursor: pointer;
    }

    #tblproductdetails tr td {
        /*border: none;
        font-weight: 500;*/
    }

    body {
        overflow-x: hidden;
    }
</style>

<style>
    .message {
        /*background: #181818;
        color: #FFF;*/
        position: fixed;
        top: -550px;
        left: 0;
        width: 100%;
        height: 250px;
        padding: 20px;
        transition: top 1000ms cubic-bezier(0.17, 0.04, 0.03, 0.94);
        overflow: hidden;
        box-sizing: border-box;
    }

        .message h1 {
            /*color: #FFF;*/
        }

    #toggle:checked ~ .message {
        top: 0;
        z-index: 1001;
    }

    #toggle {
        position: absolute;
        appearance: none;
        cursor: pointer;
        left: -100%;
        top: -100%;
    }

        #toggle + label {
            position: absolute;
            cursor: pointer;
            padding: 10px;
            background: #26ae90;
            width: 100px;
            border-radius: 3px;
            padding: 8px 10px;
            color: #FFF;
            line-height: 20px;
            font-size: 12px;
            text-align: center;
            -webkit-font-smoothing: antialiased;
            cursor: pointer;
            margin: 20px 50px;
            transition: all 3000ms ease;
        }

            #toggle + label:after {
                content: "Open";
            }

    .container {
        transition: margin 1000ms cubic-bezier(0.17, 0.04, 0.03, 0.94);
        padding: 5em 3em;
    }



    #toggle:checked ~ .container {
        margin-top: 250px;
    }

    #toggle:checked + label {
        background: #dd6149;
    }

        #toggle:checked + label:after {
            content: "Close";
        }
</style>


<link rel="stylesheet" type="text/css" href="../../../app-assets/vendors/css/tables/jsgrid/jsgrid-theme.min.css">
<link rel="stylesheet" type="text/css" href="../../../app-assets/vendors/css/tables/jsgrid/jsgrid.min.css">
<link rel="stylesheet" type="text/css" href="../app-assets/vendors/css/hopscotch.css">
<script type="text/javascript" src="~/Scripts/Excelmport/xlsx.full.min.js"></script>
<script type="text/javascript" src="~/Scripts/Excelmport/excelimport.js"></script>
<script src="~/app-assets/data/table2excel.js" type="text/javascript"></script>

<div class="myData" data-x="M54" />

<div id="Entry" style="margin-top:-20px;">

    <section class="grid-row-label">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header" style="border-bottom:1px solid #e6e6e6">
                        <h3 class="card-title mb-0" style="float:left"> Sales Invoice</h3>

                        <h3 class="col-md-3 text-right" id="gndtotal" style="float:right;color:red;font-weight:500">0.00 </h3>

                        <h3 class="text-md-right" id="fc" style="float:right;opacity:0;color:red;font-weight:500">fc </h3>

                    </div>
                    <div class="card-content collapse show">
                        <div class="card-body" style="margin-top:-60px">

                            <form action="#">
                                <div class="form-body">
                                    <hr style="margin-top:30px" />

                                    <div class="row" style="background-color:#E0F3F4 ;margin-left:3px;width:100%;height:228px;margin-top:-20px;">

                                        <div class="col-md-12" style="margin-top:-5px;">
                                            <br />
                                            <div class="form-group">

                                                <div class="row" id="slnorow">

                                                    <label class="col-lg-1" style="margin-top:5px">Invoice No</label>
                                                    <div class="col-lg-11">
                                                        <div class="row">
                                                            <div class="col-md-1">

                                                                <select id="txtBillseriesId" name="priority" class="form-control"></select>
                                                            </div>
                                                            @*<div class="hopscotch-bubble animated tour-demo-tour" id="tour1" style="position: absolute; top: 65px; left:187px;display:none">

                                                                    <div class="hopscotch-bubble-container" style="width: 280px; padding: 10px;">
                                                                        <div class="hopscotch-bubble-content">
                                                                            <h3 class="hopscotch-title">Search Invoice Number Here.</h3>
                                                                            <div class="hopscotch-content"></div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="hopscotch-bubble-arrow-container hopscotch-arrow up">
                                                                        <div class="hopscotch-bubble-arrow-border"></div>
                                                                        <div class="hopscotch-bubble-arrow"></div>
                                                                    </div>
                                                                </div>*@

                                                            @*===div for copy===*@
                                                            <div class="col-md-2 input-group" id="copybill" style="display:none">
                                                                <div class="input-group-prepend">
                                                                    <span class="input-group-btn" title="Previous">
                                                                        <button type="button" disabled="" id="btnprvs" onclick="GetBillPrevousornext(-1)" class="btn btn-outline-primary" style="height:85%"><i class="ft-chevron-left"></i></button>
                                                                    </span>
                                                                </div>
                                                                <input type="text" class="form-control" id="txtBillSlNocopy" style="height:85%;background-color:white" onkeypress="isNumberInt(event,this)" placeholder="Search Invoice">
                                                                <div class="input-group-append">
                                                                    <span class="input-group-btn" title="Next">
                                                                        <button type="button" id="btnnxt" disabled="" onclick="GetBillPrevousornext(1)" class="btn btn-outline-primary" style="height:85%"> <i class="ft-chevron-right"></i></button>
                                                                    </span>
                                                                </div>
                                                            </div>
                                                            @*===========*@

                                                            @*=====div for page load======*@
                                                            <div class="col-md-2" id="bill">
                                                                <input type="text" class="form-control" disabled="" id="txtBillSlNo" onkeypress="isNumberInt(event,this)">
                                                            </div>

                                                            <input type="text" class="form-control" id="txtBlSlNo" style="display:none">
                                                            @*===========*@
                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px">Pay Type<span class="danger">*</span></label>
                                                            <div class="col-md-2">
                                                                <select id="select_payterms" name="priority" class="form-control" onchange="loadcust()">
                                                                    <option value="0" disabled>--Select--</option>
                                                                    <option value="1">Cash</option>
                                                                    <option value="2">Credit</option>
                                                                    <option value="3">Card</option>
                                                                </select>
                                                            </div>


                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px;">Transfer</label>

                                                            <div class="col-md-2 input-group">
                                                                <select id="select_transfer" class="form-control">
                                                                    <option value="0">--Select--</option>
                                                                    <option value="1">Quotation</option>
                                                                    <option value="2">Sales Order</option>
                                                                    <option value="3">Enquiry</option>
                                                                    <option value="4">Recall Old</option>
                                                                    <option value="5">Delivery Order</option>
                                                                </select>
                                                                <div class="input-group-append">
                                                                    <button class="btn btn-outline-primary" onclick="Transfer()" id="btntrnsfr" type="button">⇆</button>
                                                                </div>
                                                            </div>



                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px">TRN Number</label>
                                                            <div class="col-md-2">
                                                                <input type="text" id="txtlpono" class="form-control" onkeyup="$('#Trnno').val($('#txtlpono').val())">
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>


                                                <div class="row" style="margin-top:-5px">
                                                    <label class="col-lg-1" style="margin-top:8px">Customer<span class="danger">*</span></label>
                                                    <div class="col-lg-11">
                                                        <div class="row">
                                                            <div class="col-md-3 input-group">
                                                                <input type="text" id="txtcustomer" class="form-control" style="height:90%" onkeyup="changetoupper(this.id), checkcustomerempty(event)">
                                                                <input type="text" id="txtCustId" style="display:none" value="0" />
                                                                <div class="input-group-append" id="addVisa">
                                                                    <button class="btn btn-outline-primary" onclick="window.open('../master/CustomerMaster')" id="btncst" type="button" style="height:90%">+</button>
                                                                </div>
                                                            </div>
                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px">Date</label>
                                                            <div class="col-md-2">
                                                                <input type="text" id="txtivdate" class="form-control" name="IVDate" onchange="getdate()">
                                                            </div>
                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px">Terms</label>

                                                            <div class="col-md-2 input-group">
                                                                <select id="select_terms" class="form-control"></select>

                                                                <div class="input-group-append">
                                                                    <button class="btn btn-outline-primary" onclick="Addpopupwindow(5)" id="btnterms" type="button">+</button>
                                                                </div>
                                                            </div>



                                                            <label class="col-lg-1 text-lg-right" style="margin-top:10px">Due Date</label>
                                                            <div class="col-md-2">
                                                                <input type="text" disabled="" id="txtduedate" class="form-control" name="duedate" style="background-color:white;">
                                                            </div>
                                                        </div>
                                                    </div>

                                                </div>


                                                <div class="row">

                                                    <div class="col-md-12">


                                                        <div class="row" style="margin-top:-10px">
                                                            <label class="col-lg-1" style="margin-top:30px">Delivery Instructions</label>

                                                            <div class="col-lg-11">
                                                                <div class="row">
                                                                    <div class="col-md-3">
                                                                        <textarea id="txtaddress" class="form-control" style="position:absolute;width:92%; height:178%;white-space:normal" name="Address"></textarea>
                                                                    </div>

                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">Location<span class="danger">*</span></label>
                                                                    <div class="col-md-2 input-group">
                                                                        <select id="select_locn" name="priority" class="form-control"></select>
                                                                        <div class="input-group-append">
                                                                            <button class="btn btn-outline-primary" onclick="Addpopupwindow(3)" id="btnlocn" type="button">+</button>
                                                                        </div>
                                                                    </div>

                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">SalesMan<span class="danger">*</span></label>


                                                                    <div class="col-md-2 input-group">
                                                                        <select id="select_salesman" name="priority" class="form-control"></select>
                                                                        <div class="input-group-append">
                                                                            <button class="btn btn-outline-primary" onclick="Addpopupwindow(4)" id="btnsales" type="button">+</button>
                                                                        </div>
                                                                    </div>

                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">Supply To<span class="danger">*</span></label>
                                                                    <div class="col-md-2 input-group">
                                                                        <select id="select_place" class="form-control"></select>
                                                                        <div class="input-group-append">
                                                                            <button class="btn btn-outline-primary" onclick="Addpopupwindow(2)" id="btnsply" type="button">+</button>
                                                                        </div>
                                                                    </div>


                                                                </div>
                                                            </div>
                                                        </div>


                                                    </div>

                                                </div>


                                                <div class="row" style="margin-top:-35px">
                                                    <div class="col-md-12">
                                                        <div class="row">
                                                            <label class="col-lg-1"></label>

                                                            <div class="col-lg-11">
                                                                <div class="row">
                                                                    <div class="col-md-3">

                                                                    </div>

                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">Currency<span class="danger">*</span></label>

                                                                    <div class="col-md-2 input-group">
                                                                        <select id="select_crncy" class="form-control"></select>
                                                                        <div class="input-group-append">
                                                                            <button class="btn btn-outline-primary" onclick="Addpopupwindow(1)" id="btncrncy" type="button">+</button>
                                                                        </div>
                                                                    </div>

                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">Rate</label>
                                                                    <div class="col-md-2">

                                                                        <input type="text" id="txtcrncyrate" class="form-control" onkeypress="isNumber(event,this)">

                                                                    </div>
                                                                    <label class="col-lg-1 text-lg-right" style="margin-top:10px">Job No</label>
                                                                    <div class="col-md-2">

                                                                        <input type="text" id="select_jobno" onkeyup="checkjobempty()" class="form-control">
                                                                        <input type="text" id="ProjectJobId" value="0" style="display:none">
                                                                    </div>

                                                                </div>
                                                            </div>
                                                        </div>


                                                    </div>
                                                </div>


                                            </div>
                                        </div>
                                    </div>

                                    <hr style="margin-top:3px" />
                                    <div class="px-0">
                                        <div class="row" style="margin-top:-15px;margin-left:3px">
                                            <div id="popupdesc" style="display:none;" onclick="closewarningdesc()">
                                                <div id="toast-container" class="toast-container toast-middle-left" style="margin-top:-3%;">
                                                    <div class="toast alert bg-warning mb-5" aria-live="assertive" style="width:110%">
                                                        <div class="toast-message" id="descpopup"></div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="row" style="height:26px;">

                                                    <div class="col-md-2">
                                                        <div class="form-group">
                                                            <label>Product<span class="danger">*</span></label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-2">
                                                        <div class="form-group">
                                                            <label>Location<span class="danger">*</span></label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Unit</label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Quantity<span class="danger">*</span></label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Rate<span class="danger">*</span></label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Discount</label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Tax Group</label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Tax %</label>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <label>Amount</label>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="row">
                                                    <div class="col-md-2 input-group" id="dd">
                                                        <input type="text" id="txtproduct0" class="form-control" onkeyup="checkpdcttextempty(event)" onkeydown="Focusnextgrid(event, 'p', 0)" aria-describedby="btnpdct" onblur="productpopuprefresh()">
                                                        <input type="text" id="ProductDesc0" style="display:none" />
                                                        <input type="text" id="PrdtId0" value="0" style="display:none" />
                                                        <input type="text" id="TransPrdtId0" value="0" style="display:none" />
                                                        <input type="text" id="LPCost" value="0" style="display:none" />
                                                        <input type="text" id="AvgCost0" value="0" style="display:none" />
                                                        <input type="text" id="Sumtotqty" value="0" style="display:none" />
                                                        <input type="text" id="Custlastsellingprice" value="0" style="display:none" />
                                                        <input type="text" id="LineAvgCost0" value="0" style="display:none">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-outline-primary" onclick="window.open('../master/ItemMaster')" id="btnpdct" type="button" style="height:63%">+</button>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-2">
                                                        <div class="form-group">
                                                            <select id="select_location0" class="form-control" onkeydown="Focusnextgrid(event, 'l', 0)" onchange="GetBin(0,$('#PrdtId0').val(),0)"></select>
                                                            <input type="text" id="txtlcn" style="display:none">
                                                        </div>
                                                    </div>


                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <select id="select_unit0" class="form-control" name="Units" onkeydown="Focusnextgrid(event, 'u', 0)"></select>
                                                            <input type="text" id="txtunit" style="display:none" />
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <input type="text" id="txtquantity0" name="prdaddqty" class="form-control" onkeypress="isNumberInt(event, this)" maxlength="8" onkeyup="checkqty(0),checkpricegroup(0),amountcalculation(0)" onkeydown="Focusnextgrid(event, 'q', 0)">
                                                            <input type="text" id="txtstocktotloseqty0" value="0" style="display:none">


                                                        </div>
                                                    </div>


                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <input type="text" id="txtrate0" class="form-control" name="Rates" onkeypress="isNumber(event, this)" onkeyup="amountcalculation(0)" onkeydown="Focusnextgrid(event, 'r', 0)">
                                                            <input type="text" id="txtfcrate0" style="display:none">
                                                            <input type="text" id="LastSellingPrice" style="display:none">

                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <input type="text" id="txtdiscount0" class="form-control" onkeypress="isNumber(event,this)" onkeyup="amountcalculation(0)" onkeydown="Focusnextgrid(event, 'd', 0)">
                                                            <input type="text" id="txtfcdiscount0" style="display:none">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <select id="select_tax0" class="form-control" name="Tax" onchange="ChangeTax(0,this)" onkeydown="Focusnextgrid(event, 't', 0)"></select>
                                                            <input type="text" id="txttaxableamnt0" class="form-control" style="display:none">
                                                            <input type="text" id="txtfctaxableamnt0" style="display:none">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">
                                                            <input type="text" id="txttaxpercent0" class="form-control" name="Taxpercent" disabled="">
                                                            <input type="text" id="txttaxamnt0" class="form-control" style="display:none">
                                                            <input type="text" id="txtfctaxamnt0" style="display:none">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <input type="text" id="txtamnt0" class="form-control" disabled="">
                                                            <input type="text" id="txtfcamnt0" style="display:none">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-1">
                                                        <div class="form-group">

                                                            <button type="button" id="btnadd" onclick="productaddconfirm()" onkeydown="Focusnextgrid(event, 'b', 0)" class="btn btn-outline-primary" style="height:40px;width:100px">+Add</button>
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>

                                    </div>
                                </div>
                                <div class="px-2">
                                    <div id="customView" class="jsgrid" style="position: relative; height: auto; width: 100%; border:solid 1px;border-color:#e9e9e9;margin-top:-28px;overflow-x: auto;overflow-y: hidden;margin-bottom:-10px;">
                                        <div class="jsgrid-grid-header jsgrid-header-scrollbar" style="width: 2050px;">
                                            <table class="jsgrid-table" id="tblsalesinvoiceheader">
                                                <tr class="jsgrid-header-row">
                                                    <th class="jsgrid-header-cell jsgrid-control-field jsgrid-align-center" id="editheader" style="width: 15px;"><i class="icon-trash"></i></th>
                                                    <th class="jsgrid-header-cell jsgrid-control-field jsgrid-align-center" id="editcancelheader" style="width: 15px;display:none;margin-top:5px"></th>
                                                    <th class="jsgrid-header-cell jsgrid-align-right jsgrid-header-sortable" style="width: 15px;">Sl No</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-right jsgrid-header-sortable" style="width: 40px;">Code</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-right jsgrid-header-sortable" style="width: 110px;">Description</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Unit</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-right jsgrid-header-sortable" style="width: 40px;">Location</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Quantity</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Rate</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Discount</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 40px;">Taxable Amount</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 38px;">Tax</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 22px;">Tax%</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Tax Amount</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: 30px;">Amount</th>
                                                    <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable ShowAverageCost" style="width: 30px;display:none">Avg Cost</th>
                                                </tr>
                                            </table>
                                        </div>
                                        <div id="proddiv" class="" style="position: relative; overflow-x: auto;overflow-y: scroll; height:280px; width: 2050px;border-bottom:1px solid;border-bottom-color:#e9e9e9">
                                            <table class="jsgrid-table" id="tblsalesinvoice"></table>
                                        </div>


                                    </div>

                                </div>

                                <br />
                                <div class="px-3" style="border-top:1px solid #BABFC7;border-bottom:1px solid #BABFC7;height:185px;background-color:#E0F3F4;">
                                    <table>
                                        <tr>
                                            <td width="25%">
                                                <div id="TaxSplit">
                                                    <div id="transsplitdiv" class="jsgrid" style="overflow:auto;height:170px;width:100%;top:-15px;margin-left:-15px">

                                                        <label class="tot" style="">Products : </label>
                                                        <input type="text" class="tot" id="TotalProducts" style="border:none;width:20%;background-color:#E0F3F4;font-size:120%;" autocomplete="off" disabled value="0">
                                                        <label class="tot">Quantity : </label>
                                                        <input type="text" class="tot" id="TotalPdtQty" style="border:none;width:20%;background-color:#E0F3F4;font-size:120%;" autocomplete="off" disabled value="0">

                                                        <table class="headertable" id="tbltaxsplit" style="border:1px solid #BABFC7;background-color:white;">
                                                            <tr>
                                                                <th class="text-center" style="font-weight:500;width:30%;border:1px solid #BABFC7;height:50px"><b>Tax Group</b></th>
                                                                <th class="text-center" style="font-weight:500;width:40%;border:1px solid #BABFC7;height:50px"><b>Taxable Amount</b></th>
                                                                <th class="text-center" style="font-weight:500;width:40%;border:1px solid #BABFC7;height:50px"><b>Tax Amount</b></th>
                                                            </tr>
                                                        </table>
                                                    </div>
                                                </div>
                                            </td>
                                            <td width="43%">

                                                <div id="" class="jsgrid text-lg-right" style="left:5px;height:200px; overflow: auto;width:100%;overflow:hidden">
                                                    <table class="headertable" id="" style="background-color:white;">
                                                        <tr>
                                                            <td class="text-center rndof" style="display:none">
                                                                <b>Round Off</b>
                                                                <div class="custom-control custom-checkbox" style="float:right">
                                                                    <input type="checkbox" class="custom-control-input" id="roundoffstatus" onchange="roundoffcalc()" checked="">
                                                                    <label class="custom-control-label" for="roundoffstatus"></label>
                                                                </div>
                                                            </td>
                                                            <td class="text-center" style="border-left:1px solid #BABFC7;"><b>Discount</b></td>
                                                            <td class="text-center" style="border-left:1px solid #BABFC7;"><b>Discount%</b></td>
                                                            <td class="text-center" style="border-left:1px solid #BABFC7;"><b>Tot. Discount</b></td>
                                                            <td class="text-center" style="border-left:1px solid #BABFC7;"><b>Total Taxable</b></td>
                                                            <td class="text-center" style="border-left:1px solid #BABFC7;"><b>Total Tax</b></td>

                                                        </tr>
                                                        <tr>
                                                            <td class="rndof" style="display:none">
                                                                <input type="text" id="TotRoundOff" disabled="" style="font-weight:bold;text-align:center;border:none;" value="0.00" class="form-control">
                                                            </td>
                                                            <td style="border-left:1px solid #BABFC7;">
                                                                <input type="text" id="disc" class="form-control" style="font-weight:bold;text-align:center;border:none;" value="0.00" onclick="discclr(0)" onblur="discclr(1)" onkeypress="isNumber(event, this)" onkeyup="CalcDiscountSplitTax1(),roundoffcalc();">
                                                                <input type="text" id="fcdisc" class="form-control" style="display:none">
                                                            </td>
                                                            <td style="border-left:1px solid #BABFC7;">
                                                                <input type="text" id="Discountpercent" disabled="" style="font-weight:bold;text-align:center;border:none;" class="form-control">
                                                            </td>
                                                            <td style="border-left:1px solid #BABFC7;">
                                                                <input type="text" id="TotalDiscount" class="form-control" style="border:none;font-weight:bold;text-align:center;" disabled value="0.00">
                                                                <input type="text" id="FcTotalDiscount" style="display:none">
                                                            </td>
                                                            <td style="border-left:1px solid #BABFC7;">
                                                                <input type="hidden" id="HiddenTotal" value="0.00" />
                                                                <input type="text" id="TotalTaxable" class="form-control" style="border:none;font-weight:bold;text-align:center;" disabled value="0.00">
                                                                <input type="text" id="FcTotalTaxable" style="display:none">
                                                            </td>

                                                            <td style="border-left:1px solid #BABFC7;">
                                                                <input type="text" id="TotalTax" class="form-control" style="border:none;font-weight:bold;text-align:center;" disabled value="0.00">
                                                                <input type="text" id="FcTotalTax" style="display:none">

                                                                <input type="text" id="GrandTotal" style="display:none">
                                                                <input type="text" id="FcGrandTotal" style="display:none">
                                                                <input type="text" id="TotalAvgCost" style="display:none">
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="3" id="msgdiv">
                                                                @*<div class="form-group">*@
                                                                <textarea id="txtmsg" rows="4" class="form-control" name="notes" style="width:100%;resize:none;overflow:hidden;border:none;font-weight:bold;" placeholder="Remarks"></textarea>
                                                                @*</div>*@
                                                            </td>
                                                            <td class="text-center" style="font-weight:500;border-left:1px solid #BABFC7;">
                                                                @*<div class="form-group" style="font-weight:500">*@
                                                                Advance :
                                                                @*</div>*@
                                                            </td>
                                                            <td colspan="1" style="border-left:1px solid #BABFC7;">
                                                                @*<div class="form-group">*@

                                                                <input type="text" id="CashAdvance" style="border:none;font-weight:bold;text-align:center;" class="form-control" onkeypress="isNumber(event, this)" onkeyup="maxcheck()" value="0.00">
                                                                @*</div>*@
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </td>
                                            <td width="35%">
                                                <div class="text-right" style="margin-top:-14%">
                                                    <button type="button" style="width:120px" id="btnsubmit" class="btn btn-primary btn-min-width mr-1 mb-1"><u>S</u>ave <i class="fa fa-check-square-o"></i></button>
                                                    <button type="button" style="width:106px;" id="btnview" onclick="GetRows(1)" class="btn btn-primary btn-min-width mr-1 mb-1" autocomplete="off">View <i class="ft-eye"></i></button>
                                                    <button type="button" style="width:120px" id="btnlist" onclick="GetRows(0)" class="btn btn-primary btn-min-width mr-1 mb-1">Copy <i class="ft-align-justify"></i></button>
                                                    <button style="display:none;width:120px" type="button" id="btnprint" onclick="PrintthisBill()" class="btn btn-primary btn-min-width mr-1 mb-1">Print <i class="ft-printer"></i></button>
                                                    <button type="button" style="width:120px" id="btnnew" onclick="formrefreshconfirm()" class="btn btn-primary btn-min-width mr-1 mb-1">New <i class="ft-refresh-cw position-right"></i></button>
                                                    <button style="display:none;width:120px" type="button" id="btnsaveedit" onclick="UpdateSales()" class="btn btn-secondary btn-min-width mr-1 mb-1">Update<i class="fa fa-check-square-o"></i></button>
                                                    <button style="display:none;width:120px" type="button" id="btndelete" class="btn btn-danger btn-min-width mr-1 mb-1">Delete<i class="fa fa-times"></i></button>
                                                    <button style="display:none;width:106px" type="button" id="btnedit" onclick="$('#OTPDiv').show(), $('#txtotp,#otpremarks').prop('disabled', false), $('#txtotp').focus()" class="btn btn-secondary btn-min-width mr-1 mb-1">Edit<i class="fa ft-edit"></i></button>
                                                    <button style="display:none;width:100px" type="button" id="btnwrk" onclick="billdetails($('#txtBillSlNocopy').val(), $('#txtBillseriesId').val(), ERPDeptId)" class="btn btn-secondary btn-min-width mr-1 mb-1">Work<i class="fa ft-wind"></i></button>
                                                    <button style="display:none;width:120px" type="button" id="btncustomprint" onclick="confirmprint()" class="btn btn-secondary btn-min-width mr-1 mb-1">Custom <i class="ft-printer"></i></button>
                                                    <input type="file" id="fileUpload" style="width:238px;display:none;" onchange="Upload()" class="btn gradient-back-to-earth btn-min-width mr-1 mb-1 white" />
                                                    @*<input type="button" id="upload" style="width:120px;display:none;" value="Upload" onclick="Upload()" class="btn gradient-back-to-earth btn-min-width mr-1 mb-1 white" />*@
                                                    <button id="upload" type="button" style="width:120px;display:none;" value="Upload" onclick="Upload()" class="btn gradient-back-to-earth  mr-1 mb-1 btn-sm white"><i class="fa fa-upload"></i></button>
                                                    <input type="button" id="btnExporttoExcel" style="display:none;" value="Export To Excel" class="btn gradient-back-to-earth btn-min-width mr-1 mb-1 white" />
                                                </div>
                                            </td>

                                        </tr>
                                    </table>
                                </div>
                                <br />
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>

<div style="margin-bottom:3%" class="row col-md-12 white">
    <h6 class="col-md-1" style="font-size:medium;text-align:left;font-weight:500">Save : Alt+S</h6>
    <h6 class="col-md-1" style="font-size:medium;text-align:left;font-weight:500">Copy : Alt+C</h6>
    <h6 class="col-md-1" style="font-size:medium;text-align:left;font-weight:500">New  : Alt+N</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500">Close Popups  : Esc</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;margin-left:-2%">Multiple Product List : F2</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;">Item Mapping : F3</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;margin-left:0%">Last Sales Transactions : F7</h6>

    <h6 class="col-md-3" style="font-size:medium;text-align:left;font-weight:500;">Last Purchase Transactions : F8</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;margin-left:-4%">All Transactions : F9</h6>
    <h6 class="col-md-3" style="font-size:medium;text-align:left;font-weight:500;margin-left:-3%">Focus To Product Table : Alt+G</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;margin-left:-3%">Order Bouncing : Alt+B</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;">Substitute Items : Alt+5</h6>
    <h6 class="col-md-2" style="font-size:medium;text-align:left;font-weight:500;">Previous Data : Alt+P</h6>

</div>

<div class="container" style="display:none">


    <h1>Pure CSS3 Slide Down Toggle Demo</h1>
    <h2> Click the Open button to see hidden mesage.</h2>

</div>

<input type="checkbox" name="toggle" id="toggle" style="display:none" />

<label for="toggle" style="display:none"></label>

@*<div class="message" style="width:93%;margin-left:5%;height:18.2%;background-color:#009da0;">
        <div class="row col-md-12" style="height:50px">
            <div class="modal-title col-md-2" id="prodheader" style="font-weight:600;color:white;font-size:larger;"></div>

            <div class="col-md-1" id="PopUpDetail1" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail2" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail3" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-1" id="PopUpDetail4" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail5" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail6" style="font-weight:400;text-align:center;color:white;">

            </div>
            <div class="col-md-1">
                <button type="button" class="close" onclick="hidepopup(1)">
                    <span>×</span>
                </button>
            </div>
        </div>

        <section id="productdiv" style="display:none;height:100px;">
            <div class="row">
                <div class="col-sm-12">
                    <div class="" style="height:135px;">
                        <div class="" style="overflow:scroll;height:300px;width:100%;overflow:auto;background-color:white;color:black">
                            <table class="table table-responsive-md-md text-center" id="tblproductdetails" style="top:-10px;"></table>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>*@




<div id="productpdiv" style="display:none;border-radius: 25px;">
    <div id="toast-containerinfo" class="toast-container toast-top-half-width" style="position:absolute; top:0; right:0%;opacity:100">

        <div class="toast-primary" style="height:180px;margin-top:70px;font-weight:500;text-align:center;opacity:100;width:100%" id="infomessage">
            @*<h5 class="modal-title" id="prodheader"></h5>*@
            <button type="button" class="close" onclick="productpopuprefresh()" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">×</span>
            </button>
            <section id="productdiv" style="display:none;height:25%;">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="card-body">
                            <input type="hidden" id="LPCost" value="0" />
                            <input type="hidden" id="AvgCost" value="0" />
                            <input type="hidden" id="Sumtotqty" value="0" />
                            <input type="hidden" id="LastSellingPrice" value="0" />
                            <div class="card-block" style="height:115px;width:100%;">
                                <table class="table table-responsive-md-md text-center" id="tblproductdetails"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </section>



        </div>

    </div>
</div>
<div class="" id="PopUpDetailbin" style="display:none">

</div>

@*<div class="message" style="width:98%;margin-left:2%;height:19%;background-color:#009da0;z-index:100">
        <div class="row col-md-12" style="height:30px">
            <div class="modal-title col-md-2" id="prodheader" style="font-weight:600;color:white;font-size:larger;"></div>

            <div class="col-md-1 ShowAverageCost" id="PopUpDetail1" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail2" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail3" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-1" id="PopUpDetail4" style="font-weight:400;text-align:center;color:white;"></div>
            <div class="col-md-2" id="PopUpDetail5" style="font-weight:400;text-align:center;color:white;font-weight:600;color:white;font-size:larger"></div>
            <div class="col-md-2" id="PopUpDetail6" style="font-weight:400;text-align:right;color:white; ">

            </div>
            <div class="" id="PopUpDetailbin" style="display:none">

            </div>

            <div class="col-md-1" style="display:none">
                <button type="button" class="close" onclick="hidepopup(1)">
                    <span>×</span>
                </button>
            </div>
        </div>

        <section id="productdiv" style="display:none;height:130px;overflow-y:hidden;overflow-x:hidden">
            <div class="row">
                <div class="col-sm-12">
                    <div class="" style="height:135px;">
                        <div class="" style="overflow:scroll;height:300px;width:100%;overflow:auto;background-color:white;color:black">
                            <table class="table table-responsive-md-md text-center" id="tblproductdetails" style="top:-10px;"></table>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-12">
                    <div class="" style="height:135px;background-color:#009da0">
                    </div>
                </div>
            </div>



        </section>

    </div>*@

<div id="MonthwisePurchase" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="jobheader" style="padding-right: 17px;background:rgba(0,0,0,0.5); display: block; display:none;">
    <div class="modal-dialog modal-lg" role="document" style="margin-top:100px;margin-left:250px">
        <div class="modal-content" style="width:180%;">
            <div class="modal-header bg-primary white">
                <h4 class="modal-title" id="MonthwisePurchaseheader"></h4>


                <button type="button" class="close" onclick="MonthwisePurchasepopuprefresh()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>


            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <section id="MonthwisePurchasediv" style="display:none;">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <div id="PurchaseDetails">
                                                <h5 style="margin-left:20px">Purchase Details</h5>
                                                <div class="card-block">
                                                    <table class="table table-responsive-md-md text-center table-bordered table-striped" id="tblMonthwisePurchase" style="font-size:small">
                                                        <tr>
                                                            <th>Year</th>
                                                            <th>January</th>
                                                            <th>February</th>
                                                            <th>March</th>
                                                            <th>April</th>
                                                            <th>May</th>
                                                            <th>June</th>
                                                            <th>July</th>
                                                            <th>August</th>
                                                            <th>September</th>
                                                            <th>October</th>
                                                            <th>November</th>
                                                            <th>December</th>
                                                            <th>Total</th>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </div>
                                            <div id="SalesDetails">
                                                <h5 style="margin-left:20px">Sales Details</h5>
                                                <div class="card-block">
                                                    <table class="table table-responsive-md-md text-center table-bordered table-striped" id="tblMonthwiseSales" style="font-size:small">
                                                        <tr>
                                                            <th>Year</th>
                                                            <th>January</th>
                                                            <th>February</th>
                                                            <th>March</th>
                                                            <th>April</th>
                                                            <th>May</th>
                                                            <th>June</th>
                                                            <th>July</th>
                                                            <th>August</th>
                                                            <th>September</th>
                                                            <th>October</th>
                                                            <th>November</th>
                                                            <th>December</th>
                                                            <th>Total</th>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

@*<div id="productpopupdiv" class="modal fade text-left show message" tabindex="-1" role="dialog" aria-labelledby="prodheader" style="display:none;margin-left:-1%;margin-top:55px;height:260px;">
        <div class="modal-dialog modal-xl" role="document" >
            <div class="modal-content" style="width:100%;">
                <div class="modal-header" style="background-color:#E0F3F4;height:80px;">

                    <div class="row col-md-12" style="">
                        <div class="modal-title col-md-2" id="prodheader" style="font-weight:600;color:#006F73;font-size:larger;"></div>

                        <div class="col-md-2 font-medium-3" id="PopUpDetail1" style="font-weight:600;font-size:larger;text-align:center;color:#FF3D00;"></div>
                        <div class="col-md-2 font-medium-3" id="PopUpDetail2" style="font-weight:600;font-size:large;text-align:center;color:#FF3D00;"></div>
                        <div class="col-md-2 font-medium-3" id="PopUpDetail3" style="font-weight:600;font-size:large;text-align:center;color:#FF3D00;"></div>
                        <div class="col-md-2 font-medium-3" id="PopUpDetail4" style="font-weight:600;font-size:large;text-align:center;color:#FF3D00;"></div>
                        <div class="col-md-2 font-medium-3" id="PopUpDetail5" style="font-weight:600;font-size:large;text-align:center;color:#FF3D00;"></div>
                    </div>
                    <button type="button" class="close" onclick="productpopuprefresh()" style="height:2px">
                        <span>×</span>
                    </button>
                </div>
                <section id="productdiv" style="display:none;height:50px;margin-top:-5px;">
                    <div class="row" >
                        <div class="col-sm-12" >
                            <div class="card card-body" style="margin-top:-10px;height:135px;">
                                <div class="card-block" style="overflow:scroll;height:115px;width:100%;overflow:auto;margin-top:-20px;">
                                    <table class="table table-responsive-md-md text-center" id="tblproductdetails" style="top:-10px;"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </div>
    </div>*@


<script type="text/javascript" src="../Projectscript/SalesInvoice.js"></script>
<script type="text/javascript" src="~/ProjectScript/Windowsprint.js"></script>


<script src="~/Scripts/Autocomplete/jquery-ui.js"></script>


<script>
    function Upload() {
        if (copyflag == 0)
        {
            //Reference the FileUpload element.
            var fileUpload = document.getElementById("fileUpload");

            //Validate whether File is valid Excel file.
            var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.xls|.xlsx)$/;
            if (regex.test(fileUpload.value.toLowerCase())) {
                if (typeof (FileReader) != "undefined") {
                    var reader = new FileReader();

                    //For Browsers other than IE.
                    if (reader.readAsBinaryString) {
                        reader.onload = function (e) {
                            ProcessExcel(e.target.result);
                        };
                        reader.readAsBinaryString(fileUpload.files[0]);
                    } else {
                        //For IE Browser.
                        reader.onload = function (e) {
                            var data = "";
                            var bytes = new Uint8Array(e.target.result);
                            for (var i = 0; i < bytes.byteLength; i++) {
                                data += String.fromCharCode(bytes[i]);
                            }
                            ProcessExcel(data);
                        };
                        reader.readAsArrayBuffer(fileUpload.files[0]);
                    }

                } else {
                    warningshow("This browser does not support HTML5.");
                }
            } else {
                warningshow("Please upload a valid Excel file.");
            }
        }



    };




    function ProcessExcel(data) {
        var a = 0; b = 0; c = 0;
        //Read the Excel File data.
        var workbook = XLSX.read(data, {
            type: 'binary'
        });

        //Fetch the name of First Sheet.
        var firstSheet = workbook.SheetNames[0];

        //Read all rows from First Sheet into an JSON array.
        var excelRows = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[firstSheet]);



        for (var k = 0; k < excelRows.length; k++) {
            if (excelRows[k]["Product"] == '' || excelRows[k]["Product"] == undefined || excelRows[k]["Product"] == '')
                {
                    a = 1;
                    break;
                }
            if (excelRows[k]["Quantity"] == 0 || excelRows[k]["Quantity"] == undefined || excelRows[k]["Quantity"] == '') {
                    b = 1;
                    break;
                }
            if (excelRows[k]["Rate"] == 0 || excelRows[k]["Rate"] == undefined || excelRows[k]["Rate"] == '') {
                    c = 1;
                    break;
                }
              }




        if (a != 0) {
            warningshow("Please Enter Code of all Items");
        }
        else if (b != 0) {
            warningshow("Please Enter Quantity for all Items");
        }
        else if (c != 0) {
            warningshow("Please Enter Rate for all Items");
        }
        else {

            //Add the data rows from Excel file.

            var sl = 0;
            $('#tblAlert tr').remove();
            var Prod1 = "<tr class='jsgrid-row'><td colspan=4><h2 style='color:#FF586B'>Create new Items Before Billing!</h2></td></tr>" +
                                "<tr class='jsgrid-row' style='color:#607D8B'><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>ProductCode</th><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>Description</th></tr>";
            $('#tblAlert').append(Prod1);


            var la = 1;
            var oArray = new Array();
            for (var j = 0; j <= excelRows.length; j++) {

                if (j < excelRows.length) {
                    var Product = ''; Description = ''; Unit = ''; Location = ''; Quantity = ''; Rate = ''; Discount = ''; Taxable = ''; Tax = ''; TaxAmount = ''; Amount = ''; AvgCost = '';
                    if (excelRows[j]["Product"] == undefined) { Product = '' } else { Product = excelRows[j]["Product"] }
                    if (excelRows[j]["Description"] == undefined) { Description = '' } else { Description = excelRows[j]["Description"] }
                    if (excelRows[j]["Unit"] == undefined) { Unit = '' } else { Unit = excelRows[j]["Unit"] }
                    if (excelRows[j]["Location"] == undefined) { Location = '' } else { Location = excelRows[j]["Location"] }
                    if (excelRows[j]["Quantity"] == undefined) { Quantity = '' } else { Quantity = excelRows[j]["Quantity"] }
                    if (excelRows[j]["Rate"] == undefined) { Rate = '' } else { Rate = excelRows[j]["Rate"] }
                    if (excelRows[j]["Discount"] == undefined) { Discount = '' } else { Discount = excelRows[j]["Discount"] }
                    if (excelRows[j]["Taxable"] == undefined) { Taxable = '' } else { Taxable = excelRows[j]["Taxable"] }
                    if (excelRows[j]["Tax"] == undefined) { Tax = '' } else { Tax = excelRows[j]["Tax"] }
                    if (excelRows[j]["TaxAmount"] == undefined) { TaxAmount = '' } else { TaxAmount = excelRows[j]["TaxAmount"] }
                    if (excelRows[j]["Amount"] == undefined) { Amount = '' } else { Amount = excelRows[j]["Amount"] }
                    if (excelRows[j]["AvgCost"] == undefined) { AvgCost = '' } else { AvgCost = excelRows[j]["AvgCost"] }

                    oArray.push({
                        'ItemCode': $.trim(excelRows[j]["Product"]),
                        'Description': $.trim(excelRows[j]["Description"]),
                        'MinQty': $.trim(excelRows[j]["Quantity"]),
                        'UnitPrice': $.trim(excelRows[j]["Rate"]),
                        'SlNumber': parseInt(j + 1),
                    })

                }
                else if (j == excelRows.length) {
                    var data = { 'ItemMasterModel': oArray };
                    $.ajax(
                    {
                        type: "POST",
                        url: "../Master/ItemDetailsGetforExcelImport",
                        data: data,
                        success: function (result) {


                            for (var m = 0; m < result.oList.length; m++) {
                                if (result.oList[m].Status == 0) {

                                    var Prod =
                                        "<tr class='jsgrid-row' style='color:#607D8B'>" +
                                        "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].ItemCode + "</td>" +
                                        "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].Description + "</td></tr>";
                                    $('#tblAlert').append(Prod);

                                }
                                else {


                                    var bins = '';
                                    if ($('#select_location0').val() == 1) { if (result.oList[m].Bin_A != '') { bins = bins + result.oList[m].Bin_A; } }
                                    else if ($('#select_location0').val() == 2) { if (result.oList[m].Bin_B != '') { bins = bins + result.oList[m].Bin_B; } }
                                    else if ($('#select_location0').val() == 3) { if (result.oList[m].Bin_C != '') { bins = bins + result.oList[m].Bin_C; } }
                                    else if ($('#select_location0').val() == 4) { if (result.oList[m].Bin_D != '') { bins = bins + result.oList[m].Bin_D; } }
                                    else if ($('#select_location0').val() == 5) { if (result.oList[m].Bin_E != '') { bins = bins + result.oList[m].Bin_E; } }
                                    else if ($('#select_location0').val() == 6) { if (result.oList[m].Bin_F != '') { bins = bins + result.oList[m].Bin_F; } }
                                    else if ($('#select_location0').val() == 7) { if (result.oList[m].Bin_G != '') { bins = bins + result.oList[m].Bin_G; } }
                                    else if ($('#select_location0').val() == 8) { if (result.oList[m].Bin_H != '') { bins = bins + result.oList[m].Bin_H; } }


                                    var Prod =
                                        "<tr  class='jsgrid-row' style='color:#607D8B'>" +
                                        "<td id='excode" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].ItemCode + "</td>" +
                                        "<td id='exdesc" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].Description + "</td>" +
                                        "<td id='exitemid" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].ItemId + "</td>" +
                                        "<td id='exunitid" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].UnitId + "</td>" +
                                        "<td id='exqty" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].MinQty + "</td>" +
                                        "<td id='exdisc" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>0</td>" +
                                        "<td id='exvatid" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].VatId + "</td>" +
                                        "<td id='exprice" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].SellingPrice + "</td>" +
                                        "<td id='exotherdesc" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].Otherdescription + "</td>" +
                                        "<td id='exavgcost" + la + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[m].AvgCost + "</td>" +
                                        "<td style='display:none' id=" + 'Binex' + la + ">" + bins + "</td>" +
                                        "</tr>";
                                    $('#tblAlert').append(Prod);
                                    la++;
                                }
                            }

                            if (result.oList[0].Status == 0)
                            {
                                $('#alertpopup').show();
                                $('#alertdiv').show();
                                $('#alertdiv1').hide();
                                $("#btnokalert").focus();
                            }

                            else
                            {
                                $('#tblsalesinvoice tr').remove();

                                for (var f = 1; f < sl; f++) {
                                    if ($('#tblsalesinvoice tr').length == 0)
                                        i = 1;
                                    var id = parseInt(i);


                                    var fcval = parseFloat($('#txtcrncyrate').val() || 0).toFixed(Decimal);

                                    if ($('#excode' + f).text())
                                    {
                                        var ProdRow1 = "<tr onclick=GetproddetailsGrid(" + id + "),GetPrdtId(" + $('#exitemid' + f).text() + ",'" + $('#exdesc' + f).text() + "','" + $('#excode' + f).text() + "'," + 2 + ") onfocusout='updaterow(" + id + ")'  id=" + 'row' + id + " class='jsgrid-row'>" +
                         "<td id= 'col13_" + id + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:15px'><input class='jsgrid-button jsgrid-delete-button jsgrid-align-center' id='btnrodelt' type='button' onclick='rowdelete(" + id + ")' title='Delete'></td>" +
                         "<td id=" + 'td' + id + " class='jsgrid-cell' style='width:15px;text-align:center'>" + id + "</td>" +
                         "<td class='jsgrid-cell jsgrid-align-right' style='width:40px;text-align:center'><input type='text' id=" + 'PrdtId' + id + " style='display:none' value='" + $('#exitemid' + f).text() + "' /><input type='text' style='display:none;height:30px' id=" + 'Otherdescription' + id + " value='" + $('#exotherdesc' + f).text() + "'><input type='text' style='display:none;height:30px' id=" + 'MRP' + id + " value='0'><input type='text' style='height:30px;background-color:white' disabled='' class='form-control text-left' id=" + 'txtproduct' + id + " value='" + $('#excode' + f).text() + "' data-toggle='tooltip' title='" + $('#excode' + f).text() + "'></td>" +
                         "<td class='jsgrid-cell jsgrid-align-right' style='width:110px;text-align:center'><input type='text' style='height:30px;background-color:white' disabled='' class='form-control text-left' id=" + 'ProductDesc' + id + " value='" + $('#exdesc' + f).text() + "' data-toggle='tooltip' title='" + $('#exdesc' + f).text() + "'></td>" +
                         "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'><select id=" + 'select_unit' + id + " style='background-color:white;height:30px' class='form-control' onchange='changeunit(" + id + ",this)' onkeydown=Focusnextgrid(event,'u'," + id + ") onfocusout=focusoutgrid('u'," + id + ") onfocusin=focusingrid('u'," + id + ")>" + UnitSelect + "</select></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center' style='width:40px'><select style='background-color:white;height:30px' id=" + 'select_location' + id + " class='form-control' onchange ='GetBin(" + id + "," + $('#exitemid' + f).text() + ",0),Locationqtycheckmain(" + id + ")' onkeydown=Focusnextgrid(event,'l'," + id + ") onfocusout=focusoutgrid('l'," + id + ") onfocusin=focusingrid('l'," + id + ")>" + LocnSelect + "</select></td>" +
                         "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'><input type='text' name='prdaddqty' class='form-control text-center' id=" + 'txtquantity' + id + " value=" + ($('#exqty' + f).text() || 1) + " style='background-color:white;height:30px' onkeyup='amountcalculation(" + id + ")' onkeydown=Focusnextgrid(event,'q'," + id + ") onkeypress=isNumberInt(event,this) onfocusout=focusoutgrid('q'," + id + ") onfocusin=focusingrid('q'," + id + ")></td>" +
                         "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'> <input type='text' id=" + 'txtfcrate' + id + " value=" + parseFloat($('#exprice' + f).text() * fcval).toFixed(Decimal) + "  style='display:none'><input type='text' class='form-control text-center' id=" + 'txtrate' + id + " value=" + parseFloat($('#exprice' + f).text()).toFixed(Decimal) + " style='background-color:white;height:30px' onkeyup='amountcalculation(" + id + ")' onkeypress=isNumber(event,this) onkeydown=Focusnextgrid(event,'r'," + id + ") onblur=checkrate(" + id + ") onfocusout=focusoutgrid('r'," + id + ") onfocusin=focusingrid('r'," + id + ")></td>" +
                         "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfcdiscount' + id + " value=" + parseFloat(($('#exdisc' + f).text() || 0) * fcval).toFixed(Decimal) + "  style='display:none'><input type='text' id=" + 'txtdiscount' + id + " class='form-control text-center' style='background-color:white;height:30px' value=" + parseFloat(($('#exdisc' + f).text() || 0)).toFixed(Decimal) + " onkeyup='amountcalculation(" + id + ")' onkeypress=isNumber(event,this) onkeydown=Focusnextgrid(event,'d'," + id + ") onfocusout=focusoutgrid('d'," + id + ") onfocusin=focusingrid('d'," + id + ")></td>" +
                         "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:40px'><input type='text' id=" + 'txtfctaxableamnt' + id + " value=0  style='display:none'><input type='text' disabled='' class='form-control text-center' style='background-color:white;height:30px' id=" + 'txttaxableamnt' + id + " value='0' onkeyup='amountcalculation(" + id + ")'></td>" +
                         "<td class='jsgrid-cell jsgrid-align-center' style='width:38px'><select style='background-color:white;height:30px' id=" + 'select_tax' + id + " class='form-control' onchange='ChangeTax(" + id + ",this)' onkeydown=Focusnextgrid(event,'t'," + id + ") onfocusout=focusoutgrid('t'," + id + ") onfocusin=focusingrid('t'," + id + ")>" + TaxSelect + "</select></td>" +
                         "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:22px'><input typ='text' disabled='' style='background-color:white;height:30px' class='form-control text-center' id=" + 'txttaxpercent' + id + " value=0 onkeyup='amountcalculation(" + id + ")'></td>" +
                         "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfctaxamnt' + id + " value=0 style='display:none'><input typ='text' style='background-color:white;height:30px' class='form-control text-center'  id=" + 'txttaxamnt' + id + " value=0 disabled=''></td>" +
                         "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfcamnt' + id + " value=0  style='display:none'><input typ='text' class='form-control text-center' style='background-color:white;height:30px' disabled='' id=" + 'txtamnt' + id + " value=0></td>" +
                         "<td class='jsgrid-cell jsgrid-align-center ShowAverageCost' style='width:30px'><input type='text' id=" + 'LineAvgCost' + id + " value=0 style='display:none'> <input type='text' disabled='' class='form-control text-center' id=" + 'AvgCost' + id + " value=" + parseFloat($('#exavgcost' + f).text()).toFixed(Decimal) + " style='background-color:white;height:30px'></td>" +
                         "<td style='display:none' id=" + 'Bin' + id + ">" + $('#Binex' + f).text() + "</td>" +
                         "</tr>";

                                        $('#tblsalesinvoice').append(ProdRow1);
                                        $('#select_unit' + id).val(parseInt($('#exunitid' + f).text()));
                                        $('#select_tax' + id).val(parseInt($('#exvatid' + f).text()));
                                        $('#txttaxpercent' + id).val(($('#select_tax' + id).find("option:selected").attr("name")));
                                        $('#select_location' + id).val($('#select_locn').val());

                                        if (parseFloat($('#exdisc' + f).text()) > 0) {
                                            $('#disc').prop("disabled", true);
                                            $('#disc').val('0.00');
                                            $('#Discountpercent').val('');
                                            BillDiscountFlag = 1;
                                        }
                                        amountcalculation(id);
                                        TaxSplit(id);

                                        CalcGrandTotal(i);
                                        fccalculation(i);

                                        if (usermenu1.indexOf("M230") == -1) {
                                            $('.ShowAverageCost').css('display', 'none');
                                        }
                                        else {
                                            $('.ShowAverageCost').css('display', '');
                                        }


                                        var n = ProdIdArray.includes($('#exitemid' + f).text());
                                        if (n != true) {
                                            ProdIdArray.push($('#exitemid' + f).text());
                                        }

                                        var m = autoProdIdArray.includes($('#exitemid' + f).text());
                                        if (n != true) {
                                            autoProdIdArray.push($('#exitemid' + f).text());
                                        }

                                        i++;
                                        CalcDiscountSplitTax1();

                                    }

                                }

                            }

                        }
                    });
                }
                sl++;

            }


            $('#disc').val('0.00');
            $('#Discountpercent').val('');


            clearrow(0);
            $('#proddiv').animate({ scrollTop: 5000 }, 900);

        }

    };

</script>

<script type="text/javascript">
    function exportbilltotable() {
        var row = ""
        var PayType = $("#select_payterms option:selected").text();
        var CustName = $('#txtcustomer').val();                      var CustAddress = $('#txtaddress').val();
        var InvDate = $('#txtivdate').val();                         var Location = $("#select_locn option:selected").text();
        var SalesMan = $("#select_salesman option:selected").text(); var SupplyTo = $("#select_place option:selected").text();
        var Amount = $("#gndtotal").text();
        row += '<tr><td><b>Bill Series</b></td><td><b>' + $("#txtBillseriesId option:selected").text() + '</b></td><td><b>Bill No<b> </td><td><b>' + $('#txtBillSlNocopy').val() + '</b></td></tr>';
        row += '<tr><td><b>Customer</b></td><td><b>' + CustName + '</b></td><td><b>Date<b> </td><td><b>' + InvDate + '</b></td><td><b>Location</b></td><td><b>' + Location + '</b></b></td><td><b>Supply To</b></td><td><b><b>' + SupplyTo + '<b></b></td></tr>';
        row += '<tr><td> </td><td><b>' + CustAddress + '</b></td><td><b>Pay Type</b></td><td><b>' + PayType + '</b></td><td><b>Sales Man</b></td><td><b>' + SalesMan + '</b></td><td><b>Total</b></td><td><b>' + Amount + '</b></td><td></td></tr>'
        row += '<tr><td>Item Code</td><td>Name</td><td>Unit</td><td>Qantity</td><td>Rate</td><td>Discount</td><td>Taxable Amount</td><td>Tax Amount</td><td>Amount</td></tr>'

        for (k = 1; k < i; k++) {
            var ProductId = $('#PrdtId' + k).val();                                   var ProductCode = $('#txtproduct' + k).val();
            var ProductDescr = $('#ProductDesc' + k).val();                           var BillSeriesId = $('#txtBillseriesId').val();
            var BillSlNo = $('#txtBillSlNo').val();                                   var UnitId = $('#select_unit' + k).val();
            var UnitName = $('#select_unit' + k).find("option:selected").attr("name");var ProdQty = $('#txtquantity' + k).val();
            var ProdRate = $('#txtfcrate' + k).val();                                 var FcProdRate = $('#txtrate' + k).val();
            var ProdDisc = $('#txtfcdiscount' + k).val();                             var FcProdDisc = $('#txtdiscount' + k).val();
            var TaxableAmount = $('#txtfctaxableamnt' + k).val();                     var FCTaxableAmount = $('#txttaxableamnt' + k).val();
            var TaxId = $('#select_tax' + k).val();                                   var TaxPercent = $('#txttaxpercent' + k).val();
            var TaxAmount = $('#txtfctaxamnt' + k).val();                             var FCTaxAmount = $('#txttaxamnt' + k).val();
            var Amount = $('#txtfcamnt' + k).val();                                   var FCAmount = $('#txtamnt' + k).val();
            var LocnId = $('#select_location' + k).val();
            row += '<tr><td>' + ProductCode + '</td><td>' + ProductDescr + '</td><td>' + UnitName + '</td><td>' + ProdQty + '</td><td>' + ProdRate + '</td><td>' + ProdDisc + '</td><td>' + TaxableAmount + '</td><td>' + TaxAmount + '</td><td>' + Amount + '</td></tr>'
        }
        $('#tbExport').html('')
        $('#tbExport').append(row);
    }



    $(function () {
        $("#btnExporttoExcel").click(function () {

            if ($('#tblsalesinvoice tr').length > 0)
            {
                exportbilltotable();
                var BillNo = 'Invoice-' + $('#txtBillSlNocopy').val();
                $("#tbExport").table2excel({
                    filename: BillNo + ".xls"
                });
            }
            else
            {
                warningshow("No Products!");
            }
        });

    });
</script>



<script type="text/javascript">
    $(document).ready(function () {
        if ("@Request.QueryString["from"]" == "SalesReport") {
            var srlsrs = sessionStorage.getItem("sales_srs");
            var srlno = sessionStorage.getItem("sales_slno");
            var dep = sessionStorage.getItem("sales_deptid");
            sessionStorage.removeItem("sales_srs");
            sessionStorage.removeItem("sales_slno");
            sessionStorage.removeItem("sales_deptid");
            var numId = parseInt(srlsrs);
            var num = parseInt(srlno);
            var deprtid=parseInt(dep)
            if (!isNaN(numId) && !isNaN(num) && !isNaN(deprtid)) {
                ReportGetCopy(numId,num,deprtid);
            }
        }
     else if ("@Request.QueryString["from"]" == "AccountStatement") {
            var srlsrs = sessionStorage.getItem("sales_srs");
            var srlno = sessionStorage.getItem("sales_slno");
            var dep = sessionStorage.getItem("sales_deptid");
            sessionStorage.removeItem("sales_srs");
            sessionStorage.removeItem("sales_slno");
            sessionStorage.removeItem("sales_deptid");
            var numId = parseInt(srlsrs);
            var num = parseInt(srlno);
            var deprtid = parseInt(dep)
            if (!isNaN(numId) && !isNaN(num)&& !isNaN(deprtid)) {
                ReportGetCopy(numId, num, deprtid);
            }
     }
     else if ("@Request.QueryString["from"]" == "WorkItem") {
         var srlsrs = sessionStorage.getItem("sales_srswork");
         var srlno = sessionStorage.getItem("sales_slnowork");
         var dep = sessionStorage.getItem("sales_deptidwork");
         sessionStorage.removeItem("sales_srswork");
         sessionStorage.removeItem("sales_slnowork");
         sessionStorage.removeItem("sales_deptidwork");
         var numId = parseInt(srlsrs);
         var num = parseInt(srlno);
         var deprtid = parseInt(dep)
         if (!isNaN(numId) && !isNaN(num) && !isNaN(deprtid)) {
             ReportGetCopy(numId, num, deprtid);
         }
     }
    });

    function ReportGetCopy(BillSeries, Billno,depid) {

        NextInvoiceNo = parseInt($('#txtBillSlNo').val() || 0);
        var data = {};
        data.BillSeriesId = BillSeries;
        data.BillSlNo = Billno;
        data.DeptId = depid;
        $.ajax({
            type: "POST",
            url: "../SalesInvoice/SalesGetandGets",
            data: data,
            success: function (result) {
                $('#txtBillSlNo').val(Billno)
                SalesGets(result.oList);
                $('.form-control').prop('disabled', true);
                $('.jsgrid-button').prop('disabled', true);
                $('#btnsubmit').prop("disabled", true);
                $('#btnlist').prop("disabled", true);
                $('#btnadd').prop("disabled", true);
                $('#btnprint').show();
                $('#txtBillSlNo').focus();

            }

        });

    }
</script>

<table id="tbExport" style="display:none"></table>

<div id="popupdiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="myheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none">
    <div class="modal-dialog" role="document" style="top:10%">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h3 class="modal-title" id="myheader"></h3>
                <button type="button" class="close" onclick="popuprefresh()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <form id="currencydiv" style="display:none">
                <div class="modal-body" style="overflow:auto;height:250px;">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="txt_code">Code<span class="danger">*</span></label>
                        <input type="text" id="txt_code" onkeyup="changetoupper(this.id),$('#txt_cname').val($('#txt_code').val())" class="form-control">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="unitdesc">Name</label>
                        <input type="text" id="txt_cname" maxlength="100" class="form-control">
                    </fieldset>
                    <br />
                    <fieldset class="form-group floating-label-form-group">
                        <label for="unitname">Rate<span class="danger">*</span></label>
                        <input type="text" id="txt_rate" maxlength="8" onkeypress="return isNumber(event, this)" class="form-control">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="unitname">Remarks</label>
                        <textarea id="txt_remark" rows="5" class="form-control" name="comment"></textarea>
                    </fieldset>
                    <br>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="popuprefresh()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btncrncysave" onclick="SaveCurrency(1)">
                </div>
            </form>
            <form id="areadiv" style="display:none">
                <div class="modal-body" style="overflow:auto;height:250px;">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupcode">Area Code<span class="danger">*</span></label>
                        <input type="text" onkeyup="changetoupper(this.id),$('#txtname').val($('#txtcode').val())" id="txtcode" class="form-control" autocomplete="off">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupname">Area Name<span class="danger">*</span></label>
                        <input type="text" id="txtname" class="form-control" autocomplete="off">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupdesc">Group</label>
                        <div class="input-group">

                            <select id="select_areagroup" class="form-control"></select>
                            <div class="input-group-append">
                                <button class="btn btn-outline-primary" type="button" onclick="areagroupadd(1)">+</button>
                            </div>
                        </div>

                    </fieldset>


                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupdesc">Description</label>
                        <input type="text" id="txtdescription" class="form-control" autocomplete="off">
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="popuprefresh()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btnareasave" onclick="SavePlace(1)">
                </div>
            </form>


            <form id="locationdiv" style="display:none">
                <div class="modal-body" style="overflow:auto;height:250px;">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="grp">Code<span class="danger">*</span></label>
                        <input type="text" onkeyup="changetoupper(this.id),$('#LocationName').val($('#LocationCode').val())" id="LocationCode" class="form-control" name="Code">

                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="sbgroupname">Name<span class="danger">*</span></label>
                        <input type="text" id="LocationName" class="form-control" name="Name">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="sbgroupdesc">Description</label>
                        <input type="text" id="LocationDescription" class="form-control" name="Description">
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="popuprefresh()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btnlocnsave" onclick="SaveLocation(1)">
                </div>
            </form>


            <form id="salesmandiv" style="display:none;">
                <div class="modal-body" style="overflow:auto;height:290px;">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catcode">Code<span class="danger">*</span></label>
                        <input type="text" id="code" maxlength="25" onkeyup="changetoupper(this.id),$('#txt_fname').val($('#txt_code').val())" class="form-control" name="txt_code">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catname">Name<span class="danger">*</span></label>
                        <input type="text" id="txt_fname" maxlength="100" class="form-control" name="txt_fname">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catdesc">Target Amount</label>
                        <input type="text" id="txt_amount" maxlength="12" class="form-control" name="txt_amount" onkeypress="return isNumber(event, this)">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catdesc">Address 1</label>
                        <input type="text" id="txt_address1" maxlength="100" class="form-control" name="txt_address1">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catdesc">Address 2</label>
                        <input type="text" id="txt_address2" maxlength="100" class="form-control" name="txt_address2">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catdesc">Address 3</label>
                        <input type="text" id="txt_address3" maxlength="100" class="form-control" name="txt_address3">
                    </fieldset>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="catdesc">Contact Number</label>
                        <input type="text" id="txt_contactnumber" maxlength="13" class="form-control" name="txt_contactnumber">
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="popuprefresh()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btnsalesmansave" onclick="SaveSalesman(1)">
                </div>
            </form>
            <form id="termsdiv" style="display:none">
                <div class="modal-body">

                    <fieldset class="form-group floating-label-form-group">
                        <label for="sbcatname">Description<span class="danger">*</span></label>
                        <input type="text" id="txtdesc" class="form-control" autocomplete="off">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="sbcatdesc">Terms</label>
                        <input type="text" id="txtterms" class="form-control" autocomplete="off">
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="popuprefresh()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btntermssave" onclick="SaveTerms(1)">
                </div>
            </form>

        </div>
    </div>
</div>

<div id="areapopupdiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="armyheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none">
    <div class="modal-dialog" role="document" style="top:10%">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h3 class="modal-title" id="armyheader"></h3>
                <button type="button" class="close" onclick="areagroupadd(2)" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <form id="areagroupdiv" style="display:none">
                <div class="modal-body" style="overflow:auto;height:250px;">
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupcode">Area Code<span class="danger">*</span></label>
                        <input type="text" onkeyup="changetoupper(this.id),$('#artxtname').val($('#artxtcode').val())" id="artxtcode" class="form-control" autocomplete="off">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupname">Area Name<span class="danger">*</span></label>
                        <input type="text" id="artxtname" class="form-control" autocomplete="off">
                    </fieldset>
                    <br>
                    <fieldset class="form-group floating-label-form-group">
                        <label for="groupdesc">Description</label>
                        <input type="text" id="artxtdescription" class="form-control" autocomplete="off">
                    </fieldset>
                </div>
                <div class="modal-footer">
                    <input type="reset" class="btn btn-outline-secondary" onclick="areagroupadd(2)" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="Save" id="btnareasave" onclick="SaveAreagrp(1)">
                </div>
            </form>

        </div>
    </div>
</div>

<div id="jobpopupdiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="jobheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none;">
    <div class="modal-dialog modal-xl" role="document" style="margin-top:230px">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h3 class="modal-title" id="jobheader"></h3>
                <button type="button" class="close" onclick="jobpopuprefresh()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="Jobdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="row" style="height:26px;">

                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label>Job Details</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label>Unit</label>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">
                                        <label>Quantity</label>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">
                                        <label>Rate</label>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">
                                        <label>Discount</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label>Tax Group</label>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">
                                        <label>Tax</label>
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">
                                        <label>Amount</label>
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-2">

                                    <input type="text" id="productjob" class="form-control" style="margin-left:1px" onkeyup="changetoupper(this.id)">

                                </div>

                                <select id="locn_job" class="form-control" disabled style="background-color:white;display:none"></select>
                                <input type="hidden" id="txtlocn_job" class="form-control" />

                                <div class="col-md-2">
                                    <div class="form-group">

                                        <select id="unit_job" class="form-control"></select>
                                        <input type="hidden" id="txtunit_job" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">

                                        <input type="text" id="quantity_job" class="form-control" onkeyup="CalcJobAmount()" onkeypress="isNumberInt(event, this)">
                                    </div>
                                </div>


                                <div class="col-md-1">
                                    <div class="form-group">
                                        <input type="text" id="txtrate_job" class="form-control" onkeyup="CalcJobAmount()" onkeypress="isNumber(event, this)">
                                        <input type="hidden" id="txtsubtotal_job" class="form-control" />
                                        <input type="hidden" id="fcamount_job" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">
                                        <input type="text" id="discount_job" class="form-control" onkeypress="isNumber(event, this)" onkeyup="CalcJobAmount()">
                                        <input type="hidden" id="fctxtdisc_job" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">

                                        <select id="tax_job" class="form-control"></select>
                                    </div>
                                </div>
                                <div class="col-md-1">
                                    <div class="form-group">

                                        <input type="text" id="taxpercentage_job" class="form-control" disabled style="background-color:white">
                                    </div>
                                </div>
                                <div class="col-md-2">
                                    <div class="form-group">

                                        <input type="text" id="amount_job" class="form-control" disabled style="background-color:white">
                                        <input type="hidden" id="txttaxable_job" class="form-control" />
                                        <input type="hidden" id="txttax_job" class="form-control" />
                                        <input type="hidden" id="txtsubtotal_job" class="form-control" />

                                        <input type="hidden" id="fctxttaxable_job" class="form-control" />
                                        <input type="hidden" id="fctxttax_job" class="form-control" />
                                        <input type="hidden" id="fctxtsubtotal_job" class="form-control" />
                                    </div>
                                </div>


                            </div>
                            <div class="form-body">
                                <div class="text-right">
                                    <input type="button" class="btn btn-outline-primary" value="Save" id="btnjobsave" onclick="JobAdd()">
                                    <input type="button" class="btn btn-outline-secondary" onclick="jobpopuprefresh()" data-dismiss="modal" value="close">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<div id="salestranspopupdiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="jobheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none;top:-1%">
    <div class="modal-dialog modal-xl" role="document" style="margin-top:100px">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h4 class="modal-title col-md-10" id="salesheader"></h4>

                <div style="float:right" id="alltranscheckboxdivsales" class="custom-control custom-checkbox col-md-1">
                    <input type="checkbox" class="custom-control-input" id="status_type" onchange="CheckTransType()">
                    <label class="custom-control-label" for="status_type" id="idforlabeltype">All</label>
                </div>
                <button type="button" class="close" onclick="salestranspopuprefresh()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="salestransdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <section>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="card">
                                            <div class="card-body">
                                                <div class="card-block" style="overflow:scroll;width:100%;overflow:auto">
                                                    <div id="" class="jsgrid" style="position: relative;overflow-y:scroll;width:100%;height:530px">
                                                        <table class="table table-responsive-md-md jsgrid-table compact table-bordered table-striped" id="tblsalestrans" style="width:100%;overflow-x:scroll;overflow-y:scroll;font-size:small"></table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </div>
            </form>

            <form id="purchasetransdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <section>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="card-body">
                                            <div class="card-block" style="overflow:scroll;width:100%;overflow:auto">
                                                <div id="" class="jsgrid" style="position: relative;overflow-y:scroll;width:100%;height:530px">
                                                    <input type="hidden" id="transid" />
                                                    <table class="table table-responsive-md-md jsgrid-table compact table-bordered table-striped" id="tblurchasetrans" style="width:100%;overflow-x:scroll;overflow-y:scroll;font-size:small"></table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </div>
            </form>

            <form id="alltranstransdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <section>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="card">
                                            <div class="card-body">
                                                <div class="card-block" style="overflow:scroll;width:100%;overflow:auto">
                                                    <div id="" class="jsgrid" style="position: relative;overflow-y:scroll;width:100%;height:530px;font-size:small">

                                                        <table class="table table-responsive-md-md jsgrid-table compact table-bordered table-striped" id="tblalltrans" style="width:100%;overflow-x:scroll;overflow-y:scroll"></table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>

<div id="PendingPurchaseTransactionPopup" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="PurchaseTransactionheader" style="padding-right: 17px; display: block; display:none">
    <div class="modal-dialog modal-lg" role="document" style="margin-top:100px;margin-left:300px">
        <div class="modal-content" style="width:170%;">
            <div class="modal-header bg-primary white">
                <h4 class="modal-title col-md-10" id="PendingPurchaseTransactionheader"></h4>

                <div id="allpendingcheckboxdiv" class="custom-control custom-checkbox col-md-1" style="display:none">
                    <input type="checkbox" class="custom-control-input" id="select_statuspending" onchange="PendingTransType()">
                    <label class="custom-control-label" for="select_statuspending">All</label>
                </div>

                <button type="button" class="close" onclick="ClosePendingPurTransPopup()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <section id="pendingpurchasetrans" style="display:none">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="card-body">

                            <div class="card-block" style="overflow:scroll;width:100%;overflow:auto">
                                <div id="" class="jsgrid" style="position: relative;overflow-y:scroll;width:100%;height:410px">
                                    <input type="hidden" id="pendingtransid" />
                                    <table class="table table-responsive-md-md text-center" id="tblpendingpurchasetrans" style="width:100%;overflow-x:scroll;overflow-y:scroll;font-size:small"></table>
                                </div>
                            </div>


                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>

<div id="alternateitem" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="jobheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none;">
    <div class="modal-dialog modal-llg" role="document" style="margin-top:100px">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h4 class="modal-title" id="alternateitemheader"></h4>
                <button type="button" class="close" onclick="$('#alternateitem').hide()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="alternateitemdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <section>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="card">
                                            <div class="card-body">
                                                <table class="table table-responsive-md-md text-center table-bordered table-striped" id="tblalternateitem"></table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </div>
            </form>


        </div>
    </div>

</div>

<div id="Enquirypopup" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="OtherCostheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none">
    <div class="modal-dialog modal-xl" role="document" style="top:10%;">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h4 class="modal-title" id="Enquiryheader"></h4>
                <button type="button" class="close" onclick="CloseEnquiry()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <form id="Enquirydivcust" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateenq">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateenq1" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateenq">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateenq1" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>

                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch1" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear1" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblEnquirycust" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="View" id="btnview">
                </div>
            </form>
            <form id="Enquirydiv" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateenq">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateenq" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateenq">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateenq" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustenq">Customer</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchCustenq" class="form-control" placeholder="Search Customer" onkeyup="checkcusttextempty()" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddencustIdenq" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch" onclick="" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblEnquiry" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                </div>
            </form>
            <form id="Enquirydivsub" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustenq">Product</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchProdenq" class="form-control" placeholder="Search Product" onkeyup="checkProdempty()" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddenProdIdenq" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch2" onclick="" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear2" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblEnquirypsub" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="Back(1)" data-dismiss="modal" value="Back">
                    <input type="button" class="btn btn-outline-primary" value="Add" id="btnprdtadd">
                </div>
            </form>
            <form id="Qtndiv" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateqtn">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateqtn" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateqtn">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateqtn" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustqtn">Customer</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchCustqtn" class="form-control" placeholder="Search Customer" onkeyup="emptyId(event)" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddencustIdqtn" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearchqtn" onclick="SearchQuotation(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclearqtn" onclick="SearchQuotation(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblQtn" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-secondary" onclick="EditQtn()" data-dismiss="modal" value="Add">
                </div>
            </form>
            <form id="Qtndivcust" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateqtn1">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateqtn1" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateqtn1">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateqtn1" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>

                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSQtnCust(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSQtnCust(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblQtncust" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="View" id="btnview1">
                </div>
            </form>
            <form id="Qtndivsub" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustso">Product</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchProdqtn" class="form-control" onkeyup="emptyId(event)" placeholder="Search Product" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddenProdIdqtn" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSQtnSub(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSQtnSub(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblQtnsub" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="Back(2)" data-dismiss="modal" value="Back">
                    <input type="button" class="btn btn-outline-primary" value="Add" id="btnprdtadd1">
                </div>
            </form>
            <form id="SalesOrderdiv" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateso">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateso" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateso">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateso" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustso">Customer</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchCustso" class="form-control" placeholder="Search Customer" onkeyup="emptyId(event)" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddencustIdso" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch" onclick="SearchSOrder(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear" onclick="SearchSOrder(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesOrder" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-secondary" onclick="EditSalesOrder()" data-dismiss="modal" value="Add">
                </div>
            </form>
            <form id="SalesOrderdivcust" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdateso1">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdateso1" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDateso1">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDateso1" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>

                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch1" onclick="SearchSOrderCust(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear1" onclick="SearchSOrderCust(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesOrdercust" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="View" id="btnview2">
                </div>
            </form>
            <form id="SalesOrderdivsub" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustso">Product</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchProdso" class="form-control" onkeyup="emptyId(event)" placeholder="Search Product" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddenProdIdso" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearch2" onclick="SearchSOrderSub(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclear2" onclick="SearchSOrderSub(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesOrdersub" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="Back(3)" data-dismiss="modal" value="Back">
                    <input type="button" class="btn btn-outline-primary" value="Add" id="btnprdtadd2">
                </div>
            </form>
            <form id="SalesInvdiv" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdatesi">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdatesi" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDatesi">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDatesi" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustsi">Customer</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchCustsi" class="form-control" placeholder="Search Customer" onkeyup="emptyId(event)" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddencustIdsi" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" id="btnsearchsi" onclick="SearchSInv(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" id="btnclearsi" onclick="SearchSInv(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesInv" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-secondary" onclick="EditSalesInvoice()" data-dismiss="modal" value="Add">
                </div>
            </form>
            <form id="SalesInvdivcust" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdatesi1">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdatesi1" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDatesi1">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDatesi1" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>

                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSInvCust(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSInvCust(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesInvcust" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="View" id="btnview3">
                </div>
            </form>
            <form id="SalesInvdivsub" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustso">Product</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchProdsi" class="form-control" onkeyup="emptyId(event)" placeholder="Search Product" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddenProdIdsi" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSInvoiceSub(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchSInvoiceSub(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblSalesInvsub" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="Back(4)" data-dismiss="modal" value="Back">
                    <input type="button" class="btn btn-outline-primary" value="Add" id="btnprdtadd3">
                </div>
            </form>
            <form id="DeliveryOrderdiv" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdatedo">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdatedo" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDatedo">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDatedo" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchCustdo">Customer</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchCustdo" class="form-control" placeholder="Search Customer" onkeyup="emptyId(event)" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddencustIddo" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrder(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrder(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblDeliveryOrder" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-secondary" onclick="EditDeliveryOrder()" data-dismiss="modal" value="Add">
                </div>
            </form>
            <form id="DeliveryOrderdivcust" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchFromdatedo1">From Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchFromdatedo1" class="form-control" placeholder="Search From Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchToDatedo1">To Date</label>
                                </div>
                                <div class="col-md-2" style="margin-top:17px;">
                                    <div class="form-group">
                                        <input type="text" id="SearchToDatedo1" class="form-control" placeholder="Search To Date" style="height:35px;font-weight:200;">
                                    </div>
                                </div>

                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrderCust(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrderCust(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblDeliveryOrdercust" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="CloseEnquiry()" data-dismiss="modal" value="close">
                    <input type="button" class="btn btn-outline-primary" value="View" id="btnview4">
                </div>
            </form>
            <form id="DeliveryOrderdivsub" style="display:none;">
                <div class="modal-body">
                    <div class="table-responsive">
                        <div class="col-md-12">
                            <div class="row" style="background-color:#f0f6f6;">
                                <div class="col-md-1" style="margin-top:17px;text-align:center;">
                                    <label for="SearchProddo">Product</label>
                                </div>
                                <div class="col-md-3" style="margin-top:17px;">
                                    <input type="text" id="SearchProddo" class="form-control" onkeyup="emptyId(event)" placeholder="Search Product" style="height:35px;font-weight:200;">
                                    <input type="hidden" id="hiddenProdIddo" />
                                </div>
                                <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrderSub(1)" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                                    </div>
                                </div>
                                <div class="col-md-1" style="margin-top:16px;">
                                    <div class="form-group">
                                        <button type="button" onclick="SearchDlOrderSub(0)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="overflow-auto" style="height:525px;overflow:scroll;width:100%;overflow:auto;">
                            <table id="tblDeliveryOrdersub" class="table table-striped table-bordered zero-configuration dataTable"></table>
                        </div>

                    </div>
                </div>
                <div class="modal-footer">

                    <input type="button" class="btn btn-outline-secondary" onclick="Back(5)" data-dismiss="modal" value="Back">
                    <input type="button" class="btn btn-outline-primary" value="Add" id="btnprdtadd4">
                </div>
            </form>
        </div>
    </div>

</div>

<div id="Revisionpopupdiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="revheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none;">
    <div class="modal-dialog modal-xl" role="document" style="margin-top:230px">
        <div class="modal-content">
            <div class="modal-header bg-primary white">
                <h3 class="modal-title" id="revheader"></h3>
                <button type="button" class="close" onclick="$('#Revisionpopupdiv,#Revdiv').hide()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="Revdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12" style="overflow:scroll;height:280px;width:100%;overflow:auto;">
                            <table class="table table-responsive-md-md text-center" id="tblRevision"></table>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>

<div id="alertpopup" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="myheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block; display:none">
    <div class="modal-dialog" role="document" style="top:20%">
        <div class="modal-content" style="width:600px">
            <form id="alertdiv" style="display:none;">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12" style="overflow:scroll;height:200px;width:100%;overflow:auto;">
                            <table class="table table-responsive-md-md text-center" id="tblAlert"></table>
                        </div>
                    </div>
                    <div class="text-right">
                        <input type="button" class="btn btn-outline-primary" value="Ok" id="btnokalert" onclick="alertpopuprefresh()">
                    </div>

                </div>
            </form>
            <form id="alertdiv1" style="display:none">

                <div class="modal-body">
                    <div class="row">
                        <div class="placeholder"></div>
                        <div class="col-md-12" style="overflow:scroll;height:200px;width:100%;overflow:auto;">
                            <div class="swal2-icon swal2-success animate" style="display: block;"><span class="line tip animate-success-tip"></span> <span class="line long animate-success-long"></span><div class="placeholder"></div> <div class="fix"></div></div>
                            <br />
                            <h2 id="savealert" class="text-center"></h2>
                            <hr />
                        </div>
                    </div>
                    <div class="text-right">

                        <button style="" type="button" id="btnok" class="btn btn-outline-primary btn-min-width mr-1 mb-1 btn-sizebig">Print <i class="ft-printer"></i></button>
                        <button style="" type="button" id="btncustomok" class="btn btn-outline-primary btn-min-width mr-1 mb-1" onclick="confirmprint()">Custom Print <i class="ft-printer"></i></button>
                        <button style="" type="button" id="btncnclalrt" class="btn btn-outline-primary btn-min-width mr-1 mb-1">Cancel <i class="ft-x-circle"></i></button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<div class="modal fade text-left show" id="iconForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel17" style="padding-right: 17px; display: none;background:rgba(0,0,0,0.5);">
    <div class="modal-dialog modal-lg" role="document" style="margin-top:2%;margin-left:25%">
        <div class="modal-content" style="width:200%; margin-left:-320px;">
            <div class="modal-header bg-primary white">
                <div style="width:20%">

                    <h4 class="modal-title" id="Itemname" style="font-weight:600;font-size:x-large;"></h4>
                </div>

                <div style="width:80%;height:45px">
                    <div class="modal-title" id="pdthead" style="width:100%;">
                        <div style="width:100%;">
                            <table style="width:100%">
                                <tr style="width:100%">
                                    <td id="pcol2" style="font-weight:600;width:100%"></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
                <button type="button" class="close" data-dismiss="modal" onclick="closepopupprdtlist(0), clearprodlist(1), $('#iconForm').hide(); " aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-2">
                            <h4 class="modal-title" id="Itemname" style="font-weight:600">Product List</h4>
                        </div>
                        <div class="col-md-10">

                            <table id="ItemDetails" style="display:none;margin-left:10%;">
                                <tr>
                                    <td id="pcol1" style="font-weight:600"></td>

                                </tr>
                            </table>
                        </div>


                    </div>
                    <div class="row" style="background-color:#f0f6f6;height:75px">

                        <div class="col-md-2" style="display:none">

                            <input type="text" id="searchGroup" class="form-control" placeholder="Search Group" onkeyup="checkgrptextempty(event)" style="height:35px;font-weight:200;">
                            <input type="hidden" id="hiddengrpno" />

                            <div class="form-group">
                                <input type="text" id="searchSubGroup" class="form-control" placeholder="Search SubGroup" onkeyup="checkSubgrptextempty(event)" style="height:35px;font-weight:200;">
                                <input type="hidden" id="hiddensubgrpno" />
                            </div>
                            <div class="form-group">
                                <input type="text" id="searchCat" class="form-control" placeholder="Search Catogory" onkeyup="checkCategorytextempty(event)" style="height:35px;font-weight:200;">
                                <input type="hidden" id="hiddencatno" />
                            </div>
                            <div class="form-group">
                                <input type="text" id="searchSubcat" class="form-control" placeholder="Search SubCatogory" onkeyup="checkSubCategorytextempty(event)" style="height:35px;font-weight:200;">
                                <input type="hidden" id="hiddensubcatno" />
                            </div>
                        </div>

                        <div class="col-md-2" style="margin-top:17px;display:none">
                            <div class="form-group">
                                <select id="SearchType" class="form-control" style="height:35px" onkeydown="Focusnextgrid(event,'g',0)">
                                    <option value="0">
                                        Search By
                                    </option>
                                    <option value="1">
                                        Model
                                    </option>
                                    <option value="2">
                                        Group
                                    </option>
                                    <option value="3">
                                        Sub Group
                                    </option>
                                    <option value="4">
                                        Category
                                    </option>
                                    <option value="5">
                                        Sub Category
                                    </option>
                                </select>
                                <input type="hidden" id="hiddentypeid" />
                            </div>
                        </div>

                        <div class="col-md-3" style="margin-top:17px;">
                            <div class="form-group">
                                <input type="text" id="searchItemCode" class="form-control" placeholder="Search Here" onkeyup="checkitemtextempty(event)" style="height:35px;font-weight:200" onkeydown="Focusnextgrid(event,'s',0)">
                                <input type="hidden" id="hiddenitemcode" />
                            </div>
                        </div>

                        <div class="col-md-1" style="margin-top:17px;margin-left:10%;">

                        </div>

                        <div class="col-md-2" style="margin-top:17px;">

                            <label class="tot">Products : </label>

                        </div>
                        <div class="col-md-1" style="margin-top:17px;margin-left:-5%;">

                            <input type="text" id="Totgridpdcts" class="tot" style="border:none;background-color:#f0f6f6;font-size:130%;" autocomplete="off" disabled="" value="0">

                        </div>
                        <div class="col-md-2" style="margin-top:17px;">

                            <label class="tot">Quantity : </label>

                        </div>
                        <div class="col-md-1" style="margin-top:17px;margin-left:-5%;">

                            <input type="text" id="Totgridqty" class="tot" style="border:none;background-color:#f0f6f6;font-size:130%;" autocomplete="off" disabled="" value="0">

                        </div>


                        <div class="col-md-1" style="margin-top:16px;margin-left:-5px;display:none">
                            <div class="form-group">
                                <button type="button" id="btnsearchproduct" onkeydown="Focusnextgrid(event,'bt',1)" onclick="" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                            </div>

                        </div>
                        <div class="col-md-1" style="margin-top:16px;">
                            <div class="form-group">
                                <button type="button" id="btnclearproduct" onkeydown="Focusnextgrid(event, 'bt', 2)" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;display:none">Clear <i class="ft-refresh-cw position-right"> </i></button>
                            </div>
                        </div>
                    </div>

                </div>
                <div id="div1" style="height:500px;overflow-x:hidden;">
                    <table id="Productlist" class="table table-striped table-bordered zero-configuration dataTable">
                        <thead><tr><th style='width:90px;'> </th><th>Product</th><th>Description</th><th>Stock</th><th>Unit</th><th>Location</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Tax</th></tr></thead>
                    </table>
                </div>


                <div style="" class="text-right">
                    <input type="button" id="btnaddgrid" onclick="addgridproducts()" class="btn btn-outline-primary btn-lg" value="Add-[F4]" style="height:45px;width:110px;">
                    <input type="button" class="btn btn-outline-secondary btn-lg" style="height:45px;width:75px" onclick="closepopupprdtlist(0), $('#iconForm').hide(); " value="close">
                </div>

            </div>

        </div>
    </div>

</div>

<div id="OTPDiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="myheader" style="background:rgba(0,0,0,0.5); display: block;margin-top:0%;display: none;">
    <div class="modal-dialog modal-dialog-centered" role="document" style="top:-25%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="$('#OTPDiv').hide()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row" id="panel" style="margin-top:2%;">

                        <label class="col-md-5" style="text-align:left" id="reason">Enter the OTP:</label>
                        <div class="col-md-7">
                            <input type="text" id="txtotp" class="form-control" autocomplete="off">
                        </div>
                    </div>
                    <div class="row" id="panel" style="margin-top:2%;">

                        <label class="col-md-5" style="text-align:left" id="reason">Remarks:</label>
                        <div class="col-md-7">
                            <input type="text" id="otpremarks" class="form-control" autocomplete="off">
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" style="width:100px;" id="btnotpcancel" onclick="$('#OTPDiv').hide(), $('#txtotp,#otpremarks').val('')" class="btn btn-outline-secondary">Cancel</button>
                <button type="button" style="width:100px" id="btnotpsave" onclick="CheckEditInvoce()" class="btn btn-outline-warning">Continue</button>
            </div>


        </div>
    </div>
</div>

<div id="CancelOTPDiv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="myheader" style="background:rgba(0,0,0,0.5); display: block;margin-top:0%;display: none;">
    <div class="modal-dialog modal-dialog-centered" role="document" style="top:-25%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="$('#CancelOTPDiv').hide()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row" id="panel" style="margin-top:2%;">

                        <label class="col-md-5" style="text-align:left" id="reason">Enter the OTP:</label>
                        <div class="col-md-7">
                            <input type="text" id="cancelotp" class="form-control" autocomplete="off">
                        </div>
                    </div>
                    <div class="row" id="panel" style="margin-top:2%;">

                        <label class="col-md-5" style="text-align:left" id="reason">Remarks:</label>
                        <div class="col-md-7">
                            <input type="text" id="cancelotpremarks" class="form-control" autocomplete="off">
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" style="width:100px;" id="btndivdelete" onclick="$('#CancelOTPDiv').hide(), $('#cancelotp,#cancelotpremarks').val('')" class="btn btn-outline-secondary">Cancel</button>
                <button type="button" style="width:100px" id="btncnclsave" onclick="CheckCancelInvoce()" class="btn btn-outline-warning">Continue</button>
            </div>


        </div>
    </div>
</div>

<div id="Multiprice" class="card px-2" style="width:25%;display:none">
    <div id="Multipricediv" class="jsgrid" style="position: relative; overflow: auto;width:100%;display:none">
        <table class="table table-responsive-md-md jsgrid-table" id="tblMultiprice">
            <tr>
                <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: auto;text-align:left;font-weight:500"><b>Price</b></th>
                <th class="jsgrid-header-cell jsgrid-align-center jsgrid-header-sortable" style="width: auto;text-align:left;font-weight:500"><b>No of Qty</b></th>
            </tr>
        </table>
    </div>
</div>

<div class="modal fade text-left show" id="addacnttype" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block;display:none;">
    <div class="modal-dialog" role="document" style="top:200px">
        <div class="modal-content">

            <div class="modal-body">
                <br /> <br />
                <center><h2 style="color:#ef1111">Please Add Bill Series!</h2>    <br />    </center>
            </div>
        </div>
    </div>
</div>

<div id="bouncediv" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="revheader" style="background:rgba(0,0,0,0.5); display: block;display:none">
    <div class="modal-dialog modal-xl" role="document" style="margin-top:50px">
        <div class="modal-content" style="width:1500px;margin-left:3%">
            <div class="modal-header bg-white">
                <h3 class="modal-title" id="revheader">Order Bouncing</h3>
                <button type="button" class="close" id="popupclose" onclick="popupclose()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="orderbounce" style="max-width:100%;display:none">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-2">
                            <label for="BounceCustomer">Customer</label>
                            <input type="text" id="BounceCustomer" class="form-control" onkeydown="emptycheckcust(event)">
                            <input style="display:none" type="text" id="BounceCustId">
                        </div>

                        <div class="col-md-2">
                            <label for="opndate">Item Name<span class="danger">*</span></label>
                            <input type="text" id="BounceItem" class="form-control" onkeyup="emptycheckitem(event)">
                            <input style="display:none" type="text" id="BounceItemId">
                        </div>


                        <div class="col-md-3">

                            <label for="opntype">Description</label>
                            <input type="text" id="BounceDesc" class="form-control" name="Name">
                        </div>
                        <div class="col-md-3">

                            <label for="opndesc">Remarks</label>
                            <input type="text" id="BounceRemark" class="form-control" name="Name">

                        </div>
                        <div class="col-md-1">

                            <label for="opnamount">Quantity</label>
                            <input type="text" id="BounceQty" class="form-control" name="Name" onkeypress=isNumber(event,this)>

                        </div>

                        <div class="col-md-1">

                            <label for="btnadd" style="opacity:0">Add</label>
                            <button type="button" id="btnaddbounce" onclick="addbounce()" class="btn btn-outline-primary" style="height:40px;">+Add</button>

                        </div>

                    </div>
                    <hr style="margin-top:-.2%;margin-bottom:1%" />
                    <div class="row">

                        <div id="openingdiv" class="col-md-12" style="height:305px;width:100%;overflow-y:auto;">
                            <table class="table table-responsive-md-md text-center" id="tblbounce" style="border:1px solid #BABFC7">
                                <tr class="jsgrid-header-row">
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">
                                        SlNo
                                    </th>
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">
                                        Name
                                    </th>
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">
                                        Description
                                    </th>
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">
                                        Remarks
                                    </th>
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">
                                        Quantity
                                    </th>
                                    <th class="text-center jsgrid-header-cell" style="font-weight:500;border:1px solid #BABFC7;">

                                    </th>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </form>
            <div class="modal-footer">
                <button type="button" id="btnsubmitbounce" class="btn btn-outline-primary" onclick="saveOrderBouncing()">Save -[F6]</button>
                <button type="button" id="btnclearbounce" class="btn btn-outline-primary" onclick="clearbounce(2)">Clear</button>
            </div>
        </div>

    </div>

</div>


<div class="modal fade text-left show" id="automobiles" tabindex="-1" role="dialog" aria-labelledby="myModalLabel17" style="padding-right: 17px; display: none;background:rgba(0,0,0,0.5);margin-top:-1.5%">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" style="width:200%; margin-left:-320px;">
            <div class="modal-header bg-primary white" id="autopdthead" style="height:60px">
                <div style="width:20%">

                    <h4 class="modal-title" id="AutoItemname" style="font-weight:600;font-size:x-large;"></h4>
                </div>

                <div style="width:80%">
                    <table id="TblAutomobile" style="margin-left:10%;">
                        <tr>
                            <td id="autopcol1" style="font-weight:600"></td>

                        </tr>
                        <tr>
                            <td id="autopcol2" style="font-weight:600"></td>
                        </tr>
                    </table>
                </div>
                <button type="button" class="close" data-dismiss="modal" onclick="closeautomobile()" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row">
                        <h4 class="modal-title" id="Itemname" style="font-weight:600">Product List</h4>
                    </div>
                    <div class="row" style="background-color:#f0f6f6;height:75px">


                        <div class="col-md-2" style="margin-top:17px;">
                            <div class="form-group">
                                <select id="AutoType" class="form-control" style="height:35px"></select>
                                <input type="hidden" id="autotypeid" />
                            </div>
                        </div>

                        <div class="col-md-2" style="margin-top:17px;">
                            <div class="form-group">
                                <input type="text" id="AutoItemCode" class="form-control" placeholder="Search Here" style="height:35px;font-weight:200">
                                <input type="hidden" id="Autoitemid" />
                            </div>
                        </div>

                        @*<div class="col-md-2" style="margin-top:17px;margin-left:10%;">

                            </div>

                            <div class="col-md-2" style="margin-top:17px;">

                                <label class="tot">Products : </label>

                            </div>
                            <div class="col-md-1" style="margin-top:17px;margin-left:-5%;">

                                <input type="text" id="Totgridpdcts" class="tot" style="border:none;width:50%;background-color:#f5f7fa;font-size:130%;" autocomplete="off" disabled="" value="0">

                            </div>
                            <div class="col-md-2" style="margin-top:17px;">

                                <label class="tot">Quantity : </label>

                            </div>
                            <div class="col-md-1" style="margin-top:17px;margin-left:-5%;">

                                <input type="text" id="Totgridqty" class="tot" style="border:none;width:50%;background-color:#f5f7fa;font-size:130%;" autocomplete="off" disabled="" value="111110">

                            </div>*@


                        <div class="col-md-1" style="margin-top:16px;margin-left:-5px;">
                            <div class="form-group">
                                <button type="button" id="btnautoproduct" onclick="AutoMobileItemList()" class="btn btn-primary btn-min-width mr-1 mb-1 " style="position:absolute;width:100px;font-weight:400;">Search <i class="fa fa-search position-right"></i>  </button>
                            </div>

                        </div>
                        <div class="col-md-1" style="margin-top:16px;">
                            <div class="form-group">
                                <button type="button" id="btnautoclear" onclick="clearauto()" class="btn btn-primary btn-min-width mr-1 mb-1" style="width:100px;font-weight:400;">Clear <i class="ft-refresh-cw position-right"> </i></button>
                            </div>
                        </div>
                    </div>

                </div>
                <div id="div1" style="height:500px;overflow-x:hidden;">
                    <table id="AutoProductlist" class="table table-striped table-bordered zero-configuration dataTable">
                        <tr><th style='width:90px;'><input onchange=autocheckall() type="checkbox" id='autoSlNoHeadCheckgrid0' class="form-control" style="zoom:.7;align:center"> </th><th>Product</th><th>Description</th><th>Stock</th><th>Unit</th><th>Quantity</th><th>Rate</th><th>Discount</th><th>Tax</th><th>Location</th></tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <input type="button" id="btnaddauto" onclick="autoaddgridproducts()" class="btn btn-outline-primary btn-lg" value="Add-[F4]" style="height:45px;width:110px;">
                    <input type="button" class="btn btn-outline-secondary btn-lg" style="height:45px;width:75px" onclick="closeautomobile()" value="close">
                </div>
            </div>

        </div>
    </div>

</div>

<div class="modal fade text-left show" id="deptdiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block;display:none">
    <div class="modal-dialog" role="document" style="top:200px">
        <div class="modal-content">

            <div class="modal-body">
                <div class="swal-icon swal-icon--warning">
                    <span class="swal-icon--warning__body">
                        <span class="swal-icon--warning__dot"></span>
                    </span>
                </div>

            </div>
            <div class="modal-footer">
                <center>
                    <h2 style="color:#ef1111" id="deptmsg"></h2>    <br />
                    <button type="button" id="btndept" onclick="$('#deptdiv').hide(); $('#txtBillSlNocopy').focus(); $('#txtBillSlNocopy').select();" class="btn btn-outline-primary" style="height:40px;">OK</button>
                </center>
            </div>
        </div>
    </div>
</div>

<div class="modal fade text-left show" id="duecheckdiv" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block;display:none">
    <div class="modal-dialog" role="document" style="top:200px;max-width:35%">
        <div class="modal-content">

            <div class="modal-body">
                <div class="swal-icon swal-icon--warning">
                    <span class="swal-icon--warning__body">
                        <span class="swal-icon--warning__dot"></span>
                    </span>
                </div>
                <div class="" style="height:200px;overflow-y:auto">
                    <center>
                        <table class="text-center" id="duemsg"></table>
                    </center>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" id="btndue" onclick="$('#duecheckdiv').hide(); $('#txtproduct0').focus();" class="btn btn-outline-primary" style="height:40px;">OK</button>
            </div>
        </div>
    </div>
</div>


<div id="Loadingsave" class="overlay1" style="background: none;display: none;">
    <div style="margin-top:23%;margin-left: 50%;">
        <img src="/app-assets/img/Loading_1.gif">
    </div>
</div>

<div style="display:none">
    <input type="text" value="0" id="CrncyId" />
    <input type="text" value="0" id="AreaId" />
    <input type="text" value="0" id="LocationId" />
    <input type="text" value="0" id="SalesmanId" />
    <input type="text" value="0" id="TermsId" />

    <input type="text" id="HiddenDesc" />
    <input type="text" id="HiddenItem" />
    <input type="text" id="HiddenItemId" />
    <input type="text" id="EditId" value="0" />

    <input type="text" id="HiddenGridDesc" />
    <input type="text" id="HiddenGridItem" />
    <input type="text" id="HiddenGridItemId" />

    <input type="text" id="HiddenAutoDesc" />
    <input type="text" id="HiddenAutoItem" />

    <input type="text" id="HiddenAutoItemId" />
    <input type="text" id="DepartmentCode" />
    <input type="text" id="CurrentTimeSales" />

</div>

<div style="display:none">


    <input type="text" id="codelength" value="0" />
    <input type="text" id="RowGetprdt" value="0" />
    <input type="text" id="roundgndtotal" value="0" />
    <input type="text" id="roundfcgndtotal" value="0" />
    <input type="text" id="EnquiryNo" value="0" />
    <input type="text" id="QuotationNo" value="0" />
    <input type="text" id="OrderNo" value="0" />
    <input type="text" id="DeliveryOrderNO" value="0" />
    <input type="text" id="RowGet1" value="0" />
    <input type="text" id="RowGet" value="0" />
    <input type="text" id="RowGet2" value="0" />
    <input type="text" id="RowGet3" value="0" />
    <input type="text" id="RowGet3qt" value="0" />
    <input type="text" id="RowGet4" value="0" />
    <input type="text" id="RowGet5" value="0" />
    <input type="text" id="RowGet6" value="0" />
    <input type="text" id="RowGet7" value="0" />
    <input type="text" id="RowGet8" value="0" />
    <input type="text" id="RowGet9" value="0" />
    <input type="text" id="RowGet10" value="0" />
    <input type="text" id="RowGet11" value="0" />
    <input type="text" id="RowGet12" value="0" />
    <input type="text" id="enqnosearch" value="0" />
    <input type="text" id="RowGetenqcust" value="0" />
    <input type="text" id="RowGet3qt" value="0" />
    <input type="text" id="PriceGroupId" value="0" />
    <input type="text" id="temptxtproduct0" value="0" />
    <input type="text" id="mltrsltlng" value="0" />
    <input type="text" id="mltrcurrlength" value="0" />
    <input type="text" id="CheckForDiscount" value="0" />
    @*<table id="barcode1"></table>*@
    <img id="barcode1" />

</div>
<div id="salesviewpopup" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="jobheader" style="padding-right: 17px; background:rgba(0,0,0,0.5); display: block;display:none">
    <div class="modal-dialog modal-xl" role="document" style="margin-top:100px">
        <div class="modal-content">
            <div class="modal-header bg-primary white">


                <div class="col-md-2">
                    <input type="text" style="" id="DateFrom" class="form-control">
                </div>
                <div style="margin-top:.6%">
                    -
                </div>
                <div class="col-md-2">
                    <input type="text" style="" id="DateTo" class="form-control">
                </div>
                <div class="col-md-1" style="margin-top:.6%">
                    Department
                </div>
                <div class="col-md-2">
                    <select id="select_dept" class="form-control"></select>
                </div>
                <button type="button" id="Btlgetlist" style="" class="btn btn-warning" onclick="SalesInvoiceList(1)">GO</button>
                <div class="col-md-2 input-group" style="margin-left:10%">

                </div>

                <button type="button" class="close" onclick="$('#salesviewpopup').hide(); $('#txtBillSlNocopy').focus(); $('#txtBillSlNocopy').select(); " data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <form id="salesviewdiv" style="">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12">
                            <section>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="card">
                                            <div class="card-body">
                                                <div class="card-block">
                                                    <div id="" class="jsgrid" style="position: relative;overflow:auto;width:100%;height:500px">
                                                        <table class="table table-responsive-md-md text-center table-striped table-bordered zero-configuration dataTable" id="tblsalesview" style="width:100%;overflow-x:scroll;overflow-y:scroll;"></table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>



<div style="display:none">


    <input type="text" id="adr1" />
    <input type="text" id="adr2" />
    <input type="text" id="adr3" />
    <input type="text" id="PhoneNo" />


    <input type="text" id="Trnno" />

    <input type="text" id="savedbillno" />

    <input type="text" id="Otherdescription0" />
    <input type="text" id="MRP0" />

    <input type="text" id="txtcreditlimit" />

    <input type="text" class="form-control" id="SalesDepartmentId" />
    <input type="text" class="form-control" id="SalesDepartment" />

    <img src="/app-assets/img/oryx.png" alt="company logo">
</div>

<div id='modal_dialog' class="overlay" style="display: none;">
    <div class="modal fade text-left show" id="keyboard" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" style="display: block; padding-right: 17px; top:28%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">

                <div class="modal-body">
                    <div class="swal-icon swal-icon--warning">
                        <span class="swal-icon--warning__body">
                            <span class="swal-icon--warning__dot"></span>
                        </span>
                    </div>
                    <div id="soldmessage" class="swal-title" style="">Product Already Added.Do You Want to Continue?</div>
                </div>
                <div class="modal-footer">
                    <button type="button" id="btnNo" class="btn btn-primary btn-sizebig" autofocus="" autocomplete="off">Cancel</button>
                    <button type="button" onclick="" id="btnYes" class="btn btn-primary" autocomplete="off">Ok</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="CustomPrint" class="modal fade text-left show" tabindex="-1" role="dialog" aria-labelledby="myheader" style="background:rgba(0,0,0,0.5); display: block;margin-top:0%;display: none;">
    <div class="modal-dialog modal-dialog-centered" role="document" style="top:-25%">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Custom Print</h3>
                <button type="button" class="close" onclick="$('#CustomPrint').hide()" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>

            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row" id="panel" style="margin-top:2%;">

                        <div class="col-md-6">

                            <button type="button" style="width:100px" id="btncustprnt" onclick="PrintBill(1)" class="btn btn-warning white">Bin <i class="ft-printer"></i></button>
                        </div>
                        <div class="col-md-6 text-right">

                            <button type="button" style="width:100px" id="btncustprnt1" onclick="PrintBill(2)" class="btn btn-primary">Print <i class="ft-printer"></i></button>
                        </div>


                    </div>

                </div>

            </div>
            <div class="modal-footer">

            </div>


        </div>
    </div>
</div>



<script>
    if (usermenu1.indexOf("M230") == -1) {
        $('.ShowAverageCost').css('display', 'none');
    }
    else {
        $('.ShowAverageCost').css('display', '');
    }

    function confirmprint()
    {
        if ($('#tblsalesinvoice tr').length > 0) {
            $('#CustomPrint').show();
            $('#btncustprnt').focus();
        }
        else {
            warningshow('Please select a bill to print', 'txtBillSlNocopy');
            $('#txtBillSlNocopy').select();
        }
    }


    //Custom Print
    function PrintBill(flg)
    {
        $('#CustomPrint').hide();
        $("#custom1").prop("checked", true);

        if ($('#alertpopup').is(':visible')) {       //Custom Print During Save
            if (flg == 1) {
                PrintthisBillWindows('SALES', i, 'WITHBINAUTOMOBILESSAVE');

            }
            else if (flg == 2) {
                if (SalesBillType == 'MOBILE')
                    PrintthisBillWindows('SALES', i, 'MAINMOBILE');
                else if (SalesBillType == 'LOCAL')
                    PrintthisBillWindows('SALES', i, 'MAIN');
                else if (SalesBillType == 'ORYX')
                    PrintthisBillWindows('SALES', i, 'MAINORYX');
                else if (SalesBillType == 'AUTOMOBILES')
                    PrintthisBillWindows('SALES', i, 'MAINAUTOMOBILES');
                else if (SalesBillType == 'DEFAULT')
                    PrintthisBillWindowsNew('SALES', i, 'SPAREPARTSCOPY');
            }
            alertpopuprefresh();
            formrefresh();
            Tbldelete();
        }
        else                      //Custom Print During Copy
        {
            if (flg == 1) {
                PrintthisBillWindows('SALES', i, 'WITHBINAUTOMOBILESCOPY');

            }
            else if (flg == 2) {
                if (SalesBillType == 'MOBILE')
                    PrintthisBillWindows('SALES', i, 'COPYMOBILE');
                else if (SalesBillType == 'LOCAL')
                    PrintthisBillWindows('SALES', i, 'COPY');
                else if (SalesBillType == 'ORYX')
                    PrintthisBillWindows('SALES', i, 'COPYORYX');
                else if (SalesBillType == 'AUTOMOBILES')
                    PrintthisBillWindows('SALES', i, 'COPYAUTOMOBILES');
                else if (SalesBillType == 'DEFAULT')
                    PrintthisBillWindowsNew('SALES', i, 'SPAREPARTS');
            }

        }
    }


    //Print After Copy
  function PrintthisBill()
    {
      if ($('#tblsalesinvoice tr').length > 0) {
          if (SalesBillType == 'MOBILE')
              PrintthisBillWindows('SALES', i, 'COPYMOBILE');
          else if (SalesBillType == 'LOCAL')
              PrintthisBillWindows('SALES', i, 'COPY');
          else if (SalesBillType == 'ORYX')
              PrintthisBillWindows('SALES', i, 'COPYORYX');
          else if (SalesBillType == 'AUTOMOBILES')
              PrintthisBillWindows('SALES', i, 'COPYAUTOMOBILES');
          else if (SalesBillType == 'DEFAULT')
              PrintthisBillWindowsNew('SALES', i, 'SPAREPARTS');
      }
      else {
          warningshow('Please select a bill to print', 'txtBillSlNocopy');
          $('#txtBillSlNocopy').select();
      }

  }

    function getdate() {
        var terms = $($('#select_terms')).find("option:selected").attr("name");
        if ($('#select_terms').val() != 0) {
            var Dt = $('#txtivdate').val();
            var someDate = new Date(Dt.slice(6, 10) + '-' + Dt.slice(3, 5) + '-' + Dt.slice(0, 2));
            someDate.setDate(parseInt(someDate.getDate()) + parseInt(terms));
            var month = +someDate.getMonth() + 1;
            var day = someDate.getDate();

            if (day < 10) {
                day = '0' + day;
            }
            if (month < 10) {
                month = '0' + month;
            }

            newdate = day + "/" + month + "/" + someDate.getFullYear();
            $('#txtduedate').val(newdate);
        }
        else {
            $('#txtduedate').val(CurDate);
        }

    }

    //update salesinvoice
    function UpdateSales()
    {

        //CalcGrandTotal(i);
        //CalcDiscountSplitTax1();
        //roundoffcalc();
        productpopuprefresh();
        var len = $('#tblsalesinvoice tr').length;

        var r = parseFloat($('#txtcrncyrate').val()).toFixed(Decimal);
        $("#txtcrncyrate").val(isNaN(r) ? 0 : r);

        var rowcount = CountRows();

        if ($("#txtBillSlNo").val() == '') {
            warningshow('Please Enter Bill Number', 'txtBillSlNo');
            return false;
        }
        else if (editflag != 0) {
            warningshow('Please Update Edit Mode');
            return false;
        }
        else if (copyflag == 1) {
            return false;
        }
        else if (($("#txtCustId").val() != 0) && (len > 0) && (parseFloat($('#GrandTotal').val()) <= 0) && ($('#disc').val() != 0)) {
            warningshow('GrandTotal Cannot be Negative or Zero', 'disc');
            $('#disc').select();
            return false;
        }
        else if ($("#select_payterms").val() == 0) {
            warningshow('Please Select Payment Type', 'select_payterms');
            return false;
        }
        else if ($.trim($("#txtcustomer").val()) == '') {
            warningshow('Please Select Customer', 'txtcustomer');
            return false;
        }
        else if (($("#txtCustId").val() == 0) && ($("#select_payterms").val() == 2)) {
            warningshow('Please Select Customer', 'txtcustomer');
            return false;
        }
        else if ($('#select_locn').val() == 0) {
            warningshow('Please Select Location', 'select_locn');
            return false;
        }
        else if ($('#select_salesman').val() == 0) {
            warningshow('Please Select Sales Man', 'select_salesman');
            return false;
        }
        else if ($('#select_place').val() == 0) {
            warningshow('Please Select Place', 'select_place');
            return false;
        }
        else if ($('#select_crncy').val() == 0 || $('#select_crncy').val() == null) {
            warningshow('Please Select Currency', 'select_crncy');
            return false;
        }
        else if ($.trim($('#txtcrncyrate').val()) == '' || $.trim($('#txtcrncyrate').val()) == 0) {
            warningshow('Enter Currency Rate', 'txtcrncyrate');
            $('#txtcrncyrate').select();
            return false;
        }
        else if (($('#select_jobno').val() != '') && ($('#ProjectJobId').val() == 0)) {
            warningshow('Please Select A Valid Job', 'select_jobno');
            return false;
        }
        else if (rowcount == 0) {
            warningshow('No Products Added!', 'txtproduct0');
            return false;
        }
        else if ((parseFloat($('#GrandTotal').val()) <= 0) && ($('#disc').val() != 0)) {
            warningshow('GrandTotal Cannot be Negative or Zero', 'disc');
            $('#disc').select();
            return false;
        }
        else if ((parseFloat($('#disc').val()) >= parseFloat($('#CheckForDiscount').val())) && parseFloat($('#disc').val() != 0)) {
            warningshow('Discount must be less than ' + parseFloat($('#CheckForDiscount').val()), 'disc');
            $('#disc').select();
            return false;
        }
        else if (Creditcheck(2) == 1 && Creditflag == 0) {


            $('#promptdiv').show();
            $('#promptflag').val('updatebill'); $('#promptRowId').val(0);
            $('#promptmessage').append('Credit Limit Of ' + parseFloat($('#txtcreditlimit').val() || 0) + ' Exceeded.</br>Enter OTP Continue!');
            $('#promptdata').focus();
        }
        else {
            var a = maxcheck();
            if (a != false) {
                for (var k = 1; k <= i - 1; k++) {
                    var sts = updaterow(k);
                    if (sts == false)
                        break;
                    if (k == (i - 1)) {
                        $('#confirm').show();
                        $('#confirmOk').focus();
                        $('#Confirmflag').val('update'); $('#ConfirmRowId').val(0);
                        $('#confirmmessage').text('Do You Want To Update The Bill?');
                    }
                }
            }

        }
    }

//confirm update
    function updateconfirm()
    {
        $('#Loadingsave').show();
        var r = parseFloat($('#txtcrncyrate').val()).toFixed(Decimal);
        $("#txtcrncyrate").val(isNaN(r) ? 0 : r);

        $('#btnsaveedit').prop('disabled', true);
        var oArray = new Array();
        for (var k = 1; k <= i - 1; k++) {
            var ProductId = $('#PrdtId' + k).val();
            var ProductCode = $('#txtproduct' + k).val();
            var ProductDescr = $('#ProductDesc' + k).val();
            var BillSeriesId = $('#txtBillseriesId').val();
            var BillSlNo = $('#txtBillSlNo').val();
            var UnitId = $('#select_unit' + k).val();
            var UnitName = $('#select_unit' + k).find("option:selected").attr("name");
            var ProdQty = $('#txtquantity' + k).val();
            var ProdRate = $('#txtfcrate' + k).val();
            var FcProdRate = $('#txtrate' + k).val();
            var ProdDisc = $('#txtfcdiscount' + k).val();
            var FcProdDisc = $('#txtdiscount' + k).val();
            var TaxableAmount = $('#txtfctaxableamnt' + k).val();
            var FCTaxableAmount = $('#txttaxableamnt' + k).val();
            var TaxId = $('#select_tax' + k).val();
            var TaxPercent = $('#txttaxpercent' + k).val();
            var TaxAmount = $('#txtfctaxamnt' + k).val();
            var FCTaxAmount = $('#txttaxamnt' + k).val();
            var Amount = $('#txtfcamnt' + k).val();
            var FCAmount = $('#txtamnt' + k).val();
            var LocnId = $('#select_location' + k).val();
            if ($('#select_location' + k).val() == 0 || $('#select_location' + k).val() == '' || $('#select_location' + k).val() == null)
                LocnId = UserLocationId;
            var BatchSNo = 1;
            var Batch = '';
            var PayType = $('#select_payterms').val();
            var LPONumber = $('#txtlpono').val();
            var CustId = $('#txtCustId').val();
            var CustName = $('#txtcustomer').val();
            var CustAddress = $('#txtaddress').val();
            var InvDate = $('#txtivdate').val();
            var InvTerms = $('#select_terms').val();
            var DueDate = $('#txtduedate').val();
            var LocId = $('#select_locn').val();
            if ($('#select_locn').val() == 0 || $('#select_locn').val() == '' || $('#select_locn').val() == null)
                LocId = UserLocationId;
            var SalesManId = $('#select_salesman').val();
            var AreaId = $('#select_place').val();
            var CurrencyId = $('#select_crncy').val();
            var CurrencyRate = $('#txtcrncyrate').val();
            var JobNumber = $('#ProjectJobId').val();
            var GrandTotal = $('#FcGrandTotal').val();
            var RoundGrandTotal = $('#roundgndtotal').val();
            var FCGrandTotal = $('#GrandTotal').val();
            var RoundFCGrandTotal = $('#roundfcgndtotal').val();
            var TotalDiscount = $('#FcTotalDiscount').val();
            var FCTotalDiscount = $('#TotalDiscount').val();
            var TotalTaxable = $('#FcTotalTaxable').val();
            var FCTotTaxable = $('#TotalTaxable').val();
            var TotalTax = $('#FcTotalTax').val();
            var FCTotTax = $('#TotalTax').val();
            var Remarks = $('#txtmsg').val();
            var DeptId = ERPDeptId;
            var UserId = ERPUserId;
            var DelFlag = 1;
            var EnquiryNo = $('#enqno' + k).val();
            var QuotationNo = $('#qutnnum' + k).val();
            var OrderNo = $('#slordeno' + k).val();
            var DeliveryOrderNo = $('#delvno' + k).val();
            var BillDiscount = $('#fcdisc').val();
            var AvgCost = $('#AvgCost' + k).val();
            var TotalCost = $('#TotalAvgCost').val();
            var SOSubId = $('#slordsubid' + k).val();
            var DOrdSubId = $('#delvsubid' + k).val();
            var FcBillDiscount = $('#disc').val();
            var Taxable0 = $('#splittaxable_0').val();
            var Tax0 = $('#splittax_0').val();
            var Taxable5 = $('#splittaxable_5').val();
            var Tax5 = $('#splittax_5').val();
            var Taxable12 = $('#splittaxable_12').val();
            var Tax12 = $('#splittax_12').val();
            var Taxable18 = $('#splittaxable_18').val();
            var Tax18 = $('#splittax_18').val();
            var Taxable28 = $('#splittaxable_28').val();
            var Tax28 = $('#hiddensplittax_28').val();
            var Tax28 = $('#splittax_28').val();
            var TaxId1 = $('#mtaxid1').val();
            var TaxId2 = $('#mtaxid2').val();
            var TaxId3 = $('#mtaxid3').val();
            var TaxId4 = $('#mtaxid4').val();
            var TaxId5 = $('#mtaxid5').val();
            var CashAdvance = $('#CashAdvance').val();

            if (ProductCode != undefined) {

                oArray.push({

                    'ProductId': ProductId,
                    'ProductCode': ProductCode,
                    'ProductDescr': ProductDescr,
                    'BillSeriesId': BillSeriesId,
                    'BillSlNo': BillSlNo,
                    'UnitId': UnitId,
                    'UnitName': UnitName,
                    'ProdQty': ProdQty,
                    'ProdRate': ProdRate,
                    'FcProdRate': FcProdRate,
                    'ProdDisc': ProdDisc,
                    'FcProdDisc': FcProdDisc,
                    'TaxableAmount': TaxableAmount,
                    'FCTaxableAmount': FCTaxableAmount,
                    'TaxId': TaxId,
                    'TaxPercent': TaxPercent,
                    'TaxAmount': TaxAmount,
                    'FCTaxAmount': FCTaxAmount,
                    'Amount': Amount,
                    'FCAmount': FCAmount,
                    'LocnId': LocnId,
                    'BatchSNo': BatchSNo,
                    'Batch': Batch,
                    'PayType': PayType,
                    'LPONumber': LPONumber,
                    'CustId': CustId,
                    'CustName': CustName,
                    'CustAddress': CustAddress,
                    'InvDate': InvDate,
                    'InvTerms': InvTerms,
                    'DueDate': DueDate,
                    'LocId': LocId,
                    'SalesManId': SalesManId,
                    'AreaId': AreaId,
                    'CurrencyId': CurrencyId,
                    'CurrencyRate': CurrencyRate,
                    'JobNumber': JobNumber,
                    'GrandTotal': GrandTotal,
                    'RoundGrandTotal': RoundGrandTotal,
                    'FCGrandTotal': FCGrandTotal,
                    'RoundFCGrandTotal': RoundFCGrandTotal,
                    'TotalDiscount': TotalDiscount,
                    'FCTotalDiscount': FCTotalDiscount,
                    'TotalTaxable': TotalTaxable,
                    'FCTotTaxable': FCTotTaxable,
                    'TotalTax': TotalTax,
                    'FCTotTax': FCTotTax,
                    'Remarks': Remarks,
                    'DeptId': DeptId,
                    'UserId': UserId,
                    'DelFlag': DelFlag,
                    'EnquiryNo': EnquiryNo,
                    'QuotationNo': QuotationNo,
                    'OrderNo': OrderNo,
                    'DeliveryOrderNo': DeliveryOrderNo,
                    'BillDiscount': BillDiscount,
                    'AvgCost': AvgCost,
                    'TotalCost': TotalCost,
                    'SOSubId': SOSubId,
                    'DOrdSubId': DOrdSubId,
                    'FcBillDiscount': FcBillDiscount,
                    'Taxable0': Taxable0,
                    'Tax0': Tax0,
                    'Taxable5': Taxable5,
                    'Tax5': Tax5,
                    'Taxable12': Taxable12,
                    'Tax12': Tax12,
                    'Taxable18': Taxable18,
                    'Tax18': Tax18,
                    'Taxable28': Taxable28,
                    'Tax28': Tax28,
                    'TaxId1': TaxId1,
                    'TaxId2': TaxId2,
                    'TaxId3': TaxId3,
                    'TaxId4': TaxId4,
                    'TaxId5': TaxId5,
                    'CashAdvance': CashAdvance,
                })
            }

        }



        if (oArray != "") {
            var data = { 'SalesInvoiceModel': oArray };
            $.ajax(
        {

            type: "POST",
            url: "../SalesInvoice/SalesInvoiceUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var billno = result.oList[i].BillSlNo;
                    $('#savedbillno').val(billno);
                    $('#CurrentTimeSales').val(result.oList[0].CurrentDate);
                    JsBarcode("#barcode1", $('#txtBillseriesId').val()+'-'+billno);
                    var billsrs = $('#txtBillseriesId').find("option:selected").text();
                    $('#btnsaveedit').prop('disabled', false);
                    $('#Loadingsave').hide();
                    if (status != 0) {
                        Showalerts(status, billsrs, billno);

                    }
                    else {
                        $('#tblAlert tr').remove();
                        $('#alertpopup').show();
                        $('#alertdiv').show();
                        $('#alertdiv1').hide();
                        var Prod1 = "<tr class='jsgrid-row'><td colspan=4><h2 style='color:#FF586B'>Not enough quantity on hand!</h2></td></tr>" +
                          "<tr class='jsgrid-row' style='color:#607D8B'><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>ProductCode</th><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>Description</th><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>Quantity</th><th class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>Location</th></tr>";
                        $('#tblAlert').append(Prod1);
                        $("#btnokalert").focus();
                        for (var i = 0; i <= result.oList.length; i++) {
                            var Prod =
                            "<tr class='jsgrid-row' style='color:#607D8B'>" +
                            "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[i].ProductCode + "</td>" +
                            "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[i].ProductDescr + "</td>" +
                            "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[i].ProdQty + "</td>" +
                            "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center'>" + result.oList[i].LocnName + "</td></tr>";
                            $('#tblAlert').append(Prod);
                        }
                    }
                }
            }
        });
        }
    }



    var m = 1;
    var currentbillno;
    var updateflag = 0;


    function CheckEditInvoce() {
        if ($.trim($('#txtotp').val()) == '') {
            warningshow('Enter OTP', 'txtotp');
        }
        else if ($.trim($('#otpremarks').val()) == '') {
            warningshow('Enter Remarks', 'otpremarks');
        }
        else {
            var data = {};
            data.UserId = ERPUserId;
            data.OTP = $("#txtotp").val();
            data.Remarks = $('#otpremarks').val();
            data.Operation = 'Sales Invoice- OTP - Edit , Bill No : ' + $("#txtBillseriesId ").find("option:selected").text() + ' - ' + $("#txtBillSlNocopy").val();
            data.DeptId = ERPDeptId;
            $.ajax({
                type: "POST",
                url: "../Home/OTPCheckforUser",
                data: data,
                success: function (result) {
                    for (var i = 0; i < result.oList.length; i++) {
                        var status = result.oList[i].Status;
                        OTPCheck(status)
                    }
                }
            });
        }
    }

    function OTPCheck(status) {
        if (status == 1) {
            EditInvoice();
        }
        else {
            warningshow('Invalid OTP', 'txtotp');
            $("#txtotp").select();
        }
    }

    function EditInvoice() {
        $('#OTPDiv').hide();
        $('#txtotp').val('')
        if ($('#tblsalesinvoice tr').length >= 1)
        {
            updateflag = 1;
            copyflag = 0;
            $('.jsgrid-button').prop("disabled", false);
            $('#txtBillSlNo').val($('#txtBillSlNocopy').val());
            $('#btntrnsfr').css("height", '100%');
            $('#select_transfer').css("height", '100%');
            $('#btnedit').hide();
            $('#btnprint').hide();
            $('#btncustomprint').hide();

            $('#btnsaveedit').show();
            $('#copybill').hide();
            $('#btndelete').hide();
            $('#btnwrk').hide();
            $('#bill').show();
            $('.form-control,.btn-outline-primary').prop("disabled", false);
            $('#txttaxpercent0').prop("disabled", true);
            $('#txtamnt0').prop("disabled", true);
            $('#txtBillSlNo').prop("disabled", true);
            $('#txtBillseriesId').prop("disabled", true);

            $('#TotalDiscount').prop("disabled", true);
            $('#TotalTaxable').prop("disabled", true);
            $('#TotalTax').prop("disabled", true);
          //  $('#select_location0').prop("disabled", true);
            $('#select_transfer').prop("disabled", true);
            $('#btntrnsfr').prop("disabled", true);



            $('#TotRoundOff').prop("disabled", true);
            $('#Discountpercent,#TotalProducts,#TotalPdtQty').prop("disabled", true);
            $('#roundoffstatus').prop("disabled", false);

            var ln = parseInt($('#tblsalesinvoice tr').length);
            for (var id = 1; id <= ln; id++) {
                $('#txtproduct' + id).prop('disabled', true);
                //$('#select_unit' + id).prop('disabled', true);
                //$('#txtquantity' + id).prop('disabled', true);
                //$('#txtrate' + id).prop('disabled', true);
                //$('#txtdiscount' + id).prop('disabled', true);
              //  $('#select_tax' + id).prop('disabled', true);
               // $('#select_location' + id).prop('disabled', true);
                $('#ProductDesc' + id).prop('disabled', true);
                $('#AvgCost' + id).prop('disabled', true);
                $('#txttaxableamnt' + id).prop('disabled', true);
                $('#txttaxpercent' + id).prop('disabled', true);
                $('#txttaxamnt' + id).prop('disabled', true);
                $('#txtamnt' + id).prop('disabled', true);

                if (parseFloat($('#txtdiscount' + id).val()) > 0) {
                    $('#disc').prop("disabled", true);
                    $('#disc').val('0.00');
                    $('#Discountpercent').val('');
                    BillDiscountFlag = 1;
                }
            }
            $('#txtduedate').css("background-color", 'WHITE');
            $('#txttaxpercent0').css("background-color", 'WHITE');
            $('#txtamnt0').css("background-color", 'WHITE');
            $('#txtproduct0').focus();

            for (var j = 0; j <= DefaultTaxArray.length; j++) {
                var k = DefaultTaxArray[j];
                $('#splittaxable_' + k).prop("disabled", true);
                $('#hiddensplittaxable_' + k).prop("disabled", true);
                $('#splittax_' + k).prop("disabled", true);
                $('#hiddensplittax_' + k).prop("disabled", true);
            }
            if ((usermenu1.indexOf("M224") != -1)) {
                $("#upload").show();
                $("#fileUpload").show();
            }
            $("#btnExporttoExcel").hide();
        }
        else
        {
            warningshow('Plaease select Bill', 'txtBillSlNocopy');
        }

    }



    //Copy Function
    function GetRows(flg) {
        //if (editflag != 0) {
        //    warningshow('Please Update Edit Mode');
        //}
       if (copyflag==0) {
            var rowcount = CountRows();
            if (rowcount > 0) {
                $('#confirm').show();
                $('#confirmOk').focus();
                $('#Confirmflag').val('copy'); $('#ConfirmRowId').val(0);
                $('#confirmmessage').text('Data will be lost.Do you want to Continue?');
            }
            else {
                SalesCopy(flg);
            }
       }
       else {
           SalesCopy(flg);
       }
    }

    //Clear Fields Before Copy
    function SalesCopy(flg)
    {
        copyflag = 1;

        Tbldelete();

        if ((usermenu1.indexOf("M224") != -1)) {

            $("#btnExporttoExcel").show();
        }

        productpopuprefresh();
        hidepopup(1);

        $('#copybill').show();
        $('#bill').hide();
        $('#slnorow').css("height", '55px');
        currentbillno = $('#txtBlSlNo').val();

        $('#popupdiv').hide();
        $('#txtivdate').val(CurDate);
        $('#txttaxpercent0').val('');
        $('#txtmsg').val('');
        $('#select_payterms').val(0);
        $('#select_transfer').val(0);
        $('#txtcustomer').val('');
        $('#select_terms').val(0);
        $('#txtduedate').val(CurDate);
        $('#txtaddress').val('');
        $('#adr1').val('');
        $('#adr2').val('');
        $('#adr3').val('');
        $('#Trnno').val('');
        $('#txtcreditlimit').val('');

        $('#PhoneNo').val('');


        $('#PriceGroupId').val(0);
        $('#select_locn').val(0);
        $('#select_salesman').val(UserSalesmanId);
        $('#select_place').val(1);
        $('#select_crncy').val(BaseCurrency);
        $('#txtcrncyrate').val(parseFloat($('#select_crncy').find("option:selected").attr("name") || 0).toFixed(Decimal));
        $('#select_jobno').val('');
        $('#txtproduct0').val('');

        $('#select_location0').val(0);
        $('#select_unit0').val(0);
        $('#txtquantity0').val('');
        $('#txtstocktotloseqty0').val(0);
        $('#txtrate0').val('');
        $('#txtdiscount0').val('');
        $('#select_tax0').val(0);
        $('#txtamnt0').val('');
        $('#TotalDiscount').val('0.00');
        $('#TotalTaxable').val('0.00');
        $('#CheckForDiscount').val(0);
        $('#TotalTax').val('0.00');
        $('#GrandTotal').val('0.00');
        $('#disc').val('0.00');
        $('#fcdisc').val('');
        $('#Discountpercent').val('');
        $('#TotRoundOff').val('0.00');
        $('#fcdisc').val('');
        $('#gndtotal').text('');
        $('#fc').text('fc');
        $("#fc").css("opacity", '0');
        GrandTotal = 0;
        $('#gndtotal').text('0.00');
        $('#CashAdvance').val('0.00');


        $('#btntrnsfr').css("height", '85%');
        $('#select_transfer').css("height", '85%');

        $('#txtduedate').css("background-color", '#ECEFF1');
        $('#txttaxpercent0').css("background-color", '#ECEFF1');
        $('#txtamnt0').css("background-color", '#ECEFF1');

        $('.form-control,.btn-outline-primary').prop("disabled", true);
        $('.jsgrid').prop("disabled", true);

        $('#txtBillseriesId').prop("disabled", false);

        $('#btnsubmit').prop("disabled", true);
        $('#btnlist').prop("disabled", true);
        $('#btnadd').prop("disabled", true);
        $('#txtcustomer').prop("disabled", true);
        $('#btnprvs').prop("disabled", false);
        $('#btnnxt,#confirmOk').prop("disabled", false);
        $('#txtBillSlNocopy').prop("disabled", false);
        $('#txtBillSlNocopy').select();
        $('#txtBillSlNocopy').focus();

        $('#btnprvs').show();
        $('#btnnxt').show();

        $('#btnprint').show();
        $('#btncustomprint').show();
        $('#btnsubmit').hide();
        $('#btnlist').hide();
        $("#panel1").hide();

        $("#btnwrk").show();

        TaxClear();


        $('#roundoffstatus').prop("checked", false);
        $('#roundoffstatus').prop("disabled", true);
        closewarningdesc();

        $("#upload").hide();
        $("#fileUpload").hide();
        $("#btnExporttoExcel").prop("disabled", false);
        if (flg == 0) {
            $('#txtBillSlNocopy').focus();
            $('#txtBillSlNocopy').prop('disabled', false);
            $('#txtBillSlNocopy').select();
        }
        else {
            $('#salesviewpopup,#btnviewsales').show();
            $('#select_dept').val(0);
            $('#DateFrom,#DateTo,#select_dept').prop("disabled", false);
            $('#DateFrom').val(CurDate); $('#DateTo').val(CurDate); $('#SelectSalesReports').val(0);
            SalesInvoiceList(1);
            $('.notdis').prop("disabled", false);
            $('#select_dept').focus();
        }
    }
    function SalesInvoiceList() {
        $('#Loadingsave').show();
        var data = {};
        data.FromDate = $('#DateFrom').val();
        data.ToDate = $('#DateTo').val();
        data.DeptId = $('#select_dept').val();
        data.UserId = ERPUserId;
        $.ajax({
            type: "POST",
            url: '../SalesInvoice/SalesInvoiceGetList',
            data: data,
            success: function (result) {

                disable_datatable('tblsalesview');
                $("#txtquantity0,#txtproduct0").blur();
                $('#tblsalesview tr').remove();

                var ProdRow = "<thead><tr><th class='text-left' style='width:5%' >SalesInvoice</th><th style='width:5%' class='text-center'>Department</th><th style='width:5%' class='text-center'>Date</th><th style='width:15%'>CustomerName</th><th style='width:16%'>Address</th><th style='width:2%'>SalesMan</th><th style='width:10%'>User</th><th style='width:5%'>Location</th><th  style='width:5%'  class='text-right' >GrandTotal</th><th style='width:8%'>Bill#</th><th style='width:3%'></th></tr>" +
                                   "<tr><th class='text-left' style='width:5%'>SalesInvoice</th><th style='width:5%' class='text-center'> Department</th><th class='text-center' style='width:5%'>Date</th><th style='width:15%'>CustomerName</th><th style='width:16%'>Address</th><th style='width:2%'>SalesMan</th><th style='width:10%'>User</th><th style='width:5%'>Location</th><th  style='width:5%'  class='text-right'>GrandTotal</th><th style='width:8%'>Bill#</th><th style='width:3%'> </th></tr></thead><tbody>";

                if (result.length != 0) {

                    for (var n = 0; n < result.length; n++) {

                        ProdRow += "<tr class='jsgrid-row' ondblclick='SalesGetCall(" + result[n].BillSeriesId + "," + result[n].BillSlNo + "," + result[n].DeptId + ",1)'>" +
                           "<td class='text-left'> " + result[n].BillDescription + " - " + result[n].BillSlNo + "</td>" +
                            "<td class='text-center'>" + result[n].DepartmentName + " </td>" +
                           "<td class='text-center'>" + result[n].InvDate + "                                   </td>" +
                           "<td  class='text-left'>" + result[n].CustName + "                                   </td>" +
                           "<td  class='text-left'>" + result[n].CustAddress + "                                   </td>" +
                           "<td class='text-left'>" + result[n].SalesMan + "                                   </td>" +
                           "<td class='text-left'>" + result[n].UserName + "                                   </td>" +
                           "<td class='text-left'>" + result[n].Location + "                                   </td>" +
                           "<td class='text-right'>" + parseFloat(result[n].FCGrandTotal || 0).toFixed(Decimal) + " </td>" +
                            "<td class='text-left'>" + result[n].BillSlNo + "                                   </td>" +
                            "<td style='width:3%' class='text-center'>" +
                            "<button class='btn white btn-round btn-xs' type='button' style='background-color:#FF9800;font-size:smaller;margin:0' onclick='SalesGetCall(" + result[n].BillSeriesId + "," + result[n].BillSlNo + "," + result[n].DeptId + ",2)' data-toggle='tooltip' data-placement='top' data-original-title=Print><i class='ft-printer'></i></button>" +
                            "</td>" +
                            "</tr>";
                    }
                    $('#tblsalesview').html(ProdRow + '</tbody>');
                    datatableWithsearch('tblsalesview', 'Multiple');
                    $('#tblsalesview').scrollTop(0);

                }
                else {
                    $('#tblsalesview').html(ProdRow + '</tbody>');
                    datatableWithsearch('tblsalesview', 'Multiple');
                }
                $('#Loadingsave').hide();
            }
        });
    }



    function SalesGetCall(BillSeriesId, BillSlNo, DeptId, type) {
        var data = {};
        data.BillSeriesId = BillSeriesId;
        data.BillSlNo = BillSlNo;
        data.DeptId = DeptId;
        $.ajax({
            type: "POST",
            url: "../SalesInvoice/SalesGetandGets",
            data: data,
            success: function (result) {
                Tbldelete();
                copyrefresh();
                TaxClear();
                //$("#btndelete,#btnsaveedit,#btnedit").hide();
                if (result.oList.length > 0) {
                    if (DeptArray.includes(result.oList[0].DeptId)) {
                        if (result.oList[0].DeptId == ERPDeptId) {
                            $('#btnedit').show();
                            $("#btndelete").show();
                        }
                        else {
                            $('#btnedit').hide();
                            $("#btndelete").hide();
                        }
                        $('#disc').val(parseFloat(result.oList[0].BillDiscount || 0).toFixed(Decimal));
                        $('#GrandTotal').val((parseFloat(result.oList[0].GrandTotal || 0).toFixed(Decimal)));
                        $('#TotalTaxable').val((parseFloat(result.oList[0].TotalTaxable || 0).toFixed(Decimal)));
                        $('#HiddenTotal').val((parseFloat(result.oList[0].TotalTaxable || 0).toFixed(Decimal)));
                        $('#TotalDiscount').val((parseFloat(result.oList[0].TotalDiscount || 0).toFixed(Decimal)));
                        $('#TotalTax').val((parseFloat(result.oList[0].TotalTax || 0).toFixed(Decimal)));
                        CalcDiscountSplitTax1();
                        SalesGets(result.oList);
                        if (type == 0) {
                            $('#txtBillSlNocopy').focus();
                            $('#txtBillSlNocopy').select();
                        }
                        else {
                            $('.arrow,.tooltip-inner').hide();
                            $('#salesviewpopup').hide();
                            if (type == 2) { PrintthisBill(1); }
                        }
                    }
                    else {
                        $('#btnedit').hide();
                        $("#btndelete").hide();
                        $('#btndept').prop('disabled', false);
                        $('#deptmsg').text('')
                        $('#deptmsg').append('Return NO : ' + $('#txtBillseriesId').find("option:selected").text() + ' - ' + result.oList[0].ReturnNo + ' is From </br> Department - ' + result.oList[0].DepartmentName);
                        $('#deptdiv').show();
                        $('#btndept').focus();
                    }
                }
                else {
                    $('#returndiv').show();
                    $('#returnmsg').append('<h2>Return Bill ' + $('#txtBillseriesId').find("option:selected").text() + ' - ' + BillSlNo + ' Not Exists!</h2>');
                    $('#btnreturn').focus();
                }
                $('#btnsubmit').prop("disabled", true);
                $('#btnlist').prop("disabled", true);
                $('#btnadd').prop("disabled", true);
            }
        });
    }


    //Next-Prev Button For Copy
    function GetBillPrevousornext(Value)
    {
        $('#Warningpopup').fadeOut();
            $('#txtBillSlNocopy').prop("disabled", false);
            $('#Warningpopup').fadeOut();

            if ($('#txtBillSlNocopy').val() == '' && Value==-1) {
                $('#txtBillSlNocopy').focus();
                $('#txtBillSlNocopy').val(($('#txtBlSlNo').val()));
            }
           else if ($('#txtBillSlNocopy').val() == '' && Value == 1) {
                $('#txtBillSlNocopy').focus();
                $('#txtBillSlNocopy').val(0);
            }


            var Billno = parseInt($('#txtBillSlNocopy').val() || 0);
            Billno = Billno + Value;

            if (((currentbillno == 1) && (Billno == 0))) {

                warningshow('Bill Number Not Valid', 'txtBillSlNocopy');
                return false;

            }
            else if ((Billno < 0) || (Billno >= $('#txtBlSlNo').val())) {

                warningshow('Bill Number Not Valid', 'txtBillSlNocopy');
                $('#txtBillSlNocopy').select();
                return false;

            }
            else if (Billno == 0) {

                warningshow('Bill Number Not Valid', 'txtBillSlNocopy');
                $('#txtBillSlNocopy').select();
                return false;

            }
            else {

                $('#txtBillSlNocopy').val(Billno);
                var data = {};
                data.BillSeriesId = $('#txtBillseriesId').val();
                data.BillSlNo = Billno;
                data.DeptId = ERPDeptId;
                $.ajax({
                    type: "POST",
                    url: "../SalesInvoice/SalesGetandGets",
                    data: data,
                    success: function (result) {
                        cleargridids();
                        Tbldelete();
                        copyrefresh();
                        $('#txtBillSlNocopy').focus();
                        $('#txtBillSlNocopy').select();
                        $('#btnsubmit').prop("disabled", true);
                        $('#btnlist').prop("disabled", true);
                        $('#btnadd').prop("disabled", true);

                        JsBarcode("#barcode1", $('#txtBillseriesId').val() + '-' + data.BillSlNo);
                        TaxClear();
                        if (result.oList.length > 0)
                        {
                            if (DeptArray.includes(result.oList[0].DeptId)) {
                                if (result.oList[0].DeptId == ERPDeptId) {
                                    $('#btnedit').show();
                                    $("#btndelete").show();
                                }
                                else {
                                    $('#btnedit').hide();
                                    $("#btndelete").hide();
                                }
                                SalesGets(result.oList);
                            }
                            else {
                                warningshow('Bill NO : ' + $('#txtBillseriesId').find("option:selected").text() + ' - ' + result.oList[0].BillSlNo + ' is From Department - ' + result.oList[0].DepartmentName);
                                $('#btnedit').hide();
                                $("#btndelete").hide();
                            }
                        }

                    }
                });
            }
    }

    //Copy Function For Sales Invoice
    function SalesGets(result) {




        if (result[0].FCGrandTotal > result[0].CreditLimit)
            Creditflag = 1;
        else
            Creditflag = 0;

        for (var n = 0; n < result.length; n++) {
            var bins = '';

            if (result[n].LocnId == 1)
            {
                if (result[n].Bin_A != '') { bins = bins + result[n].Bin_A; }
            }
            else if (result[n].LocnId == 2)
            {
                if (result[n].Bin_B != '') { bins = bins + result[n].Bin_B; }
            }
            else if(result[n].LocnId == 3)
            {
                if (result[n].Bin_C != '') {  bins = bins + result[n].Bin_C; }
            }
            else if (result[n].LocnId == 4) {
                if (result[n].Bin_D != '') {  bins = bins + result[n].Bin_D; }
            }
            else if (result[n].LocnId == 5) {
                if (result[n].Bin_E != '') {  bins = bins + result[n].Bin_E; }
            }
            else if (result[n].LocnId == 6) {
                if (result[n].Bin_F != '') {  bins = bins + result[n].Bin_F; }
            }
            else if (result[n].LocnId == 7) {
                if (result[n].Bin_G != '') {  bins = bins + result[n].Bin_G; }
            }
            else if (result[n].LocnId == 8) {
                if (result[n].Bin_H != '') {  bins = bins + result[n].Bin_H; }

            }
            $('#SalesDepartment').val(result[n].DepartmentName);
            $('#CurrentTimeSales').val(result[n].CurrentDate);
                $('#txtBillSlNocopy').val(result[n].BillSlNo);
                $('#txtSalesNo').val(result[n].BillSlNo);
                $('#txtBillseriesId').val(result[n].BillSeriesId);
                $('#txtcustomer').val(result[n].CustName);
                $('#txtCustId').val(result[n].CustId);
                $('#txtaddress').val(result[n].CustAddress);
                $('#select_payterms').val(result[n].PayType);

                $('#select_terms').val(result[n].InvTerms);
                $('#txtduedate').val(result[n].DueDate);
                $('#CashAdvance').val((result[n].PdtCashAdvance).toFixed(Decimal));
                $('#txtcreditlimit').val((result[n].CreditLimit || 0).toFixed(Decimal));


                if (result[n].SalesManId != 0 || result[n].SalesManId != '')
                    $('#select_salesman').val(result[n].SalesManId);
                else
                    $('#select_salesman').val(UserSalesmanId);
                if (result[n].AreaId != 0 || result[n].AreaId != '')
                    $('#select_place').val(result[n].AreaId);
                else
                    $('#select_place').val(0);
                if (result[n].CurrencyId != 0 || result[n].CurrencyId != '') {
                    $('#select_crncy').val(result[n].CurrencyId);
                    $('#txtcrncyrate').val(parseFloat(result[n].CurrencyRate || 0).toFixed(Decimal));
                }
                else {
                    $('#select_crncy').val(BaseCurrency);
                    $('#txtcrncyrate').val(parseFloat($('#select_crncy').find("option:selected").attr("name") || 0).toFixed(Decimal));
                }
                $('#select_locn').val(result[n].LocId);
                $('#select_location0').val($('#select_locn').val());
                $('#select_jobno').val(result[n].JobCode);
                $('#GrandTotal').val((parseFloat(result[n].FCGrandTotal).toFixed(Decimal)));
                $('#FcGrandTotal').val((parseFloat(result[n].GrandTotal).toFixed(Decimal)));
                $('#TotalTaxable').val((parseFloat(result[n].TotalTaxable).toFixed(Decimal)));
                $('#FcTotalTaxable').val((parseFloat(result[n].FCTotTaxable).toFixed(Decimal)));
                $('#TotalDiscount').val((parseFloat(result[n].TotalDiscount).toFixed(Decimal)));
                $('#FcTotalDiscount').val((parseFloat(result[n].FCTotalDiscount).toFixed(Decimal)));
                $('#TotalTax').val((parseFloat(result[n].TotalTax).toFixed(Decimal)));
                $('#FcTotalTax').val((parseFloat(result[n].FCTotTax).toFixed(Decimal)));
                $('#txtmsg').val(result[n].Remarks);
                $('#gndtotal').text(parseFloat(result[n].GrandTotal).toFixed(Decimal));
                $('#ProjectJobId').val(result[n].JobNumber);
                $('#TotalAvgCost').val((parseFloat(result[n].TotalCost).toFixed(Decimal)));
                $('#txtivdate').val(result[n].InvDate);
                $('#disc').val(parseFloat(result[n].BillDiscount).toFixed(Decimal));
                $('#fcdisc').val(parseFloat(result[n].FcBillDiscount).toFixed(Decimal));
                $('#Trnno').val(result[n].LPONumber);
                $('#txtlpono').val(result[n].LPONumber);
                $('#PhoneNo').val(result[n].PhoneNumber);

                if (result[n].RoundFCGrandTotal != 0) {
                    $('#roundoffstatus').prop("checked", true);
                    $('#TotRoundOff').val(parseFloat(result[n].RoundFCGrandTotal).toFixed(Decimal) || 0);
                    $('#roundgndtotal').val(parseFloat(result[n].RoundGrandTotal).toFixed(Decimal) || 0);
                    $('#roundfcgndtotal').val(parseFloat(result[n].RoundFCGrandTotal).toFixed(Decimal) || 0);
                }
                else {
                    $('#roundoffstatus').prop("checked", false);
                    $('#TotRoundOff').val('0.00');
                    $('#roundgndtotal').val('0.00');
                    $('#roundfcgndtotal').val('0.00');
                }

                var rowcount = CountRows();
                if (rowcount == 0) {
                    i = 1;
                }

                BillDiscountFlag = 0;
                var slno = rowcount + 1;
                var id = parseInt(n + 1);

                var Otherdescription = "";
                if (result[n].Otherdescription != undefined)
                    Otherdescription = result[n].Otherdescription;

                var desc = result[n].ProductDescr;
                var j = 0, strLength = desc.length;
                for (j; j < strLength; j++) { desc = desc.replace(" ", "#%#"); }

                var code = result[n].ProductCode;
                var k = 0, strLength1 = code.length;
                for (k; k < strLength1; k++) { code = code.replace(" ", "#%#"); }

                var ProdRow1 = "<tr onclick=GetproddetailsGrid(" + id + "),GetPrdtId(" + result[n].ProductId + ",'" + desc + "','" + code + "'," + 3 + ") onfocusout='updaterow(" + id + ")'  id=" + 'row' + id + " class='jsgrid-row'>" +
                          "<td id= 'col13_" + id + "' class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:15px'><input class='jsgrid-button jsgrid-delete-button jsgrid-align-center' id='btnrodelt' type='button' onclick='rowdelete(" + id + ")' title='Delete'></td>" +
                          "<td id=" + 'td' + id + " class='jsgrid-cell' style='width:15px;text-align:center'>" + slno + " </td>" +
                          "<td class='jsgrid-cell jsgrid-align-right' style='width:40px;text-align:center'><input type='text' id=" + 'slordeno' + id + " style='display:none' value='" + result[n].OrderNo + "' /><input type='text' id=" + 'delvno' + id + " style='display:none' value='" + result[n].DeliveryOrderNo + "' /><input type='text' id=" + 'slordsubid' + id + " style='display:none' value='" + result[n].SOSubId + "' /><input type='text' id=" + 'delvsubid' + id + " style='display:none' value='" + result[n].DOrdSubId + "' /><input type='text' style='display:none;height:30px' id=" + 'Otherdescription' + id + " value='" + Otherdescription + "'><input type='text' id=" + 'PrdtId' + id + " style='display:none' value='" + result[n].ProductId + "' /><input type='text' style='height:30px;background-color:white' disabled='' class='form-control text-left' id=" + 'txtproduct' + id + " value='" + result[n].ProductCode + "' data-toggle='tooltip' title='" + result[n].ProductCode + "'></td>" +
                          "<td class='jsgrid-cell jsgrid-align-right' style='width:110px;text-align:center'><input type='text' style='height:30px;background-color:white' disabled='' class='form-control text-left' id=" + 'ProductDesc' + id + " value='" + result[n].ProductDescr + "' data-toggle='tooltip' title='" + result[n].ProductDescr + "'></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'><select disabled='' id=" + 'select_unit' + id + " style='background-color:white;height:30px' class='form-control' onchange='changeunit(" + id + ",this)' onkeydown=Focusnextgrid(event,'u'," + id + ") onfocusout=focusoutgrid('u'," + id + ") onfocusin=focusingrid('u'," + id + ")>" + UnitSelect + "</select></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:40px'><select id=" + 'select_location' + id + " value=" + result[n].LocnId + " style='background-color:white;height:30px' disabled='' class='form-control' onchange ='GetBin(" + id + "," + result[n].ProductId + ",0)'  onkeydown=Focusnextgrid(event,'l'," + id + ") onfocusout=focusoutgrid('l'," + id + ") onfocusin=focusingrid('l'," + id + ")>" + LocnSelect + "</select></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'><input type='text' disabled='' class='form-control text-center' id=" + 'txtquantity' + id + " value=" + result[n].ProdQty + " style='background-color:white;height:30px' onkeyup='checkqty(" + id + "),amountcalculation(" + id + ")' onkeydown=Focusnextgrid(event,'q'," + id + ") onkeypress=isNumberInt(event,this) onfocusout=focusoutgrid('q'," + id + ") onfocusin=focusingrid('q'," + id + ")><input type='text' class='form-control text-center' id=" + 'txtstocktotloseqty' + id + " value='0' style='display:none'></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center' style='width:30px'> <input type='text' id=" + 'txtfcrate' + id + " value=" + parseFloat(result[n].FcProdRate).toFixed(Decimal) + "  style='display:none'><input type='text' disabled='' class='form-control text-center' id=" + 'txtrate' + id + " value=" + parseFloat(result[n].ProdRate).toFixed(Decimal) + " style='background-color:white;height:30px' onkeyup='amountcalculation(" + id + ")' onkeypress=isNumber(event,this) onkeydown=Focusnextgrid(event,'r'," + id + ") onfocusout=focusoutgrid('r'," + id + ") onfocusin=focusingrid('r'," + id + ")></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfcdiscount' + id + " value=" + parseFloat(result[n].FcProdDisc).toFixed(Decimal) + "  style='display:none'><input type='text' disabled='' id=" + 'txtdiscount' + id + " class='form-control text-center' style='background-color:white;height:30px' value=" + parseFloat(result[n].ProdDisc).toFixed(Decimal) + " onkeyup='amountcalculation(" + id + ")' onkeypress=isNumber(event,this) onkeydown=Focusnextgrid(event,'d'," + id + ") onfocusout=focusoutgrid('d'," + id + ") onfocusin=focusingrid('d'," + id + ")></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:40px'><input type='text' id=" + 'txtfctaxableamnt' + id + " value=" + parseFloat(result[n].FCTaxableAmount).toFixed(Decimal) + "  style='display:none'><input type='text' disabled='' class='form-control text-center' style='background-color:white;height:30px' id=" + 'txttaxableamnt' + id + " value=" + parseFloat(result[n].TaxableAmount).toFixed(Decimal) + " onkeyup='amountcalculation(" + id + ")'></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center' style='width:38px'><select style='background-color:white;height:30px' disabled='' id=" + 'select_tax' + id + " class='form-control' onchange='ChangeTax(" + id + ",this)' onkeydown=Focusnextgrid(event,'t'," + id + ") onfocusout=focusoutgrid('t'," + id + ") onfocusin=focusingrid('t'," + id + ")>" + TaxSelect + "</select></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:22px'><input typ='text' disabled='' style='background-color:white;height:30px' class='form-control text-center' id=" + 'txttaxpercent' + id + " value=" + result[n].TaxPercent + " onkeyup='amountcalculation(" + id + ")'></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfctaxamnt' + id + " value=" + parseFloat(result[n].FCTaxAmount).toFixed(Decimal) + "  style='display:none'><input typ='text' style='background-color:white;height:30px' class='form-control text-center'  id=" + 'txttaxamnt' + id + " value=" + parseFloat(result[n].TaxAmount).toFixed(Decimal) + " disabled=''></td>" +
                          "<td class='jsgrid-cell jsgrid-control-field jsgrid-align-center' style='width:30px'><input type='text' id=" + 'txtfcamnt' + id + " value=" + parseFloat(result[n].FCAmount).toFixed(Decimal) + "  style='display:none'><input typ='text' class='form-control text-center' style='background-color:white;height:30px' disabled='' id=" + 'txtamnt' + id + " value=" + parseFloat(result[n].Amount).toFixed(Decimal) + "></td>" +
                          "<td class='jsgrid-cell jsgrid-align-center ShowAverageCost' style='width:30px'><input type='text' id=" + 'LineAvgCost' + id + " value=" + (result[n].AvgCost * result[n].ProdQty) + " style='display:none'> <input type='text' disabled='' class='form-control text-center' id=" + 'AvgCost' + id + " value=" + parseFloat(result[n].AvgCost).toFixed(Decimal) + " style='background-color:white;height:30px'></td>" +
                          "<td style='display:none' id=" + 'Bin' + id + ">" + bins + "</td>" +
                          "</tr>";
                $('#tblsalesinvoice').append(ProdRow1);
                $('#select_unit' + id).val(result[n].UnitId);
                $('#select_tax' + id).val(result[n].TaxId);
                $('#select_location' + id).val(result[n].LocnId);

                TaxSplit(id);

                $('.jsgrid-button').prop("disabled", true);
                i++;

            }
            CalcGrandTotal(i);
            CalcDiscountSplitTax1();
            roundoffcalc();

            $('#proddiv').animate({ scrollTop: 5000 }, 900);
            totalproducts();
            if (usermenu1.indexOf("M230") == -1) {
                $('.ShowAverageCost').css('display', 'none');
            }
            else {
                $('.ShowAverageCost').css('display', '');
            }

    }

    $('#txtivdate').val(CurDate);
    $('#txtduedate').val(CurDate);
    $("#txtcustomer").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.CustName = $("#txtcustomer").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2ph',
                            label: item.CustName,
                            label1: item.CustAccount,
                            label2:item.PhoneNumber,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1 + '\n' + item.CustState1,
                            Street:item.CustStreet1,
                            City: item.CustCity1,
                            State: item.CustState1,
                            TRNNumber: item.TRNNumber,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            PriceGroupId: item.PriceGroupId,
                            PhoneNumber: item.PhoneNumber,
                            CreditLimit:item.CreditLimit,
                            headers: ["Customer Name", "Account Code","Phone No"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#txtcustomer').val(ui.item.CustName);
            $('#txtaddress').val(ui.item.Address);
            $('#txtCustId').val(ui.item.CustId);
            if (ui.item.SalesmanId != 0 && ui.item.SalesmanId!=null)
            $('#select_salesman').val(ui.item.SalesmanId);
            $('#select_crncy').val(ui.item.CurncyId);
            $('#txtcrncyrate').val(parseFloat($('#select_crncy').find("option:selected").attr("name") || 0).toFixed(Decimal));
            $('#select_terms').val(ui.item.CustTermsId || 0);
            $('#adr1').val(ui.item.Street);
            $('#adr2').val(ui.item.City);
            $('#adr3').val(ui.item.State);
            $('#Trnno').val(ui.item.TRNNumber);
            $('#txtlpono').val(ui.item.TRNNumber);

            $('#PhoneNo').val(ui.item.PhoneNumber);
            $('#txtcreditlimit').val(ui.item.CreditLimit);


            if (ui.item.AreaId != 0)
            $('#select_place').val(ui.item.AreaId||0);

            $('#PriceGroupId').val(ui.item.PriceGroupId || 0);
            getdate();
            for (j = 0; j <= i; j++) {
                amountcalculation(j);
            }
            CalcGrandTotal(i);
            $('#disc').val('0.00');
            $('#Discountpercent').val('');
            CalcDiscountSplitTax1();
            roundoffcalc();

            CustDuedate(ui.item.CustId);



        },

    });
    $("#txtproduct0").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            if ($('#select_locn').val() == 0) {
                warningshow('Please Select Location', 'select_locn');
                $("#txtproduct0").val('');
                return false;
            }
            else if ($('#txtproduct0').val() != '')
            {
                var data = {};
                data.ItemCode = $("#txtproduct0").val();
                data.LocId = $("#select_locn").val();
                data.DeptId = ERPDeptId;
                data.CustId = $("#txtCustId").val();
                data.UserId = ERPUserId;
                data.ProductMultiPriceId = $("#PriceGroupId").val();
                $.ajax({
                    url: '../SalesInvoice/ProductSearchSales',
                    type: "POST",
                    data: data,
                    dataType: "json",
                    success: function (data) {
                        if (data.length)
                        {
                            response($.map(data, function (item) {
                                return ({
                                    ColCount: '-9',
                                    label: item.ItemCode,
                                    label1: item.Description,
                                    label2: item.UnitName,
                                    label3: item.stocktotloseqty,
                                    label4: item.SellingPrice.toFixed(Decimal),
                                    label5: item.GrpName.substring(0, 15),
                                    label6: item.SbgrpName.substring(0, 15),
                                    label7: item.CategoryName.substring(0, 15),
                                    label8: item.SubCategoryName.substring(0, 15),

                                    stocktotloseqty: item.stocktotloseqty,
                                    Unit: item.UnitId,
                                    Tax: item.VatId,
                                    Taxpercent: item.VatPer,
                                    Rates: item.SellingPrice,
                                    UnitName: item.UnitName,
                                    ProductId: item.ItemId,
                                    Product: item.ItemCode,
                                    ProductDesc: item.Description,
                                    LPCost: item.LPCost,
                                    AvgCost: item.AvgCost,
                                    Otherdescription: item.Otherdescription,
                                    MRP: item.MRP,
                                    headers: ["Code", "Description", "Unit", "Quantity", "Price", "Group/Manufacturer", "SubGroup", "Category", "SubCategory"]
                                })
                            }));
                        }
                    else
                    {

                        hidepopup(1);
                    }
                    }
                })
            }

        },
        autoFocus: true,
        response: function (event, ui) {                                                                         //Automatically Select Item while scanning
            if (ui.content.length == 1) {
                ui.item = ui.content[0];
                $(this).data('ui-autocomplete')._trigger('select', 'autocompleteselect', ui);
                $(this).autocomplete('close');
            }
        },
        select: function (event, ui) {


            var ProdFlag = 0;
            var allow = 0;

            for (var p = 1; p <= i; p++) {
                if (ui.item.ProductId==$('#PrdtId' + p).val()) {
                    ProdFlag = 1;
                }
            }
            if (ProdFlag == 1) {        //Prodcut Already added in grid

                $("#txtproduct0,#select_location0,#select_unit0,#txtquantity0,#txtrate0,#txtdiscount0,#select_tax0").blur();
                $('#modal_dialog').show();
                $('#btnNo').focus();

                dialog(function () {        // Ok Button

                    $('#modal_dialog').hide();
                    $('#txtquantity0').focus();

                                                                                  //Select Begin
                    $('#descpopup').text('');
                    $('#descpopup').text(ui.item.ProductDesc);
                    $('#popupdesc').show();
                    $('#codelength').val((ui.item.Product).length);
                    $('#TransPrdtId0').val(ui.item.ProductId);


                        $('#txtproduct0').val(ui.item.Product);
                        $('#ProductDesc0').val(ui.item.ProductDesc);
                        $('#PrdtId0').val(ui.item.ProductId);
                        $('#Otherdescription0').val(ui.item.Otherdescription);
                        $('#MRP0').val(ui.item.MRP);
                        $('#select_unit0').val(ui.item.Unit);
                        $('#select_tax0').val(ui.item.Tax);
                        $('#txttaxpercent0').val(ui.item.Taxpercent);
                        $('#txtrate0').val((ui.item.Rates).toFixed(Decimal));
                        $('#txtunit').val(ui.item.UnitName);
                        $('#txtstocktotloseqty0').val(ui.item.stocktotloseqty);
                        if ((ui.item.stocktotloseqty <= 0 && (Negativebill == 'NO')) && (ui.item.stocktotloseqty <= 0 && ($("#select_locn").find("option:selected").attr("name") == 0))) {
                            warningshow('No stock!', 'txtproduct0');
                            qtyflag = 1;
                            $('#txtproduct0').select();
                            return false;
                        }
                        else
                        {
                            $('#txtquantity0').val(1);
                            $('#txtquantity0').select();
                        }


                        if (ui.item.UnitName == 'FOC') {
                            foc = 1;
                        }
                        else {
                            foc = 0;
                        }
                        amountcalculation(0);
                        qtyflag = 0;

                        var data = {};
                        data.ProductId = ui.item.ProductId;
                        data.CustId = $("#txtCustId").val();
                        data.DeptId = ERPDeptId;
                        $.ajax({
                            type: "POST",
                            url: '../SalesInvoice/CustomerProductDetailsSearch',
                            data: data,
                            success: function (result) {
                                CustPrdctLoad(result.oList);
                            }
                        });
                        var data = {};
                        data.ItemId = ui.item.ProductId;
                        $.ajax({
                            type: "POST",
                            url: '../Master/ProductMultiPriceGetandGets',
                            data: data,
                            success: function (result) {
                                MultipriceLoad(result.oList);
                            }

                        });

                                                                                   //Select end

             },
             function () {               // Cancel Button

                 $('#modal_dialog').hide();
                 clearrow(0);
                  return false;
             }
            );

            }
           else if (ProdFlag==0)
           {
                                                                               //Select Begin
               $('#descpopup').text('');
               $('#descpopup').text(ui.item.ProductDesc);
               $('#popupdesc').show();
               $('#codelength').val((ui.item.Product).length);
               $('#TransPrdtId0').val(ui.item.ProductId);


               $('#txtproduct0').val(ui.item.Product);
               $('#ProductDesc0').val(ui.item.ProductDesc);
               $('#PrdtId0').val(ui.item.ProductId);
               $('#Otherdescription0').val(ui.item.Otherdescription);
               $('#MRP0').val(ui.item.MRP);
               $('#select_unit0').val(ui.item.Unit);
               $('#select_tax0').val(ui.item.Tax);
               $('#txttaxpercent0').val(ui.item.Taxpercent);
               $('#txtrate0').val((ui.item.Rates).toFixed(Decimal));
               $('#txtunit').val(ui.item.UnitName);
               $('#txtstocktotloseqty0').val(ui.item.stocktotloseqty);
               if ((ui.item.stocktotloseqty <= 0 && (Negativebill == 'NO')) && (ui.item.stocktotloseqty <= 0 && ($("#select_locn").find("option:selected").attr("name") == 0))) {
                   warningshow('No stock!', 'txtproduct0');
                   qtyflag = 1;
                   $('#txtproduct0').select();
                   return false;
               }
               else {
                   $('#txtquantity0').val(1);
                   $('#txtquantity0').select();
               }


               if (ui.item.UnitName == 'FOC') {
                   foc = 1;
               }
               else {
                   foc = 0;
               }
               amountcalculation(0);
               qtyflag = 0;

               var data = {};
               data.ProductId = ui.item.ProductId;
               data.CustId = $("#txtCustId").val();
               data.DeptId = ERPDeptId;
               $.ajax({
                   type: "POST",
                   url: '../SalesInvoice/CustomerProductDetailsSearch',
                   data: data,
                   success: function (result) {
                       CustPrdctLoad(result.oList);
                   }
               });

               var data = {};
               data.ItemId = ui.item.ProductId;
               $.ajax({
                   type: "POST",
                   url: '../Master/ProductMultiPriceGetandGets',
                   data: data,
                   success: function (result) {
                       MultipriceLoad(result.oList);
                   }

               });
                                                 //Select end

            }

        },
    })
    .on('autocompleteselect  autocompletefocus', function (ev, ui) {
        //if (ui)
        //    hidepopup(0);

            var data = {};
            data.ProductId = ui.item.ProductId;
            data.CustId = $("#txtCustId").val();
            data.DeptId = ERPDeptId;
            $.ajax({
                type: "POST",
                url: '../SalesInvoice/CustomerProductDetailsSearch',
                data: data,
                success: function (result) {
                    CustPrdctLoad(result.oList);
                }
            });


    });

    //Confirmbox Function work as browser confirm function
    function dialog(yesCallback, noCallback) {
        $('#btnYes').click(function () {
            yesCallback();
        });
        $('#btnNo').click(function () {
            noCallback();
        });
    }


    function MultipriceLoad(result)
    {
        $('#tblMultiprice td').remove();
        for (var i = 0; i < result.length; i++) {
            var slno = parseInt(i + 1);
            var Multiprice = "<tr>" +
            "<td style='width: auto;text-align:left' id='MpPrice" + slno + "'>" + result[i].Price + " </td>" +
            "<td style='width: auto;text-align:left' id='NoQty" + slno + "'>" + result[i].NoQty + " </td>" +
           "</tr>";
            $('#tblMultiprice').append(Multiprice);
        }
    }

    $("#select_jobno").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.JobCode = $("#select_jobno").val();

            $.ajax({
                url: '../SalesInvoice/JobSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount:'2',
                            label: item.JobCode,
                            label1: item.Description,
                            ProjectJobId: item.ProjectJobId,
                            headers: ["Job Code", "Description"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#txtproduct0').focus();
            $('#ProjectJobId').val(ui.item.ProjectJobId);

            setTimeout(function () {
                $('#select_jobno').val(ui.item.label1);
           });

        },

    });
    $("#txtBillSlNocopy").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            $('#tblsalesinvoice tr').remove();
            currentbillno = $('#txtBlSlNo').val();
            var data = {};
            data.BillSlNo = $("#txtBillSlNocopy").val();
            data.BillSeriesId = $("#txtBillseriesId").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            if (parseInt(data.BillSlNo) < 0 || parseInt(data.BillSlNo) >= currentbillno) {
                warningshow('Bill Number Not Valid', 'txtBillSlNocopy');
            }
            else
            {
                $.ajax({
                    url: '../SalesInvoice/SerialNoSearch',
                    type: "POST",
                    data: data,
                    dataType: "json",
                    //success: function (data) {

                    //    response($.map(data, function (item) {
                    //        return ({
                    //            ColCount: '3',
                    //            label: item.BillSlNo,
                    //            label1: item.CustName,
                    //            label2: item.InvDate,
                    //            billsl: item.BillSlNo,
                    //            billseries: item.BillSeriesId,
                    //            headers: ["Bill No", "Customer Name", "Inv Date"]
                    //        })
                    //    }));
                    //}

                    success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'sl4',
                            label:   item.BillSlNo ,
                            label1: item.CustName,
                            label2: item.DepartmentName + '-' + item.BillDescription,
                            label3: item.InvDate,
                            billsl: item.BillSlNo,
                            billseries: item.BillSeriesId,
                            DepartmentCode: item.DepartmentName,
                            DeptId:item.DeptId,
                            headers: ["Bill No", "Customer Name", "Department-Billseries"]
                        })
                    }));
                }
                })
            }
        },
        autoFocus: true,
        select: function (event, ui) {
            var data = {};
            data.BillSeriesId = ui.item.billseries;
            data.BillSlNo = ui.item.billsl;
            data.DeptId = ui.item.DeptId;
            $.ajax({
                type: "POST",
                url: "../SalesInvoice/SalesGetandGets",
                data: data,
                success: function (result) {
                    TaxClear();
                    $('#btnsubmit').prop("disabled", true);
                    $('#btnlist').prop("disabled", true);
                    $('#btnadd').prop("disabled", true);

                    JsBarcode("#barcode1", $('#txtBillseriesId').val() + '-' + data.BillSlNo);

                    if (result.oList.length > 0) {
                        if (DeptArray.includes(result.oList[0].DeptId)) {
                            if (result.oList[0].DeptId == ERPDeptId) {
                                $('#btnedit').show();
                                $("#btndelete").show();
                            }
                            else {
                                $('#btnedit').hide();
                                $("#btndelete").hide();
                            }
                            SalesGets(result.oList);
                            $('#txtBillSlNo').focus();
                            $('#txtBillSlNocopy').select();
                        }

                        else {
                            $('#btnedit').hide();
                            $("#btndelete").hide();
                            $('#btndept').prop('disabled', false);
                            $('#deptmsg').text('')
                            $('#deptmsg').append('Bill NO : ' + $('#txtBillseriesId').find("option:selected").text() + ' - ' + result.oList[0].BillSlNo + ' is From </br> Department - ' + result.oList[0].DepartmentName);
                            $('#deptdiv').show();
                            $('#btndept').focus();
                        }
                    }
                }
            });
        },

    });
    $("#SearchCustenq").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#SearchCustenq").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#SearchCustenq').val(ui.item.CustName);
            $('#hiddencustIdenq').val(ui.item.CustId);
        },

    });
    $("#SearchCustqtn").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#SearchCustqtn").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#SearchCustqtn').val(ui.item.CustName);
            $('#hiddencustIdqtn').val(ui.item.CustId);
        },

    });
    $("#SearchCustso").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#SearchCustso").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#SearchCustso').val(ui.item.CustName);
            $('#hiddencustIdso').val(ui.item.CustId);
        },

    });
    $("#SearchCustsi").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#SearchCustsi").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#SearchCustsi').val(ui.item.CustName);
            $('#hiddencustIdsi').val(ui.item.CustId);
        },

    });
    $("#SearchCustdo").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#SearchCustdo").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#SearchCustdo').val(ui.item.CustName);
            $('#hiddencustIddo').val(ui.item.CustId);
        },

    });
    $("#BounceCustomer").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.CustName = $("#BounceCustomer").val();
            data.CustType = 'C';
            $.ajax({
                url: '../Master/CustomerOrSupplierSearch',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '-2',
                            label: item.CustName,
                            label1: item.CustAccount,
                            CustName: item.CustName,
                            Address: item.CustStreet1 + '\n' + item.CustCity1,
                            CustId: item.CustId,
                            SalesmanId: item.SalesmanId,
                            CurncyId: item.CurrencyId,
                            CustTermsId: item.CustTermsId,
                            AreaId: item.AreaId,
                            headers: ["Customer Name", "Account Code"]
                        })
                    }));
                }
            })

        },
        autoFocus: true,
        select: function (event, ui) {
            $('#BounceCustomer').val(ui.item.CustName);
            $('#BounceCustId').val(ui.item.CustId);
        },

    });

    $("#SearchProdenq").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

                var data = {};
                data.ItemCode = $("#SearchProdenq").val();
                data.LocId = $("#select_locn").val();
                data.DeptId = ERPDeptId;
                data.CustId = 0;
                data.UserId = ERPUserId;
                data.ProductMultiPriceId = 0;
                $.ajax({
                    url: '../SalesInvoice/ProductSearchSales',
                    type: "POST",
                    data: data,
                    dataType: "json",
                    success: function (data) {

                        response($.map(data, function (item) {
                            return ({
                                ColCount: 'FIVEEnq',
                                label: item.ItemCode,
                                label1: item.Description,
                                label2: item.UnitName,
                                label3: item.stocktotloseqty,
                                label4: item.SellingPrice.toFixed(Decimal),

                                ProductId: item.ItemId,
                                Product: item.ItemCode,
                                ProductDesc: item.Description,
                                headers: ["Product Code", "Product Description", "UnitName", "Quantity", "Price"]
                            })
                        }));
                    }
                })
        },
        autoFocus: true,

        select: function (event, ui) {
                $('#SearchProdenq').val(ui.item.Product);
                $('#hiddenProdIdenq').val(ui.item.ProductId);
        },

    });
    $("#SearchProdqtn").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#SearchProdqtn").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            data.CustId = 0;
            data.UserId = ERPUserId;
            data.ProductMultiPriceId = 0;
            $.ajax({
                url: '../SalesInvoice/ProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'FIVEEnq',
                            label: item.ItemCode,
                            label1: item.Description,
                            label2: item.UnitName,
                            label3: item.stocktotloseqty,
                            label4: item.SellingPrice.toFixed(Decimal),

                            ProductId: item.ItemId,
                            Product: item.ItemCode,
                            ProductDesc: item.Description,
                            headers: ["Product Code", "Product Description", "UnitName", "Quantity", "Price"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#SearchProdqtn').val(ui.item.Product);
            $('#hiddenProdIdqtn').val(ui.item.ProductId);
        },
    });
    $("#SearchProdso").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#SearchProdso").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            data.CustId = 0;
            data.UserId = ERPUserId;
            data.ProductMultiPriceId = 0;
            $.ajax({
                url: '../SalesInvoice/ProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'FIVEEnq',
                            label: item.ItemCode,
                            label1: item.Description,
                            label2: item.UnitName,
                            label3: item.stocktotloseqty,
                            label4: item.SellingPrice.toFixed(Decimal),

                            ProductId: item.ItemId,
                            Product: item.ItemCode,
                            ProductDesc: item.Description,
                            headers: ["Product Code", "Product Description", "UnitName", "Quantity", "Price"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#SearchProdso').val(ui.item.Product);
            $('#hiddenProdIdso').val(ui.item.ProductId);
        },
    });
    $("#SearchProdsi").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#SearchProdsi").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            data.CustId = 0;
            data.UserId = ERPUserId;
            data.ProductMultiPriceId = 0;
            $.ajax({
                url: '../SalesInvoice/ProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'FIVEEnq',
                            label: item.ItemCode,
                            label1: item.Description,
                            label2: item.UnitName,
                            label3: item.stocktotloseqty,
                            label4: item.SellingPrice.toFixed(Decimal),

                            ProductId: item.ItemId,
                            Product: item.ItemCode,
                            ProductDesc: item.Description,
                            headers: ["Product Code", "Product Description", "UnitName", "Quantity", "Price"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#SearchProdsi').val(ui.item.Product);
            $('#hiddenProdIdsi').val(ui.item.ProductId);
        },
    });
    $("#SearchProddo").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#SearchProddo").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            data.CustId = 0;
            data.UserId = ERPUserId;
            data.ProductMultiPriceId = 0;
            $.ajax({
                url: '../SalesInvoice/ProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'FIVEEnq',
                            label: item.ItemCode,
                            label1: item.Description,
                            label2: item.UnitName,
                            label3: item.stocktotloseqty,
                            label4: item.SellingPrice.toFixed(Decimal),

                            ProductId: item.ItemId,
                            Product: item.ItemCode,
                            ProductDesc: item.Description,
                            headers: ["Product Code", "Product Description", "UnitName", "Quantity", "Price"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#SearchProddo').val(ui.item.Product);
            $('#hiddenProdIddo').val(ui.item.ProductId);
        },
    });
    $("#BounceItem").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#BounceItem").val();
            data.LocId = $("#select_locn").val();
            data.DeptId = ERPDeptId;
            data.CustId = 0;
            data.UserId = ERPUserId;
            data.ProductMultiPriceId = 0;
            $.ajax({
                url: '../SalesInvoice/ProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: 'Twoserch',
                            label: item.ItemCode,
                            label1: item.Description,

                            ProductId: item.ItemId,
                            Product: item.ItemCode,
                            ProductDesc: item.Description,
                            headers: ["Code", "Description"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#BounceItem').val(ui.item.Product);
            $('#BounceItemId').val(ui.item.ProductId);
            $('#BounceDesc').val(ui.item.ProductDesc);

        },
    });


    $("#AutoItemCode").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {

            var data = {};
            data.ItemCode = $("#AutoItemCode").val();
            $.ajax({
                url: '../SalesInvoice/AutomobileProductSearchSales',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {

                    response($.map(data, function (item) {
                        return ({
                            ColCount: '2',
                            label: item.ItemCode,
                            label1: item.ItemCode,

                            ProductId: item.ItemId,
                            Product: item.ItemCode,

                            headers: ["Code", "Description"]
                        })
                    }));
                }
            })
        },
        autoFocus: true,

        select: function (event, ui) {
            $('#AutoItemCode').val(ui.item.Product);
            $('#Autoitemid').val(ui.item.ProductId);
            AutoMobileItemList();
        },
    });

    //Catogory AutoComplete
    $("#searchCat").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.CategoryName = $("#searchCat").val();
            data.DeptId = ERPDeptId;
            data.UserId = ERPUserId;
            $.ajax({
                url: '../inventory/CatogorySearchStockAdjustment',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '1',
                            label: item.CategoryName,
                            CategoryName: item.CategoryName,
                            CategoryId: item.CategoryId,
                            headers: ["Catogory Name"],
                        })
                    }));
                }
            })
        },
        autoFocus: true,
        select: function (event, ui) {
            $('#hiddencatno').val(ui.item.CategoryId);
        }
    });

    //subcatogory Search
    $("#searchSubcat").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.SubCategoryName = $("#searchSubcat").val();
            data.CategoryId = $("#hiddencatno").val();
            $.ajax({
                url: '../inventory/SubCatogorySearchStockAdjustment',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '1',
                            label: item.SubCategoryName,
                            SubCategoryName: item.SubCategoryName,
                            SubCategoryId: item.SubCategoryId,
                            headers: ["SubCatogory Name"],
                        })
                    }));
                }
            })
        },
        autoFocus: true,
        select: function (event, ui) {
            $('#hiddensubcatno').val(ui.item.SubCategoryId);
        }
    });
    //Group Search

    $("#searchGroup").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.GrpName = $("#searchGroup").val();
            $.ajax({
                url: '../inventory/GroupSearchStockAdjustment',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '1',
                            label: item.GrpName,
                            GrpName: item.GrpName,
                            GrpId: item.GrpId,
                            headers: ["Group Name"],
                        })
                    }));
                }
            })
        },
        autoFocus: true,
        select: function (event, ui) {
            $('#hiddengrpno').val(ui.item.GrpId);
        }
    });

    //SubGroup Search
    $("#searchSubGroup").autocomplete({
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            var data = {};
            data.SbgrpName = $("#searchSubGroup").val();
            data.GrpId = $("#hiddengrpno").val();
            $.ajax({
                url: '../inventory/SubGroupSearchStockAdjustment',
                type: "POST",
                data: data,
                dataType: "json",
                success: function (data) {
                    response($.map(data, function (item) {
                        return ({
                            ColCount: '1',
                            label: item.SbgrpName,
                            SbgrpName: item.SbgrpName,
                            SbgrpId: item.SbgrpId,
                            headers: ["Sub Group Name"],
                        })
                    }));
                }
            })
        },
        autoFocus: true,
        select: function (event, ui) {
            $('#hiddensubgrpno').val(ui.item.SbgrpId);
        }
    });

    //ItemCode Search
    $("#searchItemCode").autocomplete({                                               //Not Using Now
        delay: 0,
        minLength: 0,
        source: function (request, response) {
            //var grp = '', subgrp = '', cat = '', subcat = '', Condition = ''
            //var GrpId = $('#hiddengrpno').val();
            //var SubGrpId = $('#hiddensubgrpno').val();
            //var CatId = $('#hiddencatno').val();
            //var SubCatID = $('#hiddensubcatno').val();
            //var item = $("#searchItemCode").val();


            //if (GrpId != '') { Condition += 'GroupId=' + GrpId }
            //if (SubGrpId != '') { if (Condition.length == 0) Condition += 'SubGroupId=' + SubGrpId; else Condition += ' and SubGroupId=' + SubGrpId; }
            //if (CatId != '') { if (Condition.length == 0) Condition += 'CategoryId=' + CatId; else Condition += ' and CategoryId=' + CatId; }
            //if (SubCatID != '') { if (Condition.length == 0) Condition += 'SubCategoryId=' + SubCatID; else Condition += ' and SubCategoryId=' + SubCatID; }

            //if (item != '') { if (Condition.length == 0) Condition += '(Description like  ' + "'" + item + "%'or ItemCode like  " + "'" + item + "%')"; else Condition += 'and (Description like  ' + "'" + item + "%'" + ' or ItemCode like  ' + "'" + item + "%')" }

            var h1 = '';
            var h2 = '';
            if ($('#SearchType').val() == 0) { h1 = 'ItemCode'; h2 = 'Description' }
            else if ($('#SearchType').val() == 1) { h1 = 'ItemCode'; h2 = 'Model' }
            else if ($('#SearchType').val() == 2) { h1 = 'Group Code'; h2 = 'Group Name' }
            else if ($('#SearchType').val() == 3) { h1 = 'SubGroup Code'; h2 = 'SubGroup Name' }
            else if ($('#SearchType').val() == 4) { h1 = 'Category Code'; h2 = 'Category Name' }
            else if ($('#SearchType').val() == 5) { h1 = 'SubCategory Code'; h2 = 'SubCategory Name' }


            if ($('#SearchType').val() != 0) {

                if ($.trim($("#searchItemCode").val() != ''))
                    var data = {};
                data.Condition = $("#searchItemCode").val();
                data.invtype = $('#SearchType').val();
                $.ajax({
                    url: '../SalesInvoice/ItemCodeSearchSales',
                    type: "POST",
                    data: data,
                    dataType: "json",
                    success: function (data) {

                        response($.map(data, function (item) {
                            return ({
                                ColCount: 'Twoserch',
                                label: item.ItemCode,
                                label1: item.Description,
                                ItemCode: item.ItemCode,
                                Description: item.Description,
                                ItemId: item.ItemId,
                                headers: [h1, h2],
                            })
                        }));
                    }
                })
            }

        },
        autoFocus: true,
        select: function (event, ui) {

            $("#searchItemCode").val(ui.item.ItemCode);

            if ($('#SearchType').val() == 0) { $('#hiddenitemcode').val(ui.item.ItemId); }
            else if ($('#SearchType').val() == 1) { $('#hiddenitemcode').val(ui.item.ItemId); }
            else if ($('#SearchType').val() == 2) { $('#hiddengrpno').val(ui.item.ItemId); }
            else if ($('#SearchType').val() == 3) { $('#hiddensubgrpno').val(ui.item.ItemId); }
            else if ($('#SearchType').val() == 4) { $('#hiddencatno').val(ui.item.ItemId); }
            else if ($('#SearchType').val() == 5) { $('#hiddensubcatno').val(ui.item.ItemId); }

            MultipleProductBind(2);

        }
    });

//-----------------------Search Id'sClear-----------------------------
    function checkgrptextempty(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key != 13) {
            if ($('#searchGroup').val() == '')
                $('#hiddengrpno').val('');
            else {
                $('#hiddengrpno').val(0);
            }
        }
    }

    function checkSubgrptextempty(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key!= 13) {
            if ($('#searchSubGroup').val() == '')
                $('#hiddensubgrpno').val('');
            else {
                $('#hiddensubgrpno').val(0);
            }
        }
    }

    function checkCategorytextempty(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key != 13) {
            if ($('#searchCat').val() == '')
                $('#hiddencatno').val('');
            else {
                $('#hiddencatno').val(0);
            }
        }
    }

    function checkSubCategorytextempty(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key != 13) {
            if ($('#searchSubcat').val() == '')
                $('#hiddensubcatno').val('');
            else {
                $('#hiddensubcatno').val(0);
            }
        }
    }

    function checkitemtextempty(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;

        if (key == 32) {
            if ($('#SearchType').val() == 0 && $('#searchItemCode').val() != '')
                MultipleProductBind(2);

            if ($('#searchItemCode').val() == '') {
                $('#hiddenitemcode').val('');
                //if ($('#SearchType').val() == 0)
                //$('#btnclearproduct').click();
                clearprodlist(1);
                MultipleProductBind(2);
            }

        }
        else if (key == 40 || key == 13)
        {
            try {
                var row = $('#Productlist').find("td:eq(2)").attr('id').match(/\d+/)[0];

                if (row)
                {
                    $('#qtypr' + row).focus(); $('#qtypr' + row).select();
                    Getproddetails(row);
                    GetPrdtId($('#ItemIdgrid' + row).val(), $('#Itemdescgrid' + row).text(), $('#col' + row).text(), 1);
                    rowbgcolor(row);
                }
            }
            catch (err) {
               // rowbgcolor(0);
            }
        }
    }

    function emptycheckcust(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key != 13) {
            $('#BounceCustId').val('');
        }
    }

    function emptycheckitem(e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key != 13) {
            $('#BounceItemId').val('');
        }
    }

  //-------------------------End---------------------------------------

    //Clear Search Fields in Multiple Product Selection List
    function clearprodlist(flg) {
        $('#searchGroup').val('');
        $('#hiddengrpno').val('');
        $('#searchSubGroup').val('');
        $('#hiddensubgrpno').val('');
        $('#searchCat').val('');
        $('#hiddencatno').val('');
        $('#searchSubcat').val('');
        $('#hiddensubcatno').val('');
        $('#searchItemCode').val('');
        $('#hiddenitemcode').val('');

        if (flg != 0)
        {
          //  MultiPdtArray = [];

        }

        if(flg==1)
        $('#searchItemCode').focus();
    }

    //Load Stock Qty When Location Change  during product add
    function checkqtyload(result) {
        if (result.length == 'undefined')
            $('#txtstocktotloseqty0').val(0);
        else {
            for (var j = 0; j < result.length; j++)
                $('#txtstocktotloseqty0').val(result[j].stocktotloseqty);
        }
    }

    //Check Qty>Stock Qty
    function checkqty(id) {
        if ((($('#txtquantity' + id).attr('name') == 'prdaddqty') && (Negativebill == 'NO')) && (($('#txtquantity' + id).attr('name') == 'prdaddqty') && ($('#select_location'+id).find("option:selected").attr("name") == 0)))
        {
            var pflg = 0;
            var pdtsumqty = 0;
            var pdtsumqty1 = 0;
            for (var p = 1; p <= i; p++) {
                if (($('#PrdtId' + p).val() == $("#PrdtId" + id).val()) && ($('#select_location' + p).val() == $("#select_location" + id).val()) && ($('#txtquantity' + p).attr('name') == 'prdaddqty')) {
                    pflg = 1;
                }
            }
            if (pflg == 0)               //If Product is not in the grid qty must be less than stockqty
            {
                if (($('#PrdtId' + id).val() != 0) && (parseInt($('#txtquantity' + id).val()) > parseInt($('#txtstocktotloseqty' + id).val()))) {
                    warningshow('Not Enough Stock!Available stock is ' + $('#txtstocktotloseqty' + id).val());
                    $('#txtquantity' + id).val('');
                    $('#txtquantity' + id).focus();
                    return false;
                }
            }
            else                         //else qty must be less than stockqty-(totprodqty of grid)
            {
                for (var g = 1; g <= i; g++) {
                    if (g == id)                      //During Edit, add qty of rows except editing row
                        continue;
                    else {
                        if (($('#PrdtId' + g).val() == $("#PrdtId" + id).val()) && ($('#select_location' + g).val() == $("#select_location" + id).val()) && ($('#txtquantity' + g).attr('name') == 'prdaddqty')) {
                            pdtsumqty = parseInt(pdtsumqty) + parseInt($("#txtquantity" + g).val());
                            pdtsumqty1 = parseInt(pdtsumqty);
                        }
                    }
                }
                if ($("#txtquantity" + id).val() > (parseInt($('#txtstocktotloseqty' + id).val()) - pdtsumqty1)) {
                    warningshow('Available Quantity is ' + (parseInt($('#txtstocktotloseqty' + id).val()) - pdtsumqty1), 'txtquantity' + id);
                    $('#txtquantity' + id).val('');
                    $('#txtquantity' + id).focus();
                    return false;
                }
            }
        }


    }

    //Change Rate Based On no of Quantity from pricegroup table
    function checkpricegroup()
    {
        if (($('#PriceGroupId').val() == 0)) {                              //    && ((parseInt($('#txtrate0').val()) == 0)||(parseInt($('#txtrate0').val()) == ''))
            var lng = parseInt($('#tblMultiprice tr').length);
            for (var j = 0; j <= lng; j++) {
                if ( ($('#PrdtId0').val() != 0) && (parseInt($('#txtquantity0').val()) >= parseInt($('#NoQty' + j).text())) && (parseFloat($('#MpPrice' + j).text()).toFixed(Decimal)>0)) {
                    $('#txtrate0').val(parseFloat($('#MpPrice' + j).text()).toFixed(Decimal));
                }
                //else if (($('#PrdtId0').val() != 0) && ($('#txtquantity0').val() == '') && (parseFloat($('#MpPrice' + la).text()).toFixed(Decimal)>0)) {
                //    $('#txtrate0').val('0.00');
                //}

            }
        }
    }



    //Check Rate>Average Rate (check onblur)
    function checkrate(id) {
        if (($('#select_unit' + id).find("option:selected").attr("name") != 'FOC') && (BelowCost == 'NO') && ($('#PrdtId' + id).val() != 0) && ($('#AvgCost' + id).val() != 0) && (parseInt($('#txtrate' + id).val()) < parseInt($('#AvgCost' + id).val()))) {
          warningshow('Rate must be greater than ' + $('#AvgCost' + id).val(), 'txtrate'+id);
          return false;
      }
    }

    var custstats = "Last Selling Price";

    //Product Details Popup
    function CustPrdctLoad(result) {
        $('#tblproductdetails td').remove();
        //$('#PopUpDetail6').text('BINS : ');
        $('#PopUpDetailbin').text('');
        for (var n = 0; n < result.length; n++) {

            var bins = '';
            if ($('#select_location0').val() == 1) { if (result[n].Bin_A != '') { bins = bins + result[n].Bin_A; } }
            else if ($('#select_location0').val() == 2) { if (result[n].Bin_B != '') { bins = bins + result[n].Bin_B; } }
            else if ($('#select_location0').val() == 3) { if (result[n].Bin_C != '') { bins = bins + result[n].Bin_C; } }
            else if ($('#select_location0').val() == 4) { if (result[n].Bin_D != '') { bins = bins + result[n].Bin_D; } }
            else if ($('#select_location0').val() == 5) { if (result[n].Bin_E != '') { bins = bins + result[n].Bin_E; } }
            else if ($('#select_location0').val() == 6) { if (result[n].Bin_F != '') { bins = bins + result[n].Bin_F; } }
            else if ($('#select_location0').val() == 7) { if (result[n].Bin_G != '') { bins = bins + result[n].Bin_G; } }
            else if ($('#select_location0').val() == 8) { if (result[n].Bin_H != '') { bins = bins + result[n].Bin_H; } }



            var custstat;
            if (result[n].LastSellingPrice == 0) {
                custstat = "Last Selling Price";
            }
            else {
                custstat = result[n].custstats;
            }


            $('#productpdiv,#Infospopup').slideDown();
            $('#prodheader').text('Location Stock Details');
            $('#productdiv').show();

            var strr = result[n].Locationstock;
            var strr1 = strr.replace(/&/gi, "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;");
            var strr2 = strr1.replace(/#/gi, "&emsp;");

            //if (result[0].ProductCode!='undefined') {
            //    $('#prodheader').text(result[0].ProductCode);
            //}
            //$('#productdiv').show();

            //var strr = result[n].Locationstock;
            //var strr1 = strr.replace(/&/gi, "&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;");
            //var strr2 = strr1.replace(/#/gi, "&emsp;");
            //var strr3 = strr2.replace(/,/gi, "&nbsp;");



            if (result[n].custstats == 'Last Selling Price' && $('#txtCustId').val() == 0) {
                //$('#PopUpDetail0').text('Location Wise Stock ')
                //$('#PopUpDetail1').text('C : ' + (parseFloat(result[n].AvgCost || 0).toFixed(Decimal)))
                //$('#PopUpDetail2').text('LPC : ' + (parseFloat(result[n].LPCost || 0).toFixed(Decimal)))
                //$('#PopUpDetail3').text('LSP : ' + (parseFloat(result[n].LastSellingPrice || 0).toFixed(Decimal)))
                //$('#PopUpDetail5').text('Total Stock : ' + (result[n].Sumtotqty || 0))
                //$('#PopUpDetail4').hide();

                var ProdRow = "<tr class='jsgrid-row' id='pdctrow'>" +
         "<td style='border:none;font-weight:500;' class='text-left yellow'><b>" + result[0].ProductCode + "</b></td>" +
         "<td style='border:none;font-weight:500' class='text-left'><table width='100%'><tr><td style='border:none;font-weight:500' class='text-left'><b>C : </b>" + (parseFloat(result[n].AvgCost || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>LP : </b>" + (parseFloat(result[n].LPCost || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>LSP : </b>" + (parseFloat(result[n].LastSellingPrice || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>Stock : </b>" + (result[n].Sumtotqty || 0) + "</td>" + "</tr></table></td></tr>" +
         "<tr class='jsgrid-row' id='pdctrow1'><td colspan=4 class='text-left' style='border:none'> " + strr2 + "</td ></tr>";
            }
            else {
                //$('#PopUpDetail4').show();
                //$('#PopUpDetail0').text('Location Wise Stock ')
                //$('#PopUpDetail1').text('C : ' + (parseFloat(result[n].AvgCost || 0).toFixed(Decimal)))
                //$('#PopUpDetail2').text('LPC : ' + (parseFloat(result[n].LPCost || 0).toFixed(Decimal)))
                //$('#PopUpDetail3').text('LSP : ' + (parseFloat(result[n].LastSellingPrice || 0).toFixed(Decimal)))
                //$('#PopUpDetail4').text('CLSP : ' + (parseFloat(result[n].CustLastSellingPrice || 0).toFixed(Decimal)))
                //$('#PopUpDetail5').text('Total Stock : ' + (result[n].Sumtotqty || 0))

                var ProdRow = "<tr class='jsgrid-row' id='pdctrow'>" +
         "<td style='border:none;font-weight:500;' class='text-left yellow'><b>" + result[0].ProductCode + "</b></td>" +
         "<td style='border:none;font-weight:500' class='text-left'><table width='100%'><tr><td style='border:none;font-weight:500' class='text-left'><b>C : </b>" + (parseFloat(result[n].AvgCost || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>LP : </b>" + (parseFloat(result[n].LPCost || 0).toFixed(Decimal)) + "</td>" +
          "<td style='border:none;font-weight:500' class='text-left'><b>CLSP : </b>" + (parseFloat(result[n].CustLastSellingPrice || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>CLSP' : </b>" + (parseFloat(result[n].LastSellingPrice || 0).toFixed(Decimal)) + "</td>" +
         "<td style='border:none;font-weight:500' class='text-left'><b>Stock : </b>" + (result[n].Sumtotqty || 0) + "</td>" + "</tr></table></td></tr>" +
         "<tr class='jsgrid-row' id='pdctrow1'><td colspan=5 class='text-left' style='border:none'> " + strr2 + "</td ></tr>";

            }
            if (bins != "")
            {
                //$('#PopUpDetail6').text('BINS :' + bins)
                $('#PopUpDetailbin').text(bins);
            }


            $('#tblproductdetails').append(ProdRow);


            //var ProdRow1 =
            //   "<tr class='jsgrid-row' id='pdctrow1'><td colspan=5 class='text-left' style='border:none'> " + strr3 + "</td ></tr><tr class='jsgrid-row' style='margin-top:-5px'><td colspan=5 class='text-left' style='border:none'></td ></tr>";
            //$('#tblproductdetails').append(ProdRow1);

            $('#AvgCost0').val(parseFloat(result[n].AvgCost || 0).toFixed(Decimal));
            $('#tbllocqty').attr('border', '1');
            $('#tbllocqty').attr('bordercolor', 'white');
        }
       // hidepopup(0);
    }

    $('#AutoType').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#AutoItemCode').focus();
            $('#AutoItemCode').select();
        }
    });

    $('#AutoItemCode').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            try {
                var row = $('#AutoProductlist').find("td:eq(2)").attr('id').match(/\d+/)[0];
                if(row)
                {
                    if ((($('#Autoitemid').val() != 0) && ($('#Autoitemid').val() != '')) || $('#AutoItemCode').val() == '') {
                        $('#autoqtypr' + row).focus(); $('#autoqtypr' + row).select();
                        Getproddetailsauto(row);
                        GetPrdtId($('#autoItemIdgrid' + row).val(), $('#autoItemdescgrid' + row).text(), $('#autocol' + row).text(), 4);
                    }
                }

            }
            catch (err) {
            }


        }
        else if((key == 37 &&  $('#AutoItemCode').val() == ''))
        {
            $('#AutoType').focus();
        }
        else if (key != 13 && key != 9 && key != 20 && key != 16 && key != 17 && key != 18 && key != 37 && key != 39 && !(key > 111 && key < 124))
        {
            $('#Autoitemid').val('');
            $('#AutoProductlist tr td').remove();
            $('#autopcol1').text("");
            $('#autopcol2').text("");
            $('#AutoItemname').text('');
            $('#autopdthead').css("height", '60px');
        }

    });

    $('#btnautoproduct').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 39) {
                e.preventDefault();
            $('#btnautoclear').focus();
        }
    });

    $('#searchGroup').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#searchSubGroup').focus();
            $('#searchSubGroup').select();
        }
    });
    $('#searchSubGroup').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#searchCat').focus();
            $('#searchCat').select();
        }
    });
    $('#searchCat').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#searchSubcat').focus();
            $('#searchSubcat').select();
        }
    });
    $('#searchSubcat').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#searchItemCode').focus();
            $('#searchItemCode').select();
        }
    });
    $('#searchItemCode').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#btnsearchproduct').focus();
           // $('#btnsearchproduct').select();
        }
    });


    $('#BounceCustomer').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#BounceItem').focus();
            $('#BounceItem').select();
        }
    });

    $('#BounceItem').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#BounceDesc').focus();
            $('#BounceDesc').select();
        }
    });
    $('#BounceDesc').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#BounceRemark').focus();
            $('#BounceRemark').select();
        }
    });
    $('#BounceRemark').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#BounceQty').focus();
            $('#BounceQty').select();
        }
    });
    $('#BounceQty').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 13) {
            e.preventDefault();
            $('#btnaddbounce').focus();
        }
    });

$('#txtquantity0').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        e.preventDefault();
        var inputs = $(this).closest('form').find(':input:visible');
        inputs.eq(inputs.index(this) + 1).focus();
        inputs.eq(inputs.index(this) + 1).select();

    }

});

$('#txtrate0').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        if ( ($('#select_unit0').find("option:selected").attr("name") != 'FOC') && (BelowCost == 'NO') && ($('#PrdtId0').val() != 0) && ($('#AvgCost0').val() != 0) && (parseInt($('#txtrate0').val()) < parseInt($('#AvgCost0').val()))) {
            warningshow('Rate must be greater than ' + $('#AvgCost0').val());
            $('#txtrate0').select();
            return false;
        }
        else
        {
            e.preventDefault();
            var inputs = $(this).closest('form').find(':input:visible');
            inputs.eq(inputs.index(this) + 1).focus();
        }
    }
});



$('#txtdiscount0').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        e.preventDefault();
        var inputs = $(this).closest('form').find(':input:visible');
        $('#btnadd').focus();
    }

});
$('#txtivdate').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        e.preventDefault();
        $('#select_terms').focus();
    }

});
$('#txtcrncyrate').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        e.preventDefault();
        $('#select_jobno').focus();
    }
});
$('#txtcrncyrate').keyup(function (e) {

    for (j = 0; j <= i; j++) {
        amountcalculation(j);
    }
    $('#disc').val('0.00');
    $('#Discountpercent').val('');
    CalcGrandTotal(i);
    CalcDiscountSplitTax1();
    roundoffcalc();
});
$('#txtBillseriesId').keydown(function (e) {
    var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
    if (key == 13) {
        e.preventDefault();
        $('#txtcustomer').focus();
    }

});

function billdetails(BillSlNo, BillSeriesID, DeptId) {
    sessionStorage.setItem("sales_slno", BillSlNo);
    sessionStorage.setItem("sales_srs", BillSeriesID);
    sessionStorage.setItem("sales_deptid", DeptId);
    window.location = "@Url.Action("WorkItemUserNew", "WorkItemUser", new { from = "SalesInvoice" })";
}

 //Date Picker
$(function () {
    $('#txtivdate,#SearchFromdateqtn,#SearchToDateqtn,#SearchFromdateqtn1,#SearchToDateqtn1,#SearchFromdateso,#SearchToDateso,#SearchToDateso1,#SearchFromdateso1').daterangepicker({
        minDate: minDate,
        maxDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
        singleDatePicker: true,
        showDropdowns: true,
        locale: {
            format: 'DD/MM/YYYY'
        }
    });

    $('#SearchFromdatesi,#SearchToDatesi,#SearchFromdatesi1,#SearchToDatesi1,#SearchFromdatedo,#SearchToDatedo,#SearchFromdatedo1,#SearchToDatedo1').daterangepicker({
        minDate: minDate,
     //   maxDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
        singleDatePicker: true,
        showDropdowns: true,
        locale: {
            format: 'DD/MM/YYYY'
        }
    });

    $('#SearchFromdateenq,#SearchToDateenq,#SearchToDateenq1,#SearchFromdateenq1,#txtduedate').daterangepicker({
        minDate: minDate,
      //  maxDate: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
        singleDatePicker: true,
        showDropdowns: true,
        locale: {
            format: 'DD/MM/YYYY'
        }
    });
});


//------------Main Popups Save---------------
function Addpopupwindow(Id) {
    $("#popupdiv").css("margin-top", '0px');
    $('#currencydiv').hide(); $('#areadiv').hide();
    $('#locationdiv').hide(); $('#salesmandiv').hide();
    $('#termsdiv').hide();

    $('#popupdiv').show();


    if (Id == 1) {
        $('#myheader').text('Currency');
        $('#currencydiv').show();
        $('#txt_code').focus();

    }

    else if (Id == 2) {
        GetAreaGroupselect(0);
        $('#myheader').text('Area');
        $('#areadiv').show();
        $('#txtcode').focus();

    }
    else if (Id == 3) {
        $('#myheader').text('Location');
        $('#locationdiv').show();
        $('#LocationCode').focus();
    }
    else if (Id == 4) {
        $('#myheader').text('SalesMan');
        $('#salesmandiv').show();
        $("#popupdiv").css("margin-top", '-130px');
        $('#code').focus();
    }
    else if (Id == 5) {
        $('#myheader').text('Terms');
        $('#termsdiv').show();
        $('#txtdesc').focus();
    }
}
function areagroupadd(Id)
{
    if (Id == 1) {
        $('#areapopupdiv').show();
    $('#armyheader').text('Area Group');
    $('#areagroupdiv').show();
    $('#artxtcode').focus();
 }
 else if(Id==2)
 {

     $('#areapopupdiv').hide();
     $('#areagroupdiv').hide();
     $('#artxtname').val('');
     $('#artxtname').val('');
     $('#artxtdescription').val('');

 }
}
function addpopupjob(Id)
{
    $('#jobpopupdiv').show();
    $('#Jobdiv').hide(); $('#othercostdiv').hide();
    if (Id == 1) {

        $('#Jobdiv').show();
        $('#jobheader').text('JOB');
        $('#othercostdiv').show();
        $('#productjob').focus();
    }
   else if (Id == 2) {
        $('#othercostdiv').show();
        $('#jobheader').text('Other Cost');
        $('#txtdesc').focus();
    }

}
function SaveCurrency(Flag) {
    if ($('#txt_code').val() == "") {
        warningshow('Please Enter Code', 'txt_code');
    }
    else if ($('#txt_cname').val() == "") {
        warningshow('Please Enter Name', 'txt_cname');
    }
    else if ($('#txt_rate').val() == "") {
        warningshow('Please Enter Rate', 'txt_rate');
    }
    else {
        var data = {};   //array
        data.Id = $('#CrncyId').val();
        data.CurrencyCode = $('#txt_code').val();
        data.CurrencyName = $('#txt_cname').val();
        data.CurrencyRate = $('#txt_rate').val();
        data.Remarks = $('#txt_remark').val();
        data.DelFlag = Flag;
        $.ajax({
            type: "POST",
            url: "../Master/CurrencyInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].Id;
                    popupShowalerts(status,1);
                    crncyload(id);
                    $('#txtcrncyrate').val(parseFloat(data.CurrencyRate || 0).toFixed(Decimal));
                    popuprefresh();
                }
            }

        });

    }
}
function SavePlace(Flag) {
    if ($('#txtcode').val() == "") {
        warningshow('Please Enter Code', 'txtcode');
    }
    else if ($('#txtname').val() == "") {
        warningshow('Please Enter Name', 'txtname');
    }
    else if ($('#select_areagroup').val() == "0") {
        warningshow('Please Select Group', 'select_areagroup');
    }
    else {
        var data = {};   //array
        data.AreaId = $('#AreaId').val();;
        data.AreaName = $('#txtname').val();
        data.AreaGrpId = $('#select_areagroup').val();
        data.AreaCode = $('#txtcode').val();
        data.Description = $('#txtdescription').val();
        data.DelFlag = Flag;
        $.ajax({
            type: "POST",
            url: "../Master/AreaInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].AreaId;
                    popupShowalerts(status,1);
                    placeload(id);
                    popuprefresh();

                }
            }
        });

    }


}
function SaveLocation(Flag) {
    if ($('#LocationCode').val() == "") {
        warningshow('Please Enter Code', 'LocationCode');
    }
    else if ($('#LocationName').val() == "") {
        warningshow('Please Enter Name', 'LocationName');
    }
    else {
        var data = {};   //array
        data.LocationId = $('#LocationId').val();;
        data.LocationName = $('#LocationName').val();
        data.LocationCode = $('#LocationCode').val();
        data.LocationDescription = $('#LocationDescription').val();
        data.DelFlag = Flag;
        $.ajax({
            type: "POST",
            url: "../Master/LocationInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].LocationId;
                    LocnLoad(id);
                    popupShowalerts(status,1);
                    popuprefresh();

                }
            }
        });

    }


}
function SaveSalesman(Flag) {
    if ($('#code').val() == "") {
        warningshow('Please Enter Code', 'code');
    }
    else if ($('#txt_fname').val() == "") {
        warningshow('Please Enter  Name', 'txt_fname');
    }
    else if ($('#txt_lname').val() == "") {
        warningshow('Please Enter Last Name', 'txt_lname');
    }
    else {
        var data = {};
        data.Id = $('#SalesmanId').val();
        data.Code = $('#code').val();
        data.FirstName = $('#txt_fname').val();
        data.LastName = $('#txt_lname').val();
        data.TargetAmount = $('#txt_amount').val();
        data.Image = $('file').val();
        data.ContactNumber = $('#txt_contactnumber').val();
        data.Address1 = $('#txt_address1').val();
        data.Address2 = $('#txt_address2').val();
        data.Address3 = $('#txt_address3').val();
        data.DelFlag = Flag;
        $.ajax({
            type: "POST",
            url: "../Master/SalesmanInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].Id;
                    popupShowalerts(status,1);
                    Salesman(id);
                    popuprefresh();

                }
            }
        });
    }

}
function SaveTerms(Flag) {
    if ($('#txtterms').val() == "") {
        warningshow('Please Enter Terms', 'txtterms');
    }
    else {
        var data = {};   //array
        data.TermsId = $('#TermsId').val();;
        data.Terms = $('#txtterms').val();
        data.TermsDescription = $('#txtdesc').val();
        data.DelFlag = Flag;

        $.ajax({
            type: "POST",
            url: "../Master/TermsInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].TermsId;
                    popupShowalerts(status,1);
                    Terms(id);
                    getdate();
                    popuprefresh();

                }
            }
        });

    }


}

function SaveAreagrp(Flag) {
    if ($('#artxtcode').val() == "") {
        warningshow('Please Enter Code', 'artxtcode');
    }
    else if ($('#artxtname').val() == "") {
        warningshow('Please Enter Name', 'artxtname');
    }
    else {
        var data = {};   //array
        data.AreaGrpId = 0;
        data.GroupName = $('#artxtname').val();
        data.AreaCode = $('#artxtcode').val();
        data.Description = $('#artxtdescription').val();
        data.DelFlag = Flag;
        $.ajax({
            type: "POST",
            url: "../Master/AreaGroupInsertandUpdate",
            data: data,
            success: function (result) {
                for (var i = 0; i <= result.oList.length; i++) {
                    var status = result.oList[i].Status;
                    var id = result.oList[i].AreaGrpId;
                    popupShowalerts(status,0);
                    GetAreaGroupselect(id);
                    areagroupadd(2);
                }
            }
        });

    }
}

function AreaGroupLoad(result, AreaGrpId) {
    $("#select_areagroup").empty();
    $("#select_areagroup").append("<option value='0'>Select Group</option>");
    for (var i = 0; i < result.length; i++) {
        $("#select_areagroup").append("<option value='" + result[i].AreaGrpId + "'>" + result[i].AreaName + "</option>");
    }
    if (AreaGrpId == 0) {
        $('#select_areagroup').val(0);
    }
    else {
        $('#select_areagroup').val(AreaGrpId);
    }
}
function GetAreaGroupselect(AreaGrpId) {
    var data = {};
    data.AreaGrpId = 0;
    $.ajax({
        type: "POST",
        url: "../Master/AreaGroupGetandGets",
        data: data,
        success: function (result) {
            AreaGroupLoad(result.oList, AreaGrpId);
        }
    });

}

function popupShowalerts(Status,id) {
    if (Status == 1) {

        swal('Data Saved Successfully', "", "success");
        $('.swal-button swal-button--confirm').focus();
    }
    else if (Status == 2) {
        swal('Data Updated Successfully', "", "success");
        $('.swal-button swal-button--confirm').focus();

    }
    else if (Status == 3) {
        swal('Data Deleted', "", "error");
        $('.swal-button swal-button--confirm').focus();
    }
    else {
        swal('Data Already Exists', "", "warning");
        $('.swal-button swal-button--confirm').focus();
    }
    if (id == 1)
    {
        $('#popupdiv').hide();
    }
}


</script>

<script>


    function removescript()
    {
        document.getElementById('script0348710783').src = '~/Scripts/Voice/VoiceSearch_Menu.js';

    }

    $('#txtproduct0').keydown(function (e) {
        var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
        if (key == 113) {
            localStorage.removeItem('Eumi_VoiceControl');
            localStorage.setItem('Eumi_VoiceControl', 'txtproduct0');
            recognition.start();
            //console.log('sales voice activated' + localStorage.getItem('Eumi_VoiceControl'))
            removescript();
        }

    });



    function ShowVoiceautocomplete(value) {
        if (((value.replace(/ /g, '')).toLowerCase()).search("newsearch") >= 0) {
            noteContent = '';
            $('#txtproduct0').val('');
            $("#txtproduct0").keydown();
        }

        else
        {
            $('#txtproduct0').val(value);
            $("#txtproduct0").keydown();
        }
    }




</script>
<script type="text/javascript" src="~/app-assets/FromStack/dist/JsBarcode.all.js"></script>




@*<script src="~/Scripts/Voice/script.js"></script>*@

@*
    KeyBoard Shortcuts
    ======================

    Alt+1    -   Pop Up to Show Sales Transaction Details of Selected Product

    Esc      -   Close All Popups

    Alt+S    -   Save Sales Invoice

    Alt+L    -   Copy Function For Sales Invoice

    Alt+C    -   FormRefresh function

    Alt+2    -   Pop Up to Show Multiple Product List To Add To Product Grid


*@




