hvp-shared 6.84.0 → 6.85.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.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Client Billing Enums
3
+ *
4
+ * Enums for the client-facing billing portal where pet owners
5
+ * request CFDI income invoices for their veterinary visits.
6
+ */
7
+ /**
8
+ * Status of a client invoice request through the processing pipeline.
9
+ */
10
+ export declare enum ClientInvoiceStatus {
11
+ /** Request created, not yet processing */
12
+ pending = "pending",
13
+ /** Background job is running (lookup, CFDI build, stamping) */
14
+ processing = "processing",
15
+ /** CFDI stamped successfully, PDF/XML available */
16
+ stamped = "stamped",
17
+ /** Processing failed (see errorMessage) */
18
+ failed = "failed"
19
+ }
20
+ /**
21
+ * All ClientInvoiceStatus values as array (for dropdowns/filters)
22
+ */
23
+ export declare const CLIENT_INVOICE_STATUS_VALUES: ClientInvoiceStatus[];
24
+ /**
25
+ * ClientInvoiceStatus labels in Spanish (for UI)
26
+ */
27
+ export declare const CLIENT_INVOICE_STATUS_LABELS: Record<ClientInvoiceStatus, string>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /**
3
+ * Client Billing Enums
4
+ *
5
+ * Enums for the client-facing billing portal where pet owners
6
+ * request CFDI income invoices for their veterinary visits.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CLIENT_INVOICE_STATUS_LABELS = exports.CLIENT_INVOICE_STATUS_VALUES = exports.ClientInvoiceStatus = void 0;
10
+ /**
11
+ * Status of a client invoice request through the processing pipeline.
12
+ */
13
+ var ClientInvoiceStatus;
14
+ (function (ClientInvoiceStatus) {
15
+ /** Request created, not yet processing */
16
+ ClientInvoiceStatus["pending"] = "pending";
17
+ /** Background job is running (lookup, CFDI build, stamping) */
18
+ ClientInvoiceStatus["processing"] = "processing";
19
+ /** CFDI stamped successfully, PDF/XML available */
20
+ ClientInvoiceStatus["stamped"] = "stamped";
21
+ /** Processing failed (see errorMessage) */
22
+ ClientInvoiceStatus["failed"] = "failed";
23
+ })(ClientInvoiceStatus || (exports.ClientInvoiceStatus = ClientInvoiceStatus = {}));
24
+ /**
25
+ * All ClientInvoiceStatus values as array (for dropdowns/filters)
26
+ */
27
+ exports.CLIENT_INVOICE_STATUS_VALUES = Object.values(ClientInvoiceStatus);
28
+ /**
29
+ * ClientInvoiceStatus labels in Spanish (for UI)
30
+ */
31
+ exports.CLIENT_INVOICE_STATUS_LABELS = {
32
+ [ClientInvoiceStatus.pending]: "Pendiente",
33
+ [ClientInvoiceStatus.processing]: "Procesando",
34
+ [ClientInvoiceStatus.stamped]: "Facturada",
35
+ [ClientInvoiceStatus.failed]: "Error",
36
+ };
@@ -24,3 +24,5 @@ export * from './payroll-features.constants';
24
24
  export * from './inventory-session.enums';
25
25
  export * from './documentation.enums';
26
26
  export * from './settlement.enums';
27
+ export * from './client-billing.enums';
28
+ export * from './sat-income-invoice';
@@ -40,3 +40,5 @@ __exportStar(require("./payroll-features.constants"), exports);
40
40
  __exportStar(require("./inventory-session.enums"), exports);
41
41
  __exportStar(require("./documentation.enums"), exports);
42
42
  __exportStar(require("./settlement.enums"), exports);
43
+ __exportStar(require("./client-billing.enums"), exports);
44
+ __exportStar(require("./sat-income-invoice"), exports);
@@ -0,0 +1,95 @@
1
+ /**
2
+ * SAT Catalog Constants for CFDI Income Invoices (Facturas de Ingreso)
3
+ *
4
+ * Based on SAT catalogs for electronic invoicing (CFDI 4.0).
5
+ * These are specific to income invoices — payroll catalogs are in sat-catalogs.ts.
6
+ *
7
+ * @see SAT Catalogs: http://omawww.sat.gob.mx/tramitesyservicios/Paginas/anexo_20_version3-3.htm
8
+ */
9
+ /**
10
+ * SAT Fiscal Regime codes applicable to invoice receivers (clients).
11
+ * Broader set than payroll (which only uses 605/616).
12
+ */
13
+ export declare const SATClientFiscalRegime: {
14
+ readonly GeneralLaw: "601";
15
+ readonly LegalPersonsNonProfit: "603";
16
+ readonly SalariesAndWages: "605";
17
+ readonly LeaseIncome: "606";
18
+ readonly TaxIncorporation: "612";
19
+ readonly WithoutFiscalObligations: "616";
20
+ readonly BusinessActivityIncome: "621";
21
+ readonly SimplifiedTrust: "625";
22
+ readonly SimplifiedTrustLegal: "626";
23
+ };
24
+ export type SATClientFiscalRegimeCode = (typeof SATClientFiscalRegime)[keyof typeof SATClientFiscalRegime];
25
+ /**
26
+ * Fiscal regime labels in Spanish for client portal dropdowns
27
+ */
28
+ export declare const SAT_CLIENT_FISCAL_REGIME_LABELS: Record<SATClientFiscalRegimeCode, string>;
29
+ /**
30
+ * Fiscal regimes array for dropdowns
31
+ */
32
+ export declare const SAT_CLIENT_FISCAL_REGIMES_ARRAY: {
33
+ code: SATClientFiscalRegimeCode;
34
+ label: string;
35
+ }[];
36
+ /**
37
+ * SAT CFDI Use codes applicable to income invoices for veterinary services/products.
38
+ * Subset of the full catalog — only codes relevant to HVP clients.
39
+ */
40
+ export declare const SATCfdiUse: {
41
+ readonly GeneralExpenses: "G03";
42
+ readonly MedicalExpenses: "D01";
43
+ readonly NoFiscalEffect: "S01";
44
+ readonly PeriodicPayments: "CP01";
45
+ readonly Acquisitions: "G01";
46
+ };
47
+ export type SATCfdiUseCode = (typeof SATCfdiUse)[keyof typeof SATCfdiUse];
48
+ /**
49
+ * CFDI Use labels in Spanish for client portal dropdowns
50
+ */
51
+ export declare const SAT_CFDI_USE_LABELS: Record<SATCfdiUseCode, string>;
52
+ /**
53
+ * CFDI Use array for dropdowns
54
+ */
55
+ export declare const SAT_CFDI_USE_ARRAY: {
56
+ code: SATCfdiUseCode;
57
+ label: string;
58
+ }[];
59
+ /**
60
+ * SAT Payment Form codes.
61
+ * Maps from QVET payment methods to SAT-compliant codes.
62
+ */
63
+ export declare const SATPaymentForm: {
64
+ readonly Cash: "01";
65
+ readonly NominalCheck: "02";
66
+ readonly ElectronicTransfer: "03";
67
+ readonly CreditCard: "04";
68
+ readonly ElectronicWallet: "05";
69
+ readonly ElectronicMoney: "06";
70
+ readonly DigitalVouchers: "08";
71
+ readonly DebitCard: "28";
72
+ readonly ServiceCard: "29";
73
+ readonly ToBeDefined: "99";
74
+ };
75
+ export type SATPaymentFormCode = (typeof SATPaymentForm)[keyof typeof SATPaymentForm];
76
+ /**
77
+ * Payment form labels in Spanish
78
+ */
79
+ export declare const SAT_PAYMENT_FORM_LABELS: Record<SATPaymentFormCode, string>;
80
+ /**
81
+ * Maps QVET payment method strings to SAT payment form codes.
82
+ * QVET uses Spanish descriptors; SAT uses numeric codes.
83
+ *
84
+ * TODO: Validate actual QVET payment method strings from qvet_collection_details data.
85
+ */
86
+ export declare const QVET_PAYMENT_METHOD_TO_SAT: Record<string, SATPaymentFormCode>;
87
+ /**
88
+ * Default SAT payment form when QVET payment method is unknown
89
+ */
90
+ export declare const DEFAULT_SAT_PAYMENT_FORM: SATPaymentFormCode;
91
+ /**
92
+ * Resolves a QVET payment method string to SAT payment form code.
93
+ * Falls back to "99" (Por definir) if unknown.
94
+ */
95
+ export declare function resolvePaymentForm(qvetPaymentMethod: string): SATPaymentFormCode;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /**
3
+ * SAT Catalog Constants for CFDI Income Invoices (Facturas de Ingreso)
4
+ *
5
+ * Based on SAT catalogs for electronic invoicing (CFDI 4.0).
6
+ * These are specific to income invoices — payroll catalogs are in sat-catalogs.ts.
7
+ *
8
+ * @see SAT Catalogs: http://omawww.sat.gob.mx/tramitesyservicios/Paginas/anexo_20_version3-3.htm
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.DEFAULT_SAT_PAYMENT_FORM = exports.QVET_PAYMENT_METHOD_TO_SAT = exports.SAT_PAYMENT_FORM_LABELS = exports.SATPaymentForm = exports.SAT_CFDI_USE_ARRAY = exports.SAT_CFDI_USE_LABELS = exports.SATCfdiUse = exports.SAT_CLIENT_FISCAL_REGIMES_ARRAY = exports.SAT_CLIENT_FISCAL_REGIME_LABELS = exports.SATClientFiscalRegime = void 0;
12
+ exports.resolvePaymentForm = resolvePaymentForm;
13
+ // ============================================================================
14
+ // Fiscal Regime - Client (c_RegimenFiscal)
15
+ // ============================================================================
16
+ /**
17
+ * SAT Fiscal Regime codes applicable to invoice receivers (clients).
18
+ * Broader set than payroll (which only uses 605/616).
19
+ */
20
+ exports.SATClientFiscalRegime = {
21
+ GeneralLaw: "601",
22
+ LegalPersonsNonProfit: "603",
23
+ SalariesAndWages: "605",
24
+ LeaseIncome: "606",
25
+ TaxIncorporation: "612", // RIF (being phased out)
26
+ WithoutFiscalObligations: "616",
27
+ BusinessActivityIncome: "621",
28
+ SimplifiedTrust: "625", // RESICO Personas Físicas
29
+ SimplifiedTrustLegal: "626", // RESICO Personas Morales
30
+ };
31
+ /**
32
+ * Fiscal regime labels in Spanish for client portal dropdowns
33
+ */
34
+ exports.SAT_CLIENT_FISCAL_REGIME_LABELS = {
35
+ "601": "General de Ley Personas Morales",
36
+ "603": "Personas Morales con Fines no Lucrativos",
37
+ "605": "Sueldos y Salarios e Ingresos Asimilados a Salarios",
38
+ "606": "Arrendamiento",
39
+ "612": "Personas Físicas con Actividades Empresariales y Profesionales",
40
+ "616": "Sin obligaciones fiscales",
41
+ "621": "Incorporación Fiscal",
42
+ "625": "Régimen Simplificado de Confianza (Persona Física)",
43
+ "626": "Régimen Simplificado de Confianza (Persona Moral)",
44
+ };
45
+ /**
46
+ * Fiscal regimes array for dropdowns
47
+ */
48
+ exports.SAT_CLIENT_FISCAL_REGIMES_ARRAY = Object.entries(exports.SAT_CLIENT_FISCAL_REGIME_LABELS).map(([code, label]) => ({
49
+ code: code,
50
+ label: `${code} - ${label}`,
51
+ }));
52
+ // ============================================================================
53
+ // CFDI Use (c_UsoCFDI)
54
+ // ============================================================================
55
+ /**
56
+ * SAT CFDI Use codes applicable to income invoices for veterinary services/products.
57
+ * Subset of the full catalog — only codes relevant to HVP clients.
58
+ */
59
+ exports.SATCfdiUse = {
60
+ GeneralExpenses: "G03",
61
+ MedicalExpenses: "D01",
62
+ NoFiscalEffect: "S01",
63
+ PeriodicPayments: "CP01",
64
+ Acquisitions: "G01",
65
+ };
66
+ /**
67
+ * CFDI Use labels in Spanish for client portal dropdowns
68
+ */
69
+ exports.SAT_CFDI_USE_LABELS = {
70
+ G03: "Gastos en general",
71
+ D01: "Honorarios médicos, dentales y gastos hospitalarios",
72
+ S01: "Sin efectos fiscales",
73
+ CP01: "Pagos",
74
+ G01: "Adquisición de mercancías",
75
+ };
76
+ /**
77
+ * CFDI Use array for dropdowns
78
+ */
79
+ exports.SAT_CFDI_USE_ARRAY = Object.entries(exports.SAT_CFDI_USE_LABELS).map(([code, label]) => ({
80
+ code: code,
81
+ label: `${code} - ${label}`,
82
+ }));
83
+ // ============================================================================
84
+ // Payment Form (c_FormaPago)
85
+ // ============================================================================
86
+ /**
87
+ * SAT Payment Form codes.
88
+ * Maps from QVET payment methods to SAT-compliant codes.
89
+ */
90
+ exports.SATPaymentForm = {
91
+ Cash: "01",
92
+ NominalCheck: "02",
93
+ ElectronicTransfer: "03",
94
+ CreditCard: "04",
95
+ ElectronicWallet: "05",
96
+ ElectronicMoney: "06",
97
+ DigitalVouchers: "08",
98
+ DebitCard: "28",
99
+ ServiceCard: "29",
100
+ ToBeDefined: "99",
101
+ };
102
+ /**
103
+ * Payment form labels in Spanish
104
+ */
105
+ exports.SAT_PAYMENT_FORM_LABELS = {
106
+ "01": "Efectivo",
107
+ "02": "Cheque nominativo",
108
+ "03": "Transferencia electrónica de fondos",
109
+ "04": "Tarjeta de crédito",
110
+ "05": "Monedero electrónico",
111
+ "06": "Dinero electrónico",
112
+ "08": "Vales de despensa",
113
+ "28": "Tarjeta de débito",
114
+ "29": "Tarjeta de servicios",
115
+ "99": "Por definir",
116
+ };
117
+ /**
118
+ * Maps QVET payment method strings to SAT payment form codes.
119
+ * QVET uses Spanish descriptors; SAT uses numeric codes.
120
+ *
121
+ * TODO: Validate actual QVET payment method strings from qvet_collection_details data.
122
+ */
123
+ exports.QVET_PAYMENT_METHOD_TO_SAT = {
124
+ Efectivo: "01",
125
+ "Tarjeta de Crédito": "04",
126
+ "Tarjeta de Débito": "28",
127
+ Transferencia: "03",
128
+ "Tarjeta crédito": "04",
129
+ "Tarjeta débito": "28",
130
+ };
131
+ /**
132
+ * Default SAT payment form when QVET payment method is unknown
133
+ */
134
+ exports.DEFAULT_SAT_PAYMENT_FORM = "99";
135
+ /**
136
+ * Resolves a QVET payment method string to SAT payment form code.
137
+ * Falls back to "99" (Por definir) if unknown.
138
+ */
139
+ function resolvePaymentForm(qvetPaymentMethod) {
140
+ if (!qvetPaymentMethod)
141
+ return exports.DEFAULT_SAT_PAYMENT_FORM;
142
+ const normalized = qvetPaymentMethod.trim();
143
+ // Direct match
144
+ if (exports.QVET_PAYMENT_METHOD_TO_SAT[normalized]) {
145
+ return exports.QVET_PAYMENT_METHOD_TO_SAT[normalized];
146
+ }
147
+ // Case-insensitive partial match
148
+ const lc = normalized.toLowerCase();
149
+ if (lc.includes("efectivo"))
150
+ return "01";
151
+ if (lc.includes("crédito") || lc.includes("credito"))
152
+ return "04";
153
+ if (lc.includes("débito") || lc.includes("debito"))
154
+ return "28";
155
+ if (lc.includes("transferencia"))
156
+ return "03";
157
+ if (lc.includes("cheque"))
158
+ return "02";
159
+ return exports.DEFAULT_SAT_PAYMENT_FORM;
160
+ }
@@ -0,0 +1,2 @@
1
+ export * from './requests';
2
+ export * from './responses';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./requests"), exports);
18
+ __exportStar(require("./responses"), exports);
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Client Billing API - Request Types
3
+ *
4
+ * Request types for the client-facing billing portal endpoints.
5
+ *
6
+ * @see /api/client-billing/*
7
+ */
8
+ /**
9
+ * Register a new client account.
10
+ *
11
+ * @example POST /api/client-billing/auth/register
12
+ */
13
+ export interface RegisterClientRequest {
14
+ email: string;
15
+ password: string;
16
+ name: string;
17
+ }
18
+ /**
19
+ * Log in with email and password.
20
+ *
21
+ * @example POST /api/client-billing/auth/login
22
+ */
23
+ export interface LoginClientRequest {
24
+ email: string;
25
+ password: string;
26
+ }
27
+ /**
28
+ * Update client fiscal profile data.
29
+ * All fields optional — only provided fields are updated.
30
+ *
31
+ * @example PATCH /api/client-billing/profile
32
+ */
33
+ export interface UpdateClientProfileRequest {
34
+ name?: string;
35
+ rfc?: string;
36
+ businessName?: string;
37
+ fiscalRegime?: string;
38
+ postalCode?: string;
39
+ cfdiUse?: string;
40
+ }
41
+ /**
42
+ * Look up a ticket by albarán number and amount for verification.
43
+ * Amount is required as security measure (prevents facturing others' tickets).
44
+ *
45
+ * @example POST /api/client-billing/invoices/lookup
46
+ */
47
+ export interface LookupTicketRequest {
48
+ deliveryNoteNumber: number;
49
+ amount: number;
50
+ }
51
+ /**
52
+ * Request an invoice to be generated for a ticket.
53
+ * Uses fiscal data from the client's saved profile.
54
+ *
55
+ * @example POST /api/client-billing/invoices
56
+ */
57
+ export interface CreateClientInvoiceRequest {
58
+ deliveryNoteNumber: number;
59
+ amount: number;
60
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Client Billing API - Request Types
4
+ *
5
+ * Request types for the client-facing billing portal endpoints.
6
+ *
7
+ * @see /api/client-billing/*
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Client Billing API - Response Types
3
+ *
4
+ * Response types for the client-facing billing portal endpoints.
5
+ *
6
+ * @see /api/client-billing/*
7
+ */
8
+ import { ClientInvoiceStatus } from '../../constants/client-billing.enums';
9
+ /**
10
+ * Client account data returned after login/register.
11
+ *
12
+ * @example POST /api/client-billing/auth/login
13
+ */
14
+ export interface ClientAuthResponse {
15
+ token: string;
16
+ client: ClientProfileResponse;
17
+ }
18
+ /**
19
+ * Client profile with fiscal data.
20
+ *
21
+ * @example GET /api/client-billing/profile
22
+ */
23
+ export interface ClientProfileResponse {
24
+ id: string;
25
+ email: string;
26
+ name: string;
27
+ rfc?: string;
28
+ businessName?: string;
29
+ fiscalRegime?: string;
30
+ postalCode?: string;
31
+ cfdiUse?: string;
32
+ isProfileComplete: boolean;
33
+ createdAt: string;
34
+ }
35
+ /**
36
+ * Single line item within a ticket lookup or invoice.
37
+ */
38
+ export interface InvoiceLineItemResponse {
39
+ productName: string;
40
+ quantity: number;
41
+ unitPrice: number;
42
+ discount: number;
43
+ taxRate: number;
44
+ taxAmount: number;
45
+ total: number;
46
+ satProductCode?: string;
47
+ satUnitCode?: string;
48
+ }
49
+ /**
50
+ * Result of looking up a ticket by albarán number.
51
+ * Returned before the client confirms invoice creation.
52
+ *
53
+ * @example POST /api/client-billing/invoices/lookup
54
+ */
55
+ export interface TicketLookupResponse {
56
+ deliveryNoteNumber: number;
57
+ date: string;
58
+ customerName: string;
59
+ subtotal: number;
60
+ taxTotal: number;
61
+ total: number;
62
+ paymentMethod: string;
63
+ lineItems: InvoiceLineItemResponse[];
64
+ }
65
+ /**
66
+ * Client invoice summary for list views.
67
+ *
68
+ * @example GET /api/client-billing/invoices
69
+ */
70
+ export interface ClientInvoiceListItemResponse {
71
+ id: string;
72
+ deliveryNoteNumber: number;
73
+ date: string;
74
+ total: number;
75
+ status: ClientInvoiceStatus;
76
+ cfdiUuid?: string;
77
+ createdAt: string;
78
+ }
79
+ /**
80
+ * Full client invoice detail.
81
+ *
82
+ * @example GET /api/client-billing/invoices/:id
83
+ */
84
+ export interface ClientInvoiceDetailResponse {
85
+ id: string;
86
+ deliveryNoteNumber: number;
87
+ date: string;
88
+ customerName: string;
89
+ subtotal: number;
90
+ taxTotal: number;
91
+ total: number;
92
+ paymentMethod: string;
93
+ status: ClientInvoiceStatus;
94
+ cfdiUuid?: string;
95
+ facturamaId?: string;
96
+ errorMessage?: string;
97
+ lineItems: InvoiceLineItemResponse[];
98
+ createdAt: string;
99
+ updatedAt: string;
100
+ }
101
+ /**
102
+ * Processing status for polling during invoice generation.
103
+ *
104
+ * @example GET /api/client-billing/invoices/:id/status
105
+ */
106
+ export interface ClientInvoiceStatusResponse {
107
+ id: string;
108
+ status: ClientInvoiceStatus;
109
+ progress?: number;
110
+ message?: string;
111
+ errorMessage?: string;
112
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Client Billing API - Response Types
4
+ *
5
+ * Response types for the client-facing billing portal endpoints.
6
+ *
7
+ * @see /api/client-billing/*
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,3 +12,4 @@ export * from './cash-reconciliation';
12
12
  export * from './time-off-request';
13
13
  export * from './job';
14
14
  export * from './inventory-session';
15
+ export * from './client-billing';
@@ -28,3 +28,4 @@ __exportStar(require("./cash-reconciliation"), exports);
28
28
  __exportStar(require("./time-off-request"), exports);
29
29
  __exportStar(require("./job"), exports);
30
30
  __exportStar(require("./inventory-session"), exports);
31
+ __exportStar(require("./client-billing"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hvp-shared",
3
- "version": "6.84.0",
3
+ "version": "6.85.0",
4
4
  "description": "Shared types and utilities for HVP backend and frontend",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",