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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$comp  = $_SESSION["comp_" . $dbname];


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

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Sale Print";

$maindb = 'salemain';
$trandb = 'saletran';

$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 cepheisy_msp_root.`company` where `code`='$comp'")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>
                    <h5>
                        <?php echo $getcmpname['add1'] . "" . $getcmpname['add2'] . "" . $getcmpname['add3']; ?><br>
                        <?php // echo $getcmpname['station'] . " " . $getcmpname['city'] . "" . $getcmpname['pin']; ?>
                        <?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . "  " . $getcmpname['mobile']; ?>
                    </h5>
                    <hr>
                </div>
            </div>

            <h3 class="text-center" >ON APPROVEL</h3>
            <div class="border" style="height:100px" >
                <table style="width:100%;">
                    <tr>
                        <th style="color:black; width:10%; text-align: right"><label> M/s. &nbsp </label></th>
                        <th style="color:black; width:50%"><label><?php echo $showparty['name']; ?></label></th>
                        <th style="color:black; width:20%; text-align: right"><label>VOUCHER No:&nbsp</label> </th>
                        <td style="color:black; width:20%"><?php echo $getdata['vouchno']; ?></td>
                    </tr>
                </table>
                <table style="width:100%; ">
                    <tr>
                        <th style="color:black; width:10%"></th>
                        <td style="color:black; width:50%"></td>
                        <th style="color:black; width:20%l;text-align: right;"><label>DATE: &nbsp</label></th>
                        <td style="color:black; width:20%"><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`,`item`,`unit`,`qty`,`mrp`,`rate`,`amount`FROM `$trandb`WHERE `vouchno`='$vouch'")or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {
                        $getitem = mysqli_query($conn, "SELECT `name`,`code`  From `item` WHERE `code` = $showtran[item] ")or die(mysqli_error($conn));
                        $showitem = mysqli_fetch_array($getitem);

                        Echo"<tr>";
                        Echo"<td style=''>$showtran[srno]</td>";
                        Echo"<td style=''>$showitem[name]</td>";
                        Echo"<td style=''>$showtran[unit]</td>";
                        Echo"<td style='text-align: right;'>$showtran[qty]</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:150px' class='border'>
                    <table>
                        <tr>
                            <th style="color:black;"><label>Remark:&nbsp </label></th>
                            <td class='text-right'><? Echo $getdata[remark1]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label></label></th>
                            <td class='text-right'><? Echo $getdata[remark2]; ?></td>
                        </tr>

                    </table>
                </div>
                <div style='float:right; width:372px;  height:150px' class='border'>
                    <table class='table'>
                        <tr>
                            <th style="color:black;"><label>Sub Total:</label></th>
                            <td class='text-right'><? Echo $getdata[subtotal]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label>Less: Discount</label></th>
                            <td class='text-right'><? Echo $getdata[litemdisc]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label>Bill Amount</label></th>
                            <td class='text-right'><? Echo $getdata[netamt]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label>Balance</label></th>
                            <td class='text-right'><? Echo $getdata[balance]; ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div style="border:1px solid black;">
                <table class="table">
                    <tr>
                        <td><label><?php Echo rsword($getdata[netamt]); ?></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'); ?>
