<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->
<style>
.m-input{
  border: 1px solid #ebedf2 !important;
  background-color: #f4f5f833 !important;
}
#payment_view_table .dataTables_scrollHeadInner {
  width:100% !important;
  padding: 0 !important;
}

</style>


<?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">
  Vehicle Profile
</h3>
</div>
</div>
</div>
-->

<!-- END: Subheader -->
<div class="m-content">
  <div class="row">
    <div class="col-xl-3 col-lg-4">
      <div class="m-portlet m-portlet--full-height  ">
        <div class="m-portlet__body" style="padding-top: 0px">
          <div class="m-card-profile">
            <div class="m-card-profile__title m--hide">
              Vehicle Profile
            </div>
            <div class="m-card-profile__pic">
              <div class="m-card-profile__pic-wrapper" style="overflow: hidden;">
                <img src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/app/media/img/users/user.png" alt=""/>
              </div>
            </div>
            <div class="m-card-profile__details">
              <span class="m-card-profile__name">
                <?php echo $provider_data->loan_provider_name ?>
              </span>
              <br/>

            </div>


            <div class="m-card-profile__details">
              <span class="m-card-profile__name">

              </span>
            </div>
            <br/>
          </div>
          <ul class="m-nav m-nav--hover-bg m-portlet-fit--sides">
            <li class="m-nav__separator m-nav__separator--fit" style="margin-top: 0px"></li>
            <li class="m-nav__section m--hide">
              <span class="m-nav__section-text">
                Section
              </span>
            </li>
            <li class="m-nav__item profile_nav" id="nav_info" data-nav="info" data-table-name=''>
              <a href="javascript:;" class="m-nav__link">
                <i class="m-nav__link-icon fa fa-info-circle"></i>
                <span class="m-nav__link-title">
                  <span class="m-nav__link-wrap">
                    <span class="m-nav__link-text">
                      Provider Info
                    </span>
                  </span>
                </span>
              </a>
            </li>

            <li class="m-nav__item profile_nav" id="nav_wage_slips" data-nav="wage_slips" data-table-name='loans_view_table'>
              <a href="javascript:;" class="m-nav__link">
                <i class="m-nav__link-icon fa fa-shopping-cart"></i>
                <span class="m-nav__link-title">
                  <span class="m-nav__link-wrap">
                    <span class="m-nav__link-text">
                      Loans
                    </span>
                  </span>
                </span>
              </a>
            </li>

            <li class="m-nav__item profile_nav" id="nav_wage_slip_payments" data-nav="wage_slip_payments" data-table-name='loan_payments_view_table'>
              <a href="javascript:;" class="m-nav__link">
                <i class="m-nav__link-icon fa fa-rupee-sign"></i>
                <span class="m-nav__link-title">
                  <span class="m-nav__link-wrap">
                    <span class="m-nav__link-text">
                      Loan Payments
                    </span>
                  </span>
                </span>
              </a>
            </li>


          </ul>

        </div>
      </div>
    </div>
    <div class="col-xl-9 col-lg-8">
      <div id="div_info" class="profile_nav_div">

        <div class="m-portlet">
          <div class="m-portlet__body m-portlet__body--no-padding">
            <div class="row m-row--no-padding m-row--col-separator-xl">
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-1 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total Payable Loan Amount
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-brand">
                          <label class="total_loan_payable_amount_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end:: Widgets/Stats2-1 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-1 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total OP Balance Payable
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-brand">
                          <label class="total_op_balance_payable_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end:: Widgets/Stats2-1 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-3 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total Paid
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-success">
                          <label class="total_paid_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--begin:: Widgets/Stats2-3 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-3 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Balance to Pay
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-success">
                          <label class="balance_to_pay_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--begin:: Widgets/Stats2-3 -->
              </div>
            </div>
            <div class="row m-row--no-padding m-row--col-separator-xl">
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-1 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total Receivable Loan Amount
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-brand">
                          <label class="total_loan_receivable_amount_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end:: Widgets/Stats2-1 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-1 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total OP Balance Receivable
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-brand">
                          <label class="total_op_balance_receivable_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--end:: Widgets/Stats2-1 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-3 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Total Received
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-success">
                          <label class="total_received_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--begin:: Widgets/Stats2-3 -->
              </div>
              <div class="col-md-12 col-lg-12 col-xl-3">
                <!--begin:: Widgets/Stats2-3 -->
                <div class="m-widget1">
                  <div class="m-widget1__item">
                    <div class="row m-row--no-padding align-items-center">
                      <div class="col">
                        <h3 class="m-widget1__title">
                          Balance to Receive
                        </h3>
                      </div>
                      <div class="col m--align-right">
                        <span class="m-widget1__number m--font-success">
                          <label class="balance_to_receive_info"></label>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
                <!--begin:: Widgets/Stats2-3 -->
              </div>
            </div>
          </div>
        </div>

        <div class="m-portlet">
          <div class="m-portlet__head">
            <div class="m-portlet__head-caption">
              <div class="m-portlet__head-title">
                <h3 class="m-portlet__head-text">
                  Provider Info
                </h3>
              </div>
            </div>
          </div>
          <div class="m-portlet__body">
            <form autocomplete="off" class="m-form m-form--fit m-form--label-align-right">
              <div class="m-portlet__body">
                <!--   <div class="form-group m-form__group row">
                <div class="col-9 ml-auto">
                <h4 class="m-form__section">
                1. Supplier Details
              </h4>
            </div>
          </div> -->
          <div class="form-group m-form__group row">
            <label class="col-xl-3 col-lg-3 col-form-label">
              Provider ID
            </label>
            <div class="col-xl-7 col-lg-7">
              <div class="input-group m-input-group--air">
                <div class="input-group-prepend">
                  <span class="input-group-text">
                    <i class="fa fa-hashtag "></i>
                  </span>
                </div>
                <input disabled type="text" name="name" class="form-control m-input m-input--solid" value="<?php echo $provider_data->loan_provider_id ?>">
              </div>
            </div>
          </div>
          <div class="form-group m-form__group row">
            <label class="col-xl-3 col-lg-3 col-form-label">
              Provider ID
            </label>
            <div class="col-xl-7 col-lg-7">
              <div class="input-group m-input-group--air date">
                <div class="input-group-prepend">
                  <span class="input-group-text">
                    <i class="fa fa-truck"></i>
                  </span>
                </div>
                <input  disabled type="text" class="form-control m-input m-input--solid"  value="<?php echo $provider_data->loan_provider_name ?>">
              </div>
            </div>
          </div>


        </div>

      </form>
    </div>
  </div>

</div>
<div id="div_wage_slips" class="profile_nav_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">
            Loans
          </h3>
        </div>
      </div>
      <div class="m-portlet__head-tools">

      </div>
    </div>
    <div class="m-portlet__body">
      <div class="m-form m-form--label-align-right m--margin-bottom-10">
        <div class="row">
          <div class="col-xl-12 order-2 order-xl-1">
            <div class="form-group m-form__group row ">
              <div class="col-md-6">
                <div class="form-group m-form__group">
                  <label>
                    Loan Pupose:
                  </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_loan_purpose"   data-placeholder="Select Purpose">
                      <option selected value="all">All Loans</option>
                      <option selected value="0">For Whole Business</option>
                      <?php
                      foreach($work_contracts as $row): ?>
                      <option data-work-status="<?php echo $row->work_status?>" value="<?php echo $row->work_id?>">For Project : <?php echo $row->work_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <?php $this->view("modules/include_tables/table_loans");?>
  </div>
</div>
</div>

<div id="div_wage_slip_payments" class="profile_nav_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 Payments Towards Loan
          </h3>
        </div>
      </div>
      <div class="m-portlet__head-tools">

      </div>
    </div>
    <div class="m-portlet__body">
      <!--begin: Datatable -->
      <?php $this->view("modules/include_tables/table_loan_transaction");?>
      <!--end: Datatable -->
    </div>
  </div>
</div>

</div>

</div>
</div>
</div>

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

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

</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 src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/app/js/dashboard.js" type="text/javascript"></script>
<!--end::Page Snippets -->

<script>
function hide_all(){
  $(".profile_nav").removeClass('m-nav__item--active');
  $(".profile_nav_div").hide();
}
function active(menu_name){
  hide_all();
  $("#nav_"+menu_name).addClass('m-nav__item--active');
  $("#div_"+menu_name).show();
  $("#div_"+menu_name).fadeIn("slow");
  $('html, body').animate({
    scrollTop: eval($("#div_"+menu_name).offset().top - 150)
  }, 500);
}
//  Hide All Div and In Active All Menu
hide_all();
//  Active First Menu and Its div
active('info');
$('body').on('click', '.profile_nav', function() {
  var nav = $(this).attr('data-nav');
  active(nav);
})
</script>
<script>

$("#loans_menu").addClass('m-menu__item--active');

select_summary();
function select_summary(){
  var loan_provider_id = "<?php echo $provider_data->loan_provider_id?>";
  $.post("<?php echo base_url().'loans/select_provider_summary' ?>",{
    loan_provider_id:loan_provider_id
  },function(data){
    var obj= $.parseJSON(data);
    if(obj.count==1){
      $(".total_loan_payable_amount_info").html(obj.total_payable_loan_amount);
      $(".total_op_balance_payable_info").html(obj.total_op_balance_payable);
      $(".total_paid_info").html(obj.total_paid);
      $(".balance_to_pay_info").html(obj.balance_to_pay);
      $(".total_loan_receivable_amount_info").html(obj.total_receivable_loan_amount);
      $(".total_op_balance_receivable_info").html(obj.total_op_balance_receivable);
      $(".total_received_info").html(obj.total_received);
      $(".balance_to_receive_info").html(obj.balance_to_receive);
    }
  })
}
</script>
<!-- Bill Scripts -->
<?php $this->view("modules/include_scripts/bill_scripts");?>

<!-- Transaction Scripts -->
<?php $this->view("modules/include_scripts/transaction_scripts");?>
<?php $this->view("modules/include_scripts/loans_scripts");?>


<script>

$("#table_filter_loan_purpose,#table_filter_loan_provider").select2({
  placeholder: "Select Option"
})

jQuery(document).ready(function() {
  $('.profile_nav').on('click', function(e){
    var table_name = $(this).attr('data-table-name');
    if(table_name!=''){
      var tables = table_name.split(',');
      $.each(tables, function( index, value ){
        var table_name = value;
        eval(table_name).ajax.reload();
      });
    }
  });


  $(".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: {
        payable_balance: {
          number: !0,
          required: !0
        },
        paid_amount: {
          number: !0,
          required: !0
        },
        expense_amount: {
          number: !0,
          required: !0
        },
        received_amount: {
          number: !0,
          required: !0
        },
        budget: {
          number: !0,
          required: !0
        },
        edit_paid_amount: {
          number: !0,
          required: !0
        }
      }, 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) {
        var modal_id = l.attr('data-modal-id');
        var form_type = l.attr('data-form-type');
        $("#" + form_id + "_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);
          $("#"+modal_id).modal('toggle');
          $("."+form_id+"_fields").val('');
          $("."+form_id+"_select").val('').trigger("change");
          loan_payments_view_table.ajax.reload();
          loans_view_table.ajax.reload();
          select_provider('provider_add');
          select_provider('provider_edit');
          select_provider('table_filter_loan_provider');
        } 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>
