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

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

$vouch = $_GET['vouchno'];
$type = $_GET['type'];

$cond = '';
$lcond = '';
$formname = "Transfer Voucher";
$maindb = 'trnfmain';
$trandb = 'trnftran';
//$root = 'cepheisy_cism_root';
$fseries = $_SESSION["series_" . $dbname];

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`")or die(mysqli_error($conn));



$getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`company`")or die(mysqli_error($conn));
$comp2 = mysqli_fetch_array($getcomp2);


if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }

</style>
</head>
<body>
    <?php
    $tdhg = "24px";
    $qry = mysqli_fetch_array($getqry);
    ?>
    <div class="page">
        <div class="subpage">
            <div class="row">
                <div class="col-sm-12 text-center">
                    <table style="width:100%">
                        <tr>
                            <td style="width:33.33%"></td> 
                            <td style="width:33.33%;text-align: center"><label class="label-control"><? Echo $formname; ?></label></td> 
                            <td style="width:33.33%;text-align: right"><label class="label-control">ESTD : 1952</label></td> 
                        </tr>
                    </table>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12 text-justify">
                    <label class="label-control">
                        <?
                        if ($comp[address] == "") {
                            Echo "$comp2[add1]" . "$comp2[add2]" . "$comp2[add3]";
                        } else {
                            Echo "$comp[address]";
                        }
                        ?>
                    </label>
                </div>
            </div>
            <div class="border">
                <div class="row">
                    <table style="width: 100%">
                        <tr>
                            <td width="5%" class="text-right"><label class="label-control">No  :</label></td>
                            <td width="20%"><label class="label-control"><? Echo $qry[vouchno]; ?></label></td>

                            <td width="25%"></td>
                            <td width="25%"></td>

                            <td width="5%" class="text-right"><label class="label-control">Date  :</label></td>
                            <td width="20%"><label class="label-control"><? Echo $qry[mydt]; ?></label></td>

                        </tr>
                    </table>
                </div>
                <div class="row">
                    <?
                    $getcust = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`='$qry[fgodown]'")or die(mysqli_error($conn));
                    $cust = mysqli_fetch_array($getcust);
                    $getcust2 = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`='$qry[tgodown]'")or die(mysqli_error($conn));
                    $cust2 = mysqli_fetch_array($getcust2);
                    ?>
                    <table width="50%" class="table-hover pad">
                        <tr>
                            <td width="20%" valign="top" class="numeric">
                                <label class="smfont pad">From</label>
                            </td>
                            <td width="30%" class="pad">
                                <label class="smfont pad"><?= $cust['name'] ?></label>

                            </td>
                            <td width="20%" valign="top" class="numeric">
                                <label class="smfont pad">To</label>
                            </td>
                            <td width="30%" class="pad">
                                <label class="smfont pad"><?= $cust2['name'] ?></label>

                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div style="border-right: 1px solid black;border-left: 1px solid black;">
                <div class="row">
                    <div class="col-sm-12 pad">
                        <table class="table-condensed table-bordered" style="width: 100%">
                            <tr style="background-color:#cccccc;border: 1px solid black; height: <?= $tdhg; ?>">
                                <th width="5%" class="numeric">Sr</th>
                                <th width="10%">Barcode</th>
                                <th width="70%">Item</th>
                                <th class="numeric" width="15%">Qty.</th>
                            </tr>
                            <?
                            $ctab = $totqty = 0;
                            $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$qry[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                            while ($tran = mysqli_fetch_array($gettran)) {
                                $getitem = mysqli_query($conn, "SELECT `name` FROM `product` WHERE `code`='$tran[itemcode]'")or die(mysqli_error($conn));
                                $item = mysqli_fetch_array($getitem);
                                ?>
                                <tr style="height: <?= $tdhg; ?>">
                                    <td class="numeric"><? Echo $tran[srno]; ?></td>
                                    <td ><? Echo $tran[barcode]; ?></td>
                                    <td ><? Echo $item[name]; ?></td>
                                    <td class="numeric"><? Echo $tran[qty]; ?></td>
                                </tr>
                                <?
                                $ctab = $ctab + 1;
                                $totqty = $totqty + $tran[qty];
                            }
                            if ($ctab < 4) {
                                for ($i = $ctab; $i < 5; $i++) {
                                    ?>
                                    <tr style="height: <?= $tdhg; ?>">
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?> 
                        </table>
                    </div>
                </div>
            </div>
            <div class="border">
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <table class="table-hover rborder pad" style="float: left;width:65%">
                            <tr>
                                <td><label class="smfont pad"><? Echo $qry[remark1] . $qry[remark2]; ?></label></td>
                            </tr>
                        </table>
                        <table class="table-hover" style="float: left;width:35%">
                            <tr>
                                <td><label class="smfont pad">Total Qty.</label></td>
                                <td><label class="smfont pad"></label></td>
                                <td class="numeric"><label class="smfont pad"><? Echo $totqty; ?></label></td>
                            </tr>
                        </table>
                    </div>
                </div>

            </div>

        </div>
    </div>
    <?php include('includes/linksfoot.php'); ?>
