Ejemplo n.º 1
0
 public crudController(ClienteCRUD servicioCliente, ProductoCRUD servicioProducto, ProveedorCRUD servicioProveedor, facturaciones servicioFactura, entradas servicioEntrada)
 {
     _servicioCliente   = servicioCliente;
     _servicioProducto  = servicioProducto;
     _servicioProveedor = servicioProveedor;
     _servicioEntrada   = servicioEntrada;
     _servicioFactura   = servicioFactura;
 }
Ejemplo n.º 2
0
 public busquedasController(ClienteCRUD servicioCliente, facturaciones servicioFacturacion, entradas servicioEntradas, ProductoCRUD servicioProducto, ProveedorCRUD servicioProveedor)
 {
     _servicioCliente     = servicioCliente;
     _servicioProducto    = servicioProducto;
     _servicioProveedor   = servicioProveedor;
     _servicioEntradas    = servicioEntradas;
     _servicioFacturacion = servicioFacturacion;
 }
        public ActionResult Procesar(UsuarioInfoCompraViewModel compraVM)
        {
            UnidadDeTrabajo <productos>             unidad_productos             = new UnidadDeTrabajo <productos>(new BDContext());
            UnidadDeTrabajo <facturaciones>         unidad_facturaciones         = new UnidadDeTrabajo <facturaciones>(new BDContext());
            UnidadDeTrabajo <usuario_facturaciones> unidad_usuario_facturaciones = new UnidadDeTrabajo <usuario_facturaciones>(new BDContext());
            UnidadDeTrabajo <facturacion_producto>  unidad_facturacion_producto  = new UnidadDeTrabajo <facturacion_producto>(new BDContext());
            BDContext context = new BDContext();

            try
            {
                // obtener el id del usuario que esta logueado
                var userID = User.Identity.GetUserId();

                // obtener el usuario con ese id de base de datos
                var usuario_BD = context.usuarios.Where(u => u.Usuario_ID.Equals(userID)).Single();

                // obtener todos los productos en su carrito
                List <sp_obtenerProductosUsuarioCarrito_Result> lista_productos_cliente = context.sp_obtenerProductosUsuarioCarrito(usuario_BD.userId).ToList();
                productos producto_BD;

                // calcular total y subtotal
                double total = 0, subtotal = 0, impuesto = 0.13;
                foreach (var producto in lista_productos_cliente)
                {
                    producto_BD = unidad_productos.genericDAL.Get(producto.productoId);
                    subtotal   += (double)(producto.cantidad_producto * producto_BD.precio);
                }
                impuesto = impuesto * subtotal;
                total    = subtotal + impuesto;

                // obtener el siguiente id de facturaciones
                sp_obtenerUltimoIdFactura_Result2 id_factura = context.sp_obtenerUltimoIdFactura().FirstOrDefault();

                // crear una nueva factura
                facturaciones factura = new facturaciones
                {
                    nombre    = compraVM.nombre_tarjeta,
                    fecha     = DateTime.UtcNow,
                    impuesto  = 13,
                    subtotal  = subtotal,
                    total     = total,
                    id_estado = 2
                };

                // agregar factura

                unidad_facturaciones.genericDAL.Add(factura);
                unidad_facturaciones.Complete();

                // asignar factura a usuario

                usuario_facturaciones factura_usuario = new usuario_facturaciones
                {
                    usuarioId     = usuario_BD.userId,
                    facturacionId = (int)id_factura.Column1,
                    id_estado     = 2
                };
                unidad_usuario_facturaciones.genericDAL.Add(factura_usuario);
                unidad_usuario_facturaciones.Complete();

                // asignar productos a factura

                /*facturacion_producto facturacion_producto;
                 * List<facturacion_producto> lista_facturaciones_producto = new List<facturacion_producto>();*/

                IProductosFacturacionDAL productosFacturacionDAL = new ProductosFacturacionDALImpl();

                sp_obtenerFacturacionesProducto_Result facturacionProducto;
                foreach (var producto in lista_productos_cliente)
                {
                    /*facturacion_producto = new facturacion_producto
                     * {
                     *  productoId = producto.productoId,
                     *  cantidad = producto.cantidad_producto,
                     *  id_estado = 2,
                     *  facturacionId = (int)id_factura.Column1,
                     * };
                     * lista_facturaciones_producto.Add(facturacion_producto);*/

                    facturacionProducto = new sp_obtenerFacturacionesProducto_Result
                    {
                        productoId    = producto.productoId,
                        facturacionId = (int)id_factura.Column1,
                        cantidad      = producto.cantidad_producto,
                        id_estado     = 2
                    };

                    productosFacturacionDAL.agregarProductoFacturacion(facturacionProducto);
                }

                //generar factura PDF

                generarFactura((int)id_factura.Column1);


                /* unidad_facturacion_producto.genericDAL.AddRange(lista_facturaciones_producto);
                 * unidad_facturacion_producto.Complete();
                 */
                // limipar el carrito del usuario
                context.sp_eliminarCarritoCliente(usuario_BD.userId);

                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
        public void generarFactura(int idfactura)
        {
            List <facturacion_producto> productosFacturacion;
            List <productos>            productos;
            List <facturaciones>        facturaciones;

            //lista productos por facturacion
            using (UnidadDeTrabajo <facturacion_producto> unidad = new UnidadDeTrabajo <facturacion_producto>(new BDContext()))
            {
                productosFacturacion = unidad.genericDAL.GetAll().ToList();
            }

            //lista productos
            using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext()))
            {
                productos = unidad.genericDAL.GetAll().ToList();
            }

            //lista factruaciones
            using (UnidadDeTrabajo <facturaciones> unidad = new UnidadDeTrabajo <facturaciones>(new BDContext()))
            {
                facturaciones = unidad.genericDAL.GetAll().ToList();
            }


            //objeto producto
            productos producto = new productos();

            //objeto facturaciones
            facturaciones facturacion = new facturaciones();

            using (UnidadDeTrabajo <facturaciones> unidad = new UnidadDeTrabajo <facturaciones>(new BDContext()))
            {
                facturacion = unidad.genericDAL.Get(idfactura);
            }
            var Renderer = new HtmlToPdf();

            var html = @" 
                    <!doctype html>
                    <html>
                    <head>
                        <meta charset=""utf-8"">
                          <title> Factura </title>
  
                          <style>
                            .invoice-container {
                                max-width: 800px;
                                margin: auto;
                                padding: 30px;
                                border: 1px solid #eee;
                                box-shadow: 0 0 10px rgba(0, 0, 0, .15);
                                font-size: 16px;
                                line-height: 24px;
                                font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;
                                color: #555;
                            }

                                .invoice-container table {
                                    width: 100%;
                                    line-height: inherit;
                                    text-align: left;
                                }

                                    .invoice-container table td {
                                        padding: 5px;
                                        vertical-align: top;
                                    }

                                    .invoice-container table tr td:nth-child(2) {
                                        text-align: right;
                                    }

                                    .invoice-container table tr.top table td {
                                        padding-bottom: 20px;
                                    }

                                        .invoice-container table tr.top table td.title {
                                            font-size: 45px;
                                            line-height: 45px;
                                            color: #333;
                                        }

                                    .invoice-container table tr.information table td {
                                        padding-bottom: 40px;
                                    }

                                    .invoice-container table tr.heading td {
                                        background: #eee;
                                        border-bottom: 1px solid #ddd;
                                        font-weight: bold;
                                    }

                                    .invoice-container table tr.details td {
                                        padding-bottom: 20px;
                                    }

                                    .invoice-container table tr.item td {
                                        border-bottom: 1px solid #eee;
                                    }

                                    .invoice-container table tr.item.last td {
                                        border-bottom: none;
                                    }

                                    .invoice-container table tr.total td:nth-child(2) {
                                        border-top: 2px solid #eee;
                                        font-weight: bold;
                                    }

                            @@media only print {
                                .invoice-container table tr.top table td {
                                    width: 100%;
                                    display: block;
                                    text-align: center;
                                }

                                .invoice-container table tr.information table td {
                                    width: 100%;
                                    display: block;
                                    text-align: center;
                                }
                            }
                        </style>
                         </head>
                     <body>
                        <div class=""invoice-container"">
                                <table cellpadding=""0"" cellspacing =""0"">
     
                                    <tr class=""top"">
                                        <td colspan=""2"">
                                            <table>
                                                <tr>
                                                    <td class=""title"">
                                                        [email protected]
                                                    </td>
                                                    <td>
                                                        Numero de Factura:" + idfactura + @"<br>
                                                        Fecha de la compra:" + facturacion.fecha + @"<br>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                </tr>
                                <tr class=""information"">
                                    <td colspan= ""2"">
                                        <table>
                                            <tr>
                                                <td>
                                                    Amaz@n Cr, Inc.<br>
                                                    Rohmoser Pavas<br>
                                                    San Jose , Costa Rica
                                                    
                                                </td>
                                                <td>
                                                    2295-4909 <br>
                                                    Dudas o consultas : [email protected]
                                                </td>
                                            </tr>
                                        </table>
                                     </td>
                                 </tr>
 
                                <tr class=""heading"">
                                    <td>
                                        Nombre del Producto
                                    </td>
                                    <td>
                                        Cantidad
                                    </td>
                                    <td>Precio</td>
                                </tr>";


            foreach (var itemProductoFacturacion in productosFacturacion)
            {
                if (itemProductoFacturacion.id_estado == 1)
                {
                    continue;
                }
                else
                {
                    if (itemProductoFacturacion.facturacionId == idfactura)
                    {
                        //facturaciones

                        foreach (var itemFacturaciones in facturaciones)
                        {
                            if (itemFacturaciones.facturacionId == itemProductoFacturacion.facturacionId)
                            {
                                facturacion = new facturaciones
                                {
                                    facturacionId = itemFacturaciones.facturacionId,
                                    nombre        = itemFacturaciones.nombre,
                                    total         = itemFacturaciones.total,
                                    subtotal      = itemFacturaciones.subtotal
                                };
                            }
                        }

                        //productos
                        foreach (var itemProducto in productos)
                        {
                            if (itemProducto.productoId == itemProductoFacturacion.productoId)
                            {
                                producto = new productos
                                {
                                    productoId = itemProducto.productoId,
                                    nombre     = itemProducto.nombre,
                                    precio     = itemProducto.precio
                                };

                                html += @"<tr class=""item"">
                                            <td>" + producto.nombre + @"</td>
                                            <td>" + itemProductoFacturacion.cantidad + @"</td>
                                            <td>" + producto.precio + @"</td>
                                        </tr>";
                            }
                        }
                    }
                }
            }

            html += @"
                                <br><br>
                                <tr class=""total"">
                                    <td></td>
                                    <td>IVA:</td>
                                    <td>13%</td>
                                </tr>
                                <tr class=""total"">
                                    <td></td>
                                    <td>Subtotal:</td>
                                    <td>" + facturacion.subtotal + @"</td>

                                </tr>
                                <tr class=""total"">
                                    <td></td>
                                    <td>Total:</td>
                                    <td>" + facturacion.total + @"</td>

                                </tr>


                           </table>
                       </div>
                    </body>
                    </html>

                    ";

            /*  FacturacionPDF facturacionPDF;
             *
             * facturacionPDF = new FacturacionPDF
             * {
             *    nombreProducto = producto.nombre,
             *    idFacturacion = facturacion.facturacionId,
             *    nombreFactura = facturacion.nombre,
             *    subtotal = facturacion.subtotal,
             *    precio = producto.precio,
             *    fecha = facturacion.fecha
             * };
             *
             * List<FacturacionPDF> facturacionesPDF = new List<FacturacionPDF>();
             * facturacionesPDF.Add(facturacionPDF);*/


            var PDF = Renderer.RenderHtmlAsPdf(html);

            // save resulting pdf into file
            PDF.SaveAs("~/Content/dist/facturacionesPDF/" + facturacion.nombre + facturacion.facturacionId + ".pdf");
        }
        // GET: FacturacionProductos
        public ActionResult Index(int id)
        {
            List <facturacion_producto> productosFacturacion;
            List <productos>            productos;
            List <facturaciones>        facturaciones;

            //lista productos por facturacion
            using (UnidadDeTrabajo <facturacion_producto> unidad = new UnidadDeTrabajo <facturacion_producto>(new BDContext()))
            {
                productosFacturacion = unidad.genericDAL.GetAll().ToList();
            }

            //lista productos
            using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext()))
            {
                productos = unidad.genericDAL.GetAll().ToList();
            }

            //lista factruaciones
            using (UnidadDeTrabajo <facturaciones> unidad = new UnidadDeTrabajo <facturaciones>(new BDContext()))
            {
                facturaciones = unidad.genericDAL.GetAll().ToList();
            }

            //lista view model facturacion productos
            List <FacturacionProductosViewModels> productoVM = new List <FacturacionProductosViewModels>();

            //objeto facturacion producto view models
            FacturacionProductosViewModels facturacion_Producto;

            //objeto producto
            productos producto = new productos();

            //objeto facturaciones
            facturaciones facturacion = new facturaciones();


            foreach (var item in productosFacturacion)
            {
                if (item.id_estado == 1)
                {
                    continue;
                }
                else
                {
                    if (item.facturacionId == id)
                    {
                        //facturaciones

                        foreach (var itemFacturaciones in facturaciones)
                        {
                            if (itemFacturaciones.facturacionId == item.facturacionId)
                            {
                                facturacion = new facturaciones
                                {
                                    facturacionId = itemFacturaciones.facturacionId,
                                    nombre        = itemFacturaciones.nombre,
                                };
                            }
                        }

                        //productos
                        foreach (var itemProducto in productos)
                        {
                            if (itemProducto.productoId == item.productoId)
                            {
                                producto = new productos
                                {
                                    productoId = itemProducto.productoId,
                                    nombre     = itemProducto.nombre,
                                    precio     = itemProducto.precio
                                };
                            }
                        }

                        //facturacion productos
                        facturacion_Producto = new FacturacionProductosViewModels
                        {
                            facturacionId = facturacion.facturacionId,
                            nombre        = facturacion.nombre,
                            productoId    = producto.productoId,
                            nombre1       = producto.nombre,
                            precio        = producto.precio,
                            cantidad      = item.cantidad
                        };
                        productoVM.Add(facturacion_Producto);
                    }
                    id_promocion = id;
                }
            }
            return(View("~/Views/Admin/FacturacionProductosAdmin/Index.cshtml", productoVM));
        }
        // GET: VentasAdmin
        public ActionResult Index()
        {
            List <facturacion_producto> productosFacturacion;
            List <productos>            productos;
            List <facturaciones>        facturaciones;

            //lista productos por facturacion
            using (UnidadDeTrabajo <facturacion_producto> unidad = new UnidadDeTrabajo <facturacion_producto>(new BDContext()))
            {
                productosFacturacion = unidad.genericDAL.GetAll().ToList();
            }

            //lista productos
            using (UnidadDeTrabajo <productos> unidad = new UnidadDeTrabajo <productos>(new BDContext()))
            {
                productos = unidad.genericDAL.GetAll().ToList();
            }

            //lista factruaciones
            using (UnidadDeTrabajo <facturaciones> unidad = new UnidadDeTrabajo <facturaciones>(new BDContext()))
            {
                facturaciones = unidad.genericDAL.GetAll().ToList();
            }

            //lista view model facturacion productos
            List <VentasViewModel> ventasVM = new List <VentasViewModel>();

            //objeto facturacion producto view models
            VentasViewModel ventaVM;

            //objeto producto
            productos producto = new productos();

            //objeto facturaciones
            facturaciones facturacion = new facturaciones();

            foreach (var itemProductoFacturacion in productosFacturacion)
            {
                //facturaciones

                foreach (var itemFacturaciones in facturaciones)
                {
                    if (itemFacturaciones.facturacionId == itemProductoFacturacion.facturacionId)
                    {
                        facturacion = new facturaciones
                        {
                            facturacionId = itemFacturaciones.facturacionId,
                            fecha         = itemFacturaciones.fecha
                        };
                    }
                }

                //productos
                foreach (var itemProducto in productos)
                {
                    if (itemProducto.productoId == itemProductoFacturacion.productoId)
                    {
                        producto = new productos
                        {
                            productoId = itemProducto.productoId,
                            nombre     = itemProducto.nombre,
                            precio     = itemProducto.precio
                        };
                    }
                }

                //facturacion productos
                ventaVM = new VentasViewModel
                {
                    facturacionId = facturacion.facturacionId,
                    productoId    = producto.productoId,
                    nombre        = producto.nombre,
                    cantidad      = itemProductoFacturacion.cantidad,
                    precio        = producto.precio,
                    fecha         = facturacion.fecha
                };
                ventasVM.Add(ventaVM);
            }
            return(View("~/Views/Admin/VentasAdmin/Index.cshtml", ventasVM));
        }