Esempio n. 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);
        }
Esempio n. 2
0
        public async Task <int> SaveAsync(BillingDiscount discount, CancellationToken token = default(CancellationToken))
        {
            var result = 0;

            using (var scope = transactionScopeBuilder.Create())
            {
                await deleteBillingDiscountQueryProcessor.DeleteAsync(discount.BillingId);

                if (discount.DiscountAmount1 != 0)
                {
                    discount.DiscountAmount = discount.DiscountAmount1;
                    discount.DiscountType   = 1;
                    result += await addBillingDiscountQueryProcessor.SaveAsync(discount);
                }

                if (discount.DiscountAmount2 != 0)
                {
                    discount.DiscountAmount = discount.DiscountAmount2;
                    discount.DiscountType   = 2;
                    result += await addBillingDiscountQueryProcessor.SaveAsync(discount);
                }

                if (discount.DiscountAmount3 != 0)
                {
                    discount.DiscountAmount = discount.DiscountAmount3;
                    discount.DiscountType   = 3;
                    result += await addBillingDiscountQueryProcessor.SaveAsync(discount);
                }
                if (discount.DiscountAmount4 != 0)
                {
                    discount.DiscountAmount = discount.DiscountAmount4;
                    discount.DiscountType   = 4;
                    result += await addBillingDiscountQueryProcessor.SaveAsync(discount);
                }

                if (discount.DiscountAmount5 != 0)
                {
                    discount.DiscountAmount = discount.DiscountAmount5;
                    discount.DiscountType   = 5;
                    result += await addBillingDiscountQueryProcessor.SaveAsync(discount);
                }
                scope.Complete();
            }
            return(result);
        }
Esempio n. 3
0
        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);
        }