<?php
require_once "../models/Operations.php";

$sql = "SELECT pos_id,pos_ent_id FROM tb_pos;";
$posInfo = executePDOFetchAll($sql);

$sqlPaymentValues = "";

foreach ($posInfo as $pos) {

    // IF EXISTE MORE DATA TO SAVE ADD A COMA TO THE SECOND ROW
    if (!empty(trim((string) $sqlPaymentValues))) {
        $sqlPaymentValues .= ", ";
    }

    $sqlPaymentValues .= "('{$pos['pos_ent_id']}', '{$pos['pos_id']}', '6', 'CASH'),
    ('{$pos['pos_ent_id']}', '{$pos['pos_id']}', '6', 'CREDIT CARD'),
    ('{$pos['pos_ent_id']}', '{$pos['pos_id']}', '6', 'BANK DEPOSIT'),
    ('{$pos['pos_ent_id']}', '{$pos['pos_id']}', '6', 'CASHBACK')";
}

$sqlQueryPosPaymentType = "INSERT INTO tb_payments_type (
    pay_type_ent_id
    ,pay_type_pos_id
    ,pay_type_created_by
    ,pay_type_name )
VALUES
" . $sqlPaymentValues;

$sqlUpdateSaleType = "UPDATE tb_sale_type SET sale_type_status = 'Disabled' WHERE sale_type_name = 'Without Taxes';";
executeQueryPDO($sqlUpdateSaleType);

$answer = executeQueryPDOApi($sqlQueryPosPaymentType, "Saved", "BRANCHES PAYMENT TYPE");
var_dump($answer);
