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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Crednote Print";

$maindb = 'credmain';
$trandb = 'credoth';

$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));
$getdata = mysqli_fetch_array($getqry);


$cmpname = mysqli_query($conn, "SELECT * From cepheisy_msp_root.`company`")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);



//$gettran = mysqli_query($conn, "SELECT * From $trandb ")or die(mysqli_error($conn));
//$showtran = mysqli_fetch_array($gettran);

include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    thead{
        font-size:12px;
    }
    label{
        font-size:12px;
    }
    #id1{
        font-size:10px;
    }
    #id2{
        border:1px solid black;
        border-left:none;
        height: 250px
    }
    #id3{
        border:1px solid black;
        height: 250px
    }
</style>
</head>
<body>
    <?php
    $tdhg = "24px";
    ?>
    <a class="btn btn-primary goBack" onclick="window.close()" style="float: right">Go Back</a>
    <div class="page">
        <div class="subpage" style="margin-top: 1px">
            <div class="row">
                <div class="col-sm-12 text-center">
                    <h1><? Echo $getcmpname['name']; ?></h1>
                    <h4>
                        <?php echo $getcmpname['add1'] . ", " . $getcmpname['add2'] . ", " . $getcmpname['add3']; ?><br>
                        <?php echo $getcmpname['station'] . ", " . $getcmpname['city'] . "-" . $getcmpname['pin']; ?><br>
                        <?php echo "Email :" . $getcmpname['email'] . " &nbsp " . "Contact No :" . $getcmpname['tel'] . "/" . $getcmpname['mobile']; ?>
                    </h4>
                    <hr>
                </div>
            </div>

            <h3 class="text-center" >CREDIT NOTE</h3>
            <div class="border" style="height:100px" >
                <table style="width:100%;">
                    <tr>
                        <th style="color:black; width:10%; text-align: right"><label> M/s. &nbsp </label></th>
                        <th style="color:black; width:50%"><label><?php echo $showparty['name']; ?></label></th>
                        <th style="color:black; width:15%;"><label>No &nbsp</label> </th>
                        <td style="color:black; width:5%">:</td>
                        <td style="color:black; width:20%"><?php echo $getdata['vouchno']; ?></td>
                    </tr>
                </table>
                <table style="width:100%; ">
                    <tr>
                        <th style="color:black; width:10%"></th>
                        <td style="color:black; width:50%"></td>
                        <th style="color:black; width:15%;"><label>DATE </label></th>
                        <td style="color:black; width:5%;">:</td>
                        <td style="color:black; width:20%"><?php echo $getdata[mydt]; ?></td>
                    </tr>
                </table>
<!--                <table style="width:100%; ">
                    <tr>
                        <th style="color:black; width:10%"></th>
                        <td style="color:black; width:50%"></td>
                        <th style="color:black; width:15%;"><label>Type</label></th>
                        <td style="color:black; width:5%;">:</td>
                        <td style="color:black; width:20%"><?php echo "Othe"; ?></td>
                    </tr>
                </table>-->
            </div>
            <div style="border:1px solid black; border-top: none;">
                <table class="table table-hover table-bordered" >
                    <tr style="">
                        <th style="width:5%;  color:black;"><label>Sr.</label></th>
                        <th style="width:20%; color:black;"><label>Description</label></th>
                        <th style="width:10%; 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)) {
                        $itemname = $showtran[itemname];
                        

                        Echo"<tr>";
                        Echo"<td style=''>$showtran[srno]</td>";
                        Echo"<td style=''>$showtran[descrip]</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>
                                
                            </tr>      
                            <?php
                        }
                    }
                    ?>
                </table>
            </div>
            <div >
                <div style='float: left; width:372px; height:60px' class='border'>
                    <table style="width:100%">
                        <tr>
                            <th style="color:black;width:20%;"><label>Remark</label></th>
                            <td style="color:black;width:5%;">:</td>
                            <td style="color:black;width:75%;"><? Echo $getdata[remark1]; ?></td>

                        </tr>
                        <tr>
                            <th style="color:black;width:20%;"><label></label></th>
                            <td style="color:black;width:5%;"></td>
                            <td style="color:black;width:75%;"><? Echo $getdata[remark2]; ?></td>

                        </tr>
                    </table>
                </div>
                <div style='float:right; width:372px;  height:60px' class='border'>
                    <table class='table'>
                        <tr>
                            <th style="color:black;"><label>Sub Total:</label></th>
                            <td class='text-right'><? Echo $getdata[subtotal]; ?></td>
                        </tr>
                        <tr>
                            <th style="color:black;"><label>Total Amount:</label></th>
                            <td class='text-right'><? Echo $getdata[netamt]; ?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div style="border:1px solid black;">
                <table class="table">
                    <tr>
                        <td><label><?php Echo rsword($getdata[netamt]); ?></label></td>
                    </tr>
                </table>
            </div>
            <div style="width: 100%">
                <div style="width: 50%; float: left;">
                    <div style=" padding-bottom: 30px; ">
                        <table style="width:100%;">
                            <tr>
                                <td style="padding-right:15px; width:30%;">E.& &nbsp O.E</td>
                            </tr>
                            <tr>
                                <td style="padding-right:15px; width:30%;">Subject to Mumbai Jurisdiction</td>
                            </tr>
                        </table>
                    </div>
                </div> 
                <div style="width: 50%;float: right;">
                    <table style="width:100%;">
                        <tr>

                            <td style="text-align:right; padding-right:15px;padding-top:15px;"><label><?php Echo " For " . $getcmpname['name']; ?></label></td>
                        </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right; padding-right:15px;padding-top:50px;"><label><?php Echo " Authorised Singnatory"; ?></label></td>
                        </tr>
                    </table>
                </div> 
            </div>
            <!--            <div style=" padding-bottom: 30px; ">
                            <table style="width:100%;">
                                <tr>
                                    <td style="padding-right:15px;padding-top:15px; width:30%;">E.& &nbsp O.E</td>
                                    <td style="padding-right:15px;padding-top:15px; width:60px;"></td>
                                    <td style="text-align:right; padding-right:15px;padding-top:15px;"><label><?php Echo " For " . $getcmpname['name']; ?></label></td>
                                </tr>
                            </table>
                        </div>-->
        </div>
    </div>
    <?php include('includes/linksfoot.php'); ?>
