'pnl-settings-profit-cost-basis', 'description' => __('The gross margin, monthly operating costs and free-shipping threshold that the profit and loss reports calculate with.', 'ai-eshop-optimizer'), 'icon' => 'scale', 'title' => __('Profit and cost basis', 'ai-eshop-optimizer'), 'footer' => class_exists('\Rooster\Admin\States') ? \Rooster\Admin\States::save_button($form_id) : '', )); echo $open; $rows = \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-pnl-gross-margin', 'label' => __('Gross profit margin (%)', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('gross_margin', (string) round($margin), array('id' => 'aieo-pnl-gross-margin', 'type' => 'number', 'xs' => true, 'unit' => '%', 'min' => 1, 'max' => 99, 'step' => 1)), 'help' => __('Rough average gross margin on product sales (default 60). Used to estimate profit per order and the break-even free-shipping threshold in Results → Delivery Statistics.', 'ai-eshop-optimizer'), )); $rows .= \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-pnl-ops-cost', 'label' => __('Operations costs', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('ops_cost_monthly', (string) (float) $ops, array('id' => 'aieo-pnl-ops-cost', 'type' => 'number', 'short' => true, 'unit' => $sym . ' ' . __('/ month', 'ai-eshop-optimizer'), 'min' => 0, 'step' => 'any')), 'help' => __('Your fixed MONTHLY overhead — hosting, wages, tooling, everything EXCEPT ad spend (e.g. 8000). The ROI Wizard charges a prorated share against the report period (per-day rate × days in the range), so ROI reflects true business profit, not just revenue minus ad spend.', 'ai-eshop-optimizer'), )); $rows .= \Rooster\Admin\Ui::field_row(array( 'id' => 'aieo-pnl-free-ship', 'label' => __('Free-shipping threshold', 'ai-eshop-optimizer'), 'control' => \Rooster\Admin\Ui::input('free_ship_threshold', (string) (float) $fs, array('id' => 'aieo-pnl-free-ship', 'type' => 'number', 'short' => true, 'unit' => $sym, 'min' => 0, 'step' => 'any')), 'help' => __('Your CURRENT order-subtotal bar for free shipping (default 35). The Delivery Statistics “Free-ship ≥” column recommends raising it to this + (courier cost ÷ margin), so the extra turnover covers the courier cost you absorb.', 'ai-eshop-optimizer') . $fs_note, )); echo AIEO_DMM_UI::card_form('aieo_dmm_pnl_settings_save', $this->get_id(), $form_id, '
' . $rows . '
'); echo $close; } public function ajax_save() { AIEO_DMM::verify_ajax_request(); if (isset($_POST['gross_margin']) && $_POST['gross_margin'] !== '') { $m = (float) $_POST['gross_margin']; if ($m < 1) { $m = 1; } if ($m > 99) { $m = 99; } update_option(AIEO_DMM::GROSS_MARGIN_OPTION, $m, false); } if (isset($_POST['ops_cost_monthly']) && $_POST['ops_cost_monthly'] !== '') { $oc = (float) $_POST['ops_cost_monthly']; if ($oc < 0) { $oc = 0; } update_option(AIEO_DMM::OPS_COST_MONTHLY_OPTION, $oc, false); } if (isset($_POST['free_ship_threshold']) && $_POST['free_ship_threshold'] !== '') { $fs = (float) $_POST['free_ship_threshold']; if ($fs < 0) { $fs = 0; } update_option(AIEO_DMM::FREE_SHIP_THRESHOLD_OPTION, $fs, false); } wp_send_json_success(array( 'message' => __('Saved.', 'ai-eshop-optimizer'), 'gross_margin' => AIEO_DMM::get_gross_margin_pct(), 'ops_cost_monthly' => AIEO_DMM::get_ops_cost_monthly(), 'free_ship_threshold' => AIEO_DMM::get_free_shipping_threshold_option(), )); } }