mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-25 22:27:05 -04:00
* Add show/hide cost price & profit feature * .env should be ignored. * js code formatted. .vscode folder ignore for vscode user settings.json * style is replaced with bootstrap class, formatted and .env.example * toggle button on table to like in other * comment corrected. * class re-factored * minor refactor * formatted with 4 space --------- Co-authored-by: Lotussoft Youngtech <lotussoftyoungtech@gmail.com>
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/**
|
|
* public/js/hide_cost_profit.js
|
|
* toggle cost and profit in graphical report.
|
|
*/
|
|
$(function () {
|
|
const safeSetItem = (key, value) => {
|
|
try {
|
|
localStorage.setItem(key, value);
|
|
} catch (e) {
|
|
console.error("Storage error", e);
|
|
}
|
|
};
|
|
|
|
const safeGetItem = (key) => {
|
|
try {
|
|
return localStorage.getItem(key);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
};
|
|
|
|
let summaryVisibility = JSON.parse(safeGetItem("summaryVisibility")) || {
|
|
cost: false,
|
|
profit: false,
|
|
};
|
|
|
|
function applySummaryVisibility() {
|
|
const rows = $("#chart_report_summary .summary_row");
|
|
if (rows.length < 2) return; // Prevent errors if data is missing
|
|
|
|
const costRow = rows.eq(rows.length - 2);
|
|
const profitRow = rows.eq(rows.length - 1);
|
|
|
|
summaryVisibility.cost ? costRow.show() : costRow.hide();
|
|
summaryVisibility.profit ? profitRow.show() : profitRow.hide();
|
|
}
|
|
|
|
$("#toggleCostProfitButton").on("click", function () {
|
|
summaryVisibility.cost = !summaryVisibility.cost;
|
|
summaryVisibility.profit = !summaryVisibility.profit;
|
|
safeSetItem("summaryVisibility", JSON.stringify(summaryVisibility));
|
|
applySummaryVisibility();
|
|
});
|
|
|
|
applySummaryVisibility();
|
|
});
|