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 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(); }