Nota Timbangan Generation
Relevant source files
The following files were used as context for generating this wiki page:
The Nota Timbangan Generation system is a critical component of the Outmanage outbound logistics platform. Its primary purpose is to generate official weighing receipts (weighbridge tickets) in PDF format after a product has been weighed during the shipment process. These receipts provide a legal and operational record of the gross, tare, and net weights of goods leaving the facility.
This module integrates deeply with the shipment weighing workflow, specifically handling the transformation of database weighing records into formatted documents. It ensures that any changes to orders—such as customer reassignments or quantity revisions—trigger a regeneration of the relevant PDF documents to maintain data integrity across physical and digital records.
Sources: CLAUDE.md:43-46, src/services/notaTimbanganPdfService.ts:1-10
System Architecture and Data Flow
The generation process is handled primarily by the notaTimbanganPdfService, which utilizes the pdfkit library to create small-format (receipt-sized) documents. The service is typically invoked by the deliveryOrderService or shipment-related weighing endpoints.
Weighing Workflow and PDF Trigger
When a shipment item reaches the COMPLETED status through a weighing action, the system creates a ShipmentChosenProductWeighing record. This record acts as the data source for the PDF generation.
Logic and Recalculation
A unique aspect of the generation logic is the handling of Bulk Weighing. If multiple delivery order items share a single weighing event, the service calculates the totalQuantity by filtering linked items that share the same shipmentChosenProductWeighingId.
Sources: src/services/notaTimbanganPdfService.ts:124-140
Document Structure and Specifications
The generated PDF is designed as a compact receipt with specific dimensions and metadata.
| Property | Value | Source |
|---|---|---|
| Size | [240, 320] (Points) | src/services/notaTimbanganPdfService.ts:65 |
| Margins | T:10, B:10, L:15, R:15 | src/services/notaTimbanganPdfService.ts:66-71 |
| Font | Helvetica / Helvetica-Bold | src/services/notaTimbanganPdfService.ts:80-81 |
| Storage Directory | src/public/nota-timbangan/ | src/services/notaTimbanganPdfService.ts:20 |
| Timezone | Asia/Jakarta (GMT+7) | src/services/notaTimbanganPdfService.ts:87-97 |
Information Fields
The document is divided into three primary sections:
- Header Info: Ticket Number, Time In/Out (formatted as
DD/MM/YY - HH:mm:ss). - Product Info: Vehicle Plate Number, Product Name, and Reference Code.
- Weight Data: Gross Weight, Tare Weight, and Net Weight (all in kg, formatted with Indonesian locale
id-ID).
Sources: src/services/notaTimbanganPdfService.ts:107-160
Data Models
The generation process relies on a complex hierarchy of included data from the Prisma schema.
Sources: prisma/schema.prisma:356-385
Lifecycle and Consistency Management
The system enforces document consistency through automatic regeneration triggers in src/services/deliveryOrderService.ts.
Trigger Events for Regeneration
- Customer Change: If a Delivery Order's customer is changed after weighing (e.g., during a correction), the old Nota Timbangan file is deleted via
fs.unlinkSync, and a new one is generated with updated customer details. - DO Revision: When quantities are revised post-weighing, the system scales weights proportionally and regenerates the PDF to reflect the new "Berat Bruto" and "Berat Netto".
Sources: src/services/deliveryOrderService.ts:512-535, src/services/deliveryOrderService.ts:705-725
File Storage Implementation
The system uses an asynchronous check to ensure the public directories exist before writing files.
// src/services/notaTimbanganPdfService.ts:23-36
const ensureDirectoriesExist = async () => {
if (!(await existsAsync(PUBLIC_DIR))) {
await mkdirAsync(PUBLIC_DIR, { recursive: true });
}
if (!(await existsAsync(NOTA_TIMBANGAN_DIR))) {
await mkdirAsync(NOTA_TIMBANGAN_DIR, { recursive: true });
}
};
Sources: src/services/notaTimbanganPdfService.ts:23-36
Summary
The Nota Timbangan Generation module provides the physical proof of weighing essential for outbound logistics. By automating the PDF creation through pdfkit and linking it to the database lifecycle of ShipmentChosenProductWeighing records, the system ensures that weighing data is always accurate, formatted correctly for Indonesian standards, and synchronized with any administrative changes to the underlying delivery orders.