예제 #1
0
        public FinancialOnTheWayBuyingGoodSummary CreateFinancialOnTheWayBuyingGoodSummary(Session session,
                                                                                           Guid OwnerOrgId,
                                                                                           DateTime IssueDate,
                                                                                           string FinancialAccountCode)
        {
            FinancialOnTheWayBuyingGoodSummary result = new FinancialOnTheWayBuyingGoodSummary(session);

            try
            {
                ETLAccountingBO     accountingBO = new ETLAccountingBO();
                FinancialAccountDim accountDim   = accountingBO.GetFinancialAccountDim(session, FinancialAccountCode);
                DimBO       dimBO     = new DimBO();
                MonthDim    monthDim  = dimBO.GetMonthDim(session, (short)IssueDate.Month);
                YearDim     yearDim   = dimBO.GetYearDim(session, (short)IssueDate.Year);
                OwnerOrgDim ownOrgDim = dimBO.GetOwnerOrgDim(session, OwnerOrgId);
                result.BeginBalance          = 0;
                result.FinancialAccountDimId = accountDim != null ? accountDim : accountingBO.CreateFinancialAccountDim(session, FinancialAccountCode);
                result.MonthDimId            = monthDim != null ? monthDim : dimBO.CreateMonthDim(session, (short)IssueDate.Month);
                result.YearDimId             = yearDim != null ? yearDim : dimBO.CreateYearDim(session, (short)IssueDate.Year);
                result.OwnerOrgDimId         = ownOrgDim != null ? ownOrgDim : dimBO.CreateOwnerOrgDim(session, OwnerOrgId);
                result.RowStatus             = Constant.ROWSTATUS_ACTIVE;
                if (result.FinancialAccountDimId == null || result.MonthDimId == null || result.YearDimId == null || result.OwnerOrgDimId == null)
                {
                    return(null);
                }
                var date = new DateTime(IssueDate.Year, IssueDate.Month, 1);
                FinancialOnTheWayBuyingGoodSummary previousSummary = GetFinancialOnTheWayBuyingGoodSummary(session,
                                                                                                           OwnerOrgId, date.AddMonths(-1), FinancialAccountCode);

                if (previousSummary != null)
                {
                    result.BeginBalance = previousSummary.EndBalance;
                }
                result.Save();
                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #2
0
        public void CreateFinancialOnTheWayBuyingGoodDetail(Session session, ETL_FinancialOnTheWayBuyingGoodDetail Detail, string MainAccountCode)
        {
            try
            {
                if (Detail == null ||
                    MainAccountCode.Equals(string.Empty) ||
                    Detail.PurchaseInvoiceId.Equals(Guid.Empty) ||
                    Detail.InputInventoryCommandId.Equals(Guid.Empty) ||
                    Detail.OwnerOrgId.Equals(Guid.Empty) ||
                    Detail.IssueDate == null)
                {
                    return;
                }

                //bool flgNewSummary = false;
                Util util = new Util();
                CorrespondFinancialAccountDim defaultCorrespondindAcc = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);
                FinancialAccountDim           defaultFinancialAcc     = FinancialAccountDim.GetDefault(session, FinancialAccountDimEnum.NAAN_DEFAULT);
                ETLAccountingBO accountingBO = new ETLAccountingBO();
                FinancialOnTheWayBuyingGoodSummary summary   = GetFinancialOnTheWayBuyingGoodSummary(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode);
                FinancialOnTheWayBuyingGoodDetail  newDetail = new FinancialOnTheWayBuyingGoodDetail(session);
                if (summary == null)
                {
                    summary = CreateFinancialOnTheWayBuyingGoodSummary(session, Detail.OwnerOrgId, Detail.IssueDate, MainAccountCode);
                    if (summary == null)
                    {
                        return;
                    }
                }
                else
                {
                    var date = new DateTime(Detail.IssueDate.Year, Detail.IssueDate.Month, 1);
                    FinancialOnTheWayBuyingGoodSummary previousSummary = GetFinancialOnTheWayBuyingGoodSummary(session,
                                                                                                               Detail.OwnerOrgId, date.AddMonths(-1), MainAccountCode);

                    if (previousSummary != null)
                    {
                        summary.BeginBalance = previousSummary.EndBalance;
                    }
                }
                /*2014/02/22 Duc.Vo MOD START*/
                CorrespondFinancialAccountDim correspondFinancialAccountDim = null;
                FinancialAccountDim           financialAccountDim           = null;
                InventoryCommand InputCommand = null;
                NAS.DAL.Invoice.PurchaseInvoice PurchaseInvoice = 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);
                }

                if (!Detail.InputInventoryCommandId.Equals(Guid.Empty))
                {
                    InputCommand = util.GetXpoObjectByFieldName <InventoryCommand, Guid>(session, "InventoryCommandId", Detail.InputInventoryCommandId, BinaryOperatorType.Equal);
                    if (InputCommand == null)
                    {
                        return;
                    }
                }
                if (!Detail.PurchaseInvoiceId.Equals(Guid.Empty))
                {
                    PurchaseInvoice = util.GetXpoObjectByFieldName <NAS.DAL.Invoice.PurchaseInvoice, Guid>(session, "BillId", Detail.PurchaseInvoiceId, BinaryOperatorType.Equal);
                    if (PurchaseInvoice == null)
                    {
                        return;
                    }
                }

                OnTheWayBuyingGoodArtifact artifact = GetOnTheWayBuyingGoodArtifact(
                    session,
                    summary.FinancialOnTheWayBuyingGoodSummaryId,
                    PurchaseInvoice.BillId,
                    InputCommand.InventoryCommandId);

                if (artifact == null)
                {
                    artifact = CreateOnTheWayBuyingGoodArtifact(
                        session,
                        summary.FinancialOnTheWayBuyingGoodSummaryId,
                        PurchaseInvoice.BillId,
                        InputCommand.InventoryCommandId);

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

                CurrencyDim currencyDim = util.GetXpoObjectByFieldName <CurrencyDim, string>(
                    session,
                    "Code",
                    Detail.CurrencyCode,
                    BinaryOperatorType.Equal);

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

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

                if (financialTransactionDim == null)
                {
                    financialTransactionDim = accountingBO.CreateFinancialTransactionDim(session, Detail.TransactionId);
                    if (financialTransactionDim == null)
                    {
                        return;
                    }
                }

                newDetail.CorrespondFinancialAccountDimId = correspondFinancialAccountDim;
                newDetail.Credit                       = Detail.Credit;
                newDetail.Debit                        = Detail.Debit;
                newDetail.ActuaPrice                   = Detail.ActualPrice;
                newDetail.BookingPrice                 = Detail.BookedPrice;
                newDetail.FinancialAccountDimId        = financialAccountDim;
                newDetail.OnTheWayBuyingGoodArtifactId = artifact;
                newDetail.FinancialTransactionDimId    = financialTransactionDim;
                newDetail.CurrencyDimId                = currencyDim;
                /*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)
                {
                    summary.BeginBalance = summary.EndBalance = (decimal)Detail.Debit;
                    summary.CreditSum    = summary.DebitSum = 0;
                }
                else
                {
                    CorrespondFinancialAccountDim defaultAccDim = CorrespondFinancialAccountDim.GetDefault(session, CorrespondFinancialAccountDimEnum.NAAN_DEFAULT);
                    summary.CreditSum = (decimal)summary.OnTheWayBuyingGoodArtifacts.SelectMany(t => t.FinancialOnTheWayBuyingGoodDetails).
                                        Where(i => i.RowStatus == 1 &&
                                              i.Credit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(i => i.Credit);

                    summary.DebitSum = (decimal)summary.OnTheWayBuyingGoodArtifacts.SelectMany(t => t.FinancialOnTheWayBuyingGoodDetails).
                                       Where(i => i.RowStatus == 1 &&
                                             i.Debit > 0 && i.CorrespondFinancialAccountDimId == defaultCorrespondindAcc).Sum(i => i.Debit);

                    summary.BeginBalance = summary.BeginBalance + summary.DebitSum - summary.CreditSum;
                }

                summary.Save();
            }
            catch (Exception)
            {
                return;
            }
        }