        <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>Purchase Order</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 $temp_id;?> "class="col-xs-12 col-sm-12" />
                                                                
                                   <div class="row">
                                                    <div class="col-sm-3">  
                                                        Supplier
                                                            <select class="form-control standardSelect choosen-select" id="supselect" data-placeholder="Choose a Supplier..." name="sup">
    							                                <option value="0"> Select Supplier </option>
                                                             <?php 
                                                             foreach ($agentdetail as $dbagent) {            
                                                              ?>
    							                            <option value="<?php echo $dbagent->sup_id; ?>"><?php echo $dbagent->sup_company; ?></option>
                                                              <?php }?>                                                           
                                                            </select> 
                                                        <input type="hidden" name="sup_type" value="" id="sup_type">                          
                                                    </div>
                                                    
                                                     <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-3">
                                                           Sup Ref. No.
                                                           <input type="text" id="sup_ref"  name="sup_ref" placeholder="" value=""class="col-xs-12 col-sm-12 form-control input-sm form-control-sm" /> 
                                                    </div>
                                                    
                                                    
                                                    <div class="col-sm-3" style="text-align: center;">Add New<br>
                                                         
                                                            <button class="btn btn-secondary btn-sm" name="tax" id="new_product" onclick ="add_data(this.id);" data-backdrop='static' data-keyboard='false'>Product</button> 
                                                            <button class="btn btn-secondary btn-sm" name="Ser" id="add_services" onclick ="add_data(this.id);" data-backdrop='static' data-keyboard='false'>Services</button>
                                                            <button class="btn btn-secondary btn-sm" name="Ser" id="new_supplier" onclick ="add_data(this.id);" data-backdrop='static' data-keyboard='false'>Supplier</button>
                                                    </div>
                                                    
                                                    
                                                  
                                                   
                                                   
                                                    
                                                   
                                                         
                                                     
                                               </div>
                                               
                                               <div class="row">
                                                    <div class="col-sm-3">  
                                                        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 State..." 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-3">   
                                                        Product/Service
                                                        <select class="form-control standardSelect" id="itemselect" data-placeholder="Choose a State..." name="itemselect">
							                                <option value="">  </option>                                                          
                                                        </select>                          
                                                    </div>
                                                   </div>
                                               
                                               <div class="row">
                                                   
                                                    <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" onkeyup="cur_cal()"/>
                                                        
                                                    </div>
                                                    
                                                    <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-1" 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 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-1">
                                                            Quantity
                                                        <input type="text" id="qty"  name="qty" placeholder="" value="<?php  ?> "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 >
							                                
                                                         <?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" />
                                                                <?php echo form_error('productqty'); ?>
                                                    </div>
                                                    
                                                   <div class="col-sm-2"><br>
                                                        
                                                       <button type="button" class="btn btn-sm btn-primary btn-white btn-round" 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">Rate</span> </th>
                                    													<th style="text-align:right">Quantity </th>
                                                                                        <th style="text-align:right"><span id="cr2_chng">Total</span>  </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" 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" id="tcdes" data-placeholder="Choose a Supplier..." name="tcdes">
    							                                <option value="0"> Select Conditions</option>
    							                               
                                                             <?php 
                                                             foreach ($tc as $dbagent) {            
                                                              ?>
    							                            <option value="<?php echo $dbagent->tmdes_id; ?>"><?php echo $dbagent->tmdes_des; ?></option>
                                                              <?php }?>                                                           
                                                            </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 >   
                                                             <br>
                                                            <div class="col-lg-12">
                                                                 Remarks
                                                                 <textarea id="remark" name="remark" rows="2" cols="60" style="width: 100%;"></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"  name="inv_tot_item" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control" style="text-align: right;"/>
                                                                        </div>
                                                                       <div class="col-lg-6 float-end">
                                                                              Sub Total
                                                                            <input type="text" id="inv_total"  name="inv_total" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control" 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 d-inline">  
                                                                             Discount(Amount)
                                                                            <input type="text" id="dis_total"  name="dis_total" placeholder="%" value="0" class="col-xs-12 col-sm-12 form-control" onclick="this.select();" onkeyup="cal_dis_amt();" style="text-align: right;"/>
                                                                        </div>
                                                                        <div class="col-lg-6 float-end">
                                                                              Discount(%)
                                                                              <input type="text" id="dis_pc"  name="dis_pc" placeholder="Dis_amount" value="0" class="col-xs-12 col-sm-12 form-control" 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 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" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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" 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"  name="final" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control" style="text-align: right;"/>
                                                                        </div>
                                                                        </div>
                                                                         </div>
                                                                         </div>
                                    								        
                                    								    </div>
                                    								    
                                    								</div>
                                                                
                                                                
                                                                         
                                                              
                                                          <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-white btn-info btn-bold" id="btn_save">
                                                    <i class="ace-icon fa fa-floppy-o bigger-120 blue"></i>
                                                   Save
                                            </button>
                                             <button class="btn btn-white btn-info btn-bold" id="btn_draft">
                                                    <i class="ace-icon fa fa-floppy-o bigger-120 blue"></i>
                                                    Save for Later
                                            </button>
                                            <button class="btn btn-white btn-info btn-bold" id="btn_cancel">
                                                    <i class="ace-icon fa fa-times red2"></i>
                                                    Cancel PO
                                            </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">Add</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">
                            
                        </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_data">Confirm</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">Edit</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>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-primary" id="update_data">Confirm</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>



$(document).ready(function() {
    document.getElementById("load").style.display = "none";
    cal_ttot(); 
    
    show_product();
  $('#tcdes').change(function() {
    //debugger;
    let tr = $("<tr/>").appendTo("#data tbody");

    $('#tcdes, #tccat').each(function(index) {
      var input = $(this);
      $(tr).insertBefore("#finalrow").append('<td class=row-' + $(input).attr("id") + '><input type="hidden" id="term[]" name="term[]" value="' + $(input).find('option:selected').val() + '">' + $(input).find('option:selected').text() + '  </td>');
    });
    

    $(tr).append('<td class="row-time"></td>');
    $("#calc")[0].reset();

    var removeBtn = $('<button class="removeBtn btn btn-outline-danger btn-sm" id="removeBtn">X</button>');
    $('.row-time:last').append(removeBtn);

  });
});

$(document).ready(function() {
  $("#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;

    }


  });
});

 

    function cur_cal(){
       // var total = $('#pricelkr').val() / $('#cur_rt').val();
        var total = $('#price').val() * $('#cur_rt').val();
        $('[name="pricelkr"]').val(total.toFixed(2));
        sin_item_tot();
        cal_ttot();
    }
    
        function sin_item_tot(){
        var total = $('#price').val() * $('#qty').val();
        $('[name="total"]').val(total.toFixed(2));
        cal_ttot();
    }

    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_tax_pc(){
        var pc = $('#tax_pc').val();
        var dis = ($('#net').val() * pc)/100;
        //alert(dis);
      $('#tax_total').val(dis.toFixed(2));
      cal_ttot();
      cal_total();
    }
    
    function cal_tax_amt(){
        var tax_total = $('#tax_total').val();
      var pc = (tax_total/$('#net').val())*100;
      $('#tax_pc').val(pc);
      cal_total();
      cal_ttot();
    }

    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 myvat(){
      var checkBox = document.getElementById("chk_vat");
            if (checkBox.checked == true){
                var val = parseFloat($('#inv_total').val())+parseFloat($('#other_amnt').val())-parseFloat($('#dis_total').val())+parseFloat($('#nbt').val());
                var prc = '<?=$tax[0]->tax_value?>';
          var vat = (val * prc)/100;
        } else {
          var vat = 0;
        }
      
      $('[name="vat"]').val(vat.toFixed(2));
      cal_total();
    }

    function mynbt(){
      var checkBox = document.getElementById("chk_nbt");
            if (checkBox.checked == true){
                var val = parseFloat($('#inv_total').val())+parseFloat($('#other_amnt').val())-parseFloat($('#dis_total').val());
                var prc = '<?=$tax[1]->tax_value?>';
                var nbt = (val* prc)/100;
        } else {
          var nbt = 0;
        }
      
      $('[name="nbt"]').val(nbt.toFixed(2));
      cal_total();
    }

    function cal_total(){
    
      if($('#dis_total').val()!=""){
        var dis =  $('#dis_total').val();
      }else{ var dis = 0;}
      
      var nett =  parseInt($('#inv_total').val())-parseInt(dis);
      $('#net').val(nett);
      
        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)+ parseInt(vat)+ parseInt(nbt)+ parseInt(tax_total)+parseInt(ship)+ parseInt(bank)+ parseInt(trfee);
        $('[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(); ?>Po_Controller/getinvoice_product/'+tempid+'',
                async : true,
                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 + parseInt(data[i][4] * data[i][5]);
                        var tot_item = tot_item + parseInt(data[i][5]);
                        html += '<tr>'+
                                //'<td>'+(i+1)+'</td>'+
                                '<td>'+(i+1)+'</td>'+
                                '<td>'+data[i][0]+"-"+data[i][1]+'</td>'+
                                '<td>'+data[i][2]+'</td>'+
                                '<td style="text-align:right">'+data[i][3]+'</td>'+
                                '<td style="text-align:right">'+data[i][4]+'</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;">'+
                                '<div class="hidden-sm hidden-xs btn-group">'+
                                ' <button class="btn btn-outline-danger btn-sm" name="tax" id="'+data[i][6]+'" onclick ="del_data(this.id);">X</button>'+
                                    //'<a href="javascript:void(0);" class="btn btn-xs btn-success item_edit" data-product_code="'+data[i].inv_pro_id+'" data-product_price="'+data[i].product_name+'" data-product_prc="'+data[i].unit_price+'" data-qty="'+data[i].qty+'"><i class="ace-icon fa fa-pencil bigger-120"></i></a>'+' '+
                                   // '<a href="javascript:void(0);" class="btn btn-xs btn-danger item_delete" data-product_code="'+data[i].po_itm_id+'"><i class="ace-icon fa fa-trash-o bigger-120"></i></a>'+
                               '</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";
                }
 
            });
        }


     function  show_term(){
           
           var tempid = $('#temp_id').val();
                       $.ajax({
                type  : 'ajax',
                url   : '<?php echo base_url(); ?>Po_Controller/termshow/'+tempid+'',
                async : true,
                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 + parseInt((data[i].po_itm_unitprice * data[i].po_itm_qty));
                       // var tot_item = tot_item + parseInt(data[i].po_itm_qty);
                        
                        $('#lblName').text(data[i].tcat_name+ ':' +data[i].tmdes_des);
                       
                       
                    }
                   // $('#show_data').html(html);
                   // $('[name="inv_total"]').val(tot);
                   // $('[name="inv_tot_item"]').val(tot_item);
                   // cal_total();
                }
 
            });
       } 

        //$('#addrow').on('click',function(){
            function addrow(){
           // alert("test");
            var price = $('#price').val();
            var qty = $('#qty').val();
            var e = document.getElementById("itemselect");
            
            var f = document.getElementById("supselect");
            var sup_id = f.options[f.selectedIndex].value;
            

            var ff = document.getElementById("partselect");
            var prt_id = ff.options[ff.selectedIndex].value;
            
            var dis_price = 1;
            var unt = document.getElementById("unitid");
                var unit = unt.options[unt.selectedIndex].value;
        
            var curn = document.getElementById("curid");
                var cur = curn.options[curn.selectedIndex].value;
           // var cur = $('#curid').val();
            var tempid = $('#temp_id').val();
           
                   var tot = price * qty; 
            var g = document.getElementById("catselect");
            var cat = g.options[g.selectedIndex].value;       
            
            if(cat=="0000"){
                var ser =  e.options[e.selectedIndex].value; var item = "";}else{var ser = ""; var item = e.options[e.selectedIndex].value;}
                
            $.ajax({
                type : "POST",
                url  : "<?php echo site_url('Po_Controller/addinvoice_product')?>",
                dataType : "JSON",
                data : {temp_id:tempid, price:price , qty:qty, item:item, sup:sup_id,unit:unit,cur:cur,prt_id:prt_id,ser:ser},
                success: function(data){
                    document.getElementById("curid").disabled = true;
                    document.getElementById("supselect").disabled = true;
                    show_product();
                    
                }
            });
            return false;
        };
        
        
        
        $('#tccat').change(function(){ 
            document.getElementById("load").style.display = "block";
            $('#tcdes option').remove();
             var f = document.getElementById("tccat");
            var cat_id = f.options[f.selectedIndex].value;
           
              $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/gettc')?>',
                dataType : 'json',
                data : {cat_id:cat_id},
                success : function(data){
                    console.log(data);
                    $('#tcdes').append($('<option>', {
                                                            value: "0",
                                                            text: "select"
                                                        }));
                                                        
                                                         var i;
                            for (var i = 0; i < data['tc'].length; i++) {
                               $('#tcdes').append($('<option>', {
                                                            value: data['tc'][i].tmdes_id,
                                                            text: data['tc'][i].tmdes_des
                                                        }));
                            }
                    
          document.getElementById("load").style.display = "none";
					
                }
 
            });
        });
        
        function addtcrow(){
            
            var f = document.getElementById("tccat");
            var tc_cat = f.options[f.selectedIndex].value;
            var d = document.getElementById("tcdes");
            var tc_des = d.options[d.selectedIndex].value;
            var tempid = $('#temp_id').val();
            
              $.ajax({
                type : "POST",
                url  : "<?php echo site_url('Po_Controller/addtc')?>",
                dataType : "JSON",
                data : {temp_id:tempid, tc_cat:tc_cat , tc_des:tc_des},
                success: function(data){
                    
                       alert(data);
                    
                    //$("#agentselect").prop("disabled", false);
                   // $('#agentselect').prop('disabled', 'disabled');
                    //show_product();
                    show_term();
                    
                }
            });
            return false;
            
        }
        

    
    $('#catselect').change(function(){ 
        document.getElementById("load").style.display = "block";
    
                $('#partselect option').remove();
                $('#itemselect option').remove();
                $('#specselect option').remove();
                
                $('[name="price"]').val("");
                    $('[name="pricelkr"]').val("");
					
          var id = $(this).val();
          if(id=="0000"){
              var g = document.getElementById("catselect");
                var id = g.options[g.selectedIndex].value;
                document.getElementById("load").style.display = "block";
              
              $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getservice')?>',
                dataType : 'json',
                data : {cat_id:id},
                success : function(data){
                    $('#partselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                    
                    
                    
                     $('#itemselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                     
                 var i;
                            for (var i = 1; i < data['service'].length; i++) {
                               $('#itemselect').append($('<option>', {
                                                            value: data['service'][i].serv_id,
                                                            text: data['service'][i].serv_name
                                                        }));
                            }
					document.getElementById("load").style.display = "none";
					$("#partselect").trigger("chosen:updated");
					$("#itemselect").trigger("chosen:updated");
				
                }
 
            }); 
          }else{
              document.getElementById("load").style.display = "block";
              var g = document.getElementById("catselect");
                var id = g.options[g.selectedIndex].value;
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getpart_num')?>',
                dataType : 'json',
                data : {cat_id:id},
                success : function(data){
                    $('#partselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                    
                    var i;
                    for(i=0; i<data['part'].length; i++){
                            $('#partselect').append($('<option>', {
                                                            value: data['part'][i].part_id,
                                                            text: data['part'][i].part_no
                                                        }));
                        
                                                
                    }
                    
                     $('#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].brand_name+"|"+data['item'][i].model_name+"|"+data['item'][i].itm_name+"|"+data['item'][i].spec_spec
                                                        }));
                            }
                            
                        $('#specselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));   
                     
                 var i;
                            for (var i = 0; i < data['spec'].length; i++) {
                               $('#specselect').append($('<option>', {
                                                            value: data['spec'][i].spec_id,
                                                            text: data['spec'][i].spec_spec
                                                        }));
                            }
                            
                            
                    document.getElementById("load").style.display = "none";  
                    choos();
					
                }
 
            }); 
          }
      });
      
      $('#supselect').change(function(){ 
          document.getElementById("load").style.display = "block";
                    $('[name="price"]').val("");
                    $('[name="pricelkr"]').val("");
					$('[name="qty"]').val("");
					$('[name="total"]').val("");
					document.getElementById("curid").selectedIndex = "0";
					 
          var id = $(this).val();
          if(id!=0){
              $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getsup')?>',
                dataType : 'json',
                data : {sup_id:id},
                success : function(data){
                    $('[name="cur"]').val(data['sup'][0].curr_symble);
                    $("#curid").val(data['sup'][0].curr_id);
                    $('[name="sup_type"]').val(data['sup'][0].sup_type);
                    document.getElementById("cr_chng").innerHTML = "Rate("+data['sup'][0].curr_symble+")"; 
                    document.getElementById("cr2_chng").innerHTML = "Total("+data['sup'][0].curr_symble+")"; 
                    
                    if(data['sup'][0].sup_type=="Foreign"){
                      var txt1 = document.getElementById("for_foreign1");                      
                      txt1.style.display = "none";
                      var txt2 = document.getElementById("trafee");                      
                      txt2.style.display = "none";
                      
                      document.getElementById("for_foreign2").style.display = "block";
                      $('#supselect_chosen').css('border', '3px solid rgb(247, 166, 126)');
                      
                      
                    }else{
                      var txt1 = document.getElementById("for_foreign1");                      
                      txt1.style.display = "none";
                      document.getElementById("for_foreign2").style.display = "none";
                      document.getElementById("trafee").style.display = "block";
                      $('#supselect_chosen').css('border', '0px solid #ced4da');
                    }
                    
                    if(data['sup'][0].sup_tax == 1){
                        if(data['sup'][0].sup_type=="Foreign"){
                            var txt = document.getElementById("tx");
                            txt.style.display = "block";
                        }else{
                      var txt = document.getElementById("for_tax");
                      txt.style.display = "block";
                        }
                    }else{
                      var txt = document.getElementById("for_tax");
                      txt.style.display = "none";
                    }
                    document.getElementById("load").style.display = "none";
                    choos();
                }
 
            }); 
          }else{
              document.getElementById("load").style.display = "none";
          }
             
      });
    
    $('#partselect').change(function(){ 
       
                $('#itemselect option').remove();
                $('#specselect option').remove();
                $('#specselect').append($('<option>', {value: "",text: "select" }));
                
                $('[name="price"]').val("");
                    $('[name="pricelkr"]').val("");
                
          //var id = $(this).val();
          //var f = document.getElementById("partselect");
            var part_id = $(this).val();
             document.getElementById("load").style.display = "block";
          
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getprod')?>',
                dataType : 'json',
                data : {part_id:part_id},
                success : function(data){
                            for (var i = 0; i < data['item'].length; i++) {
                               $('#itemselect').append($('<option>', {
                                                            value: data['item'][i].item_id,
                                                            text: data['item'][i].brand_name+"|"+data['item'][i].model_name+"|"+data['item'][i].itm_name
                                                        }));
                            }
                   
                       // $('[name="price"]').val(data['item'][0].item_selling_price);
                  //  $('[name="pricelkr"]').val(data['item'][0].item_selling_price);
                  $("#unitid").val(data['item'][0].unit_id);
                  document.getElementById("load").style.display = "none";
					cur_cal();choos();
                }
 
            }); 
      });  
      
    $('#itemselect').change(function(){ 
       
                $('#partselect option').remove();
                $('#partselect').append($('<option>', {value: "",text: "select" }));
                $('#specselect option').remove();
                $('#specselect').append($('<option>', {value: "",text: "select" }));
                
                var f = document.getElementById("catselect");
                var cat = f.options[f.selectedIndex].value;
                
                var g = document.getElementById("itemselect");
                var id = g.options[g.selectedIndex].value;
                
          //var id = $(this).val();
          
          if(id!=0){
              if(cat!="0000"){
                  
                  var g = document.getElementById("itemselect");
                var id = g.options[g.selectedIndex].value;
                  $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getpart')?>',
                dataType : 'json',
                data : {itm_id:id},
                success : function(data){
                  $('#partselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                                        
                                                        
                  var i;
                    for(i=0; i<data['prt'].length; i++){
                        var dd = data['prt'][i].split("/");
                            $('#partselect').append($('<option>', {
                                                            value: dd[0],
                                                            text: dd[1]
                                                        }));
                        
                                                
                    }
                   
                    //$('[name="price"]').val(data['item'][0].item_selling_price);
                   // $('[name="pricelkr"]').val(data['item'][0].item_selling_price);
                   $("#unitid").val(data['item'][0].unit_id);
					cur_cal();choos();
					
                }
 
            }); 
              
                  
              }else{
                  var g = document.getElementById("itemselect");
                var id = g.options[g.selectedIndex].value;
                $('#partselect option').remove();
                $('#partselect').append($('<option>', { value: "", text: "select" }));
                $('#specselect option').remove(); $('#specselect').append($('<option>', { value: "", text: "select" }));
                
                $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getserv_id')?>',
                dataType : 'json',
                data : {id:id},
                success : function(data){
                  $('#partselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                                        var dt = data['service'][0].unit_id+1;
                                                        $("#unitid").val(data['service'][0].unit_id);
				
				choos();
					
                }
 
            }); 
                
                   
                    $('[name="price"]').val("1");
                    $('[name="pricelkr"]').val("1");
                }
          }
         
      }); 
     
    $('#specselect').change(function(){ 
       
                $('#itemselect option').remove(); 
                $('#itemselect').append($('<option>', { value: "", text: "select" }));
                
                
                $('#partselect option').remove(); $('#partselect').append($('<option>', { value: "", text: "select" }));
                
                $('[name="price"]').val("");
                    $('[name="pricelkr"]').val("");
                
          //var id = $(this).val();
          //var f = document.getElementById("partselect");
            var part_id = $(this).val();
          
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getprod_spec')?>',
                dataType : 'json',
                data : {part_id:part_id},
                success : function(data){
                            for (var i = 0; i < data['item'].length; i++) {
                               $('#itemselect').append($('<option>', {
                                                            value: data['item'][i].item_id,
                                                            text: data['item'][i].brand_name+"|"+data['item'][i].model_name+"|"+data['item'][i].itm_name
                                                        }));
                            }
                   
                     //   $('[name="price"]').val(data['item'][0].item_selling_price);
                   // $('[name="pricelkr"]').val(data['item'][0].item_selling_price);
					$("#unitid").val(data['item'][0].unit_id);
					cur_cal();choos();
                }
                
            }); 
      }); 
    
      
                //Save data to invoice
        $('#btn_save').on('click',function(){
            var e = document.getElementById("supselect");
            var agent_id = e.options[e.selectedIndex].value;
            var temp_id = $('#temp_id').val();
            var qty = $('#inv_tot_item').val();
            var total = $('#inv_total').val();
            var dis = $('#dis_total').val();
            var dis_val = $('#dis_total').val();
            var final = $('#final').val();
            var mes_ref = $('#mes_ref').val();
            var sup_ref = $('#sup_ref').val();
            var bank_fee = $('#bank_fee').val();
            var ship = $('#ship').val();
            var tax = $('#tax_pc').val();
            var vat = $('#vat').val();
            var nbt = $('#nbt').val();
            var trfee = $('#trfee').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 sup_type = $('#sup_type').val();
            var remark = $('#remark').val();
          
          
                //$(function(){
                var tcvalues = $("input[name='term\\[\\]']")
              .map(function(){return $(this).val();}).get();
                //});
                
                if(tcvalues.length != 0){
                                $.ajax({
                            type : "POST",
                            url  : "<?php echo site_url('Po_Controller/save_inv')?>",
                            dataType : "JSON",
                            data : {agent_id:agent_id, temp_id:temp_id, qty:qty, total:total, dis:dis, dis_val:dis_val, final:final,mes_ref:mes_ref,sup_ref:sup_ref,bank_fee:bank_fee,ship:ship,tax:tax,vat:vat,nbt:nbt,other:other,trfee:trfee,cur:cur,unit:unit,sup_type:sup_type,tcvalues:tcvalues,remark:remark},
                            success: function(data){
                                
                                //show_product()
                                swal('Data Saved');
                               
                                location.href = "<?php echo site_url('allpo')?>/";
                            }
                        });
                }else{
                    swal("please add terms and condition");
                }
                
                
            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('Po_Controller/delete')?>",
                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('Po_Controller/getservice')?>',
                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_sup();
                                        }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 choos(){
                    $("#partselect").trigger("chosen:updated");
					$("#itemselect").trigger("chosen:updated");
					$("#specselect").trigger("chosen:updated");
    }
    
    function get_sup(){
        $('#supselect option').remove();
        $("#supselect").trigger("chosen:updated");
        $.ajax({
                        type  : 'ajax',
                        method : "POST",
                        url   : "<?php echo site_url('supplier_list')?>",
                        async : true,
                        dataType : 'json',
                        success : function(data){
                              $('#supselect').append($('<option>', {
                                                            value: "",
                                                            text: "select"
                                                        }));
                                                        
                                                        
                  var i;
                    for(i=0; i<data['sup'].length; i++){
                            $('#supselect').append($('<option>', {
                                                            value: data['sup'][i].sup_id,
                                                            text: data['sup'][i].sup_company
                                                        }));
                        
                                                
                    }
                       $("#supselect").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>