<?php
session_start();
include 'session_check.php';
//$id=$_REQUEST['id'];//  stored id
?>

<head>
    <meta charset="UTF-8">
    <title>AdminLTE 2 | Dashboard</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- Bootstrap 3.3.2 -->
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- FontAwesome 4.3.0 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <!-- Ionicons 2.0.0 -->
    <link href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css" />
    <!-- Theme style -->
    <link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
    <!-- AdminLTE Skins. Choose a skin from the css/skins 
         folder instead of downloading all of them to reduce the load. -->
    <link href="dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
    <!-- iCheck -->
    <link href="plugins/iCheck/flat/blue.css" rel="stylesheet" type="text/css" />
    <!-- Morris chart -->
    <!--<link href="plugins/morris/morris.css" rel="stylesheet" type="text/css" />-->
    <!-- jvectormap -->
    <link href="plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
    <!-- Date Picker -->
    <link href="plugins/datepicker/datepicker3.css" rel="stylesheet" type="text/css" />
    <!-- Daterange picker -->
    <link href="plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
    <!-- bootstrap wysihtml5 - text editor -->
    <link href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />

    <!-----		sweet alert css and js link	---->
    <link rel="stylesheet" href="dist/sweetalert.css">
    <script src="dist/sweetalert.min.js"> </script>

    <link rel="stylesheet" type="text/css" href="custom/custom.css">
    <!---- Ck editor-->
    <script src="ckeditor/ckeditor.js"></script>
    <!----    data table css file   ---->
    <link href="DataTables/datatables.min.css" rel="stylesheet" type="text/css">

</head>



<?php
include 'include/header.php';
include 'include/left-nav.php';
?>
<!-- Right side column. Contains the navbar and content of the page -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <br>
        <br>
        <ol class="breadcrumb">
            <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Add Commission</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container">
            <div class="col-sm-6 col-sm-offset-3 well" style="padding: 25px">
                <form action="add_commssion_code.php" method="POST" novalidate>
                    <div class="form-group">
                        <div class="row" style="text-align: center; font-size: 21px; font-weight: 600; padding-bottom: 40px">
                            Add Commission Amount
                        </div>
                        <div class="row">
                            <?php
                            /******** date fetching for edit **** */
                            if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
                                $id = $_REQUEST['id'];
                                include 'include/db.php';
                                $comm_query = "select * from commission_master where id = '$id'";
                                $res = mysqli_query($conn, $comm_query);
                                $result = mysqli_fetch_array($res);
                              
                            }
                            /******** date fetching for edit **** */
                            ?>
                            <div class="col-sm-12">
                                <select class="form-control" id="commission_type" name="commission_type">
                                    <option value=0>Select</option>
                                    <option value="joining" <?php if( isset($result['commission_type']) && $result['commission_type'] == 'joining') echo 'selected';  ?>>joining</option>
                                    <option value="pairing" <?php if( isset($result['commission_type']) && $result['commission_type'] == 'pairing') echo 'selected';  ?>>pairing</option>
                                </select>
                            </div>
                        </div>
                        <br>
                        <div class="row pairing" style="display:none">

                            <div class="col-sm-6">
							    <label> Stipulated time(day) </label>
                                <input type="text" name="stipulated_day" class="form-control" placeholder="No of days" value="<?php echo isset($result['stipulated_day']) ? $result['stipulated_day'] : '' ?>" required>
                            </div>
                            <div class="col-sm-6">
								<label> Special commission (%) </label>
                                <input type="text" name="stipulated_comm_amount" class="form-control" placeholder="Special Commission" value="<?php echo isset($result['stipulated_comm_amount']) ? $result['stipulated_comm_amount'] : '' ?>" required> 
                            </div>
                        </div>
                        <br>
                        <div class="row pairing" style="display:none">
                            <div class="col-sm-12">
								<label> Negated commission (%) </label>
                                <input type="text" name="negated_comm_amount" class="form-control" placeholder="Negated Commission" required value="<?php echo isset($result['negated_comm_amount']) ? $result['negated_comm_amount'] : '' ?>">
                            </div>
                        </div>
                        <br>
                        <div class="row joining" style="display:none">
                            <div class="col-sm-12">
							<label> Commission Amount (%) </label>
                                <input type="text" name="joining_comm_amount" class="form-control" placeholder="Commission Amount " required value="<?php echo isset($result['direct_comm_amount']) ? $result['direct_comm_amount'] : '' ?>">
                            </div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-6 col-sm-offset-3 text-center">
                                <input type="hidden" id="edit" name="id" value="<?php echo isset($_REQUEST['id']) ? $_REQUEST['id'] : '' ?>">
                                <input type="submit" value="Add" id="add_pacakge" class="btn btn-default">
                            </div>
                        </div>
                    </div>
                </form>
            </div>

        </div><!-- /.row -->
    </section><!-- /.content -->

    <!----table-->
    <section class="content">
        <div class="row">
            <div class="col-sm-12">
                <div class="box">
                    <div class="box-header">
                    </div><!-- /.box-header -->
                    <div class="box-body table-responsive">

                        <table id="example" class="table table-striped table-bordered nowrap" style="width:100%">
                            <thead>
                                <tr>
                                    <th> Sr.no </th>
                                    <th>Commission Type</th>
                                    <th>Direct Commission Amount</th>
                                    <th>Stipulated Day</th>
                                    <th>Stipulated Commission Amount</th>
                                    <th>Negated Commission Amount</th>
                                    <th>Date</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $qr1 = "SELECT  * from commission_master WHERE commission_type != 'regular'";
                                $con1 = mysqli_query($conn, $qr1);
                                if (mysqli_num_rows($con1) > 0) {
                                    $count = 1;
                                    while ($ro = mysqli_fetch_array($con1)) {
                                        $id = $ro['id'];
                                ?>
                                        <tr>
                                            <td> <?php echo $count++; ?> </td>
                                            <td> <?php echo $ro['commission_type']; ?> </td>
                                            <td> <?php echo $ro['direct_comm_amount']; ?> </td>
                                            <td> <?php echo $ro['stipulated_day']; ?> </td>
                                            <td> <?php echo $ro['stipulated_comm_amount']; ?> </td>
                                            <td> <?php echo $ro['negated_comm_amount']; ?> </td>
                                            <td> <?php echo $ro['created_at']; ?> </td>
                                            <td><a href="manage_commission.php?id=<?php echo $id ?>">Edit</a></td>
                                    <?php

                                    }
                                }
                                    ?>
                            </tbody>
                        </table>

                    </div><!-- /.box-body -->
                </div><!-- /.box -->


            </div><!-- /.col -->
        </div><!-- /.row -->
    </section><!-- /.content -->
    <!----table--->
</div><!-- /.content-wrapper -->

<!-- jQuery 2.1.3 -->
<script src="plugins/jQuery/jQuery-2.1.3.min.js"></script>
<!-- jQuery UI 1.11.2 -->
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
<?php
if ($status == 'Deactive') {
    include 'modal_show.php';
}
?>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.2 JS -->
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- Morris.js charts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<!--<script src="plugins/morris/morris.min.js" type="text/javascript"></script>-->
<!-- Sparkline -->
<script src="plugins/sparkline/jquery.sparkline.min.js" type="text/javascript"></script>
<!-- jvectormap -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js" type="text/javascript"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js" type="text/javascript"></script>
<!-- jQuery Knob Chart -->
<script src="plugins/knob/jquery.knob.js" type="text/javascript"></script>
<!-- daterangepicker -->
<script src="plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<!-- datepicker -->
<script src="plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js" type="text/javascript"></script>
<!-- Slimscroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- FastClick -->
<script src='plugins/fastclick/fastclick.min.js'></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js" type="text/javascript"></script>
<!--  Data table js link   --->
<script src="DataTables/datatables.min.js"></script>

<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<!-- <script src="dist/js/pages/dashboard.js" type="text/javascript"></script>-->

<script>
    $('#example').DataTable();
    /*$(function () {
        $("#example1").dataTable();
        $('#example2').dataTable({
          "bPaginate": true,
          "bLengthChange": false,
          "bFilter": false,
          "bSort": true,
          "bInfo": true,
          "bAutoWidth": false
        });
      });*/
    $('#commission_type').change(function() {
        var comm_type = $(this).val();
        if (comm_type == "joining") {
            $('.joining').show();
            $('.pairing').hide();
        } else if (comm_type == "pairing") {
            $('.pairing').show();
            $('.joining').hide();
        } else {
            $('.pairing').hide();
            $('.joining').hide();
        }
    });

    var edit = $('#edit').val();
    if(edit!="")
    {
        var commission_type = $('#commission_type').val();
    //alert(commission_type);
    if (commission_type == 'pairing') {
        $('.pairing').show();
        $('.joining').hide();
    } else if (commission_type == 'joining') {
        $('.joining').show();
        $('.pairing').hide();
    }
    }
    

</script>

<?php
include 'include/footer.php';
?>