<?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){
    $sql_skk = "WHERE sklad_id = '$sklad_id'";
}

$sql = "SELECT `region_id`, `kontr_id`, `kontr_nomi`, `qarzi_som`, `qarzi_val`, `max_sum`, `max_val`, `time`, latitude, longitude, oxirgi_savdo_sanasi, savdo_qizarsin, telefon FROM `kontragentlar` $sql_skk";

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

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

$count=1;

$list_kontr = array();

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

        $region_id=$row['region_id'];
        $dokon_id=$row['kontr_id'];
		$nomi=$row['kontr_nomi'];
		$qarzi_som=$row['qarzi_som'];
        $qarzi_val=$row['qarzi_val'];
		$max_val=$row['max_val'];
        $max_sum=$row['max_val'];
		$time=$row['time'];
		$latitude=$row['latitude'];
		$longitude=$row['longitude'];
		$oxirgi_savdo_sanasi=$row['oxirgi_savdo_sanasi'];
		$savdo_qizarsin=$row['savdo_qizarsin'];
		$telefon=$row['telefon'];

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

    	array_push($list_kontr,
                array(
                        'region_id' => $region_id,
                        'kontr_id' => $dokon_id,
                        'kontr_nomi' => $nomi,
                        'qarzi_som' => $qarzi_som,
                        'qarzi_val' => $qarzi_val,
                        'max_sum' => $max_sum,
                        'max_val' => $max_val,
                        'time' => $time,
                        'latitude' => $latitude,
                        'longitude' => $longitude,
                        'oxirgi_savdo_sanasi' => $oxirgi_savdo_sanasi,
                        'savdo_qizarsin' => $savdo_qizarsin,
                        'telefon' => $telefon
                     )
                  );

		}

    }

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