<style type="text/css">
    .amount{
        text-align: right !important;
    }

    .quantity {
        text-align: center !important;
    }
    .btn-group button {
        height:30px;}
    .input-append select {
        width:140px;}

    #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 {
        font-size: 10px;
    }
    #content .wrap #grid_content_1 .row-fluid.scRow .row-fluid.scRow .span12.scCol #grid_block_6 .content.np #listCharge tbody #trInfosCharge td .row-fluid .controls-row .span3 {
        font-weight: bold;
    }
</style>
<script type="application/javascript">
    $('select').select2();
    $(document).ready(function(){
            $('select').select2();
            $.each($(".select2-container"), function (i, n) {
                $(n).next().show().fadeTo(0, 0).height("0px").css("left", "auto"); // make the original select visible for validation engine and hidden for us
                $(n).prepend($(n).next());
                $(n).delay(500).queue(function () {
                    $(this).removeClass("validate[required]"); //remove the class name from select2 container(div), so that validation engine dose not validate it
                    $(this).dequeue();
                });
            });
            jQuery('.datepicker2').datepicker({
                    dateFormat : 'dd-mm-yy',
                    changeMonth : true,
                    changeYear : true
            });
    });

                                function loadPoListBySupplierID() {
                                        $('#poList').empty();
                                        $('#outstandingItems tbody').empty();
                                        $.ajax({
                                                type: "POST",
                                                data: "supplier="+ $("#supplier option:selected").val(),
                                                url: "<?php echo base_url() ?>receiveItems/getPoList",
                                                success: function(data) {
                                                         var resul = eval ("(" + data + ")"); 
                               var n=resul.records.length;
                               var i=0;
                               var opt='' +
                                                '<option></option><option value="-1">None</option>';
                                for (i=0;i<n;i++)
                                        opt=opt + '<option value="' + resul.records[i].id + '">' + resul.records[i].formNo + '</option>';
							
                              $('#poList').append(opt);
                                                }
                                         });
                                }

                            function loadSupplierDefaultValue(me){
                                        $('#currency').attr("value","");
                                        $('#exchange_rate').attr("value","");
                                        loadPoListBySupplierID();
                                        $.ajax({
                                                type: "POST",
                                                data: "supplier="+ $("#supplier option:selected").val(),
                                                url: "<?php echo base_url() ?>supplier/loadSupplierDefaultValue",
                                                success: function(data) {
                                                         var resul = eval ("(" + data + ")"); 
                                                        $('#currency').attr("value",resul.records[0].currency);
                                                        $('#exchange_rate').attr("value",resul.records[0].exchangeRate);
                                                }
                                         });
					 
                                }
				
                                function refreshSupplier(){
                                        $.ajax({
                                                type: "POST",
                                                url: "<?php echo base_url() ?>supplier/refreshSupplier",
                                                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].supplierName + '</option>';
                                                        $('#supplier').empty();
                              $('#supplier').append(opt);
                                                }
                                         });
					 
                                }
			
				
				
        function calculamount() {
                $("#itemAmount").val(accounting.formatNumber(accounting.unformat($("#itemunitprice").val())*accounting.unformat($("#itemqte").val()),2));
        }			
				
  
  function getTotal (){
        $("#totalpayable").val("");
	
         var n =$("#t_listItemOrdered > tbody > tr").length-1;
         var total =0;
         for (i=0; i<=n; i++) {
                        total= total + accounting.unformat($('#t_listItemOrdered > tbody > tr:eq(' + i + ') > td:eq(5)').text())*1; 
         }
	 
         var n1 =$("#t_listItemOrdered > tbody > tr").length-1;
         var total1 =0;
         for (i=0; i<=n1; i++) {
                        total1= total1 + accounting.unformat($('#t_listItemOrdered1 > tbody > tr:eq(' + i + ') > td:eq(5)').text())*1; 
         }
  
         $("#totalpayable").val(accounting.formatNumber(total + total1,2));
	
  }
					
					
function msg(type, message){
	
        $("#msg_div p").html(message);
        $("#msg_div").attr("class","alert " + type);
}

function delRow(me){
        var td=me.parentNode;
        var tr=td.parentNode;
        var tBody=tr.parentNode;
        tBody.removeChild(tr);
}


function displaysItemDefaultValue(){
          $("#itemdes").val($("#itemComboList option:selected").attr("data-desc"));
         $("#itemunitprice").val(accounting.formatNumber($("#itemComboList option:selected").attr("data-price"),2));
         $("#itemAmount").val(accounting.formatNumber(0,2));
          }


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 saveItemReceiced(me){
			
                //$(me).parent().validationEngine('showPrompt', '*date field is required');
                //alert (jQuery( $(tr).find("td").eq(7).children("input:first-child")).valid());
                        if ($("#receivedID").val()=="null"){ 
                        //new 
                         if( $("#frmReceive").validationEngine('validate')){
                         var tr = $(me).parent().parent();
                         var v =$(tr).find("td").eq(7).children("input:last-child").val();
                          if (v<1 || v > ($(tr).find("td").eq(4).text()- $(tr).find("td").eq(6).text()) || isNaN($(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text()) ) {
                                  $(tr).find("td").eq(7).children("input:last-child").validationEngine('showPrompt', 'Qty received Incorrect');
                          }else {
                                  $.ajax({
                                          type: "POST",
                                          data: {
                                                  supplierID : $("#supplier").val(),
                                                  formNo : $("#formNo").val(),
                                                  deliveryDate : $("#createdDate").val(),
                                                  shippingMethodID : $("#shippingMethod").val(),
                                                  supplierDoNo : $("#supplierDoNumber").val(),
                                                  purchaseOrderID : $("#poList").val(),
                                                  locationID : $("#location").val(),
                                                  employeeID : $("#purchaseInvoiceId").val(),
                                                  memo : $("#memo").val(),

                                                  poDetailID : $(me).attr("data-podetailsid"),
                                                  itemCode : $(tr).find("td").eq(0).text(),
                                                  itemname : $(tr).find("td").eq(1).text(),
                                                  quantityReceivedTotal : $(tr).find("td").eq(6).text(),
                                                  description : $(tr).find("td").eq(2).text(),
                                                  quantityOrder : $(tr).find("td").eq(4).text(),
                                                  quantityReceived : $(tr).find("td").eq(7).children("input:last-child").val(),
                                                  unitPrice : $(tr).find("td").eq(3).text(),
                                                  amount : $(tr).find("td").eq(5).text()
				
                                                  },
                                          url: "<?php echo base_url() ?>receiveItems/saveNewItemReceived",
                                          success: function(data) {
                                                  var resul = eval ("(" + data + ")"); 
                                                   $("#receivedID").val(resul.receivedID);
                                                  $("#poList").attr('disabled','disabled');
                                                  $("#supplier").attr('disabled','disabled');
                                                  msg("alert alert-success","Data saved successfully !!!")
                                                  var tr = $(me).parent().parent();
                                                  $(''+
                                                   '<tr>' +
                                                          '<td>' +  $(tr).find("td").eq(0).text() + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(1).text()  + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(2).text()  + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(4).text()  + '</td>'+
                                                          '<td>' + $(tr).find("td").eq(7).children("input:last-child").val() + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text() + '</td>'+
                                                          '<td>'+
                                                          '</td>'+
                                                          '</tr>'
                                                        ).insertBefore( "#trInfos" );
                                                        delRow (me);
                                                        getTotal ();
                                                  }
                                          });
                          }
                         }
			 
			 
                        }else{
                                // save detail only
                                 var tr = $(me).parent().parent();
                         var v =$(tr).find("td").eq(7).children("input:last-child").val();
                          if (v<1 || v > ($(tr).find("td").eq(4).text()- $(tr).find("td").eq(6).text()) || isNaN($(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text()) ) {
                                  $(tr).find("td").eq(7).children("input:last-child").validationEngine('showPrompt', 'Qty received Incorrect');
                          }else {
                                  $.ajax({
                                          type: "POST",
                                          data: {
                                                  receiveID : $("#receivedID").val(),

                                                  poDetailID : $(me).attr("data-podetailsid"),
                                                  itemCode : $(tr).find("td").eq(0).text(),
                                                  itemname : $(tr).find("td").eq(1).text(),
                                                  quantityReceivedTotal : $(tr).find("td").eq(6).text(),
                                                  description : $(tr).find("td").eq(2).text(),
                                                  quantityOrder : $(tr).find("td").eq(4).text(),
                                                  quantityReceived : $(tr).find("td").eq(7).children("input:last-child").val(),
                                                  unitPrice : $(tr).find("td").eq(3).text(),
                                                  amount : $(tr).find("td").eq(5).text()
				
                                                  },
                                          url: "<?php echo base_url() ?>receiveItems/saveNewItemDetailOnly",
                                          success: function(data) {
                                                  var resul = eval ("(" + data + ")"); 
                                                   $("#receivedID").val(resul.receivedID);
                                                  $("#poList").attr('disabled','disabled');
                                                  $("#supplier").attr('disabled','disabled');
                                                  msg("alert alert-success","Data saved successfully !!!")
                                                  var tr = $(me).parent().parent();
                                                  $(''+
                                                   '<tr>' +
                                                          '<td>' +  $(tr).find("td").eq(0).text() + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(1).text()  + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(2).text()  + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(4).text()  + '</td>'+
                                                          '<td>' + $(tr).find("td").eq(7).children("input:last-child").val() + '</td>'+
                                                          '<td>' +  $(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text() + '</td>'+
                                                          '<td>'+
                                                          '</td>'+
                                                          '</tr>'
                                                        ).insertBefore( "#trInfos" );
                                                        delRow (me);
                                                        getTotal ();
                                                  }
                                          });
                          }
                        }
}

        function getPoItems(me){
                $('#outstandingItems tbody').empty();
                 $.ajax({
                  type: "POST",
                  data: {
                          poId : $("#poList").val()
                          },
                  url: "<?php echo base_url() ?>receiveItems/getPoItemList",
                  success: function(data) {

                         var resul = eval ("(" + data + ")"); 
                         var n=resul.records.length;
                         var tcontent = "";
                         for (i=0;i<n;i++) {
                                tcontent=tcontent + '<tr><td class="span1">' + resul.records[i].itemCode + '</td>' + 
                                                '<td class="span2">' + resul.records[i].itemName + '</td>' + 
                                                '<td class="span2">' + resul.records[i].description + '</td>' + 
                                                '<td class="span1">' + resul.records[i].unitPrice + '</td>' + 
                                                '<td class="span1">' + resul.records[i].quantityOrder + '</td>' + 
                                                '<td class="span1">' + (resul.records[i].unitPrice*resul.records[i].quantityOrder)  + '</td>' + 
                                                '<td class="span1">' + resul.records[i].quantityReceivedTotal + '</td>' + 
                                                '<td class="span1"><input placeholder="R.:' + (resul.records[i].quantityOrder-resul.records[i].quantityReceivedTotal)  +'" name="" class="span12 validate[required,custom[integer], min[1], max[' + (resul.records[i].quantityOrder-resul.records[i].quantityReceivedTotal) +'] ]" type="text"/></td>' + 
                                                '<td class="span1"><button type="button" onclick="saveItemReceiced(this)" data-poDetailsId="'+ resul.records[i].poDetailId  +'" class="btn btn-mini btn-primary"><i class="icon-ok icon-white"></i></button></td></tr>';
				
                        }
			 
                                $('#outstandingItems tbody').append(tcontent);
                  }
			
                 });	
        }
	
        function displayLocationAdress(){
                $("#locationAdress").text($("#location option:selected").attr("data-locationadress"));
        }
	
        function getItemDetails(me){
          $("#itemname").val("");
          $("#itemdes").val("");
          $.ajax({
                  type: "POST",
                  data: "code="+ me.value,
                  url: "<?php echo base_url() ?>purchasetransaction/getItemDetails",
                  success: function(data) {
                          if(data!="item Not found"){
                                   var resul = eval ("(" + data + ")");
                                  $("#itemname").val(resul.description);
                                  $("#itemdes").val(resul.name);
                          }else{
                                  $("#itemdes").attr("placeholder",data);
                                  $("#itemname").attr("placeholder",data);				  }
                  }
           });
        }
  
  
  function calculTotal(me){
    var tr = $(me).parent().parent();
    var v1 =$(tr).find("td").eq(4).children("input:last-child").val();
    $(tr).find("td").eq(5).children("input:last-child").val(accounting.formatNumber(accounting.unformat(v1)*accounting.unformat($(tr).find("td").eq(3).text()),2));
  }
  
  function editRow(me){
        var tr = $(me).parent().parent();
        var v =$(tr).find("td").eq(4).text();
	
        if($(me).attr("data-poDetailID")>0){
                  $(tr).find("td").eq(4).empty();
                 $($(tr).find("td").eq(4)).append('<input onkeyup="calculTotal(this)" class="input-mini" type="text" data-previewvalue="' + v + '" value="' + v + '" />');
                
                 var pv = $(tr).find("td").eq(5).text();
                  $(tr).find("td").eq(5).empty();
                 $($(tr).find("td").eq(5)).append('<input class="input-mini" disabled type="text" data-previewvalue="' + pv+ '" value="' + pv + '" />');
                
                $(tr).find("td").eq(6).empty();
                 $($(tr).find("td").eq(6)).append( '<button class="btn btn-mini btn-primary" style="margin-right:3px;" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" onclick="updateRow(this)" type="button"><i class="icon-ok"></i></button>'+
                          '<button id="btnCancel" class="btn btn-mini btn-warning" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" onclick="cancelEdit(this)" type="button"><i class="icon-remove-sign"></i></button>');
                          
        }else {
          if (!$("#itemComboList").length) {
           $(tr).replaceWith('<tr>' +
                  '<td class="span1">' + $(tr).find("td").eq(0).text() + '</td>'+
          '<td class="span2" >' +
                '<select id="itemComboList" class="span10" data-lineNo="' + $(tr).find("td").eq(0).text() +  '" data-previewvalue="' + $(tr).find("td").eq(1).text() +'" onchange="displaysItemDefaultValue()"><option></option>' +
<?php
if ($items) {
    foreach ($items as $row) {
        ?>
                                                '<option data-desc= "<?php echo $row->description; ?>" data-price= "<?php echo $row->supplierPrice; ?>" \n\
                                                    data-taxid="<?php echo $row->inputTaxID; ?>" data-taxcode="<?php echo $row->inputTaxCode; ?>" \n\
                                                    data-taxPercentage="<?php echo $row->inputTaxPercentage; ?>" value="<?php echo $row->ID; ?>"><?php
        echo str_replace("'", " ", $row->name, $count)
        . " [" . str_replace("'", " ", $row->itemCode, $count) . "]";
        ?></option>'+
        <?php
    }
}
?>
            '</select>' +
            '<div class="btn-group span1">' +
            '<button class="btn btn-mini btn-primary dropdown-toggle" data-toggle="dropdown">' +
            '   <span class="i-arrow-down-2"></span> </button> <ul class="dropdown-menu">' +
            '<li><a target="_blank" href="<?php echo base_url() ?>icsetting/itemNew">' +
            '<i class="icon-plus-sign"></i><?php echo $this->lang->line('addNewItem') ?></a></li>' +
            '<li><a href="#" onclick="refreshItems()"><i class="icon-refresh"></i><?php echo $this->lang->line('refreshlist') ?></a>' +
            '</li> </ul></div></td>' +	  
             '<td class="span2"><input id="itemdes" data-previewvalue="' + $(tr).find("td").eq(2).text() + '" value="' + $(tr).find("td").eq(2).text() + '" name="itemdes" class="span12 validate[required]" type="text" placeholder="Description"></td>'+
                  '<td class="span1"><input id="itemunitprice" data-previewvalue="' + $(tr).find("td").eq(3).text() + '" value="' + $(tr).find("td").eq(3).text() + '" onkeyup="calculamountET()" name="itemunitprice" class="span12 validate[required,custom[number]]" type="text" placeholder="Unit Priece"></td>'+
                  '<td class="span1"><input id="itemqte" data-previewvalue="' + $(tr).find("td").eq(4).text() + '" value="' + $(tr).find("td").eq(4).text() + '" onkeyup="calculamountET()"  name="itemqte" class="span12 validate[required,custom[integer]]" type="text" placeholder="Qty"></td>'+
                  '<td class="span1"><input id="itemAmount" data-previewvalue="' + $(tr).find("td").eq(5).text() + '" value="' + $(tr).find("td").eq(5).text() + '" name="itemAmount" onkeydown="return false;" class="input-mini validate[required]" type="text" placeholder="Amount"></td>'+
                  '<td class="span1">'+
                          '<button class="btn btn-mini btn-primary" data-itemid="'+ $(me).attr("data-itemid") +'" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-itemid="' + $(me).attr("data-itemid") + '" data-myid="' + $(me).attr("data-myid") + '" onclick="updateRow(this)" type="button"><i class="icon-ok"></i></button>\n\
                            <button id="btnCancel" class="btn btn-mini btn-warning" data-itemid="'+ $(me).attr("data-itemid") +'" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" onclick="cancelEdit(this)" type="button"><i class="icon-remove-sign"></i></button>'+
                  '</td>'+
          '</tr>');
            $("#itemComboList").val($(me).attr("data-itemid"));
            $("#itemComboList").select2();
		
          }else{
                  msg (1,"alert","Please, do save the current details before addind new one");
                  }
		
        }
  }
  function refreshItems(){
                                        $.ajax({
                                                type: "POST",
                                                url: "<?php echo base_url() ?>po_transaction/refreshItems",
                                                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 data-price="'+ resul.records[i].price +'" data-description="' + resul.records[i].description + '" value="' + resul.records[i].id + '">' + resul.records[i].name + '[' + resul.records[i].code + ']' + '</option>';
                                                    $('#itemComboList').empty();
                                                    $('#itemComboList').append(opt);
                                                                    }
                                         });
					 
                                }
  
  function cancelEdit(me){
  
     var tr = $(me).parent().parent();
          if ($(me).attr("data-poDetailID") <= 0){
                   $(tr).replaceWith( '<tr>' +
                  '<td>' +  $("#itemComboList").attr("data-lineNo") + '</td>'+
                  '<td>' + $("#itemComboList").attr("data-previewvalue") + '</td>'+
                  '<td>' + $("#itemdes").attr("data-previewvalue") + '</td>'+
                  '<td class="amount">' + $("#itemunitprice").attr("data-previewvalue") + '</td>'+
                  '<td class="quantity">' + $("#itemqte").attr("data-previewvalue") + '</td>'+
                  '<td class="amount">' + $("#itemAmount").attr("data-previewvalue") + '</td>'+
                  '<td class="quantity">'+
                         '<button data-itemid="'+ $(me).attr("data-itemid") +'" style="margin-right:3px;" onClick="editRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
             '<button data-itemid="'+ $(me).attr("data-itemid") +'" onClick="deleteRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                  '</td>'+
          '</tr>');
                 getTotal ();
          }else {
                  var tr = $(me).parent().parent();
                 var v =$(tr).find("td").eq(4).children("input:last-child").attr("data-previewvalue");
                 $(tr).find("td").eq(4).empty();
                 $(tr).find("td").eq(4).text(v);
                 
                  var v1 =$(tr).find("td").eq(5).children("input:last-child").attr("data-previewvalue");
                 $(tr).find("td").eq(5).empty();
                 $(tr).find("td").eq(5).text(v1);
                 
                 
                 $(tr).find("td").eq(6).empty();
                 $($(tr).find("td").eq(6)).append(  '<button data-itemid="' + $(me).attr("data-itemid") + '" style="margin-right:3px;" onClick="editRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
             '<button onClick="deleteRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>');
          }
  
  }
  
   function deleteRow(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 btn-danger" id="_confirmBtn">Ok</button>' +
        '<button class="btn" id="canb">Cancel</button>');
        $("#_popupTitle").html("Confirm delete");
        $( "#canb" ).click(function() {
                $('#popupModal').modal('hide');
        });
         var tr = $(me).parent().parent();
        var v =$(tr).find("td").eq(4).text();
        $( "#_confirmBtn" ).click(function() {
                $('#popupModal').modal('hide');
                  $.ajax({
                  type: "POST",
                  data: "rowId="+ $(me).attr("data-myid") +"&poDetailID=" + $(me).attr("data-podetailid") + "&qty=" + v,
                  url: "<?php echo base_url() ?>receiveItems/deleteReceiveItemdetails",
                  success: function(data) {
                          msg (1,"alert alert-success","Details successfully deleted");
                                        delRow(me);			  }
                  });
                 getTotal();
					
        });
				  
				  
    }
  
  function updateRow(me){
        if ($(me).attr("data-poDetailID") <= 0){
                if( $("#frmReceiveItemNoPo").validationEngine('validate')){
                        var tr = $(me).parent().parent();
                                $.ajax({
                                        type: "POST",
                                        data: {
                                              itemReceivedID : $(me).attr("data-myid"),
                                              itemID : $("#itemComboList").val(),
                                              quantityReceivedTotal : "0",
                                              quantityOrder : "0",
                                              option: "noPo",
                                              poDetailID : $(me).attr("data-podetailid"),
                                              quantityReceivedTotal : $(tr).find("td").eq(6).text(),
                                              description : $("#itemdes").val(),
                                              quantityReceived : $("#itemqte").val(),
                                              unitPrice : accounting.unformat($("#itemunitprice").val()),
                                              amount : accounting.unformat($("#itemAmount").val())
			  
                                                },
                                         url: "<?php echo base_url() ?>receiveItems/updateReceiveItemDetail",
                                         success: function(data) {
                                                var tr = $(me).parent().parent();
                                                 $(tr).replaceWith('<tr>' +
                                                        '<td>' +  $("#itemComboList").attr("data-lineNo") + '</td>'+
                                                          '<td>' +  $("#itemComboList option:selected").text() + '</td>'+
                                                          '<td>' +  $("#itemdes").val()  + '</td>'+
                                                          '<td class="amount">' +  accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                                                          '<td>' + $("#itemqte").val() + '</td>'+
                                                          '<td class="amount">' +  accounting.formatNumber($("#itemAmount").val(),2) + '</td>'+
                                                         '<td class="quantity">'+
                                                             '<button data-itemid="'+ $("#itemComboList").val() +'" style="margin-right:3px;" onClick="editRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                                                             '<button data-itemid="'+ $("#itemComboList").val() +'" onClick="deleteRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                                                        '</td>'+
                                                    '</tr>');
                                                  getTotal ();
                                                }
                                        });
                }
        }else {
                var tr = $(me).parent().parent();
                var v =$(tr).find("td").eq(4).children("input:last-child").attr("data-previewvalue");
                var v1 =$(tr).find("td").eq(4).children("input:last-child").val();
		
                var vT =accounting.unformat($(tr).find("td").eq(5).children("input:last-child").val());
                
                $.ajax({
                        type: "POST",
                        data: {
                                itemReceivedID : $(me).attr("data-myid"),
                                poDetailID : $(me).attr("data-poDetailID"),
                                qtyPoUpdate : v-v1,
                                amount : vT,
                                option: "Po",
                                quantityReceived : v1
	  
                                },
                         url: "<?php echo base_url() ?>receiveItems/updateReceiveItemDetail",
                         success: function(data) {
                                var tr = $(me).parent().parent();
                                 var tr = $(me).parent().parent();
                                 var v =$(tr).find("td").eq(4).children("input:last-child").val();
                                 $(tr).find("td").eq(4).empty();
                                 $(tr).find("td").eq(4).text(v);
                                 
                                  $(tr).find("td").eq(5).empty();
                                 $(tr).find("td").eq(5).text(vT);
                                 
                                 $(tr).find("td").eq(6).empty();
                                 $($(tr).find("td").eq(6)).append(  '<button style="margin-right:3px;" data-itemid="' + $(me).attr("data-itemid") + '" onClick="editRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                                         '<button data-itemid="' + $(me).attr("data-itemid") + '" onClick="deleteRow(this)" data-poDetailID="' + $(me).attr("data-poDetailID") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>');
                                }
                        });
        }
  }
  
  function calculamountET(){
        $("#itemAmount").val(accounting.formatNumber(accounting.unformat($("#itemunitprice").val())*accounting.unformat($("#itemqte").val()),2));
  }
  
  function addnewitemnotinpo(){
      if (!$("#itemComboList").length) {
                        $('<tr><td class="span1">' + ($("#trInfos").attr("data-currentRow")*1+1) + '</td>'+
                 '<td class="span2" >' +
                '<select id="itemComboList" class="span10" onchange="displaysItemDefaultValue()"><option></option>' +
<?php
if ($items) {
    foreach ($items as $row) {
        ?>
                                        '<option data-desc= "<?php echo $row->description; ?>" data-price= "<?php echo $row->supplierPrice; ?>" \n\
                                            data-taxid="<?php echo $row->inputTaxID; ?>" data-taxcode="<?php echo $row->inputTaxCode; ?>" \n\
                                            data-taxPercentage="<?php echo $row->inputTaxPercentage; ?>" value="<?php echo $row->ID; ?>"><?php
        echo str_replace("'", " ", $row->name, $count)
        . " [" . str_replace("'", " ", $row->itemCode, $count) . "]";
        ?></option>'+
        <?php
    }
}
?>
            '</select>' +
            '<div class="btn-group span1">' +
            '<button class="btn btn-mini btn-primary dropdown-toggle" data-toggle="dropdown">' +
            '   <span class="i-arrow-down-2"></span> </button> <ul class="dropdown-menu">' +
            '<li><a target="_blank" href="<?php echo base_url() ?>icsetting/itemNew">' +
            '<i class="icon-plus-sign"></i><?php echo $this->lang->line('addNewItem') ?></a></li>' +
            '<li><a href="#" onclick="refreshItems()"><i class="icon-refresh"></i><?php echo $this->lang->line('refreshlist') ?></a>' +
            '</li> </ul></div></td>' +
                        '<td class="span3"><input id="itemdes" name="itemdes" class="span12 validate[required]" type="text" placeholder="Description"></td>'+
                        '<td class="span1"><input id="itemunitprice" onkeyup="calculamount()" name="itemunitprice" class="span12 validate[required,custom[number]] tar" type="text" placeholder="Unit Priece"></td>'+
                        '<td class="span1"><input id="itemqte" onkeyup="calculamount()"  name="itemqte" class="span12 validate[required,custom[integer]] tar" type="text" placeholder="Qty"></td>'+
                        '<td class="span1"><input id="itemAmount" name="itemAmount" onkeydown="return false;" class="span12 tar" type="text" placeholder="Amount (Include Tax)"></td>'+
                        '<td class="span1 tac">'+
                                                        '<button class="btn btn-mini btn-primary" onclick="savenewitemnotinpo(this)" type="button"><i class="icon-ok-circle icon-white"></i></button>'+
                                                        '<button id="btnCancel" class="btn btn-mini btn-danger" onclick="delRow(this)" type="button"><i class="icon-remove-circle icon-white"></i></button>'+
                                                '</td>'+
                    '</tr>').insertBefore( "#trInfos" );
                  $('#itemComboList').select2();
	
 
                                        }else{
                                                msg (1,"alert","Please, do save the current details before addind new one");
                                                }
  }
  
  function savenewitemnotinpo(me){
   
    $.ajax({
            type: "POST",
            data: {
                 receiveID : $("#receivedID").val(),

                  poDetailID : "-1",
                  itemID : $("#itemComboList").val(),
                  lineNo :$("#trInfos").attr("data-currentRow")*1+1,
                  quantityReceivedTotal : "0",
                  quantityOrder : "0",
                  description : $("#itemdes").val(),
                  quantityReceived : $("#itemqte").val(),
                  unitPrice : accounting.unformat($("#itemunitprice").val()),
                  amount : accounting.unformat($("#itemAmount").val())


                    },
            url: "<?php echo base_url() ?>receiveItems/saveNewItemDetailOnly",
            success: function(data) {
                    var resul = eval ("(" + data + ")");
                    $("#poList").attr('disabled','disabled');
                    $("#supplier").attr('disabled','disabled');
//                    msg("alert alert-success","Data saved successfully !!!");  
                     
                    $('<tr>' +
                            '<td>' +  ($("#trInfos").attr("data-currentRow")*1+1)  + '</td>'+
                              '<td>' +  $("#itemComboList option:selected").text() + '</td>'+
                              '<td>' +  $("#itemdes").val()  + '</td>'+
                              '<td class="amount">' +  accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                              '<td>' + $("#itemqte").val() + '</td>'+
                              '<td class="amount">' +  accounting.formatNumber($("#itemAmount").val(),2) + '</td>'+
                              '<td><button data-itemid="'+ $("#itemComboList").val() +'" data-myid="' + resul.detailID + '"  style="margin-right:3px;" onClick="editRow(this)" data-poDetailID="-1"  class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                               ' <button data-itemid="'+ $("#itemComboList").val() +'" data-myid="' + resul.detailID + '"  onClick="deleteRow(this)" data-poDetailID="-1"  class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                        '</td></tr>').insertBefore("#trInfos");
                        $("#trInfos").attr("data-currentRow",$("#trInfos").attr("data-currentRow")*1+1);
                      //  $("#btnCancel").trigger("click");
                        delRow (me);

                        getTotal ();
                    }
            });
  }
 
 function saveItemReceived(me){ 
                
			
		//$(me).parent().validationEngine('showPrompt', '*date field is required');
		//alert (jQuery( $(tr).find("td").eq(7).children("input:first-child")).valid());

				// save detail only
				 var tr = $(me).parent().parent();
			 var v =$(tr).find("td").eq(7).children("input:last-child").val();
		  	  if (v<1 || v > ($(tr).find("td").eq(4).text()- $(tr).find("td").eq(6).text()) || isNaN($(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text()) ) {
				  $(tr).find("td").eq(7).children("input:last-child").validationEngine('showPrompt', 'Qty received Incorrect');
			  }else {
				  $.ajax({
					  type: "POST",
					  data: {
						  receiveID : $("#receivedID").val(),

						  poDetailID : $(me).attr("data-podetailsid"),
						  itemID : $(tr).find("td").eq(0).attr("data-itemId"),
                                                  lineNo : $("#trInfos1").attr("data-currentRow")*1+1,
						  quantityReceivedTotal : $(tr).find("td").eq(6).text(),
						  description : $(tr).find("td").eq(2).text(),
						  quantityOrder : $(tr).find("td").eq(4).text(),
						  quantityReceived : $(tr).find("td").eq(7).children("input:last-child").val(),
						  unitPrice : accounting.unformat($(tr).find("td").eq(3).text()),
						  amount : accounting.unformat($(tr).find("td").eq(5).text())
				
						  },
					  url: "<?php echo base_url() ?>receiveItems/saveNewItemDetailOnly",
					  success: function(data) {
						  var resul = eval ("(" + data + ")"); 
						  $("#poList").attr('disabled','disabled');
						  $("#supplier").attr('disabled','disabled');
						  msg("alert alert-success","Data saved successfully !!!")
						  var tr = $(me).parent().parent();
						  $(''+
						   '<tr>' +
							  '<td>' + ( $("#trInfos1").attr("data-currentRow")*1+1)  + '</td>'+
							  '<td>' +  $(tr).find("td").eq(1).text()  + '</td>'+
							  '<td>' +  $(tr).find("td").eq(2).text()  + '</td>'+
							  '<td class="amount">' +  $(tr).find("td").eq(4).text()  + '</td>'+
							  '<td class="quantity">' + $(tr).find("td").eq(7).children("input:last-child").val() + '</td>'+
							  '<td class="amount">' +  $(tr).find("td").eq(7).children("input:last-child").val()*$(tr).find("td").eq(4).text() + '</td>'+
							  '<td><button data-itemid="'+ $(tr).find("td").eq(0).attr("data-itemId") +'" data-myid="' + resul.detailID + '"  style="margin-right:3px;" onClick="editRow(this)" data-poDetailID="-1"  class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                               ' <button data-itemid="'+ $(tr).find("td").eq(0).attr("data-itemId") +'" data-myid="' + resul.detailID + '"  onClick="deleteRow(this)" data-poDetailID="-1"  class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                        '</td></tr>'
							).insertBefore( "#trInfos1" );
							delRow (me);
							getTotal ();
                                                        $("#trInfos1").attr("data-currentRow", $("#trInfos1").attr("data-currentRow")*1+1)
						  }
					  });
			  }
			
			}
                        
                        
 function getPoItems(){
                $("#divOpo").attr("style","display:block;");
		$('#outstandingItems tbody').empty();
		 $.ajax({
		  type: "POST",
		  data: {
			  poId : $("#poNumber").attr("data-id")
			  },
		  url: "<?php echo base_url() ?>receiveItems/getPoItemList",
		  success: function(data) {

			 var resul = eval ("(" + data + ")"); 
			 var n=resul.records.length;
			 var tcontent = "";
			 for (i=0;i<n;i++) {
				tcontent=tcontent + '<tr><td class="span1" data-itemId="'+ resul.records[i].itemId +'">' + resul.records[i].lineNo + '</td>' + 
				 		'<td class="span2">' + resul.records[i].itemName+ '[' + resul.records[i].itemCode + ']' + '</td>' + 
						'<td class="span2">' + resul.records[i].description + '</td>' + 
						'<td class="span1">' + resul.records[i].unitPrice + '</td>' + 
						'<td class="span1">' + resul.records[i].quantityOrder + '</td>' + 
						'<td class="span1">' + (resul.records[i].unitPrice*resul.records[i].quantityOrder)  + '</td>' + 
						'<td class="span1">' + resul.records[i].quantityReceivedTotal + '</td>' + 
						'<td class="span1"><input placeholder="R.:' + (resul.records[i].quantityOrder-resul.records[i].quantityReceivedTotal)  +'" name="" class="span12 validate[required,custom[integer], min[1], max[' + (resul.records[i].quantityOrder-resul.records[i].quantityReceivedTotal) +'] ]" type="text"/></td>' + 
						'<td class="span1"><button type="button" onclick="saveItemReceived(this)" data-poDetailsId="'+ resul.records[i].poDetailId  +'" class="btn btn-mini btn-primary"><i class="icon-ok icon-white"></i></button></td></tr>';
				
			}
			 
				$('#outstandingItems tbody').append(tcontent);
		  }
			
		 });	
	}
        
        function closediv(){
            $("#divOpo").attr("style","display:none;");
        }
</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() . "AccountPayables/home" ?>'> <?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('titlepo_received') ?></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="alert alert-info">
                    <strong><?php echo $this->lang->line('titlepo_received') ?></strong>
                </div>
            </div>

            <?php
            if ($receivItems) {
                $Purchaser = "";
                $memo = "";
                $shippingmetod = "";
                foreach ($receivItems as $rowIn) {
                    $Purchaser = $rowIn->employeeName;
                    $memo = $rowIn->memo;
                    $shippingmetod = $rowIn->shipping;
                    ?>    

                    <div class="row-fluid scRow">                            
                        <div class="span4 scCol">
                            <div class="block" id="grid_block_1">

                                <div class="content">

                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('formNo') ?></div>
                                        <div class="span8">
                                            <input type="hidden" id="receivedID"  value="<?php echo $rowIn->myid; ?>"  />
                                            <input type="text" class="span12" value="<?php echo $rowIn->reFormNo; ?>" disabled />
                                        </div>
                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('date') ?></div>
                                        <div class="span7">
                                            <input type="text" class="span12" value="<?php echo $rowIn->deliveryDate; ?>" disabled />
                                        </div>
                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('supplierDoNumber') ?></div>
                                        <div class="span8">
                                            <input type="text" class="span12" value="<?php echo $rowIn->supplierDoNo; ?>" disabled />
                                        </div><!-- span -->
                                    </div> <!-- row -->

                                </div><!-- content -->
                            </div><!-- grid block 1-->
                        </div><!-- scCol -->


                        <div class="span4 scCol">
                            <div class="block" id="grid_block_3">
                                <div class="content">
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('supplier') ?></div>
                                        <div class="span8">
                                            <input type="text" class="span12" value="<?php echo $rowIn->supplierName; ?>" disabled />
                                        </div>
                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('currency') ?></div>
                                        <div class="span8">
                                            <input type="text" class="span12" value="<?php echo $rowIn->currencyWord; ?>" disabled />
                                        </div><!-- span -->
                                    </div><!-- control row -->

                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('exchangeRate') ?></div>
                                        <div class="span8">
                                            <input type="text" class="span12" value="<?php echo $rowIn->exchangeRate; ?>" disabled />
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                </div><!-- content -->

                            </div><!-- grid block 1-->
                        </div><!-- scCol -->


                        <div class="span4 scCol">
                            <div class="block" id="grid_block_2">
                                <div class="content">
                                    <div class="controls-row">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('poList') ?></div>
                                            <div class="span8">
                                                <input type="text" class="span12" id="poNumber" data-id="<?php echo $rowIn->PoNO; ?>" value="<?php echo $rowIn->poFormNo; ?>" disabled />
                                            </div><!-- span -->

                                        </div><!-- row control -->

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('location') ?></div>
                                            <div class="span8">
                                                <input type="text" class="span12" value="<?php echo $rowIn->state; ?>" disabled />
                                            </div>
                                        </div> <!-- control -->

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('address') ?></div>
                                            <div class="span8">
                                                <input type="text" class="span12" value="<?php echo $rowIn->address; ?>" disabled />
                                            </div><!-- span -->
                                        </div><!-- row control -->
                                    </div><!-- content -->
                                </div><!-- grid block 1-->
                            </div><!-- scCol -->

                        </div><!-- row-fluid scRow-->

                    <?php
                    }
                } else {
                    ?>
                    <div class="alert alert-error">
                        Recieve Items Not found or uneditable !!!
                    </div>

<?php } ?>
     <div id="divOpo" style="display:none;" class="row-fluid scRow">                            
	  <div class="span12 scCol">
		<div class="block" id="grid_block_4">
	       <div class="head">
           	<h2><?php echo $this->lang->line('outstandingPo')?></h2>
           	<ul class="buttons">
            	<li><a class="block_toggle collapsed" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
                        	<span class="i-arrow-down-3"></span></a></li>
          	</ul>  
                
          </div><!-- head -->
          <div class="content np">
   				  <table id="outstandingItems" cellpadding="0" cellspacing="0" width="100%">
            			<thead>
                			<tr>
                       	 	<th>#</th>
                        	<th><?php echo $this->lang->line('item')?></th>
                        	<th><?php echo $this->lang->line('itemDesc')?></th>
                        	<th><?php echo $this->lang->line('unitPrice')?></th>
                        	<th><?php echo $this->lang->line('qtyOrder')?></th>
                                <th><?php echo $this->lang->line('amount')?></th>
                                <th><?php echo $this->lang->line('totalQtyReceive')?></th>
                        	<th><?php echo $this->lang->line('qtyReceive')?></th>
                        	<th><?php echo $this->lang->line('action')?></th>
                    		</tr>
                		</thead>
                		<tbody>
                			
               		</tbody>
           		  </table>
            <div class="footer">
            	<div class="side fr">
                	<div class="btn-group">
                    <button style="margin-right:6px;" onclick="closediv()" class="btn btn-mini btn-primary" type="button" name="validat">Close</button>
                    
       				</div><!-- btn group -->      
       			</div><!-- side fr -->      
       		</div><!-- footer -->      
          </div><!-- content -->
        </div><!-- grid block 1-->
      </div><!-- scCol -->
    </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('PoReceivedItems') ?></h2>
                                <ul class="buttons">
                                    <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="#" title="Add New"</a></li>
                                <li><a href="#" onclick="getPoItems()" title="Add New"><span class="i-plus-2"></span></a></li>
                                 </ul>
                            </div><!-- head -->

                            <div class="content np">
                <?php if ($receiveItemsDetails && $receivItems) { ?>
                                    <table id="t_listItemOrdered" cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th><?php echo $this->lang->line('item') ?></th>
                                                <th><?php echo $this->lang->line('itemDesc') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('unitPrice') ?></th>
                                                <th class="quantity"><?php echo $this->lang->line('qtyReceive') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('amount') ?></th>
                                                <th class="quantity"><?php echo $this->lang->line('action') ?></th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                            <?php
                                            $totalpayable = 0;
                                            $lastrow = 0;
                                            foreach ($receiveItemsDetails as $row) {
                                                if ($row->poDetailID > 0) {
                                                    if ($lastrow < $row->lineNo)
                                                        $lastrow = $row->lineNo;
                                                    ?>
                                                    <tr>
                                                        <td><?php echo $row->lineNo ?></td>
                                                        <td><?php echo $row->name . '[' . $row->itemCodee . ']' ?></td>
                                                        <td><?php echo $row->description ?></td>
                                                        <td class="amount"><?php echo number_format($row->unitPrice, 2) ?></td>
                                                        <td class="quantity"><?php echo $row->quantityReceived ?></td>
                                                        <td class="amount"><?php echo number_format($row->amount, 2) ?></td>
                                                        <td class="quantity">
                                                            <button data-itemid="<?php echo $row->itemid ?>" onClick="editRow(this)" data-poDetailID="<?php echo $row->poDetailID ?>" data-myid="<?php echo $row->myid; ?>" class="btn btn-mini"><i class="icon-pencil"></i></button>
                                                            <button data-itemid="<?php echo $row->itemid ?>" onClick="deleteRow(this)" data-poDetailID="<?php echo $row->poDetailID ?>" data-myid="<?php echo $row->myid; ?>" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>
                                                        </td>
                                                    </tr>
        <?php }
    } ?>

                                            <tr id="trInfos1"  data-currentRow="<?php echo $lastrow; ?>">
                                                <td colspan="7">
                                                    <div id="msg_div1" 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>
                                        </tbody>
                                    </table> 
                                    <?php
                                } else {
                                    ?>
                                    <div class="span12 alert alert-error">
                                        No items found !!!
                                    </div>

<?php } ?>  
                            </div><!-- grid block 1-->
                        </div><!-- scCol -->
                    </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('receivedItemsNoPo') ?></h2>
                                    <ul class="buttons">
                                        <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="#" title="Add New"</a></li>
                                <li><a href="#trInfos" onclick="addnewitemnotinpo()" title="Add New"><span class="i-plus-2"></span></a></li>
                                 </ul>
                                </div><!-- head -->

                                <div class="content np">
                                    <form id="frmReceiveItemNoPo" action="#"> 
<?php if ($receiveItemsDetails && $receivItems) { ?>
                                            <table id="t_listItemOrdered1" cellpadding="0" cellspacing="0" width="100%">
                                                <thead>
                                                    <tr>
                                                        <th>#</th>
                                                        <th><?php echo $this->lang->line('item') ?></th>
                                                        <th><?php echo $this->lang->line('itemDesc') ?></th>
                                                        <th class="amount"><?php echo $this->lang->line('unitPrice') ?></th>
                                                        <th class="quantity"><?php echo $this->lang->line('qtyReceive') ?></th>
                                                        <th class="amount"><?php echo $this->lang->line('amount') ?></th>
                                                        <th class="quantity"><?php echo $this->lang->line('action') ?></th>
                                                    </tr>
                                                </thead>
                                                <tbody id="tbodyitemNotInPo">

                                                    <?php
                                                    $totalpayable = 0;
                                                    $lastrow =0;
                                                    foreach ($receiveItemsDetails as $row) {
                                                        $totalpayable = $totalpayable + $row->amount;
                                                        
                                                        if ($row->poDetailID <= 0) {
                                                             if ($lastrow < $row->lineNo)
                                                                $lastrow = $row->lineNo;
                                                            ?>
                                                            <tr>
                                                                <td><?php echo $row->lineNo ?></td>
                                                                <td><?php echo $row->name . '[' . $row->itemCodee . ']' ?></td>
                                                                <td><?php echo $row->description ?></td>
                                                                <td class="amount"><?php echo number_format($row->unitPrice, 2) ?></td>
                                                                <td class="quantity"><?php echo $row->quantityReceived ?></td>
                                                                <td class="amount"><?php echo number_format($row->amount, 2) ?></td>
                                                                <td class="quantity">
                                                                    <button data-itemid="<?php echo $row->itemid ?>" onClick="editRow(this)" data-poDetailID="<?php echo $row->poDetailID ?>" data-myid="<?php echo $row->myid; ?>" class="btn btn-mini"><i class="icon-pencil"></i></button>
                                                                    <button data-itemid="<?php echo $row->itemid ?>" onClick="deleteRow(this)" data-poDetailID="<?php echo $row->poDetailID ?>" data-myid="<?php echo $row->myid; ?>" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>
                                                                </td>
                                                            </tr>
        <?php }
    } ?>

                                                </tbody>
                                                    <tr id="trInfos" data-currentRow="<?php echo $lastrow; ?>">
                                                        <td colspan="7">
                                                            <div id="msg_div1" 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>
                                            </table> 
    <?php
} else {
    ?>
                                            <div class="span12 alert alert-error">
                                                No items found !!!
                                            </div>

<?php } ?>
                                    </form>    
                                </div><!-- grid block 1-->
                            </div><!-- scCol -->
                        </div><!-- row-fluid scRow-->




<?php if ($receivItems) { ?>
                            <div class="row-fluid scRow">
                                <div class="span7 scCol">
                                    <div class="block" id="grid_block_4">
                                        <div class="content np">

                                            <div class="controls-row">
                                                <div class="span4"><?php echo $this->lang->line('purchaser') ?></div>
                                                <div class="span8">
                                                    <input type="text" class="span12" value="<?php echo $Purchaser; ?>" disabled />
                                                </div>
                                            </div><!-- row control -->

                                            <div class="controls-row">
                                                <div class="span4"><?php echo $this->lang->line('memo') ?></div>
                                                <div class="span8">
                                                    <textarea style="height: 75px;" id="memo" class="span12"><?php echo $memo; ?></textarea>
                                                </div><!-- span -->
                                            </div><!-- row control -->

                                        </div>    
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->

                                <div class="span5 scCol">
                                    <div class="block" id="grid_block_4">
                                        <div class="content np">     
                                            <div class="controls-row">
                                                <div class="span4"><?php echo $this->lang->line('shippingmethod') ?></div>
                                                <div class="span8">
                                                    <input type="text" class="span12" value="<?php echo $shippingmetod; ?>" disabled />
                                                </div><!-- span -->

                                            </div><!-- row control -->

                                            <div class="controls-row">
                                                <div class="span4"><?php echo $this->lang->line('totalPayable') ?></div>
                                                <div class="span8">
                                                    <input id="totalpayable" disabled="disabled"  class="span12 amount" type="text" value="<?php echo number_format($totalpayable, 2); ?>">
                                                </div>
                                            </div><!-- row control -->
                                        </div>    
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                            </div><!-- row-fluid scRow-->
<?php } ?>
                    </div><!-- grid 1 -->
                </div><!-- wrap -->
            </div><!-- content -->



