This commit is contained in:
@@ -219,6 +219,7 @@ namespace Sockeye.Biz
|
|||||||
var CustomerName = jCustomer["name"].Value<string>();
|
var CustomerName = jCustomer["name"].Value<string>();
|
||||||
if (multiSite)
|
if (multiSite)
|
||||||
CustomerName += " - " + jSite["name"].Value<string>();
|
CustomerName += " - " + jSite["name"].Value<string>();
|
||||||
|
long CurrentCustomerId = 0;
|
||||||
|
|
||||||
//Create customer if we don't have one already
|
//Create customer if we don't have one already
|
||||||
if (await ct.Customer.AnyAsync(z => z.Name == CustomerName))
|
if (await ct.Customer.AnyAsync(z => z.Name == CustomerName))
|
||||||
@@ -232,8 +233,9 @@ namespace Sockeye.Biz
|
|||||||
c.DoNotContact = jCustomer["doNotContact"].Value<bool>();
|
c.DoNotContact = jCustomer["doNotContact"].Value<bool>();
|
||||||
c.Notes = jCustomer["notes"].Value<string>();
|
c.Notes = jCustomer["notes"].Value<string>();
|
||||||
c.DbId = jSite["dbId"].Value<string>();
|
c.DbId = jSite["dbId"].Value<string>();
|
||||||
if (c.DbId == "v7_no_dbid"){
|
if (c.DbId == "v7_no_dbid")
|
||||||
c.DbId=null;
|
{
|
||||||
|
c.DbId = null;
|
||||||
c.Tags.Add("v7");
|
c.Tags.Add("v7");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -248,13 +250,55 @@ namespace Sockeye.Biz
|
|||||||
c.EmailAddress = jCustomer["adminEmail"].Value<string>();
|
c.EmailAddress = jCustomer["adminEmail"].Value<string>();
|
||||||
CustomerBiz biz = CustomerBiz.GetBiz(ct);
|
CustomerBiz biz = CustomerBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(c);
|
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<long>()}/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<string>());
|
||||||
|
if (p == null)
|
||||||
|
{
|
||||||
|
//Create it here
|
||||||
|
p = new Product();
|
||||||
|
p.Name = jPurchase["name"].Value<string>();
|
||||||
|
p.VendorId = 1;
|
||||||
|
p.OurCode = p.VendorCode = jPurchase["productCode"].Value<string>();
|
||||||
|
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<string>()))
|
||||||
|
{
|
||||||
|
var s = new Purchase();
|
||||||
|
s.VendorId = 1;
|
||||||
|
s.ProductId = p.Id;
|
||||||
|
s.CustomerId = CurrentCustomerId;
|
||||||
|
s.CancelDate = DateUtil.EpochToDateNullIsNull(jPurchase["cancelDate"].Value<long?>());
|
||||||
|
s.CouponCode = jPurchase["couponCode"].Value<string>();
|
||||||
|
s.ExpireDate = DateUtil.EpochToDateNullIsNull(jPurchase["expireDate"].Value<long?>());
|
||||||
|
s.Name = p.Name;
|
||||||
|
s.ProcessedDate = s.PurchaseDate = DateUtil.EpochToDateNullIsMin(jPurchase["purchaseDate"].Value<long?>());
|
||||||
|
s.Quantity = jPurchase["quantity"].Value<int>();
|
||||||
|
s.RenewNoticeSent = jPurchase["renewNoticeSent"].Value<bool>();
|
||||||
|
s.SalesOrderNumber = jPurchase["salesOrderNumber"].Value<string>();
|
||||||
|
s.VendorData = jPurchase["notes"].Value<string>();
|
||||||
|
PurchaseBiz biz=PurchaseBiz.GetBiz(ct);
|
||||||
|
await biz.CreateAsync(s);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}//site loop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,22 @@ namespace Sockeye.Util
|
|||||||
return sb.ToString().Trim();
|
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
|
}//eoc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user