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

$formname = 'Job Given';
$maindb = 'jobgiven';
$trandb = 'jobgivetran';
$file = 'jobgiven_fr.php';

$zcomp = $_SESSION["comp_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';

$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];
$series = $_GET['series'];
if (empty($series)) {
    $series = $_SESSION["series_" . $dbname];
}
$keycond = " and `series`='$series'";
$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt, DATE_FORMAT(`expectdate`, '%d-%m-%Y') AS expect FROM `$maindb` WHERE vouchno='$vouchno' $keycond") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

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


$gcust = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`=$getmdata[party]") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($gcust);

$gkar = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`=$getmdata[karigar]") or die(mysqli_error($conn));
$karigar = mysqli_fetch_array($gkar);

$gprod = mysqli_query($conn, "SELECT * FROM `item` WHERE `code`=$getmdata[prodcode]") or die(mysqli_error($conn));
$product = mysqli_fetch_array($gprod);

$gcolor = mysqli_query($conn, "SELECT * FROM `color` WHERE `code`=$getmdata[colorname]") or die(mysqli_error($conn));
$color = mysqli_fetch_array($gcolor);

$gprocess = mysqli_query($conn, "SELECT * FROM `process` WHERE `code`=$getmdata[process]") or die(mysqli_error($conn));
$process = mysqli_fetch_array($gprocess);
?>

<!DOCTYPE HTML>
<html lang="en-US">


</head>
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    .page {
        width: 210mm;
        min-height: 120mm;
        padding: 4mm;
        margin: 10mm auto;
        border: 1px #D3D3D3 solid;
        border-radius: 5px;
        /*background: white;*/

    }
    .subpage {
        padding: 0cm;
        /*        border: 1px solid;*/
        height: 288mm;
        outline: 2cm #ffffff solid;
    }

    @page {
        size: A4;
        margin: 0;
    }
    @media print {
        html, body {
            width: 210mm;
            height: 240mm;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: initial;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
        }
    }
    .border{
        border: 1px solid;
    }
</style>

<body id="main_container">
    <div class="book">
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <!--<div class="container col-lg-12">-->
            <div style="border:solid 0px;height: 100px" class="col-lg-12" >
<!--                <div class="row">
                    <center><p style="margin-top:2px;margin-bottom: 2px;font-size:11px; "><u>Subject To Mumbai Jurisdiction</u></p></center>
                </div>                        -->

<div >
    <h2><center><b ><? Echo $comp['pname']; ?></b></center></h2>
                    <center><b ><? Echo $comp['add1']; ?></b></center>
                </div>                        

                    <div>
                        <table style="width:100%">
                            <tr style="width:100%">
                                <td style="text-align:left;width:50%"><b><?php echo $formname ?></b></td>
                                <td style="text-align:right;width:50%"><b><?php echo $karigar[name] ?></b></td>
                            </tr>
                        </table>
                    </div>
            </div>
            <!--</div>-->

            <hr style="border-top: dotted 1px;" />
            <?php
            mysqli_select_db($conn, $zdb);
            
            ?>
            <table style="width:100%">
                <tbody style="width:100%">

                    <tr style="width:100%">
                        <td style="text-align: left;width:35%">
                            <b>Job Given No:</b>
                            <?php echo "$getmdata[vouchno]"; ?> 
                        </td>
                        <td style="text-align: center;width:35% ">
                            <b>Date:</b>
                            <?php echo "$getmdata[vouchdt]"; ?> 
                        </td>
                        <td style="text-align: center;width:30% ">
                            <b>Sale Order :</b>
                            <?php echo "$getmdata[saleorder]"; ?> 
                        </td>
                    </tr>
                </tbody>
            </table>
            <table style="width:100%">
                <tbody style="width:100%">

                    <tr style="height:20px;width:100%">
                        <td  style="width:14%"><b>Product</b> </td>
                        <td  style="width:1%"><b>:</b></td>
                        <td  style="width:35%"><?php echo "$product[name]"; ?></td>
                        <td style="width:25%"></td>
                        <td  style="width:10%"></td>
                        <td  style="width:14%"></td>
                    </tr>
                    <tr style="height:20px;width:100%">
                        <td style="width:14%"><b>Color </b></td>
                        <td  style="width:1%"><b>:</b></td>
                        <td  style="width:35%"><?php echo "$color[name]"; ?> </td>
                        <td style="width:25%"></td>
                        <td  style="width:10%"></td>
                        <td  style="width:15%"></td>
                    </tr>
                    <tr style="height:20px;width:100%">
                        <td style="width:14%"><b>Process</b></td>
                        <td  style="width:1%"><b>:</b></td>
                        <td  style="width:35%"><b><?php echo "$process[name]"; ?> </b></td>
                        <td style="width:25%"></td>
                        <td  style="width:10%"></td>
                        <td  style="width:14%"></td>
                    </tr>

                    <tr style="height:20px;width:100%">
                        <td style="width:14%"><b>Qty</b></td>
                        <td  style="width:1%"><b>:</b></td>
                        <td  style="width:35%"><b><?php echo "$getmdata[qty]"; ?></b> </td>
                        <td style="width:25%"><b></b></td>
                        <td  style="width:10%"><b>Expect :</b></td>
                        <td  style="width:14%"><?php echo "$getmdata[expect]"; ?> </td>
                    </tr>
                </tbody>
            </table>
            <br>

                <tr>
                    <td  colspan="2"> <b>Remarks :</b>
                            <? echo "$getmdata[remark1]"; ?>    
                        </td>
                </tr>
                <tr>
                    <td  colspan="2">
                            <? echo "$getmdata[remark2]"; ?>    
                        </td>
                </tr>
                

                <br>
                <br>
                
                <table  border="solid 1px" style="border-collapse: collapse; width:70%">
                    <tr>
                        <th style="width:5%; color:black;"><label>Sr.</label></th>
                        <th style="width:25%; color:black;"><label>Material</label></th>
                        <th style="width:10%; color:black; text-align: left;"><label>Color</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Meters</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Yard</label></th>
                        <th style="width:10%; color:black; text-align: right;"><label>Qty.</label></th>
                                        
                    </tr>

                    <?php
                    $ctr = 0;
                    $ctab = $totqty = 0;
                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' $keycond ORDER BY `srno`")or die(mysqli_error($conn));
                    while ($tran = mysqli_fetch_array($gettran)) {
                    $finditem = mysqli_query($conn, "SELECT `code`,`name` FROM `rawmat` WHERE `code`='$tran[item]'") or die(mysqli_error($conn));
                        $fitem = mysqli_fetch_array($finditem);
                        $item = $fitem[name];

                    $findcolor = mysqli_query($conn, "SELECT `code`,`name` FROM `color` WHERE `code`='$tran[color]'") or die(mysqli_error($conn));
                        $fcolor = mysqli_fetch_array($findcolor);
                        $color = $fcolor[name];


                        Echo"<tr>";
                        Echo"<td style=''>$tran[srno]</td>";
                        Echo"<td style=''>$item</td>";
                        Echo"<td style='text-align: left;'>$color</td>";
                        Echo"<td style='text-align: right;'>$tran[meters]</td>";
                        Echo"<td style=' text-align:right;'>$tran[yard]</td>";
                        Echo"<td style=' text-align:right;'>$tran[qty]</td>";
                        Echo"</tr>";

                        $ctr++;
                        $ctab = $ctab + 1;
                        $totqty = $totqty + $tran[qty];
                        $totmeter = $totmeter + $tran[meters];
                        $totyard = $totyard + $tran[yard];
                    }
                    
                    $tqty = number_format($totqty,2);
                    $tyard = number_format($totyard,2);
                    $tmeter = number_format($totmeter,2);
                    ?>
                    <tr style="">
                        <td colspan="3" style="text-align: right;"><b>Total</b></td>
                        <td style="text-align: right;padding-right: 5px;"><b><? echo $tmeter; ?></b></td>
                        <td style="text-align: right;padding-right: 5px;"><b><? echo $tyard; ?></b></td>
                        <td style="text-align: right;"><b><? echo $tqty; ?></b></td>

                    </tr>
                    <?
//                    if ($ctab < 5) {
//                        for ($i = $ctab; $i <= 5; $i++) {
//                            $ctab = $ctab + 1;
//                            ?>
<!--                            <tr style="height:26px;">
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                            </tr>      -->
                           <?php
//                        }
//                    }
//                    ?>  
                
                
<!--                <tr style="height:60px">
                    <td>
                        <div></div>
                    </td>
                </tr>-->

                
                
                
                
                
                
                  
            </table>
            <table style="border-collapse: collapse; width:100%">
                <br>
                <br>
                <br>
                <br>
                <tr>
                    <td style="text-align: left; width:50%;">
                        <hr align="left" style="border: 1px solid black; width:50%"/>
                        <b>Authorised Signatory</b>
                    </td>
                    <td style="text-align: center; width:50%;">
                        <hr style="border: 1px solid black; width:70%"/>
                        <b>Received By/Account Holder</b>
                    </td>
                </tr>
            </table>
        </div>  
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
