Exemplo n.º 1
0
        public ActionResult Create()
        {
            createInvoiceViewModel model = new createInvoiceViewModel();

            model.productList             = new productsListViewModel();
            model.ownProducts             = new productsListViewModel();
            model.productList.productList = new List <productsViewModel>();
            model.ownProducts             = _productService.getProductsList();
            return(View(model));
        }
Exemplo n.º 2
0
        private bool addNewInvoiceInformations(createInvoiceViewModel model)
        {
            decimal total               = 0,
                    totalTax            = 0,
                    grandTotal          = 0;
            bool     result             = true;
            invoices createInvoiceModel = new invoices();

            AutoMapper.Mapper.Map(model, createInvoiceModel);
            foreach (var item in model.productList.productList)
            {
                total    = total + item.price * item.count;
                totalTax = totalTax + ((item.price * item.count) * item.TaxRate) / 100;
            }
            grandTotal = grandTotal + (total + totalTax);
            createInvoiceModel.grandTotal = grandTotal;
            createInvoiceModel.taxPrice   = totalTax;
            createInvoiceModel.price      = total;
            db.invoices.Add(createInvoiceModel);
            if (db.SaveChanges() > 0)
            {
                int InvoiceId = createInvoiceModel.id;

                foreach (var item in model.productList.productList)
                {
                    invoiceProducts createInvoiceProductsModel = new invoiceProducts();
                    AutoMapper.Mapper.Map(item, createInvoiceProductsModel);
                    createInvoiceProductsModel.invoiceId  = InvoiceId;
                    createInvoiceProductsModel.productId  = item.id;
                    createInvoiceProductsModel.totalCount = item.count;
                    db.invoiceProducts.Add(createInvoiceProductsModel);
                }
                if (db.SaveChanges() > 0)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            else
            {
                result = false;
            }
            if (result)
            {
                model.totalPriceText = getTotalPriceText(model.grandTotal);
            }
            return(result);
        }
Exemplo n.º 3
0
        private bool checkConstract(createInvoiceViewModel model)
        {
            bool result = true;

            if (model.buyerAdress == null ||
                model.buyerName == null ||
                model.buyerSurname == null ||
                model.productList.productList.Count == 0 ||
                model.productList.productList.Where(w => w.price == 0 || w.TaxRate == 0 || w.count == 0).Count() > 0)
            {
                result = false;
            }
            return(result);
        }
Exemplo n.º 4
0
        public createInvoiceViewModel addNewInvoice(createInvoiceViewModel model)
        {
            model.result = true;
            if (!checkConstract(model))
            {
                model.result = false;
                return(model);
            }
            foreach (var item in model.productList.productList.Where(w => w.id == 0))
            {
                int itemAddResult = _productService.saveNewProduct(item);
                if (itemAddResult == 0)
                {
                    model.result = false;
                    return(model);
                }
                else
                {
                    item.id = itemAddResult;
                }
            }
            if (!addNewInvoiceInformations(model))
            {
                model.result = false;
            }

            if (model.productList.productList.Where(w => w.TaxRate == 18).Count() > 0)
            {
                model.taxRate = 18;
            }
            else
            {
                model.taxRate = model.productList.productList.Where(w => w.TaxRate == 18).FirstOrDefault().TaxRate;
            }
            if (model.productList.productList.Where(w => w.TaxRate == 8).Count() > 0)
            {
                model.taxRate2 = model.productList.productList.Where(w => w.TaxRate == 8).FirstOrDefault().TaxRate;
                foreach (var item in model.productList.productList.Where(w => w.TaxRate == model.taxRate2))
                {
                    model.taxPrice2 = model.taxPrice2 + (((item.price * item.count) * item.TaxRate) / 100);
                }
            }
            model.taxPrice = model.taxPrice - model.taxPrice2;

            return(model);
        }
Exemplo n.º 5
0
        public ActionResult Create(createInvoiceViewModel model)
        {
            model = _InvoicesService.addNewInvoice(model);
            if (!model.result)
            {
                ToastrService.AddToUserQueue("Kayıt sırasında bir hata oluşmuştur.", "Kuaför Store", Data.Enums.ToastrType.Error);
                model.ownProducts = new productsListViewModel();
                model.ownProducts = _productService.getProductsList();
                return(View(model));
            }

            return(new Rotativa.ViewAsPdf("Print", model)
            {
                PageOrientation = Rotativa.Options.Orientation.Landscape,
                PageSize = Rotativa.Options.Size.A4,
                PageMargins = new Rotativa.Options.Margins(0, 0, 0, 0)
            });
        }