<script type="application/javascript">
$(document).ready(function() {
	$('select').select2();
	jQuery('.datepicker2').datepicker({
			dateFormat : 'dd-mm-yy',
			changeMonth : true,
			changeYear : true
			});
    $("table.editable").on("click",".edit",function(){
        var eRow   = $(this).parents('tr');
        var eState = $(this).attr('data-state');
        if(eState == null){
            $(this).html('<span class="icon-ok-circle">');
            eState = 1;
        }
        
        eRow.find('td').each(function(){            
            if(eState == 1){
                var eContent = $(this).html(); 
//				alert(eContent);
//				alert($(this).attr('id'));
				if($(this).attr('id') == 'unitPrice'){     
                	if(eContent.indexOf('<') < 0){
                    	$(this).addClass("editing").html('<input class="tar" type="text" value="' + eContent + '" disabled/>');                    
                	}
				}else if($(this).attr('id') == 'quantitySent'){
                	if(eContent.indexOf('<') < 0){
                    	$(this).addClass("editing").html('<input class="tar" type="text" value="' + eContent + '" onBlur="calculate_amount(this)"/>');                    
                	}
				}else if($(this).attr('id') == 'amount'){
                	if(eContent.indexOf('<') < 0){
                    	$(this).addClass("editing").html('<input class="tar" type="text" value="' + accounting.formatNumber(eContent) + '" disabled/>');                    
                	}
				}
            }
            if(eState == 2){
                var eContent = $(this).find('input').val();                                
                if(eContent != null){
                    $(this).removeClass("editing").html(accounting.formatNumber(eContent,2));
                    // Here your ajax action after Save button pressed
			        var fldid = $('td:first', $(this).parents('tr')).text(); 
			        var ID = $('td:eq(1)', $(this).parents('tr')).text(); 
					var deliveryID = $("#deliveryID").val();
					var fieldname = $(this).attr('id');
                	var newContent = $(this).val();
					var urls = "<?php echo base_url()?>sotransaction/doDetails_update";
//			 		alert(fieldname);
					postData = {
						'deliveryID' : deliveryID,
						'ID' : ID,
						'fldid' : fldid,
						'fieldname' : fieldname,
						'eContent' : accounting.unformat(eContent),
					};
 					$.ajax({
  						type: "POST",
  						dataType: "json",
						url: urls,
						data: postData ,
	  					async: false,
						success: function(content){
						}
					});
					/* $.ajax({
  						type: "POST",
  						url: "menu_save?id=" + fldid,
  						success: function(){
						alert('Data has been saved...');
					}, 
		});   */    // Here your ajax action after delete confirmed
					
                }
            }
        });
        
        if(eState == 1) 
            $(this).attr('data-state','2');
        else{
            $(this).removeAttr('data-state');
            $(this).html('<span class="i-pen">');
        }
    });
});
function selectCustomer(){
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/customerSearch',
			dataType:"json",
			success: function(content){
				if(content.status == "success") {
					var items = [];
//					items.push('<option value=""><?php echo $this->lang->line('pleaseselect')?></option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].ID+'">'
//						+ content.message[i].code + ' [ '+ content.message[i].desc + ' ]</option>');
						+ content.message[i].customerName + ' [ ' + content.message[i].accountCode + ' ]</option>');
					}
//					for (var x = startrows; x < tablerows ; x++) {
 						var rowId = "#customerID";
						jQuery(rowId).empty();
						jQuery(rowId).append(items.join('</br>'));
//					}
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
					return false;
			}
		});
}
function refreshLocation(){
 $.ajax({
	type: "POST",
	url: "<?php echo base_url() ?>purchasetransaction/refreshLocation",
	success: function(data) {
	
	   var resul = eval ("(" + data + ")"); 
	   var n=resul.records.length;
	   var i=0;
	   var opt='' +
		'<option></option>';
		for (i=0;i<n;i++)
			opt=opt + '<option value="' + resul.records[i].id +'">' + resul.records[i].location + '</option>';
		$('#location').empty();
		$('#location').append(opt);
	}
   });	
}
function selectSO(obj){
//						alert($("#salesorder option:selected").val());
	var customerID = obj.value;
			postData = {
				customerID : customerID
			};
	if($("#salesorder option:selected").val() == 0){ 
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/SalesOrderSearch',
			dataType:"json",
			data: postData,
			success: function(content){
				if(content.status == "success") {
					var items = [];
					items.push('<option value=""><?php echo $this->lang->line('pleaseselect')?></option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].ID+'">'
//						+ content.message[i].code + ' [ '+ content.message[i].desc + ' ]</option>');
						+ content.message[i].OrderNo + '</option>');
					}
//					for (var x = startrows; x < tablerows ; x++) {
 						var rowId = "#salesorder";
						jQuery(rowId).empty();
						jQuery(rowId).append(items.join('</br>'));
//					}
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
						$('#currencyID').val(content.message1.currencyID).change();
						$('#exchangeRate').val(parseFloat(content.exchangeRate).toFixed(5));
					return false;
			}
		});
	}
	$("#grid_block_5").show();
	return;
}
function refreshEmployee(){
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/employeeSearch',
			dataType:"json",
			success: function(content){
				if(content.status == "success") {
					var items = [];
//					items.push('<option value=""><?php echo $this->lang->line('pleaseselect')?></option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].ID+'">'
//						+ content.message[i].code + ' [ '+ content.message[i].desc + ' ]</option>');
						+ content.message[i].employeeName + '</option>');
					}
//					for (var x = startrows; x < tablerows ; x++) {
 						var rowId = "#salesPerson";
						jQuery(rowId).empty();
						jQuery(rowId).append(items.join('</br>'));
//					}
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
					return false;
			}
		});
}
function addRow(){
	var tablerows = $("#bill").val();
    var rowToInsert = '';
    rowToInsert = "<td class='span2'><select id='itemID"+ tablerows +"' style='width: 200px;' onChange='selectDesc(this)'></select></td>";
    rowToInsertUM = "<td class='span1'><select id='unitOfMeasureID"+ tablerows +"' class='input-mini' ></select></td>";
    $("#oTable2 tbody").append(
		"<tr>" +
        "<td class='span1'><input type='text' name='lineNo' class='span12'/>"+
		rowToInsert +
        "<td class='span4'><input type='text' name='description' class='span12'/>"+
		rowToInsertUM +
        "<td class='span2 tar'><input type='text' name='unitprice' class='span12 tar' onBlur='calculate_amount1(this)' value='0'/></td>"+
        "<td class='span2 tar'><input type='text' name='qtySent' class='span12 tar' onBlur='calculate_amount1(this)' value='0'/></td>"+
        "<td class='span2 tar'><input type='text' name='amount' class='span12 tar' disabled/></td>"+
        "<td class='tac'><button class='btn btn-mini btn-danger remove' title='<?php echo $this->lang->line('cancel') ?>' onClick='cancelRow(this)'><span class='icon-remove-circle'></button>" + 
		"<button class='btn btn-mini btn-primary' title='<?php echo $this->lang->line('save') ?>' onClick='saveDetails(this)'><span class='icon-ok-circle'></button></td>"+
        "</tr>");
	$('select').select2({
		placeholder: 'Please',
	});
  	selectoption(tablerows);
  	$("#bill").val(parseInt(tablerows) + 1);
  	selectUnitmeasure(tablerows);
}
function cancelRow(obj){
    var eRow   = $(obj).parents('tr');
	var totalAmount = $("#totalAmount").val();
	var amount = parseFloat($('td:eq(6)', $(obj).parents('tr')).find("input").val());
	$("#totalAmount").val((parseFloat(totalAmount) - parseFloat(amount)).toFixed(2));
	eRow.remove();
	$("#addLine").show(); 
}
function saveDetails(obj){
    var eRow   = $(obj).parents('tr');
	var deliveryID = $("#deliveryID").val();
	var customerID = $("#customerID option:selected").val();
	var itemID = $('td:eq(1) option:selected', $(obj).parents('tr')).val();
	var lineNo = $('td:eq(0)', $(obj).parents('tr')).find("input").val();
	var description = $('td:eq(2)', $(obj).parents('tr')).find("input").val();
	var unitmeasure = $('td:eq(3) option:selected', $(obj).parents('tr')).val();
	var unitPrice = $('td:eq(4)', $(obj).parents('tr')).find("input").val();
	var qtySent = $('td:eq(5)', $(obj).parents('tr')).find("input").val();
	var amount = $('td:eq(6)', $(obj).parents('tr')).find("input").val();
	postData = {
		'ID' : deliveryID,
		'lineNo' : lineNo,
		'itemID' : itemID,
		'description' : description,
		'unitmeasure' : unitmeasure,
		'unitPrice' : unitPrice,
		'qtySent' : qtySent,
		'amount' : amount,
		};
 				$.ajax({
  					type: "POST",
  					dataType: "json",
					url: "<?php echo base_url()?>sotransaction/doDetails_save",
					data: postData ,
	  				async: false,
					success: function(content){
						if(content.status == "success") {
							eRow.remove();
    						$("#oTable2 tbody").append(
							"<tr><td style='display:none'>"+content.details.ID+"</td>" +
        					"<td>"+content.details.lineNo+"</td>" +
        					"<td>"+content.details.itemCode+"</td>" +
        					"<td>"+description+"</td>" +
        					"<td class='tac'>"+content.details.code+"</td>" +
        					"<td class='tar'>"+accounting.formatNumber(unitPrice,2)+"</td>" +
        					"<td class='tar'>"+accounting.formatNumber(qtySent,2)+"</td>" +
        					"<td class='tar'>"+accounting.formatNumber(amount,2)+"</td>" +
        					"<td class='tac'><button class='btn btn-mini btn-danger remove' title='<?php echo $this->lang->line('remove') ?>' onClick='saveRemove(this)'><span class='i-trashcan'></button></td>" +
					        "</tr>");
							alert(content.message);
//							$("#deliveryID").val(content.ID);
//							location.reload();
						}
					}
				});  
}
function selectoption(line){
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/itemSearch',
			dataType:"json",
			success: function(content){
				if(content.status == "success") {
					var items = [];
					items.push('<option value=""><?php echo $this->lang->line('pleaseselect')?></option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].ID+'">'
						+ content.message[i].itemCode + ' [ '+ content.message[i].name + ' ]</option>');
					}
//					for (var x = startrows; x < tablerows ; x++) {
 						var rowId = "#itemID"+line;
						jQuery(rowId).empty();
						jQuery(rowId).append(items.join('</br>'));
//					}
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
					return false;
			}
		});
}
function selectDesc(obj){
    var eRow   = $(this).parents('tr');
	var ID = obj.value;
	var customerID = $("#customerID option:selected").val();
	var currencyID = $("#currencyID option:selected").val();
	var effdate = $("#effdate").val();
	postData = {
		ID : ID,
		customerID : customerID,
		currencyID : currencyID,
		effdate : effdate
	};
	
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/itemSearch2',
			dataType:"json",
			data: postData,
	  				async: false,
			success: function(content){
				if(content.status == "success") {
					$('td:eq(2)', $(obj).parents('tr')).find("input").val(content.message.description);
 					$('td:eq(4)', $(obj).parents('tr')).find("input").val(accounting.formatNumber(content.price,2));
 					$('td:eq(3)', $(obj).parents('tr')).find("select").val(content.message.unitOfMeasureID).change();
// 					$('#unitOfMeasureID').val(content.message.unitOfMeasureID).change();
				}
			}
		});
}
function selectUnitmeasure(line){
		$.ajax({
			type: "POST",
        	url: '<?php echo base_url();?>sotransaction/umSearch',
			dataType:"json",
			success: function(content){
				if(content.status == "success") {
					var items = [];
//					items.push('<option value=""><?php echo $this->lang->line('pleaseselect')?></option>');
					for ( var i = 0; i < content.message.length; i++) {
					items.push('<option value="'+content.message[i].fldid+'">'
//						+ content.message[i].code + ' [ '+ content.message[i].desc + ' ]</option>');
						+ content.message[i].code + '</option>');
					}
//					for (var x = startrows; x < tablerows ; x++) {
 						var rowId = "#unitOfMeasureID"+line;
						jQuery(rowId).empty();
						jQuery(rowId).append(items.join('</br>'));
//					}
				} else {
					$("#error").html('<p>'+content.message+'</p>');
				}
					return false;
			}
		});
}
function shipMethodSelect(){
 $.ajax({
	type: "POST",
	url: "<?php echo base_url() ?>setting/refreshShippingMethod",
	success: function(data) {
	
	   var resul = eval ("(" + data + ")"); 
	   var n=resul.records.length;
	   var i=0;
	   var opt='' +
		'<option></option>';
		for (i=0;i<n;i++)
			opt=opt + '<option value="' + resul.records[i].id +'">' + resul.records[i].name + '</option>';
		$('#shippingmethod').empty();
		$('#shippingmethod').append(opt);
	}
   });		
}
function calculate_amount(obj){
	var totalAmount = accounting.unformat($("#totalAmount").val());
	var previousAmount = accounting.unformat($('td:eq(10)', $(obj).parents('tr')).find("input").val());
//	var totalShiped = parseFloat($('td:eq(6)', $(obj).parents('tr')).text()) - parseFloat($('td:eq(7)', $(obj).parents('tr')).text());
//	var qtysent = $('td:eq(7)', $(obj).parents('tr')).find("input").val();
//	if(qtysent > totalShiped){
//		alert("<?php echo $this->lang->line('message9') ?>");
//	}
	var amount = parseFloat($('td:eq(9)', $(obj).parents('tr')).find("input").val()) * parseFloat($('td:eq(7)', $(obj).parents('tr')).find("input").val());
	$('td:eq(10)', $(obj).parents('tr')).find("input").val(amount.toFixed(2));
	$("#totalAmount").val(accounting.formatNumber(parseFloat(totalAmount) + parseFloat(amount) - parseFloat(previousAmount),2));
}
function calculate_amount1(obj){
	var totalAmount = $("#totalAmount").val();
	var amount = parseFloat($('td:eq(5)', $(obj).parents('tr')).find("input").val()) * parseFloat($('td:eq(4)', $(obj).parents('tr')).find("input").val());
	$("#totalAmount").val((parseFloat(totalAmount) + parseFloat(amount)).toFixed(2));
	$('td:eq(6)', $(obj).parents('tr')).find("input").val(amount.toFixed(2));
}
function removeLine(obj){
	var totalAmount = $("#totalAmount").val();
	var amount = parseFloat($('td:eq(7)', $(obj).parents('tr')).find("input").val());
	$("#totalAmount").val((parseFloat(totalAmount) - parseFloat(amount)).toFixed(2));
    var eRow   = $(obj).parents('tr');
	eRow.remove();
}
function saveRemove(obj){
    var eRow   = $(obj).parents('tr');deliveryID
	var deliveryID = $("#deliveryID").val();
	var totalAmount = accounting.unformat($("#totalAmount").val());
	var lineAmount = accounting.unformat($('td:eq(6)', $(obj).parents('tr')).text());
	var Amount = parseFloat(totalAmount) - parseFloat(lineAmount);
	var ID = $('td:eq(0)', $(obj).parents('tr')).text();
				postData = {
					ID : ID,
					deliveryID : deliveryID,
					totalAmount : totalAmount,
					lineAmount : lineAmount
				};
				$.ajax({
					type: "POST",
        			url: '<?php echo base_url();?>sotransaction/doDetails_delete',
					dataType:"json",
					data: postData,
	  				async: false,
					success: function(content){
						if(content.status == "success") {
							alert(content.message);
							$("#totalAmount").val(parseFloat(Amount).toFixed(2));
							eRow.remove();
						}
					}
				}); 
}

function printSalesDOedit(){
	//var selDateFrom = $('#selDateFrom').val();
	var deliveryID = $("#deliveryID").val();
	window.open("<?php echo base_url();?>sotransaction/SalesDO_print/"+deliveryID);
}
</script>
<div id="content"> 
<div class="wrap">
	<div class="head">
		<div class="info">
			<h1><?php echo element('compName', $this->session->userdata('logged_in')) ?> [ 
				<?php echo element('compNo', $this->session->userdata('logged_in')) ?> ]</h1>
			<ul class="breadcrumb">
            	<li><a href='<?php echo base_url()."home" ?>'><?php echo $this->lang->line('dashboard') ?></a> <span class="divider">-</span></li>
                <li><a href='<?php echo base_url()."so/home" ?>'> <?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                <li class="active"><?php echo $this->lang->line('title') ?></li>
            </ul>
		</div>
		<div class="search">
			<form action="<?php echo base_url() ?>admin/search" method="post">
				<input name="search_text" type="text" placeholder="search..."/>                                
            	<button type="submit"><span class="i-magnifier"></span></button>
			</form>
		</div>        
                                        
	</div><!-- head --> 
<div class="content" id="grid_content_1">
	<div class="row-fluid">
		<div class="block">
		<div class="head">
			<h2><?php echo $this->lang->line('title') ?></h2>
                     <div class="side fr">
                         <button class="btn btn-link" onClick="printSalesDOedit()">Print</button>
                    </div>
		</div>
		</div>
	</div>
      	<div class="block">
      	<div class="content">
	<div class="row-fluid scRow">                            
	  <div class="span6 scCol">
		<div class="block ns" id="grid_block_1">
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span3"><?php echo $this->lang->line('customer') ?></div>
              	<div class="span9">
					<?php
							$preselcust = $headerDo->customerID;
							$options[] = $this->lang->line('pleaseselect');
							foreach($customers as $row){
								$options[$row->ID] = $row->customerName.' [ '.$row->accountCode.' ]';
							}
							$js='class="span8" id="customerID" disabled';
							echo form_dropdown('customerID', $options, $preselcust, $js);
						?>       
                	<div class="btn-group">
						<button class="btn btn-small btn-primary dropdown-toggle" data-toggle="dropdown">
                		<span class="i-arrow-down-2"></span>
                		</button>
						<ul class="dropdown-menu">
      					<!-- dropdown menu links -->
      						<li><a target="_blank" href="<?php echo base_url() ?>CustomerSetup/CustomerNew"  id="btnNewCustomer">
                    			<i class="icon-plus-sign"></i> <?php echo $this->lang->line('addNewCustomer')?></a></li>
                                <li><a href="#" onclick="selectCustomer()"><i class="icon-refresh"></i> <?php echo $this->lang->line('refreshlist')?></a></li>
						</ul>
         			</div><!-- btn group -->
            	</div>                
         	</div><!-- End Row 1 -->
                	<div class="controls-row"><!-- Row 4-->
                    	<div class="span3"><?php echo $this->lang->line('orderNo');?></div>
                   		<div class="span9">
                            	<?php 								
								$data = array(
									'name'=>'formNo', 
									'id'=>'formNo', 
									'disabled'=>'disabled', 
									'class'=>'input-medium',); 
								echo form_input($data, $headerDo->formNo); ?>
                            	<?php 								
								$data = array(
									'name'=>'deliveryToID', 
									'id'=>'deliveryToID', 
									'type'=>'hidden',); 
								echo form_input($data, $headerDo->deliverToID); ?>
                  		</div>
                 	</div><!-- End Row 4-->
                  <div class="controls-row"><!-- Row 3 -->
                    	<div class="span3"><?php echo $this->lang->line('effective_date');?></div>
                    <div class="span9">
                    	<div class="input-prepend">
                        	<span class="add-on"><i class="i-calendar"></i></span>
                            	<?php 								
								$data = array(
									'name'=>'deliveryID', 
									'id'=>'deliveryID', 
									'type'=>'hidden',); 
								echo form_input($data, $headerDo->ID); ?>
                            	<?php 								
								$data = array(
									'type'=>'text',
									'name'=>'effdate', 
									'id'=>'effdate', 
									'class'=>'input-medium datepicker2',); 
								echo form_input($data, date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($headerDo->deliveryOrderDate))); ?>
                        </div>                                                                                                
                     </div>
                    </div><!-- End Row 3 -->
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span3"><?php echo $this->lang->line('location') ?></div>
              	<div class="span9">
					<?php
							$presellocation = $headerDo->locationID;
							$options = '';
							$options[] = $this->lang->line('pleaseselect');
							foreach($location as $row){
								$options[$row->fldid] = $row->city . '=>' . $row->address;
							}
							$js='class="span8" id="location"';
							echo form_dropdown('location', $options, $presellocation, $js);
						?>       
                	<div class="btn-group">
						<button class="btn btn-small btn-primary dropdown-toggle" data-toggle="dropdown">
                		<span class="i-arrow-down-2"></span>
                		</button>
						<ul class="dropdown-menu">
      					<!-- dropdown menu links -->
      						<li><a target="_blank" href="<?php echo base_url() ?>setting/location"  id="btnLocation">
                    			<i class="icon-plus-sign"></i> <?php echo $this->lang->line('addLocation')?></a></li>
                                <li><a href="#"  onclick="refreshLocation()"><i class="icon-refresh"></i> <?php echo $this->lang->line('refreshlist')?></a></li>
						</ul>
         			</div><!-- btn group -->
            	</div>                
         	</div><!-- End Row 1 -->
        </div><!--grid_block_1 -->
      </div><!--span6 scCol -->
	  <div class="span6 scCol">
		<div class="block ns" id="grid_block_1">
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span3"><?php echo $this->lang->line('salesorder') ?></div>
              	<div class="span9">
					<?php
							$preselso = $headerDo->salesOrderID;
							$options = '';
							$options[] = $this->lang->line('pleaseselect');
							foreach($salesorder as $row){
								$options[$row->ID] = $row->OrderNo;
							}
							$js='class="span8" id="salesorder" disabled';
							echo form_dropdown('salesorder', $options, $preselso, $js);
						?>       
            	</div>                
         	</div><!-- End Row 1 -->
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span3"><?php echo $this->lang->line('currency') ?></div>
              	<div class="span9">
					<?php
							$preselcurrency = $headerDo->currencyID;
							$options[] = $this->lang->line('pleaseselect');
							foreach($currency as $row){
								$options[$row->fldid] = $row->fldcurr_code.' [ '.$row->fldcurr_desc.' ]';
							}
							$js='class="span8" id="currencyID" disabled';
							echo form_dropdown('currencyID', $options, $preselcurrency, $js);
						?>       
            	</div>                
         	</div><!-- End Row 1 -->
                	<div class="controls-row"><!-- Row 4-->
                    	<div class="span3"><?php echo form_label($this->lang->line('exchangerate'),'exchangeRate');?></div>
                   		<div class="span9">
                            	<?php 								
								$data = array(
									'name'=>'exchangeRate', 
									'id'=>'exchangeRate', 
									'class'=>'input-medium tar',); 
								echo form_input($data, number_format($headerDo->exchangeRate,2)); ?>
                  		</div>
                 	</div><!-- End Row 4-->
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span3"><?php echo $this->lang->line('salesperson') ?></div>
              	<div class="span9">
					<?php
							$preselperson = $headerDo->employeeID;
							$options = '';
							$options[] = $this->lang->line('pleaseselect');
							foreach($employees as $row){
								$options[$row->ID] = $row->employeeName;
							}
							$js='class="span8" id="salesPerson"';
							echo form_dropdown('salesPerson', $options, $preselperson, $js);
						?>       
                	<div class="btn-group">
						<button class="btn btn-small btn-primary dropdown-toggle" data-toggle="dropdown">
                		<span class="i-arrow-down-2"></span>
                		</button>
						<ul class="dropdown-menu">
      					<!-- dropdown menu links -->
      						<li><a target="_blank" href="<?php echo base_url() ?>employeeSetup/EmployeeNew"  id="btnNewEmpoyee">
                    			<i class="icon-plus-sign"></i> <?php echo $this->lang->line('addNewEmployee')?></a></li>
                                <li><a href="#" onclick="refreshEmployee()" id="btnNewEmpoyee"><i class="icon-refresh"></i> <?php echo $this->lang->line('refreshlist')?></a></li>
						</ul>
         			</div><!-- btn group -->
            	</div>                
         	</div><!-- End Row 1 -->
        </div><!--grid_block_1 -->
      </div><!--span6 scCol -->
    </div><!--row-fluid scRow -->
	<div class="row-fluid scRow">                            
	  <div class="span12 scCol">
		<div class="block ns" id="grid_block_3">
                  <div class="controls-row"><!-- Row 5 -->
                  	<div class="span2"><?php echo $this->lang->line('shipto')?></div>
                   	<div class="span10">
						<?php
							$data = array(
									'name'=>'address', 
									'id'=>'address', 
									'class'=>'span12',);
							$js = 'style="height:100px"'; 
							echo form_textarea($data, $headerDo->toAddress, $js); ?>                       
                    </div>                        
                  </div><!-- End Row 5-->
                	<div class="controls-row"><!-- Row 4-->
                    	<div class="span2"><?php echo form_label($this->lang->line('memo'),'memo');?></div>
                   		<div class="span10">
                            	<?php 								
								$data = array(
									'name'=>'memo', 
									'id'=>'memo', 
									'class'=>'span12'); 
								echo form_input($data, $headerDo->memo); ?>
                            	<?php 								
								$data = array(
									'name'=>'bill', 
									'id'=>'bill', 
									'value'=> 1,
									'type' => 'hidden'); 
								echo form_input($data); ?>
                  		</div>
                 	</div><!-- End Row 4-->
        </div><!--grid_block_1 -->
      </div><!--span12 scCol -->
    </div><!--row-fluid scRow -->
    </div><!--row-fluid scRow -->
    </div><!--row-fluid scRow -->
	<div class="row-fluid scRow">                            
	  <div class="span12 scCol">
		<div class="block" id="grid_block_4">
	       <div class="head">
           	<h2><?php echo $this->lang->line('outstanding')?></h2>
                    	<ul class="buttons">
                            <li><a href="#" class="block_toggle" title="Close"><span class="i-arrow-down-3"></span></a></li>
                        </ul>                                        
          </div><!-- head -->
          <div class="content np">
   			<table id="oTable" cellpadding="0" cellspacing="0" width="100%" class="editable">
         		<thead>
             	<tr>
                	<th style='display:none'></th>
                	<th style='display:none'></th>
            		<th>#</th>
            		<th><?php echo $this->lang->line('itemCode')?></th>
            		<th><?php echo $this->lang->line('description')?></th>
            		<th class="tac"><?php echo $this->lang->line('daterequired')?></th>
            		<th class="tac"><?php echo $this->lang->line('um')?></th>
            		<th class="tar"><?php echo $this->lang->line('unitPrice')?></th>
            		<th class="tar"><?php echo $this->lang->line('qtyOrd')?></th>
            		<th class="tar"><?php echo $this->lang->line('qtySend')?></th>
            		<th class="tar"><?php echo $this->lang->line('amount')?></th>
            		<th class="tac"><?php echo $this->lang->line('action')?></th>
              	</tr>
        		</thead>
                <tbody>
			<?php 
				if($datatbls1){
				foreach($datatbls1 as $datatbl):
				?>
            	<tr>
                	<td id="doID" style="display:none" ><?php echo $datatbl->doID; ?></td>
                	<td id="soID" style="display:none" ><?php echo $datatbl->ID; ?></td>
                	<td><?php echo $datatbl->lineNo?></td>
                	<td><?php echo $datatbl->itemCode?></td>
                    <td><?php echo $datatbl->description ?></td>
                	<td id="requiredDate" class="tac"><?php echo date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($datatbl->requiredDate)) ?></td>
                	<td id="code" class="tac"><?php echo $datatbl->code?></td>
                	<td id="unitPrice" class="tar"><?php echo number_format(($datatbl->price != 0)? $datatbl->price : $datatbl->unitPrice ,2); ?></td>
                	<td id="quantityOrder" class="tar"><?php echo number_format($datatbl->quantityOrder,2); ?></td>
                	<td id="quantitySent" class="tar"><?php echo number_format($datatbl->quantitySent,2); ?></td>
                	<td id="amount" class="tar"><?php echo number_format($datatbl->shipAmount,2); ?></td>
 					<td id="action" class="tac"><?php
							$js = 'class="btn btn-mini btn-primary edit" title="'.$this->lang->line('edit').'"  onClick=""';
							echo form_button('edit','<span class="i-pen">',$js);
						?></td>
               </tr>
            <?php endforeach; }?>
                </tbody>
     		</table>
          </div><!--content -->
        </div><!--grid_block_4 -->
      </div><!--span6 scCol -->
    </div><!--row-fluid scRow -->
	<div class="row-fluid scRow">                            
	  <div class="span12 scCol">
		<div class="block" id="grid_block_5">
	       <div class="head">
           	<h2><?php echo $this->lang->line('withoutso')?></h2>
                    	<ul class="buttons">
                            <li><a href="#" class="block_toggle" title="Close"><span class="i-arrow-down-3"></span></a></li>
                        </ul>                                        
          </div><!-- head -->
          <div class="content np">
   			<table id="oTable2" cellpadding="0" cellspacing="0" width="100%">
         		<thead>
             	<tr>
                	<td style="display:none" ></td>
            		<th>#</th>
            		<th><?php echo $this->lang->line('itemCode')?></th>
            		<th><?php echo $this->lang->line('description')?></th>
            		<th><?php echo $this->lang->line('um')?></th>
            		<th class="tar"><?php echo $this->lang->line('unitPrice')?></th>
            		<th class="tar"><?php echo $this->lang->line('qtySend')?></th>
            		<th class="tar"><?php echo $this->lang->line('amount')?></th>
            		<th class="tac"><?php echo $this->lang->line('action')?></th>
              	</tr>
        		</thead>
                <tbody>
			<?php $bil = 0; 
				if($datatbls){
				foreach($datatbls as $datatbl):
				$bil++?>
            	<tr>
                	<td style="display:none" ><?php echo $datatbl->ID; ?></td>
                	<td><?php echo $datatbl->lineNo?></td>
                	<td><?php echo $datatbl->itemCode?></td>
                    <td><?php echo $datatbl->description ?></td>
                	<td class="tac"><?php echo $datatbl->code?></td>
                	<td class="tar"><?php echo number_format($datatbl->unitPrice,2); ?></td>
                	<td class="tar"><?php echo number_format($datatbl->quantitySent,2); ?></td>
                	<td class="tar"><?php echo number_format($datatbl->amount,2); ?></td>
 					<td class="tac"><?php
							$js = 'class="btn btn-mini btn-danger remove" title="'.$this->lang->line('delete').'"  onClick="saveRemove(this)"';
							echo form_button('remove','<span class="i-trashcan">',$js);
						?></td>
               </tr>
            <?php endforeach; }?>
                </tbody>
     		</table>
          </div><!--content -->
            <div class="footer">
            	<div class="side fl">
                	<div class="btn-group">
            				<button class="btn btn-small btn-primary" onClick="addRow()" id="addLine">
                				<span class="i-plus"></span> <?php echo $this->lang->line('addnewline')?></button>
                    </div>
                </div>
            </div>                                    
        </div><!--grid_block_5 -->
      </div><!--span6 scCol -->
    </div><!--row-fluid scRow -->
	<div class="row-fluid scRow">                            
	  <div class="span12 scCol">
		<div class="block" id="grid_block_3">
            	<div class="head">
                	<h2><?php echo $this->lang->line('memoandshipto') ?></h2>
                    	<ul class="buttons">
                            <li><a href="#" class="block_toggle" title="Close"><span class="i-arrow-down-3"></span></a></li>
                        </ul>                                        
                </div>
          <div class="content">
			<div class="controls-row"> <!-- row 1 -->
            	<div class="span2"><?php echo $this->lang->line('shipMethod') ?></div>
              	<div class="span4">
					<?php
							$preselshipmethod = $headerDo->shippingMethodID;
							$options = '';
							$options[] = $this->lang->line('pleaseselect');
							foreach($shippingMethod as $row){
								$options[$row->ID] = $row->code . ' [ ' . $row->name . ' ]';
							}
							$js='class="span8" id="shippingmethod"';
							echo form_dropdown('shippingmethod', $options, $preselshipmethod, $js);
						?>       
                	<div class="btn-group">
						<button class="btn btn-small btn-primary dropdown-toggle" data-toggle="dropdown">
                		<span class="i-arrow-down-2"></span>
                		</button>
						<ul class="dropdown-menu">
      					<!-- dropdown menu links -->
      						<li><a target="_blank" href="<?php echo base_url() ?>setting/masterCodeSetup"  id="btnNewShipMethod">
                    			<i class="icon-plus-sign"></i> <?php echo $this->lang->line('newShipMethod')?></a></li>
                                <li><a href="#" onclick="shipMethodSelect()"><i class="icon-refresh"></i> <?php echo $this->lang->line('refreshlist')?></a></li>
						</ul>
         			</div><!-- btn group -->
            	</div>                
                    	<div class="span2 tar"><?php echo $this->lang->line('totalAmount');?></div>
                   		<div class="span4">
                            	<?php 								
								$data = array(
									'name'=>'totalAmount', 
									'id'=>'totalAmount', 
									'disabled'=>'disabled', 
									'class'=>'span12 tar',); 
								echo form_input($data, number_format($headerDo->totalAmount, 2)); ?>
                  		</div>
                 	</div><!-- End Row 4-->
          </div><!--content -->
        </div><!--grid_block_1 -->
      </div><!--span12 scCol -->
    </div><!--row-fluid scRow -->
</div><!--grid_content_1 -->
</div><!--wrap -->
</div><!--content -->
