<?php

require_once dirname(__FILE__) . '/function/func_addorder.php';
session_start();
//session_destroy();
if ($_GET['p'] == "addProduct") {
    $idproduct_refunds = $_GET['idproduct_refunds'];
    $price_product_refunds = $_GET['price_product_refunds'];
    $idorder_ww = $_GET['idorder'];
    echo $idorder_ww;
    $getOrder = Gettotal_Order_Del($idorder_ww);
    $total_price_product_refunds = $getOrder['order_price_product_refunds'] - $price_product_refunds;
    echo $total_price_product_refunds;
    $idproductD = deleteProduct_Refunds($idproduct_refunds);
    $Edit = editTotal_order($idorder_ww, $total_price_product_refunds);
    echo "1";
} else {
    if ($_GET['p'] == "showUnit") {
        ?>
    <table class="table table-striped table-bordered table-hover text-center" id="dataTables-example">
        <thead>
            <tr>
                <th>ลำดับ</th>
                <th>ชื่อสินค้า</th>
                <th>ชื่อโรงงาน</th>
                <th>หน่วย</th>
                <th>จำนวน</th>
                <th>ราคาเปิด</th>
                <th>ต้นทุนลด%</th>
                <th>ขายลด%</th>
                <th>ขายเพิ่มสุทธิ</th>
<?php

require_once dirname(__FILE__) . '/function/func_addorder.php';
session_start();
$z = 1;
if ($_GET['p'] == "addProduct") {
    $idorder = $_GET['idorder'];
    $idUnit = $_GET['idUnit'];
    $productName = $_GET['productName'];
    $factoryName = $_GET['factoryName'];
    $AmountProduct = $_GET['AmountProduct'];
    $price = $_GET['price'];
    $total_price = $_GET['total_price'];
    $total_price_all = $_GET['total_price_all'] + $price * $AmountProduct;
    $diff = $_GET['diff'];
    $type_factory = $_GET['type_factory'];
    $idProduct = $productName;
    $amount = 1;
    $idunit = $products[$i]['idUnit'];
    $getDiff = getDiffBathaction($idProduct, $idUnit);
    foreach ($getDiff as $value) {
        $val_amount_unit = $value['amount_unit'];
        $val_price = $value['price_unit'];
        $amount = $val_amount_unit * $amount;
    }
    $idproduct = addProductRefunds($idorder, $idUnit, $AmountProduct, $price, $type_factory, $diff / $amount);
    $Edit = editTotal_order($idorder, $total_price_all);
    //header("location: ../edit_product_refunds.php");*/
    echo "1";
}