Ejemplo n.º 1
0
        public List <DJ_Fact> TransformToDiaryJournal(Session session, ETL_Transaction transaction)
        {
            List <DJ_Fact> result = null;

            try
            {
                List <ETL_GeneralJournal> CreditJournalList = new List <ETL_GeneralJournal>();
                List <ETL_GeneralJournal> DebitJournalList  = new List <ETL_GeneralJournal>();
                int    Credit_Count = 0;
                int    Debit_Count  = 0;
                string month        = transaction.IssuedDate.Month.ToString();
                string year         = transaction.IssuedDate.Year.ToString();
                Util   util         = new Util();
                //if (!Util.IsExistXpoObject<MonthDim>(session, "Name", month, BinaryOperatorType.Equal))
                //{
                //    MonthDim newMonthDim = new MonthDim(session);
                //    newMonthDim.Description = month;
                //    newMonthDim.Name = month;
                //    newMonthDim.RowStatus = Constant.ROWSTATUS_ACTIVE;
                //    newMonthDim.Save();
                //}

                //if (!Util.IsExistXpoObject<YearDim>(session, "Name", year, BinaryOperatorType.Equal))
                //{
                //    YearDim newYearDim = new YearDim(session);
                //    newYearDim.Description = year;
                //    newYearDim.Name = year;
                //    newYearDim.RowStatus = Constant.ROWSTATUS_ACTIVE;
                //    newYearDim.Save();
                //}

                //if (!Util.IsExistXpoObject<OwnerOrgDim>(session, "Name", "QUASAPHARCO", BinaryOperatorType.Equal))
                //{
                //    OwnerOrgDim newOwnerOrgDim = new OwnerOrgDim(session);
                //    newOwnerOrgDim.Description = "QUASAPHARCO";
                //    newOwnerOrgDim.Name = "QUASAPHARCO";
                //    newOwnerOrgDim.RowStatus = Constant.ROWSTATUS_ACTIVE;
                //    //Vuong miss GUID
                //    newOwnerOrgDim.Save();
                //}

                string mode = "";
                foreach (ETL_GeneralJournal journal in transaction.GeneralJournalList)
                {
                    Account account = session.GetObjectByKey <Account>(journal.AccountId);
                    if (account != null)
                    {
                        //if (!Util.IsExistXpoObject<FinancialAccountDim>(session, "Code", account.Code, BinaryOperatorType.Equal))
                        //{
                        //    FinancialAccountDim _FinancialAccountDim = new FinancialAccountDim(session);
                        //    _FinancialAccountDim.Code = account.Code;
                        //    _FinancialAccountDim.Description = account.Description;
                        //    _FinancialAccountDim.RowStatus = Constant.ROWSTATUS_ACTIVE;
                        //    _FinancialAccountDim.Save();
                        //}

                        //if (!Util.IsExistXpoObject<CorrespondFinancialAccountDim>(session, "Code", account.Code, BinaryOperatorType.Equal))
                        //{
                        //    CorrespondFinancialAccountDim _CorrespondFinancialAccountDim = new CorrespondFinancialAccountDim(session);
                        //    _CorrespondFinancialAccountDim.Code = account.Code;
                        //    _CorrespondFinancialAccountDim.Description = account.Description;
                        //    _CorrespondFinancialAccountDim.RowStatus = Constant.ROWSTATUS_ACTIVE;
                        //    _CorrespondFinancialAccountDim.Save();
                        //}

                        if (journal.Credit == 0)
                        {
                            DebitJournalList.Add(journal);
                            Debit_Count++;
                        }
                        else
                        {
                            CreditJournalList.Add(journal);
                            Credit_Count++;
                        }
                    }
                }
                Debit_Count  = Debit_Count > 2 ? 2 : Debit_Count;
                Credit_Count = Credit_Count > 2 ? 2 : Credit_Count;
                mode         = Credit_Count.ToString() + Debit_Count.ToString();
                result       = new List <DJ_Fact>();
                switch (mode) //[Credit][Debit]
                {
                case "00":    //Error
                {
                    return(null);
                }

                case "01":
                case "10":    //BalanceForwardTransaction
                {
                    foreach (ETL_GeneralJournal journal in transaction.GeneralJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.BeginCredit      = (Decimal)journal.Credit;
                        DiaryJournalFact.BeginDebit       = (Decimal)journal.Debit;
                        DiaryJournalFact.CreditSum        = 0;
                        DiaryJournalFact.DebitSum         = 0;
                        DiaryJournalFact.EndCredit        = 0;
                        DiaryJournalFact.EndDebit         = 0;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = true;
                        result.Add(DiaryJournalFact);
                    }
                    break;
                }

                case "11":
                {
                    foreach (ETL_GeneralJournal journal in DebitJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = 0;
                        DiaryJournalFact.DebitSum         = (Decimal)journal.Debit;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in CreditJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = (Decimal)journal_dt.Credit;
                            detail.Debit          = 0;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }

                    foreach (ETL_GeneralJournal journal in CreditJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = (Decimal)journal.Credit;
                        DiaryJournalFact.DebitSum         = 0;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in DebitJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = 0;
                            detail.Debit          = (Decimal)journal_dt.Debit;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }
                    break;
                }

                case "12":    //1 Credit - n Debit
                {
                    foreach (ETL_GeneralJournal journal in CreditJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = (Decimal)journal.Credit;
                        DiaryJournalFact.DebitSum         = 0;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in DebitJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = 0;
                            detail.Debit          = (Decimal)journal_dt.Debit;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }

                    foreach (ETL_GeneralJournal journal in DebitJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = 0;
                        DiaryJournalFact.DebitSum         = (Decimal)journal.Debit;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in CreditJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = (Decimal)journal.Debit;
                            detail.Debit          = 0;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }
                    break;
                }

                case "21":    //n Credit - 1 Debit
                {
                    foreach (ETL_GeneralJournal journal in CreditJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = (Decimal)journal.Credit;
                        DiaryJournalFact.DebitSum         = 0;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in DebitJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = 0;
                            detail.Debit          = (Decimal)journal.Credit;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }

                    foreach (ETL_GeneralJournal journal in DebitJournalList)
                    {
                        DJ_Fact DiaryJournalFact = new DJ_Fact();
                        DiaryJournalFact.CreditSum        = 0;
                        DiaryJournalFact.DebitSum         = (Decimal)journal.Debit;
                        DiaryJournalFact.MainAccountDim   = journal.AccountId;
                        DiaryJournalFact.Month            = month;
                        DiaryJournalFact.Year             = year;
                        DiaryJournalFact.OwnerOrg         = transaction.OwnerOrgId;
                        DiaryJournalFact.IsBalanceForward = false;
                        DiaryJournalFact.DetailList       = new List <DJ_Detail>();
                        foreach (ETL_GeneralJournal journal_dt in CreditJournalList)
                        {
                            DJ_Detail detail = new DJ_Detail();
                            detail.AccountDim     = journal_dt.AccountId;
                            detail.Credit         = (Decimal)journal_dt.Credit;
                            detail.Debit          = 0;
                            detail.TransactionDim = transaction.TransactionId;
                            DiaryJournalFact.DetailList.Add(detail);
                        }
                        result.Add(DiaryJournalFact);
                    }
                    break;
                }
                }
            }
            catch (Exception)
            {
            }
            return(result);
        }
Ejemplo n.º 2
0
        protected ETL_FinancialPrepaidExpenseTransformData TransformTransaction
        (
            Session session,
            ETL_FinancialPrepaidExpenseTransaction transaction,
            string AccountCode)
        {
            Util util = new Util();
            ETL_FinancialPrepaidExpenseTransformData result = new ETL_FinancialPrepaidExpenseTransformData();
            Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal);

            if (account == null)
            {
                return(null);
            }
            if (transaction == null)
            {
                return(null);
            }
            ETL_Transaction etlTransaction = transaction;

            string subMainAccount = string.Empty;

            List <ETL_FinancialPrepaidExpenseDetail> detail = new List <ETL_FinancialPrepaidExpenseDetail>();

            try
            {
                ETLAccountingBO           accountingBO      = new ETLAccountingBO();
                FinancialLiabilityBO      liabilityBO       = new FinancialLiabilityBO();
                List <ETL_GeneralJournal> JournalListJoined = JoinJournal(session, etlTransaction.GeneralJournalList);
                List <ETL_GeneralJournal> FinishJournalList = liabilityBO.ClearJournalList(session, JournalListJoined, account.AccountId);
                foreach (ETL_GeneralJournal journal in FinishJournalList)
                {
                    ETL_FinancialPrepaidExpenseDetail temp = new ETL_FinancialPrepaidExpenseDetail();
                    temp.AccountCode           = string.Empty;
                    temp.CorrespondAccountCode = string.Empty;
                    if (accountingBO.IsRelateAccount(session, account.AccountId, journal.AccountId))
                    {
                        temp.AccountCode = subMainAccount = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    else
                    {
                        temp.CorrespondAccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    temp.CurrencyCode     = session.GetObjectByKey <Currency>(journal.CurrencyId).Code;
                    temp.IsBalanceForward = etlTransaction.IsBalanceForward;
                    temp.IssueDate        = etlTransaction.IssuedDate;
                    temp.OwnerOrgId       = etlTransaction.OwnerOrgId;
                    temp.TransactionId    = etlTransaction.TransactionId;
                    temp.Credit           = (decimal)journal.Credit;
                    temp.Debit            = (decimal)journal.Debit;
                    detail.Add(temp);
                }

                result.MainAccountCode = subMainAccount;
                result.ETL_DetailList  = detail;
            }
            catch (Exception)
            {
                return(null);
            }
            return(result);
        }
Ejemplo n.º 3
0
        //public bool IsExistInJournalList(Session session,List<ETL_GeneralJournal> journalList, string AccountCode)
        //{
        //    ETLAccountingBO accountingBO = new ETLAccountingBO();
        //    if (journalList == null) return false;
        //    if (journalList.Count == 0) return false;
        //    bool result = false;
        //    try
        //    {
        //        Util util = new Util();
        //        Account account = util.GetXpoObjectByFieldName<Account, string>(session, "Code",AccountCode,BinaryOperatorType.Equal);
        //        if(account == null) return false;
        //        foreach (ETL_GeneralJournal journal in journalList)
        //        {
        //            if (accountingBO.IsRelateAccount(session, journal.AccountId, account.AccountId))
        //            {
        //                return true;
        //            }
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        return false;
        //    }
        //    return result;
        //}
        //public bool IsExistInJournalList(Session session, List<ETL_GeneralJournal> journalList, Guid AccountId)
        //{
        //    bool result = false;
        //    try
        //    {
        //        Account account = session.GetObjectByKey<Account>(AccountId);
        //        if (account == null) return false;
        //        return IsExistInJournalList(session, journalList, account.Code);
        //    }
        //    catch (Exception)
        //    {
        //        return false;
        //    }
        //    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;
        //}
        //public 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;
        //    }
        //    return result;
        //}

        //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 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);
        //                    }
        //                }
        //            }
        //        }
        //        return result;
        //    }
        //    catch (Exception)
        //    {
        //        return null;
        //    }
        //    return result;
        //}

        public List <ETL_FinnancialSupplierLiabilityDetail> TransformTransactionToSupplierLiabilityDetail(Session session, ETL_Transaction transaction, string AccountCode)
        {
            Util    util    = new Util();
            Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal);

            if (account == null)
            {
                return(null);
            }
            if (transaction == null)
            {
                return(null);
            }
            ETL_Transaction etlTransaction = transaction;

            List <ETL_FinnancialSupplierLiabilityDetail> detail = new List <ETL_FinnancialSupplierLiabilityDetail>();

            try
            {
                ETLAccountingBO           accountingBO      = new ETLAccountingBO();
                List <ETL_GeneralJournal> JournalListJoined = JoinJournal(session, etlTransaction.GeneralJournalList);
                List <ETL_GeneralJournal> FinishJournalList = ClearJournalList(session, JournalListJoined, account.AccountId);
                foreach (ETL_GeneralJournal journal in FinishJournalList)
                {
                    ETL_FinnancialSupplierLiabilityDetail temp = new ETL_FinnancialSupplierLiabilityDetail();
                    temp.AccountCode           = "";
                    temp.CorrespondAccountCode = "";
                    if (accountingBO.IsRelateAccount(session, account.AccountId, journal.AccountId))
                    {
                        temp.AccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    else
                    {
                        temp.CorrespondAccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    temp.CurrencyCode     = session.GetObjectByKey <Currency>(journal.CurrencyId).Code;
                    temp.IsBalanceForward = etlTransaction.IsBalanceForward;
                    temp.IssueDate        = etlTransaction.IssuedDate;
                    temp.OwnerOrgId       = etlTransaction.OwnerOrgId;
                    temp.SupplierId       = etlTransaction.SupplierOrgId;
                    temp.TransactionId    = etlTransaction.TransactionId;
                    temp.Credit           = (decimal)journal.Credit;
                    temp.Debit            = (decimal)journal.Debit;
                    detail.Add(temp);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(detail);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public List <ETL_FinancialOnTheWayBuyingGoodDetail> TransformTransactionOnTheWayBuyingGoodDetail(Session session, ETL_Transaction transaction, string AccountCode)
        {
            Util    util    = new Util();
            Account account = util.GetXpoObjectByFieldName <Account, string>(session, "Code", AccountCode, BinaryOperatorType.Equal);

            if (account == null)
            {
                return(null);
            }
            if (transaction == null)
            {
                return(null);
            }
            ETL_Transaction etlTransaction = transaction;
            List <ETL_FinancialOnTheWayBuyingGoodDetail> detailList = new List <ETL_FinancialOnTheWayBuyingGoodDetail>();

            try
            {
                ETLAccountingBO      accountingBO          = new ETLAccountingBO();
                FinancialLiabilityBO liabilityBO           = new FinancialLiabilityBO();
                ETL_FinancialOnTheWayBuyingGoodDetail temp = null;
                List <ETL_GeneralJournal>             JournalListJoined = liabilityBO.JoinJournal(session, etlTransaction.GeneralJournalList);
                List <ETL_GeneralJournal>             FinishJournalList = liabilityBO.ClearJournalList(session, JournalListJoined, account.AccountId);
                foreach (ETL_GeneralJournal journal in JournalListJoined)
                {
                    temp                       = new ETL_FinancialOnTheWayBuyingGoodDetail();
                    temp.AccountCode           = "";
                    temp.CorrespondAccountCode = "";
                    if (accountingBO.IsRelateAccount(session, account.AccountId, journal.AccountId))
                    {
                        temp.AccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    else
                    {
                        temp.CorrespondAccountCode = session.GetObjectByKey <Account>(journal.AccountId).Code;
                    }
                    temp.ActualPrice             = (transaction as ETL_TransactionS04a6DN).ActualPrice;
                    temp.BookedPrice             = (transaction as ETL_TransactionS04a6DN).BookedPrice;
                    temp.IssueDate               = etlTransaction.IssuedDate;
                    temp.OwnerOrgId              = etlTransaction.OwnerOrgId;
                    temp.TransactionId           = etlTransaction.TransactionId;
                    temp.Credit                  = journal.Credit;
                    temp.Debit                   = journal.Debit;
                    temp.Credit                  = journal.Credit;
                    temp.Debit                   = journal.Debit;
                    temp.CurrencyCode            = session.GetObjectByKey <Currency>(journal.CurrencyId).Code;
                    temp.TransactionId           = etlTransaction.TransactionId;
                    temp.IsBalanceForward        = etlTransaction.IsBalanceForward;
                    temp.PurchaseInvoiceId       = (transaction as ETL_TransactionS04a6DN).PurchaseInvoiceId;
                    temp.InputInventoryCommandId = (transaction as ETL_TransactionS04a6DN).InputInventoryCommandId;
                    detailList.Add(temp);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(detailList);
        }
Ejemplo n.º 6
0
        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);
        }