private void GenerateMPFDataByPeriod(GenericMPFFileDetail mpfFileDetail, ArrayList periodList) { foreach (GenericMPFFileContributionDetail contributionDetail in mpfFileDetail.MPFContributionDetailList) { MPFPeriod currentMPFPeriod = null; foreach (MPFPeriod mpfPeriod in periodList) { if (mpfPeriod.PeriodFrom < contributionDetail.PeriodTo && mpfPeriod.PeriodTo > contributionDetail.PeriodFrom) { if (mpfPeriod.PeriodFrom > contributionDetail.PeriodFrom) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } if (mpfPeriod.PeriodTo < contributionDetail.PeriodTo) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } currentMPFPeriod = mpfPeriod; } } if (currentMPFPeriod == null) { currentMPFPeriod = CreateMPFPeriod(contributionDetail.PeriodFrom, contributionDetail.PeriodTo); periodList.Add(currentMPFPeriod); } string[] mpfFileMCDetailStringList = new string[6]; mpfFileMCDetailStringList[0] = MPFPlanPlanNo; mpfFileMCDetailStringList[1] = "1"; mpfFileMCDetailStringList[2] = mpfFileDetail.HKIDPassport; mpfFileMCDetailStringList[3] = contributionDetail.MCER.ToString("0.00"); mpfFileMCDetailStringList[4] = contributionDetail.MCEE.ToString("0.00"); mpfFileMCDetailStringList[5] = contributionDetail.RelevantIncome.ToString("0.00"); currentMPFPeriod.DetailStringList.Add(string.Join(FIELD_DELIMITER, mpfFileMCDetailStringList)); if (contributionDetail.VCEE != 0 || contributionDetail.VCER != 0) { string vcPlanNo = string.Empty; System.Xml.XmlNodeList vcPlanNoNodeNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(mpfFileDetail.EmpAVCPlanExtendXMLString).GetElementsByTagName("EmpAVCPlanBOCIVCPlanNo"); if (vcPlanNoNodeNode.Count > 0) { vcPlanNo = vcPlanNoNodeNode[0].InnerText; } if (string.IsNullOrEmpty(vcPlanNo)) { throw new Exception("Voluntary Plan No. is missing:" + mpfFileDetail.EmpNo + " - " + mpfFileDetail.EmpName); } string[] mpfFileVCDetailStringList = new string[6]; mpfFileVCDetailStringList[0] = vcPlanNo; mpfFileVCDetailStringList[1] = "0"; mpfFileVCDetailStringList[2] = mpfFileDetail.HKIDPassport; mpfFileVCDetailStringList[3] = contributionDetail.VCER.ToString("0.00"); mpfFileVCDetailStringList[4] = contributionDetail.VCEE.ToString("0.00"); mpfFileVCDetailStringList[5] = contributionDetail.RelevantIncome.ToString("0.00"); currentMPFPeriod.DetailStringList.Add(string.Join(FIELD_DELIMITER, mpfFileVCDetailStringList)); } } }
private MPFPeriod CreateMPFPeriod(DateTime PeriodFrom, DateTime PeriodTo) { MPFPeriod mpfPeriod = new MPFPeriod(); mpfPeriod.PeriodFrom = PeriodFrom; mpfPeriod.PeriodTo = PeriodTo; mpfPeriod.DetailStringList = new ArrayList(); return(mpfPeriod); }
//private void SaveSequenceNo(int NewSequenceNo) //{ // EMPFPlan mpfPlan = new EMPFPlan(); // mpfPlan.MPFPlanID = MPFPlanID; // if (EMPFPlan.db.select(dbConn, mpfPlan)) // { // System.Xml.XmlDocument xmlDoc = HROne.CommonLib.Utility.GetXmlDocumentByDataString(mpfPlan.MPFPlanExtendData); // System.Xml.XmlNodeList nodeList = xmlDoc.GetElementsByTagName(MPF_PLAN_XML_SEQUENCE_NODE_NAME); // System.Xml.XmlNode sequenceNoNode; // if (nodeList.Count > 0) // sequenceNoNode = nodeList[0]; // else // { // sequenceNoNode = xmlDoc.CreateElement(MPF_PLAN_XML_SEQUENCE_NODE_NAME); // xmlDoc.DocumentElement.AppendChild(sequenceNoNode); // } // sequenceNoNode.InnerText = NewSequenceNo.ToString(); // nodeList = xmlDoc.GetElementsByTagName(MPF_PLAN_XML_LAST_GENERATE_DATE); // System.Xml.XmlNode lastDateNode; // if (nodeList.Count > 0) // lastDateNode = nodeList[0]; // else // { // lastDateNode = xmlDoc.CreateElement(MPF_PLAN_XML_LAST_GENERATE_DATE); // xmlDoc.DocumentElement.AppendChild(lastDateNode); // } // lastDateNode.InnerText = AppUtils.ServerDateTime().ToString("yyyyMMdd"); // mpfPlan.MPFPlanExtendData = xmlDoc.InnerXml; // EMPFPlan.db.update(dbConn, mpfPlan); // } //} private void GenerateMPFDataByPeriod(GenericMPFFileDetail mpfFileDetail, ArrayList periodList) { foreach (GenericMPFFileContributionDetail contributionDetail in mpfFileDetail.MPFContributionDetailList) { MPFPeriod currentMPFPeriod = null; foreach (MPFPeriod mpfPeriod in periodList) { if (mpfPeriod.PeriodFrom < contributionDetail.PeriodTo && mpfPeriod.PeriodTo > contributionDetail.PeriodFrom) { if (mpfPeriod.PeriodFrom > contributionDetail.PeriodFrom) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } if (mpfPeriod.PeriodTo < contributionDetail.PeriodTo) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } currentMPFPeriod = mpfPeriod; } } if (currentMPFPeriod == null) { currentMPFPeriod = CreateMPFPeriod(contributionDetail.PeriodFrom, contributionDetail.PeriodTo); periodList.Add(currentMPFPeriod); } EEmpPersonalInfo empInfo = new EEmpPersonalInfo(); empInfo.EmpID = mpfFileDetail.EmpID; EEmpPersonalInfo.db.select(dbConn, empInfo); string[] mpfFileMCDetailStringList = new string[13]; mpfFileMCDetailStringList[0] = "D"; mpfFileMCDetailStringList[1] = string.Empty.PadLeft(10); mpfFileMCDetailStringList[2] = mpfFileDetail.HKIDPassport.PadRight(15).Substring(0, 15); mpfFileMCDetailStringList[3] = empInfo.EmpEngSurname.PadRight(20).Substring(0, 20); mpfFileMCDetailStringList[4] = empInfo.EmpEngOtherName.PadRight(20).Substring(0, 20); mpfFileMCDetailStringList[5] = contributionDetail.RelevantIncome.ToString("00000000000.00").Replace(".", ""); mpfFileMCDetailStringList[6] = contributionDetail.MCEE.ToString("00000000000.00").Replace(".", ""); mpfFileMCDetailStringList[7] = contributionDetail.MCER.ToString("00000000000.00").Replace(".", ""); mpfFileMCDetailStringList[8] = contributionDetail.VCEE.ToString("00000000000.00").Replace(".", ""); mpfFileMCDetailStringList[9] = contributionDetail.VCER.ToString("00000000000.00").Replace(".", ""); mpfFileMCDetailStringList[10] = ((double)0).ToString("00000000000.00").Replace(".", ""); // no surcharge support mpfFileMCDetailStringList[11] = " "; // Not In Use Since file specification 1.7a mpfFileMCDetailStringList[12] = string.Empty.PadLeft(8); // Not In Use Since file specification 1.7a currentMPFPeriod.TotalContributionAmount += contributionDetail.MCER + contributionDetail.MCEE; currentMPFPeriod.TotalContributionAmount += contributionDetail.VCER + contributionDetail.VCEE; currentMPFPeriod.DetailStringList.Add(string.Join(FIELD_DELIMITER, mpfFileMCDetailStringList)); } }
//private double GenerateMPFDataByPeriod(GenericExistingEmployeeMPFFileDetail mpfFileDetail, ArrayList periodList, string recordType) private double GenerateMPFDataByPeriod(GenericMPFFileDetail mpfFileDetail, ArrayList periodList, string recordType) { double m_totalFigures = 0; // for use in data segment footer //ECessationReason m_empTermReason = new ECessationReason(); //m_empTermReason.CessationReasonID = mpfFileDetail.CessationReasonID; //m_empTermReason = ECessationReason.db.select(dbConn, m_empTermReason); //if (m_empTermReason) // return 0; foreach (GenericMPFFileContributionDetail contributionDetail in mpfFileDetail.MPFContributionDetailList) { MPFPeriod currentMPFPeriod = null; foreach (MPFPeriod mpfPeriod in periodList) { if (mpfPeriod.PeriodFrom < contributionDetail.PeriodTo && mpfPeriod.PeriodTo > contributionDetail.PeriodFrom) { if (mpfPeriod.PeriodFrom > contributionDetail.PeriodFrom) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } if (mpfPeriod.PeriodTo < contributionDetail.PeriodTo) { mpfPeriod.PeriodFrom = contributionDetail.PeriodFrom; } currentMPFPeriod = mpfPeriod; } } if (currentMPFPeriod == null) { currentMPFPeriod = CreateMPFPeriod(contributionDetail.PeriodFrom, contributionDetail.PeriodTo); periodList.Add(currentMPFPeriod); } m_totalFigures += (contributionDetail.VCEE + contributionDetail.VCER + contributionDetail.MCEE + contributionDetail.MCER + contributionDetail.RelevantIncome + contributionDetail.VCRelevantIncome); if (recordType == "CA") { string[] mpfFileMCDetailStringList = new string[15]; mpfFileMCDetailStringList[0] = recordType.PadRight(2).Substring(0, 2); mpfFileMCDetailStringList[1] = this.MPFPlanParticipationNo.PadRight(4).Substring(0, 4); mpfFileMCDetailStringList[2] = mpfFileDetail.HKIDPassport.PadRight(15).Substring(0, 15); mpfFileMCDetailStringList[3] = "FMPF"; // <-- hardcode for MT000288 Fidelity scheme // this.MPFSchemeCode.PadRight(4).Substring(0, 4); mpfFileMCDetailStringList[4] = contributionDetail.PeriodFrom.ToString("yyyyMMdd").PadRight(8).Substring(0, 8); mpfFileMCDetailStringList[5] = contributionDetail.PeriodTo.ToString("yyyyMMdd").PadRight(8).Substring(0, 8); mpfFileMCDetailStringList[6] = "M"; // MPF Mandatory contribution mpfFileMCDetailStringList[7] = "RG"; mpfFileMCDetailStringList[8] = contributionDetail.MCER.ToString("0000000000000.00").Replace(".", ""); mpfFileMCDetailStringList[9] = contributionDetail.MCEE.ToString("0000000000000.00").Replace(".", ""); mpfFileMCDetailStringList[10] = currentMPFPeriod.PeriodFrom.ToString("yyyyMMdd").PadRight(8).Substring(0, 8); mpfFileMCDetailStringList[11] = "".PadRight(15); mpfFileMCDetailStringList[12] = "".PadRight(2); mpfFileMCDetailStringList[13] = "".PadRight(1); mpfFileMCDetailStringList[14] = contributionDetail.RelevantIncome.ToString("0000000000000.00").Replace(".", ""); currentMPFPeriod.DetailStringList.Add(string.Join(FIELD_DELIMITER, mpfFileMCDetailStringList)); } if (contributionDetail.VCEE != 0 || contributionDetail.VCER != 0) { //string vcPlanNo = string.Empty; //System.Xml.XmlNodeList vcPlanNoNodeNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(mpfFileDetail.EmpAVCPlanExtendXMLString).GetElementsByTagName("EmpAVCPlanBOCIVCPlanNo"); //if (vcPlanNoNodeNode.Count > 0) // vcPlanNo = vcPlanNoNodeNode[0].InnerText; //if (string.IsNullOrEmpty(vcPlanNo)) //{ // throw new Exception("Voluntary Plan No. is missing:" + mpfFileDetail.EmpNo + " - " + mpfFileDetail.EmpName); //} if (recordType == "CA") { string[] mpfFileVCDetailStringList = new string[15]; mpfFileVCDetailStringList[0] = recordType.PadRight(2).Substring(0, 2); mpfFileVCDetailStringList[1] = this.MPFPlanParticipationNo.PadRight(4).Substring(0, 4); mpfFileVCDetailStringList[2] = mpfFileDetail.HKIDPassport.PadRight(15).Substring(0, 15); mpfFileVCDetailStringList[3] = this.MPFSchemeCode.PadRight(4).Substring(0, 4); mpfFileVCDetailStringList[4] = contributionDetail.PeriodFrom.ToString("yyyyMMdd").PadRight(8).Substring(0, 8); mpfFileVCDetailStringList[5] = contributionDetail.PeriodTo.ToString("yyyyMMdd").PadRight(8).Substring(0, 8); mpfFileVCDetailStringList[6] = "V"; // Voluntary Mandatory contribution mpfFileVCDetailStringList[7] = "RG"; mpfFileVCDetailStringList[8] = contributionDetail.VCER.ToString("0000000000000.00").Replace(".", ""); mpfFileVCDetailStringList[9] = contributionDetail.VCEE.ToString("0000000000000.00").Replace(".", ""); mpfFileVCDetailStringList[10] = currentMPFPeriod.PeriodFrom.ToString("yyyyMMdd"); mpfFileVCDetailStringList[11] = "".PadRight(15); mpfFileVCDetailStringList[12] = "".PadRight(2); mpfFileVCDetailStringList[13] = "".PadRight(1); mpfFileVCDetailStringList[14] = contributionDetail.RelevantIncome.ToString("0000000000000.00").Replace(".", ""); currentMPFPeriod.DetailStringList.Add(string.Join(FIELD_DELIMITER, mpfFileVCDetailStringList)); } } } return(m_totalFigures); }
public override FileInfo GenerateMPFFile() { TransactionTime = AppUtils.ServerDateTime(); string mpfFileData = string.Empty; // get Scheme No System.Xml.XmlNodeList mpfPlanSchemeNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_SUB_SCHEME_NO); if (mpfPlanSchemeNoNode.Count > 0) { MPFPlanSchemeNo = mpfPlanSchemeNoNode[0].InnerText.Trim(); } else { MPFPlanSchemeNo = string.Empty; } // get Group No string MPFPlanGroupNo; System.Xml.XmlNodeList mpfPlanGroupNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_GROUP_NO); if (mpfPlanGroupNoNode.Count > 0) { MPFPlanGroupNo = mpfPlanGroupNoNode[0].InnerText.Trim(); } else { MPFPlanGroupNo = string.Empty; } // get Sub-group No string MPFPlanSubGroupNo; System.Xml.XmlNodeList mpfPlanSubGroupNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_SUB_GROUP_NO); if (mpfPlanSubGroupNoNode.Count > 0) { MPFPlanSubGroupNo = mpfPlanSubGroupNoNode[0].InnerText.Trim(); } else { MPFPlanSubGroupNo = string.Empty; } // get File Sequence Number //string strLastGenerateDate; //System.Xml.XmlNodeList mpfPlanLastGenerateDateNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_LAST_GENERATE_DATE); //if (mpfPlanLastGenerateDateNode.Count > 0) //{ // strLastGenerateDate = mpfPlanLastGenerateDateNode[0].InnerText.Trim(); //} //else //{ // strLastGenerateDate = string.Empty; //} //if (strLastGenerateDate.Equals(AppUtils.ServerDateTime().ToString("yyyyMMdd"))) //{ // System.Xml.XmlNodeList mpfPlanSequenceNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName(MPF_PLAN_XML_SEQUENCE_NODE_NAME); // if (mpfPlanSequenceNoNode.Count > 0) // { // if (!int.TryParse(mpfPlanSequenceNoNode[0].InnerText.Trim(), out SequenceNo)) // SequenceNo = 1; // } // else // SequenceNo = 1; //} //else // SequenceNo = 1; //// get Scheme No //System.Xml.XmlNodeList mpfPlanPlanNoNode = HROne.CommonLib.Utility.GetXmlDocumentByDataString(MPFPlanExtendXMLString).GetElementsByTagName("MPFPlanPlanNo"); //if (mpfPlanPlanNoNode.Count > 0) //{ // MPFPlanPlanNo = mpfPlanPlanNoNode[0].InnerText.Trim(); //} //else // MPFPlanPlanNo = string.Empty; MPFPeriodList = new ArrayList(); foreach (GenericExistingEmployeeMPFFileDetail bankFileDetail in ExistingEmployeeMPFFileDetails) { GenerateMPFDataByPeriod(bankFileDetail, MPFPeriodList); } foreach (GenericNewJoinEmployeeMPFFileDetail mpfFileDetail in NewJoinEmployeeMPFFileDetails) { GenerateMPFDataByPeriod(mpfFileDetail, MPFPeriodList); } //foreach (GenericAdditionalEmployeeMPFFileDetail bankFileDetail in AdditionalEmployeeMPFFileDetails) // GenerateMPFDataByPeriod(bankFileDetail, MPFPeriodList); foreach (GenericBackPaymentEmployeeMPFFileDetail bankFileDetail in BackPaymentEmployeeMPFFileDetails) { GenerateMPFDataByPeriod(bankFileDetail, MPFPeriodList); } int lineCount = 1; // Include Header for (int idx = 0; idx < MPFPeriodList.Count - 1; idx++) { MPFPeriod currentMpfPeriod = ((MPFPeriod)MPFPeriodList[idx]); MPFPeriod NextMpfPeriod = ((MPFPeriod)MPFPeriodList[idx + 1]); if (currentMpfPeriod.PeriodFrom > NextMpfPeriod.PeriodFrom) { MPFPeriodList.Remove(currentMpfPeriod); MPFPeriodList.Insert(idx + 1, currentMpfPeriod); } } foreach (MPFPeriod mpfPeriod in MPFPeriodList) { string[] periodRecordHeader = new string[9]; periodRecordHeader[0] = "S"; periodRecordHeader[1] = mpfPeriod.PeriodFrom.ToString("yyyyMMdd"); periodRecordHeader[2] = mpfPeriod.PeriodTo.ToString("yyyyMMdd"); periodRecordHeader[3] = " "; // leave blank periodRecordHeader[4] = ((double)0).ToString("00.00").Replace(".", ""); // no surcharge support periodRecordHeader[5] = " "; // no surcharge support periodRecordHeader[6] = mpfPeriod.DetailStringList.Count.ToString("000000"); periodRecordHeader[7] = mpfPeriod.TotalContributionAmount.ToString("0000000000000.00").Replace(".", ""); periodRecordHeader[8] = ((double)0).ToString("0000000000000.00").Replace(".", ""); // no surcharge support string periodRecordHeaderString = string.Join(FIELD_DELIMITER, periodRecordHeader); mpfFileData += RECORD_DELIMITER + periodRecordHeaderString; lineCount++; foreach (string mpfContributionString in mpfPeriod.DetailStringList) { mpfFileData += RECORD_DELIMITER + mpfContributionString; lineCount++; } } //HashCount = 1; string[] mpfFileHeader = new string[8]; mpfFileHeader[0] = "H"; mpfFileHeader[1] = MPFPlanGroupNo.PadRight(8).Substring(0, 8); mpfFileHeader[2] = MPFPlanSubGroupNo.PadRight(2).Substring(0, 2); mpfFileHeader[3] = "D"; mpfFileHeader[4] = AppUtils.ServerDateTime().ToString("yyyyMMdd"); mpfFileHeader[5] = lineCount.ToString("000000"); mpfFileHeader[6] = ((double)TotalAdditionalEmployeeMC + TotalAdditionalEmployeeVC + TotalBackPaymentEmployeeMC + TotalBackPaymentEmployeeVC + TotalExistingEmployeeMC + TotalExistingEmployeeVC + TotalNewJoinEmployeeMC + TotalNewJoinEmployeeVC) .ToString("0000000000000.00").Replace(".", ""); mpfFileHeader[7] = ((double)0).ToString("0000000000000.00").Replace(".", ""); // no surcharge support mpfFileData = string.Join(FIELD_DELIMITER, mpfFileHeader) + mpfFileData; //string[] mpfFileFooter = new string[19]; //mpfFileFooter[0] = FormNo; //mpfFileFooter[1] = string.Empty.PadRight(46); //mpfFileFooter[2] = "99"; //mpfFileFooter[3] = "999999"; //mpfFileFooter[4] = ((double)(this.TotalAdditionalEmployeeMC + this.TotalAdditionalEmployeeVC + this.TotalBackPaymentEmployeeMC + this.TotalBackPaymentEmployeeVC + this.TotalExistingEmployeeMC + this.TotalExistingEmployeeVC + this.TotalNewJoinEmployeeMC + this.TotalNewJoinEmployeeVC)).ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[5] = " "; // leave blank for internal use //if (PaymentMethod == PaymentMethodEnum.CHEQUE) // mpfFileFooter[6] = "C"; //else if (PaymentMethod == PaymentMethodEnum.AUTOPAY) // mpfFileFooter[6] = "B"; //else if (PaymentMethod == PaymentMethodEnum.CASH) // mpfFileFooter[6] = "D"; //else // mpfFileFooter[6] = " "; //mpfFileFooter[7] = " "; //mpfFileFooter[8] = " "; //mpfFileFooter[9] = ExistingEntitiesCount.ToString("0000000"); //mpfFileFooter[10] = NewJoinEntitiesCount.ToString("0000000"); //mpfFileFooter[11] = this.TotalExistingEmployeeMC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[12] = this.TotalNewJoinEmployeeMC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[13] = this.TotalExistingEmployeeVC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[14] = this.TotalNewJoinEmployeeVC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[15] = this.TotalAdditionalEmployeeMC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[16] = this.TotalAdditionalEmployeeVC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[17] = this.TotalBackPaymentEmployeeMC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileFooter[18] = this.TotalBackPaymentEmployeeVC.ToString("0000000000000000.00").Replace(".", ""); //mpfFileData += string.Join(FIELD_DELIMITER, mpfFileFooter); // HeadCount include footer record //HashCount++; //string[] mpfFileHeader = new string[9]; //mpfFileHeader[0] = "HEADER "; //mpfFileHeader[1] = "MPF CONTRIBUTION DTL "; //mpfFileHeader[2] = "AMCND "; //mpfFileHeader[3] = "EXT "; //mpfFileHeader[4] = "MPF "; //mpfFileHeader[5] = TransactionTime.ToString("yyyyMMdd"); //mpfFileHeader[6] = TransactionTime.ToString("HHmmss"); //mpfFileHeader[7] = HashCount.ToString("0000000"); //mpfFileHeader[8] = TotalRelevantIncome.ToString("0000000000000.00").Replace(".", ""); //mpfFileData = string.Join(FIELD_DELIMITER, mpfFileHeader) + RECORD_DELIMITER + mpfFileData; FileInfo result = GenerateTempFileName(); StreamWriter writer = new StreamWriter(result.OpenWrite()); writer.Write(mpfFileData); writer.Close(); //SaveSequenceNo(m_SequenceNo + 1); return(result); }