        <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>Product Management</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>
        
  
                <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" 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_name; ?></option>
                                                              <?php }?>                                                           
                                                            </select>
                                                        <input type="hidden" name="sup_type" value="" id="sup_type">                          
                                                    </div>
                                                    
                                                    <div class="col-sm-3"><br>
                                                       <!--button type="submit" class="btn btn-sm btn-primary btn-white btn-round" name="showhide" id="showhide">
                                                                                <i class="ace-icon fa fa-pencil-square-o bigger-150 middle orange2"></i>
                                                                                <span class="bigger-110">Show/Hide</span>

							                                        </button-->
                                                                  </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 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" /> 
                                                    </div>
                                                   
                                                   
                                                    
                                                   
                                                         
                                                     
                                               </div>
                                               
                                               <div class="row">
                                                    <div class="col-sm-3">  
                                                        Catagory
                                                        <select class="chosen-select 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">
                                                           Brand
                                                            <select class="form-control" id="brandselect" data-placeholder="Choose a brand..." name="brand">
							                                    <option value="0"> Select Brand </option>                                                         
                                                        </select> 
                                                    </div-->
                                                    
                                                    <div class="col-sm-3">
                                                            Part Number
                                                            <select class="form-control" id="partselect" data-placeholder="Choose a State..." name="partselect">
							                                    <option value="">  </option>
                                                                                                                 
                                                        </select>
                                                              </div>
                                                    <div class="col-sm-6">   
                                                        Product/Service
                                                        <select class="form-control" id="itemselect" data-placeholder="Choose a State..." name="itemselect">
							                                <option value="">  </option>                                                          
                                                        </select>                          
                                                    </div>
                                                   
                                                     
                                               </div>
                                               
                                               <div class="row">
                                                   
                                                    <div class="col-sm-2">
                                                            Price (LKR)
                                                        <input type="text" id="pricelkr"  name="pricelkr" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control" onkeyup="cur_cal()"/>
                                                                <?php echo form_error('productqty'); ?>
                                                    </div>
                                                    
                                                    <div class="col-sm-1" >
                                                            Cur
                                                        <input type="text" id="cur"  name="cur" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control" />
                                                        <input type="hidden" id="curid"  name="curid" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12" />
                                                    </div>
                                                    
                                                    
                                                        <div class="col-sm-1" style="display:none;" id="for_foreign">
                                                           Rate
                                                        <input type="text" id="cur_rt"  name="cur_rt" placeholder="" value="1"class="col-xs-12 col-sm-12 form-control" onkeyup="cur_cal()"/>
                                                    </div>
                                                    
                                                    <div class="col-sm-2" style="display:none;" id="for_foreign1">
                                                            Price
                                                        <input type="text" id="price"  name="price" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control" />
                                                                <?php echo form_error('productqty'); ?>
                                                    </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" onkeyup="sin_item_tot()"/>
                                                                <?php echo form_error('productqty'); ?>
                                                    </div>
                                                    
                                                    <div class="col-sm-1">
                                                            Unit
                                                        <input type="text" id="unit"  name="unit" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12 form-control" />
                                                        <input type="hidden" id="unitid"  name="unitid" placeholder="" value="<?php  ?> "class="col-xs-12 col-sm-12" />
                                                        
                                                                
                                                    </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" />
                                                                <?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;">
                                    										<table id="simple-table" class="table table-bordered">
                                    											<thead class="thead-dark">
                                    												<tr>
                                    													
                                    													<th scope="col"">Items</th>
                                    													<th>Items Description</th>
                                    													<th><span id="cr_chng"> Price</span> </th>
                                    													<th >Quantity </th>
                                                                                                                                            <th >Total </th>
                                    
                                    													
                                    													
                                    
                                    													<th>Action</th>
                                    												</tr>
                                    											</thead>
                                    
                                    											<tbody id="show_data">
                                    									
                                    								
                                    											</tbody>
                                    										</table>
                                    									</div><!-- /.span -->
                                                                                                            
                                                                                                            
                                    								</div><!-- /.row -->
                                                                
                                                                
                                                                                  
                                                
                                                                <div class="row">
                                                                       <div class="col-sm-3 d-inline">
                                                                              Total
                                                                            <input type="text" id="inv_total"  name="inv_total" placeholder="Total" value="0" class="col-xs-12 col-sm-12 form-control" />
                                                                        </div>
                                                                        <div class="col-sm-3 float-end">
                                                                              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" />
                                                                        </div>
                                                                </div> 
                                                                
                                                                    <div class="row">
                                                                        
                                                                       <div class="col-sm-3 pull-right">
                                                                              Discounted Amount
                                                                            <input type="text" id="dis_total"  name="dis_total" placeholder="%" value="0" class="col-xs-12 col-sm-12" onkeyup="cal_dis_amt();" />
                                                                        </div>
                                                                        <div class="col-sm-3 pull-right">
                                                                              Discount %
                                                                              <input type="text" id="dis_pc"  name="dis_pc" placeholder="Dis_amount" value="0" class="col-xs-12 col-sm-12" onkeyup="cal_dis_pc();" />
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                                                <div class="row">
                                                                        
                                                                       <div class="col-sm-3 pull-right">
                                                                              Other Amount
                                                                            <input type="text" id="other_amnt"  name="other_amnt" placeholder="Other" value="0.00" class="col-xs-12 col-sm-12" onkeyup="cal_total();" />
                                                                        </div>
                                                                        <div class="col-sm-3 pull-right">
                                                                              Other - Reason
                                                                              <input type="text" id="other_reason"  name="other_reason" placeholder="Total" value="Other" class="col-xs-12 col-sm-12" />
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                </div>
                                                                <div id="for_foreign" style="display: none;">
                                                                    <div class="row">
                                                                            <div class="col-sm-3 pull-right">
                                                                                 Banking Fee
                                                                                  <input type="text" id="bank_fee"  name="bank_fee" placeholder="bank_fee" value="0.00" class="col-xs-12 col-sm-12" onkeyup="cal_total();" />
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                    </div>
                                                                    <div class="row">
                                                                            <div class="col-sm-3 pull-right">
                                                                                 Shipping & Handling 
                                                                                  <input type="text" id="ship"  name="ship" placeholder="ship" value="0.00" class="col-xs-12 col-sm-12" onkeyup="cal_total();" />
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                    </div>
                                                                </div>
                                                                <div id="for_tax" style="display: none;">
                                                                    <div class="row">
                                                                        
                                                                       <div class="col-sm-3 pull-right">
                                                                              Taxed Amount
                                                                            <input type="text" id="tax_total"  name="tax_total" placeholder="Dis_amount" value="0" class="col-xs-12 col-sm-12" onkeyup="cal_tax_amt();" />
                                                                        </div>
                                                                        <div class="col-sm-3 pull-right">
                                                                              Tax %
                                                                              <input type="text" id="tax_pc"  name="tax_pc" placeholder="%" value="0" class="col-xs-12 col-sm-12" onkeyup="cal_tax_pc();" />
                                                                        <div class="help-block" id="input-span-slider"></div>
                                                                        </div>
                                                                    </div>
                                                                    <div class="row">
                                                                            <div class="col-sm-3 pull-right">
                                                                                 VAT 10% <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" onkeyup="cal_total();" />
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                    </div>
                                                                    <div class="row">
                                                                            <div class="col-sm-3 pull-right">
                                                                                 NBT 5% <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" onkeyup="cal_total();" />
                                                                            <div class="help-block" id="input-span-slider"></div>
                                                                            </div>
                                                                    </div>
                                                                </div>
                                                                <div class="row">
                                                                        
                                                                       <div class="col-sm-3 pull-right">
                                                                              Total amount
                                                                            <input type="text" id="final"  name="final" placeholder="Total" value="0" class="col-xs-12 col-sm-12" />
                                                                        </div>
                                                                        </div>
                                                                
                                    
                                     <div class="row">
                                                                        
                                        <div class="col-sm-3 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>
                                        </div>
                                         <div class="col-sm-3 center-block">
                                             <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>
                                        </div>
                                         <div class="col-sm-3 center-block">
                                            <button class="btn btn-white btn-info btn-bold" id="btn_cancel">
                                                    <i class="ace-icon fa fa-times red2"></i>
                                                    Cancel invoice
                                            </button>
                                        </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">
                <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">
                <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-->
            
            
<script src="<?php echo base_url(); ?>assets/js/jquery.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/popper.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery.matchHeight.min.js"></script>



<script>

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

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

    function cal_dis_pc(){
        var pc = $('#dis_pc').val();
        var dis = ($('#inv_total').val() * pc)/100;
      $('#dis_total').val(dis.toFixed(2));
      cal_total();
    }
    
    function cal_tax_pc(){
        var pc = $('#tax_pc').val();
        var dis = ($('#inv_total').val() * pc)/100;
      $('#tax_total').val(dis.toFixed(2));
      cal_total();
    }
    function cal_tax_amt(){
      $('#tax_pc').val("");
      cal_total();
    }

    function myvat(){
      var checkBox = document.getElementById("chk_vat");
            if (checkBox.checked == true){
          var vat = ($('#inv_total').val() * 10)/100;
        } else {
          var vat = 0;
        }
      
      $('[name="vat"]').val(vat);
      cal_total();
    }

    function mynbt(){
      var checkBox = document.getElementById("chk_nbt");
            if (checkBox.checked == true){
          var nbt = ($('#inv_total').val() * 5)/100;
        } else {
          var nbt = 0;
        }
      
      $('[name="nbt"]').val(nbt);
      cal_total();
    }

    function cal_total(){
     // if($('#dis_pc').val()!=""){
      //  var dis =  ($('#dis_pc').val() * $('#inv_total').val())/100;

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

        var total = parseInt($('#inv_total').val()) - parseInt(dis) + parseInt(other)+ parseInt(vat)+ parseInt(nbt)+ parseInt(tax_total)+parseInt(ship)+ parseInt(bank);
        $('[name="final"]').val(total);
    }

        //function show all product
        function show_product(){
        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].po_itm_unitprice * data[i].po_itm_qty));
                        var tot_item = tot_item + parseInt(data[i].po_itm_qty);
                        html += '<tr>'+
                                //'<td>'+(i+1)+'</td>'+
                                '<td>'+(i+1)+'</td>'+
                                '<td>'+data[i].item_description+'<br>'+data[i].part_no+'</td>'+
                                '<td>'+data[i].po_itm_unitprice+'</td>'+
                                '<td>'+data[i].po_itm_qty+'</td>'+
                                '<td>'+(data[i].po_itm_unitprice * data[i].po_itm_qty)+'</td>'+
                                '<td style="text-align:right;">'+
                                '<div class="hidden-sm hidden-xs btn-group">'+
                                    //'<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);
                    $('[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 item = e.options[e.selectedIndex].value;
            var f = document.getElementById("supselect");
            var sup_id = f.options[f.selectedIndex].value;

            var f = document.getElementById("partselect");
            var prt_id = f.options[f.selectedIndex].value;
            
            var dis_price = 1;
            var unit = $('#unitid').val();
            var cur = $('#curid').val();
            var tempid = $('#temp_id').val();
           // if(dis_price==="1"){
                //    var tot = price * qty;
               // }else{
                   var tot = price * qty; 
            
            $.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},
                success: function(data){
                    
                       // alert(data);
                    
                    //$("#agentselect").prop("disabled", false);
                   // $('#agentselect').prop('disabled', 'disabled');
                    show_product();
                    
                }
            });
            return false;
        };
    
    $('#catselect').change(function(){ 
       
                $('#brandselect option').remove();
                $('#itemselect option').remove();
                
          var id = $(this).val();
          
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getproduct')?>',
                dataType : 'json',
                data : {u_id:id},
                success : function(data){
                    $('#itemselect').append($('<option>', {
                                                            value: "0",
                                                            text: "select"
                                                        }));
                    $('#brandselect').append($('<option>', {
                                                            value: "0",
                                                            text: "select"
                                                        }));
                                                        
                    var i;
                    for(i=0; i<data['brand'].length; i++){
                                                $('#brandselect').append($('<option>', {
                                                            value: data['brand'][i].brand_id,
                                                            text: data['brand'][i].brand_name
                                                        }));
                    }
                    
                    var i;
                    for(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].itm_name+" | "+data['item'][i].item_description
                                                        }));
                    }
					
                }
 
            }); 
      });
      
      $('#supselect').change(function(){ 
                
          var id = $(this).val();
          
             $.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);
                    $('[name="curid"]').val(data['sup'][0].curr_id);
                    $('[name="sup_type"]').val(data['sup'][0].sup_type);
                    
                    if(data['sup'][0].sup_type=="Foreign"){
                      var txt = document.getElementById("for_foreign");
                      txt.style.display = "block";
                      var txt1 = document.getElementById("for_foreign1");                      
                      txt1.style.display = "block";
                      
                    }else{
                      var txt = document.getElementById("for_foreign");
                      txt.style.display = "none";
                      var txt1 = document.getElementById("for_foreign1");                      
                      txt1.style.display = "none";
                    }
                    
                    if(data['sup'][0].sup_tax == 1){
                      var txt = document.getElementById("for_tax");
                      txt.style.display = "block";
                    }else{
                      var txt = document.getElementById("for_tax");
                      txt.style.display = "none";
                    }
                    
                }
 
            }); 
      });
      
      
    $('#itemselect').change(function(){ 
       
                $('#partselect option').remove();
                
          var id = $(this).val();
          var f = document.getElementById("supselect");
            var sup_id = f.options[f.selectedIndex].value;
          
             $.ajax({
                type  : 'ajax',
                method:'POST',
                url   : '<?php echo site_url('Po_Controller/getpart')?>',
                dataType : 'json',
                data : {u_id:id,sup_id:sup_id},
                success : function(data){

                  $('#partselect').append($('<option>', {
                                                            value: "0",
                                                            text: "select"
                                                        }));
                     
                    if(data['itm'][0].item_partnum!=""){
                        var txt = data['itm'][0].item_partnum;
                        var splitted = txt.split("\n");
                            for (var i = 0; i < splitted.length; i++) {
                                 $('#partselect').append($('<option>', {
                                                            value: splitted[i],
                                                            text: splitted[i]
                                                        }));
                            }
                    }else{
                        $('#partselect').append($('<option>', {
                                                            value: data['itm'][0].item_spec,
                                                            text: data['itm'][0].item_spec
                                                        }));
                    }
                    //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
                    //                                    }));
                    //}
                   
                    $('[name="price"]').val(data['itm'][0].item_selling_price);
                    $('[name="pricelkr"]').val(data['itm'][0].item_selling_price);
					$('[name="unit"]').val(data['itm'][0].unit_symble);
					$('[name="unitid"]').val(data['itm'][0].unit_id);
					//$('[name="cur"]').val(data['sup'][0].curr_symble);
					//$('[name="curid"]').val(data['sup'][0].curr_id);
					if($('[name="curid"]').val()!=1){
					    $('[name="cur_rt"]').val(data['itm'][0].usd_rate);
					}
					
					cur_cal();
					
                }
 
            }); 
      }); 
      
      
                //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 vat = $('#vat').val();
            var nbt = $('#nbt').val();

            var other = $('#other_amnt').val();
            var cur = $('#curid').val();
            var unit = $('#unitid').val();
            var sup_type = $('#sup_type').val();
       
                
                $.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,vat:vat,nbt:nbt,other:other,cur:cur,unit:unit,sup_type:sup_type},
                success: function(data){
                    
                    //show_product()
                    alert('Data Saved');
                    location.href = "<?php echo site_url('Po_Controller/view_pdf')?>/"+data;
                }
            });
            return false;
            
          });
        
   
</script>















