<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>

<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<div id="main-wrapper">    
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>
        
<div class="page-wrapper">
<div class="container-fluid">
<br><br>

<?php
if ($ref_code != "MGP10000") 
{
    echo "<script type='text/javascript'>alert('You are not authorized');</script>";
    unset($_SESSION['sess_user']);
    session_destroy();
    echo "<script type='text/javascript'> document.location='https://mygoldsdnbhd.com/log-masuk/'; </script>";
} 
?>

<div class="row">
<div class="col-lg-12">
<div class="card">
    <div class="card-body">
        <form method="post" action="../Controller/Database_sql.php" enctype="multipart/form-data">
            <div class="form-body">
                <h3 class="card-title">Add New Emas Setting</h3>
                <hr>
                <div class="row p-t-20">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Emas Name</label>
                            <input type="text" class="form-control" name="emas_name" required>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Emas Price Per Gram (RM)</label>
                            <input type="number" step="0.01" class="form-control" name="emas_price" required value="0.00">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Sale Profit Per Gram (RM)</label>
                            <input type="number" step="0.01" class="form-control" name="emas_sale_profit_pergram" required value="0.00">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Upah Simpan Per Gram(%)</label>
                            <input type="number" step="0.01" class="form-control" name="emas_upah_simpan" required value="0.00">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Buy Back Percent Per Gram(%)</label>
                            <input type="number" step="0.01" class="form-control" name="emas_buy_back_percent" required value="0.00">
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">Emas Remark</label>
                            <input type="text" maxlength="100" class="form-control" name="emas_remark">
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-actions">
                <button name="Add_Emas_Setting" class="btn btn-success"><i class="fa fa-check"></i> Add</button>
            </div>
        </form>
    </div>
</div>
</div>
</div>

<div class="row">
<div class="col-12">
<div class="card">
    <div class="card-body">
        <h4 class="card-title">Emas Settings</h4>
        <div class="table-responsive m-t-40">            
            <table class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>Emas Code</th>
                        <th>Emas Name <font color="White">______</font></th>
                        <th>Price (RM)</th>
                        <th>Profit / Gram (RM)</th>
                        <th>Upah Simpan (%)</th>
                        <th>Buy Back (%)</th>
                        <th>Remark</th>
                        <th>Action</th>
                    </tr>
                </thead>                                      
                <tbody>
                    <?php
                    $q = "SELECT *
                    FROM emas_setting
                    Where status='1'
                    order by id Desc";
                    $result = $mysqli->query($q);
                    if ($result ->num_rows > 0)
                    {
                        while($record = $result -> fetch_assoc())
                        {    
                            $id = $record['id'];
                            $emas_ref_code = $record['emas_ref_code'];
                            $emas_name = $record['emas_name'];
                            $emas_price = $record['emas_price'];
                            $emas_sale_profit_pergram = $record['emas_sale_profit_pergram'];
                            $emas_upah_simpan = $record['emas_upah_simpan'];
                            $emas_buy_back_percent = $record['emas_buy_back_percent'];
                            $emas_remark = $record['emas_remark'];
                    ?>
                    <form method="post" onsubmit="return confirm('Do you want to proceed?');" action="../Controller/Database_sql.php" enctype="multipart/form-data">
                    <tr>
                        <td><?php echo $emas_ref_code; ?></td>
                        <td><input type="text" class="form-control" name="emas_name" value="<?php echo $emas_name; ?>"></td>
                        <td><input type="number" step="0.01" class="form-control" name="emas_price" value="<?php echo $emas_price; ?>"></td>
                        <td><input type="number" step="0.01" class="form-control" name="emas_sale_profit_pergram" value="<?php echo $emas_sale_profit_pergram; ?>"></td>
                        <td><input type="number" step="0.01" class="form-control" name="emas_upah_simpan" value="<?php echo $emas_upah_simpan; ?>"></td>
                        <td><input type="number" step="0.01" class="form-control" name="emas_buy_back_percent" value="<?php echo $emas_buy_back_percent; ?>"></td>
                        <td><textarea maxlength="100" rows="2" class="form-control" name="emas_remark"><?php echo $emas_remark; ?></textarea></td>
                        <input type="hidden" class="form-control" name="id" value="<?php echo $id; ?>">
                        <td>
                            <button name="Update_Emas_Setting" class="btn btn-success"><i class="fa fa-check"></i> Update</button>
                            <button name="Delete_Emas_Setting" class="btn btn-danger"> Remove</button>                                   
                        </td>
                    </form> 
                    </tr>
                    <?php 
                        }
                    }
                    ?>
                </tbody>
            </table>
            </form>                                 
        </div>
    </div>
</div>                      
</div>
</div>

</div>
</div>

<?php include ("../Footer/footer.php"); ?>

</div>
    
<?php include ("../Header/all_jquery.php"); ?>

</body>

</html>
