コード例 #1
0
        public async Task <int> DeleteAsync(BillingDeleteSource source, CancellationToken token = default(CancellationToken))
        {
            var result = 0;
            var app    = await getApplicationControlByCompanyQueryProcessor.GetAsync(source.CompanyId, token);

            using (var scope = transactionScopeBuilder.Create())
            {
                foreach (var id in source.Ids)
                {
                    if (app.RegisterContractInAdvance == 1)
                    {
                        await updateBillingDivisionContractQueryProcessor.UpdateWithBillingIdAsync(id, source.LoginUserId, token);
                    }
                    else
                    {
                        await deleteBillingDivisionContractQueryProcessor.DeleteWithBillingIdAsync(id, token);
                    }

                    if (app.UseDiscount == 1)
                    {
                        await deleteBillingDiscountQueryProcessor.DeleteAsync(id, token);
                    }

                    result += await DeleteInnerAsync(id, token);
                }
                scope.Complete();
            }
            return(result);
        }
コード例 #2
0
 public async Task <int> DeleteAsync(long BillingId, CancellationToken token = default(CancellationToken))
 => await deleteBillingDivisionContractQueryProcessor.DeleteWithBillingIdAsync(BillingId);
コード例 #3
0
ファイル: BillingSaveProcessor.cs プロジェクト: fwka1605/next
        public async Task <IEnumerable <Billing> > SaveItemsAsync(IEnumerable <Billing> billings, CancellationToken token = default(CancellationToken))
        {
            var source = billings.ToArray();
            var result = new List <Billing>();

            using (var scope = transactionScopeBuilder.Create())
            {
                BillingInput billingInput = null;
                var          index        = 0;
                if (source[0].BillingInputId == null && source[0].Id == 0)
                {
                    billingInput = await addBillingInputQueryProcessor.AddAsync(token);
                }

                foreach (var billing in source)
                {
                    if (billingInput != null)
                    {
                        billing.BillingInputId = billingInput.Id;
                    }

                    result.Add(await SaveInnerAsync(billing));

                    if (billing.UseDiscount)
                    {
                        var discounts = (await customerDiscountQueryProcessor.GetAsync(billing.CustomerId, token)).ToList();

                        if (discounts.Count > 0)
                        {
                            var discount  = new BillingDiscount();
                            var billingId = result[index].Id;
                            discount.BillingId = billingId;
                            await deleteBillingDiscountQueryProcessor.DeleteAsync(billingId, token);

                            for (var i = 0; i < discounts.Count; i++)
                            {
                                var customerDiscount = discounts[i];
                                discount.DiscountType   = customerDiscount.Sequence;
                                discount.DiscountAmount = customerDiscount.GetRoundingValue(billing.BillingAmount, billing.CurrencyPrecision);
                                await addBillingDiscountQueryProcessor.SaveAsync(discount, token);
                            }
                        }
                    }
                    else if (!billing.UseDiscount && billing.BillingDiscountId != null)
                    {
                        var billingId = result[index].Id;
                        await deleteBillingDiscountQueryProcessor.DeleteAsync(billingId, token);
                    }

                    /* query から見直し updateBilling の 修正が必要 */
                    var contract = new BillingDivisionContract();
                    contract.BillingId      = result[index].Id;
                    contract.CreateBy       = billing.CreateBy;
                    contract.UpdateBy       = billing.UpdateBy;
                    contract.CompanyId      = billing.CompanyId;
                    contract.CustomerId     = billing.CustomerId;
                    contract.ContractNumber = billing.ContractNumber;

                    if (billing.BillingDivisionContract == 1)
                    {
                        await updateBillingDivisionContractQueryProcessor.UpdateBillingAsync(contract, token);
                    }
                    else if (billing.BillingDivisionContract == 2)
                    {
                        await deleteBillingDivisionContractQueryProcessor.DeleteWithBillingIdAsync(billing.Id, token);
                    }
                    else if (billing.BillingDivisionContract == 3)
                    {
                        var newContractNo = await billingDivisionContractQueryProcessor.GetNewContractNumberAsync(contract.CompanyId, token);

                        contract.ContractNumber = newContractNo.ToString();
                        var setting = await billingDivisionSettingQueryProcessor.GetAsync(billing.CompanyId, token);

                        contract.FirstDateType        = setting.FirstDateType;
                        contract.Monthly              = setting.Monthly;
                        contract.BasisDay             = setting.BasisDay;
                        contract.DivisionCount        = setting.DivisionCount;
                        contract.RoundingMode         = setting.RoundingMode;
                        contract.RemainsApportionment = setting.RemainsApportionment;
                        contract.Comfirm              = 0;
                        contract.CancelDate           = null;
                        await addBillingDivisionContractQueryProcessor.SaveAsync(contract, token);
                    }
                    index++;
                }
                scope.Complete();
            }
            return(result);
        }