From c64c1ad11a6943907cfcecdd46f347d813439021 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 8 Feb 2023 23:36:28 +0000 Subject: [PATCH] --- .../SockBotProcessPurchasesIntoLicenses.cs | 29 ++++++++++++++++++- .../SockBotProcessVendorNotifications.cs | 20 +++++++++++-- server/util/AySchema.cs | 6 +++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/server/generator/SockBotProcessPurchasesIntoLicenses.cs b/server/generator/SockBotProcessPurchasesIntoLicenses.cs index 9939440..4d15e5c 100644 --- a/server/generator/SockBotProcessPurchasesIntoLicenses.cs +++ b/server/generator/SockBotProcessPurchasesIntoLicenses.cs @@ -293,6 +293,30 @@ namespace Sockeye.Biz else { //it's a RAVEN license + +//get last license for this dbid, if active then take all it's value and update it with this +/* +Check if new or renewal: +if it's a renewal it will have several "original_XXXX" fields (they won't exist on first purcahse): + "subscription": { + "expiration_date": "2023-03-07T00:15:13.0000000Z", + "id": "833674953-1", + "interval": "Monthly without end", + "original_notification_no": "7925", + "original_purchase_id": "833674953", + "original_running_no": "1", +*/ + +//If renewal and there is no last license then it's a problem -> THROW EXCEPTION + +//If no last license and not renewal then it's a new purchase -> GENERATE NEW + +//If last license and renewal then it's a renewal -> UPDATE LAST LICENSE DATES SAVE NEW + +//If last license and NEW then it's an additional add on count + //if dbid matches -> ADD TO COUNT PUT THAT IN NOTES OF LICENSE + //if no dbid match then -> THROW EXCEPTION + //iterate the purchases and update / set the license foreach (var purchase in purchaseGroup) { @@ -314,7 +338,10 @@ namespace Sockeye.Biz 301033168 AyaNova subscription additional 250 customer users yearly 250customerusersyearly Product 12 months HD1 Oct 6, 2022, 12:59 AM */ - - sockeye note: Need to handle multiple raven license purchases, my policy is the freshest date is honoured so for examle tri-star bought in December then in Feb 2 users each time so the feb is the freshest, the trick is when the december renews not to cut it short but still use the feb date. since eventually sockeye will be automated it needs to handle this up front now, not later + // - sockeye note: Need to handle multiple raven license purchases, my policy is the freshest date is honoured so for examle tri-star bought in December then in Feb 2 users each time so the feb is the freshest, the trick is when the december renews not to cut it short but still use the feb date. since eventually sockeye will be automated it needs to handle this up front now, not later + //algorithm: check if existing license for db id, if yes, is it for more users than current license? + //if yes then is it unexpired? + //if yes then honour the //RAVEN licenses have one week padding to be on the safe side var dtOneYear = DateTime.UtcNow.AddYears(1).AddDays(7); var dtOneMonth = DateTime.UtcNow.AddMonths(1).AddDays(7); diff --git a/server/generator/SockBotProcessVendorNotifications.cs b/server/generator/SockBotProcessVendorNotifications.cs index 549fb97..af75aae 100644 --- a/server/generator/SockBotProcessVendorNotifications.cs +++ b/server/generator/SockBotProcessVendorNotifications.cs @@ -246,10 +246,26 @@ namespace Sockeye.Biz p.Quantity = jPurchase["quantity"].Value(); p.VendorNotificationId = vn.Id; + p.IsRenewal = false;//default, set to true in subscription block processor below //it's a subscription? - if (jPurchase["subscription"] != null && jPurchase["subscription"]["expiration_date"] != null) + if (jPurchase["subscription"] != null) { - p.ExpireDate = jPurchase["subscription"]["expiration_date"].Value(); + if (jPurchase["subscription"]["expiration_date"] != null) + p.ExpireDate = jPurchase["subscription"]["expiration_date"].Value(); + + if (jPurchase["subscription"]["original_purchase_id"] != null) + p.IsRenewal = true;//the existance of the field is enough, we're going to assume the original purchase id is most definitive though there are other original_xx fields: + /* + Renewal example: + if it's a renewal it will have several "original_XXXX" fields (they won't exist on first non-renewal purchase): + "subscription": { + "expiration_date": "2023-03-07T00:15:13.0000000Z", + "id": "833674953-1", + "interval": "Monthly without end", + "original_notification_no": "7925", + "original_purchase_id": "833674953", + "original_running_no": "1", + */ } PurchaseBiz pbiz = PurchaseBiz.GetBiz(ct); diff --git a/server/util/AySchema.cs b/server/util/AySchema.cs index 6c7f9b8..5a4b17f 100644 --- a/server/util/AySchema.cs +++ b/server/util/AySchema.cs @@ -903,7 +903,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); + "vendorid BIGINT NOT NULL REFERENCES avendor(id), productid BIGINT REFERENCES aproduct(id), pgroup INTEGER NOT NULL DEFAULT 4, salesordernumber TEXT NOT NULL, " + "productnet DECIMAL(38,18) NOT NULL default 0, discount DECIMAL(38,18) NOT NULL default 0, vendorfee DECIMAL(38,18) NOT NULL default 0, revenue DECIMAL(38,18) NOT NULL default 0, " + "currency TEXT, purchasedate TIMESTAMPTZ NOT NULL, expiredate TIMESTAMPTZ, canceldate TIMESTAMPTZ, couponcode text, notes text, " - + "renewnoticesent BOOL NOT NULL DEFAULT false, quantity INTEGER NOT NULL DEFAULT 1, dbid TEXT, " + + "renewnoticesent BOOL NOT NULL DEFAULT false, quantity INTEGER NOT NULL DEFAULT 1, dbid TEXT, isrenewal BOOL NOT NULL DEFAULT false," + "vendornotificationid BIGINT REFERENCES avendornotification(id), licenseid BIGINT REFERENCES alicense(id), processed BOOL NOT NULL DEFAULT false, " + "wiki TEXT, tags VARCHAR(255) ARRAY )"); @@ -1210,6 +1210,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseDiscount', 'Discount' FROM atranslation t where t.baselanguage = 'en'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseVendorFee', 'Vendor fee' FROM atranslation t where t.baselanguage = 'en'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseRevenue', 'Revenue' FROM atranslation t where t.baselanguage = 'en'"); + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseIsRenewal', 'Renewal' FROM atranslation t where t.baselanguage = 'en'"); //spanish translations await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'Purchase', 'Purchase' FROM atranslation t where t.baselanguage = 'es'"); @@ -1229,6 +1230,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseDiscount', 'Discount' FROM atranslation t where t.baselanguage = 'es'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseVendorFee', 'Vendor fee' FROM atranslation t where t.baselanguage = 'es'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseRevenue', 'Revenue' FROM atranslation t where t.baselanguage = 'es'"); + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseIsRenewal', 'Renewal' FROM atranslation t where t.baselanguage = 'es'"); //french translations await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'Purchase', 'Purchase' FROM atranslation t where t.baselanguage = 'fr'"); @@ -1248,6 +1250,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseDiscount', 'Discount' FROM atranslation t where t.baselanguage = 'fr'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseVendorFee', 'Vendor fee' FROM atranslation t where t.baselanguage = 'fr'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseRevenue', 'Revenue' FROM atranslation t where t.baselanguage = 'fr'"); + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseIsRenewal', 'Renewal' FROM atranslation t where t.baselanguage = 'fr'"); //german translations @@ -1268,6 +1271,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseDiscount', 'Discount' FROM atranslation t where t.baselanguage = 'de'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseVendorFee', 'Vendor fee' FROM atranslation t where t.baselanguage = 'de'"); await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseRevenue', 'Revenue' FROM atranslation t where t.baselanguage = 'de'"); + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'PurchaseIsRenewal', 'Renewal' FROM atranslation t where t.baselanguage = 'de'"); #endregion purchase