Overview
The Quotation model represents construction project quotations with a complex nested structure. It includes factory information, financial calculations, and a hierarchical organization of sections and items. This model is designed to handle detailed cost breakdowns for construction projects.Schema Definition
The Quotation model uses Mongoose with pagination support through themongoose-paginate-v2 plugin. It features nested subdocuments for sections and items.
Source Location
src/models/quotation.js
Top-Level Fields
Name or identifier of the factory or manufacturing facility associated with the quotation.Constraints:
- Required: Yes
Fixed reference or identifier for the quotation.Constraints:
- Required: Yes
Detailed description of the quotation, including project overview and scope.Constraints:
- Required: Yes
Base cost before additional charges and taxes.Constraints:
- Required: Yes
Contingency amount for unexpected costs or changes.Constraints:
- Required: Yes
VAT (Value Added Tax) or IVA amount.Constraints:
- Required: Yes
Administrative costs and overhead.Constraints:
- Required: Yes
Profit margin or utility percentage.Constraints:
- Required: Yes
Final total price including all costs, fees, and taxes.Constraints:
- Required: Yes
Nested Structure
Sections Array
Array of section objects representing different phases or areas of the construction project.
Plugins
mongoose-paginate-v2
The Quotation schema includes themongoose-paginate-v2 plugin for efficient pagination of quotation queries.
Enabled Methods:
Quotation.paginate(query, options)- Paginated query with customizable page size and sorting
Example Document
Validation Rules
Hierarchical Structure
The Quotation model follows a three-level hierarchy:Usage Examples
Creating a New Quotation
Querying with Pagination
Accessing Nested Data
Calculation Notes
Price Calculations: The schema stores calculated values like
item_total, section_price, and total_price. Ensure these are properly calculated before saving:item_total=quantity×item_valuesection_price= sum of allitem_totalin that sectiontotal_price=subtotal+unexpected+iva+administratitive+utility
Typo Notice: The field name
administratitive appears to be a typo of “administrative”. This is preserved from the source schema but should be noted for potential future refactoring.Related Models
- User: Quotations may be associated with users who created or are responsible for them
Best Practices
- Data Consistency: Always validate that calculated fields match the sum of their components
- Nested Updates: Use Mongoose subdocument methods when updating sections or items
- Indexing: Consider adding indexes on
factoryandfixfields for faster queries - Validation: Implement custom validators to ensure at least one section exists in meaningful quotations