<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } if (!function_exists('safeDecryptPrice')) { } function renderPricingEditor(array $listing): string { $price = safeDecryptPrice($listing["price"] ?? "0"); $salePrice = $listing["sale_price"] ? safeDecryptPrice($listing["sale_price"]) : ""; $unitLabel = $listing["unit_label"] ? safeDecryptPrice($listing["unit_label"]) : "g"; $unitInc = $listing["unit_increment"] ? safeDecryptPrice($listing["unit_increment"]) : "1"; $unitMin = $listing["unit_min"] ? safeDecryptPrice($listing["unit_min"]) : "1"; $unitPricePer = $listing["unit_price_per"] ? safeDecryptPrice($listing["unit_price_per"]) : "0"; $unitTiers = $listing["unit_tiers"] ? safeDecryptPrice($listing["unit_tiers"]) : "[]"; $unitActive = ((int)($listing["unit_pricing_code"] ?? 0) === 6030); $html = "<div class=\"pricing-editor\"><span class=\"section-label\">Pricing</span>"; $html .= UI::field("listing-price", "Base Price (CAD)", "number", $price, ["step" => "0.01", "min" => "0"]); $html .= UI::field("listing-sale_price", "Sale Price", "number", $salePrice, ["step" => "0.01", "min" => "0"]); $html .= "<div class=\"form-group\"><span>Unit Pricing</span><select id=\"listing-unit_pricing_code\" class=\"form-group input\"><option value=\"6031\"" . (!$unitActive ? " selected" : "") . ">Disabled</option><option value=\"6030\"" . ($unitActive ? " selected" : "") . ">Enabled</option></select></div>"; $html .= UI::field("listing-unit_label", "Unit Label", "text", $unitLabel); $html .= UI::field("listing-unit_increment", "Increment", "number", $unitInc, ["step" => "0.1"]); $html .= UI::field("listing-unit_min", "Minimum", "number", $unitMin, ["step" => "0.1"]); $html .= UI::field("listing-unit_price_per", "Price Per Unit", "number", $unitPricePer, ["step" => "0.01"]); $html .= "<div class=\"form-group\"><span>Tier Pricing (JSON)</span><input id=\"listing-unit_tiers\" class=\"form-group input\" type=\"text\" value=\"" . UI::e($unitTiers) . "\"></div></div>"; return $html; } 