<?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">

          Invoices

        </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 $this->session->userdata("dashboard_link")?>" 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().'invoices' ?>" class="m-nav__link">
              <span class="m-nav__link-text">Invoices</span>
            </a>
          </li>
        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">

    <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">
              <div class="m-form__group ">
                <label>
                  Date:
                </label>
                <input  id="table_filter_date_range2"   type="text" class="form-control m-input m-input--air m-input--pill"  >
              </div>
            </div>
            <div class="col-md-4">
              <div class="form-group m-form__group">
                <label>
                  Work:
                </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_work2"  name="work" data-placeholder="Select Work">
                    <option value="all">All Works</option>
                    <?php
                    foreach($work_contracts as $row): ?>
                      <option data-work-status="<?php echo $row->work_status?>" value="<?php echo $row->work_id?>"><?php echo $row->work_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>


    <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 Invoice Payments

            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">

          <?php if(($this->config->item('User_client_payment_creation_admin_only')==0 || ($this->config->item('User_client_payment_creation_admin_only')==1 && ($this->session->userdata('user_role')=='admin' || $this->session->userdata('user_role')=='madmin'))) && $this->session->userdata('user_role')!='auditor' ){?>

            <a href="#" data-toggle="modal" data-target="#client_payment_add_modal" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="la la-plus"></i>
                <span>
                  Receive New Payment
                </span>
              </span>
            </a>

          <?php } ?>
        
        </div>
      </div>
      <div class="m-portlet__body">

        <!--begin: Datatable -->
        <?php $this->view("modules/include_tables/table_invoice_payments");?>
        <!--end: Datatable -->
      </div>
    </div>
  </div>

</div>
</div>
<?php $this->view("modules/include_modals/modal_transaction_delete");?>


<!-- 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");?>

<?php $this->view("modules/include_scripts/invoices_payments_scripts");?>
<?php $this->view("modules/include_scripts/transaction_scripts");?>
<?php $this->view("modules/include_scripts/client_payments_scripts");?>
<script>
  $("#client_payments_menu").addClass('m-menu__item--active m-menu__item--open');
  $("#client_payments_menu_2").addClass('m-menu__item--active');

  $(".form_submit_btn").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: {

      }, 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) {
          $("#form_invoice_delete_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);
          var modal_id = l.attr('data-modal-id');
          var form_type = l.attr('data-form-type');
          $("#"+modal_id).modal('toggle');
          invoice_payments_view_table.ajax.reload();

        } 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>
