// EJI API for Google Sheets: Legal. Paste this whole file into Extensions > Apps Script // (replace what is there), save, then reload the sheet. Every formula starts with EJI_: type =EJI_ in a cell to see them, or use // EJI API > Insert formula… One sheet needs only this one script; to add an area, copy a new script that has it and paste over this one. // ===== EJI API core: one menu for every EJI family in this sheet (Finance, Accounting, Medical, ...) ===== /** @OnlyCurrentDoc */ // Google asks for this sheet only, not for all your Google Sheets // Every family part below registers itself with a function ejiFamily__(); nothing here depends on file order. var EJI_CATALOG_ = [{"family":"Legal","name":"EJI_LEGAL_SECTION","doc":"The new section for an old one (or the old for a new). =EJI_LEGAL_SECTION(\"IPC\", 420) gives 318. Not reviewed by a lawyer.","example":"=EJI_LEGAL_SECTION(\"IPC\", 420)","params":[{"name":"code","desc":"IPC, CrPC, IEA (old) or BNS, BNSS, BSA (new)"},{"name":"section","desc":"the section number, e.g. 420 or \"304B\""},{"name":"field","desc":"newSection (default), newSubSection, newTitle, oldTitle, status; \"all\" lists every match"}]},{"family":"Legal","name":"EJI_LEGAL_SECTION_SEARCH","doc":"Sections whose title has your words.","example":"=EJI_LEGAL_SECTION_SEARCH(\"theft\")","params":[{"name":"query","desc":"words in the section title"},{"name":"limit","desc":"how many, up to 100 (default 30)"}]},{"family":"Legal","name":"EJI_LEGAL_ACTS","doc":"Acts whose text has your words, with the matching passage.","example":"=EJI_LEGAL_ACTS(\"dowry death\")","params":[{"name":"query","desc":"words inside the Acts, e.g. \"dowry death\""},{"name":"limit","desc":"how many, up to 50 (default 10)"}]},{"family":"Legal","name":"EJI_LEGAL_JUDGMENTS","doc":"Judgments (metadata) with your words in the title or judge.","example":"=EJI_LEGAL_JUDGMENTS(\"bihar\", \"sc\", 2023)","params":[{"name":"query","desc":"words in the parties or judge"},{"name":"court","desc":"sc for the Supreme Court, hc for High Courts (blank for both)"},{"name":"year","desc":"decision year"},{"name":"limit","desc":"how many, up to 100 (default 25)"}]},{"family":"Legal","name":"EJI_LEGAL_JUDGMENT_SEARCH","doc":"Words inside judgment texts we hold, with the matching passage.","example":"=EJI_LEGAL_JUDGMENT_SEARCH(\"specific performance\")","params":[{"name":"query","desc":"words inside the judgments"},{"name":"limit","desc":"how many, up to 50 (default 10)"}]},{"family":"Legal","name":"EJI_LEGAL_JUDGMENT_TEXT","doc":"The text of one judgment (a cell holds at most 50,000 characters, so use the start to read on).","example":"=EJI_LEGAL_JUDGMENT_TEXT(\"sc:2023INSC1043\")","params":[{"name":"id","desc":"the judgment id from EJI_LEGAL_JUDGMENTS"},{"name":"start","desc":"character to start from (default 0)"}]},{"family":"Legal","name":"EJI_LEGAL_CITATION","doc":"What a citation or CNR number is, and the judgment we hold for it.","example":"=EJI_LEGAL_CITATION(\"2023 INSC 600\")","params":[{"name":"citation","desc":"e.g. \"2023 INSC 600\", \"(2020) 5 SCC 1\", \"AIR 1973 SC 1461\" or a CNR"},{"name":"field","desc":"one field, e.g. type, normalised, judgmentId"}]},{"family":"Legal","name":"EJI_LEGAL_PENDENCY","doc":"District and taluka court pendency (NJDG). With a field you get one number.","example":"=EJI_LEGAL_PENDENCY(\"total\")","params":[{"name":"field","desc":"total, civil, criminal, filedLastMonth, disposedLastMonth, filedByWomen, filedBySeniorCitizens, day"}]},{"family":"Legal","name":"EJI_LEGAL_BILLS","doc":"Parliament bills with your words in the name.","example":"=EJI_LEGAL_BILLS(\"data protection\")","params":[{"name":"query","desc":"words in the bill name"},{"name":"status","desc":"e.g. Pending, Passed"},{"name":"limit","desc":"how many, up to 200 (default 25)"}]},{"family":"Legal","name":"EJI_LEGAL_LIMITATION","doc":"Last day to file a claim. =EJI_LEGAL_LIMITATION(\"money-lent\", DATE(2024,1,15)). Without arguments it lists the kinds.","example":"=EJI_LEGAL_LIMITATION(\"money-lent\", DATE(2024,1,15))","params":[{"name":"kind","desc":"e.g. money-lent, goods-sold, breach-of-contract, appeal-high-court"},{"name":"accrual","desc":"the date the right to sue arose"},{"name":"field","desc":"lastDay (default), article, period, startsWhen; \"all\" gives every field"}]},{"family":"Legal","name":"EJI_LEGAL_CHEQUE_BOUNCE","doc":"Dates for a bounced cheque (Negotiable Instruments Act s.138).","example":"=EJI_LEGAL_CHEQUE_BOUNCE(A2, B2, \"demandNoticeWithin\")","params":[{"name":"chequeDate","desc":"date on the cheque"},{"name":"returned","desc":"date the bank returned it"},{"name":"field","desc":"presentWithin, demandNoticeWithin, paymentDueBy, noticeInTime...; blank lists all"},{"name":"noticeSent","desc":"date the demand notice was sent"},{"name":"noticeReceived","desc":"date the drawer received it"}]},{"family":"Legal","name":"EJI_LEGAL_INTEREST","doc":"Simple interest (or yearly compounding) between two dates.","example":"=EJI_LEGAL_INTEREST(100000, 12, DATE(2024,1,1), DATE(2025,1,1))","params":[{"name":"principal","desc":"the sum"},{"name":"ratePercentPerYear","desc":"e.g. 12"},{"name":"start","desc":"first day"},{"name":"end","desc":"last day"},{"name":"compound","desc":"true for yearly compounding"},{"name":"field","desc":"interest (default), total, days; \"all\" gives every field"}]}]; function ejiFamilies_() { var out = []; if (typeof ejiFamily_fin_ === "function") out.push(ejiFamily_fin_()); if (typeof ejiFamily_acc_ === "function") out.push(ejiFamily_acc_()); if (typeof ejiFamily_med_ === "function") out.push(ejiFamily_med_()); if (typeof ejiFamily_my_ === "function") out.push(ejiFamily_my_()); if (typeof ejiFamily_legal_ === "function") out.push(ejiFamily_legal_()); return out; } function onOpen() { var ui = SpreadsheetApp.getUi(); var menu = ui.createMenu("EJI API") .addItem("Insert formula…", "ejiFormulaSidebar") .addItem("Add a formula guide tab", "ejiFormulaGuide") .addItem("Refresh values", "ejiRefresh") .addSeparator(); ejiFamilies_().forEach(function (f) { var sub = ui.createMenu(f.name); f.items.forEach(function (it) { sub.addItem(it[0], it[1]); }); menu.addSubMenu(sub); }); menu.addToUi(); } // Forget cached answers (every family) and enter the EJI formulas of the current sheet again, so their values are fetched // fresh. Nothing else is touched: other formulas and everything typed stay exactly as they are. function ejiRefresh() { ejiFamilies_().forEach(function (f) { if (f.bump) f.bump(); }); var sheet = SpreadsheetApp.getActiveSheet(); var formulas = sheet.getDataRange().getFormulas(); var mine = new RegExp("\\b(" + "EJI_[A-Z0-9_]+|TALLY_[A-Z0-9_]+|MED_[A-Z0-9_]+|IPOLISTGAIN|STOCKCLOSE|INDEXCLOSE|NAVRETURN|IPOSTATUS|FUNDNAME|IPOPRICE|FUNDNAV|IPODATE|IPOSUBS|INDEXPE|IPOLOT|IPOGMP|NAVON|FXINR|EJI" + ")\\s*\\(", "i"); var runs = []; formulas.forEach(function (row, i) { var j = 0; while (j < row.length) { if (!mine.test(row[j])) { j++; continue; } var start = j; while (j < row.length && mine.test(row[j])) j++; runs.push({ r: i + 1, c: start + 1, f: row.slice(start, j) }); } }); if (!runs.length) { SpreadsheetApp.getUi().alert("There are no EJI formulas on this sheet."); return; } // Clear, wait, enter again. Whatever happens in between, the formulas that were cleared are put back (finally). var cleared = [], failed = []; try { runs.forEach(function (x) { sheet.getRange(x.r, x.c, 1, x.f.length).clearContent(); cleared.push(x); }); SpreadsheetApp.flush(); } finally { cleared.forEach(function (x) { try { sheet.getRange(x.r, x.c, 1, x.f.length).setFormulas([x.f]); } catch (e) { failed.push(x.r + ":" + x.c); } }); } if (failed.length) throw new Error("Could not enter the formulas again at row:column " + failed.join(", ") + ". Use Edit > Undo to bring them back."); } // ---- fields: one value out of an API answer ---- // A dotted field of the answer: latestNav, returns.1y, 0.nav (first item), -1.nav (last), *.nav (every item: a column). function ejiField_(data, field) { var parts = (field == null || String(field).trim() === "") ? [] : String(field).trim().split("."); function walk(v, i) { if (i >= parts.length) return v; var k = parts[i]; if (k === "*") { if (!Array.isArray(v)) throw new Error("* needs a list"); return v.map(function (x) { return walk(x, i + 1); }); } if (Array.isArray(v)) { if (!/^-?\d+$/.test(k)) throw new Error("This is a list: use 0 for the first item, -1 for the last, or * for all"); var x = v[Number(k) < 0 ? v.length + Number(k) : Number(k)]; if (x === undefined) throw new Error("The list has " + v.length + " items, no item " + k); return walk(x, i + 1); } if (v === null || typeof v !== "object" || !Object.prototype.hasOwnProperty.call(v, k)) { var here = (v !== null && typeof v === "object") ? Object.keys(v).slice(0, 12).join(", ") : ""; throw new Error("No field " + parts.slice(0, i + 1).join(".") + (here ? ". Fields here: " + here : "")); } return walk(v[k], i + 1); } function cell(x) { if (x === null || x === undefined) return ""; if (typeof x === "object") throw new Error("That is a group of fields; pick one inside it: " + Object.keys(x).slice(0, 6).join(", ")); return x; } var v = walk(data, 0); if (Array.isArray(v)) return v.length ? v.map(function (x) { return [cell(x)]; }) : ""; return cell(v); } // Every single-value field of an answer as [field, sample]: objects opened, a list as "0.x" and "*.x". function ejiListFields_(data) { var out = []; function visit(v, at, depth) { if (out.length >= 300) return; if (v === null || typeof v !== "object") { if (at) out.push([at, v === null || v === undefined ? "" : v]); return; } if (depth > 5) return; if (Array.isArray(v)) { if (!v.length) return; var pre = at ? at + "." : ""; if (v[0] !== null && typeof v[0] === "object" && !Array.isArray(v[0])) { Object.keys(v[0]).forEach(function (k) { var x = v[0][k]; if (x === null || typeof x !== "object") out.push([pre + "*." + k, x === null ? "" : x]); }); } else if (v[0] === null || typeof v[0] !== "object") out.push([pre + "*", v[0]]); visit(v[0], pre + "0", depth + 1); return; } Object.keys(v).forEach(function (k) { visit(v[k], at ? at + "." + k : k, depth + 1); }); } visit(data, "", 0); return out; } // What a cell shows when the field is left empty: the fields to choose from. function ejiPickHint_(data) { var names = ejiListFields_(data).map(function (f) { return f[0]; }).filter(function (n) { return n.indexOf("*") < 0; }); return names.length ? "Pick a field: " + names.slice(0, 40).join(", ") + (names.length > 40 ? ", …" : "") : "This answer has no fields"; } // ---- Insert formula… (a sidebar) and the formula guide tab ---- var EJI_SIDEBAR_ = "\n\n\n\n
\n
\n \n
\n
\n\n

\n\n\n"; function ejiFormulaSidebar() { var fields = []; ejiFamilies_().forEach(function (f) { (f.fields || []).forEach(function (s) { fields.push({ fn: s.fn, label: f.name + ": " + s.label, arg: s.arg, example: s.example }); }); }); var data = "var CAT = " + JSON.stringify(EJI_CATALOG_) + ", FIELDS = " + JSON.stringify(fields) + ";"; var html = HtmlService.createHtmlOutput(EJI_SIDEBAR_.replace("/*DATA*/", data.replace(/ 0) { var m = (n - 1) % 26; s = String.fromCharCode(65 + m) + s; n = Math.floor((n - 1) / 26); } return s; } // Called by the sidebar: a table at the selected cell. A header row, then one row per value, each formula reading its row's value. function ejiInsertTable(fn, keysText, fields) { var spec = ejiFieldSpec_(fn); var keys = String(keysText == null ? "" : keysText).split(/[,;\n]+/).map(function (k) { return k.trim(); }).filter(Boolean); if (!keys.length) keys = [spec.example]; fields = (fields || []).map(String).filter(function (f) { return /^[A-Za-z0-9_.\-]+$/.test(f); }); if (!fields.length) throw new Error("Tick at least one field"); var cell = SpreadsheetApp.getActiveRange().getCell(1, 1), sh = cell.getSheet(), r0 = cell.getRow(), c0 = cell.getColumn(); var col = ejiColName_(c0); var rows = [[spec.arg].concat(fields)]; keys.forEach(function (k, i) { rows.push([k].concat(fields.map(function (f) { return "=" + fn + "(" + col + (r0 + 1 + i) + ", \"" + f + "\")"; }))); }); var range = sh.getRange(r0, c0, rows.length, rows[0].length); range.setValues(rows); sh.getRange(r0, c0, 1, rows[0].length).setFontWeight("bold"); return range.getA1Notation(); } // A tab named "EJI formulas" listing every formula of this script, what it gives and an example to copy. function ejiFormulaGuide() { var ss = SpreadsheetApp.getActive(); var sh = ss.getSheetByName("EJI formulas") || ss.insertSheet("EJI formulas"); sh.clear(); var rows = [["Area", "Formula", "What it gives", "Example (copy into a cell)"]].concat(EJI_CATALOG_.map(function (c) { return [c.family, c.name + "(" + c.params.map(function (p) { return p.name; }).join(", ") + ")", c.doc, c.example ? "'" + c.example : ""]; })); sh.getRange(1, 1, rows.length, 4).setValues(rows); sh.getRange(1, 1, 1, 4).setFontWeight("bold"); sh.setFrozenRows(1); sh.autoResizeColumns(1, 2); sh.setColumnWidth(3, 460); sh.setColumnWidth(4, 320); ss.setActiveSheet(sh); } // ===== end of the core ===== // EJI API Legal for Google Sheets. This is the Legal part of an EJI API script. // Menu "EJI API" > Legal > Set API key stores your Legal key (leg_...) in this script's properties, never in a cell. // Reference information only, not legal advice. The IPC/CrPC/Evidence Act to BNS/BNSS/BSA table has not been reviewed by a lawyer. var EJI_LEGAL_BASE_ = "https://legal.ejiapi.com/api/legal/v1"; var EJI_LEGAL_CACHE_SECONDS_ = 3600; // 1 hour; EJI API > Refresh values fetches fresh answers var EJI_LEGAL_MAX_CELLS_ = 50; // keys looked up one by one, so a range is capped // ---------- plumbing ---------- function ejiLegal_(path, params) { var props = PropertiesService.getScriptProperties(); var q = []; Object.keys(params || {}).forEach(function (k) { var v = params[k]; if (v !== undefined && v !== null && String(v).trim() !== "") q.push(encodeURIComponent(k) + "=" + encodeURIComponent(String(v).trim())); }); var full = path + (q.length ? "?" + q.join("&") : ""); var cacheKey = "l" + (props.getProperty("EJI_LEGAL_CACHE_V") || "0") + ":" + full; if (cacheKey.length > 240) cacheKey = cacheKey.slice(0, 200) + Utilities.base64Encode(Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, cacheKey)); var cache = CacheService.getScriptCache(); var hit = cache.get(cacheKey); if (hit) return JSON.parse(hit); var key = props.getProperty("EJI_LEGAL_KEY"); if (!key) throw new Error("Set your key first: menu EJI API > Legal > Set API key"); var res; try { res = UrlFetchApp.fetch(EJI_LEGAL_BASE_ + full, { method: "get", headers: { "X-API-Key": key, "X-Client": "sheets" }, muteHttpExceptions: true }); } catch (e) { throw new Error("Could not reach EJI (" + e.message + "). Run EJI API > Legal > Check setup once to give the script permission."); } var text = res.getContentText(), code = res.getResponseCode(); if (code !== 200) { var detail = text; try { detail = JSON.parse(text).detail || text; } catch (e) {} throw new Error(code === 401 ? "The Legal key was not accepted. EJI API > Legal > Set API key." : String(detail).slice(0, 160)); } if (text.length < 90000) cache.put(cacheKey, text, EJI_LEGAL_CACHE_SECONDS_); // a cached value may not exceed 100 KB return JSON.parse(text); } function ejiLegalCell_(v) { if (v === null || v === undefined) return ""; if (Array.isArray(v)) return v.join(", "); if (typeof v === "object") return JSON.stringify(v); return v; } function ejiLegalDate_(d, name) { if (d instanceof Date) return Utilities.formatDate(d, "Asia/Kolkata", "yyyy-MM-dd"); var s = String(d === undefined || d === null ? "" : d).trim(); if (!/^\d{4}-\d{2}-\d{2}$/.test(s)) throw new Error(name + " must be a date (a date cell, or text like 2026-01-15)"); return s; } // A table from rows of objects: a header row, then one row per object. Nothing found gives one line saying so. function ejiLegalTable_(rows, cols) { var heads = cols.map(function (c) { return c[1]; }); if (!rows.length) return [heads, heads.map(function (h, i) { return i === 0 ? "Nothing found" : ""; })]; return [heads].concat(rows.map(function (r) { return cols.map(function (c) { return ejiLegalCell_(r[c[0]]); }); })); } // One answer object from a field name, or the whole object as two columns (name, value) when no field is asked for. function ejiLegalPick_(obj, field) { var f = field === undefined || field === null ? "" : String(field).trim(); if (f) { if (!(f in obj)) throw new Error("There is no field '" + f + "'. Fields: " + Object.keys(obj).join(", ")); var v = obj[f]; return (v && typeof v === "object" && !Array.isArray(v) && "date" in v) ? v.date : ejiLegalCell_(v); } return Object.keys(obj).map(function (k) { var v = obj[k]; return [k, (v && typeof v === "object" && !Array.isArray(v) && "date" in v) ? v.date : ejiLegalCell_(v)]; }); } // ---------- sections: IPC, CrPC and Evidence Act to BNS, BNSS and BSA (and back) ---------- /** The new section for an old one (or the old for a new). =EJI_LEGAL_SECTION("IPC", 420) gives 318. Not reviewed by a lawyer. * @param {string} code IPC, CrPC, IEA (old) or BNS, BNSS, BSA (new) * @param {string|number} section the section number, e.g. 420 or "304B" * @param {string} [field] newSection (default), newSubSection, newTitle, oldTitle, status; "all" lists every match * @customfunction */ function EJI_LEGAL_SECTION(code, section, field) { var c = String(code === undefined || code === null ? "" : code).trim(); var s = String(section === undefined || section === null ? "" : section).trim(); if (!c || !s) throw new Error("Give the code and the section, e.g. =EJI_LEGAL_SECTION(\"IPC\", 420)"); var r = ejiLegal_("/sections/lookup", { code: c, section: s }).data; var m = r.matches || []; if (!m.length) throw new Error("No match in the table"); var f = String(field === undefined || field === null || field === "" ? "" : field).trim(); if (f.toLowerCase() === "all") { return ejiLegalTable_(m, [["oldSection", "Old"], ["oldTitle", "Old title"], ["status", "Status"], ["newSection", "New"], ["newSubSection", "Sub"], ["newTitle", "New title"]]); } var first = m[0]; var isOld = /^(ipc|crpc|iea)$/i.test(c); var want = f || (isOld ? "newSection" : "oldSection"); if (!(want in first)) throw new Error("There is no field '" + want + "'. Fields: " + Object.keys(first).join(", ")); return ejiLegalCell_(first[want]); } /** Sections whose title has your words. =EJI_LEGAL_SECTION_SEARCH("theft") * @param {string} query words in the section title * @param {number} [limit] how many, up to 100 (default 30) * @customfunction */ function EJI_LEGAL_SECTION_SEARCH(query, limit) { var r = ejiLegal_("/sections/search", { q: query, limit: Math.min(Math.max(Math.floor(Number(limit) || 30), 1), 100) }).data; var rows = Array.isArray(r) ? r : (r.matches || []); return ejiLegalTable_(rows, [["code", "Mapping"], ["oldSection", "Old"], ["oldTitle", "Old title"], ["status", "Status"], ["newSection", "New"], ["newTitle", "New title"]]); } // ---------- Acts ---------- /** Acts whose text has your words, with the matching passage. =EJI_LEGAL_ACTS("dowry death") * @param {string} query words inside the Acts, e.g. "dowry death" * @param {number} [limit] how many, up to 50 (default 10) * @customfunction */ function EJI_LEGAL_ACTS(query, limit) { var r = ejiLegal_("/acts/search", { q: query, limit: Math.min(Math.max(Math.floor(Number(limit) || 10), 1), 50) }).data; return ejiLegalTable_(r, [["title", "Act"], ["year", "Year"], ["passage", "Passage"], ["id", "Id"]]); } // ---------- judgments ---------- /** Judgments (metadata) with your words in the title or judge. =EJI_LEGAL_JUDGMENTS("bihar", "sc", 2023) * @param {string} query words in the parties or judge * @param {string} [court] sc for the Supreme Court, hc for High Courts (blank for both) * @param {number} [year] decision year * @param {number} [limit] how many, up to 100 (default 25) * @customfunction */ function EJI_LEGAL_JUDGMENTS(query, court, year, limit) { var r = ejiLegal_("/judgments", { q: query, source: court, year: year, limit: Math.min(Math.max(Math.floor(Number(limit) || 25), 1), 100) }).data; return ejiLegalTable_(r, [["id", "Id"], ["title", "Title"], ["court", "Court"], ["decisionDate", "Decided"], ["outcome", "Outcome"], ["citation", "Citation"]]); } /** Words inside judgment texts we hold, with the matching passage. =EJI_LEGAL_JUDGMENT_SEARCH("specific performance") * @param {string} query words inside the judgments * @param {number} [limit] how many, up to 50 (default 10) * @customfunction */ function EJI_LEGAL_JUDGMENT_SEARCH(query, limit) { var r = ejiLegal_("/judgments/text/search", { q: query, limit: Math.min(Math.max(Math.floor(Number(limit) || 10), 1), 50) }).data; return ejiLegalTable_(r, [["id", "Id"], ["title", "Title"], ["decisionDate", "Decided"], ["passage", "Passage"]]); } /** The text of one judgment (a cell holds at most 50,000 characters, so use the start to read on). =EJI_LEGAL_JUDGMENT_TEXT("sc:2023INSC1043") * @param {string} id the judgment id from EJI_LEGAL_JUDGMENTS * @param {number} [start] character to start from (default 0) * @customfunction */ function EJI_LEGAL_JUDGMENT_TEXT(id, start) { var i = String(id === undefined || id === null ? "" : id).trim(); if (!/^(sc|hc):[A-Za-z0-9_.:-]+$/.test(i)) throw new Error("Give a judgment id such as sc:2023INSC1043"); var r = ejiLegal_("/judgments/" + i + "/text", { start: Math.max(Math.floor(Number(start) || 0), 0), maxChars: 45000 }).data; return r.text; } /** What a citation or CNR number is, and the judgment we hold for it. =EJI_LEGAL_CITATION("2023 INSC 600") * @param {string} citation e.g. "2023 INSC 600", "(2020) 5 SCC 1", "AIR 1973 SC 1461" or a CNR * @param {string} [field] one field, e.g. type, normalised, judgmentId * @customfunction */ function EJI_LEGAL_CITATION(citation, field) { var r = ejiLegal_("/citations/parse", { q: citation }).data; return ejiLegalPick_(r, field); } // ---------- courts and Parliament ---------- /** District and taluka court pendency (NJDG). With a field you get one number. =EJI_LEGAL_PENDENCY("total") * @param {string} [field] total, civil, criminal, filedLastMonth, disposedLastMonth, filedByWomen, filedBySeniorCitizens, day * @customfunction */ function EJI_LEGAL_PENDENCY(field) { return ejiLegalPick_(ejiLegal_("/pendency", {}).data, field); } /** Parliament bills with your words in the name. =EJI_LEGAL_BILLS("data protection") * @param {string} [query] words in the bill name * @param {string} [status] e.g. Pending, Passed * @param {number} [limit] how many, up to 200 (default 25) * @customfunction */ function EJI_LEGAL_BILLS(query, status, limit) { var r = ejiLegal_("/bills", { q: query, status: status, limit: Math.min(Math.max(Math.floor(Number(limit) || 25), 1), 200) }).data; return ejiLegalTable_(r, [["name", "Bill"], ["year", "Year"], ["house", "House"], ["status", "Status"], ["introduced", "Introduced"]]); } // ---------- calculators ---------- /** Last day to file a claim. =EJI_LEGAL_LIMITATION("money-lent", DATE(2024,1,15)). Without arguments it lists the kinds. * @param {string} [kind] e.g. money-lent, goods-sold, breach-of-contract, appeal-high-court * @param {Date|string} [accrual] the date the right to sue arose * @param {string} [field] lastDay (default), article, period, startsWhen; "all" gives every field * @customfunction */ function EJI_LEGAL_LIMITATION(kind, accrual, field) { var k = String(kind === undefined || kind === null ? "" : kind).trim(); if (!k) { var list = ejiLegal_("/calc/limitation", {}).data; return ejiLegalTable_(list, [["kind", "Kind"], ["article", "Article"], ["period", "Period"], ["startsWhen", "Starts when"]]); } var r = ejiLegal_("/calc/limitation", { kind: k, accrual: ejiLegalDate_(accrual, "accrual") }).data; var f = String(field === undefined || field === null ? "" : field).trim(); if (f.toLowerCase() === "all") return ejiLegalPick_(r, ""); return ejiLegalPick_(r, f || "lastDay"); } /** Dates for a bounced cheque (Negotiable Instruments Act s.138). =EJI_LEGAL_CHEQUE_BOUNCE(A2, B2, "demandNoticeWithin") * @param {Date|string} chequeDate date on the cheque * @param {Date|string} returned date the bank returned it * @param {string} [field] presentWithin, demandNoticeWithin, paymentDueBy, noticeInTime...; blank lists all * @param {Date|string} [noticeSent] date the demand notice was sent * @param {Date|string} [noticeReceived] date the drawer received it * @customfunction */ function EJI_LEGAL_CHEQUE_BOUNCE(chequeDate, returned, field, noticeSent, noticeReceived) { var p = { cheque_date: ejiLegalDate_(chequeDate, "chequeDate"), returned: ejiLegalDate_(returned, "returned") }; if (noticeSent) p.notice_sent = ejiLegalDate_(noticeSent, "noticeSent"); if (noticeReceived) p.notice_received = ejiLegalDate_(noticeReceived, "noticeReceived"); return ejiLegalPick_(ejiLegal_("/calc/cheque-bounce", p).data, field); } /** Simple interest (or yearly compounding) between two dates. =EJI_LEGAL_INTEREST(100000, 12, DATE(2024,1,1), DATE(2025,1,1)) * @param {number} principal the sum * @param {number} ratePercentPerYear e.g. 12 * @param {Date|string} start first day * @param {Date|string} end last day * @param {boolean} [compound] true for yearly compounding * @param {string} [field] interest (default), total, days; "all" gives every field * @customfunction */ function EJI_LEGAL_INTEREST(principal, ratePercentPerYear, start, end, compound, field) { var r = ejiLegal_("/calc/interest", { principal: principal, rate: ratePercentPerYear, start: ejiLegalDate_(start, "start"), end: ejiLegalDate_(end, "end"), compound: compound ? "true" : "false" }).data; var f = String(field === undefined || field === null ? "" : field).trim(); if (f.toLowerCase() === "all") return ejiLegalPick_(r, ""); return ejiLegalPick_(r, f || "interest"); } // ---------- menu ---------- function ejiLegalSetKey() { var ui = SpreadsheetApp.getUi(); var r = ui.prompt("EJI Legal", "Paste your Legal key (it starts leg_). Ask for one at legal.ejiapi.com/get-key", ui.ButtonSet.OK_CANCEL); if (r.getSelectedButton() !== ui.Button.OK) return; var key = r.getResponseText().trim(); if (!/^leg_[A-Za-z0-9_-]{10,}$/.test(key)) { ui.alert("That does not look like a Legal key (leg_...)."); return; } PropertiesService.getScriptProperties().setProperty("EJI_LEGAL_KEY", key); ejiLegalBump_(); ui.alert("Key saved. Try =EJI_LEGAL_SECTION(\"IPC\", 420) in any cell."); } function ejiLegalCheck() { var ui = SpreadsheetApp.getUi(); try { var d = ejiLegal_("/pendency", {}).data; ui.alert("All set. The key works. Pending in district courts: " + Number(d.total).toLocaleString("en-IN") + " cases."); } catch (e) { ui.alert("Not working yet: " + e.message); } } // ---------- family registration (the core's EJI API menu shows these under Legal) ---------- function ejiFamily_legal_() { return { id: "legal", name: "Legal", bump: function () { ejiLegalBump_(); }, items: [["Set API key", "ejiLegalSetKey"], ["Check setup", "ejiLegalCheck"]], fields: [] }; } function ejiLegalBump_() { var props = PropertiesService.getScriptProperties(); props.setProperty("EJI_LEGAL_CACHE_V", String(Number(props.getProperty("EJI_LEGAL_CACHE_V") || "0") + 1)); }