<?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 = "Debit Note";

$maindb = 'debmain';
$trandb = 'debtran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt   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`='1'") 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);
?>

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


<?php
//        include("includes/files.php");
//        include("includes/tabsuf.php");
?>

<style>
    @media print {
        .noPrint {
            display: none;
        }
    }

    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }

    .page {
        width: 210mm;
        min-height: 297mm;
        padding: 4mm;
        margin: 10mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        /*background: white;*/

    }

    .subpage {
        padding: 0cm;
        /*        border: 1px solid;*/
        height: 288mm;
        outline: 2cm #ffffff solid;
    }

    @page {
        size: A4;
        margin: 0;
    }

    @media print {

        .noPrint {
            display: none;
        }

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

        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }
    }

    .numeric {
        text-align: right;
    }

    .rnone {
        border-right: none;
    }

    .lnone {
        border-left: none;
    }
</style>
<title>TILEWEB</title>
</head>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<body id="main_container">
    <div class="book">
        <button class="btn btn-primary goBack noPrint" onclick="window.close()" style="width:150px;float:right;height:35px;background-color: #26A69A;color:white;padding-left: 1%">Go Back</button>
        &nbsp;&nbsp;&nbsp;
        <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="width: 150px;float:right;height:35px;background-color:#9E8759;color:white;">Print</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <table style="border:solid 1px;width:100%">
                <tr>
                    <td width="20%"><img style="width:100%;height:auto" src="images/logo/HALOGO.jpeg" alt="logo"></td>
                    <!-- <td width="80%">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                         &nbsp;&nbsp;&nbsp;&nbsp;
                        <?php echo $getcmpname['compname']; ?>
                    </td> -->
                </tr>
                <!-- <tr>
                    <td colspan="2"><center><?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd2'] . " " . $getcmpname['hoadd3']; ?></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><?php echo "Contact No :" . $getcmpname['htel']; ?></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><?php echo "GST No :" . $getcmpname['gstno']; ?></center></td>
                </tr>
                <tr>
                    <td colspan="2"><center><b><?php echo $formname; ?></b></center></td>
                </tr> -->
            </table>
            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                <?php
                mysqli_select_db($conn, $zdb);

                $gcust = mysqli_query($conn, "SELECT * FROM `accmast` where accode = '$getdata[party]' ") or die(mysqli_error($conn));
                $cust = mysqli_fetch_array($gcust);
                ?>
                <table class="table table-border table-hover" style="width:100%">
                    <tr>
                        <td style="text-align: left; width:5%"><b>M/s.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo "$showparty[name]"; ?></td>
                        <td style="text-align: right ; width:30%"><b>Debit Note No.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo " $getdata[vouchno]"; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:5%"><b></b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:40%"><?= $cust['add1'] ?></td>
                        <td style="text-align: right ; width:30%"><b>Date</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo " $getdata[invdt]"; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:5%"><b></b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:40%"><?= $cust['add2'] ?></td>
                        <td style="text-align: right ; width:30%"><b>Against Invoice No.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo " $getdata[invno]"; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:7%"><b>Mobile</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo "$cust[mobile]"; ?></td>
                        <td style="text-align: right ; width:30%"><b>Date</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo "$getdata[vouchdt]"; ?></td>
                    </tr>
                </table>
            </div>
            <div>
                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:10%; color:black;"><label>Sr. No.</label></th>
                        <th style="width:30%; color:black;"><label>Description</label></th>
                        <th style="width:15%; color:black;"><label>Unit</label></th>
                        <th style="width:15%; 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:15%; color:black; text-align: right;"><label>Rate</label></th>
                        <th style="width:15%; color:black; text-align: right;"><label>Amount</label></th>
                    </tr>

                    <?php
                    $ctr = 0;
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouch' order by srno") or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {

                        $getuint = mysqli_query($conn, "SELECT `name`,`code`  From `unit` WHERE `code` = '$showtran[unit]' ") or die(mysqli_error($conn));
                        $showunit = mysqli_fetch_array($getuint);

                        echo "<tr>";
                        echo "<td style=''>$showtran[srno]</td>";
                        echo "<td style=''>$showtran[itemname]</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
                        }
                    }
                    ?>

                    <tr style="">
                        <td colspan="2" style="border:none"><? echo "$getdata[remark1]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                        <td colspan="" style="text-align: right;border:none"> Subtotal </td>
                        <td style="text-align: right;border:none "> <? echo $totqty; ?> </td>
                        <td style="border:none"></td>
                        <td style="text-align: right;border-left: none;"> <? echo  $getdata['grossamt']; ?> </td>

                    </tr>
                    <?php
                    if ($getdata['totidsc'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right; " class="lnone rnone"> Less: Item Discount </td>
                            <td style="text-align: right; " class="lnone "> <? echo  $getdata['totdisc']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['addpack'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right;" class=" rnone"> Add: Cartage </td>
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['addpack']; ?> </td>
                        </tr>
                    <?php
                    }
                    if ($getdata['addgst'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right; " class=" rnone"> Add: GST </td>
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['addgst']; ?> </td>
                        </tr>
                    <?php
                    }

                    if ($getdata['billamt'] > 0) {
                    ?>
                        <tr>
                            <td colspan="5" style="text-align: right; " class=" rnone"><b>Total Amount</b></td>
                            <td style="text-align: right; " class="lnone "><b><? echo $getdata['billamt']; ?></b></td>
                        </tr>
                    <?php
                    }

                    ?>
                    <tr>
                        <td colspan="9">
                            Rupees
                            <?php echo rsword(round($getdata['billamt'])); ?>
                        </td>

                    </tr>
                </table>
            </div>

            <div>
                <table class="border">
                    <tr>
                        <td class="border" style="width: 541px; font-size: 14px;">
                            <!--<img src="images/taximg.png">-->
                        </td>
                        <td class="border" style="width: 216px">
                            <?php
                            require("includes/dbconnect.php");
                            ?>
                            <div style=" text-align:right; font-size: 14px; font-weight: 900"><? echo "For $getcmpname[compname]"; ?></div>
                            <br>
                            <br>
                            <br>
                            <div style=" margin-left: 51px; font-size: 11px"><b> AUTHORISED SIGNATORY</b></div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <!--</div>-->
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function() {
            formGeneral();
        });
    </script>
</body>

</html>