<?php
require_once "../../includes/db.php";

$id              = $_POST['id'];
$name            = $_POST['product_name_edit'];
$sku             = $_POST['sku_edit'];
$product_type    = $_POST['product_type_edit'];
$status          = $_POST['status_edit'];
$category_id     = $_POST['category_id_edit'];
$sales_rep       = $_POST['sales_rep_edit'];
$rep_sort        = $_POST['rep_sort_edit'];
$selling_price   = $_POST['selling_price_edit'];
$sale_comm       = $_POST['sale_comm_edit'];
$sale_tax_rate   = $_POST['sale_tax_rate_edit'];
$admin_comm      = $_POST['admin_comm_edit'];
$prch_price      = $_POST['prch_price_edit'];
$prch_comm       = $_POST['prch_comm_edit'];
$prch_tax_rate   = $_POST['prch_tax_rate_edit'];
$margin          = $_POST['margin_edit'];

$stmt = $pdo->prepare("
    UPDATE products 
    SET p_name = ?, 
        sku = ?, 
        pdt_type = ?, 
        status = ?, 
        pdt_categ = ?, 
        sale_count = ?, 
        reporting_order = ?, 
        p_sale_px = ?, 
        sale_comm = ?, 
        sale_vat = ?, 
        admin_fee = ?, 
        p_prch_px = ?, 
        prch_comm = ?, 
        inp_vat = ?, 
        margin = ?
    WHERE id = ?
");

$stmt->execute([
    $name,
    $sku,
    $product_type,
    $status,
    $category_id,
    $sales_rep,
    $rep_sort,
    $selling_price,
    $sale_comm,
    $sale_tax_rate,
    $admin_comm,
    $prch_price,      // ✅ fixed
    $prch_comm,
    $prch_tax_rate,
    $margin,
    $id
]);

echo "success";
exit;