Exemplo n.º 1
0
        public void FixInvokedBussinessObjects(Session session, XPCollection <DAL.System.Log.BusinessObject> invokedBussinessObjects)
        {
            if (invokedBussinessObjects == null || invokedBussinessObjects.Count == 0)
            {
                return;
            }

            CriteriaOperator criteria_0 = CriteriaOperator.Parse("not(IsNull(FinancialTransactionDimId))");
            CriteriaOperator criteria_1 = new InOperator("FinancialTransactionDimId.RefId", invokedBussinessObjects.Select(i => i.RefId));
            CriteriaOperator criteria_2 = new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater);
            CriteriaOperator criteria   = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1, criteria_2);
            CorrespondFinancialAccountDim defaultAccDim = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);

            XPCollection <FinancialCustomerLiabilityDetail> neededToBeFixList = new XPCollection <FinancialCustomerLiabilityDetail>(session, criteria);
            FinancialCustomerLiabilitySummary_Fact          fact = null;

            if (neededToBeFixList != null && neededToBeFixList.Count > 0)
            {
                foreach (FinancialCustomerLiabilityDetail detail in neededToBeFixList)
                {
                    fact             = detail.FinancialCustomerLiabilitySummary_FactId;
                    detail.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                    detail.Save();
                    if (defaultAccDim != null && detail.CorrespondFinancialAccountDimId != null &&
                        detail.CorrespondFinancialAccountDimId.Code.Equals(defaultAccDim.Code))
                    {
                        fact.CreditSum -= detail.Credit;
                        fact.DebitSum  -= detail.Debit;
                    }

                    fact.EndCreditBalance
                        = fact.BeginCreditBalance +
                          fact.CreditSum -
                          fact.DebitSum;

                    fact.EndDebitBalance
                        = fact.BeginDebitBalance +
                          fact.DebitSum -
                          fact.CreditSum;

                    fact.Save();
                }
            }
        }
Exemplo n.º 2
0
        public FinancialCustomerLiabilitySummary_Fact CreateFinnancialCustomerLiabilitySummaryFact(Session session,
                                                                                                   Guid OwnerOrgId,
                                                                                                   Guid CustomerOrgId,
                                                                                                   DateTime IssueDate,
                                                                                                   string FinancialAccountCode,
                                                                                                   bool IsBalanceForward)
        {
            FinancialCustomerLiabilitySummary_Fact result = new FinancialCustomerLiabilitySummary_Fact(session);

            try
            {
                ETLAccountingBO accountingBO = new ETLAccountingBO();
                DimBO           dimBO        = new DimBO();
                result.BeginCreditBalance    = 0;
                result.BeginDebitBalance     = 0;
                result.CreditSum             = 0;
                result.DebitSum              = 0;
                result.EndCreditBalance      = 0;
                result.EndDebitBalance       = 0;
                result.FinancialAccountDimId = accountingBO.GetFinancialAccountDim(session, FinancialAccountCode);
                result.MonthDimId            = dimBO.GetMonthDim(session, (short)IssueDate.Month);
                result.YearDimId             = dimBO.GetYearDim(session, (short)IssueDate.Year);
                result.OwnerOrgDimId         = dimBO.GetOwnerOrgDim(session, OwnerOrgId);
                result.RowStatus             = Constant.ROWSTATUS_ACTIVE;
                result.CustomerOrgDimId      = dimBO.GetCustomerOrgDim(session, CustomerOrgId);
                if (result.FinancialAccountDimId == null || result.MonthDimId == null || result.YearDimId == null || result.OwnerOrgDimId == null || result.CustomerOrgDimId == null)
                {
                    return(null);
                }
                result.Save();
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public void CreateFinancialCustomerLiabilityDetail(
            Session session,
            ETL_FinnancialCustomerLiabilityDetail Detail,
            string MainAccountCode)
        {
            try
            {
                Util util = new Util();
                CorrespondFinancialAccountDim defaultCorrespondindAcc = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);
                FinancialAccountDim           defaultFinancialAcc     = FinancialAccountDim.GetDefault(session, FinancialAccountDimEnum.NAAN_DEFAULT);
                ETLAccountingBO accountingBO = new ETLAccountingBO();
                FinancialCustomerLiabilitySummary_Fact Fact      = GetFinnancialCustomerLiabilitySummaryFact(session, Detail.OwnerOrgId, Detail.CustomerOrgId, Detail.IssueDate, MainAccountCode);
                FinancialCustomerLiabilityDetail       newDetail = new FinancialCustomerLiabilityDetail(session);
                if (Fact == null)
                {
                    Fact = CreateFinnancialCustomerLiabilitySummaryFact(session, Detail.OwnerOrgId, Detail.CustomerOrgId, Detail.IssueDate, MainAccountCode, Detail.IsBalanceForward);
                    if (Fact == null)
                    {
                        return;
                    }
                }

                var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1);
                FinancialCustomerLiabilitySummary_Fact previousSummary = GetFinnancialCustomerLiabilitySummaryFact(session,
                                                                                                                   Detail.OwnerOrgId, Detail.CustomerOrgId, date.AddMonths(-1), MainAccountCode);

                if (previousSummary != null)
                {
                    Fact.BeginCreditBalance = previousSummary.EndCreditBalance;
                    Fact.BeginDebitBalance  = previousSummary.EndDebitBalance;
                }

                /*2014/02/22 Duc.Vo MOD START*/
                CorrespondFinancialAccountDim correspondFinancialAccountDim = null;
                FinancialAccountDim           financialAccountDim           = null;

                if (!Detail.CorrespondAccountCode.Equals(string.Empty))
                {
                    correspondFinancialAccountDim = util.GetXpoObjectByFieldName <CorrespondFinancialAccountDim, string>(session, "Code", Detail.CorrespondAccountCode, BinaryOperatorType.Equal);
                }
                if (!MainAccountCode.Equals(string.Empty))
                {
                    financialAccountDim = util.GetXpoObjectByFieldName <FinancialAccountDim, string>(session, "Code", MainAccountCode, BinaryOperatorType.Equal);
                }
                /*2014/02/22 Duc.Vo MOD END*/

                FinancialTransactionDim financialTransactionDim = util.GetXpoObjectByFieldName <FinancialTransactionDim, Guid>(session, "RefId", Detail.TransactionId, BinaryOperatorType.Equal);

                CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>(session, "Code", Detail.CurrencyCode, BinaryOperatorType.Equal);
                if (financialTransactionDim == null)
                {
                    financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, Detail.TransactionId);
                    if (financialTransactionDim == null)
                    {
                        return;
                    }
                }

                /*2014/02/22 Duc.Vo INS START*/
                if (financialAccountDim == null && !MainAccountCode.Equals(string.Empty))
                {
                    financialAccountDim = accountingBO.CreateFinancialAccountDim(session, MainAccountCode);
                }
                if (correspondFinancialAccountDim == null && !Detail.CorrespondAccountCode.Equals(string.Empty))
                {
                    correspondFinancialAccountDim = accountingBO.CreateCorrespondFinancialAccountDim(session, Detail.CorrespondAccountCode);
                }

                if (currencyDim == null && !Detail.CurrencyCode.Equals(string.Empty))
                {
                    currencyDim = accountingBO.CreateCurrencyDim(session, Detail.CurrencyCode);
                }

                newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim;
                newDetail.Credit                = Detail.Credit;
                newDetail.Debit                 = Detail.Debit;
                newDetail.CurrencyDimId         = currencyDim;
                newDetail.FinancialAccountDimId = financialAccountDim;
                newDetail.FinancialCustomerLiabilitySummary_FactId = Fact;
                newDetail.FinancialTransactionDimId = financialTransactionDim;

                /*2014-02-22 ERP-1417 Duc.Vo INS START*/


                if (newDetail.FinancialAccountDimId == null)
                {
                    newDetail.FinancialAccountDimId = defaultFinancialAcc;
                }
                if (newDetail.CorrespondFinancialAccountDimId == null)
                {
                    newDetail.CorrespondFinancialAccountDimId = defaultCorrespondindAcc;
                }
                /*2014-02-22 ERP-1417 Duc.Vo INS END*/

                newDetail.RowStatus = Constant.ROWSTATUS_ACTIVE;
                newDetail.Save();

                if (Detail.IsBalanceForward)
                {
                    Fact.BeginCreditBalance = Fact.EndCreditBalance = Detail.Credit;
                    Fact.BeginDebitBalance  = Fact.EndDebitBalance = Detail.Debit;
                    Fact.CreditSum          = 0;
                    Fact.DebitSum           = 0;
                }
                else
                {
                    Fact.CreditSum = Fact.FinancialCustomerLiabilityDetails.Where(i => i.RowStatus == 1 &&
                                                                                  i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Credit);

                    Fact.DebitSum = Fact.FinancialCustomerLiabilityDetails.Where(i => i.RowStatus == 1 &&
                                                                                 i.Debit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(d => d.Debit);

                    Fact.EndCreditBalance = Fact.BeginCreditBalance + Fact.CreditSum - Fact.DebitSum;
                    Fact.EndDebitBalance  = Fact.BeginDebitBalance + Fact.DebitSum - Fact.CreditSum;
                }
                Fact.Save();
            }
            catch (Exception)
            {
                return;
            }
        }