<?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'];
$gtype = $_GET['type'];



$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`='$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);
?>

<!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 {
            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>
</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="float: right;width: 150px;height:35px;background-color: white;color:#A0B1BA;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12" >
                <h3><center><? Echo $getcmpname['compname']; ?></center></h3>
                <center><?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd1'] . " " . $getcmpname['hoadd3']; ?></center>
                <center><?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['htel'] . "/" . $getcmpname['mobile']; ?></center>
                <h5><center><b><?php echo $formname; ?></b></center></h5>

            </div>
            <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>Voucher</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:7%"><b>Shop.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo "$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[vouchdt]"; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:7%"></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:40%"><?php echo "$cust[add1] $cust[add2]"; ?></td>
                        <td style="text-align: right ; width:30%"></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:20%"></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%"></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:20%"></td>
                    </tr>
                </table>
            </div>
            <div>
                <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:5%; color:black;"><label>Sr.</label></th>
                        <th style="width:55%; 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: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)) {
                        if ($gtype == 'R') {
                            $getitem = mysqli_query($conn, "SELECT code, name FROM `item` WHERE code = '$showtran[itemcode]'") or die(mysqli_error($conn));
                        } else {
                            $getitem = mysqli_query($conn, "SELECT code, name FROM `packing` WHERE code = '$showtran[itemcode]'") or die(mysqli_error($conn));
                        }
                        $geti = mysqli_fetch_array($getitem);
                        $itemname = $geti['name'];

                        $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 width='5%'>$showtran[srno]</td>";
                        Echo"<td width='65%'>$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="3" style="border:none" ><? echo "$getdata[remark1]" . " &nbsp;" . "$getdata[remark2]"; ?></td>
                        <!--<td style="text-align: right;border:none "> </td>-->
                        <td style="text-align: right;border:none" ><b>Subtotal</b></td>
                        <td style="border-right: 1px;border-left: 1px; "></td>
                        <td style="text-align: right;border-left: none;"> <? echo $getdata[subtotal]; ?>  </td>

                    </tr>

                    <?php
                    if ($getdata['totdiscamt'] > 0) {
                        ?> 
                        <tr>

                            <td colspan="4" style="text-align: right; " class="lnone rnone"><b>Discount</b></td>
                            <td style="text-align: right; " class="lnone rnone">   </td>
                            <!--<td class="lnone rnone"></td>--> 
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['totdiscamt']; ?>  </td>
                        </tr>
                        <?php
                    }
                  ?>
                    <?php
                    if ($getdata['taxableamt'] > 0) {
                        ?> 
                        <tr>

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

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

                            <td colspan="4" style="text-align: right; " class="lnone rnone"><b>Net Amount</b></td>
                            <td style="text-align: right; " class="lnone rnone">   </td>
                            <!--<td class="lnone rnone"></td>--> 
                            <td style="text-align: right; " class="lnone "> <? echo $getdata['billamt']; ?>  </td>
                        </tr>
                        <?php
                    }
                  ?>
                    <tr>
                        <td colspan="3">
                            <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                                <tbody style="border-collapse: collapse;">

                                    <tr>

                                        <td style="width:25%;">G.S.T No</td>
                                        <td style="width:75%;"><?= $getdata['gstno'] ?></td>
                                    </tr>

                                    <tr>

                                        <td style="width:25%;">A/c. Name</td>
                                        <td style="width:75%;"><?= $getcmpname[acname] ?></td>
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">Branch</td>
                                        <td style="width:75%;"></td>
                                        <!-- <td style="width:75%;"><?= $getcmpname[branchname] ?></td> -->
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">Account No.</td>
                                        <td style="width:75%;"></td>
                                        <!-- <td style="width:75%;"><?= $getcmpname[acno] ?></td> -->
                                    </tr>
                                    <tr>

                                        <td style="width:25%;">IFSC Code</td>
                                        <td style="width:75%;"><?= $getcmpname[bankcode] ?></td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td colspan="3" style="border:none;border-collapse: collapse; ">
                            <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                                <tbody style="border-collapse: collapse;">

                                    <tr>

                                        <!--<td style="width:57px;">&nbsp;</td>-->
                                        <td style="width:32px;text-align: right">%</td>
                                        <td style="width:89px;text-align: right" >Tax On</td>
                                        <td style="width:89px;text-align: right" >CGST</td>
                                        <td style="width:89px;text-align: right">SGST</td>
                                        <td style="width:89px;text-align: right">IGST</td>
                                        <td style="width:99px;">&nbsp;</td>
                                    </tr>
                                    <?php
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right' style='text-align: right;'><b>&nbsp;</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'><b>5%</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[taxable5]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[cgst5]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[sgst5]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[igst5]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[totgst5]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'><b>12%</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[taxable12]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[cgst12]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[sgst12]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[igst12]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[totgst12]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'><b>18%</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[taxable18]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[cgst18]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[sgst18]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[igst18]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[totgst18]</td>";
                                    Echo "</tr>";
                                    Echo "<tr style='height: 21px'>";
//                                    Echo "<td class='text-right'><b>&nbsp;</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'><b>28%</b></td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[taxable28]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[cgst28]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[sgst28]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[igst28]</td>";
                                    Echo "<td class='text-right' style='text-align: right;'>$getdata[totgst28]</td>";
                                    Echo "</tr>";
                                    ?>
                                </tbody>
                            </table>
                        </td>
                    </tr>



            <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[pname]"; ?></div>
                            <br>
                            <br>
                            <br>
                            <div style=" margin-left: 51px; font-size: 11px">AUTHORISED SIGNATORY</div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>    
        <!--</div>-->
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
