[
‘sliding_door’ => [
‘name’ => ‘🚪 Sliding Door’,
‘icon’ => ‘🚪’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (60mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 6.5],
‘glass’ => [‘material’ => ‘Tempered Glass (5mm)’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 2.1],
‘roller’ => [‘material’ => ‘Stainless Steel Roller’, ‘unit’ => ‘pieces’, ‘per_unit’ => 4],
‘handle’ => [‘material’ => ‘Aluminum Handle’, ‘unit’ => ‘pieces’, ‘per_unit’ => 2],
‘lock’ => [‘material’ => ‘Multi-point Lock’, ‘unit’ => ‘sets’, ‘per_unit’ => 1],
‘weatherstrip’ => [‘material’ => ‘Weatherstrip Seal’, ‘unit’ => ‘meters’, ‘per_unit’ => 8.2],
‘screw’ => [‘material’ => ‘Stainless Screws’, ‘unit’ => ‘boxes’, ‘per_unit’ => 0.5],
]
],
‘hinged_door’ => [
‘name’ => ‘🚪 Hinged Door’,
‘icon’ => ‘🚪’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (50mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 5.8],
‘glass’ => [‘material’ => ‘Tempered Glass (4mm)’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 1.9],
‘hinge’ => [‘material’ => ‘Heavy Duty Hinge’, ‘unit’ => ‘pieces’, ‘per_unit’ => 3],
‘handle’ => [‘material’ => ‘Door Handle Set’, ‘unit’ => ‘pieces’, ‘per_unit’ => 1],
‘lock’ => [‘material’ => ‘Mortise Lock’, ‘unit’ => ‘sets’, ‘per_unit’ => 1],
‘weatherstrip’ => [‘material’ => ‘Rubber Seal’, ‘unit’ => ‘meters’, ‘per_unit’ => 6.4],
‘screw’ => [‘material’ => ‘Frame Screws’, ‘unit’ => ‘boxes’, ‘per_unit’ => 0.3],
]
],
‘french_door’ => [
‘name’ => ‘🚪 French Door’,
‘icon’ => ‘🚪’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (70mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 7.2],
‘glass’ => [‘material’ => ‘Double Glazed Glass’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 2.4],
‘hinge’ => [‘material’ => ‘Decorative Hinge’, ‘unit’ => ‘pieces’, ‘per_unit’ => 4],
‘handle’ => [‘material’ => ‘French Door Handle’, ‘unit’ => ‘pieces’, ‘per_unit’ => 2],
‘lock’ => [‘material’ => ‘Multi-point Lock System’, ‘unit’ => ‘sets’, ‘per_unit’ => 1],
‘weatherstrip’ => [‘material’ => ‘Magnetic Seal’, ‘unit’ => ‘meters’, ‘per_unit’ => 9.5],
‘screw’ => [‘material’ => ‘Stainless Steel Screws’, ‘unit’ => ‘boxes’, ‘per_unit’ => 0.6],
]
]
],
‘windows’ => [
‘sliding_window’ => [
‘name’ => ‘🪟 Sliding Window’,
‘icon’ => ‘🪟’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (45mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 4.8],
‘glass’ => [‘material’ => ‘Clear Glass (4mm)’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 1.5],
‘roller’ => [‘material’ => ‘Nylon Roller’, ‘unit’ => ‘pieces’, ‘per_unit’ => 4],
‘handle’ => [‘material’ => ‘Window Handle’, ‘unit’ => ‘pieces’, ‘per_unit’ => 1],
‘lock’ => [‘material’ => ‘Window Lock’, ‘unit’ => ‘pieces’, ‘per_unit’ => 1],
‘weatherstrip’ => [‘material’ => ‘Fiber Brush Seal’, ‘unit’ => ‘meters’, ‘per_unit’ => 5.6],
‘track’ => [‘material’ => ‘Aluminum Track’, ‘unit’ => ‘meters’, ‘per_unit’ => 2.2],
]
],
‘casement_window’ => [
‘name’ => ‘🪟 Casement Window’,
‘icon’ => ‘🪟’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (40mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 5.2],
‘glass’ => [‘material’ => ‘Tempered Glass (4mm)’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 1.3],
‘hinge’ => [‘material’ => ‘Friction Hinge’, ‘unit’ => ‘pieces’, ‘per_unit’ => 2],
‘handle’ => [‘material’ => ‘Casement Handle’, ‘unit’ => ‘pieces’, ‘per_unit’ => 1],
‘lock’ => [‘material’ => ‘Multi-point Lock’, ‘unit’ => ‘sets’, ‘per_unit’ => 1],
‘weatherstrip’ => [‘material’ => ‘EPDM Seal’, ‘unit’ => ‘meters’, ‘per_unit’ => 4.8],
‘screw’ => [‘material’ => ‘Frame Screws’, ‘unit’ => ‘boxes’, ‘per_unit’ => 0.4],
]
],
‘fixed_window’ => [
‘name’ => ‘🪟 Fixed Window’,
‘icon’ => ‘🪟’,
‘raw_materials’ => [
‘frame’ => [‘material’ => ‘Aluminum Frame (35mm)’, ‘unit’ => ‘meters’, ‘per_unit’ => 3.5],
‘glass’ => [‘material’ => ‘Float Glass (4mm)’, ‘unit’ => ‘sq meters’, ‘per_unit’ => 1.2],
‘sealant’ => [‘material’ => ‘Silicone Sealant’, ‘unit’ => ‘tubes’, ‘per_unit’ => 0.8],
‘gasket’ => [‘material’ => ‘Glass Gasket’, ‘unit’ => ‘meters’, ‘per_unit’ => 4.2],
‘screw’ => [‘material’ => ‘Fixing Screws’, ‘unit’ => ‘boxes’, ‘per_unit’ => 0.2],
]
]
]
];
public function calculateMaterials($doorSelections, $windowSelections) {
$results = [
‘doors’ => [],
‘windows’ => [],
‘summary’ => []
];
$allMaterials = [];
// Calculate door materials
foreach ($doorSelections as $type => $quantity) {
if ($quantity > 0 && isset($this->products[‘doors’][$type])) {
$product = $this->products[‘doors’][$type];
$results[‘doors’][$type] = [
‘name’ => $product[‘name’],
‘icon’ => $product[‘icon’],
‘quantity’ => $quantity,
‘materials’ => []
];
foreach ($product[‘raw_materials’] as $key => $material) {
$total = $material[‘per_unit’] * $quantity;
$results[‘doors’][$type][‘materials’][$key] = [
‘material’ => $material[‘material’],
‘unit’ => $material[‘unit’],
‘per_unit’ => $material[‘per_unit’],
‘total’ => round($total, 2)
];
// Add to summary
$materialKey = $material[‘material’];
if (!isset($allMaterials[$materialKey])) {
$allMaterials[$materialKey] = [
‘material’ => $material[‘material’],
‘unit’ => $material[‘unit’],
‘total’ => 0
];
}
$allMaterials[$materialKey][‘total’] += $total;
}
}
}
// Calculate window materials
foreach ($windowSelections as $type => $quantity) {
if ($quantity > 0 && isset($this->products[‘windows’][$type])) {
$product = $this->products[‘windows’][$type];
$results[‘windows’][$type] = [
‘name’ => $product[‘name’],
‘icon’ => $product[‘icon’],
‘quantity’ => $quantity,
‘materials’ => []
];
foreach ($product[‘raw_materials’] as $key => $material) {
$total = $material[‘per_unit’] * $quantity;
$results[‘windows’][$type][‘materials’][$key] = [
‘material’ => $material[‘material’],
‘unit’ => $material[‘unit’],
‘per_unit’ => $material[‘per_unit’],
‘total’ => round($total, 2)
];
// Add to summary
$materialKey = $material[‘material’];
if (!isset($allMaterials[$materialKey])) {
$allMaterials[$materialKey] = [
‘material’ => $material[‘material’],
‘unit’ => $material[‘unit’],
‘total’ => 0
];
}
$allMaterials[$materialKey][‘total’] += $total;
}
}
}
// Round summary totals
foreach ($allMaterials as &$material) {
$material[‘total’] = round($material[‘total’], 2);
}
$results[‘summary’] = $allMaterials;
return $results;
}
public function getProducts() {
return $this->products;
}
}
// Initialize estimator
$estimator = new AluminumEstimator();
$products = $estimator->getProducts();
// Handle form submission
$results = null;
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’ && isset($_POST[‘calculate’])) {
$doorSelections = [];
$windowSelections = [];
// Get door quantities
foreach ($products[‘doors’] as $type => $product) {
$doorSelections[$type] = isset($_POST[‘door_’ . $type]) ? max(0, (int)$_POST[‘door_’ . $type]) : 0;
}
// Get window quantities
foreach ($products[‘windows’] as $type => $product) {
$windowSelections[$type] = isset($_POST[‘window_’ . $type]) ? max(0, (int)$_POST[‘window_’ . $type]) : 0;
}
$results = $estimator->calculateMaterials($doorSelections, $windowSelections);
}
?>