<?php

// Created by Ilhomjon on 06.03.2021
header('Content-type: text/html; charset=UTF-8');
require "connect.php";


$sql_kk = "";
$sklad_id = $_GET['sklad_id'];
if($sklad_id !== null && $sklad_id != ""){
    $sql_skk = "WHERE sklad_id = '$sklad_id' AND qoldiq > 0";
} else {
    $sql_skk = "WHERE sklad_id = '0' OR sklad_id = '' OR sklad_id = '000000001'";
}

$sql = "SELECT Id, gruppa_id, tovar_id, nomi, valyuta_turi, kirim_narxi_som, kirim_narxi_val, sotish_narxi_chakana_som, sotish_narxi_chakana_val, sotish_narxi_per_som, sotish_narxi_per_val, blokdagi_soni, qoldiq, can_narx, time, rasmi, tartibi FROM tovarlar $sql_skk";

mysqli_set_charset($conn,"utf8");
$result = mysqli_query($conn,"SET NAMES utf8");

$result = mysqli_query($conn, $sql);

$count=1;

$list_tovarlar = array();

if ($result !== false && $result->num_rows > 0) {
    while($row=mysqli_fetch_array($result)){

        $gruppa_id=$row['gruppa_id'];
        $tovar_id=$row['tovar_id'];
        $nomi=$row['nomi'];
        $valyuta_turi=$row['valyuta_turi'];
        $kirim_narxi_som=$row['kirim_narxi_som'];
        $kirim_narxi_val=$row['kirim_narxi_val'];
        $sotish_narxi_chakana_som=$row['sotish_narxi_chakana_som'];
        $sotish_narxi_chakana_val=$row['sotish_narxi_chakana_val'];
        $sotish_narxi_per_som=$row['sotish_narxi_per_som'];
        $sotish_narxi_per_val=$row['sotish_narxi_per_val'];
        $blokdagi_soni=$row['blokdagi_soni'];
        $qoldiq=$row['qoldiq'];
        $can_narx=$row['can_narx'];
		$time=$row['time'];
		$rasmi=$row['rasmi'];
	    $tartibi=$row['tartibi'];

		$nomi = str_replace('"', '`', $nomi);

         array_push($list_tovarlar,
            array(
                    'gruppa_id' => $gruppa_id,
                    'tovar_id' => $tovar_id,
                    'nomi' => $nomi,
                    'valyuta_turi' => $valyuta_turi,
                    'kirim_narxi_som' => $kirim_narxi_som,
                    'kirim_narxi_val' => $kirim_narxi_val,
                    'sotish_narxi_chakana_som' => $sotish_narxi_chakana_som,
                    'sotish_narxi_chakana_val' => $sotish_narxi_chakana_val,
                    'sotish_narxi_per_som' => $sotish_narxi_per_som,
                    'sotish_narxi_per_val' => $sotish_narxi_per_val,
                    'blokdagi_soni' => $blokdagi_soni,
                    'qoldiq' => $qoldiq,
                    'can_narx' => $can_narx,
                    'time' => $time,
                    'rasmi'=> $rasmi,
                    'tartibi'=> $tartibi
                 )
                );

		$count++;
	}

}

echo json_encode($list_tovarlar);
$conn->close();
?>
