<style type="text/css">
    .amount{
        text-align: right !important;
    }
    
    .quantity {
        text-align: center !important;
    }
.input-prepend span, input-prepend button{
	height:18px;
	padding:3px;
	}
#content .wrap #grid_content_1 .row-fluid.scRow .row-fluid.scRow .span12.scCol #grid_block_5 .content.np #listDetails tbody #trInfos td .row-fluid .controls-row .span3 {
	font-size: 11px;
	color: #000;
	font-weight: bold;
}
.test {
	font-size: 10px;
}
.span3 {
	font-size: 10px;
}
tbody td {
	font-size:11px;
	}
#content .wrap #grid_content_1 .row-fluid.scRow .row-fluid.scRow .span12.scCol #grid_block_6 .content.np #listpmt tbody #trInfospmt td .row-fluid .controls-row .span3 {
	font-weight: bold;
}
</style>

<script>
    
    $(document).ready(function(){
      $('select').select2();
            jQuery('.datepicker2').datepicker({
    dateFormat : 'dd-mm-yy',
            changeMonth : true,
            changeYear : true
    });
    });
     window.onbeforeunload = function (e) {
        if (accounting.unformat( $('#outofbalance').val() ) !== 0 ){
  var message = "The out of balance is different of zero, Confirm leave ",
  e = e || window.event;
  // For IE and Firefox
  if (e) {
    e.returnValue = message;
  }

  // For Safari
  return message;
        }
};
    
				  function calculAmount(){
					var j_itemTaxAmount=accounting.unformat($("#itemTax").val())*accounting.unformat($("#amountExcludedTax").val())/100;
					$("#taxAmount").val(accounting.formatNumber(j_itemTaxAmount,2));
					$("#amountIT").val(accounting.formatNumber(j_itemTaxAmount + accounting.unformat($("#amountExcludedTax").val()),2));
					
				}
				
			
				   function EndEdit(me){ 
					 
					 var dID = $(me).attr("data-itemId");
					 	 $(''+
					 '<tr>' +
                                             '<td class="span1">' + $(me).parent().parent().find("td").eq(0).html() + '</td>' +
						'<td>' +  $("#itemcode").val() + '</td>'+
                        '<td>' + $("#itemname").val() + '</td>'+
                        '<td>' + $("#itemdes").val() + '</td>'+
                        '<td class="amount">' + accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                        '<td>' + $("#itemqte").val() + '</td>'+
                        '<td class="amount">' + $("#itemAmountET").val() + '</td>'+
                        '<td class="tac">' + $("#itemTax").val() + ' | ' + $("#displayTaxCode").text()  + '</td>'+
                        '<td class="amount">' + $("#itemTaxAmount").val() + '</td>'+
                        '<td class="amount">' + $("#itemAmountIT").val() + '</td>'+
                         '<td>'+
						'<button data-taxcode="' + $(me).attr("data-taxcode") + '" data-taxrate="' + $(me).attr("data-taxrate") +'"  onclick="editRow(this)" data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") +'" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>' +
                         ' <button my-id="' + dID + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>'+
						'</td>'+
                    '</tr>'
					  ).insertBefore( "#trInfos" );
					  delRowInvoice(me);
					   getTotal ();
					 }
					 
				  function cancelEdit(me){
					 
					 var dID = $(me).attr("data-itemId");
					 	 $(''+
					 '<tr>' +
						'<td>' +  $("#itemcode").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#itemname").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#itemdes").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemunitprice").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#itemqte").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemAmountET").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#itemTax").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemTaxAmount").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemAmountIT").attr("data-previewvalue") + '</td>'+
                        '<td>'+
						'<button data-taxcode="' + $(me).attr("data-taxcode") + '" data-taxrate="' + $(me).attr("data-taxrate") +'"  onclick="editRow(this)" data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") +'" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>' +
                         ' <button my-id="' + dID + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan></i></button>'+
						'</td>'+
                    '</tr>'
					  ).insertBefore( "#trInfos" );
					  delRowInvoice(me);
					   getTotal ();
					 }
					 
				function getTotal (){
					
						 var n =$("#listDetails > tbody > tr").length - 2;
						 var totalAmount =0;
						 var impot = 0;
						 var total = 0;
						 var i = 0;
						 for (i=0; i<=n; i++) {
							 
								totalAmount= totalAmount + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(3)').text())*1; 
								impot= impot + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(5)').text())*1; 
								total= total + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(6)').text())*1; 
								
						 }
					
						
						 $("#totalallocated").val(accounting.formatNumber(totalAmount,2));
					
						$("#totaltaxamount").val(accounting.formatNumber(impot,2));
					
						$("#totalpaid").val(accounting.formatNumber(total,2));
                                                calculateOutOfBallance();
					}
	     
		
			  function delRowInvoice(me){
				  var td=me.parentNode;
				  var tr=td.parentNode;
				  var tBody=tr.parentNode;
				  tBody.removeChild(tr);
				  getTotal ();
			  }
			  
			  function msg(n,type, message){
	$("#msg_div" + n +" p").html(message);
	$("#msg_div").attr("class","alert " + type);
}
			  
				  function editRowPayment (me){
                                       var  tr = $(me).parent().parent();
                                        if (!$("#pmtAccount").length) {
					 $(tr).replaceWith( '<tr><td class="span1">'+ $(me).parent().parent().find("td").eq(0).html()  +'</td>' +
							'<td class="span2" ><select data-lineNo="' + $(me).parent().parent().find("td").eq(0).html() + '" data-previewvalue="' + $(me).parent().parent().find("td").eq(1).html() + '" name="pmtAccount" id="pmtAccount" class= "span12 validate[required]"><option></option>' +
									 <?php
				if($pmtAccount){
				 foreach($pmtAccount as $row){
					 ?>
                     '<option  value="<?php echo $row->ID; ?>"><?php echo substr($row->acctCode,0,4).'-'.substr($row->acctCode,4,3).'-'.substr($row->acctCode,7)." | "; echo str_replace(array("\n", "\r","'"), " ",$row->acctName, $count); ?></option>'+
			    <?php }} ?>
							 '</select></td>'+
													'<td class="span4"><input data-previewvalue="' + $(me).parent().parent().find("td").eq(2).html() + '"  id="pmtdesc" name="pmtdesc"  type="text" class="span12 validate[required]" placeholder="Description" value="' + $(me).parent().parent().find("td").eq(2).html() + '"></td>'+
													'<td class="span1"><input data-previewvalue="' + $(me).parent().parent().find("td").eq(3).html() + '" class="span12" id="amountExcludedTax" onkeyup="calculAmount()" name="amountExcludedTax" value="' + $(me).parent().parent().find("td").eq(3).html() + '" class="input-mini validate[required, custom[number]]" type="text" placeholder="Amount"></td>'+
													'<td class="span1"><div  class="span12 input-prepend"><input style="max-width: 22px;" data-previewvalue= "' + $(me).attr("data-taxcode") + ' | ' + $(me).attr("data-taxpercentage") + '"  value="' + $(me).attr("data-taxpercentage") + '" data-taxid="' + $(me).attr("data-taxid") + '" id="itemTax" disabled onkeyup="calculAmount()" onblur="calculAmount()" name="itemTax" class="validate[required, custom[number]]" type="text" placeholder="Tax(%)"><span id="displayTaxCode" style="margin-top:0;" onclick="taxPopup ()"  class="btn add-on">' + $(me).attr("data-taxcode") + '</span></div></td></td>'+
										'<td class="span1"> <input data-previewvalue="' + $(me).parent().parent().find("td").eq(5).html() + '" id="taxAmount" value="' + $(me).parent().parent().find("td").eq(5).html() + '"  name="taxAmount" class="span12" type="text" placeholder="Amount"></td>'+
													'<td class="span1"><input data-previewvalue="' + $(me).parent().parent().find("td").eq(6).html() + '" onkeydown="return false;" id="amountIT" value="' + $(me).parent().parent().find("td").eq(6).html() + '"name="amountIT" class="span12" type="text" placeholder="Amount (Exclude Tax)"></td>'+
						'<td class="span1">'+
						 	'<button data-myid="' + $(me).attr("data-myid") + '" data-accid="' + $(me).attr("data-accid") + '" data-taxpercentage = "' + $(me).attr("data-taxpercentage") + '" data-taxcode = "' + $(me).attr("data-taxcode") + '" data-taxid="' + $(me).attr("data-taxid") + '" onclick = "updatePdetails(this)" class="btn-icon btn-mini btn-success-form" type="button"><i class="i-checkmark-3"></i></button>'+
						 	' <button data-myid="' + $(me).attr("data-myid") + '" data-accid="' + $(me).attr("data-accid") + '" data-taxpercentage = "' + $(me).attr("data-taxpercentage") + '" data-taxcode = "' + $(me).attr("data-taxcode") + '" data-taxid="' + $(me).attr("data-taxid") + '" onclick="delCancelEditpmt(this)" id="btnCancelpmt" class="btn-icon btn-mini btn-danger-form" type="button"><i class="i-cross"></i></button>'+
						'</td>'+
                    '</tr>'
					  );
					
					$("#pmtAccount").val($(me).attr("data-accid"));
                                        $("#pmtAccount").select2();
					}else{
						msg (2,"alert","Please, do save the current details before adding new one");
						}
				 }	
				 
				 function delCancelEditpmt (me){
                                  var  tr = $(me).parent().parent();
					 $("#pmtAccount").val($(me).attr("data-accid"));
					 	$(tr).replaceWith( '<tr>' +
                                                 '<td>' +  $("#pmtAccount").attr("data-lineNo") + '</td>'+
						'<td>' +  $("#pmtAccount").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#pmtdesc").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#amountExcludedTax").attr("data-previewvalue") + '</td>'+
                        '<td>' + $("#itemTax").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#taxAmount").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#amountIT").attr("data-previewvalue") + '</td>'+
                        '<td>'+
						'<button onclick="editRowPayment(this)" data-taxpercentage = "' + $(me).attr("data-taxpercentage") + '" data-taxcode = "' + $(me).attr("data-taxcode") + '" data-myid="' + $(me).attr("data-myid") + '" data-accid="' + $(me).attr("data-accid") + '" data-taxid="' + $(me).attr("data-taxid") + '" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>' +
                         ' <button onclick="deleteRowPdetails(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>'+
						'</td>'+
                    '</tr>'
					  );
					 }	
					 
					 
					 function updatePdetails(me) {
                                              var  tr = $(me).parent().parent();
						 $.ajax({
							  type: "POST",
							  data: {
                                                                        rowID  : $(me).attr("data-myid"),
									accountID : $("#pmtAccount").val(),
									amountIncludedTax : accounting.unformat($("#amountIT").val()),
									amountExcludedTax :  accounting.unformat($("#amountExcludedTax").val()),
									taxID: $("#itemTax").attr("data-taxid"),
                                                                         taxRate: $("#itemTax").val(),    
									taxAmount : accounting.unformat($("#taxAmount").val()),
									description : $("#pmtdesc").val(),
									
								  },
							  url: "<?php echo base_url() ?>gltransaction/updOtherRecieveRow",
							  success: function(data) {
									 msg (2,"alert alert-success","Details successfully updated");
									 $(tr).replaceWith( '<tr>' +
                                                                                       '<td>' +  $("#pmtAccount").attr("data-lineNo") + '</td>'+
											'<td>' +  $("#pmtAccount option:selected").text() + '</td>'+
											'<td>' + $("#pmtdesc").val() + '</td>'+
											'<td class="amount">' + accounting.formatNumber($("#amountExcludedTax").val(),2) + '</td>'+
											'<td>' + $("#displayTaxCode").text() + " | " + $("#itemTax").val()  + '</td>'+
											'<td class="amount">' + $("#taxAmount").val() + '</td>'+
											'<td class="amount">' + $("#amountIT").val() + '</td>'+
											'<td>'+
											'<button onclick="editRowPayment(this)" data-myid="' + $(me).attr("data-myid") + '" data-accid="' + $("#pmtAccount").val() + '" data-taxcode = "' + $("#displayTaxCode").text() + '" data-taxpercentage = "' + $("#itemTax").val() + '" data-taxid="' + $("#itemTax").val() + '" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>' +
											 ' <button data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i</button>'+
											'</td>'+
										'</tr>'
										  );
									   getTotal();
									 } });
								 
						}
					
				function  deleteRowPdetails(me){
							$('#popupModal').modal('show');
						  $("#_popupTitle").html("Confirm delete");
						  $("#_popupContent").html("Your about to delete definively this row. <br/> Click on ok to confirm");
						  
						  $('#_popupFooter').empty();
							 $('#_popupFooter').append('<button class="btn-form btn-success-form" id="detButton">Ok</button>' +
						  ' <button class="btn-form btn-danger-form" id="canb">Cancel</button>');
						  $("#_popupTitle").html("Confirm delete");
						  $( "#canb" ).click(function() {
							  $('#popupModal').modal('hide');
						  });
						  
						     $( "#detButton" ).click(function() {
							  $('#popupModal').modal('hide');
							   $.ajax({
					 				 type: "POST",
								  data: {
										rowID :$(me).attr("data-myid")					  
						  				},
					 			 url: "<?php echo base_url() ?>gltransaction/deleteOtherReceiveRow",
							  	 success: function(data) {
										 msg (2,"alert alert-success","Details successfully deleted");
							 			 delRowInvoice(me);
							             getTotal();
						 
						  			}} ); 
							 });
					}
                function addnewrow(){
                     n = $("#trInfospmt").attr("data-currentRow")*1 + 1;
                     if (!$("#accountID").length && !$("#pmtAccount").length) {
                     $(''+
                         '<tr><td>' + n +'</td>'+
                            '<td class="span2" ><select data-lineNo="' + n + '" data-previewvalue="' + n + '" name="accountID" id="accountID" class= "span12 validate[required]"><option></option>' +
									 <?php
				if($pmtAccount){
				 foreach($pmtAccount as $row){
					 ?>
                     '<option  value="<?php echo $row->ID; ?>"><?php echo $row->acctCode." | "; echo str_replace(array("\n", "\r","'"), " ",$row->acctName, $count); ?></option>'+
			    <?php }} ?>
							 '</select></td>'+
                    '<td class="span4"><input  id="itemDesc" name="itemDesc"  type="text" class="span12 validate[required]" placeholder="Description"></td>'+
                    '<td class="span1"><input id="amountExcludedTax" onkeyup="calculAmount()" name="amountExcludedTax" class="span12 validate[required, custom[number]] amount" type="text" placeholder="Amount"></td>'+
                     '<td class="span1"> <div  class="input-prepend"><input style="width:22px;" data-taxid="" id="itemTax" disabled onkeyup="calculAmount()" onchange="calculAmount()" name="itemTax" class="span6 validate[required, custom[number]]" type="text" placeholder="Tax(%)"><span onclick="taxPopup ()" style="margin-top:0;" id="displayTaxCode"  class="btn add-on">....</span></div></td>' +
                                                                            '<td class="span1"><input id="taxAmount" disabled name="taxAmount" class="span12 amount" type="text" placeholder="Amount"></td>'+
                                                                            '<td class="span1"><input disabled  id="amountIT" name="amountIT" class="span12 amount" type="text" placeholder="Amount (Exclude Tax)"></td>'+
                    '<td class="span1">'+
                            '<button onclick = "savenewrow(this)" class="btn-icon btn-mini btn-success-form" type="button"><i class="i-checkmark-3"></i></button>'+
                            ' <button onclick="delRowInvoice(this)" id="btnCancel" class="btn-icon btn-mini btn-danger-form" type="button"><i class="i-cross"></i></button>'+
                    '</td>'+
'</tr>').insertBefore( "#trInfospmt" );
        $('#accountID').select2();
         
            }else{
                    msg (2,"alert","Please, do save the current details before adding new one");
                    }
                }
		
        
        function savenewrow(me){
        $(me).attr("disabled","disabled");
             $.ajax({
                    type: "POST",
                    data: {
                                  otherPaymentID : $("#masterID").val(),
                                    
                                    lineNo : $("#trInfospmt").attr("data-currentRow")*1+1,
                                    amountIncludedTax : accounting.unformat($("#amountIT").val()),
                                    accountID : $("#accountID").val(),
                                    description: $("#itemDesc").val(),
                                    amountExcludedTax: accounting.unformat($("#amountExcludedTax").val()),
                                    taxAmount : accounting.unformat($("#taxAmount").val()),
                                     taxID: $("#itemTax").attr("data-taxid"),
                                    taxRate: $("#itemTax").val() 

                            },
                    url: "<?php echo base_url() ?>gltransaction/saveotherReceiveDetailOnly",
                    success: function(data) {
                     msg (1,"alert alert-success","Details successfully saved");
                      var resul = eval ("(" + data + ")"); 
                      $("#trInfospmt").attr("data-currentRow", $("#trInfospmt").attr("data-currentRow")*1+1);
                    $(''+
                        '<tr><td>' +  $("#trInfospmt").attr("data-currentRow") +'</td>'+
                              '<td>' +  $("#accountID option:selected").text() + '</td>'+
                              '<td>' + $("#itemDesc").val() + '</td>'+
                              '<td class="amount">' + accounting.formatNumber($("#amountExcludedTax").val(),2) + '</td>'+
                              '<td class="tac">' +$("#itemTax").val() + ' | ' + $("#displayTaxCode").text() + '</td>'+
                              '<td class="amount">' + accounting.formatNumber($("#taxAmount").val(),2) + '</td>'+
                              '<td class="amount">' + accounting.formatNumber($("#amountIT").val(),2) + '</td>'+
                              '<td>'+
                            '<button onclick="editRowPayment(this)" data-myid="' + resul.detailID + '" data-accid="' + $("#pmtAccount").val() + '" data-taxcode = "' + $("#displayTaxCode").text() + '" data-taxpercentage = "' + $("#itemTax").val() + '" data-taxid="' + $("#itemTax").val() + '" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>' +
                             ' <button data-myid="' + resul.detailID + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i</button>'+
                            '</td>'+
                    '</tr>'
                ).insertBefore( "#trInfospmt" );
                    $("#btnCancel").trigger("click");
                    getTotal();
                    msg (2,"alert alert-success","Details successfully saved");
               }
             }); //end ajax
        }
        
         function taxPopup () {
        $('#popupModal').modal('show');
        $("#_popupTitle").html("Purchase Invoice");
        $("#_popupContent").html('' +
          '<label>Select a tax</label>' +
          '<select style="width:100%;" onchange="calculAmount()" name="itemTaxPopup" id="itemTaxPopup"  class= "validate[required]">' +
<?php
if ($taxmaster) {
    foreach ($taxmaster as $row2) {
        ?>
                             '<option data-taxcode="<?php echo $row2->code ?>" value="<?php echo $row2->ID; ?>" data-tax="' + <?php echo $row2->taxPercentage; ?> + '">' + 
                                                 '<?php echo $row2->code . " | " . $row2->taxPercentage . " | ";
        echo str_replace(array("\n", "\r","'"), " ", $row2->name, $count); ?></option>'+
    <?php }
} ?>
                                                         '</select>');
                  $("#itemTaxPopup").select2();
	
        $('#_popupFooter').empty();
           $('#_popupFooter').append('<button class="btn-form btn-success-form" id="confButton">Ok</button>' +
        ' <button class="btn-form btn-danger-form" id="canb">Cancel</button>');
        $("#_popupTitle").html("Tax Master");
        $( "#canb" ).click(function() {
                $('#popupModal').modal('hide');
        });
        $( "#confButton" ).click(function() {
                $('#popupModal').modal('hide');
                 $("#itemTax").attr("data-taxid",$("#itemTaxPopup").val() );
                 $("#itemTax").val ($("#itemTaxPopup option:selected").attr("data-tax"));
                 $("#displayTaxCode").html($("#itemTaxPopup option:selected").attr("data-taxcode"));
                 calculAmount();
        });
	
}
            
            $(document).ready(function(){
                calculateOutOfBallance();
});
            
             function calculateOutOfBallance(){
               $("#outofbalance").val(accounting.formatNumber(accounting.unformat($("#amountpaid").val())-accounting.unformat($("#totalpaid").val()),2));
            }
            
                 function updateMaster(){
                 $.ajax({
                type: "POST",
                data: {
                            masterID  : $("#masterID").val(),
                            amountPaid : accounting.unformat($("#amountpaid").val()),
                            refNo : $("#refNo").val(),
                            project : $("#project").val(),
                            date : $("#createDate").val(),
                            receiveFrom : $("#receiveFrom").val(),
                             memo : $("#memo").val(),
                              formNo : $("#formNo").val()

                      },
                url: "<?php echo base_url() ?>gltransaction/updatepayotherreceiveMaster",
                success: function(data) {
                                //1 success
                                // 2 error
                                // 3 warning 
                                if (data == 1){
                            alertbox("Update success ...", 1);
                           calculateOutOfBallance();
                       }else{
                           alertbox("Update fail ...", 1); 
                       }
                             } });
            }
        
            </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()."gl/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">
          
     <?php
  $memo ="";
   if ($otherPay){	 
	 foreach($otherPay as $row){
		 $memo = $row->memo;
	?> 
   <div class="block">
         <div class="head">
     <h2><strong><?php echo $this->lang->line('title') ?></strong></h2>
</div><!-- head -->
        <div class="content">
            
	<div class="row-fluid scRow">                            
	  <div class="span4 scCol">
		<div class="block ns" id="grid_block_1">
                    <input type="hidden" id="masterID" value="<?php echo $row->ID; ?>" />
             
                   <div class="controls-row">
                     
                                        <div class="span4"><?php echo $this->lang->line('formno') ?></div>
                                        <div class="span4">
                                            <input class="span12 validate[required]" id="formNo" name="formNo" value='<?php echo $row->frmNo; ?>' style="color:red;"   type="text" placeholder="Form number ...">
                                        </div>
                                        <div class="span4">
                                            <input class="span11" type="text" value="<?php echo str_pad($row->serialNo, 8, '0', STR_PAD_LEFT);  ?>" placeholder="Serial" disabled="disabled">
                                        </div>
                                    </div> <!-- row -->
            
            
            <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('date') ?></div>
                <div class="span8">
                                                 <input id="createDate" type="text" class="datepicker2 validate[required] financhk span12" value="<?php echo date("d-m-Y", strtotime($row->receivePaymentDate)); ?>" />
                                            </div>
         	
            </div><!-- control row -->
            
             
            
          <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('receiveFrom'); ?></div>
         	<div class="span8">
                    <textarea style="min-height:85px;" id="receiveFrom" class="span12"><?php echo $row->receiveFrom; ?></textarea>
         	</div>
         </div> <!-- row -->
         
        
       </div><!-- grid block 1-->
      </div><!-- scCol -->
	 
      
       <div class="span4 scCol">
		<div class="block ns" id="grid_block_2">
                    
                     <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('bank') ?></div>
         	<div class="span8">
				<input disabled="disabled" type="text" value="<?php echo $row->bankShortName.' | '.$row->branch; ?>" class="span12" />            
            </div><!-- span -->
            </div><!-- control row -->
             <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('acctno') ?></div>
         	<div class="span8">
				<input disabled="disabled" type="text" value="<?php echo $row->bankAccountNo; ?>" class="span12" />            
            </div><!-- span -->
            </div><!-- control row -->
            <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('project') ?></div>
         	<div class="span8">
			<select id="project" class="span12">
                                                    <option></option>
        <?php
        if ($project != '') {
            foreach ($project as $Prow) {
                ?>
                                                            <option <?php if ($Prow->ID == $row->projectID) echo "selected" ?> value="<?php echo $Prow->ID; ?>"><?php echo $Prow->project_name; ?></option>
            <?php
            }
        }
        ?>
                                                </select>	
                </div>
            </div><!-- control row -->
          
        </div><!-- grid block 1-->
      </div><!-- scCol -->
      
      <div class="span4 scCol">
		<div class="block" id="grid_block_3">
    
           <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('paymentmethood') ?></div>
         	<div class="span8">
              <input disabled="disabled" type="text" value="<?php echo $row->methodPay; ?>" class="span12" />
         	</div>
         </div> <!-- row -->
           <div class="controls-row">
         	 <div class="span4"><?php echo $this->lang->line('amountReceived') ?></div>
         	   <div class="span8">
                       <input id="amountpaid" onkeyup="calculateOutOfBallance()" type="text" value="<?php echo number_format($row->totalReceived,2); ?>" class="span12" />
         	</div>
           </div> <!-- row -->
             <div class="controls-row">
         	 <div class="span4"><?php echo $this->lang->line('refno') ?></div>
         	   <div class="span8">
                       <input id="refNo" type="text" value="<?php echo $row->referenceNo; ?>" class="span12" />
         	</div>
           </div> <!-- row -->
            
           
            <!--div class="controls-row">
         		<div class="span4"><?php echo $this->lang->line('location') ?></div>
         		<div class="span8">
               		 <textarea class="span12" disabled="disabled" ><?php echo $row->code.' | '.$row->address; ?></textarea>
         		</div>
            </div-->
            
        </div><!-- grid block 1-->
      </div><!-- scCol -->
      
      
      
    </div><!-- row-fluid scRow-->
    
    
    
    </div><!-- content -->
    <div class="row-fluid scRow">                            
                            <div class="span12 scCol">
                                <textarea placeholder="<?php echo $this->lang->line('memo') ?>"  id="memo" class="span12"><?php echo $memo; ?></textarea>
                            </div>
                        </div>
      
     <div class="footer">
            	<div class="side fr">
                	<div class="btn-group">
                        <button onclick="updateMaster();" class="btn-form btn-success-form" id="hidePrompt" type="button" name="hidePrompt">Update</button></div>
                </div>
            </div>
    </div><!-- block-->
    <?php } } ?>
    
    
    
      
	
	<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('paymentdetails') ?></h2>
                     <ul class="buttons fr">
                    	<li><a class="block_toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                        	<span class="i-arrow-down-3"></span></a></li>
                    </ul> 
                             <ul class="buttons fr">
                                <li><a href="#trInfos" onclick="addnewrow()" title="Add New"><span class="i-plus-2"></span></a></li>
                            </ul>
                 	
                     
             	 </div><!-- head -->
          <div class="content np">
   				<table id="listDetails" cellpadding="0" cellspacing="0" width="100%">
            	<thead>
                    <tr> <th>#</th>
                        <th><?php echo $this->lang->line('account') ?></th>
                        <th><?php echo $this->lang->line('description') ?></th>
                        <th class="amount"><?php echo $this->lang->line('amount') ?></th>
                        <th><?php echo $this->lang->line('tax') ?></th>
                        <th class="amount"><?php echo $this->lang->line('taxAmount') ?></th>
                        <th class="amount"><?php echo $this->lang->line('amountIncludeTax') ?></th>
                        <th><?php echo $this->lang->line('action') ?></th>
                    </tr>
                </thead>
                <tbody>
                                 <?php
				 $tAllocated=0;
				 $t_taxAmount=0;
				 $tpaid=0;
                                 $lastrow = 0;
		if($pdetails &&$otherPay) {
				 foreach($pdetails as $rowD){
                                      if ($lastrow < $rowD->lineNo)
                                            $lastrow = $rowD->lineNo;
					     $tAllocated += $rowD->amountExcludedTax; ;
						 $t_taxAmount+= $rowD->taxAmount;
				 		 $tpaid += $rowD->amountIncludedTax;
					 ?>
                     <tr>
                         <td><?php echo $rowD->lineNo; ?></td>
                    	<td><?php echo substr($rowD->acctCode,0,4).'-'.substr($rowD->acctCode,4,3).'-'.substr($rowD->acctCode,7) . ' | ' . $rowD->acctName; ?></td>
                        <td><?php echo $rowD->description; ?></td>
                        <td class="amount"><?php echo number_format($rowD->amountExcludedTax,2); ?></td>
                        <td><?php echo $rowD->code . ' | '. $rowD->taxRate; ?></td>
                        <td class="amount"><?php echo number_format($rowD->taxAmount,2); ?></td>
                        <td class="amount"><?php echo number_format($rowD->amountIncludedTax,2); ?></td>
                       <td>
                         <button onclick="editRowPayment(this)" data-taxcode="<?php echo $rowD->code?>" data-taxpercentage="<?php echo $rowD->taxRate?>"  data-taxid="<?php echo $rowD->taxid?>" data-accid= "<?php echo $rowD->accountNoID?>" data-myid="<?php echo $rowD->rowID; ?>" class="btn-icon btn-mini btn-warning-form"><i class="i-pen"></i></button>
                         <button onclick="deleteRowPdetails(this)" data-myid="<?php echo $rowD->rowID; ?>" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>
                        </td>
                    </tr>
                     <?php } ?>
                     <tr id="trInfospmt" data-currentRow="<?php echo $lastrow; ?>">
                	<td colspan="8">
                	    <div id="msg_div2" class="alert alert-info">
                       
                       
                        	<h4><?php echo $this->lang->line('lastMessage') ?></h4>
                        	<p style="padding-top:10px;"><?php echo $this->lang->line('noMessage') ?></p>
					    </div>
                	</td>
                </tr><?php }else {?>
                  
                <tr id="trInfospmt" data-currentRow="<?php echo $lastrow; ?>">
                	<td colspan="8">
                	    <div id="msg_div2" class="alert alert-info">
                        
                        	<h4><?php echo $this->lang->line('lastMessage') ?></h4>
                        	<p style="padding-top:10px;"><?php echo $this->lang->line('noMessage') ?>No Data found</p>
					    </div>
                	</td>
                </tr>
                   <?php }?>
                </tbody>
            </table>     
          </div><!-- content -->
        </div><!-- grid block 1-->
      </div><!-- scCol -->
    </div><!-- row-fluid scRow-->
    <div class="row-fluid scRow"> 
      <div class="span6 scCol">
		<div class="block" id="grid_block_4">
          
        </div><!-- grid block 1-->
      </div><!-- scCol -->        
	  <div class="span6 scCol">
		<div class="block" id="grid_block_4">
          <div class="content np">
                      <div class="controls-row">
                      
                      <div class="span4"><?php echo $this->lang->line('totalallocated')?></div>
                      <div class="span8">
                          <input  id="totalallocated" class="span12 amount" value="<?php echo number_format($tAllocated,2);?>" type="text" placeholder="0" disabled="disabled" >
                      </div>
                  </div><!-- row control -->
                  <div class="controls-row">
                    <div class="span4"><?php echo $this->lang->line('totaltaxamount')?></div>
                      <div class="span8">
                          <input  id="totaltaxamount" value="<?php echo number_format($t_taxAmount,2); ?>" class="span12 amount" type="text" disabled="disabled"  placeholder="0">
                      </div>
                  </div><!-- row control -->
                  <div class="controls-row">
                    <div class="span4"><?php echo $this->lang->line('totalpaid')?></div>
                      <div class="span8">
                          <input  id="totalpaid" disabled="disabled" value="<?php echo number_format($tpaid,2); ?>" class="span12 amount" type="text" placeholder="0">
                      </div>
                  </div><!-- row control -->
                  <div class="controls-row">
                    <div class="span4"><?php echo $this->lang->line('outofbalance')?></div>
                      <div class="span8">
                          <input id="outofbalance" disabled="disabled"  class="span12 amount" type="text" placeholder="0">
                      </div>
                  </div><!-- row control -->
                 
              </div>    
        </div><!-- grid block 1-->
      </div><!-- scCol -->
    </div><!-- row-fluid scRow-->
</div><!-- grid 1 -->
</div><!-- wrap -->
</div><!-- content -->
                    
                    
   