Exemplo n.º 1
0
        public async Task <AdvanceReceivedResult> SaveAsync(IEnumerable <AdvanceReceived> receiveds, CancellationToken token = default(CancellationToken))
        {
            var result = new AdvanceReceivedResult {
                ProcessResult        = new ProcessResult(),
                AdvancedReceiveItems = new List <AdvanceReceived>(),
            };

            using (var scope = transactionScopeBuilder.Create())
            {
                foreach (var item in receiveds)
                {
                    var updateAt = await dbFunctionProcessor.GetDbDateTimeAsync(token);

                    var x = await addReceiptQueryProcessor.AddAdvanceReceivedAsync(item.OriginalReceiptId, item.CustomerId, item.LoginUserId, item.OriginalUpdateAt, updateAt, token);

                    if (x == null)
                    {
                        result.ProcessResult.ErrorCode = Rac.VOne.Common.ErrorCode.OtherUserAlreadyUpdated;
                        return(result);
                    }
                    result.AdvancedReceiveItems.Add(new AdvanceReceived {
                        ReceiptId         = x.Id,
                        OriginalReceiptId = x.OriginalReceiptId.Value,
                        UpdateAt          = x.UpdateAt,
                        ReceiptCategoryId = x.ReceiptCategoryId,
                        LoginUserId       = x.UpdateBy,
                    });
                    await updateReceiptQueryProcessor.UpdateOriginalRemainAsync(item.OriginalReceiptId, item.LoginUserId, updateAt, token);
                }
                result.ProcessResult.Result = true;

                scope.Complete();
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <BillingBalancesResult> SaveAsync(string SessionKey, int CompanyId, DateTime CarryOverAt, int LoginUserId)
        {
            return(await authorizationProcess.DoAuthorizeAsync(SessionKey, async token =>
            {
                var billingBalanceList = new List <BillingBalance>();

                var lastCarryOverAt = await billingBalanceProcessor.GetLastCarryOverAtAsync(CompanyId, token);

                //保存中の繰越データを削除
                await billingBalanceBackProcessor.DeleteAsync(CompanyId, token);

                //前回繰越データの待避
                await billingBalanceBackProcessor.SaveAsync(CompanyId, token);

                //繰越対象得意先を取得
                var billingBalances = (await billingBalanceProcessor.GetBillingBalancesAsync(CompanyId,
                                                                                             lastCarryOverAt, CarryOverAt, token)).ToList();

                var CreateAt = await dbFunctionProcessor.GetDbDateTimeAsync(token);

                //繰越残高を取得
                foreach (BillingBalance billingBalance in billingBalances)
                {
                    //前回繰越残高を取得
                    var lastBillingBalanceResult = (await billingBalanceProcessor.GetLastBillingBalanceAsync(CompanyId,
                                                                                                             billingBalance.CurrencyId, billingBalance.CustomerId, billingBalance.StaffId,
                                                                                                             billingBalance.DepartmentId, token)).ToList();
                    var lastBillingBalance = (lastBillingBalanceResult.Count > 0) ? lastBillingBalanceResult.FirstOrDefault()
                                             .BalanceCarriedOver : 0M;

                    //対象期間内の請求金額取得
                    var billingAmount = await billingBalanceProcessor.GetBillingAmountAsync(CompanyId,
                                                                                            billingBalance.CurrencyId, billingBalance.CustomerId, billingBalance.StaffId,
                                                                                            billingBalance.DepartmentId, CarryOverAt, lastCarryOverAt, token);

                    //対象期間内の消込額取得
                    var receiptAmount = await billingBalanceProcessor.GetReceiptAmountAsync(CompanyId,
                                                                                            billingBalance.CurrencyId, billingBalance.CustomerId, billingBalance.StaffId,
                                                                                            billingBalance.DepartmentId, CarryOverAt, lastCarryOverAt, token);

                    billingBalance.BalanceCarriedOver = lastBillingBalance + billingAmount - receiptAmount;
                    billingBalance.CarryOverAt = CarryOverAt;
                    billingBalance.CreateAt = CreateAt;
                    billingBalance.CreateBy = LoginUserId;
                }

                //前回繰越残高を削除
                await billingBalanceProcessor.DeleteAsync(CompanyId, token);

                //今回繰越残高登録
                foreach (BillingBalance billingBalance in billingBalances)
                {
                    if (billingBalance.BalanceCarriedOver != 0)
                    {
                        var billingBalanceResult = await billingBalanceProcessor.SaveAsync(billingBalance, token);
                        billingBalanceList.Add(billingBalanceResult);
                    }
                }
                return new BillingBalancesResult
                {
                    ProcessResult = new ProcessResult {
                        Result = true
                    },
                    BillingBalances = billingBalanceList
                };
            }, logger));
        }