  <?php
    $this->load->view('templates/header');
  ?>
    <script>
        var link = "challan";
        var sub_link = "add";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1 class="content_top"><?php echo empty($cm_data) ? 'ADD JANGAD ISSUE' : 'UPDATE JANGAD ISSUE'; ?></h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Jangad Issue</a></li>
        <li class="active"><?php echo empty($cm_data) ? 'Add' : 'Update' ?></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="challan_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="cm_entry_no" name="cm_entry_no" value="<?php echo (empty($cm_data)?$entry_no:$cm_data[0]['cm_entry_no'])?>" placeholder=" " autocomplete="off" readonly />
                                        <label>ISSUE NO</label>
                                    </div>
                                    <!-- issue no -->

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

                                    <!-- party -->
                                    <div class="col-md-2 floating-label">
                                        <?php if(empty($cm_data)): ?>
                                        <?php echo form_dropdown('', $customer_data, 0,'id="cm_cust_id" name="cm_cust_id" class="form-control flexselect floating-select" onchange="get_customer_data(this.value)" placeholder=" " autocomplete="off" tabindex="2" ');  ?>
                                        <?php else: ?>
                                        <?php if($cm_data[0]['is_editable'] == 0): ?>
                                            <input type="text" class="form-control floating-input" value="<?php echo $cm_data[0]['customer']; ?>" placeholder=" " autocomplete="off" tabindex="2" readonly/>

                                            <input type="hidden" id="cm_cust_id" name="cm_cust_id" value="<?php echo $cm_data[0]['cm_cust_id'];?>"/>
                                        <?php else: ?>
                                            <?php echo form_dropdown('', $customer_data, $cm_data[0]['cm_cust_id'],'id="cm_cust_id" name="cm_cust_id" class="form-control flexselect floating-select" onchange="get_customer_data(this.value)" placeholder=" " autocomplete="off" tabindex="2" ');  ?>

                                        <?php endif; ?>
                                        <?php endif; ?>

                                        <label>PARTY</label>
                                    </div>
                                    <!-- party -->

                                    <!-- broker -->
                                    <div class="col-md-4 floating-label">
                                        <?php if(empty($cm_data)): ?>
                                        <?php echo form_dropdown('', $broker_data, 0,'id="cm_broker_id" name="cm_broker_id" class="form-control flexselect floating-select" onchange="get_broker_data(this.value)" placeholder=" " autocomplete="off" tabindex="3" ');  ?>
                                        <?php else: ?>
                                        <?php if($cm_data[0]['is_editable'] == 0): ?>
                                        <input type="text" class="form-control floating-input" value="<?php echo $cm_data[0]['broker']; ?> - <?php echo $cm_data[0]['broker_pan']; ?> - <?php echo $cm_data[0]['broker_mobile']; ?>" placeholder=" " autocomplete="off" tabindex="3" readonly/>

                                        <input type="hidden" id="cm_broker_id" name="cm_broker_id" value="<?php echo $cm_data[0]['cm_broker_id'];?>"/>
                                        <?php else: ?>
                                        <?php echo form_dropdown('', $broker_data, $cm_data[0]['cm_broker_id'],'id="cm_broker_id" name="cm_broker_id" class="form-control flexselect floating-select" onchange="get_broker_data(this.value)" placeholder=" " autocomplete="off" tabindex="3" ');  ?>
                                        <?php endif; ?>
                                        <?php endif; ?>
                                        <label>BROKER</label>
                                    </div>
                                    <!-- broker -->

                                    <!-- through -->
                                    <div class="col-md-2 floating-label">
                                        <?php if(empty($cm_data)): ?>
                                            <input type="text" class="form-control floating-input" id="cm_through" name="cm_through" value="<?php echo ''?>" placeholder=" " autocomplete="off" tabindex="4"/>
                                        <?php else: ?>
                                        <?php if($cm_data[0]['is_editable'] == 0): ?>
                                            <input type="text" class="form-control floating-input" id="cm_through" name="cm_through" value="<?php echo $cm_data[0]['cm_through']; ?>" placeholder=" " autocomplete="off" tabindex="4" readonly/>
                                        <?php else: ?>
                                            <input type="text" class="form-control floating-input" id="cm_through" name="cm_through" value="<?php echo $cm_data[0]['cm_through']; ?>" placeholder=" " autocomplete="off" tabindex="4"/>
                                        <?php endif; ?>
                                        <?php endif; ?>
                                        <label>THROUGH</label>
                                    </div>
                                    <!-- through -->
                                    <div class="col-md-2 floating-label">
                                        <textarea class="form-control floating-input" name="cm_notes" id="cm_notes" placeholder=" " autocomplete="off" tabindex="5"><?php echo empty($cm_data) ? ' ' : $cm_data[0]['cm_notes']; ?></textarea>

                                        <label>Notes</label>
                                    </div>
                                </div>
                                <div class="form-group floating-form">
                                    <div class="col-md-1 col-md-offset-9">
                                        <?php $display_btn = !empty($cm_data) ? '' : 'style="display:none;"'; ?>
                                        <button type="button" class="btn btn-primary" id="sbt_btn" <?php echo $display_btn; ?> onclick="<?php echo empty($cm_data) ? 'add_challan(0);' : "add_challan(".$cm_data[0]['cm_id'].");"  ?>" tabindex="10"><?php echo empty($cm_data) ? 'Submit' : 'Update'; ?></button>
                                         <input type="hidden" id="cm_id" value="<?php echo empty($cm_data) ? 0 : $cm_data[0]['cm_id']; ?>" >
                                    </div>
                                    <div class="col-md-1">
                                        <a href="<?php echo base_url('challan/challanctrl/challan_master?action=view');?>" type="button" class="btn btn-danger" id="cnl_btn" tabindex="11">Cancel</a>
                                    </div>
                                    <div class="col-md-1 floating-label">
                                        <input type="text" id="cm_total_qty" class="form-control floating-input" name="cm_total_qty" value="<?php echo empty($cm_data) ? '' : $cm_data[0]['cm_total_qty']; ?>" style="margin-top: 5px;margin-bottom: 5px;"  placeholder=" " autocomplete="off" readonly="">
                                        <label>Total Qty</label>

                                        <input type="hidden" id="cm_total_amt" class="form-control floating-input" name="cm_total_amt" value="<?php echo empty($cm_data) ? '' : $cm_data[0]['cm_total_amt']; ?>" style="margin-top: 5px;margin-bottom: 5px;"  placeholder=" " autocomplete="off" readonly="">
                                        <!-- <label>Total Amt</label> -->
                                    </div>
                                </div>
                            </div>
                            <div class="box box-primary">
                                <div class="box-header with-border"><!-- /.box-header -->
                                    <h3 class="box-title">Add Product</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">
                                    <br>
                                        <tr class="floating-form">
                                            <!-- diamond code -->
                                            <td class="floating-label" width="6%">
                                                <?php echo form_dropdown('', $diamond_data,'','id="dm_id" class="form-control flexselect floating-select" onchange="get_diamond_data(this.value)" placeholder=" " autocomplete="off" tabindex="6"');?>
                                                <label>STOCK ID</label>
                                            </td>
                                            <!-- diamond code -->

                                            <!-- diamond shape -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_sh" placeholder=" " autocomplete="off" readonly/>
                                                <label>SH</label>
                                            </td>
                                            <!-- diamond shape -->

                                            <!-- diamond weight -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_wt" placeholder=" " autocomplete="off" readonly/>
                                                <label>WT</label>
                                            </td>
                                            <!-- diamond weight -->

                                            <!-- diamond color -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_col" placeholder=" " autocomplete="off" readonly/>
                                                <label>COL</label>
                                            </td>
                                            <!-- diamond color -->

                                            <!-- diamond clarity -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_cla" placeholder=" " autocomplete="off" readonly/>
                                                <label>CLA</label>
                                            </td>
                                            <!-- diamond clarity -->

                                            <!-- diamond cutting -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_cut" placeholder=" " autocomplete="off" readonly/>
                                                <label>CUT</label>
                                            </td>
                                            <!-- diamond cutting -->

                                            <!-- diamond polish -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_pol" placeholder=" " autocomplete="off" readonly/>
                                                <label>POL</label>
                                            </td>
                                            <!-- diamond polish -->

                                            <!-- diamond symetry -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_sym" placeholder=" " autocomplete="off" readonly/>
                                                <label>SYM</label>
                                            </td>
                                            <!-- diamond symetry -->

                                            <!-- diamond florocent -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_fl" placeholder=" " autocomplete="off" readonly/>
                                                <label>FL</label>
                                            </td>
                                            <!-- diamond florocent -->

                                            <!-- diamond lab -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_lab" placeholder=" " autocomplete="off" readonly/>
                                                <label>LAB</label>
                                            </td>
                                            <!-- diamond lab -->

                                            <!-- diamond disc -->
                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_disc" placeholder=" " autocomplete="off" onkeyup="get_rap_amt()" tabindex="7"/>
                                                <label>DISC</label>
                                            </td>
                                            <!-- diamond disc -->
                                            <input type="hidden" class="form-control floating-input" id="dm_rap" placeholder=" " autocomplete="off" readonly/>
                                             <td class="floating-label" width="5%">
                                                <input class="form-control floating-input" id="dm_dollar" name="dm_dollar" placeholder=" " autocomplete="off" readonly/>
                                                <label>DOLLAR</label>
                                            </td>
                                            <!-- diamond rapnet -->

                                                




                                            <td class="floating-label" width="5%">
                                                <input type="text" class="form-control floating-input" id="dm_ppc" name="dm_ppc" placeholder=" " autocomplete="off" readonly/>
                                                <label>PRICE/CERT</label>
                                            </td>
                                            <!-- diamond rapnet -->

                                            <!-- certificate -->
                                            <td class="floating-label" width="5%">
                                                <?php echo form_dropdown('', [], 0,'id="dm_cert" name="dm_cert" class="form-control flexselect floating-select" placeholder=" " autocomplete="off" tabindex="8" ');  ?>

                                                <label>CERT</label>
                                            </td>
                                            <!-- certificate -->

                                            <!-- add trans -->
                                            <td style="text-align: center;" width="5%">
                                                <button  type="button" class="btn btn-success" onclick="<?php echo empty($cm_data) ? 'add_challan_trans_row(0)' : 'add_challan_trans_row('.$cm_data[0]['cm_id'].')' ; ?>"  style="padding-top: 5px;padding-bottom: 5px;width: 90%" tabindex="9">Add
                                                </button>
                                            </td>
                                            <!-- add trans -->

                                        </tr>
                                    </table>
                                </div>
                            </div><!-- /.box -->
                            <div class="box box-primary">
                            <div class="box-header with-border">
                                <h3 class="box-title">Product 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 cutting -->
                                        <th class="floating-label" width="5%">CUT</th>
                                        <!-- diamond cutting -->

                                        <!-- diamond polish -->
                                        <th class="floating-label" width="5%">POL</th>
                                        <!-- diamond polish -->

                                        <!-- diamond symetry -->
                                        <th class="floating-label" width="5%">SYM</th>
                                        <!-- diamond symetry -->

                                        <!-- diamond florocent -->
                                        <th class="floating-label" width="5%">FL</th>
                                        <!-- diamond florocent -->

                                        <!-- diamond lab -->
                                        <th class="floating-label" width="5%">LAB</th>
                                        <!-- diamond lab -->

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

                                        <!-- diamond rapnet -->
                                        <th class="floating-label" width="5%">DOLLAR</th>
                                        <!-- diamond rapnet -->
                                        <th class="floating-label" width="5%">PRICE/CT</th>
                                        <!-- certificate issue? -->
                                        <th class="floating-label" width="5%">CERT</th>
                                        <!-- certificate issue? -->

                                        <!-- remove trans -->
                                        <th style="text-align: center;" width="5%">REMOVE</th>
                                        <!-- remove trans -->
                                    </tr>
                                    <?php
                                        $cnt = 1;
                                        if(!empty($ct_data)):
                                            foreach ($ct_data 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="ct_id[]" id="ct_id_<?php echo $cnt; ?>" value="<?php echo $value['ct_id'] ?>">
                                                        <input type="hidden" name="ct_dm_id[]" id="ct_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 -->

                                                    <!-- cut -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_cut[]" id="ct_dm_cut_<?php echo $cnt; ?>" value="<?php echo $value['dm_cut']; ?>" readonly="">
                                                    </td>
                                                    <!-- cut -->

                                                    <!-- pol -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_pol[]" id="ct_dm_pol_<?php echo $cnt; ?>" value="<?php echo $value['dm_pol']; ?>" readonly="">
                                                    </td>
                                                    <!-- pol -->

                                                    <!-- sym -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_sym[]" id="ct_dm_sym_<?php echo $cnt; ?>" value="<?php echo $value['dm_sym']; ?>" readonly="">
                                                    </td>
                                                    <!-- sym -->

                                                    <!-- fl -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_fl[]" id="ct_dm_fl_<?php echo $cnt; ?>" value="<?php echo $value['dm_fl']; ?>" readonly="">
                                                    </td>
                                                    <!-- fl -->

                                                    <!-- lab -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_dm_lab[]" id="ct_dm_lab_<?php echo $cnt; ?>" value="<?php echo $value['dm_lab']; ?>" readonly="">
                                                    </td>
                                                    <!-- lab -->

                                                    <!-- 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']; ?>" readonly="">
                                                    </td>
                                                    <!-- disc -->
                                                     <?php
                                                        
                                                        $per = $value['ct_dm_rap'] * ($value['ct_dm_disc']/100);
                                                        $ppc = $value['ct_dm_rap'] + $per;
                                                            
                                                        $dollar = $ppc * $value['ct_dm_wt'];
                                                    ?>
                                                    <!-- rap -->
                                                    <input type="hidden" class="form-control floating-input" name="ct_dm_rap[]" id="ct_dm_rap_<?php echo $cnt; ?>" value="<?php echo $value['ct_dm_rap']; ?>" readonly="">
                                                     <td>
                                                        
                                                        <input class="form-control floating-input" name="ct_dollar[]" id="ct_dollar_<?php echo $cnt; ?>" value="<?php echo number_format($dollar,2); //$value['ct_dollar']; ?>" readonly="">
                                                    </td>
                                                    <!-- rap -->
                                                    <td>
                                                        <input class="form-control floating-input" name="ct_ppc[]" id="ct_ppc_<?php echo $cnt; ?>" value="<?php echo $ppc; //$value['ct_ppc']; ?>" readonly="">
                                                    </td>
                                                    <!-- cert -->
                                                    <td>
                                                        <input class="form-control floating-input" value="<?php echo $cert; ?>" readonly="">
                                                        <input type="hidden" class="form-control floating-input" name="ct_dm_cert[]" id="ct_dm_cert_<?php echo $cnt; ?>" value="<?php echo $value['ct_dm_cert']; ?>" readonly="">
                                                    </td>
                                                    <!-- cert -->

                                                    <!-- remove button -->
                                                    <td style="text-align: center;">
                                                        <?php if($value['ct_delete'] != 1): ?>
                                                            <a href="javascript:void(0)">
                                                            <i class="glyphicon glyphicon-ban-circle" style="color: #dd4b39;padding-top: 9px;"></i>
                                                        </a>
                                                        <?php else: ?>
                                                            <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>
                                                        <?php endif; ?>

                                                    </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 src="<?php echo assets('js/challan.js')?>"></script>
<?php
    if(!empty($cm_data))
    {
        echo "<script>";
        echo "challan_cnt = $cnt;";
        echo "</script>";
    }
?>
</body>
</html>