          <div class="breadcrumbs">
            <div class="breadcrumbs-inner">
                <div class="row m-0">
                    <div class="col-sm-4">
                        <div class="page-header float-left">
                            <div class="page-title">
                                <h1>Authorize Invoice</h1>
                            </div>
                        </div>
                    </div>
                    <!--div class="col-sm-8">
                        <div class="page-header float-right">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li> 
                                    <li><a href="#">Forms</a></li>
                                    <li class="active">Basic</li>
                                </ol>
                            </div>
                        </div>
                    </div-->
                </div>
            </div>
        </div>
        <style>
.content{position: relative;}
.overlay{position: absolute;left: 0; top: 0; right: 0; bottom: 0;z-index: 2;background-color: rgba(255,255,255,0.8);position: fixed;   overflow-y: scroll;}
.overlay-content {
    position: absolute;
    transform: translateY(-50%);
     -webkit-transform: translateY(-50%);
     -ms-transform: translateY(-50%);
    top: 50%;
    left: 15%;
    right: 0;
    text-align: center;
    color: #555; 
    position: fixed; 
   overflow-y: scroll;
}

.tableFixHead          { overflow: auto; }
.tableFixHead thead th { position: sticky; top: 0; z-index: 1; }
</style>  
                                                                
    <div class="overlay" style="display:block" id="load"><div class="overlay-content"><img src="<?php echo base_url(); ?>assets/images/loader.gif" alt="Loading..." style="width: 60px;"/></div></div>
                    
      
          <link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/lib/chosen/chosen.min.css">
  
                <div class="content">
            <div class="animated fadeIn">

                <div class="form-group">
                    <input type="hidden" id="temp_id"  name="temp_id" placeholder="" value="<?php echo $inv_id;?> "class="col-xs-12 col-sm-12" />
                                                                
                                   <div class="row">
                                                   
                                                    
                                                     <!--div class="col-sm-3">
                                                           MES Ref. No.
                                                           <input type="text" id="mes_ref"  name="mes_ref" placeholder="" value=""class="col-xs-12 col-sm-12 input-sm form-control-sm form-control" /> 
                                                    </div-->
                                                    
                                                    <div class="col-sm-4"> 
                                                        Sales Rep
                                                            <select class="form-control standardSelect choosen-select" id="saleselect" data-placeholder="Choose a Supplier..." name="sales" disabled>
    							                               <option value="<?php echo $inv[0]->po_ref_id;?>" selected><?php echo $inv[0]->user_fname." ".$inv[0]->user_lname;?></option>                                                      
                                                            </select>   
                                                    </div>
                                                    
                                                     <div class="col-sm-4">  
                                                        Customer
                                                            <select class="form-control standardSelect" id="supselect" data-placeholder="Choose a Supplier..." name="sup" disabled>
    							                                <option value="<?php echo $inv[0]->po_sup_id;?>" selected><?php echo $inv[0]->cust_company;?></option>
                                                                                                                       
                                                            </select> 
                                                                                 
                                                    </div>
                                                    
                                                  
                                                    
                                               </div>
                                               
                                               <div class="row">
                                                    <!--div class="col-sm-4">  
                                                        Catagory
                                                        <select class="standardSelect form-control" id="catselect" data-placeholder="Choose a cat..." name="cat">
							<option value="0"> Select Category </option>
                                                         <?php 
                                                         foreach ($category as $cat) {            
                                                          ?>
							<option value="<?php echo $cat->cat_id; ?>"><?php echo $cat->cat_name; ?></option>
                                                          <?php }?>                                                           
                                                        </select>                          
                                                    </div-->
                                                  
                                                    
                                                    <!--div class="col-sm-3">
                                                            Part Number
                                                            <select class="form-control standardSelect" id="partselect" data-placeholder="Choose a part..." name="partselect">
							                                    <option value="">Select</option>                    
                                                        </select>
                                                              </div-->
                                                    <!--div class="col-sm-3">   
                                                        Spec
                                                            <select class="form-control standardSelect" id="specselect" data-placeholder="Choose a spec..." name="specselect">
							                                    <option value="">  </option>                    
                                                        </select>                         
                                                    </div-->
                                                   
                                                     
                                               
                                                   <div class="col-sm-6" style="display:none">   
                                                        Products
                                                        <select class="form-control standardSelect" id="itemselect" data-placeholder="Type to Choose..." name="itemselect">
							                                <option value="">  </option>                                                          
                                                        </select>                          
                                                    </div>
                                                   </div>
                                               
                                               <div class="row" style="display:none">
                                                   
                                                    <div class="col-sm-2">
                                                            Price
                                                        <input type="text" id="price"  name="price" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" />
                                                        
                                                    </div><br><div class="" style="display:none" id="loader"> &nbsp; <div class=""><img src="<?php echo base_url(); ?>assets/images/loader.gif" alt="Loading..." style="width: 30px;"/></div></div>
    
                                                    <div style="display:none">
                                                    <div class="col-sm-1" >
                                                            Currency
                                                        <select class="form-control-sm form-control" id="curid" data-placeholder="Choose a currency" name="curselect">
							                                
                                                         <?php 
                                                         foreach ($curren as $cat) {            
                                                          ?>
							                                <option value="<?php echo $cat->curr_id; ?>"><?php echo $cat->curr_symble; ?></option>
                                                          <?php }?>                                                         
                                                        </select>      
                                                    </div>
                                                    
                                                    
                                                        <div class="col-sm-2" id="">
                                                           Cur. Rate
                                                        <input type="text" id="cur_rt"  name="cur_rt" placeholder="" value="1"class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="cur_cal()"/>
                                                    </div>
                                                    </div>
                                                    
                                                    <div class="col-sm-2" style="display:none;" id="for_foreign1">
                                                            Price
                                                        <input type="text" id="pricelkr"  name="pricelkr" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="cur_cal()"/>
                                                        
                                                    </div>
                                                   
                                                     
                                                    <div class="col-sm-2">
                                                            Quantity
                                                        <input type="text" id="qty"  name="qty" placeholder="" value=""class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="sin_item_tot();"/>
                                                                <?php echo form_error('productqty'); ?>
                                                    </div>
                                                    
                                                    <div class="col-sm-1">
                                                            Unit
                                                            <select class="form-control-sm form-control" id="unitid" data-placeholder="Choose a currency" name="unitid" disabled >
							                                <option selected value='0002'>EA</option>
                                                         <?php 
                                                         foreach ($unit as $cat) {            
                                                          ?>
							                                <option value="<?php echo $cat->unit_id; ?>" disable><?php echo $cat->unit_symble; ?></option>
                                                          <?php }?>                                                         
                                                        </select> 
                                                        
                                                                
                                                    </div>
                                                    
                                                    
                                                    <div class="col-sm-2">
                                                            Total
                                                        <input type="text" id="total"  name="total" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" readonly/>
                                                                <?php echo form_error('productqty'); ?>
                                                    </div>
                                                    
                                                    <div class="col-sm-2">
                                                            Free Items
                                                        <input type="text" id="free"  name="free" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" />
                                                        <input type="hidden" id="freeqty"  name="freeqty" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" />
                                                    </div><div class="" style="display:none" id="loader2"> &nbsp; <div class=""><img src="<?php echo base_url(); ?>assets/images/loader.gif" alt="Loading..." style="width: 30px;"/></div></div>
    
                                                    
                                                   <div class="col-sm-1"><br>
                                                        
                                                       <button type="button" class="btn btn-secondary btn-sm" name="add" id="addrow" onclick="addrow();">
                                                                                <i class="ace-icon fa fa-pencil-square-o bigger-150 middle orange2"></i>
                                                                                <span class="bigger-110">Add</span></button>
                                                                                
                                                                                

							</button>
                                                                  </div> 
                                                </div>    
                                               
                                         <div class="space"></div>
                                        
                                         <div class="row" id="agent" style="display: none">
                                            <div class="col-sm-3">
                                                            Contact
                                                        <input type="text" id="ag_cont"  name="ag_cont" placeholder="Contact Detail" value="" class="col-xs-12 col-sm-12" />
                                                                
                                                    </div>
                                            <div class="col-sm-3">
                                                            Credit Limit
                                                        <input type="text" id="ag_limit"  name="ag_limit" placeholder="" value=""class="col-xs-12 col-sm-12" />
                                                              
                                                    </div>
                                            <div class="col-sm-3">
                                                            Credit Time
                                                        <input type="text" id="ag_time"  name="ag_time" placeholder="" value="" class="col-xs-12 col-sm-12" />
                                                               
                                                    </div>
                                            <div class="col-sm-3">
                                                            Balance
                                                        <input type="text" id="ag_bal"  name="ag_bal" placeholder="" value="" class="col-xs-12 col-sm-12" />
                                                                
                                                    </div>
                                            
                                        </div>
                                        
                                        
        

                                      <div class="space"></div>
                                      
                                                <div class="row">
                                                        
                                                </div>
                                      
                                      
                                       <div class="space" style="padding-bottom: 10px;"></div>
                                      
                                      <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 10px;overflow:scroll;height:250px;width:100%;overflow:auto">
                                    										<table id="simple-table" class="table table-bordered tableFixHead">
                                    											<thead class="thead-dark">
                                    												<tr>
                                    													
                                    													<th scope="col">ID</th>
                                    													<th>Item Code</th>
                                    													<th>Item Description</th>
                                    													<th style="text-align:right">Unit</th>
                                    													<th style="text-align:right"><span id="cr_chng">Inv Rate</span> </th>
                                    													<th style="text-align:right"><span id="cr_chng">Act Rate</span> </th>
                                    													<th style="text-align:right">Quantity </th>
                                                                                        <th style="text-align:right"><span id="cr2_chng">Total</span>  </th>
                                                                                        <th style="text-align:right">Free Item</th>                
                                    													<th>Action</th>
                                    												</tr>
                                    											</thead>
                                            
                                    											<tbody id="show_data" >
                                    									
                                    								
                                    											</tbody>
                                    										</table>
                                    									</div><!-- /.span -->
                                                                                                            
                                                                                                            
                                    								</div><!-- /.row -->
                                    								
                                    								<div class="row">
                                    								    <div class="col-lg-6">
                                    								        
                                    								       <div class="row">
                                    								           
                                    							        
                                    						<!--div class="col-lg-6">   
                                    						<form id="calc">
                                                     
                                                        T & C Catagory 
                                                            <select class="form-control standardSelect choosen-select" id="tccat" data-placeholder="" name="tccat">
    							                                <option value="0"> Select T & C Catagory </option>
                                                             <?php 
                                                             foreach ($tccatdetails as $dbagent) {            
                                                              ?>
    							                            <option value="<?php echo $dbagent->tcat_id; ?>"><?php echo $dbagent->tcat_name; ?></option>
                                                              <?php }?>                                                           
                                                            </select>                        
                                                    
                                                                </div-->
                                                    
                                                    		 <!--div class="col-lg-6">       
                                                     
                                                       TC Description
                                                            <select class="form-control standardSelect choosen-select" id="tcdes" data-placeholder="Choose..." name="tcdes">
    							                                <option value="0"> Select Conditions</option>
    							                                                                                    
                                                            </select>                         
                                                    
                                                    
                                                                
                                                            </div-->
                                                            
                                                            <!--div class="col-lg-12"> Terms & Conditions
                                                            
                                                              <table  id="data">
                                                          <thead>
                                                        
                                                          <tr id="finalrow">
                                                            <td></td>
                                                            <td></td>
                                                           
                                                            <td id="total"></td>
                                                          </tr>
                                                          </thead>
                                                          
                                                          <tbody></tbody>
                                                        
                                                        </table></div>
                                                            
                                                          
                                                             </form -->   
                                                             
                                                            <div class="col-lg-12">
                                                                 Remarks
                                                                 <textarea id="remark" name="remark" rows="2" cols="60"></textarea>
                                                            </div> 
                                                    
                                                    </div>
                                                 
                                                    
                                               
                                                   
                                    								    </div>
                                    								    
                                    								    
                                    								    
                                    								    <div class="col-lg-6">
                                    								        <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									     <div class="row" style="float: right;">
                                    									         <div class="col-lg-6 d-inline">
                                                                              Total Quantity
                                                                            <input type="text" id="inv_tot_item" readonly name="inv_tot_item" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" style="text-align: right;"/>
                                                                        </div>
                                                                       <div class="col-lg-6 float-end">
                                                                              Sub Total
                                                                            <input type="text" id="inv_total" readonly name="inv_total" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" style="text-align: right;"/>
                                                                        </div>
                                                                        
                                                                </div> 
                                    									    
                                                                         </div>
                                                                         </div>
                                                                         
                                                                       
                                                                         
                                                                         <div class="row">
                                            									<div class="col-lg-12" style="padding-bottom: 2px;">
                                            									     <div class="row" style="float: right;">
                                                                                
                                                                                <div class="col-lg-6 col-lg-6 d-inline">
                                                                                      Discount %
                                                                                 <input type="text" id="dis_pc" <?php if(0<$inv[0]->po_discount){?> style="color:red;background: #6c6b6b61;" <?php } ?> name="dis_pc" placeholder="Dis_amount" value="<?php echo $inv[0]->po_discount;?>" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_dis_pc();" style="text-align: right;"/>
                                                                         </div>
                                                                         
                                                                         <div class="col-lg-6 float-end">
                                                                              Discount
                                                                              <input type="text" id="dis_total" readonly  name="dis_total" placeholder="%" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="" style="text-align: right;"/>
                                                                         <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                                </div>
                                            									    
                                            									    </div>
                                                                         </div>
                                                                         
                                                                         <input type="hidden" id="dis_total"  name="dis_total" placeholder="%" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_dis_amt();" style="text-align: right;"/>
                                                                        
                                                                         <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									     <div class="row" style="float: right;">
                                                                        
                                                                        <div class="col-lg-12 float-end">
                                                                              Net Total
                                                                              <input type="text" id="net"  name="net" placeholder="Net Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_dis_pc();" style="text-align: right;"/>
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                    									    
                                    									    </div>
                                                                         </div>
                                                                         
                                                                           <div id="tx" style="display: none;">
                                                                             <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                                                        
                                                                         <div class="row" style="float: right;">
                                                                        
                                                                       <div class="col-lg-6 d-inline">
                                                                                 Tax amount
                                                                            <input type="text" id="tax_total"  name="tax_total" placeholder="Dis_amount" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_tax_amt();" style="text-align: right;"/>
                                                                        </div>
                                                                        <div class="col-lg-6 float-end">
                                                                              Tax %
                                                                              <input type="text" id="tax_pc"  name="tax_pc" placeholder="%" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_tax_pc();" style="text-align: right;"/>
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                                                        
                                                                         </div>
                                                                         </div>
                                                                         
                                                                         <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									     <div class="row" style="float: right;">
                                                                        
                                                                        <div class="col-lg-12 float-end">
                                                                              Total
                                                                              <input type="text" id="ttot"  name="ttot" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_dis_pc();" style="text-align: right;"/>
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                    									    
                                    									    </div>
                                                                         </div>
                                                                         
                                                                         </div>
                                                                      
                                                                         <div id="for_tax" style="display: none;">
                                                                         
                                                                         <div class="row" >
                                                                         <div class="col-lg-12" style="padding-bottom: 2px;">
                                    									        <div class="row" style="float: right;">
                                    									    <div class="col-lg-12 d-inline">
                                    									        NBT <?php echo $tax[1]->tax_value  ?>% <input type="checkbox" id="chk_nbt" name="chk_nbt" value="10"  onclick="mynbt()">
                                                                                  <input type="text" id="nbt"  name="nbt" placeholder="nbt" value="0.00" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="cal_total();" style="text-align: right;"/>
                                                                            <div class="help-block" id="input-span-slider"></div>
                                    									         </div>
                                    									         </div>
                                    									    
                                    									    </div>     
                                                                             
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									    <div class="row" style="float: right;">
                                    									    
                                    									    
                                    									    <div class="col-lg-12 d-inline">
                                    									        VAT <?php echo $tax[0]->tax_value  ?>% <input type="checkbox" id="chk_vat" name="chk_vat" value="10" onclick="myvat()">
                                                                                  <input type="text" id="vat"  name="vat" placeholder="vat" value="0.00" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="cal_total();" style="text-align: right;"/>
                                                                            <div class="help-block" id="input-span-slider"></div>
                                    									         </div>
                                    									    </div>
                                    									    </div>
                                    									   
                                    									    
                                                                         </div>
                                                                         
                                                                         <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									     <div class="row" style="float: right;">
                                                                        
                                                                        <div class="col-lg-12 float-end">
                                                                              Total
                                                                              <input type="text" id="txtot"  name="txtot" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onkeyup="cal_dis_pc();" style="text-align: right;"/>
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                    									    
                                    									    </div>
                                                                         </div>
                                                                         
                                                                         </div>   
                                                                         
                                                                         
                                                                         
                                                                        
                                                                       <div id="trafee" style="display: block;">  
                                                                          <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									     <div class="row" style="float: right;">
                                                                        
                                                                        <!--div class="col-lg-12 float-end">
                                                                              Transport Fee
                                                                              <input type="text" id="trfee"  name="trfee" placeholder="Transport Fee" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_total();" style="text-align: right;"/>
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div-->
                                                                </div>
                                    									    
                                    									    </div>
                                                                         </div>
                                                                         </div>
                                                                         
                                                                         
                                                                         
                                                                          <div id="for_foreign2" style="display: none;">
                                                                              
                                                                              
                                                                         <div class="row">
                                                                             
                                                                              <div class="col-lg-12" style="padding-bottom: 2px;">
                                    									         <div class="row" style="float: right;">
                                    									    <div class="col-lg-12 float-end">
                                                                                 Shipping Fee 
                                                                                  <input type="text" id="ship"  name="ship" placeholder="ship" value="0.00" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_total();" style="text-align: right;"/>
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                            </div>
                                                                            
                                    									     </div>
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									    <div class="row" style="float: right;">
                                    									    <div class="col-lg-12 float-end">
                                                                                 Bank Fee
                                                                                  <input type="text" id="bank_fee"  name="bank_fee" placeholder="bank_fee" value="0.00" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_total();" style="text-align: right;"/>
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                           </div>
                                                                            
                                    									     </div>
                                    									    
                                                                         </div>
                                                                         </div>
                                                                       
                                                                        
                                                                         <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 2px;">
                                    									    <div class="row" style="float: right;">
                                                                        

                                                                        <!--div class="col-lg-6 float-end">
                                                                              Other - Reason
                                                                              <input type="text" id="other_reason"  name="other_reason" placeholder="Total" value="Other" class="col-xs-12 col-sm-12 form-control" />
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div-->
                                                                                                                                               <div class="col-lg-12 d-inline">
                                                                              Other Fee
                                                                            <input type="text" id="other_amnt"  name="other_amnt" placeholder="Other" value="0.00" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" onclick="this.select();" onkeyup="cal_total();" style="text-align: right;"/>
                                                                        </div>
                                                                </div>
                                    									    </div>
                                                                         </div>
                                                                         
                                                                          
                                                                         
                                                                         
                                                                         
                                                                         <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 15px;padding-top: 15px;">
                                    									    <div class="row" style="float: right;">
                                    									    <div class="col-lg-12 d-inline">
                                                                            Grand Total
                                                                            <input type="text" id="final" readonly name="final" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" style="text-align: right;"/>
                                                                        </div>
                                                                        </div>
                                                                         </div>
                                                                         </div>
                                    								        
                                    								    </div>
                                    								    
                                    								</div>
                                                                
                                                                
                                                                         
                                                         <input type="hidden" value="0" id="auth" name="auth">     
                                                          <div class="row">
                                    									<div class="col-lg-12" style="padding-bottom: 10px;">      
                                    
                                                                <div class="row" style="float: right; text-align: right;">
                                                                        
                                        <div class="col-md-12 center-block">
                                            <button class="btn btn-outline-secondary btn-sm" id="btn_save">
                                                    <i class="ace-icon fa fa-floppy-o bigger-120 blue"></i>
                                                   Authorize Invoice
                                            </button>
                                             <!--button class="btn btn-outline-secondary btn-sm" id="btn_draft">
                                                    <i class="ace-icon fa fa-floppy-o bigger-120 blue"></i>
                                                    Save for Later
                                            </button-->
                                            <button class="btn btn-outline-secondary btn-sm" id="btn_cancel">
                                                <a href="<?php echo base_url('allqtn');?>">Back</a>
                                                    <i class="ace-icon fa fa-times red2"></i>
                                            </button>
                                        </div>
                                        
                                    </div>
                                     </div>
                                    </div>
                                    
                    
                </div>
                                    
            </div>
            
            </div>
            
           
            
            <div class="clearfix"></div>
            
             <!--MODAL add-->
          <form id="frm_add_data">
              <div class="modal fade" id="addmodel" tabindex="-1" role="dialog" aria-labelledby="scrollmodalLabel" aria-hidden="true" data-backdrop='static' data-keyboard='false'>
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="scrollmodalLabel">Detail</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body" id="Modal_Add">
                            <table id="grn_table" class="table table-bordered tableFixHead">
                                <thead class="thead-dark">
                                    												<tr>
                                    													<th scope="col">ID</th>
                                    													<th>Buying Price</th>
                                    													<th scope="col">GRN QTY</th>
                                    													<th>GRN Date</th>
                                    													
                                    												</tr>
                                    											</thead>
                                    <tbody id="grn_display">
                                        
                                    </tbody>											
                                </table>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        </div>
                    </div>
                </div>
            </div>
          </form>
            <!--END MODAL add-->
            
            
            <!--MODAL edit-->
          <form id="frm_edit_data">
              <div class="modal fade" id="editmodel" tabindex="-1" role="dialog" aria-labelledby="scrollmodalLabel" aria-hidden="true" data-backdrop='static' data-keyboard='false'>
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="scrollmodalLabel">Change Details</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body" id="modal_edit">
                              <div class="form-group row">
               
                                    <input type="hidden" name="inv_id" id="inv_id" class="form-control" readonly="" value="save_services">
                                <label class="col-md-2 col-form-label">Item Price</label>
                                <div class="col-md-4">
                                  <input type="text" id="act_price"  name="act_price" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" readonly/>
                                </div>
                                <label class="col-md-2 col-form-label">Invoiced Price</label>
                                <div class="col-md-4">
                                  <input type="text" id="inv_price"  name="inv_price" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" />
                                </div>
                            </div>
                            <div class="form-group row">
                                   
                                <label class="col-md-2 col-form-label">Free Items</label>
                                <div class="col-md-2">
                                  <input type="text" id="fr_cnt"  name="fr_cnt" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" readonly/>
                                </div>
                                <div class="col-md-2">
                                  <input type="text" id="fr_itm"  name="fr_itm" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" readonly/>
                                </div>
                                <label class="col-md-2 col-form-label">Invoiced Free Items</label>
                                <div class="col-md-4">
                                  <input type="text" id="inv_fr"  name="inv_fr" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" />
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-primary" id="save_auth" >Save New Data</button>
                        </div>
                    </div>
                </div>
            </div>
          </form>
            <!--END MODAL edit-->
            
             <!--MODAL DELETE-->
         <form>
            <div class="modal fade" id="Modal_Delete" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop='static' data-keyboard='false'>
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Delete Product</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>
                  </div>
                  <div class="modal-body">
                       <strong>Are you sure to delete this record?</strong>
                  </div>
                  <div class="modal-footer">
                    <input type="hidden" name="product_code_delete" id="product_code_delete" class="form-control">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
                    <button type="button" type="submit" id="btn_delete" class="btn btn-primary">Yes</button>
                  </div>
                </div>
              </div>
            </div>
            </form>
        <!--END MODAL DELETE-->
            
                    

                    
    
            
            
<script src="<?php echo base_url(); ?>assets/js/jquery.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/lib/chosen/chosen.jquery.min.js"></script>

<script>

var input = document.getElementById("qty");

input.addEventListener("keyup", function(event) {
  // Number 13 is the "Enter" key on the keyboard
  if (event.keyCode === 13) {
    event.preventDefault();
    document.getElementById('free').focus();document.getElementById("free").select();
  }
});

var input = document.getElementById("price");

input.addEventListener("keyup", function(event) {
  // Number 13 is the "Enter" key on the keyboard
  if (event.keyCode === 13) {
    event.preventDefault();
    document.getElementById('qty').focus();document.getElementById("qty").select();
  }
});


$(document).ready(function() {
   
     document.getElementById("load").style.display = "none";
    cal_ttot();
    cal_total();cal_dis_pc();
    
    show_product();
    
  $("#data").on('click', '.removeBtn', function() {

    $(this).closest('tr').remove();

    let tr = $("").appendTo("#data tbody");
    $('#calc input, #calc select').each(function(index) {
      var input = $(this);
      $(tr).insertBefore("#finalrow").append('' + $(input).val() + '');
    });

    const componentFactor = $(tr).children(".row-component").text();
    const units = $(tr).children(".row-units").text();
    const total = componentFactor * units;
    $("#total").html(sumColumn(5));


    function sumColumn(index) {
      var total = 0;
      $("td:nth-child(" + index + ")").each(function() {
        if (this.id !== 'total') {
          total += parseInt($(this).text(), 10) || 0;
        }
      });
      return total;

    }


  });
});

//cusromer select

    $('#saleselect').change(function(){ 
       
                $('#itemselect option').remove();
                $('#supselect option').remove();
               
                
                $('[name="price"]').val("");
                    $('[name="pricelkr"]').val("");
            var part_id = $(this).val();
             document.getElementById("load").style.display = "block";
             
         
          
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('cust_data')?>',
                dataType : 'json',
                data : {part_id:part_id},
                success : function(data){
                    
                     $('#supselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                                        
                            for (var i = 0; i < data['customer'].length; i++) {
                                
                                  
                                                        
                               $('#supselect').append($('<option>', {
                                                            value: data['customer'][i].custmid,
                                                            text: data['customer'][i].cusname
                                                        }));
                            }
                            
                            
                                $('#itemselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                     
                 var i;
                            for (var i = 0; i < data['item'].length; i++) {
                               $('#itemselect').append($('<option>', {
                                                            value: data['item'][i].item_id,
                                                            text: data['item'][i].itm_name
                                                        }));
                            }
                            
                    $("#supselect").trigger("chosen:updated");
                    $("#itemselect").trigger("chosen:updated");
                       // $('[name="price"]').val(data['item'][0].sel_price);
                  //$('[name="pricelkr"]').val(data['item'][0].sel_price);
                 // $("#unitid").val(data['item'][0].uid);
                  document.getElementById("load").style.display = "none";
                  document.getElementById("supselect").focus();
                 // $('select[name^="supselect"]').eq(0).focus();
					
                }
 
            }); 
      });  


    var timer = null;
    $('#price').keydown(function(){
        document.getElementById("loader").style.display = "block"; 
           clearTimeout(timer); 
           timer = setTimeout(cur_cal, 1000)
    });
    
    function cur_cal(){
       
        var act_val = $('#pricelkr').val();
        var price = $('#price').val();
        var cal = (act_val/100)*95;

        document.getElementById("loader").style.display = "none"; 
            if(price == act_val){
                return;
            }else if(price < cal){
                swal({title: "Cannot Change!",  text: "Price is less than 5%",showConfirmButton:true, showCancelButton: true, confirmButtonText: 'Ok',
              focusConfirm:true}).then(function() {
                    document.getElementById('qty').focus();document.getElementById("qty").select();
                  });
                 
                $('[name="auth"]').val(1);
                $('#price').val(act_val);
               document.querySelector('#btn_save').innerHTML = 'Request Approval';
           
                return;
            }else if(price<act_val){
                
                swal({title: "Need Approval!",  text: "Price is less than Actual Price",showConfirmButton:true, showCancelButton: true, confirmButtonText: 'Ok',
              focusConfirm:true}).then(function() {
                    document.getElementById('qty').focus();document.getElementById("qty").select();
                  });
                 
                $('[name="auth"]').val(1);
               document.querySelector('#btn_save').innerHTML = 'Request Approval';
           
                return;
            }else{
                $('[name="auth"]').val(0);
               document.querySelector('#btn_save').innerHTML = 'Create Invoice';
               document.getElementById("qty").focus();document.getElementById("qty").select();
            }
       
        sin_item_tot();
        cal_ttot();
    }
    
    function sin_item_tot(){
        var total = $('#price').val() * $('#qty').val();
        $('[name="total"]').val(total.toFixed(2));
        if($('#freeqty').val()!=0){
            var fr = Math.floor($('#qty').val() / $('#freeqty').val());
        $('[name="free"]').val(fr);
        }
        
        cal_ttot();
    }
    
    var timer = null;
    $('#free').keydown(function(){
        document.getElementById("loader2").style.display = "block"; 
           clearTimeout(timer); 
           timer = setTimeout(cal_free, 1000)
    });
    
    function cal_free(){
        if($('#freeqty').val()!=0){
            var fr = $('#qty').val() / $('#freeqty').val();
            if($('#free').val() > fr){
                swal({title: "Need Approval!",  text: "Free Quantity exceeded",showConfirmButton:true, showCancelButton: true, confirmButtonText: 'Ok',
              focusConfirm:true}).then(function() {
                    document.getElementById('addrow').focus();
                  });
                $('[name="auth"]').val(1);
               document.querySelector('#btn_save').innerHTML = 'Request Approval';
             document.getElementById("loader2").style.display = "none";
                return;
            }else{
                $('[name="auth"]').val(0);
                    document.getElementById('addrow').focus();
                
               document.querySelector('#btn_save').innerHTML = 'Create Invoice';
               document.getElementById("loader2").style.display = "none";
            }
        }
        
    }

    function cal_dis_amt(){
      $('#dis_pc').val("");
      cal_total();
      cal_ttot();
    }

    function cal_dis_pc(){
        var pc = $('#dis_pc').val();
        var dis = ($('#inv_total').val() * pc)/100;
      $('#dis_total').val(dis.toFixed(2));
      var nett = parseFloat($('#inv_total').val()) - dis;
      $('#net').val(nett.toFixed(2));
      cal_ttot();
      cal_total();
    }
   
    function cal_ttot(){
        
        var ttot = parseFloat($('#tax_total').val())+parseFloat($('#net').val());
        $('#ttot').val(ttot.toFixed(2));
        
        var txtot = parseFloat($('#net').val())+parseFloat($('#vat').val())+parseFloat($('#nbt').val());
        $('#txtot').val(txtot.toFixed(2));
    }

    function cal_total(){
    
      if($('#dis_total').val()!=""){
        var dis =  $('#dis_total').val();
      }else{ var dis = 0;}
      
        var other = $('#other_amnt').val();
        var vat = $('#vat').val();
        var nbt = $('#nbt').val();
        var ship = $('#ship').val();
        var bank = $('#bank_fee').val();
        var tax_total = $('#tax_total').val();
        var trfee = $('#trfee').val();

        var total = parseInt($('#inv_total').val()) - parseInt(dis) + parseInt(other);
        $('[name="final"]').val(total.toFixed(2));
        cal_ttot();
    }

        //function show all product
        function show_product(){
            document.getElementById("load").style.display = "block";
        var tempid = $('#temp_id').val();
            $.ajax({
                type  : 'ajax',
                url   : '<?php echo base_url(); ?>authinvprod/'+tempid+'',
                async : true,
                method:'POST',
                dataType : 'json',
                success : function(data){
                  console.log(data);
                    var html = '';
                    var i;
                    var tot = 0;
                    var tot_item = 0;
                    for(i=0; i<data.length; i++){
                        var tot = tot + parseFloat(data[i][4] * data[i][5]);
                        var tot_item = tot_item + parseFloat(data[i][5]);
                        if(data[i][10]!=0){
                            var frcal = parseFloat(data[i][10])/data[i][9]
                            var frqty = parseFloat(data[i][5])/frcal;
                        }else{var frqty = 0;}
                          
                                
                          if(frqty < data[i][7]){var colqty = "color:red;background: #6c6b6b61;";
                          }else if(data[i][5]<1){
                              var colqty = "color:green";
                          }else{var colqty = "color:green";}
                          if(data[i][8]!=data[i][4]){var col = "color:red;background: #6c6b6b61;";}else{var col = "color:green";}
                          
                        html += '<tr>'+
                                //'<td>'+(i+1)+'</td>'+
                                '<td>'+(i+1)+'</td>'+
                                '<td>'+data[i][0]+'</td>'+
                                '<td>'+data[i][2]+'</td>'+
                                '<td style="text-align:right">'+data[i][3]+'</td>'+
                                '<td style="text-align:right;'+col+'">'+data[i][4]+'</td>'+
                                '<td style="text-align:right">'+data[i][8]+'</td>'+
                                '<td style="text-align:right">'+data[i][5]+'</td>'+
                                '<td style="text-align:right">'+parseFloat(data[i][4] * data[i][5]).toFixed(2)+'</td>'+
                                '<td style="text-align:right;'+colqty+'">'+data[i][7]+'</td>'+
                                '<td style="text-align:right;">'+
                                '<div class="hidden-sm hidden-xs btn-group">'+
                                '<button class="btn btn-outline-danger btn-sm" name="tax" id="'+data[i][11]+'" onclick ="view_grn(this.id);">GRN</button>'+
                                '<button class="btn btn-outline-danger btn-sm" name="tax" id="'+data[i][6]+'" onclick ="view_auth(this.id);">Auth</button>'+
                                '</div>'+
                                '</td>'+
                                '</tr>';
                    }
                    $('#show_data').html(html);
                    $('[name="inv_total"]').val(tot.toFixed(2));
                    $('[name="net"]').val(tot.toFixed(2));
                    $('[name="inv_tot_item"]').val(tot_item);
                    cal_total();
                    document.getElementById("load").style.display = "none";
               cal_dis_pc();
                 
            }
 
            });
        }

        
     function view_grn(id){
         $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('get_grn')?>',
                dataType : 'json',
                data : {item_id:id},
                success : function(data){
                   
                     $('#addmodel').modal('show')
                            $('#grn_display').html(data);
                }
 
            }); 
     }
        
     function view_auth(id){
                    $('[name="inv_id"]').val("");
                   $('[name="act_price"]').val("");
                   $('[name="inv_price"]').val("");
                   
                   
                   $('[name="fr_cnt"]').val("");
                   $('[name="fr_itm"]').val("");
                   $('[name="inv_fr"]').val("");
                   
                   document.getElementById("inv_price").style.backgroundColor = "white";
                   document.getElementById("inv_fr").style.backgroundColor = "white";
         
         $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('get_qto_item')?>',
                dataType : 'json',
                data : {item_id:id},
                success : function(data){
                   console.log(data);
                   $('[name="inv_id"]').val(id);
                   $('[name="act_price"]').val(data[1]);
                   $('[name="inv_price"]').val(data[5]);
                   if(data[2]==0){var frcount=0;var fr_itm=0;}else{
                   var frcount = (data[3] / data[2]);
                       var fr_itm = data[4]/frcount;
                   }
                   var cnt = data[4]+" / "+ frcount;
                   
                   
                   $('[name="fr_cnt"]').val(cnt);
                   $('[name="fr_itm"]').val(parseFloat(fr_itm).toFixed(2));
                   $('[name="inv_fr"]').val(data[6]);
                   
                   if(data[1]!=data[5]){document.getElementById("inv_price").style.backgroundColor = "#ff000063";}
                   if(data[6]!=(fr_itm)){document.getElementById("inv_fr").style.backgroundColor = "#ff000063";}
                     $('#editmodel').modal('show');
                }
 
            });
     }
     
     $('#save_auth').on('click',function(){
         var tempid = $('#temp_id').val();
         
         
          swal({
                  title: "Are you sure?",
                  text: "Save, Entered Details will be Updated",
                  icon: "warning",
                  buttons: true,
                  dangerMode: true,
                })
                .then((willDelete) => {
                  if (willDelete) {
                               $.ajax({
                                type  : 'ajax',
                                method : "POST",
                                url   : "<?php echo site_url('updt_item')?>",
                                async : true,
                                dataType : 'json',
                                data: $("#frm_edit_data").serialize(),
                                success : function(data){
                                   swal(data);
                                    $('#editmodel').modal('hide');
                                    show_product();
                                }
                 
                            });
                  } else {
                    swal("No Changes");
                    document.getElementById("load").style.display = "none";
                  }
                });
     });
    
                //Save data to invoice
        $('#btn_save').on('click',function(){
            var e = document.getElementById("supselect");
            var sup_id = e.options[e.selectedIndex].value;
            
                var f = document.getElementById("saleselect");
                var sales = f.options[f.selectedIndex].value;
            
            var temp_id = $('#temp_id').val();
            var qty = $('#inv_tot_item').val();
            var total = $('#inv_total').val();
            var dis = $('#dis_pc').val();
            var final = $('#final').val();
            
            
            var other = $('#other_amnt').val();
                var curn = document.getElementById("curid");
                var cur = curn.options[curn.selectedIndex].value;
            var unt = document.getElementById("unitid");
                var unit = unt.options[unt.selectedIndex].value;
       
            var remark = $('#remark').val();
          
                if((sup_id=="")||(sales=="")){
                   swal({title: "Cannot Save!",  text: "Please Select Sales Rep and Customer",showConfirmButton:true, showCancelButton: true, confirmButtonText: 'Ok',
              focusConfirm:true});
              return;
                }else if((qty=='0')||(total=='0')||(final=='0')){
                    
                swal({title: "Cannot Save!",  text: "Please Add Items",showConfirmButton:true, showCancelButton: true, confirmButtonText: 'Ok',
              focusConfirm:true});  return;
                
                }else{
                    
                    $.ajax({
                            type : "POST",
                            url  : "<?php echo site_url('auth_inv_data')?>",
                            dataType : "JSON",
                            method:'POST',
                            data : {id:temp_id,qty:qty, total:total, dis:dis, final:final,other:other,remark:remark},
                            success: function(data){
                                //show_product()
                                swal('Authorized');
                                location.href = "<?php echo site_url('allqtn')?>/";
                            }
                        });
                      
                }
               
            return false;
            
          });
          
          //get data for delete record
        function del_data(clickedID){
            var product_code = clickedID;
            // alert(product_code);
            $('#Modal_Delete').modal('show');
            $('[name="product_code_delete"]').val(product_code);
        };
        
          //delete record to database
        $('#btn_delete').on('click',function(){
            var product_code = $('#product_code_delete').val();
            $.ajax({
                type : "POST",
                url  : "<?php echo site_url('prodelete_data')?>",
                dataType : "JSON",
                data : {product_code:product_code},
                success: function(data){
                    $('[name="product_code_delete"]').val("");
                    $('#Modal_Delete').modal('hide');
                    show_product();
                }
            });
            return false;
        });
        
               //show add new
    function show_servicedata(){
      $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('getservice_data')?>',
                dataType : 'json',
                success : function(data){
                     
                 var i;
                            for (var i = 0; i < data['service'].length; i++) {
                               $('#itemselect').append($('<option>', {
                                                            value: data['service'][i].serv_id,
                                                            text: data['service'][i].serv_name
                                                        }));
                            }
					
                }
 
            }); 
         
           
     
    }
    
        // save new data
    $('#save_data').on('click',function(){
     
             var rt = document.getElementById('table').value;
           
            swal({
                  title: "Are you sure?",
                  text: "Save, Entered Details will be Saved",
                  icon: "warning",
                  buttons: true,
                  dangerMode: true,
                })
                .then((willDelete) => {
                  if (willDelete) {
                               $.ajax({
                                type  : 'ajax',
                                method : "POST",
                                url   : "<?php echo site_url('')?>"+rt,
                                async : true,
                                dataType : 'json',
                                data: $("#frm_add_data").serialize(),
                                success : function(data){
                                    if(data[2]=="error"){
                                        swal(data[0]);
                                    }else{
                                        swal(data[0]);
                                        $("#addmodel").modal('hide');
                                        $('#tb_bdy').html("");
                                        show_servicedata();
                                        if(data[1].includes("supplier")){
                                            get_cus();
                                        }else{
                                           get_cat(); 
                                        }
                                        
                                    }
                                    
                                }
                 
                            });
                  } else {
                    swal("No Changes");
                    document.getElementById("load").style.display = "none";
                  }
                });
            
           
            
        });
        
   
       //show add new
    function add_data(clickedID){
     var rt = clickedID;
           $.ajax({
                        type  : 'ajax',
                        method : "POST",
                        url   : "<?php echo site_url('')?>"+rt,
                        async : true,
                        dataType : 'json',
                        success : function(data){
                              $('#addmodel').modal('show')
                            $('#Modal_Add').html(data);
                        }
         
                    });
           
     
    }
    
    function get_part(){
        
                if (event.keyCode == 13) {
                 console.log("Enter key is pressed");
                        var part = document.getElementById('add_num').value;
                        var all = $('#part_num').val();
                        if(part!=""){
                            if(all!=""){all = all + "\n" +part;}else{all = part;}
                        }
                        
                        
                        $('#part_num').val(all);
                        $('#add_num').val("");
                 return true;
              } else {
                 return false;
              }
        
    }

    function get_sup(){
        $('#supselect option').remove();
        $("#supselect").trigger("chosen:updated");
        $.ajax({
                        type  : 'ajax',
                        method : "POST",
                        url   : "<?php echo site_url('customer_list')?>",
                        async : true,
                        dataType : 'json',
                        success : function(data){
                            
                              $('#saleselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                               
               
                    
                             var i;
                    for(i=0; i<data[1].length; i++){
                            $('#saleselect').append($('<option>', {
                                                            value: data[1][i].user_id,
                                                            text: data[1][i].user_fname+" "+data[1][i].user_lname
                                                        }));
                        
                                                
                    }  
                                                
                    
                       $("#supselect").trigger("chosen:updated");
                       $("#saleselect").trigger("chosen:updated");
                        }
         
                    });
                    
                    
    }
    
    function get_cat(){ 
        $('#catselect option').remove();
        $("#catselect").trigger("chosen:updated");
        $.ajax({
                        type  : 'ajax',
                        method : "POST",
                        url   : "<?php echo site_url('catagory_list')?>",
                        async : true,
                        dataType : 'json',
                        success : function(data){
                              $('#catselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                                        
                                                        
                  var i;
                    for(i=0; i<data['cat'].length; i++){
                            $('#catselect').append($('<option>', {
                                                            value: data['cat'][i].cat_id,
                                                            text: data['cat'][i].cat_name
                                                        }));
                        
                                                
                    }
                       $("#catselect").trigger("chosen:updated");
                        }
         
                    });
                    
                    
    }

</script>

<script>
    jQuery(document).ready(function() {
        jQuery(".standardSelect").chosen({
            disable_search_threshold: 5,
            no_results_text: "Oops, nothing found!",
            width: "100%"
        });
    });
</script>