@huloglobal/vendure-plugin-quotations 0.8.5 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +107 -10
  3. package/dist/approvals.d.ts +46 -0
  4. package/dist/approvals.d.ts.map +1 -0
  5. package/dist/approvals.js +136 -0
  6. package/dist/approvals.js.map +1 -0
  7. package/dist/crons.d.ts +5 -3
  8. package/dist/crons.d.ts.map +1 -1
  9. package/dist/crons.js +16 -10
  10. package/dist/crons.js.map +1 -1
  11. package/dist/csv.d.ts +7 -0
  12. package/dist/csv.d.ts.map +1 -0
  13. package/dist/csv.js +32 -0
  14. package/dist/csv.js.map +1 -0
  15. package/dist/deposits.d.ts +25 -0
  16. package/dist/deposits.d.ts.map +1 -0
  17. package/dist/deposits.js +59 -0
  18. package/dist/deposits.js.map +1 -0
  19. package/dist/events.d.ts +55 -0
  20. package/dist/events.d.ts.map +1 -0
  21. package/dist/events.js +58 -0
  22. package/dist/events.js.map +1 -0
  23. package/dist/index.d.ts +4 -0
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +7 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/pay-links.d.ts +37 -0
  28. package/dist/pay-links.d.ts.map +1 -0
  29. package/dist/pay-links.js +61 -0
  30. package/dist/pay-links.js.map +1 -0
  31. package/dist/payment.service.d.ts +117 -0
  32. package/dist/payment.service.d.ts.map +1 -0
  33. package/dist/payment.service.js +476 -0
  34. package/dist/payment.service.js.map +1 -0
  35. package/dist/pdf.d.ts +15 -0
  36. package/dist/pdf.d.ts.map +1 -0
  37. package/dist/pdf.js +356 -0
  38. package/dist/pdf.js.map +1 -0
  39. package/dist/plugin.d.ts +5 -2
  40. package/dist/plugin.d.ts.map +1 -1
  41. package/dist/plugin.js +18 -6
  42. package/dist/plugin.js.map +1 -1
  43. package/dist/pro-settings.d.ts +72 -0
  44. package/dist/pro-settings.d.ts.map +1 -0
  45. package/dist/pro-settings.js +202 -0
  46. package/dist/pro-settings.js.map +1 -0
  47. package/dist/pro.service.d.ts +130 -0
  48. package/dist/pro.service.d.ts.map +1 -0
  49. package/dist/pro.service.js +732 -0
  50. package/dist/pro.service.js.map +1 -0
  51. package/dist/quotation.controller.d.ts +50 -6
  52. package/dist/quotation.controller.d.ts.map +1 -1
  53. package/dist/quotation.controller.js +618 -24
  54. package/dist/quotation.controller.js.map +1 -1
  55. package/dist/quotation.service.d.ts +188 -11
  56. package/dist/quotation.service.d.ts.map +1 -1
  57. package/dist/quotation.service.js +636 -99
  58. package/dist/quotation.service.js.map +1 -1
  59. package/dist/quote-total.d.ts +49 -0
  60. package/dist/quote-total.d.ts.map +1 -0
  61. package/dist/quote-total.js +81 -0
  62. package/dist/quote-total.js.map +1 -0
  63. package/dist/templates.d.ts +13 -1
  64. package/dist/templates.d.ts.map +1 -1
  65. package/dist/templates.js +17 -6
  66. package/dist/templates.js.map +1 -1
  67. package/dist/types.d.ts +12 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/types.js +2 -0
  70. package/dist/types.js.map +1 -1
  71. package/dist/webhooks.d.ts +61 -0
  72. package/dist/webhooks.d.ts.map +1 -0
  73. package/dist/webhooks.js +308 -0
  74. package/dist/webhooks.js.map +1 -0
  75. package/package.json +4 -3
  76. package/ui/components/quotations.component.ts +328 -19
@@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
2
2
  import { HttpClient } from '@angular/common/http';
3
3
  import { NotificationService } from '@vendure/admin-ui/core';
4
4
 
5
- type Tab = 'quotes' | 'editor' | 'settings';
5
+ type Tab = 'quotes' | 'editor' | 'reports' | 'templates' | 'settings';
6
6
 
7
7
  interface QuoteLine {
8
8
  productVariantId?: number | null; sku?: string; description: string;
@@ -99,10 +99,10 @@ interface QuoteLine {
99
99
  <div>
100
100
  <strong>⏳ Full-featured evaluation</strong> —
101
101
  <ng-container *ngIf="meta.eval?.daysRemaining != null; else evalNoClock">
102
- <strong>{{ meta.eval.daysRemaining }} day{{ meta.eval.daysRemaining === 1 ? '' : 's' }} left</strong> with everything enabled — sending, chasers and order conversion included.
102
+ <strong>{{ meta.eval.daysRemaining }} day{{ meta.eval.daysRemaining === 1 ? '' : 's' }} left</strong> with everything enabled — templates, follow-ups, approval, webhooks, sales reports and deposits included.
103
103
  </ng-container>
104
- <ng-template #evalNoClock>everything is enabled — sending, chasers and order conversion included.</ng-template>
105
- Afterwards the plugin drops to the free tier (draft + preview only).
104
+ <ng-template #evalNoClock>everything is enabled — templates, follow-ups, approval, webhooks, sales reports and deposits included.</ng-template>
105
+ Afterwards the plugin drops to the free tier: quoting, sending, reminders, PDFs and pay links stay free.
106
106
  <div class="premium-line" *ngIf="meta.premiumFeatures?.length">Included now: {{ meta.premiumFeatures.join(' · ') }}</div>
107
107
  <div class="sofar-line" *ngIf="meta.recentStats?.length">So far: {{ soFarLine() }}</div>
108
108
  </div>
@@ -119,7 +119,7 @@ interface QuoteLine {
119
119
  </div>
120
120
  </div>
121
121
  <div class="update-banner major" *ngIf="meta.tier !== 'trial'">
122
- <div><strong>🔓 Free tier</strong> — premium features need a licence. Subscribe below (monthly or annual, cancel any time) or buy a lifetime licence. Drafting, pricing and previews stay active; sending, chasers and order conversion need a licence. Everything you built is saved and reactivates instantly with a key.
122
+ <div><strong>🔓 Free tier</strong> — premium features need a licence. Subscribe below (monthly or annual, cancel any time) or buy a lifetime licence. Quoting, sending, chasers and reminders, PDFs, storefront requests and pay links stay free; the features below need a licence. Everything you built is saved and reactivates instantly with a key.
123
123
  <div class="premium-line" *ngIf="meta.premiumFeatures?.length">With a licence: {{ meta.premiumFeatures.join(' · ') }}</div>
124
124
  <div class="sofar-line" *ngIf="meta.recentStats?.length">{{ meta.eval?.source === 'server' ? 'During your evaluation' : 'So far' }}: {{ soFarLine() }}</div>
125
125
  </div>
@@ -143,6 +143,8 @@ interface QuoteLine {
143
143
  <div class="tabs" role="tablist">
144
144
  <button class="tab" role="tab" [class.active]="tab==='quotes'" (click)="go('quotes')">Quotes<span class="tab-count" *ngIf="list?.totalItems">{{ list.totalItems }}</span></button>
145
145
  <button class="tab" role="tab" [class.active]="tab==='editor'" (click)="go('editor')">{{ editing?.id ? 'Edit ' + editing.reference : 'New quote' }}</button>
146
+ <button class="tab" role="tab" [class.active]="tab==='reports'" (click)="go('reports')">Reports</button>
147
+ <button class="tab" role="tab" [class.active]="tab==='templates'" (click)="go('templates')">Templates<span class="tab-count" *ngIf="templates?.length">{{ templates.length }}</span></button>
146
148
  <button class="tab" role="tab" [class.active]="tab==='settings'" (click)="go('settings')">Settings</button>
147
149
  </div>
148
150
  </div></div>
@@ -175,8 +177,8 @@ interface QuoteLine {
175
177
  <div class="kpi" [class.kpi-alert]="openRequests() > 0" (click)="showRequests()" title="Show requests awaiting a quote"><div class="kpi-label">Requests</div><div class="kpi-num">{{ openRequests() }}</div><div class="kpi-sub">{{ openRequests() ? 'waiting for a price' : 'inbox clear' }}</div></div>
176
178
  <div class="kpi"><div class="kpi-label">Sent · 30d</div><div class="kpi-num">{{ stats?.last30?.sent || 0 }}</div><div class="kpi-sub">quotes emailed</div></div>
177
179
  <div class="kpi"><div class="kpi-label">Win rate · 30d</div><div class="kpi-num">{{ stats?.last30?.winRate == null ? '—' : stats.last30.winRate + '%' }}</div><div class="kpi-sub">{{ stats?.last30?.won || 0 }} accepted</div></div>
178
- <div class="kpi"><div class="kpi-label">Value won · 30d</div><div class="kpi-num">{{ money(stats?.last30?.valueWonPence || 0, cfg?.currency || 'GBP') }}</div><div class="kpi-sub">{{ stats?.last30?.accepted || 0 }} accepted this month</div></div>
179
- <div class="kpi"><div class="kpi-label">Open pipeline</div><div class="kpi-num">{{ money(openPipeline()) }}</div><div class="kpi-sub">sent + viewed</div></div>
180
+ <div class="kpi"><div class="kpi-label">Value won · 30d</div><div class="kpi-num">{{ moneyMap(stats?.last30?.valueWonByCurrency) }}</div><div class="kpi-sub">{{ stats?.last30?.accepted || 0 }} accepted this month</div></div>
181
+ <div class="kpi"><div class="kpi-label">Open pipeline</div><div class="kpi-num">{{ moneyMap(stats?.pipelineByCurrency) }}</div><div class="kpi-sub">sent + viewed</div></div>
180
182
  <div class="kpi"><div class="kpi-label">Avg response</div><div class="kpi-num">{{ stats?.avgResponseHours == null ? '—' : stats.avgResponseHours + 'h' }}</div><div class="kpi-sub">send → decision</div></div>
181
183
  </div>
182
184
  </vdr-page-block>
@@ -222,9 +224,14 @@ interface QuoteLine {
222
224
  <h3 class="step-title" style="margin:0">{{ detail.reference }} — {{ money(detail.totalPence, detail.currency) }} <span class="pill" [ngClass]="'st-' + detail.status" style="margin-left:8px">{{ detail.status }}</span></h3>
223
225
  <div class="picker">
224
226
  <button class="gbtn gbtn-primary gbtn-sm" *ngIf="canSend(detail)" (click)="send(detail)" [disabled]="busy">{{ detail.sentAt ? 'Re-send' : 'Send to customer' }}</button>
225
- <button class="gbtn gbtn-primary gbtn-sm" *ngIf="detail.status==='accepted'" (click)="convert(detail)" [disabled]="busy">Convert to order</button>
227
+ <button class="gbtn gbtn-outline gbtn-sm" *ngIf="detail.status==='draft' || detail.status==='requested'" (click)="markSent(detail)" [disabled]="busy" title="You shared the quote yourself (PDF or link): open it for the customer without e-mailing">Mark as sent</button>
228
+ <button class="gbtn gbtn-primary gbtn-sm" *ngIf="['accepted','converted'].includes(detail.status) && payment?.available && !payment?.paid && !payment?.payUrl" (click)="createPayLink(detail)" [disabled]="busy">Create pay link</button>
229
+ <button class="gbtn gbtn-outline gbtn-sm" *ngIf="detail.status==='accepted'" (click)="convert(detail)" [disabled]="busy">Convert to order</button>
226
230
  <button class="gbtn gbtn-outline gbtn-sm" *ngIf="isEditable(detail)" (click)="edit(detail)">Edit</button>
227
231
  <button class="gbtn gbtn-outline gbtn-sm" (click)="previewEmail(detail)">Preview email</button>
232
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="previewPage(detail)" title="The customer page as they see it; not counted as an opening">Preview page</button>
233
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="openPdf(detail)">PDF</button>
234
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="saveAsTemplate(detail)" [disabled]="busy">Save as template</button>
228
235
  <button class="gbtn gbtn-outline gbtn-sm" *ngIf="canSend(detail)" (click)="testSend(detail)" [disabled]="busy">Test-send to me</button>
229
236
  <button class="gbtn gbtn-outline gbtn-sm" *ngIf="['sent','viewed','expired','draft'].includes(detail.status)" (click)="extend(detail)" [disabled]="busy">Extend validity</button>
230
237
  <button class="gbtn gbtn-outline gbtn-sm" (click)="duplicate(detail)" [disabled]="busy">Duplicate</button>
@@ -239,7 +246,42 @@ interface QuoteLine {
239
246
  Customer link: <a [href]="detail.publicUrl" target="_blank">{{ detail.publicUrl }}</a>
240
247
  <button class="gbtn gbtn-outline gbtn-sm" style="margin-left:6px" (click)="copyLink(detail)">{{ linkCopied ? 'Copied ✓' : 'Copy' }}</button>
241
248
  </p>
242
- <p class="hint" *ngIf="detail.convertedOrderId">Converted to draft order <a [routerLink]="['/orders', 'draft', detail.convertedOrderId]">#{{ detail.convertedOrderId }}</a> — open it in Orders to complete.</p>
249
+ <p class="hint" *ngIf="detail.convertedOrderId">Converted to order <a [routerLink]="['/orders', detail.convertedOrderId]">#{{ detail.convertedOrderId }}</a> — open it in Orders to complete.</p>
250
+ <div class="request-box" *ngIf="payment && (payment.payUrl || payment.paid || payment.deposit || payment.plan?.deposit)">
251
+ <strong>Payment</strong>
252
+ <span *ngIf="payment.paid"> — paid in full{{ payment.paidAt ? ' on ' + (payment.paidAt | date:'d MMM y') : '' }}.</span>
253
+ <span *ngIf="!payment.paid && payment.payUrl"> — {{ payment.payLabel }}: <a [href]="payment.payUrl" target="_blank">{{ payment.payUrl }}</a>
254
+ <button class="gbtn gbtn-outline gbtn-sm" style="margin-left:6px" (click)="emailPayLink(detail)" [disabled]="busy">E-mail the link</button></span>
255
+ <div *ngIf="payment.deposit">Deposit {{ money(payment.deposit.depositPence, detail.currency) }} ({{ payment.deposit.pct }}%): {{ payment.deposit.depositPaid ? 'paid' : 'awaiting payment' }} ·
256
+ Balance {{ money(payment.deposit.balancePence, detail.currency) }}: {{ payment.deposit.balancePaid ? 'paid' : (payment.deposit.balanceLink ? 'pay link sent or ready' : 'not requested yet') }}
257
+ <button class="gbtn gbtn-outline gbtn-sm" *ngIf="payment.deposit.depositPaid && !payment.deposit.balancePaid" (click)="balance(detail)" [disabled]="busy">E-mail the balance link</button></div>
258
+ <div *ngIf="!payment.deposit && payment.plan?.deposit && !payment.payUrl" class="hint">On acceptance the customer pays a deposit of {{ money(payment.plan.deposit, detail.currency) }} ({{ payment.plan.pct }}%) first, then the balance.</div>
259
+ </div>
260
+ <div class="request-box" *ngIf="depositEditable(detail)">
261
+ <strong>Deposit for this quote</strong>
262
+ <div class="picker" style="margin-top:6px">
263
+ <select class="form-select" [(ngModel)]="depositEdit.mode"><option value="">Default ({{ proSettings?.settings?.depositPct || 0 }}%)</option><option value="none">No deposit</option><option value="pct">Deposit of</option></select>
264
+ <input class="form-input num-in" type="number" min="1" max="99" step="0.01" *ngIf="depositEdit.mode==='pct'" [(ngModel)]="depositEdit.pct"> <span *ngIf="depositEdit.mode==='pct'">%</span>
265
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="saveDeposit(detail)" [disabled]="busy">Save deposit</button>
266
+ </div>
267
+ </div>
268
+ <div class="request-box" *ngIf="approval?.configured && approval.status !== 'not_needed'">
269
+ <strong>Discount approval</strong> — {{ approvalLabel() }}
270
+ <div class="hint">{{ approval.reasons.join('; ') }}</div>
271
+ <div class="hint" *ngIf="!approval.active">Paused until a licence is active: quotes can be sent without approval meanwhile.</div>
272
+ <div *ngIf="approval.row?.comment" class="hint">“{{ approval.row.comment }}” — {{ approval.row.decidedBy }}</div>
273
+ <div class="picker" style="margin-top:6px" *ngIf="approval.active">
274
+ <button class="gbtn gbtn-primary gbtn-sm" *ngIf="['needed','rejected','stale'].includes(approval.status) && ['draft','requested','sent','viewed','expired'].includes(detail.status)" (click)="requestApproval(detail)" [disabled]="busy">Request approval</button>
275
+ <ng-container *ngIf="approval.status === 'pending'">
276
+ <ng-container *ngIf="approval.canDecide; else noDecide">
277
+ <input class="form-input" style="min-width:240px" placeholder="Comment (optional)" [(ngModel)]="approvalComment">
278
+ <button class="gbtn gbtn-primary gbtn-sm" (click)="decide(detail, 'approve')" [disabled]="busy">Approve</button>
279
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="decide(detail, 'reject')" [disabled]="busy">Reject</button>
280
+ </ng-container>
281
+ <ng-template #noDecide><span class="hint">{{ approval.cannotDecideReason }}</span></ng-template>
282
+ </ng-container>
283
+ </div>
284
+ </div>
243
285
  <table class="table">
244
286
  <thead><tr><th>Item</th><th class="num">Qty</th><th class="num">Unit</th><th class="num">Disc.</th><th class="num">Total</th></tr></thead>
245
287
  <tbody>
@@ -422,6 +464,66 @@ interface QuoteLine {
422
464
  </vdr-page-block>
423
465
  </ng-container>
424
466
 
467
+ <!-- REPORTS -->
468
+ <ng-container *ngIf="!loading && tab==='reports'">
469
+ <vdr-page-block>
470
+ <div class="card"><div class="card-block">
471
+ <h3 class="step-title">Last 12 months</h3>
472
+ <p class="hint">Quotes created and sent each month, how many were accepted (by the month the customer accepted), the win rate on the quotes sent that month, and the value won in each currency. Currencies are never added together.</p>
473
+ <table class="table" *ngIf="monthly?.months?.length">
474
+ <thead><tr><th>Month</th><th class="num">Created</th><th class="num">Sent</th><th class="num">Accepted</th><th class="num">Win rate</th><th class="num">Value won</th></tr></thead>
475
+ <tbody><tr *ngFor="let m of monthly.months">
476
+ <td>{{ m.month }}</td><td class="num">{{ m.created }}</td><td class="num">{{ m.sent }}</td><td class="num">{{ m.accepted }}</td>
477
+ <td class="num">{{ m.winRatePct == null ? '—' : m.winRatePct + '%' }}</td><td class="num">{{ moneyMap(m.wonByCurrency) }}</td>
478
+ </tr></tbody>
479
+ </table>
480
+ </div></div>
481
+ </vdr-page-block>
482
+ <vdr-page-block>
483
+ <div class="card"><div class="card-block">
484
+ <div class="row-between">
485
+ <h3 class="step-title" style="margin:0">Sales by staff and source <span class="hint inline" *ngIf="meta?.tier === 'free'">· needs a licence</span></h3>
486
+ <div class="picker">
487
+ <input class="form-input" type="date" [(ngModel)]="reportFrom"> → <input class="form-input" type="date" [(ngModel)]="reportTo">
488
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="loadSales()">Show</button>
489
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="downloadCsv()">Download CSV</button>
490
+ </div>
491
+ </div>
492
+ <p class="hint" *ngIf="salesError">{{ salesError }}</p>
493
+ <ng-container *ngIf="sales">
494
+ <h4 class="step-title" style="margin-top:12px">By member of staff (quotes sent {{ sales.from }} – {{ sales.to }})</h4>
495
+ <table class="table"><thead><tr><th>Prepared by</th><th class="num">Sent</th><th class="num">Won</th><th class="num">Win rate</th><th class="num">Value won</th><th class="num">Avg. hours to accept</th></tr></thead>
496
+ <tbody><tr *ngFor="let r of sales.byStaff"><td>{{ r.name || r.email || 'The store' }}<div class="hint" *ngIf="r.email">{{ r.email }}</div></td><td class="num">{{ r.sent }}</td><td class="num">{{ r.won }}</td><td class="num">{{ r.winRatePct }}%</td><td class="num">{{ moneyMap(r.wonByCurrency) }}</td><td class="num">{{ r.avgAcceptHours == null ? '—' : r.avgAcceptHours }}</td></tr></tbody></table>
497
+ <h4 class="step-title" style="margin-top:12px">By source (quotes created)</h4>
498
+ <table class="table"><thead><tr><th>Source</th><th class="num">Created</th><th class="num">Sent</th><th class="num">Won</th><th class="num">Win rate</th><th class="num">Value won</th></tr></thead>
499
+ <tbody><tr *ngFor="let r of sales.bySource"><td>{{ sourceLabel(r.source) }}</td><td class="num">{{ r.created }}</td><td class="num">{{ r.sent }}</td><td class="num">{{ r.won }}</td><td class="num">{{ r.winRatePct }}%</td><td class="num">{{ moneyMap(r.wonByCurrency) }}</td></tr></tbody></table>
500
+ </ng-container>
501
+ </div></div>
502
+ </vdr-page-block>
503
+ </ng-container>
504
+
505
+ <!-- TEMPLATES -->
506
+ <ng-container *ngIf="!loading && tab==='templates'">
507
+ <vdr-page-block>
508
+ <div class="card"><div class="card-block">
509
+ <h3 class="step-title">Quote templates <span class="hint inline" *ngIf="meta?.tier === 'free'">· needs a licence</span></h3>
510
+ <p class="hint">A template keeps the reusable part of a quote: lines, discounts, VAT, notes, terms, validity and currency (never the customer or internal notes). Save one from any quote with <strong>Save as template</strong>; start a new draft from it here.</p>
511
+ <table class="table" *ngIf="templates?.length; else noTemplates">
512
+ <thead><tr><th>Name</th><th class="num">Lines</th><th>Currency</th><th>Updated</th><th></th></tr></thead>
513
+ <tbody><tr *ngFor="let t of templates">
514
+ <td><strong>{{ t.name }}</strong></td><td class="num">{{ t.lines }}</td><td>{{ t.currency }}</td><td class="hint">{{ t.updatedAt | date:'d MMM y' }}</td>
515
+ <td class="num"><div class="picker" style="justify-content:flex-end">
516
+ <button class="gbtn gbtn-primary gbtn-sm" (click)="newFromTemplate(t)" [disabled]="busy">New quote</button>
517
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="renameTemplate(t)" [disabled]="busy">Rename</button>
518
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="deleteTemplate(t)" [disabled]="busy">Delete</button>
519
+ </div></td>
520
+ </tr></tbody>
521
+ </table>
522
+ <ng-template #noTemplates><p class="hint">No templates yet.</p></ng-template>
523
+ </div></div>
524
+ </vdr-page-block>
525
+ </ng-container>
526
+
425
527
  <!-- SETTINGS -->
426
528
  <ng-container *ngIf="!loading && tab==='settings' && cfg">
427
529
  <vdr-page-block>
@@ -498,6 +600,19 @@ interface QuoteLine {
498
600
  <div class="form-row wide"><label>Acknowledgement email to the customer <span class="hint">(variables: {{ '{{customerName}} {{reference}} {{summary}} {{businessName}}' }})</span></label>
499
601
  <textarea class="form-input" rows="7" [(ngModel)]="cfg.requestAckBody"></textarea></div>
500
602
  </div>
603
+ <h3 class="step-title" style="margin-top:14px">PDF and payment</h3>
604
+ <div class="form-grid">
605
+ <div class="form-row"><label>Attach the quote as a PDF</label>
606
+ <span class="gb-switch-group">
607
+ <button class="gb-switch" role="switch" [attr.aria-checked]="cfg.attachPdf" [class.on]="cfg.attachPdf" (click)="cfg.attachPdf = !cfg.attachPdf"><span class="gb-switch-knob"></span></button>
608
+ <span class="gb-switch-label">{{ cfg.attachPdf ? 'On — the quote e-mail carries the PDF' : 'Off — the PDF is a link on the quote page' }}</span>
609
+ </span></div>
610
+ <div class="form-row"><label>Pay link on acceptance</label>
611
+ <span class="gb-switch-group">
612
+ <button class="gb-switch" role="switch" [attr.aria-checked]="cfg.payLinkOnAccept" [class.on]="cfg.payLinkOnAccept" (click)="cfg.payLinkOnAccept = !cfg.payLinkOnAccept" [disabled]="!proSettings?.payLinks?.available"><span class="gb-switch-knob"></span></button>
613
+ <span class="gb-switch-label">{{ !proSettings?.payLinks?.available ? 'Needs HULO Payments for Vendure (pay links)' : cfg.payLinkOnAccept ? 'On — the customer is e-mailed a pay link as soon as they accept' : 'Off — create the pay link from the quote' }}</span>
614
+ </span></div>
615
+ </div>
501
616
  <h3 class="step-title" style="margin-top:14px">Quote email</h3>
502
617
  <div class="form-grid">
503
618
  <div class="form-row wide"><label>Subject</label><input class="form-input" [(ngModel)]="cfg.emailSubject"></div>
@@ -516,7 +631,7 @@ interface QuoteLine {
516
631
  </vdr-page-block>
517
632
  <vdr-page-block>
518
633
  <div class="card"><div class="card-block">
519
- <h3 class="step-title">Weekly report</h3>
634
+ <h3 class="step-title">Weekly report <span class="hint inline" *ngIf="digest && !digest.premium">· needs a licence (settings are kept)</span></h3>
520
635
  <p class="hint">Every Monday at 08:00 (server time) Quotations emails a short report: quotes created, sent and accepted, value won, storefront requests and win rate for the week against the week before, plus the next set-up step. Needs the same SMTP settings as quote emails.</p>
521
636
  <div class="form-grid" *ngIf="digest; else digestLoading">
522
637
  <div class="form-row"><label>Send the weekly report</label>
@@ -540,6 +655,55 @@ interface QuoteLine {
540
655
  <ng-template #digestLoading><p class="hint">Loading…</p></ng-template>
541
656
  </div></div>
542
657
  </vdr-page-block>
658
+ <vdr-page-block *ngIf="proSettings">
659
+ <div class="card"><div class="card-block">
660
+ <h3 class="step-title">Deposits, approval, follow-ups and webhooks <span class="hint inline" *ngIf="!proSettings.premium">· need a licence (settings are kept)</span></h3>
661
+ <h4 class="step-title" style="margin-top:10px">Deposits</h4>
662
+ <div class="form-grid">
663
+ <div class="form-row"><label>Deposit on acceptance (%)</label><input class="form-input num-in" type="number" min="0" max="99" step="0.01" [(ngModel)]="ps.depositPct"><div class="hint">0 = no deposit. The customer pays the deposit, then the balance; deposit + balance = the quote total exactly.</div></div>
664
+ <div class="form-row"><label>Only for quotes above</label><input class="form-input" [(ngModel)]="ps.depositAbove" placeholder="GBP 1000, EUR 1200 (empty = every quote)"></div>
665
+ </div>
666
+ <h4 class="step-title" style="margin-top:10px">Discount approval</h4>
667
+ <div class="form-grid">
668
+ <div class="form-row"><label>Discount off list over (%)</label><input class="form-input num-in" type="number" min="0" max="100" step="0.01" [(ngModel)]="ps.approvalMaxPct"></div>
669
+ <div class="form-row"><label>Discount amount over</label><input class="form-input" [(ngModel)]="ps.approvalMaxAmount" placeholder="GBP 500, EUR 600"></div>
670
+ <div class="form-row"><label>Quote total over</label><input class="form-input" [(ngModel)]="ps.approvalAbove" placeholder="GBP 20000"></div>
671
+ <div class="form-row"><label>Approvers (admin e-mails)</label><input class="form-input" [(ngModel)]="approversText" placeholder="Empty = any SuperAdmin"></div>
672
+ <div class="form-row"><label>Let the preparer approve when they are the only approver</label>
673
+ <span class="gb-switch-group"><button class="gb-switch" role="switch" [attr.aria-checked]="ps.approvalSelfSole" [class.on]="ps.approvalSelfSole" (click)="ps.approvalSelfSole = !ps.approvalSelfSole"><span class="gb-switch-knob"></span></button></span></div>
674
+ </div>
675
+ <h4 class="step-title" style="margin-top:10px">Follow-up sequence</h4>
676
+ <p class="hint">Up to three extra e-mails after a quote is sent, while it is still open and unpaid. Variables as in the quote e-mail.</p>
677
+ <div class="form-grid" *ngFor="let f of ps.followups; let i = index">
678
+ <div class="form-row"><label>Step {{ i + 1 }}</label>
679
+ <span class="gb-switch-group"><button class="gb-switch" role="switch" [attr.aria-checked]="f.enabled" [class.on]="f.enabled" (click)="f.enabled = !f.enabled"><span class="gb-switch-knob"></span></button>
680
+ <span class="gb-switch-label">{{ f.enabled ? 'On' : 'Off' }}</span></span></div>
681
+ <div class="form-row"><label>Days after sending</label><input class="form-input num-in" type="number" min="1" max="365" [(ngModel)]="f.days"></div>
682
+ <div class="form-row wide"><label>Subject</label><input class="form-input" [(ngModel)]="f.subject"></div>
683
+ <div class="form-row wide"><label>Body</label><textarea class="form-input" rows="4" [(ngModel)]="f.body"></textarea></div>
684
+ </div>
685
+ <h4 class="step-title" style="margin-top:10px">Webhooks and team alerts</h4>
686
+ <p class="hint">Up to five URLs. JSON deliveries are signed: <code>X-Hulo-Signature: sha256=HMAC(secret, timestamp + "." + body)</code>. Slack and Teams take their incoming-webhook URL. Only public https/http addresses on the standard ports; failed deliveries retry with back-off.</p>
687
+ <div class="form-grid" *ngFor="let h of ps.webhooks; let i = index">
688
+ <div class="form-row wide"><label>URL {{ i + 1 }}</label>
689
+ <div class="picker"><input class="form-input" style="min-width:340px" [(ngModel)]="h.url" placeholder="https://hooks.slack.com/services/…">
690
+ <select class="form-select" [(ngModel)]="h.format"><option value="json">JSON (signed)</option><option value="slack">Slack</option><option value="teams">Microsoft Teams</option></select>
691
+ <button class="gbtn gbtn-outline gbtn-sm" *ngIf="h.id" (click)="testWebhook(h)" [disabled]="busy">Send test</button>
692
+ <button class="gbtn gbtn-outline gbtn-sm" (click)="ps.webhooks.splice(i, 1)">✕</button></div></div>
693
+ <div class="form-row wide"><label>Events</label>
694
+ <div class="picker"><label *ngFor="let ev of webhookEventKeys()" style="font-weight:normal"><input type="checkbox" [checked]="h.events.includes(ev)" (change)="toggleEvent(h, ev)"> {{ proSettings.webhookEvents[ev] }}</label></div></div>
695
+ </div>
696
+ <div class="picker"><button class="gbtn gbtn-outline gbtn-sm" *ngIf="ps.webhooks.length < 5" (click)="ps.webhooks.push({ url: '', format: 'json', events: ['quote_accepted'], enabled: true })">+ Add webhook</button></div>
697
+ <p class="hint" *ngIf="proSettings.webhookSecret">Signing secret: <code>{{ proSettings.webhookSecret }}</code> <a style="cursor:pointer" (click)="regenerateSecret()">Regenerate</a></p>
698
+ <div class="picker" style="margin-top:14px"><button class="gbtn gbtn-primary" (click)="saveProSettings()" [disabled]="busy">{{ busy ? 'Saving…' : 'Save' }}</button></div>
699
+ <ng-container *ngIf="webhookLog?.length">
700
+ <h4 class="step-title" style="margin-top:14px">Delivery log (30 days)</h4>
701
+ <table class="table"><thead><tr><th>When</th><th>Event</th><th>Quote</th><th>State</th><th>Tries</th><th>Result</th><th></th></tr></thead>
702
+ <tbody><tr *ngFor="let l of webhookLog"><td class="hint">{{ l.createdAt | date:'d MMM HH:mm' }}</td><td>{{ l.event }}</td><td>{{ l.quoteId || 'test' }}</td><td><span class="pill" [ngClass]="'st-' + l.state">{{ l.state }}</span></td><td>{{ l.attempts }}</td><td class="hint">{{ l.code || '' }} {{ l.error }}</td>
703
+ <td><button class="gbtn gbtn-outline gbtn-sm" *ngIf="l.state === 'failed'" (click)="retryWebhook(l)">Retry</button></td></tr></tbody></table>
704
+ </ng-container>
705
+ </div></div>
706
+ </vdr-page-block>
543
707
  </ng-container>
544
708
 
545
709
  <vdr-page-block *ngIf="loading"><div class="card"><div class="card-block"><p class="hint">Loading…</p></div></div></vdr-page-block>
@@ -806,6 +970,22 @@ export class QuotationsComponent implements OnInit, OnDestroy {
806
970
  * away while every item stays done — an undone item brings it back. */
807
971
  private setupHiddenNow = false;
808
972
 
973
+ // 0.9.0: payment, approval, templates, reports, premium settings.
974
+ payment: any = null;
975
+ approval: any = null;
976
+ approvalComment = '';
977
+ depositEdit: { mode: string; pct: number | null } = { mode: '', pct: null };
978
+ templates: any[] = [];
979
+ monthly: any = null;
980
+ sales: any = null;
981
+ salesError = '';
982
+ reportFrom = '';
983
+ reportTo = '';
984
+ proSettings: any = null;
985
+ ps: any = null;
986
+ approversText = '';
987
+ webhookLog: any[] = [];
988
+
809
989
  // Weekly report card (Settings tab).
810
990
  digest: any = null;
811
991
  digestRecipient = '';
@@ -837,7 +1017,142 @@ export class QuotationsComponent implements OnInit, OnDestroy {
837
1017
  });
838
1018
  }
839
1019
 
840
- go(t: Tab) { this.tab = t; }
1020
+ go(t: Tab) {
1021
+ this.tab = t;
1022
+ if (t === 'reports') { this.loadMonthly(); if (this.meta?.tier !== 'free') this.loadSales(); }
1023
+ if (t === 'templates') this.loadTemplates();
1024
+ if (t === 'settings') { this.loadProSettings(); this.loadWebhookLog(); }
1025
+ }
1026
+
1027
+ // ── money per currency (never summed across currencies) ─────────────
1028
+ moneyMap(m: any): string {
1029
+ const parts = Object.entries(m || {}).filter(([, v]) => Number(v)).map(([c, v]) => this.money(Number(v), c));
1030
+ return parts.length ? parts.join(' + ') : this.money(0, this.cfg?.currency || 'GBP');
1031
+ }
1032
+ sourceLabel(s: string): string {
1033
+ return ({ form: 'Request form', product: 'Product page', cart: 'Basket', calculator: 'Calculator', other: 'Other storefront requests', manual: 'Made by staff' } as any)[s] || s;
1034
+ }
1035
+
1036
+ // ── payment, deposit, approval on the quote screen ──────────────────
1037
+ loadQuoteExtras(id: number) {
1038
+ this.http.get<any>(`/quotations/quotes/${id}/payment`).subscribe({ next: p => { this.payment = p; this.depositEdit = { mode: p?.override?.mode || '', pct: p?.override?.pct || null }; this.cdr.markForCheck(); }, error: () => { this.payment = null; } });
1039
+ this.http.get<any>(`/quotations/quotes/${id}/approval`).subscribe({ next: a => { this.approval = a; this.cdr.markForCheck(); }, error: () => { this.approval = null; } });
1040
+ if (!this.proSettings) this.loadProSettings();
1041
+ }
1042
+ depositEditable(q: any): boolean {
1043
+ if (!this.proSettings?.premium || this.payment?.payUrl || this.payment?.deposit) return false;
1044
+ if (!['requested', 'draft', 'sent', 'viewed', 'accepted'].includes(q.status)) return false;
1045
+ return Number(this.proSettings?.settings?.depositPct || 0) > 0 || !!this.depositEdit.mode;
1046
+ }
1047
+ approvalLabel(): string {
1048
+ return ({ needed: 'needed before sending', pending: 'waiting for an approver', approved: 'approved', rejected: 'rejected', stale: 'the quote changed: approval needed again' } as any)[this.approval?.status] || this.approval?.status || '';
1049
+ }
1050
+ private act(url: string, body: any, ok: string, q: any, what: string) {
1051
+ this.busy = true;
1052
+ this.http.post<any>(url, body).subscribe({
1053
+ next: () => { this.busy = false; if (ok) this.notify.success(ok); this.openQuote(q.id); this.loadList(); },
1054
+ error: e => { this.busy = false; this.notify.error(this.errMsg(e, what)); this.cdr.markForCheck(); },
1055
+ });
1056
+ }
1057
+ markSent(q: any) { this.act(`/quotations/quotes/${q.id}/mark-sent`, {}, `Quote ${q.reference} is open for the customer`, q, 'Marking as sent'); }
1058
+ createPayLink(q: any) { this.act(`/quotations/quotes/${q.id}/pay-link`, { email: confirm('E-mail the pay link to the customer now?') }, 'Pay link created', q, 'Creating the pay link'); }
1059
+ emailPayLink(q: any) { this.act(`/quotations/quotes/${q.id}/pay-link/email`, {}, 'Pay link e-mailed', q, 'E-mailing the pay link'); }
1060
+ balance(q: any) { this.act(`/quotations/quotes/${q.id}/balance`, { email: true }, 'Balance link e-mailed', q, 'The balance link'); }
1061
+ saveDeposit(q: any) { this.act(`/quotations/quotes/${q.id}/deposit`, { mode: this.depositEdit.mode, pct: this.depositEdit.pct }, 'Deposit saved', q, 'Saving the deposit'); }
1062
+ requestApproval(q: any) { this.act(`/quotations/quotes/${q.id}/approval/request`, {}, 'Approval requested', q, 'Requesting approval'); }
1063
+ decide(q: any, decision: 'approve' | 'reject') {
1064
+ this.act(`/quotations/quotes/${q.id}/approval/decide`, { decision, comment: this.approvalComment }, decision === 'approve' ? 'Approved' : 'Rejected', q, 'Discount approval');
1065
+ this.approvalComment = '';
1066
+ }
1067
+ previewPage(q: any) { window.open(`/quotations/quotes/${q.id}/page`, '_blank'); }
1068
+ openPdf(q: any) { window.open(`/quotations/quotes/${q.id}/pdf`, '_blank'); }
1069
+ saveAsTemplate(q: any) {
1070
+ const name = prompt('Template name', q.reference);
1071
+ if (name === null) return;
1072
+ this.act(`/quotations/quotes/${q.id}/save-template`, { name }, 'Template saved', q, 'Saving the template');
1073
+ }
1074
+
1075
+ // ── templates ───────────────────────────────────────────────────────
1076
+ loadTemplates() {
1077
+ this.http.get<any>('/quotations/templates').subscribe({ next: r => { this.templates = r?.items || []; this.cdr.markForCheck(); }, error: () => undefined });
1078
+ }
1079
+ newFromTemplate(t: any) {
1080
+ this.busy = true;
1081
+ this.http.post<any>(`/quotations/templates/${t.id}/new-quote`, { channelId: this.cfg?.channelId || 1 }).subscribe({
1082
+ next: q => { this.busy = false; this.notify.success(`Draft ${q.reference} created from "${t.name}"`); this.edit(q); this.cdr.markForCheck(); },
1083
+ error: e => { this.busy = false; this.notify.error(this.errMsg(e, 'Quote templates')); this.cdr.markForCheck(); },
1084
+ });
1085
+ }
1086
+ renameTemplate(t: any) {
1087
+ const name = prompt('New name', t.name);
1088
+ if (!name) return;
1089
+ this.http.put<any>(`/quotations/templates/${t.id}`, { name }).subscribe({ next: () => this.loadTemplates(), error: e => this.notify.error(this.errMsg(e, 'Quote templates')) });
1090
+ }
1091
+ deleteTemplate(t: any) {
1092
+ if (!confirm(`Delete template "${t.name}"?`)) return;
1093
+ this.http.delete<any>(`/quotations/templates/${t.id}`).subscribe({ next: () => this.loadTemplates(), error: e => this.notify.error(this.errMsg(e, 'Quote templates')) });
1094
+ }
1095
+
1096
+ // ── reports ─────────────────────────────────────────────────────────
1097
+ loadMonthly() {
1098
+ this.http.get<any>('/quotations/reports/monthly').subscribe({ next: r => { this.monthly = r; this.cdr.markForCheck(); }, error: () => undefined });
1099
+ }
1100
+ private reportParams(): any {
1101
+ const p: any = {};
1102
+ if (this.reportFrom) p.from = this.reportFrom;
1103
+ if (this.reportTo) p.to = this.reportTo;
1104
+ return p;
1105
+ }
1106
+ loadSales() {
1107
+ this.salesError = '';
1108
+ this.http.get<any>('/quotations/reports/sales', { params: this.reportParams() }).subscribe({
1109
+ next: r => { this.sales = r; this.reportFrom = r.from; this.reportTo = r.to; this.cdr.markForCheck(); },
1110
+ error: e => { this.sales = null; this.salesError = this.errMsg(e, 'Sales reports'); this.cdr.markForCheck(); },
1111
+ });
1112
+ }
1113
+ downloadCsv() {
1114
+ const p = new URLSearchParams(this.reportParams()).toString();
1115
+ window.open(`/quotations/reports/sales-csv${p ? '?' + p : ''}`, '_blank');
1116
+ }
1117
+
1118
+ // ── premium settings ────────────────────────────────────────────────
1119
+ loadProSettings() {
1120
+ this.http.get<any>('/quotations/pro/settings').subscribe({
1121
+ next: r => { this.proSettings = r; this.ps = JSON.parse(JSON.stringify(r.settings)); this.approversText = (r.settings.approvers || []).join(', '); this.cdr.markForCheck(); },
1122
+ error: () => undefined,
1123
+ });
1124
+ }
1125
+ webhookEventKeys(): string[] { return Object.keys(this.proSettings?.webhookEvents || {}); }
1126
+ toggleEvent(h: any, ev: string) { h.events = h.events.includes(ev) ? h.events.filter((x: string) => x !== ev) : [...h.events, ev]; }
1127
+ saveProSettings() {
1128
+ this.busy = true;
1129
+ const body = { ...this.ps, approvers: this.approversText.split(/[\s,;]+/).filter(Boolean), webhooks: (this.ps.webhooks || []).filter((h: any) => (h.url || '').trim()) };
1130
+ this.http.post<any>('/quotations/pro/settings', body).subscribe({
1131
+ next: r => {
1132
+ this.busy = false;
1133
+ if (r.errors?.length) this.notify.error(r.errors.join(' ')); else this.notify.success('Saved');
1134
+ this.loadProSettings();
1135
+ },
1136
+ error: e => { this.busy = false; this.notify.error(this.errMsg(e, 'Saving')); this.cdr.markForCheck(); },
1137
+ });
1138
+ }
1139
+ testWebhook(h: any) {
1140
+ this.busy = true;
1141
+ this.http.post<any>(`/quotations/webhooks/${h.id}/test`, {}).subscribe({
1142
+ next: r => { this.busy = false; r?.state === 'sent' ? this.notify.success(`Test delivered (HTTP ${r.code})`) : this.notify.error(`Test failed: ${r?.error || r?.state}`); this.loadWebhookLog(); },
1143
+ error: e => { this.busy = false; this.notify.error(this.errMsg(e, 'Webhooks')); this.cdr.markForCheck(); },
1144
+ });
1145
+ }
1146
+ loadWebhookLog() {
1147
+ this.http.get<any>('/quotations/webhooks/log').subscribe({ next: r => { this.webhookLog = r?.items || []; this.cdr.markForCheck(); }, error: () => undefined });
1148
+ }
1149
+ retryWebhook(l: any) {
1150
+ this.http.post<any>(`/quotations/webhooks/log/${l.id}/retry`, {}).subscribe({ next: () => setTimeout(() => this.loadWebhookLog(), 1500), error: e => this.notify.error(this.errMsg(e, 'Webhooks')) });
1151
+ }
1152
+ regenerateSecret() {
1153
+ if (!confirm('Regenerate the signing secret? Receivers must be updated with the new one.')) return;
1154
+ this.http.post<any>('/quotations/webhooks/secret/regenerate', {}).subscribe({ next: () => this.loadProSettings(), error: e => this.notify.error(this.errMsg(e, 'Webhooks')) });
1155
+ }
841
1156
 
842
1157
  /** 402 / licence errors read as one sentence; everything else as the server's message. */
843
1158
  errMsg(e: any, what: string): string {
@@ -925,15 +1240,9 @@ export class QuotationsComponent implements OnInit, OnDestroy {
925
1240
 
926
1241
  maxPage() { return this.list ? Math.max(1, Math.ceil(this.list.totalItems / this.list.perPage)) : 1; }
927
1242
 
928
- openPipeline(): number {
929
- const rows = this.stats?.byStatus || [];
930
- return rows.filter((r: any) => r.status === 'sent' || r.status === 'viewed')
931
- .reduce((s: number, r: any) => s + Number(r.value || 0), 0);
932
- }
933
-
934
1243
  openQuote(id: number) {
935
1244
  this.http.get<any>(`/quotations/quotes/${id}`).subscribe({
936
- next: q => { this.detail = q; this.cdr.markForCheck(); },
1245
+ next: q => { this.detail = q; this.loadQuoteExtras(id); this.cdr.markForCheck(); },
937
1246
  error: () => this.notify.error('Could not load the quote'),
938
1247
  });
939
1248
  }
@@ -1043,7 +1352,7 @@ export class QuotationsComponent implements OnInit, OnDestroy {
1043
1352
  customerCompany: q.customerCompany, customerPhone: q.customerPhone,
1044
1353
  notes: q.notes || '', internalNotes: q.internalNotes || '', terms: q.terms || '',
1045
1354
  vatRate: Number(q.vatRate), discountType: q.discountType, discountValue: Number(q.discountValue),
1046
- validityDays: 30, currency: q.currency || 'GBP',
1355
+ validityDays: Number(q.validityDays) || 30, currency: q.currency || 'GBP',
1047
1356
  preparedByName: q.preparedByName || this.me?.name || '', preparedByEmail: q.preparedByEmail || this.me?.email || '',
1048
1357
  lines: (q.lines || []).map((l: any) => ({
1049
1358
  productVariantId: l.productVariantId, sku: l.sku, description: l.description,