+
${cfg.next ? `
` : ''}
${o.status !== 'Cancelado' && o.status !== 'Entregue'
? `
`
@@ -169,6 +175,92 @@ function renderOrdersTable(data) {
})
);
+ // Reimprimir ticket de cozinha
+ wrap.querySelectorAll('.btn-reprint').forEach(btn =>
+ btn.addEventListener('click', async () => {
+ const orderId = btn.dataset.id;
+ const order = _ordersData.find(o => String(o.id) === String(orderId));
+ if (!order) return showToast('Pedido não encontrado.', 'error');
+
+ const comanda = _comandasMap[String(order.id_comanda)];
+ const product = _productsFullMap[String(order.id_product)];
+
+ const dataAtual = new Date().toLocaleString('pt-BR');
+ const nomeEstabelecimento = 'RRBEC - Bar & Restaurante';
+ const nomeProduto = product?.name || order.product_name || `Produto #${order.id_product}`;
+ const obs = order.obs || '';
+ const usuario = order.applicant || 'Sistema';
+ const nomeComanda = comanda?.name || `Comanda #${comanda?.id || order.id_comanda}`;
+ const nomeMesa = comanda?.mesa_name || comanda?.mesa || '–';
+
+ const htmlTicket = `
+
+
+
+
+
Ticket Cozinha - ${nomeComanda}
+
+
+
+
+
+
+
+ ${nomeComanda}
+
+
+ Mesa: ${nomeMesa}
+ ${dataAtual}
+
+
+
${nomeProduto}
+
+ ${obs ? `
OBS: ${obs}
` : ''}
+
+
+
+
+
+ `;
+
+ window.electronAPI.printDirect(htmlTicket).then(r => {
+ if (r.ok) {
+ showToast('Ticket reimpresso!', 'success');
+ } else if (r.error === 'NO_PRINTER') {
+ showToast('⚠️ Nenhuma impressora configurada. Configure uma impressora nas configurações do sistema.', 'warning', 5000);
+ const printWindow = window.open('', '', 'width=300,height=400');
+ printWindow.document.write(htmlTicket);
+ printWindow.document.close();
+ setTimeout(() => printWindow.print(), 300);
+ } else {
+ const printWindow = window.open('', '', 'width=300,height=400');
+ printWindow.document.write(htmlTicket);
+ printWindow.document.close();
+ setTimeout(() => printWindow.print(), 300);
+ }
+ });
+ })
+ );
+
// Editar observação
wrap.querySelectorAll('.btn-edit-obs').forEach(btn =>
btn.addEventListener('click', () => {
diff --git a/src/renderer/pages/produtos.js b/src/renderer/pages/produtos.js
index 85435ae..e58b3da 100644
--- a/src/renderer/pages/produtos.js
+++ b/src/renderer/pages/produtos.js
@@ -146,10 +146,21 @@ function filtrarProdutos(categorias, unidades) {
function abrirModalProduto(produto, categorias, unidades) {
const isEdit = !!produto;
+ const imagemAtual = produto?.image || '';
+
openModal({
title: isEdit ? `Editar: ${produto.name}` : 'Novo Produto',
body: `
`,
footer: `
`,
});
+ const previewEl = document.getElementById('prod-img-preview');
+ const fileInput = document.getElementById('prod-img-file');
+ const imgInput = document.getElementById('prod-img');
+
+ previewEl.addEventListener('click', () => fileInput.click());
+ document.getElementById('btn-select-img').addEventListener('click', () => fileInput.click());
+
+ fileInput.addEventListener('change', () => {
+ const file = fileInput.files[0];
+ if (!file) return;
+ if (file.size > 5 * 1024 * 1024) {
+ showToast('Imagem muito grande. Máximo 5MB.', 'warning');
+ return;
+ }
+ const reader = new FileReader();
+ reader.onload = (e) => {
+ const base64 = e.target.result;
+ imgInput.value = base64;
+ previewEl.innerHTML = `

`;
+ };
+ reader.readAsDataURL(file);
+ });
+
+ const btnRemoveImg = document.getElementById('btn-remove-img');
+ if (btnRemoveImg) {
+ btnRemoveImg.addEventListener('click', () => {
+ imgInput.value = '';
+ previewEl.innerHTML = '
📷';
+ });
+ }
+
document.getElementById('btn-salvar-prod').addEventListener('click', async () => {
const btn = document.getElementById('btn-salvar-prod');
btn.disabled = true;
@@ -212,7 +250,6 @@ function abrirModalProduto(produto, categorias, unidades) {
const catVal = parseInt(document.getElementById('prod-cat').value);
const unitVal = parseInt(document.getElementById('prod-unit').value);
- // Constrói o payload enviando apenas o que é necessário/preenchido
const data = {
name: document.getElementById('prod-nome').value.trim(),
description: document.getElementById('prod-desc').value.trim(),
@@ -220,9 +257,11 @@ function abrirModalProduto(produto, categorias, unidades) {
quantity: parseInt(document.getElementById('prod-qty').value) || 0,
active: document.getElementById('prod-ativo').value === 'true',
cuisine: document.getElementById('prod-cuisine').value === 'true',
- image: document.getElementById('prod-img').value.trim(),
};
+ const imgValue = document.getElementById('prod-img').value.trim();
+ if (imgValue) data.image = imgValue;
+
if (catVal) data.category = catVal;
if (unitVal) data.unit_of_measure = unitVal;