<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->

<?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">
          Purchase Requests
        </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().'purchase_request' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Purchase Requests
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              List of Purchase Requests
            </h3>
          </div>
        </div>

      </div>
      <div class="m-portlet__body">
        <div class="m-form m-form--label-align-right m--margin-bottom-10">
          <div class="row align-items-center">
            <div class="col-xl-12 order-2 order-xl-1">
              <div class="form-group m-form__group row ">
                <div class="col-md-4">
                  <?php if(!isset($list_type) || $list_type!="pending"){?>
                    <div class="m-form__label">
                      <label class="m-label m-label--single">
                        Date:
                      </label>
                    </div>
                    <div class="row">
                      <div class="col-md-6">
                        <div class="m-form__control">
                          <input value="<?php if($page_name=='purchase_request_view'){ echo date('d-m-Y');}?>" data-date-format="dd-mm-yyyy" id="table_filter_purchase_request_start_date" type="text"  class="form-control m-input table_filter  m-input--pill m-input--air" placeholder="Start Date" >
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="m-form__control">
                          <input value="<?php if($page_name=='purchase_request_view'){ echo date('d-m-Y');}?>" data-date-format="dd-mm-yyyy" id="table_filter_purchase_request_end_date" type="text"  class="form-control m-input table_filter  m-input--pill m-input--air" placeholder="End Date" >
                        </div>
                      </div>
                      <div class="col-md-12">
                        <div class="m-radio-inline">
                          <label class="m-radio m-radio--solid m-radio--state-success">
                            <input type="radio"  class="table_filter" checked name="date_type" value="requested_date"> Requested Date
                            <span></span>
                          </label>
                          <label class="m-radio m-radio--solid m-radio--state-primary">
                            <input type="radio"  class="table_filter" name="date_type" value="approved_date_1"> <?php if($this->config->item('Purchase_purchase_request_second_approval')==1){?>1st<?php } ?> Approved Date
                            <span></span>
                          </label>
                          <?php if($this->config->item('Purchase_purchase_request_second_approval')==1){?>
                          <label class="m-radio m-radio--solid m-radio--state-primary">
                            <input type="radio"  class="table_filter" name="date_type" value="approved_date_2"> 2nd Approved Date
                            <span></span>
                          </label>
                        <?php } ?>
                        </div>
                      </div>
                    </div>

                  <?php } ?>
                </div>
                <div class="col-md-4">
                  <div class="form-group m-form__group">
                    <label>
                      Requests to Location:
                    </label>
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select style="width: 100%" class="form-control m-select2 table_filter" id="table_filter_location"   data-placeholder="Select Work">
                        <option value="all">All Location</option>
                        <?php
                        foreach($stock_locations as $row):
                          $location_name = $row->location_name;
                          if($row->location_type=='work_site'){
                            $location_name .= " [Work Site]";
                          }elseif($row->location_type=='ware_house'){
                            $location_name .= " [Warehouse]";
                          }
                          ?>
                          <option value="<?php echo $row->location_id?>"><?php echo $location_name?></option>
                          <?php
                        endforeach;
                        ?>
                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>
                </div>
                <div class="col-md-4">
                  <div class="form-group m-form__group">
                    <label>
                      Approval Status:
                    </label>
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select style="width: 100%" class="form-control m-select2 table_filter" id="table_filter_status"   data-placeholder="Select Status">
                        <option selected value="all">All Requests</option>
                        <option value="1">Approved</option>
                        <?php if($this->config->item('Purchase_purchase_request_second_approval')==1){?>
                          <option value="10">1st Level Approval Pending</option>
                          <option value="20">2nd Level Approval Pending</option>
                        <?php }else{ ?>
                          <option value="0">Approval Pending</option>
                        <?php } ?>
                        <option value="2">Rejected</option>
                        <option value="30">Approved & Order Not Created</option>
                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--begin: Datatable -->
        <?php $this->view("modules/include_tables/table_purchase_request");?>
        <!--end: Datatable -->
      </div>
    </div>
  </div>
</div>
</div>
<!-- end:: Body -->
<!-- begin::Footer -->

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

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

<!--begin::Page Snippets -->
<script>
//    Toggle Sidebar
// $("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
// $("#body").addClass("m-brand--minimize m-aside-left--minimize");
$("#purchase_request_menu").addClass('m-menu__item--active m-menu__item--open');
<?php if(isset($list_type) && $list_type=="pending"){?>
  $("#purchase_request_menu_3").addClass('m-menu__item--active');
  <?php }else{ ?>
    $("#purchase_request_menu_2").addClass('m-menu__item--active');
    <?php } ?>
    </script>
    <?php $this->view("modules/include_modals/modal_purchase_requests");?>
    <?php $this->view("modules/include_scripts/purchase_request_view_scripts");?>
