From 8390f9aa336c632969b01ab1fa4f95f7c9bea4bc Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 27 Dec 2022 23:35:16 +0000 Subject: [PATCH] --- server/biz/GlobalBizSettingsBiz.cs | 52 +++++++++++++++++++++++++++--- server/util/DateUtil.cs | 16 +++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/server/biz/GlobalBizSettingsBiz.cs b/server/biz/GlobalBizSettingsBiz.cs index 0a660f1..883086d 100644 --- a/server/biz/GlobalBizSettingsBiz.cs +++ b/server/biz/GlobalBizSettingsBiz.cs @@ -219,6 +219,7 @@ namespace Sockeye.Biz var CustomerName = jCustomer["name"].Value(); if (multiSite) CustomerName += " - " + jSite["name"].Value(); + long CurrentCustomerId = 0; //Create customer if we don't have one already if (await ct.Customer.AnyAsync(z => z.Name == CustomerName)) @@ -232,8 +233,9 @@ namespace Sockeye.Biz c.DoNotContact = jCustomer["doNotContact"].Value(); c.Notes = jCustomer["notes"].Value(); c.DbId = jSite["dbId"].Value(); - if (c.DbId == "v7_no_dbid"){ - c.DbId=null; + if (c.DbId == "v7_no_dbid") + { + c.DbId = null; c.Tags.Add("v7"); } else @@ -248,13 +250,55 @@ namespace Sockeye.Biz c.EmailAddress = jCustomer["adminEmail"].Value(); CustomerBiz biz = CustomerBiz.GetBiz(ct); var NewObject = await biz.CreateAsync(c); + CurrentCustomerId = NewObject.Id; + }//customer creation - //Add all customer related shit here + //SITE PURCHASES + res = await client.GetAsync($"{URL_ROCKFISH}api/site/{jSite["id"].Value()}/purchases"); + var jaPurchaseList = JArray.Parse(await res.Content.ReadAsStringAsync()); + + foreach (JObject jPurchase in jaPurchaseList) + { + //create product if not exist then import + //Get product id if exists + var p = await ct.Product.AsNoTracking().FirstOrDefaultAsync(z => z.Name == jPurchase["name"].Value()); + if (p == null) + { + //Create it here + p = new Product(); + p.Name = jPurchase["name"].Value(); + p.VendorId = 1; + p.OurCode = p.VendorCode = jPurchase["productCode"].Value(); + ProductBiz biz = ProductBiz.GetBiz(ct); + p = await biz.CreateAsync(p); + } + + //Now we can add the sale that we have the product + if (!await ct.Purchase.AnyAsync(z => z.SalesOrderNumber == jPurchase["salesOrderNumber"].Value())) + { + var s = new Purchase(); + s.VendorId = 1; + s.ProductId = p.Id; + s.CustomerId = CurrentCustomerId; + s.CancelDate = DateUtil.EpochToDateNullIsNull(jPurchase["cancelDate"].Value()); + s.CouponCode = jPurchase["couponCode"].Value(); + s.ExpireDate = DateUtil.EpochToDateNullIsNull(jPurchase["expireDate"].Value()); + s.Name = p.Name; + s.ProcessedDate = s.PurchaseDate = DateUtil.EpochToDateNullIsMin(jPurchase["purchaseDate"].Value()); + s.Quantity = jPurchase["quantity"].Value(); + s.RenewNoticeSent = jPurchase["renewNoticeSent"].Value(); + s.SalesOrderNumber = jPurchase["salesOrderNumber"].Value(); + s.VendorData = jPurchase["notes"].Value(); + PurchaseBiz biz=PurchaseBiz.GetBiz(ct); + await biz.CreateAsync(s); + } } - } + + + }//site loop diff --git a/server/util/DateUtil.cs b/server/util/DateUtil.cs index 0b8068c..1a66ef7 100644 --- a/server/util/DateUtil.cs +++ b/server/util/DateUtil.cs @@ -153,6 +153,22 @@ namespace Sockeye.Util return sb.ToString().Trim(); } + public static DateTime? EpochToDateNullIsNull(long? uepoch) + { + DateTime dt = DateTime.Now; + if (uepoch == null) return null; + return DateTimeOffset.FromUnixTimeSeconds(uepoch.Value).DateTime; + } + + + public static DateTime EpochToDateNullIsMin(long? uepoch) + { + DateTime dt = DateTime.Now; + if (uepoch == null) return DateTime.MinValue; + return DateTimeOffset.FromUnixTimeSeconds(uepoch.Value).DateTime; + } + + }//eoc