From 6719f452d18d80bec014e7e27ab817829c4be008 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 3 Sep 2024 16:16:18 -0600 Subject: [PATCH] Working on stuff --- PayoutTest.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++ PublicAssets.js | 12 ++++++++ package-lock.json | 7 ++++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 PayoutTest.js create mode 100644 PublicAssets.js diff --git a/PayoutTest.js b/PayoutTest.js new file mode 100644 index 0000000..3dc06e4 --- /dev/null +++ b/PayoutTest.js @@ -0,0 +1,73 @@ +require("dotenv").config(); +const noblox = require('noblox.js'); + +const payoutPercentages = { + "Honeywell Vista Device Pack": .6 +} + +noblox.setCookie(process.env.COOKIE).then(() => { + noblox.getGroupTransactions(process.env.GROUPID, "Sale").then((transactions) => { + // Calculate the first and last days of the previous month + const now = new Date(); + const firstDayOfLastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1); + const lastDayOfLastMonth = new Date(now.getFullYear(), now.getMonth(), 0); // Last day of the previous month + + // Filter transactions to those within the previous month + const previousMonthTransactions = transactions.filter((transaction) => { + const transactionDate = new Date(transaction.created); + //console.log(transaction) + return transactionDate >= firstDayOfLastMonth && transactionDate <= lastDayOfLastMonth && transaction.currency.amount > 0; + }); + + console.log(previousMonthTransactions); + + // Calculate total revenue + const totalRevenue = previousMonthTransactions.reduce((acc, transaction) => acc + transaction.currency.amount, 0); + + // Calculate total revenue per product + const totalRevPerProduct = previousMonthTransactions.reduce((acc, transaction) => { + if (!acc[transaction.details.name]) { + acc[transaction.details.name] = 0; + } + acc[transaction.details.name] += transaction.currency.amount; + return acc; + }, {}); + + // Calculate percentage to pay out per product + const payouts = Object.keys(totalRevPerProduct).reduce((acc, product) => { + if (!payoutPercentages[product]) { + acc[product] = 0; + } else { + acc[product] = Math.floor(totalRevPerProduct[product] * payoutPercentages[product]); + } + return acc; + }, {}); + + // Get list of people that bought products + const buyers = previousMonthTransactions.reduce((acc, transaction) => { + if (!acc[transaction.agent.id]) { + acc[transaction.agent.id] = { + name: transaction.agent.name, + total: 0, + products: [] + }; + } + acc[transaction.agent.id].total += transaction.currency.amount; + acc[transaction.agent.id].products.push({ + name: transaction.details.name, + amount: transaction.currency.amount + }); + return acc; + }, {}); + + console.log("Buyers"); + console.log(JSON.stringify(buyers, null, 2)); + console.log("Rev"); + console.log(totalRevPerProduct); + console.log("Payouts"); + console.log(payouts); + console.log(`Total Revenue: ${totalRevenue}`); + // Print a single line for every transaction + + }); +}); diff --git a/PublicAssets.js b/PublicAssets.js new file mode 100644 index 0000000..4b254a4 --- /dev/null +++ b/PublicAssets.js @@ -0,0 +1,12 @@ +require("dotenv").config(); +const noblox = require('noblox.js'); + +const payoutPercentages = { + "Honeywell Vista Device Pack": .6 +} + +noblox.setCookie(process.env.COOKIE).then(() => { + noblox.getGroupAssets(process.env.GROUPID, "Model").then((assets) => { + console.log(assets) + }); +}); diff --git a/package-lock.json b/package-lock.json index b227e66..336131f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,21 @@ { "name": "roblortest", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { + "name": "roblortest", + "version": "1.0.0", + "license": "ISC", "dependencies": { "colors": "^1.4.0", "crypto": "^1.0.1", "discord.js": "^14.15.3", "dotenv": "^16.4.5", "noblox.js": "^6.0.2" - } + }, + "devDependencies": {} }, "node_modules/@discordjs/builders": { "version": "1.8.2",