@baack-software/baack-ts-crm 0.0.6 → 0.0.7

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.
package/src/sales.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  isCostInvoice,
6
6
  outstandingByAge,
7
7
  outstandingTotals,
8
+ overdueByDay,
8
9
  overdueTotals,
9
10
  paymentsByDay,
10
11
  paymentsReceived,
@@ -46,6 +47,8 @@ export interface SalesSummary {
46
47
  /** Draft invoices now, whenever drafted: not yet sent, so not in the other figures. */
47
48
  drafts: { count: number; totals: MoneyTotals };
48
49
  byDay: { day: string; totals: MoneyTotals }[];
50
+ /** What was overdue at the end of each day of the period (see `overdueByDay`). */
51
+ overdueByDay: { day: string; totals: MoneyTotals }[];
49
52
  byAge: { bucket: AgeBucket; totals: MoneyTotals }[];
50
53
  byMethod: { method: RemittanceMethod; totals: MoneyTotals }[];
51
54
  /** Invoices the business pays, apart from the sales figures above. */
@@ -150,6 +153,7 @@ export function salesSummary(
150
153
  return { count: drafts.length, totals: sum(drafts, (invoice) => invoice.total) };
151
154
  })(),
152
155
  byDay: paymentsByDay(remittances, range),
156
+ overdueByDay: overdueByDay(invoices, remittances, range, now),
153
157
  byAge: outstandingByAge(invoices, now),
154
158
  byMethod: paymentsByMethod(remittances, range),
155
159
  costs: {
package/src/store.ts CHANGED
@@ -15,7 +15,7 @@ import { leadsBySource, type SourceCount } from './leads.ts';
15
15
  import { addMoney, type MoneyTotals } from './money.ts';
16
16
  import { inRange, periodChange, previousRange, type DateRange } from './period.ts';
17
17
  import { dealCompany, dealOutcome, defaultPipeline, pipelineByStage, type StageSummary } from './pipeline.ts';
18
- import { paymentsByDay, paymentsReceived } from './invoices.ts';
18
+ import { isCostInvoice, overdueByDay, paymentsByDay, paymentsReceived } from './invoices.ts';
19
19
  import { salesRemittances, salesSummary, type SalesSummary } from './sales.ts';
20
20
  import { countsTowardsTarget, salesTarget, type SalesTarget } from './target.ts';
21
21
  import { timeline, type Timeline } from './timeline.ts';
@@ -424,6 +424,8 @@ export interface Dashboard {
424
424
  revenue: Compared<MoneyTotals> & { currencyCode: string | undefined };
425
425
  /** Payments received less refunds on each day of the period. */
426
426
  revenueByDay: { day: string; totals: MoneyTotals }[];
427
+ /** What customers owed past its due date at the end of each day of the period (see `overdueByDay`). */
428
+ overdueByDay: { day: string; totals: MoneyTotals }[];
427
429
  /** Leads created in each period. */
428
430
  newLeads: Compared<number>;
429
431
  /** Leads created in the period, counted and valued per day or week. */
@@ -453,12 +455,14 @@ export function selectDashboard(
453
455
  own?: ReadonlySet<string>,
454
456
  /** The user's chosen pipeline, for the pipeline card (see `defaultPipeline`). */
455
457
  chosenPipeline?: string,
458
+ now = new Date(),
456
459
  ): Dashboard {
457
460
  const before = previousRange(range);
458
461
  const { leads, deals, pipelines } = state;
459
462
  const shownPipeline = defaultPipeline(pipelines, deals, chosenPipeline);
460
463
  // Revenue is what customers paid: payments the business made on its costs aren't counted.
461
464
  const remittances = salesRemittances(state, own);
465
+ const salesInvoices = state.invoices.filter((invoice) => !isCostInvoice(invoice, own));
462
466
 
463
467
  const firstWins = new Map<string, string>();
464
468
  let openValue: MoneyTotals = {};
@@ -507,6 +511,7 @@ export function selectDashboard(
507
511
  change: revenueCurrency ? periodChange(current[revenueCurrency] ?? 0, previous[revenueCurrency] ?? 0) : undefined,
508
512
  },
509
513
  revenueByDay: paymentsByDay(remittances, range),
514
+ overdueByDay: overdueByDay(salesInvoices, remittances, range, now),
510
515
  newLeads: compare(
511
516
  count(leads, (lead) => lead.createdTimestamp, range),
512
517
  count(leads, (lead) => lead.createdTimestamp, before),