Пример #1
0
        public Task <IEnumerable <MFBilling> > GetItems(MFBillingSource source, CancellationToken token = default(CancellationToken))
        {
            var query = $@"
SELECT      mfb.*
FROM        MFBilling mfb
INNER JOIN  Billing b
ON          b.Id        = mfb.BillingId";

            if (source.CompanyId.HasValue)
            {
                query += @"
AND         b.CompanyId = @CompanyId";
            }
            if (source.Ids?.Any() ?? false)
            {
                query += @"
AND         b.Id        IN (SELECT Id FROM @Ids)";
            }
            if (source.IsMatched.HasValue)
            {
                query += $@"
AND         b.AssignmentFlag {(source.IsMatched.Value ? "=" : "<>")} 2";
            }
            return(dbHelper.GetItemsAsync <MFBilling>(query, source, token));
        }
Пример #2
0
        /// <summary>登録</summary>
        /// <param name="source">MFC請求書 の ID(ハッシュ文字列)は、<see cref="Billing.CustomerKana"/>へ設定されているものとする</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <IEnumerable <Billing> > SaveAsync(MFBillingSource source, CancellationToken token = default(CancellationToken))
        {
            var billings     = source.Billings;
            var customers    = source.Customers;
            var newCustomers = new List <Customer>();
            var result       = new List <Billing>();

            using (var scope = transactionScopeBuilder.Create())
            {
                foreach (var c in customers)
                {
                    newCustomers.Add(await customerProcessor.SaveAsync(c, token: token));
                }

                var staffs = (await staffProcessor.GetAsync(new StaffSearch {
                    Ids = newCustomers.Select(x => x.StaffId).Distinct().ToArray()
                }, token)).ToDictionary(x => x.Id);

                foreach (var billing in billings)
                {
                    if (billing.CustomerId == 0)
                    {
                        var customer = newCustomers.Where(x => x.Code == billing.CustomerCode).FirstOrDefault();
                        var staff    = staffs[customer.StaffId];

                        billing.CustomerId        = customer.Id;
                        billing.StaffId           = customer.StaffId;
                        billing.CollectCategoryId = customer.CollectCategoryId;
                        billing.DepartmentId      = staff.DepartmentId;
                    }
                    var savedBilling = await billingSaveProcessor.SaveAsync(billing, token);

                    var mfId      = billing.CustomerKana;
                    var mfBilling = new MFBilling
                    {
                        BillingId = savedBilling.Id,
                        CompanyId = savedBilling.CompanyId,
                        Id        = mfId
                    };
                    await addMFBillingQueryProcessor.SaveAsync(mfBilling, token);

                    result.Add(savedBilling);
                }
                scope.Complete();
            }
            return(result);
        }
Пример #3
0
 public Task <IEnumerable <MFBilling> > GetAsync(MFBillingSource source, CancellationToken token = default(CancellationToken))
 => mfBillingQueryProcessor.GetItems(source, token);
Пример #4
0
 public async Task <IEnumerable <MFBilling> > Get(MFBillingSource source, CancellationToken token)
 => (await mfBillingProcessor.GetAsync(source, token)).ToArray();
Пример #5
0
 public async Task <ActionResult <IEnumerable <Billing> > > Save(MFBillingSource source, CancellationToken token)
 => (await mfBillingProcessor.SaveAsync(source, token)).ToArray();