Pricing & Cost Calculation
Relevant source files
The following files were used as context for generating this wiki page:
The Pricing & Cost Calculation system in Duplicator is responsible for determining the unit and total costs of print jobs based on machine type (duplicator vs. photocopier), consumables used (ink, toner, masters), and paper formats (A3, A4). It provides a management interface for administrators to set pack prices and unit rates, while automatically calculating real-time costs for users during the print recording process.
The system distinguishes between "calculated prices" (derived from historical consumable consumption) and "used prices" (manually set by administrators). This allows the collective to adjust rates based on actual wear and tear while maintaining a stable billing price for users.
Sources: app/view/admin.prix.html.php, app/models/tirage_multimachines_good.php:127-142
Architecture and Data Flow
The pricing logic is split between server-side PHP for persistence and calculation, and client-side JavaScript for real-time UI updates. Data is primarily stored in the prix and papier tables of the SQLite database.
Core Calculation Flow
The following diagram illustrates how the system determines the cost of a print run:
The system uses the get_price() function to retrieve the current rates for all machines and paper types from the database.
Sources: app/models/tirage_multimachines_good.php:258, app/view/tirage_multimachines.html.php:688-695
Cost Components
Costs are categorized into three main pillars: Consumables, Paper, and Machine-specific overheads (drums and developers).
Consumables Calculation
- Duplicators: Costs are calculated based on the number of masters used and the number of "passages" (ink impressions). Each duplicator can have multiple drums (e.g.,
tambour_noir,tambour_rouge) with distinct unit prices. - Photocopiers: Costs depend on the ink type (Inkjet like ComColor vs. Laser Toner like Konica). For color prints, the system sums the unit costs of all individual colors (CMYK or specialized inks).
| Component | Logic | Source |
|---|---|---|
| Master | nb_masters * unit_price | app/models/tirage_multimachines_good.php:336 |
| Passage | nb_passages * unit_price | app/models/tirage_multimachines_good.php:337 |
| Toner/Ink | nb_pages * (color1_unit + color2_unit ...) | app/models/tirage_multimachines_good.php:133-142 |
| Paper | nb_sheets * paper_unit_price | app/models/tirage_multimachines_good.php:338 |
Format Adjustments
The system treats A3 as the standard base unit. For A4 prints:
- Masters and Passages: The cost is divided by 2 compared to A3.
- Ink/Toner: The per-page cost is divided by 2.
- Paper: The A4 sheet price is stored as exactly half of the A3 price.
Sources: app/models/tirage_multimachines_good.php:116, app/view/admin.prix.html.php:171
Photocopier Pricing Logic
Photocopier pricing is more complex than duplicators because it involves fill rates and specialized maintenance parts (drums/developers).
Logic by Machine Type
The calculatePageCost function identifies the machine technology to apply the correct pricing model:
Fill Rate Multiplier
For color photocopiers, the system can adjust the cost based on a fill rate (density of ink on the page).
- Standard: 50% fill rate is a multiplier of 1.0.
- Custom: Multiplier =
(fill_rate / 0.5). Thus, 100% fill rate doubles the consumable cost.
Sources: app/view/tirage_multimachines.html.php:306-307, app/tests/Unit/TiragePricingTest.php:21-25
Administration and Maintenance
The PriceManager class manages the persistence of these rates. It allows administrators to input "Pack Prices" (purchase cost of a box of ink or masters) and "Unit Prices" (the price billed to the user per unit).
Key Functions
insertPrice($machine, $type, $prix_pack, $prix_unite): Updates the consumable price for a specific machine.insertPapier($prix_a4): Sets the A4 paper price and automatically sets the A3 price to$prix_a4 * 2.get_price(): A global helper function that fetches all pricing data, mapping it into a structured array indexed by machine key (e.g.,dupli_1,photocop_2).
Sources: app/models/admin/PriceManager.php, app/controler/functions/pricing.php
Admin Table Data Structure
The admin.prix view displays a comparison between historical performance and current pricing:
| Column | Description |
|---|---|
| Prix Calculé | Purchase Pack Price / Historical Average Yield |
| Prix Utilisé | The actual unit price currently being charged to users. |
| Prix à l'Achat | The cost recorded for the last pack purchase. |
| Sources: app/view/admin.prix.html.php:57-61 |
Conclusion
The Pricing & Cost Calculation system provides a flexible framework for managing the expenses of a print collective. By decoupling purchasing costs from user billing and providing automatic adjustments for A4 formats and fill rates, it ensures that the collective can remain financially sustainable while offering transparent pricing to its members.