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

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

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

$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);

//$getgodown = mysqli_query($conn, "SELECT * FROM `godown` WHERE `code`= '$fmain[godown]'") or die(mysqli_error($conn));
//$getgd = mysqli_fetch_array($getgodown);


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">
                <div class="text-center">
                    <h3>PACKING LIST INVOICE</h3>
                </div>
            </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">Mark & Nos.</td>
                    <td width="30%" class="border">Nos. & Kind of Packages</td>
                    <td width="40%" class="border">Description of Goods</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="4%">Sr</td>
                    <td class="border" width="10%">Barcode</td>
                    <td class="border" width="5%">Item Code</td>
                    <td class="border" width="27%">Item Name</td>
                    <td class="border" width="10%">Hsncode</td>
                    <td class="border" width="7%">Gram</td>
                    <td class="border" width="7%">Unit</td>
                    <td class="border" width="7%">Batch</td>
                    <td class="border text-right" width="7%">Qty</td>
                </tr>
                <?php
                $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)) {

                    $barcode  = $row['barcode'];
                    $itemcode = $row['itemcode'];
//                    $itemname = $row['itemname'];
                    $hsncode  = $row['hsncode'];
                    $gram     = $row['gram'];
                    $unit     = $row['unit'];
                    $batch    = $row['batch'];
                    $qty      = $row['qty'];

                    $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'>$barcode</td>";
                    echo "<td class='border '>$itemcode</td>";
                    echo "<td class='border '>$itemname</td>";
                    echo "<td class='border '>$hsncode</td>";
                    echo "<td class='border text-right'>$gram</td>";
                    echo "<td class='border text-right'>$unit</td>";
                    echo "<td class='border text-right'>$batch</td>";
                    echo "<td class='border text-right'>$qty</td>";
                    echo "</tr>";

                    $totqty = $totqty + $row[qty];
                }
                ?>
                <tr>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="text-right" style="border-right:1px solid black">Total</td>
                    <td class="border text-right" width="7%"><?php echo $totqty ?></td>
                </tr>
            </table>
            <table class="border">
                <tr>
                    <td class="text-right" width="50%">&nbsp;</td>
                    <td class=" text-right" width=50%"></td>
                </tr>
                <tr>
                    <td class="text-right" width="50%">&nbsp;</td>
                    <td class="text-right" width=50%">Signature & Date.</td>
                </tr>
            </table>
        </div>
    </div>

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