<table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="branches_view_table">
  <thead>
    <tr class="">
      <th>Sl No</th>
      <th>Branch Name</th>
      <th>Email</th>
      <th>Phone</th>
      <th>Sale Price Cat</th>
      <th>Quotation<br/>Prefix</th>
      <th>Work Order<br/>Prefix</th>
      <th>Logo</th>
      <th>Quotation Header</th>
      <th>Quotation Footer</th>
      <th>Work Order Header</th>
      <th>Work Order Logo</th>
      <th>Work Order Footer</th>
      <th>Address</th>
      <th>Tax No</th>
      <th>State Code</th>
      <th>Status</th>
      <th>Actions</th>
      <th>branch_id</th>
      <th>status</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>


<div class="modal fade" tabindex="-1" id="branch_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #00c5dc;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff">
          Add New Branch
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <form autocomplete="off" data-form-type="document" data-modal-id="branch_add_modal" id="form_branch_add" method="post" action="<?php echo base_url() . 'branches/create' ?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state  ">
        <div class="modal-body">
          <div class="m-form__content">
            <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_branch_add_msg">
              <div class="m-alert__icon">
                <i class="la la-warning"></i>
              </div>
              <div class="m-alert__text">
                Oh snap! Change a few things up and try submitting again.
              </div>
              <div class="m-alert__close">
                <button type="button" class="close" data-close="alert" aria-label="Close"></button>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-6">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Branch Name
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="name">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Email
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="email" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="email">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-envelope"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Phone
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="phone">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Service Quotation Prefix
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="quotation_prefix">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Prefix
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="workorder_prefix">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-3">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Branch Logo <br/>(Size - 528 X 588 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="branch_logo" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-5">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Status
                </label>
                <div>
                  <span class="m-bootstrap-switch m-bootstrap-switch--pill m-bootstrap-switch--air">
                    <input name="status" data-switch="true" type="checkbox" data-on-color="success" data-off-color="danger" data-on-text="Active" data-off-text="In-Active" checked="checked">
                  </span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group"  >
                <label for="user_name">
                  Sale Price Category
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="sale_price_category_add"  name="sale_price_category"  style="width: 100%" class="form-control m-input"  aria-describedby="basic-addon1" >
                    <option selected disabled>Select Sale Price Category</option>
                    <option value="1"><?php echo $this->config->item('Material_sale_price1_name') ?></option>
                    <option value="2"><?php echo $this->config->item('Material_sale_price2_name') ?></option>
                    <option value="3"><?php echo $this->config->item('Material_sale_price3_name') ?></option>
                    <option value="4"><?php echo $this->config->item('Material_sale_price4_name') ?></option>
                    <option value="5"><?php echo $this->config->item('Material_sale_price5_name') ?></option>
                    <option value="6"><?php echo $this->config->item('Material_sale_price6_name') ?></option>
                  </select>
                </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">
                  Quotation Header (First Page Only)<br/>(Size - 793 X 748 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="quotation_header" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </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">
                  Quotation Footer <br/>(Size - 2482 X 157 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="quotation_footer" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Header (First Page Only) <br/>(Size - 1024 X 1460 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_header" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Logo (All Page Header Except First Page) <br/>(Size - 1024 X 588 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_logo" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Footer <br/>(Size - 2482 X 157 PX)
                </label>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_footer" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </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">
                  Address
                </label>
                <textarea required placeholder="Address" rows="7" name="address" class="form-control m-input  m-input--air m-input--pill" ></textarea>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-6">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Tax No
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="taxno">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
              </div>
              <div class="form-group m-form__group"  >
                <label for="user_name">
                  State Code
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="state_id_add"  name="state_id"  style="width: 100%" class="form-control m-input"  aria-describedby="basic-addon1" >
                    <option selected disabled>Select State</option>
                    <?php
                    foreach($tax_state_codes as $row):
                      ?>
                      <option value="<?php echo $row->state_id?>"><?php echo $row->state_name." - ".$row->state_code?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary " data-dismiss="modal">
            Close
          </button>
          <button type="submit" class="btn btn-primary form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>


<div class="modal fade" tabindex="-1" id="branch_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #00c5dc;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff">
          Update Branch Details
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <form autocomplete="off" data-form-type="document" data-modal-id="branch_edit_modal" id="form_branch_edit" method="post" action="<?php echo base_url() . 'branches/update' ?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state ">
        <div class="modal-body">
          <div class="m-form__content">
            <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_branch_edit_msg">
              <div class="m-alert__icon">
                <i class="la la-warning"></i>
              </div>
              <div class="m-alert__text">
                Oh snap! Change a few things up and try submitting again.
              </div>
              <div class="m-alert__close">
                <button type="button" class="close" data-close="alert" aria-label="Close"></button>
              </div>
            </div>
          </div>
          <div class="row">
            <input type="hidden" name="branch_id" id="branch_id_edit">
            <div class="col-lg-6">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Branch Name
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="name" id="branch_name_edit">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Email
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="email" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="email" id="branch_email_edit">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-envelope"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Phone
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="phone" id="branch_phone_edit">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Service Quotation Prefix
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="quotation_prefix" id="quotation_prefix_edit">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Work Order Prefix
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1" name="workorder_prefix" id="workorder_prefix_edit">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Change / Upload Branch Logo
                </label>
                <div>
                  <img id="logo_preview_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input type="file" class="custom-file-input" name="branch_logo" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </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">
                  Status
                </label>
                <div>
                  <span class="m-bootstrap-switch m-bootstrap-switch--pill m-bootstrap-switch--air">
                    <input id="branch_status_edit" name="status" data-switch="true" type="checkbox" data-on-color="success" data-off-color="danger" data-on-text="Active" data-off-text="In-Active" checked="checked">
                  </span>
                </div>
              </div>
            </div>
            <div class="col-lg-6">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Quotation Header (First Page Only) (Size - 793 X 748 PX)
                </label>
                <div>
                  <img id="quotation_header_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="quotation_header" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </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">
                  Quotation Footer (Size - 2482 X 157 PX)
                </label>
                <div>
                  <img id="quotation_footer_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="quotation_footer" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Header (First Page Only) (Size - 1024 X 1460 PX)
                </label>
                <div>
                  <img id="workorder_header_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_header" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Logo (All Page Header Except First Page) (Size - 1024 X 588 PX)
                </label>
                <div>
                  <img id="workorder_logo_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_logo" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Work Order Footer (Size - 2482 X 157 PX)
                </label>
                <div>
                  <img id="workorder_footer_edit" style="width: 200px;padding-bottom:20px" />
                </div>
                <div class="custom-file">
                  <input required type="file" class="custom-file-input" name="workorder_footer" id="customFile">
                  <label class="custom-file-label" for="customFile">Choose file</label>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary " data-dismiss="modal">
            Close
          </button>
          <button type="submit" class="btn btn-primary form_submit_btn">
            Update
          </button>
        </div>
      </form>
    </div>
  </div>
</div>


<div class="modal fade" tabindex="-1" id="branch_delete_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="branch">
    <form autocomplete="off" data-form-type="branch" data-modal-id="branch_delete_modal" id="form_branch_delete" method="post" action="<?php echo base_url() . 'branches/delete' ?>" class="form-horizontal">
      <div class="modal-content">
        <div class="alert alert-danger" role="alert" style="margin-bottom: 0px">
          <button type="button" class="close" data-dismiss="modal"></button>
          <br />
          <h4 class="alert-heading">Warning! Please Confirm Your Action</h4>
          <br />
          <p> Are You Sure to Delete this branch ? This can not be undone ! </p>
          <p>
            <button class="btn btn-danger form_submit_btn" type="submit" name="submit">Confirm & Delete</button>
            <button type="button" class="btn btn-primary modal-dismiss" data-dismiss="modal">Cancel</button>
          </p>
          <input type="hidden" value name="branch_id" id="branch_id_delete">
        </div>
      </div>
    </form>
  </div>
</div>


<script>
function show_image(input, type) {
  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#branch_logo_' + type).attr('src', e.target.result).width(150).height(200);
    };

    reader.readAsDataURL(input.files[0]);
  }
}
</script>
