Skip to content

Commit

Permalink
Merge pull request #315 from fiit-tp-tim20/main
Browse files Browse the repository at this point in the history
archive report export
  • Loading branch information
Matej96 authored Jun 17, 2024
2 parents 52c9edd + b3ce610 commit 436736b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
41 changes: 41 additions & 0 deletions apps/saip-fe/src/components/reports/ArchiveReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next";
// @ts-ignore
import { MyContext } from "../../api/MyContext";
import getCompanyReport from "../../api/GetCompanyReport";
import {CSVLink} from "react-csv";

function ArchiveReport() {
const { t } = useTranslation();
Expand Down Expand Up @@ -38,6 +39,40 @@ function ArchiveReport() {
}));
};

const exportMarketingToCSV = () => {
const csvData = [[t("misc.round"), t("marketing.types.tv.title"), t("marketing.types.viral.title"), t("marketing.types.billboards.title"), "OOH", t("marketing.types.podcasts.title")]];
const keys = Object.keys(data.marketing);

for (let i = 0; i < data.marketing.tv.length; i++) {
const row: number[] = [];
row.push(i);
for (const key of keys) {
row.push(data.marketing[key][i]);
}
csvData.push(row);
}

return csvData;
};

const exportProductionToCSV = () => {
const csvData = [[t("misc.round"), t("dashboard.decision_archive.quantity"), t("dashboard.decision_archive.price"), t("dashboard.decision_archive.capital"), t("dashboard.decision_archive.upgrades"), t("dashboard.decision_archive.done")]];

for (let i = 0; i < data.marketing.tv.length; i++) {
const row: number[] = [];
row.push(i);
row.push(data.production.volume[i]);
row.push(data.production.sell_price[i]);
row.push(data.factory.capital[i]);
row.push(data.factory.upgrades[i]);
row.push(data.factory.upgrade_turn[i]);

csvData.push(row);
}

return csvData;
};

// poradie
return (
<div className="flex w-[600px] flex-col md:w-[900px] xl:w-[1280px]">
Expand Down Expand Up @@ -93,6 +128,9 @@ function ArchiveReport() {
<div className="background-container my-2 flex flex-col rounded-2xl p-6">
<div className="flex flex-row items-center justify-between py-2">
<h2>{t("dashboard.decision_archive.marketing") as string}</h2>
<CSVLink data={exportMarketingToCSV()} filename={"marketing_report.csv"} className="button-light font-bold py-2 px-4 rounded-lg focus:outline-none focus:shadow-outline">
{t("dashboard.decision_archive.export_to_csv") as string}
</CSVLink>
</div>
<table className="table-auto table-white">
<tbody>
Expand Down Expand Up @@ -130,6 +168,9 @@ function ArchiveReport() {
<div className="background-container my-2 flex flex-col rounded-2xl p-6">
<div className="flex flex-row items-center justify-between py-2">
<h2>{t("dashboard.decision_archive.prod") as string}</h2>
<CSVLink data={exportProductionToCSV()} filename={"production_report.csv"} className="button-light font-bold py-2 px-4 rounded-lg focus:outline-none focus:shadow-outline">
{t("dashboard.decision_archive.export_to_csv") as string}
</CSVLink>
</div>
<table className="table-auto table-white">
<tbody>
Expand Down
39 changes: 21 additions & 18 deletions apps/saip-fe/src/components/reports/CompanyReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,32 @@ function CompanyReport() {
<div className="flex w-[600px] flex-col md:w-[900px] xl:w-[1280px]">
<div className="flex flex-row justify-between">
<h1 className="my-4">{t("dashboard.company_report.title") as string}</h1>
<div>
<div className="flex">
<button
onClick={exportToCSV}
className="button-light font-bold py-2 px-4 rounded-lg focus:outline-none focus:shadow-outline"
style={{ marginTop: "28px", maxHeight: "40px" }}
>
Export to CSV
{t("dashboard.decision_archive.export_to_csv") as string}
</button>
<label htmlFor="turn" className="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-600">
{t("dashboard.for_round") as string}
</label>
<select
id="turn"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 hover:cursor-pointer"
value={numberShow}
onChange={(e) => {
setNumberShow(parseInt(e.target.value, 10));
}}
>
{[...Array(TURN).keys()].map((o) => {
if (o === 0) return null;
return <option value={o}>{o}</option>;
})}
</select>
<div>
<label htmlFor="turn" className="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-600">
{t("dashboard.for_round") as string}
</label>
<select
id="turn"
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 hover:cursor-pointer"
value={numberShow}
onChange={(e) => {
setNumberShow(parseInt(e.target.value, 10));
}}
>
{[...Array(TURN).keys()].map((o) => {
if (o === 0) return null;
return <option value={o}>{o}</option>;
})}
</select>
</div>
</div>
</div>
{isLoading ? (
Expand Down
6 changes: 3 additions & 3 deletions apps/saip-fe/src/components/reports/IndustryReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function IndustryReport() {
};

const exportToCSV = () => {
const csvData = [["Spoločnosť", "Hodnota jednej akcie", "Výsledok hospodárenia po zdanení", "Predajná cena", "Podiel na trhu"]];
const csvData = [[t("dashboard.industry_report.table.company"), t("dashboard.industry_report.table.value"), t("dashboard.industry_report.table.after_tax"), t("dashboard.industry_report.table.price"), t("dashboard.industry_report.table.share"), t("dashboard.industry_report.table.upgrades")]];
data && Object.entries(data.industry).forEach(([company, info]) => {
csvData.push([company, numberWithSpaces(info.stock_price) + " €", numberWithSpaces(info.net_profit) + " €", numberWithSpaces(info.sell_price) + " €/ks", numberWithSpaces(info.market_share) + " %"]);
csvData.push([company, info.stock_price, info.net_profit, info.sell_price, info.market_share, info.finished_upgrades]);
});
return csvData;
};
Expand Down Expand Up @@ -112,7 +112,7 @@ function IndustryReport() {
<h2>{t("dashboard.industry_report.ranking") as string}</h2>
<div>
<CSVLink data={exportToCSV()} filename={"industry_report.csv"} className="button-light font-bold py-2 px-4 rounded-lg focus:outline-none focus:shadow-outline">
Export CSV
{t("dashboard.decision_archive.export_to_csv") as string}
</CSVLink>
{/* Add a button to open the tutorial */}
<button
Expand Down
3 changes: 2 additions & 1 deletion apps/saip-fe/src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
"tip": {
"text1": "The investment in upgrades is expressed as the sum of the investments in upgrades.",
"text2": "It is not possible to determine which enhancement the company developed in which round. It is necessary to keep a separate record of it."
}
},
"export_to_csv": "Export to CSV"
}
},
"product": {
Expand Down
6 changes: 3 additions & 3 deletions apps/saip-fe/src/i18n/locales/sk/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@
"title": "Archív rozhodnutí",
"marketing": "Archív marketingu",
"prod": "Archív produkcie",
"quantity": "Vyrobené množstvo=",
"quantity": "Vyrobené množstvo",
"price": "Predajná cena",
"capital": "Investície do kapitálu",
"upgrades": "Investície do vylepšení",
"done": "Dokončené vylepšenia",
"tip": {
"text1": "Investície do vylepšení sú vyjadrené ako súčet investícií do vylepšení.",
"text2": "Nie je možné určiť, ktoré vylepšenie podnik v ktorom kole vyvíjal. Je potrebné si viesť o tom evidenciu zvlášť."
}

},
"export_to_csv": "Exportovať do CSV"
}
},
"product": {
Expand Down

0 comments on commit 436736b

Please sign in to comment.