import { division, multiply } from "../aggregation/aggregation"; export class TrUtils { // static DecimalsNumber:number=2; static IsNull(Value: any) { return Value === null || typeof Value === 'undefined'; } static IsEmpty(Value: any) { return Value === null || typeof Value === 'undefined' || Value === ''; } static IsZero(Value: any) { return Value === null || typeof Value === 'undefined' || Value === 0; } static IsFixedZero(Value: any) { return Value === null || typeof Value === 'undefined' || Value === '0.00'; } static Stringify(RecordData: any) { if (this.IsNull(RecordData)) { return RecordData; } let StringifiedResult: any = JSON.parse(JSON.stringify(RecordData)); return StringifiedResult; } static ConcatObjects(obj1: any, obj2: any) { // tslint:disable-next-line:forin for (let key in obj2) { obj1[key] = obj2[key]; } return obj1; } static ConvertPercToVal(Discount: any, Total: any, DecimalsNumber: number = 2) { if (this.IsNull(Total)) { return null; } else { if (this.IsNull(Discount)) { Discount = 0; } if (this.IsNull(Total)) { Total = 0; } let value = this.FixedTo(division(multiply(Total, Discount), 100), DecimalsNumber); if (isNaN(value)) { value = 0; } return value; } } static FixedTo(value: any, DecimalsNumber: number = 2) { if (this.IsNull(value)) { value = 0; } value = Number(value); let Result: string = value.toFixed(DecimalsNumber); return Number(Result); } static FixPriceValue(Value: any, DecimalsNumber: number = 2) { if (this.IsNull(Value)) { Value = 0; } if (typeof Value === 'string') { Value = Number(Value); } let Result: string = Value.toFixed(DecimalsNumber); return Result; } static SetValueToZeroIfNull(Value: any) { if (this.IsNull(Value)) { Value = 0; } return Value; } static SetPercToStringIfNull(Value: any) { if (this.IsNull(Value)) { Value = ''; } return Value; } static SetPercToTrueIfNull(Value: any) { if (this.IsNull(Value)) { Value = true; } return Value; } static CheckInvalidSelect(Value: any) { return Value === null || typeof Value === 'undefined' || Value === '' || Value === -1 || Value === '-1'; } static isTaxable(tax: string) { return (tax === 'TI') ? true : false; } }