diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index 21225137..6549866c 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -1708,7 +1708,7 @@ {/await} - + +
{ - const data = fullStatement; - if (!data || data.length === 0) { - return; - } + if (data?.user?.tier === "Pro") { + const data = fullStatement; + if (!data || data.length === 0) { + return; + } - let properties = [ - { - key: filterRule === "annual" ? "calendarYear" : "date", - label: filterRule === "annual" ? "Year" : "Quarter", - }, - ]; + let properties = [ + { + key: filterRule === "annual" ? "calendarYear" : "date", + label: filterRule === "annual" ? "Year" : "Quarter", + }, + ]; - for (let i = 0; i < statementConfig?.length; i++) { - properties.push({ - key: statementConfig[i]?.propertyName, - label: statementConfig[i]?.label, - }); - } + for (let i = 0; i < statementConfig?.length; i++) { + properties.push({ + key: statementConfig[i]?.propertyName, + label: statementConfig[i]?.label, + }); + } - // Helper function to handle special cases + // Helper function to handle special cases - // Create rows for CSV/Excel - let rows = data.map((item) => - properties?.map((property) => item[property?.key] || 0), - ); + // Create rows for CSV/Excel + let rows = data.map((item) => + properties?.map((property) => item[property?.key] || 0), + ); - // Include headers - const headers = properties.map((prop) => prop.label); - rows.unshift(headers); + // Include headers + const headers = properties.map((prop) => prop.label); + rows.unshift(headers); - // Check the format to export - if (format.toLowerCase() === "csv") { - const csvContent = rows?.map((row) => row.join(",")).join("\n"); - const blob = new Blob([csvContent], { - type: "data:text/csv;charset=utf-8", - }); - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = - $stockTicker.toLowerCase() + - `${filterRule === "annual" ? "_annual" : "_quarter"}_balance_sheet_statement.csv`; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - } /*else if (format.toLowerCase() === "excel") { + // Check the format to export + if (format.toLowerCase() === "csv") { + const csvContent = rows.map((row) => row.join(",")).join("\n"); + const blob = new Blob([csvContent], { + type: "data:text/csv;charset=utf-8", + }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = + $stockTicker.toLowerCase() + + `${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } /*else if (format.toLowerCase() === "excel") { const worksheet = XLSX.utils.aoa_to_sheet(rows); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement"); @@ -389,6 +391,9 @@ } */ + } else { + goto("/pricing"); + } }; $: { @@ -623,6 +628,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download +
diff --git a/src/routes/stocks/[tickerID]/stats/cash-flow/+page.svelte b/src/routes/stocks/[tickerID]/stats/cash-flow/+page.svelte index 2cf90a60..ed9b9ec0 100644 --- a/src/routes/stocks/[tickerID]/stats/cash-flow/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/cash-flow/+page.svelte @@ -9,7 +9,7 @@ import { Button } from "$lib/components/shadcn/button/index.js"; //import * as XLSX from 'xlsx'; import { Chart } from "svelte-echarts"; - + import { goto } from "$app/navigation"; import { init, use } from "echarts/core"; import { LineChart, BarChart } from "echarts/charts"; import { GridComponent, TooltipComponent } from "echarts/components"; @@ -278,53 +278,54 @@ }; const exportFundamentalData = (format = "csv") => { - const data = fullStatement; - if (!data || data.length === 0) { - return; - } + if (data?.user?.tier === "Pro") { + const data = fullStatement; + if (!data || data.length === 0) { + return; + } - let properties = [ - { - key: filterRule === "annual" ? "calendarYear" : "date", - label: filterRule === "annual" ? "Year" : "Quarter", - }, - ]; + let properties = [ + { + key: filterRule === "annual" ? "calendarYear" : "date", + label: filterRule === "annual" ? "Year" : "Quarter", + }, + ]; - for (let i = 0; i < statementConfig?.length; i++) { - properties.push({ - key: statementConfig[i]?.propertyName, - label: statementConfig[i]?.label, - }); - } + for (let i = 0; i < statementConfig?.length; i++) { + properties.push({ + key: statementConfig[i]?.propertyName, + label: statementConfig[i]?.label, + }); + } - // Helper function to handle special cases + // Helper function to handle special cases - // Create rows for CSV/Excel - let rows = data.map((item) => - properties?.map((property) => item[property?.key] || 0), - ); + // Create rows for CSV/Excel + let rows = data.map((item) => + properties?.map((property) => item[property?.key] || 0), + ); - // Include headers - const headers = properties.map((prop) => prop.label); - rows.unshift(headers); + // Include headers + const headers = properties.map((prop) => prop.label); + rows.unshift(headers); - // Check the format to export - if (format.toLowerCase() === "csv") { - const csvContent = rows?.map((row) => row.join(",")).join("\n"); - const blob = new Blob([csvContent], { - type: "data:text/csv;charset=utf-8", - }); - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = - $stockTicker.toLowerCase() + - `${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - } /*else if (format.toLowerCase() === "excel") { + // Check the format to export + if (format.toLowerCase() === "csv") { + const csvContent = rows.map((row) => row.join(",")).join("\n"); + const blob = new Blob([csvContent], { + type: "data:text/csv;charset=utf-8", + }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = + $stockTicker.toLowerCase() + + `${filterRule === "annual" ? "_annual" : "_quarter"}_cashflow_statement.csv`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } /*else if (format.toLowerCase() === "excel") { const worksheet = XLSX.utils.aoa_to_sheet(rows); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement"); @@ -335,6 +336,9 @@ } */ + } else { + goto("/pricing"); + } }; $: { @@ -567,6 +571,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download + diff --git a/src/routes/stocks/[tickerID]/stats/employees/+page.svelte b/src/routes/stocks/[tickerID]/stats/employees/+page.svelte index 401e5b64..713c777d 100644 --- a/src/routes/stocks/[tickerID]/stats/employees/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/employees/+page.svelte @@ -6,6 +6,7 @@ } from "$lib/store"; import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; import { Button } from "$lib/components/shadcn/button/index.js"; + import { goto } from "$app/navigation"; import { Chart } from "svelte-echarts"; import { init, use } from "echarts/core"; import { BarChart } from "echarts/charts"; @@ -260,55 +261,59 @@ } const exportData = (format = "csv") => { - // Add headers row - const csvRows = []; - csvRows.push("Date,Employees,Change,Growth"); + if (data?.user?.tier === "Pro") { + // Add headers row + const csvRows = []; + csvRows.push("Date,Employees,Change,Growth"); - // Add data rows - historyList.forEach((item, index) => { - const date = new Date(item.filingDate).toLocaleString("en-US", { - month: "short", - day: "numeric", - year: "numeric", + // Add data rows + historyList.forEach((item, index) => { + const date = new Date(item.filingDate).toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + }); + + const employees = item.employeeCount; + + // Calculate change + const change = + index + 1 < historyList.length + ? item.employeeCount - historyList[index + 1].employeeCount + : 0; + + // Calculate growth percentage + let growth = "0.00%"; + if (index + 1 < historyList.length) { + const growthValue = + ((item.employeeCount - historyList[index + 1].employeeCount) / + item.employeeCount) * + 100; + if (growthValue > 0) { + growth = `+${growthValue.toFixed(2)}%`; + } else if (growthValue < 0) { + growth = `-${Math.abs(growthValue).toFixed(2)}%`; + } + } + + const csvRow = `${date},${employees},${change},${growth}`; + csvRows.push(csvRow); }); - const employees = item.employeeCount; - - // Calculate change - const change = - index + 1 < historyList.length - ? item.employeeCount - historyList[index + 1].employeeCount - : 0; - - // Calculate growth percentage - let growth = "0.00%"; - if (index + 1 < historyList.length) { - const growthValue = - ((item.employeeCount - historyList[index + 1].employeeCount) / - item.employeeCount) * - 100; - if (growthValue > 0) { - growth = `+${growthValue.toFixed(2)}%`; - } else if (growthValue < 0) { - growth = `-${Math.abs(growthValue).toFixed(2)}%`; - } - } - - const csvRow = `${date},${employees},${change},${growth}`; - csvRows.push(csvRow); - }); - - // Create CSV blob and trigger download - const csv = csvRows.join("\n"); - const blob = new Blob([csv], { type: "text/csv" }); - const url = window.URL.createObjectURL(blob); - const a = document.createElement("a"); - a.setAttribute("hidden", ""); - a.setAttribute("href", url); - a.setAttribute("download", `${$stockTicker}_employees.csv`); - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); + // Create CSV blob and trigger download + const csv = csvRows.join("\n"); + const blob = new Blob([csv], { type: "text/csv" }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.setAttribute("hidden", ""); + a.setAttribute("href", url); + a.setAttribute("download", `${$stockTicker}_employees.csv`); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } else { + goto("/pricing"); + } }; @@ -546,6 +551,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download + diff --git a/src/routes/stocks/[tickerID]/stats/income/+page.svelte b/src/routes/stocks/[tickerID]/stats/income/+page.svelte index 4c520741..502bb1cb 100644 --- a/src/routes/stocks/[tickerID]/stats/income/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/income/+page.svelte @@ -9,7 +9,7 @@ import { Button } from "$lib/components/shadcn/button/index.js"; //import * as XLSX from 'xlsx'; import { Chart } from "svelte-echarts"; - + import { goto } from "$app/navigation"; import { init, use } from "echarts/core"; import { LineChart, BarChart } from "echarts/charts"; import { GridComponent, TooltipComponent } from "echarts/components"; @@ -258,53 +258,54 @@ displayStatement = "revenue"; const exportFundamentalData = (format = "csv") => { - const data = fullStatement; - if (!data || data.length === 0) { - return; - } + if (data?.user?.tier === "Pro") { + const data = fullStatement; + if (!data || data.length === 0) { + return; + } - let properties = [ - { - key: filterRule === "annual" ? "calendarYear" : "date", - label: filterRule === "annual" ? "Year" : "Quarter", - }, - ]; + let properties = [ + { + key: filterRule === "annual" ? "calendarYear" : "date", + label: filterRule === "annual" ? "Year" : "Quarter", + }, + ]; - for (let i = 0; i < statementConfig?.length; i++) { - properties.push({ - key: statementConfig[i]?.propertyName, - label: statementConfig[i]?.label, - }); - } + for (let i = 0; i < statementConfig?.length; i++) { + properties.push({ + key: statementConfig[i]?.propertyName, + label: statementConfig[i]?.label, + }); + } - // Helper function to handle special cases + // Helper function to handle special cases - // Create rows for CSV/Excel - let rows = data.map((item) => - properties?.map((property) => item[property?.key] || 0), - ); + // Create rows for CSV/Excel + let rows = data.map((item) => + properties?.map((property) => item[property?.key] || 0), + ); - // Include headers - const headers = properties.map((prop) => prop.label); - rows.unshift(headers); + // Include headers + const headers = properties.map((prop) => prop.label); + rows.unshift(headers); - // Check the format to export - if (format.toLowerCase() === "csv") { - const csvContent = rows.map((row) => row.join(",")).join("\n"); - const blob = new Blob([csvContent], { - type: "data:text/csv;charset=utf-8", - }); - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = - $stockTicker.toLowerCase() + - `${filterRule === "annual" ? "_annual" : "_quarter"}_income_statement.csv`; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - } /*else if (format.toLowerCase() === "excel") { + // Check the format to export + if (format.toLowerCase() === "csv") { + const csvContent = rows.map((row) => row.join(",")).join("\n"); + const blob = new Blob([csvContent], { + type: "data:text/csv;charset=utf-8", + }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = + $stockTicker.toLowerCase() + + `${filterRule === "annual" ? "_annual" : "_quarter"}_income_statement.csv`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } /*else if (format.toLowerCase() === "excel") { const worksheet = XLSX.utils.aoa_to_sheet(rows); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement"); @@ -315,6 +316,9 @@ } */ + } else { + goto("/pricing"); + } }; $: { @@ -548,6 +552,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download + diff --git a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte index 2ccc1bfd..1846c979 100644 --- a/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/market-cap/+page.svelte @@ -8,6 +8,7 @@ import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; import { Button } from "$lib/components/shadcn/button/index.js"; //import * as XLSX from 'xlsx'; + import { goto } from "$app/navigation"; import { Chart } from "svelte-echarts"; import { init, use } from "echarts/core"; @@ -242,50 +243,54 @@ } const exportData = (format = "csv") => { - // Add headers row - const csvRows = []; + if (data?.user?.tier === "Pro") { + // Add headers row + const csvRows = []; - csvRows.push("Date,Market Cap,Growth"); + csvRows.push("Date,Market Cap,Growth"); - // Add data rows - tableList?.forEach((item, index) => { - const date = item.date; - const marketCap = item.marketCap; + // Add data rows + tableList?.forEach((item, index) => { + const date = item.date; + const marketCap = item.marketCap; - // Calculate growth percentage - let growth = "-"; - if (index + 1 < tableList.length) { - if (item.marketCap - tableList[index + 1].marketCap > 0) { - growth = `+${( - ((item.marketCap - tableList[index + 1].marketCap) / - item.marketCap) * - 100 - ).toFixed(2)}%`; - } else if (item.marketCap - tableList[index + 1].marketCap < 0) { - growth = `-${( - Math.abs( - (tableList[index + 1].marketCap - item.marketCap) / - item.marketCap, - ) * 100 - ).toFixed(2)}%`; + // Calculate growth percentage + let growth = "-"; + if (index + 1 < tableList.length) { + if (item.marketCap - tableList[index + 1].marketCap > 0) { + growth = `+${( + ((item.marketCap - tableList[index + 1].marketCap) / + item.marketCap) * + 100 + ).toFixed(2)}%`; + } else if (item.marketCap - tableList[index + 1].marketCap < 0) { + growth = `-${( + Math.abs( + (tableList[index + 1].marketCap - item.marketCap) / + item.marketCap, + ) * 100 + ).toFixed(2)}%`; + } } - } - const csvRow = `${date},${marketCap},${growth}`; - csvRows.push(csvRow); - }); + const csvRow = `${date},${marketCap},${growth}`; + csvRows.push(csvRow); + }); - // Create CSV blob and trigger download - const csv = csvRows.join("\n"); - const blob = new Blob([csv], { type: "text/csv" }); - const url = window.URL.createObjectURL(blob); - const a = document.createElement("a"); - a.setAttribute("hidden", ""); - a.setAttribute("href", url); - a.setAttribute("download", `${$stockTicker}_market_cap.csv`); - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); + // Create CSV blob and trigger download + const csv = csvRows.join("\n"); + const blob = new Blob([csv], { type: "text/csv" }); + const url = window.URL.createObjectURL(blob); + const a = document.createElement("a"); + a.setAttribute("hidden", ""); + a.setAttribute("href", url); + a.setAttribute("download", `${$stockTicker}_market_cap.csv`); + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } else { + goto("/pricing"); + } }; @@ -447,6 +452,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download + diff --git a/src/routes/stocks/[tickerID]/stats/ratios/+page.svelte b/src/routes/stocks/[tickerID]/stats/ratios/+page.svelte index 7c3d56b0..a767639f 100644 --- a/src/routes/stocks/[tickerID]/stats/ratios/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/ratios/+page.svelte @@ -9,6 +9,7 @@ import * as DropdownMenu from "$lib/components/shadcn/dropdown-menu/index.js"; import { Button } from "$lib/components/shadcn/button/index.js"; //import * as XLSX from 'xlsx'; + import { goto } from "$app/navigation"; import { init, use } from "echarts/core"; import { LineChart, BarChart } from "echarts/charts"; import { GridComponent, TooltipComponent } from "echarts/components"; @@ -217,53 +218,54 @@ } const exportFundamentalData = (format = "csv") => { - const data = fullStatement; - if (!data || data.length === 0) { - return; - } + if (data?.user?.tier === "Pro") { + const data = fullStatement; + if (!data || data.length === 0) { + return; + } - let properties = [ - { - key: filterRule === "annual" ? "calendarYear" : "date", - label: filterRule === "annual" ? "Year" : "Quarter", - }, - ]; + let properties = [ + { + key: filterRule === "annual" ? "calendarYear" : "date", + label: filterRule === "annual" ? "Year" : "Quarter", + }, + ]; - for (let i = 0; i < statementConfig?.length; i++) { - properties.push({ - key: statementConfig[i]?.propertyName, - label: statementConfig[i]?.label, - }); - } + for (let i = 0; i < statementConfig?.length; i++) { + properties.push({ + key: statementConfig[i]?.propertyName, + label: statementConfig[i]?.label, + }); + } - // Helper function to handle special cases + // Helper function to handle special cases - // Create rows for CSV/Excel - let rows = data.map((item) => - properties?.map((property) => item[property?.key] || 0), - ); + // Create rows for CSV/Excel + let rows = data.map((item) => + properties?.map((property) => item[property?.key] || 0), + ); - // Include headers - const headers = properties.map((prop) => prop.label); - rows.unshift(headers); + // Include headers + const headers = properties.map((prop) => prop.label); + rows.unshift(headers); - // Check the format to export - if (format.toLowerCase() === "csv") { - const csvContent = rows.map((row) => row.join(",")).join("\n"); - const blob = new Blob([csvContent], { - type: "data:text/csv;charset=utf-8", - }); - const url = URL.createObjectURL(blob); - const a = document.createElement("a"); - a.href = url; - a.download = - $stockTicker.toLowerCase() + - `${filterRule === "annual" ? "_annual" : "_quarter"}_ratios_statement.csv`; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - URL.revokeObjectURL(url); - } /*else if (format.toLowerCase() === "excel") { + // Check the format to export + if (format.toLowerCase() === "csv") { + const csvContent = rows.map((row) => row.join(",")).join("\n"); + const blob = new Blob([csvContent], { + type: "data:text/csv;charset=utf-8", + }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = + $stockTicker.toLowerCase() + + `${filterRule === "annual" ? "_annual" : "_quarter"}_balance_sheet_statement.csv`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } /*else if (format.toLowerCase() === "excel") { const worksheet = XLSX.utils.aoa_to_sheet(rows); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, "Ratios Statement"); @@ -274,6 +276,9 @@ } */ + } else { + goto("/pricing"); + } }; fullStatement = data?.getRatiosStatement; @@ -532,6 +537,17 @@ class="ml-2 w-full border-gray-600 border bg-[#09090B] sm:hover:bg-[#27272A] ease-out flex flex-row justify-between items-center px-3 py-2 text-white rounded-lg truncate" > Download +