-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaloon.js
More file actions
192 lines (166 loc) · 6.35 KB
/
Copy pathsaloon.js
File metadata and controls
192 lines (166 loc) · 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const localStorageKey = 'to-do-list-saloon';
import { recipesSaloon } from './RecipesSaloon.js';
import { ingredientCosts } from './IngredientCostsSaloon.js'; // novo
function validateIfExistsNewTask()
{
let values = JSON.parse(localStorage.getItem(localStorageKey) || "[]")
let inputValue = document.getElementById('input-new-task').value
let exists = values.find(x => x.name == inputValue)
return !exists ? false : true
}
function newTask()
{
let input = document.getElementById('input-new-task')
input.style.border = ''
// validation
if(!input.value)
{
input.style.border = '1px solid red'
alert('Digite algo para inserir em sua lista')
}
else if(validateIfExistsNewTask())
{
alert('Já existe uma tarefa igual a essa na lista!')
}
else
{
// increment to localStorage
let values = JSON.parse(localStorage.getItem(localStorageKey) || "[]")
values.push({
name: input.value,
checked: false
})
localStorage.setItem(localStorageKey,JSON.stringify(values))
showValues()
}
input.value = ''
}
function showValues() {
let values = JSON.parse(localStorage.getItem(localStorageKey) || "[]");
let list = document.getElementById('to-do-list');
list.innerHTML = '';
for (let i = 0; i < values.length; i++) {
const task = values[i];
const isChecked = task.checked ? "checked" : "";
list.innerHTML += `
<li class="${isChecked}" onclick="toggleChecked(${i})">
${task.name}
<button id='btn-ok' onclick='event.stopPropagation(); removeItem("${task.name}")'>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-lg" viewBox="0 0 16 16"><path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425a.247.247 0 0 1 .02-.022Z"/></svg>
</button>
</li>
`;
}
}
function removeItem(data)
{
let values = JSON.parse(localStorage.getItem(localStorageKey) || "[]")
let index = values.findIndex(x => x.name == data)
values.splice(index,1)
localStorage.setItem(localStorageKey,JSON.stringify(values))
showValues()
}
function toggleChecked(index) {
let values = JSON.parse(localStorage.getItem(localStorageKey) || "[]");
values[index].checked = !values[index].checked;
localStorage.setItem(localStorageKey, JSON.stringify(values));
showValues();
}
showValues()
window.newTask = newTask;
window.removeItem = removeItem;
window.toggleChecked = toggleChecked;
// Popula o seletor com as receitas do Saloon
function populateRecipeSelect() {
const select = document.getElementById("recipe-select");
select.innerHTML = ''; // limpa o conteúdo anterior
Object.keys(recipesSaloon).forEach(recipeName => {
const option = document.createElement("option");
option.value = recipeName;
option.textContent = recipeName;
select.appendChild(option);
});
}
// Emojis para ingredientes
function getEmoji(ingredientName) {
const map = {
"Banana": "🍌",
"Milho": "🌽",
"Trigo": "🌾",
"Água": "💧",
"Cana de Açúcar": "🎋",
"Melado de Cana": "🍯",
"Leite": "🥛",
"Ovos": "🥚",
"Ovo": "🥚",
"Carne de Pássaro": "🍗",
"Alho": "🧄",
"Orégano": "🌿",
"Banana": "🍌",
"Garrafa de Água": "💧",
"Amora": "🍇",
"Fardo de Garrafa de Vidro": "🍼",
"Açúcar": "🍲",
"Rótulo": "📜",
"Álcool Artesanal": "🍶",
"Farinha de Trigo": "🍚",
"Fardo de Leite Integral": "🍱",
"Carne de Caça Grande": "🍖",
"Carne de Caça" : "🍖",
"Oleo de Milho": "🥫",
"Amido de Milho": "🍚",
"Levedura": "🍿",
"Batata": "🥔",
"Alho": "🧄",
};
return map[ingredientName] || "💢";
}
// Cálculo da receita
function calculateRecipe() {
const recipeName = document.getElementById("recipe-select").value;
const quantity = parseInt(document.getElementById("recipe-quantity").value);
const resultEl = document.getElementById("calculation-result");
if (!recipeName || isNaN(quantity) || quantity <= 0) {
resultEl.innerHTML = "Por favor, selecione uma receita e insira uma quantidade válida.";
return;
}
const recipe = recipesSaloon[recipeName];
const totalYield = recipe.yield * quantity;
const minUnit = recipe.minPrice;
const maxUnit = recipe.maxPrice;
const minTotal = minUnit * totalYield;
const maxTotal = maxUnit * totalYield;
// Calcular custo total
let totalCost = 0;
let ingredientsHTML = '<ul class="ingredients-list">';
recipe.ingredients.forEach(ingredient => {
const emoji = getEmoji(ingredient.name);
const totalQty = ingredient.quantity * quantity;
const unitCost = ingredientCosts[ingredient.name] || 0;
const ingredientCost = unitCost * totalQty;
totalCost += ingredientCost;
ingredientsHTML += `<li class='ingredient-item'>${emoji} ${ingredient.name}: ${totalQty} (U$ ${ingredientCost.toFixed(2)})</li>`;
});
ingredientsHTML += "</ul>";
const lucroMin = minTotal - totalCost;
const lucroMax = maxTotal - totalCost;
resultEl.innerHTML = `
<strong>${recipeName}</strong><br>
<strong>Quantidade total:</strong> ${totalYield}<br>
<strong>Preço unitário:</strong> U$ ${minUnit.toFixed(2)} - U$ ${maxUnit.toFixed(2)}<br>
<strong>Faixa de preço total:</strong> U$ ${minTotal.toFixed(2)} - U$ ${maxTotal.toFixed(2)}<br>
<strong><span style="color:darkred">Custo de produção:</span></strong> U$ ${totalCost.toFixed(2)}<br>
<strong><span style="color:darkgreen">Lucro estimado:</span></strong> U$ ${lucroMin.toFixed(2)} - U$ ${lucroMax.toFixed(2)}<br><br>
<strong>Ingredientes:</strong><br>
${ingredientsHTML}
`;
}
// Inicializa tudo
function init() {
showValues();
populateRecipeSelect();
document.getElementById("calculate-btn").addEventListener("click", calculateRecipe);
}
init();
window.newTask = newTask;
window.removeItem = removeItem;