public IResult Add(List <BasketDetailDto> dtos)
        {
            var result = BusinessRules.Run(CheckToken());

            if (result != null)
            {
                return(new ErrorResult(result.Message));
            }

            int basketId = CreateNewBasketIfNotHaveActive().Data.Id;

            foreach (var dto in dtos)
            {
                BasketDetail basketDetail = new BasketDetail
                {
                    BasketId   = basketId,
                    ProductId  = dto.ProductId,
                    Count      = dto.Count,
                    CreateDate = DateTime.Now,
                    Active     = true
                };

                _basketDetailDal.Add(basketDetail);
            }

            return(new SuccessResult(BusinessMessages.BasketDetailAdded));
        }
Beispiel #2
0
        private void CreatePostpayBasket(BasketDetail basketDetail)
        {
            // trying to remove existing sale with same basket because
            // FCS sends unnecessary BasketCreate to the POS who originally
            // called BasketCancelHold
            log.Debug("PosManager: Creating Postpay basket.");
            RemoveSaleWithBasketId(currentSales, basketDetail.BasketID);

            log.Debug("PosManager:Handling postpay basket");
            int pumpId = int.Parse(basketDetail.PumpID);

            log.Debug("PosManager: PostpayBasket with basketId:{0} and basketType:Create.", basketDetail.BasketID);

            var sale = CreateNewSale(pumpId);

            if (sale == null)
            {
                return;
            }

            sale.SaleType   = SaleType.Postpay;
            sale.SoldBasket = basketDetail;
            sale.Amount     = basketDetail.Amount;

            InvokeBasketChangedEventForPump(true, pumpId);
        }
Beispiel #3
0
        private async Task CreatePrepayBasket(BasketDetail basketDetail)
        {
            int pumpId = int.Parse(basketDetail.PumpID);

            log.Debug("PosManager: Creating prepay basket for pump {0}", pumpId);

            if (RestorePrepaySaleFromBackup(basketDetail))
            {
                log.Debug("PosManager: Prepay sale with basket restored from backup");
                InvokeBasketChangedEventForPump(true, pumpId);
            }
            else
            {
                log.Debug("PosManager: Handling new prepay basket");
                var  sales           = GetSales(currentSales, pumpId);
                bool isBasketChanged = false;

                if (sales != null)
                {
                    var sale = sales.FirstOrDefault(saleStatus => saleStatus?.InvoiceNo == basketDetail?.Prepay?.PrepayInvoice);
                    if (sale != null)
                    {
                        log.Debug("PosManager: Prepay basket with basketId:{0} and basketTye create.", basketDetail.BasketID);
                        if (basketDetail.IsRefundAvailable())
                        {
                            log.Debug("PosManager: There is refund for this prepay basket.");
                            if (sale.SoldBasket == null)
                            {
                                sale.SoldBasket = basketDetail;
                                isBasketChanged = true;
                            }
                        }
                        else
                        {
                            log.Debug("PosManager: There is no refund for this prepay basket.Hold and Remove basket");

                            basketDetail.SetPayTenderInfo(GetAutoRemoveBasketTenderInfo(sale));

                            var response = await fcsService?.HoldAndRemoveBasket(basketDetail,
                                                                                 sale.TotalPaid,
                                                                                 sale.Change,
                                                                                 sale.Receipt,
                                                                                 GetInvoiceNo(sale));

                            if (response.ResultOK)
                            {
                                log.Debug("PosManager: Hold and remove basket successfully.Remove Sale from sale status list.");
                                sales.Remove(sale);
                            }
                            else
                            {
                                log.Error("PosManager: Hold and remove  Basket failed.");
                            }
                        }
                    }
                }
                InvokeBasketChangedEventForPump(isBasketChanged, pumpId);
            }
        }
Beispiel #4
0
        public IActionResult Delete(BasketDetail basketDetail)
        {
            var result = _basketDetailService.Delete(basketDetail);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Beispiel #5
0
        private bool RestorePrepaySaleFromBackup(BasketDetail basketDetail)
        {
            log.Debug("PosManager: Restore prepay sale from back up sales.");
            var removedSale = RemoveSaleWithBasketId(backupPrepaySales, basketDetail.BasketID);

            if (removedSale != null && IsSamePrepay(removedSale.SoldBasket, basketDetail))
            {
                return(AddSale(currentSales, removedSale));
            }

            return(false);
        }
Beispiel #6
0
 private async Task CreateBasket(BasketDetail basketDetail)
 {
     log.Debug("PosManager: Creating basket.");
     if (basketDetail.Prepay != null)
     {
         log.Debug("PosManager: Prepay basket with basket Id:{0}", basketDetail.BasketID);
         await CreatePrepayBasket(basketDetail);
     }
     else
     {
         log.Debug("PosManager: Postpay basket with basket Id:{0}", basketDetail.BasketID);
         CreatePostpayBasket(basketDetail);
     }
 }
        private void PostPay(StringWriter receipt, BasketDetail basket)
        {
            Label(receipt, "Pump");
            receipt.WriteLine("#{0} - {1}", basket.PumpID, basket.Grade);

            Label(receipt, "Volume");
            receipt.WriteLine("{0:0.000}", basket.Volume);

            Label(receipt, "Price");
            FuelUnitPrice(receipt, basket.UnitPrice);

            Label(receipt, "Total");
            receipt.WriteLine("{0:0.00}", basket.Amount);
        }
Beispiel #8
0
        public void Update_UpdateBasketDetail_ReturnTrueResult()
        {
            IBasketDetailService basketDetailService = new BasketDetailManager(_mockBasketDetailDal.Object);
            BasketDetail         basketDetail        = new BasketDetail
            {
                Id         = 1,
                BasketId   = It.IsAny <int>(),
                ProductId  = It.IsAny <int>(),
                Count      = It.IsAny <int>(),
                CreateDate = DateTime.Now,
                Active     = true
            };
            var result = basketDetailService.Update(basketDetail);

            Assert.IsTrue(result.Success);
        }
Beispiel #9
0
        public void InvalidParameters_ThrowValidationException()
        {
            BasketDetail basketDetail = new BasketDetail
            {
                Id         = 1,
                BasketId   = 0,
                ProductId  = It.IsAny <int>(),
                Count      = It.IsAny <int>(),
                CreateDate = DateTime.Now,
                Active     = true
            };

            var result = _validator.TestValidate(basketDetail);

            result.ShouldHaveAnyValidationError();
        }
Beispiel #10
0
        public void AddToBasket(Basket basket, Product product)
        {
            using (var context = new ECommerceContext())
            {
                BasketDetail basketDetail = context.BasketDetails.FirstOrDefault(b => b.ProductId == product.Id);
                if (basketDetail != null)
                {
                    basketDetail.Quantity++;
                    context.BasketDetails.Update(basketDetail);
                    context.SaveChanges();
                    return;
                }

                context.BasketDetails.Add(new BasketDetail {
                    ProductId = product.Id, BasketId = GetBasketByUserId(1).Id, Quantity = 1
                });
                context.SaveChanges();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Umbraco mapper custom mapping for mapping basket information to a view model
        /// </summary>
        /// <returns></returns>
        public static object GetBasketDetail(IUmbracoMapper mapper, IPublishedContent contentToMapFrom, string propertyName, bool recursive)
        {
            var umbracoContext  = UmbracoContext.Current;
            var customerContext = new CustomerContext(umbracoContext);
            var currentCustomer = customerContext.CurrentCustomer;
            var basket          = currentCustomer.Basket();

            var basketDetail = new BasketDetail();

            AutoMapper.Mapper.Map(basket, basketDetail);

            var preparation = basket.SalePreparation();

            if (preparation.IsReadyToInvoice())
            {
                var invoice = preparation.PrepareInvoice();
                basketDetail.DeliveryPrice = invoice.TotalShipping();
            }

            return(basketDetail);
        }
Beispiel #12
0
        private void ClearBasket(BasketDetail basketDetail)
        {
            log.Debug("PosManager: Clear Basket.");
            var removedSale = RemoveSaleWithBasketId(currentSales, basketDetail.BasketID);

            if (removedSale != null)
            {
                log.Debug("PosManager: RemovedSale is found.");
                if (removedSale.SoldBasket.Prepay != null)
                {
                    log.Debug("PosManager: RemovedSale.SoldBasket.Prepay is not null.Add removed sale to back up sales.");
                    AddSale(backupPrepaySales, removedSale);
                }

                InvokeBasketChangedEventForPump(true, removedSale.PumpId);
            }
            else
            {
                log.Error("PosManager: RemovedSale not found.");
            }
        }
Beispiel #13
0
        private bool IsSamePrepay(BasketDetail first, BasketDetail second)
        {
            log.Debug("PosManager: Check if same prepay or not.");
            if ((first == null || second == null) ||
                first.Prepay == null || second.Prepay == null ||
                first.Prepay.PrepayInvoice == null || second.Prepay.PrepayInvoice == null)
            {
                log.Debug("PosManager: IsSamePrepay is false.");
                return(false);
            }

            if (first.Prepay.PrepayInvoice == second.Prepay.PrepayInvoice)
            {
                log.Debug("PosManager: IsSamePrepay is true.");
                return(true);
            }
            else
            {
                log.Debug("PosManager:IsSamePrepay is false.");
                return(false);
            }
        }
Beispiel #14
0
 public bool IsRefundPossibleForThisBasket(BasketDetail possibleBasket)
 {
     return(SaleType == SaleType.Prepay &&
            possibleBasket?.Prepay?.PrepayAmount > possibleBasket?.Amount);
 }
 public IResult Update(BasketDetail basketDetail)
 {
     _basketDetailDal.Update(basketDetail);
     return(new SuccessResult(BusinessMessages.BasketDetailUpdated));
 }