public List <ETL_GeneralJournal> JoinJournal(Session session, List <ETL_GeneralJournal> journalList) { List <ETL_GeneralJournal> result = new List <ETL_GeneralJournal>(); try { ETLAccountingBO accountingBO = new ETLAccountingBO(); foreach (ETL_GeneralJournal journal in journalList) { ETL_GeneralJournal rsJournal = GetJournal(session, result, journal.AccountId); if (rsJournal == null) { rsJournal = new ETL_GeneralJournal(); rsJournal.AccountId = accountingBO.GetHighestAccount(session, journal.AccountId).AccountId; rsJournal.CreateDate = journal.CreateDate; rsJournal.Credit = journal.Credit; rsJournal.CurrencyId = journal.CurrencyId; rsJournal.Debit = journal.Debit; rsJournal.JournalType = journal.JournalType; result.Add(rsJournal); } else { rsJournal.Credit += journal.Credit; rsJournal.Debit += journal.Debit; } } return(result); } catch (Exception) { return(null); } return(result); }
public ETL_GeneralJournal GetJournal(Session session, List <ETL_GeneralJournal> journalList, string AccountCode) { ETLAccountingBO accountingBO = new ETLAccountingBO(); ETL_GeneralJournal result = new ETL_GeneralJournal(); try { if (journalList == null) { return(null); } Util util = new Util(); Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal); if (account == null) { return(null); } foreach (ETL_GeneralJournal journal in journalList) { if (accountingBO.IsRelateAccount(session, journal.AccountId, account.AccountId)) { return(journal); } } return(null); } catch (Exception) { return(null); } return(result); }
private List <ETL_GeneralJournal> JoinJournal(Session session, List <ETL_GeneralJournal> journalList, string mainAccountCode) { List <ETL_GeneralJournal> result = new List <ETL_GeneralJournal>(); CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", mainAccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account mainAccount = session.FindObject <Account>(criteria); if (mainAccount == null) { return(null); } try { ETLAccountingBO accountingBO = new ETLAccountingBO(); foreach (ETL_GeneralJournal journal in journalList) { if (accountingBO.IsRelateAccount(session, mainAccount.AccountId, journal.AccountId)) { ETL_GeneralJournal masterJournal = new ETL_GeneralJournal(); masterJournal.AccountId = journal.AccountId; masterJournal.CreateDate = journal.CreateDate; masterJournal.Credit = journal.Credit; masterJournal.Debit = journal.Debit; masterJournal.CurrencyId = journal.CurrencyId; masterJournal.JournalType = journal.JournalType; result.Add(masterJournal); } else { ETL_GeneralJournal rsJournal = GetJournal(session, result, journal.AccountId); if (rsJournal == null) { rsJournal = new ETL_GeneralJournal(); rsJournal.AccountId = accountingBO.GetHighestAccount(session, journal.AccountId).AccountId; rsJournal.CreateDate = journal.CreateDate; rsJournal.Credit = journal.Credit; rsJournal.CurrencyId = journal.CurrencyId; rsJournal.Debit = journal.Debit; rsJournal.JournalType = journal.JournalType; result.Add(rsJournal); } else { rsJournal.Credit += journal.Credit; rsJournal.Debit += journal.Debit; } } } return(result); } catch (Exception) { return(null); } }
public ETL_Transaction ExtractTransaction(Session session, Guid TransactionId) { ETL_Transaction resultTransaction = null; try { Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); if (transaction == null) { return(resultTransaction); } resultTransaction = new ETL_Transaction(); resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); foreach (GeneralJournal journal in transaction.GeneralJournals) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); tempJournal.AccountId = journal.AccountId.AccountId; tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; resultTransaction.GeneralJournalList.Add(tempJournal); } } catch (Exception) { throw; } return(resultTransaction); }
public bool IsJoinableJournals(Session session, ETL_GeneralJournal journal1, ETL_GeneralJournal journal2) { bool result = false; ETLAccountingBO accountingBO = new ETLAccountingBO(); try { result = (accountingBO.IsRelateAccount(session, journal1.AccountId, journal2.AccountId) || accountingBO.IsRelateAccount(session, journal1.AccountId, journal2.AccountId)) && ((journal1.Credit * journal2.Credit > 0) || (journal1.Debit * journal2.Debit > 0)) && (journal1.CurrencyId == journal2.CurrencyId) && (journal1.JournalType == journal2.JournalType); } catch (Exception) { return(false); } return(result); }
private ETL_GeneralJournal GetJournal(Session session, List <ETL_GeneralJournal> journalList, Guid AccountId) { ETL_GeneralJournal result = new ETL_GeneralJournal(); try { Account account = session.GetObjectByKey <Account>(AccountId); if (account == null) { return(null); } return(GetJournal(session, journalList, account.Code)); } catch (Exception) { return(null); } }
public List <ETL_GeneralJournal> JoinJournalList(Session session, List <ETL_GeneralJournal> journalList) { List <ETL_GeneralJournal> result = null; try { result = new List <ETL_GeneralJournal>(); ETLAccountingBO accountingBO = new ETLAccountingBO(); foreach (ETL_GeneralJournal journal in journalList) { if (!IsOffBalanceAccount(session, journal.AccountId)) { bool flag = false; foreach (ETL_GeneralJournal rs_journal in result) { if (IsJoinableJournals(session, rs_journal, journal)) { flag = true; rs_journal.Debit += journal.Debit; rs_journal.Credit += journal.Credit; rs_journal.AccountId = accountingBO.GetHighestAccount(session, rs_journal.AccountId).AccountId; } } if (!flag) { ETL_GeneralJournal temp_journal = journal; temp_journal.AccountId = accountingBO.GetHighestAccount(session, temp_journal.AccountId).AccountId; result.Add(temp_journal); } } } } catch (Exception) { return(null); } return(result); }
public ETL_GeneralJournal JoinJournal(Session session, ETL_GeneralJournal journal1, ETL_GeneralJournal journal2) { ETL_GeneralJournal result = null; ETLAccountingBO accountingBO = new ETLAccountingBO(); try { if (!IsJoinableJournals(session, journal1, journal2)) { return(null); } result = journal1; result.Debit += journal2.Debit; result.Credit += journal2.Credit; result.AccountId = accountingBO.GetHighestAccount(session, journal1.AccountId).AccountId; return(result); } catch (Exception) { return(null); } return(result); }
protected ETL_ActualPriceTransaction ExtractTransaction(Session session, Guid TransactionId, string AccountCode) { ETL_ActualPriceTransaction resultTransaction = null; try { bool Acceptable = false; CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", AccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account account = session.FindObject <Account>(criteria); /*2014/02/20 Duc.Vo INS START*/ Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); /*2014/02/20 Duc.Vo INS END*/ Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); if (transaction == null) { return(resultTransaction); } Util util = new Util(); /*2014/02/20 Duc.Vo MOD START*/ resultTransaction = new ETL_ActualPriceTransaction(); if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } if (transaction is SaleInvoiceTransaction) { if ((transaction as SaleInvoiceTransaction).SalesInvoiceId.SourceOrganizationId != null) { resultTransaction.CustomerOrgId = (transaction as SaleInvoiceTransaction).SalesInvoiceId.SourceOrganizationId.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } else if (transaction is PurchaseInvoiceTransaction) { if ((transaction as PurchaseInvoiceTransaction).PurchaseInvoiceId.SourceOrganizationId != null) { resultTransaction.SupplierOrgId = (transaction as PurchaseInvoiceTransaction).PurchaseInvoiceId.SourceOrganizationId.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } } else if (transaction is PaymentVouchesTransaction) { PaymentVoucherTransactionBO paymentVoucherTransactionBO = new PaymentVoucherTransactionBO(); Organization SuppOrg = paymentVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = paymentVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } else if (transaction is ReceiptVouchesTransaction) { ReceiptVoucherTransactionBO receiptVoucherTransactionBO = new ReceiptVoucherTransactionBO(); Organization SuppOrg = receiptVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = receiptVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } else { Organization SuppOrg = accountingBO.GetAllocatedSupplierByManualTransaction(session, transaction.TransactionId); Organization CustOrg = accountingBO.GetAllocatedCustomerByManualTransaction(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } if (resultTransaction.SupplierOrgId == Guid.Empty) { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (resultTransaction.CustomerOrgId == Guid.Empty) { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } /*2014/02/20 Duc.Vo MOD END*/ resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; //resultTransaction.GeneralJournalList = new List<ETL_GeneralJournal>(); List <ETL_GeneralJournal> tmpGeneralJournalList = new List <ETL_GeneralJournal>(); double sumDebit_NotRelativeBussiness = 0; foreach (GeneralJournal journal in transaction.GeneralJournals. Where(i => i.RowStatus == Constant.ROWSTATUS_BOOKED_ENTRY || i.RowStatus == Constant.ROWSTATUS_ACTIVE)) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; } else { tempJournal.AccountId = defaultAccount.AccountId; } tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; if (tempJournal.Debit > 0 && !accountingBO.IsRelateAccount(session, AccountCode, tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "611", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "621", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "622", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "623", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "627", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "631", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "632", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "635", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "641", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "642", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "811", tempJournal.AccountId) && !accountingBO.IsRelateAccount(session, "821", tempJournal.AccountId) ) { sumDebit_NotRelativeBussiness += tempJournal.Debit; continue; } //resultTransaction.GeneralJournalList.Add(tempJournal); tmpGeneralJournalList.Add(tempJournal); Account tmpAccount = session.GetObjectByKey <Account>(tempJournal.AccountId); bool flgIsLeafAccount = tmpAccount.Accounts == null || tmpAccount.Accounts.Count == 0 ? true : false; if (flgIsLeafAccount && accountingBO.IsRelateAccount(session, account.AccountId, tempJournal.AccountId)) { Acceptable = true; } } if (!Acceptable) { return(null); } ETL_GeneralJournal masterJournal = tmpGeneralJournalList. Where(j => j.Debit == transaction.Amount || j.Credit == transaction.Amount).FirstOrDefault(); if (masterJournal == null) { return(null); } if (masterJournal.Credit == sumDebit_NotRelativeBussiness && sumDebit_NotRelativeBussiness > 0) { return(null); } else if (masterJournal.Credit > 0) { masterJournal.Credit -= sumDebit_NotRelativeBussiness; } resultTransaction.GeneralJournalList = tmpGeneralJournalList; } catch (Exception ex) { throw ex; } resultTransaction.AccountCode = AccountCode; return(resultTransaction); }
public List <ETL_GeneralJournal> ClearJournalList(Session session, List <ETL_GeneralJournal> journalList, Guid AccountId) { List <ETL_GeneralJournal> result = new List <ETL_GeneralJournal>(); try { char AccountSide = 'N'; char MainAccountSide = 'C'; short DebitCount = 0; short CreditCount = 0; ETLAccountingBO accountingBO = new ETLAccountingBO(); foreach (ETL_GeneralJournal journal in journalList) { if (journal.Credit > 0) { if (accountingBO.IsRelateAccount(session, AccountId, journal.AccountId)) { AccountSide = 'C'; } CreditCount++; } else { if (accountingBO.IsRelateAccount(session, AccountId, journal.AccountId)) { AccountSide = 'D'; } DebitCount++; } } if (DebitCount == 1) { MainAccountSide = 'D'; } if (MainAccountSide == AccountSide) { return(journalList); } ETL_GeneralJournal mainJournal = new ETL_GeneralJournal(); if (MainAccountSide == 'C') { mainJournal = journalList.Where(r => r.Credit > 0).FirstOrDefault(); result.Add(mainJournal); foreach (ETL_GeneralJournal journal in journalList) { if (journal.Debit > 0) { if (!accountingBO.IsRelateAccount(session, AccountId, journal.AccountId)) { mainJournal.Credit -= journal.Debit; } else { result.Add(journal); } } } } if (MainAccountSide == 'D') { mainJournal = journalList.Where(r => r.Debit > 0).FirstOrDefault(); result.Add(mainJournal); foreach (ETL_GeneralJournal journal in journalList) { if (journal.Credit > 0) { if (!accountingBO.IsRelateAccount(session, AccountId, journal.AccountId)) { mainJournal.Debit -= journal.Credit; } else { result.Add(journal); } } } } } catch (Exception) { return(null); } return(result); }
public ETL_FinancialPrepaidExpenseTransaction ExtractTransaction(Session session, Guid TransactionId, string AccountCode) { ETL_FinancialPrepaidExpenseTransaction resultTransaction = null; try { bool Acceptable = false; CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", AccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account account = session.FindObject <Account>(criteria); Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); if (transaction == null) { return(resultTransaction); } resultTransaction = new ETL_FinancialPrepaidExpenseTransaction(); if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); foreach (GeneralJournal journal in transaction.GeneralJournals.Where(i => i.RowStatus == Constant.ROWSTATUS_BOOKED_ENTRY || i.RowStatus == Constant.ROWSTATUS_ACTIVE)) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; } else { tempJournal.AccountId = defaultAccount.AccountId; } tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; resultTransaction.GeneralJournalList.Add(tempJournal); Account tmpAccount = session.GetObjectByKey <Account>(tempJournal.AccountId); bool flgIsLeafAccount = tmpAccount.Accounts == null || tmpAccount.Accounts.Count == 0 ? true : false; if (flgIsLeafAccount && accountingBO.IsRelateAccount(session, account.AccountId, tempJournal.AccountId)) { Acceptable = true; } } if (!Acceptable) { return(null); } } catch (Exception ex) { throw ex; } resultTransaction.AccountCode = AccountCode; return(resultTransaction); }
public ETL_Transaction ExtractTransaction(Session session, Guid TransactionId) { ETL_Transaction resultTransaction = null; try { Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); Util util = new Util(); resultTransaction = new ETL_Transaction(); if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } if (transaction is PaymentVouchesTransaction) { PaymentVoucherTransactionBO paymentVoucherTransactionBO = new PaymentVoucherTransactionBO(); Organization SuppOrg = paymentVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = paymentVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } if (transaction is ReceiptVouchesTransaction) { ReceiptVoucherTransactionBO receiptVoucherTransactionBO = new ReceiptVoucherTransactionBO(); Organization SuppOrg = receiptVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = receiptVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); foreach (GeneralJournal journal in transaction.GeneralJournals) { if (journal.RowStatus >= 1) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; tempJournal.AccountCode = journal.AccountId.Code; tempJournal.AccountName = journal.AccountId.Name; } else { tempJournal.AccountId = defaultAccount.AccountId; tempJournal.AccountCode = defaultAccount.Code; tempJournal.AccountName = defaultAccount.Name; } tempJournal.CreateDate = journal.CreateDate; tempJournal.Debit = journal.Debit; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; tempJournal.CurrencyCode = CurrencyBO.DefaultCurrency(session).Code; tempJournal.CurrencyName = CurrencyBO.DefaultCurrency(session).Name; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; tempJournal.CurrencyCode = journal.CurrencyId.Code; tempJournal.CurrencyName = journal.CurrencyId.Name; } tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; resultTransaction.GeneralJournalList.Add(tempJournal); } } } catch (Exception ex) { throw ex; } return(resultTransaction); }
public ETL_GoodsInInventoryTransaction ExtractTransaction(Session session, Guid TransactionId, string AccountCode) { ETL_GoodsInInventoryTransaction resultTransaction = null; try { bool Acceptable = false; CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", AccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account account = session.FindObject <Account>(criteria); Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); if (transaction == null) { return(resultTransaction); } resultTransaction = new ETL_GoodsInInventoryTransaction(); if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); double numOfItem = 0; InventoryCommand command = null; if (transaction != null) { InventoryJournal inventoryJournal = null; try { inventoryJournal = transaction.InventoryJournalFinancials.FirstOrDefault().InventoryJournalId; numOfItem = inventoryJournal.Debit > 0 ? inventoryJournal.Debit : inventoryJournal.Credit; command = (inventoryJournal.InventoryTransactionId as InventoryCommandItemTransaction).InventoryCommandId; } catch (Exception) { numOfItem = 0; command = null; } } resultTransaction.Quantity = numOfItem; resultTransaction.ArtifactId = command == null ? Guid.Empty : command.InventoryCommandId; if (numOfItem != 0) { resultTransaction.Price = (decimal)resultTransaction.Amount / (decimal)numOfItem; } else { resultTransaction.Price = 0; } foreach (GeneralJournal journal in transaction.GeneralJournals.Where(i => i.RowStatus == Constant.ROWSTATUS_BOOKED_ENTRY || i.RowStatus == Constant.ROWSTATUS_ACTIVE)) { if ((journal.Debit + journal.Credit) == 0) { continue; } ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; } else { tempJournal.AccountId = defaultAccount.AccountId; } tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; resultTransaction.GeneralJournalList.Add(tempJournal); Account tmpAccount = session.GetObjectByKey <Account>(tempJournal.AccountId); bool flgIsLeafAccount = tmpAccount.Accounts == null || tmpAccount.Accounts.Count == 0 ? true : false; if (flgIsLeafAccount && accountingBO.IsRelateAccount(session, account.AccountId, tempJournal.AccountId)) { Acceptable = true; } } if (!Acceptable) { return(null); } } catch (Exception ex) { throw ex; } resultTransaction.AccountCode = AccountCode; return(resultTransaction); }
public ETL_TransactionS04a6DN ExtractTransaction(Session session, Guid TransactionId, string AccountCode) { ETL_TransactionS04a6DN resultTransaction = null; try { bool Acceptable = false; Util util = new Util(); InventoryCommand command = null; NAS.DAL.Invoice.PurchaseInvoice invoice = null; CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", AccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account account = session.FindObject <Account>(criteria); Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); if (transaction == null) { return(resultTransaction); } try { if (transaction is InventoryCommandFinancialTransaction) { command = (((transaction as InventoryCommandFinancialTransaction). InventoryJournalFinancials.FirstOrDefault().InventoryJournalId.InventoryTransactionId) as InventoryCommandItemTransaction).InventoryCommandId; invoice = GetAllocatedPurchaseInvoiceByInventoryCommand(session, command.InventoryCommandId); } else { command = GetAllocatedInputInventoryCommandByManualTransaction(session, transaction.TransactionId); invoice = GetAllocatedPurchaseInvoiceByManualTransaction(session, transaction.TransactionId); } } catch (Exception) { command = null; invoice = null; } if (command == null) { return(null); } if (invoice == null) { return(null); } resultTransaction = new ETL_TransactionS04a6DN(); resultTransaction.InputInventoryCommandId = command.InventoryCommandId; resultTransaction.PurchaseInvoiceId = invoice.BillId; if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } if (resultTransaction.SupplierOrgId == Guid.Empty) { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (resultTransaction.CustomerOrgId == Guid.Empty) { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; double numOfItem = 0; if (transaction != null) { InventoryJournal inventoryJournal = null; try { inventoryJournal = transaction.InventoryJournalFinancials.FirstOrDefault().InventoryJournalId; numOfItem = inventoryJournal.Debit > 0 ? inventoryJournal.Debit : inventoryJournal.Credit; } catch (Exception) { numOfItem = 0; } } resultTransaction.ActualPrice = resultTransaction.Amount / numOfItem; resultTransaction.BookedPrice = resultTransaction.ActualPrice; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); foreach (GeneralJournal journal in transaction.GeneralJournals.Where(i => i.RowStatus == Constant.ROWSTATUS_BOOKED_ENTRY || i.RowStatus == Constant.ROWSTATUS_ACTIVE)) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); /*2014/02/20 Duc.Vo MOD START*/ if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; } else { tempJournal.AccountId = defaultAccount.AccountId; } /*2014/02/20 Duc.Vo MOD END*/ tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; tempJournal.GeneralJournalId = journal.GeneralJournalId; resultTransaction.GeneralJournalList.Add(tempJournal); if (accountingBO.IsRelateAccount(session, account.AccountId, tempJournal.AccountId) && journal.Credit > 0) { Acceptable = true; } } if (!Acceptable) { return(null); } } catch (Exception ex) { throw ex; } return(resultTransaction); }
public ETL_Transaction ExtractTransaction(Session session, Guid TransactionId, string AccountCode) { ETL_Transaction resultTransaction = null; try { bool Acceptable = false; CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria_Code = new BinaryOperator("Code", AccountCode, BinaryOperatorType.Equal); CriteriaOperator criteria = CriteriaOperator.And(criteria_Code, criteria_RowStatus); Account account = session.FindObject <Account>(criteria); /*2014/02/20 Duc.Vo INS START*/ Organization defaultOrg = Organization.GetDefault(session, OrganizationEnum.NAAN_DEFAULT); Organization currentDeployOrg = Organization.GetDefault(session, OrganizationEnum.QUASAPHARCO); Account defaultAccount = Account.GetDefault(session, DefaultAccountEnum.NAAN_DEFAULT); /*2014/02/20 Duc.Vo INS END*/ Transaction transaction = session.GetObjectByKey <Transaction>(TransactionId); //if (transaction == null) //{ // return resultTransaction; //} Util util = new Util(); /*2014/02/20 Duc.Vo MOD START*/ resultTransaction = new ETL_Transaction(); if (currentDeployOrg != null) { resultTransaction.OwnerOrgId = currentDeployOrg.OrganizationId; } else { resultTransaction.OwnerOrgId = defaultOrg.OrganizationId; } if (transaction is SaleInvoiceTransaction) { if ((transaction as SaleInvoiceTransaction).SalesInvoiceId.SourceOrganizationId != null) { resultTransaction.CustomerOrgId = (transaction as SaleInvoiceTransaction).SalesInvoiceId.SourceOrganizationId.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } if (transaction is PurchaseInvoiceTransaction) { if ((transaction as PurchaseInvoiceTransaction).PurchaseInvoiceId.SourceOrganizationId != null) { resultTransaction.SupplierOrgId = (transaction as PurchaseInvoiceTransaction).PurchaseInvoiceId.SourceOrganizationId.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } } if (transaction is PaymentVouchesTransaction) { PaymentVoucherTransactionBO paymentVoucherTransactionBO = new PaymentVoucherTransactionBO(); Organization SuppOrg = paymentVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = paymentVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } if (transaction is ReceiptVouchesTransaction) { ReceiptVoucherTransactionBO receiptVoucherTransactionBO = new ReceiptVoucherTransactionBO(); Organization SuppOrg = receiptVoucherTransactionBO.GetAllocatedSupplier(session, transaction.TransactionId); Organization CustOrg = receiptVoucherTransactionBO.GetAllocatedCustomer(session, transaction.TransactionId); if (SuppOrg != null) { resultTransaction.SupplierOrgId = SuppOrg.OrganizationId; } else { resultTransaction.SupplierOrgId = defaultOrg.OrganizationId; } if (CustOrg != null) { resultTransaction.CustomerOrgId = CustOrg.OrganizationId; } else { resultTransaction.CustomerOrgId = defaultOrg.OrganizationId; } } /*2014/02/20 Duc.Vo MOD END*/ resultTransaction.TransactionId = transaction.TransactionId; resultTransaction.Amount = transaction.Amount; resultTransaction.Code = transaction.Code; resultTransaction.CreateDate = transaction.CreateDate; resultTransaction.Description = transaction.Description; resultTransaction.IsBalanceForward = (transaction is BalanceForwardTransaction); resultTransaction.IssuedDate = transaction.IssueDate; resultTransaction.UpdateDate = transaction.UpdateDate; resultTransaction.GeneralJournalList = new List <ETL_GeneralJournal>(); foreach (GeneralJournal journal in transaction.GeneralJournals) { ETL_GeneralJournal tempJournal = new ETL_GeneralJournal(); if (journal.AccountId != null) { tempJournal.AccountId = journal.AccountId.AccountId; } else { tempJournal.AccountId = defaultAccount.AccountId; } tempJournal.CreateDate = journal.CreateDate; tempJournal.Credit = journal.Credit; if (journal.CurrencyId == null) { tempJournal.CurrencyId = CurrencyBO.DefaultCurrency(session).CurrencyId; } else { tempJournal.CurrencyId = journal.CurrencyId.CurrencyId; } tempJournal.Debit = journal.Debit; tempJournal.Description = journal.Description; tempJournal.GeneralJournalId = journal.GeneralJournalId; tempJournal.JournalType = journal.JournalType; resultTransaction.GeneralJournalList.Add(tempJournal); if (IsRelateAccount(session, account.AccountId, tempJournal.AccountId)) { Acceptable = true; } } if (!Acceptable) { return(null); } } catch (Exception ex) { throw ex; } return(resultTransaction); }