Emails customers a polite reminder with the invoice attached at 3, 14 and 30 days overdue, and sends you a morning summary of what's owed.

UsesGmailQuickBooks Online

Chase overdue QuickBooks invoices

Unpaid invoices slip past their due date, and chasing them by hand is awkward and easy to forget, so cash comes in late. Every weekday morning this reads the overdue invoices in QuickBooks and emails each customer a polite reminder from your Gmail, with the invoice PDF attached: a friendly note at 3 days overdue, a follow-up at 14 and a firmer one at 30. A customer with several overdue invoices gets one email covering them. You get one short summary that leads with the number that matters, such as 'Chased 4 invoices · $12,480.00 overdue across 9 invoices', then lists what went out and everything still owed.

Each invoice gets each reminder once. What was sent is recorded, so a rerun never repeats an email, and a reminder that falls on a weekend goes out on Monday. Until you switch sending on, every run is a preview: nothing reaches your customers, and you get each kind of reminder written out in full to check. An invoice with no email address in QuickBooks is listed for you rather than skipped, totals in different currencies are never added together, and if QuickBooks can't be read or a reminder can't be sent, the run says so and is marked failed instead of passing for a quiet morning.

You need QuickBooks Online and Gmail connected, and the email address the summary should go to. Switch on sending to customers once the preview looks right.

Run every weekday at 09:00.Run every weekday at 09:00.
Set summaryEmail to blank.Set summaryEmail to blank.
Set sendToCustomers to false.Set sendToCustomers to false.
Set signOffName to blank.Set signOffName to blank.
Set firstReminderDays to 3.Set firstReminderDays to 3.
Set secondReminderDays to 14.Set secondReminderDays to 14.
Set thirdReminderDays to 30.Set thirdReminderDays to 30.
Set liveMode to false.Set liveMode to false.
If sendToCustomers is yesIf sendToCustomers is yes
Yes
Change liveMode to true.Change liveMode to true.
Else if @sendToCustomers isn't no
Stop and report a problem: Set the 'sendToCustomers' step to true to email reminders to your customers, or to false to get a preview of them in your own inbox first. Nothing was sent.Stop and report a problem: Set the 'sendToCustomers' step to true to email reminders to your customers, or to false to get a preview of them in your own inbox first. Nothing was sent.
Otherwise
No steps
Get today's date and save it as today.Get today's date and save it as today.
Set reminderHistory to an empty list.Set reminderHistory to an empty list.
If a step below fails, save the error as historyErrorIf a step below fails, save the error as historyError
Try
Get the stored value 'invoice_reminder_history'. Save it as storedHistory.Get the stored value 'invoice_reminder_history'. Save it as storedHistory.
If storedHistory.found is yesIf storedHistory.found is yes
Yes
Change reminderHistory to storedHistory.value.Change reminderHistory to storedHistory.value.
No
No steps
On error
Stop and report a problem: Couldn't read the record of reminders already sent, so nothing was sent this morning: that record is what stops a customer being chased twice. Lodol said: historyError.message.Stop and report a problem: Couldn't read the record of reminders already sent, so nothing was sent this morning: that record is what stops a customer being chased twice. Lodol said: historyError.message.
Set businessName to blank.Set businessName to blank.
Set overdueInvoices to an empty list.Set overdueInvoices to an empty list.
Set nextPage to 1.Set nextPage to 1.
Set morePages to true.Set morePages to true.
If a step below fails, save the error as quickbooksErrorIf a step below fails, save the error as quickbooksError
Try
If signOffName is blankIf signOffName is blank
Yes
QuickBooks OnlineQuickBooks OnlineGet QuickBooks company info. Save it as company.Get QuickBooks company info. Save it as company.
Trim company.CompanyInfo.CompanyName and save it as businessName.Trim company.CompanyInfo.CompanyName and save it as businessName.
No
Trim signOffName and save it as businessName.Trim signOffName and save it as businessName.
While morePages is yes:While morePages is yes:
QuickBooks OnlineQuickBooks Online List up to 1000 QuickBooks invoices. Save it as overduePage. List up to 1000 QuickBooks invoices. Save it as overduePage.
Combine overdueInvoices and overduePage.QueryResponse.Invoice into one list and save it as overdueInvoices. Combine overdueInvoices and overduePage.QueryResponse.Invoice into one list and save it as overdueInvoices.
Change morePages to overduePage.has_more. Change morePages to overduePage.has_more.
Change nextPage to overduePage.next_start_position. Change nextPage to overduePage.next_start_position.
On error
Stop and report a problem: QuickBooks couldn't be read, so no reminders were sent this morning. Check that QuickBooks is still connected in Lodol. QuickBooks said: quickbooksError.message.Stop and report a problem: QuickBooks couldn't be read, so no reminders were sent this morning. Check that QuickBooks is still connected in Lodol. QuickBooks said: quickbooksError.message.
If businessName is blankIf businessName is blank
Yes
Stop and report a problem: Your QuickBooks company has no name to sign the reminders with. Put the name to sign off with in the 'signOffName' step at the top of this workflow, then run it again. Nothing was sent.Stop and report a problem: Your QuickBooks company has no name to sign the reminders with. Put the name to sign off with in the 'signOffName' step at the top of this workflow, then run it again. Nothing was sent.
No
No steps
Keep only Id, DocNumber, TxnDate, DueDate, Balance, TotalAmt, CurrencyRef, CustomerRef, and BillEmail in overdueInvoices and save it as overdueInvoices.Keep only Id, DocNumber, TxnDate, DueDate, Balance, TotalAmt, CurrencyRef, CustomerRef, and BillEmail in overdueInvoices and save it as overdueInvoices.
Sort overdueInvoices by DueDate, smallest first and save it as overdueInvoices.Sort overdueInvoices by DueDate, smallest first and save it as overdueInvoices.
Match overdueInvoices with reminderHistory by “Id” and “invoice_id” and save it as overdueInvoices.Match overdueInvoices with reminderHistory by “Id” and “invoice_id” and save it as overdueInvoices.
Set overdueNow to an empty list.Set overdueNow to an empty list.
Set remindersDue to an empty list.Set remindersDue to an empty list.
Set stillOverdueLines to an empty list.Set stillOverdueLines to an empty list.
Set updatedHistory to an empty list.Set updatedHistory to an empty list.
For each invoice in overdueInvoices:For each invoice in overdueInvoices:
Count the days from invoice.DueDate to today and save it as daysOverdue.Count the days from invoice.DueDate to today and save it as daysOverdue.
If daysOverdue is less than 1 or invoice.Balance is less than or equal to 0If daysOverdue is less than 1 or invoice.Balance is less than or equal to 0
Yes
Skip to the next item.Skip to the next item.
No
No steps
Add a record of currency and balance to the end of overdueNow and save it as overdueNow.Add a record of currency and balance to the end of overdueNow and save it as overdueNow.
Set stageReached to 0.Set stageReached to 0.
If daysOverdue is greater than or equal to thirdReminderDaysIf daysOverdue is greater than or equal to thirdReminderDays
Yes
Change stageReached to 3.Change stageReached to 3.
Else if @daysOverdue is greater than or equal to @secondRem…
Change stageReached to 2.Change stageReached to 2.
Else if @daysOverdue is greater than or equal to @firstRemi…
Change stageReached to 1.Change stageReached to 1.
Otherwise
No steps
Set stageSent to 0.Set stageSent to 0.
Set stageFlagged to 0.Set stageFlagged to 0.
If invoice.due_date is invoice.DueDateIf invoice.due_date is invoice.DueDate
Yes
Change stageSent to invoice.reminder_stage.Change stageSent to invoice.reminder_stage.
Change stageFlagged to invoice.flagged_stage.Change stageFlagged to invoice.flagged_stage.
Add a record of invoice id, due date, reminder stage, and flagged stage to the end of updatedHistory and save it as updatedHistory.Add a record of invoice id, due date, reminder stage, and flagged stage to the end of updatedHistory and save it as updatedHistory.
No
No steps
Set numberStyle to “thousands”.Set numberStyle to “thousands”.
If the length of invoice.CurrencyRef.value is 3If the length of invoice.CurrencyRef.value is 3
Yes
Change numberStyle to “currency”.Change numberStyle to “currency”.
No
No steps
Format invoice.Balance as a number and save it as balanceText.Format invoice.Balance as a number and save it as balanceText.
Set amountText to balanceText.Set amountText to balanceText.
If invoice.Balance is less than invoice.TotalAmtIf invoice.Balance is less than invoice.TotalAmt
Yes
Format invoice.TotalAmt as a number and save it as totalText.Format invoice.TotalAmt as a number and save it as totalText.
Build the text “@balanceText still to pay of @totalText” and save it as amountText.Build the text “@balanceText still to pay of @totalText” and save it as amountText.
No
No steps
Make invoice.DueDate readable as “November 2, 2026” and save it as dueDateText.Make invoice.DueDate readable as “November 2, 2026” and save it as dueDateText.
Set invoiceName to invoice.DocNumber.Set invoiceName to invoice.DocNumber.
If invoice.DocNumber is emptyIf invoice.DocNumber is empty
Yes
Make invoice.TxnDate readable as “November 2, 2026” and save it as issuedText.Make invoice.TxnDate readable as “November 2, 2026” and save it as issuedText.
Change invoiceName to “dated issuedText”.Change invoiceName to “dated issuedText”.
No
No steps
Set daysText to “@daysOverdue days overdue”.Set daysText to “@daysOverdue days overdue”.
If daysOverdue is 1If daysOverdue is 1
Yes
Change daysText to “1 day overdue”.Change daysText to “1 day overdue”.
No
No steps
Build the text “• @invoice.CustomerRef.name, invoice @invoiceName: @amountText, @daysText” and save it as summaryLine.Build the text “• @invoice.CustomerRef.name, invoice @invoiceName: @amountText, @daysText” and save it as summaryLine.
If stageReached is greater than stageSentIf stageReached is greater than stageSent
Yes
Merge a record of stage reached, stage sent, stage flagged, and 5 more into invoice and save it as dueForReminder.Merge a record of stage reached, stage sent, stage flagged, and 5 more into invoice and save it as dueForReminder.
Add dueForReminder to the end of remindersDue and save it as remindersDue.Add dueForReminder to the end of remindersDue and save it as remindersDue.
No
Set progress to “first reminder goes out at firstReminderDays days overdue”.Set progress to “first reminder goes out at firstReminderDays days overdue”.
If stageSent is 3If stageSent is 3
Yes
Change progress to “third and last reminder sent”.Change progress to “third and last reminder sent”.
Else if @stageSent is 2
Build the text “second reminder sent; the third goes out at @thirdReminderDays days overdue” and save it as progress.Build the text “second reminder sent; the third goes out at @thirdReminderDays days overdue” and save it as progress.
Else if @stageSent is 1
Build the text “first reminder sent; the second goes out at @secondReminderDays days overdue” and save it as progress.Build the text “first reminder sent; the second goes out at @secondReminderDays days overdue” and save it as progress.
Otherwise
No steps
Add summaryLine (progress) to the end of stillOverdueLines and save it as stillOverdueLines.Add summaryLine (progress) to the end of stillOverdueLines and save it as stillOverdueLines.
Group the items in remindersDue by “CustomerRef.value” and save it as customersToChase.Group the items in remindersDue by “CustomerRef.value” and save it as customersToChase.
Set chasedLines to an empty list.Set chasedLines to an empty list.
Set chasedCount to 0.Set chasedCount to 0.
Set noEmailLines to an empty list.Set noEmailLines to an empty list.
Set problems to an empty list.Set problems to an empty list.
Set examples to an empty list.Set examples to an empty list.
Set sampledStages to an empty list.Set sampledStages to an empty list.
Set sampleAttachments to an empty list.Set sampleAttachments to an empty list.
Set sentVerb to “ would go to ”.Set sentVerb to “ would go to ”.
If liveMode is yesIf liveMode is yes
Yes
Change sentVerb to “ sent to ”.Change sentVerb to “ sent to ”.
No
No steps
For each customer in customersToChase:For each customer in customersToChase:
Get the first item of customer.items and save it as firstInvoice.Get the first item of customer.items and save it as firstInvoice.
Get “BillEmail.Address” from every item in customer.items and save it as billEmails.Get “BillEmail.Address” from every item in customer.items and save it as billEmails.
Remove duplicates and empty items from billEmails and save it as knownEmails.Remove duplicates and empty items from billEmails and save it as knownEmails.
Join knownEmails with “, ” and save it as sendTo.Join knownEmails with “, ” and save it as sendTo.
If customer.key is blankIf customer.key is blank
Yes
Change sendTo to blank.Change sendTo to blank.
No
No steps
If sendTo is blank and customer.key isn't blankIf sendTo is blank and customer.key isn't blank
Yes
If a step below fails, save the error as lookupErrorIf a step below fails, save the error as lookupError
Try
QuickBooks OnlineQuickBooks OnlineGet QuickBooks customer customer.key. Save it as customerRecord.Get QuickBooks customer customer.key. Save it as customerRecord.
Trim customerRecord.Customer.PrimaryEmailAddr.Address and save it as sendTo.Trim customerRecord.Customer.PrimaryEmailAddr.Address and save it as sendTo.
On error
Add • firstInvoice.CustomerRef.name: couldn't look up their email address in QuickBooks (lookupError.message), so no reminder went out. It will be tried again on the next run. to the end of problems and save it as problems.Add • firstInvoice.CustomerRef.name: couldn't look up their email address in QuickBooks (lookupError.message), so no reminder went out. It will be tried again on the next run. to the end of problems and save it as problems.
Skip to the next item.Skip to the next item.
No
No steps
If sendTo is blankIf sendTo is blank
Yes
For each unreachable in customer.items:For each unreachable in customer.items:
If unreachable.stage_reached is greater than unreachable.stage_flagged If unreachable.stage_reached is greater than unreachable.stage_flagged
Yes
Add unreachable.summary_line: there's no email address on the invoice or on the customer in QuickBooks, so it can't be chased. Add one and its reminder goes out on the next run. to the end of noEmailLines and save it as noEmailLines.Add unreachable.summary_line: there's no email address on the invoice or on the customer in QuickBooks, so it can't be chased. Add one and its reminder goes out on the next run. to the end of noEmailLines and save it as noEmailLines.
Keep each item in updatedHistory where item.invoice_id is not unreachable.Id and save it as historyWithoutUnreachable.Keep each item in updatedHistory where item.invoice_id is not unreachable.Id and save it as historyWithoutUnreachable.
Add a record of invoice id, due date, reminder stage, and flagged stage to the end of historyWithoutUnreachable and save it as updatedHistory.Add a record of invoice id, due date, reminder stage, and flagged stage to the end of historyWithoutUnreachable and save it as updatedHistory.
No
Add unreachable.summary_line (no email address in QuickBooks, so not chased) to the end of stillOverdueLines and save it as stillOverdueLines.Add unreachable.summary_line (no email address in QuickBooks, so not chased) to the end of stillOverdueLines and save it as stillOverdueLines.
Skip to the next item.Skip to the next item.
No
No steps
Get “stage_reached” from every item in customer.items and save it as stagesReached.Get “stage_reached” from every item in customer.items and save it as stagesReached.
Find the largest number in stagesReached and save it as reminderStage.Find the largest number in stagesReached and save it as reminderStage.
Set writeEmail to true.Set writeEmail to true.
If liveMode is no and sampledStages contains reminderStageIf liveMode is no and sampledStages contains reminderStage
Yes
Change writeEmail to false.Change writeEmail to false.
No
No steps
If writeEmail is yesIf writeEmail is yes
Yes
Set invoicePdfs to an empty list.Set invoicePdfs to an empty list.
Set pdfProblem to blank.Set pdfProblem to blank.
For each pdfInvoice in customer.items:For each pdfInvoice in customer.items:
If a step below fails, save the error as pdfError If a step below fails, save the error as pdfError
Try
QuickBooks OnlineQuickBooks OnlineGet the PDF of QuickBooks invoice pdfInvoice. Save it as invoicePdf.Get the PDF of QuickBooks invoice pdfInvoice. Save it as invoicePdf.
Add invoicePdf.document_ref to the end of invoicePdfs and save it as invoicePdfs.Add invoicePdf.document_ref to the end of invoicePdfs and save it as invoicePdfs.
On error
Build the text “@pdfInvoice.summary_line: couldn't get the invoice PDF from QuickBooks (@pdfError.message), so no reminder went out. It will be tried again on the next run.” and save it as pdfProblem.Build the text “@pdfInvoice.summary_line: couldn't get the invoice PDF from QuickBooks (@pdfError.message), so no reminder went out. It will be tried again on the next run.” and save it as pdfProblem.
Stop repeating.Stop repeating.
If pdfProblem isn't blankIf pdfProblem isn't blank
Yes
Add pdfProblem to the end of problems and save it as problems.Add pdfProblem to the end of problems and save it as problems.
Skip to the next item.Skip to the next item.
No
No steps
Set invoiceRef to “invoice firstInvoice.invoice_name”.Set invoiceRef to “invoice firstInvoice.invoice_name”.
Set thisInvoice to “this invoice”.Set thisInvoice to “this invoice”.
Set copyNote to “A copy of the invoice is attached”.Set copyNote to “A copy of the invoice is attached”.
If customer.count is greater than 1If customer.count is greater than 1
Yes
Change invoiceRef to “@customer.count invoices”.Change invoiceRef to “@customer.count invoices”.
Change thisInvoice to “these invoices”.Change thisInvoice to “these invoices”.
Change copyNote to “A copy of each invoice is attached”.Change copyNote to “A copy of each invoice is attached”.
No
No steps
Build the text “Friendly reminder: @invoiceRef from @businessName” and save it as emailSubject.Build the text “Friendly reminder: @invoiceRef from @businessName” and save it as emailSubject.
Build the text “We hope all is well. This is a friendly reminder that payment for @thisInvoice is now past due:” and save it as opening.Build the text “We hope all is well. This is a friendly reminder that payment for @thisInvoice is now past due:” and save it as opening.
Build the text “@copyNote for convenience. If payment is already on its way, thank you, and please disregard this note. If anything looks wrong, just reply to this email and w...” and save it as closing.Build the text “@copyNote for convenience. If payment is already on its way, thank you, and please disregard this note. If anything looks wrong, just reply to this email and w...” and save it as closing.
If reminderStage is 3If reminderStage is 3
Yes
Build the text “Payment overdue: @invoiceRef from @businessName” and save it as emailSubject.Build the text “Payment overdue: @invoiceRef from @businessName” and save it as emailSubject.
Build the text “Payment for @thisInvoice is now well past due, and we haven't yet received it:” and save it as opening.Build the text “Payment for @thisInvoice is now well past due, and we haven't yet received it:” and save it as opening.
Build the text “@copyNote. We'd be grateful if you could arrange payment as soon as possible, or reply to let us know when to expect it. If something is holding it up, please ...” and save it as closing.Build the text “@copyNote. We'd be grateful if you could arrange payment as soon as possible, or reply to let us know when to expect it. If something is holding it up, please ...” and save it as closing.
Else if @reminderStage is 2
Build the text “Following up: @invoiceRef from @businessName” and save it as emailSubject.Build the text “Following up: @invoiceRef from @businessName” and save it as emailSubject.
Build the text “We're following up because our records still don't show payment for @thisInvoice:” and save it as opening.Build the text “We're following up because our records still don't show payment for @thisInvoice:” and save it as opening.
Build the text “@copyNote. Could you let us know when we can expect payment? If you've already paid, thank you, and please let us know so we can update our records. If anythin...” and save it as closing.Build the text “@copyNote. Could you let us know when we can expect payment? If you've already paid, thank you, and please let us know so we can update our records. If anythin...” and save it as closing.
Otherwise
No steps
Set customerLines to an empty list.Set customerLines to an empty list.
For each listedInvoice in customer.items:For each listedInvoice in customer.items:
Add • Invoice listedInvoice.invoice_name: listedInvoice.amount_text, due listedInvoice.due_date_text (listedInvoice.days_text) to the end of customerLines and save it as customerLines. Add • Invoice listedInvoice.invoice_name: listedInvoice.amount_text, due listedInvoice.due_date_text (listedInvoice.days_text) to the end of customerLines and save it as customerLines.
Join customerLines with a new line and save it as invoiceList.Join customerLines with a new line and save it as invoiceList.
Set greetName to firstInvoice.CustomerRef.name.Set greetName to firstInvoice.CustomerRef.name.
If greetName contains “:”If greetName contains “:”
Yes
Get the text before “:” in greetName and save it as greetName.Get the text before “:” in greetName and save it as greetName.
No
No steps
Build the text “Hi @greetName, @opening @invoiceList @closing Kind regards, @businessName” and save it as reminderBody.Build the text “Hi @greetName, @opening @invoiceList @closing Kind regards, @businessName” and save it as reminderBody.
If liveMode is yesIf liveMode is yes
Yes
If a step below fails, save the error as sendErrorIf a step below fails, save the error as sendError
Try
GmailGmailSend an email to sendTo.Send an email to sendTo. Subject: emailSubjectreminderBody
On error
Add • firstInvoice.CustomerRef.name: the reminder for invoiceRef couldn't be sent to sendTo (sendError.message). It will be tried again on the next run. to the end of problems and save it as problems.Add • firstInvoice.CustomerRef.name: the reminder for invoiceRef couldn't be sent to sendTo (sendError.message). It will be tried again on the next run. to the end of problems and save it as problems.
Skip to the next item.Skip to the next item.
For each sentInvoice in customer.items:For each sentInvoice in customer.items:
Keep each item in updatedHistory where item.invoice_id is not sentInvoice.Id and save it as historyWithoutSent. Keep each item in updatedHistory where item.invoice_id is not sentInvoice.Id and save it as historyWithoutSent.
Add a record of invoice id, due date, reminder stage, and flagged stage to the end of historyWithoutSent and save it as updatedHistory. Add a record of invoice id, due date, reminder stage, and flagged stage to the end of historyWithoutSent and save it as updatedHistory.
If a step below fails, save the error as recordErrorIf a step below fails, save the error as recordError
Try
Set the stored value 'invoice_reminder_history' to updatedHistory.Set the stored value 'invoice_reminder_history' to updatedHistory.
On error
Stop and report a problem: The reminder to firstInvoice.CustomerRef.name (invoiceRef) was sent, but Lodol couldn't record it (recordError.message), so the run stopped there rather than send any more. Reminders sent before it are recorded and won't repeat, but the next run has no record of this one, so firstInvoice.CustomerRef.name will get it a second time.Stop and report a problem: The reminder to firstInvoice.CustomerRef.name (invoiceRef) was sent, but Lodol couldn't record it (recordError.message), so the run stopped there rather than send any more. Reminders sent before it are recorded and won't repeat, but the next run has no record of this one, so firstInvoice.CustomerRef.name will get it a second time.
No
Add reminderStage to the end of sampledStages and save it as sampledStages.Add reminderStage to the end of sampledStages and save it as sampledStages.
Combine sampleAttachments and invoicePdfs into one list and save it as sampleAttachments.Combine sampleAttachments and invoicePdfs into one list and save it as sampleAttachments.
Look up reminderStage in a table and save it as sampleName.Look up reminderStage in a table and save it as sampleName.
Add ———Add ——— The sampleName, as firstInvoice.CustomerRef.name would receive it (its invoice is attached to this email) To: sendTo Subject: emailSubject reminderBody to the end of examples and save it as examples.
No
No steps
For each chasedInvoice in customer.items:For each chasedInvoice in customer.items:
Look up chasedInvoice.stage_reached in a table and save it as stageName.Look up chasedInvoice.stage_reached in a table and save it as stageName.
Add chasedInvoice.summary_line, stageName@sentVerb@sendTo to the end of chasedLines and save it as chasedLines.Add chasedInvoice.summary_line, stageName@sentVerb@sendTo to the end of chasedLines and save it as chasedLines.
Add 1 to chasedCount.Add 1 to chasedCount.
If liveMode is yesIf liveMode is yes
Yes
If a step below fails, save the error as tidyErrorIf a step below fails, save the error as tidyError
Try
Set the stored value 'invoice_reminder_history' to updatedHistory.Set the stored value 'invoice_reminder_history' to updatedHistory.
On error
Add • Couldn't update the record of reminders sent (tidyError.message). Nothing will be sent twice, but some notes in this summary may appear again next time. to the end of problems and save it as problems.Add • Couldn't update the record of reminders sent (tidyError.message). Nothing will be sent twice, but some notes in this summary may appear again next time. to the end of problems and save it as problems.
No
No steps
Count the items in overdueNow and save it as overdueCount.Count the items in overdueNow and save it as overdueCount.
If overdueCount is 0If overdueCount is 0
Yes
Finish the run: No overdue invoices in QuickBooks this morning, so there was nothing to chase.Finish the run: No overdue invoices in QuickBooks this morning, so there was nothing to chase.
No
No steps
Group the items in overdueNow by “currency”, with the total “balance” of each and save it as currencyTotals.Group the items in overdueNow by “currency”, with the total “balance” of each and save it as currencyTotals.
Set totalParts to an empty list.Set totalParts to an empty list.
For each currencyGroup in currencyTotals:For each currencyGroup in currencyTotals:
Set totalStyle to “thousands”.Set totalStyle to “thousands”.
If the length of currencyGroup.key is 3If the length of currencyGroup.key is 3
Yes
Change totalStyle to “currency”.Change totalStyle to “currency”.
No
No steps
Format currencyGroup.total as a number and save it as groupTotalText.Format currencyGroup.total as a number and save it as groupTotalText.
Add groupTotalText to the end of totalParts and save it as totalParts.Add groupTotalText to the end of totalParts and save it as totalParts.
Join totalParts with “ and ” and save it as totalsText.Join totalParts with “ and ” and save it as totalsText.
Set overdueWord to “invoices”.Set overdueWord to “invoices”.
If overdueCount is 1If overdueCount is 1
Yes
Change overdueWord to “invoice”.Change overdueWord to “invoice”.
No
No steps
Combine problems and noEmailLines into one list and save it as attentionLines.Combine problems and noEmailLines into one list and save it as attentionLines.
If chasedCount is 0 and the length of attentionLines is 0 is yesIf chasedCount is 0 and the length of attentionLines is 0 is yes
Yes
Finish the run: No reminders were due this morning. Still overdue: overdueCount overdueWord, totalsText in all. Each will be chased when it reaches its next reminder.Finish the run: No reminders were due this morning. Still overdue: overdueCount overdueWord, totalsText in all. Each will be chased when it reaches its next reminder.
No
No steps
Set chasedWord to “invoices”.Set chasedWord to “invoices”.
If chasedCount is 1If chasedCount is 1
Yes
Change chasedWord to “invoice”.Change chasedWord to “invoice”.
No
No steps
Set chasedPart to “Preview: no reminders due”.Set chasedPart to “Preview: no reminders due”.
If liveMode is yes and chasedCount is greater than 0If liveMode is yes and chasedCount is greater than 0
Yes
Build the text “Chased @chasedCount @chasedWord” and save it as chasedPart.Build the text “Chased @chasedCount @chasedWord” and save it as chasedPart.
Else if @liveMode is yes
Change chasedPart to “No reminders sent”.Change chasedPart to “No reminders sent”.
Else if @chasedCount is greater than 0
Build the text “Preview: @chasedCount @chasedWord ready to chase” and save it as chasedPart.Build the text “Preview: @chasedCount @chasedWord ready to chase” and save it as chasedPart.
Otherwise
No steps
Build the text “@chasedPart · @totalsText overdue across @overdueCount @overdueWord” and save it as headline.Build the text “@chasedPart · @totalsText overdue across @overdueCount @overdueWord” and save it as headline.
Set previewNote to blank.Set previewNote to blank.
If liveMode is noIf liveMode is no
Yes
Change previewNote to:Change previewNote to:This is a preview: nothing has been sent to your customers. Below is what would have gone out this morning, with each kind of reminder written out in full at the end and its invoice attached to this email. When you're happy with them, set the 'sendToCustomers' step to true and the next run sends them for real.
No
No steps
Set attentionSection to blank.Set attentionSection to blank.
If attentionLines isn't emptyIf attentionLines isn't empty
Yes
Join attentionLines with a new line and save it as attentionText.Join attentionLines with a new line and save it as attentionText.
Build the text “Needs your attention: @attentionText” and save it as attentionSection.Build the text “Needs your attention: @attentionText” and save it as attentionSection.
No
No steps
Set chasedSection to blank.Set chasedSection to blank.
If chasedCount is greater than 0If chasedCount is greater than 0
Yes
Join chasedLines with a new line and save it as chasedText.Join chasedLines with a new line and save it as chasedText.
Set chasedHeading to:Set chasedHeading to:Reminders that would go out this morning:
If liveMode is yesIf liveMode is yes
Yes
Change chasedHeading to:Change chasedHeading to:Reminders sent this morning:
No
No steps
Build the text “@chasedHeading@chasedText” and save it as chasedSection.Build the text “@chasedHeading@chasedText” and save it as chasedSection.
No
No steps
Set stillOverdueSection to blank.Set stillOverdueSection to blank.
If stillOverdueLines isn't emptyIf stillOverdueLines isn't empty
Yes
Join stillOverdueLines with a new line and save it as stillOverdueText.Join stillOverdueLines with a new line and save it as stillOverdueText.
Build the text “Still overdue: @stillOverdueText” and save it as stillOverdueSection.Build the text “Still overdue: @stillOverdueText” and save it as stillOverdueSection.
No
No steps
Join examples with a blank line and save it as examplesText.Join examples with a blank line and save it as examplesText.
If a step below fails, save the error as summaryErrorIf a step below fails, save the error as summaryError
Try
GmailGmailSend an email to summaryEmail.Send an email to summaryEmail. Subject: headlineheadline previewNote@attentionSection@chasedSection@stillOverdueSection@examplesText
On error
Add • The summary email couldn't be sent to summaryEmail (summaryError.message). to the end of problems and save it as problems.Add • The summary email couldn't be sent to summaryEmail (summaryError.message). to the end of problems and save it as problems.
If problems isn't emptyIf problems isn't empty
Yes
Join problems with a new line and save it as problemText.Join problems with a new line and save it as problemText.
Stop and report a problem: headline. Not everything went through:Stop and report a problem: headline. Not everything went through: problemText.
No
No steps
Finish the run: headline. The summary went to summaryEmail.Finish the run: headline. The summary went to summaryEmail.