Beispiel #1
0
        public Ent_Ecommerce_Chazki get_Ventas_por_Chazki(string ven_id)
        {
            Ent_Ecommerce_Chazki ven = null;
            string sqlquery          = "USP_ECOMMERCE_LISTA_CHAZKI";

            try
            {
                //Ent_Conexion.conexion = "Server=192.168.1.242;Database=BDPOS;User ID=sa;Password=1;Trusted_Connection=False;";
                using (SqlConnection cn = new SqlConnection(Ent_Conexion.conexionEcommerce))
                {
                    if (cn.State == 0)
                    {
                        cn.Open();
                    }
                    using (SqlCommand cmd = new SqlCommand(sqlquery, cn))
                    {
                        cmd.CommandTimeout = 0;
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@ven_id", ven_id);

                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataSet        ds = new DataSet();
                        da.Fill(ds);
                        if (ds.Tables.Count > 0)
                        {
                            DataTable dtD  = ds.Tables[0]; //data articulos
                            DataTable dtIC = ds.Tables[1]; //data chaski
                            DataTable dtID = ds.Tables[2]; //data direccion cliente
                            ven = new Ent_Ecommerce_Chazki();
                            /*ARTICULOS*/
                            List <Ent_DetallesVentaCanal_E> listVenD = new List <Ent_DetallesVentaCanal_E>();
                            foreach (DataRow item in dtD.Rows)
                            {
                                Ent_DetallesVentaCanal_E venD = new Ent_DetallesVentaCanal_E();
                                venD.codigoProducto = item["codigo_articulo"].ToString();
                                venD.nombreProducto = item["descripcion_articulo"].ToString();
                                venD.total          = item["precio_total"].ToString();
                                venD.cantidad       = Convert.ToInt32(Convert.ToDouble(item["cantidad"].ToString()));
                                listVenD.Add(venD);
                            }
                            ven.detalles2 = listVenD;
                            /*TIENDA ORIGEN*/
                            if (dtIC.Rows.Count > 0)
                            {
                                Ent_Informacion_Tienda_envio_E ic = new Ent_Informacion_Tienda_envio_E();
                                ic.id                      = Convert.ToInt32(dtIC.Rows[0]["id"]);
                                ic.chaski_storeId          = dtIC.Rows[0]["chazki_store_id"].ToString();
                                ic.chaski_branchId         = dtIC.Rows[0]["chazki_branch_id"].ToString();
                                ic.chaski_api_key          = dtIC.Rows[0]["chaski_api_key"].ToString();
                                ic.deliveryTrack_Code      = dtIC.Rows[0]["deliveryTrack_Code"].ToString();
                                ic.mode                    = dtIC.Rows[0]["mode"].ToString();
                                ic.tiempo                  = dtIC.Rows[0]["tiempo"].ToString();
                                ic.payment_method          = dtIC.Rows[0]["payment_method"].ToString();
                                ic.proofPayment            = dtIC.Rows[0]["proofPayment"].ToString();
                                ven.informacionTiendaEnvio = ic;
                            }
                            /*CLENTE DESTINO*/
                            if (dtID.Rows.Count > 0) //des
                            {
                                Ent_Informacion_Tienda_Destinatario_E id = new Ent_Informacion_Tienda_Destinatario_E();

                                id.nroDocumento      = dtID.Rows[0]["dni_ruc"].ToString();
                                id.email             = dtID.Rows[0]["correo"].ToString();
                                id.cliente           = dtID.Rows[0]["cliente"].ToString();
                                id.referencia        = "";
                                id.telefono          = dtID.Rows[0]["telefono"].ToString();
                                id.direccion_entrega = dtID.Rows[0]["direccion_cliente"].ToString();
                                id.ubigeo            = dtID.Rows[0]["ubigeo"].ToString();
                                ven.informacionTiendaDestinatario = id;
                            }
                            //ven.historialEstados = listHist;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ven = null;
            }
            return(ven);
        }
Beispiel #2
0
        public string Envia_Courier_chazki(string ven_id, string tienda_id)
        {
            string retorno = "";

            try
            {
                /*delivery CHASKI*/
                Dat_Chazki objChazki = new Dat_Chazki();

                Ent_Ecommerce_Chazki cvCzk = objChazki.get_Ventas_por_Chazki(ven_id, tienda_id);

                List <Ent_Chazki> list_chazki = new List <Ent_Chazki>();

                if (cvCzk.listaArticulos != null)
                {
                    /* DATA CHASKI : PRODUCCION*/

                    Ent_Chazki chazki = new Ent_Chazki();
                    chazki.storeId           = cvCzk.informacionTiendaEnvio.storeId;  // "10411"; // proporcionado por chazki
                    chazki.branchId          = cvCzk.informacionTiendaEnvio.branchId; // proporcionado por chazki
                    chazki.deliveryTrackCode = cvCzk.informacionTiendaEnvio.deliveryTrackCode;
                    chazki.proofPayment      = "Ninguna";                             // por definir la evindencia que será entregada al cliente
                    chazki.deliveryCost      = 0;
                    chazki.mode          = "Express";                                 //pendiente definir el modo con el que se va a trabajar el canal de venta.
                    chazki.time          = "";
                    chazki.paymentMethod = "Pagado";
                    chazki.country       = "PE";

                    /* DATA CHASKI : TEST*/

                    //Ent_Chazki chazki = new Ent_Chazki();
                    //chazki.storeId = "10411";
                    //chazki.branchId = "CCSC-B187";
                    //chazki.deliveryTrackCode = cvCzk.informacionTiendaEnvio.deliveryTrackCode;
                    //chazki.proofPayment = "Ninguna"; // por definir la evindencia que será entregada al cliente
                    //chazki.deliveryCost = 0;
                    //chazki.mode = "Express"; //pendiente definir el modo con el que se va a trabajar el canal de venta.
                    //chazki.time = "";
                    //chazki.paymentMethod = "Pagado";
                    //chazki.country = "PE";

                    /* DATA ARTICULO*/

                    List <Ent_ItemSold_E> listItemSold = new List <Ent_ItemSold_E>();
                    foreach (var producto in cvCzk.listaArticulos)
                    {
                        if (producto.codigoProducto != "9999997")
                        {
                            Ent_ItemSold_E _item = new Ent_ItemSold_E();
                            _item.name     = producto.nombreProducto;
                            _item.currency = "PEN";
                            _item.price    = Convert.ToDouble(producto.total);
                            _item.weight   = 0.3;
                            _item.volumen  = 0;
                            _item.quantity = producto.cantidad;
                            _item.unity    = "Caja";
                            _item.size     = "M";
                            listItemSold.Add(_item);
                        }
                    }

                    //CLIENTE
                    chazki.listItemSold   = listItemSold;
                    chazki.notes          = "Entregar a Cliente";
                    chazki.documentNumber = cvCzk.informacionTiendaDestinatario.nroDocumento;
                    //chazki.email = "*****@*****.**";
                    if (cvCzk.informacionTiendaDestinatario.email == "" || cvCzk.informacionTiendaDestinatario.email == null)
                    {
                        chazki.email = "servicio.clientes.peru @bata.com";
                    }
                    else
                    {
                        chazki.email = cvCzk.informacionTiendaDestinatario.email; //
                    }

                    chazki.phone = cvCzk.informacionTiendaDestinatario.telefono;
                    int CadRuc = cvCzk.informacionTiendaDestinatario.nroDocumento.Length;

                    if (CadRuc > 8)
                    {
                        chazki.documentType = "RUC";
                        chazki.lastName     = "";
                        chazki.companyName  = cvCzk.informacionTiendaDestinatario.cliente;
                        chazki.name_tmp     = "";
                    }
                    else
                    {
                        chazki.documentType = "DNI";
                        chazki.companyName  = "";
                        chazki.name_tmp     = cvCzk.informacionTiendaDestinatario.cliente;
                        chazki.lastName     = "";
                    }
                    /* DATA DIRECCION*/
                    List <Ent_AddressClient_E> listAdressClient = new List <Ent_AddressClient_E>();
                    Ent_AddressClient_E        addressClient    = new Ent_AddressClient_E();
                    Dat_Chazki datos     = new Dat_Chazki();
                    string[]   desUbigeo = null;

                    desUbigeo               = datos.get_des_ubigeo(cvCzk.informacionTiendaDestinatario.ubigeo);
                    addressClient.nivel_2   = desUbigeo[0];
                    addressClient.nivel_3   = desUbigeo[1];
                    addressClient.nivel_4   = desUbigeo[2];
                    addressClient.name      = cvCzk.informacionTiendaDestinatario.direccion_entrega;
                    addressClient.reference = cvCzk.informacionTiendaDestinatario.referencia;
                    addressClient.alias     = "No Alias";
                    Ent_Position_E position = new Ent_Position_E();
                    position.latitude      = 0;
                    position.longitude     = 0;
                    addressClient.position = position;
                    listAdressClient.Add(addressClient);
                    chazki.addressClient = listAdressClient;

                    list_chazki.Add(chazki);

                    string jsonChazki        = JsonConvert.SerializeObject(list_chazki);
                    Response_Registro_E rpta = new Response_Registro_E();

                    using (var http = new HttpClient())
                    {
                        http.DefaultRequestHeaders.Add("chazki-api-key", cvCzk.informacionTiendaEnvio.api_key); //PRODUCCION
                        //http.DefaultRequestHeaders.Add("chazki-api-key", "KfXfqgEBhfMK4T8Luw8ba91RynMtjzTY"); //TEST

                        HttpContent content = new StringContent(jsonChazki);
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                        var request = http.PostAsync("https://integracion.chazki.com:8443/chazkiServices/delivery/create/deliveryService", content); //PRODUCCION
                        //var request = http.PostAsync("https://sandboxintegracion.chazki.com:8443/chazkiServices/delivery/create/deliveryService", content); //TEST

                        var response = request.Result.Content.ReadAsStringAsync().Result;
                        rpta = JsonConvert.DeserializeObject <Response_Registro_E>(response);

                        if (rpta.descriptionResponse == "SUCCESS")
                        {
                            retorno = rpta.codeDelivery;
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                retorno = "";
            }
            return(retorno);
        }
Beispiel #3
0
        public Ent_Ecommerce_Chazki get_Ventas_por_Chazki(string ven_id, string tienda_id)
        {
            Ent_Ecommerce_Chazki ven = null;
            string sqlquery          = "USP_ECOMMERCE_LISTA_CHAZKI_split";

            try
            {
                using (SqlConnection cn = new SqlConnection(Ent_Conexion.conexion))
                {
                    if (cn.State == 0)
                    {
                        cn.Open();
                    }
                    using (SqlCommand cmd = new SqlCommand(sqlquery, cn))
                    {
                        cmd.CommandTimeout = 0;
                        cmd.CommandType    = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@ven_id", ven_id);
                        cmd.Parameters.AddWithValue("@ven_tda", tienda_id);
                        SqlDataAdapter da = new SqlDataAdapter(cmd);
                        DataSet        ds = new DataSet();
                        da.Fill(ds);
                        if (ds.Tables.Count > 0)
                        {
                            //DataTable dtC = ds.Tables[0];
                            DataTable dtArticulos = ds.Tables[0]; //data articulos
                            DataTable dtChazki    = ds.Tables[1]; //data chaski
                            DataTable dtCliente   = ds.Tables[2]; //data direccion cliente
                            ven = new Ent_Ecommerce_Chazki();
                            /*ARTICULOS*/
                            List <Ent_ListaArticulos> listaArticulos = new List <Ent_ListaArticulos>();
                            foreach (DataRow item in dtArticulos.Rows)
                            {
                                Ent_ListaArticulos venD = new Ent_ListaArticulos();
                                venD.codigoProducto = item["codigo_articulo"].ToString();
                                venD.nombreProducto = item["descripcion_articulo"].ToString();
                                venD.total          = item["precio_total"].ToString();
                                venD.cantidad       = Convert.ToInt32(Convert.ToDouble(item["cantidad"].ToString()));
                                listaArticulos.Add(venD);
                            }
                            ven.listaArticulos = listaArticulos;
                            /*TIENDA ORIGEN*/
                            if (dtChazki.Rows.Count > 0)
                            {
                                Ent_ChazkiApi Chazki = new Ent_ChazkiApi();
                                Chazki.storeId           = dtChazki.Rows[0]["chazki_store_id"].ToString();
                                Chazki.branchId          = dtChazki.Rows[0]["chazki_branch_id"].ToString();
                                Chazki.api_key           = dtChazki.Rows[0]["chaski_api_key"].ToString();
                                Chazki.deliveryTrackCode = dtChazki.Rows[0]["deliveryTrack_Code"].ToString();
                                Chazki.mode                = dtChazki.Rows[0]["mode"].ToString();
                                Chazki.time                = dtChazki.Rows[0]["tiempo"].ToString();
                                Chazki.paymentMethod       = dtChazki.Rows[0]["payment_method"].ToString();
                                ven.informacionTiendaEnvio = Chazki;
                            }
                            /*CLENTE DESTINO*/
                            if (dtCliente.Rows.Count > 0)
                            {
                                Ent_Cliente Cliente = new Ent_Cliente();

                                Cliente.nroDocumento      = dtCliente.Rows[0]["dni_ruc"].ToString();
                                Cliente.email             = dtCliente.Rows[0]["correo"].ToString();
                                Cliente.cliente           = dtCliente.Rows[0]["cliente"].ToString();
                                Cliente.referencia        = "";
                                Cliente.telefono          = dtCliente.Rows[0]["telefono"].ToString();
                                Cliente.direccion_entrega = dtCliente.Rows[0]["direccion_cliente"].ToString();
                                Cliente.ubigeo            = dtCliente.Rows[0]["ubigeo"].ToString();

                                ven.informacionTiendaDestinatario = Cliente;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ven = null;
            }
            return(ven);
        }