<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">
  
            <!-- begin:: Content Head -->
            <div class="kt-subheader  kt-grid__item" id="kt_subheader">
              <div class="kt-container  kt-container--fluid ">
                <div class="kt-subheader__main">
                  <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                  <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                  <span class="kt-subheader__desc"><a href="<?=base_url('multi_orders/')?>"><?php echo $this->lang->line('invoices') ?></a></span>
                </div>
              </div>
            </div>
    <!-- Content Header (Page header) -->
  <div class="row">
    <div class="col-md-12">
      <div class="box box-primary" style="padding: 20px">
        <div class="box-header with-border">
          <h3 class="box-title"><?php echo $this->lang->line('add-an-invoice') ?></h3>
        </div>
         <?php if(isset($msg) || validation_errors() !== ''): ?>
        <div class="alert alert-warning alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon fa-warning"></i> Alert!</h4>
            <?= validation_errors();?>
            <?= isset($msg)? $msg: ''; ?>
        </div>
        <?php endif; ?>  
        <?php echo form_open_multipart(base_url('multi_orders/add/')); ?>
          <div class="box-body">
              <div class="col-md-8">          
                    <label><?php echo $this->lang->line('products') ?></label>
                   
              </div> 
              <div class="col-md-2">          
                      <label><?php echo $this->lang->line('quantity') ?></label>
              </div> 
              <div class="col-md-2">          
                 <label><?php echo $this->lang->line('price') ?></label>
              </div>
              <div class="form-group  product_clone" id="product_clone">
                <div class="col-md-8">          
                  <select class="form-control product_id " name="id_producer[]" class="product_id"   dir="rtl" onchange="get_product_price(this.value)" required>
                    <option value=""><?php echo $this->lang->line('select'); echo' '; echo $this->lang->line('products');  ?></option>      
                    <?php $count=0; foreach($bills_producer as $row){?>
                    <option  value="<?= $row['id']; ?>"><?= $row['name']; ?></option>
                      <?php }?>
                  </select>
                </div> 
                <div class="col-md-2">          
                  <input type="text" class="form-control" name="quantity[]" placeholder="<?php echo $this->lang->line('quantity') ?>" value="1">
                </div> 
                <div class="col-md-2">          
                   <input type="text" class="form-control product_price" name="product_price[]"  placeholder="$ " value="" required>
                </div><br><br><br>     
              </div><br>
              <div class="new">
              </div>
              <div class="box-footer">
                <button type="button" class="btn btn-primary" onclick="create_new()" >+<?php echo $this->lang->line('new-item') ?></button>
                <button type="button" class="btn btn-warning remove" onclick="remove_last()" ><?php echo $this->lang->line('remove') ?></button>              </div>     
              <div class="form-group">
              <label for="exampleInputEmail1"><?php echo $this->lang->line('the-students') ?></label>
              <br>  
               <select  class="form-control" name="id_user" dir="rtl" data-placeholder="<?php echo $this->lang->line('choose') ; echo $this->lang->line('students'); ?>" required>
              <option value=""><?php echo $this->lang->line('select'); echo' '; echo $this->lang->line('students');  ?></option>   
             <?php $count=0; foreach($bills_user  as $row){?>
                   <option value="<?= $row['id']; ?>"><?= $row['username']; ?></option>
                   <?php } ?>
               </select>
              </div>
            <div class="form-group">
              <label><?php echo $this->lang->line('the-beginning-and-end-of-the-subscription') ?></label>
                <div class="input-group mb-5">
                  <!-- <div class="input-group-addon"style="border-left:#000;">
                    <i class="fa fa-calendar"></i>
                  </div> -->
                  <input type="text" class="form-control pull-right datepicker" id="start_datepicker" name="start_expiry">
              </div>
            </div>   
            <script> 
               function show() { 
                  document.getElementById('benefits').style.display='block'; 
              } 
               function show2() { 
                 document.getElementById('benefits').style.display='none';   
              } 
            </script> 
            <div class="form-group">
              <label>  <?php echo $this->lang->line('custom-fee') ?></label>
              <div class="radio">
                <input type="radio" name="paymentnew2"  value="1" onclick="show();">
                  <label> <?php echo $this->lang->line('yes') ?>
                    </label>
              </div>
              <div class="radio">
                  <input type="radio" name="paymentnew2"  value="2"  checked=""  onclick="show2();">
                  <label> <?php echo $this->lang->line('no') ?>
                    </label>
              </div>
            </div>    
            <div class="form-group" id="benefits" style="display: none">
              <label for="exampleInputPassword1">  <?php echo $this->lang->line('custom-fee') ?></label>
              <input type="number" class="form-control" id="exampleInputPassword1" placeholder="<?php echo $this->lang->line('enter-the-custom-price-if-any'); ?>" name="paymentnew" value="0" >
            </div>
            <div class="form-group">
                <label> <?php echo $this->lang->line('payment') ?> <?php echo $this->lang->line('status') ?></label>
              <div class="radio">
                  <input type="radio" name="paid"  value="1"  checked="">
                  <label>   <?php echo $this->lang->line('payment-is-made') ?>
                    </label>
              </div>
              <div class="radio">
                  <input type="radio" name="paid"  value="2">
                  <label>   <?php echo $this->lang->line('not-paid') ?>
                      </label>
              </div>
              <div class="radio">
                  <input type="radio" name="paid"  value="3">
                  <label>  <?php echo $this->lang->line('complimentary') ?> 
                  </label>
              </div>
              <div class="radio">
                <input type="radio" name="paid"  value="4">
                  <label> <?php echo $this->lang->line('retriever') ?>
                </label>
              </div> 
            </div>   
            <div class="form-group">
              <label><?php echo $this->lang->line('note') ?></label>
              <textarea class="form-control" rows="3" placeholder="<?php echo $this->lang->line('describe') ?>.." name="note"></textarea>
            </div>
            <div class="form-group">
              <label for="exampleInputPassword1"> <?php echo $this->lang->line('discount') ?>   </label>
              <input type="number" class="form-control" id="exampleInputPassword1" placeholder="<?php echo $this->lang->line('discount') ?> " name="discount" value="0" >
            </div>
            <div class="form-group">
                <label><?php echo $this->lang->line('the-reason-for-the-discount') ?>    </label>
                <textarea class="form-control" rows="3" placeholder="<?php echo $this->lang->line('describe') ?>..." name="discount_why"></textarea>
            </div>
            <div class="box-footer">
                <button type="submit" class="btn btn-primary" name="submit" value="submit"><?php echo $this->lang->line('save') ?></button>
            </div>               
         </form>
      </div>
    
    </div>
  </div>
<script>
function create_new(){ 
  var $button = $('.product_clone').clone();
  $('.new').html($button);
}    
function get_product_price(id){    
    
    var that = $(this);
   var id = id;
     $.ajax({
                method: "POST",
                url: "<?php echo base_url()?>Multi_orders/get_price/" +id,
                data: {'id':id},
              success: function(e) { 
                var obj = JSON.parse(e);
                if(obj.status == 1){ $(".product_clone .product_price:nth-child(1)").val(obj.price);
                // $(that).parents(".product_id").find(".product_price").val(obj.price);
                // $( ".product_price" ).val(obj.price);
                }
              }
            });
} function remove_last(){
    $(".product_clone:last-child").remove();
  }
 
