Esempio n. 1
0
        public void SaleService_Add_ShouldBeOk()
        {
            _product.Object.Availability = 1;
            _sale = ObjectMother.GetSale(_product.Object);

            Action Act = () => _service.Add(_sale);

            Act.Should().NotThrow();
            _repository.Verify(r => r.Add(_sale));
        }
Esempio n. 2
0
        public void SaleIntegration_Add_ShouldBeOk()
        {
            _product.Id           = 1;
            _product.Availability = 1;
            _sale = ObjectMother.GetSaleSql(_product);

            _expectedSale = _service.Add(_sale);

            _expectedSale.Should().NotBeNull();
            _expectedSale.Id.Should().Be(_sale.Id);
        }
Esempio n. 3
0
        public async Task <IActionResult> AddSale(SaleRequest sale)
        {
            DataResponse response = new DataResponse();

            try
            {
                if (!ModelState.IsValid)
                {
                    response.Message = string.Join("", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                    return(BadRequest(response));
                }
                var client = await _clientService.GetById(sale.IdClient);

                if (client == null)
                {
                    response.Message = "The id client is not found.";
                    return(NotFound(response));
                }
                await _saleService.Add(sale);

                response.Success = 1;
                response.Message = "The sale has been added.";
                return(Ok(response));
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                return(StatusCode(500, response));
            }
        }
Esempio n. 4
0
        private void CalculateBanknoteChange(
            IList <SaleBanknote> banknotesChange,
            IEnumerable <Banknote> banknotes,
            decimal givenValue,
            decimal totalSelling,
            out string details)
        {
            details = string.Empty;
            var changeValue = givenValue - totalSelling;

            if (changeValue > 0)
            {
                var sale = new Sale()
                {
                    Total    = totalSelling,
                    Descount = 0
                };
                _saleService.Add(sale);

                CalculateNotes(banknotesChange, banknotes, changeValue, out int totalRest, out string detailsNotes);
                CalculateCents(banknotesChange, banknotes, changeValue, totalRest, out string detailsCents);

                details = detailsNotes + detailsCents;

                if (banknotesChange.Any())
                {
                    sale.Banknotes = banknotesChange;
                    _saleService.Update(sale);
                }
            }
        }
        public async Task <ActionResult <SaleViewModel> > Post([FromBody] SaleViewModel saleViewModel)
        {
            var sale = _mapper.Map <Sale>(saleViewModel);

            await _saleService.Add(sale);

            saleViewModel.Id           = sale.Id;
            saleViewModel.DateRegister = sale.DateRegister;

            return(CustomResponse(saleViewModel));
        }
Esempio n. 6
0
        public IActionResult Create(CreateSaleViewModel createVM)
        {
            if (ModelState.IsValid)
            {
                var saleDTO = _mapper.Map <SaleBindingModel, SaleDTO>(createVM.Sale);
                _saleService.Add(saleDTO);

                return(RedirectToAction(nameof(Items)));
            }
            createVM.ProductTitles = new SelectList(_productService.GetTitles(), "Id", "Title");
            return(View(createVM));
        }
Esempio n. 7
0
 public ActionResult Create(CreateSale createSale)
 {
     if (ModelState.IsValid)
     {
         _saleService.Add(createSale);
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View(createSale));
     }
 }
Esempio n. 8
0
        public IActionResult add(SaleRequestDTO model)
        {
            BaseResponse response = new BaseResponse();

            try
            {
                _sale.Add(model);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }
            return(Ok(response));
        }
Esempio n. 9
0
 public ActionResult Create(SaleViewModel sale)
 {
     if (!ModelState.IsValid)
     {
         ErrorNotification("Kayıt Eklenemedi!");
         return(RedirectToAction("Create"));
     }
     _saleService.Add(new Sale
     {
         //TODO:Alanlar buraya yazılacak
         //Örn:BrandName = brand.BrandName,
     });
     SuccessNotification("Kayıt Eklendi.");
     return(RedirectToAction("SaleIndex"));
 }
Esempio n. 10
0
        public IActionResult Add(SaleRequest req)
        {
            var resp = new ProductsResponse();

            try
            {
                _salesService.Add(req);
                resp.Success = 1;
            }
            catch (Exception ex)
            {
                resp.Message = ex.Message;
                return(BadRequest(resp));
            }

            return(Ok(resp));
        }
Esempio n. 11
0
        public ActionResult Create(CreateSaleViewModel createSale)
        {
            if (ModelState.IsValid)
            {
                Sale sale = _saleService.Add(createSale);

                if (sale == null)
                {
                    ModelState.AddModelError("msg", "Database problems");
                    return(View(createSale));
                }

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(createSale));
            }
        }
Esempio n. 12
0
 public ActionResult Create(MobileShopSaleViewModel salevm)
 {
     try
     {
         var id = _saleService.Add(Mapper.Map <Sale>(salevm));
         if (!string.IsNullOrEmpty(salevm.ActionType) && salevm.ActionType == "Invoice")
         {
             return(Redirect("/MobileShopSale/ReportSaleMasterDetail/" + id));
         }
         if (!string.IsNullOrEmpty(salevm.ActionType) && salevm.ActionType == "Label")
         {
             return(Redirect("/MobileShopSale/ReportLevelPrint/" + id));
         }
         if (!string.IsNullOrEmpty(salevm.ActionType) && salevm.ActionType == "Print")
         {
             return(Redirect("/MobileShopSale/ReportInvoicePrint/" + id));
         }
         return(Redirect("/MobileShopSale/"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','failure')"));
     }
 }
Esempio n. 13
0
        private Sale RecordSale(string InvoiceNo, string AmountPaid, string subTotalAmt, DateTime?SaleDate, decimal totalAmount, decimal balance)
        {
            Sale sales = new Sale();

            sales.CustomerID    = txtCustomer.Tag.ToString();
            sales.Amount        = totalAmount;
            sales.SubTotal      = decimal.Parse(subTotalAmt);
            sales.InvoiceDate   = SaleDate.Value;
            sales.InvoiceNumber = InvoiceNo;
            sales.StoreID       = DEFAULT_LOCALSTOREID; //arbituary value, to bo replaced
            sales.Tax           = Math.Round(_saletax, 2);
            sales.PaymentModeID = int.Parse(cmbPaymentMode.SelectedValue.ToString());

            //sales.Discount = txtSaleDiscount.Text == "" ? 0 : txtSaleDiscount.Text.ToDecimal();
            sales.AmountPaid = decimal.Parse(AmountPaid);
            sales.Balance    = balance;
            sales.DateClosed = decimal.Parse(AmountPaid) >= decimal.Parse(subTotalAmt) ? SaleDate : null;
            //sales.SaleTypeID = (int)SaleStatus.Invoice;

            //sales.SaleTypeID = int.Parse(TypeOfSale.Order.ToString());
            sales.SaleStatusID = _sale.GetSaleStatus(totalAmount, AmountPaid.ToDecimal());
            sales.EmployeeID   = txtSalesPerson.Tag == null ? DEFAULT_SALESPERSONID : txtSalesPerson.Tag.ToString();
            sales.Discount     = txtSaleDiscount.Text == "" ? 0 : decimal.Parse(txtSaleDiscount.Text);
            sales.VoidSale     = false;
            sales.LocationID   = cmbLocation.SelectedValue.ToInt();

            try
            {
                sales = _sale.Add(sales);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred", "ucSale", "btnRecord");
            }
            return(sales);
        }
Esempio n. 14
0
 public IActionResult Add([FromBody] SaleDTO saleDTO)
 {
     _saleService.Add(saleDTO);
     return(Ok(saleDTO));
 }
Esempio n. 15
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            if (btnRecord.Text == "OK")
            {
                ((frmControlHost)this.Parent).Close();
                return;
            }

            if (gridViewItemLayout.Rows.Count == 0)
            {
                Helper.ShowMessage("Sale must contain at least one product",
                                   "Sale Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                Product    product;
                SaleDetail salesDetails;
                Sale       sales = new Sale();

                string   InvoiceNo   = txtInvoiceNo.Text;
                string   AmountPaid  = txtAmountPaid.Text;
                string   subTotalAmt = txtSubTotal.Text;
                DateTime?SaleDate    = dtpSaleDate.Value;
                decimal  tax         = txtSalTax.Text.ToDecimal();
                int      locationID  = cmbLocation.SelectedValue.ToInt();
                decimal  saletax     = _sale.CalculateTax(subTotalAmt.ToDecimal(), tax);
                decimal  totalAmount = txtTotalAmt.Text.ToDecimal();

                sales.CustomerID    = txtCustomer.Tag.ToString();
                sales.Amount        = totalAmount;
                sales.CustBalance   = totalAmount;
                sales.SubTotal      = decimal.Parse(subTotalAmt);
                sales.InvoiceDate   = SaleDate.Value;
                sales.InvoiceNumber = InvoiceNo;
                sales.StoreID       = DEFAULT_LOCALSTOREID; //arbituary value, to bo replaced
                sales.Tax           = Math.Round(saletax, 2);
                sales.PaymentModeID = int.Parse(cmbPaymentMode.SelectedValue.ToString());

                sales.AmountPaid = 0;
                sales.Balance    = 0;
                sales.DateClosed = null;

                sales.SaleStatusID = (int)Status;//_sale.GetSaleStatus(totalAmount, AmountPaid.ToDecimal());
                sales.EmployeeID   = txtSalesPerson.Tag == null ? DEFAULT_SALESPERSONID : txtSalesPerson.Tag.ToString();
                sales.Discount     = txtSaleDiscount.Text == "" ? 0 : decimal.Parse(txtSaleDiscount.Text);
                sales.VoidSale     = false;
                sales.LocationID   = cmbLocation.SelectedValue.ToInt();

                try
                {
                    sales = _sale.Add(sales);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "An error occurred", "ucQuote", "btnRecord");
                    Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                foreach (DataGridViewRow dr in gridViewItemLayout.Rows)
                {
                    if (dr.Cells[0].Value == null)
                    {
                        return;
                    }

                    salesDetails = new SaleDetail();
                    product      = new Product();

                    salesDetails.SaleID        = sales.SaleID;
                    salesDetails.Quantity      = int.Parse(dr.Cells["ColQty"].Value.ToString());
                    salesDetails.ProductID     = dr.Cells["ColItmNumber"].Value.ToString();
                    salesDetails.UnitPrice     = decimal.Parse(dr.Cells["ColPrice"].Value.ToString());
                    salesDetails.Discount      = decimal.Parse(dr.Cells["ColDiscount"].Value.ToString());
                    salesDetails.Tax           = decimal.Parse(dr.Cells["ColTax"].Value.ToString());
                    salesDetails.InvoiceNumber = InvoiceNo;
                    salesDetails.LineTotal     = decimal.Parse(dr.Cells["ColTotal"].Value.ToString());

                    try
                    {
                        _saleDetail.Add(salesDetails);
                    }
                    catch (Exception ex)
                    {
                        _sale.RollBackSaleTransaction(InvoiceNo);
                        _logger.LogError(ex, "An error occurred", "ucQuote", "btnRecord");
                        Helper.ShowMessage("Transaction was not completed, An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                txtInvoiceNo.Tag = false;

                txtSubTotal.Tag = null;
                txtTotalAmt.Tag = null;

                Helper.ClearForm(this);
                gridViewItemLayout.Rows.Clear();

                lblStatus.Text = "Quote recorded successfully";

                GetInvoiceNo();
            }
            catch (Exception ex)
            {
                Helper.ShowMessage("An error occured sale has been cancelled \n" + ex.Message,
                                   "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 16
0
        public ActionResult Create(SaleViewModel sale)
        {
            var getUserId = Convert.ToInt32(GeneralHelpers.GetUserId());

            if (!ModelState.IsValid)
            {
                ErrorNotification("Satış Eklenemedi!");
                return(RedirectToAction("Create"));
            }
            //satış yapılınca stok miktarından otomatik olarak düşer onay ya da onaylanmama durumuna göre stoklar güncellenir
            //Eğer satılacak ürün stokta varsa ve kalan stok miktarı satılandan büyükse hata döner işlemi yapmaz
            var product  = _productQueryableRepository.Table.AsNoTracking().FirstOrDefault(x => x.ProductId == sale.ProductId);
            var userMail = _userQueryableRepository.Table.AsNoTracking().FirstOrDefault(x => x.UserId == getUserId);

            if (product == null || product.RemainingStockAmount < sale.AmountOfSales)
            {
                ErrorNotification($"Satış Gerçekleşemedi Sattığınız Ürün Miktarı Satabileceğinizden Fazla Gözüküyor! <br /> Satabileceğiniz Ürün Stoğu Miktarı:<strong> {product.RemainingStockAmount.ToString()}</strong>");
                return(RedirectToAction("Create"));
            }
            _saleService.Add(new Sale
            {
                UserId          = getUserId,
                InvoiceImage    = sale.InvoiceImage,
                InvoiceDate     = sale.InvoiceDate,
                AddDate         = DateTime.Now,
                AmountOfSales   = sale.AmountOfSales,
                InvoiceImageExt = ".png",
                InvoiceNo       = sale.InvoiceNo,
                ProductId       = sale.ProductId,
                CustomerId      = sale.CustomerId,
                InvoiceTotal    = sale.InvoiceTotal
            });

            _productService.Update(new Product
            {
                ProductName         = product.ProductName,
                CriticalStockAmount = product.CriticalStockAmount,
                Point                = product.Point,
                PointToMoney         = product.PointToMoney,
                ProductCode          = product.ProductCode,
                ProductShortCode     = product.ProductShortCode,
                StockAmount          = product.StockAmount,
                UnitTypeId           = product.UnitTypeId,
                RemainingStockAmount = product.RemainingStockAmount - sale.AmountOfSales,
                ProductId            = sale.ProductId
            });
            var mailEnable = System.Configuration.ConfigurationManager.AppSettings["MailEnable"];

            if (mailEnable == "true")
            {
                var mail = MailHelper.SendMail(
                    $"{userMail.FirstName + " " + userMail.LastName} Tarafından {sale.InvoiceNo} Fatura Numarasıyla Yeni Bir Satış Gerçekleştirildi.<br/> Lütfen bayipuan.com üzerinde takip ediniz.",
                    $"*****@*****.**", "Yeni Bir Satış Yapıldı!", true);
                if (mail)
                {
                    SuccessNotification("Mail Gönderildi");
                }
                else
                {
                    ErrorNotification("Mail Gönderilemedi!");
                }
            }

            SuccessNotification("Kayıt Eklendi. Yönetici Onayından Sonra Puan Kazanacaksınız!");
            return(RedirectToAction("SaleIndex"));
        }