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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];
$para = $_GET['para'];
$zroot = $_SESSION["zdbroot"];


$cond = '';
$lcond = '';

$maindb = 'credmain';

$formname = 'Credit Note ';
$trandb = 'credoth';

$fseries = $_SESSION["society_" . $dbname];

$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));

$getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`company` where `code` = '$fseries' ")or die(mysqli_error($conn));
$comp2 = mysqli_fetch_array($getcomp2);


if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>
<link href="styles/inv_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }
    .right{
        text-align: right;
    }
    .left{
        text-align: left;
    }
    .center{
        text-align: center;
    }
    label{
        font-size:16px;
    }



</style>
</head>
<body>
    <?php
    $tdhg = "24px";
    $qry = mysqli_fetch_array($getqry);
    ?>
    <div class="page">
        <div class="subpage">
            <table width="100%">
                <tr>
                    <td style="width:25%">

                    </td>
                    <td style="width:50%">
                        <table style="width:100%">
                            <tr>
                                <td style="text-align: center;width: 100%;font-size: 24px"><? Echo $comp2[compname] ?></td>
                            </tr>
                            <tr>
                                <td class="center"><label class="label-control" style=""><? Echo $comp2[address] . " " . $comp2[city] . " " . $comp2[pin]; ?></label></td> 
                            </tr>
                            <tr>
                                <td style="width:33.33%; text-align: center "><label class="label-control"><h4><? Echo $formname; ?></h4></label></td> 
                            </tr>
                        </table> 
                    </td>
                    <td style="width:25%">

                        <table style="width:100%">
                            <tr>
                                <!--<td style="width:33.33%;text-align: right"><img src="images/since_logo.png" style="width: 130px;height: 60px"></td>--> 
                            </tr>
                        </table> 
                    </td>
                </tr>
            </table>

            <div class="border">

                <div class="row">
                    <?
                    $getpartyname = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$qry[accode]' AND `grpcode`='010'")or die(mysqli_error($conn));
                    $mpartyname = mysqli_fetch_array($getpartyname);
                    $partyname = $mpartyname[name];
                    $address = $mpartyname[address];
                    $wing = $mpartyname[wing];
                    $flatno = $mpartyname[flatno];
                    $city = $mpartyname[city];
                    $pin = $mpartyname[pin];
                    $panno = $mpartyname[vattin];
                    $gstno = $mpartyname[gstno];
                    ?>
                    <table style="width:100%;" class=" pad">


                        <tr>
                            <td width="7    %" class="">
                                <label class="">M/s.</label>
                            </td>
                            <td width="43%" class="">
                                <label class=""><? Echo $partyname; ?></label>
                            </td>
                            <td width="15%" class="text-right">
                                <label class="label-control">Voucher No  :</label>
                            </td>
                            <td width="35%">
                                <label class="label-control">&nbsp;<? Echo $qry[vouchno]; ?></label>
                            </td>
                        </tr>
                        <tr>
                            <td  class="">
                                <label class="">Wing:</label>
                            </td>
                            <td  class="">
                                <label class=""><? Echo $wing . "&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;    " . " " . "Flat No." . "&nbsp; " . $flatno; ?></label>
                            </td>
                            <td  class="text-right">
                                <label class="label-control">Date   :</label>
                            </td>
                            <td  class="">
                                <label class="label-control">&nbsp;<? Echo $qry[mydt]; ?></label>
                            </td>
                        </tr>
                        <?php if ($gstno != '') { ?>
                            <tr>
                                <td  class="">
                                    <label class="">GST No.</label>
                                </td>
                                <td  class="">
                                    <label class=""><? Echo $gstno; ?></label>
                                </td>
                                <td  class="text-right">
                                    <label class="label-control"></label>
                                </td>
                                <td  class="">
                                    <label class="label-control"></label>
                                </td>
                            </tr>
                        <?php } if ($panno != '') { ?>
                            <tr>
                                <td  class="">
                                    <label class="">GST No.</label>
                                </td>
                                <td  class="">
                                    <label class=""><? Echo $gstno; ?></label>
                                </td>
                                <td  class="text-right">
                                    <label class="label-control"></label>
                                </td>
                                <td  class="">
                                    <label class="label-control"></label>
                                </td>
                            </tr>
                        <?php } ?>
                    </table>
                </div>
                <table class="table-condensed table-hover" style="width: 100%; border:1px solid black">
                    <thead  class="mySearchTr">
                        <tr > 
                            <th style="width: 5%;border: 1px solid black;">Sr.</th>
                            <th style="width: 75%;border: 1px solid black;">Description</th>
                            <th class="text-right" style="width: 20%;border: 1px solid black;">Amount</th>                                    
                        </tr> 
                    </thead>
                    <?
                    $ctab = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$qry[vouchno]' ORDER BY `srno`")or die(mysqli_error($conn));
                    while ($tran = mysqli_fetch_array($gettran)) {
                        $getdeb = mysqli_query($conn, "SELECT name FROM `accmast` WHERE `accode`='$tran[debparty]' ")or die(mysqli_error($conn));
                        $fetdeb = mysqli_fetch_array($getdeb);
                        ?>
                        <tr style="height: <?= $tdhg; ?>">
                            <td class="numeric" style="border:1px solid black;font-size:16px;"><? Echo $tran[srno]; ?></td>
                            <td style="border:1px solid black;font-size:16px; "><? Echo $fetdeb[name]; ?></td>
                            <td class="numeric text-right" style="border:1px solid black;font-size:16px;"><? Echo $tran[amount]; ?></td>
                        </tr>
                        <?
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 27) {
                        for ($i = $ctab; $i < 28; $i++) {
                            ?>
                            <tr style="height: <?= $tdhg; ?>">
                                <td style="border:1px solid black;"></td>
                                <td style="border:1px solid black;"></td>
                                <td style="border:1px solid black;"></td>
                            </tr>
                            <?php
                        }
                    }
                    ?> 
                </table>
                <?php
                $mwords = round($qry[billamt]);
                $words = rsword($mwords);
                ?>
                <table width="100%" >
                    <tr>
                        <td class="right pad" style="border:1px solid black;" >
                            <label class=" pad" >&nbsp;<strong>Total</strong></label>
                        </td>
                        <td width="20%" style="border:1px solid black;font-size: 13px" class="right pad "><label><strong>&nbsp;&nbsp;<?php echo $qry[billamt]; ?></strong></label></td>
                    </tr>
                    <tr>
                        <td class="pad" style="border:1px solid black;" >
                            <label class=" pad"><i class="fa fa-inr"></i>&nbsp;<strong><?php Echo $words . " Only"; ?></strong></label>
                        </td>
                        <td width="20%" style="border:1px solid black;font-size: 13px" class="right pad "><label><strong>&nbsp;</strong></label></td>
                    </tr>
                    <tr>    
                        <td width="80%" style="border:1px solid black;" ><label class="pad">Narration : <? Echo $qry[rem1]; ?></label></td>
                        <td width="20%" style="border:1px solid black;"><label class="pad"></label></td>
                    </tr>
                </table>
                <table class="" align='center' style="border:none;height:35%;width:90%;">
                    <tr width="50%">
                        <td><b>&nbsp;</b></td>
                        <td width="40%" class="text-right" style="font-size: 15px"> 
                            <strong>For&nbsp;<?php echo $comp2[compname] ?></strong>
                        </td>
                    </tr>   
                    <tr width="50%">
                        <td><b>&nbsp;</b></td>
                        <td width="40%" class="text-right" style="font-size: 15px"> 
                            <strong>&nbsp;</strong>
                        </td>
                    </tr> 
                    <tr width="50%">
                        <td><b>&nbsp;</b></td>
                        <td width="40%" class="text-right" style="font-size: 15px"> 
                            <strong>&nbsp;</strong>
                        </td>
                    </tr> 
                    <tr width="50%">
                        <td><b>&nbsp;</b></td>
                        <td width="40%" class="text-right" style="font-size: 15px"> 
                            <strong>&nbsp;</strong>
                        </td>
                    </tr> 
                    <tr width="50%">
                        <td></td>
                        <td class="text-right" style="font-size: 15px"> 
                            <strong><?php echo$comp2[sigdesi]; ?></strong>
                        </td>
                    </tr>                        
                </table>
<!--                <table width="100%" style="border:1px solid black;">
        <tr>
            <td width="80%" style="border:1px solid black;" ><label class="pad">Narration : <? Echo $qry[rem1]; ?></label></td>

        </tr>
    </table>            -->
            </div>
        </div>
        <?php ?>

    </div>
</div>
<?php include('includes/linksfoot.php'); ?>
