1. Abre a tua Google Sheet →
Extensões → Apps Script
2. Cola o código abaixo e guarda:
const SHEET_NAME = 'Pedidos';
function sheet_() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let s = ss.getSheetByName(SHEET_NAME);
if (!s) { s = ss.insertSheet(SHEET_NAME); s.appendRow(['num','mesa','artigos','total','nota','estado','hora']); }
return s;
}
function doPost(e) {
try {
const d = JSON.parse(e.postData.contents);
const s = sheet_();
if (d.action === 'add') {
const art = (d.items || []).map(i => i.qty + '× ' + i.name).join(', ');
s.appendRow([d.num, 'Mesa ' + d.table, art, d.total, d.note || '', 'new', d.time]);
}
if (d.action === 'update') {
const v = s.getDataRange().getValues();
for (let i = 1; i < v.length; i++) {
if (String(v[i][0]) === String(d.num)) { s.getRange(i + 1, 6).setValue(d.status); break; }
}
}
return ContentService.createTextOutput(JSON.stringify({ok:true})).setMimeType(ContentService.MimeType.JSON);
} catch (err) {
return ContentService.createTextOutput(JSON.stringify({ok:false,error:err.message})).setMimeType(ContentService.MimeType.JSON);
}
}
function doGet() {
const rows = Math.max(0, sheet_().getLastRow() - 1);
return ContentService.createTextOutput(JSON.stringify({ok:true, rows})).setMimeType(ContentService.MimeType.JSON);
}
3. Implementar → Nova implementação → Aplicação Web
4. Executar como:
Eu · Acesso:
Qualquer pessoa
5. Copia o URL e cola acima.