Exemplo n.º 1
0
        public ActionResult ReinicioContrasena(ResetPassword formReset, string email)
        {
            if (ModelState.IsValid)
            {
                string rutUsuario = formReset.rut;
                object o;
                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                    o = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", rutUsuario);
                    string resp = o.ToString();

                    string[] usuario1 = resp.Split('|');
                    string   existe   = usuario1[0];
                    string   rutUser  = usuario1[1];
                    if (existe == "TRUE")
                    {
                        //si el usuario existe, rescatar los Ultimos 4 números del rut
                        string[] splitRutUser = rutUser.Split('-');
                        string   theRut       = splitRutUser[0];
                        int      numRut       = theRut.Length;
                        //con la pw nueva. guardo en AX el email y la contraseña nueva.
                        string pwNueva = theRut.Substring(numRut - 4, 4);

                        //ingresar datos al AX, CreateCustTable
                        object UpdateCustTable;
                        UpdateCustTable = DynAx.CallStaticClassMethod("WebPageConection", "UpdateCustPassword", rutUser, pwNueva);
                        if (UpdateCustTable.ToString() == "True")
                        {
                            ViewBag.OkReset = "Contraseña actualizada";
                            //enviar mail con link de recuperación
                            string url = Url.Action("Recuperar", "Usuarios",
                                                    new System.Web.Routing.RouteValueDictionary(new { id = formReset.rut }),
                                                    "http", Request.Url.Host);
                            SendEMail(email, url);
                        }
                        else
                        {
                            ViewBag.errorUpdatePw = "No se pudo recuperar la contraseña";
                        }
                    }
                    else
                    {
                        ViewBag.message2 = "No existes como usuario";
                    }
                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("ERROR: " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Recuperar(Resetpw formPw, string id, string OldPw)
        {
            if (ModelState.IsValid)
            {
                object o;
                object getUser;

                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");


                getUser = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", id);
                string   resp     = getUser.ToString();
                string[] usuario1 = resp.Split('|');
                string   pw       = usuario1[2];

                if (OldPw == pw)
                {
                    if (OldPw != formPw.ConfirmPassword)
                    {
                        o = DynAx.CallStaticClassMethod("WebPageConection", "UpdateCustPassword", id, formPw.ConfirmPassword);
                        if (o.ToString() == "True")
                        {
                            //var updatepw = from cli in db.Clientes
                            //               where id = cli.RutCliente
                            //               select cli;
                            ViewBag.cambio = "CONTRASEÑA CAMBIADA CON EXITO";
                        }
                    }
                    else
                    {
                        ViewBag.badOldpw = "La contraseña nueva no puede ser igual ";
                    }
                }
                else
                {
                    ViewBag.badOldpw = "No coincide la contraseña antigua";
                }
                DynAx.Logoff();
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }


            return(View());
        }
Exemplo n.º 3
0
        public JsonResult validaUsuario(string rut)
        {
            object getUsuario;

            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
            getUsuario = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", rut);
            string responseUser = getUsuario.ToString();

            string[] UsSplit      = responseUser.Split('|');
            string   existeEnAX   = UsSplit[0];
            string   rutUsuario   = UsSplit[1];
            string   pw           = UsSplit[2];
            string   EmailCliente = UsSplit[4];

            if (existeEnAX == "TRUE")
            {
                if (String.IsNullOrEmpty(pw))
                {
                    ViewBag.SinPw = "No cuentas con password registrada";
                }
            }
            else
            {
                ViewBag.NoExisteCliente = "No existes como cliente en el sistema";
            }


            return(Json(JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public ActionResult Recuperar(string id)
        {
            //id es el rut del usuario

            object getUser;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
            getUser = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", id);

            string resp = getUser.ToString();

            string[] usuario1 = resp.Split('|');
            string   existe   = usuario1[0];


            if (existe == "TRUE")
            {
                ViewBag.rutUsuario = id;
            }
            else
            {
                ViewBag.noexistes = "No existes como cliente";
            }
            DynAx.Logoff();
            return(View());
        }
Exemplo n.º 5
0
        public DataSet GetPrecios()
        {
            Int64 transaccion;
            Int32 contador = 0;

            Axapta Dynax       = new Axapta();
            string _account    = "";   /* "001640";*/
            string _salestaker = "";
            string _dataarea   = "";
            string o           = "";
            string itemid;
            string cantidad;
            string detalle           = "";
            string precio_solicitado = "";
            string artCompetencia    = "";
            string marcaCompetencia  = "";
            string pricecompetitor   = "";
            string competitorName    = "";

            conexionaxapta();
            if (conectadoax == true)
            {
                SqlConnection conn = new SqlConnection(cadenainterface);
                conn.Open();
                SqlCommand comand = new SqlCommand("select TransaccionNum, CustAccount, SalesTaker , DataAreaId from SPonline_Enc where TransaccionEstatus=0  order by TransaccionNum desc ", conn);


                SqlDataReader readerencabezado = comand.ExecuteReader();
                if (readerencabezado.HasRows)
                {
                    while (readerencabezado.Read())
                    {
                        transaccion = readerencabezado.GetInt64(0);
                        _account    = /*"001640";*/ readerencabezado.GetString(1);
                        _salestaker = /* "0079";*/ readerencabezado.GetString(2);
                        _dataarea   = /* "dsr";*/ readerencabezado.GetString(3);



                        SqlCommand cmoanddetalle = new SqlCommand("select COUNT(*) from SPonline_Det where TransaccionNum = " + transaccion, conn);

                        contador = Convert.ToInt32(cmoanddetalle.ExecuteScalar());
                        //     contador = Convert.ToInt32(  cmoanddetalle.ExecuteNonQuery() ) ;
                        if (contador > 0)   // verifica que el pedido tenga articulos
                        {
                            SqlCommand    cmdlineaspedido = new SqlCommand("select ItemId , Qty , RequestPrice , CompetitorItem ,CompetitorMarca , CompetitorPrice, CompetitorName from SPonline_Det where TransaccionNum = " + transaccion, conn);
                            SqlDataReader readerdetalle   = cmdlineaspedido.ExecuteReader();
                            if (readerdetalle.HasRows)
                            {
                                while (readerdetalle.Read())
                                {
                                    itemid            = readerdetalle.GetString(0);
                                    detalle           = detalle + itemid /*"010298"*/ + "|";
                                    cantidad          = Convert.ToString(readerdetalle.GetInt32(1));
                                    detalle           = detalle + cantidad /* "3"*/ + "|";
                                    precio_solicitado = Convert.ToString(readerdetalle.GetDecimal(2));
                                    detalle           = detalle + precio_solicitado + "|";
                                    artCompetencia    = readerdetalle.GetString(3);
                                    detalle           = detalle + artCompetencia + "|";
                                    marcaCompetencia  = readerdetalle.GetString(4);
                                    detalle           = detalle + marcaCompetencia + "|";
                                    pricecompetitor   = Convert.ToString(readerdetalle.GetDecimal(5));
                                    detalle           = detalle + pricecompetitor + "|";
                                    competitorName    = readerdetalle.GetString(6);
                                    detalle           = detalle + competitorName + "|";
                                }

                                char[] charsToTrim = { '|' };
                                detalle = detalle.TrimEnd(charsToTrim);
                            }


                            try
                            {
                                //   detalle = "011127_289";
                                o = (string)axp.CallStaticClassMethod("JSM_GenerarPedidoVentaOnLine", "SOLICITUD_PRECIO", _account, _salestaker, _dataarea, detalle);


                                //    axp.Logoff();
                            }
                            catch (Exception ex)
                            {
                                ex.ToString();
                            }



                            SqlCommand comandupdstatus = new SqlCommand("update SPonline_Enc set TransaccionEstatus = 1 where TransaccionNum = " + transaccion, conn);
                            comandupdstatus.ExecuteNonQuery();
                            detalle = "";

                            readerdetalle.Close();
                        } // fin del if cuenta registros

                        _account    = "";
                        _salestaker = "";
                        _dataarea   = "";
                    }  // fin del while del encabezado
                }
                axp.Dispose();
                axp.Logoff();   // cierra la sesion de ax
                readerencabezado.Close();


                SqlDataAdapter da = new SqlDataAdapter("select TransaccionNum, CustAccount, SalesTaker from SPonline_Enc  where TransaccionEstatus=0", conn);
                DataSet        ds = new DataSet();
                da.Fill(ds);

                SqlCommand comandubicacion = new SqlCommand("exec BORRAR_SESSIONE_APP", conn);
                comandubicacion.ExecuteNonQuery();

                conn.Dispose();
                conn.Close();
                return(ds);
            }
            else
            {
                DataSet ds = new DataSet();


                return(ds);
            }
        }
Exemplo n.º 6
0
        public ActionResult LogIn(UserModel users, string ReturnUrl)
        {
            var usmodel = new UserModel();

            //validar si el usuario ya tiene una sesion activa con un npedido asociado
            if (ModelState.IsValid)
            {
                //var user = db.Clientes.FirstOrDefault(u => u.RutCliente == users.rut);
                //var pass = db.Clientes.FirstOrDefault(u => u.Password == users.password);
                //var comp = db.CabeceraCarro.Any(c => c.RutCliente == users.rut);
                //var existe_usuario = (from c in db.Clientes
                //                         where c.RutCliente + "-" + c.DigCliente == users.rut
                //                     select c);
                object getUsuario;

                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                    try
                    {
                        string usuario = users.rut;
                        getUsuario = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", usuario);
                        string resp = getUsuario.ToString();

                        string[] usuario1   = resp.Split('|');
                        string   existeEnAX = usuario1[0];


                        if (existeEnAX == "TRUE")
                        {
                            string rutUsuario = usuario1[1];
                            string pw         = usuario1[2];

                            string[] splitRutUser = rutUsuario.Split('-');
                            string   theRut       = splitRutUser[0];
                            int      numRut       = theRut.Length;
                            //con la pw nueva. guardo en AX el email y la contraseña nueva.
                            string pwNueva = theRut.Substring(numRut - 4, 4);

                            string NombreCliente = usuario1[3];

                            string EmailCliente = usuario1[4];
                            if (users.password == pwNueva)
                            {
                                return(RedirectToAction("Recuperar", "Usuarios", new { id = rutUsuario }));
                            }
                            else
                            {
                                if (pw == users.password)
                                {
                                    //si loguea
                                    Session["nombreuser"] = NombreCliente;
                                    Session["rutuser"]    = rutUsuario;
                                    Session["emailuser"]  = EmailCliente;
                                    TempData["logueado"]  = "Sent";
                                }
                                else
                                {
                                    //no loguea
                                    ViewBag.badpw = "Contraseña Incorrecta";
                                    //Response.Write("Contraseña Incorrecta");
                                    usmodel.rut      = rutUsuario;
                                    usmodel.password = pw;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error = (ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("NO HUBO CONEXION CON EL SISTEMA, ERROR: " + ex.Message);
                }
            }

            return(View(users));
        }
Exemplo n.º 7
0
        public ActionResult Registration(DatosPersonalesModel user)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.StateId == "Región Met").OrderBy(c => c.Name).ToList();
            if (ModelState.IsValid)
            {
                string   rut   = user.rut;
                string[] rutus = Convert.ToString(rut).Split('-');
                string   rut1  = rutus[0];
                string   dig1  = rutus[1];

                //var existeuser = (from u in db.Clientes
                //                  where u.RutCliente + "" + u.DigCliente == rut1 + "" + dig1
                //                  select u).FirstOrDefault();

                //if (existeuser == null)
                //{
                //    var crearuser = db.Clientes.Create();
                //    crearuser.RutCliente = rut1;
                //    crearuser.DigCliente = dig1;
                //    crearuser.Nombre = user.Nombre;
                //    crearuser.Apellido = user.Apellido;
                //    crearuser.Email = user.Email;
                //    crearuser.Direccion = user.Direccion;
                //    crearuser.Comuna = user.Comuna;
                //    crearuser.TelFijo = user.TelFijo;
                //    crearuser.TelMovil = user.TelMovil;
                //    crearuser.Password = user.Password;
                //    crearuser.ConfirmPassword = user.ConfirmPassword;
                //    db.Clientes.Add(crearuser);

                //    try
                //    {
                //        db.SaveChanges();
                //    }
                //    catch (Exception p)
                //    {
                //        ViewBag.error = p.Message;
                //    }

                //}
                //else
                //{
                //    Response.Write("ya existes como usuario");
                //}

                object RegistraUsuario;
                object o1;
                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                    try
                    {
                        string rutcom = rut1 + "-" + dig1;

                        o1 = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", rutcom);
                        string   resp     = o1.ToString();
                        string[] usuario1 = resp.Split('|');
                        string   existe   = usuario1[0];

                        if (existe == "FALSE")
                        {
                            RegistraUsuario = DynAx.CallStaticClassMethod("WebPageConection", "CreateCust", rut1 + "-" + dig1, dig1, user.Nombre + " " + user.Apellido, user.Email, user.TelFijo, user.TelMovil, user.Comuna, user.Direccion, user.Password);
                            //Response.Write(o.ToString());
                            ViewBag.Message = "Registrado";
                            return(View("RegistrationExitosa"));
                        }
                        else
                        {
                            ViewBag.error = "Estas registrado en el sistema";
                        }
                    }
                    catch (Exception e)
                    {
                        ViewBag.error = "[15]" + e.Message;
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("ERROR: " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }
            return(View());
        }
Exemplo n.º 8
0
        //public ActionResult ConfirmarTransferenciaSinRegistro(int id, string rutcliente)
        //{
        //    DateTime hoydia = DateTime.Today;
        //    string fecha = hoydia.ToString("MMdd");
        //    string fecha_exito = hoydia.ToString("dd/MM/yyyy");

        //    if (Session["cart"] != null)
        //    {
        //        string npedido = Session["cart"].ToString();
        //        //string rutcliente = Session["rutuser"].ToString();
        //        int np = Convert.ToInt32(npedido);

        //        var carrito = (from c in db.CabeceraCarro
        //                       where c.NPedido == np && c.EstadoOc == false
        //                       select c).FirstOrDefault();

        //        carrito.EstadoOc = true;
        //        try
        //        {
        //            db.SaveChanges();
        //        }
        //        catch (Exception ep)
        //        {
        //            ViewBag.error = "[4]" + ep.Message;
        //        }

        //        if (IngresaTransferenciaAx(np, rutcliente, fecha_exito) == true)
        //        {
        //            ViewBag.ExitoT = "Enviada";
        //            ViewBag.npedido = np;
        //            Session["cart"] = null;
        //            return View("ConfirmarTransferenciaSinRegistro");
        //        }
        //        else
        //        {
        //            ViewBag.NoIngresa = "No se ingresó la transferencia";
        //            return View("MetodoDePago");
        //        }

        //    }
        //    else
        //    {
        //        ViewBag.errorC = "Carro expiró";
        //    }
        //    return View();
        //}

        //public ActionResult ConfirmarTransferencia(int id , string rutcliente)
        //{
        //    DateTime hoydia = DateTime.Today;
        //    string fecha = hoydia.ToString("MMdd");
        //    string fecha_exito = hoydia.ToString("dd/MM/yyyy");

        //    var carrito = (from c in db.CabeceraCarro
        //                   where c.NPedido == id && c.EstadoOc == false
        //                   select c).FirstOrDefault();

        //    var OrdenesPagadas1 = (from c in db.CabeceraCarro
        //                           from cli in db.Clientes
        //                           where c.NPedido == id && c.EstadoOc == true
        //                           select cli).FirstOrDefault();

        //    if (Session["cart"] != null)
        //    {
        //        if (Session["rutuser"] == null)
        //        {
        //            carrito.EstadoOc = true;
        //            try
        //            {
        //                db.SaveChanges();
        //            }
        //            catch (Exception ep)
        //            {
        //                ViewBag.error = "[4]" + ep.Message;
        //            }

        //            if (IngresaTransferenciaAx(id, rutcliente, fecha_exito) == true)
        //            {
        //                ViewBag.ExitoT = "Enviada";
        //                ViewBag.npedido = id;
        //                Session["cart"] = null;
        //                //enviar correo

        //                var ProductosComprados = from prd in db.DetalleCarro
        //                                         where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
        //                                         select prd;



        //                SmtpClient smtp = new SmtpClient();
        //                smtp.Host = "smtp.gmail.com";
        //                smtp.Port = 587;
        //                smtp.EnableSsl = true;
        //                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        //                smtp.UseDefaultCredentials = false;
        //                smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "ventasweb.2017");

        //                var send_mail = new MailMessage();
        //                send_mail.IsBodyHtml = true;
        //                send_mail.From = new MailAddress("*****@*****.**", "Yolito Centro ferretero");
        //                send_mail.To.Add(new MailAddress("*****@*****.**"));

        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
        //                send_mail.Subject = "Confirmación de transferencia del Pedido Número: " + "Web_" + id + ", Fecha: " + fecha_exito;
        //                string textBody = string.Empty;
        //                foreach (var pc in ProductosComprados)
        //                {
        //                     textBody = textBody + ("<br/>Nombre del producto : <strong>" + pc.ItemName + " </strong><br />" + "Código del producto: <strong>" + pc.ItemBarCode + " </strong><br />" + "Precio: <strong>" + pc.Precio + "</strong> <br/>" + "Cantidad: <strong>" + pc.Cantidad + "</strong><hr />");
        //                }
        //                send_mail.Body = textBody;
        //                try
        //                {
        //                    smtp.Send(send_mail);
        //                }
        //                catch (Exception p)
        //                {
        //                    ViewBag.error = "[8]" + p.Message;
        //                }

        //            }
        //            else
        //            {
        //                ViewBag.NoIngresa = "No se ingresó el pedido en el sistema";
        //            }
        //        }
        //    }
        //    else
        //    {
        //        ViewBag.errorC = "Carro expiró";
        //    }
        //    return View("ConfirmaTransferencia");
        //}

        //public bool IngresaTransferenciaAx(int id, string rutcliente, string fecha_exito)
        //{
        //    var CbPagadas = from c in db.CabeceraCarro
        //                    where c.NPedido == id && c.EstadoOc == true
        //                    select c;//tomar el email de aca y el rut
        //    var sessionrut = Session["rutuser"];

        //    var CarrosPagados = from prd in db.DetalleCarro
        //                        where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
        //                        select prd;

        //    var totalCompra = CarrosPagados.Select(c => c.Subtotal).Sum();

        //    var OrdenesPagadas = CbPagadas.FirstOrDefault();

        //    var InsertOrdenesPagadas = db.CarroPagado.Create();

        //    if (sessionrut != null)
        //    {

        //        InsertOrdenesPagadas.NPedido = OrdenesPagadas.NPedido;
        //        InsertOrdenesPagadas.RutCliente = OrdenesPagadas.RutCliente;
        //        InsertOrdenesPagadas.NombreCliente = OrdenesPagadas.NombreCliente;

        //        InsertOrdenesPagadas.CodigoCompraTBK = "Trasferencia";
        //        InsertOrdenesPagadas.NumTarjetaTBK = "transf";
        //        InsertOrdenesPagadas.NCuotasTBK = "transf";
        //        InsertOrdenesPagadas.FechaCompra = fecha_exito;
        //        InsertOrdenesPagadas.Monto = totalCompra.ToString();
        //        InsertOrdenesPagadas.EstadoOc = OrdenesPagadas.EstadoOc;
        //        db.CarroPagado.Add(InsertOrdenesPagadas);

        //        try
        //        {
        //            db.SaveChanges();
        //        }
        //        catch (Exception pr)
        //        {
        //            ViewBag.error = "[5]" + pr.Message;
        //        }
        //        //ingresar pago en AX

        //        object IngresaCabecera;
        //        object IngresaDetalleCarro;
        //        object ingresaPago;
        //        Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
        //        System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
        //        DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
        //        string[] clie = OrdenesPagadas.RutCliente.Split('-');
        //        string rut = clie[0];
        //        string dig = clie[1];
        //        try
        //        {
        //            //ingresar el pedido.
        //            var getdata = CbPagadas.FirstOrDefault();

        //            IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
        //                "Web_" + OrdenesPagadas.NPedido,
        //                rut + "-" + dig,
        //                getdata.ComunaDespacho,
        //                getdata.CalleDespacho,
        //                getdata.ObservacionDespacho,
        //                "",
        //                getdata.ModoEntrega,
        //                getdata.Local  );

        //            ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
        //                "Web_" + OrdenesPagadas.NPedido,
        //                rut + "-" + dig,
        //                "",
        //                "",
        //                "",
        //                "",
        //                OrdenesPagadas.MontoPagado);

        //            foreach (var d in CarrosPagados)
        //            {
        //                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
        //                    "Web_" + d.NPedido,
        //                    d.ItemBarCode,
        //                    d.Cantidad,
        //                    d.Precio);
        //            }
        //            //enviar monto del flete
        //            //o1 = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight", "Web_" + OrdenesPagadas.NPedido, OrdenesPagadas.CostoDespacho);
        //            DynAx.Logoff();


        //            return true;
        //        }
        //        catch (Exception ex)
        //        {
        //            ViewBag.error = "[6]" + ex.Message;
        //            DynAx.Logoff();
        //            return false;
        //        }
        //    }
        //    else
        //    {
        //        InsertOrdenesPagadas.NPedido = OrdenesPagadas.NPedido;
        //        InsertOrdenesPagadas.RutCliente = "1-9";
        //        InsertOrdenesPagadas.NombreCliente = "Cliente no presenta registro";
        //        InsertOrdenesPagadas.CodigoCompraTBK = "Trasferencia";
        //        InsertOrdenesPagadas.NumTarjetaTBK = "transf";
        //        InsertOrdenesPagadas.NCuotasTBK = "transf";
        //        InsertOrdenesPagadas.FechaCompra = fecha_exito;
        //        InsertOrdenesPagadas.Monto = totalCompra.ToString();
        //        InsertOrdenesPagadas.EstadoOc = OrdenesPagadas.EstadoOc;
        //        db.CarroPagado.Add(InsertOrdenesPagadas);

        //        try
        //        {
        //            db.SaveChanges();
        //        }
        //        catch (Exception pr)
        //        {
        //            ViewBag.error = "[5]" + pr.Message;
        //        }

        //        object IngresaCabecera;
        //        object IngresaDetalleCarro;
        //        object ingresaPago;
        //        object IngresaDespacho;
        //        Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
        //        System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
        //        DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
        //        string[] clie = OrdenesPagadas.RutCliente.Split('-');
        //        string rut = clie[0];
        //        string dig = clie[1];
        //        try
        //        {
        //            //ingresar el pedido.
        //            var getdata = CbPagadas.FirstOrDefault();

        //            if (OrdenesPagadas.ModoEntrega == "D")
        //            {
        //                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
        //                    "Web_" + OrdenesPagadas.NPedido,
        //                    "1-9",
        //                    OrdenesPagadas.ComunaDespacho,
        //                    OrdenesPagadas.CalleDespacho,
        //                    OrdenesPagadas.ObservacionDespacho,
        //                    "D",
        //                    "03");

        //                ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
        //                    "Web_" + OrdenesPagadas.NPedido,
        //                    "1-9",
        //                    "",
        //                    "",
        //                    "",
        //                    "",
        //                    OrdenesPagadas.MontoPagado);
        //                //enviar monto del flete
        //                IngresaDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
        //                    "Web_" + OrdenesPagadas.NPedido,
        //                    OrdenesPagadas.CostoDespacho);
        //            }
        //            else
        //            {
        //                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
        //                    "Web_" + OrdenesPagadas.NPedido,
        //                    "1-9",
        //                    "Retira",
        //                    "Retira",
        //                    "Retira en local",
        //                    "R",
        //                    OrdenesPagadas.Local);

        //                ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay", "Web_" + OrdenesPagadas.NPedido,
        //                    "1-9",
        //                    "",
        //                    "",
        //                    "",
        //                    "",
        //                    OrdenesPagadas.MontoPagado);
        //            }



        //            foreach (var d in CarrosPagados)
        //            {
        //                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
        //                    "Web_" + d.NPedido,
        //                    d.ItemBarCode,
        //                    d.Cantidad,
        //                    d.Precio);
        //            }

        //            DynAx.Logoff();


        //            return true;
        //        }
        //        catch (Exception ex)
        //        {
        //            ViewBag.error = "[6]" + ex.Message;
        //            DynAx.Logoff();
        //            return false;
        //        }

        //    }

        //}
        public bool CrearPedidoAx(int numero_oc, string comunalocal, string ModoEntrega)
        {
            object CreateSalesTable;
            object CreateSalesLine;
            object CreateSalesWebpay;
            object CreateSalesLineFreight;

            var CarroPagado = (from c in db.CabeceraCarro
                               where c.NPedido == numero_oc && c.EstadoOc == true
                               select c);

            var ProductosComprados = (from prd in db.DetalleCarro
                                      where prd.NPedido == numero_oc && prd.CabeceraCarro.EstadoOc == true
                                      select prd).ToList();

            var OrdenesPagadas = CarroPagado.FirstOrDefault();

            var CarroPagado1 = (from prd in db.CarroPagado
                                where prd.NPedido == numero_oc
                                select prd).FirstOrDefault();

            if (CarroPagado.Count() != 0)
            {
                try
                {
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                    if (Session["rutuser"] == null)
                    {
                        CreateSalesTable = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                       "AWeb_" + OrdenesPagadas.NPedido,   //SalesId
                                                                       "1-9",                              //CustAccount
                                                                       comunalocal,                        //_County
                                                                       ModoEntrega,                        //_Street
                                                                       ModoEntrega,                        //Obs
                                                                       OrdenesPagadas.ResponsableDespacho, //Contacto
                                                                       OrdenesPagadas.ModoEntrega,         //TDS
                                                                       OrdenesPagadas.Local,               //InventLocationId
                                                                       OrdenesPagadas.tipoDocumento);      //SalesDocumentCode
                    }
                    else
                    {
                        CreateSalesTable = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                       "AWeb_" + OrdenesPagadas.NPedido,   //SalesId
                                                                       OrdenesPagadas.RutCliente,          //CustAccount
                                                                       comunalocal,                        //_County
                                                                       ModoEntrega,                        //_Street
                                                                       ModoEntrega,                        //Obs
                                                                       OrdenesPagadas.ResponsableDespacho, //Contacto
                                                                       OrdenesPagadas.ModoEntrega,         //TDS
                                                                       OrdenesPagadas.Local,               //InventLocationId
                                                                       OrdenesPagadas.tipoDocumento);      //SalesDocumentCode
                    }

                    foreach (var p in ProductosComprados)
                    {
                        CreateSalesLine = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                      "AWeb_" + p.NPedido, //SalesId
                                                                      p.ItemBarCode,       //ItemBarCode
                                                                      p.Cantidad,          //Qty
                                                                      p.Precio);           //Price
                    }

                    //agregar el costo del despacho
                    if (ModoEntrega == "D")
                    {
                        CreateSalesLineFreight = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                             "AWeb_" + OrdenesPagadas.NPedido, //SalesId
                                                                             OrdenesPagadas.CostoDespacho);    //Freight
                    }


                    CreateSalesWebpay = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                    "AWeb_" + CarroPagado1.NPedido, //SalesId
                                                                    CarroPagado1.RutCliente,        //CustAccount
                                                                    CarroPagado1.CodigoCompraTBK,   //CodTrans
                                                                    CarroPagado1.NumTarjetaTBK,     //CardNum
                                                                    CarroPagado1.TipoCuota,         //PayMode
                                                                    CarroPagado1.NCuotasTBK,        //amount Feed
                                                                    CarroPagado1.Monto              //amount
                                                                    );
                    DynAx.Logoff();
                    return(true);
                }
                catch (Exception e)
                {
                    TempData["ErrorCreateSalesLine"] = e.Message;
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        public ActionResult MetodoDePago(string radiobt, string rut, string NombreDespacho, int ncarro, string Retira, string Local, string Responsable, string Comunas, string Calle, string Obs, string Despacho1, string Email, string EmailRetira, string tipoDocumento)
        {
            var totalCompra = (from d in db.DetalleCarro
                               where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                               select d.Subtotal).Sum();


            var CarroCliente = from c in db.DetalleCarro
                               where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                               select c;

            ViewBag.RutUsuariocomprador = rut;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

            object o;

            if (radiobt == "despacho")
            {
                TempData["rutDespacho"] = rut;

                //el proceso de despacho
                object o1;
                string itemcode = string.Empty;
                string canti    = string.Empty;

                try
                {
                    foreach (var p in CarroCliente)
                    {
                        itemcode += p.ItemBarCode + "|";
                        canti    += p.Cantidad + "|";
                    }
                    o1 = DynAx.CallStaticClassMethod("WebPageConection", "CalcFreight", itemcode, canti);

                    string valorflete = o1.ToString();

                    var Despacho = from c in db.CabeceraCarro
                                   where c.NPedido == ncarro && c.EstadoOc == false
                                   select c;

                    int montodesp = Convert.ToInt32(valorflete) + totalCompra;
                    foreach (var i in Despacho)
                    {
                        i.RutCliente          = rut;
                        i.NombreCliente       = NombreDespacho;
                        i.ComunaDespacho      = Comunas;
                        i.CalleDespacho       = Calle;
                        i.ObservacionDespacho = Obs;
                        i.CostoDespacho       = valorflete;
                        i.ModoEntrega         = Despacho1;
                        i.Local         = "03";
                        i.EmailCliente  = Email;
                        i.MontoPagado   = montodesp.ToString();
                        i.tipoDocumento = tipoDocumento;
                    }

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception p)
                    {
                        ViewBag.error = "[01] " + p.Message;
                    }


                    foreach (var c in CarroCliente)
                    {
                        o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                        "03", c.Cantidad);
                        //Response.Write(c.ItemBarCode + "<br/>");
                        if (o.ToString() == "1")
                        {
                            //Response.Write(totalCompra);
                            int dp = Convert.ToInt32(valorflete);
                            ViewBag.despacho = dp;
                            return(View("MetodoDePago", db.DetalleCarro));
                        }
                        else
                        {
                            TempData["error"] = "Producto no disponible para despacho";
                            return(RedirectToAction("Despacho", new { id = c.NPedido }));
                        }
                    }

                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = "[3]" + ex.Message;
                }
            }
            else
            {
                //proceso retira en tienda

                var Despacho = from c in db.CabeceraCarro
                               where c.NPedido == ncarro && c.EstadoOc == false
                               select c;

                foreach (var i in Despacho)
                {
                    i.RutCliente          = rut;
                    i.ResponsableDespacho = Responsable;
                    i.RutResponsable      = rut;
                    i.ModoEntrega         = Retira;
                    i.Local         = Local;
                    i.EmailCliente  = EmailRetira;
                    i.MontoPagado   = totalCompra.ToString();
                    i.tipoDocumento = tipoDocumento;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ep)
                {
                    ViewBag.error = ep.Message;
                }

                foreach (var c in CarroCliente)
                {
                    o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                    Local, c.Cantidad);
                    //Response.Write(c.ItemBarCode + "<br/>");
                    if (o.ToString() == "1")
                    {
                        ViewBag.Comunas = db.AddressCounty.Where(c1 => c1.DlvRoute != "").OrderBy(c1 => c1.Name).ToList();
                        //Response.Write(totalCompra);
                        ViewBag.Tienda = Local;
                        return(View("MetodoDePago", db.DetalleCarro));
                    }
                    else
                    {
                        TempData["error"] = "Producto no disponible en la tienda";
                        return(RedirectToAction("Despacho", new { id = c.NPedido }));
                    }
                }
                DynAx.Logoff();
            }

            return(View(db.DetalleCarro));
        }
Exemplo n.º 10
0
        public ActionResult TipoPago(string Comunas, string Calle, string Obs, int ncarro, string Despacho1, string tipoDocumento)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.DlvRoute != "").OrderBy(c => c.Name).ToList();
            if (ModelState.IsValid)
            {
                if (Session["cart"] != null)
                {
                    object o;
                    object o1;
                    string itemcode = string.Empty;
                    string canti    = string.Empty;


                    var CarroCliente = from c in db.DetalleCarro
                                       where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                                       select c;

                    var totalCompra = (from d in db.DetalleCarro
                                       where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                                       select d.Subtotal).Sum();

                    try
                    {
                        Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                        System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                        DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                        try
                        {
                            //ingresar el pedido.
                            foreach (var p in CarroCliente)
                            {
                                itemcode += p.ItemBarCode + "|";
                                canti    += p.Cantidad + "|";
                            }
                            o1 = DynAx.CallStaticClassMethod("WebPageConection", "CalcFreight", itemcode, canti);

                            string valorflete = o1.ToString();

                            var Despacho = from c in db.CabeceraCarro
                                           where c.NPedido == ncarro && c.EstadoOc == false
                                           select c;

                            int montodesp = Convert.ToInt32(valorflete) + totalCompra;
                            foreach (var i in Despacho)
                            {
                                i.RutCliente          = Session["rutuser"].ToString();
                                i.NombreCliente       = Session["nombreuser"].ToString();
                                i.ComunaDespacho      = Comunas;
                                i.CalleDespacho       = Calle;
                                i.ObservacionDespacho = Obs;
                                i.CostoDespacho       = valorflete;
                                i.ModoEntrega         = Despacho1;
                                i.Local         = "03";
                                i.MontoPagado   = montodesp.ToString();
                                i.tipoDocumento = tipoDocumento;
                            }

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception p)
                            {
                                ViewBag.error = "[01] " + p.Message;
                            }


                            foreach (var c in CarroCliente)
                            {
                                o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                                "03", c.Cantidad);
                                //Response.Write(c.ItemBarCode + "<br/>");
                                if (o.ToString() == "1")
                                {
                                    //Response.Write(totalCompra);
                                    int dp = Convert.ToInt32(valorflete);
                                    ViewBag.despacho = dp;
                                    return(View(db.DetalleCarro));
                                }
                                else
                                {
                                    TempData["error"] = "Producto no disponible en la tienda";
                                    return(RedirectToAction("Despacho", new { id = c.NPedido }));
                                }
                            }
                            DynAx.Logoff();
                        }
                        catch (Exception ex)
                        {
                            ViewBag.error = "[2] " + ex.Message;
                        }

                        DynAx.Logoff();
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error = "[3]" + ex.Message;
                    }
                }
            }
            else
            {
                ViewBag.error = "Error en formulario";
            }

            return(View(db.DetalleCarro));
        }
Exemplo n.º 11
0
        public ActionResult TipopagoRet(string Responsable, string rut, int ncarro, string radiobt, string Local, string tipoDocumento)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.DlvRoute != "").OrderBy(c => c.Name).ToList();

            ViewBag.despacho = "Retira en tienda";
            if (Session["cart"] != null)
            {
                object o;
                var    totalCompra = (from d in db.DetalleCarro
                                      where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                                      select d.Subtotal).Sum();


                var Despacho = (from c in db.CabeceraCarro
                                where c.NPedido == ncarro && c.EstadoOc == false
                                select c).FirstOrDefault();

                var CarroCliente = from c in db.DetalleCarro
                                   where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                                   select c;

                Despacho.RutCliente          = Session["rutuser"].ToString();
                Despacho.NombreCliente       = Session["nombreuser"].ToString();
                Despacho.ResponsableDespacho = Responsable;
                Despacho.RutResponsable      = rut;
                Despacho.ModoEntrega         = radiobt;
                Despacho.Local         = Local;
                Despacho.MontoPagado   = totalCompra.ToString();
                Despacho.tipoDocumento = tipoDocumento;
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ep)
                {
                    ViewBag.error = ep.Message;
                }
                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                foreach (var c in CarroCliente)
                {
                    o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                    Local, c.Cantidad);
                    //Response.Write(c.ItemBarCode + "<br/>");
                    if (o.ToString() == "1")
                    {
                        ViewBag.Comunas = db.AddressCounty.Where(c1 => c1.DlvRoute != "").OrderBy(c1 => c1.Name).ToList();
                        //Response.Write(totalCompra);
                        return(View(db.DetalleCarro));
                    }
                    else
                    {
                        TempData["error"] = "Producto no disponible en la tienda";
                        return(RedirectToAction("Despacho", new { id = c.NPedido }));
                    }
                }

                DynAx.Logoff();
            }

            return(View(db.DetalleCarro));
        }
Exemplo n.º 12
0
        public ActionResult ConfirmaTransferencia(int id)
        {
            //ingresar transferencia AX y enviar correos. validar si es retira
            var CbPagadas = from c in db.CabeceraCarro
                            where c.NPedido == id && c.EstadoOc == true
                            select c;//tomar el email de aca y el rut

            var getdata = CbPagadas.FirstOrDefault();

            ViewBag.npedido = id;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

            object IngresaCabecera;
            object IngresaPago;
            object MontoDespacho;
            object IngresaDetalleCarro;

            if (PagaOrden(id) == true)
            {
                //ingresar cabecera en AX
                foreach (var it in CbPagadas)
                {
                    if (it.ModoEntrega == "D")
                    {
                        try
                        {
                            IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          "1-9",
                                                                          getdata.ComunaDespacho,
                                                                          getdata.CalleDespacho,
                                                                          getdata.ObservacionDespacho,
                                                                          "D",
                                                                          "03");
                        }
                        catch (Exception ep)
                        {
                            ViewBag.error = "[15] " + ep.Message;
                        }


                        try
                        {
                            IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      getdata.MontoPagado);
                        }
                        catch (Exception jp)
                        {
                            ViewBag.error = "[16] " + jp.Message;
                        }

                        try
                        {
                            MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                        "AWeb_" + getdata.NPedido,
                                                                        getdata.CostoDespacho);
                        }
                        catch (Exception lp)
                        {
                            ViewBag.error = "[17]" + lp.Message;
                        }

                        try
                        {
                            var CarrosPagados = from prd in db.DetalleCarro
                                                where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                                select prd;

                            foreach (var d in CarrosPagados)
                            {
                                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                                  "AWeb_" + d.NPedido,
                                                                                  d.ItemBarCode,
                                                                                  d.Cantidad,
                                                                                  d.Precio);
                            }
                        }
                        catch (Exception op)
                        {
                            ViewBag.error = "[18]" + op.Message;
                        }

                        ViewBag.ExitoT = "exito";
                    }
                    else
                    {
                        try
                        {
                            if (Session["rutuser"] != null)
                            {
                                //si se registra enviar el rut
                                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                              "AWeb_" + getdata.NPedido,
                                                                              Session["rutuser"].ToString(),
                                                                              getdata.ComunaDespacho,
                                                                              getdata.CalleDespacho,
                                                                              getdata.ObservacionDespacho,
                                                                              "R",
                                                                              getdata.Local);
                            }
                            else
                            {
                                //si no es registro. el pedido se registra con rut-9
                                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                              "AWeb_" + getdata.NPedido,
                                                                              "1-9",
                                                                              getdata.ComunaDespacho,
                                                                              getdata.CalleDespacho,
                                                                              getdata.ObservacionDespacho,
                                                                              "R",
                                                                              getdata.Local);
                            }
                        }
                        catch (Exception ep)
                        {
                            ViewBag.error = "[15] " + ep.Message;
                        }

                        try
                        {
                            if (Session["rutuser"] != null)
                            {
                                IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          Session["rutuser"].ToString(),
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          getdata.MontoPagado);
                            }
                            else
                            {
                                IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          "1-9",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          getdata.MontoPagado);
                            }
                        }
                        catch (Exception jp)
                        {
                            ViewBag.error = "[16] " + jp.Message;
                        }

                        //try
                        //{
                        //    MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight", "Web_" + getdata.NPedido, getdata.CostoDespacho);
                        //}
                        //catch (Exception lp)
                        //{
                        //    ViewBag.error = "[17]" + lp.Message;
                        //}

                        try
                        {
                            var CarrosPagados = from prd in db.DetalleCarro
                                                where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                                select prd;

                            foreach (var d in CarrosPagados)
                            {
                                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                                  "AWeb_" + d.NPedido,
                                                                                  d.ItemBarCode,
                                                                                  d.Cantidad,
                                                                                  d.Precio);
                            }
                        }
                        catch (Exception op)
                        {
                            ViewBag.error = "[18]" + op.Message;
                        }

                        ViewBag.ExitoT = "exito";
                    }
                }
            }
            DynAx.Logoff();//cierro session ax

            return(View());
        }
Exemplo n.º 13
0
        public ActionResult TransferenciaSinRegistro(int id)
        {
            //ingresar transferencia AX y enviar correos. validar si es retira
            var CbPagadas = from c in db.CabeceraCarro
                            where c.NPedido == id && c.EstadoOc == true
                            select c;//tomar el email de aca y el rut

            var getdata = CbPagadas.FirstOrDefault();

            DateTime hoydia      = DateTime.Today;
            string   fecha       = hoydia.ToString("MMdd");
            string   fecha_exito = hoydia.ToString("dd/MM/yyyy");

            if (PagaOrden(id) == true)
            {
                ViewBag.npedido = id;
                object IngresaCabecera;
                object IngresaDetalleCarro;
                object ingresaPago;
                object MontoDespacho;
                var    CarrosPagados = from prd in db.DetalleCarro
                                       where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                       select prd;

                int montototal = 0;


                string textBody = string.Empty;
                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                try
                {
                    //ingresar el pedido.
                    IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9", getdata.ComunaDespacho,
                                                                  getdata.CalleDespacho,
                                                                  getdata.ObservacionDespacho,
                                                                  "D",
                                                                  "03");

                    ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                              "AWeb_" + getdata.NPedido,
                                                              "1-9",
                                                              "",
                                                              "",
                                                              "",
                                                              "", getdata.MontoPagado);

                    MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                "AWeb_" + getdata.NPedido,
                                                                getdata.CostoDespacho);

                    if (getdata.ModoEntrega == "D")
                    {
                        int valordesp   = Convert.ToInt32(getdata.CostoDespacho);
                        int valorpagado = Convert.ToInt32(getdata.MontoPagado);

                        montototal = valordesp + valorpagado;

                        IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      getdata.ComunaDespacho,
                                                                      getdata.CalleDespacho,
                                                                      getdata.ObservacionDespacho,
                                                                      "D",
                                                                      "03");

                        ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  getdata.MontoPagado);

                        MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                    "AWeb_" + getdata.NPedido,
                                                                    getdata.CostoDespacho);

                        textBody = "Hola estimado, <strong>" + getdata.NombreCliente + "</strong><br />" +
                                   "<br /> El detalle de tu compra es: <br /><table ><tr><td>Pedido:</td> <td>" + "Web_" + id + "</td></tr><tr><td>Fecha de pago:</td><td>" + fecha_exito + "</td></tr><tr><td>Tipo Pago:</td> <td>Transferencia</td></tr><tr><td>Modo entrega: </td><td>" + "Despacho" + "</td></tr><tr><td>Monto total:</td><td>" + montototal.ToString("#,##") + "</td></tr></table> <br /> Detalle de los productos comprados: <br/>";
                    }

                    else
                    {
                        IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      "Retira",
                                                                      "Retira",
                                                                      "Retira en local",
                                                                      "R",
                                                                      getdata.Local);

                        ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  getdata.MontoPagado);

                        textBody = "Hola estimado, <strong>" + getdata.NombreCliente + "</strong><br />" +
                                   "<br /> El detalle de tu compra es: <br /><table ><tr><td>Pedido pagado:</td> <td>" + "Web_" + id + "</td></tr><tr><td>Fecha de pago:</td><td>" + fecha_exito + "</td></tr><tr><td>Tipo Pago:</td> <td>Transferencia</td></tr><tr><td>Modo Entrega:</td><td>" + getdata.ModoEntrega + "</td></tr><tr><td>Local :</td><td>" + getdata.Local + "</td></tr><tr><td>Monto total:</td><td>" + getdata.MontoPagado + "</td></tr></table> <br /> Detalle de los productos comprados: <br/>";
                    }
                    foreach (var d in CarrosPagados)
                    {
                        IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                          "AWeb_" + d.NPedido,
                                                                          d.ItemBarCode,
                                                                          d.Cantidad,
                                                                          d.Precio);
                    }

                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = "[6]" + ex.Message;
                    DynAx.Logoff();
                }
                var ProductosComprados = from pr in db.DetalleCarro
                                         where pr.NPedido == id && pr.CabeceraCarro.EstadoOc == true
                                         select pr;

                SmtpClient smtp = new SmtpClient();
                smtp.Host                  = "smtp.gmail.com";
                smtp.Port                  = 587;
                smtp.EnableSsl             = true;
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "ventasweb.2017");

                var send_mail = new MailMessage();
                send_mail.IsBodyHtml = true;
                send_mail.From       = new MailAddress("*****@*****.**", "Yolito Centro ferretero");
                send_mail.To.Add(new MailAddress("*****@*****.**"));

                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Subject = "Confirmación de transferencia del Pedido Número: " + "AWeb_" + id + ", Fecha: " + fecha_exito;
                foreach (var pc in ProductosComprados)
                {
                    textBody = textBody + ("<br/>Nombre del producto : <strong>" + pc.ItemName + " </strong><br />" + "Código del producto: <strong>" + pc.ItemBarCode + " </strong><br />" + "Precio: <strong>" + pc.Precio + "</strong> <br/>" + "Cantidad: <strong>" + pc.Cantidad + "</strong><hr />");
                }
                send_mail.Body = textBody;
                try
                {
                    smtp.Send(send_mail);
                }
                catch (Exception p)
                {
                    ViewBag.error = "[8]" + p.Message;
                }
            }
            else
            {
                ViewBag.error = "No se actualizo el estado del pedido";
            }

            return(View());
        }