<?php
date_default_timezone_set('Asia/Colombo');
session_start();
require_once("connectioni.php");
// ini_set('session.gc_maxlifetime', 30 * 60 * 60 * 60); 
$_SESSION["brand"] = "";

if ($_SESSION["CURRENT_USER"] == "") {
    echo "Please Loging Again !!!";
    exit();
}

if ($_SESSION["dev"] == "") {
    echo "Invalid User Session";
    exit();
}

   $sql_invpara="SELECT * from invpara where flag='".$_SESSION['company']."'";  
    $result_invpara =mysqli_query($GLOBALS['dbinv'],$sql_invpara);
    $row_invpara = mysqli_fetch_array($result_invpara);
?>
  
<style>

    .talign{
        text-align: left !important; 

    }
    .text{
        font-weight: 600; 
        color: black;
    }
    .form-horizontal .form-group{
        margin-top:-10px !important;
    }
</style>
<!-- Main content -->
<section class="content" style='background-color:#b4bac1f0;'>

    <div class="box box-primary" style='border:none'>
        
        <form role="form" name ="form1" class="form-horizontal">
            <div class="box-body " style='padding:0px;background-color:#b4bac1f0;'>
                <div class="row">
                    <div class="col-md-5">
                        <a onclick="new_inv();" class="btn btn-default">
                            <span class="fa fa-user-plus"></span> &nbsp; New
                        </a>
                        <a onclick="save_inv();" class="btn btn-success">
                            <span class="fa fa-save"></span> &nbsp; Save
                        </a>
                        <a onclick="print_inv();" class="btn btn-default">
                            <span class="fa fa-print"></span> &nbsp; Print
                        </a> 
                        <!--<a onclick="print_inv_net();" class="btn btn-default">-->
                        <!--    <span class="fa fa-print"></span> &nbsp; Print W/O Dis-->
                        <!--</a>-->
                        <a onclick="NewWindow('sales_order_search.php', 'mywin', '800', '700', 'yes', 'center');
                        return false" class="btn btn-primary">
                        <span class="fa fa-search"></span> &nbsp; Search
                    </a>
                    <!-- <a onclick="NewWindow('search_inv_new.php', 'mywin', '800', '700', 'yes', 'center');-->
                    <!--    return false" class="btn btn-default">-->
                    <!--    <span class="fa fa-search"></span> &nbsp; Search DOT-->
                    <!--</a>-->
                    <?php if ($_SESSION['User_Type'] == "1") { ?>
                        <a onclick="cancel_inv();" class="btn btn-danger">
                            <span class="fa fa-trash"></span> &nbsp; Delete
                        </a>	
                    <?php } ?>
    
                </div> 
                <div class="col-md-2" hidden> 
                    <label style="background-color: #00CCCC"><input type="radio" name="paymethod" value="credit" id="paymethod_1" onclick="paytype('CA');"  />&nbsp;CASH&nbsp;&nbsp;&nbsp;</label>
                    <label style="background-color: #00CCCC"><input type="radio" name="paymethod" value="credit" id="paymethod_0"  onclick="paytype('CREDIT');" />&nbsp;CREDIT</label>
                </div>
                <div class="col-md-5"> 
                        <label class="col-md-2 control-label talign" for="invno">Company</label>
                        <div class="col-md-4" onclick="paytype()" onchange="paytype()"> 
            
                            <select id="type2" class="form-control input-sm" disabled >
                                <option value="NORMAL">NORMAL</option>
                                <option value="DOT">DOT</option> 
                            </select> 
                        </div>
                    <label class="col-md-1 control-label talign" style="margin-left: 36px;" for="invdate">Date</label>
                    <div class="col-md-4">  
                        <?php if (($_SESSION['User_Type'] == "1") or (strtoupper($_SESSION['CURRENT_USER']) == "ADMIN")    or (strtoupper($_SESSION['CURRENT_USER']) == "ADMIN_BN")) { ?>
                        <input type="date"    value="<?php echo date('Y-m-d'); ?>" name="invdate" id="invdate"  class="form-control  input-sm">  
                         <?php }else{ ?>
                              <input type="date" disabled   value="<?php echo date('Y-m-d'); ?>" name="invdate" id="invdate"  class="form-control  input-sm"> 
                         <?php } ?>
                    </div>
    
    
                </div>
            </div>
            <br>
           

            <input type="hidden" id="tmpno" class="form-control">
            <input type="hidden" id="item_count" class="form-control">
            <input type="hidden" name="c_subcode" id="c_subcode">
            <input type="hidden" name="ordno" id="ordno">
            <input type="hidden" name="balance" id="balance">
            <input type="hidden" name="creditlimit" id="creditlimit">
      
           
          <!--PAYMENT DETAILS-->
           
          <!-- START CHEQUE -->
            <div id="cheque_view" class="col-lg-12" style='display: none;' > 
                <div class="form-group" style='background-color:#edddb3;'>
                    <label class="col-md-1 control-label talign" for="invno">Cheque No</label>
                    <div class="col-md-2">
                        <input type="text" placeholder="Cheque No"   id="cheque_no" name="cheque_no" class="form-control input-sm">
                    </div>
                    <label class="col-md-1 control-label talign" for="invno">Cheque Date</label>
                    <div class="col-md-2">
                        <input type="date" placeholder="Cheque Date"   id="cheque_date" name="cheque_date" class="form-control">
                    </div>
                    <label class="col-md-1 control-label talign" for="invno">Bank Name</label>
                    <div class="col-md-2">
                        <select  class="form-control"  id="cheque_bank_name" name="cheque_bank_name"> 
                                <option value="">Select Bank Name</option>
                                <?php
                                    $sql = "select * from s_bank where CANCELL='0'"; 
                                    foreach ($conn->query($sql) as $row) {
                                        echo "<option value=\"" . $row["REFNO"] . "\">" . $row["NAME"] . " </option>";
                                    }
                                ?>
                        </select>
                    </div> 
                     <label class="col-md-1 control-label talign" for="invno">Cheque Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Cheque Amount"   id="cheque_amount" name="cheque_amount" class="form-control">
                    </div>
                </div> 
            </div>
            <!-- END CHEQUE -->
           <!-- STRAT CARD -->
           <div id="card_view" class="col-lg-12" style='display: none;' > 
                <div class="form-group" style='background-color:#edddb3;'>
                    <label class="col-md-1 control-label talign" for="invno">Card Number</label>
                    <div class="col-md-2">
                        <input type="text" placeholder="Card Number"   id="card_number" name="card_number" class="form-control input-sm">
                    </div> 
                    <label class="col-md-1 control-label talign" for="invno">Card Name</label>
                    <div class="col-md-2">
                         <select  class="form-control"  id="card_type" name="card_type"> 
                            <option value="">Select Card Name</option>
                            <?php
                            $sql = "Select * from s_paycard_type where CANCELL='0'  ";
                            foreach ($conn->query($sql) as $row) {
                            echo "<option value=\"" . $row["REFNO"] . "\">" . $row["NAME"] . "</option>";
                            }
                            ?>
                        </select>
                    </div> 
                    <label class="col-md-1 control-label talign" for="invno">Card Date</label>
                    <div class="col-md-2">
                        <input type="date" placeholder="Card Date"   id="card_date" name="card_date" class="form-control input-sm">
                    </div> 
                     <label class="col-md-1 control-label talign" for="invno">Card Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Card Amount"   id="card_amount" name="card_amount" class="form-control">
                    </div>
                </div> 
                 
            </div>
            <!-- CARD END -->
           
           <!-- START BANK TRANSFER -->
            <div id="bank_deposit_view" class="col-lg-12" style='display: none;' > 
                <div class="form-group" style='background-color:#edddb3;'> 
                    <label class="col-md-1 control-label talign" for="invno">Bank Name</label>
                    <div class="col-md-2">
                        <select  class="form-control"  id="bank_deposit_bank_name" name="bank_deposit_bank_name"> 
                                <option value="">Select Bank Name</option>
                                <?php
                                    $sql = "select * from a_lcodes where (cat='B' or cat='C') AND COMPANY='".$_SESSION['company']."'"; 
                                    foreach ($conn->query($sql) as $row) {
                                        echo "<option value=\"" . $row["c_code"] . "\">" . $row["c_code"] . " " . $row["c_name"] . "</option>";
                                    }
                                ?>
                        </select>
                    </div>  
                    <label class="col-md-1 control-label talign" for="invno">TT Date</label>
                    <div class="col-md-2">
                        <input type="date" placeholder="TT Date"   id="bank_deposit_date" name="bank_deposit_date" class="form-control">
                    </div>
                    <label class="col-md-1 control-label talign" for="invno">Note</label>
                    <div class="col-md-2">
                        <input type="text" placeholder="Note"   id="bank_deposit_note" name="bank_deposit_note" class="form-control input-sm">
                    </div>
                     <label class="col-md-1 control-label talign" for="invno">Bank Tranfer Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Bank Tranfer Amount"   id="bank_deposit_amount" name="bank_deposit_amount" class="form-control">
                    </div>
                </div>  
            </div>

            <!-- END BANK TRANSFER -->
           
           <!-- STRAT ONLINE PAYMENT -->
            <div id="online_pay_view" class="col-lg-12" style='display: none;' > 
                <div class="form-group" style='background-color:#edddb3;'> 
                    <label class="col-md-1 control-label talign" for="invno">Bank Name</label>
                    <div class="col-md-2">
                        <select  class="form-control"  id="online_pay_bank_name" name="online_pay_bank_name"> 
                                <option value="">Select Bank Name</option>
                                <?php
                                    $sql = "select * from a_lcodes where (cat='B' or cat='C') AND COMPANY='".$_SESSION['company']."'"; 
                                    foreach ($conn->query($sql) as $row) {
                                        echo "<option value=\"" . $row["c_code"] . "\">" . $row["c_code"] . " " . $row["c_name"] . "</option>";
                                    }
                                ?>
                        </select>
                    </div>  
                    <label class="col-md-1 control-label talign" for="invno">Note</label>
                    <div class="col-md-2">
                        <input type="text" placeholder="Note"   id="online_pay_note" name="online_pay_note" class="form-control input-sm">
                    </div>
                     <label class="col-md-1 control-label talign" for="invno">Online Pay Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Online Pay Amount"   id="online_pay_amount" name="online_pay_amount" class="form-control">
                    </div>
                </div>  
            </div>
             <!-- END ONLINE PAYMENT -->
             
             <!-- START GIFT CARD --> 
            <div id="gift_card_view" class="col-lg-12" style='display: none;' > 
                 <div class="form-group" style='background-color:#edddb3;'>   
                    <label class="col-md-1 control-label talign" for="invno">Gift Card No</label>
                    <div class="col-md-2">
                        <input type="text" placeholder="Gift Card No"   id="gift_card_no" name="gift_card_no" class="form-control input-sm">
                    </div>
                      <label class="col-md-1 control-label talign" for="invno">Gift Card Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Gift Card Amount"   id="gift_card_amount" name="gift_card_amount" class="form-control">
                    </div>
                </div>  
                 
            </div>
            <!-- END GIFT CARD -->
            
             <!-- START GIFT CARD --> 
            <div id="cash_view" class="col-lg-12" style='display: none;' > 
                 <div class="form-group" style='background-color:#edddb3;'>    
                      <label class="col-md-1 control-label talign" for="invno">Cash Amount</label>
                    <div class="col-md-2">
                        <input type="number" placeholder="Cash Amount"   id="cash_amount" name="cash_amount" class="form-control">
                    </div>
                </div>  
                 
            </div>
            <!-- END GIFT CARD -->
           
           
           
           
           
            <div id="msg_box"  class="span12 text-center"  ></div>
           
           <!--PAYMENT DETAILS-->
           
           <div class="form-group"></div>
            <div class="form-group">
                <label class="col-md-1 control-label talign" for="invno">Order No</label>
                <div class="col-md-2">
                    <input type="text" placeholder="Ref No"  disabled id="invno" class="form-control input-sm">
                </div> 
                <label class="col-md-1 control-label talign" for="salesord1">Po No</label>
                <div class="col-md-2">
                    <input type="text" name="salesord1"   id="salesord1"   oninput="this.value = this.value.toUpperCase()" class="form-control input-sm">  
                </div>
                <div class="col-md-1"></div>
                 <div hidden class='col-md-3'>
                    <label class="col-md-3 control-label talign" for="salesord1">Inq.No</label>
                    <div class="col-md-6">
                        <input type="text" name="inquiry" disabled  id="inquiry" class="form-control input-sm">  
                    </div>
                    <div class="col-md-1" style='padding:0px;'>
                        <a  onclick="load_inquiry();" class="btn btn-primary btn-sm">View</a>
                    </div>
                </div>
                     <label class="col-md-1 control-label talign" for="invno">Pay Type</label>
                    <div class="col-md-1"> 
        
                        <select id="pay_type" class="form-control input-sm" onclick="pay_type_change();" onchange="pay_type_change();">
                           
                            <?php
                     
                        $sql = "select * from s_paytype where CANCELL='0' ";
                     
                    $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    while ($row = mysqli_fetch_array($result)) {
                        echo "<option value='" . $row["REFNO"] . "'>" . $row["NAME"] . "</option>";
                    }
                    ?>
                    
                    
                            
                        </select> 
                    </div>
                     
                
            </div>  

            <div class="form-group">
                <label class="col-md-1 control-label talign" for="invno">Customer</label>

                <div class="col-md-2">
                    <input type="text"  class="form-control input-sm" disabled="disabled" name="firstname_hidden" id="firstname_hidden">
                </div>

                <div class="col-md-3">
                    <input type="text" class="form-control input-sm" id="firstname"  oninput="this.value = this.value.toUpperCase()" name="firstname" />
                </div>
                <div class="col-md-1" style='padding:0px;'>
                    <a href=""  class="btn btn-primary btn-sm" onClick="NewWindow('../serach_customer.php', 'mywin', '800', '700', 'yes', 'center');
                    return false" onFocus="this.blur()">
                    Find
                    </a>
                    
                    <a    class="btn btn-warning btn-sm" onclick="customer_model();">
                    New
                    </a>
                </div>
            <div class="col-lg-1" style='background-color:#d8deed;padding:0px;text-align:center;'>
                <label  class="col-form-label input_mr" style='margin-bottom:0px !important'>SO Status</label>
                <input  class="form-control" type="text"  disabled id="Result" name="Result" style='height:24px !important;text-align:center;'>
            </div>
            <div class="col-lg-1" style='background-color:#d8deed;padding:0px;text-align:center;'>
                <label  class="col-form-label input_mr" style='margin-bottom:0px !important'>Rtn Chq</label>
                <input  class="form-control" type="text"  disabled id="txtreturn" name="txtreturn" style='height:24px !important;text-align:center;'>
            </div>
            <div class="col-lg-1" style='background-color:#d8deed;padding:0px;text-align:center;'>
                <label  class="col-form-label input_mr" style='margin-bottom:0px !important'>Over 60</label>
                <input  class="form-control" type="text"  disabled id="over60" name="over60" style='height:24px !important;text-align:center;'>
            </div>
            <div class="col-lg-1" style='background-color:#d8deed;padding:0px;text-align:center;'>
                <label  class="col-form-label input_mr" style='margin-bottom:0px !important'>Credit Bal</label>
                <input  class="form-control" type="text"  disabled id="crebal" name="crebal" style='height:24px !important;text-align:center;'>
            </div>
            <div class="col-lg-1" style='background-color:#d8deed;padding:0px;text-align:center;'>
                <label  class="col-form-label input_mr" style='margin-bottom:0px !important'>Over Pay</label>
                <input  class="form-control" type="text"  disabled id="overpay" name="overpay" style='height:24px !important;text-align:center;'>
            </div>
 

        </div>

        <div class="form-group">
            <label class="col-md-1 control-label talign" for="invno">Address</label>

            <div class="col-md-5">
                <input type="text"  class="form-control input-sm"  oninput="this.value = this.value.toUpperCase()" name="cus_address" id="cus_address">
                <input type="hidden"  class="form-control input-sm"  name="cus_address2" id="cus_address2">  
            </div>
            
            <label class="col-md-1 control-label talign" for="invno">Tel</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm"    name="tel" id="tel">    
            </div>
            
              <div  class="col-md-1" style='background-color:#00CCCC;'>
                <input type="radio" name="vatgroup" value="vat" id="vatgroup_0" onclick="calc();">
                <b>VAT</b>
            </div>  
            <div  class="col-md-1" style='background-color:#00CCCC;'>
                <input type="radio" name="vatgroup" checked value="vat" id="vatgroup_1" onclick="calc();">
                <b>Non VAT</b>
            </div>  
            <div  class="col-md-1" style='background-color:#00CCCC;'>
                <input type="radio" name="vatgroup" value="vat" id="vatgroup_2" onclick="calc();">
                <b>SVAT</b>
            </div>                      
            <div  class="col-md-1 hidden">
                <input type="radio" name="vatgroup" value="vat" id="vatgroup_3" onclick="calc();">
                <b>EVAT</b>
            </div> 
            
            
            

            <label class="col-md-1 control-label talign  hidden" for="invno">Brand</label>

            <div class="col-md-2">
                <select id="brand"  class="form-control input-sm hidden" onblur="brandsession();" >

                    <?php
                    if (($_SESSION["CURRENT_DEP"] != "") and ( !is_numeric($_SESSION["CURRENT_DEP"]))) {
                        $sql = "select * from brand_mas where act ='1' and costcenter='" . $_SESSION["CURRENT_DEP"] . "' and barnd_name='TYRE' order by barnd_name";
                    } else {
                        $sql = "select * from brand_mas where act ='1' and barnd_name='TYRE' order by barnd_name";
                    }
                    $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    while ($row = mysqli_fetch_array($result)) {
                        echo "<option value='" . $row["barnd_name"] . "'>" . $row["barnd_name"] . "</option>";
                    }
                    ?>
                </select>
            </div> 

        </div>

        <div class="form-group">
            <label class="col-md-1 control-label talign" for="invno">VAT NO</label>

            <div class="col-md-2">
                <input type="text" disabled class="form-control input-sm" name="vat1" id="vat1">
            </div>

            <div class="col-md-3">                    
                <input type="text"  disabled class="form-control input-sm" name="vat2" id="vat2">    
            </div>
             <label class="col-md-1 control-label talign" for="invno">Job No</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm"     name="jobno" id="jobno">    
            </div>
            <label class="col-md-1 control-label talign" for="invno">Labour</label> 
            <div class="col-md-2">  
                 <select id="labour"  class="form-control" > </select>  
            </div>
            

           
             

        </div>


        <div class="form-group">
            <label class="col-md-1 control-label talign" for="invno">Sales Ex</label>

            <div class="col-md-2">
                <select id="salesrep" class="form-control input-sm" >

                    <?php
                    // require_once("connectioni.php");
                    // if ($_SESSION["MANAGER"] != "") {
                    //     $sql = "select * from s_salrep where pactive='1' and manager='" . $_SESSION["MANAGER"] . "'order by REPCODE";
                    //     $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    //     while ($row = mysqli_fetch_array($result)) {
                    //         echo "<option value='" . $row["REPCODE"] . "'>" . $row["REPCODE"] . " " . $row["Name"] . "</option>";
                    //     }
                    // } else if ($_SESSION["CURRENT_REP"] == "") {
                    //     $sql = "select * from s_salrep where pactive='1' order by REPCODE";
                    //     $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    //     while ($row = mysqli_fetch_array($result)) {
                    //         echo "<option value='" . $row["REPCODE"] . "'>" . $row["REPCODE"] . " " . $row["Name"] . "</option>";
                    //     }
                    // } else {
                    //     $sql = "select * from s_salrep where pactive='1' and repcode = '" . $_SESSION["CURRENT_REP"] . "' order by REPCODE";
                    //     $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    //     while ($row = mysqli_fetch_array($result)) {
                    //         echo "<option value='" . $row["REPCODE"] . "'>" . $row["REPCODE"] . " " . $row["Name"] . "</option>";
                    //     }
                    // }
                    ?>
                </select>
            </div>
            <label class="col-md-1 control-label talign"   for="invno">Department</label>
            <div class="col-md-2">   
                <select id="department" onclick="calc();" onchange="calc();"  class="form-control" >

                    <?php
                    // if ( $_SESSION["CURRENT_DEP"] != "" ) {
                    //     $sql = "select * from s_stomas where act ='1' and CODE='" . $_SESSION["CURRENT_DEP"] . "'  order by CODE";
                    // } else {
                    //     $sql = "select * from s_stomas where act='1' order by CODE";
                    // }
                  
                    
                    // $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    // while ($row = mysqli_fetch_array($result)) {
                    //             //echo "<option value='" . $row["barnd_name"] . "'>" . $row["barnd_name"] . "</option>";
                    //     if ($row["CODE"] == "01") {
                    //         echo "<option selected value='" . $row["CODE"] . "'><strong>" . $row["DESCRIPTION"] . "-" . $row["CODE"] . "<strong></option>";
                    //     } else {
                    //         echo "<option value='" . $row["CODE"] . "'>" . $row["DESCRIPTION"] . "-" . $row["CODE"] . "</option>";
                    //     }
                    // }
                    ?>
                </select> 
            </div> 
           <label class="col-md-1 control-label talign" for="invno">Vehicle No</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm"    name="vehino" id="vehino">    
            </div>
           
            <label class="col-md-1 control-label talign" for="invno">Mileage</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm"    name="millage" id="millage">    
            </div>
        </div>

        <div class="form-group hidden">
            <label class="col-md-1 control-label talign" for="invno">Print W/O Dis</label>
            <div class="col-md-2">   
                <input type="checkbox"  name="promotion" id="promotion">    
            </div>
            <label class="col-md-1 control-label talign" for="invno">Discount 1</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm"  onkeyup="calc();" DISABLED name="discount_org1" id="discount_org1">    
            </div>
            <label class="col-md-1 control-label talign" for="invno">Discount 2</label>
            <div class="col-md-2">   
                <input type="text"  class="form-control input-sm" onkeyup="calc();" DISABLED name="discount_org2" id="discount_org2">   
                <input type="hidden"  class="form-control input-sm" onkeyup="calc();" name="discount_org3" id="discount_org3">    						
            </div>
            <label class="col-md-1 control-label talign hidden" for="invno">Delivery Type</label> 
            <div class="col-md-2 hidden"> 

                <select id="delitype" class="form-control input-sm" >
                    <option value="NORMAL">NORMAL</option>
                    <option value="URGENT">URGENT</option>
                    <option value="TRANSPORT">TRANSPORT</option>
                    <option value="URGENT / TRANSPORT">URGENT / TRANSPORT</option>
                </select>

            </div>
            
        </div>    
        
        <div class="form-group"> 
            <ul class="nav nav-tabs">
                <li class="active" style='background-color:#d7d7d7;display:none'> <a data-toggle="tab" href="#product" >PRODUCT</a></li>
                <li  style='background-color:#d7d7d7;display:none'><a data-toggle="tab" href="#dag">DAG</a></li>
                <li  style='background-color:#d7d7d7;display:none'><a data-toggle="tab" href="#purchase">PURCHASE</a></li>
                <!--<li><a data-toggle="tab" href="#service">SERVICE</a></li>-->
            </ul>
        </div>
        
        <div class="tab-content">
            <!------------product------------->
            <div id="product" class="tab-pane fade in active"> 
                <div class="row">
                      <table class="table table-bordered">
                            <tr class='info'>
                                <th  class='col-md-1'>Item Code</th>
                                <th  size="15"></th>
                                <th  class='col-md-3'>Description</th>
                                <th  class='col-md-1'>Serial No</th>
                                <th  class='col-md-2'>Price</th>
                                <th  class='col-md-1'>Qty</th>
                                <th class='col-md-1'>Dis1 (%)</th>
                                <th class='col-md-1'>Dis2 (%)</th>
                                <th class='col-md-2'>Unit Total</th>
                                <th  size="15">#</th>
                                <th  size="15"></th>
                            </tr>
                
                
                            <tr>
                                <td>
                                    <input type="text" class="form-control input-sm" name="itemd_hidden" id="itemd_hidden" disabled onblur="itno_ind();">
                                    <input type="hidden" name="cat1" id="cat1">  
                                </td>
                                <td><a href="serach_item.php?stname=invoice" onclick="NewWindow(this.href, 'mywin', '800', '700', 'yes', 'center');
                                return false" onfocus="this.blur()">
                                <input type="button" name="searchitem" id="searchitem" value="View" class="btn btn-primary btn-sm">
                            </a></td>
                            <td>
                                <input type="text"  class="form-control input-sm" id="itemd" name="itemd" disabled="disabled">
                            </td> 
                             <td>
                                <input type="text"  class="form-control input-sm" id="serialno" name="serialno" >
                            </td> 
                            <td>
                                <input type="number"   name="rate" id="rate" value="" class="form-control input-sm"  onkeyup="calc();">
                                <input type="hidden" name="part_no" id="part_no"> <input type="hidden" name="actual_selling" id="actual_selling">
                            </td>
                            <td>
                                <input type="number" name="qty" id="qty" value="" onkeyup="calc();" class="form-control input-sm">
                            </td>
                            <td>
                                <input type="number" size="15" name="discountper" id="discountper" value="" onkeyup="calcnew();" class="form-control input-sm" onkeypress="keyset('subtotal', event);"> 
                            </td>
                            <td>
                                <input type="number" size="15" name="discountper1" id="discountper1" value="" onkeyup="calcnew();" class="form-control input-sm" onkeypress="keyset('subtotal', event);"> 
                            </td>
                            <td>
                                <input type="text" size="15" name="subtotal" id="subtotal" value="" class="form-control input-sm" disabled="disabled" onkeypress="keyset('additem_tmp', event);">
                            </td>
                            <td><input type="button" name="additem_tmp" id="additem_tmp" value="Add" onclick="add_tmp('add');" class="btn btn-primary"></td>
                            <td></td>
                        </tr>
                
                    </table>
                    
                    <table class="table table-bordered" id="itemdetails"></table>
                </div>
                  
           </div>
           
           
           <!------------dag------------->
            <div id="dag" class="tab-pane fade"> 
                <div class="row">
                     <table class="table table-bordered">
                                <tr class='info'> 
                                    <th style="width: 100px;">Job No</th> 
                                    <th style="width: 10px;"></th>
                                    <th style="width: 100px;">Make</th> 
                                    <th style="width: 100px;">Design</th> 
                                    <th style="width: 70px;">Size</th> 
                                    <th style="width: 100px;">Serial No</th>   
                                    <th style="width: 90px;">Cost</th>
                                    <th style="width: 120px;">Selling</th> 
                                    <th style="width: 60px;">Dis</th>
                                    <th style="width: 120px;">SubTotal</th>
                                    <th style="width: 50px;"></th>
                                </tr>
                                
                                <tr>
                                    <td>
                                        <input type="text" placeholder="Job No" id="dag_jobno" disabled class="form-control input-sm">
                                    </td>
                                    <td>
                                        <a href="" onclick="NewWindow('invoice_search_dag.php', 'mywin', '800', '700', 'yes', 'center');
                                        return false" onfocus="this.blur()">
                                        <input type="button" class="btn btn-primary btn-sm" value="..." id="searchcust" name="searchcust">
                                        </a>
                                    </td>
                                    <td>
                                        <input type="text" placeholder="Make" id="dag_make" disabled class="form-control input-sm">
                                    </td>
                                    <td>
                                        <input type="text" placeholder="Design" id="dag_design" disabled class="form-control input-sm">
                                    </td>
                                    
                                    <td>
                                        <input type="text" placeholder="Size" id="dag_size" disabled class="form-control input-sm">
                                    </td>
                                    <td>
                                        <input type="text" placeholder="Serial No" id="dag_serialno" disabled class="form-control input-sm">
                                    </td> 
                                    
                                      
                                     
                                      <?php       if($_SESSION['user_type']=="ADMIN"){?>
                                  <td style="visibility:visible">
                            <input type="number" placeholder="Cost" id="dag_cost" disabled onkeyup="calc_dag();"   onchange="calc_dag();" class="form-control input-sm">
                        </td>
                           
                                    <?php    }else{?>
                                     <td style="visibility:hidden">
                            <input type="number" placeholder="COST" id="dag_cost" disabled onkeyup="calc_dag();"   onchange="calc_dag();" class="form-control input-sm">
                        </td>
                                          
                                     <?php    }?>
                                    
                                    
                                    <td>
                                        <input type="number" placeholder="Selling" id="dag_selling" onkeyup="calc_dag();" onchange="calc_dag();" class="form-control input-sm">
                                    </td>
                                    
                                    <td>
                                        <input type="number" placeholder="Dis" id="dag_dis"    onkeyup="calc_dag();" onchange="calc_dag();" class="form-control input-sm">
                                    </td>
                                    <td>
                                        <input type="number" placeholder="Subtotal" id="dag_subtotal" disabled="" class="form-control input-sm">
                                    </td>
                    
                                    <td><a onclick="add_tmp('dag');" class="btn btn-default btn-sm"> <span class="fa fa-plus"></span> &nbsp; </a></td>
                                </tr> 
                            </table>
                            
                            <table class="table table-bordered" id="dag_table"></table>
                </div>
                  
           </div>
            
           <!-----------purchase-------------->
           <div id="purchase" class="tab-pane fade"> 
                <div class="row">
                     
                     <table class="table table-bordered" id="purchase_table"></table>
                </div>
                  
           </div>
           
           <!----------service--------------->
           <!--<div id="service" class="tab-pane fade"> -->
           <!--     <div class="row"> -->
           <!--          <table class="table table-bordered" id="service_table"></table>-->
           <!--     </div>-->
                  
           <!--</div>-->
           <!------------------------->
           
        </div>

        

    
   



  <table class="table">
        <tr>
            <th style="width: 100px;">Stock Level</th>
            <th style="width: 60px;"><input type="text" style="max-width: 70px !important;" class="form-control input-sm" disabled=""  name="stklevel" id="stklevel">   </th>
            <th style="width: 600px;"></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;"><div class="col-md-2" id="transp"></div></th>
            <th style="width: 150px;">Sub Total</th>
            <th style="width: 220px;"><input type="text"  disabled class="form-control input-sm"   name="subtot" id="subtot"></th>
            <th></th>
        </tr>
        <tr>
            <th style="width: 100px;">Credit Period</th>
            <th style="width: 60px;"><input type="text"  style="max-width: 70px !important;" class="form-control input-sm"   name="credper" id="credper"></th>
            <td><input type="button" style="visibility: hidden" id="cred_up_but" name="cred_up_but" value="Cred Period Update" onclick="credupdate();" class="btn btn-primary"></td>
            <th style="width: 120px;"> <div id="msg_boxcredup"  class="span12 text-center"  ></div></label></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;"></th>
            <th style="width: 120px;">Discount Given</th>
            <th style="width: 120px;"><input type="text"  disabled class="form-control input-sm"   name="totdiscount" id="totdiscount"></th>
            <th></th>
        </tr>   
        <tr>
            <th style="width: 100px;" hidden>Month Tot Qty</th>
                        <th style="width: 60px;" hidden><input type="text"  class="form-control input-sm" disabled=""  name="txtinvt" id="txtinvt">   </th>
                        <th style="width: 100px;" ><label class="col-md-1 control-label" id="remarkslbl" note="remarkslbl"for="txt_usernm">REMARK</label></th>
                        <th style="width: 760px;" ><textarea name="remarks" id="remarks" cols="60" oninput="this.value = this.value.toUpperCase()" rows="1" class="form-control"></textarea>  </th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Tax</th>
                        <th style="width: 120px;"><input type="text"  disabled class="form-control input-sm"   name="tax" id="tax"></th>
            <th  style="width: 120px;" hidden>Card Fee</th>
            <th  style="width: 120px;" hidden>
                 <select id="cardfee" class="form-control input-sm"   onclick="add_tmp('up');" onchange="add_tmp('up');">
                            <?php
                        $sql = "select * from s_cardfee where CANCELL='0' ";
                    $result = mysqli_query($GLOBALS['dbinv'], $sql);
                    while ($row = mysqli_fetch_array($result)) {
                        echo "<option value='" . $row["REFNO"] . "'>" . $row["NAME"] . "</option>";
                    }
                    ?>
                    
                    
                            
                        </select></th>
            <th></th>
        </tr>   
<!--                    <tr>
                        <th style="width: 100px;">Credit Period</th>
                        <th style="width: 60px;"><input type="text"  class="form-control input-sm"   name="credper" id="credper"></th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Discount</th>
                        <th style="width: 120px;"><input type="text"  class="form-control input-sm"   name="totdiscount" id="totdiscount"></th>
                        <th></th>
                    </tr>                    -->
                    
                     
               
                    
                    <tr>
                         <th style="width: 100px;"></th>
                        <th style="width: 60px;"></th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;">Grand Total</th>
                        <th style="width: 120px;"><input type="text"  disabled class="form-control input-sm"   name="invtot" id="invtot"></th>
                        <th></th>
                    </tr>  
                    <tr>
                        <th style="width: 100px;"></th>
                        <th style="width: 60px;"></th>
                        <th style="width: 400px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th style="width: 120px;"></th>
                        <th></th>
                    </tr>  

                </table>
                <div id="storgrid"></div>

                <div  class='space' >
                    <br>&nbsp; 
                </div>
                
                <div class="form-group">
                    <label class="col-md-1 control-label" for="invno">Delivery</label>
                    <div class="col-md-2">   
                        <input type="checkbox"  onclick="delichk();"   name="promotion" id="deli_chk">    
                    </div>
                    <div class="col-md-3">   

                    </div>
                    <div class="col-md-4">   
                        <div id="msg_boxdeliup"  class="span12 text-center"  ></div>
                    </div>
                    <div class="col-md-3">   

                    </div>
                </div>
                
                <div class="form-group"   style="visibility: hidden">
                    <label class="col-md-1 control-label" id="deli_label" for="invno">Details</label>
                    <div class="col-md-4">
                        <input type="text"  class="form-control input-sm"   placeholder="Name"  id="deli_name">
                    </div>
                    <div class="col-md-4">
                        <input type="text" class="form-control input-sm"  placeholder="Address"  id="deli_address"   />
                    </div>
                    <div class="col-md-1" id="deli_upbut">
                        <a onclick="deli_update();"  class="btn btn-primary">
                            <span class="fa fa-save"></span> &nbsp; Update Sub Details
                        </a>
                    </div>
                    <div class="col-md-2" id="printdeli">
                        <!--<a onclick="print_deli();"  class="btn btn-primary">-->
                        <!--    <span class="fa fa-print"></span> &nbsp; -->
                        <!--</a>-->
                    </div>
                </div>
              
            </form>
        </div>

    </section>
<?php
include 'customer_model.php';
?>
    <script src="js/sales_order.js?v8"></script>
    <script src="js/comman.js"></script>
    <script>
        new_inv();

    </script>

 