-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFix1099_Protection_STRICT.gs
More file actions
141 lines (127 loc) · 4.59 KB
/
Copy pathFix1099_Protection_STRICT.gs
File metadata and controls
141 lines (127 loc) · 4.59 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
/**
* Fix1099 Contractor Tracker - STRICT Formula Protection
*
* 這個版本會完全鎖住公式欄位,用戶無法編輯
* Users CANNOT edit formula columns at all
*
* HOW TO USE:
* 1. Open your Google Sheet
* 2. Extensions → Apps Script
* 3. Delete all existing code
* 4. Paste this entire script
* 5. Click Save (disk icon)
* 6. Run "setupProtection" function (click Run button)
* 7. Authorize when prompted
* 8. Done! Formulas are now locked.
*/
/**
* Main function: Apply STRICT protection to formula columns
* This will LOCK columns H, J, K completely
* Only the sheet owner can edit them
*/
function setupProtection() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('Contractor Tracker');
if (!sheet) {
SpreadsheetApp.getUi().alert(
'Error',
'Sheet "Contractor Tracker" not found.\n\nMake sure you are in the correct template.',
SpreadsheetApp.getUi().ButtonSet.OK
);
return;
}
// Remove any existing protections first
const existingProtections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
existingProtections.forEach(protection => {
protection.remove();
});
// Get current user (owner)
const owner = Session.getEffectiveUser().getEmail();
// Protect Column H: 1099 Required? (STRICT - completely locked)
const rangeH = sheet.getRange('H7:H2000');
const protectionH = rangeH.protect().setDescription('🔒 Formula: 1099 Required (Auto-Calculate)');
protectionH.removeEditors(protectionH.getEditors());
protectionH.addEditor(owner);
// Protect Column J: Filing Status (STRICT - completely locked)
const rangeJ = sheet.getRange('J7:J2000');
const protectionJ = rangeJ.protect().setDescription('🔒 Formula: Filing Status (Auto-Calculate)');
protectionJ.removeEditors(protectionJ.getEditors());
protectionJ.addEditor(owner);
// Protect Column K: Risk Level (STRICT - completely locked)
const rangeK = sheet.getRange('K7:K2000');
const protectionK = rangeK.protect().setDescription('🔒 Formula: Risk Level (Auto-Calculate)');
protectionK.removeEditors(protectionK.getEditors());
protectionK.addEditor(owner);
// Success message
SpreadsheetApp.getUi().alert(
'✅ Protection Applied Successfully',
'Formula columns are now LOCKED:\n\n' +
'🔒 Column H (1099 Required?)\n' +
'🔒 Column J (Filing Status)\n' +
'🔒 Column K (Risk Level)\n\n' +
'Users CANNOT edit these columns.\n' +
'Only you (the owner) can edit them.\n\n' +
'You can edit columns A-G and I normally.',
SpreadsheetApp.getUi().ButtonSet.OK
);
}
/**
* Creates custom menu when spreadsheet opens
* NO REMOVE OPTION - customers cannot disable protection
*/
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Fix1099')
.addItem('📖 Help & Instructions', 'showHelp')
.addToUi();
}
/**
* Show help dialog
*/
function showHelp() {
const helpText =
'Fix1099 Contractor Tracker - Help\n\n' +
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n' +
'🔒 PROTECTED COLUMNS (Locked):\n' +
'• Column H: 1099 Required?\n' +
'• Column J: Filing Status\n' +
'• Column K: Risk Level\n\n' +
'These columns are LOCKED and calculate automatically.\n' +
'You cannot edit them.\n\n' +
'✏️ YOU CAN EDIT:\n' +
'• Column A: Contractor Name\n' +
'• Column B: Email\n' +
'• Column C: Phone\n' +
'• Column D: TIN/W-9 Status\n' +
'• Column E: Contract Status\n' +
'• Column F: Service Type\n' +
'• Column G: Total Paid 2026\n' +
'• Column I: W-9 Received?\n\n' +
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n' +
'📧 Support:\n' +
'Email: ai.rapid2006@gmail.com\n' +
'Phone: (818) 925-5239\n\n' +
'Need help? Contact us anytime!';
SpreadsheetApp.getUi().alert(
'Fix1099 - Help & Instructions',
helpText,
SpreadsheetApp.getUi().ButtonSet.OK
);
}
/**
* OWNER ONLY: Remove all protections
* This function is NOT in the menu
* Can only be run manually from script editor by the owner
*/
function removeAllProtections() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Contractor Tracker');
const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE);
protections.forEach(protection => {
protection.remove();
});
SpreadsheetApp.getUi().alert(
'Protection Removed',
'All formula protections have been removed.\n\nYou can now edit all columns.',
SpreadsheetApp.getUi().ButtonSet.OK
);
}