예제 #1
0
        /// <summary>
        /// カートを作成します
        /// </summary>
        /// <param name="companyCode">企業コード</param>
        /// <param name="storeCode">店舗コード</param>
        /// <param name="storeName">店舗名</param>
        /// <param name="terminalNo">端末番号</param>
        /// <param name="userId">ユーザー ID</param>
        /// <param name="userName">ユーザー名</param>
        /// <param name="receiptNo">レシート番号</param>
        /// <param name="transactionNo">取引番号</param>
        /// <returns>作成したカート Document</returns>
        public async Task <CartDocument> CreateCartAsync(
            string companyCode,
            string storeCode,
            string storeName,
            int terminalNo,
            string userId,
            string userName,
            long receiptNo,
            long transactionNo)
        {
            // HACK:同一カートの同時利用を抑制する排他制御が必要な場合は実装する
            var cart = new CartDocument()
            {
                CartId           = Guid.NewGuid().ToString(),
                Status           = CartStatus.EnteringItem.Code,
                GenerateDateTime = DateTimeUtility.GetApplicationTimeNow(),
                CompanyCode      = companyCode,
                StoreCode        = storeCode,
                StoreName        = storeName,
                TerminalNo       = terminalNo,
                TransactionNo    = transactionNo,
                ReceiptNo        = receiptNo,
                ReceiptText      = string.Empty,
                User             = new UserInfo {
                    UserId = userId, UserName = userName
                },
            };

            cart.Sales.ReferenceDateTime = cart.GenerateDateTime;
            await this.CreateAsync(cart);

            return(cart);
        }
        /// <summary>
        /// カート情報から取引ログを作成します
        /// </summary>
        /// <param name="cart">カート Document</param>
        /// <returns>作成した取引ログ Document</returns>
        public async Task <TransactionLogDocument> CreateTransactionLogAsync(CartDocument cart)
        {
            var tranDoc = new TransactionLogDocument
            {
                CompanyCode      = cart.CompanyCode,
                StoreCode        = cart.StoreCode,
                StoreName        = cart.StoreName,
                TerminalNo       = cart.TerminalNo,
                TransactionNo    = cart.TransactionNo,
                TransactionType  = cart.TransactionType,
                BusinessDate     = DateTimeUtility.GetApplicationTimeNow().Date,
                GenerateDateTime = DateTimeUtility.GetApplicationTimeNow(),
                ReceiptNo        = cart.ReceiptNo,
                User             = cart.User,
                Sales            = cart.Sales,
                LineItems        = cart.LineItems.Select(l => (TransactionLogBase.LineItem)l).ToList(),
                Payments         = cart.Payments,
                Taxes            = cart.Taxes
            };

            await this.CreateAsync(tranDoc);

            return(tranDoc);
        }