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

$formname = 'DAMAGED';
$maindb = 'dammain';
$trandb = 'damtran';
$file = '';
$source = "DM";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';

$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'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

//$compqry = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `cono`= '1'") or die(mysqli_error($conn));
//$fcomp = mysqli_fetch_array($compqry);


// $getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[party]'") or die(mysqli_error($conn));
// $getp = mysqli_fetch_array($getpaccode);
// $add1 = $getp['add1'];
// $add2 = $getp['add2'];
// $add3 = $getp['add3'];
// $city = $getp['city'];
// $pin = $getp['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/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: 165mm;
        min-height: 200mm;
        padding: 1mm;
        margin: 1mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 1px;
        /*background: white;*/

    }

    .subpage {
        border: 1px solid black;


    }

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

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

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

        .page {
            width: 165mm;
            min-height: 180mm;
            /* padding: 1mm; */
            /* margin: 1mm auto; */
            /*border: 1px  solid black;*/
            border-radius: 1px;
            /*background: white;*/

        }

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

        th {
            font-weight: bold;
            font-size: 15px;
        }
    }
</style>
<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);
if ($paytype == 6) {
    $payno = $zcomp['gpaydno'];
} else {
    $payno = $zcomp['gpayno'];
}
?>
<!--<body id="main_container" onload="window.print();">-->

<body id="main_container" onload="">
    <div class="book">
        <div class="page">
            <!-- <div class="subpage"> -->
            <div class='col-md-12 col-lg-12'>
                <table style="width: 100%">
                    <?php
                    require("includes/dbconnect.php");
                    $comp = mysqli_query($conn, "SELECT * FROM `company`") or die(mysql_errno());
                    $fcomp = mysqli_fetch_assoc($comp);
                    ?>
<br>
                    <tr>
                        <td style="text-align:center">
                            <img src="images/logo.png" alt="Logo" style="height: 111px;width: 40%;">
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:center"><b style="font-family:Arial;font-size:17px;">
                                <center style='background-color:black;color:white'><u><?= $formname ?></u></center>
                            </b></td>
                    </tr>
                </table>
            </div>
            <?php
            mysqli_select_db($conn, $zdb);

            ?>
            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                <table class="table table-border table-hover" style="width:100%">
                    <tr>
                        <td style="text-align: left; width:5%"><b>Voucher:</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:50%"><?php echo $getmdata['vouchno']; ?></td>
                        <td style="text-align: right ; width:20%"><b>Date:</b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:20%"><?php echo $getmdata['vouchdt']; ?></td>
                    </tr>
                </table>
            </div>
            <div style="border:1px solid black;">
                <table style="width:100%" class="mc-table table-bordered">
                    <tr>
                        <th class="border" style="width:5%;  text-align: center;">Sr</th>
                        <th class="border" style="width:44%; text-align: center;">Item name</th>
                        <th class="border" style="width:10%; text-align: right;">Qty.</th>
                        <th class="border" style="width:10%; text-align: right;">Cost</th>
                        <th class="border" style="width:10%; text-align: right;">Amount</th>
                        <!--                            <th class="border" style="width:5%; text-align: right;">Disc.%</th>
                            <th class="border" style="width:7%; text-align: right;">Disc.</th>
                            <th class="border" style="width:5%; text-align: right;">Vat%</th>
                            <th class="border" style="width:7%; text-align: right;">Vat</th>-->
                        <!--<th class="border" style="width:12%; text-align: right;">Total</th>-->
                    </tr>

                    <?php
                    $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' 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:24px;">
                            <td class="border f12" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                            <td class="border f12"><?php echo "$getb[name]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[qty]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[cost]"; ?></td>
                            <td class="border f12" style="text-align: right;"><?php echo "$row[amount]"; ?></td>
                            <!--                                <td class="border f12" style="text-align: right"><?php // echo "$row[discperc]"; 
                                                                                                                    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[discamt]"; 
                                                                                    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[vatperc]"; 
                                                                                    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[vat]"; 
                                                                                    ?></td>
                                <td class="border f12" style="text-align: right"><?php // echo "$row[total]"; 
                                                                                    ?></td>-->
                        </tr>
                        <?
                        $ctab = $ctab + 1;
                        $grqty = $grqty + $row['totqty'];
                        $totamt = $totamt + $row['amount'];
                    }
                    if ($ctab < 17) {
                        for ($i = $ctab; $i <= 17; $i++) {
                            $ctab = $ctab + 1;
                        ?>
                            <tr style="height:24px;">
                                <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>
                                    <td class="border"></td>-->

                            </tr>
                    <?php
                        }
                    }
                    ?>

                    <tr style="height:25px;">
                        <td class="border" colspan="3"><?= $getmdata['rem1'] . ' ' . $getmdata['rem2']; ?></td>
                        <td class="border text-right f12 bold">Total</td>
                        <td class="border text-right f12 bold"><?php echo number_format(round($totamt), 2) ?></td>
                        <!--<td class="border"></td>-->
                    </tr>


                    <!--                        <tr style="height:25px;">
                            <td class="border" colspan="8">GPAY No. <?= $payno ?></td>        

                        </tr>    -->
                </table>
                <table class="cust-cal table " style="" style="width:100%">

                    <tr>
                        <td style="width:50%">

                            <!--                                <table style="width:100%">
                                    <?php if ($zcomp['bank'] != '') { ?>
                                        <tr>
                                            <td style="width:25%">Bank Name</td>
                                            <td style="width:75%"><?= $zcomp['bank']; ?></td>
                                        </tr>
                                        <tr>
                                            <td style="width:25%">A/c. No.  </td>
                                            <td style="width:75%"><?= $zcomp['acno']; ?></td>
                                        </tr>
                                        <tr>
                                            <td style="width:25%">Branch</td>
                                            <td style="width:75%"><?= $zcomp['branch']; ?></td>
                                        </tr>
                                        <tr>
                                            <td style="width:25%">IFSC</td>
                                            <td style="width:75%"><?= $zcomp['bankcode']; ?></td>
                                        </tr>
                                        <tr>
                                            <td colspan="2">&nbsp;</td>
                                        </tr>
                                    <?php } ?>
                                    <tr>
                                        <td colspan="2"><b>Proforma Validity for only 12 hrs.</b></td>
                                    </tr>
                                </table>-->
                        </td>
                        <td style="width:50%">
                            <table style="width:100%">
                                <tr>

                                    <td class="" style="text-align: right; width: 50%"><b><? echo "For $zcomp[compname]"; ?></b></td>

                                <tr>
                                    <td class="" style="text-align: left; height: 50px;">&nbsp;</td>

                                </tr>
                                <tr>

                                    <td class="" style="text-align: right; width: 50%">Authorised Signatory</td>

                                </tr>
                            </table>
                        </td>
                    </tr>
                    <!--                        <tr>
                            <td colspan="2">
                                <b style="font-size:16px">Rupess <?php echo rsword(round($getmdata["billamt"])); ?> Only</b>
                            </td>
                        </tr>-->
                </table>
            </div>
        </div>
    </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function() {
            formGeneral();
        });
    </script>
</body>

</html>