public IActionResult updateSaleDetails([FromBody] SaleDetailModel request)
 {
     try {
         User currentUser = _userService.CheckUseRole(_httpContextAccessor.HttpContext.User, menu, "update");
         if (currentUser != null)
         {
             SaleDetailModel model = _context.SaleDetails.FirstOrDefault(p => p.id == request.id);
             model.date       = request.date;
             model.inv_no     = request.inv_no;
             model.item_id    = request.item_id;
             model.unit_id    = request.unit_id;
             model.price      = request.price;
             model.qty        = request.qty;
             model.total      = request.total;
             model.discount   = request.discount;
             model.tax        = request.tax;
             model.net_amount = request.net_amount;
             model.status     = request.status;
             _context.SaveChanges();
             _eventService.SaveEvent(currentUser.User_Id, EventUserLog.EVENT_UPDATE, model.inv_no.ToString(), "SaleDetail");
             return(Ok(model));
         }
         else
         {
             return(Ok(SendResult.SendError("You don`t have update permision.")));
         }
     } catch (Exception error) {
         Console.WriteLine(error);
         return(BadRequest(SendResult.SendError("You don`t update SaleDetail info")));
     }
 }
Exemple #2
0
        public void WhenIRequestTheSaleDetailsForSale(int saleId)
        {
            var query = _context.Container
                        .GetInstance <GetSaleDetailQuery>();

            _result = query.Execute(saleId);
        }
Exemple #3
0
        //decimal _descountInPercentage = 0;
        //decimal _discountAmount = 0;
        //decimal _vatInPercentage = 0;
        //decimal _vatAmount = 0;
        //decimal _serviceCharge = 0;
        //decimal _netAmount = 0;

        #endregion

        #region Constructor

        public SaleForm()
        {
            InitializeComponent();
            IKernel kernel = BootStrapper.Initialize();

            _saleService       = kernel.GetService(typeof(SaleService)) as SaleService;
            _saleDetailService = kernel.GetService(typeof(SaleDetailService)) as SaleDetailService;

            _sale           = new SaleModel();
            _saleDetail     = new SaleDetailModel();
            _saleDetailList = new List <SaleDetailModel>();
        }
        public void TestGetShouldReturnSaleDetails()
        {
            var sale = new SaleDetailModel();

            _mocker.GetMock <IGetSaleDetailQuery>()
            .Setup(p => p.Execute(1))
            .Returns(sale);

            var result = _controller.Get(1);

            Assert.That(result,
                        Is.EqualTo(sale));
        }
Exemple #5
0
        public void TestGetDetailShouldReturnSaleDetail()
        {
            var saleId = 1;

            var model = new SaleDetailModel();

            _mocker.GetMock <IGetSaleDetailQuery>()
            .Setup(p => p.Execute(saleId))
            .Returns(model);

            var viewResult = _controller.Detail(saleId);

            var result = (SaleDetailModel)viewResult.Model;

            Assert.That(result, Is.EqualTo(model));
        }
 public IActionResult getSaleDetails([FromBody] JObject request)
 {
     try {
         User currentUser = _userService.CheckUseRole(_httpContextAccessor.HttpContext.User, menu, "read");
         if (currentUser != null)
         {
             int             id    = request["id"].Value <int>();
             SaleDetailModel model = _context.SaleDetails.FirstOrDefault(s => s.id == id);
             return(Ok(model));
         }
         else
         {
             return(Ok(SendResult.SendError("You don`t have read permision.")));
         }
     } catch (Exception error) {
         Console.WriteLine(error);
         return(BadRequest(SendResult.SendError("You don`t get SaleDetail info")));
     }
 }
        private SaleDetailDBModel PopulateSaleDetailDBModel(SaleDetailModel item)
        {
            var productInfo = products.GetProductById(item.ProductId);

            if (productInfo == null)
            {
                throw new Exception($"Product with id {item.ProductId} could not be found!");
            }

            var detail = new SaleDetailDBModel
            {
                ProductId     = item.ProductId,
                Quantity      = item.Quantity,
                PurchasePrice = Decimal.Parse(productInfo.RetailPrice) * item.Quantity,
            };

            detail.Tax = productInfo.IsTaxable ? CalculateTax(detail.PurchasePrice) : 0;
            return(detail);
        }
 public IActionResult CreateSaleDetail([FromBody] SaleDetailModel request)
 {
     try {
         User currentUser = _userService.CheckUseRole(_httpContextAccessor.HttpContext.User, menu, "create");
         if (currentUser != null)
         {
             request.date       = DateTime.Now;
             request.created_by = currentUser.User_Id;
             _context.Add(request);
             _context.SaveChanges();
             _eventService.SaveEvent(currentUser.User_Id, EventUserLog.EVENT_CREATE, request.inv_no.ToString(), "SaleDetail");
             return(Ok(request));
         }
         else
         {
             return(Ok(SendResult.SendError("You don`t have create permision.")));
         }
     } catch (Exception error) {
         Console.WriteLine(error);
         return(BadRequest(SendResult.SendError("You don`t create new SaleDetail")));
     }
 }
 public IActionResult removeSaleDetails([FromBody] JObject request)
 {
     try {
         User currentUser = _userService.CheckUseRole(_httpContextAccessor.HttpContext.User, menu, "delete");
         if (currentUser != null)
         {
             int             id    = request["id"].Value <int>();
             SaleDetailModel model = _context.SaleDetails.FirstOrDefault(p => p.id == id);
             string          name  = model.inv_no.ToString();
             _context.SaleDetails.Remove(model);
             _context.SaveChanges();
             _eventService.SaveEvent(currentUser.User_Id, EventUserLog.EVENT_REMOVE, name, "SaleDetails");
             return(Ok(true));
         }
         else
         {
             return(Ok(SendResult.SendError("You don`t have delete permision.")));
         }
     } catch (Exception error) {
         Console.WriteLine(error);
         return(BadRequest(SendResult.SendError("You don`remove SaleDetail")));
     }
 }
Exemple #10
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            //if (_productSearchForm != null && _productSearchForm.Visible)
            //{
            //    return;
            //}
            //_productSearchForm = new ProductSearchForm();
            //_productSearchForm.Show();

            _productSearchForm = new ProductSearchForm();

            // Show testDialog as a modal dialog and determine if DialogResult = OK.
            _productSearchForm.ShowDialog();

            _productSearchInformation = _productSearchForm._productSearchInformation;

            var saleProduct = new SaleDetailModel
            {
                //SaleId
                ProductId                   = _productSearchInformation.ProductId,
                ProductName                 = _productSearchInformation.ProductName,
                ProductQuantity             = 1,
                ProductUnitPrice            = _productSearchInformation.ProductUnitPrice,
                ProductDiscountInPercentage = _productSearchInformation.DiscountInPercentage,
            };

            saleProduct.ProductDiscountAmount = saleProduct.ProductQuantity * saleProduct.ProductUnitPrice *
                                                saleProduct.ProductDiscountInPercentage / 100;
            saleProduct.ProductTotalPrice = saleProduct.ProductQuantity * saleProduct.ProductUnitPrice -
                                            saleProduct.ProductDiscountAmount;

            _saleDetailList.Add(saleProduct);

            LoadDataGridView();
            _productSearchForm.Dispose();
            CalculateSalePriceDetail();
        }
        public async Task <ActionResult> Sales(ProductsViewModel model)
        {
            var productList = await GetAllProducts();

            StringBuilder         productsAddedToCartString = new StringBuilder(model.ProductsAddedToCartString);
            List <SelectListItem> listAvailableItems        = new List <SelectListItem>();
            List <SelectListItem> listCartItems             = new List <SelectListItem>();
            decimal subTotal = model.SubTotal;
            decimal taxRate  = _configHelper.GetTaxRate() / 100;
            decimal tax      = model.Tax;
            decimal total    = model.Total;
            List <SaleDetailModel> saleDetails = new List <SaleDetailModel>();;

            foreach (ProductModel product in productList)
            {
                SelectListItem availableList = new SelectListItem()
                {
                    Text  = product.ProductName,
                    Value = product.Id.ToString()
                };
                listAvailableItems.Add(availableList);
            }

            if (model.SelectedAvailableProducts != null)
            {
                foreach (var selectedAvailableProduct in model.SelectedAvailableProducts)
                {
                    int          Id = Convert.ToInt32(selectedAvailableProduct);
                    ProductModel selectedProduct = productList.FirstOrDefault(p => p.Id == Id);
                    selectedProduct.QuantityInStock -= model.Quantity;
                    productsAddedToCartString.Append($"{selectedAvailableProduct}:{selectedProduct.ProductName}:{model.Quantity};");
                    subTotal += selectedProduct.RetailPrice * model.Quantity;
                    if (selectedProduct.IsTaxable)
                    {
                        tax += selectedProduct.RetailPrice * model.Quantity * taxRate;
                    }
                }
            }

            if (model.SelectedProductsAddedToCart != null)
            {
                foreach (var selectedProductToBeRemoved in model.SelectedProductsAddedToCart)
                {
                    ProductModel selectedProduct = productList.FirstOrDefault(p => p.Id == Convert.ToInt32(selectedProductToBeRemoved));
                    selectedProduct.QuantityInStock += model.Quantity;
                    productsAddedToCartString.Replace($"{selectedProductToBeRemoved}:{selectedProduct.ProductName}:{model.Quantity};", string.Empty);
                    subTotal -= selectedProduct.RetailPrice * model.Quantity;
                    if (selectedProduct.IsTaxable)
                    {
                        tax -= selectedProduct.RetailPrice * model.Quantity * taxRate;
                    }
                }
            }

            total = subTotal + tax;

            string[] productsAddedToCartStringArray = productsAddedToCartString.ToString().Split(';');
            foreach (string productsAddedToCartStringItem in productsAddedToCartStringArray)
            {
                if (!productsAddedToCartStringItem.IsNullOrWhiteSpace())
                {
                    string[] itemInfo         = productsAddedToCartStringItem.Split(':');
                    int      cartItemId       = Convert.ToInt32(itemInfo[0]);
                    int      cartItemQuantity = Convert.ToInt32(itemInfo[2]);

                    SelectListItem cartList = new SelectListItem()
                    {
                        Text  = itemInfo[1],
                        Value = itemInfo[0]
                    };
                    listCartItems.Add(cartList);

                    SaleDetailModel saleDetailModel = new SaleDetailModel();
                    saleDetailModel.ProductId = cartItemId;
                    saleDetailModel.Quantity  = cartItemQuantity;
                    saleDetails.Add(saleDetailModel);
                }
            }

            ProductsViewModel productsViewModel = new ProductsViewModel()
            {
                AvailableProducts         = listAvailableItems,
                ProductsAddedToCart       = listCartItems,
                ProductsAddedToCartString = productsAddedToCartString.ToString(),
                Quantity = model.Quantity,
                SubTotal = subTotal,
                Tax      = tax,
                Total    = total
            };

            if (null == model.SelectedAvailableProducts && null == model.SelectedProductsAddedToCart)
            {
                SaleModel sale = new SaleModel();
                sale.SaleDetails = saleDetails;
                await _saleEndPoint.PostSale(sale);

                ProductsViewModel resetProductsViewModel = new ProductsViewModel()
                {
                    AvailableProducts         = listAvailableItems,
                    ProductsAddedToCart       = new List <SelectListItem>(),
                    ProductsAddedToCartString = "",
                    Quantity = 1,
                    SubTotal = 0,
                    Tax      = 0,
                    Total    = 0
                };
                return(RedirectToAction("Sales", new { serializedModel = JsonConvert.SerializeObject(resetProductsViewModel) }));
            }

            return(RedirectToAction("Sales", new { serializedModel = JsonConvert.SerializeObject(productsViewModel) }));
        }
Exemple #12
0
 public void Insert(SaleDetailModel saledetailmodel)
 {
     throw new NotImplementedException();
 }