<?php $this->load->view("common/header"); ?>
<!-- end: HEAD -->

<!-- end: CSS REQUIRED FOR THIS PAGE ONLY -->
<!-- end: HEAD -->
<!-- start: BODY -->
<body>
<!-- start: HEADER -->
<div class="navbar navbar-inverse navbar-fixed-top"> 
  <!-- start: TOP NAVIGATION CONTAINER -->
  <div class="container">
    <div class="navbar-header"> 
      <!-- start: RESPONSIVE MENU TOGGLER -->
      <button data-target=".navbar-collapse" data-toggle="collapse" class="navbar-toggle" type="button"> <span class="clip-list-2"></span> </button>
      <!-- end: RESPONSIVE MENU TOGGLER --> 
      <!-- start: LOGO -->
      <?php $this->load->view("common/logo"); ?>
      <!-- end: LOGO --> 
    </div>
    <div class="navbar-tools"> 
      <!-- start: TOP NAVIGATION MENU -->
      <?php $this->load->view("common/notifications.php"); ?>
      <!-- end: TOP NAVIGATION MENU --> 
    </div>
  </div>
  <!-- end: TOP NAVIGATION CONTAINER --> 
</div>
<!-- end: HEADER --> 
<!-- start: MAIN CONTAINER -->
<div class="main-container">
<div class="navbar-content"> 
  <!-- start: SIDEBAR -->
  <?php $this->load->view("common/navigation"); ?>
  <!-- end: SIDEBAR --> 
</div>
<!-- start: PAGE -->
<div class="main-content">
<!-- end: SPANEL CONFIGURATION MODAL FORM -->
<div class="container">
<!-- start: PAGE HEADER -->
<div class="row">
  <div class="col-sm-12"> 
    <!-- start: PAGE TITLE & BREADCRUMB -->
    <ol class="breadcrumb">
      <li> <a href="#"> Dashboard </a> </li>
      <li> <a href=""> Loading </a> </li>
      <li class="active"> Arrange New Delivery </li>
      <li class="search-box">
        <form class="sidebar-search">
          <div class="form-group">
            <input type="text" placeholder="Start Searching...">
            <button class="submit"> <i class="clip-search-3"></i> </button>
          </div>
        </form>
      </li>
    </ol>
    <div class="page-header">
      <h1>Arrange Next New Delivery</h1>
    </div>
    <p>Please fill in the information below. The field labels marked with * are required input fields.</p>
  </div>
</div>
<!-- end: PAGE HEADER --> 
<!-- start: PAGE CONTENT 
                    <!-- start grid -->

<div class="row">
  <div class="col-md-12"> 
    <!-- start: DYNAMIC TABLE PANEL -->
    <div class="panel panel-default">
      <div class="panel-heading"> <i class="fa fa-plus"></i>  New Delivery </div>
      <div class="panel-body">
        <div class="alert alert-danger" style="display:none;">
          <button class="close" data-dismiss="alert"> × </button>
          <i class="fa fa-times-circle"></i> <strong></strong> <span class="errortxt"></span> </div>
        <div class="alert alert-success" style="display:none;">
          <button class="close" data-dismiss="alert"> × </button>
          <i class="fa fa-check-circle"></i> <strong></strong><span class="succetxt"></span> </div>
        <form role="form" class="form-horizontal" id="create_sales_form" action="#" method="post">
          <div class="col-md-12"></div>
          <!--col-md-12-->
          <div class="col-md-12">
            <div class="col-md-2">
              <div class="form-group">
                <label>Delivery Date Time *</label>
                <input id="open_datetime" name="open_datetime" type='text' class="form-control date" value="" data-bv-field="date"/>
              </div>
            </div>
           <!-- <div class="col-md-3">
              <div class="form-group">
                <label>Document Referance No *</label>
                <input type="text" class="form-control" id="card_ref_number" name="card_ref_number" readonly >
              </div>
            </div>-->
            <div class="col-md-12">
              <div class="panel panel-default">
                <div class="panel-heading" style="font-weight: 700;">Please select these before adding any product</div>
                <div class="panel-body">
                  <div class="col-sm-3">
                    <div class="form-group">
                      <label>Warehouse * </label>
                      <select id="warehouse_id" class="form-control search-select" name="warehouse_id" >
                        <?php 
$ss_warehouse_id=$this->session->userdata('ss_warehouse_id'); 
foreach ($warehouse_list as $row)
{
$sel='';
if($ss_warehouse_id==$row->id)
{
 $sel=' selected="selected"';
}
?>
                        <option <?php echo $sel; ?> value="<?php echo $row->id; ?>"> <?php echo $row->name; ?> </option>
                        <?php }?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-3" >
                    <div class="form-group">
                      <label>Driver *</label>
                      <select  id="sales_rep_id" class="form-control search-select" name="sales_rep_id" >
                        <option value="">- Please Select -</option>
                        <?php 						
						foreach ($sales_rep_list as $row)
							{?>
                        <option  value="<?php echo $row['user_id'];?>"
                                                       
                            <?php  if(isset($sale_rep_issue_id)&&$row['user_id']==$sales_rep_issue_details['sales_rep_id'])echo 'selected="selected"'?>
                            > <?php echo $row['user_first_name'];?> </option>
                        <?php }  ?>
                      </select>
                    </div>
                  </div>
                  <div class="col-sm-3">
                    <div class="form-group">
                      <label>Area  * </label>
                      <select id="area_id" class="form-control search-select" name="area_id" >
                        <option value="">- select Area - </option>
                        <?php 
																 
							foreach ($areas_list as $row)
							{
							$sel='';
							if($area_id==$row->area_id)
							{
								$sel='selected="selected"';
							}
						?>
                        <option <?php echo $sel ?> value="<?php echo $row->area_id; ?>"> <?php echo $row->area_name; ?> </option>
                        <?php }?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-2" style="margin-right:2%;">
                    <div class="form-group">
                      <label>Vehicle *</label>
                      <select  id="vehicle_id" class="form-control search-select" name="vehicle_id">
                        <option value="">-Select vehicle-</option>
                        <?php 						
						foreach ($vehicle_list as $row)
							{?>
                        <option  value="<?php echo $row['vehicle_id'];?>"><?php echo $row['vehicle_name'];?></option>
                        <?php }  ?>
                      </select>
                    </div>
                  </div>
                   <input type="hidden" name="issue_type" id="issue_type" value="1" >
                  <br>
                  
                  <!--                                                        
<div class="col-sm-3">
<div class="form-group">
<label for="issue_type">Item Type * </label>
<select id="issue_type" name="issue_type" class="form-control">
<option value="SEETTU_ORDER"> Seettu Orders</option>
<option value="FREE_ISSUE_ORDERS">  Free Issue orders </option>
</select>
 </div>
 </div>
 
 -->
                  
                  <div class="col-md-10">
                    <div class="form-group">
                      <label>Remark *</label>
                      <input type="text" class="form-control" id="remark" name="remark">
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!--col-md-8-->
          
          <div class="col-md-12">
            <div class="modal-footer" style="margin-bottom:10px;">
              <input type="submit" class="btn btn-primary" value="Next" name="add_sale" id="add_sale">
              <button id="reset" class="btn btn-danger" type="button">Reset</button>
            </div>
          </div>
        </form>
        
        <!-- end: DYNAMIC TABLE PANEL --> 
        
      </div>
    </div>
    
    <!-- end grid --> 
    
  </div>
  <!-- end: PAGE --> 
</div>
<!-- end: MAIN CONTAINER --> 
<!-- start: FOOTER -->
<div class="footer clearfix">
  <div class="footer-inner"> 2014 &copy; clip-one by cliptheme. </div>
  <div class="footer-items"> <span class="go-top"><i class="clip-chevron-up"></i></span> </div>
</div>
<!-- end: FOOTER --> 
<!-- start: RIGHT SIDEBAR --> 
<!-- end: RIGHT SIDEBAR -->
<div id="event-management" class="modal fade" tabindex="-1" data-width="760" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times; </button>
        <h4 class="modal-title">Event Management</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" data-dismiss="modal" class="btn btn-light-grey"> Close </button>
        <button type="button" class="btn btn-danger remove-event no-display"> <i class='fa fa-trash-o'></i> Delete Event </button>
        <button type='submit' class='btn btn-success save-event'> <i class='fa fa-check'></i> Save </button>
      </div>
    </div>
  </div>
</div>
<input name="tmpVal" type="hidden" id="tmpVal" value="0">
<input name="" id="type_sale" type="hidden" value="22">
<!-- start ajax model -->
<div id="ajax-modal" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" style="display: none;"></div>
<!-- end ajax model --> 

<!-- start: MAIN JAVASCRIPTS -->
<?php $this->load->view("common/footer"); ?>
<script src="<?php echo asset_url(); ?>js/jquery-ui.js" ></script> 
<script src="<?php echo asset_url(); ?>js/moment-with-locales.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootstrap-datetimepicker.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/bootbox.min.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.js"></script> 
<script type="text/javascript" src="<?php echo asset_url(); ?>js/accounting.min.js"></script> 

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

<script> clearForm();

function insertSalesData() {
    var type = 'A';
    var sale_reference_no = $('#sale_reference_no').val();
    var fields = $("#create_sales_form").serialize();
    var rowCount = $('#rowCount').val();
    if (rowCount != 0) {
        $("#add_sale").prop("disabled", true);
        $("#add_sale").val('Please wait...');
        $.post("<?php echo base_url();?>marketing_delivery_process/save_loading_master", fields).success(function(data) {
            //window.alert(fields);
            var obj = jQuery.parseJSON(data);
            if (obj.error == 1) {
                $('.alert-success').hide();
                $('.alert-danger').show();
                $(".errortxt").text(obj.disMsg);
                window.scrollTo(500, 0);
                //empty item table
            }
            if (obj.error == 0) {
                window.scrollTo(500, 0);
                $("#soTable > tbody").empty();
                displayNotice('page', 'Seettu successfully added!');
                clearForm();
                // window.location.reload();
                //empty footer details
                var last_id = obj.status;
                //sendUrl='sales2/view/'+obj.sale_id;
                location.href = "<?php echo base_url('marketing_delivery_process/pending_delivery_details');?>/" + last_id;
            }
        }).fail(function(jqXHR, textStatus, error) {
            // Handle error here
            alert("Errror : All Data required. You miss some data - " + error);
            location.reload();
        });
    } else {
        bootbox.alert('Please add terms.', function() {
            $('#add_item').focus();
        });
    }
}
//function to initiate bootstrap-datepicker
$(function() {
    //showKeys();
    var currentDate = new Date();
    $('#open_datetime').datetimepicker({
        defaultDate: new Date()
    });
    $("#vehicle_id").select2();
    $("#area_id").select2();
    $("#sales_rep_id").select2();
    $("#warehouse_id").select2();
});
$(document).ready(function() {
    $('#in_type').focus();
    $(".noEnterSubmit").on('keyup', function(e) {});
    $('#add_sale').keypress(function(event) {});
    $(window).keydown(function(event) {
        $(":focus").each(function() {
            //alert("Focused Elem_id = "+ this.id );
            focus_id = this.id;
            //	alert(focus_id);
            //	alert(event.keyCode);
            var rowCount = $('#rowCount').val();
            var fld = 'quantity_' + rowCount;
            if (focus_id == fld) {
                if (event.keyCode == 16) {
                    $('#add_item').focus();
                }
            }
            if (event.keyCode == 18) {
                setTimeout(function() {
                    //alert();
                    $("#create_sales_form").submit()
                    //do something special
                }, 1000);
                //	alert(114);
                //$('#create_sales_form').submit(function(){return true;});
                // event.preventDefault();
                // return false;
            }
            if (event.keyCode == 13) {
                event.preventDefault();
                return false;
            }
        });
    });
});
 </script>
</body>
<!-- end: BODY -->
</html>