<?php

require "global.ajax.php";
// https://evopos.dev/ajax/create-sale-type.php/go=ruta?ent[]=1&ent[]=2&ent[]=3&ent[]=4&ent[]=5&ent[]=6&ent[]=7&ent[]=8

$valores = array_values($_GET);

foreach ($valores as $valor) {
    if (is_array($valor)) {
        foreach ($valor as $entId) {

            $query = "SELECT pos_id,pos_business_category FROM tb_pos WHERE pos_ent_id = '{$entId}';";
            $result = executePDOFetchAll($query);
            // var_dump($result);

            if (is_array($result)) {
                foreach ($result as $posCategory) {

                    if ($posCategory['pos_business_category'] == "Restaurant") {

                        $sqlPosCategory = "INSERT INTO tb_sale_type (sale_type_ent_id,sale_type_pos_id,sale_type_created_by,sale_type_name,sale_type_tax,sale_type_tax_law,sale_type_add_tax) VALUES 
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Local', 'Yes', 'Yes', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Take Away', 'Yes', 'No', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Delivery', 'Yes', 'No', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Pedidos Ya', 'Yes', 'No', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Uber Eats', 'Yes', 'No', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Didi Food', 'Yes', 'No', 0.00);";
                    }

                    if ($posCategory['pos_business_category'] == "Nightclub") {

                        $sqlPosCategory = "INSERT INTO tb_sale_type (sale_type_ent_id,sale_type_pos_id,sale_type_created_by,sale_type_name,sale_type_tax,sale_type_tax_law,sale_type_add_tax) VALUES 
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Local', 'Yes', 'Yes', 0.00);";
                    }

                    if ($posCategory['pos_business_category'] == "Others") {

                        $sqlPosCategory = "INSERT INTO tb_sale_type (sale_type_ent_id,sale_type_pos_id,sale_type_created_by,sale_type_name,sale_type_tax,sale_type_tax_law,sale_type_add_tax) VALUES 
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Local', 'Yes', 'Yes', 0.00),
                        ('{$entId}','{$posCategory['pos_id']}', 6, 'Delivery', 'Yes', 'No', 0.00);";
                    }

                    $resPosCategory = executeQueryPDOApi($sqlPosCategory, "Saved", "Sale Type");
                    var_dump($resPosCategory);
                }
            } else {
                echo "No Array <br>";
                echo $result;
            }
        }
    }
}
