<form role="form" class="form-horizontal" id="bulk_break_form" action="#" method="post">
  <input type="hidden" value="<?php echo $product_id;?>" name="product_id" id="product_id"/>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">Bulk Break</h4>
    <font style="color:#333;">The field labels marked with * are required input fields.</font>
  </div>
  <div class="modal-body">
    <div id="error"></div>
      <div class="col-md-12">
          <div class="form-group">
            <h5>
              <label class="control-label"> <?php echo $product_details->product_name,"(".$product_details->product_code.")"; ?> </label>
            </h5>
           </div>
        </div>
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Quantity taking from main product* </label>
            </h5>
            <input type="number" class="form-control" name="main_qty" id="main_qty" max="<?php echo $qty; ?>" min="1" required="required">
		</div>
	</div>
    
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Unit Cost of Main Product* </label>
            </h5>
            <input type="text" class="form-control" name="unit_cost" id="unit_cost" value="<?php echo $product_details->product_cost; ?>">
		</div>
	</div>
    
    <div class="col-md-12">
      <div class="form-group">
        <label>Sub Product*</label>
        <input type="hidden" id="sub_product_id"  name="sub_product_id" class="js-data-product-sn-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select Item-" onChange="setitemselect()"/>
      </div>
    </div>
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Breaking into Quantity* </label>
            </h5>
              <input type="text" class="form-control" name="sub_qty" id="sub_qty">
		</div>
	</div>
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Wholesale Price* </label>
            </h5>
            <input type="text" class="form-control" name="wholesale_price" id="wholesale_price">
		</div>
	</div>
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Cash Price* </label>
            </h5>
            <input type="text" class="form-control" name="retail_price" id="retail_price">
		</div>
	</div>
    <div class="col-md-12">
		<div class="form-group">
            <h5>
              <label class="control-label"> Credit Price* </label>
            </h5>
            <input type="text" class="form-control" name="credit_price" id="credit_price">
		</div>
	</div>
  </div>
  <div class="">
  <div class="col-md-12 well">
		<div class="pull-right">
    <input type="submit" name="do_break" value="BREAK" class="btn btn-primary" />
    </div>
    </div>
  </div>
  
  <!--/.col-md-12-->
</form>

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION--> 
<script src="<?php echo asset_url(); ?>js/form-validation-bulk_break.js"></script> 
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION--> 

<script>
   jQuery(document).ready(function() {
        FormValidator.init();
   });
   $("#sub_product_id").select2({
	   
	  // var cat_srh=$("#cat_srh").val();
	 //  var subcategory=$("#subcategory").val();
        ajax: {
			'type': 'POST',
				'url': '<?php echo base_url('bulk_break/get_sub_products');?>/'+$("#product_id").val(),
                dataType: 'json',
                delay: 0,
			
                data: function (query) {
							//alert(1);
                if (!query)
                        query = '';
                return {
                		search_string: query,
				 		main_product_id: $("#product_id").val(),
				  		//subcategory: $("#subcategory").val(),
						//service_item_avalable: $("#service_item_avalable").val(),
                        format: 'json'
                };
                },
                results: function (data) {
                return {
                results: $.map(data, function (item) {
                return {
					//alert();
                text: item.product_name+' ('+item.product_code+')',
                        slug: item.product_id,
                        id: item.product_id
                };
                })
                };
                },
                cache: true
         }
        });
</script> 
<script type="text/javascript">
function insertBulkData(){
	
var product_id	=$('#product_id').val();
var sub_product_id = $('#sub_product_id').val();
var main_qty	= $('#main_qty').val();
var sub_qty		= $('#sub_qty').val();
var unit_cost	= $('#unit_cost').val();
var retail_price	=	$('#retail_price').val();
var wholesale_price	=	$('#wholesale_price').val();
var credit_price	=	$('#credit_price').val();
					 
$.post( "<?php echo base_url('bulk_break/process'); ?>", {
	product_id		:product_id,
	product_qty		:main_qty,
	product_cost	:unit_cost,
	sub_product_id	:sub_product_id,
	sub_product_qty	:sub_qty,
	wholesale_price	:wholesale_price,
	retail_price	:retail_price,
	credit_price	:credit_price,
	warehouse_id	: ""
})
.done(function( data ) {
		
	var obj = jQuery.parseJSON(data);
	// alert(obj.type); //last id
	   
	if (obj.status==0) 
	{
		$('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');
		$('body').modalmanager('removeLoading');
		$('body').attr('class','');
	}
	 else {
			  /**/
	  if($('#vehicle_id')){
		  var data = {
	
		id: obj.id,
	
		text: $('#vehicle_name').val()
	
		};
	
		var newOption = new Option(data.text, data.id, false, true);
	
		$('#vehicle_id').append(newOption).trigger('change');
	
		$('#customer_id').focus();
	  }
	  else loadGrid();
	  /**/

	  $('div#ajax-modal').modal('hide');
	  // load location data
	  
	  if(obj.type=='E'){
		  
		  displayNotice('page','vehicle has been updated successfully!')
	  }
	  if(obj.type=='A'){
			displayNotice('page','vehicle has been added successfully!')    
	  }
	 }
	  });
return false;
}
</script>