Overview
The Sale data model represents service transactions and electronic invoices in MotorDesk. It integrates with Peru’s SUNAT (tax authority) system for electronic billing and tracks vehicle maintenance services.TypeScript Interface
Field Reference
Identification Fields
Unique identifier for the sale transactionFormat:
sale-XXX where XXX is a sequential numberExample: sale-001Reference to the branch where the sale was madeType: Foreign key to Branch modelExample:
branch-001Reference to the user who created the saleType: Foreign key to User modelExample:
user-001Customer & Vehicle Fields
Reference to the customer (invoice recipient)Type: Foreign key to Customer modelExample:
cust-001Note: Typically the vehicle owner, but can be differentReference to the vehicle being servicedType: Foreign key to Vehicle modelExample:
veh-001Reference to the driver who brought the vehicleType: Foreign key to Customer model (nullable)Example:
cust-002 or nullNote: Can be null if no driver is specifiedInvoice Fields (SUNAT)
Type of tax document (voucher type)Valid Values:
FACTURA- Invoice (for companies with RUC)BOLETA- Receipt (for individuals with DNI)NOTA_CREDITO- Credit noteNOTA_DEBITO- Debit note
FACTURADocument series identifierFormat: Alphanumeric series code assigned by SUNATExamples:
F001 (Factura), B002 (Boleta)Note: Series are configured per branch and document typeSequential document number within the seriesFormat: Zero-padded numeric string (typically 6 digits)Example:
000150, 000320Note: Auto-increments per seriesDate and time when the invoice was issuedFormat: ISO 8601 datetime stringExample:
2023-10-26T14:30:00ZFinancial Fields
Currency code for the transactionValid Values:
PEN- Peruvian Sol (default)USD- US Dollar
PENTotal amount before taxesType: Decimal number with 2 decimal placesExample:
122.88Calculation: Sum of all sale detail subtotalsIGV (Value Added Tax) amountType: Decimal number with 2 decimal placesExample:
22.12Calculation: subtotal * 0.18 (18% IGV rate in Peru)Total amount including taxesType: Decimal number with 2 decimal placesExample:
145.00Calculation: subtotal + igvVehicle Maintenance Fields
Odometer reading when vehicle arrived for serviceType: IntegerExample:
45000Note: Used to track vehicle mileage historyRecommended mileage for next serviceType: IntegerExample:
50000Calculation: kilometrajeIngreso + product.frecuenciaCambioKmSUNAT Integration Fields
Electronic invoice status with SUNATValid Values:
PENDIENTE- Pending submission to SUNATACEPTADO- Accepted by SUNATRECHAZADO- Rejected by SUNATERROR- Error during submission
ACEPTADOReference to another document (for credit/debit notes)Type: Foreign key to Sale model (nullable)Example:
sale-001 or nullNote: Required when tipoComprobante is NOTA_CREDITO or NOTA_DEBITOReason for credit/debit noteType: Text description (nullable)Example:
"Devolución parcial de productos" or nullNote: Required when tipoComprobante is NOTA_CREDITO or NOTA_DEBITOSystem Fields
Timestamp when the sale record was createdFormat: ISO 8601 datetime stringExample:
2023-10-26T14:30:00ZTimestamp of last synchronization with SUNATFormat: ISO 8601 datetime string or nullExample:
2023-10-26T14:31:00Z or nullNote: Null indicates the document hasn’t been synced with SUNAT yetSoft delete flagDefault:
falseNote: Sales are soft-deleted to maintain audit trailRelationships
Sale Details (Line Items)
Sale Details (Line Items)
Each sale has multiple line items (sale details) that specify products, quantities, and prices.
Customer
Customer
The customer who receives the invoice (usually the vehicle owner).
Vehicle
Vehicle
The vehicle being serviced in this transaction.
Driver (Chofer)
Driver (Chofer)
The driver who brought the vehicle for service (optional).
Branch
Branch
The business location where the sale was made.
User
User
The employee who processed the sale.
Referenced Document
Referenced Document
For credit/debit notes, reference to the original document.
Example Data
Invoice (Factura) - Accepted by SUNAT
Receipt (Boleta) - Pending SUNAT Submission
Business Logic
IGV Calculation
Peru’s Value Added Tax (IGV) is 18% and must be calculated correctly:Document Series Generation
Next Service Calculation
SUNAT Status Updates
Electronic Billing Flow
- Sale is created with
estadoSunat: "PENDIENTE" - Document is submitted to SUNAT via API
- Status updates to
"ACEPTADO"or"RECHAZADO" - If accepted,
syncedAttimestamp is recorded - System generates PDF and XML for the customer
Validation Rules
Data Storage
Mock Data Location
/src/data/mock/sales.tsTypeScript export with sample sale dataJSON Data Location
/src/data/json/sales.jsonRaw JSON array of sale objectsRelated Models
- Customers - Invoice recipients
- Vehicles - Vehicles being serviced
- Products - Items sold in the transaction
- Sale Details - Line items for each sale (linked via
saleId)
