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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
$zcomp = $_SESSION["comp_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);
$zyear = $myyear;

$vouch = $_GET['invno'];
$cond = '';
$lcond = '';
$formname = "E-Way Bill Print";

$saltype = $_REQUEST['saltype'];


if ($saltype == 'R') {
    $maindb = 'rawmain';
    $trandb = 'rawtran';
    $itemdb = 'rawmat';
    $gstdb = "gsteinvoice";
    $deemexp = 'L';
    $suptype = "B2B";
    $revchg = 'N';
} else {
    $maindb = 'gstmain';
    $trandb = 'gsttran';
    $itemdb = 'item';

    $gstdb = "gsteinvoice";
    $deemexp = 'L';
    $suptype = "B2B";
    $revchg = 'N';
}
//print "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as vouchdt, DATE_FORMAT(a.`ewaydt`, '%d-%m-%Y %h:%i:%p')as ewaydt,DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as docdate,b.gstno,
//                               b.name as transname, DATE_FORMAT(a.`uploaddate`, '%d-%m-%Y')as uploaddate FROM `$maindb` a,transport b WHERE vouchno='$vouch' and a.transporter = b.code ";
$getqry = mysqli_query($conn, "SELECT a.*, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as vouchdt, DATE_FORMAT(a.`ewaydt`, '%d-%m-%Y %h:%i:%p')as ewaydt, ewaydt as newaydt, DATE_FORMAT(a.`vouchdt`, '%d-%m-%Y')as docdate,b.gstno,
                               b.name as transname, DATE_FORMAT(a.`uploaddate`, '%d-%m-%Y')as uploaddate FROM `$maindb` a,transport b WHERE vouchno='$vouch' and a.transporter = b.code ") or die(mysqli_error($conn));
//print table($getqry);
$get = mysqli_fetch_array($getqry);

$compcd = $_SESSION["comp_" . $dbname];


$transactp = $get['transactype'];
if ($transactp == 1) {
    $transactype = "Regular";
} elseif ($transactp == 2) {
    $transactype = "Bill To - Ship To";
} elseif ($transactp == 3) {
    $transactype = "Bill From - Dispatch From";
} else {
    $transactype = "";
}


$uniqueno = $get['ewaybillno'];
$uploaddt = $get['uploaddate'];
if($get['ewaydt'] == ""){
    
$entrydate = $get['newaydt'];
}else{
$entrydate = $get['ewaydt'];
    
}


$irn = $get['irn'];
//browse($irn);
$getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`company`  where code ='$compcd'") or die(mysqli_error($conn));
$fetcomp2 = mysqli_fetch_array($getcomp2);

$getparty = mysqli_query($conn, "SELECT * FROM `accmast` where accode='$get[party]'") or die(mysqli_error($conn));
$fetparty = mysqli_fetch_array($getparty);
$getq2 = mysqli_query($conn, "SELECT * FROM `gsteinvoice` where invno='$get[invno]' and frm='$saltype'") or die(mysqli_error($conn));
$fetq2 = mysqli_fetch_array($getq2);
?>



<!DOCTYPE html>

<title><?= $formname; ?></title>



<style>
    table,
    td {
        border: 0px solid black;
    }

    table {
        border-collapse: collapse;
        width: 100%;
        text-align: left;
    }

    table.table1,
    td {
        padding: 15px;
    }

    .th1 {
        padding: 8px;
        padding-left: 70px;
    }
</style>

</head>

<body>



    <center>

        <!--<h2><?= $formname; ?></h2>-->

        <br>

        <h3 style="font-size:20px">Part - A Slip</h3>





        <table class="table1" style="width:55%">



            <tr>

                <th class="th1">E-Way Bill No:</th>

                <th class="th1"><?= $uniqueno; ?></th>

            </tr>



            <tr>

                <th class="th1">E-Way Bill Date:</th>

                <th class="th1"><?= $entrydate; ?></th>

            </tr>



            <tr>

                <th class="th1">Generated By:</th>

                <th class="th1"><?= $fetcomp2['gst'] . " - " . $fetcomp2['pname'] ?></th>

            </tr>



            <tr style="border-bottom: 1px solid black;">

                <th class="th1">Valid Form:</th>

                <th class="th1">Not Valid for Movement as Part B is not entered</th>

            </tr>


            <tr>

                <th class="th1" style="font-size:18px">IRN Details</th>
                <th class="th1"></th>

            </tr>

            <tr>

                <th class="th1">IRN:</th>

                <th class="th1"><?= $irn; ?></th>

            </tr>

            <tr>

                <th class="th1">Ack No:</th>

                <th class="th1"><?= $fetq2['ackno'] ?></th>

            </tr>

            <tr style="border-bottom: 1px solid black;">

                <th class="th1">Ack Date:</th>

                <th class="th1"><?= $uploaddt ?></th>

            </tr>


            <tr>

                <th class="th1" style="font-size:20px">Part-A</th>
                <th class="th1"></th>

            </tr>



            <tr>

                <th class="th1">GSTIN of Supplier</th>

                <th class="th1"><?= $fetcomp2['gst'] . " , " . $fetcomp2['pname'] ?></th>

            </tr>



            <tr>

                <th class="th1">Place Of Dispatch</th>

                <th class="th1"><?= $fetcomp2['city'] . " , " . $fetcomp2['state'] . " - " . $fetcomp2['pin'] ?></th>

            </tr>



            <tr>

                <th class="th1">GSTIN of Recipient</th>

                <th class="th1"><?= $fetparty['gstno'] . " , " . $fetparty['name'] ?></th>

            </tr>





            <tr>

                <th class="th1">Place of Delivery</th>
                <?php if ($get['delcity'] != '' && $get['delstate'] != '' && $get['delpin'] != '') { ?>
                    <th class="th1"><?= $get['delcity'] . " , " . $get['delstate'] . " - " . $get['delpin'] ?></th>
                <?php } else { ?>
                    <th class="th1"><?= $fetparty['city'] . " , " . $fetparty['state'] . " - " . $fetparty['pin'] ?></th>
                <?php      } ?>
            </tr>





            <tr>

                <th class="th1">Document No.</th>

                <th class="th1"><?= "$get[invno]/" . left($zyear, 2) . "-" . right($zyear, 2) ?> </th>

            </tr>





            <tr>

                <th class="th1">Document Date</th>

                <th class="th1"><?= $get['vouchdt'] ?></th>

            </tr>





            <tr>

                <th class="th1">Transaction Type:</th>

                <th class="th1"><?= $transactype ?></th>

            </tr>





            <tr>

                <th class="th1">Value of Goods</th>

                <th class="th1"><?= $get['netamt'] ?></th>

            </tr>

            <?php

            $gettran = mysqli_query($conn, "SELECT a.hsncode,b.name FROM `$trandb` a, `$itemdb` b 
                                                  WHERE a.item=b.code and a.vouchno='$get[vouchno]'") or die(mysqli_error($conn));
            
            ?>

            <tr>

                <th class="th1">HSN Code</th>

                <th class="th1">

                    <?php
                    while ($fettran = mysqli_fetch_array($gettran)) {
                        echo "$fettran[hsncode] - $fettran[name] ,";
                    }
                    ?>

                </th>

            </tr>

            <tr>
                <th class="th1">Reason for Transportation</th>

                <th class="th1">Outward - Supply</th>
            </tr>





            <tr style="">

                <th class="th1">Transporter</th>

                <th class="th1"><?= $get['gstno'] . " - " . $get['transname'] ?></th>

            </tr>

            <tr style="border-bottom: 1px solid black;">

                <th>

                    &nbsp;

                </th>

                <th>

                    <img alt='<?= $uniqueno ?>' src='barcode.php?text=<?= $uniqueno ?>' style='height:35px;' class="text-center" />

                    <p style="padding-left: 15%"> <?= $uniqueno ?></p>

                </th>
            </tr>

        </table>

    </center>
</body>

</html>