<title>Other Loans</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Other Loans'" [active_item]="'Other Loans'"></app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">


          <button *ngIf="otherLoans && otherLoans.length > 0" type="button" class="btn btn-info filterbtn"
            title="{{ 'tooltip_lbl_download_csv' |translate}}" (click)="downloadCsv()">
            <i class="icon-download pr-1"></i>
            <span>{{'lbl_downLoad_csv' | translate}}</span>
          </button>
          <button type="button" class="btn btn-info filterbtn"
            title="{{ 'other_loan_tooltip_filter_option_loan' |translate}}" (click)="drawer.toggle();">
            <i class="icon-filter pr-1"></i>
            <span>{{'button_lbl_filter' | translate}}</span>
          </button>
        </div>
      </div>
    </div>
    <div class="col-sm-12">
      <mat-drawer-container autosize>
        <div class="card">
          <ng-container *ngIf="otherLoans && otherLoans.length > 0 else NoOtherLoans">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="otherLoans"
                class="mat-elevation-z8 table-striped table-vcenter lastcolumntable"
                style="min-width: 1800px; box-shadow: none;" aria-label="">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width:75px">#</th>
                  <td mat-cell *matCellDef="let element; let i = index;" style="width:75px">
                    {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="fullName">
                  <th mat-header-cell *matHeaderCellDef style="width: 15%;">{{'lbl_full_name' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 15%;">
                    <div *ngIf="element.fullName else NoValue">
                      {{element.fullName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="birthdate">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_date_of_birth' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.birthdate else NoValue">
                      {{element.birthdate | date}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <!-- <ng-container matColumnDef="panCardNo">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_pan_card_no' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.panCardNo else NoValue">
                      {{element.panCardNo}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="aadhaarCardNo">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_aadhar_card_no' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.aadhaarCardNo else NoValue">
                      {{element.aadhaarCardNo}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container> -->
                <ng-container matColumnDef="contactNo">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_contact_no' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.contactNo else NoValue">
                      {{element.contactNo}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="monthlyincome">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_monthly_income' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.monthlyincome else NoValue">
                      {{currency}}{{element.monthlyincome}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="addressline1">
                  <th mat-header-cell *matHeaderCellDef colspan="2" style="width:20%;">{{'lbl_address' | translate}}
                  </th>
                  <td mat-cell *matCellDef="let element" colspan="2" style="width:20%;">
                    <div *ngIf="element.addressline1 || element.addressline2 else NoValue">
                      {{element.addressline1}},{{element.addressline2}},{{element.city}} - {{element.pincode}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="createdDate">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_request_date' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    {{element.createdDate | date :'medium'}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="serviceName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_service_name' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.serviceName else NoValue">
                      {{element.serviceName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Action" stickyEnd>
                  <th mat-header-cell *matHeaderCellDef translate style="padding-left: 20px;">{{'lbl_action' |
                    translate}}
                  </th>
                  <td mat-cell *matCellDef="let element" class="text-center">
                    <div class="media-body text-right icon-state">

                      <a title="{{ 'other_loan_tooltip_edit_option_loan' |translate}}" *ngIf="isEditPermission"
                        href="javascript:;" class="btn btn-sm btn-info filterbtn"
                        (click)="editDialog(element,basicmodal)">
                        <i class="icon-pencil"></i>
                      </a>
                    </div>
                  </td>
                </ng-container>
                <tr mat-header-row *matHeaderRowDef="displayColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let row; columns: displayColumns;" class="student-element-row"
                  style="cursor: pointer;"></tr>
              </table>
            </div>
          </ng-container>

          <ng-template #NoOtherLoans>
            <div class="d-flex vertical-center nodata">

            </div>
          </ng-template>

          <div class="card-footer" *ngIf="otherLoans && otherLoans.length > 0">
            <ul class="pagination mb-0 float-right">
              <li [ngClass]="{ disabled: paginate.currentPage == 1 }" class="page-item page-prev">
                <a class="page-link" href="javascript:;" tabindex="-1" (click)="setPage(paginate.currentPage - 1)">
                  <span>{{'button_lbl_prev' | translate}}</span>
                </a>
              </li>
              <li *ngFor="let page of paginate.pages" class="page-item active"
                [ngClass]="{ active: paginate.currentPage == page }"><a
                  [ngClass]="{current:paginate.currentPage == page}" class="page-link" href="javascript:;"
                  (click)="setPage(page)">{{page}}</a></li>
              <li [ngClass]="{ disabled: paginate.currentPage === paginate.totalPages}"
                (click)="setPage(paginate.currentPage + 1)" class="page-item page-next">
                <a class="page-link" href="javascript:;"><span>{{'button_lbl_next' | translate}}</span></a>
              </li>
            </ul>
          </div>

        </div>
        <mat-drawer #drawer class="example-sidenav" mode="over" position="end">
          <div class="col-lg-12 px-3 pt-3">
            <div class="d-inline" style="width: 100%;"><i class="fa fa-filter"><span>{{'button_lbl_filter' |
                  translate}}</span></i>
              <button v class="close" aria-label="Close" (click)="drawer.toggle();">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
          </div>
          <hr>
          <div class="position px-3">
            <div class="form-group">
              <input class="form-control" type="text" id="search" [(ngModel)]="searchString"
                placeholder="{{'lbl_search'| translate}}">
            </div>
            <div class="form-group">
              <ng-select [items]="serviceTypes" class="js-example-basic-single p-0"
                placeholder="{{'bank_loan_lbl_search_by_service_name'|translate}}" bindLabel="name" bindValue="id"
                name="selectedOtherLoan" [(ngModel)]="selectedService" [multiple]="true">
              </ng-select>
            </div>
          </div>
          <div class="modal-footer p-0" style="margin-bottom: 20px;justify-content: center;">
            <div class="float-right d-inline">
              <button type="button" class="btn btn-secondary filterbtn"
                title="{{ 'tooltip_lbl_clear_filter' |translate}}" (click)="drawer.toggle();clearSearch();">
                <span>{{'button_lbl_clear' | translate}}</span>
              </button>
              <button type="button" class="btn btn-info filterbtn" title="{{ 'tooltip_lbl_filter_loans' |translate}}"
                (click)="drawer.toggle();setPage(1);">
                <span>{{'lbl_search' | translate}}</span>
              </button>
            </div>
          </div>
          <div class="px-3">
          </div>
        </mat-drawer>

      </mat-drawer-container>
    </div>
  </div>
</div>

<ng-template #basicmodal let-modal>
  <div>
    <form [formGroup]="otherLoanform">
      <div class="modal-header">
        <h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
        <button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body p-20" style="height:calc(100vh - 200px);overflow: auto;">
        <div class="form-row">
          <div class="form-group col-lg-4">
            <label for="fullName">{{'lbl_full_name' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="fullName" formControlName="fullName" onlyAlphabets required>
            <mat-error
              *ngIf="(otherLoanform.get('fullName') && !otherLoanform.get('fullName')!.valid && otherLoanform.get('fullName')!.touched)">
              {{'message_lbl_full_name_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="birthdate">{{'lbl_date_of_birth' | translate}} <span style="color: red;">*</span></label>
            <mat-form-field appearance="outline" class="w-100" style="margin-top: -0.25em;"
              (click)="toggleMenuService.togglePickerStyles()">
              <input matInput [matDatepicker]="filterPickerFrom" placeholder="Select Birthdate"
                formControlName="birthdate" name="birthdate" [readonly]="true" (focus)="filterPickerFrom.open()"
                (click)="toggleMenuService.togglePickerStyles()">
              <mat-datepicker-toggle matSuffix [for]="filterPickerFrom"
                (click)="toggleMenuService.togglePickerStyles()">
              </mat-datepicker-toggle>
              <mat-datepicker #filterPickerFrom></mat-datepicker>
            </mat-form-field>
            <mat-error
              *ngIf="(otherLoanform.get('birthdate') && !otherLoanform.get('birthdate')!.valid && otherLoanform.get('birthdate')!.touched)">
              {{'message_lbl_birthdate_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="contactNo">{{'lbl_contact_no' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="contactNo" formControlName="contactNo" ContactNo required>
            <mat-error
              *ngIf="(otherLoanform.get('contactNo') && !otherLoanform.get('contactNo')!.valid  && otherLoanform.get('contactNo')!.touched)">
              <span *ngIf="otherLoanform.get('contactNo')!.errors!['required']">
                {{'message_lbl_contact_no_is_required' | translate}}</span>
              <span *ngIf="otherLoanform.get('contactNo')!.errors!['minlength']">{{'message_lbl_enter_valid_contact_no'
                |
                translate}}</span>
            </mat-error>
          </div>
        </div>

        <!-- <div class="form-row"> -->
        <!-- <div class="form-group col-lg-4">
            <label for="panCardNo">{{'lbl_pan_card_no' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="panCardNo" formControlName="panCardNo" maxlength="10"
              maxlength="10" required oninput="this.value = this.value.toUpperCase()"
              (keypress)="keyPressAlphanumeric($event)">
            <mat-error
              *ngIf="(otherLoanform.get('panCardNo') && !otherLoanform.get('panCardNo')!.valid && otherLoanform.get('panCardNo')!.touched)">
              <span *ngIf="otherLoanform.get('panCardNo')!.errors!['required']">{{'message_lbl_pan_card_no_is_required' |
                translate}}</span>
              <span *ngIf="otherLoanform.get('panCardNo')!.errors?.['pattern']">{{'message_lbl_enter_valid_pan_card' |
                translate}}</span>
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="aadhaarCardNo">{{'lbl_aadhar_card_no' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="aadhaarCardNo" formControlName="aadhaarCardNo" maxlength="12"
              onlyNumbers required>
            <mat-error
              *ngIf="(otherLoanform.get('aadhaarCardNo') && !otherLoanform.get('aadhaarCardNo')!.valid && otherLoanform.get('aadhaarCardNo')!.touched)">
              <span *ngIf="otherLoanform.get('aadhaarCardNo')!.errors!['required']">
                {{'message_lbl_aadhar_card_no_is_required' | translate}}</span>
              <span *ngIf="otherLoanform.get('aadhaarCardNo')!.errors?.['pattern']">{{'message_lbl_enter_valid_aadhar_card_no'
                | translate}}</span>
            </mat-error>
          </div> -->

        <!-- </div> -->
        <form [formGroup]="customFieldForm">
          <div class="row mx-0">
            <ng-container *ngFor="let controlName of customFieldForm?.controls | keyvalue;let i = index">
              <div class="col-md-4 pl-0">
                <div class="form-group">
                  <label>{{ controlName.key | titlecase }}</label>
                  <ng-container *ngIf="hints[i]">
                    <a class="systooltip"><i class="fa fa-info-circle w-4 h-4 ml-1" style="margin-top:4px"></i>
                      <span class="tooltiptext">{{hints[i]
                        }}</span>
                    </a>
                  </ng-container>
                  <input class="form-control" [formControlName]="controlName.key" type="text">
                  <mat-error
                    *ngIf="(customFieldForm.get(controlName.key) && !customFieldForm.get(controlName.key)!.valid  && customFieldForm.get(controlName.key)!.touched)">
                    <span *ngIf="customFieldForm.get(controlName.key)!.errors?.['required']">{{controlName.key}}
                      is required</span>
                    <span *ngIf="customFieldForm.get(controlName.key)!.errors?.['pattern']">{{controlName.key}}
                      is invalid</span>
                  </mat-error>
                </div>
              </div>
            </ng-container>
          </div>
        </form>
        <div class="form-row">
          <div class="form-group col-lg-4">
            <label for="email">{{'lbl_email' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="email" formControlName="email" required>
            <mat-error
              *ngIf="(otherLoanform.get('email') && !otherLoanform.get('email')!.valid && otherLoanform.get('email')!.touched)">
              <span *ngIf="otherLoanform.get('email')!.errors!['required']">
                {{'message_lbl_email_is_required' | translate}}</span>
              <span *ngIf="otherLoanform.get('email')!.errors?.['pattern']">{{'Enter
                Valid Email' | translate}}</span>
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="employmentTypeId">{{'lbl_employment_type' | translate}} <span
                style="color: red;">*</span></label>
            <ng-select [items]="employments" class="js-example-basic-single p-0"
              placeholder="{{ 'placeholder_lbl_select_employment_type' |translate}}" bindLabel="name" bindValue="id"
              formControlName="employmentTypeId" name="employmentTypeId">
            </ng-select>
            <mat-error
              *ngIf="(otherLoanform.get('employmentTypeId') && !otherLoanform.get('employmentTypeId')?.valid && otherLoanform.get('employmentTypeId')?.touched)">
              {{'message_lbl_employment_type_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="serviceId">{{'lbl_service_name' | translate}} <span style="color: red;">*</span></label>
            <ng-select [items]="serviceTypes" class="js-example-basic-single p-0"
              placeholder="{{ 'lbl_select_loan_type' |translate}}" bindLabel="name" bindValue="id"
              formControlName="serviceId" name="serviceId">
            </ng-select>
            <mat-error
              *ngIf="(otherLoanform.get('serviceId') && !otherLoanform.get('serviceId')?.valid && otherLoanform.get('serviceId')?.touched)">
              {{'message_lbl_loan_type_is_required' | translate}}
            </mat-error>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-6">
            <label for="addressline1">{{'lbl_address_line1' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" id="addressline1" formControlName="addressline1"
              placeholder="{{'lbl_type_here'| translate}}" name="addressline1" required />
            <mat-error
              *ngIf="(otherLoanform.get('addressline1') && !otherLoanform.get('addressline1')?.valid && otherLoanform.get('addressline1')?.touched)">
              {{'message_lbl_address_line_1_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-md-6">
            <label for="addressline2">{{'lbl_address_line_2' | translate}}</label>
            <input class="form-control" type="text" id="addressline2" formControlName="addressline2"
              placeholder="{{'lbl_type_here'| translate}}" name="addressline2" />
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-lg-4">
            <label for="pincode">{{'lbl_pincode' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" id="pincode" formControlName="pincode"
              placeholder="{{'lbl_type_here'| translate}}" maxlength="6" onlyNumbers
              (keyup)="onKeyUpEvent($event,false)" required>
            <mat-error
              *ngIf="(otherLoanform.get('pincode') && !otherLoanform.get('pincode')?.valid && otherLoanform.get('pincode')?.touched)">
              {{'message_lbl_pincode_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="cityId">{{'lbl_city' | translate}} <span style="color: red;">*</span></label>
            <ng-select [items]="cities" class="js-example-basic-single p-0"
              placeholder="{{ 'lbl_select_city' |translate}}" bindLabel="name" bindValue="id" formControlName="cityId"
              name="cityId">
            </ng-select>
            <mat-error
              *ngIf="(otherLoanform.get('cityId') && !otherLoanform.get('cityId')?.valid && otherLoanform.get('cityId')?.touched)">
              {{'message_lbl_city_is_required' | translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="monthlyincome">{{'lbl_monthly_income' | translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" name="monthlyincome" formControlName="monthlyincome" required
              onlyNumbers>
            <mat-error
              *ngIf="(otherLoanform.get('monthlyincome') && !otherLoanform.get('monthlyincome')!.valid && otherLoanform.get('monthlyincome')!.touched)">
              {{'message_lbl_monthly_income_is_required' | translate}}
            </mat-error>
          </div>
        </div>

      </div>
      <div class="modal-footer">
        <button class="btn btn-sm btn-info filterbtn" (click)="insertUpdateotherLoan()">
          {{'button_lbl_save' | translate}}
        </button>
        <button class="btn btn-sm btn-secondary filterbtn" (click)="cancelUser()">
          {{'button_lbl_cancel' | translate}}
        </button>
      </div>
    </form>
  </div>
</ng-template>