File

src/app/pipes/payments-filter.pipe.ts

Metadata

Methods

searchAmount
searchAmount(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchAmountFormatted
searchAmountFormatted(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchDate
searchDate(date: string, target: string)
Parameters :
Name Type Optional
date string No
target string No
Returns : boolean
searchDeliveryDate
searchDeliveryDate(date: string, target: string)
Parameters :
Name Type Optional
date string No
target string No
Returns : boolean
searchMemo
searchMemo(value: Payment, target: string)
Parameters :
Name Type Optional
value Payment No
target string No
Returns : boolean
searchPayFrom
searchPayFrom(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayFromAccountDisplayName
searchPayFromAccountDisplayName(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayFromAccountName
searchPayFromAccountName(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayFromAccountNumber
searchPayFromAccountNumber(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayment
searchPayment(value: Payment, target: string)
Parameters :
Name Type Optional
value Payment No
target string No
Returns : boolean
searchPayToAccountNumber
searchPayToAccountNumber(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayToBankAccount
searchPayToBankAccount(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayToDisplayName
searchPayToDisplayName(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
searchPayToName
searchPayToName(payment: Payment, target: string)
Parameters :
Name Type Optional
payment Payment No
target string No
Returns : boolean
transform
transform(input: Payment[], targetRaw: string)
Parameters :
Name Type Optional
input Payment[] No
targetRaw string No
Returns : Payment[]
import { DatePipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { LOCALE } from '../app.constants';
import { Payment } from '../models';

@Pipe({
  name: 'paymentsFilter'
})
export class PaymentsFilterPipe implements PipeTransform {
  transform(input: Payment[], targetRaw: string): Payment[] {
    if (
      input === null ||
      input === undefined ||
      targetRaw === null ||
      targetRaw === undefined
    ) {
      return input;
    }
    const target = targetRaw.toLowerCase();
    const pmts = input.filter(value => this.searchPayment(value, target));
    return pmts;
  }

  searchPayment(value: Payment, target: string) {
    const datePipe = new DatePipe(LOCALE);
    const dateStr = value.paymentDateFormatted;
    const shortDate = dateStr
      ? datePipe.transform(new Date(dateStr), 'shortDate')
      : null;
    const mediumDate = dateStr
      ? datePipe.transform(new Date(dateStr), 'mediumDate').toLowerCase()
      : null;
    const longDate = dateStr
      ? datePipe.transform(new Date(dateStr), 'longDate').toLowerCase()
      : null;
    const deliveryDateStr = value.expectedDeliveryDate;
    const shortDeliveryDate = deliveryDateStr
      ? datePipe.transform(new Date(deliveryDateStr), 'shortDate')
      : null;
    const mediumDeliveryDate = deliveryDateStr
      ? datePipe
          .transform(new Date(deliveryDateStr), 'mediumDate')
          .toLowerCase()
      : null;
    const longDeliveryDate = deliveryDateStr
      ? datePipe.transform(new Date(deliveryDateStr), 'longDate').toLowerCase()
      : null;

    return (
      this.searchPayToName(value, target) ||
      this.searchPayToDisplayName(value, target) ||
      this.searchPayToAccountNumber(value, target) ||
      this.searchPayToBankAccount(value, target) ||
      this.searchPayFrom(value, target) ||
      this.searchPayFromAccountName(value, target) ||
      this.searchPayFromAccountDisplayName(value, target) ||
      this.searchPayFromAccountNumber(value, target) ||
      this.searchMemo(value, target) ||
      this.searchDate(shortDate, target) ||
      this.searchDate(mediumDate, target) ||
      this.searchDate(longDate, target) ||
      this.searchDeliveryDate(shortDeliveryDate, target) ||
      this.searchDeliveryDate(mediumDeliveryDate, target) ||
      this.searchDeliveryDate(longDeliveryDate, target) ||
      this.searchAmount(value, target) ||
      this.searchAmountFormatted(value, target)
    );
  }

  searchPayFrom(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payFrom !== null &&
      payment.payFrom !== undefined &&
      payment.payFrom.toLowerCase().includes(target)
    );
  }

  searchPayFromAccountName(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payFromAccountName !== null &&
      payment.payFromAccountName !== undefined &&
      payment.payFromAccountName.toLowerCase().includes(target)
    );
  }

  searchPayFromAccountDisplayName(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payFromAccountDisplayName !== null &&
      payment.payFromAccountDisplayName !== undefined &&
      payment.payFromAccountDisplayName.toLowerCase().includes(target)
    );
  }

  searchPayToName(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payToName !== null &&
      payment.payToName !== undefined &&
      payment.payToName.toLowerCase().includes(target)
    );
  }

  searchPayToDisplayName(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.displayName !== null &&
      payment.displayName !== undefined &&
      payment.displayName.toLowerCase().includes(target)
    );
  }

  searchPayToBankAccount(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payToBankAccount !== null &&
      payment.payToBankAccount !== undefined &&
      payment.payToBankAccount.toLowerCase().includes(target)
    );
  }

  searchPayFromAccountNumber(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payFromAccount !== null &&
      payment.payFromAccount !== undefined &&
      payment.payFromAccount.toLowerCase().includes(target)
    );
  }

  searchPayToAccountNumber(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.payToBankAccount !== null &&
      payment.payToBankAccount !== undefined &&
      payment.payToBankAccount.toLowerCase().includes(target)
    );
  }

  searchMemo(value: Payment, target: string): boolean {
    return (
      value !== null &&
      value !== undefined &&
      value.memo !== null &&
      value.memo !== undefined &&
      value.memo.toLowerCase().includes(target)
    );
  }

  searchDate(date: string, target: string): boolean {
    return date != null && date !== undefined && date.includes(target);
  }

  searchDeliveryDate(date: string, target: string): boolean {
    return date != null && date !== undefined && date.includes(target);
  }

  searchAmountFormatted(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.amountFormatted !== null &&
      payment.amountFormatted !== undefined &&
      payment.amountFormatted.includes(target)
    );
  }

  searchAmount(payment: Payment, target: string): boolean {
    return (
      payment !== null &&
      payment !== undefined &&
      payment.amount !== null &&
      payment.amount !== undefined &&
      payment.amount.toString().includes(target)
    );
  }
}

results matching ""

    No results matching ""