<?php

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


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

$product = $_REQUEST["product"];


$prodcode = $_POST['prodcode'];

//$prodcode = '{"NGLS":200,"NGL":200}';

$jsondata = json_decode($prodcode, true);
//$err = json_last_error();
//$msg = json_last_error_msg();
//var_dump($prodcode,$jsondata,$err,$msg);


echo "<table class='table table-striped table-condensed table-bordered'  style='width: 100%'>";
echo "<thead>";
echo"<tr style='background-color: #6082BF;'>";
echo "<th width='3%'></th>";
echo "<th width='6%'>Sr</th>";
echo"<th width='25%'>Packing Material</th>";
echo"<th width='8%'>AR.No.</th>";
echo"<th width='8%'>Actual Qty.</th>";
echo"<th width='8%'>Issued Qty.</th>";
echo"</tr>";
echo"</thead>";
echo"<tbody class='tbody4'>";
$ctr = 0;

foreach ($jsondata as $key => $value) {
    $gettran = mysqli_query($conn, "SELECT * FROM `finprodpack` WHERE `code`='$product' and `relprod`='$key' order by `srno`")or die(mysqli_error($conn));
    while ($tran = mysqli_fetch_array($gettran)) {
        $getpack = mysqli_query($conn, "SELECT code,name FROM `item` WHERE `code`='$tran[packing]' ")or die(mysqli_error($conn));
        $pack = mysqli_fetch_array($getpack);
        $qty = $tran['qty'];
        $actqty = $qty * $value;

        Echo "<tr>";
        Echo "<td><i class='fa fa-close remove' ></i></td>";
        Echo "<td><input type='text' class='form-control form text-right srno'    name='srno4[]'      value='$tran[srno]' readonly></td>";
        Echo "<td>";
        Echo "<select class='form-control form packing select2' name='packing[]' style='width:100%' readonly>";
        Echo "<option value='$pack[code]'>$pack[name]</option>";
        Echo "</select>";
        Echo "</td>";
        Echo "<td><input type='text' class='form-control form  arno'   name='arno[]'  step='any'   value=''></td>";
        Echo "<td><input type='number' class='form-control form text-right actqty'   name='actqty[]'  step='any'   value='$actqty' readonly></td>";
        Echo "<td><input type='number' class='form-control form text-right issuedqty'   name='issuedqty[]'  step='any'   value='$actqty'></td>";
        Echo "</tr>";

        $ctr++;
    }
}


echo "</tbody>";
echo "<input type='hidden' class='form-control form items4' id='items4' name='items4' value='$ctr'>";
echo "</table>";
?>