<script>

$("#local_material_purchase_bill_paid_date_add,#local_material_purchase_bill_paid_date_edit,#local_material_purchase_bill_reference_date_add,#local_material_purchase_bill_date_add").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  },
  endDate: '+0d',
  <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
    startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
    <?php } ?>
  })
  $('body').on('change', '#local_material_purchase_bill_payment_mode_add', function() {
    var payment_mode=$('#local_material_purchase_bill_payment_mode_add :selected').val();
    if(payment_mode=='POST DATED CHEQUE'){
      $('#local_material_purchase_bill_paid_date_add').datepicker('destroy');
      $("#local_material_purchase_bill_paid_date_add").datepicker( {
        todayHighlight:!0, orientation:"bottom left", templates: {
          leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
        },
        <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
          startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
          <?php } ?>
        })
      }else{
        $('#local_material_purchase_bill_paid_date_add').datepicker('destroy');
        $("#local_material_purchase_bill_paid_date_add").datepicker( {
          todayHighlight:!0, orientation:"bottom left", templates: {
            leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
          },
          endDate: '+0d',
          <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
            startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
            <?php } ?>
          })
        }
      })

      $("#local_material_purchase_bill_tax_percent_add").select2({
        placeholder: "Select Tax %",
        dropdownParent: $("#form_local_material_purchase_bill_add")
      })
      $("#local_material_purchase_bill_debit_acc_add").select2({
        placeholder: "Select Debit Account",
        dropdownParent: $("#form_local_material_purchase_bill_add")
      })
      $("#local_material_purchase_bill_payment_mode_add").select2({
        placeholder: "Select Debit Account",
        dropdownParent: $("#form_local_material_purchase_bill_add")
      })
      $("#local_material_purchase_bill_work_add").select2({
        placeholder: "Select Work",
        dropdownParent: $("#form_local_material_purchase_bill_add"),
        templateResult: format_project_dropdown
      })

      $("#local_material_purchase_bill_work_edit").select2({
        placeholder: "Select Work",
        dropdownParent: $("#form_local_material_purchase_bill_edit"),
        templateResult: format_project_dropdown
      })
      $("#local_material_purchase_bill_tax_percent_edit").select2({
        placeholder: "Select Tax %",
        dropdownParent: $("#form_local_material_purchase_bill_edit")
      })
      $("#local_material_purchase_bill_debit_acc_edit").select2({
        placeholder: "Select Debit Account",
        dropdownParent: $("#form_local_material_purchase_bill_edit")
      })
      $("#expense_head_edit").select2({
        placeholder: "Select Expense Head",
        dropdownParent: $("#form_local_material_purchase_bill_edit")
      })

      <?php if($page_name=='work_profile'){?>
        var work_id = "<?php echo $work_data->work_id ?>";
        $("#local_material_purchase_bill_work_add").val(work_id).trigger('change');
        $("#local_material_purchase_bill_work_add").attr('required',true);

        $("#local_material_purchase_bill_work_edit").val(work_id).trigger('change');
        $("#local_material_purchase_bill_work_edit").attr('required',true);
        <?php } ?>

        function calculate_local_material_purchase_bill_balance(form_type=''){
          if(form_type=='edit'){
            var tax_percent = parseFloat($('#local_material_purchase_bill_tax_percent_edit :selected').data('tax-percent'));
            var bill_amount = parseFloat(($("#local_material_purchase_bill_amount_edit").val()=='') ? 0 : parseFloat($("#local_material_purchase_bill_amount_edit").val()));
            var tax_amount = bill_amount*tax_percent/100;
            $("#local_material_purchase_bill_tax_amount_edit").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            var payable_amount = parseFloat(bill_amount+tax_amount);
            $("#local_material_purchase_bill_payable_amount_edit").val(payable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            var paid_amount = ($("#local_material_purchase_bill_total_paid_edit").val()=='') ? 0 : parseFloat($("#local_material_purchase_bill_total_paid_edit").val());
            $("#local_material_purchase_bill_balance_edit").val((payable_amount-paid_amount).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
          }else{
            var tax_percent = parseFloat($('#local_material_purchase_bill_tax_percent_add :selected').data('tax-percent'));
            var bill_amount = parseFloat(($("#local_material_purchase_bill_amount_add").val()=='') ? 0 : parseFloat($("#local_material_purchase_bill_amount_add").val()));
            var tax_amount = bill_amount*tax_percent/100;
            $("#local_material_purchase_bill_tax_amount_add").val(tax_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            var payable_amount = parseFloat(bill_amount+tax_amount);
            $("#local_material_purchase_bill_payable_amount_add").val(payable_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
            var paid_amount = ($("#local_material_purchase_bill_paid_amount_add").val()=='') ? 0 : parseFloat($("#local_material_purchase_bill_paid_amount_add").val());
            $("#local_material_purchase_bill_balance_amount_add").val((payable_amount-paid_amount).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
          }
        }
        $('body').on('change keyup', '#local_material_purchase_bill_paid_amount_add', function() {
          var value = $(this).val();
          // if(value=="" || value==null){
          //   $(this).val(0)
          // }
          if($(this).val()>0){
            $(".local_material_purchase_bill_paid_amount_req_fields").attr('required',true);
          }else{
            $(".local_material_purchase_bill_paid_amount_req_fields").removeAttr('required',true);
          }
          calculate_local_material_purchase_bill_balance('add');
        })
        $('body').on('change keyup', '.local_material_purchase_bill_amount_fields_add', function() {
          var value = $(this).val();
          // if(value=="" || value==null){
          //   $(this).val(0);
          // }
          calculate_local_material_purchase_bill_balance('add');
          $("#local_material_purchase_bill_paid_amount_add").val($('#local_material_purchase_bill_payable_amount_add').val());
          $("#local_material_purchase_bill_paid_amount_add").attr('max',$('#local_material_purchase_bill_payable_amount_add').val());
          if($("#local_material_purchase_bill_paid_amount_add").val()>0){
            $(".local_material_purchase_bill_paid_amount_req_fields").attr('required',true);
          }else{
            $(".local_material_purchase_bill_paid_amount_req_fields").removeAttr('required',true);
          }
        })
        $('body').on('change keyup', '#local_material_purchase_bill_date_add', function() {
          $("#local_material_purchase_bill_paid_date_add").datepicker("setDate",$(this).val());
        })

        $('body').on('change keyup', '.local_material_purchase_bill_amount_fields_edit', function() {
          var value = $(this).val();
          // if(value=="" || value==null){
          //   $(this).val(0)
          // }
          calculate_local_material_purchase_bill_balance('edit');
        })
        $('body').on('click', '#btn_add_local_material_purchase_bill', function() {
          var i = parseInt($('#current_row_count_local_purchase_items').val());
          if(i==0){
            var item_no = i + 1;
            var new_row = '<tr class="row_'+i+'">';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="'+item_no+'" name="bill_items[sl_no]['+i+']" value="'+item_no+'"/></div></div></td>';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Item Name" class="form-control m-input" name="bill_items[item_name]['+i+']" id="bill_item_name_'+item_no+'"/></div></div></td>';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input numeric_fields local_material_purchase_item_add_fields" data-sl-no="'+item_no+'" name="bill_items[item_qty]['+i+']" id="bill_item_qty_'+item_no+'"/></div></div></td>';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Unit" class="form-control m-input local_material_purchase_item_add_fields" name="bill_items[item_unit]['+i+']" id="bill_item_unit_'+item_no+'"/></div></div></td>';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Rate" class="form-control m-input numeric_fields local_material_purchase_item_add_fields" data-sl-no="'+item_no+'" name="bill_items[item_rate]['+i+']" id="bill_item_rate_'+item_no+'"/></div></div></td>';
            new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input readonly required type="text" placeholder="Total Amt" class="form-control m-input numeric_fields local_material_purchase_item_add_fields local_material_purchase_item_total_add" name="bill_items[item_total]['+i+']" id="bill_item_total_'+item_no+'"/></div></div></td>';
            // new_row += '<td><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_local_purchase_items btn btn-danger btn-icon-only" ><i class="fa fa-trash"></i></a></td>';
            new_row += '<td></td>';
            new_row += '</tr>';
            $('#table_body_local_purchase_items').append(new_row);
            $('#current_row_count_local_purchase_items').val(item_no);
          }

        })
        $('body').on('click', '#local_material_purchase_bill_edit_btn', function() {
          var no = $(this).closest('tr').children('td');
          $('#local_material_purchase_bill_id_edit').val(no.eq(28).text());
          $('#local_material_purchase_bill_date_edit').datepicker("setDate", no.eq(2).text());
          var expense_type=no.eq(3).text();
          $('#local_material_purchase_bill_work_edit').val(no.eq(27).text()).trigger('change');
          $('#local_material_purchase_bill_no_edit').val(no.eq(5).text());
          $('#local_material_purchase_bill_consignee_edit').val(no.eq(6).text());
          $('#local_material_purchase_bill_payable_amount_edit').val(no.eq(15).text());
          $('#local_material_purchase_bill_description_edit').val(no.eq(19).text());
          $('#local_material_purchase_bill_remarks_edit').val(no.eq(20).text());
          $('#expense_head_edit').val(no.eq(26).text()).trigger('change');
          $('#local_material_purchase_bill_total_paid_edit').val(no.eq(16).text());
          $('#local_material_purchase_bill_balance_edit').val(no.eq(17).text());
          $('#local_material_purchase_bill_tax_percent_edit').val(no.eq(30).text()).trigger('change');
          var tax_amount=parseFloat(no.eq(31).text());
          var payable_amount=parseFloat(no.eq(15).text());
          var bill_amount = parseFloat(payable_amount-tax_amount);
          $('#local_material_purchase_bill_amount_edit').val(bill_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
          var file = no.eq(29).text();
          if(file!=''){
            var file_data='<tr>'+
            '<td><a style="word-break: break-all" target="_blank" href="'+file+'" style="margin-left: 5px;margin-right: 5px" >'+file+'</a></td>'+
            '<td><a style="margin-left: 5px;margin-right: 5px" id="local_material_purchase_bill_attachment_item_delete_btn" href="javascript:;" class="btn btn-sm btn-danger m-btn m-btn--icon  m-btn--pill m-btn--air"><i class="la la-trash"></i> Change</a></td>'+
            '</tr>';
            $("#local_material_purchase_bill_edit_file_table_body").html(file_data);
            $("#local_material_purchase_bill_edit_file_table").show();
            $("#local_material_purchase_bill_edit_file_upload").hide();
          }else{
            $("#local_material_purchase_bill_edit_file_table").hide();
            $("#local_material_purchase_bill_edit_file_upload").show();
          }
          var bill_items = no.eq(32).text();
          if(bill_items!=''){
            var obj = $.parseJSON(bill_items);
            var i=0;var item_no=1;
            var bill_items_row='';
            while (i < obj.length) {
              var new_row = '<tr class="row_'+i+'">';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="'+item_no+'" name="bill_items[sl_no]['+i+']" value="'+item_no+'"/></div></div></td>';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Item Name" class="form-control m-input" name="bill_items[item_name]['+i+']" value="'+obj[i]['item_name']+'" id="bill_item_name_'+item_no+'_edit"/></div></div></td>';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields" data-sl-no="'+item_no+'" value="'+obj[i]['item_qty']+'" name="bill_items[item_qty]['+i+']" id="bill_item_qty_'+item_no+'_edit"/></div></div></td>';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input local_material_purchase_item_edit_fields" value="'+obj[i]['item_unit']+'" name="bill_items[item_unit]['+i+']" id="bill_item_unit_'+item_no+'_edit"/></div></div></td>';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields" data-sl-no="'+item_no+'" value="'+obj[i]['item_rate']+'" name="bill_items[item_rate]['+i+']" id="bill_item_rate_'+item_no+'_edit"/></div></div></td>';
              new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required readonly type="text" placeholder="Total Amt" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields local_material_purchase_item_total_edit" value="'+obj[i]['item_total']+'" name="bill_items[item_total]['+i+']" id="bill_item_total_'+item_no+'_edit"/></div></div></td>';
              if(i!=0){
                new_row += '<td><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_local_purchase_items_edit btn btn-danger btn-icon-only" ><i class="fa fa-trash"></i></a></td>';
              }else{
                new_row += '<td></td>';
              }
              new_row += '</tr>';
              item_no++;
              i++;
              bill_items_row+=new_row;
              // $('#table_body_local_purchase_items_edit').append(new_row);
              $('#current_row_count_local_purchase_items_edit').val(item_no);
            }
            $("#table_body_local_purchase_items_edit").html(bill_items_row);
          }
          calculate_local_material_purchase_bill_balance('edit');
        })
        $('body').on('click', '#local_material_purchase_bill_attachment_item_delete_btn', function() {
          $("#local_material_purchase_bill_edit_file_table").hide();
          $("#local_material_purchase_bill_edit_file_upload").show();
          $("#local_material_purchase_bill_attachment_delete_status").val(1);
        })

        function calculate_bill_item_total(form_type='add'){
          var grand_total_amount = 0;

          $(".local_material_purchase_item_total_"+form_type).each(function(){
            if($(this).val()!=''){
              grand_total_amount += parseFloat($(this).val());
            }
          });
          $("#local_material_purchase_bill_amount_"+form_type).val(grand_total_amount);
          calculate_local_material_purchase_bill_balance(form_type)
        }
        $('body').on('change keyup', '.local_material_purchase_item_add_fields', function() {
          var slno = $(this).data('sl-no');
          var qty = parseFloat($("#bill_item_qty_"+slno).val());
          var rate = parseFloat($("#bill_item_rate_"+slno).val());
          if (isNaN(rate)) {
            rate = 0;
          }
          if (isNaN(qty)) {
            qty = 0;
          }
          var total = qty*rate;
          $("#bill_item_total_"+slno).val(total.toFixed(2));
          calculate_bill_item_total('add');
        })
        $('body').on('change keyup', '.local_material_purchase_item_edit_fields', function() {
          calculate_bill_item_total('edit');
        })

        $("#addrow_local_purchase_items").on("click", function () {
          var i = parseInt($('#current_row_count_local_purchase_items').val());
          var item_no = i + 1;
          var new_row = '<tr class="row_'+i+'">';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="'+item_no+'" name="bill_items[sl_no]['+i+']" value="'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Item Name" class="form-control m-input" name="bill_items[item_name]['+i+']" id="bill_item_name_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input numeric_fields local_material_purchase_item_add_fields" data-sl-no="'+item_no+'" name="bill_items[item_qty]['+i+']" id="bill_item_qty_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Unit" class="form-control m-input local_material_purchase_item_add_fields" name="bill_items[item_unit]['+i+']" id="bill_item_unit_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Rate" class="form-control m-input numeric_fields local_material_purchase_item_add_fields" data-sl-no="'+item_no+'" name="bill_items[item_rate]['+i+']" id="bill_item_rate_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required readonly type="text" placeholder="Total Amt" class="form-control m-input numeric_fields local_material_purchase_item_add_fields local_material_purchase_item_total_add" name="bill_items[item_total]['+i+']" id="bill_item_total_'+item_no+'"/></div></div></td>';
          new_row += '<td><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_local_purchase_items btn btn-danger btn-icon-only" ><i class="fa fa-trash"></i></a></td>';
          new_row += '</tr>';
          $('#table_body_local_purchase_items').append(new_row);
          $('#current_row_count_local_purchase_items').val(item_no);
          calculate_bill_item_total('add');
        });

        $("#table_body_local_purchase_items").on("click", ".ibtnDel_local_purchase_items", function (event) {
          var sl_no = $(this).attr("data-sl-no");

          var counter = parseInt($("#current_row_count_local_purchase_items").val());
          $(this).closest("tr").remove();
          counter -= 1;
          // $("#current_row_count_local_purchase_items").val(counter);
          calculate_bill_item_total('add');
        });


        $("#addrow_local_purchase_items_edit").on("click", function () {
          var i = parseInt($('#current_row_count_local_purchase_items_edit').val());
          var item_no = i + 1;
          var new_row = '<tr class="row_'+i+'">';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input item_slno" data-sl-no="'+item_no+'" name="bill_items[sl_no]['+i+']" value="'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Item Name" class="form-control m-input" name="bill_items[item_name]['+i+']" id="bill_item_name_'+item_no+'_edit"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Qty" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields" data-sl-no="'+item_no+'" name="bill_items[item_qty]['+i+']" id="bill_item_qty_'+item_no+'_edit"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Unit" class="form-control m-input local_material_purchase_item_edit_fields" name="bill_items[item_unit]['+i+']" id="bill_item_unit_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required type="text" placeholder="Rate" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields" data-sl-no="'+item_no+'" name="bill_items[item_rate]['+i+']" id="bill_item_rate_'+item_no+'"/></div></div></td>';
          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input required readonly type="text" placeholder="Total Amt" class="form-control m-input numeric_fields local_material_purchase_item_edit_fields local_material_purchase_item_total_edit" name="bill_items[item_total]['+i+']" id="bill_item_total_'+item_no+'_edit"/></div></div></td>';
          new_row += '<td><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_local_purchase_items btn btn-danger btn-icon-only" ><i class="fa fa-trash"></i></a></td>';
          new_row += '</tr>';
          $('#table_body_local_purchase_items_edit').append(new_row);
          $('#current_row_count_local_purchase_items_edit').val(item_no);
          calculate_bill_item_total('edit');
        });

        $("#table_body_local_purchase_items_edit").on("click", ".ibtnDel_local_purchase_items_edit", function (event) {
          var sl_no = $(this).attr("data-sl-no");

          var counter = parseInt($("#current_row_count_local_purchase_items_edit").val());
          $(this).closest("tr").remove();
          counter -= 1;
          $("#current_row_count_local_purchase_items_edit").val(counter);
          calculate_bill_item_total('edit');
        });

        </script>
