예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["ID"] == null || !roles.tienePermiso(numeroPermiso, int.Parse(Session["ID"].ToString())))
            {
                return(RedirectToAction("Index", "Home"));
            }
            OrdenDeCompraGeneral ordenDeCompraGeneral = db.ordenesDeCompra.Find(id);

            db.ordenesDeCompra.Remove(ordenDeCompraGeneral);
            ordenDeCompraGeneral.eliminarDetalleBD();
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Edit([Bind(Include = "OrdenDeCompraGeneralID,fechaEntrega,formaRetiro,formaPago,subtotal,miscelaneos,totalNeto,IVA,total, añoOC, numeroOC, texto, tipo")] OrdenDeCompraGeneral ordenDeCompraGeneral,
                                 FormCollection post)
        {
            if (Session["ID"] == null || !roles.tienePermiso(numeroPermiso, int.Parse(Session["ID"].ToString())))
            {
                return(RedirectToAction("Index", "Home"));
            }
            //ordenDeCompraGeneral.añoOC = DateTime.Now.Year;
            //ordenDeCompraGeneral.obtenerNumeroOC();
            ordenDeCompraGeneral.estado      = db.ordenesDeCompra.Find(ordenDeCompraGeneral.OrdenDeCompraGeneralID).estado;
            ordenDeCompraGeneral.ProveedorID = db.Proveedores.Find(int.Parse(post["ProveedorID"].ToString()));

            if (string.IsNullOrEmpty(ordenDeCompraGeneral.ProveedorID.personaContacto1))
            {
                ordenDeCompraGeneral.atencionA = "--";
            }
            else
            {
                ordenDeCompraGeneral.atencionA = ordenDeCompraGeneral.ProveedorID.personaContacto1;
            }

            string fechaEntrega = post["fechaEntrega"].ToString();

            ordenDeCompraGeneral.fechaEntrega = new DateTime(int.Parse(fechaEntrega.Split('/')[2]),
                                                             int.Parse(fechaEntrega.Split('/')[1]), int.Parse(fechaEntrega.Split('/')[0]));

            string Fecha = post["Fecha"].ToString();

            ordenDeCompraGeneral.Fecha = new DateTime(int.Parse(Fecha.Split('/')[2]),
                                                      int.Parse(Fecha.Split('/')[1]), int.Parse(Fecha.Split('/')[0]));

            /*
             * string FechaVigencia = post["FechaVigencia"].ToString();
             *
             * ordenDeCompraGeneral.FechaVigencia = new DateTime(int.Parse(FechaVigencia.Split('/')[2]),
             *  int.Parse(FechaVigencia.Split('/')[1]), int.Parse(FechaVigencia.Split('/')[0]));
             * //*/
            //ordenDeCompraGeneral.obtenerID();

            ordenDeCompraGeneral.guardar();

            //Se guarda el detalle:
            string[] codigoDetalle             = Request.Form.GetValues("codigoDetalle");
            string[] cantidadDetalle           = Request.Form.GetValues("cantidadDetalle");
            string[] descripcionDetalle        = Request.Form.GetValues("descripcionDetalle");
            string[] tipoDeCompraDetalle       = Request.Form.GetValues("tipoDeCompraDetalle");
            string[] codigoInternoDetalleStock = Request.Form.GetValues("codigoInternoDetalleStock");
            string[] codigoInternoDetalle      = Request.Form.GetValues("codigoInternoDetalle");
            string[] plazoEntregaDetalle       = Request.Form.GetValues("plazoEntregaDetalle");
            string[] precioUnitarioDetalle     = Request.Form.GetValues("precioUnitarioDetalle");
            string[] descuentoDetalle          = Request.Form.GetValues("descuentoDetalle");
            string[] totalDetalle = Request.Form.GetValues("totalDetalle");

            ordenDeCompraGeneral.eliminarDetalleBD();

            for (int i = 0; i < codigoDetalle.Length; i++)
            {
                DetalleOrdenCompra detalle = new DetalleOrdenCompra();

                //detalle.DetalleOrdenCompraID =
                detalle.IDOrdenCompra = ordenDeCompraGeneral.OrdenDeCompraGeneralID;
                detalle.codigo        = codigoDetalle[i];
                detalle.cantidad      = double.Parse(cantidadDetalle[i].Replace(',', '.'));
                detalle.descripcion   = descripcionDetalle[i];
                detalle.tipoDeCompra  = tipoDeCompraDetalle[i];

                if (detalle.tipoDeCompra.Equals("Compra Directa"))
                {
                    detalle.codigoInternoRentamaq = codigoInternoDetalle[i];
                }
                else
                {
                    detalle.codigoInternoRentamaq = codigoInternoDetalleStock[i];
                }

                detalle.plazoEntrega        = int.Parse(plazoEntregaDetalle[i]);
                detalle.precioUnitario      = int.Parse(precioUnitarioDetalle[i]);
                detalle.descuento           = int.Parse(descuentoDetalle[i]);
                detalle.porcentajeDescuento = 0;
                detalle.valorTotal          = detalle.cantidad * (detalle.precioUnitario - detalle.descuento);
                detalle.obtenerID();
                detalle.guardar();
            }
            return(RedirectToAction("Index"));
        }