protected static void Read(XmlReader reader, STMTTRNRS aTranList, string sectionTag) { string lastName = string.Empty; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { lastName = reader.Name; if (reader.Name == "STMTRS" || reader.Name == "CCSTMTRS") { STMTRS acctTrans = new STMTRS(); aTranList.Stmtrs.Add(acctTrans); Read(reader, acctTrans, reader.Name); } } if (reader.NodeType == XmlNodeType.Text) { if (lastName == "TRNUID") { aTranList.TRNUID = reader.Value.Trim(); } } if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == sectionTag)) { return; } } }
protected static void Copy(CABankStatement aDest, STMTRS aSrc) { aDest.BankStatementFormat = "OFX"; aDest.StartBalanceDate = aSrc.BANKTRANLIST.DTSTART; aDest.EndBalanceDate = aSrc.BANKTRANLIST.DTEND; aDest.CuryEndBalance = aSrc.LEDGERBAL.BALAMT; }
protected static void Read(XmlReader reader, STMTRS aTranList, string sectionTag) { Type type = aTranList.GetType(); PropertyInfo[] members = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo iMem in members) { string name = iMem.Name; Type tp = iMem.PropertyType; } string lastName = string.Empty; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { lastName = reader.Name; if (reader.Name == "BANKACCTFROM") { Read(reader, aTranList.BANKACCTFROM); } if (reader.Name == "CCACCTFROM") { Read(reader, aTranList.CCACCTFROM); } if (reader.Name == "BANKTRANLIST") { Read(reader, aTranList.BANKTRANLIST); } if (lastName == "LEDGERBAL") { Read(reader, aTranList.LEDGERBAL, "LEDGERBAL"); } if (lastName == "AVAILBAL") { Read(reader, aTranList.AVAILBAL, "AVAILBAL"); } } if (reader.NodeType == XmlNodeType.Text) { if (lastName == "CURDEF") { aTranList.CURDEF = reader.Value.Trim(); } } if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == sectionTag)) { return; } } }
protected static void Read(XmlReader reader, STMTRS aTranList, string sectionTag) { Type type = aTranList.GetType(); PropertyInfo[] members = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo iMem in members) { string name = iMem.Name; Type tp = iMem.PropertyType; } string lastName = string.Empty; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { lastName = reader.Name; if (reader.Name == "BANKACCTFROM") { Read(reader, aTranList.BANKACCTFROM); } if(reader.Name == "CCACCTFROM") { Read(reader, aTranList.CCACCTFROM); } if (reader.Name == "BANKTRANLIST") { Read(reader, aTranList.BANKTRANLIST); } if (lastName == "LEDGERBAL") Read(reader, aTranList.LEDGERBAL, "LEDGERBAL"); if (lastName == "AVAILBAL") Read(reader, aTranList.AVAILBAL, "AVAILBAL"); } if (reader.NodeType == XmlNodeType.Text) { if (lastName == "CURDEF") { aTranList.CURDEF = reader.Value.Trim(); } } if (reader.NodeType == XmlNodeType.EndElement && (reader.Name == sectionTag)) { return; } } }
protected void Export(CABankStatementEntry aGraph, STMTRS aAcctStatement, bool updateCurrent) { if (!aAcctStatement.HasAccountInfo()) throw new PXException(Messages.OFXImportErrorAccountInfoIsIncorrect); CashAccount acct = aGraph.cashAccountByExtRef.Select(aAcctStatement.IsBankAccount() ? aAcctStatement.BANKACCTFROM.ACCTID : aAcctStatement.CCACCTFROM.ACCTID); if (acct == null) throw new PXException(Messages.CashAccountWithExtRefNbrIsNotFoundInTheSystem, aAcctStatement.BANKACCTFROM.ACCTID); if (aGraph.casetup.Current.IgnoreCuryCheckOnImport != true && acct.CuryID != aAcctStatement.CURDEF) throw new PXException(Messages.CashAccountHasCurrencyDifferentFromOneInStatement, acct.CashAccountCD, acct.CuryID, aAcctStatement.CURDEF); foreach (OFXStatementReader.STMTTRN iTran in aAcctStatement.BANKTRANLIST.Trans) { string stmtRefNbr; if (aGraph.IsAlreadyImported(acct.CashAccountID, iTran.FITID, out stmtRefNbr)) { throw new PXException(Messages.TransactionWithFitIdHasAlreadyBeenImported, iTran.FITID, stmtRefNbr, acct.CashAccountCD, acct.Descr); } } CABankStatement statement = null; if (updateCurrent == false || aGraph.BankStatement.Current == null || aGraph.BankStatement.Current.CashAccountID == null) { aGraph.Clear(); statement = new CABankStatement(); statement.CashAccountID = acct.CashAccountID; statement = aGraph.BankStatement.Insert(statement); aGraph.BankStatement.Current = statement; } else { statement = aGraph.BankStatement.Current ; if (statement.CashAccountID.HasValue) { if (statement.CashAccountID != acct.CashAccountID) { throw new PXException(Messages.ImportedStatementIsMadeForAnotherAccount, acct.CashAccountCD, acct.Descr); } } } CABankStatement copy = (CABankStatement)aGraph.BankStatement.Cache.CreateCopy(statement); Copy(copy, aAcctStatement); statement = aGraph.BankStatement.Update(copy); foreach (OFXStatementReader.STMTTRN iTran in aAcctStatement.BANKTRANLIST.Trans) { CABankStatementDetail detail = new CABankStatementDetail(); Copy(detail,iTran); detail = aGraph.Details.Insert(detail); CABankStatementDetail detail1 = (CABankStatementDetail)aGraph.Details.Cache.CreateCopy(detail); //Must be done after to avoid overwriting of debit by credit CopyForUpdate(detail1, iTran); detail = aGraph.Details.Update(detail1); } aGraph.Save.Press(); }
protected void Export(CABankStatementEntry aGraph, STMTRS aAcctStatement, bool updateCurrent) { if (!aAcctStatement.HasAccountInfo()) { throw new PXException(Messages.OFXImportErrorAccountInfoIsIncorrect); } CashAccount acct = aGraph.cashAccountByExtRef.Select(aAcctStatement.IsBankAccount() ? aAcctStatement.BANKACCTFROM.ACCTID : aAcctStatement.CCACCTFROM.ACCTID); if (acct == null) { throw new PXException(Messages.CashAccountWithExtRefNbrIsNotFoundInTheSystem, aAcctStatement.BANKACCTFROM.ACCTID); } if (aGraph.casetup.Current.IgnoreCuryCheckOnImport != true && acct.CuryID != aAcctStatement.CURDEF) { throw new PXException(Messages.CashAccountHasCurrencyDifferentFromOneInStatement, acct.CashAccountCD, acct.CuryID, aAcctStatement.CURDEF); } foreach (OFXStatementReader.STMTTRN iTran in aAcctStatement.BANKTRANLIST.Trans) { string stmtRefNbr; if (aGraph.IsAlreadyImported(acct.CashAccountID, iTran.FITID, out stmtRefNbr)) { throw new PXException(Messages.TransactionWithFitIdHasAlreadyBeenImported, iTran.FITID, stmtRefNbr, acct.CashAccountCD, acct.Descr); } } CABankStatement statement = null; if (updateCurrent == false || aGraph.BankStatement.Current == null || aGraph.BankStatement.Current.CashAccountID == null) { aGraph.Clear(); statement = new CABankStatement(); statement.CashAccountID = acct.CashAccountID; statement = aGraph.BankStatement.Insert(statement); aGraph.BankStatement.Current = statement; } else { statement = aGraph.BankStatement.Current; if (statement.CashAccountID.HasValue) { if (statement.CashAccountID != acct.CashAccountID) { throw new PXException(Messages.ImportedStatementIsMadeForAnotherAccount, acct.CashAccountCD, acct.Descr); } } } CABankStatement copy = (CABankStatement)aGraph.BankStatement.Cache.CreateCopy(statement); Copy(copy, aAcctStatement); statement = aGraph.BankStatement.Update(copy); foreach (OFXStatementReader.STMTTRN iTran in aAcctStatement.BANKTRANLIST.Trans) { CABankStatementDetail detail = new CABankStatementDetail(); Copy(detail, iTran); detail = aGraph.Details.Insert(detail); CABankStatementDetail detail1 = (CABankStatementDetail)aGraph.Details.Cache.CreateCopy(detail); //Must be done after to avoid overwriting of debit by credit CopyForUpdate(detail1, iTran); detail = aGraph.Details.Update(detail1); } aGraph.Save.Press(); }