<?php
require_once("../includes/config.php");
$arrstatus = getFullStatus("", $link1);
/////////check approval is applicable or not
$apply_app = getAnyDetails(base64_decode($_REQUEST['pid']), "apply_approval", "tabid", "tab_master", $link1);
$docid = base64_decode($_REQUEST['id']);
//// stock conversion details
$sql_locdet = "SELECT * FROM stock_conversion_master where system_ref_no='" . $docid . "'";
$res_locdet = mysqli_query($link1, $sql_locdet);
$row_locdet = mysqli_fetch_assoc($res_locdet);
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>
            <?= siteTitle ?>
        </title>
        <link rel="shortcut icon" href="../images/titleimg.png" type="image/png">
        <script src="../js/jquery.js"></script>
        <?php
        include("../includes/fontawesome.html");
        include("../includes/main_css.html");
        include("../includes/bootstrap.html");
        include("../includes/datatables.html");
        ?>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <link href="../css/loader.css" rel="stylesheet"/>
    </head>
    <body>
        <div class="container-fluid">
            <div class="row content">
                <?php
                include("../includes/leftnav_admin.php");
                ?>
                <div class="<?= $screenwidth ?>">
                    <h2 align="center"><i class="fa <?= $fa_icon ?>"></i> Stock Conversion View</h2>
                    <h4 align="center"><?php echo "( " . $row_locdet['system_ref_no'] . " )"; ?></h4>
                    <div class="form-group"  id="page-wrap" style="margin-left:10px;" >
                        <form id="frm1" name="frm1" class="form-horizontal" action="" method="post">
                            <div class="panel-group">
                                <div class="panel panel-success table-responsive">
                                    <div class="panel-heading"><i class="fa fa-newspaper-o fa-lg"></i>&nbsp;&nbsp;Stock Conversion Details</div>
                                    <div class="panel-body">
                                        <table class="table table-bordered" width="100%">
                                            <tbody>
                                                <tr>
                                                    <td width="20%"><label class="control-label">Location</label></td>
                                                    <td width="30%"><?= getAnyDetails($row_locdet['location_code'], "locationname", "location_code", "location_master", $link1) . " (" . $row_locdet['location_code'] . ")"; ?>
                                                    </td>
                                                    <td width="20%"><label class="control-label">Conversion Type</label></td>
                                                    <td width="30%"><?= $row_locdet['conversion_type']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="20%"><label class="control-label">Status</label></td>
                                                    <td width="30%"><?= $arrstatus[$row_locdet['status']] ?></td>
                                                    <td width="20%"><label class="control-label">Remark</label></td>
                                                    <td width="30%"><?= $row_locdet['remark']; ?></td>
                                                </tr>
                                                <tr>
                                                    <td width="20%"><label class="control-label">Create By</label></td>
                                                    <td width="30%"><?= getAnyDetails($row_locdet['entry_by'], "name", "username", "admin_users", $link1) ?></td>
                                                    <td width="20%"><label class="control-label">Create Date</label></td>
                                                    <td width="30%"><?= dt_format($row_locdet['entry_date']) . " | " . time_format($row_locdet['entry_time']) ?></td>
                                                </tr>
                                                <?php
                                                if ($apply_app == "Y") {
                                                    $row_app = mysqli_fetch_assoc(mysqli_query($link1, "select action_by,action_taken,action_date,action_remark from  approval_activity where ref_no='" . $docid . "'"));
                                                    if ($row_app['action_by'] != '') {
                                                        ?>
                                                        <tr>
                                                            <td width="20%"><label class="control-label">Approval By</label></td>
                                                            <td width="30%"><?= getAnyDetails($row_app['action_by'], "name", "username", "admin_users", $link1) ?></td>
                                                            <td width="20%"><label class="control-label">Approval Date</label></td>
                                                            <td width="30%"><?= dt_format($row_app['action_date']) ?></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="20%"><label class="control-label">Approval Action</label></td>
                                                            <td width="30%"><?= $arrstatus[$row_app['action_taken']] ?></td>
                                                            <td width="20%"><label class="control-label">Approval Remark</label></td>
                                                            <td width="30%"><?= $row_app['action_remark'] ?></td>
                                                        </tr>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div><!--close panel body-->
                                </div><!--close panel-->
                                <div class="panel panel-success table-responsive">
                                    <div class="panel-heading"><i class="fa fa-cubes fa-lg"></i>&nbsp;&nbsp;Stock Conversion Part Details</div>
                                    <div class="panel-body">
                                        <table class="table table-bordered" width="100%">
                                            <thead>
                                                <tr class="<?= $tableheadcolor ?>">
                                                    <th width="35%">Part Name</th>
                                                    <th width="10%">Available Stock</th>
                                                    <th width="10%">Conversion Qty</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
/// select stock conversion part wise data table info
                                                $res = mysqli_query($link1, "SELECT * FROM stock_conversion_data where system_ref_no='" . $docid . "'");
                                                while ($row = mysqli_fetch_assoc($res)) {
                                                    $stock = explode(' ', $row_locdet['conversion_type']);
                                                    if ($stock[0] == 'Fresh') {
                                                        $select_field = "ok_qty";
                                                    } else if ($stock[0] == 'Damag') {
                                                        $select_field = "damage_qty";
                                                    }
                                                    $query = "SELECT " . $select_field . " from inventory_status where location_code='" . $row_locdet['location_code'] . "' and partcode='" . $row['partcode'] . "'";
                                                    $res1 = mysqli_query($link1, $query);
                                                    $row1 = mysqli_fetch_array($res1);
                                                    ?>
                                                    <tr>
                                                        <td><?= getAnyDetails($row['partcode'], "part_name", "partcode", "partcode_master", $link1) . " (" . $row['partcode'] . ")"; ?></td>
                                                        <td align="right"><?= $row1[$select_field]; ?></td>
                                                        <td align="right"><?= $row['qty'] ?></td>
                                                    </tr>
                                                    <?php
                                                }
                                                ?> 
                                            </tbody>
                                        </table>
                                    </div><!--close panel body-->
                                    
                                </div><!--close panel-->
                            </div><!--close panel group-->
                             <button title="Back" type="button" style="margin-left: 428px;" class="btn<?= $btncolor ?>" onClick="window.location.href = 'stock_conversion_list.php?location=<?php
                                    if (isset($_REQUEST['location'])) {
                                        echo $_REQUEST['location'];
                                    }
                                    ?>&stock_type=<?php
                                    if (isset($_REQUEST['stock_type'])) {
                                        echo $_REQUEST['stock_type'];
                                    }
                                    ?>&daterange=<?php
                                    if (isset($_REQUEST['daterange'])) {
                                        echo $_REQUEST['daterange'];
                                    }
                                    ?><?= $pagenav ?>'"><i class="fa fa-reply fa-lg"></i>&nbsp;&nbsp;Back</button>
                        </form>
                    </div>
                    <!--End form group--> 
                </div>
                <!--End col-sm-9--> 
            </div>
            <!--End row content--> 
        </div>
        <!--End container fluid-->
        <div id="loader"></div>
        <?php
        include("../includes/footer.php");
        include("../includes/connection_close.php");
        ?>
    </body>
</html>
