Skip to content

[IP-389]: Notes template/selection option in quotations and invoices#612

Merged
nielsdrost7 merged 2 commits into
InvoicePlane:developfrom
KhawarMehfooz:389/notes-templates
Jul 14, 2026
Merged

[IP-389]: Notes template/selection option in quotations and invoices#612
nielsdrost7 merged 2 commits into
InvoicePlane:developfrom
KhawarMehfooz:389/notes-templates

Conversation

@KhawarMehfooz

@KhawarMehfooz KhawarMehfooz commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Checklist

Checklist

  • My code follows the code formatting guidelines.
  • I have tested my changes locally.
  • I selected the appropriate branch for this PR.
  • I have rebased my changes on top of the selected branch.
  • I included relevant documentation updates if necessary.
  • I have an accompanying issue ID for this pull request.

Description

Adds reusable, company-scoped note/terms templates so admins no longer have to retype the same boilerplate legal/payment text on every invoice or quote.

  • New NoteTemplate model (table note_templates, fields template_title/template_body), scoped via the existing BelongsToCompany trait.
  • New "Note Templates" resource in the Company panel under a new Settings nav group, with full CRUD gated by the existing manage-company-settings permission (same as NumberingResource).
  • New InsertNoteTemplateAction — an "Insert Template" hint-action on MarkdownEditor fields that opens a searchable template picker and either appends or replaces the field's content.
  • Wired onto Invoice notes + invoice_terms, and Quote notes.
  • Expanded the Note Template body editor's toolbar (headings, lists, blockquote, code block, etc.) beyond the initial bold/italic-only set.

Related Issue(s)

Closes #389

Motivation and Context

Company admins were retyping the same standard terms (e.g. "SEO Project Terms", "Web Dev Payment Terms") into every invoice/quote. This adds a small reusable template library plus a one-click insert action on the notes/terms fields, removing that repetitive work.

Issue Type (Check one or more)

  • Bugfix
  • Improvement of an existing feature
  • New feature

Screenshots (If Applicable)

New Navigation Menu

  • New navigation menu for managing Notes Template resource.
Screenshot 2026-07-14 at 4 40 41 PM
  • Insert Note template on invoice resource
Screenshot 2026-07-14 at 4 41 56 PM
  • Choosing the Notes Template
Screenshot 2026-07-14 at 4 42 33 PM

Summary by CodeRabbit

  • New Features

    • Added company note templates with title and formatted body content.
    • Added template management under Company Settings, including create, edit, search, and delete actions.
    • Added note template insertion to invoice and quote notes fields, with options to replace or append content.
    • Restricted template access to authorized users and the active company.
  • Tests

    • Added coverage for template management, company isolation, validation, and insertion into invoices and quotes.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds company-scoped note templates with database persistence, Filament management, permission checks, and reusable insertion actions for invoice and quote note fields. Feature tests cover CRUD, tenancy isolation, validation, and editor insertion.

Changes

Note template workflow

Layer / File(s) Summary
Template storage and model
Modules/Core/Database/Migrations/..., Modules/Core/Models/NoteTemplate.php, Modules/Core/Database/Factories/NoteTemplateFactory.php
Creates the company-owned note_templates table, Eloquent model, factory, and cascading company relationship.
Template management UI
Modules/Core/Services/NoteTemplateService.php, Modules/Core/Filament/Company/Resources/NoteTemplates/..., Modules/Core/Providers/CompanyPanelProvider.php
Adds CRUD service operations, Filament forms and tables, permission checks, resource routing, and Settings navigation registration.
Invoice and quote insertion
Modules/Core/Filament/Company/Actions/InsertNoteTemplateAction.php, Modules/Invoices/.../InvoiceForm.php, Modules/Quotes/.../QuoteForm.php
Adds a shared action that replaces or appends selected company template content in invoice, invoice terms, and quote note editors.
Feature validation
Modules/Core/Tests/Feature/NoteTemplatesTest.php, Modules/Invoices/Tests/Feature/InvoicesTest.php, Modules/Quotes/Tests/Feature/QuotesTest.php
Covers template listing, tenancy isolation, modal CRUD, required-title validation, and insertion into invoice and quote notes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MarkdownEditor
  participant InsertNoteTemplateAction
  participant NoteTemplate
  participant FormState
  MarkdownEditor->>InsertNoteTemplateAction: submit selected template and replacement mode
  InsertNoteTemplateAction->>NoteTemplate: load company-scoped template
  NoteTemplate-->>InsertNoteTemplateAction: return template body
  InsertNoteTemplateAction->>FormState: replace or append body
Loading

Suggested reviewers: nielsdrost7

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR adds company-scoped note templates and lets users insert them in quote and invoice editors as requested.
Out of Scope Changes check ✅ Passed The changes stay within the template-management and template-insertion scope described by the issue.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the core change: note template selection for quotations and invoices.
📋 Issue Planner

Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).

View plan for ticket: #389

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
Modules/Core/Tests/Feature/NoteTemplatesTest.php (1)

148-154: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Assign Livewire result to a variable for consistency.

Assigning the Livewire component execution to a $component variable and asserting $component->assertSuccessful() verifies the action succeeded without internal errors and matches the structure of your other tests. As per coding guidelines, structure tests to define all variables in the Act section before asserting.

♻️ Proposed refactor
-        Livewire::actingAs($this->user)
+        $component = Livewire::actingAs($this->user)
             ->test(ListNoteTemplates::class)
             ->mountAction(TestAction::make('delete')->table($template))
             ->callMountedAction();
 
         /* Assert */
+        $component->assertSuccessful();
         $this->assertDatabaseMissing('note_templates', ['id' => $template->id]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Modules/Core/Tests/Feature/NoteTemplatesTest.php` around lines 148 - 154,
Update the delete-action test using ListNoteTemplates to assign the Livewire
test chain to a $component variable in the Act section, then assert
$component->assertSuccessful() before verifying the note template is absent from
the database.

Source: Coding guidelines

Modules/Core/Filament/Company/Resources/NoteTemplates/Tables/NoteTemplatesTable.php (1)

42-46: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Ensure bulk deletions use the service layer.

The single DeleteAction on line 37 correctly delegates to NoteTemplateService::deleteNoteTemplate(). However, DeleteBulkAction relies on the default Eloquent deletion. If the service layer performs necessary business logic (such as logging or cascading cleanup), bulk deletions will bypass it. Consider overriding the action for DeleteBulkAction to use the service as well.

♻️ Proposed refactor
             ->toolbarActions([
                 BulkActionGroup::make([
-                    DeleteBulkAction::make(),
+                    DeleteBulkAction::make()
+                        ->action(function (\Illuminate\Database\Eloquent\Collection $records) {
+                            $records->each(fn ($record) => app(NoteTemplateService::class)->deleteNoteTemplate($record, []));
+                        }),
                 ]),
             ]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@Modules/Core/Filament/Company/Resources/NoteTemplates/Tables/NoteTemplatesTable.php`
around lines 42 - 46, Update the DeleteBulkAction within NoteTemplatesTable to
delete each selected NoteTemplate through
NoteTemplateService::deleteNoteTemplate(), matching the existing single
DeleteAction behavior, instead of relying on default Eloquent deletion.
Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php (1)

228-229: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid restricting the Markdown toolbar for fields receiving rich templates.

The PR successfully expands the template editor's toolbar to support headings, lists, and blockquotes. However, the destination fields on the invoice form restrict the toolbar to only bold and italic. When a user inserts a rich template into these fields, they will lack the UI controls necessary to properly edit the imported formatting.

  • Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php#L228-L229: Remove the ->toolbarButtons(['bold', 'italic']) restriction on the notes field or expand it to match the template editor.
  • Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php#L249-L250: Apply the same adjustment to the invoice_terms field.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php`
around lines 228 - 229, The notes field at
Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php
lines 228-229 and the invoice_terms field at lines 249-250 restrict their
Markdown toolbar to bold and italic; remove that toolbarButtons restriction or
expand both fields to match the rich template editor’s supported formatting
while preserving their existing hintAction configuration.
Modules/Core/Services/NoteTemplateService.php (1)

35-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused parameter.

The $data parameter is not used anywhere within this method. You can safely remove it to clean up the signature.

♻️ Proposed refactor
-    public function deleteNoteTemplate(NoteTemplate $noteTemplate, array $data = []): NoteTemplate
+    public function deleteNoteTemplate(NoteTemplate $noteTemplate): NoteTemplate
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Modules/Core/Services/NoteTemplateService.php` at line 35, Remove the unused
$data parameter from the deleteNoteTemplate method signature, preserving the
NoteTemplate argument and return type. Update any callers to invoke
deleteNoteTemplate with only the NoteTemplate instance.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Modules/Core/Filament/Company/Actions/InsertNoteTemplateAction.php`:
- Around line 32-34: Update the NoteTemplate lookup inside the action closure of
InsertNoteTemplateAction to scope the query to the current company/tenant before
resolving data['note_template_id']; preserve the existing template-selection
flow while ensuring cross-company template IDs cannot be accessed.
- Line 5: Update the Action import used by InsertNoteTemplateAction to
Filament\Forms\Components\Actions\Action, and align any method return types or
type references in InsertNoteTemplateAction with that form-component action
class so hintAction() receives the expected type.

In `@Modules/Quotes/Filament/Company/Resources/Quotes/Schemas/QuoteForm.php`:
- Around line 221-222: Update the notes editor configuration in the Quote form
schema by removing the restrictive toolbarButtons(['bold', 'italic']) call from
the field using InsertNoteTemplateAction::make('notes), allowing Filament’s
comprehensive default Markdown toolbar to provide the intended formatting
options.

---

Nitpick comments:
In
`@Modules/Core/Filament/Company/Resources/NoteTemplates/Tables/NoteTemplatesTable.php`:
- Around line 42-46: Update the DeleteBulkAction within NoteTemplatesTable to
delete each selected NoteTemplate through
NoteTemplateService::deleteNoteTemplate(), matching the existing single
DeleteAction behavior, instead of relying on default Eloquent deletion.

In `@Modules/Core/Services/NoteTemplateService.php`:
- Line 35: Remove the unused $data parameter from the deleteNoteTemplate method
signature, preserving the NoteTemplate argument and return type. Update any
callers to invoke deleteNoteTemplate with only the NoteTemplate instance.

In `@Modules/Core/Tests/Feature/NoteTemplatesTest.php`:
- Around line 148-154: Update the delete-action test using ListNoteTemplates to
assign the Livewire test chain to a $component variable in the Act section, then
assert $component->assertSuccessful() before verifying the note template is
absent from the database.

In
`@Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php`:
- Around line 228-229: The notes field at
Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php
lines 228-229 and the invoice_terms field at lines 249-250 restrict their
Markdown toolbar to bold and italic; remove that toolbarButtons restriction or
expand both fields to match the rich template editor’s supported formatting
while preserving their existing hintAction configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b205cc88-0c53-4fd6-b37f-74055d60f11c

📥 Commits

Reviewing files that changed from the base of the PR and between d086ad1 and d1a9ad9.

📒 Files selected for processing (15)
  • Modules/Core/Database/Factories/NoteTemplateFactory.php
  • Modules/Core/Database/Migrations/2026_07_14_000001_create_note_templates_table.php
  • Modules/Core/Filament/Company/Actions/InsertNoteTemplateAction.php
  • Modules/Core/Filament/Company/Resources/NoteTemplates/NoteTemplateResource.php
  • Modules/Core/Filament/Company/Resources/NoteTemplates/Pages/ListNoteTemplates.php
  • Modules/Core/Filament/Company/Resources/NoteTemplates/Schemas/NoteTemplateForm.php
  • Modules/Core/Filament/Company/Resources/NoteTemplates/Tables/NoteTemplatesTable.php
  • Modules/Core/Models/NoteTemplate.php
  • Modules/Core/Providers/CompanyPanelProvider.php
  • Modules/Core/Services/NoteTemplateService.php
  • Modules/Core/Tests/Feature/NoteTemplatesTest.php
  • Modules/Invoices/Filament/Company/Resources/Invoices/Schemas/InvoiceForm.php
  • Modules/Invoices/Tests/Feature/InvoicesTest.php
  • Modules/Quotes/Filament/Company/Resources/Quotes/Schemas/QuoteForm.php
  • Modules/Quotes/Tests/Feature/QuotesTest.php

Comment thread Modules/Core/Filament/Company/Actions/InsertNoteTemplateAction.php
Comment thread Modules/Core/Filament/Company/Actions/InsertNoteTemplateAction.php
Comment thread Modules/Quotes/Filament/Company/Resources/Quotes/Schemas/QuoteForm.php Outdated
@nielsdrost7 nielsdrost7 merged commit 8eea9bd into InvoicePlane:develop Jul 14, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core]: Notes template/selection option in quotations and invoices

2 participants