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