diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index c0952255..986e0c2d 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -315,7 +315,7 @@ export class ImportDataController extends Controller { rowCount++; const profileSalary = new ProfileSalary(); profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; @@ -407,7 +407,7 @@ export class ImportDataController extends Controller { const profileSalary = new ProfileSalary(); profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTime(item.MP_POS_DATE); + item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; @@ -524,7 +524,16 @@ export class ImportDataController extends Controller { profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; @@ -639,7 +648,16 @@ export class ImportDataController extends Controller { profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = existingProfile.MARRIAGE_STATE; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; profileCouple.createdUserId = request.user.sub; profileCouple.createdFullName = request.user.name; @@ -750,14 +768,14 @@ export class ImportDataController extends Controller { }); let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + // startDate = startDate ? new Date(startDate, 0, 1) : null_; let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + // endDate = endDate ? new Date(endDate, 0, 1) : null_; education.profileId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; @@ -824,14 +842,14 @@ export class ImportDataController extends Controller { }); let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.START_EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) : null_; - startDate = startDate ? new Date(startDate, 0, 1) : null_; + // startDate = startDate ? new Date(startDate, 0, 1) : null_; let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTime(item.EDUCATION_YEAR) + ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) : null_; - endDate = endDate ? new Date(endDate, 0, 1) : null_; + // endDate = endDate ? new Date(endDate, 0, 1) : null_; education.profileEmployeeId = _item.id; education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; diff --git a/src/interfaces/extension.ts b/src/interfaces/extension.ts index 5b44a91d..e6c256de 100644 --- a/src/interfaces/extension.ts +++ b/src/interfaces/extension.ts @@ -27,6 +27,25 @@ class Extension { } return null; } + public static ConvertToDateTimeV2(value: any) { + if (value != "" && value != null) { + if (value.toString().length > 4) { + const chars = value.split("/"); + let year = Number(chars[2]) + 1900; + let month = Extension.MonthToNumber(chars[1]); + return new Date(year, month, chars[0]); + } else { + if (value.toString().length == 4) { + if (value < 1800) { + return null; + } else if (value > 2500) { + return new Date(value - 543, 0, 1); + } + } + } + } + return null; + } public static CheckRelationship(value: any) { if (value != "" && value != null) { @@ -76,6 +95,36 @@ class Extension { return ""; } } + public static MonthToNumber(value: string) { + switch (value.trim().toUpperCase()) { + case "JAN": + return 0; + case "FEB": + return 1; + case "MAR": + return 2; + case "APR": + return 3; + case "MAY": + return 4; + case "JUN": + return 5; + case "JUL": + return 6; + case "AUG": + return 7; + case "SEP": + return 8; + case "OCT": + return 9; + case "NOV": + return 10; + case "DEC": + return 11; + default: + return 0; + } + } public static ToThaiShortMonth(value: number) { switch (value) {