//public void LoadBankFileDetail(string MPFFileFullPath) //{ // FileInfo fileInfo = new FileInfo(MPFFileFullPath); // if (fileInfo.Length % 80 != 0) // throw new Exception("Incorrect file size"); // StreamReader mpfFileStream = fileInfo.OpenText(); // char[] charRead = new char[80]; // int lineNo = 0; // try // { // while (mpfFileStream.Read(charRead, 0, 80) > 0) // { // string line = new string(charRead); // lineNo++; // if (lineNo == 1) // { // string[] mpfFileHeader1 = new string[7]; // mpfFileHeader1[0] = line.Substring(0, 1); // mpfFileHeader1[1] = line.Substring(1, 18); // mpfFileHeader1[2] = line.Substring(19, 28); // mpfFileHeader1[3] = line.Substring(47, 16); // mpfFileHeader1[4] = line.Substring(63, 3); // mpfFileHeader1[5] = line.Substring(66, 8); // mpfFileHeader1[6] = line.Substring(74, 6); // if (!mpfFileHeader1[0].Equals("S")) // throw new Exception("Invalid file header on line 1"); // RemoteProfileID = mpfFileHeader1[1].Trim(); // TransactionReference = mpfFileHeader1[3].Trim(); // if (!DateTime.TryParseExact(mpfFileHeader1[5] + mpfFileHeader1[6], "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.None, out TransactionTime)) // TransactionTime = TransactionTime = AppUtils.ServerDateTime(); // } // else // { // string[] bankFileDetailRecord = new string[10]; // bankFileDetailRecord[0] = line.Substring(0, 1); // bankFileDetailRecord[1] = line.Substring(1, 12); // bankFileDetailRecord[2] = line.Substring(13, 20); // bankFileDetailRecord[3] = line.Substring(33, 3); // bankFileDetailRecord[4] = line.Substring(36, 3); // bankFileDetailRecord[5] = line.Substring(39, 9); // bankFileDetailRecord[6] = line.Substring(48, 10); // bankFileDetailRecord[7] = line.Substring(58, 4); // bankFileDetailRecord[8] = line.Substring(62, 6); // bankFileDetailRecord[9] = line.Substring(68, 12); // GenericBankFileDetail bankFileDetail = new GenericBankFileDetail(); // if (!bankFileDetailRecord[0].Equals(" ")) // throw new Exception("Invalid record header on record detail" + " (line " + lineNo + ")"); // bankFileDetail.EmpNo = bankFileDetailRecord[1] + bankFileDetailRecord[8]; // bankFileDetail.EmpNo = bankFileDetail.EmpNo.Trim(); // bankFileDetail.EmpBankAccountHolderName = bankFileDetailRecord[2].Trim(); // bankFileDetail.BankCode = bankFileDetailRecord[3].Trim(); // bankFileDetail.BranchCode = bankFileDetailRecord[4].Trim(); // bankFileDetail.AccountNo = bankFileDetailRecord[5].Trim(); // double tmpRecordAmount = 0; // if (!double.TryParse(bankFileDetailRecord[6].Insert(8, "."), out tmpRecordAmount)) // throw new Exception("Invalid amount on record detail" + " (line " + lineNo + ")"); // bankFileDetail.Amount = tmpRecordAmount; // int valueDateNumeric = 0; // if (m_PlanCode == "F" || m_PlanCode == "G") // { // if (!bankFileDetailRecord[7].Trim().Equals(string.Empty)) // throw new Exception("Invalid value date on record detail" + " (line " + lineNo + ")"); // } // else // { // if (!int.TryParse(bankFileDetailRecord[7], out valueDateNumeric)) // throw new Exception("Invalid value date on record detail" + " (line " + lineNo + ")"); // int days = valueDateNumeric / 100; // int month = valueDateNumeric % 100; // bankFileDetail.ValueDate = new DateTime(currentDateTime.Year, month, days); // // find a value date which is nearest to the current date // if (bankFileDetail.ValueDate < currentDateTime.AddDays(-180)) // // to prevent 29 Feb issue, use "new DateTime" to re-assign the value // bankFileDetail.ValueDate = new DateTime(currentDateTime.Year + 1, month, days); // if (bankFileDetail.ValueDate.Day != days && bankFileDetail.ValueDate.Month != month) // throw new Exception("Invalid value date on record detail" + " (line " + lineNo + ")"); // } // m_TotalAmount += bankFileDetail.Amount; // BankFileDetails.Add(bankFileDetail); // } // } // if (m_TotalAmount - tmpHeaderTotalAmount >= 0.01 || RecordCount != tmpHeaderRecordCount) // throw new Exception("Total Amount / Record Count does not match with File Header"); // } // finally // { // mpfFileStream.Close(); // } //} public override FileInfo GenerateMPFFile() { string mpfFileData = string.Empty; // get Form No if (MPFSchemeCode.Equals("MT00261", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "INB1"; } else if (MPFSchemeCode.Equals("MT00245", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "INB2"; } else if (MPFSchemeCode.Equals("MT00512", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "INB7"; } else if (MPFSchemeCode.Equals("MT00555", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "INBA"; } else if (MPFSchemeCode.Equals("MT0027A", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "HAB1"; } else if (MPFSchemeCode.Equals("MT00253", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "HAB2"; } else if (MPFSchemeCode.Equals("MT00520", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "HAB7"; } else if (MPFSchemeCode.Equals("MT00563", StringComparison.CurrentCultureIgnoreCase)) { FormNo = "HABA"; } else { FormNo = " "; } // get Employer ID System.Xml.XmlNodeList mpfEmployerIDNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName("MPFPlanEmployerID"); if (mpfEmployerIDNode.Count > 0) { m_EmployerID = mpfEmployerIDNode[0].InnerText.PadRight(8).Substring(0, 8); } else { m_EmployerID = string.Empty.PadRight(8); } System.Xml.XmlNodeList defaultClassNameNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName("MPFPlanDefaultClassName"); if (defaultClassNameNode.Count > 0) { m_DefaultClassName = defaultClassNameNode[0].InnerText.Trim().ToUpper(); } else { m_DefaultClassName = string.Empty; } System.Xml.XmlNodeList payCenterNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName("MPFPlanPayCenter"); if (payCenterNode.Count > 0) { m_PayCenterCode = payCenterNode[0].InnerText.PadRight(4).Substring(0, 4).ToUpper(); } else { m_PayCenterCode = string.Empty.PadRight(4); } { HashCount = 1; string[] mpfFileHeader3 = new string[8]; mpfFileHeader3[0] = " "; mpfFileHeader3[1] = "0"; if (FormNo.Substring(2).Equals("B1")) { mpfFileHeader3[2] = "B5"; } else if (FormNo.Substring(2).Equals("B2")) { mpfFileHeader3[2] = "B6"; } else if (FormNo.Substring(2).Equals("B7")) { mpfFileHeader3[2] = "BM"; } else if (FormNo.Substring(2).Equals("BA")) { mpfFileHeader3[2] = "BX"; } mpfFileHeader3[3] = PayPeriodFr.ToString("yyyyMMdd"); mpfFileHeader3[4] = PayPeriodTo.ToString("yyyyMMdd"); mpfFileHeader3[5] = m_PayCenterCode.PadRight(4).Substring(0, 4).ToUpper(); mpfFileHeader3[6] = "D"; mpfFileHeader3[7] = string.Empty.PadLeft(55); string mpfFileHeaderString3 = string.Join(FIELD_DELIMITER, mpfFileHeader3); if (mpfFileHeaderString3.Length != 80) { throw new Exception("Invalid Length on header line 3"); } mpfFileData = mpfFileHeaderString3; } foreach (GenericExistingEmployeeMPFFileDetail bankFileDetail in ExistingEmployeeMPFFileDetails) { mpfFileData += GenerateExistingMPFFileDetail(bankFileDetail) + RECORD_DELIMITER; } foreach (GenericNewJoinEmployeeMPFFileDetail mpfFileDetail in NewJoinEmployeeMPFFileDetails) { mpfFileData += GenerateNewJoinMPFFileDetail(mpfFileDetail) + RECORD_DELIMITER; } //foreach (GenericAdditionalEmployeeMPFFileDetail bankFileDetail in AdditionalEmployeeMPFFileDetails) //{ // mpfFileData += GenerateAdditionalMPFFileDetail(bankFileDetail) + RECORD_DELIMITER; //} foreach (GenericBackPaymentEmployeeMPFFileDetail bankFileDetail in BackPaymentEmployeeMPFFileDetails) { mpfFileData += GenerateBackPaymentMPFFileDetail(bankFileDetail) + RECORD_DELIMITER; } { HashCount++; string[] mpfFileFooter = new string[9]; mpfFileFooter[0] = " "; mpfFileFooter[1] = "9"; mpfFileFooter[2] = ((double)(this.TotalAdditionalEmployeeMC + this.TotalAdditionalEmployeeVC + this.TotalBackPaymentEmployeeMC + this.TotalBackPaymentEmployeeVC + this.TotalExistingEmployeeMC + this.TotalExistingEmployeeVC + this.TotalNewJoinEmployeeMC + this.TotalNewJoinEmployeeVC)).ToString("0000000000000000.00").Replace(".", ""); mpfFileFooter[3] = "D"; mpfFileFooter[4] = " "; mpfFileFooter[5] = " "; mpfFileFooter[6] = ExistingEntitiesCount.ToString("0000000"); mpfFileFooter[7] = NewJoinEntitiesCount.ToString("0000000"); mpfFileFooter[8] = string.Empty.PadRight(31); string mpfFileFooterString = string.Join(FIELD_DELIMITER, mpfFileFooter); if (mpfFileFooterString.Length != 80) { throw new Exception("Invalid Length on header line 3"); } mpfFileData += mpfFileFooterString; } { string[] mpfFileHeader2 = new string[8]; mpfFileHeader2[0] = "M"; mpfFileHeader2[1] = EmployerID.PadRight(8).Substring(0, 8); mpfFileHeader2[2] = "0000"; mpfFileHeader2[3] = FormNo.Substring(0, 2); mpfFileHeader2[4] = HashCount.ToString("0000000"); mpfFileHeader2[5] = TransactionTime.ToString("yyyyMMdd"); mpfFileHeader2[6] = TransactionTime.ToString("HHmmss"); mpfFileHeader2[7] = string.Empty.PadRight(44); string mpfFileHeaderString2 = string.Join(FIELD_DELIMITER, mpfFileHeader2); if (mpfFileHeaderString2.Length != 80) { throw new Exception("Invalid Length on header line 3"); } mpfFileData = mpfFileHeaderString2 + RECORD_DELIMITER + mpfFileData; } //{ // string[] mpfFileHeader1 = new string[7]; // mpfFileHeader1[0] = "S"; // mpfFileHeader1[1] = RemoteProfileID.PadRight(18).Substring(0, 18); // mpfFileHeader1[2] = string.Empty.PadRight(28); // mpfFileHeader1[3] = TransactionReference.PadRight(16).Substring(0, 16); // mpfFileHeader1[4] = string.Empty.PadRight(3); // mpfFileHeader1[5] = TransactionTime.ToString("yyyyMMdd"); // mpfFileHeader1[6] = TransactionTime.ToString("HHmmss"); // string mpfFileHeaderString1 = string.Join(FIELD_DELIMITER, mpfFileHeader1); // if (mpfFileHeaderString1.Length != 80) // throw new Exception("Invalid Length on header line 3"); // mpfFileData = mpfFileHeaderString1 + RECORD_DELIMITER // + mpfFileData; //} FileInfo result = GenerateTempFileName(); StreamWriter writer = new StreamWriter(result.OpenWrite()); writer.Write(mpfFileData); writer.Close(); return(result); }
public override FileInfo GenerateMPFFile() { TransactionTime = AppUtils.ServerDateTime(); int mpfFileContributionRecordCount = 0; int mpfFileTerminationRecordCount = 0; string mpfFileContributionHeaderString = string.Empty; string mpfFileTerminationHeaderString = string.Empty; string mpfFileContributionData = string.Empty; string mpfFileTerminationData = string.Empty; // get Plan No System.Xml.XmlNodeList mpfPlanPlanNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_PLAN_NO); if (mpfPlanPlanNoNode.Count > 0) { MPFPlanPlanNo = mpfPlanPlanNoNode[0].InnerText.Trim(); } else { MPFPlanPlanNo = string.Empty; } // get Payroll Frequency System.Xml.XmlNodeList mpfPlanPayFrequencyNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_PAY_FREQUENCY); if (mpfPlanPayFrequencyNode.Count > 0) { MPFPlanPayFrequency = mpfPlanPayFrequencyNode[0].InnerText.Trim(); } foreach (GenericExistingEmployeeMPFFileDetail mpfFileDetail in ExistingEmployeeMPFFileDetails) { string terminationLine = string.Empty; mpfFileContributionData += GenerateMPFDetailLine(mpfFileDetail, out terminationLine) + RECORD_DELIMITER; mpfFileContributionRecordCount += mpfFileDetail.MPFContributionDetailList.Count; if (!string.IsNullOrEmpty(terminationLine)) { mpfFileTerminationData += terminationLine + RECORD_DELIMITER; mpfFileTerminationRecordCount++; } } foreach (GenericNewJoinEmployeeMPFFileDetail mpfFileDetail in NewJoinEmployeeMPFFileDetails) { string terminationLine = string.Empty; mpfFileContributionData += GenerateMPFDetailLine(mpfFileDetail, out terminationLine) + RECORD_DELIMITER; mpfFileContributionRecordCount += mpfFileDetail.MPFContributionDetailList.Count; if (!string.IsNullOrEmpty(terminationLine)) { mpfFileTerminationData += terminationLine + RECORD_DELIMITER; mpfFileTerminationRecordCount++; } } foreach (GenericAdditionalEmployeeMPFFileDetail mpfFileDetail in AdditionalEmployeeMPFFileDetails) { string terminationLine = string.Empty; mpfFileContributionData += GenerateMPFDetailLine(mpfFileDetail, out terminationLine) + RECORD_DELIMITER; mpfFileContributionRecordCount += mpfFileDetail.MPFContributionDetailList.Count; if (!string.IsNullOrEmpty(terminationLine)) { mpfFileTerminationData += terminationLine + RECORD_DELIMITER; mpfFileTerminationRecordCount++; } } foreach (GenericBackPaymentEmployeeMPFFileDetail mpfFileDetail in BackPaymentEmployeeMPFFileDetails) { string terminationLine = string.Empty; mpfFileContributionData += GenerateMPFDetailLine(mpfFileDetail, out terminationLine) + RECORD_DELIMITER; mpfFileContributionRecordCount += mpfFileDetail.MPFContributionDetailList.Count; if (!string.IsNullOrEmpty(terminationLine)) { mpfFileTerminationData += terminationLine + RECORD_DELIMITER; mpfFileTerminationRecordCount++; } } //HashCount = 1; { string[] mpfFileContributionHeaderArray = new string[12]; mpfFileContributionHeaderArray[0] = mpfFileContributionRecordCount.ToString("00000"); mpfFileContributionHeaderArray[1] = MPFPlanPlanNo.PadRight(6).Substring(0, 6); mpfFileContributionHeaderArray[2] = TransactionTime.ToString("yyyyMMdd"); mpfFileContributionHeaderArray[3] = ((double)m_TotalNewJoinMCER + m_TotalExistingMCER + m_TotalAdditionalMCER + m_TotalBackPaymentMCER ) .ToString("000000000000000.00").Replace(".", ""); mpfFileContributionHeaderArray[4] = ((double)m_TotalNewJoinMCEE + m_TotalExistingMCEE + m_TotalAdditionalMCEE + m_TotalBackPaymentMCEE ) .ToString("000000000000000.00").Replace(".", ""); mpfFileContributionHeaderArray[5] = ((double)m_TotalNewJoinVCER + m_TotalExistingVCER + m_TotalAdditionalVCER + m_TotalBackPaymentVCER ) .ToString("000000000000000.00").Replace(".", ""); mpfFileContributionHeaderArray[6] = ((double)m_TotalNewJoinVCEE + m_TotalExistingVCEE + m_TotalAdditionalVCEE + m_TotalBackPaymentVCEE ) .ToString("000000000000000.00").Replace(".", ""); mpfFileContributionHeaderArray[7] = AIATotalVCRelevantIncome.ToString("000000000000000.00").Replace(".", string.Empty); mpfFileContributionHeaderArray[8] = TotalRelevantIncome.ToString("000000000000000.00").Replace(".", string.Empty); mpfFileContributionHeaderArray[9] = string.Empty.PadRight(20); mpfFileContributionHeaderArray[10] = " "; mpfFileContributionHeaderArray[11] = PayPeriodFr.ToString("yyyyMMdd"); mpfFileContributionHeaderString = string.Join(FIELD_DELIMITER, mpfFileContributionHeaderArray); if (mpfFileContributionHeaderString.Length != 151) { throw new Exception("Invalid length for file header"); } mpfFileContributionData = mpfFileContributionHeaderString + RECORD_DELIMITER + mpfFileContributionData; } if (mpfFileTerminationRecordCount > 0) { string[] mpfFileTerminationHeaderArray = new string[3]; mpfFileTerminationHeaderArray[0] = mpfFileTerminationRecordCount.ToString("00000"); mpfFileTerminationHeaderArray[1] = MPFPlanPlanNo.PadRight(6).Substring(0, 6); mpfFileTerminationHeaderArray[2] = string.Empty.PadRight(20); mpfFileTerminationHeaderString = string.Join(FIELD_DELIMITER, mpfFileTerminationHeaderArray); mpfFileTerminationData = mpfFileTerminationHeaderString + RECORD_DELIMITER + mpfFileTerminationData; } FileInfo contributionFileInfo = GenerateTempFileName(); StreamWriter writer = new StreamWriter(contributionFileInfo.OpenWrite()); writer.Write(mpfFileContributionData); writer.Close(); //SaveSequenceNo(m_SequenceNo + 1); FileInfo zipFileInfo = new FileInfo(Path.GetTempFileName()); zipFileInfo.MoveTo(zipFileInfo.FullName + ".zip"); DirectoryInfo zipFolderInfo = zipFileInfo.Directory.CreateSubdirectory("AIAMPFFile" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmssfff")); List <FileInfo> fileInfoList = new List <FileInfo>(); { contributionFileInfo.MoveTo(System.IO.Path.Combine(zipFolderInfo.FullName, ActualMPFContributionFileName())); fileInfoList.Add(contributionFileInfo); if (mpfFileTerminationRecordCount > 0) { FileInfo terminationFileInfo = GenerateTempFileName(); writer = new StreamWriter(terminationFileInfo.OpenWrite()); writer.Write(mpfFileTerminationData); writer.Close(); terminationFileInfo.MoveTo(System.IO.Path.Combine(zipFolderInfo.FullName, ActualMPFTerminationFileName())); fileInfoList.Add(terminationFileInfo); } } zip.Compress(zipFolderInfo.FullName, "*", zipFileInfo.FullName); foreach (FileInfo fileInfo in fileInfoList) { fileInfo.Delete(); } zipFolderInfo.Delete(true); return(zipFileInfo); }