<?php $this->view("includes/Inc_pagehead"); ?>
<!-- Page Styles Goes Here-->
<style>
.item_table td {
  padding: .75rem !important;
}

.item_table th {
  white-space: nowrap;
  padding: .75rem !important;
}

.table thead th {
  border-top: 2px solid #f4f5f8 !important;
}

.payment-table tbody td {
  border-top: 2px solid #f4f5f8 !important;
}

.m-invoice-2 .m-invoice__wrapper .m-invoice__head .m-invoice__container.m-invoice__container--centered {
  width: 90% !important;
}

.m-invoice-2 .m-invoice__wrapper .m-invoice__body.m-invoice__body--centered {
  width: 90% !important;
}

.holder {
  height: 100px;
  width: 100px;
  border: 2px solid black;
}

.holder img {
  max-width: 100px;
  max-height: 100px;
  min-width: 100px;
  min-height: 100px;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td:not(:first-child) {
  text-align: left !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  color: black !important;
}
.m-invoice-2 .m-invoice__wrapper .m-invoice__body table tbody tr td {
  vertical-align: top !important;
}
</style>
<?php $this->view("includes/Inc_navigation"); ?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          <?php echo $this->config->item('Quotation_sales_quotation_title') ?>
        </h3>
        <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
          <li class="m-nav__item m-nav__item--home">
            <a href="#" class="m-nav__link m-nav__link--icon">
              <i class="m-nav__link-icon la la-home"></i>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url() . 'dashboard' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Home
              </span>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url() . 'sales_quotation' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                <?php echo $this->config->item('Quotation_sales_quotation_title') ?>
              </span>
            </a>
          </li>
        </ul>
      </div>
      <div></div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--full-height">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              Add New <?php echo $this->config->item('Quotation_sales_quotation_title') ?>
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">

        </div>
      </div>
      <div class="m-portlet__body m-portlet__body--no-padding">
        <form autocomplete="off" id="form_template_select" method="post" action="<?php echo base_url() . 'sales_quotation/add' ?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right ">
          <div class="m-form__content">
            <div class="row">
              <div class="col-lg-8" style="margin-top:30px;margin-bottom:50px">
                <div class="form-group m-form__group row">
                  <label class="col-4 col-form-label">
                    Select Template
                  </label>
                  <div class="col-8">
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select width="100%" required multiple class="form-control m-select2" id="quotation_template" name="template_id[]">
                        <!-- <option selected disabled> Select Quotation Template</option> -->
                        <?php foreach ($sales_quotation_templates as $key => $value) { ?>
                          <option value="<?php echo $value->template_id ?>"><?php echo $value->template_no ?> [<?php echo $value->title ?>]</option>
                        <?php } ?>
                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>

                </div>
              </div>
              <div class="col-lg-4" style="margin-top:30px;margin-bottom:50px">
                <button type="submit" class="btn btn-brand ">
                  Go
                </button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
    <?php if ($selected_template_data != '') { ?>
      <form autocomplete="off" id="form_quotation_add" data-form-type="quotation_create" method="post" action="<?php echo base_url() ?>sales_quotation/create" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right ">
        <div class="m-portlet m-portlet--full-height">
          <div class="m-portlet__body m-portlet__body--no-padding">
            <div class="m-invoice-2" style="padding-bottom: 20px">
              <div class="m-invoice__wrapper">
                <div class="m-invoice__head">
                  <div class="m-invoice__container m-invoice__container--centered">
                    <div class="m-invoice__logo" style="padding-top: 3rem;">
                      <a href="#">
                      </a>
                    </div>
                  </div>
                </div>
                <div class="m-invoice__body m-invoice__body--centered" style="min-height: 200px">
                  <div class="row">
                    <div class="col-lg-12">
                      <div class="row">
                        <div class="col-lg-6">
                          <div class="form-group m-form__group">
                            <label>Customer Name</label>
                            <input type="text" required name="customer_name" class="form-control m-input m-input--air m-input--pill" placeholder="Customer Name">
                            <!-- <span class="m-form__help"></span> -->
                          </div>
                          <div class="form-group m-form__group" style="padding-top:0px">
                            <label>Customer Phone</label>
                            <input type="text"  name="customer_phone" class="form-control m-input m-input--air m-input--pill" placeholder="Customer Phone No">
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                        <div class="col-lg-6">
                          <div class="form-group m-form__group">
                            <label>Address</label>
                            <textarea required name="address" rows="6" class="form-control m-input m-input--air m-input--pill" placeholder="Address"></textarea>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-lg-4">
                          <div class="form-group m-form__group">
                            <label>State</label>
                            <input type="text" required name="state" class="form-control m-input m-input--air m-input--pill" placeholder="State">
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                        <div class="col-lg-2">
                          <div class="form-group m-form__group">
                            <label>Quotation Date</label>
                            <input data-date-format="dd-mm-yyyy" id="quotation_date" required type="text" name="quotation_date" class="form-control m-input m-input--air m-input--pill" placeholder="Quotation Date">
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                        <div class="col-lg-2">
                          <div class="form-group m-form__group">
                            <label>Expiry Date</label>
                            <input data-date-format="dd-mm-yyyy" id="expiry_date" required type="text" name="expiry_date" class="form-control m-input m-input--air m-input--pill" placeholder="Expiry Date">
                            <span class="m-form__help"></span>
                          </div>
                        </div>

                        <div class="col-lg-4">
                          <div class="form-group m-form__group m-select2--pill">
                            <label for="user_name">
                              Prepared By
                            </label>
                            <div class="m-select2 m-select2--air m-select2--pill">
                              <select required style="width: 100%" class="form-control m-select2 m-select2-general" name="prepared_by">
                                <option selected disabled> Select Prepared By</option>
                                <?php foreach ($sales_staffs as $key => $value) { ?>
                                  <option value="<?php echo $value->user_id ?>"><?php echo $value->user_alias ?></option>
                                <?php } ?>
                              </select>
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        </div>
                        <div class="col-lg-4">
                          <!-- <div class="form-group m-form__group m-select2--pill">
                            <label for="user_name">
                              Quotation Type
                            </label>
                            <div class="m-select2 m-select2--air m-select2--pill">
                              <select required style="width: 100%" class="form-control m-select2 m-select2-general" name="quotation_type">
                                <option selected disabled> Select Quotation Type </option>
                                <option value="product">Product</option>
                                <option value="service">Service</option>
                              </select>
                              <span class="m-form__help"></span>
                            </div>
                          </div> -->
                        </div>
                      </div>
                      <?php foreach ($selected_template_data as $key => $value) { ?>
                        <div style="background: white;border: 4px solid #f7f7fa;padding: 15px;margin: 5px;padding-bottom: 0px">
                          <div class="m-section" style="margin-bottom: 10px">
                            <h3 class="m-section__heading">Quotation Details - <?php echo $value->template_no ?></h3>
                            <div class="row">
                              <div class="col-lg-12">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Title
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <input value="<?php echo $value->title ?>" required type="text" name="title_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields" placeholder="Title" aria-describedby="basic-addon1">
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                              <div class="col-lg-12">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Sub Title
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <input required value="<?php echo $value->sub_title ?>" type="text" name="subtitle_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields" placeholder="Sub Title" aria-describedby="basic-addon1">
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                              <div class="col-lg-12">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Description
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <textarea type="text" rows="3" name="description_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields" placeholder="Description " aria-describedby="basic-addon1"><?php echo $value->description ?></textarea>
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                              <div class="col-lg-12">
                                <table class="table m-table table-bordered item_table m-table--head-bg-warning">
                                  <thead>
                                    <tr>
                                      <th style="text-align:left;color:black">Products</th>
                                      <th style="text-align:left;color:black">Amount/Sqft</th>
                                      <th style="text-align:left;color:black">Warranty</th>
                                      <th style="text-align:left;color:black">Method of Application</th>
                                    </tr>
                                  </thead>
                                  <tbody>
                                    <tr>
                                      <td>
                                        <div class="form-group m-form__group">
                                          <textarea required class="form-control form_quotation_template_add_fields" placeholder="Products" name="products_<?php echo $value->template_id ?>" id="products_add_quotation_template_<?php echo $value->template_id ?>" aria-required="true"></textarea>
                                          <span class="m-form__help"></span>
                                        </div>
                                      </td>
                                      <td>
                                        <div class="form-group m-form__group">
                                          <input data-template-id="<?php echo $value->template_id ?>" required id="unit_price_<?php echo $value->template_id ?>" type="text" value="<?php echo $value->unit_price ?>" name="amount_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields amount_fields" placeholder="Amount / Sqft" aria-describedby="basic-addon1">
                                          <span class="m-form__help"></span>
                                        </div>
                                      </td>
                                      <td>
                                        <div class="form-group m-form__group">
                                          <textarea required rows="12" class="form-control form_quotation_template_add_fields" placeholder="Warranty" name="warranty_<?php echo $value->template_id ?>" aria-required="true"><?php echo $value->warranty ?></textarea>
                                          <span class="m-form__help"></span>
                                        </div>
                                      </td>
                                      <td>
                                        <div class="form-group m-form__group">
                                          <textarea required class="form-control form_quotation_template_add_fields" placeholder="Methods" name="methods_<?php echo $value->template_id ?>" id="methods_add_quotation_template_<?php echo $value->template_id ?>" aria-required="true"></textarea>
                                          <span class="m-form__help"></span>
                                        </div>
                                      </td>
                                    </tr>
                                  </tbody>
                                </table>
                              </div>
                              <div class="col-lg-6">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Approx. Sqft
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <input data-template-id="<?php echo $value->template_id ?>" required type="text" id="quantity_<?php echo $value->template_id ?>" name="quantity_<?php echo $value->template_id ?>" class="amount_fields form-control m-input form_quotation_template_add_fields" placeholder="Approx. Sqft" aria-describedby="basic-addon1">
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                              <div class="col-lg-6">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Total Amount
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <input readonly required type="text" id="total_amount_view_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields" placeholder="Total Amount" aria-describedby="basic-addon1">
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                              <input type="hidden" name="total_amount_<?php echo $value->template_id ?>" id="total_amount_<?php echo $value->template_id ?>" />
                              <div class="col-lg-12">
                                <div class="form-group m-form__group">
                                  <label for="user_name">
                                    Notes
                                  </label>
                                  <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                                    <textarea type="text" name="notes_<?php echo $value->template_id ?>" class="form-control m-input form_quotation_template_add_fields" placeholder="Notes " aria-describedby="basic-addon1"><?php echo $value->notes ?></textarea>
                                  </div>
                                  <span class="m-form__help"></span>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      <?php } ?>
                      <div style="background: white;border: 4px solid #f7f7fa;padding: 15px;margin: 5px;padding-bottom: 0px">
                        <div class="m-section" style="margin-bottom: 10px">
                          <h3 class="m-section__heading">Terms & Conditions</h3>
                          <div class="row">
                            <div class="col-lg-12">
                              <table style="width: 100%;max-width: 100%" id="table_terms" class="table m-table table-bordered item_table m-table--head-bg-success">
                                <thead>
                                  <tr>
                                    <th style="width:5%;text-align:left;color:white">Sl No</th>
                                    <th style="width:70%;text-align:left;color:white">Description</th>
                                    <th style="width:6%;text-align:left;color:white">&nbsp;</th>
                                  </tr>
                                </thead>
                                <tbody id="table_body_terms">
                                  <?php
                                  $i = 0;
                                  foreach ($terms_and_condition_templates as $key => $value) {?>
                                    <tr class="row_<?php echo $i ?>">
                                      <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="<?php echo $i + 1 ?>" name="terms[sl_no][<?php echo $i ?>]" value="<?php echo $i + 1 ?>" /></div>
                                        </div>
                                      </td>
                                      <td>
                                        <div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;">
                                          <textarea rows="2" class="form-control m-input m-input--pill m-input--air" name="terms[description][<?php echo $i ?>]" id="description_<?php echo $i + 1 ?>" /><?php echo $value->description ?></textarea>
                                        </div>
                                      </td>
                                      <td>
                                        <a href="javascript:" data-row-sl-no="<?php echo $i ?>" class="ibtnDel_terms btn btn-danger btn-icon-only">
                                          <i class="fa fa-trash"></i>
                                        </td>
                                      </tr>
                                      <?php $i++;
                                    } ?>
                                  </tbody>
                                  <tfoot>
                                    <tr>
                                      <td colspan="10" style="text-align: left;border-bottom: 1px solid #e7ecf1;">
                                        <button type="button" class="btn btn-block " id="addrow_terms"><i class="fa fa-plus-square"></i> Add new Terms and Condition</button>
                                      </td>
                                    </tr>
                                  </tfoot>
                                </table>
                                <input type="hidden" value="<?php echo $i ?>" id="current_row_count_terms_and_conditions" name="current_row_count">
                                <input type="hidden" value="<?php echo $i ?>" id="actual_row_count_terms_and_conditions" name="actual_row_count">
                              </div>
                            </div>
                          </div>
                        </div>
                        <input type="hidden" name="template_id" value="<?php echo $selected_template_id ?>">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="m-portlet__foot m-portlet__foot--fit">
              <div class="m-form__actions m-form__actions">
                <div class="row">
                  <div class="col-lg-3 ml-lg-auto" style="border-right: 1px solid #ebedf2;">
                    <button type="submit" class="btn btn-primary form_submit_btn_3">
                      Save & Submit
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </form>
      <?php } ?>
    </div>
  </div>
</div>


<!-- end:: Body -->
<!-- begin::Footer -->

<?php $this->view("includes/Inc_footer"); ?>
<!-- end::Footer -->

<!-- end:: Page -->

<?php $this->view("includes/Inc_sidebar"); ?>
<?php $this->view("includes/Inc_scripts"); ?>

<!--begin::Page Snippets -->
<?php //$this->view("modules/include_scripts/bill_scripts");
?>
<script>
//    Toggle Sidebar
$("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
$("#body").addClass("m-brand--minimize m-aside-left--minimize");

$("#sales_quotation_menu").addClass('m-menu__item--active m-menu__item--open');
$("#sales_quotation_menu_1").addClass('m-menu__item--active');


$("#quotation_template").select2({
  placeholder: "Select Quotation Template"
})

$("select[name=prepared_by]").select2({
  placeholder: "Select Prepared By"
})

// quotation_type
$("select[name=quotation_type]").select2({
  placeholder: "Select Quotation Type"
})

$('#photo').change(function() {
  const file = this.files[0];
  console.log(file);
  if (file) {
    let reader = new FileReader();
    reader.onload = function(event) {
      console.log(event.target.result);
      $('#imgPreview').attr('src', event.target.result);
    }
    reader.readAsDataURL(file);
    $('.img_preview_holder').show();
  }
});
<?php if ($selected_template_data != '') { ?>
  var template_id = ("<?php echo $selected_template_id ?>").split(',');
  $("#quotation_template").val(template_id).trigger('change');
  <?php foreach ($selected_template_data as $key => $value) { ?>
    $("#products_add_quotation_template_<?php echo $value->template_id ?>").summernote({
      height: 200,
      width: '100%',
      toolbar: [
        // [groupName, [list of button]]
        ['style', ['bold', 'italic']],
        ['fontsize', ['fontsize']],
        ['color', ['color']],
        ['para', ['ul', 'ol', 'paragraph']],
        ['height', ['height']]
      ]
    });
    $("#methods_add_quotation_template_<?php echo $value->template_id ?>").summernote({
      height: 200,
      width: '100%',
      toolbar: [
        // [groupName, [list of button]]
        ['style', ['bold', 'italic']],
        ['fontsize', ['fontsize']],
        ['color', ['color']],
        ['para', ['ul', 'ol', 'paragraph']],
        ['height', ['height']]
      ]
    });
    $('#products_add_quotation_template_<?php echo $value->template_id ?>').summernote('code', '<?php echo $value->products ?>');
    $('#methods_add_quotation_template_<?php echo $value->template_id ?>').summernote('code', '<?php echo $value->method_of_application ?>');
    <?php }
  } ?>

  $("#quotation_date,#expiry_date").datepicker({
    todayHighlight: !0,
    orientation: "bottom left",
    templates: {
      leftArrow: '<i class="la la-angle-left"></i>',
      rightArrow: '<i class="la la-angle-right"></i>'
    }
  })


  function calculate_total_amount(template_id) {
    var unit_price = parseFloat($("#unit_price_" + template_id).val());
    var area = parseFloat($("#quantity_" + template_id).val());
    var total_amount = unit_price * area;
    $("#total_amount_" + template_id).val(total_amount.toFixed());
    $("#total_amount_view_" + template_id).val(area + " X " + unit_price + " = " + total_amount.toFixed() + "+GST");
  }

  $('body').on('change keyup', '.amount_fields', function() {
    var template_id = $(this).data('template-id');
    calculate_total_amount(template_id);
  })
  </script>
  <script>
  $("#form_template_select").validate({
    rules: {
      template_id: {
        required: !0
      }
    },
    invalidHandler: function(e, r) {
      var i = $("#form_template_select_msg");
      i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
    },
    submitHandler: function(e) {
      this.submit();
    }
  });
  $(".form_submit_btn_3").click(function(e) {
    e.preventDefault();
    var a = $(this),
    l = $(this).closest("form"),
    action = l.attr('action');
    var form_id = l.attr('id');
    l.validate({
      rules: {
        "quantity": {
          required: !0,
          number: !0
        },
        "amount": {
          required: !0,
          number: !0
        }
      },
      invalidHandler: function(e, r) {
        var i = $("#" + form_id + "_msg");
        i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
      },
      submitHandler: function(e) {}
    }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
    l.ajaxSubmit({
      url: action,
      success: function(e, t, r, s) {
        var modal_id = l.attr('data-modal-id');
        var form_type = l.attr('data-form-type');
        $("#" + form_id + "_msg").addClass("m--hide");
        // Block UI
        mApp.blockPage({
          overlayColor: "#000000",
          type: "loader",
          state: "success",
          message: "Please wait..."
        }), setTimeout(function() {
          mApp.unblockPage()
        }, 2e3);
        var obj = $.parseJSON(e);
        if (obj.status == 1) {
          a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
          // toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
          // $("#"+modal_id).modal('toggle');
          // $("."+form_id+"_fields").val("");
          // location.reload();
          swal({
            width: 500,
            title: obj.flashdata_title,
            text: obj.flashdata_msg,
            type: obj.flashdata_type,
            showCancelButton: !0,
            confirmButtonText: "Go to Quotation Details",
            cancelButtonText: "Add New Quotation",
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            reverseButtons: !0,
            closeOnClickOutside: false,
            allowOutsideClick: false,
          }).then(function(e) {
            e.value ? window.location.replace("<?php echo base_url() ?>sales_quotation/profile/view/" + obj.quotation_id) : "cancel" === e.dismiss && window.location.replace("<?php echo base_url() ?>sales_quotation/add");
          })
        } else {
          a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
          toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
        }

        if (obj == null) {
          setTimeout(function() {
            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
            toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
          }, 2e4)
        }
      },
      error: function() {
        a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
        toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
      }
    })
  )
});
</script>
<script>
$("#addrow_terms").on("click", function() {
  var i = parseInt($('#current_row_count_terms_and_conditions').val());
  var new_i = i + 1;
  console.log(new_i);

  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="' + new_i + '" name="terms[sl_no][' + i + ']" value="' + new_i + '"/></div></div></td>';
  new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><textarea rows="2" class="form-control m-input m-input--pill m-input--air" name="terms[description][' + i + ']" id="description_' + new_i + '"/></textarea></div></td><td>';
  new_row += '<a href="javascript:" data-row-sl-no="' + i + '" class="ibtnDel_terms btn btn-danger btn-icon-only" ><i class="fa fa-trash"></i></td></tr>';

  $('#table_body_terms').append(new_row);
  $('#current_row_count_terms_and_conditions').val(new_i);
});

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

  var counter = parseInt($("#current_row_count_terms_and_conditions").val());
  $(this).closest("tr").remove();
  counter -= 1;
  $("#current_row_count_terms_and_conditions").val(counter);

});
</script>
