{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
        <div class="pull-right">
          {% if quotation['quotation_status'] is defined and quotation['quotation_status'] == 4  %}
            <a href="{{ approve }}" data-toggle="tooltip" id="button-approve" title="{{ button_approve }}" class="btn btn-success"><i class="fa fa-thumbs-o-up"></i></a>
          {% else %}
            <button type="button" class="btn btn-success" disabled name="button"><i {% if quotation['quotation_status'] is defined and quotation['quotation_status'] == 1 %} data-toggle="tooltip" title="{{ button_approved }}"{% endif %} class="fa fa-thumbs-o-up"></i></button>
          {% endif %}
          {% if quotation['quotation_status'] is defined and quotation['quotation_status']== 2 %}
            <button disabled class="btn btn-danger"><i class="fa fa-times"></i></button>
          {% else %}
            <button id="button-cancel" class="btn btn-danger" data-toggle="tooltip" title="{{ button_cancel }}"><i class="fa fa-times"></i></button>
          {% endif %}
            <a href="{{ back }}" data-toggle="tooltip" title="{{ button_back }}" 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>
        {% if success is defined and success %}
        <div class="alert alert-success"><i class="fa fa-check-circle"></i> {{ success }}
          <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
      {% endif %}
        {% if warning is defined and warning %}
        <div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> {{ warning }}
          <button type="button" class="close" data-dismiss="alert">&times;</button>
        </div>
      {% endif %}
    </div>
  </div>
    <div class="container-fluid">
        <div class="panel panel-default">
					<div class="panel-heading">
		        <h3 class="panel-title"><i class="fa fa-info"></i> {{ heading_title }}</h3>
		      </div>
					<div class="panel-body">
						<ul class="nav nav-tabs nav-justified">
              <li class="active"><a href="#tab-product" data-toggle="tab">{{ tab_product }}</a></li>
              <li><a href="#tab-quotation" data-toggle="tab">{{ tab_quotation }}</a></li>
              <li><a href="#tab-history" data-toggle="tab">{{ tab_history }}</a></li>
						</ul>
						<div class="tab-content">
              <div class="tab-pane active" id="tab-product">
                <div class="container-fluid">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th class="text-center">{{ column_image }}</th>
                        <th class="text-left">{{ column_product_name }}</th>
                        <th class="text-left">{{ column_model }}</th>
                        <th class="text-left">{{ column_quantity }}</th>
                        <th class="text-left">{{ column_price }}</th>
                        <th class="text-left">{{ column_total }}</th>
                        <th class="text-left">{{ column_requested_price }}</th>
                        <th class="text-left">{{ column_requested_total }}</th>
                        <th class="text-left">{{ column_approval_price }}</th>
                        <th class="text-left">{{ column_approval_total }}</th>
                      </tr>
                    </thead>
                    <tbody>
                      {% if products is defined and products %}
                        {% for product in products %}
                          <tr>
                            <td class="text-center"> {% if product['image'] is defined and product['image'] %} <img src="{{product['image'] }}" alt="{{ product['name'] }}"> {% endif %}</td>
                            <td class="text-left">{{ product['name'] }}</td>
                            <td class="text-left">{{ product['model'] }}</td>
                            <td class="text-left">{{ product['quantity'] }}</td>
                            <td class="text-left">{{ product['price'] }}</td>
                            <td class="text-left">{{ product['total'] }}</td>
                            <td class="text-left">{{ product['request_price'] }}</td>
                            <td class="text-left">{{ product['request_total'] }}</td>
                            <td class="text-left">
                              {% if quotation['quotation_status'] == 4 or quotation['quotation_status'] == 2 or quotation['quotation_status'] == 1 %}
                              <div class="input-group btn-block" style="max-width: 280px;">
                                <span class="input-group-btn"><button class="btn">{% if product['approved_price'] is defined and product['approved_price'] %}{{ product['approved_price'] }}{% else %} {{ currency_symbol }}{% endif %}</button></span>
                                <input type="text" class="form-control approval_price" name="approve_price[{{ product['id'] }}]" placeholder="{{ placeholder_approve_price }}" value="" id="{{ product['id'] }}">
                                <span class="input-group-btn"><button pid="{{ product['id'] }}" bid="{{ product['id'] }}" type="button" data-toggle="tooltip" title="{{ button_approve_price }}" class="btn btn_approve_price" ><i class="fa fa-refresh"></i></button></span>
                              </div><span id="message_approval{{ product['id'] }}"></span>
                            {% elseif product['approved_price'] is defined and product['approved_price'] %}{{ product['approved_price'] }} {% endif %}
                            </td>
                            <td class="text-left">{{ product['approved_total'] }}</td>
                          </tr>
                        {% endfor %}
                        <tr>
                          <td colspan="5" class="text-right">{{ column_total }}</td>
                          <td class="text-left">{{ total }}</td>
                          <td class="text-right">{{ column_requested_total }}</td>
                          <td class="text-left">{{ request_total }}</td>
                          <td class="text-right">{{ column_approval_total }}</td>
                          <td class="text-left">{{ approved_total }}</td>
                        </tr>
                      {% endif %}
                    </tbody>
                  </table>
                </div>
							</div>
	            <div class="tab-pane" id="tab-quotation">
								<div class="container-fluid">
									<div class="table-responsive">
										<h4>{{ heading_title }}</h4>
										<table class="table table-bordered">
											{% if quotation is defined and quotation %}
                        <tr>
  												<th cl ss="text-left col-sm-3">{{ column_id }}</th>
                        <td class="text-left col-sm-9">{% if quotation['id'] is defined and quotation['id'] %}{{ quotation['id'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_store }}</th>
  												<td class="text-left col-sm-9">{% if quotation['store_name'] is defined and quotation['store_name'] %}{{ quotation['store_name'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_store_url }}</th>
  												<td class="text-left col-sm-9">{% if quotation['store_url'] is defined and quotation['store_url'] %}{{ quotation['store_url'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_status }}</th>
  												<td class="text-left col-sm-9">
                            {% if quotation['quotation_status'] is defined and quotation['quotation_status'] == 1 %}
                            {{ text_approved }}
                          {% elseif quotation['quotation_status'] is defined and quotation['quotation_status'] == 2  %}
                            {{ text_cancelled }}
                            {% elseif quotation['quotation_status'] is defined and quotation['quotation_status'] == 3  %}
                              {% if order_completed is defined and order_completed %}
                                {{ text_order_completed }}
                              {% else %}
                                {{ text_submitted }}
                              {% endif %}
                            {% elseif quotation['quotation_status'] is defined and quotation['quotation_status'] == 4  %}
                            {{ text_under_review }}
                            {% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ colum_cutomer }}</th>
  												<td class="text-left col-sm-9">{% if quotation['firstname'] is defined and quotation['firstname'] %}{{ quotation['firstname'] }}{% endif %}{% if quotation['lastname'] is defined and quotation['lastname'] %}{{ quotation['lastname'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_customer_group }}</th>
  												<td class="text-left col-sm-9">{% if quotation['name'] is defined and quotation['name'] %}{{ quotation['name'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_email }}</th>
  												<td class="text-left col-sm-9">{% if quotation['email'] is defined and quotation['email'] %}{{ quotation['email'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_contact }}</th>
                          <td class="text-left col-sm-9">{% if quotation['telephone'] is defined and quotation['telephone'] %}{{ quotation['telephone'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_fax }}</th>
                          <td class="text-left col-sm-9">{% if quotation['name'] is defined and quotation['name'] %}{{ quotation['name'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_ip }}</th>
                          <td class="text-left col-sm-9">{% if quotation['ip'] is defined and quotation['ip'] %}{{ quotation['ip'] }}{% endif %}</td>
  											</tr>

  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_total }}</th>
                          <td class="text-left col-sm-9">{% if quotation['total'] is defined and quotation['total'] %}{{ quotation['total'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_requested_total }}</th>
                          <td class="text-left col-sm-9">{% if quotation['request_total'] is defined and quotation['request_total'] %}{{ quotation['request_total'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_added_date }}</th>
                          <td class="text-left col-sm-9">{% if quotation['added_date'] is defined and quotation['added_date'] %}{{ quotation['added_date'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_last_modified }}</th>
                          <td class="text-left col-sm-9">{% if quotation['last_modified'] is defined and quotation['last_modified'] %}{{ quotation['last_modified'] }}{% endif %}</td>
  											</tr>
  											<tr>
  												<th cl ss="text-left col-sm-3">{{ column_modified_by }}</th>
  												<td class="text-left col-sm-9">{% if quotation['modified_by'] is defined and quotation['modified_by'] %}{{ text_admin }} {% else %}{{ text_customer }}{% endif %}</td>
  											</tr>
                      {% endif %}
										</table>
									</div>
								</div>
							</div>
							<div class="tab-pane" id="tab-history">
								<div class="container-fluid">
                  <table class="table table-bordered table-hover">
                    <thead>
                      <tr>
                        <th class="text-left">{{ column_comment }}</th>
                        <th class="text-left">{{ column_added_date }}</th>
                        <th class="text-left">{{ column_added_by }}</th>
                      </tr>
                    </thead>
                    <tbody>
                      {% if histories %}
                        {% for history in histories %}
                          <tr>
                            <td class="text-left">{% if history['comment'] is defined and history['comment'] %}{{ history['comment'] }}{% else %} {{ text_not_available }}{% endif %}</td>
                            <td>{{ history['added_date'] }}</td>
                            <td>{% if history['added_by'] == 0 %}{{ text_customer }} {% else %}{{ text_admin }}{% endif %}</td>
                          </tr>
                        {% endfor %}
                      {% else %}
                        <tr>
                          <td class="text-center" colspan="3"><strong>{{ text_no_history }}</strong></td>
                        </tr>
                       {% endif %}
                    </tbody>
                  </table>
								</div>
							</div>
						</div>
					</div>
				</div>
    </div>

</div>
<script type="text/javascript">
  $(document).on('ready', function(){
    var approval_price = 0;
    $('.approval_price').on('keyup', function(){
      var approval_price = $(this).val();
      var id = $(this).attr('id');
      if(approval_price==''){
        $('#message_approval'+id+'').text("");
      }else if (approval_price != parseFloat(approval_price, 10 )){
        $('#message_approval'+id+'').text("{{ text_message_digit }}").css({'color':'red'});
        return false;
      }else{
        $('#message_approval'+id+'').text("");
      }
    });
    $(document).on('click', '.btn_approve_price', function(){
        var qrp_id = $(this).attr('bid');
        approval_price = $('#'+qrp_id).val();
        $.ajax({
          url:'index.php?route=quotemanager/quotations/setapprovalprice&user_token={{ user_token }}',
          type:'post',
          dataType:'json',
          data:{qrp_id:qrp_id, approval_price:approval_price},
          success:function(response){
            if(response){
              location.reload();
            }
          }
        });
    });
  });
  $('#button-approve').on('click', function(){
    $(this).text('loading...').attr('disabled', 'disabled');
  });
  $('#button-cancel').on('click', function(){
    var qc = $(this).attr('qc');
    if ({{ quotation['order_id'] }}) {
      var order_id = {{ quotation['order_id'] }};
      var store_id = {{ quotation['store_id'] }};
      $.ajax({
        url: '{{ catalog }}index.php?route=api/order/history&user_token={{ user_token }}&store_id= ' + store_id + ' =&order_id=' + order_id,
        type: 'post',
        dataType: 'json',
        data: {order_status_id:7,notify:1,comment:'{{ text_quotation_cancel }}'},
        beforeSend: function() {
    			$('#button-cancel').button('loading');
    		},
    		complete: function() {
    			$('#button-cancel').button('reset');
    		},
        success: function(json) {
          if (json) {
            console.log(json);
          }
        }
      });
    }
    $.ajax({
      url:'index.php?route=quotemanager/quotations/cancel&user_token={{ user_token }}',
      type:'post',
      dataType:'json',
      data:{qc: {{ quotation_id }}},
      beforeSend: function() {
        $('#button-cancel').button('loading');
      },
      complete: function() {
        $('#button-cancel').button('reset');
      },
      success:function(response){
        if(response['success']=='success'){
          location.reload();
        }
      }
    });
  });
</script>
{{ footer }}
