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

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

if (isset($_REQUEST['saleorder'])) {
    $saleorder = $_REQUEST['saleorder'];

    $gettran = mysqli_query($conn, "SELECT * FROM `sordtran` WHERE `vouchno`='$saleorder' $keycond ORDER BY `srno`")or die(mysqli_error($conn));

    // $gettran = mysqli_query($conn, "SELECT * FROM `itemtran` WHERE itemcode = '$prodcode' ORDER BY srno") or die(mysqli_error($conn));
    $count = mysqli_num_rows($gettran);
    $ctr = 0;

    if ($count > 0) {
        $ctr = 0;
        while ($tran = mysqli_fetch_array($gettran)) {
            $finditem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
            $fitem = mysqli_fetch_array($finditem);

            $findcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` WHERE `code`='$tran[color]'") or die(mysqli_error($conn));
            $fcolor = mysqli_fetch_array($findcolor);

            Echo "<tr>";
            Echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
            Echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$tran[srno]'>
                      <input type='hidden' class='form-control form text-right purvouch' name='purvouch_$sctr' value='$fetquery[purvouch]'>
                      <input type='hidden' class='form-control form text-right pursrno' name='pursrno_$sctr' value='$fetquery[pursrno]'></td>";
            Echo "<td>";
            Echo "<input type='text' class='form-control form barcode' name='barcode_$ctr' value='$tran[barcode]'>";
            Echo "</td>";
            Echo "<td>";
            Echo "<select class='form-control form item select2' name='item_$ctr' style='width:100%'>";
            Echo "<option value='$fitem[code]'>$fitem[name]</option>";
            $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `item` WHERE `prodtype`='$get[prodtype]'")or die(mysqli_error($conn));
            while ($item = mysqli_fetch_array($gitem)) {
                Echo "<option value='$item[code]'>$item[name]</option>";
            }
            Echo "</select>";
            Echo "<input type='hidden' class='msp' name='msp_$ctr' value='$tran[msp]' >";
            Echo "<input type='hidden' class='otprowsucs' name='otprowsucs_$ctr' value='$tran[otprowsucs]' >";
            Echo "</td>";
            Echo "<td>";
            Echo "<select class='form-control form color select2' name='color_$ctr' style='width:100%'>";
            Echo "<option value='$fcolor[code]'>$fcolor[name]</option>";
            $gcolor = mysqli_query($conn, 'SELECT `code`,`name` FROM `color` order by name')or die(mysqli_error($conn));
            while ($color = mysqli_fetch_array($gcolor)) {
                Echo "<option value='$color[code]'>$color[name]</option>";
            }
            Echo "</select>";
            echo "</td>";
            Echo "<td><input type='text' class='form-control form text-right qty'      name='qty_$ctr'      value='$tran[qty]'></td>";
            Echo "<input type='hidden' class='msp' name='msp_$ctr' >";
            Echo "<input type='hidden' class='otpvalue' id='otpvalue_$ctr' name='otpvalue_$ctr' value='$tran[otpvalue]'>";
//                                            Echo "<td><input type='text' class='form-control form text-right rate'     name='rate_$ctr'     value='$tran[rate]'></td>";
//                                            Echo "<td><input type='text' class='form-control form text-right amount'   name='amount_$ctr'   value='$tran[amount]' readonly>
//                                            <input type='hidden' class='form-control form text-right mspamount'   name='mspamount_$ctr'   value='$tran[mspamount]' readonly></td>";
            Echo "</tr >";
            $ctr++;
        }
    }
    ?>
        <input type="hidden" id="items" name="items" value="<?php echo $ctr; ?>" />

<?php
}
