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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
$zcomp = $_SESSION["comp_" . $dbname];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';

$formname = 'Excess Print';
$maindb = 'excmain';
$trandb = 'exctran';


$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));
$getdata = mysqli_fetch_array($getqry);


$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company`  where `code`='$zcomp'")or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);

$getparty = mysqli_query($conn, "SELECT `accode`,`name` From accmast WHERE `accode` = '$getdata[party]'")or die(mysqli_error($conn));
$showparty = mysqli_fetch_array($getparty);

//$gettran = mysqli_query($conn, "SELECT * From $trandb ")or die(mysqli_error($conn));
//$showtran = mysqli_fetch_array($gettran);






include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    thead{
        font-size:12px;
    }
    label{
        font-size:12px;
    }
    #id1{
        font-size:10px;
    }
    #id2{
        border:1px solid black;
        border-left:none;
        height: 250px
    }
    #id3{
        border:1px solid black;
        height: 250px
    }
</style>
</head>
<body>
    <?php
    $tdhg = "24px";
    ?>
    <a class="btn btn-primary goBack" onclick="window.close()" style="float: right">Go Back</a>
    <div class="page">
        <div class="subpage" style="margin-top: 1px">
            <div class="row">
                <div class="col-sm-12 text-center">
                    <h1><? Echo $getcmpname['name']; ?></h1>
                    <h4>
                        <?php echo $getcmpname['add1'] . ", " . $getcmpname['add2'] . ", " . $getcmpname['add3']; ?><br>
                        <?php echo $getcmpname['station'] . ", " . $getcmpname['city'] . "-" . $getcmpname['pin']; ?><br>
                        <?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . "/" . $getcmpname['mobile']; ?>
                    </h4>
                    <hr>
                </div>
            </div>

            <h3 class="text-center" ><?echo "$formname";?></h3>
            <div class="border" style="height:100px" >
                <table style="width:100%;">
                    <tr>
                       
                        <th style="color:black; width:10%; padding-left:15px;  "><label>VOUCHER No</label> </th>
                        <th style="color:black; width:2%;  text-align: center">:</th>
                        <th style="color:black; width:50%"><?php echo $getdata['vouchno']; ?></td>
                    </tr>
                </table>
                <table style="width:100%; ">
                    <tr>
                        <th style="color:black; width:10%; padding-left:15px;"><label>DATE</label></th>
                        <th style="color:black; width:2%;  text-align: center">:</th>       
                        <td style="color:black; width:50%"><label><?php echo $getdata[mydt]; ?></label></td>
                        
                    </tr>
                </table>
            </div>
            <div style="border:1px solid black; border-top: none;">
                <table class="table table-hover table-bordered" >
                    <tr style="">
                        <th style="width:5%; color:black;"><label>Sr.</label></th>
                        <th style="width:25%; color:black;"><label>Itemname.</label></th>
                        <th style="width:10%; color:black;"><label>Unit</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Qty.</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Mrp</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Amount</label></th>
                    </tr>
                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT `srno`, `itemcode`, `trqty`, `unit`, `mrp`, `rate`, `amount` FROM `$trandb` WHERE `vouchno`='$vouch' ORDER BY `srno`")or die(mysqli_error($conn));
                     
                    while ($showtran = mysqli_fetch_array($gettran)) {
                        $getitem = mysqli_query($conn, "SELECT `name`,`code`  From `item` WHERE `code` = $showtran[itemcode]  ")or die(mysqli_error($conn));
                        $showitem = mysqli_fetch_array($getitem);
                        
                        $getunit = mysqli_query($conn, "SELECT `code`, `name` FROM `unit` WHERE `code` = $showtran[unit]")or die(mysqli_error($conn));
                        $shounit = mysqli_fetch_array($getunit);
                        
                        Echo"<tr>";
                        Echo"<td style=''>$showtran[srno]</td>";
                        Echo"<td style=''>$showitem[name]</td>";
                        Echo"<td style=''>$shounit[name]</td>";
                        Echo"<td style='text-align: right;'>$showtran[trqty]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[mrp]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[rate]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[amount]</td>";
                        Echo"</tr>";
                        $ctr++;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 15) {
                        for ($i = $ctab; $i <= 15; $i++) {
                            $ctab = $ctab + 1;
                            ?>
                            <tr style="height:26px;">
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                            </tr>      
                            <?php
                        }
                    }
                    ?>
                </table>
            </div>
            <div >
                <div style='float: left; width:372px; height:75px' class='border'>
                    <table>
                        <tr>
                            <th style="color:black;"><label>Remark:&nbsp </label></th>
                            <td class='text-left'><? Echo $getdata[remark]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label></label></th>
                            <td class='text-left'><? Echo $getdata[remark2]; ?></td>
                        </tr>

                    </table>
                </div>
                <div style='float:right; width:372px;  height:75px' class='border'>
                    <table class='table'>
                        <tr>
                            <th style="color:black;"><label>Sub Total:</label></th>
                            <td class='text-right'><? Echo $getdata[total]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label>Quantity</label></th>
                            <td class='text-right'><? Echo $getdata[qty]; ?></td>
                        </tr>
                        
                    </table>
                </div>
            </div>
            <div style="border:1px solid black;">
                <table class="table">
                    <tr>
                        <td><label><?php Echo rsword($getdata[total]); ?></label></td>
                    </tr>
                </table>
            </div>
            <div style="border:1px solid black; border-top:none; padding-bottom: 30px; ">
                <table class="table">
                    <tr>
                        <td style="text-align:right; padding-right:15px;padding-top:15px;"><label><?php Echo " For " . $getcmpname['name']; ?></label></td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <?php include('includes/linksfoot.php'); ?>
