Fixed MM integration

Leandro Silva [09-23-18 - 23:59]
Fixed MM integration
Filename
LeoGuildManager.lua
LeoGuildManager.txt
LeoGuildManagerUI.lua
diff --git a/LeoGuildManager.lua b/LeoGuildManager.lua
index 65d190f..e799367 100644
--- a/LeoGuildManager.lua
+++ b/LeoGuildManager.lua
@@ -2,7 +2,7 @@
 LeoGM = {}
 LeoGM.name = "LeoGuildManager"
 LeoGM.displayName = "Leo's Guild Manager"
-LeoGM.version = "0.9.4"
+LeoGM.version = "0.9.5"
 LeoGM.chatPrefix = "|c39B027" .. LeoGM.name .. "|r: "
 LeoGM.panelList = { "Rules", "Purge" }
 LeoGM.members = {}
@@ -224,6 +224,8 @@ function LeoGM.BuildDepositsHistory(guildId, scanSince)

     if LeoGM.isScanning then return nil end

+    LeoGMWindowPurgePanelListResult:SetText("Scanning gold deposits ...")
+
     LeoGMWindowPurgePanelListButton:SetEnabled(false)
     LeoGMWindowPurgePanelLoadingIcon:SetHidden(false)
     LeoGMWindowPurgePanelLoadingIcon.animation:PlayForward()
@@ -326,8 +328,8 @@ function LeoGM.DoDepositsScan(guildNum, checkOlder, scanSince, startIndex, endIn
     LeoGMWindowPurgePanelListButton:SetEnabled(true)
     LeoGMWindowPurgePanelLoadingIcon:SetHidden(true)
     LeoGMWindowPurgePanelLoadingIcon.animation:Stop()
-    --LeoGM.PostScan()
-    LeoGM.BuildSalesHistory(guildNum, scanSince)
+    LeoGM.PostScan()
+    --LeoGM.BuildSalesHistory(guildNum, scanSince)
 end

 function LeoGM.ScanOlderDeposits(guildNum, scanSince, oldNumEvents, badLoads)
@@ -360,17 +362,25 @@ function LeoGM.PostScan()
             end
         end
     end
-    --[[
-    if MasterMerchant then
+
+    local collected = false
+    if MasterMerchant and MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild] and
+            MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers
+    then
         for sn, sellerData in pairs(MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers) do
             for _, member in pairs(LeoGM.members) do
-                if sn == member.name and sellerData.sales[5] then
-                    member.sales = member.sales + sellerData.sales[5]
+                if sn == member.name and sellerData.sales[8] then
+                    member.sales = member.sales + sellerData.sales[8]
+                    collected = true
                 end
             end
         end
     end
-    ]]
+    if collected == false then
+        LeoGMWindowPurgePanelListResult:SetText("|cFF2222MasterMerchant sales data not found for this guild.|r Try again in a few moments if it is still initializing.")
+        return
+    end
+    --[[
     for _, event in pairs(LeoGM.salesEvents) do
         for _, member in pairs(LeoGM.members) do
             if event.seller == member.name then
@@ -379,6 +389,7 @@ function LeoGM.PostScan()
             end
         end
     end
+    ]]
     LeoGM.memberScroll:RefreshData()
 end

@@ -402,6 +413,7 @@ function LeoGM.Initialize()
     LeoGM.InitializeUI()
     LeoGM.RestorePosition()

+    --[[
     SLASH_COMMANDS["/rr"] = function(cmd)
         ReloadUI()
     end
@@ -409,13 +421,14 @@ function LeoGM.Initialize()
     SLASH_COMMANDS["/leogm"] = function(cmd)
         LeoGM:ShowUI()
     end
+    ]]
 end

 function LeoGM.OnAddOnLoaded(event, addonName)
     if addonName == LeoGM.name then
         EVENT_MANAGER:UnregisterForEvent(LeoGM.Name, EVENT_ADD_ON_LOADED)
         LeoGM.Initialize()
-        --        d(LeoGM.name .. " started.")
+        --d(LeoGM.name .. " started.")
     end
 end

diff --git a/LeoGuildManager.txt b/LeoGuildManager.txt
index b74752c..4e7f60f 100644
--- a/LeoGuildManager.txt
+++ b/LeoGuildManager.txt
@@ -1,6 +1,6 @@
 ## Title: Leo's Guild Manager
 ## APIVersion: 100024
-## Version: 0.9.4
+## Version: 0.9.5
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoGMSavedVariables
 ## DependsOn: LibStub LibFeedback MasterMerchant
diff --git a/LeoGuildManagerUI.lua b/LeoGuildManagerUI.lua
index 411a9e2..dc52fc2 100644
--- a/LeoGuildManagerUI.lua
+++ b/LeoGuildManagerUI.lua
@@ -58,10 +58,10 @@ function LeoGMMemberList:SetupEntry(control, data)
     control.name.data = data.name

     control.deposits = GetControl(control, "Deposits")
-    control.deposits:SetText(data.deposits)
+    control.deposits:SetText(LeoGM.formatNumber(data.deposits))

     control.sales = GetControl(control, "Sales")
-    control.sales:SetText(data.sales)
+    control.sales:SetText(LeoGM.formatNumber(data.sales))

     control.online = GetControl(control, "Online")
     control.online:SetText(LeoGM.GetTime(data.online))
@@ -267,27 +267,16 @@ function LeoGM.ListPurge()
         LeoGMWindowPurgePanelListResult:SetText("|cFF2222You don't have permission to scan guild gold deposits.|r")
         return
     end
-    LeoGMWindowPurgePanelListResult:SetText("Sorry, fixing the MM integration. Will be back soon.")
-    --[[
-    LeoGMWindowPurgePanelListResult:SetText("Scanning gold deposits ...")
-    d(MasterMerchant.version)
-    d(#MasterMerchant.SRIndex)
-    d(#MasterMerchant.SSIndex)
-    d(#MasterMerchant.guildSales)
-    d(#MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild])
-    d(#MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers)
-    if not MasterMerchant or
-            not MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild] or
-            not MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers or
-            #MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers == 0
+    if MasterMerchant == nil or
+        MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild] == nil or
+        MasterMerchant.guildSales[LeoGM.savedVariables.selectedGuild].sellers == nil
     then
         LeoGMWindowPurgePanelListResult:SetText("|cFF2222MasterMerchant sales data not found for this guild.|r Try again in a few moments if it is still initializing.")
         return
     end
-    ]]
     LeoGM.GetGuildMembers(guildId)
     local scanSince = GetTimeStamp() - 7 * 24 * 60 * 60
-    --LeoGM.BuildDepositsHistory(guildId, scanSince)
+    LeoGM.BuildDepositsHistory(guildId, scanSince)
 end

 function LeoGM.InitializeUI()