<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$usertype = $_SESSION["usertype_" . $dbname];

//$stor = $_SESSION["stor_" . $dbname];


if ($_REQUEST["prodcode"]) {

    $prodcode = $_REQUEST["prodcode"];
    $partycode = $_REQUEST["party"];
//    browse($prodcode);
//    browse($party);
    
    $getp = mysqli_query($conn, "SELECT a.party, b.rate , MAX(b.rate) as maxrate, b.product FROM `salemain` a, `saletran` b 
                                 WHERE a.vouchno = b.vouchno and a.party = '$partycode' and b.prodcode = '$prodcode'")or die(mysqli_error($conn));
//    $getp = mysqli_query($conn, "SELECT a.party, b.rate, MAX(b.rate) as prevrate , b.product , c.name FROM `salemain` a, `saletran` b , `product` c
//                                WHERE a.vouchno = b.vouchno and b.product = '$prodcode'  and a.party = '$partycode' and b.product = c.code")or die(mysqli_error($conn));
    $r = mysqli_fetch_assoc($getp);
    
if(mysqli_num_rows($getp) > 0){
    $success = true;
}else{
    $success = false;
    
}
    $rows = array();
    $rows[] = [ 'success' => $success,
        'name'          => $r['name'],
        'unit'          => $r['unit'],
        'hsncode'       => $r['hsncode'],
        'rate'          => $r['maxrate'],
    ];
    header("Content-type: application\json");
    echo json_encode($rows);
}
?>