<!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>Sales Order</h4>
                        </div>
                    </div>
                    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">Sales Order</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">Add Order</a></li>
                        </ol>
                    </div>
                </div>
                
                <div class="row">


                    <div class="col-12">
            
                               
                            
                          <div class="col-xl-12 col-xxl-12 col-sm-12">
                             <div class="card">

                               <?php echo form_open(base_url(''),array('class'=>"form-horizontal add_sales_order", 'id'=>"add_sales_order")); ?>
                                    
                                        <?php if($this->session->flashdata('sales_order_success')){ ?>
                                <div class="alert alert-success solid" style='text-align:center;'><?php echo $this->session->flashdata('sales_order_success'); ?></div>
                            <?php } ?> 
                                <div class="card-body">
                                    <div id='sales_order_success' class='alert alert-success solid' style='display:none;'></div>
                                       <div class="row">
                                            
                                                    <input type="hidden" name="created" id="created" value="<?php echo date('Y-m-d H:i:s'); ?>" class="form-control required">
                                              

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

                                                <div class="form-group">
                                                    <label class="form-label">Customer Name:</label>
                                                    <select  data-live-search="true" name="party_id" required="required" id="party_id">
                                                        <option>Select Parties</option>
                                                        <?php foreach ($parties as $party) { ?>
                                                          <option value="<?php echo $party['p_id']; ?>"><?php echo $party['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">Party Code:</label>
                                                          <input type="text"  disabled="disabled"  class="form-control party_code">
                                                     </div>

                                                </div>
                                                
                                                <div class="col-lg-3 col-md-6 col-sm-12">

                                                    <div class="form-group">
                                                    <label class="form-label">PO.Date:</label>
                                                    <input type="date" name="so_date" id="so_date" required="required" class="form-control grade" 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">PO.NO:</label>
                                                        <input type="text" name="so_no" id="so_no" required="required"  class="form-control so_no">
                                                        <span id="check"></span>
                                                     </div>
                                                     
                                                </div>
                                                <div class="col-lg-3 col-md-6 col-sm-12">
                                                    <div class="form-group">
                                                    <label class="form-label">GST Rate:</label>
                                                    <select  data-live-search="true" name="gst" required="required" id="gst">
                                                    <option>Select GST</option>
                                                     <option value="4.5">4.5</option>
                                                      <option value="17">17</option>
                                                      <option value="18">18</option>
                                                       <option value="0">0</option>
                                                        
                                                </select>
                                                 </div>
                                               </div>
                                                <!-- <div class="col-lg-2 col-md-6 col-sm-12">
                                                 <div class="form-group">
                                                    <label class="form-label">SO.Date:</label>
                                                    <input type="text"  readonly="readonly" value="<?php echo date('d/m/y'); ?>" class="form-control grade">
                                                 </div>
                                                </div> -->
                                                <div class="col-lg-2 col-md-6 col-sm-12">
                                                    

                                                 <div class="form-group">
                                                    <label class="form-label">Tolerance:</label>
                                                    <input type="text" id="tolerance" name="tolerance" class="form-control tolerance" 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">Intructions:</label>
                                                <input type="text" name="instruction" id="instruction" class="form-control code">
                                             </div>

                                        </div>


                                        <div class="col-lg-3 col-md-6 col-sm-12">
                                        <div class="form-group">
                                              <label class="form-label">Pay Term:</label>
                                                <select  data-live-search="true" name="pay_term" required="required" id="pay_term">
                                                    <option>Select Term</option>
                                                     <option value="30">30 Days</option>
                                                      <option value="45">45 Days</option>
                                                       <option value="60">60 Days</option>
                                                        <option value="0">CAD</option>
                                                </select>
                                           </div> 

                                        </div>


                                         <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Item Description:</label>
                                                      <select  data-live-search="true" name="product_id" required="required" id="product_id">
                                                        <option value="">Select Component</option>
                                                        <?php if(!empty($get_fg)){?>

                                                        <?php foreach ($get_fg as $get_all_pro_fg) { ?>
                                                            <option value="<?php echo $get_all_pro_fg['id']; ?>"><?php echo $get_all_pro_fg['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">Item Code:</label>
                                                    <input type="text"  readonly="readonly"   class="form-control pro_code">
                                                 </div>
                                                </div>


                                               <div class="col-lg-3 col-md-6 col-sm-12">
                                                <div class="form-group">
                                                    <label class="form-label">Party Ref Code:</label>
                                                     <select  data-live-search="true" name="ref_code" required="required" id="ref_code">
                                                    <option value="">Select Party Ref Code</option>
                                                        <?php if(!empty($get_fg)){?>

                                                        <?php foreach ($get_ref_party as $get_ref_partys) { ?>
                                                            <option value="<?php echo $get_ref_partys['ref_code']; ?>"><?php echo $get_ref_partys['ref_code']; ?></option>

                                                        <?php } } ?>
                                                      
                                                  </select>

                                                    <!-- <input type="text" name="ref_code" id="ref_code"  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">Delv.Date:</label>
                                                      <input type="date" required="required" name="delv_date" id="delv_date"  class="form-control ">
                                                 </div>
                                                </div>

                                                 <div class="col-lg-3 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                    <label class="form-label">Unit Rate:</label>
                                                     <input type="number" step=".01" required="required" readonly="readonly" name="unit_rate" id="unit_rate"  class="form-control " onchange="addZeroes(this)">

                                                     
                                                       </div>
                                                </div>

                                                <div class="col-lg-3 col-md-6 col-sm-12">
                                                  <div class="form-group">
                                                    <label class="form-label">Quantity:</label>
                                                    <input type="text" required="required" name="quantity" id="quantity"  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">Unit:</label>
                                                    <input type="text" value="Pc" 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">Amount+(GST):</label>
                                                    <input type="text" required="required" readonly="readonly" name="amount" id="amount"  class="form-control ">

                                                       </div>

                                                </div>





                                        
                                              </div>

                                     <button type="submit" id="save_data" class="btn btn-primary">Save <i class="icon-arrow-right14 position-right"></i></button>
                                    </div>

                                     <?php form_close();?>
                                </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>
                                   <?php if($this->session->flashdata('material_danger')){ ?>
                                    <div class="alert alert-danger solid " style='text-align:center;'><?php echo $this->session->flashdata('material_danger'); ?></div>
                                <?php } ?>
                                 <div id='material_danger' class='alert alert-danger solid' style='display:none;width: 30%;'></div>
                               <br/><br/><br/>
                                <div class="table-responsive">

                                    <table id="example5" class="display" style="font-size:12px; min-width: 1500px">
                                        <thead>
                                            <tr>
                                                
                                                <th>SO No</th>
                                                <th>SO Date</th>
                                                <th>Delivery Date</th>
                                                <th>Party Name</th>
                                               <th>Items</th>
                                                <th>Qty</th>
                                                <th>Remaining Qty</th>
                                                <th>Tolerance</th>
                                                <th>Qty Tolorence</th>
                                                <th>Status</th>
                                                <!-- <th>Items</th> -->
                                                <th>Action</th>
                                                
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php if(!empty($get_po)) {?>
                                                <?php foreach ($get_po as $all_get_po) {
                                                   
                                                 ?>
                                            <tr>

                                                 
                                                <td><strong><?php echo $all_get_po['so_no']; ?></strong></td>
                                                <td><?php   echo date("d-m-Y", strtotime($all_get_po['so_date']) );  ?></td>
                                                 <td><?php 
                                                 $so_d_date = so_delivery_date($all_get_po['id']);
                                                 
                                                 echo date("d-m-Y", strtotime($so_d_date) );
                                                 
                                                 ?></td>
                                                <td><strong><?php echo $all_get_po['party_name']; ?></strong></td>
                                               <td><?php 
                                               $items = sale_order_pro ($all_get_po['id']);
                                               echo product_name($items);
                                                        
                                               ?></td>
                                                    <td><?php echo qty_so($all_get_po['id']); ?></td>
                                                     <?php  $deliver = deliverd_qty($all_get_po['id']); ?>
                                                         <td><?php  echo qty_so($all_get_po['id'])-$deliver; ?></td>
                                                    <td><?php echo tolerence($all_get_po['id']); ?>%</td>
                                                    <td><?php echo qty_so_tolorence($all_get_po['id']); ?></td>
                                                 <?php if($all_get_po['status']==0) {?>
                                                <td><span class="badge badge-warning">Open Order</span></td>
                                                <?php }else if($all_get_po['status']==1) {?>
                                                    <td><span class="badge badge-success">Completed</span></td>
                                                <?php } ?>
                                               
                                                
                                                <td>

                                                 
                                                  <a href="<?php echo base_url('Sales_order/view_invoice_details_so/'.$all_get_po['id']);?> " target="_blank"  class="badge badge-primary">View</a>

                                                  <a href="<?php echo base_url('Sales_order/edit_sales_order/'.$all_get_po['id']); ?>" class="btn btn-sm btn-primary"><i class="la la-pencil"></i></a>
                                                  <a href="javascript:void(0);" onclick="delete_data_so(<?php echo $all_get_po['id']; ?>)" class="btn btn-sm btn-danger"><i class="la la-trash-o"></i></a>

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

                   
                </div>
            </div>
       
        <!--**********************************
            Content body end
        ***********************************-->


        <!--**********************************
            Footer start
        ***********************************-->
        
        <!--**********************************
            Footer end
        ***********************************-->

        <!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->


    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <style>
        .redborder{
            border:1px solid red;
        }
        </style>

         <SCRIPT language=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;
       }
       //-->
    </SCRIPT>
    <script type='text/javascript'>

       $("#product_id").change(function() {
    
        var id =  this.value;
        //alert(id);
        $.ajax({
                    type:'POST',
                    url:'<?php echo base_url('Sales_order/fg_product_code'); ?>',
                    data:{id:id},
                    dataType:'json',
                    success:function(data){
                        //console.log(data[0].material_code);
                        $('.pro_code').val(data[0].pro_code);
                        //$('.unit').val(data[0].unit);
                       
                       //$('.weight').val(data[0].weight);
                       
                    },
                    error:function(data){console.log(data.responseText);}
                });

    });

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

          var id =  this.value;
       
        $.ajax({
                    type:'POST',
                    url:'<?php echo base_url('Sales_order/fg_product_rates'); ?>',
                    data:{id:id},
                    dataType:'json',
                    success:function(data){
                        //console.log(data[0].material_code);
                        $('#unit_rate').val(data[0].rates);
                        //$('.unit').val(data[0].unit);
                       
                       //$('.weight').val(data[0].weight);
                       
                    },
                    error:function(data){console.log(data.responseText);}
                });

    });
    
    $("#unit_rate,#quantity").keyup(function() {

        var gst = $('#gst').val();
       
            if(gst !=0){
          var aa = $('#unit_rate').val() * $('#quantity').val();
           //var total = aa*1.17;
             var total = aa*1.18;
                
            }else{

                 var total = $('#unit_rate').val() * $('#quantity').val();
            }
           //var result = number_format(total);
         var output=parseInt(total).toLocaleString(); 
          $('#amount').val(output);

    });

 function addZeroes(ev) {
           
            // Convert input string to a number and store as a variable.
            var value = Number(ev.value);
            // Split the input string into two arrays containing integers/decimals
            var res = ev.value.split(".");
            // If there is no decimal point or only one decimal place found.
            if (res.length == 1 || res[1].length < 3) {
                // Set the number to two decimal places
                value = value.toFixed(4);
            }
            // Return updated or original number.
            if (ev.value != "") {
                ev.value = String(value);
            }
        }


          function delete_data_so(id) { 
        var id = id;
        if (confirm('Are you sure you want to Delete.?')) {
  
         $.ajax({
                type:'POST',
                url:'<?php echo base_url('Sales_order/sales_order_delete_data/'); ?>'+id,
                data:id,
                dataType:'json',
                success:function(data){
                    console.log('first'+data.status);
                    
                        console.log('second'+data.status);
                        //debugger;
                        $('#material_danger').show().html('Deleted Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Sales_order/all_sales_order'); ?>"} , 3000);
                    
                },
                error:function(data){console.log(data.responseText);}
            });
        } else {
  
            }
        } 


  
    var add_order = $('#add_sales_order');   
    
    add_order.on('submit',function(e){

        e.preventDefault();
        $("#save_data").attr('disabled', true);
        var add_add_order = add_order.serialize();
         //var id = $('#main_product').val();
      
            $.ajax({
                type:'POST',
                url:'<?php echo base_url('Sales_order/all_sales_order'); ?>',
                data:add_add_order,
                dataType:'json',
                success:function(data){
                    console.log('first'+data.status);
                    if(data.status === 'true'){
                        console.log('second'+data.status);
                        $('#sales_order_success').show().html('Sales Order added Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Sales_order/all_sales_order/'); ?>"} , 2000);
                    }else if(data.check_status === 'true'){
                        $("#save_data").attr('disabled', false);
                               alert('Sales Order Number Already Created ....!');
                               $('#sales_order_success').show().html('Sales Order added Successfully');
                       setTimeout(function(){location.href="<?php echo base_url('Sales_order/all_sales_order/'); ?>"} , 2000);
                    }else{
                        console.log('third'+data);  
                    }
                },
                error:function(data){console.log(data.responseText);}
            });
       // }
    });

   



        $("#party_id").change(function() {
    
        var id =  this.value;

        $.ajax({
                    type:'POST',
                    url:'<?php echo base_url('Sales_order/parties_code'); ?>',
                    data:{id:id},
                    dataType:'json',
                    success:function(data){
                        //console.log(data[0].material_code);
                        $('.party_code').val(data[0].party_code);
                        //$('.code').val(data[0].pro_code);
                       
                       //$('.weight').val(data[0].weight);
                       
                    },
                    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>   

       <?php  $this->load->view('footer'); ?>
        
</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> 