public detalleReporteExistenciasProducto(Maestro Ms, DateTime inicio, DateTime termino)
 {
     // TODO: Complete member initialization
     this.ProductoID = Ms.ProductoID;
     this.descripcionProducto = Ms.descripcionProducto;
     this.MaestroID = Ms.MaestroID.ToString();
     this.fechaMaestro = Ms.fecha;
     this.Inicio = inicio;
     this.Termino = termino;
     this.stockIngresado = Ms.cantidadEntrante;
     this.stockSaliente = Ms.cantidadSaliente;
 }
 public detalleReporteExistenciasProducto(Maestro Ms, DateTime inicio, DateTime termino)
 {
     // TODO: Complete member initialization
     this.ProductoID          = Ms.ProductoID;
     this.descripcionProducto = Ms.descripcionProducto;
     this.MaestroID           = Ms.MaestroID.ToString();
     this.fechaMaestro        = Ms.fecha;
     this.Inicio         = inicio;
     this.Termino        = termino;
     this.stockIngresado = Ms.cantidadEntrante;
     this.stockSaliente  = Ms.cantidadSaliente;
 }
Esempio n. 3
0
        private void importarMaestros()
        {
            string fileLocation = Server.MapPath("~/Content/stock.xls");


            string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
            fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\"";

            excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
            fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";

            OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);


            string nombreHoja = "registro$";
            string strSQL = "SELECT * FROM [" + nombreHoja + "]";

            OleDbDataAdapter da = new OleDbDataAdapter(strSQL, excelConnection);
            DataSet ds = new DataSet();

            da.Fill(ds);
            int i = 992;
            
            RentaMaq.DAL.Context db = new DAL.Context();
            while (i<=1116)
            {
                Maestro maestro = new Maestro();
                DateTime fecha = Formateador.fechaStringToDateTime(Convert.ToString(ds.Tables[0].Rows[i].ItemArray[0]));
                string numeroParte = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[1]);
                string descripcion = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[2]);
                string unidad = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[3]);
                string entrada = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[4]);
                string salida = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[5]);
                string proveedor = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[6]);
                string preciounitario = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[7]);
                string preciototal = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[8]);
                string entregado = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[9]);
                string afi = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[10]);
                string observaciones = Convert.ToString(ds.Tables[0].Rows[i].ItemArray[11]);


                double cantidadEntrante = 0;
                double cantidadSaliente = 0;

                if (entrada.Equals(""))
                {
                    cantidadSaliente = Convert.ToDouble(salida);
                }
                else {

                    cantidadEntrante = Convert.ToDouble(entrada);
                }
                int precioUnitario = 0;
                int precioTotal = 0;
                if (!preciounitario.Equals("")) {
                    precioUnitario = Convert.ToInt32(preciounitario.Replace(",",""));

                }
                if (!preciototal.Equals("")) {
                    precioTotal = Convert.ToInt32(Math.Floor(double.Parse(preciototal.Replace(",", ""))));
                }

                if (proveedor.Equals(""))
                {
                    proveedor = "0";
                }
                else {
                    if (proveedor.Trim().Equals("SALFA"))
                    {
                        proveedor = "18";
                    }
                    else
                    {
                        Proveedor proveedorBuscar = db.Proveedores.Where(s => s.nombreProveedor.Contains(proveedor.Trim())).ToList()[0];
                        proveedor = proveedorBuscar.ProveedorID.ToString();
                    }
                }

                Producto producto = db.Productos.SingleOrDefault(s => s.numeroDeParte == numeroParte && s.descripcion == descripcion);
                maestro.fecha = fecha;
                if (producto != null)
                {
                    maestro.ProductoID = Convert.ToString(producto.ProductoID);
                }
                else {
                    producto = db.Productos.SingleOrDefault(s => s.numeroDeParte == numeroParte);
                    if (producto != null)
                    {
                        maestro.ProductoID = Convert.ToString(producto.ProductoID);
                    }
                    else
                    {
                        //INGRESAR PRODUCTO
                        Producto nuevoProducto = new Producto();
                        nuevoProducto.numeroDeParte = numeroParte;
                        nuevoProducto.idBodega = 1;
                        nuevoProducto.descripcion = descripcion;
                        nuevoProducto.unidadDeMedida = unidad;

                        db.Productos.Add(nuevoProducto);
                        db.SaveChanges();

                        maestro.ProductoID = nuevoProducto.ProductoID.ToString();

                    }   
                }                
                maestro.descripcionProducto = descripcion;
                maestro.cantidadEntrante = cantidadEntrante;
                maestro.cantidadSaliente = cantidadSaliente;
                maestro.proveedor = proveedor;
                maestro.valorUnitario = precioUnitario;
                maestro.valorTotal = precioTotal;
                maestro.entragadoA = entregado;
                maestro.afiEquipo = afi;
                maestro.observaciones = observaciones;


                 i++;
                db.Maestros.Add(maestro);
            }
            db.SaveChanges();
        }
        public ActionResult generarOTTrabajoPendiente([Bind(Include = "ordenDeTrabajoGeneralID,fechaOTAbierta,fechaOTCerrada,operador,faena,turno,idEquipo,horometro,kilometraje,tipoMantenimientoARealizar,horasMantenimientoNivelCombustible,horasMantenimientoFecha,horasMantenimientoHRInicio,horasMantenimientoHRTermino,horasMantenimientoHRSDetenido,trabajoRealizar,conclusionesTrabajoRealizado,estadoEquipo,trabajosPendientesPorRealizar,fechaTrabajosPendientesPorRealizar,numeroFolio,area,nombreMantenedor,nombreOperador,nombreSupervisor,tipoOTSegunMantenimiento, IDOTAnterior")] ordenDeTrabajoGeneral ordenDeTrabajoGeneral, 
            FormCollection form, HttpPostedFileBase file)
        {
            if (Session["ID"] == null || !roles.tienePermiso(numeroPermiso, int.Parse(Session["ID"].ToString())))
            {
                return RedirectToAction("Index", "Home");
            }
            ordenDeTrabajoGeneral.fechaOTAbierta = Formateador.fechaFormatoGuardar((string)form["fechaOTAbierta"]);
            ordenDeTrabajoGeneral.fechaOTCerrada = Formateador.fechaFormatoGuardar((string)form["fechaOTCerrada"]);
            ordenDeTrabajoGeneral.horasMantenimientoFecha = Formateador.fechaFormatoGuardar((string)form["horasMantenimientoFecha"]);
            ordenDeTrabajoGeneral.fechaTrabajosPendientesPorRealizar = Formateador.fechaFormatoGuardar((string)form["fechaTrabajosPendientesPorRealizar"]);

            equipos equipo = equipos.ObtenerConTipo(Convert.ToInt32(ordenDeTrabajoGeneral.idEquipo));
            ordenDeTrabajoGeneral.patenteEquipo = equipo.patenteEquipo;
            ordenDeTrabajoGeneral.tipoEquipo = equipo.tipoEquipo;
            ordenDeTrabajoGeneral.verificarTrabajoPendiente = "FALSE";

            ordenDeTrabajoGeneral anterior = db.ordenDeTrabajoGenerals.Find(ordenDeTrabajoGeneral.IDOTAnterior);
            anterior.verificarTrabajoPendiente = "TRUE";

            db.Entry(anterior).State = EntityState.Modified;

            db.ordenDeTrabajoGenerals.Add(ordenDeTrabajoGeneral);
            db.SaveChanges();

            int idOT = ordenDeTrabajoGeneral.ordenDeTrabajoGeneralID;
            string[] ejecutantesDelTrabajo = Request.Form.GetValues("ejecutanteDelTrabajo");
            string[] cargo = Request.Form.GetValues("cargo");
            string[] HH = Request.Form.GetValues("HH");
            for (int i = 0; i < ejecutantesDelTrabajo.Length; i++)
            {
                ejecutanteTrabajoOT ejecutanteTrabajoOT = new ejecutanteTrabajoOT();
                ejecutanteTrabajoOT.ordenDeTrabajoGeneralID = idOT;
                ejecutanteTrabajoOT.nombreTrabajador = ejecutantesDelTrabajo[i];
                ejecutanteTrabajoOT.cargo = cargo[i];
                if (HH[i].Equals(""))
                {
                    ejecutanteTrabajoOT.HH = 0;
                }
                else
                {
                    ejecutanteTrabajoOT.HH = Convert.ToInt32(HH[i]);
                }

                db.ejecutanteTrabajoOTs.Add(ejecutanteTrabajoOT);
            }







            string[] materialUtilizado = Request.Form.GetValues("materialUtilizado");
            string[] matUtcantidad = Request.Form.GetValues("matUtcantidad");
            string[] matUtNumeroParte = Request.Form.GetValues("matUtNumeroParte");
            if (!materialUtilizado[0].Equals(""))
            {


                for (int i = 0; i < materialUtilizado.Length; i++)
                {
                    materialesUtilizadosOT materialesUtilizadosOT = new materialesUtilizadosOT();
                    materialesUtilizadosOT.ordenDeTrabajoGeneralID = idOT;
                    materialesUtilizadosOT.nombreMaterial = materialUtilizado[i];
                    materialesUtilizadosOT.cantidad = Convert.ToDouble(matUtcantidad[i]);
                    materialesUtilizadosOT.materialID = Convert.ToInt32(matUtNumeroParte[i]);
                    materialesUtilizadosOT.precioActual = db.Productos.Find(Convert.ToInt32(matUtNumeroParte[i])).precioUnitario;
                    db.materialesUtilizadosOTs.Add(materialesUtilizadosOT);


                    Maestro maestro = new Maestro();
                    maestro.afiEquipo = equipo.numeroAFI;
                    maestro.fecha = ordenDeTrabajoGeneral.horasMantenimientoFecha;
                    maestro.descripcionProducto = materialUtilizado[i];
                    maestro.cantidadEntrante = 0;
                    maestro.cantidadSaliente = Convert.ToDouble(matUtcantidad[i]);
                    maestro.idOT = idOT;
                    maestro.ProductoID = matUtNumeroParte[i];
                    maestro.observaciones = "Agregada Automaticamente de OT:" + ordenDeTrabajoGeneral.numeroFolio;

                    Producto producto = db.Productos.Find(int.Parse(maestro.ProductoID));
                    producto.stockActual = producto.stockActual - maestro.cantidadSaliente;
                    db.Entry(producto).State = EntityState.Modified;
                    db.Maestros.Add(maestro);

                }
            }
            //save

            string[] materialRequerido = Request.Form.GetValues("materialRequerido");
            string[] matReqCantidad = Request.Form.GetValues("matReqCantidad");
            string[] matReqNumeroParte = Request.Form.GetValues("matReqNumeroParte");



            if (!materialRequerido[0].Equals(""))
            {
                pedidos pedido = new pedidos();
                pedido.fecha = Formateador.formatearFechaCompleta(DateTime.Now);
                pedido.estado = "NUEVA";
                pedido.nota = "Agregado Automaticamente desde OT:" + ordenDeTrabajoGeneral.numeroFolio;
                pedido.idOT = idOT;
                db.pedidos.Add(pedido);
                db.SaveChanges();

                for (int i = 0; i < materialRequerido.Length; i++)
                {
                    materialesRequeridosOT materialesRequeridosOT = new materialesRequeridosOT();
                    materialesRequeridosOT.ordenDeTrabajoGeneralID = idOT;
                    materialesRequeridosOT.nombreMaterial = materialRequerido[i];
                    materialesRequeridosOT.cantidad = Convert.ToDouble(matReqCantidad[i]);
                    materialesRequeridosOT.materialID = Convert.ToInt32(matReqNumeroParte[i]);
                    materialesRequeridosOT.precioActual = db.Productos.Find(Convert.ToInt32(matReqNumeroParte[i])).precioUnitario;
                    db.materialesRequeridosOTs.Add(materialesRequeridosOT);

                    detallePedido detallePedido = new detallePedido();
                    detallePedido.cantidad = Convert.ToInt32(materialesRequeridosOT.cantidad);
                    detallePedido.descripcion = materialesRequeridosOT.nombreMaterial;
                    detallePedido.numeroParte = db.Productos.Find(materialesRequeridosOT.materialID).numeroDeParte;
                    detallePedido.pedidosID = pedido.pedidosID;
                    detallePedido.tipoPedido = "DIRECTA";
                    detallePedido.detalleTipoPedido = db.Equipos.Find(Convert.ToInt32(ordenDeTrabajoGeneral.idEquipo)).numeroAFI.ToString();
                    db.detallePedidos.Add(detallePedido);

                }
            }




            crearCarpetaSiNoExiste();
            string extImage = Convert.ToString(Request.Files["file"].ContentType);
            string[] infoImage = extImage.Split('/');
            string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName);
            string fileLocation = Server.MapPath("~/Images/OrdenTrabajo/") + ordenDeTrabajoGeneral.numeroFolio + "." + infoImage[1];
            if (!fileExtension.Equals(""))
            {
                Request.Files["file"].SaveAs(fileLocation);
                ordenDeTrabajoGeneral.rutaImagen = "Images/OrdenTrabajo/" + ordenDeTrabajoGeneral.numeroFolio + "." + infoImage[1];
            }

            registrokmhm registro = new registrokmhm();
            registro.equipoID = Convert.ToInt32(ordenDeTrabajoGeneral.idEquipo);
            registro.fecha = Formateador.fechaFormatoGuardar((string)form["fechaOTAbierta"]);
            registro.horometro = ordenDeTrabajoGeneral.horometro;
            registro.kilometraje = ordenDeTrabajoGeneral.kilometraje;
            //db.registrokmhms.Add(registro);
            registrokmhm.actualizarRegistroKmHm(registro);

            mantencionPreventiva mantecionPreventiva = new mantencionPreventiva();
            mantecionPreventiva.equipoID = Convert.ToInt32(ordenDeTrabajoGeneral.idEquipo);
            mantecionPreventiva.fecha = ordenDeTrabajoGeneral.horasMantenimientoFecha;
            mantecionPreventiva.horometroActual = ordenDeTrabajoGeneral.horometro;
            mantecionPreventiva.kilometrajeActual = ordenDeTrabajoGeneral.kilometraje;

            if (ordenDeTrabajoGeneral.horometro == 0)
            {
                mantecionPreventiva.horometroProximaMantencion = 0;
            }
            else
            {
                mantecionPreventiva.horometroProximaMantencion = ordenDeTrabajoGeneral.horometro + 400;
            }

            if (ordenDeTrabajoGeneral.kilometraje == 0)
            {
                mantecionPreventiva.kilometrajeProximaMantencion = 0;
            }
            else
            {
                mantecionPreventiva.kilometrajeProximaMantencion = ordenDeTrabajoGeneral.kilometraje + 10000;
            }

            mantecionPreventiva.nota = "Agregado Automaticamente desde OT N°:" + ordenDeTrabajoGeneral.numeroFolio;
            RentaMaq.Models.mantencionPreventiva.reemplazar(mantecionPreventiva);



            db.SaveChanges();

            return RedirectToAction("Index");
        }