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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];

mysqli_select_db($conn,$zdb);
$zroot = $_SESSION["zdir"];
##############################Print Start Here##################################
// if (isset($_POST["view"])) {
//    $custcond = '';
//     if (!empty($_POST['name'])) {
//         foreach ($_POST['name'] as $check2) {
//             $mycheck2[$count2++] .= "OR `accode` = '" . $check2 . "' ";
//         }

//         foreach ($mycheck2 as $g => $values2) {
//             $mcheck2 .= $values2;
//         }

//         $custcond = " AND (`accode` = '' " . $mcheck2 . " )";
//     }

// //    $sortby = " ORDER BY " . $_POST["sortby"];

    $vouchno = $_GET['vouchno'];

    $get = mysqli_query($conn,"SELECT * FROM `challan` WHERE `vouchno` = '$vouchno'") or die(mysqli_error($conn));

    $getno = mysqli_fetch_array($get);

    include("includes/linkshead.php");
    ?>
    <!--<link href="styles/rep_format.css" rel="stylesheet">-->
    <style>

        body{
            font-size: 15px;

        }
        td,th{
            padding:0px;
            font-size:15px;
        }
        table{
            width:100%;
            /* margin-bottom: -10%; */
            /*border : 1px solid black;*/
        }
        .center{
            text-align: center;
        }
        .left{
            text-align: left;
        }
        .right{
            text-align: right;
        }
        .padd{
            padding: 2px;
        }
        .fontsize{
            font-size:11px;
        }
        .page {
            width: 210mm;
            min-height: 280mm;
            padding: 1mm;
            margin: 10mm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;
            background: white;

        }
        .txttrnsform{
            text-transform: uppercase;
        }
        .noBorder {
            border-style: hidden;
        }

        @media print {

            body{
            font-size: 18px;
            -webkit-print-color-adjust: exact;    
                border: 0;
        }

        
        td,th{
            padding:0px;
            font-size:15px;
            border: 0;
        }
        table{
            width:65%;
           
            /* margin-bottom:10%; */
            /*border : 1px solid black;*/
        }

        .border{
            border: 2px solid black;
            /* border-top: 1px solid black; */
        }

        .right{
            text-align: right;
        }
      
        .fontsize{
            font-size:11px;
        }
        .page {
            width: 330mm;
            min-height: 280mm;
            padding: 1mm;
            margin: 10mm auto;
            border:none;
            border-radius: none;
            background: white;

        }
        .txttrnsform{
            text-transform: uppercase;
        }
        }
        
    </style>
    </head>
    <body> 

        <?php
        $ctr = 0;

        // if ($getno < 2) {
        //     $td2 = 2 - $getno;
        // } else {
        //     $td2 = fmod($getno, 2) + 1;
        // }

        // while ($lbl = mysqli_fetch_array($get)) {
            $barcode = $lbl[barcode];
            $ctr++;
            $lblctr++;
            if ($lblctr == 1) {
                echo "<div class='page' style=''>";
            }
            ?>

            <?php if ($ctr == 1) {
                ?>
                <br>
                <table width="100%">
                    <tr>
                        <td width="50%">
                            <?php
                        } else {
                            ?>  
                        <td width="50%">
                            <?php
                        }
                    
                    $getparty = mysqli_query($conn,"SELECT accode, name FROM accmast WHERE accode = '$getno[party]'")or die (mysqli_error($conn));
                    $fparty = mysqli_fetch_array($getparty);
                    $partyname = $fparty['name'];
                    $mark = $getno['mark'];
                      
                      $mcolor = "";
                      if ($mark == "U"){
                            $mcolor = "orange";  
                      } else if($mark == "V") {
                          $mcolor = "red";
                      } 
                       
                      
                      
                      $vouchdt = $getno['vouchdt'];    
                        $date = date("d-m-Y", strtotime($vouchdt));

                        ?>
                            
                        <table class="border" style="width: 50%; ">
                                        <tr>
                                            <tr class="border">
                                            <td style="font-size: 15px;"><b></b><?php echo "" . "". $partyname;?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <b class="right"><?php  echo "" . "". $date; ?></b></td>
                                        </tr>
                                <td width="100%" style="border: 0;">
                                    <table style="width: 100%;">
                                       
                                    <tr id="">
                                        <td class="" style="font-size: 15px; border-style: none; color: <?php echo $mcolor; ?>"  ><b><?php echo "" . "".  $mark; ?></b></td>
                                        <td class=" " style="font-size: 18px;"><b><?php echo  "".  $getno['sizemm']; ?></b>&nbsp;
                                            <b>X&nbsp;&nbsp;</b><?php echo "". $getno['makemm']; ?>&nbsp&nbsp&nbsp<?php echo  "". $getno['guage'] ?>&nbsp;&nbsp;<b>X&nbsp;&nbsp;<?php echo  "" . $getno['straight']; ?></b></td>
                                        
                                        </tr>    
                                         <tr id="">
                                         <td class=" " style="font-size: 18px;"><b>NAGS&nbsp</b><?php echo "" . "" . $getno['nag']; ?>&nbsp;&nbsp;<?php echo "" . "" . $getno['descrip']; ?></td>
                                         <td class=" "  style="font-size: 18px; padding-right: 125px; float: right; "  width="5%">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<b>A/P</b></td>
                                        </tr>    
                                         <tr id="">
                                         <td class=" "style="font-size: 18px;" width="20%"><b>FTS&nbsp&nbsp&nbsp&nbsp&nbsp</b><?php echo "" . "" . $getno['foot'];?>&nbsp&nbsp&nbsp<?php echo $getno['totfeet']; ?></td>
                                         <td class=" " style="font-size: 18px;"><b>R.T&nbsp</b><?php echo "" . "" . $getno['rate'];?>&nbsp&nbsp&nbsp<?php echo " ". " ". $getno['amount']; ?></td>
                                         
                                       
                                        </tr>    
                                         <tr >
                                        </tr>    
                                         <tr >
                                        </tr>    
                                         <tr style="" style=" width: 250%;">
                                        </tr>    
                                    </table>
                                </td>
                            </tr>
                        </table>
                 
                    </td>
                    <?php
                
//                if (isset($_POST["subpdf"])) {
//
//                    $name = trim($_POST["name"]);
//                    $district = trim($_POST["district"]);
//                    $state = trim($_POST["state"]);
//                    $for = trim($_POST["for"]);
//                    $class = trim($_POST["class"]);
//                    $batch = $_POST["batch"];
//                    $frompax = $_POST["frompax"];
//                    $topax = $_POST["topax"];
//                    $fromhaji = $_POST["fromhaji"];
//                    $tohaji = $_POST["tohaji"];
//                    $siscono = $_POST["siscono"];
//                    $mair = $_POST["airline"];
//                    $mjbdt = $_POST["arrvdate"];
//                    $mflt = $_POST["flight"];
//
//                    $fltcode = "";
//                    $jb_date = "";
//                    $compcond = "";
//                    $hajicond = "";
//                    $paxcond = "";
//                    $bcond = "";
//                    $ccond = "";
//                    $fcond = "";
//                    $scond = "";
//                    $dcond = "";
//                    $ncond = "";
//                    $air_code = "";
//
//                    if (!empty($name)) {
//                        $ncond = " AND `name` LIKE '%$name%' ";
//                    }
//                    if (!empty($district)) {
//                        $dcond = " AND `district` = '$district' ";
//                    }
//                    if (!empty($state)) {
//                        $scond = " AND `state` = '$state' ";
//                    }
//                    if (!empty($_POST["for"])) {
//                        $fcond = " AND `visitingfor` = '$for' ";
//                    }
//                    if (!empty($_POST["class"])) {
//                        $ccond = " AND `class` LIKE '%$class%' ";
//                    }
//                    if (!empty($_POST["batch"])) {
//                        $bcond = " AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE `batchno`= '$batch' GROUP BY `paxno`) ";
//                    }
//                    if (!empty($_POST["frompax"]) && !empty($_POST["topax"])) {
//                        $paxcond = " AND `paxid` BETWEEN '$frompax' AND '$topax'";
//                    }
//                    if (!empty($_POST["fromhaji"]) && !empty($_POST["tohaji"])) {
//                        $hajicond = " AND `hajino` BETWEEN '$fromhaji' AND '$tohaji'";
//                    }
//                    if (!empty($_POST["airline"])) {
//                        $air_code = " AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE `airline_code`= '$mair') ";
//                    }
//                    if (!empty($_POST["siscono"])) {
//                        $compcond = " AND `company` = '$siscono'";
//                    }
//                    if (!empty($_POST["flight"])) {
//                        $fltcode = " AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE `flightno`= '$mflt') ";
//                    }
//                    if (!empty($_POST["arrvdate"])) {
//                        $jb_date = " AND `paxid` IN (SELECT `paxno` FROM `airline_detail` WHERE `dept_date`= '$mjbdt' AND `srno` = 2 ) ";
//                    }
//
//                    $sortby = " ORDER BY " . $_POST["sortby"];
//
//
//
//                    $get = mysqli_query($conn,"SELECT `paxid`,`hajino`, `visitingfor`, `surname`, `name`, `midname`, `suffix`, `address`,
//                    `city`,`taluka`, `pin`, `district`, `state`, `telno`, `mobile` FROM `pax` WHERE `familyhead` = 'T'
//                    $bcond $paxcond $hajicond $ncond $dcond $scond $fcond $ccond $air_code $fltcode
//                    $jb_date $sortby LIMIT 2") or die(mysqli_error($conn));
//                    $getno = mysqli_num_rows($get);
//
//                    $get2 = mysqli_query($conn,"SELECT `paxid`,`hajino`, `visitingfor`, `surname`, `name`, `midname`, `suffix`, `address`,
//                   `city`,`taluka`, `pin`, `district`, `state`, `telno`, `mobile` FROM `pax` WHERE `familyhead` = 'T'
//                   $bcond $paxcond 
//                   $hajicond $ncond 
//                   $dcond $scond 
//                   $fcond $ccond
//                   $air_code $fltcode
//                   $jb_date $sortby ") or die(mysqli_error($conn));
//                    $getno2 = mysqli_num_rows($get2);
//
//
//                    require_once('library/fpdf/fpdf.php');
//
//                    $pdf = new FPDF('P', 'mm', array(210, 327));
//                    $pdf->AddPage();
//                    $pdf->Ln(10);
//
//                    $set = 3;
//                    $m = 0;
//                    while ($lbl2 = mysqli_fetch_array($get2)) {
//                        $m++;
//                        $add1 = substr($lbl2['address'], 0, 40);
//                        $add2 = substr($lbl2['address'], 41, 80);
//
//
//                        if (($set % 2) == 1) {
//                            $pdf->SetX("20");
//                            $y1 = $pdf->GetY();
//                            $pdf->SetFont('Arial', 'B', 9);
//                            $pdf->Cell("80", "0", $lbl2["suffix"] . " " . $lbl2["surname"] . " " . $lbl2["name"] . " " . $lbl2["midname"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y2 = $pdf->GetY();
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("80", "0", $add1, "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y3 = $pdf->GetY();
//                            $pdf->Cell("80", "0", $add2, "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y5 = $pdf->GetY();
//                            $pdf->SetFont('Arial', 'B', 9);
//                            $pdf->Cell("80", "0", "At " . "- " . $lbl2["city"] . "    " . "Pin" . "-" . " " . $lbl2["pin"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y6 = $pdf->GetY();
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("100", "0", "Tal" . " " . "-" . " " . $lbl2["taluka"] . "    " . "Dist" . " " . "-" . " " . $lbl2["district"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y7 = $pdf->GetY();
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("100", "0", "State" . " " . "-" . " " . $lbl2["state"] . "    " . "Mob" . " " . "-" . " " . $lbl2["mobile"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetX("20");
//                            $y8 = $pdf->GetY();
//                            $pdf->Cell("80", "0", "P" . " " . "-" . " " . $lbl2[paxid] . " " . "/" . " " . "H" . " " . "-" . " " . $lbl2[hajino] . " " . "/" . " " . $lbl2[visitingfor] . " " . "/" . " " . $myyear, "0");
//                            $pdf->Ln(3);
//                        } else {
//                            $pdf->SetXY("120", $y1);
//                            $pdf->SetFont('Arial', 'B', 9);
//                            $pdf->Cell("80", "0", $lbl2["suffix"] . " " . $lbl2["surname"] . " " . $lbl2["name"] . " " . $lbl2["midname"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetXY("120", $y2);
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("80", "0", $add1, "0");
//                            $pdf->Ln(3);
//                            $pdf->SetXY("120", $y3);
//                            $pdf->Cell("80", "0", $add2, "0");
//                            $pdf->Ln(3);
//
//                            $pdf->SetXY("120", $y5);
//                            $pdf->SetFont('Arial', 'B', 9);
//                            $pdf->Cell("80", "0", "At " . "- " . $lbl2["city"] . "    " . "Pin" . "-" . " " . $lbl2["pin"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetXY("120", $y6);
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("100", "0", "Tal" . " " . "-" . " " . $lbl2["taluka"] . "    " . "Dist" . " " . "-" . " " . $lbl2["district"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetXY("120", $y7);
//                            $pdf->SetFont('Arial', '', 9);
//                            $pdf->Cell("100", "0", "State" . " " . "-" . " " . $lbl2["state"] . "    " . "Mob" . " " . "-" . " " . $lbl2["mobile"], "0");
//                            $pdf->Ln(3);
//                            $pdf->SetXY("120", $y8);
//                            $pdf->Cell("80", "0", "P" . " " . "-" . " " . $lbl2[paxid] . " " . "/" . " " . "H" . " " . "-" . " " . $lbl2[hajino] . " " . "/" . " " . $lbl2[visitingfor] . " " . "/" . " " . $myyear, "0");
//                            if ($m != 16) {
//                                $pdf->Ln(17);
//                            } else {
//                                $pdf->Ln(0);
//                                $m = 0;
//                                $pdf->AddPage();
//                                $pdf->Ln(10);
//                            }
//                        }
//                        $set++;
//                    }
//
////                    $pdf->Output("Address Labels (Jeddah - Mumbai).pdf", 'D');
//                    $pdf->Output();
//                }
                ?>