Create a Subscription and Invoice Management System for Newspapers in Google Sheets
Hello, Google Sheets enthusiasts! Are you running a small newspaper agency and looking to automate subscriber management, invoice generation, and payment tracking? This Google Apps Script solution creates a powerful subscription and invoice management system right in your Google Sheet. It includes features like adding subscribers, generating invoices with a dropdown interface, tracking payments, exporting PDFs, creating summary reports, and sending invoices via WhatsApp. Below, you’ll find the main script, an HTML form, a WhatsApp integration script, and an invoice generation script, each with copy buttons for easy setup.
What This System Does
This system offers a robust set of tools for managing newspaper subscriptions:
- A custom HTML form to add or update subscriber details.
- A Subscribers sheet to store customer data (contact number, name, address, subscription type, last payment date).
- An Invoices sheet to log all invoices with details like Invoice ID, contact number, items, amount, date, status, and PDF URL.
- An Items sheet to store predefined items and their prices (used in invoice generation).
- A Payments sheet to record payment details (contact, subscription type, date, amount, notes).
- A dropdown-based invoice creation feature to select items and quantities.
- An export to PDF feature that saves invoices to Google Drive and emails them.
- A batch PDF generation feature for all pending invoices.
- A summary report feature to calculate total invoiced and paid amounts.
- A backup feature to save the spreadsheet to Google Drive.
- A WhatsApp integration to send formatted invoice messages with a clickable link.
- A custom menu in Google Sheets to access all features.
Step-by-Step Setup Instructions
- Create a New Google Sheet:
- Open Google Sheets and create a new spreadsheet (e.g., "Newspaper Subscription System").
- Save it to your Google Drive.
- Open the Apps Script Editor:
- In your Google Sheet, go to Extensions > Apps Script.
- Add the Main Google Apps Script Code:
- In the Apps Script editor, clear any code in
Code.gs
. - Copy the code from Code Block 1 and paste it into
Code.gs
. - Save the file (Ctrl + S) and name the project (e.g., "Subscription System").
- In the Apps Script editor, clear any code in
- Add the HTML Form:
- In the Apps Script editor, go to File > New > HTML file.
- Name it
SubscriberForm
(exact name required). - Copy the code from Code Block 2 and paste it into
SubscriberForm.html
. - Save the file.
- Add the WhatsApp Integration Code:
- In the Apps Script editor, go to File > New > Script file.
- Name it
WhatsApp.gs
(exact name recommended). - Copy the code from Code Block 3 and paste it into
WhatsApp.gs
. - Save the file.
- Add the Invoice Generation Code:
- In the Apps Script editor, go to File > New > Script file.
- Name it
InvoiceGeneration.gs
(exact name recommended). - Copy the code from Code Block 4 and paste it into
InvoiceGeneration.gs
. - Save the file.
- Note: The invoice generation code relies on functions in
Code.gs
(initializeSheets
,validateContact
,getSubscriberByContact
,generateInvoicePDFDirect
, andpopulateInvoiceSheet
). EnsureCode.gs
is set up first.
- Set Up the Items Sheet:
- In your Google Sheet, create an
Items
sheet or let the script create it automatically. - Add item names in column C (C4:C6) and their prices in column D (D4:D6). For example:
- C4: Daily Newspaper, D4: 5.00
- C5: Weekly Magazine, D5: 20.00
- C6: Monthly Subscription, D6: 100.00
- In your Google Sheet, create an
- Configure the Backup Folder:
- In the
backupSheet
function inCode.gs
, replaceYOUR_FOLDER_ID
with the ID of a Google Drive folder where backups will be stored. To find the folder ID, open the folder in Google Drive, and copy the ID from the URL (e.g.,https://drive.google.com/drive/folders/[FOLDER_ID]
).
- In the
- Set Up Permissions:
- Click Run in the Apps Script editor to execute the
onOpen
function. - Authorize the script by reviewing and granting permissions (Sheets, Drive, Gmail, Document).
- A custom menu (Subscription Management) will appear in your Google Sheet.
- Click Run in the Apps Script editor to execute the
- Set Up Sample Data (Optional):
- Manually add sample subscribers to the
Subscribers
sheet (e.g., contact number, name, address, subscription type). - Add sample items to the
Items
sheet as described above.
- Manually add sample subscribers to the
How to Use the Subscription System
- Add or Update Subscribers:
- Via Form: Go to Subscription Management > Add/Update Subscriber (Form) to open the HTML form. Enter a 10-digit contact number, name, address, and subscription type. If the contact exists, the form auto-fills the name and address.
- Via Prompt: Select Add/Update Subscriber (Prompt) and enter details through dialog boxes.
- Create an Invoice:
- Go to Subscription Management > Create Invoice (Dropdown).
- Enter a 10-digit contact number. If the subscriber exists, their name auto-fills; otherwise, enter a name.
- Select items and quantities from the dropdown (populated from the
Items
sheet, C4:C6). - Choose an invoice date (defaults to today).
- The invoice is logged in the
Invoices
sheet, a PDF is generated, and it’s emailed to your Google account. - An
Invoice
sheet is created/updated with the invoice details for WhatsApp integration.
- Send Invoice via WhatsApp:
- After creating an invoice, go to the
Invoice
sheet. - Run the
WhatsAppWordsWithVariedTotalRowFixed
function from the Apps Script editor or add it to the custom menu (see Tips and Troubleshooting). - A WhatsApp hyperlink is generated in cell D1 of the
Invoice
sheet. Click it to open WhatsApp with a pre-formatted invoice message.
- After creating an invoice, go to the
- Check Subscriptions:
- Select Check Subscriptions, enter a contact number, and view the subscriber’s details (name, subscription types, last payment dates).
- Record a Payment:
- Go to Record Payment, enter the contact number, subscription type, amount, date, and optional notes.
- The payment is logged in the
Payments
sheet, and theSubscribers
sheet updates the last payment date.
- Export Invoice PDF:
- Select Export Invoice PDF, enter an Invoice ID (e.g., INV001), and regenerate the PDF for that invoice.
- The PDF is saved to the
AppleInvoiceFolder
in Google Drive and emailed to your account.
- Generate All Pending Invoice PDFs:
- Choose Generate All Pending Invoice PDFs to create PDFs for all invoices marked as "Pending" in the
Invoices
sheet. - PDFs are saved to Google Drive and emailed.
- Choose Generate All Pending Invoice PDFs to create PDFs for all invoices marked as "Pending" in the
- Create a Summary Report:
- Select Create Summary Report to generate a
Summary
sheet with total invoiced and paid amounts.
- Select Create Summary Report to generate a
- Backup the Sheet:
- Choose Backup Sheet to save a copy of the spreadsheet to the specified Google Drive folder.
Code Blocks to Copy
Below are the four code blocks. Click the Copy button for each to copy the code to your clipboard, then paste it into the appropriate file in your Apps Script editor.
No comments:
Post a Comment