Agri Unit Calculator Tool
Billing • Inventory • Reports • Google Sheets Integration
👤 Customer Information
🛒 Items / Products
📋 Bill History (Local)
All calculated bills saved locally. Green = profit, Red = loss vs cost price.
| Date | Invoice | Customer | Mobile | Items | Subtotal | GST | Total | P&L |
|---|---|---|---|---|---|---|---|---|
| No bills yet. Calculate a bill first! | ||||||||
📊 Sales Reports & Charts
Period:
📈 Revenue Over Time
📊 Profit & Loss Bar Graph
🥧 Category Sales Split
🔝 Top Products
🌱 Product List (Editable — Update Daily)
Edit product names, cost price, selling price, GST% and unit. These prices auto-fill in billing.
| # | Category | Product Name | Cost Price | Sell Price | Unit | GST % | Action |
|---|
⚙️ Settings
📋 Google Sheets Integration — Setup Steps:
Step 1. Open your Google Sheet → Extensions → Apps Script
Step 2. Delete any existing code. Paste the Apps Script code from the card below.
Step 3. Click Deploy → New Deployment → Web App
• Execute as: Me
• Who has access: Anyone
Step 4. Copy the generated Web App URL and paste it below.
Step 5. Click Save Settings.
Step 1. Open your Google Sheet → Extensions → Apps Script
Step 2. Delete any existing code. Paste the Apps Script code from the card below.
Step 3. Click Deploy → New Deployment → Web App
• Execute as: Me
• Who has access: Anyone
Step 4. Copy the generated Web App URL and paste it below.
Step 5. Click Save Settings.
📋 Google Apps Script Code (Copy & Paste)
✅ This version includes proper CORS headers so Save to Sheet works correctly from the browser.
// ======================================================
// Agri Calculator — Google Apps Script (with CORS fix)
// Deploy as Web App: Execute as Me | Anyone can access
// ======================================================
function doGet(e) {
// Handles test ping from the app
return ContentService
.createTextOutput(JSON.stringify({ status: "ok", message: "Agri Sheet is connected!" }))
.setMimeType(ContentService.MimeType.JSON);
}
function doPost(e) {
try {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var ws = sheet.getSheetByName("AgriSales");
if (!ws) ws = sheet.insertSheet("AgriSales");
var data = JSON.parse(e.postData.contents);
// Add headers on first use
if (ws.getLastRow() === 0) {
ws.appendRow([
"Date", "Invoice No", "Customer Name", "Mobile No",
"Address", "Category", "Product", "Quantity", "Qty Unit",
"Price/Unit (Rs)", "GST%", "GST Amount (Rs)",
"Line Total (Rs)", "Bill Grand Total (Rs)", "Saved At"
]);
ws.getRange(1, 1, 1, 15).setFontWeight("bold")
.setBackground("#1a6b00").setFontColor("#fffbe6");
}
var savedAt = new Date().toLocaleString("en-IN");
// One row per item
data.items.forEach(function(item) {
ws.appendRow([
data.date,
data.invoiceNo,
data.customerName,
data.mobile,
data.address || "",
item.category,
item.product,
item.qty,
item.unit,
item.price,
item.gst,
item.gstAmt,
item.total,
data.grandTotal,
savedAt
]);
});
return buildResponse({ status: "ok", rows: data.items.length });
} catch (err) {
return buildResponse({ status: "error", message: err.toString() });
}
}
function buildResponse(obj) {
return ContentService
.createTextOutput(JSON.stringify(obj))
.setMimeType(ContentService.MimeType.JSON);
}
⚠️ After pasting, go to Deploy → Manage Deployments if updating an existing deployment — click Edit → New Version → Deploy.
🔁 Always redeploy after editing the script or changes won’t take effect.