Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Cantidad,PNETO,PVP,ProductID,InputID")] InputDetail inputDetail, int?ID, string tipo, string serie, string num)
        {
            //if (ID != null)
            //{

            //    var inputID = await _context.Inputs
            //                         .Where(i => i.Tipo_Comprobante == tipo && i.serie_comprobante == serie && i.num_comprobante == num)
            //                         .SingleAsync();


            //}


            if (ModelState.IsValid)
            {
                _context.Add(inputDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Inputs"));
                //return RedirectToAction(nameof(Index));
            }
            // ViewData["InputID"] = new SelectList(_context.Inputs, "InputID", "InputID", inputDetail.InputID);
            //  ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Description", inputDetail.ProductID);
            populateProductDropDownList();
            populateInputsDropDownList();
            return(RedirectToAction("Create", "Inputs"));
            //return View(inputDetail);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("FirstMidName,LastName,HighDate,Email,TipoDocumento,NumDocumento,Direccion,Telefono")] SaleMan saleMan)
        {
            if (ModelState.IsValid)
            {
                _context.Add(saleMan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(saleMan));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("FirstMidName,LastName,HighDate,Email,TipoDocumento,NumDocumento,Direccion,Telefono,CategoryID")] Provider provider)
        {
            if (ModelState.IsValid)
            {
                _context.Add(provider);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryName", provider.CategoryID);
            return(View(provider));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ProductName,Description,ImagePath,Codigo,Stock,CategoryID")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            PopulateCategoriesDropDownList();
            // ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryName", product.CategoryID);
            return(View(product));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Cantidad,PVP,Descuento,SaleID,ProductID")] SaleDetail saleDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(saleDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Sales"));
                //return RedirectToAction(nameof(Index));
            }
            //ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Description", saleDetail.ProductID);
            //ViewData["SaleID"] = new SelectList(_context.Sales, "ID", "ID", saleDetail.SaleID);
            populateProductDropDownList();
            populateSalesDropDownList();
            return(RedirectToAction("Create", "Sales"));
            //return View(saleDetail);
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Tipo_Comprobante,serie_comprobante,num_comprobante,Impuesto,ProviderID")] Input input,

                                                 string[] selectedProducts, string[] selectedCants, string[] selectedPNETOs, string[] selectedPVPs)
        {
            if (selectedProducts == null)
            {
                return(NotFound());
            }
            if (selectedCants == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedCants[i] = "10";
                }
            }
            if (selectedPNETOs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedPNETOs[i] = "100";
                }
            }
            if (selectedPVPs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedPVPs[i] = "200";
                }
            }


            input.InputDetails = new List <InputDetail>();
            int j = 0;

            CultureInfo provider = new CultureInfo("es-ES");

            //NumberStyles style = NumberStyles.AllowDecimalPoint; //| NumberStyles.AllowCurrencySymbol; //| NumberStyles.AllowThousands;

            foreach (var product in selectedProducts)
            {
                var productToAdd = new InputDetail
                {
                    InputID   = input.InputID,
                    ProductID = int.Parse(product),
                    Cantidad  = int.Parse(selectedCants[j]),//,style, CultureInfo.CurrentCulture),
                    PNETO     = decimal.Parse(selectedPNETOs[j], CultureInfo.InvariantCulture),
                    //PNETO= System.Convert.ToDecimal(selectedPNETOs[j], provider), //Fallo aquí en conversión
                    PVP = decimal.Parse(selectedPVPs[j], CultureInfo.InvariantCulture)//,style, provider),// CultureInfo.CurrentCulture)
                };
                input.InputDetails.Add(productToAdd);
                foreach (var detalle in input.InputDetails)
                {
                    // total += detalle.TotalParcial;
                    input.TotalInput += detalle.Cantidad * (decimal)detalle.PNETO;
                }
                input.Fecha_hora = DateTime.Now;
                //var productToUpdate = _context.Products.Where(p => p.ProductID == int.Parse(product));
                var productToUpdate = _context.Products.Where(p => p.ProductID == int.Parse(product)).Single();
                productToUpdate.Stock += int.Parse(selectedCants[j]);

                j++;

                if (await TryUpdateModelAsync <Product>(productToUpdate, "",
                                                        s => s.Stock))
                {
                    try
                    {
                        if (ModelState.IsValid)
                        {
                            _context.Add(input);
                            await _context.SaveChangesAsync();

                            return(RedirectToAction(nameof(Index)));
                        }
                        //await _context.SaveChangesAsync();
                        //return RedirectToAction(nameof(Index));
                    }
                    catch (DbUpdateException /* ex */)
                    {
                        //Log the error (uncomment ex variable name and write a log.)
                        ModelState.AddModelError("", "Unable to save changes. " +
                                                 "Try again, and if the problem persists, " +
                                                 "see your system administrator.");
                    }
                }
            }

            //input.Impuesto = decimal.Parse( igic);
            //input.TotalInput = SubTotal * decimal.Parse(igic);
            //input.TotalInput =  SubTotal * input.Impuesto;//¿? +subtotal

            //try
            //{
            //    if (ModelState.IsValid)
            //    {
            //
            //        _context.Add(input);
            //        await _context.SaveChangesAsync();
            //        return RedirectToAction(nameof(Index));
            //    }
            //}
            //catch (DbUpdateException /* ex */)
            //{
            //    //Log the error (uncomment ex variable name and write a log.)
            //    ModelState.AddModelError("", "Unable to save changes. " +
            //        "Try again, and if the problem persists, " +
            //        "see your system administrator.");
            //}


            //ViewData["ProviderID"] = new SelectList(_context.Providers, "ProviderID", "FirstMidName", input.ProviderID);
            PopulateProvidersDropDownList(input.ProviderID);
            populateProductDropDownList();
            return(View(input));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Tipo_Comprobante,Serie_comprobante,Num_comprobante,Impuesto,Estado,CustomerID,SaleManID")] Sale sale,
                                                 string[] selectedProducts, string[] selectedCants, string[] selectedDTOs, string[] selectedPVPs)
        {
            if (selectedProducts == null)
            {
                return(NotFound());
            }
            if (selectedCants == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedCants[i] = "10";
                }
            }
            if (selectedDTOs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedDTOs[i] = "5";
                }
            }
            if (selectedPVPs == null)
            {
                for (int i = 0; i < selectedProducts.Length; i++)
                {
                    selectedPVPs[i] = "200";
                }
            }

            Product prod = new Product();

            sale.SaleDetails = new List <SaleDetail>();
            int j        = 0;
            var SubTotal = 0.00m;

            foreach (var product in selectedProducts)
            {
                prod = _context.Products.Where(p => p.ProductID == int.Parse(product)).Single();
                prod.Stock++;
                var productToAdd = new SaleDetail {
                    SaleID = sale.ID, ProductID = int.Parse(product), Cantidad = int.Parse(selectedCants[j]), Descuento = decimal.Parse(selectedDTOs[j], CultureInfo.InvariantCulture), PVP = decimal.Parse(selectedPVPs[j], CultureInfo.InvariantCulture)
                };


                sale.SaleDetails.Add(productToAdd);
                SubTotal += productToAdd.TotalParcial;


                j++;
            }

            // pon la
            foreach (var detalle in sale.SaleDetails)
            {
                // total += detalle.TotalParcial;
                sale.TotalSale += detalle.Cantidad * (decimal)(detalle.PVP - detalle.Descuento);  //pvp y aplicado dto¿?
            }

            sale.Fecha_Hora = DateTime.Now;



            try
            {
                if (ModelState.IsValid)
                {
                    // _context.Add(prod);
                    _context.Add(sale);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists, " +
                                         "see your system administrator.");
            }


            //ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "FirstMidName", sale.CustomerID);
            //ViewData["SaleManID"] = new SelectList(_context.SaleMans, "SaleManID", "FirstMidName", sale.SaleManID);

            PopulatePersonsDropDownList(sale.CustomerID, sale.SaleManID);
            populateProductDropDownList();
            return(View(sale));
        }