<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>
     window.onbeforeunload = function (e) {
        if (accounting.unformat( $('#outofbalance').val() ) !== 0 ){
          //alert(message); 
  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;
        }
};
    $(document).ready(function(){
      $('select').select2();
            jQuery('.datepicker2').datepicker({
    dateFormat : 'dd-mm-yy',
            changeMonth : true,
            changeYear : true
    });
    });

				  function calculamount(){
					
					//if ($("#itemTax").attr("data-taxid")=="") {
					//	taxPopup ();
					//}
					var j_itemAmountET =accounting.unformat($("#itemunitprice").val())*accounting.unformat($("#itemqte").val());
					$("#itemAmountET").val(accounting.formatNumber(j_itemAmountET,2));
					
					var j_itemTaxAmount=j_itemAmountET*accounting.unformat($("#itemTax").val())/100;
					$("#itemTaxAmount").val(accounting.formatNumber(j_itemTaxAmount,2));
					$("#itemAmountIT").val(accounting.formatNumber(j_itemTaxAmount+j_itemAmountET,2));
					
				}
				
			function calculpmtAmount() { 
			  var t = accounting.unformat($("#pmtAmount").val()) * accounting.unformat($("#itemTax").val()) /100;
			  $("#pmttaxAmount").val(accounting.formatNumber(t,2));
			  $("#pmtAmountIT").val(accounting.formatNumber(t+  accounting.unformat($("#pmtAmount").val())*1,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 class="tac">' + $("#itemqte").val() + '</td>'+
                        '<td class="amount">' + $("#itemAmountET").val() + '</td>'+
                        '<td class="tac">' + $("#displayTaxCode").text() + " | " + $("#itemTax").val() + '</td>'+
                        '<td class="amount">' + $("#itemTaxAmount").val() + '</td>'+
                        '<td class="amount">' + $("#itemAmountIT").val() + '</td>'+
                         '<td class="tac">'+
						'<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 class="deleteRowPdetails(this)" 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 class="tac">' + $("#itemqte").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemAmountET").attr("data-previewvalue") + '</td>'+
                        '<td class="tac">' + $("#itemTax").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemTaxAmount").attr("data-previewvalue") + '</td>'+
                        '<td class="amount">' + $("#itemAmountIT").attr("data-previewvalue") + '</td>'+
                        '<td class="tac">'+
						'<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="pmtAmount" onkeyup="calculpmtAmount()" name="pmtAmount" 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="disabled" onkeyup="calculpmtAmount()" onblur="calculpmtAmount()" 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="pmttaxAmount" disabled value="' + $(me).parent().parent().find("td").eq(5).html() + '"  name="pmttaxAmount" 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="pmtAmountIT" value="' + $(me).parent().parent().find("td").eq(6).html() + '"name="pmtAmountIT" disabled class="span12" type="text" placeholder="Amount (Exclude Tax)"></td>'+
						'<td class="span1">'+
						 	'<button data-myid="' + $(me).attr("data-myid") + '" data-taxcode = "' + $(me).attr("data-taxcode") + '" data-taxpercentage = "' + $(me).attr("data-taxpercentage") + '" data-accid="' + $(me).attr("data-accid") + '" 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-taxcode = "' + $(me).attr("data-taxcode") + '" data-taxpercentage = "' + $(me).attr("data-taxpercentage") + '"  data-accid="' + $(me).attr("data-accid") + '" 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();
                                        //$("#itemTax").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="tar">' + $("#pmtAmount").attr("data-previewvalue") + '</td>'+
                        '<td class="tac">' + $("#itemTax").attr("data-previewvalue") + '</td>'+
                        '<td class="tar">' + $("#pmttaxAmount").attr("data-previewvalue") + '</td>'+
                        '<td class="tar">' + $("#pmtAmountIT").attr("data-previewvalue") + '</td>'+
                        '<td class="tac">'+
						'<button onclick="editRowPayment(this)" 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") + '" 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($("#pmtAmountIT").val()),
									amountExcludedTax :  accounting.unformat($("#pmtAmount").val()),
									taxID: $("#itemTax").attr("data-taxid"),
                                    taxRate: $("#itemTax").val(),    
									taxAmount : accounting.unformat($("#pmttaxAmount").val()),
									itemdescription : $("#pmtdesc").val(),
									
								  },
							  url: "<?php echo base_url() ?>OthersPayment/updatepayitemwithoutitem",
							  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="tar">' + accounting.formatNumber($("#pmtAmount").val(),2) + '</td>'+
											'<td class="tac">' + $("#displayTaxCode").text() + " | " + $("#itemTax").val() + '</td>'+
											'<td class="tar">' + $("#pmttaxAmount").val() + '</td>'+
											'<td class="tar">' + $("#pmtAmountIT").val() + '</td>'+
											'<td class="tac">'+
											'<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() ?>OthersPayment/deletePaymentWithoutItem",
							  	 success: function(data) {
										 msg (1,"alert alert-success","Details successfully deleted");
							 			 delRowInvoice(me);
							             getTotal();
						 
						  			}} ); 
							 });
					}
                function addnewrow(){
                     n = $("#trInfospmt").attr("data-currentRow")*1 + 1;
                     if (!$("#accountID").length) {
                     $(''+
                         '<tr><td class="span1">' + 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="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();
        // $('#itemTax').select2();
            }else{
                    msg (2,"alert","Please, do save the current details before adding new one");
                    }
                }
		 function calculAmount(){
                var am = accounting.unformat($("#itemTax").val())*accounting.unformat($("#amountExcludedTax").val())/100;
                 $("#taxAmount").val("0.00");
                 $("#amountIT").val("0.00");
                 if  (!isNaN(am)){
                        $("#taxAmount").val(accounting.formatNumber(am,2));
                        $("#amountIT").val(accounting.formatNumber(am*1 + 1*accounting.unformat($("#amountExcludedTax").val()),2));
                 }
        }
        
        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()),
                                    itemAccountID : $("#accountID").val(),
                                    itemdescription: $("#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/savenewpaywithoutItemDetailOnly",
                    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="tar">' + accounting.formatNumber($("#amountExcludedTax").val(),2) + '</td>'+
                              '<td class="tac">' + $("#itemTax").val() + ' | ' + $("#displayTaxCode").text()  + '</td>'+
                              '<td class="tar">' + accounting.formatNumber($("#taxAmount").val(),2) + '</td>'+
                              '<td class="tar">' + accounting.formatNumber($("#amountIT").val(),2) + '</td>'+
                              '<td class="tac">'+
                            '<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 onclick="deleteRowPdetails(this)" 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();
                 calculpmtAmount();
        });
	
}
            
            function calculateOutOfBallance(){
                //alert($("#amountpaid").val());
               $("#outofbalance").val(accounting.formatNumber(accounting.unformat($("#amountpaid").val())-accounting.unformat($("#totalpaid").val()),2));
            }
            
            
            $(document).ready(function(){
                calculateOutOfBallance();
});
            function updateMaster(){
                 $.ajax({
                type: "POST",
                data: {
                            masterID  : $("#masterID").val(),
                            amountPaid : accounting.unformat($("#amountpaid").val()),
                            refNo : $("#refNo").val(),
                            payTo : $("#payTo").val(),
                            memo: $("#memo").val(),
                            project : $("#project").val(),
                            date : $("#createDate").val(),
                            formNo : $("#formNo").val()

                      },
                url: "<?php echo base_url() ?>OthersPayment/updatepayitemwithoutitemMaster",
                success: function(data) {
                                //1 success
                                // 2 error
                                // 3 warning 
                                if ($.trim(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 np">
            
	<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->paymentDate)); ?>" />
                                            </div>
            </div><!-- control row -->
            
             
            
          <div class="controls-row">
         	<div class="span4"><?php echo $this->lang->line('payto'); ?></div>
         	<div class="span8">
                    <textarea style="min-height:85px;" id="payTo" name="payTo" class="span12"><?php echo $row->payTo; ?></textarea>
         	</div>
         </div> <!-- 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('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('balance') ?></div>
         	<div class="span8">
                    <input onkeyup="calculateOutOfBallance();" disabled="disabled" type="text" value="<?php echo $row->currentBalance; ?>" class="span12" />             
            </div><!-- span -->
            
            </div><!-- control 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 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><!-- span -->
            </div><!-- control 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('amountpaid') ?></div>
         	   <div class="span8">
                       <input id="amountpaid" onkeyup="calculateOutOfBallance()" type="text" value="<?php echo number_format($row->amountPaid,2); ?>" class="span12 tar" />
         	</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('paymentmethood') ?></div>
         	<div class="span8">
                    <textarea disabled="disabled" class="span12" ><?php echo $row->methodPay; ?></textarea>
         	</div>
         </div> <!-- row -->
         
                    
           
          
        </div><!-- grid block 1-->
      </div><!-- scCol -->
    </div><!-- row-fluid scRow-->
    <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><!-- content -->
      <div class="footer">
            	<div class="side fr">                
					<button class="btn-form btn-success-form" id="hidePrompt" onclick="updateMaster();"type="button" name="hidePrompt">Update</button>
				</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> 
                             <div class="side fr">
                                <a href="#trInfos" class="btn-icon btn-warning-form" onclick="addnewrow()" title="Add New"><span class="i-plus-2"></span></a>
                            </div>
                 	
                     
             	 </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 class="tac"><?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) {
				 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->itemdescription; ?></td>
                        <td class="tar"><?php echo number_format($rowD->amountExcludedTax,2); ?></td>
                        <td class="tac"><?php echo $rowD->code . ' | '. $rowD->taxPercentage; ?></td>
                        <td class="tar"><?php echo number_format($rowD->taxAmount,2); ?></td>
                        <td class="tar"><?php echo number_format($rowD->amountIncludedTax,2); ?></td>
                        <td class="tac">
                         <button onclick="editRowPayment(this)" data-taxcode="<?php echo $rowD->code?>" data-taxpercentage="<?php echo $rowD->taxPercentage?>" data-taxid="<?php echo $rowD->taxid?>" data-accid= "<?php echo $rowD->accountID?>" data-myid="<?php echo $rowD->itemID; ?>" class="btn-icon btn-small btn-warning-form"><span class="i-pen"></span></button>
                         <button onclick="deleteRowPdetails(this)" data-myid="<?php echo $rowD->itemID; ?>" class="btn-icon btn-small btn-danger-form"><span class="i-trashcan"></span></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-error">
                        	<h4><?php echo $this->lang->line('lastMessage') ?></h4>
                        	<p style="padding-top:10px;"> No pmts 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 -->
                    
                    
   