This commit is contained in:
2023-01-01 00:40:01 +00:00
parent 1a9776cb82
commit 0ae32405c0

View File

@@ -298,108 +298,165 @@ namespace Sockeye.Biz
#endregion customers #endregion customers
#region CASES
log.LogInformation("RFImport Cases"); #region VENDOR NOTIFICATIONS
//case projects to be tags log.LogInformation("RFImport Vendor notifications");
List<NameIdItem> CaseProjectList = new List<NameIdItem>();
{ {
res = await client.GetAsync($"{URL_ROCKFISH}api/rfcaseproject");
res = await client.GetAsync($"{URL_ROCKFISH}api/vendor-notifications/list");
responseText = await res.Content.ReadAsStringAsync(); responseText = await res.Content.ReadAsStringAsync();
var jaVendorNotificationList = JArray.Parse(responseText);
var jaRFCaseProjectList = JArray.Parse(responseText); foreach (JObject jVendorNotificationItem in jaVendorNotificationList)
foreach (JObject jRFCaseProject in jaRFCaseProjectList)
{ {
CaseProjectList.Add(new NameIdItem() { Name = jRFCaseProject["name"].Value<string>(), Id = jRFCaseProject["id"].Value<long>() }); /*[]
"{\n \"creation_date\": \"2022-12-28T20:20:24Z\",\n \
"id\": 356247074,\n \
"order_notification\": {\n \
"purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Alpharetta\",\n \"country\": \"USA\",\n \"country_id\": \"US\",\n
\"postal_code\": \"30009\",\n \"state\": \"Georgia\",\n \"state_id\": \"GA\",\n \"street1\": \"11675 Rainwater Dr., Suite 350\"\n },
\n …tart\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \
"start_date\": \"2022-12-28T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \
"vat_pct\": 0.0,\n \"your_product_id\": \"perpetual\"\n }\n ],\n
\"purchase_origin\": \"online\",\n \"sequential_invoice_no\": \"e5-US-2022-00001637070\"\n }\n }\n}"
} {
"id": 25,
"dtCreated": 1670375661,
"vendor": "shareit",
"data": "{\n \"creation_date\": \"2022-12-07T01:14:19Z\",\n \"id\": 354935062,\n \"order_notification\": {\n \"purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"customer_payment_data\": {\n \"currency\": \"USD\",\n \"payment_method\": \"PayPal\"\n },\n \"delivery_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"language\": \"English\",\n \"language_iso\": \"en\",\n \"reg_name\": \"Adtech Systems Inc.\",\n \"shopper_id\": \"50862261\",\n \"subscribe_newsletter\": true,\n \"user_id\": \"erling@adtech-systems.com-4\"\n },\n \"is_test\": false,\n \"payment_complete_date\": \"2022-12-07T01:14:19Z\",\n \"payment_status\": \"complete\",\n \"payment_status_id\": \"PCA\",\n \"purchase_date\": \"2022-12-07T01:14:16Z\",\n \"purchase_id\": 833707313,\n \"purchase_item\": [\n {\n \"accounting\": {\n \"currency\": \"USD\",\n \"product_net\": 55.65,\n \"discount\": 0.0,\n \"product_vat\": 6.68,\n \"shipping\": 0.0,\n \"shipping_vat\": 0.0,\n \"eu_vat\": -6.68,\n \"margin_net\": -5.44,\n \"your_revenue\": 50.21\n },\n \"additional_information\": [\n {\n \"additional_id\": \"ADDITIONAL1\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL2\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL3\",\n \"additional_value\": \"YES\"\n }\n ],\n \"currency\": \"USD\",\n \"delivery_type\": \"Electronically\",\n \"discount\": 0.0,\n \"extended_download_price\": 0.0,\n \"manual_order_price\": 0.0,\n \"notification_no\": 7926,\n \"product_id\": 300740315,\n \"product_name\": \"Single AyaNova schedulable resource 1 year subscription license\",\n \"product_single_price\": 55.65,\n \"purchase_item_key\": [],\n \"quantity\": 1,\n \"running_no\": 1,\n \"shipping_price\": 0.0,\n \"shipping_vat_pct\": 0.0,\n \"subscription\": {\n \"expiration_date\": \"2023-12-07T17:28:16Z\",\n \"id\": \"550286373-1\",\n \"interval\": \"Yearly without end\",\n \"original_notification_no\": \"6872\",\n \"original_purchase_id\": \"550286373\",\n \"original_running_no\": \"1\",\n \"renewal_discount_count\": \"\",\n \"renewal_discount_start\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \"start_date\": \"2017-12-07T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \"vat_pct\": 12.0\n }\n ],\n \"purchase_origin\": \"Subscription\",\n \"sequential_invoice_no\": \"e5-DE-2022-00002647549\"\n }\n }\n}",
"dtProcessed": null,
"processed": false
},
*/
} var jData = JObject.Parse(jVendorNotificationItem["data"].Value<string>());
{ var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>();
res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/list"); var p = await ct.Purchase.FirstOrDefaultAsync(z => z.SalesOrderNumber == salesOrderNumber);
responseText = await res.Content.ReadAsStringAsync(); if (p == null)
var jaRFCaseList = JArray.Parse(responseText);
//some cases are missing the start date so substitute a close other case date (not critical but sb at least in the ballpark for list viewing purposes)
DateTime dtTempCreated = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
foreach (JObject jRFCase in jaRFCaseList)
{
var g = new GZCase();
g.CaseId = jRFCase["id"].Value<long>();
g.Closed = DateUtil.EpochToDateNullIsNull(jRFCase["dtClosed"].Value<long?>());
//NOTE: closed in rockfish was the date at midnight in GMT
//so to be in the same day as here need to add a few hours, let's say 8 am for each so add 8 hours
if (g.Closed != null)
{ {
g.Closed = ((DateTime)g.Closed).AddHours(16); log.LogError($"RFImport Vendor notifications can't match sales order number {salesOrderNumber}");
} log.LogError(jData["order_notification"].ToString());
//fuckery to try to insert a at least semi close date when created date is missing
DateTime? dtTemp = DateUtil.EpochToDateNullIsNull(jRFCase["dtCreated"].Value<long?>());
if (dtTemp == null)
{
dtTemp = dtTempCreated;
} }
else else
{ {
dtTempCreated = (DateTime)dtTemp; if (!string.IsNullOrWhiteSpace(p.VendorData))
} p.VendorData += ",\n";
g.Created = (DateTime)dtTemp; p.VendorData += jVendorNotificationItem["data"].Value<string>();
g.Name = jRFCase["title"].Value<string>(); await ct.SaveChangesAsync();
g.Notes = jRFCase["notes"].Value<string>(); // var biz = PurchaseBiz.GetBiz(ct);
// await biz.PutAsync(p);
}
var ver = jRFCase["releaseVersion"].Value<string>(); }// all vendor notifications loop
if (!string.IsNullOrWhiteSpace(ver))
g.Notes += $"\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nReleased on version:{ver}";
var releaseNotes = jRFCase["releaseNotes"].Value<string>();
if (!string.IsNullOrWhiteSpace(releaseNotes))
g.Notes += $"\nRelease notes:{releaseNotes}";
//Project name to tags
g.Tags.Add(CaseProjectList.FirstOrDefault(z => z.Id == jRFCase["rfCaseProjectId"].Value<long>()).Name.Replace("z_", "legacy-"));
//priority to tags
g.Tags.Add($"{jRFCase["priority"].Value<long>()}-priority");
//check for attachments and just add as a note, don't bother with actual transfer of attachment, there aren't a lot and most are way in the past and not required for anything
//if needed in future can manually xfer it over from the rockfish.sqlite db directly using DB BRowser for sqlite which allows opening the blob from the rfcaseblob table and saving it
res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/{g.CaseId}/attachments");
responseText = await res.Content.ReadAsStringAsync();
var jAttachments = JObject.Parse(responseText);
if (jAttachments["attach"].Count() > 0)
{
g.Notes += "\n********\nRockfish attachments\n";
foreach (JObject jAttachmentRecord in jAttachments["attach"])
{
g.Notes += $"File: \"{jAttachmentRecord["name"].Value<string>()}\", rfcaseblob table id: {jAttachmentRecord["id"].Value<long>()}\n";
}
g.Notes += "\n********\n";
}
GZCaseBiz biz = GZCaseBiz.GetBiz(ct);
await biz.CreateAsync(g);
//attachments example 86400000
// /api/rfcase/4360/attachments
//{"dlkey":"ZFkAUpo1L0Gi3Q9aO5szkA","attach":[{"id":259,"name":"desired weight calcs.txt"}]}
//{"dlkey":"iR6ncD70CkzkozyT0otA","attach":[]}
}// all cases loop
//Start next case with a new sequence caseid of 4444
using (var command = ct.Database.GetDbConnection().CreateCommand())
{
command.CommandText = $"ALTER SEQUENCE agzcase_caseid_seq RESTART WITH 4443;";
await ct.Database.OpenConnectionAsync();
await command.ExecuteNonQueryAsync();
await ct.Database.CloseConnectionAsync();
}
} }
#endregion vendor notifications
#region CASES
// log.LogInformation("RFImport Cases");
// //case projects to be tags
// List<NameIdItem> CaseProjectList = new List<NameIdItem>();
// {
// res = await client.GetAsync($"{URL_ROCKFISH}api/rfcaseproject");
// responseText = await res.Content.ReadAsStringAsync();
// var jaRFCaseProjectList = JArray.Parse(responseText);
// foreach (JObject jRFCaseProject in jaRFCaseProjectList)
// {
// CaseProjectList.Add(new NameIdItem() { Name = jRFCaseProject["name"].Value<string>(), Id = jRFCaseProject["id"].Value<long>() });
// }
// }
// {
// res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/list");
// responseText = await res.Content.ReadAsStringAsync();
// var jaRFCaseList = JArray.Parse(responseText);
// //some cases are missing the start date so substitute a close other case date (not critical but sb at least in the ballpark for list viewing purposes)
// DateTime dtTempCreated = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc);
// foreach (JObject jRFCase in jaRFCaseList)
// {
// var g = new GZCase();
// g.CaseId = jRFCase["id"].Value<long>();
// g.Closed = DateUtil.EpochToDateNullIsNull(jRFCase["dtClosed"].Value<long?>());
// //NOTE: closed in rockfish was the date at midnight in GMT
// //so to be in the same day as here need to add a few hours, let's say 8 am for each so add 8 hours
// if (g.Closed != null)
// {
// g.Closed = ((DateTime)g.Closed).AddHours(16);
// }
// //fuckery to try to insert a at least semi close date when created date is missing
// DateTime? dtTemp = DateUtil.EpochToDateNullIsNull(jRFCase["dtCreated"].Value<long?>());
// if (dtTemp == null)
// {
// dtTemp = dtTempCreated;
// }
// else
// {
// dtTempCreated = (DateTime)dtTemp;
// }
// g.Created = (DateTime)dtTemp;
// g.Name = jRFCase["title"].Value<string>();
// g.Notes = jRFCase["notes"].Value<string>();
// var ver = jRFCase["releaseVersion"].Value<string>();
// if (!string.IsNullOrWhiteSpace(ver))
// g.Notes += $"\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\nReleased on version:{ver}";
// var releaseNotes = jRFCase["releaseNotes"].Value<string>();
// if (!string.IsNullOrWhiteSpace(releaseNotes))
// g.Notes += $"\nRelease notes:{releaseNotes}";
// //Project name to tags
// g.Tags.Add(CaseProjectList.FirstOrDefault(z => z.Id == jRFCase["rfCaseProjectId"].Value<long>()).Name.Replace("z_", "legacy-"));
// //priority to tags
// g.Tags.Add($"{jRFCase["priority"].Value<long>()}-priority");
// //check for attachments and just add as a note, don't bother with actual transfer of attachment, there aren't a lot and most are way in the past and not required for anything
// //if needed in future can manually xfer it over from the rockfish.sqlite db directly using DB BRowser for sqlite which allows opening the blob from the rfcaseblob table and saving it
// res = await client.GetAsync($"{URL_ROCKFISH}api/rfcase/{g.CaseId}/attachments");
// responseText = await res.Content.ReadAsStringAsync();
// var jAttachments = JObject.Parse(responseText);
// if (jAttachments["attach"].Count() > 0)
// {
// g.Notes += "\n********\nRockfish attachments\n";
// foreach (JObject jAttachmentRecord in jAttachments["attach"])
// {
// g.Notes += $"File: \"{jAttachmentRecord["name"].Value<string>()}\", rfcaseblob table id: {jAttachmentRecord["id"].Value<long>()}\n";
// }
// g.Notes += "\n********\n";
// }
// GZCaseBiz biz = GZCaseBiz.GetBiz(ct);
// await biz.CreateAsync(g);
// //attachments example 86400000
// // /api/rfcase/4360/attachments
// //{"dlkey":"ZFkAUpo1L0Gi3Q9aO5szkA","attach":[{"id":259,"name":"desired weight calcs.txt"}]}
// //{"dlkey":"iR6ncD70CkzkozyT0otA","attach":[]}
// }// all cases loop
// //Start next case with a new sequence caseid of 4444
// using (var command = ct.Database.GetDbConnection().CreateCommand())
// {
// command.CommandText = $"ALTER SEQUENCE agzcase_caseid_seq RESTART WITH 4443;";
// await ct.Database.OpenConnectionAsync();
// await command.ExecuteNonQueryAsync();
// await ct.Database.CloseConnectionAsync();
// }
// }
#endregion cases #endregion cases
@@ -615,60 +672,6 @@ namespace Sockeye.Biz
} }
#endregion trial requests #endregion trial requests
#region VENDOR NOTIFICATIONS
log.LogInformation("RFImport Vendor notifications");
{
res = await client.GetAsync($"{URL_ROCKFISH}api/vendor-notifications/list");
responseText = await res.Content.ReadAsStringAsync();
var jaVendorNotificationList = JArray.Parse(responseText);
foreach (JObject jVendorNotificationItem in jaVendorNotificationList)
{
/*[]
"{\n \"creation_date\": \"2022-12-28T20:20:24Z\",\n \
"id\": 356247074,\n \
"order_notification\": {\n \
"purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Alpharetta\",\n \"country\": \"USA\",\n \"country_id\": \"US\",\n
\"postal_code\": \"30009\",\n \"state\": \"Georgia\",\n \"state_id\": \"GA\",\n \"street1\": \"11675 Rainwater Dr., Suite 350\"\n },
\n …tart\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \
"start_date\": \"2022-12-28T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \
"vat_pct\": 0.0,\n \"your_product_id\": \"perpetual\"\n }\n ],\n
\"purchase_origin\": \"online\",\n \"sequential_invoice_no\": \"e5-US-2022-00001637070\"\n }\n }\n}"
{
"id": 25,
"dtCreated": 1670375661,
"vendor": "shareit",
"data": "{\n \"creation_date\": \"2022-12-07T01:14:19Z\",\n \"id\": 354935062,\n \"order_notification\": {\n \"purchase\": {\n \"customer_data\": {\n \"billing_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"customer_payment_data\": {\n \"currency\": \"USD\",\n \"payment_method\": \"PayPal\"\n },\n \"delivery_contact\": {\n \"address\": {\n \"city\": \"Abbotsford\",\n \"country\": \"Canada\",\n \"country_id\": \"CA\",\n \"postal_code\": \"V2S 8M1\",\n \"state\": \"British Columbia\",\n \"state_id\": \"BC\",\n \"street1\": \"35355 McKee Rd\"\n },\n \"company\": \"Adtech Systems Inc.\",\n \"email\": \"erling@myadtech.com\",\n \"first_name\": \"Erling\",\n \"last_name\": \"Lassesen\"\n },\n \"language\": \"English\",\n \"language_iso\": \"en\",\n \"reg_name\": \"Adtech Systems Inc.\",\n \"shopper_id\": \"50862261\",\n \"subscribe_newsletter\": true,\n \"user_id\": \"erling@adtech-systems.com-4\"\n },\n \"is_test\": false,\n \"payment_complete_date\": \"2022-12-07T01:14:19Z\",\n \"payment_status\": \"complete\",\n \"payment_status_id\": \"PCA\",\n \"purchase_date\": \"2022-12-07T01:14:16Z\",\n \"purchase_id\": 833707313,\n \"purchase_item\": [\n {\n \"accounting\": {\n \"currency\": \"USD\",\n \"product_net\": 55.65,\n \"discount\": 0.0,\n \"product_vat\": 6.68,\n \"shipping\": 0.0,\n \"shipping_vat\": 0.0,\n \"eu_vat\": -6.68,\n \"margin_net\": -5.44,\n \"your_revenue\": 50.21\n },\n \"additional_information\": [\n {\n \"additional_id\": \"ADDITIONAL1\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL2\",\n \"additional_value\": \"YES\"\n },\n {\n \"additional_id\": \"ADDITIONAL3\",\n \"additional_value\": \"YES\"\n }\n ],\n \"currency\": \"USD\",\n \"delivery_type\": \"Electronically\",\n \"discount\": 0.0,\n \"extended_download_price\": 0.0,\n \"manual_order_price\": 0.0,\n \"notification_no\": 7926,\n \"product_id\": 300740315,\n \"product_name\": \"Single AyaNova schedulable resource 1 year subscription license\",\n \"product_single_price\": 55.65,\n \"purchase_item_key\": [],\n \"quantity\": 1,\n \"running_no\": 1,\n \"shipping_price\": 0.0,\n \"shipping_vat_pct\": 0.0,\n \"subscription\": {\n \"expiration_date\": \"2023-12-07T17:28:16Z\",\n \"id\": \"550286373-1\",\n \"interval\": \"Yearly without end\",\n \"original_notification_no\": \"6872\",\n \"original_purchase_id\": \"550286373\",\n \"original_running_no\": \"1\",\n \"renewal_discount_count\": \"\",\n \"renewal_discount_start\": \"\",\n \"renewal_type\": \"auto\",\n \"retention_discount_count\": \"\",\n \"retention_discount_percent\": \"\",\n \"start_date\": \"2017-12-07T00:00:00\",\n \"status\": \"ToProcess\",\n \"status_id\": \"TOP\"\n },\n \"vat_pct\": 12.0\n }\n ],\n \"purchase_origin\": \"Subscription\",\n \"sequential_invoice_no\": \"e5-DE-2022-00002647549\"\n }\n }\n}",
"dtProcessed": null,
"processed": false
},
*/
var jData = JObject.Parse(jVendorNotificationItem["data"].Value<string>());
var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>();
var p = await ct.Purchase.FirstOrDefaultAsync(z => z.SalesOrderNumber == salesOrderNumber);
if (p == null)
{
log.LogError($"RFImport Vendor notifications can't match sales order number {salesOrderNumber}");
}
else
{
if (!string.IsNullOrWhiteSpace(p.VendorData))
p.VendorData += ",\n";
p.VendorData += jVendorNotificationItem["data"].Value<string>();
var biz = PurchaseBiz.GetBiz(ct);
await biz.PutAsync(p);
}
}// all vendor notifications loop
}
#endregion vendor notifications
} }
catch (Exception ex) catch (Exception ex)