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

$formname = 'Staff Detail';
$maindb = 'staff';
$trandb = 'staftran';
$file = 'staff.php';

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn,$zdb);
$zroot = $_SESSION['zdbroot'];

$admin = $_SESSION["admin_" . $dbname];

$code = $_GET['code'];

$mainqry = mysqli_query($conn,"SELECT * FROM `$maindb` WHERE code = $code ") or die(mysqli_error($conn));
$get = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

$atype = $get['active'];
include("includes/linkshead.php");
?>
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        font: 12pt "Tahoma";
    }
    * {
        box-sizing: border-box;
        -moz-box-sizing: border-box;
    }
    .page {
        width: 210mm;
        min-height: 148mm;
        padding: 2mm;
        margin: 6mm auto;
        /*border: 1px #D3D3D3 solid;*/
        border-radius: 2px;
        background: white;

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

    @page {
        size: A5;
        margin: 0;
    }
    @media print {
        html, body {
            width: 210mm;
            height: 148mm;        
        }
        .page {
            margin: 0;
            border: initial;
            border-radius: initial;
            width: 150%;
            min-height: initial;
            box-shadow: initial;
            background: initial;
            page-break-after: always;
            /*margin-left: 10%;*/ 
       }
    }
    .border{
        border: 1px solid;
    }
</style>
</head>


<body id="main_container">
    <div class="book">
        
        <div class="page">
            <div class="row">
                <div class="col-md-12 text-center">
                    <?php
                    require("includes/dbconnect.php");
                    $comp = mysqli_query($conn,"SELECT * FROM `company`") or die(mysqli_errno());
                    $zcomp = mysqli_fetch_assoc($comp);
                    ?>
                    <b><?php echo $zcomp[name]; ?></b><br>
                    <?php echo $zcomp[add1] . ' ' . $zcomp[add2] . ' ' . $zcomp[add3]; ?><br>
                    <b><?php echo $formname; ?></b>
                </div>
            </div>
            
            <br>

            <table class="" align='center' style="height:35%;width:90%;border:1px solid black;">
                <thead style="border:1px solid black; background-color: #64ccfc;">
                <th style="width:50%;border-right:1px solid black;">Staff Name & Address</th>
                <th style="width:10%;border-right:1px solid black;">Type</th>
                <th style="width:25%;border-right:1px solid black;">Designation</th>
                <th style="width:30%;text-align: center;">Contact No.</th>
                </thead>
                <?php
                $ctr = 0;
                ?>
                <tbody>
                        <?php
                        
                        
                        if ($atype == 0) {
                            $atype = "Non-Active";
                        }
                        
                        
                        if ($atype == 1) {
                            $atype = "Active";
                        }

                        $getdesig = mysqli_query($conn,"SELECT * FROM $zroot.`desig` WHERE `code` = '$get[desig]'")or die(mysqli_error($conn));
                        $fdesig = mysqli_fetch_array($getdesig);
                        $desig = $fdesig['desig'];
                        mysqli_select_db($conn,$zdb);
                        $joindt = $get['joindt'];


                        $ctr++;
                        echo "<tr style='font-weight: bold;'>";
                        echo "<td align='left' style='border-right:1px solid black;'>$get[name]</td>";
                        echo "<td align='left' style='border-right:1px solid black;'>$atype</td>";
                        echo "<td align='left' style='border-right:1px solid black;'>$desig</td>";
                        echo "<td align='center' style='border-center:1px solid black;'>$get[mobile]</td>";
                        echo "</tr>";
                        ?>



                </tbody>
            </table>

            <br><br><br><br>

            <table class="table-bordered" align='center' style="height:35%;width:90%;border:1px solid black;">
                <thead style="border:1px solid black; background-color: #64ccfc;">
                <th style="width:5%;border-right:1px solid black;">Sr</th>
                <th style="width:15%;border-right:1px solid black;">Date of Joining</th>
                <th style="width:10%;border-right:1px solid black;">Left.Date</th>
                <th style="width:10%;border-right:1px solid black;">Salary</th>
                <th style="width:10%;border-right:1px solid black; text-align: center;">M/D</th>
                <th style="width:10%;border-right:1px solid black; text-align: center;
                    ">Hrs/Day</th>
                <th style="width:10%;border-right:1px solid black;">Sal/Hours</th>
                </thead>
                <?php
                $ctr = 0;
                ?>
                <tbody>

                    <?php
                    $gettran = mysqli_query($conn,"SELECT * FROM $trandb WHERE `staffcode` = '$get[code]'")or die(mysqli_error($conn));
                    while ($tran = mysqli_fetch_array($gettran)) {

                        $lftdt = $tran['leftdate'];
                        $salary = $tran['salary_h'];
                        $saltype = $tran['saltype_h'];
                        $hrdays = $tran['hrs_day_h'];
                        $salhrs = $tran['salhrs_h'];

                        $leftdate = date("d-m-Y", strtotime($lftdt));
                        
                        $ctr2++;
                        echo "<tr style='font-weight: bold;'>";
                        echo "<td align='left' style='border-right:1px solid black;'>$ctr2</td>";
                        echo "<td align='left' style='border-right:1px solid black;'>$joindt</td>";
                        echo "<td align='left' style='border-right:1px solid black;'>$leftdate</td>";
                        echo "<td align='right' style='border-right:1px solid black;'>$salary</td>";
                        echo "<td align='center' style='border-right:1px solid black;'>$saltype</td>";
                        echo "<td align='center' style='border-right:1px solid black;'>$hrdays</td>";
                        echo "<td align='center' style='border-right:1px solid black;'>$salhrs</td>";

                        echo "</tr>";
                    }
                    ?>

                </tbody>
            </table>
            <!--            </div>-->

        </div>  
        <!--</div>-->
    </div>

    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function () {
            formGeneral();
        });
    </script>
</body>
</html>
