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

$formname = 'Contra Voucher';
$maindb = 'contra';
//$trandb = 'purtran';
/* $accdb = 'actran'; */
$file = 'contra.php';
$source = "TR";
/* $grid = 'salemain.php'; */

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$zyear = right($zdb, 4);
$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];
$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt,DATE_FORMAT(`chqdate`, '%d-%m-%Y') AS chqdate 
                         FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry);
?>

<!DOCTYPE HTML>
<html lang="en-US">

<?php include("includes/linkshead.php"); ?>
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        font: 12pt "Tahoma", sans-serif;
        background-color: #f4f4f4;
    }

    * {
        box-sizing: border-box;
    }

    .page {
        width: 210mm;
        min-height: 297mm;
        padding: 20mm;
        margin: 10mm auto;
        border: 1px solid #ddd;
        border-radius: 5px;
        background: white;
        box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    }

    h4 {
        text-align: center;
        font-weight: bold;
        text-transform: uppercase;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    td {
        padding: 8px 0;
        vertical-align: top;
    }

    b {
        font-weight: bold;
    }

    .header, .footer {
        text-align: center;
        margin-bottom: 5px;

    }
    
    .section {
        margin-bottom: 5px;
    }

    @media print {
        body, html {
            width: 210mm;
            height: 297mm;
        }

        .page {
            box-shadow: none;
            margin: 0;
            border: none;
            border-radius: 0;
            width: initial;
            min-height: initial;
            padding: 15mm;
        }
    }
</style>

<body id="main_container">
    <div class="page" style="border: 2px solid black;">
        <?php
        require("includes/dbconnect.php");
        $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysqli_error($conn));
        $zcomp = mysqli_fetch_assoc($comp);
        mysqli_select_db($conn, $zdb);
        ?>

        <div class="header">
            <h4><?php echo $formname; ?></h4>
        </div>
<hr>
        <div class="section">
            <?php
            $gcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$getmdata[frombc]'") or die(mysqli_error($conn));
            $cust = mysqli_fetch_array($gcust);

            $gcust1 = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$getmdata[tobc]'") or die(mysqli_error($conn));
            $cust1 = mysqli_fetch_array($gcust1);
            ?>
            <table>
                <tr>
                    <td style="width: 75%;">Voucher No: <b><?php echo $zyear . '/' . $getmdata['vouchno']; ?></b></td>
                    <td style="width: 25%;">Date: <b><?php echo $getmdata['vouchdt']; ?></b></td>
                </tr>
            </table>
        </div>

        <div class="section">
            <table>
                <tr>
                    <td>From: <b><?php echo $cust['name']; ?></b></td>
                </tr>
                <tr>
                    <td>To: <b><?php echo $cust1['name']; ?></b></td>
                </tr>
                <tr>
                    <td>Amount (Rs.): <b><?php echo $getmdata['amount']; ?></b> (<?php echo rsword(round($getmdata["amount"])); ?>)</td>
                </tr>
                <?php if ($getmdata['chqno'] != '') { ?>
                <tr>
                    <td>Via Cheque No.: <b><?php echo $getmdata['chqno']; ?></b> dated <b><?php echo $getmdata['chqdate']; ?></b></td>
                </tr>
                <?php } ?>
                <tr>
                    <td><b>Narration:</b> <?php echo $getmdata['narration']; ?></td>
                </tr>
            </table>
        </div>

        <div class="section">
            <p>Authorized Signature: __________________________</p>
        </div>
    </div>

    <?php include("includes/linksfoot.php"); ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>

