  <?php
    $this->load->view('templates/header');
  ?>
    <script>
        var link = "order_section";
        var sub_link = "order_master";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1 class="content_top">Order Data</h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Order Data</a></li>
        <li class="active">View</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row"><!-- left column -->
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-body">
                        <div class="alert_msg"></div>
                        <form class="form-horizontal" id="order_form">
                            <div class="box-body remove-bottom"><!-- box-body -->
                                <div class="form-group floating-form">
                                    <!-- issue no -->
                                    <div class="col-md-1 floating-label">
                                        <input type="number" class="form-control floating-input" id="om_entry_no" name="om_entry_no" value="<?php echo (empty($order_data)?$entry_no:$order_data[0]['om_entry_no'])?>" placeholder=" " autocomplete="off" readonly />
                                        <label>ORDER NO</label>
                                    </div>
                                    <!-- issue no -->

                                    <!-- issue date -->
                                    <div class="col-md-1 floating-label">
                                        <?php if(empty($order_data)): ?>
                                        <input type="text" class="form-control floating-input" id="om_entry_date" name="om_entry_date" value="<?php echo date('d-m-Y');?>"
                                        placeholder=" " autocomplete="off" tabindex="1"/>
                                        <?php else: ?>
                                            <input type="text" class="form-control floating-input" id="om_entry_datee" name="om_entry_date" value="<?php echo date('d-m-Y', strtotime($order_data[0]['om_entry_date']));?>" placeholder=" " autocomplete="off" tabindex="1" readonly/>
                                        
                                        <?php endif; ?>
                                        <label>ORDER DATE</label>
                                    </div>
                                    <!-- issue date -->

                                    <!-- party -->
                                    <?php if(!empty($order_data)): ?>
                                        <?php if($order_data[0]['om_cust_id'] > 0): ?>
                                       
                                        <div class="col-md-3 floating-label"> 
                                            <input type="text" class="form-control floating-input" value="<?php echo $order_data[0]['customer']; ?>" placeholder=" " autocomplete="off" tabindex="2" readonly/>

                                            <input type="hidden" id="om_cust_id" name="om_cust_id" value="<?php echo $order_data[0]['om_cust_id'];?>"/>
                                            <label>CUSTOMER</label>
                                        </div>
                                    <?php endif; ?>
                                    
                                    <?php endif; ?>

                                       
                                    <!-- party -->

                                    <!-- broker -->
                                    <?php if(!empty($order_data)): ?>
                                        <?php if($order_data[0]['om_broker_id'] > 0): ?>
                                    <div class="col-md-3 floating-label">
                                        <input type="text" class="form-control floating-input" value="<?php echo $order_data[0]['broker']; ?> - <?php echo $order_data[0]['broker_pan']; ?> - <?php echo $order_data[0]['broker_mobile']; ?>" placeholder=" " autocomplete="off" tabindex="3" readonly/>

                                        <input type="hidden" id="om_broker_id" name="om_broker_id" value="<?php echo $order_data[0]['om_broker_id'];?>"/>
                                       
                                     
                                        <label>BROKER</label>
                                    </div>
                                    <?php endif; ?>
                                    
                                    <?php endif; ?>
                                    <!-- broker -->
                                </div>
                               
                            </div>
                         
                            <div class="box box-primary">
                            <div class="box-header with-border">
                                <h3 class="box-title">Order Details</h3>
                                <div class="box-tools pull-right">
                                    <button type="button" class="btn btn-box-tool" data-widget="collapse">
                                        <i class="fa fa-minus"></i></button>
                                </div>
                            </div><!-- /.box-header -->
                            <div class="box-body">
                                <table class="table" id="challan_material_wrapper">
                                    <tr>
                                        <!-- diamond code -->
                                        <th class="floating-label" width="5%">STOCK ID</th>
                                        <!-- diamond code -->

                                        <!-- diamond shape -->
                                        <th class="floating-label" width="5%">SH</th>
                                        <!-- diamond shape -->

                                        <!-- diamond weight -->
                                        <th class="floating-label" width="5%">WT</th>
                                        <!-- diamond weight -->

                                        <!-- diamond color -->
                                        <th class="floating-label" width="5%">COL</th>
                                        <!-- diamond color -->

                                        <!-- diamond clarity -->
                                        <th class="floating-label" width="5%">CLA</th>
                                        <!-- diamond clarity -->

                                       

                                        <!-- diamond disc -->
                                        <th class="floating-label" width="5%">DISC</th>
                                        <!-- diamond disc -->

                                        <!-- diamond rapnet -->
                                        <th class="floating-label" width="5%">RAPNET</th>
                                        <!-- diamond rapnet -->
                                        <th class="floating-label" width="5%">PRICE/CERT</th>
                                       
                                        <!-- remove trans -->
                                        <th style="text-align: center;" width="5%">STATUS</th>
                                        <!-- remove trans -->
                                    </tr>
                                    <?php
                                        $cnt = 1;
                                        if(!empty($order_trans)):
                                            foreach ($order_trans as $key => $value):
                                                // $cert = $value['ct_dm_cert'] == 1 ? 'YES' : 'NO';
                                    ?>
                                                <tr id="rowid_<?php echo $cnt; ?>">
                                                    <!-- stock id -->
                                                    <td>
                                                        <input class="form-control floating-input" value="<?php echo $value['dm_code']; ?>" readonly="">
                                                        <input type="hidden" name="ot_id[]" id="ot_id_<?php echo $cnt; ?>" value="<?php echo $value['ot_id'] ?>">
                                                        <input type="hidden" name="ot_dm_id[]" id="ot_dm_id_<?php echo $cnt; ?>" value="<?php echo $value['dm_id']; ?>">
                                                    </td>
                                                    <!-- stock id -->

                                                    <!-- sh -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_sh[]" id="ct_dm_sh_<?php echo $cnt; ?>" value="<?php echo $value['dm_sh']; ?>" readonly="">
                                                    </td>
                                                    <!-- sh -->

                                                    <!-- wt -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_wt[]" id="ct_dm_wt_<?php echo $cnt; ?>" value="<?php echo $value['dm_wt']; ?>" readonly="">
                                                    </td>
                                                    <!-- wt -->

                                                    <!-- col -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_col[]" id="ct_dm_col_<?php echo $cnt; ?>" value="<?php echo $value['dm_col']; ?>" readonly="">
                                                    </td>
                                                    <!-- col -->

                                                    <!-- cla -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_cla[]" id="ct_dm_cla_<?php echo $cnt; ?>" value="<?php echo $value['dm_cla']; ?>" readonly="">
                                                    </td>
                                                    <!-- cla -->

                                                    <!-- disc -->
                                                    <td>
                                                        <!-- <input class="form-control floating-input" name="ct_dm_disc[]" id="ct_dm_disc_<?php echo $cnt; ?>" value="<?php echo $value['ct_dm_disc']; ?>" onkeyup="get_rap_amt_per_row(<?php echo $cnt; ?>)"> -->
                                                        <input class="form-control floating-input" name="ct_dm_disc[]" id="ct_dm_disc_<?php echo $cnt; ?>" value="<?php echo $value['dm_disc']; ?>" readonly="">
                                                    </td>
                                                    <!-- disc -->

                                                    <!-- rap -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ot_dm_rap[]" id="ot_dm_rap_<?php echo $cnt; ?>" value="<?php echo $value['dm_rap']; ?>" readonly="">
                                                    </td>
                                                    <!-- rap -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ot_dm_ppc[]" id="ot_dm_ppc_<?php echo $cnt; ?>" value="<?php echo $value['dm_ppc']; ?>" readonly="">
                                                    </td>
                                                    

                                                    <!-- remove button -->
                                                    <td style="text-align: center;">
                                                       <select class="form-control" name="ot_status" id="ot_status_<?php echo $cnt; ?>" onchange="confirm_order(<?php echo $value['ot_id'] ?>)" <?php if($value['ot_status'] == 1){ echo "disabled"; } ?>>
                                                           <option value="0" <?php if($value['ot_status'] == 0){ echo "selected"; } ?>>Pending</option>
                                                           <option value="1" <?php if($value['ot_status'] == 1){ echo "selected"; } ?> >Confirm</option>
                                                       </select>
                                                        <!-- <a href="javascript:void(0)" onclick="remove_challan_trans_row(<?php echo $cnt; ?>)"> -->
                                                            <!-- <i class="glyphicon glyphicon-trash" style="color: #dd4b39;padding-top: 9px;"></i> -->
                                                        <!-- </a> -->

                                                    </td>
                                                    <!-- remove button -->
                                                </tr>
                                    <?php
                                            $cnt++;
                                            endforeach;
                                        endif;
                                    ?>
                                </table>
                            </div><!-- /.box -->
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- /.content -->


<?php
    $this->load->view('templates/footer');
?>
<script>
    (function () {
        disable_enable_background(false)
    }());

    function confirm_order(id)
    {
        disable_enable_background(false);
        var ans = confirm("Are you sure? You want to confirm this order.");

        if(ans == true)
        {
            var check = 1;
            if($("#om_entry_no").val() == '')
            {
                $("#om_entry_no").css({'border-color':'red'});
                check = 0;
            }
            else
            {
                $("#om_entry_no").css({'border-color':'#CCC'});
            }


            if(check == 0)
            {
                var msg = 'Oh snap ! You forgot to enter entry number';
                display_alert('err',msg);
                $("body, html").animate({'scrollTop':0},1000);
            }
            else
            {
                var path = base_url+"order/orderctrl/confirm_order/"+id;
                // var form_data = $("#order_form").serialize();

                $.ajax({
                type:'post',
                url:path,
                // data:form_data,
                dataType:'json',
                success:function(resp)       
                {
                    console.log(resp);
                    if(resp == 1)
                    {
                        var msg = 'Order Confirmed successfully!';
                        display_alert('succ',msg);
                        $("body, html").animate({'scrollTop':0},2000);
                        // window.open(base_url+"order/orderctrl/order_master?action=view");
                        setTimeout(function(){
                            window.location.reload();
                        },1500);
                    }
                    else
                    {
                        var msg = 'Database Error ! Please try again letter';
                        display_alert('warn',msg);
                        $("body, html").animate({'scrollTop':0},1000);
                    }
                },function(errmsg)
                    {
                        console.log(errmsg)
                    }
                });
            }
        }
    }
</script>
</body>
</html>