Exemple #1
0
        public ActionResult facturarPedido(string Pedido, string fecha)
        {
            try
            {
                int IDPedido = int.Parse(Pedido);
                int idUser = (int)Session["userID"];
                DateTime FechaFac = DateTime.Parse(fecha);
                BIZDocumento pedido = DocWorker.ObtenerDocXID(IDPedido);

                BIZDocumento factura = new BIZDocumento();
                if (pedido.ClienteEmpresa.TipoIVA.Detalle == "Responsable Inscripto")
                {
                    factura.IDDocumentoTipo = 1; //tipo 1 es factura A.
                }
                else
                {
                    factura.IDDocumentoTipo = 13; // tipo 13 es factura B. Osea != de responsable inscripto. monotributista, exento, no categorizado, no responsable, consumidor final
                }
                factura.FechaEmision = FechaFac;
                factura.FechaUltimaModificacion = DateTime.Now;
                factura.IDClienteEmpresa = pedido.ClienteEmpresa.IDClienteEmpresa;
                factura.IDEstado = 9; //estado generada de factura 9
                factura.IDUsuarioCreacion = idUser;
                factura.IDUsuarioUltimaModificacion = idUser;
                factura.IDEmpresaLocal = 1;
                factura.IDDocumentoRef = IDPedido;
                //factura.NrDocumento = DocWorker.getLastNumberAndUpdate
                BIZDocumentoDetalle detalle;
                foreach (BIZDocumentoDetalle det in pedido.DocumentoDetalle)
                {
                    detalle = new BIZDocumentoDetalle();
                    detalle.Cantidad = det.Cantidad;
                    detalle.IDPrecioDetalle = det.IDPrecioDetalle;
                    factura.DocumentoDetalle.Add(det);
                }
                int IDDocNuevo = DocWorker.GuardarDocumentoFac(factura, pedido);

                //DocWorker.GuardarDocumento(factura);
                //DocWorker.ActualizarStatusDoc(IDPedido, 8, idUser); //8 es cancelado de pedido
                Nullable<int> idU = null;
                string ip = "Unknown";
                try { idU = (int)Session["userID"]; }
                catch (Exception ex) { }
                try { ip = Session["_ip"].ToString(); }
                catch (Exception ex) { }
                try
                {
                    Bita.guardarBitacora(new BIZBitacora("Informativo", "Factura nr#" + IDDocNuevo + " Generada. pedido nr#" + IDPedido, idU, ip));
                }
                catch (Exception ex) { }

                //mail
                BIZ.BIZCorreo correo = new BIZCorreo();
                correo.Subject = @Language.actualizacion;
                correo.To = pedido.ClienteEmpresa.Email;
                correo.cc = pedido.Usuario.Email;
                string link = "<a href='http://" + Request.Url.Host.ToLower() + ":" + Request.Url.Port + "/home/PDFMaker?odwidji32i324mu32u83257fm3209v5m320m392=u32hrwqduwqhdwqudhwqduwqdhwqduhwqudhwqudhwqud32hr32hrhf932hrn928v5u208m3f47&fghjhtyuighj=" + IDDocNuevo +"&32m3204c32094mqwdqwdwqdwqdwqd32=d4023123213213m'>Link</a>";
                string body = String.Format("<span>" + pedido.Usuario.Nombre + ",</span><br><span>" + @Language.facturaInfo + IDPedido + @Language.ingreseFact + link + "</span>");
                correo.Body = body;
                util.sendMail(correo);

                TempData["OKNormal"] = Resources.Language.OKNormal;
                return Json(new { Result = "" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                try
                {
                    Bita.guardarBitacora(new BIZBitacora("Error", "Error al originar la factura", null, null));
                }
                catch { }
                return Json(new { Result = "Error" }, JsonRequestBehavior.AllowGet);
            }
        }
Exemple #2
0
        public ActionResult GuardarCarrito()
        {
            try
            {
                var ListCarrito = (Session["ListCarrito"] as ListCarrito);
                BIZUsuario UsuarioIN = (BIZUsuario)Session["SUsuario"];
                BIZDocumentoDetalle detalle;
                if (ListCarrito.IDDocumento == 0) //es un PrePedido Nuevo
                {
                    var productosSesion = Session["productosSesion"];
                    var ListaP = (List<BIZProducto>)productosSesion;
                    BIZDocumento PrePedido = new BIZDocumento();
                    //Documento PrePedido = new Documento();
                    PrePedido.IDDocumentoTipo = 7;
                    PrePedido.FechaEmision = DateTime.Now;
                    PrePedido.FechaUltimaModificacion = PrePedido.FechaEmision;
                    PrePedido.IDClienteEmpresa = UsuarioIN.IDClienteEmpresa;
                    PrePedido.IDEstado = 15; //estado activo de PrePedido 15
                    PrePedido.IDUsuarioCreacion = UsuarioIN.IDUsuario;
                    PrePedido.IDUsuarioUltimaModificacion = UsuarioIN.IDUsuario;
                    PrePedido.FechaContable = null;
                    PrePedido.FechaVencimiento = null;
                    //DocumentoDetalle detalle;
                    foreach (modelCarrito ItemCarrito in ListCarrito.Productos)
                    {
                        detalle = new BIZDocumentoDetalle();
                        detalle.Cantidad = ItemCarrito.Cant;
                        detalle.IDPrecioDetalle = ItemCarrito.IDPrecioDetalle;
                        PrePedido.DocumentoDetalle.Add(detalle);
                    }
                    int IDDocNuevo = DocWorker.GuardarDocumento(PrePedido);
                    ListCarrito.IDDocumento = IDDocNuevo;
                    //db.Documento.Add(PrePedido);
                    //db.SaveChanges();
                }
                else //Es un PrePedido modificado
                {
                    DocWorker.RemoveDetalleDoc(ListCarrito.IDDocumento);
                    BIZDocumento PrePedido = DocWorker.ObtenerDocXID(ListCarrito.IDDocumento);
                    PrePedido.FechaUltimaModificacion = DateTime.Now;
                    PrePedido.IDUsuarioUltimaModificacion = UsuarioIN.IDUsuario;
                    foreach (modelCarrito ItemCarrito in ListCarrito.Productos)
                    {
                        detalle = new BIZDocumentoDetalle();
                        detalle.Cantidad = ItemCarrito.Cant;
                        detalle.IDPrecioDetalle = ItemCarrito.IDPrecioDetalle;
                        PrePedido.DocumentoDetalle.Add(detalle);
                    }
                    DocWorker.ActualizarDocumento(PrePedido);
                    //tengo q recargar la sesion del carrito
                    //db.Entry(documento).State = EntityState.Modified;
                    //db.SaveChanges();
                    //todavia nada....
                }
                return Json(new { Result = "" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex2)
            {
                Nullable<int> idUser = null;
                string ip = "Unknown";
                try
                {
                    idUser = (int)Session["userID"];
                }
                catch (Exception ex) { }
                try
                {
                    ip = Session["_ip"].ToString();
                }
                catch (Exception ex) { }
                try
                {
                    Bita.guardarBitacora(new BIZBitacora("Error", "Error al intentar guardar carrito", idUser, ip));
                }
                catch (Exception ex) { }

                ViewBag.AlertError = Language.ErrorLogInAgain;
                return Json(new { Result = "Error" }, JsonRequestBehavior.AllowGet);
            }
        }
Exemple #3
0
        //public  class stockCarrito {
        //    public stockCarrito()
        //    {
        //        this.Productos = new List<modelCarrito>();
        //    }
        //    public int IDCarrito;
        //    public List<modelCarrito> Productos { get; set; }
        //}
        public ActionResult SubmitPedido()
        {
            string devolver = "";
            try
            {
                BIZUsuario UsuarioIN = (BIZUsuario)Session["SUsuario"]; //q usuario?
                //primero tengo q ver por cada producto del carrito si hay stock.
                //cargo el carrito q está en sesion.
                var ListCarrito = (Session["ListCarrito"] as ListCarrito) ?? new ListCarrito();
                //stockCarrito Stock = new stockCarrito();

                Boolean TodoOK = false;

                if (ListCarrito.Productos.Count != 0)
                {
                    TodoOK = true;
                    foreach (var p in ListCarrito.Productos)
                    {
                        //p.stock = 1; // aca me traería el stock del producto
                        if (!p.conPrecio)
                            p.stock = 0;
                        else
                            p.stock = ProdWorker.CheckStockProd(p.id);

                        if (p.Cant > p.stock)
                        {
                            TodoOK = false;
                        }
                    }
                    if (TodoOK)
                    {
                        //aca hago el submit del pedido
                        BIZDocumento pedido = new BIZDocumento();
                        pedido.IDDocumentoTipo = 3; //tipo 3 es pedido
                        pedido.FechaEmision = DateTime.Now;
                        pedido.FechaUltimaModificacion = pedido.FechaEmision;
                        pedido.IDClienteEmpresa = UsuarioIN.IDClienteEmpresa;
                        pedido.IDEstado = 5; //estado activo de pedido 5 es "Pendiente de aprobacion"
                        pedido.IDUsuarioCreacion = UsuarioIN.IDUsuario;
                        pedido.IDUsuarioUltimaModificacion = UsuarioIN.IDUsuario;
                        BIZDocumentoDetalle detalle;
                        foreach (modelCarrito ItemCarrito in ListCarrito.Productos)
                        {
                            detalle = new BIZDocumentoDetalle();
                            detalle.Cantidad = ItemCarrito.Cant;
                            detalle.IDPrecioDetalle = ItemCarrito.IDPrecioDetalle;
                            pedido.DocumentoDetalle.Add(detalle);
                        }
                        int IDDocNuevo = DocWorker.GuardarDocumento(pedido);

                        Session["ListCarrito"] = null;
                        devolver = @Language.OKNormal;
                        try
                        {
                            Bita.guardarBitacora(new BIZBitacora("Informativo", "Se ha submitido el pedido nr# " + IDDocNuevo, (int)Session["userID"], Session["_ip"].ToString()));
                        }
                        catch { }
                        return Json(new { Result = devolver, CarritoStock = "ir" }, JsonRequestBehavior.AllowGet);
                    }
                    else //algun producto no tiene stock. Lo veo con JS.
                    {
                        return Json(new { Result = devolver, CarritoStock = ListCarrito, IVA = UsuarioIN.ClienteEmpresa.TipoIVA.Valor }, JsonRequestBehavior.AllowGet);
                    }
                }
            }
            catch (Exception ex2) {
                Nullable<int> idUser = null;
                string ip = "Unknown";
                try
                {
                    idUser = (int)Session["userID"];
                }
                catch (Exception ex) { }
                try
                {
                    ip = Session["_ip"].ToString();
                }
                catch (Exception ex) { }
                try
                {
                    Bita.guardarBitacora(new BIZBitacora("Error", "Error al intentar submitir un pedido", idUser, ip));
                }
                catch (Exception ex) { }
                devolver = @Language.ErrorLogInAgain;
            }
            return Json(new { Result = devolver, CarritoStock = "", IVA = 21 }, JsonRequestBehavior.AllowGet);
        }