<?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];
$credprint = "credoth_print2.php?vouchno=16";


$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);
$vouch = $_GET['vouchno'];
$cond = '';
$lcond = '';
$formname = "DEBIT NOTE";

$specialisepin = $_SESSION["specialisepin"];
//browse($specialisepin);
if ($specialisepin != "") {
    $maindb = 'debmain';
    $trandb = 'deboth';
} else {
    $maindb = 'debmain_de';
    $trandb = 'deboth_de';
}
$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt, DATE_FORMAT(`invdate`, '%d-%m-%Y')as invdate   FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`") or die(mysqli_error($conn));
$getmdata = 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);


$getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[party]'") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($getpaccode);
$accode = $cust['accode'];
$add1 = $cust['add1'];
$add2 = $cust['add2'];
$add3 = $cust['add3'];
$city = $cust['city'];
$pin  = $cust['pin'];
$paytype = $getmdata['paidby'];
?>

<!DOCTYPE HTML>
<!DOCTYPE HTML>
<html lang="en-US">
    <?php
    // include("includes/files.php");
    // include("includes/tabsuf.php");
    include("includes/linkshead.php");
    ?>
</head>
<!--<link href="css/rep_format.css" rel="stylesheet" />-->
<style>
    /*    table tr td{
            font-size: 12px;
        }*/
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        padding-right:5px;
        padding-left:5px;
        padding-top:5px;
        padding-bottom:0px;

        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    .f12{
        font-size: 12px;
    }
    .f11{
        font-size: 11px;
    }
    .f13{
        font-size: 13px;
        font-weight: bold;
        padding:3px;
    }
    .f14{
        font-size: 14px;
    }
    .bold{
        font-weight: bold;
    }
    .page {
        width: 148mm;
        min-height: 200mm;
        padding: 6mm;
        margin: 1mm auto;
        /*border: 1px #D3D3D3 solid;*/
        /*border-radius: 1px;*/
        /*background: white;*/
        page-break-after: always;


    }

    .subpage{
        border: 1px solid black;


    }
    .border {
        border: 1px solid black;
        color: black;
        padding-right: 2px;
        padding-left: 3px;
    }
    th {
        font-weight: bold;
        font-size: 13px;
    }

    @media print {
        @page {
            size: a5;
            margin: 0;
        }


        .page {
            width: 146mm;
            min-height: 200mm;
            padding: 6mm; 
            /* margin: 1mm auto; */
            /*border: 1px  solid black;*/
            /*border-radius: 1px;*/
            /*background: white;*/
            page-break-after: always;

        }
        .border {
            border: 1px solid black;
            color: black;
            padding-right: 2px;
            padding-left: 3px;
        }
        th {
            font-weight: bold;
            font-size: 13px;
        } 
        .table2 {
            border: 2px solid black;
        }
    }

</style>
<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);
header('Content-Type: text/html;charset=UTF-8');
ini_set('default_charset', 'utf-8');
?>
<!--<body id="main_container" onload="window.print();">-->
<body id="main_container" onload="">
    <!--<div class="book">-->
    <div class="page">
        <div class="subpage">
            <table style="width:100%">
                <? include("includes/inv_head1_print.php"); ?>
                <!--            <div>
                                <label class="label-control marg" >Mobile : +971 509786865</label>
                            </div>-->
            </table>
            <br>
            <? include("includes/inv_head2_print.php"); ?>
            <br>

            <div>
                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th style="width:10%; color:black;"><label>Sr.</label></th>
                        <th style="width:75%; color:black;"><label>Description.</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 `srno`,`descrip`,`amount`FROM `$trandb` WHERE `vouchno`='$vouch' order by srno") or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {
                        $descrip = $showtran['descrip'];
                        $amount = $showtran['amount'];

                        $ctr++;
                        echo "<tr>";
                        echo "<td style='text-align:center'>$ctr</td>";
                        echo "<td style=''>$descrip</td>";
                        echo "<td style=' text-align:right;'>$amount</td>";
                        echo "</tr>";

                        $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>
                            </tr>
                            <?php
                        }
                    }
                    if ($getmdata['rem1'] != '') {
                        ?>
                        <tr>
                            <td class="rnone">Remarks&nbsp;&nbsp;&nbsp;&nbsp;:

                            </td>
                            <td class=" lnone" colspan="2">
                                <? echo $getmdata['rem1']; ?>
                            </td>
                        </tr>
                    <? } ?>
                    <tr>
                        <td class="rnone"></td>
                        <td class="lnone" colspan="2">
                            <? echo $getmdata['rem2']; ?>
                        </td>
                    </tr>
                    <tr style="">
                        <td style="text-align: right;border-right:1px solid black" colspan="2"> Subtotal </td>
                        <td style="text-align: right;border-left: none;">
                            <? echo $getmdata['grossamt']; ?>
                        </td>
                    </tr>
                    <? if ($getmdata['discamt'] > 0) { ?>
                        <tr style="">
                            <td style="text-align: right;border-right:1px solid black" colspan="2">Discount</td>
                            <td style="text-align: right;border-left: none;">
                                <? echo $getmdata['discamt']; ?>
                            </td>
                        </tr>
                        <?
                    }
                    if ($getmdata['cgstamt'] > 0) {
                        ?>
                        <tr style="">
                            <td style="text-align: right;border-right:1px solid black" colspan="2">CGST
                                <? echo (round($getmdata['cgstperc'])) . "%" ?>
                            </td>
                            <td style="text-align: right;border-left: none;">
                                <? echo $getmdata['cgstamt']; ?>
                            </td>
                        </tr>
                        <?
                    }
                    if ($getmdata['sgstamt'] > 0) {
                        ?>
                        <tr style="">
                            <td style="text-align: right;border-right:1px solid black" colspan="2">SGST
                                <? echo (round($getmdata['sgstperc'])) . "%" ?>
                            </td>
                            <td style="text-align: right;border-left: none;">
                                <? echo $getmdata['sgstamt']; ?>
                            </td>
                        </tr>
                        <?
                    }
                    if ($getmdata['igstamt'] > 0) {
                        ?>
                        <tr style="">
                            <td style="text-align: right;border-right:1px solid black" colspan="2">IGST
                                <? echo (round($getmdata['igstperc'])) . "%" ?>
                            </td>
                            <td style="border-left: none;text-align: right;">
                                <? echo $getmdata['igstamt']; ?>
                            </td>
                        </tr>
                    <? } ?>
                    <tr style="">
                        <td style="text-align: right;border-right:1px solid black" colspan="2">Net Amount</td>
                        <td style="text-align: right;border-left: none;"><b>
                                <? echo $getmdata['totbillamt']; ?></b></td>
                    </tr>

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

                    </tr>


                </table>
            </div>

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

</html>