public static void WriteRecieptExtractions(object Extractions) { var extractions = (List <ExtractionModel>)Extractions; List <string> properties = new ExtractionModel().GetType().GetProperties().Select(x => x.Name).ToList(); StringBuilder sbHeader = new StringBuilder(); foreach (var prop in properties) { sbHeader.AppendFormat("{0}\t", prop); } string filepath = string.Format(@"C:\Internal\Etsy\{0}_etsy_extractiondata.txt", DateTime.Now.ToString("yyMMdd")); using (StreamWriter writer = new StreamWriter(filepath)) { writer.WriteLine(sbHeader.ToString()); foreach (var ext in extractions.OrderBy(x => x.Order_ID)) { StringBuilder sbData = new StringBuilder(); foreach (var prop in properties) { var o = ext.GetType().GetProperty(prop).GetValue(ext, null); if (o == null) { o = ""; } sbData.AppendFormat("{0}\t", o.ToString()); } writer.WriteLine(sbData.ToString()); } } }
private DataTable ReceiveData(ExtractionModel model, TableInfo info) { using OdbcConnection connection = new OdbcConnection(_configModel.DbfOdbcConn); connection.Open(); OdbcCommand command = connection.CreateCommand(); DataTable dataTable = new DataTable(); string toSelect = string.Join(",", info.SqlColumnTypes.Keys .Except(info.CustomColumns).ToList()); command.CommandText = $"SELECT {toSelect} FROM {model.TableName}"; dataTable.Load(command.ExecuteReader()); return(dataTable); }
private void Custom(ExtractionModel model, DataTable data, TableInfo info) { foreach (string customCol in info.CustomColumns) { data.Columns.Add(customCol, typeof(int)); } if (!int.TryParse(model.TableName.Substring(0, model.TableName.IndexOf("_")), out int shopNum)) { throw new ExtractionException($"Can't parse shop number: {model.FullDescription}"); } foreach (DataRow row in data.Rows) { row[data.Columns.Count - 1] = shopNum; } }
public HttpResponseMessage GetExtractionWithChildren(HttpRequestMessage request, int extractionId) { return(GetHttpResponse(request, () => { HttpResponseMessage response = null; var extractionModel = new ExtractionModel(); extractionModel.Extraction = _ExtractionProcessService.GetExtraction(extractionId); extractionModel.ExtractionRoles = _ExtractionProcessService.GetExtractionRoleByExtraction(extractionId); // notice no need to create a seperate model object since Extraction entity will do just fine response = request.CreateResponse <ExtractionModel>(HttpStatusCode.OK, extractionModel); return response; })); }
private void FillShareds(ExtractionModel model, TableInfo info) { if (!File.Exists(Path.Combine(_configModel.DbfLookUpDir, model.DbfName))) { throw new ExtractionException($"Can't find dbf file to receive data on: {model.FullDescription}"); } DataTable data = ReceiveData(model, info); if (info.CustomColumns.Count > 0) { Custom(model, data, info); } if (!_parents.Any(t => t.TableType.Equals(model.TableType))) { _parents.Add(new SharedParent { TableType = model.TableType, SharedChilds = new List <SharedChild>() }); } SharedParent parent = _parents .Where(t => t.TableType.Equals(model.TableType)) .FirstOrDefault(); if (parent is null) { throw new ExtractionException($"Can't find parent table with type, {model.FullDescription}"); } SharedChild child = new SharedChild { FileName = model.DbfName, PackageName = model.Package, Rows = data.Select() }; parent.SharedChilds.Add(child); }
public static void ExtractionReport(List <Order> Orders, ShipstationCustomer Company, List <Store> Stores) { List <ExtractionModel> extractions = new List <ExtractionModel>(); var carriers = ImportHelper.GetObjectFromJsonArray <Carrier>("carriers.js"); var services = ImportHelper.GetObjectFromJsonArray <Service>("services.js"); foreach (var order in Orders) { var store = Stores.Where(x => x.storeId == int.Parse(order.advancedOptions.storeId)).FirstOrDefault(); var carrier = carriers.Where(x => x.code == order.carrierCode).FirstOrDefault(); var service = services.Where(x => x.code == order.serviceCode).FirstOrDefault(); foreach (var item in order.items) { ExtractionModel em = new ExtractionModel(); em.etsy_company_id = Company.CompanyId; if (carrier != null) { em.Carrier_Carrier_Selected = carrier.name; em.Carrier_Service_Selected = service.name; } else { em.Carrier_Carrier_Selected = ""; em.Carrier_Service_Selected = ""; } em.Carrier_Service_Requested = order.requestedShippingService; if (order.advancedOptions != null) { em.Custom_Field_1 = order.advancedOptions.customField1; em.Custom_Field_2 = order.advancedOptions.customField2; em.Custom_Field_3 = order.advancedOptions.customField3; } else { em.Custom_Field_1 = ""; em.Custom_Field_2 = ""; em.Custom_Field_3 = ""; } em.Date_Order_Date = order.orderDate; em.Gift_Message = (order.giftMessage != null ? order.giftMessage.Replace("\t", " ").Replace("\n", " ") : ""); if (order.insuranceOptions.insuredValue == "0") { em.Insurance_Cost = "0.00"; } else { em.Insurance_Cost = order.insuranceOptions.insuredValue; } em.Item_Fill_SKU = item.fulfillmentSku; em.Item_Image_URL = item.imageUrl; em.Item_Name = item.name; em.Item_ISBN = item.upc; if (store.marketplaceName == "Etsy") { if (item.options.Count > 0) { em.Item_Options = string.Format("{0}: {1}, {2}: {3}", item.options[0].name, item.options[0].value, item.options[1].name, item.options[1].value); em.Variation_Value = string.Format("{0},{1}", item.options[0].value.Replace("'", "'"), item.options[1].value.Replace("'", "'")); } else { em.Item_Options = ""; } } else if (store.marketplaceName == "Amazon") { em.Item_Options = item.sku; } else { if (item.options.Count > 0) { em.Item_Options = string.Format("{0}: {1}, {2}: {3}", item.options[0].name, item.options[0].value, item.options[1].name, item.options[1].value); } else { em.Item_Options = ""; } } em.Item_Qty = item.quantity; em.Item_SKU = item.sku; em.Market_Markeplace_Name = store.marketplaceName; em.Market_Market_Order_URL = ""; em.Market_Store_Name = store.storeName; em.Notes_From_Buyer = (order.customerNotes != null ? order.customerNotes.Replace("\t", " ").Replace("\n", " ").Replace("\r", "") : ""); em.Notes_Internal = (order.internalNotes != null ? order.internalNotes.Replace("\t", " ").Replace("\n", " ").Replace("\r", "") : ""); em.Order_Number = order.orderNumber; em.Order_Status = order.orderStatus; em.Ship_To_Address_1 = order.shipTo.street1; em.Ship_To_Address_2 = order.shipTo.street2; em.Ship_To_Address_3 = order.shipTo.street3; em.Ship_To_City = order.shipTo.city; em.Ship_To_Company = order.shipTo.company; em.Ship_To_Country = order.shipTo.country; em.Ship_To_FirstName = FormattingHelpers.FirstNameLastNameFormatter(order.shipTo.name).Item1; em.Ship_To_LastName = FormattingHelpers.FirstNameLastNameFormatter(order.shipTo.name).Item2; em.Ship_To_Phone = order.shipTo.phone; em.Ship_To_Postal_Code = order.shipTo.postalCode; em.Ship_To_State = order.shipTo.state; extractions.Add(em); } } List <string> properties = new ExtractionModel().GetType().GetProperties().Select(x => x.Name).ToList(); StringBuilder sbHeader = new StringBuilder(); foreach (var prop in properties) { sbHeader.AppendFormat("{0}\t", prop); } using (StreamWriter writer = new StreamWriter(System.Configuration.ConfigurationManager.AppSettings["Path"] + Company.CompanyName + " orders.txt")) { writer.WriteLine(sbHeader.ToString()); foreach (var ext in extractions.OrderBy(x => x.Order_Number)) { StringBuilder sbData = new StringBuilder(); foreach (var prop in properties) { var o = ext.GetType().GetProperty(prop).GetValue(ext, null); if (o == null) { o = ""; } sbData.AppendFormat("{0}\t", o.ToString()); } writer.WriteLine(sbData.ToString()); } } }
public static void ExtractionExport(List <Receipt> Receipts, string filepath, Dictionary <int, string> Countries, bool run) { if (run) { if (File.Exists(filepath)) { File.Delete(filepath); } List <ExtractionModel> extractions = new List <ExtractionModel>(); var gclient = InternalClientService.GetInternalClientByEtsyID(Receipts.FirstOrDefault().seller_user_id); if (gclient != null) { foreach (Receipt r in Receipts) { foreach (var t in r.transactions) { string country = Countries[int.Parse(r.country_id)]; ExtractionModel em = new ExtractionModel(); em.company_id = gclient.clientID; em.Order_ID = r.receipt_id; em.date_purchased = FormattingHelpers.FromEpochUnixTime(t.creation_tsz).ToString("g"); em.customer_email_address = r.buyer_email; var FirstnameLastname = FormattingHelpers.FirstNameLastNameFormatter(r.name); em.first_name = FirstnameLastname.Item1; em.last_name = FirstnameLastname.Item2; em.delivery_address_1 = r.first_line; em.delivery_address_2 = r.second_line; em.delivery_city = r.city; em.delivery_state = r.state; em.delivery_zipCode = r.zip; em.country = country; string[] color_design = t.variations.Where(x => x.formatted_name == "Color").FirstOrDefault().formatted_value.Split('-'); em.color = color_design[0].Trim(); em.design_number = FormattingHelpers.DesignNumberFormatCheck(color_design[1].Trim()); em.design_description = "TBD"; em.print_location = "TBD"; string[] size_style = t.variations.Where(x => x.formatted_name == "Size").FirstOrDefault().formatted_value.Split('-'); string etsystyle = size_style[1].Trim(); em.size = size_style[0].Trim(); em.style_number = gclient.ClientStyles.Where(x => x.etsy_style_descripion == etsystyle).First().style_number; em.style_description = gclient.ClientStyles.Where(x => x.etsy_style_descripion == etsystyle).First().style_description; em.product_quantity = t.quantity; em.gift_message = r.message_from_buyer; em.Insured_Order = "No"; em.shipping_method = CountryService.GetCountryShippingMethodByCountry(country).Shipping_Method; em.order_status = "2"; extractions.Add(em); } } } List <string> properties = new ExtractionModel().GetType().GetProperties().Select(x => x.Name).ToList(); StringBuilder sbHeader = new StringBuilder(); foreach (var prop in properties) { sbHeader.AppendFormat("{0}\t", prop); } using (StreamWriter writer = new StreamWriter(filepath.Replace(".txt", "_extractiondata" + DateTime.Now.ToString("yyMMdd") + ".txt"))) { writer.WriteLine(sbHeader.ToString()); foreach (var ext in extractions.OrderBy(x => x.Order_ID)) { StringBuilder sbData = new StringBuilder(); foreach (var prop in properties) { var o = ext.GetType().GetProperty(prop).GetValue(ext, null); if (o == null) { o = ""; } sbData.AppendFormat("{0}\t", o.ToString()); } writer.WriteLine(sbData.ToString()); } } } }
public static List <ExtractionModel> CreateExtractionFromReceipt(InternalClient GClient, bool allReceipts) { //Creation New Rest Client var client = new RestClient(); client.BaseUrl = AppKeys.GetBaseUri(); client.Authenticator = OAuth1Authenticator.ForProtectedResource(AppKeys.GetApiKey(), AppKeys.GetSharedSecretKey(), GClient.AccessToken, GClient.AccessSecretKey); //The shop servce is where we pull receipts because functionally //The call is related to the shop object and te shop id ShopService shopservice = new ShopService(); List <Receipt> receipts; //This is just in case for some reason we want every transaction from a shop if (allReceipts) { receipts = shopservice.GetShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault()); } else { receipts = shopservice.GetOpenShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault()); } //Get the country list from etsy in advance so it doesn't //Have to be called per receipt request var countries = CountryService.GetCountryMapping(client); List <ExtractionModel> extractions = new List <ExtractionModel>(); //make sure we actually pulled back client data if (GClient != null) { //iteract through receipts foreach (Receipt r in receipts) { //iterrate through transactions of receipts foreach (var t in r.transactions) { string country = countries[int.Parse(r.country_id)]; ExtractionModel em = new ExtractionModel(); em.company_id = GClient.clientID; em.Order_ID = r.receipt_id; em.date_purchased = FormattingHelpers.FromEpochUnixTime(t.creation_tsz).ToString("g"); em.customer_email_address = r.buyer_email; var FirstnameLastname = FormattingHelpers.FirstNameLastNameFormatter(r.name); em.first_name = FirstnameLastname.Item1; em.last_name = FirstnameLastname.Item2; em.delivery_address_1 = r.first_line; em.delivery_address_2 = r.second_line; em.delivery_city = r.city; em.delivery_state = r.state; em.delivery_zipCode = r.zip; em.country = country; //This is for the variation that is assuming //it follows the format "Color - Design" string[] color_design = t.variations.Where(x => x.formatted_name == "Color").FirstOrDefault().formatted_value.Split('-'); //If there is not a "-" then it automatically //is the wrong format if (color_design.Length > 1) { //This is making sure that the Design actually is associated //with the client //TODO: Eventually check that the design is actually available in the color //that is provided. if (GClient.ClientDesigns.Where(x => x.design_number.Trim() == color_design[1].Trim()).Any()) { em.color = color_design[0].Trim(); em.design_number = FormattingHelpers.DesignNumberFormatCheck(color_design[1].Trim()); } else { em.color = color_design[0].Trim(); em.design_number = string.Format("{0} Is Not a Correct Design Id", color_design[1]); } } else { em.color = color_design[0].Trim(); em.design_number = "Color_Design Incorrect Format"; } em.design_description = "TBD"; em.print_location = "TBD"; //This is for the variation that is assuming //it follows the format "Style - Size" string[] size_style = t.variations.Where(x => x.formatted_name == "Size").FirstOrDefault().formatted_value.Split('-'); if (size_style.Length > 1) { string etsystyle = size_style[1].Trim(); em.size = size_style[0].Trim(); //Check to see if the style from the variation //has a mapping otherwise we can't know what //prodct style its suposed to be var style = GClient.ClientStyles.Where(x => x.etsy_style_descripion == etsystyle).FirstOrDefault(); if (style != null) { em.style_number = style.style_number; em.style_description = style.style_description; } else { em.style_number = "ESTY STYLE '" + etsystyle + "' NOT FOUND"; em.style_description = "ESTY STYLE '" + etsystyle + "' NOT FOUND"; } } else { em.style_number = size_style[0].Trim(); em.style_description = "Size_Style Incorrect Format"; } em.product_quantity = t.quantity; em.gift_message = r.message_from_buyer; em.Insured_Order = "No"; em.shipping_method = CountryService.GetCountryShippingMethodByCountry(country).Shipping_Method; em.order_status = "2"; extractions.Add(em); } } } return(extractions); }