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


$formname = 'Sale Return';
$maindb = 'credmain';
$trandb = 'credtran';
$file = '';
$source = "SR";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$fseries = $_SESSION["series"];
$keycond = "AND series = '$fseries'";
$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno' $keycond") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

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

//$gettrans = mysqli_query($conn, "SELECT name, code FROM `transpor` WHERE `code`= '$getmdata[transpor]'") or die(mysqli_error($conn));
//$ftrans = mysqli_fetch_array($gettrans);
?>

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

    .f12 {
        font-size: 12px;
    }

    .f11 {
        font-size: 11px;
    }

    .f13 {
        font-size: 13px;
        font-weight: bold;
        padding: 3px;
    }

    .f14 {
        font-size: 14px;
    }

    .f20 {
        font-size: 22px;
    }

    .f19 {
        font-size: 20px;
    }

    .bold {
        font-weight: bold;
    }

    .page {
        width: 190mm;
        min-height: 290mm;
        padding: 1mm;
        margin: 1mm auto;
        page-break-after: always;
    }

    .subpage {
        border: 1px solid black;
    }

    .border {
        border: 1px solid black;
        color: black;
        padding-right: 2px;
        padding-left: 3px;
    }

    hr.sk1 {
        margin-top: 15px;
        margin-bottom: 5px;
        border: 1px solid black;
    }

    th {
        font-weight: bold;
        font-size: 22px;
    }


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


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

        }

        hr.sk1 {
            margin-top: 15px;
            margin-bottom: 5px;
            border: 1px solid black;
        }

        th {
            font-weight: bold;
            font-size: 22px;
        }

        .border {
            border: 1px solid black;
            color: black;
            padding-right: 2px;
            padding-left: 3px;
        }

        .table2 {
            border: 2px solid black;
        }

        hr.sk1 {
            border: 1px solid black;

        }

        .f20 {
            font-size: 22px;
        }

        .f19 {
            font-size: 20px;
        }

        .skimg {
            width: 500px;
            height: 185px;
            margin-top: -13px
        }

    }

    .table2 {
        border: 2px solid black;
    }

    hr.sk1 {
        border: 1px solid black;

    }

    .f20 {
        font-size: 22px;
    }
</style>



<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);

?>

<body id="main_container" onload="window.print()">
    <div class="page tablerep">
        <div class="subpage">
            <tr>
                <td>
                    <center style='color:black'>Subject to Mumbai Jurisdiction</center>
                </td>
            </tr>
            <tr>
                <td>
                    <center style='color:black'><U>CREDIT NOTE</U></center>
                </td>
            </tr>
            <tr>
                <td>
                    <h2 style="font-family:Arial;font-weight:bolder;margin-top:5px;margin-bottom:3px">
                        <center style='color:black'><?= $zcomp['compname']; ?></center>
                    </h2>
                </td>
            </tr>
            <tr>
                <td>
                    <b style="font-family:Arial;font-size:16px;">
                        <center style='color:black'>Onions, Potatoes and Garlic Wholesale & Retail Merchants</center>
                    </b>
                </td>
            </tr>
            <tr>
                <td>
                    <span style="font-family:Arial;font-size:16px;">
                        <center style='color:black'><?= $zcomp['hoadd1'] . $zcomp['hoadd2'] . $zcomp['hoadd3'] . $zcomp['hocity'] . " - " . $zcomp['hopin']; ?></center>
                    </span>
                </td>
            </tr>
            <tr>
                <td>
                    <span style="font-family:Arial;font-size:16px;">
                        <center style='color:black'><?= "Tel : " . $zcomp['htel'] . "     " . "Mobile : " . $zcomp['hmobile']; ?></center>
                    </span>
                </td>
            </tr>

            <br>
            <table class="mytable" style="width:100%;margin-left:2%;">

                <tr>
                    <td style="text-align: left; width:55%;font-size:20px"><b>M/s. </b><?php echo "$cust[name]"; ?></td>
                    <td style="text-align: right ; width:20%;font-size:22px"><b>Bill No. &nbsp;</b></td>
                    <td style="width:1%;font-size:22px">:</td>
                    <td style="text-align: left; width:24%;font-size:22px"><?php echo " $getmdata[vouchno]"; ?></td>

                </tr>

                <tr>
                    <td style="text-align: left; width:55%;font-size:20px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo "$cust[add1]"; ?></td>
                    <td style="text-align: right ; width:20%;font-size:22px"><b>Date &nbsp;</b></td>
                    <td style="width:1%;font-size:22px">:</td>
                    <td style="text-align: left; width:24%;font-size:22px"><?php echo "$getmdata[vouchdt]"; ?></td>
                </tr>
                <tr>
                    <td style="text-align: left; width:55%;font-size:20px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo "$cust[add2] $cust[add3]"; ?></td>
                    <td style="text-align: right ; width:20%"></td>
                    <td style="width:1%"></td>
                    <td style="text-align: left; width:24%"></td>
                </tr>

            </table>

            <br>

            <div style="border:1px solid black;">
                <table style="width:100%" class="">
                    <tr style="height:40px;">
                        <th class="border" style="width:30%; text-align: center;">Item</th>
                        <th class="border" style="width:8%; text-align: center;">Batch</th>
                        <th class="border" style="width:8%; text-align: center;">Bag</th>
                        <th class="border" style="width:10%; text-align: center;">Kg</th>
                        <th class="border" style="width:16%; text-align: center;">Rate/10Kg</th>
                        <th class="border" style="width:14%; text-align: center;">Amount</th>
                    </tr>

                    <?php
                    $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' $keycond order by srno") or die(mysqli_error($conn));
                    $mht = '20px';
                    $ctab = 0;
                    $grqty = 0;

                    while ($row = mysqli_fetch_array($tranpart)) {
                        $getbrand = mysqli_query($conn, "SELECT * FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                        $getb = mysqli_fetch_array($getbrand);
                    ?>
                        <tr class="border" style="height:40px;">
                            <td class="border f20"><?php echo "$getb[name]"; ?></td>
                            <td class="border f20" style="text-align: right;"><?php echo "$row[batch]"; ?></td>
                            <td class="border f20" style="text-align: right;"><?php echo "$row[cartqty]"; ?></td>
                            <td class="border f20" style="text-align: right;"><?php echo "$row[qty]"; ?></td>
                            <td class="border f20" style="text-align: right"><?php echo "$row[rate]"; ?></td>
                            <td class="border f20" style="text-align: right"><?php echo "$row[amount]"; ?></td>
                        </tr>
                        <?
                        $ctab = $ctab + 1;
                        $grqty = $grqty + $row['qty'];
                        $totamt = $totamt + $row['amount'];
                    }
                    if ($ctab < 8) {
                        for ($i = $ctab; $i <= 8; $i++) {
                            $ctab = $ctab + 1;
                        ?>
                            <tr style="height:40px;">
                                <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>
                        <td colspan="2">
                            <table border="solid 1px" style="border-collapse: collapse; width:100%">
                                <tbody style="border-collapse: collapse;font-size: 12px;">

                                    <tr style="height:38px;">
                                        <!-- <td class="border f16 bold" style="width:25%;">Bank Name</td> -->
                                        <td class="border f19 bold" style="width:75%;"><?= $zcomp['bankname'] ?></td>
                                    </tr>


                                    <tr style="height:38px;">
                                        <!-- <td class="border f16 bold" style="width:25%;">Branch</td> -->
                                        <td class="border f19 bold" style="width:75%;"><?= $zcomp['branchname'] ?></td>
                                    </tr>

                                    <tr style="height:38px;">
                                        <!-- <td class="border f16 bold" style="width:25%;">Account No.</td> -->
                                        <td class="border f19 bold" style="width:75%;">A/C. NO. <?= $zcomp['acno'] ?></td>
                                    </tr>

                                    <tr style="height:38px;">
                                        <!-- <td class="border f16 bold" style="width:25%;">IFSC Code</td> -->
                                        <td class="border f19 bold" style="width:75%;">IFSC CODE <?= $zcomp['ifccode'] ?></td>
                                    </tr>
                                    <tr style="height:38px;">
                                        <!-- <td class="border f16 bold" style="width:25%;">A/c. Name</td> -->
                                        <td class="border f19 bold" style="width:75%;"><span style="border:2px solid black">G Pay : 9967087863</span></td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td colspan="4" style="border:none;border-collapse: collapse; ">
                            <table border="solid 1px" style="border-collapse: collapse; width:100%">
                                <tbody style="border-collapse: collapse;font-size: 12px;">

                                    <tr style="height:38px;">
                                        <!-- <td class="border f20 bold" colspan="2"></td> -->
                                        <td class="border text-right f20 bold" colspan="2">Total</td>
                                        <td class="border text-right f20 bold"><?php echo number_format(round($totamt), 2) ?></td>
                                    </tr>


                                    <?php if ($getmdata['packchgs'] > 0) { ?>
                                        <tr style="height:38px;">
                                            <!-- <td class="border" colspan="2"></td> -->
                                            <td class="border text-right f20 bold" colspan="2">Hel</td>
                                            <td class="border text-right f20 bold" colspan="2" ><?php echo number_format(round($getmdata['packchgs']), 2) ?></td>
                                        </tr>

                                    <?php } else { ?>
                                        <tr style="height:38px;">
                                            <!-- <td class="border" colspan="2"></td> -->
                                            <td class="border text-right f20 bold" colspan="2"></td>
                                            <td class="border text-right f20 bold" colspan="2" ></td>
                                        </tr>
                                    <?php }  ?>
                                    <tr style="height:38px;">
                                        <!-- <td class="border" colspan="2"><b></b></td> -->
                                        <td class="border text-right f20 bold" colspan="2">Bill Amount</td>
                                        <td class="border text-right f20 bold" colspan="2"><?php echo rajnumformat(round($getmdata['billamt'])) ?></td>
                                    </tr>
                                    <tr style="height:38px;">
                                        <!-- <td class="border f20 bold" colspan="2"></td> -->
                                        <td class="border text-right f20 bold" colspan="2"></td>
                                        <td class="border text-right f20 bold" colspan="2"></td>
                                    </tr>
                                    <tr style="height:38px;">
                                        <!-- <td class="border f20 bold" colspan="2"></td> -->
                                        <td class="border text-right f20 bold" colspan="2"></td>
                                        <td class="border text-right f20 bold" colspan="2"></td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>



                </table>
                <table class="" style="width:100%">

                    <tr>
                        <td style="width:50%">
                        </td>
                        <td style="width:50%">
                            <table style="width:100%">
                                <tr>
                                    <td class="f20" style="text-align: right; width: 50%"><b><? echo "For $zcomp[compname]"; ?></b></td>
                                <tr>
                                    <td class="f20" style="text-align: left; height: 50px;">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="f20" style="text-align: right; width: 50%">Authorised Signatory</td>
                                </tr>
                            </table>
                        </td>
                    </tr>

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

</html>