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

    .quantity {
        text-align: center;
    }

    .btn-group button{
        height:30px;}


    .input-prepend span, input-prepend button{
        height:18px;
        padding:3px;
    }
    #content .wrap #grid_content_1 .row-fluid.scRow .row-fluid.scRow .span12.scCol #grid_block_5 .content.np #listDetails tbody #trInfos td .row-fluid .controls-row .span3 {
        font-size: 11px;
        color: #000;
        font-weight: bold;
    }
    .test {
        font-size: 10px;
    }
    .span3 {
        font-size: 10px;
    }
    tbody td {
        font-size:11px;
    }
    #content .wrap #grid_content_1 .row-fluid.scRow .row-fluid.scRow .span12.scCol #grid_block_6 .content.np #listCharge tbody #trInfosCharge td .row-fluid .controls-row .span3 {
        font-weight: bold;
    }
</style>

<script>
    function taxPopup () {
    $('#popupModal').modal('show');
            $("#_popupTitle").html("Purchase Invoice");
            $("#_popupContent").html('' +
            '<label>Select a tax</label>' +
            '<select onclick="calculamount()" name="listTaxPopup" id="listTaxPopup"  class= "validate[required]"><option></option>' +
<?php
if ($taxmaster) {
    foreach ($taxmaster as $row2) {
        ?>
            '<option data-taxcode="<?php echo $row2->code ?>" value="<?php echo $row2->ID; ?>" data-tax="' + <?php echo $row2->taxPercentage; ?> + '">' +
                    '<?php echo $row2->code . " | " . $row2->taxPercentage . " | ";
        echo str_replace("'", " ", $row2->name, $count); ?></option>' +
    <?php }
} ?>
    '</select>');
            $('#_popupFooter').empty();
            $('#_popupFooter').append('<button class="btn btn-primary" id="confButton">Ok</button>' +
            '<button class="btn" id="canb">Cancel</button>');
            $("#_popupTitle").html("Tax Master");
            $("#canb").click(function() {
    $('#popupModal').modal('hide');
    });
            $("#confButton").click(function() {
    $('#popupModal').modal('hide');
            $("#itemTax").attr("data-taxid", $("#listTaxPopup").val());
            $("#itemTax").val ($("#listTaxPopup option:selected").attr("data-tax"));
            $("#displayTaxCode").html($("#listTaxPopup option:selected").attr("data-taxcode"));
            calculamount();
    });
    }

    function getItemDetails(me){
    $("#itemname").val("");
            $("#itemdes").val("");
            $.ajax({
            type: "POST",
                    data: "code=" + me.value,
                    url: "<?php echo base_url() ?>OthersPayment/getItemDetails",
                    success: function(data) {
                    if (data != "item Not found"){
                    var resul = eval ("(" + data + ")");
                            $("#itemcode").attr("itemID", resul.itemID);
                            $("#itemname").val(resul.name);
                            $("#itemdes").val(resul.description);
                            $("#itemTax").val(resul.tax);
                            $("#itemTax").attr("data-taxid", resul.taxID);
                            $("#displayTaxCode").text(resul.taxcode);
                    } else{
                    $("#itemcode").attr("itemID", ""),
                            $("#itemdes").attr("placeholder", data);
                            $("#itemname").attr("placeholder", data);
                            $("#itemTax").attr("data-taxid", "")
                            $("#itemTax").val("");
                            $("#itemTaxAmount").val("");
                            $("#itemAmountIT").val("");
                            $("#itemTax").attr("data-taxid", "");
                            $("#displayTaxCode").html("");
                    }
                    }
            });
    }

    function editRow(me){
    var tr = $(me).parent().parent();
            $(tr).replaceWith('<tr>' +
            '<td class="span1">' + $(me).parent().parent().find("td").eq(0).html() + '</td>' +
            '<td class="span1" >' +
            '<select class="span10" data-lineNo="' + $(me).parent().parent().find("td").eq(0).html() + '" data-previewvalue="' + $(me).parent().parent().find("td").eq(1).html() + '" 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="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"><input  id="itemunitprice" onkeyup="calculamount()" onchange="calculamount()" name="itemunitprice" class="span12" 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"><input id="itemqte"  onkeyup="calculamount()" onchange="calculamount()" name="itemqte"  class="span12" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(4).html() + '" value="' + $(me).parent().parent().find("td").eq(4).html() + '"></td>' +
            '<td class="span1"> <input id="itemAmountET" disabled name="itemAmountET" class="span12" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(5).html() + '" value="' + $(me).parent().parent().find("td").eq(5).html() + '"></td>' +
            '<td class="span1"><div  class="span12 input-prepend"><input data-previewvalue= "' + $(me).attr("data-taxcode") + ' | ' + $(me).attr("data-taxrate") + '"  value="' + $(me).attr("data-taxrate") + '" data-taxid="' + $(me).attr("data-taxid") + '" id="itemTax" onkeyup="calculamount()" onblur="calculamount()" name="itemTax" class="span7 validate[required, custom[number]]" type="text" placeholder="Tax(%)"><span id="displayTaxCode" style="margin-top:0;" onclick="taxPopup ()"  class="btn add-on">' + $(me).attr("data-taxcode") + '</span></div></td>' +
            '<td class="span1"><input onkeyup="calculamount()" disabled onchange="calculamount()" id="itemTaxAmount" name="itemTaxAmount" class="span12" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(7).html() + '" value="' + $(me).parent().parent().find("td").eq(7).html() + '"></td>' +
            '<td class="span1"><input onkeyup="calculamount()" disabled onchange="calculamount()" id="itemAmountIT" name="itemAmountIT" class="span12" type="text" data-previewvalue="' + $(me).parent().parent().find("td").eq(8).html() + '" value="' + $(me).parent().parent().find("td").eq(8).html() + '"></td>' +
            '<td class="span1">' +
            '<button data-itemid="' + $(me).attr("data-itemid") + '" onclick="updateRow(this)" data-itemid="' + $(me).attr("data-itemid") + '"  data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") + '" data-taxcode="' + $(me).attr("data-taxcode") + '" data-taxrate="' + $(me).attr("data-taxrate") + '" class="btn btn-mini btn-primary" type="button"><i class="icon-ok-circle"></i></button>' +
            '<button  id="btnCancel" data-taxcode="' + $(me).attr("data-taxcode") + '" data-itemid="' + $(me).attr("data-itemid") + '"  data-taxrate="' + $(me).attr("data-taxrate") + '" onclick="cancelEdit(this)" data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") + '"  class="btn btn-mini btn-danger" type="button"><i class="icon-remove-circle"></i></button></td>' +
            '</tr>');
            $("#itemComboList").val($(me).attr("data-itemid"));
            $("#itemComboList").select2();
    }

    function calculamount(){

    if ($("#itemTax").attr("data-taxid") == "") {
    taxPopup ();
    }
    var j_itemAmountET = accounting.unformat($("#itemunitprice").val()) * accounting.unformat($("#itemqte").val());
            $("#itemAmountET").val(accounting.formatNumber(j_itemAmountET, 2));
            var j_itemTaxAmount = j_itemAmountET * accounting.unformat($("#itemTax").val()) / 100;
            $("#itemTaxAmount").val(accounting.formatNumber(j_itemTaxAmount, 2));
            $("#itemAmountIT").val(accounting.formatNumber(j_itemTaxAmount + j_itemAmountET, 2));
    }

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

    function EndEdit(me){

    var dID = $(me).attr("data-itemId");
            $('' +
                    '<tr>' +
                    '<td>' + $("#itemComboList").attr("data-lineNo") + '</td>' +
                    '<td>' + $("#itemComboList option:selected").text() + '</td>' +
                    '<td>' + $("#itemdes").val() + '</td>' +
                    '<td>' + $("#itemunitprice").val() + '</td>' +
                    '<td>' + $("#itemqte").val() + '</td>' +
                    '<td>' + $("#itemAmountET").val() + '</td>' +
                    '<td>' + $("#itemTax").val() + '</td>' +
                    '<td>' + $("#itemTaxAmount").val() + '</td>' +
                    '<td>' + $("#itemAmountIT").val() + '</td>' +
                    '<td>' +
                    '<button data-itemid="' + $(me).attr("data-itemid") + '" data-taxcode="' + $(me).attr("data-taxcode") + '" data-taxrate="' + $(me).attr("data-taxrate") + '"  onClick="editRow(this)" data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                    ' <button onclick="deleteRow(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                    '</td>' +
                    '</tr>'
                    ).insertBefore("#trInfos");
            removeRow(me);
            getTotal ();
    }
    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"));
    }

    function cancelEdit(me){
    var tr = $(me).parent().parent();
            var dID = $(me).attr("data-itemId");
            $(tr).replaceWith('<tr>' +
            '<td>' + $("#itemComboList").attr("data-lineNo") + '</td>' +
            '<td>' + $("#itemComboList").attr("data-previewvalue") + '</td>' +
            '<td>' + $("#itemdes").attr("data-previewvalue") + '</td>' +
            '<td class="tar">' + $("#itemunitprice").attr("data-previewvalue") + '</td>' +
            '<td class="quantity">' + $("#itemqte").attr("data-previewvalue") + '</td>' +
            '<td class="tar">' + $("#itemAmountET").attr("data-previewvalue") + '</td>' +
            '<td>' + $("#itemTax").attr("data-previewvalue") + '</td>' +
            '<td class="tar">' + $("#itemTaxAmount").attr("data-previewvalue") + '</td>' +
            '<td class="tar">' + $("#itemAmountIT").attr("data-previewvalue") + '</td>' +
            '<td>' +
            '<button data-itemid="' + $(me).attr("data-itemid") + '"  data-taxcode="' + $(me).attr("data-taxcode") + '" data-taxrate="' + $(me).attr("data-taxrate") + '"  onClick="editRow(this)" data-taxid="' + $(me).attr("data-taxid") + '" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
            ' <button onclick="deleteRow(this)" data-myid="' + $(me).attr("data-myid") + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
            '</td>' +
            '</tr>'
            );
    }

    function getTotal (){

    var n = $("#listDetails > tbody > tr").length - 2;
            var totalAmount = 0;
            var impot = 0;
            var total = 0;
            var i = 0;
            for (i = 0; i <= n; i++) {

    totalAmount = totalAmount + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(5)').text()) * 1;
            impot = impot + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(7)').text()) * 1;
            total = total + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(8)').text()) * 1;
    }

    $("#totalallocated").val(accounting.formatNumber(totalAmount, 2));
            $("#totaltaxamount").val(accounting.formatNumber(impot, 2));
            $("#totalpaid").val(accounting.formatNumber(total, 2));
    }

    function updateRow(me){
    // alert($(me).attr("data-myid"));

    if ($("#itemcode").attr("itemID") == "")
            $("#itemname").val("");
            if ($("#paymentDetail").validationEngine('validate')){
    $.ajax({
    type: "POST",
            data: {
            invDetailsId :$(me).attr("data-myid"),
                    itemID:  $("#itemComboList").val(),
                    itemdescription: $("#itemdes").val(),
                    quantity : $("#itemqte").val(),
                    unitPrice: $("#itemunitprice").val(),
                    amountExcludedTax: $("#itemAmountET").val(),
                    taxID :  $("#itemTax").attr("data-taxid"),
                    taxRate: $("#itemTax").val(),
                    taxAmount: $("#itemTaxAmount").val(),
                    amountIncludedTax:$("#itemAmountIT").val()

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

    function removeRow(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 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="detButton">Ok</button>' +
            '<button class="btn" id="canb">Cancel</button>');
            $("#_popupTitle").html("Confirm delete");
            $("#canb").click(function() {
    $('#popupModal').modal('hide');
    });
            $("#detButton").click(function() {
    $('#popupModal').modal('hide');
            $.ajax({
            type: "POST",
                    data: {
                    rowID :$(me).attr("data-myid")
                    },
                    url: "<?php echo base_url() ?>OthersPayment/deletePaymentWithItem",
                    success: function(data) {
                    msg (1, "alert alert-success", "Details successfully deleted");
                            removeRow(me);
                    } });
            getTotal();
    });
    }

    function  addnewrow(){
    if (!$("#itemComboList").length) {
    $('' +
            '<tr>' +
            '<td>' + ($("#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="span2"><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]]" type="text" placeholder="Unit Priece"></td>' +
            '<td class="span1"><input id="itemqte" onkeyup="calculamount()"  name="itemqte" class="span12 validate[required,custom[integer]]" type="text" placeholder="Qty"></td>' +
            '<td class="span1"><input id="itemAmountET" name="itemAmountET" disabled class="input-mini validate[required]" type="text" placeholder="Amount (Exclude Tax)"></td>' +
            '<td class="span1"><div  class="input-prepend"><input data-taxid="" id="itemTax" onkeyup="calculamount()" name="itemTax" class="span6 validate[required, custom[number]]" type="text" placeholder="Tax(%)"><span onclick="taxPopup ()" style="margin-top:0;" id="displayTaxCode"  class="btn add-on">....</span></div></td>' +
            '<td class="span1"><input id="itemTaxAmount" name="itemTaxAmount" disabled class="span12" type="text" placeholder="Tax Amount"></td>' +
            '<td class="span1"><input id="itemAmountIT" name="itemAmountIT" disabled class="span12" type="text" placeholder="Amount (Include Tax)"></td>' +
            '<td class="span1">' +
            '<button tilte="Save" class="btn btn-mini btn-primary" onclick="savepaymentnewrow()" type="button"> <i class="icon-ok-circle"></i> </button>' +
            '<button title="Cancel" id="btnCancel" class="btn btn-mini btn-danger" onclick="removeRow(this)" type="button"><i class="icon-remove-circle"></i></button>' +
            '</td>' +
            '</tr>'
            ).insertBefore("#trInfos");
            $("#itemComboList").select2();
    } else{
    msg (1, "alert", "Please, do save the current details before addind new one");
    }
    }
    
    function savepaymentnewrow(){
         $.ajax({
            type: "POST",
            data: {
                      otherPaymentID : $("#otherPaymentId").val(),
                      
                      itemID : $("#itemComboList").val(),
                      lineNo : $("#trInfos").attr("data-currentRow")*1+1,
                      itemdescription: $("#itemdes").val(),
                      quantity : $("#itemqte").val(),
                      unitPrice: accounting.unformat($("#itemunitprice").val()),
                      amountExcludedTax: accounting.unformat($("#itemAmountET").val()),
                      taxAmount: accounting.unformat($("#itemTaxAmount").val()),
                      amountIncludedTax: accounting.unformat($("#itemAmountIT").val()),
                      taxID: $("#itemTax").attr("data-taxid"),
                      taxRate: $("#itemTax").val()

                    },
            url: "<?php echo base_url() ?>OthersPayment/savenewpaywithItemDetailOnly",
            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">' + $("#itemunitprice").val() + '</td>'+
                    '<td>' + $("#itemqte").val() + '</td>'+
                    '<td class="amount">' + $("#itemAmountET").val() + '</td>'+
                    '<td>' + $("#displayTaxCode").text() + " | " +  $("#itemTax").val() + '</td>'+
                    '<td class="amount">' + $("#itemTaxAmount").val() + '</td>'+
                    '<td class="amount">' + $("#itemAmountIT").val() + '</td>'+
                    '<td>' +
                    '<button data-itemid="' + $("#itemComboList").val() + '"  data-taxcode="' + $("#displayTaxCode").text() + '" data-taxrate="' + $("#itemTax").val() + '"  onClick="editRow(this)" data-taxid="' + $("#itemTax").attr("data-taxid") + '" data-myid="' + resul.detailID + '" class="btn btn-mini"><i class="icon-pencil"></i></button>' +
                    ' <button onclick="deleteRow(this)" data-myid="' + resul.detailID + '" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>' +
                    '</td>' +
            '</tr>'
            ).insertBefore( "#trInfos" );
              $("#btnCancel").trigger("click");
              $("#trInfos").attr("data-currentRow",($("#trInfos").attr("data-currentRow")*1+1));
              getTotal();
              msg (1,"alert alert-success","Details successfully saved");
       }
    }); //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('titleEditOpWithItem') ?></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('titleEditOpWithItem') ?></strong>
                </div>
            </div>
<?php
$memo = "";
if ($otherPay) {
    foreach ($otherPay as $row) {
        $memo = $row->memo;
        ?> 
                    <input type="hidden" id="otherPaymentId" value="<?php echo $row->pID; ?>" />
                    <div class="block">
                        <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('formno') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo $row->formNo; ?>" class="span12" />             
                                            </div><!-- span -->
                                        </div><!-- control row -->


                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('date') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo date(element('dtFormat', $this->session->userdata('logged_in')), strtotime($row->paymentDate)); ?>" class="span12" />             
                                            </div><!-- span -->
                                        </div><!-- control row -->



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

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

                                <div class="span4 scCol">
                                    <div class="block" id="grid_block_3">
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('amountpaid') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo number_format($row->amountPaid, 2); ?>" class="span12" />
                                            </div>
                                        </div> <!-- row -->

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

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('location') ?></div>
                                            <div class="span8">
                                                <textarea class="span12" disabled="disabled" ><?php echo $row->code . ' | ' . $row->address; ?></textarea>
                                            </div>
                                        </div> <!-- row -->
                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                                <div class="span4 scCol">
                                    <div class="block ns" id="grid_block_2">

                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('bank') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo $row->bankShortName . ' | ' . $row->branch; ?>" class="span12" />            
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('acctno') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo $row->bankAccountNo; ?>" class="span12" />            
                                            </div><!-- span -->
                                        </div><!-- control row -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('balance') ?></div>
                                            <div class="span8">
                                                <input disabled="disabled" type="text" value="<?php echo $row->currentBalance; ?>" class="span12" />             
                                            </div><!-- span -->

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



                                    </div><!-- grid block 1-->
                                </div><!-- scCol -->
                            </div><!-- row-fluid scRow-->

                        </div><!-- content -->

                    </div><!-- block-->
    <?php }
} ?>

            <div class="row-fluid scRow">                            
                <div class="span12 scCol">
                    <div class="block" id="grid_block_4">
                        <div class="head">
                            <h2><?php echo $this->lang->line('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="#" title="Add New"</a></li>
                                <li><a href="#trInfos" onclick="addnewrow()" title="Add New"><span class="i-plus-2"></span></a></li>
                            </ul>
                        </div><!-- head -->
                        <div class="content np">
                            <form id="paymentDetail" action="#">
                                <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="tar"><?php echo $this->lang->line('amountExcludeTax') ?></th>
                                            <th><?php echo $this->lang->line('tax') ?></th>
                                            <th class="tar"><?php echo $this->lang->line('taxAmount') ?></th>
                                            <th class="tar"><?php echo $this->lang->line('amountIncludeTax') ?></th>
                                            <th class="tac"><?php echo $this->lang->line('action') ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
<?php
$tAllocated = 0;
$t_taxAmount = 0;
$tpaid = 0;
 $lastrow = 0;
if ($pdetails) {
    foreach ($pdetails as $rowDetail) {
        $tpaid += $rowDetail->amountIncludedTax;
        if ($lastrow < $rowDetail->lineNo)
                    $lastrow = $rowDetail->lineNo;
        $t_taxAmount+= $rowDetail->taxAmount;
        $tAllocated += $rowDetail->amountExcludedTax;
        ?>
                                                <tr>
                                                    <td><?php echo $rowDetail->lineNo; ?></td>
                                                    <td><?php echo $rowDetail->name . "[" . $rowDetail->itemCode . "]"; ?></td>
                                                    <td><?php echo $rowDetail->itemdescription; ?></td>
                                                    <td class="tar"><?php echo number_format($rowDetail->unitPrice, 2); ?></td>
                                                    <td class="tar"><?php echo number_format($rowDetail->quantity); ?></td>
                                                    <td class="tar"><?php echo number_format($rowDetail->amountExcludedTax, 2); ?></td>
                                                    <td><?php echo $rowDetail->taxCode . " | " . $rowDetail->taxRate; ?></td>
                                                    <td class="tar"><?php echo number_format($rowDetail->taxAmount, 2); ?></td>
                                                    <td class="tar"><?php echo number_format($rowDetail->amountIncludedTax, 2); ?></td>
                                                    <td class="quantity">
                                                        <button onClick="editRow(this)"  data-itemid="<?php echo $rowDetail->itemID; ?>"
                                                                data-taxcode="<?php echo $rowDetail->taxCode; ?>" data-taxrate="<?php echo $rowDetail->taxRate; ?>"
                                                                data-taxid="<?php echo $rowDetail->taxID; ?>" data-myid="<?php echo $rowDetail->pDetailID; ?>" class="btn btn-mini"><i class="icon-pencil"></i></button>
                                                        <button onClick="deleteRow(this)" data-myid="<?php echo $rowDetail->pDetailID; ?>" class="btn btn-mini btn-danger"><i class="icon-trash icon-white"></i></button>
                                                    </td>
                                                </tr>
    <?php }
} else {
    ?>
                                        <div class="alert alert-error">
    <?php echo $this->lang->line('message1') ?>
                                        </div>
                                        <?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>
                                    </tbody>
                                </table> 
                            </form>    
                        </div><!-- content -->
                    </div><!-- grid block 1-->
                </div><!-- scCol -->
            </div><!-- row-fluid scRow-->

            <div class="row-fluid scRow"> 
                <div class="span6 scCol">
                    <div class="block" id="grid_block_4">
                        <div class="content np">
                            <div class="controls-row">
                                <div class="span12">
                                    <textarea  placeholder="<?php echo $this->lang->line('memo') ?>" style="height: 170px;" id="memo" class="span12"><?php echo $memo; ?></textarea>
                                </div><!-- span -->
                            </div><!-- row control -->

                        </div>    
                    </div><!-- grid block 1-->
                </div><!-- scCol -->        
                <div class="span6 scCol">
                    <div class="block" id="grid_block_4">
                        <div class="content np">
                            <div class="controls-row">

                                <div class="span4"><?php echo $this->lang->line('totalallocated') ?></div>
                                <div class="span8">
                                    <input id="totalallocated" class="span12 amount" value="<?php echo number_format($tAllocated, 2); ?>" type="text" placeholder="0" disabled="disabled" >
                                </div>
                            </div><!-- row control -->
                            <div class="controls-row">
                                <div class="span4"><?php echo $this->lang->line('totaltaxamount') ?></div>
                                <div class="span8">
                                    <input id="totaltaxamount" value="<?php echo number_format($t_taxAmount, 2); ?>" class="span12 amount" type="text" disabled="disabled"  placeholder="0">
                                </div>
                            </div><!-- row control -->
                            <div class="controls-row">
                                <div class="span4"><?php echo $this->lang->line('totalpaid') ?></div>
                                <div class="span8">
                                    <input id="totalpaid" disabled="disabled" value="<?php echo number_format($tpaid, 2); ?>" class="span12 amount" type="text" placeholder="0">
                                </div>
                            </div><!-- row control -->
                            <div class="controls-row">
                                <div class="span4"><?php echo $this->lang->line('outofbalance') ?></div>
                                <div class="span8">
                                    <input id="outofbalance" disabled="disabled"  class="span12 amount" type="text" placeholder="0">
                                </div>
                            </div><!-- row control -->

                        </div>    
                    </div><!-- grid block 1-->
                </div><!-- scCol -->
            </div><!-- row-fluid scRow--></div><!-- grid 1 -->
    </div><!-- wrap -->
</div><!-- content -->


