<?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'];
$prnsuit = $_GET['prnsuit'];
$prnbrand = $_GET['prnbrand'];

$cond = '';
$lcond = '';
$formname = "Proforma";
$maindb = 'profmain';
$trandb = 'proftran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as mydt,  DATE_FORMAT(`lrdate`, '%d-%m-%Y')as mylrdt FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`") or die(mysqli_error($conn));

if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>

<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    
    @media screen,print {
    
    body {
        font-size: 15px;
    }
    
    .skf13 {
        font-size: 14px;
    }
    
    .watermarked {
        position: relative;
    }

    .watermarked:after {
        content: "";
        display: block;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 100px;
        left: 100px;
        background-image: url("images/2gauslogo.png");
        background-size: 500px 500px;
        background-position: 30px 30px;
        background-repeat: no-repeat;
        opacity: 0.1;
        overflow: visible;
    }

    .sklogo {
        position: relative;
    }

    .sklogo:after {
        content: "";
        display: block;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 10px;
        left: 10px;
        background-image: url(images/2gauslogo.png);
        background-size: 56px 55px;
        background-position: 147px -2px;
        background-repeat: no-repeat;
        opacity: 0.7;
    }
}
</style>
</head>

<body>
    <?php
    $tdhg = "26px";
    $qry = mysqli_fetch_array($getqry);
    ?>
    <div class="page">
        <div class="" style="margin-top: 1px">
            <div class="row sklogo">
                
                <?php
                $zroot = $_SESSION["zdir"];
                $zcomp = $_SESSION["comp_" . $dbname];
                $getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
                $comp = mysqli_fetch_array($getcomp);
                ?>
                <style>
                    @media print {
                        .noPrint {
                            display: none;
                        }
                    }
                </style>
                <table class="" width="100%" id="head">
                    <tr style="text-align:center">
                        <td style="font-size: 18px">
                            <label style='font-size:20px;'><? echo $comp['name']; ?></label>
                        </td>
                    </tr>
                    <tr style="text-align:center">
                        <td style="font-size: 12px">
                            <?php echo "<p style='font-size:13px;'>$comp[add1] $comp[add2] $comp[add3] $comp[city] $comp[pin]</p>" ?>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="row">
                <div class="col-sm-12 " style="text-align:center">
                    <label class="label-control marg" style=" font-size: 17px;"><? echo $formname; ?></label>
                </div>
            </div>
            <div class="border">
                <table class="table-borderless" style="width:90%;" align="center">

                    <tbody>

                        <?php
                        $getcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE  `accode`='$qry[party]' AND `grpcode`='010'") or die(mysqli_error($conn));
                        $lparty = mysqli_fetch_array($getcust);
                        ?>
                        <tr>
                            <td colspan="" style="width:70%;">M/s. &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: <b><?php echo $lparty["name"]; ?></b></td>
                            <td style="width:30%;">Invoice No. : <b><? echo $myyear . '/' . $qry['invno']; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>

                        </tr>
                        <tr>
                            <td colspan="" style="width:70%;">Address &nbsp;&nbsp;&nbsp;&nbsp;: <b><?php echo $lparty['add1']; ?></b></td>
                            <td colspan="" style="width:30%;"><span style="margin-left:36px">Date :</span> <b><?php echo $qry['mydt']; ?></b></td>
                        </tr>
                        <tr>
                            <td colspan="" style="width:50%;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><?php echo $lparty['add2']; ?></b></td>
                        </tr>
                        <?php if ($lparty['add3'] != '') { ?>
                            <tr>
                                <td colspan="" style="width:50%;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><?php echo $lparty['add3']; ?></b></td>
                            </tr>
                        <?php } ?>
                        <tr>
                            <td colspan="" style="width:50%;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><?php echo $lparty['city'] . " - " . $lparty['pin'] ?></b></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <!-- <div class="border">
                <div class="row" style="margin-top: 10px">
                    <table style="width: 100%">
                        <tr>
                            <td width="2%"></td>
                            <td width="25%"><label class="label-control">Invoice No. : <? echo $myyear . '/' . $qry['invno']; ?></label></td>
                            <td width="25%" class="text-right"><label class="label-control">Date: <? echo $qry['mydt']; ?></label></td>
                            <td width="25%"></td>
                        </tr>
                    </table>
                </div>
                <div class="row">
                    <?php
                    // $getcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE  `accode`='$qry[party]' AND `grpcode`='010'")or die(mysqli_error($conn));
                    // $cust = mysqli_fetch_array($getcust);
                    ?>
                    <table width="50%" class="table-hover pad">
                        <tr>
                            <td width="3%"></td>
                            <td width="17%" valign="top" class="numeric">
                                <label class="smfont pad">M/s.</label>
                            </td>
                            <td width="80%" class="pad">
                                <label class="smfont"><? echo $cust['name']; ?></label><br>
                                <label class="smfont"><? echo $cust['add1']; ?></label><br>
                                <label class="smfont"><? echo $cust['add2']; ?></label><br>
                                <?php if (!empty($cust['add3'])) { ?>
                                    <label class="smfont"><? echo $cust['add3']; ?></label><br>
                                <?php } ?>   
                                <label class="smfont">City : <? echo $cust['city']; ?>  /</label>
                                <label class="smfont">Pin  :  <? echo $cust['pin']; ?></label><br>
                                <label class="smfont">Tel  : <? echo $cust['tel']; ?></label><br>
                            </td>
                        </tr>
                    </table>
                </div>
            </div> -->
            <div style="border-right: 1px solid black;border-left: 1px solid black;">
                <div class="row">
                    <div class="col-sm-12 pad watermarked">
                        <table class="table-condensed table-hover" style="width: 100%">
                            <tr style="background:#1abc9c;border: 1px solid black; height: <?= $tdhg; ?>">
                                <th width="3%" class='text-left'>Sr.</th>
                                <th width="4%" class='text-left'>Brand/Logo</th>
                                <th width="5%">Code</th>
                                <th width="15%">Description</th>
                                <th width="6%" class='text-right'>Qty.</th>
                                <th width="9%" class='text-right'>Bale Qty.(Kgs)</th>
                                <th width="8%" class='text-right'>Tot. Qty.(Kgs)</th>
                                <th width="6%" class='text-right'>Rate</th>
                                <th width="6%" class='text-right'>Amount</th>
                            </tr>
                            <?
                            $ctab = 0;
                            $tbrand = '';
                            $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)) {
                                $mbrand = $tran['brand'];

                                $getbrand = mysqli_query($conn, "SELECT * FROM `brand` WHERE `code`='$tran[brand]'") or die(mysqli_error($conn));
                                $brand = mysqli_fetch_array($getbrand);

                                $getitem = mysqli_query($conn, "SELECT * FROM `item` WHERE `barcode`='$tran[itemcode]'") or die(mysqli_error($conn));
                                $item = mysqli_fetch_array($getitem);
                            ?>
                                <tr style="height: <?= $tdhg; ?>">
                                    <td class="skf13"><?= $tran['srno']; ?></td>
                                    <td class="skf13"><?= $brand['name']; ?></td>
                                    <td class="skf13"><?= $item['code']; ?></td>
                                    <td class=""><?= $item['name']; ?></td>
                                    <td class='text-right skf13'><?= $tran['qty']; ?></td>
                                    <td class='text-right skf13'><?= $tran['baleqty']; ?></td>
                                    <td class='text-right skf13'><?= $tran['totqty']; ?></td>
                                    <td class='text-right skf13'><?= $tran['rate']; ?></td>
                                    <td class='text-right skf13'><?= $tran['amount']; ?></td>

                                </tr>
                                <?
                                $tottaka = $tran['taka'] + $tottaka;
                                $totqty = $tran['invqty'] + $totqty;
                                $ctab = $ctab + 1;
                            }
                            if ($ctab < 27) {
                                for ($i = $ctab; $i < 27; $i++) {
                                ?>
                                    <tr style="height: <?= $tdhg; ?>">
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                            <?php
                                }
                            }
                            ?>
                        </table>
                    </div>
                </div>
            </div>
            <div class="border">
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <table class="table-hover  pad" style="float: left;width:65%">
                            <tr>
                                <td><label class="smfont pad"><? echo $qry['remark1']; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad"><? echo $qry['remark2']; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad"><? echo $qry['remark3']; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont pad"><? echo $qry['remark4']; ?></label></td>
                            </tr>
                            <tr>
                                <td><label class="smfont"></label></td>
                            </tr>
                        </table>
                        <table class="table-hover " style="float: left;width:35%">
                            <tr>
                                <td><label class="smfont pad">Sub Total</label></td>
                                <td><label class="smfont pad"></label></td>
                                <td class="numeric"><label class="smfont pad"><? echo $qry['tqty']; ?></label></td>
                                <td class="numeric"><label class="smfont pad"><? echo $qry['tweight']; ?></label></td>
                                <td class="numeric"><label class="smfont pad"><? echo $qry['subtotal']; ?></label></td>
                            </tr>
                            <?php if ($qry['discount'] > 0) { ?>
                                <tr>
                                    <td><label class="smfont pad">Discount </label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['discperc'] . "%"; ?></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['discount']; ?></label></td>
                                </tr>
                            <?php } ?>
                            <?php if ($qry['freight'] > 0) { ?>
                                <tr>

                                    <td><label class="smfont pad">Freight </label></td>
                                    <td><label class="smfont pad"></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['freight']; ?></label></td>

                                </tr>
                            <?php } ?>
                            <?php if ($qry['labour'] > 0) { ?>
                                <tr>

                                    <td><label class="smfont pad">Labour</label></td>
                                    <td><label class="smfont pad"></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['labour']; ?></label></td>

                                </tr>
                            <?php } ?>
                            <?php if ($qry['tempo'] > 0) { ?>
                                <tr>

                                    <td><label class="smfont pad">Tempo</label></td>
                                    <td><label class="smfont pad"></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['tempo']; ?></label></td>

                                </tr>
                            <?php } ?>
                            <?php if ($qry['packing'] > 0) { ?>
                                <tr>

                                    <td><label class="smfont pad">Packing</label></td>
                                    <td><label class="smfont pad"></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['packing']; ?></label></td>

                                </tr>
                            <?php } ?>
                            <?php if ($qry['allchrg'] > 0) { ?>
                                <tr>

                                    <td><label class="smfont pad">All Charges</label></td>
                                    <td><label class="smfont pad"></label></td>
                                    <td class="numeric"><label class="smfont pad"><? echo $qry['allchrg']; ?></label></td>

                                </tr>
                            <?php } ?>
                        </table>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <table class="table-hover " style="float: left;width:65%">
                            <tr>
                                <td></td>
                                <td><label class="smfont pad"></label></td>
                                <td></td>
                            </tr>
                        </table>
                        <table class="table-hover tborder " style="float: left;width:35%">
                            <tr>
                                <td><label class="smfont pad">Bill Amount</label></td>
                                <td class="numeric"><label class="smfont pad"><i class="fa fa-rupee"></i></label></td>
                                <td class="numeric"><label class="smfont pad"><? echo number_format(round($qry['netamt']), 2); ?></label></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <?php
            $mwords = round($qry['netamt']);
            //            $words = convert_number_to_words($mwords);
            $words = rsword($mwords);
            ?>
            <div class="border">
                <div class="row">
                    <div class="col-sm-12" style="padding: 0px">
                        <label class="smfont pad"><?php echo $words . " Only"; ?></label>
                    </div>
                </div>
            </div>
            <?php
            $getcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
            $comp = mysqli_fetch_array($getcomp);
            ?>
            <div class="">
                <div class="row">
                    <div class="col-sm-12" style="padding:0px">
                        <table class="table-hover" width='100%'>
                            <tr>
                                <td><label class="smfont">E.O.& E.</label></td>
                                <td class="numeric">
                                    <label class="smfont"><?php echo "For " . $comp['name'] ?></label><br>
                                    <!--<img src="assets/img/sign.jpg" alt="sign">-->
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php include('includes/linksfoot.php'); ?>