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

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

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

$vouch = $_GET['vouchno'];

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

$maindb = 'purmain';
$trandb = 'purtran';

$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`")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']; ?>
                        <?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . "/" . $getcmpname['mobile']; ?>
                    </h4>
                </div>
            </div>
            <h3 class="text-center" >Purchase Voucher</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%;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="">
                <table class="table table-bordered" style="border:1px solid black; border-top: none;">
                    <tr style="">
                        <th style="width:3%; color:black;"><label>Sr.</label></th>
                        <th style="width:20%; color:black;"><label>Itemname</label></th>
                        <th style="width:8%; color:black;"><label>Unit</label></th>
                        <th style="width:6%; color:black; text-align: right;"><label>Qty.</label></th>
                        <th style="width:8%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:8%; color:black; text-align: right;"><label>Amount</label></th>
                    </tr>
                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT `srno`,`itemcode`,`unit`,`qty`,`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[itemcode] ")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[rate]</td>";
                        Echo"<td style=' text-align:right;'>$showtran[amount]</td>";
                        Echo"</tr>";
                        $ctr++;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 14) {
                        for ($i = $ctab; $i <= 14; $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>
                            </tr>      
                            <?php
                        }
                    }
                    ?>
                </table>
            </div>
            <div>
                <div style='float: left; width:374px; height:190px;border-right: 1px solid black;' class='border'>
                   
                    <table>
                        <?php if ($getdata[remark1] != '') { ?>
                            <tr class="row">
                                <th style="color:black;"><label>Remark: &nbsp </label></th>
                                <td><? Echo $getdata[remark1]; ?></td>
                            </tr>
                        <?php } if ($getdata[remark2] != '') { ?>
                            <tr class="row">
                                <th style="color:black;"><label></label></th>
                                <td><? Echo $getdata[remark2]; ?></td>
                            </tr>
                        <?php } ?>
                    </table>
                </div>
                <div style='float:right; width:372px;  height:190px;border-right: 1px solid black;' class=''>
                    <table class='table'>
                        <tr>
                            <th style="color:black;"><label>Sub Total:</label></th>
                            <td class='text-right'></td>
                            <td class='text-right'><? Echo $getdata[subtotal]; ?></td>
                        </tr>
                        <?php if ($getdata[lesother] > 0) { ?>
                            <tr>
                                <th style="color:black;"><label>Less: Discount</label></th>
                                <td class='text-right'></td>
                                <td class='text-right'><? Echo $getdata[lesother]; ?></td>
                            </tr>
                            <?php
                        }
                        if ($getdata[litemdisc] > 0) {
                            ?>
                            <tr>
                                <th style="color:black;"><label>Less: Item Discount</label></th>
                                <td class='text-right'></td>
                                <td class='text-right'><? Echo $getdata[litemdisc]; ?></td>
                            </tr>
                            <?php
                        }
                        if ($getdata[cdiscamt] > 0) {
                            ?>
                            <tr>
                                <th style="color:black;"><label>Less: Cash Discount</label></th>
                                <td class='text-right'><? Echo $getdata[cdiscperc]; ?>%</td>
                                <td class='text-right'><? Echo $getdata[cdiscamt]; ?></td>
                            </tr>
                            <?php
                        }
                        if ($getdata[vatamt] > 0) {
                            ?>
                            <tr>
                                <th style="color:black;"><label>Add: V.A.T</label></th>
                                <td class='text-right'><? Echo $getdata[vatperc]; ?>%</td>
                                <td class='text-right'><? Echo $getdata[vatamt]; ?></td>
                            </tr>
                            <?php
                        }
                        if ($getdata[packing] > 0) {
                            ?>
                            <tr>
                                <th style="color:black;"><label>Add: Packing</label></th>
                                <td class='text-right'></td>
                                <td class='text-right'><? Echo $getdata[packing]; ?></td>
                            </tr>
                        <?php } ?>
                    </table>
                </div>
            </div>
            <div>
                <div style='float:left; width:374px;  height:60px' class='border'>
                    <table class="table">
                        <tr>
                            <td><label><?php Echo rsword($getdata[netamt]); ?></label></td>
                        </tr>
                    </table>
                </div>                
                <div style='float:right; width:372px;  height:60px' class='border'>
                    <table class="table">
                        <tr>
                            <th style="color:black;"><label>Total Amount</label></th>
                            <td class='text-right'><? Echo $getdata[netamt]; ?></td>
                        </tr>
                    </table>
                </div>
            </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'); ?>
