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

$cond = '';
$lcond = '';
$formname = "TAX INVOICE";
$maindb = 'salemainexp';
$trandb = 'saletranexp';
$keyfld = 'vouchno';
$vouchno = $_GET["vouchno"];
$zroot = $_SESSION["zdir"];
$fseries = $_SESSION["series_" . $dbname];

$gmain = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE $keyfld = '$vouchno'  ") or die(mysqli_error($conn));
$fmain = mysqli_fetch_array($gmain);

$getconsg = mysqli_query($conn, "SELECT `accode`,`name`,`add1`,`add2`,`add3`, `tel`,`mobile`,`mobile2` FROM `accmast` WHERE `accode`= '$fmain[consignee]' ") or die(mysqli_error($conn));
$consg = mysqli_fetch_array($getconsg);

$getparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$fmain[partyname]' and grpcode = '010'") or die(mysqli_error($conn));
$party = mysqli_fetch_array($getparty);

$getcomp = mysqli_query($conn, "SELECT code,init,compname,hoadd1,hoadd2,hoadd3,hocity,hopin FROM $zroot.`company` ")or die(mysqli_error($conn));
$comp = mysqli_fetch_array($getcomp);
include("includes/linkshead.php");
?>
<link href="MyStyle/rep_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }
    .f-s{
        font-size: 12px;
    }
    .border{
        border:1px solid black;
    }
    .bor{
        border-left: 1px solid black;
        border-right: 1px solid black;
    }

    .fontnew{
        font-family: 'Verdana';
        font-size : 11px;
        font : 'bold';

    }
    .smsfont{
        font-family: 'Verdana';
        font-size : 13px;
        /*font : 'bold';*/
    }
    table{
        width:100%;
    }
    table td {
        font-size: 12px;
        padding: 5px;
    }

</style>
</head>
<body>

    <div class="page">
        <div class="subpage" style="padding-top: 16px">
            <div class="row text-center"><h2>CUSTOM INVOICE</h2></div>
            <table>
                <tr>
                    <td width="50" class="border">
                        <table class=" ">
                            <tr><td>Exporter</td></tr>
                            <tr><td><b><?php echo $comp['compname']; ?></b></td></tr>
                            <tr><td><b><?php echo $comp['hoadd1']; ?></b></td></tr>
                            <tr><td><b><?php echo $comp['hoadd2']; ?></b></td></tr>
                            <tr><td><b><?php echo $comp['hoadd3']; ?></b></td></tr>
                        </table>
                    </td>
                    <td width="50" class="border">
                        <table class=" " width="100%">
                            <tr>
                                <td width="50%">Invoice No.</td>
                                <td width="50%">Invoice Date.</td>
                            </tr>
                            <tr style="border-bottom:1px solid black">
                                <td width="50%"><b><?php echo $fmain[voucher]; ?></b></td>
                                <td width="50%"><b><?php echo $fmain[invdate] ?></b></td>
                            </tr>
                            <tr>
                                <td width="50%">Order No.</td>
                                <td width="50%">Import Export Code</td>
                            </tr>
                            <tr>
                                <td width="50%"><b><?php echo $fmain[orderno] ?></b></td>
                                <td width="50%"><b><?php ?></b></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="border">
                        <table>
                            <tr><td>Consignee</td></tr>
                            <tr><td><b><?php echo $consg[name]; ?></b></td></tr>
                            <?php if ($consg[add1] != '') { ?><tr><td>Address</td></tr><?php } ?>
                            <?php if ($consg[add1] != '') { ?><tr><td><b><?php
                                            echo $consg[add1];
                                        }
                                        ?></b></td></tr>
                            <?php if ($consg[add2] != '') { ?><tr><td><b><?php
                                            echo $consg[add2];
                                        }
                                        ?></b></td></tr>
                            <?php if ($consg[add3] != '') { ?><tr><td><b><?php
                                            echo $consg[add3];
                                        }
                                        ?></b></td></tr>
                            <?php if ($consg[mobile] != '') { ?><tr><td>Telephone : <?php
                                        echo $consg[mobile] . "/" . $consg[mobile2];
                                    }
                                    ?></td></tr>
                            <?php if ($consg[fax] != '') { ?><tr><td>Fax : </td></tr><?php } ?>
                        </table>
                    </td>

                    <td class="border">
                        <table>
                            <tr><td>Buyer</td></tr>
                            <tr><td><b><?php echo $party[name] ?></b></td></tr>
                            <?php if ($consg[add1] != '') { ?><tr><td>Address</td></tr><?php } ?>
                            <?php if ($consg[add1] != '') { ?><tr><td><b><?php
                                            echo $party[add1];
                                        }
                                        ?></b></td></tr>
                            <?php if ($consg[add2] != '') { ?><tr><td><b><?php
                                            echo $party[add2];
                                        }
                                        ?></b></td></tr>
                            <?php if ($consg[add3] != '') { ?><tr><td><b><?php
                                            echo $party[add3];
                                        }
                                        ?></b></td></tr>
                            <?php if ($party[mobile] != '') { ?><tr><td>Telephone : <?php
                                        echo $party[mobile] . "/" . $party[mobile2];
                                    }
                                    ?></td></tr>
                            <?php if ($party[fax] != '') { ?><tr><td>Fax : </td></tr><?php } ?>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="border">
                        <table>
                            <tr>
                                <td width="50" style="border-right:1px solid black ">
                                    <table>
                                        <tr><td>Port Of Discharge</td></tr>
                                        <tr><td><b><?php echo $fmain[portofdischarge] ?></b></td></tr>
                                    </table>    
                                </td>
                                <td width="50%">
                                    <table>
                                        <tr><td>Port of Loading</td></tr>
                                        <tr><td><b><?php echo $fmain[portofloading] ?></b></td></tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td class="border">
                        <table>
                            <tr>
                                <td width="50" style="border-right:1px solid black ">
                                    <table>
                                        <tr><td>Country of Origin of Goods</td></tr>
                                        <tr><td><b><?php echo $fmain[portofdischarge] ?></b></td></tr>
                                    </table>
                                </td>
                                <td width="50%">
                                    <table>
                                        <tr><td>Country of Final Destinations</td></tr>
                                        <tr><td><b><?php echo $fmain[portofloading] ?></b></td></tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <table class="border table-striped">
                <tr>
                    <td width="30%" class="border"><b>Mark & Nos.</b></td>
                    <td width="30%" class="border"><b>Nos. & Kind of Packages</b></td>
                    <td width="40%" class="border"><b>Description of Goods</b></td>
                </tr>
                <tr>
                    <td  class="border"><?php echo $fmain[marksnos1]; ?></td>
                    <td  class="border"><?php echo $fmain[kindpack1]; ?></td>
                    <td  class="border"><?php echo $fmain[descgood1]; ?></td>
                </tr>
                <tr>
                    <td  class="border"><?php echo $fmain[marksnos2]; ?></td>
                    <td  class="border"><?php echo $fmain[kindpack2]; ?></td>
                    <td  class="border"><?php echo $fmain[descgood2]; ?></td>
                </tr>
                <tr>
                    <td  class="border"><?php echo $fmain[marksnos3]; ?></td>
                    <td  class="border"><?php echo $fmain[kindpack3]; ?></td>
                    <td  class="border"><?php echo $fmain[descgood3]; ?></td>
                </tr>
                <tr>
                    <td  class="border"><?php echo $fmain[marksnos4]; ?></td>
                    <td  class="border"><?php echo $fmain[kindpack4]; ?></td>
                    <td  class="border"><?php echo $fmain[descgood4]; ?></td>
                </tr>
            </table>
            <table class="border">
                <tr>
                    <td class="border" width="3%"><b>Sr.</b></td>
                    <td class="border" width="7%"><b>Barcode</b></td>
                    <td class="border" width="8%"><b>Item Code</b></td>
                    <td class="border" width="20%"><b>Item Name</b></td>
                    <td class="border" width="8%"><b>Hsncode</b></td>
                    <td class="border text-center" width="5%"><b>Gram</b></td>
                    <td class="border text-right" width="5%"><b>Unit</b></td>
                    <td class="border text-right" width="5%"><b>Mrp</b></td>
                    <td class="border text-right" width="5%"><b>Batch</b></td>
                    <td class="border text-right" width="5%"><b>Qty.</b></td>
                    <td class="border text-right" width="5%"><b>Rate</b></td>
                    <td class="border text-right" width="7%"><b>Amount</b></td>
                </tr>
                <?php
                $ctr = 0;
                $totqty = 0;
                $qry = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE vouchno='$fmain[vouchno]' ORDER BY srno") or die(mysqli_error($conn));
                while ($row = mysqli_fetch_array($qry)) {
                    
                    $gitemname = mysqli_query($conn, "SELECT `code`,`name` FROM `product` WHERE `prodcode`='$row[itemcode]'")or die(mysqli_error($conn));
                    $fitemname = mysqli_fetch_array($gitemname);
                    $itemname = $fitemname['name'];

                    $ctr++;
                    echo "<tr>";
                    echo "<td class='border'>$ctr</td>";
                    echo "<td class='border'>$row[barcode]</td>";
                    echo "<td class='border '>$row[itemcode]</td>";
                    echo "<td class='border '>$itemname</td>";
                    echo "<td class='border '>$row[hsncode]</td>";
                    echo "<td class='border text-right'>$row[gram]</td>";
                    echo "<td class='border text-right'>$row[unit]</td>";
                    echo "<td class='border text-right'>$row[mrp]</td>";
                    echo "<td class='border text-right'>$row[batch]</td>";
                    echo "<td class='border text-right'>$row[qty]</td>";
                    echo "<td class='border text-right'>$row[rate]</td>";
                    echo "<td class='border text-right'>$row[amount]</td>";
                    echo "</tr>";

                    $totqty = $totqty + $row[qty];
                }
                ?>
                <!--</table>-->
                <!--<table class="border">-->
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="border text-right">Total</td>
                    <td class="border text-right"><?php echo$totqty ?></td>
                    <td class="border"></td>
                    <td class="border text-right"><?php echo $fmain[grossamt] ?></td>
                </tr>
<!--            </table>-->
            <!--<table width="100%" class="border">-->
                <tr>
                    <td colspan="10" class="border text-right"><b>Disc. Amt.</b></td>
                    <!--<td class="border text-right"></td>-->
                    <td colspan="2" class="border text-right"><?php echo $fmain[discount] ?></td>
                </tr>
                <tr>
                    <td colspan="10" class="border text-right" width="84%"><b>Taxable Value</b></td>
                    <!--<td class="border text-right" width=" "></td>-->
                    <td colspan="2" class="border text-right" width="16%"><?php echo $fmain[taxableamt] ?></td>
                </tr>
<!--                <tr>
                    <td colspan="10" class="border text-right" width="84%"><b>Taxable Value</b></td>
                    <td ><?php // echo $fmain[igstrate] ?></td>
                    <td class="border text-right" width="10%"><?php // echo $fmain[igstamt] ?></td>
                </tr>-->
                <tr>
                    <td class="border text-right" colspan="10"><b>Net Amt.</b></td>
                    <!--<td class="border text-right" width=""></td>-->
                    <td class="border text-right" colspan="2"><?php echo $fmain['billamt'] ?></td>
                </tr>
                <tr class="border">
                    <?php
                    if ($fmain['curr'] == 'R') {
                        $curr = 'Rupees';
                    } elseif ($fmain['curr'] == 'E') {
                        $curr = 'Euro';
                    } elseif ($fmain['curr'] == 'P') {
                        $curr = 'Pound';
                    } elseif ($fmain['curr'] == 'U') {
                        $curr = 'USD';
                    }
                    ?>
                    <td colspan="12">Amount Chargeable (in words) <b> : <?php echo $curr . ' ' . rsword($fmain["billamt"]) ?></b></td>
                </tr>
                
            </table>
            <table class="border">
                <tr>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="text-right"><b>
                            Signature & Date
                        </b></td>
                </tr>
            </table>

        </div>
    </div>

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