<style type="text/css">
    .amount{
        text-align: right;
    }
    .input-prepend span, btn-group button, 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 .span4 {
        font-size: 11px;
        color: #000;
        font-weight: bold;
    }
    .test {
        font-size: 10px;
    }
    .span4 {
        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 #listCharge tbody #trInfosCharge td .row-fluid .controls-row .span4 {
        font-weight: bold;
    }
</style>

<script>
$(document).ready(function(){
    $('.datepicker2').datepicker({
        dateFormat : 'dd-mm-yy',
        changeMonth : true,
        changeYear : true
    }); 
});    
    function getLatestItemPrice(){
     /*$.ajax({
            type: "POST",
            data : {
                option :'purchase',
                itemID : $("#itemComboList").val(),
                datePrice : $("#createdDate").val(),
                supplierID : $("#supplier").attr("data-supplierID")
            },
            url: "<?php echo base_url() ?>aptransaction/getPrice",
            success: function(data) {
                $("#itemunitprice").val(accounting.formatNumber(data,2));
            }
      });*/
    $.ajax({
            type: "POST",
            data : {
                option :'purchase',
                itemID : $("#itemComboList").val(),
                datePrice : $("#createdDate").val(),
                supplierID : $("#supplier").attr('data-supplierid')
            },
            url: "<?php echo base_url() ?>aptransaction/getUmList",
            dataType:'JSON',
            success: function(data) {
                //console.log(data['unitPrice'][0].price);
                if(!$('.umIDlist').length){
                    var tr = $("#itemComboList").parents('tr');
                    $(tr).find('td:nth-child(6)').html('<select class="umIDlist span12"></select>');
                    $('.umIDlist').select2();
                }
                
                if(data['unitPrice']){
                    $("#itemunitprice").val(accounting.formatNumber(data['unitPrice'][0].price,2));
                }
                
                var option = '<option value="'+data['items'][0].unitOfMeasureID+'" >'+data['items'][0].umCode+'</option>';
                if(data['umConv']){
                    for(i = 0; i<data['umConv'].length; i++){
                        option += '<option value="'+data['umConv'][i].from_um+'">'+data['umConv'][i].fromCode+'</option>';
                    }
                }
                $('.umIDlist').select2('destroy').html(option);
                $('.umIDlist').select2();
                calculamount();
            }
      });
}

    function editRow(me){
        //if(select){
            $.ajax({
                type: "POST",
                data : {
                    itemID : $(me).attr("data-itemid"),
                },
                url: "<?php echo base_url() ?>po_transaction/getUmList",
                dataType:'JSON',
                success: function(data) {
                    var option = '<option value="'+data['items'][0].unitOfMeasureID+'" >'+data['items'][0].umCode+'</option>';
                    if(data['umConv']){
                        for(i = 0; i<data['umConv'].length; i++){
                            option += '<option value="'+data['umConv'][i].from_um+'">'+data['umConv'][i].fromCode+'</option>';
                        }
                    }
                    var select = '<select class="umIDlist span12">'+
                                            option+
                                            '</select>';

                    console.log($(tr).find('td:nth-child(6)').text());
                    //$(meObj).find('td:nth-child(6)').text('').append(select); 
                    //drawRow(select,meObj);                   
                    //  alert( $(me).parent().parent().find("td").eq(0).html()); 

                    var tr = $(me).parent().parent();
                    var unit = $(tr).find('.umID').val();
                    $(tr).replaceWith('<tr><td class="span1">' + $(me).parent().parent().find("td").eq(0).html() + '</td>' +
                    '<td class="span2" >' +
                    '<select data-numrow="' + $(me).parent().parent().find("td").eq(0).html() + '" id="itemComboList" \n\
                    data-previewvalue="' + $(me).parent().parent().find("td").eq(1).html() + '" class="span12" onchange="displaysItemDefaultValue()"><option></option>' +
                    <?php
                    if ($items) {
                        foreach ($items as $row) {
                            ?>
                                '<option data-desc= "<?php echo addslashes($row->description); ?>" data-price= "<?php echo $row->supplierPrice; ?>" value="<?php echo $row->ID; ?>"><?php
                            echo str_replace(array("\n", "\r","'"), " ", $row->name, $count)
                            . " [" . str_replace(array("\n", "\r","'"), " ", $row->itemCode, $count) . "]";
                            ?></option>' +
                        <?php
                        }
                    }
                    ?>
                        '</select></td>' +
                    '<td class="span2"><input id="itemdes" name="itemdes" class="span12" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(2).html() + '" value="' + $(me).parent().parent().find("td").eq(2).html() + '"></td>' +
                    '<td class="span1 tar"><input  id="itemunitprice" onkeyup="calculamount()" onchange="calculamount()" name="itemunitprice" class="span12 tar" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(3).html() + '" value="' + $(me).parent().parent().find("td").eq(3).html() + '"></td>' +
                    '<td class="span1 tar"><input id="itemqte"  onkeyup="calculamount()" onchange="calculamount()" name="itemqte"  class="span12 tar" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(4).html() + '" value="' + $(me).parent().parent().find("td").eq(4).html() + '"></td>' +
                    '<td>'+select+'</td>'+//select+
                    '<td class="span1 tar"> <input id="itemAmountET" name="itemAmountET" class="span12 tar" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(6).html() + '" value="' + $(me).parent().parent().find("td").eq(6).html() + '" readonly></td>' +
                    '<td class="span1 tac">' +
                    '<button data-itemid="' + $(me).attr("data-itemid") + '" data-myid="' + $(me).attr("data-myid") + '" onclick="updateRow(this)" class="btn-icon btn-mini btn-success-form" type="button"><i class="i-checkmark-3"></i></button>' +
                    '<br /><button data-itemid="' + $(me).attr("data-itemid") + '" data-myid="' + $(me).attr("data-myid") + '"  id="btnCancel"  onclick="cancelEdit(this)" class="btn-icon btn-mini btn-danger-form" type="button"><i class="i-cross"></i></button></td>' +
                    '</tr>'
                    );
                    $("#itemComboList").val($(me).attr("data-itemid"));
                    $("#itemComboList,.umIDlist").select2();
                    $('.umIDlist').select2('val',unit);
                }
          });
        //}  
    }

    function calculamount(){

    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 displaysItemDefaultValue(){
    $("#itemdes").val($("#itemComboList option:selected").attr("data-desc"));
            $("#itemunitprice").val(accounting.formatNumber($("#itemComboList option:selected").attr("data-price"), 2));
            $("#itemTax").val($("#itemComboList option:selected").attr("data-taxPercentage"));
            $("#itemTax").attr("data-taxid", $("#itemComboList option:selected").attr("data-taxid"));
            $("#displayTaxCode").text($("#itemComboList option:selected").attr("data-taxcode"));
            getLatestItemPrice() ;
    }

    function calculChargeAmount() {
    var t = accounting.unformat($("#chargeAmount").val()) * accounting.unformat($("#listTax option:selected").attr("data-tax")) / 100;
            $("#chargetaxAmount").val(t);
            $("#chargeAmountIT").val(t + $("#chargeAmount").val() * 1);
    }

    function EndEdit(me){
    var tr = $(me).parent().parent();
            $(tr).replaceWith('<tr>' +
            '<td>' + $("#itemComboList").attr("data-numrow") + '</td>' +
            '<td>' + $("#itemComboList option:selected").text() + '</td>' +
            '<td>' + $("#itemdes").val() + '</td>' +
            '<td class="amount tar">' + accounting.formatNumber($("#itemunitprice").val(), 2) + '</td>' +
            '<td class="tar">' + $("#itemqte").val() + '</td>' +
            '<td class="tac">' + $(".umIDlist").select2('data').text + '<input class="umID" type="hidden" value="'+$(".umIDlist").select2('val')+'"></td>' +
            '<td class="amounnt tar">' + accounting.formatNumber($("#itemAmountET").val(), 2) + '</td>' +
            '<td class="tac">' +
            '<button data-itemid="' + $(me).attr("data-itemid") + '" onClick="editRow(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-success-form"><i class="i-pen"></i></button>' +
            '<br /><button onclick="deletePoDetails(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>' +
            '</td>' +
            '</tr>'
            );
            getTotal ();
    }

    function cancelEdit(me){
    var tr = $(me).parent().parent();
            $(tr).replaceWith('<tr>' +
            '<td>' + $("#itemComboList").attr("data-numrow") + '</td>' +
            '<td>' + $("#itemComboList").attr("data-previewvalue") + '</td>' +
            '<td>' + $("#itemdes").attr("data-previewvalue") + '</td>' +
            '<td class="amounnt tar">' + accounting.formatNumber($("#itemunitprice").attr("data-previewvalue"), 2) + '</td>' +
            '<td class="tar">' + $("#itemqte").attr("data-previewvalue") + '</td>' +
            '<td class="tac">' + $(".umIDlist").select2('data').text + '<input class="umID" type="hidden" value="'+$(".umIDlist").select2('val')+'"></td>' +
            '<td class="amount tar">' + accounting.formatNumber($("#itemAmountET").attr("data-previewvalue"), 2) + '</td>' +
            '<td class="tac">' +
            '<button data-itemid="' + $(me).attr("data-itemid") + '" onClick="editRow(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-success-form"><i class="i-pen"></i></button>' +
            '<br /><button onclick="deletePoDetails(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>' +
            '</td>' +
            '</tr>'
            );
            getTotal ();
    }

    function getTotal (){

    var n = $("#listDetails > tbody > tr").length - 2;
            var total = 0;
            var i = 0;
            for (i = 0; i <= n; i++) {
                total = total + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(6)').text()) * 1;
            }

            $("#totalpayable").val(accounting.formatNumber(total, 2));
    }

    function updateRow(me){
    // alert($(me).attr("data-myid"));
        if(validateNewRow()){
            $.ajax({
                type: "POST",
                data: {
                poID :$(me).attr("data-myid"),
                        itemID:  $("#itemComboList").val(),
                        itemdescription: $("#itemdes").val(),
                        quantity : accounting.unformat($("#itemqte").val()),
                        unitPrice: accounting.unformat($("#itemunitprice").val()),
                        umID: $('.umIDlist').select2('val'),
                        amount: accounting.unformat($("#itemAmountET").val())

                },
                url: "<?php echo base_url() ?>PO_Transaction/updatePoDetail",
                success: function(data) {
                msg (1, "alert alert-success", "Details successfully updated");
                        EndEdit(me);
                } });
                getTotal();
        }
    }

    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 deletePoDetails(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-mini btn-success-form" id="detButton">Ok</button>' +
            '<button class="btn-form btn-mini 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: {
                    invDetailsId :$(me).attr("data-myid")
                    },
                    url: "<?php echo base_url() ?>PO_Transaction/deletePoRow",
                    success: function(data) {
                    msg (1, "alert alert-success", "Details successfully deleted");
                            delRowInvoice(me);
                    }
            });
            getTotal();
    });
    }



    function  deleteCompanyCharge(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-mini btn-success-form" id="detButton">Ok</button>' +
            '<button class="btn-form btn-mini 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: {
                    chargeID :$(me).attr("data-myid")
                    },
                    url: "<?php echo base_url() ?>PO_Transaction/deleteCharge",
                    success: function(data) {
                    msg (1, "alert alert-success", "Details successfully deleted");
                            delRowInvoice(me);
                            getTotal();
                            $.ajax({
                            type: "POST",
                                    data: {
                                    invoiceId : $("#PO_TransactionId").val(),
                                            totalPayable : $("#totalpayable").val(),
                                            totalTaxAmount :  $("#totalamount").val()
                                    },
                                    url: "<?php echo base_url() ?>PO_Transaction/updateInvoice",
                                    success: function(data) {
                                    //update the invoice after delete
                                    }
                            });
                    } });
    });
            getTotal ();
    }
    function addnewrow(){
    if (!$("#itemComboList").length) {
    $('' +
            '<tr><td class="span1">' + ($("#trInfos").attr("data-currentRow") * 1 + 1) + '</td>' +
            '<td class="span3" >' +
            '<select id="itemComboList" class="span10" onchange="displaysItemDefaultValue()"><option></option>' +
<?php
if ($items) {
    foreach ($items as $row) {
        ?>
            '<option data-desc= "<?php echo addslashes($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(array("\n", "\r","'"), " ", $row->name, $count)
        . " [" . str_replace(array("\n", "\r","'"), " ", $row->itemCode, $count) . "]";
        ?></option>' +
    <?php
    }
}
?>
    '</select>' +
            '<div class="btn-group span1">' +
            '<button class="btn-icon btn-small 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 amount validate[required,custom[number]]" type="text" placeholder="Unit Price"></td>' +
            '<td class="span1"><input id="itemqte" onkeyup="calculamount()"  name="itemqte" class="span12 amount validate[required,custom[integer]]" type="text" placeholder="Qty"></td>' +
            '<td></td>'+
            '<td class="span1"><input id="itemAmountET" name="itemAmountET" disabled class="span12 amount validate[required]" type="text" placeholder="Amount (Exclude Tax)"></td>' +
            '<td class="span1 tac">' +
            '<button class="btn-icon btn-mini btn-success-form" onclick="savenewrow(this)" type="button"><span class="i-checkmark-3"></span></button>' +
            '<br /><button id="btnCancel" class="btn-icon btn-mini btn-danger-form" onclick="delRowInvoice(this)" type="button"><span class="i-cross"></span></button>' +
            '</td>' +
            '</tr>'
            ).insertBefore("#trInfos");
            $("#itemComboList").select2();
    } else{
    msg (1, "alert", "Please, do save the current details before adding new one");
    }
    }

    function validateNewRow(){
        if($("#purchaseInvoiceId").val()  && $("#itemdes").val()  && $("#itemqte").val() > 0 && parseFloat($("#itemunitprice").val()) > 0){
            console.log($("#purchaseInvoiceId").val()+'---'+$("#itemdes").val()+'---'+$("#itemqte").val()+'---'+$("#itemunitprice").val());
            return true;
        }else{
            alert('Fill up the fields before continue');
            return false;
        }
    }

    function savenewrow(me){
        if(validateNewRow()){
            $(me).attr("disabled","disabled");
            $.ajax({
                type: "POST",
                data: {
                invoiceId : $("#purchaseInvoiceId").val(),

                lineNo:  $("#trInfos").attr("data-currentRow") *1 +1,
                itemID:  $("#itemComboList").val(),
                itemdescription: $("#itemdes").val(),
                quantity : $("#itemqte").val(),
                unitPrice: accounting.unformat($("#itemunitprice").val()),
                umID: $(".umIDlist").select2('val'),
                amount: accounting.unformat($("#itemAmountET").val())
                },
                url: "<?php echo base_url() ?>PO_Transaction/saveParchaseDetail",
                success: function(data) {
                msg (1,"alert alert-success","Details successfully saved");
                var resul = eval ("(" + data + ")");
                $(''+
                '<tr><td>' + ( $("#trInfos").attr("data-currentRow") *1 +1) + '</td>' +
                '<td>' +  $("#itemComboList option:selected").text() + '</td>'+
                '<td>' + $("#itemdes").val() + '</td>'+
                '<td class="amount tar">' + accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                '<td class="amount tar">' + $("#itemqte").val() + '</td>'+
                '<td class="tac">' + $(".umIDlist").select2('data').text + '<input class="umID" type="hidden" value="'+$(".umIDlist").select2('val')+'"></td>' +
                '<td class="amount tar">' + accounting.formatNumber($("#itemAmountET").val(),2) + '</td>'+
                '<td class="tac">'+
                 '<button data-itemid="' + $("#itemComboList").val() + '" onClick="editRow(this)" data-myid="' + resul.detailID + '" class="btn-icon btn-mini btn-success-form"><i class="i-pen"></i></button>' +
                '<br /><button onclick="deletePoDetails(this)" data-myid="' + resul.detailID  + '" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>' +
               '</td>'+
                '</tr>'
                ).insertBefore( "#trInfos" );
                $("#trInfos").attr("data-currentRow", $("#trInfos").attr("data-currentRow") *1 +1);
                $("#btnCancel").trigger("click");
                $( "#calcul" ).trigger( "click" );
                getTotal();

                }
            }); //end ajax
        }
    }

</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('titlepo') ?></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 = "";
$Purchaser = "";
if ($pInvoice) {
    foreach ($pInvoice as $rowIn) {
        $memo = $rowIn->memo;
        $Purchaser = $rowIn->employeeName;
        ?> 
                    <div class="block">
                        <div class="head">
     <h2><strong><?php echo $this->lang->line('titlepo') ?></strong></h2>
</div><!-- head -->
                        <div class="content">
                            <div class="row-fluid scRow">                            
                                <div class="span4 scCol">
                                    <div class="block ns" id="grid_block_1">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('supplier'); ?></div>
                                            <div class="span8">
                                                <input type="hidden" id="purchaseInvoiceId" value="<?php echo $rowIn->poID; ?>" class="span12" />
                                                <input id="supplier" data-supplierID="<?php echo $rowIn->supplierID; ?>" type="text" disabled value="<?php echo $rowIn->supplierName; ?>" class="span12" />
                                            </div>
                                        </div> <!-- row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('formNo') ?></div>
                                            <div class="span8">
                                                <input type="text" disabled value="<?php echo $rowIn->formNo; ?>" class="span12" />
                                            </div>
                                        </div> <!-- row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('date') ?></div>
                                            <div class="span8">
                                                <input id="createdDate" type="text" value="<?php echo date("d-m-Y", strtotime($rowIn->poDate)); ?>" class="span12 datepicker2" />
                                            </div>
                                        </div> <!-- row -->
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                                <div class="span4 scCol">
                                    <div class="block" id="grid_block_2">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('terms') ?></div>
                                            <div class="span8">
                                                <input type="text" disabled value="<?php echo $rowIn->termName; ?>" class="span12" />
                                            </div>
                                        </div> <!-- row -->

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('termsdesc') ?></div>
                                            <div class="span8">
                                                <textarea class="span12" disabled="disabled" id="termDescription"> <?php echo $rowIn->termDescription ?></textarea>
                                            </div>
                                        </div> <!-- row -->
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                                <div class="span4 scCol">
                                    <div class="block ns" id="grid_block_3">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('currency') ?></div>
                                            <div class="span8">
                                                <input type="text" disabled value="<?php echo $rowIn->currencyWord; ?>" class="span12" />      
                                            </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" disabled value="<?php echo number_format($rowIn->exchangeRate, 5); ?>" class="span12 tar" />           
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                         <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('shipto') ?></div>
                                            <div class="span8">
                                                <input type="text" disabled value="<?php echo $rowIn->shiptoAdress; ?>" class="span12 " />           
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        
                                    </div><!-- content -->
                                </div><!-- content -->
                            </div><!-- grid block 1-->
                        </div><!-- scCol -->
                        <div class="footer">
                            <div class="side fr">
                                <!-- Hidden because not necessary (Sayem-11-9-2014) -->
                                <div class="btn-group">
                                    <input type="submit" name="postloctrans" value="Update" class="btn btn-warning submit">
                                </div> <!-- btn group      -->
                            </div><!-- side fr -->      
                        </div><!-- footer --> 
                    </div><!-- row-fluid scRow-->

    <?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('items') ?></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> 
                            <ul class="buttons fr">
                                <li><a href="#trInfos" onclick="addnewrow()" title="Add New"><span class="i-plus-2"></span></a></li>
                            </ul>
                        </div><!-- head -->
                        <div class="content np">
                            <table id="listDetails" cellpadding="0" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th><?php echo $this->lang->line('item') ?></th>
                                        <th><?php echo $this->lang->line('itemDesc') ?></th>
                                        <th class="tar"><?php echo $this->lang->line('unitPrice') ?></th>
                                        <th class="tar"><?php echo $this->lang->line('quantity') ?></th>
                                        <th class="tac"><?php echo $this->lang->line('um') ?></th>
                                        <th class="tar"><?php echo $this->lang->line('amount') ?></th>
                                        <th class="tac"><?php echo $this->lang->line('action') ?></th>
                                    </tr>
                                </thead>
                                <tbody>
<?php
$t_taxAmount = 0;
$lastrow = 0;
if ($pdetails && $pInvoice) {
    foreach ($pdetails as $row) {
        if ($lastrow < $row->lineNo)
            $lastrow = $row->lineNo;
        $t_taxAmount+= $row->total;
        ?>
                                            <tr>
                                                <td><?php echo $row->lineNo; ?></td>
                                                <td><?php echo $row->name . "[" . $row->itemCode . "]"; ?></td>
                                                <td><?php echo $row->description; ?></td>
                                                <td class="tar"><?php echo number_format($row->unitPrice, 2); ?></td>
                                                <td class="tar"><?php echo $row->quantityOrder; ?></td>
                                                <td class="tac"><?php echo $row->code; ?><input class="umID" type="hidden" value="<?php echo $row->umID; ?>"></td>
                                                <td class="tar"><?php echo number_format($row->total, 2); ?></td>
                                                <td class="tac">
                                                    <button onClick="editRow(this)" data-itemid="<?php echo $row->itemid; ?>" data-myid="<?php echo $row->ID; ?>" class="btn-icon btn-mini btn-success-form"><i class="i-pen"></i></button><br />
                                                    <button onClick="deletePoDetails(this)" data-myid="<?php echo $row->ID; ?>" class="btn-icon btn-mini btn-danger-form"><i class="i-trashcan"></i></button>
                                                </td>
                                            </tr>
    <?php } ?>
     <tr  data-currentRow="<?php echo $lastrow; ?>" id="trInfos">
                                    <td colspan="11">
                                        <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>
<?php } else {
    ?>

                                <tr  data-currentRow="<?php echo $lastrow; ?>" id="trInfos">
                                    <td colspan="11">
                                        <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('message1') ?></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="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  disabled="disabled" value="<?php echo $Purchaser; ?>"  class="span12" type="text"/>
                                </div>
                            </div> <!-- row -->
                            <div class="controls-row">
                                <div class="span4"><?php echo $this->lang->line('memo') ?></div>
                                <div class="span8">
                                    <textarea class="span12" id="memo"><?php echo $memo; ?></textarea>
                                </div>
                            </div> <!-- row -->
                        </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('importDutyPayable') ?>--></div>
                                <div class="span8">
                                    <!--<input id="impotpayable"   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('totalAmount') ?></div>
                                <div class="span8">
                                    <input id="totalpayable" disabled="disabled"  value="<?php echo number_format($t_taxAmount, 2); ?>" class="span12 amount" type="text" placeholder="0">
                                </div>
                            </div><!-- row control -->
                            <div class="footer">
                                <div class="side fr">
                                    <!-- Hidden because not necessary (Sayem-11-9-2014) -->
                                    <!-- <div class="btn-group">
                                        <button id="calcul" onclick="getTotal()" class="btn btn-mini btn-warning" type="button"> 
                                            <i class="icon-ok-circle"></i><?php echo $this->lang->line('calTotal') ?></button>

                                    </div> --><!-- btn group -->      
                                </div><!-- side fr -->      
                            </div><!-- footer -->   
                        </div>    
                    </div><!-- grid block 1-->
                </div><!-- scCol -->
            </div><!-- row-fluid scRow-->


        </div><!-- grid 1 -->
    </div><!-- wrap -->
</div><!-- content -->


