<!DOCTYPE html>
<html lang="en">


<!-- Mirrored from edumin.dexignlab.com/xhtml/add-departments.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 17 Nov 2020 13:56:15 GMT -->
<head>
  
   <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Rizwan </title>
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="<?php echo base_url();?>assets/images/favicon.png">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/bootstrap-select/dist/css/bootstrap-select.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/css/style.css">
    <!-- Pick date -->
   <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/pickadate/themes/default.css">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/vendor/pickadate/themes/default.date.css">
     <link href="<?php echo base_url();?>assets/vendor/datatables/css/jquery.dataTables.min.css" rel="stylesheet">
    <!-- Custom Stylesheet -->
     

</head>

<body>

    <!--*******************
        Preloader start
    ********************-->
        <div id="preloader">
        <div class="sk-three-bounce">
            <div class="sk-child sk-bounce1"></div>
            <div class="sk-child sk-bounce2"></div>
            <div class="sk-child sk-bounce3"></div>
        </div>
    </div>
    <!--*******************
        Preloader end
    ********************-->

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

      <?php  $this->load->view('header'); ?>
    
        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
            <div class="container-fluid">
            
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>Production Plan</h4>
                            <button type="button" class="badge badge-primary" data-toggle="modal" data-target=".bd-example-modal-lg" onclick="bom_destroye_production('<?php echo $this->uri->segment('3'); ?>')">Load Bom Requirement</button>                           
                        </div>

                    </div>
                    
                </div>
        
        <div class="row">


                    <div class="col-12">
                        <?php echo form_open(base_url(''),array('class'=>"form-horizontal add_plan", 'id'=>"add_plan")); ?>


         
                                        <?php if($this->session->flashdata('add_add_plan_success')){ ?>
                                <div class="alert alert-success solid" style='text-align:center;'><?php echo $this->session->flashdata('add_add_plan_success'); ?></div>
                            <?php } ?>         
                            
                         
                             <div class="card">
                               
                               <!-- <input type="hidden" name="child_id" id="child_id" value="<?php echo $child_id;?>" class="form-control required"> -->

                               <?php if($get_production ==""){ ?>
                                <div class="card-body">
                                    <div id='add_add_plan_success' class='alert alert-success solid' style='display:none;'></div>
                                       <div class="row">


                                           <input type="hidden" name="so_id" id="so_id" value="<?php echo $this->uri->segment('3'); ?>">


                                            <input type="hidden" name="pro_seg" disabled="disabled" id="pro_seg" value="<?php echo $this->uri->segment('4'); ?>">


                                           
                                            <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Job No:</label>
                                                    <input type="text" id="job" name="job" value="<?php echo $job_no; ?>" readonly="readonly"  class="form-control job">
                                                 </div>
                                                </div>


                                            <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Item:</label>
                                                    <input type="text" id="product_name" name="product_name" value="<?php echo product_name($this->uri->segment('4')); ?>" readonly="readonly" style="font-size:12px;" class="form-control product_name">
                                                 </div>
                                                </div>  


                                                 <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Company:</label>
                                                    <input type="text" id="party_id" name="party_id" value="<?php echo  partyname($get_so_data[0]['party_id']); ?>" readonly="readonly"  class="form-control party_id" style="font-size:12px;">
                                                 </div>
                                                </div>    


                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Need Production:</label>
                                                    <?php 

                                                    $total_in_stock =  get_in_balance($this->uri->segment('4'))-get_out_balance($this->uri->segment('4'));  

                                                        $condi = $total_in_stock - $get_semi_data[0]['quantity'];

                                                        if($get_semi_data[0]['quantity']  > $condi){

                                                                $total = abs($total_in_stock - $get_semi_data[0]['quantity']);

                                                        }else{

                                                              $total = abs($total_in_stock - $get_semi_data[0]['quantity']);
                                                        }
                                                    ?>
                                                    <input type="text" id="pro_qty" name="pro_qty" value="<?php echo $total;  ?>" readonly="readonly"  class="form-control pro_qty">
                                                 </div>
                                                </div>   

                                            <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Material:</label>
                                                    
                                                       <select data-live-search="true" name="material_id" required="required" id="material_id" class="form-control material_ids">
                                                        <option value="">Select Material</option> 
                                                       
                                                      <?php 
                                                          foreach ($get_material_data as $values) { ?>

                                                                 <?php  $type = material_type_po($values['material_id']);
                                                                if($type==1){
                                                         ?>    

                                                        <option value="<?php echo $values['material_id']; ?>"><?php echo material_name($values['material_id']); ?></option>
                                                        
                                                     <?php  } }?>
                                                    
                                                  </select>
                                                 </div>
                                                </div>


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;"> BOM-QTY:</label>
                                                      <input type="text" name="bom_qty"  id="bom_qty" readonly="readonly"  class="form-control bqty">
                                                 </div>
                                                </div>

                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;"> BOM-Unit:</label>
                                                      <input type="text" name="bom_unit"  id="bom_unit" readonly="readonly"  class="form-control bom_unit">
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;"> IN Stock-QTY/Bag:</label>
                                                      <input type="text" name="in_stock_qty"  id="in_stock_qty" readonly="readonly"  class="form-control in_stock_qty">
                                                 </div>
                                                </div>


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Plan QTY:</label>
                                                      <input type="text" name="p_qty"  id="p_qty"  required="required" class="form-control p_qty" onkeypress="return isNumberKey(event)">
                                                 </div>
                                                </div>


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Pcs Weight(gm):</label>
                                                      <input type="text" name="" value="<?php echo get_per_pcs_weight($this->uri->segment('4')); ?>" id="" readonly="readonly"  class="form-control ">
                                                 </div>
                                                </div>

                                               <!--   <div class="col-lg-3 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                      <label class="form-label">Color:</label>
                                                      <input type="text" id="color" name="color" readonly="readonly" class="form-control color">
                                                   </div>
                                                </div> -->
                                                    
                                                <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Color:</label>
                                                    
                                                       <select data-live-search="true" name="color_id" id="color_id" class="form-control color_id">
                                                        <option value="">Select Color</option> 
                                                       
                                                      <?php 
                                                          foreach ($get_material_data as $values) { ?>

                                                        <?php  $type = material_type_po($values['material_id']);
                                                                if($type==3){
                                                         ?>    

                                                        <option value="<?php echo $values['material_id']; ?>"><?php echo material_name($values['material_id']); ?></option>
                                                        
                                                     <?php  } }?>
                                                    
                                                  </select>
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;"> Color BOM-QTY:</label>
                                                      <input type="text" name="cqty"  id="cqty" readonly="readonly"  class="form-control cqty">
                                                 </div>
                                                </div>

                                                 <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Unit:</label>
                                                      <input type="text" name="bom_unit_color"  id="bom_unit_color" readonly="readonly"  class="form-control bom_unit_color">
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;"> Color QTY/KG:</label>
                                                      <input type="text" name="in_stock_qty_color"  id="in_stock_qty_color" readonly="readonly"  class="form-control in_stock_qty_color">
                                                 </div>
                                                </div>

                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Cutting Ratio/bag:</label>
                                                      <input type="text" name="cutting_ratio"   id="cutting_ratio"  class="form-control ">
                                                 </div>
                                                </div>  


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Semi Standard:</label>
                                                      <input type="text" name="semi_standard"   id="semi_standard"  class="form-control" onkeypress="return isNumberKey(event)" >
                                                 </div>
                                                </div>  


                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Weight Standard(kg):</label>
                                                      <input type="text" name="weight_standard"   id="weight_standard"  class="form-control"  onkeypress="return isNumberKey(event)" >
                                                 </div>
                                                </div>  

                                                <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Spacification No:</label>
                                                    <?php $mold_id =  get_mold_id($this->uri->segment('4')); ?>
                                                    
                                                      <input type="text" name="spec_no" readonly="readonly" value="<?php echo ref_no_para($mold_id); ?>" required="required" id="spec_no"  class="form-control ">

                                                 </div>
                                                </div>

                                                <div class="col-lg-3 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Mould:</label>
                                                      <select data-live-search="true" name="mold" id="mold"  readonly="readonly" class="form-control" required="required">

                                                     <!--<option value="<?php //echo mold_product_id($this->uri->segment('4')); ?>"><?php //echo mold_product($this->uri->segment('4')); ?></option>
                                                    -->   
                                                       <?php 
                                                          foreach ($get_molds_data as $values) { ?>

                                                        <option value="<?php echo $values['id']; ?>"><?php echo $values['code']; ?></option>
                                                        
                                                     <?php  } ?> 
                                                    
                                                  </select>
                                                       </div>

                                                </div>

                                               <!--   <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Machine:</label>
                                                      <select data-live-search="true" name="machine" id="machine" class="form-control" required="required">

                                                        <option>Select Machine</option>
                                                       
                                                      <?php 
                                                          foreach ($get_machine_data as $values) { ?>

                                                        <option value="<?php echo $values['id']; ?>"><?php echo $values['machine_name']; ?></option>
                                                        
                                                     <?php  } ?>
                                                    
                                                  </select>
                                                 </div>
                                                </div> -->


                                              <!--   <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Day Expected Production:</label>
                                                      <input type="date" name="day_expected" required="required" id="day_expected"  class="form-control ">
                                                 </div>
                                                </div> -->

                                                 <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label" style="font-size: 11px;">Remarks:</label>
                                                      <textarea name="remarks" class="form-control" id="remarks"></textarea> 
                                                 </div>
                                                </div>

                                                <input type="hidden" name="user_id" id="user_id" value="<?php echo $this->session->userdata('id');?>">

                                                <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                   
                                                    <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
                                                </div>
                                            </div>

                                            <div class="col-lg-6 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                   
                                                    <input type="hidden" value="<?php echo date('Y-m-d H:i:s'); ?>" name="modified" id="modified" class="form-control required">
                                                </div>
                                            </div>
                                           
                                        
                                       </div>
                                         <button type="submit" id="dc_dis" class="btn btn-primary">Submit <i class="icon-arrow-right14 position-right"></i></button>
                                     </div>

                                 <?php }else{echo ""; } ?>
                                    </div>
                                    
                          
                           
                               
                                
                                            
                                 <?php form_close();?>


                    </div>


                         
                  </div>
            </div>

            <div class="col-12">

                                 <div class="card">

                            <div class="card-body">
                                <button type="button" class="btn btn-rounded btn-success" onclick="btnExport_monthly();"><span class="btn-icon-left text-success"><i class="fa fa-download color-success"></i>
                                    </span>Download</button>
                                  
                                <div class="table-responsive">

                                    <table id="example5" class="display" style="font-size:11px;">
                                        <thead>
                                            <tr>
                                                
                                                <th>Job#</th>
                                                <th>Item</th>
                                                <th>QTY</th>
                                                <th>Material</th>
                                                <th>Production </th>
                                                <th>Color</th>
                                                <th>Ratio</th>
                                                <th>Specifications</th>
                                                <th>Mold</th>
                                             
                                                 <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
                                            <tr>

                                              <?php if(!empty($get_production)){ ?>
                                                <?php foreach ($get_production as  $value) { ?>

                                                  <td><?php echo $value['job']; ?></td>
                                                  <td><?php 
                                                      echo $value['product_name'];
                                                     // echo product_name($so_get_pro);
                                                   ?></td>
                                                  <td><?php echo $value['pro_qty']; ?></td>
                                                  <td><?php echo material_name($value['material_id']); ?></td>
                                                  <td><?php echo $value['p_qty']; ?></td>
                                                  <td><?php echo material_name($value['color_id']); ?></td>
                                                  <td><?php echo $value['cutting_ratio']; ?></td>
                                                  <td><?php echo $value['spec_no']; ?></td>
                                                  <td><?php echo mold_code($value['mold']); ?></td>
                                                  
                                                  <td><a href="<?php echo base_url('Requisition/edit_plan_production/'.$value['id'].'/'.$this->uri->segment('3').'/'.$this->uri->segment('4')); ?>" class="btn btn-sm btn-primary"><i class="la la-pencil"></i></a>
                                              </td> 

                                                     
                                               
                                            </tr>
                                        <?php } ?>

                                                 <?php } ?>
                                        </tbody>
                                      
                                    </table>
                                </div>
                                
                              </div>
                              </div>
                            </div>
        </div>


         


           <div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
                                        <div class="modal-dialog modal-lg">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                  
                                                    <button type="button" class="close" data-dismiss="modal"><span>&times;</span>
                                                    </button>
                                                </div>
                                                <div class="modal-body">
                                              
                                            <div class="col-xl-12 col-xxl-12 col-sm-12">
                                                <div class="card">
                                                    <div class="card-header">
                                  <h5 class="card-title"> BOM Components</h5>
                                                    </div>
                                                   
                                                   <div class="card-body" id="bom_details_productions">
                                              
                                                    </div>
                                                </div>
                                            </div>



                                                </div>
                                                <div class="modal-footer">
                                                   
                                 <!-- <button type="button"  class="btn btn-primary" onclick="execute('<?php  //echo $view_so_product[0]['product_id']; ?>')">Execute</button>
                                                 
                                                    <input type="hidden" id="so_id" value="<?php //echo $this->uri->segment('3'); ?>"> -->

                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                  
                                                </div>
                                            </div>
                                        </div>
                                    </div>
       
       
    </div>
                                    
  <!-- Required vendors -->
      <?php  $this->load->view('footer'); ?>
        <style>
        .redborder{
            border:1px solid red;
        }
        </style>

    <script type='text/javascript'>

      function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }

      
       $("#material_id").change(function() {

                
    
                var id =  this.value;
                 var pro_seg = $('#pro_seg').val();

                   var so_id = $('#so_id').val();
                
               $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Requisition/get_production_qty'); ?>',
                            data:{id:id,pro_seg:pro_seg,so_id:so_id},
                            dataType:'json',
                            success:function(data){
                            
                                    
                                    $('.bqty').val(data.total);
                                    $('#bom_unit').val(data.unit);
                                    $('#in_stock_qty').val(data.total_qty);
                                    $('#color').val(data.color);
                                    
                                    
                               
                            },
                            error:function(data){console.log(data.responseText);}
                        }); 
                  });



              $("#color_id").change(function() {

                
    
                var id =  this.value;
                 var pro_seg = $('#pro_seg').val();
                  var so_id = $('#so_id').val();
                
               $.ajax({
                            type:'POST',
                            url:'<?php echo base_url('Requisition/get_production_qty'); ?>',
                            data:{id:id,pro_seg:pro_seg,so_id:so_id},
                            dataType:'json',
                            success:function(data){
                            
                                    
                                    $('.cqty').val(data.total);
                                    $('#bom_unit_color').val(data.unit);
                                    $('#in_stock_qty_color').val(data.total_qty);
                                    $('#color').val(data.color);
                                    
                                    
                               
                            },
                            error:function(data){console.log(data.responseText);}
                        }); 
                  });

      function bom_destroye_production(so_id) { 
      var id =  so_id;
      

      $.ajax({
                type:'POST',
                url:'<?php echo base_url('Sales_order/bom_destroye_production'); ?>',
                data:{id:id},
                dataType:'json',
                success:function(data){
                    //console.log('first'+data.status);
                    //if(data.status === 'true'){
                     $('#bom_details_productions').show().html(data.html);
                       //$('#bom_details').show(data);
                   /* }else{
                        //console.log('third'+data);          
                    }*/
                },
                error:function(data){console.log(data.responseText);}
            });
       
        } 



                         var add_plan = $('#add_plan');   
    
                                add_plan.on('submit',function(e){
                                  
                                    e.preventDefault();
                                     var in_stock_qty = parseInt($("#in_stock_qty").val());
                                        var bom_qty = parseInt($("#bom_qty").val());

                                           var cqty = parseInt($("#cqty").val());
                                        
                                        var in_stock_qty_color = parseInt($("#in_stock_qty_color").val());
                                        
                                     /*if (in_stock_qty < bom_qty || in_stock_qty == 0) {
                                      alert("Material Stock Not Available Create P.O Please..!");
                      
                                      }else*/
                                      if(in_stock_qty_color <= cqty || in_stock_qty_color == 0){

                                         alert("Color Stock Not Available Create P.O Please..!");

                                      }else{

                                     var so_id = $('#so_id').val();
                                     if (confirm('Are you sure you want to Add Production.?')) {
  
                                      $("#dc_dis").attr('disabled', true);
       
                                    var add_plandata = add_plan.serialize();
                                     $.ajax({
                                            type:'POST',
                                            url:'<?php echo base_url('Requisition/add_plan_data'); ?>',
                                            data:add_plandata,
                                            dataType:'json',
                                            success:function(data){
                                                console.log('first'+data.id);
                                               // alert(data);
                                                if(data.status !=''){
                                                    console.log('second'+data.id);
                                                    $('#add_add_plan_success').show().html('Plan added Successfully');
                                                   setTimeout(function(){location.href="<?php echo base_url('Requisition/semi_finish_production_plan/'); ?>"+so_id} , 3000);
                                                }else{
                                                    console.log('third'+data);          
                                                }
                                            },
                                            error:function(data){console.log(data.responseText);}
                                        });
                                     } 
                                   }
                                });




        /* function add_production_plan(id) { 
          var id =  id;
          var so_id = $('#so_id').val(); 
         // alert(so_id);
         
      $.ajax({
                type:'POST',
                url:'<?php echo base_url('Requisition/view_Data_production_plan'); ?>',
                data:{so_id:so_id},
                dataType:'json',
                success:function(data){
                    //console.log('first'+data.status);
                    //if(data.status === 'true'){
                         console.log(data);
                     $('#bom_details').show().html(data.html);
                       //$('#bom_details').show(data);
                  
                },
                error:function(data){console.log(data.responseText);}
            });
       
        } */
        
           
     function btnExport_monthly()
{
    
    var tab_text="<table border='2px'><tr bgcolor='#ebebeb'>";
    var textRange; var j=0;
    tab = document.getElementById('example5'); // id of table

    for(j = 0 ; j < tab.rows.length ; j++) 
    {     
        tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
        //tab_text=tab_text+"</tr>";
    }

    tab_text=tab_text+"</table>";
    tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
    tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
    tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params


    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE "); 

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
    {
        txtArea2.document.open("txt/html","replace");
        txtArea2.document.write(tab_text);
        txtArea2.document.close();
        txtArea2.focus(); 
        sa=txtArea2.document.execCommand("SaveAs",true,"Generation_School_Report");
    }  
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  

    return (sa);
}
    </script>   

     
        
</body>

<!-- Mirrored from edumin.dexignlab.com/xhtml/add-departments.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 17 Nov 2020 13:56:15 GMT -->
</html>