public static string ImportaDataPrestaShop(TextWriter log) { string _error = ""; DataTable dtpedidos = null; DataTable dtpedidospag = null; try { dtpedidos = PrepararPedidos(); dtpedidospag = PrepararPedidos_Pagos(); if (dtpedidos != null && dtpedidospag != null) { Dat_PrestaShop update_psth = new Dat_PrestaShop(); /*agrupamos los pedidos*/ var grupo_pedido = from item in dtpedidos.AsEnumerable() //where item.Field<string>("ped_id") == "73" //|| item.Field<Int32>("ped_id") ==40 group item by new { ped_id = Convert.ToInt32(item["ped_id"]), // Modificado por : Henry Morales - 01/04/2019 // Se agregó dato de Tienda tda_id = item["tda_id"].ToString(), ped_ref = item["ped_ref"].ToString(), ped_fecha = Convert.ToDateTime(item["ped_fecha"]), ped_ubigeo_ent = item["ped_ubigeo_ent"].ToString(), ped_dir_ent = item["ped_dir_ent"].ToString(), ped_ref_ent = item["ped_ref_ent"].ToString(), // Modificado por : Henry Morales - 21/05/2018 // Se agergaron los campos de nombre y telefono de referencia para la entrega ped_nom_ent = item["ped_nom_ent"].ToString(), ped_tel_ent = item["ped_tel_ent"].ToString(), //det_peso =Convert.ToDecimal(item["det_peso"]), ped_total_sigv = Convert.ToDecimal(item["ped_total_sigv"]), ped_total_cigv = Convert.ToDecimal(item["ped_total_cigv"]), ped_dcto_sigv = Convert.ToDecimal(item["ped_dcto_sigv"]), ped_dcto_cigv = Convert.ToDecimal(item["ped_dcto_cigv"]), cli_id = item["cli_id"].ToString(), cli_nombres = item["cli_nombres"].ToString(), cli_apellidos = item["cli_apellidos"].ToString(), cli_email = item["cli_email"].ToString(), cli_direc = item["cli_direc"].ToString(), cli_telf = item["cli_telf"].ToString(), cli_telf_mov = item["cli_telf_mov"].ToString(), cli_dni = item["cli_dni"].ToString(), cli_ubigeo = item["cli_ubigeo"].ToString(), ped_ship_sigv = Convert.ToDecimal(item["ped_ship_sigv"]), name_courier = Convert.ToString(item["name_courier"]), // Modificado por : Henry Morales - 19/06/2018 // Se modificó para tomar los pagos en diferentes formas de pago (DataTable dtpedidospag) /*pag_metodo = item["pag_metodo"].ToString(), * pag_nro_trans = item["pag_nro_trans"].ToString(), * pag_fecha = Convert.ToDateTime(item["pag_fecha"]), * pag_monto = Convert.ToDecimal(item["pag_monto"]),*/ } into G select new { pedido = G.Key.ped_id, tda_id = G.Key.tda_id, ped_ref = G.Key.ped_ref, ped_fecha = G.Key.ped_fecha, ped_ubigeo_ent = G.Key.ped_ubigeo_ent, ped_dir_ent = G.Key.ped_dir_ent, ped_ref_ent = G.Key.ped_ref_ent, // Modificado por : Henry Morales - 21/05/2018 // Se agergaron los campos de nombre y telefono de referencia para la entrega ped_nom_ent = G.Key.ped_nom_ent, ped_tel_ent = G.Key.ped_tel_ent, cli_telf_mov = G.Key.cli_telf_mov, //det_peso=G.Key.det_peso, ped_total_sigv = G.Key.ped_total_sigv, ped_total_cigv = G.Key.ped_total_cigv, ped_dcto_sigv = G.Key.ped_dcto_sigv, ped_dcto_cigv = G.Key.ped_dcto_cigv, cli_id = G.Key.cli_id, cli_nombres = G.Key.cli_nombres, cli_apellidos = G.Key.cli_apellidos, cli_email = G.Key.cli_email, cli_direc = G.Key.cli_direc, cli_telef = G.Key.cli_telf, cli_dni = G.Key.cli_dni, cli_ubigeo = G.Key.cli_ubigeo, ped_ship_sigv = G.Key.ped_ship_sigv, name_courier = G.Key.name_courier, // Modificado por : Henry Morales - 19/06/2018 // Se modificó para tomar los pagos en diferentes formas de pago (DataTable dtpedidospag) /*pag_metodo = G.Key.pag_metodo, * pag_nro_trans = G.Key.pag_nro_trans, * pag_fecha = G.Key.pag_fecha, * pag_monto = G.Key.pag_monto*/ }; /*recorremos los pedidos para agregar al pedido*/ foreach (var key in grupo_pedido) { /*verifica si pedido existe*/ Boolean _existe = update_psth.Existe_Pedido_Prestashop(key.pedido.ToString()); if (_existe) { /*Si ya existe pedido y no ha facturado*/ } else { /*capturamos el detalle */ var ped_det = from item in dtpedidos.AsEnumerable() where item.Field <string>("ped_id") == Convert.ToString(key.pedido) //&& item.Field<string>("det_artic_ref").Length == 11 select new { det_artic_ref = item["det_artic_ref"].ToString(), det_desc_artic = Convert.ToString(item["det_desc_artic"]), det_cant = Convert.ToInt32(item["det_cant"]), det_prec_sigv = Convert.ToDecimal(item["det_prec_sigv"]), // SQL : Liq_Det_Precio det_peso = Convert.ToDecimal(item["det_peso"]), //det_prec_cigv = Convert.ToDecimal(item["det_prec_cigv"]), det_dcto_sigv = Convert.ToDecimal(item["det_dcto_sigv"]), // SQL : Liq_Det_comision }; /*Recorremos el detalle*/ List <Order_Dtl> items_det = new List <Order_Dtl>(); Decimal _tot_peso = 0; foreach (var key_det in ped_det) { Order_Dtl dtl = new Order_Dtl(); string articulo_talla = key_det.det_artic_ref.ToString().Trim().Replace("-", ""); string articulo = articulo_talla.Substring(0, 7); string talla = articulo_talla.Substring(7, articulo_talla.Length - 7); dtl._code = articulo; dtl._size = talla; dtl._qty = Convert.ToInt32(key_det.det_cant); dtl._priceigv = key_det.det_prec_sigv; dtl._price = Convert.ToDecimal(Math.Round(Convert.ToDouble(key_det.det_prec_sigv), 2, MidpointRounding.AwayFromZero)); dtl._commissionPctg = 0; dtl._commissionigv = 0; dtl._det_dcto_sigv = Math.Round(key_det.det_dcto_sigv, 2, MidpointRounding.AwayFromZero); dtl._commission = Convert.ToDecimal(Math.Round(Convert.ToDouble((dtl._det_dcto_sigv * dtl._qty)), 2, MidpointRounding.AwayFromZero)); dtl._ofe_porc = 0; dtl._dsctoVale = 0; dtl._ofe_id = 0; dtl._art_des = key_det.det_desc_artic; dtl._art_peso = key_det.det_peso; _tot_peso += key_det.det_peso * key_det.det_cant; items_det.Add(dtl); } #region <AJUSTE DESCUENTO> Decimal ajuste_subtotal = key.ped_total_sigv; var subtot = items_det.Sum(a => (a._price * a._qty) - a._commission); subtot += key.ped_ship_sigv; Decimal saldo = ajuste_subtotal - subtot; if (saldo != 0) { if (items_det[0]._commission != 0) { items_det[0]._commission = items_det[0]._commission - saldo; } else { Int32 item_ult = items_det.Count() - 1; items_det[item_ult]._price = items_det[item_ult]._price + saldo; } // ¨****** Verificar // Cambiar si el Saldo es diferente de 0,sumarlo al Pet_Det_Precio (dtl._price) } #endregion /*si esta lleno el list entonces agregamos el pedido en este ,metodo*/ if (items_det.Count > 0) { /*datos del cliente*/ Cliente cl = new Cliente(); cl.cli_nombres = key.cli_nombres; cl.cli_apellidos = key.cli_apellidos; cl.cli_email = key.cli_email; cl.cli_ubigeo = key.cli_ubigeo; cl.cli_direc = key.cli_direc; cl.cli_telf = key.cli_telef; cl.cli_telf_mov = key.cli_telf_mov; cl.cli_dni = key.cli_dni; /*********************/ /*metodo de pago*/ Pagos pg = new Pagos(); // Modificado por : Henry Morales - 19/06/2018 // Se modificó para tomar los pagos en diferentes formas de pago (DataTable dtpedidospag) /*pg.pag_metodo = key.pag_metodo; * pg.pag_nro_trans = key.pag_nro_trans; * pg.pag_fecha = key.pag_fecha; * pg.pag_monto = key.pag_monto;*/ DataTable pago_ped = new DataTable(); pago_ped = dtpedidospag.Clone(); pago_ped.Clear(); foreach (DataRow row in dtpedidospag.Rows) { if (row["ped_id"].ToString() == key.pedido.ToString()) { pago_ped.ImportRow(row); } } /**/ decimal igv_monto = key.ped_dcto_cigv - key.ped_dcto_sigv; //string[] pedido_update= // Modificado por : Henry Morales - 19/06/2018 // Se agergo la tabla dtpedidospag, para enviar la información de diferentes formas de pago // Modificado por : Henry Morales - 21/05/2018 // Se agergaron los campos de nombre y telefono de referencia para la entrega ( key.ped_nom_ent ; key.ped_tel_ent) string[] result = update_psth.Update_Pedido_Prestashop(1 /*Ent_Global._bas_id_codigo*/, key.tda_id, 9219, "", 0, 0, "", "", items_det, 0, 1, "", "", 0, 0, "", "", 0, null, false, 0, null, key.pedido, key.ped_ref, key.ped_ship_sigv, cl, pg, key.ped_fecha, key.ped_total_cigv, key.ped_ubigeo_ent, key.ped_dir_ent, key.ped_ref_ent, key.ped_nom_ent, key.ped_tel_ent, _tot_peso, pago_ped, key.name_courier); if (result[0].ToString() == "-1") { _error += result[1].ToString(); } else { // Se agrego para que procese luego de lectura de PS // Guia de Remisión Int32 _valida_guia; string cod_liq = result[0].ToString(); Dat_ConfigGuia.insertar_guia("0", 9, cod_liq, out _valida_guia, key.tda_id); // Genera paquete //decimal _paq_id; //_paq_id = Dat_Venta.insertar_leer_paquete(cod_liq); // Generación de Facturación string _error_venta = ""; string grabar_numerodoc = Dat_Venta.insertar_venta(cod_liq, ref _error_venta); if (grabar_numerodoc != "-1") { //aca generamos el codigo hash string _codigo_hash = ""; string _error2 = ""; string _url_pdf = ""; //Facturacion_Electronica.ejecutar_factura_electronica(grabar_numerodoc.Substring(0, 1), grabar_numerodoc, ref _codigo_hash, ref _error2, ref _url_pdf); ////Facturacion_Electronica.ejecutar_factura_electronica_ws(grabar_numerodoc.Substring(0, 1), grabar_numerodoc, ref _codigo_hash, ref _error,ref _url_pdf); //if (_codigo_hash.Length == 0 || _codigo_hash == null) //{ // Facturacion_Electronica.ejecutar_factura_electronica(grabar_numerodoc.Substring(0, 1), grabar_numerodoc, ref _codigo_hash, ref _error2, ref _url_pdf); //} //if (_codigo_hash.Length == 0 || _codigo_hash == null) //{ // _error = "ERROR HASH:"; //} //if (_error.Length > 0) //{ // log.WriteLine(_error+ " " + _error2 + " En Documento: "+ grabar_numerodoc); // /*Error*/ //} //Dat_Venta.insertar_codigo_hash(grabar_numerodoc, _codigo_hash, "V", _url_pdf); UpdaEstado updateestado = new UpdaEstado(); string[] valida = updateestado.ActualizaEstadoPS(key.ped_ref, 33); if (key.name_courier.Contains("iend")) { string[] valida2 = updateestado.ActualizaEstadoPS(key.ped_ref, 3); } } } }
public string[] Update_Pedido_Prestashop_Alm(decimal _usu, decimal _idCust, string _reference, decimal _discCommPctg, decimal _discCommValue, string _shipTo, string _specialInstr, List <Order_Dtl> _itemsDetail, decimal _varpercepcion, Int32 _estado, string _ped_id = "", string _liq = "", Int32 _liq_dir = 0, Int32 _PagPos = 0, string _PagoPostarjeta = "", string _PagoNumConsignacion = "", decimal _PagoTotal = 0, DataTable dtpago = null, Boolean _pago_credito = false, Decimal _porc_percepcion = 0, List <Order_Dtl_Temp> order_dtl_temp = null, decimal _Liq_Pst_Id = 0, string _Liq_Pst_Ref = "", Decimal _CostoE = 0, Cliente cl = null, Pagos pag = null, DateTime?_ped_fecha = null, decimal _liq_tot_cigv = 0, string _ped_ubigeo_ent = "", string _ped_dir_ent = "", string _ped_ref_ent = "", string _ped_nom_ent = "", string _ped_tel_ent = "", Decimal _det_peso = 0, DataTable pagos = null, string _name_courier = null) { string[] resultDoc = new string[2]; string sqlquery = "USP_Insertar_Modifica_Liquidacion"; SqlConnection cn = null; SqlCommand cmd = null; try { DataTable dt = new DataTable(); dt.Columns.Add("Ped_Det_Id", typeof(string)); dt.Columns.Add("Ped_Det_Items", typeof(Int32)); dt.Columns.Add("Ped_Det_ArtId", typeof(string)); dt.Columns.Add("Ped_Det_TalId", typeof(string)); dt.Columns.Add("Ped_Det_Cantidad", typeof(Int32)); dt.Columns.Add("Ped_Det_Costo", typeof(decimal)); dt.Columns.Add("Ped_Det_Precio", typeof(decimal)); dt.Columns.Add("Ped_Det_ComisionP", typeof(decimal)); dt.Columns.Add("Ped_Det_ComisionM", typeof(decimal)); dt.Columns.Add("Ped_Det_OfertaP", typeof(decimal)); dt.Columns.Add("Ped_Det_OfertaM", typeof(decimal)); dt.Columns.Add("Ped_Det_OfeID", typeof(decimal)); dt.Columns.Add("Ped_Det_ArtDes", typeof(string)); dt.Columns.Add("Ped_Det_Peso", typeof(decimal)); int i = 1; // Recorrer todas las lineas adicionAQUARELLAs al detalle if (_itemsDetail != null) { foreach (Order_Dtl item in _itemsDetail) { dt.Rows.Add(_ped_id, i, item._code, item._size, item._qty, 0, item._price, item._commissionPctg, Math.Round(item._commission, 2, MidpointRounding.AwayFromZero), item._ofe_porc, item._dscto, item._ofe_id, item._art_des, item._art_peso); i++; } } /*pedido original*/ DataTable dtordertmp = new DataTable(); dtordertmp.Columns.Add("items", typeof(Int32)); dtordertmp.Columns.Add("articulo", typeof(string)); dtordertmp.Columns.Add("talla", typeof(string)); dtordertmp.Columns.Add("cantidad", typeof(Int32)); if (order_dtl_temp != null) { foreach (Order_Dtl_Temp item in order_dtl_temp) { dtordertmp.Rows.Add(item.items, item.articulo, item.talla, item.cantidad); } } //grabar pedido //cn = new SqlConnection(Ent_Conexion.conexion); cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL_ECOM"].ToString()); if (cn.State == 0) { cn.Open(); } cmd = new SqlCommand(sqlquery, cn); cmd.CommandTimeout = 0; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Estado", _estado); cmd.Parameters.AddWithValue("@Ped_Id", _ped_id); //cmd.Parameters.AddWithValue("@LiqId", _liq); cmd.Parameters.Add("@LiqId", SqlDbType.VarChar, 12); cmd.Parameters["@LiqId"].Value = _liq; cmd.Parameters["@LiqId"].Direction = ParameterDirection.InputOutput; cmd.Parameters.AddWithValue("@Liq_BasId", _idCust); cmd.Parameters.AddWithValue("@Liq_ComisionP", _discCommPctg); cmd.Parameters.AddWithValue("@Liq_PercepcionM", _varpercepcion); cmd.Parameters.AddWithValue("@Liq_Usu", _usu); cmd.Parameters.AddWithValue("@Liq_Pst_Id", _Liq_Pst_Id); cmd.Parameters.AddWithValue("@Liq_Pst_Ref", _Liq_Pst_Ref); cmd.Parameters.AddWithValue("@liq_costoe", _CostoE); cmd.Parameters.AddWithValue("@liq_fecha", _ped_fecha); cmd.Parameters.AddWithValue("@liq_tot_cigv", _liq_tot_cigv); cmd.Parameters.AddWithValue("@liq_Ubigeo_ent", _ped_ubigeo_ent); cmd.Parameters.AddWithValue("@liq_dir_ent", _ped_dir_ent); cmd.Parameters.AddWithValue("@liq_dir_ref", _ped_ref_ent); // Modificado por : Henry Morales - 21/05/2018 // Se agergaron los campos de nombre y telefono de referencia de entrega cmd.Parameters.AddWithValue("@liq_nom_ref", _ped_nom_ent); cmd.Parameters.AddWithValue("@liq_tel_ref", _ped_tel_ent); cmd.Parameters.AddWithValue("@liq_pes_tot", _det_peso); /*ingreso de clientes*/ cmd.Parameters.AddWithValue("@bas_nombres", cl.cli_nombres); cmd.Parameters.AddWithValue("@bas_apellidos", cl.cli_apellidos); cmd.Parameters.AddWithValue("@bas_email", cl.cli_email); cmd.Parameters.AddWithValue("@bas_ubigeo", cl.cli_ubigeo); cmd.Parameters.AddWithValue("@bas_direccion", cl.cli_direc); cmd.Parameters.AddWithValue("@bas_telf", cl.cli_telf); cmd.Parameters.AddWithValue("@bas_cel", cl.cli_telf_mov); cmd.Parameters.AddWithValue("@bas_dni", cl.cli_dni); /****************************/ /*METODO DE PAGOS*/ // Modificado por : Henry Morales - 19/06/2018 // Se agregó para mandar los diversos pagos hechos en la liquidación cmd.Parameters.AddWithValue("@Detalle_Pago_ps", pagos); /*cmd.Parameters.AddWithValue("@pag_metodo", pag.pag_metodo); * cmd.Parameters.AddWithValue("@pag_metodo", pag.pag_metodo); * cmd.Parameters.AddWithValue("@pag_nro_trans", pag.pag_nro_trans); * cmd.Parameters.AddWithValue("@pag_fecha", pag.pag_fecha); * cmd.Parameters.AddWithValue("@pag_monto", pag.pag_monto);*/ /******************/ cmd.Parameters.AddWithValue("@Detalle_Pedido", dt); cmd.Parameters.AddWithValue("@Liquidacion_Directa", _liq_dir); /*PEDIDO ORIGINAL*/ cmd.Parameters.AddWithValue("@pedido_original", dtordertmp); //opcional pago por pos liquidacion directa cmd.Parameters.AddWithValue("@Pago_Pos", _PagPos); cmd.Parameters.AddWithValue("@Pago_PosTarjeta", _PagoPostarjeta); cmd.Parameters.AddWithValue("@Pago_numconsigacion", _PagoNumConsignacion); cmd.Parameters.AddWithValue("@Pago_Total", _PagoTotal); //pago directo de la liquidacion cmd.Parameters.AddWithValue("@DetallePago", dtpago); cmd.Parameters.AddWithValue("@Pago_Credito", _pago_credito); //porcentaje percepcion cmd.Parameters.AddWithValue("@Ped_Por_Perc", _porc_percepcion); cmd.Parameters.AddWithValue("@name_courier", _name_courier); //da = new SqlDataAdapter(cmd); //da.Fill(ds); cmd.ExecuteNonQuery(); resultDoc[0] = cmd.Parameters["@LiqId"].Value.ToString(); } catch (Exception ex) { if (cn != null) { if (cn.State == ConnectionState.Open) { cn.Close(); } } resultDoc[0] = "-1"; resultDoc[1] = ex.Message; } if (cn != null) { if (cn.State == ConnectionState.Open) { cn.Close(); } } return(resultDoc); }