{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-member" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_form }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-member" class="form-horizontal">
            <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-external_member_id"><span data-toggle="tooltip" title="{{ help_external_id }}">{{ entry_external_id }}</span></label>
            <div class="col-sm-4">
              <input type="text" name="external_member_id" value="{{ external_member_id }}" placeholder="{{ entry_external_id }}" id="input-external_member_id" class="form-control" />
              {% if error_external_id %}
              <div class="text-danger">{{ error_external_id }}</div>
              {% endif %}
            </div>
          </div>
            <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-first_name">{{ entry_first_name }}</label>
            <div class="col-sm-4">
              <input type="text" name="first_name" value="{{ first_name }}" placeholder="{{ entry_first_name }}" id="input-first_name" class="form-control" />
              {% if error_first_name %}
              <div class="text-danger">{{ error_first_name }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-last_name">{{ entry_last_name }}</label>
            <div class="col-sm-4">
              <input type="text" name="last_name" value="{{ last_name }}" placeholder="{{ entry_last_name }}" id="input-last_name" class="form-control" />
              {% if error_last_name %}
              <div class="text-danger">{{ error_last_name }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-email">{{ entry_email }}</label>
            <div class="col-sm-4">
              <input type="text" name="email" value="{{ email }}" placeholder="{{ entry_email }}" id="input-email" class="form-control" />
              {% if error_email %}
              <div class="text-danger">{{ error_email }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-phone_no">{{ entry_phone_no }}</label>
            <div class="col-sm-4">
              <input type="text" name="phone_no" value="{{ phone_no }}" placeholder="{{ entry_phone_no }}" id="input-phone_no" class="form-control" />
              {% if error_phone_no %}
              <div class="text-danger">{{ error_phone_no }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-gender">{{ entry_gender }}</label>
            <div class="col-sm-2">
              <select name="gender" id="input-gender" class="form-control">
                {% if gender == 'M' %}
                <option value="M" selected="selected">{{ text_male }}</option>
                <option value="F">{{ text_female }}</option>
                <option value="">{{ text_unknown }}</option>
                {% elseif gender == 'F' %}
                <option value="M">{{ text_male }}</option>
                <option value="F"  selected="selected">{{ text_female }}</option>
                <option value="">{{ text_unknown }}</option>
                {% else %}
                <option value="M">{{ text_male }}</option>
                <option value="F">{{ text_female }}</option>
                <option value="" selected="selected">{{ text_unknown }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-date_of_birth">{{ entry_date_of_birth }}</label>
            <div class="col-sm-4 date" style="display: table">
              <input type="text" name="date_of_birth" value="{{ date_of_birth }}" placeholder="{{ entry_date_of_birth }}" data-date-format="YYYY-MM-DD" id="input-date_of_birth" class="form-control" />
              <span class="input-group-btn">
              <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
              {% if error_date_of_birth %}
              <div class="text-danger">{{ error_date_of_birth }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-tier_level">{{ entry_tier_level }}</label>
                <div class="col-sm-2">
                    <select name="tier_setting_id" id="input-tier_level" class="form-control">
                      {% for tier_level in tier_levels %}
                        {% if tier_level.tier_setting_id == tier_setting_id %}
                            <option value="{{ tier_level.tier_setting_id }}" selected="selected">{{ tier_level.title }}</option>
                        {% else %}
                            <option value="{{ tier_level.tier_setting_id }}">{{ tier_level.title }}</option>
                        {% endif %}
                        {% endfor %}
                     </select>
                </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-tier_expiry_date">{{ entry_tier_expiry_date}}</label>
            <div class="col-sm-4 date" style="display: table">
              <input type="text" name="tier_expiry_date" value="{{ tier_expiry_date }}" placeholder="{{ entry_tier_expiry_date }}" data-date-format="YYYY-MM-DD" id="input-date_of_birth" class="form-control" />
              <span class="input-group-btn">
              <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
              {% if error_tier_expiry_date %}
              <div class="text-danger">{{ error_tier_expiry_date }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-total_available_point"><span data-toggle="tooltip" title="{{ help_total_available_point }}">{{ entry_total_available_point }}</span></label>
            <div class="col-sm-4"> 
                <input type="text" name="total_available_point" disabled value="{{ total_available_point}}" placeholder="{{ entry_total_available_point}}" id="input-total_available_point" class="form-control" />
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 control-label" for="input-total_tier_achieved_purchase"><span data-toggle="tooltip" title="{{ help_total_tier_achieved_purchase }}">{{ entry_total_tier_achieved_purchase }}</span></label>
            <div class="col-sm-4">
              <input type="text" name="total_tier_achieved_purchase" readonly="true" value="{{ total_tier_achieved_purchase}}" placeholder="{{ entry_total_tier_achieved_purchase}}" id="input-total_available_point" class="form-control" />
              {% if error_total_tier_achieved_purchase %}
              <div class="text-danger">{{ error_total_tier_achieved_purchase}}</div>
              {% endif %}
               <input type="hidden" id="ori_tier_setting_id" name="ori_tier_setting_id" value={{tier_setting_id}} />
               <input type="hidden" id="ori_purchase_amount" name="ori_purchase_amount" value={{total_tier_achieved_purchase}} />
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-2">
              <select name="status" id="input-status" class="form-control">
                {% if status %}
                <option value="0">{{ text_inactive }}</option>
                <option value="1" selected="selected">{{ text_active }}</option>
                {% else %}
                <option value="0" selected="selected">{{ text_inactive }}</option>
                <option value="1">{{ text_active }}</option>
                {% endif %}
              </select>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{{ footer }} 

  <script type="text/javascript">
    $('.date').datetimepicker({
		language: '{{ datepicker }}',
		pickTime: false
    });

    $('#input-tier_level').on('change', function() {
    var value = $('#input-tier_level').val();
    var orivalue = $('#ori_tier_setting_id').val();
    if(value == orivalue)
    {
        var purchase_amt = $('#ori_purchase_amount').val();
      	$('input[name=\'total_tier_achieved_purchase\']').val(purchase_amt);
	
    }
    else
    {
      $.ajax({
      url: 'index.php?route=member/member/tier&user_token={{ user_token }}&tier_setting_id=' + this.value,
      dataType: 'json',
      beforeSend: function() {
        $('#input-tier_level').after('<i class="fa fa-circle-o-notch fa-spin"></i>');
      },
      complete: function() {
        $('.fa-spin').remove();
      },
      success: function(json) {
          $('input[name=\'total_tier_achieved_purchase\']').val(json['achieve_tier_amount']);
      },
      error: function(xhr, ajaxOptions, thrownError) {
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
      }
	    });
    }
})
</script>