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

    .amount {
        text-align: right !important;
    }
    tbody td {
        font-size:11px;}


</style>
<script type="application/javascript">
   
   $(document).ready(function(){

<?php if (isset($customerID)): ?>
        //Auto selection of customer and invoice payment
        $('#payer').trigger('change');
<?php endif; ?>

        $('select').select2();
  /*****GST Register supplier's color change start******/    
  function format(state) {
    var text = state.text.match(/\(GST\)/g);
    var modTxt = state.text.replace("(GST)","");
    if(text != null)  return '<span style="color:#85c420;">'+modTxt+"</span>";
    else              return modTxt;
  }
  $("#payer").select2({
    formatResult: format,
    formatSelection: format,
    escapeMarkup: function(m) { return m; }
  });
  /*****GST Register supplier's color change end******/
        $.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 refreshProject(){
        $.ajax({
        type: "POST",
        url: "<?php echo base_url() ?>project/refreshProject",
        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].projectName + '</option>';
        $('#project').empty();
        $('#project').append(opt);
        }
        });
    }
    
    function displaybanksInfos() {
       $("#acctNo").val($("#bank option:selected").attr("data-bankAccountNo"));
   }
    
    function  activateOrDesactivate(me){
        if($(me).is(':checked')){
             var tr = $(me).parent().parent();
              v = $(tr).find("td").eq(4).text();
             $(tr).find("td").eq(5).children("input:last-child").removeAttr("disabled");
              $(tr).find("td").eq(5).children("input:last-child").val(v).focus();
        }else{
            var tr = $(me).parent().parent();
            $(tr).find("td").eq(5).children("input:last-child").attr("disabled","disabled");
            $(tr).find("td").eq(5).children("input:last-child").val("");
        }
        getTotalDiscountAndTotalApplied();
        updateOtherCharges();
    }
    
    function  activateOrDesactivate_note(me){
        if($(me).is(':checked')){
             var tr = $(me).parent().parent();
              v = $(tr).find("td").eq(5).text();
             $(tr).find("td").eq(6).children("input:last-child").removeAttr("disabled");
              $(tr).find("td").eq(6).children("input:last-child").val(v).focus();
        }else{
            var tr = $(me).parent().parent();
            $(tr).find("td").eq(6).children("input:last-child").attr("disabled","disabled");
            $(tr).find("td").eq(6).children("input:last-child").val("");
        }
        getTotalDiscountAndTotalApplied();
        updateOtherCharges();
    }
    
    function copyAmntReceive(){
        $("#amountreceive").val(accounting.formatNumber(accounting.unformat($("#totalapplied").val()) + accounting.unformat($("#totalotherschargesCopy").val()),2));
        updateTotalReceive();
    }
    
    function loadPayerDetailsValue(){
        $("#row_list_debitnote").addClass("hide");
        $("#row_list_creditnote").addClass("hide");
        $("#row_list_histo").addClass("hide");
        $("#bodyListPendingInvoices").empty();
        $("#liste_credit_note_body").empty();
        $("#liste_debit_note_body").empty();
        $("#liste_histo_body").empty();
        
        $.ajax({
            type: "POST",
            data: "payer=" + $("#payer").val(),
            url: "<?php echo base_url() ?>artransaction/loadPayerDetailsValue",
            success: function(data) {
                
                var rs = eval ("(" + data + ")"); 
                var n =rs.recordSet.length;// (rs.recordSet.length == undefined) ? 0: rs.recordSet.length;
               
                $("#currency").val(rs.currency);
                $("#exchange_rate").val(accounting.formatNumber(rs.exchangeRate,5));
                $("#previewOutOfBalance").val("0.00");
                nList = 0;
                var tbody='';
                if(n > 0)
                for (i=0;i<n;i++){
                    tbody=tbody + '<tr>' + 
                                  '    <td>' + (++nList) + '</td>' +
                                  '    <td>' + rs.recordSet[i].formNo + '</td>' +
                                  '    <td>' + rs.recordSet[i].salesInvoiceDate + '</td>' +
                                  '    <td class="amount">' + accounting.formatNumber(rs.recordSet[i].totalamount, 2)  + '</td>' +
                                  '    <td class="amount">' + accounting.formatNumber(rs.recordSet[i].totalReceivable, 2)  + '</td>' +
                                  '    <td><input onkeyup ="getTotalDiscountAndTotalApplied()" disabled type="text" class="span12 amount" /> </td>' +
                                  '    <td><input id="checkBox'+rs.recordSet[i].ID+'" data-invoiceid="'+ rs.recordSet[i].ID  +'" onchange="activateOrDesactivate(this)" type="checkbox" /> </td>' +
                                  '</tr>'
                }
                

                $("#bodyListPendingInvoices").append(tbody);
                
                var n = (rs.rsDebit.length ==undefined) ? 0: rs.rsDebit.length;
                if(n > 0){
                    $("#row_list_debitnote").removeClass("hide");
                     var tbody='', nList = 0;
                    for (i=0;i<n;i++){
                        tbody=tbody + '<tr>' + 
                                      '    <td>' + (++nList) + '</td>' +
                                      '    <td>' + rs.rsDebit[i].formNo + '</td>' +
                                      '    <td>' + rs.rsDebit[i].debitNoteDate + '</td>' +
                                      '    <td>' +  rs.rsDebit[i].invNo  + '</td>' +
                                      '    <td class="amount">' + accounting.formatNumber(rs.rsDebit[i].totalAmount, 2)  + '</td>' +
                                       '    <td class="amount">' + accounting.formatNumber(rs.rsDebit[i].total, 2)  + '</td>' +
                                      '    <td><input onkeyup ="getTotalDiscountAndTotalApplied()" disabled type="text" class="span12 amount" /> </td>' +
                                      '    <td><input id="checkBox'+rs.rsDebit[i].ID+'" data-debitnoteID="'+ rs.rsDebit[i].ID  +'" onchange="activateOrDesactivate_note(this)" type="checkbox" /> </td>' +
                                      '</tr>'
                    }

                    $("#liste_debit_note_body").append(tbody);
                    
                }
                
                 var n = (rs.rsCredit.length ==undefined) ? 0: rs.rsCredit.length;
                if(n > 0){
                    $("#row_list_creditnote").removeClass("hide");
                     var tbody='', nList = 0;
                    for (i=0;i<n;i++){
                        tbody=tbody + '<tr>' + 
                                      '    <td>' + (++nList) + '</td>' +
                                      '    <td>' + rs.rsCredit[i].formNo + '</td>' +
                                      '    <td>' + rs.rsCredit[i].creditNoteDate + '</td>' +
                                      '    <td>' +  rs.rsCredit[i].invNo  + '</td>' +
                                      '    <td class="amount">' + accounting.formatNumber(rs.rsCredit[i].totalAmount, 2)  + '</td>' +
                                       '    <td class="amount">' + accounting.formatNumber(rs.rsCredit[i].total, 2)  + '</td>' +
                                      '    <td><input onkeyup ="getTotalDiscountAndTotalApplied()" disabled type="text" class="span12 amount" /> </td>' +
                                      '    <td><input id="checkBox'+rs.rsCredit[i].ID+'" data-creditnoteID="'+ rs.rsCredit[i].ID  +'" onchange="activateOrDesactivate_note(this)" type="checkbox" /> </td>' +
                                      '</tr>'
                    }

                    $("#liste_credit_note_body").append(tbody);
                    }
                    
                    var n=rs.rsHisto.length;
                    nList = 0;
                    var tbody='';
                    if(n>0){
                    $("#row_list_histo").removeClass("hide");
                    for (i=0;i<n;i++){
                        
                        tbody=tbody + '<tr>' + 
                                      '    <td>' + (++nList) + '</td>' +
                                      '    <td>' + rs.rsHisto[i].formNo +  '</td>' +
                                      '    <td>' + rs.rsHisto[i].invoiceDate + '</td>' +
                                      '    <td>' + rs.rsHisto[i].invNo + '</td>' +
                                      '    <td class="amount">' + accounting.formatNumber(rs.rsHisto[i].totalAmount, 2)  + '</td>' +
                                      '    <td class="amount">' + accounting.formatNumber(rs.rsHisto[i].totalReceivable, 2)  + '</td>' +
                                      '    <td><input onkeyup ="getTotalDiscountAndTotalApplied()" disabled type="text" class="span12 amount" /> </td>' +
                                      '    <td class="center"><input data-historicalinvoiceID="'+ rs.rsHisto[i].ID  +'" onchange="activateOrDesactivate_note(this)" type="checkbox" /> </td>' +
                                      '</tr>'
                    }
                    $("#liste_histo_body").append(tbody);
                }
                
<?php if (isset($invoiceID)): ?>
                        $('#checkBox<?php echo $invoiceID; ?>').prop("checked",true).trigger('change');
                        var $container = $("html,body");
                        var $scrollTo = $('#checkBox<?php echo $invoiceID; ?>');
                        $container.animate({scrollTop: $scrollTo.offset().top - $container.offset().top, scrollLeft: 0},500,function(){
                            $scrollTo.parents('tr').find('td:nth-child(6) input').focus();
                        });
<?php endif; ?>
            }
        });
    }
    
    function selecOrUnselecttAll(me){
        if($(me).is(':checked')){
           $("#listDetails > tbody > tr").each (function(){
              var tr = $(this);
              v = $(tr).find("td").eq(4).text();
              $(tr).find("td").eq(5).children("input:last-child").val("0");
              $(tr).find("td").eq(6).children("input:last-child").val(v);
              $(tr).find("td").eq(7).children("input:last-child").prop("checked",true);
              $(tr).find("td").eq(5).children("input:last-child").removeAttr("disabled");
             $(tr).find("td").eq(6).children("input:last-child").removeAttr("disabled");
           });
        }else {
            $("#listDetails > tbody > tr").each (function(){
              var tr = $(this);
              v = $(tr).find("td").eq(4).text();
              $(tr).find("td").eq(5).children("input:last-child").val("");
              $(tr).find("td").eq(6).children("input:last-child").val("");
              $(tr).find("td").eq(7).children("input:last-child").prop("checked",false);
              $(tr).find("td").eq(5).children("input:last-child").attr("disabled","disabled");
             $(tr).find("td").eq(6).children("input:last-child").attr("disabled","disabled");
            });
        }
        getTotalDiscountAndTotalApplied();
    }
    
    function getTotalDiscountAndTotalApplied(){
        var  totalAppliedInvoice = 0, totalApplied = 0, totalDebit = 0, totalCredit = 0, totalHisto = 0;
        
        $("#listDetails > tbody > tr").each (function(){
            var tr = $(this);
            var ck = $(tr).find("td").eq(6).children("input:last-child");
            if($(ck).is(':checked')){
                totalAppliedInvoice += accounting.unformat($(tr).find("td").eq(5).children("input:last-child").val())*1;
            }
        });
        
        $("#liste_debit_note > tbody > tr").each (function(){
            var tr = $(this);
            var ck = $(tr).find("td").eq(7).children("input:last-child");
            if($(ck).is(':checked')){
                totalDebit += accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
            }
        });
        
         $("#liste_Credit_note > tbody > tr").each (function(){
            var tr = $(this);
            var ck = $(tr).find("td").eq(7).children("input:last-child");
            if($(ck).is(':checked')){
                
                totalCredit += accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
            }
        });
        
        $("#list_histo_invoice > tbody > tr").each (function(){
            var tr = $(this);
            var ck = $(tr).find("td").eq(7).children("input:last-child");
            if($(ck).length){
                 totalHisto += accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
            }
        });
        
        
        
        
        totalApplied = totalAppliedInvoice + totalHisto - totalCredit + totalDebit;
        bankcharges = accounting.unformat($("#bankcharges").val());
        $("#totalapplied").val(accounting.formatNumber(totalApplied, 2));
        $("#totalreceived").val(accounting.formatNumber(totalApplied+bankcharges, 2));
        $("#amountreceive").val(accounting.formatNumber(totalApplied, 2));
        
        
        $("#totalappliedHistoInvoice").val(accounting.formatNumber(totalHisto, 2));
        $("#totalappliedInvoice").val(accounting.formatNumber(totalAppliedInvoice, 2));
        $("#totalappliedDebit").val(accounting.formatNumber(totalDebit, 2));
        $("#totalappliedCredit").val(accounting.formatNumber(totalCredit, 2));
        
    }
     
    
    function updateTotalReceive(){
        var tRec = accounting.unformat($("#previewOutOfBalance").val())*1 + accounting.unformat($("#amountreceive").val())*1;   
        if (isNaN(ob))
            ob =0;
        if (isNaN(tRec))
            tRec = 0;
        $("#totalreceived").val(accounting.formatNumber(tRec, 2));
        var ob = accounting.unformat($("#totalreceived").val()) - accounting.unformat($("#totalapplied").val()) - accounting.unformat($("#totalotherscharges").val());
        $("#outofbalance").val(accounting.formatNumber(ob, 2));
    }
    
    function updateOtherCharges(){
       
        bankcharges = accounting.unformat($("#bankcharges").val());
        totalapplied = accounting.unformat($("#totalapplied").val());
        
         $("#totalreceived").val(accounting.formatNumber(totalapplied+bankcharges, 2));
         //updateTotalReceive();
    }
    
    function getSelecteddebitnote(){
         pDetails ='{"debit":[';
            firstime = true;
            $("#liste_debit_note > tbody > tr").each (function(){
                var tr = $(this);
                var ck = $(tr).find("td").eq(7).children("input:last-child");

                if($(ck).is(':checked')){
                    str ='';
                    if (firstime){
                     firstime = false;
                     str = ''
                    }else {
                       firstime = false;
                        str = ',' 
                    }
                     
                    mntApplied = accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
                    balance = accounting.unformat($(tr).find("td").eq(5).text())-mntApplied;
                    pDetails += str + '{"debitnoteID":"' + $(ck).attr("data-debitnoteID") + '"' +
                                        ',"amountApplied":"' + mntApplied + '"' +
                                        ',"balance":"' + balance + '"}'
                }
            });
            pDetails += ']}';
            return pDetails;
    }
    
    function getSelectedcreditnote(){
         pDetails ='{"credit":[';
            firstime = true;
            $("#liste_Credit_note > tbody > tr").each (function(){
                var tr = $(this);
                var ck = $(tr).find("td").eq(7).children("input:last-child");

                if($(ck).is(':checked')){
                    str ='';
                    if (firstime){
                     firstime = false;
                     str = ''
                    }else {
                       firstime = false;
                        str = ',' 
                    }
                     
                    mntApplied = accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
                    balance = accounting.unformat($(tr).find("td").eq(5).text())-mntApplied;
                    pDetails += str + '{"creditnoteID":"' + $(ck).attr("data-creditnoteID") + '"' +
                                        ',"amountApplied":"' + mntApplied + '"' +
                                        ',"balance":"' + balance + '"}'
                }
            });
            pDetails += ']}';
            return pDetails;
    }
    
    function getSelectedHisto(){
         pDetails ='{"histo":[';
            firstime = true;
            $("#list_histo_invoice > tbody > tr").each (function(){
                var tr = $(this);
                var ck = $(tr).find("td").eq(7).children("input:last-child");

                if($(ck).is(':checked')){
                    str ='';
                    if (firstime){
                     firstime = false;
                     str = ''
                    }else {
                       firstime = false;
                        str = ',' 
                    } 
                     
                    mntApplied = accounting.unformat($(tr).find("td").eq(6).children("input:last-child").val())*1;
                    balance = accounting.unformat($(tr).find("td").eq(5).text())-mntApplied;
                    pDetails += str + '{"invoiceID":"' + $(ck).attr("data-historicalinvoiceid") + '"' +
                                        ',"amountApplied":"' + mntApplied + '"' +
                                        ',"balance":"' + balance + '"}'
                }
            });
            pDetails += ']}';
            return pDetails;
    }
    
    function savePayment(){
       var outOfbalance = accounting.unformat($("#outofbalance").val());
        if (outOfbalance ==0){
        if( $("#paymentForm").validationEngine('validate') && finanEngine('financhk')){
            pDetails ='{"rs":[';
            firstime = true;
            $("#listDetails > tbody > tr").each (function(){
                var tr = $(this);
                var ck = $(tr).find("td").eq(6).children("input:last-child");

                if($(ck).is(':checked')){
                    str ='';
                    if (firstime){
                     firstime = false;
                     str = ''
                    }else {
                       firstime = false;
                        str = ',' 
                    }
                    arBalance = accounting.unformat($(tr).find("td").eq(4).text())*1;
                    mntApplied = accounting.unformat($(tr).find("td").eq(5).children("input:last-child").val())*1;
                    pDetails += str + '{"invoiceID":"' + $(ck).attr("data-invoiceid") + '"' +
                                        ',"amountApplied":"' + mntApplied + '"' +
                                        ',"arBalance":"' + arBalance + '"}';
                }
            });
            pDetails += ']}';

            $.ajax({
                type: "POST",
                data: {
                  memo: $("#memo").val(),
                  customerID: $("#payer").val(),
                  currencyID: $("#payer option:selected").attr("data-currencyID"),
                  exchangeRate: $("#exchange_rate").val(),
                  projectID: $("#project").val(),
                  formNo: $("#formNo").val(),
                  receivePaymentDate: $("#createdDate").val(),
                  bankID: $("#bank").val(),
                  //outOfBalance: accounting.unformat($("#outofbalance").val()),
                  amountReceived:  accounting.unformat($("#amountreceive").val()),
                  paymentMethodID: $("#paymentmethod").val(),
                  referenceNo: $("#refno").val(),
                  bankCharges:  accounting.unformat($("#bankcharges").val()),
                  totalDiscount:  accounting.unformat($("#totaldiscount").val()),
                  totalOtherCharge:  accounting.unformat($("#totalotherscharges").val()),
                  totalApplied:  accounting.unformat($("#totalapplied").val()),
                  pdetail : pDetails,
                  creditNote: getSelectedcreditnote(),
                  debitNote: getSelecteddebitnote(),
                  histo: getSelectedHisto()
                },
                url: "<?php echo base_url() ?>arTransaction/saveNewReceivePayment",
                success: function(data) {
                    if (data>0){ 
                        $("#btnSave").attr("class"," btn-form btn-success-form disabled");
                        $("#btnSave").attr("style","display:none;");
                        //$("#msgDiv").attr("class","alert alert-success");
                        //$("#msgDiv").html("Well Done !!! Payment Successfully created ");
						
                                                var urls = "<?php echo base_url(); ?>artransaction/newReceivePayment";
                                                window.location = urls;
                    } else {
                        $("#msgDiv").attr("class","alert alert-error");
                        $("#msgDiv").html("Oops !!! fail to insert data ");
                    }
                }
            });
        }
        }else{
            alert("Out of Balance must be 0");
        }
    }
function refreshPayMethod(){
        $.ajax({
        type: "POST",
        url: "<?php echo base_url() ?>OthersPayment/refreshPayMethod",
        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].name + '</option>';
                $('#paymentmethod').empty();
                $('#paymentmethod').append(opt);
        }
   });	
}

</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() . "AccountReceivables" ?>'> <?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('title') ?></li>
                </ul>
            </div>
            <div class="search">
                <form action="<?php echo base_url() ?>admin/search" method="post">
                    <input name="search_text" type="text" placeholder="search..."/>                                
                    <button type="submit"><span class="i-magnifier"></span></button>
                </form>
            </div>     
        </div><!-- head --> 
        <div class="content" id="grid_content_1">
            <form id="paymentForm" action="#">    

                <div class="block">
                    <div class="head">
                        <h2><strong><?php echo $this->lang->line('title') ?></strong></h2>
						<!--akmal 20151105. disable minimize button to avoid save when box is closed -->
						<!--ul class="buttons">
							<li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
						</ul-->
                    </div><!-- head -->
                    <div class="content np">
                        <div class="row-fluid scRow">     

                            <div class="span6 scCol">
                                <div class="block" id="grid_block_1">
                                    <div class="controls-row">
                                        <div class="span3"><?php echo $this->lang->line('formno') ?></div>
                                        <div class="span2">
                                            <input class="span12 validate[required]" id="formNo" name="formNo" value='<?php echo "$formNo"; ?>' 
                                                   style="color:red;" type="text" placeholder="Form number ...">
                                        </div>
                                        <div class="span6">
                                            <input  class="span11" type="text" placeholder="Serial" disabled="disabled">
                                        </div>
                                    </div> <!-- row -->									
                                    <div class="controls-row">
                                        <div class="span3"><?php echo $this->lang->line('date') ?></div>
                                        <div class="span9">
                                            <div class="input-prepend span10"><span class="add-on span2"><i class="i-calendar"></i></span>
                                                <?php
                                                $data = array(
                                                    'name' => 'createdDate',
                                                    'id' => 'createdDate',
                                                    'type' => 'text',
                                                    'onkeydown' => 'return false',
                                                    'class' => 'span10 datepicker2 validate[required] financhk',);
                                                echo form_input($data, date("d-m-Y"));
                                                ?>
                                            </div>
                                        </div>
                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span3"><?php echo $this->lang->line('bank') ?></div>
                                        <div class="span9">
                                            <select onchange="displaybanksInfos()" name="bank" id="bank" class="span10 validate[required]"><option></option>' +
                                                <?php
                                                if ($bankaccount) {
                                                    foreach ($bankaccount as $row) {
                                                        ?>
                                                        '<option data-currentBalance="<?php echo $row->currentBalance; ?>" data-bankAccountNo="<?php echo $row->bankAccountNo; ?>"  value="<?php echo $row->ID; ?>"><?php echo $row->bankShortName . " | ";
                                                echo str_replace(array("\n", "\r", "'"), " ", $row->branch, $count);
                                                        ?></option>'+
                                                    <?php }
                                                }
                                                ?>
                                            </select>
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                    <div class="controls-row">
                                        <div class="span3"><?php echo $this->lang->line('acctno') ?></div>
                                        <div class="span9">
                                            <input id="acctNo" class="span10 tar" disabled="disabled" name="acctNo" type="text" placeholder="" >
                                        </div><!-- span -->
                                    </div><!-- control row -->                           
                                    <div class="controls-row">
                                        <div class="span3"><?php echo $this->lang->line('payer') ?></div>
                                        <div class="span9">
                                            <select class="span10 validate[required]" id="payer" onchange="loadPayerDetailsValue(this)"><option></option>
                                                <?php
                                                if ($customer) {
                                                    foreach ($customer as $row) {
                                                        ?>
                                                        <option <?php echo (isset($customerID) && $customerID == $row->ID) ? 'selected="selected"' : ''; ?> value="<?php echo $row->ID; ?>"> <?php echo $row->customerName;
                                                echo ($row->gstRegNo != '' && $row->gstRegNo != '0') ? ' (GST)' : ''; ?></option>
    <?php }
}
?>
                                            </select>
                                        </div>
                                    </div> <!-- row -->                          
                                </div><!-- grid block 1-->
                            </div><!-- scCol -->

                            <div class="span6 scCol">
                                <div class="block" id="grid_block_2">
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('project') ?></div>
                                        <div class="span8">
                                            <select id="project" class="span10"><option></option>
                                                <?php
                                                if ($project != '') {
                                                    foreach ($project as $row) {
                                                        ?>
                                                        <option value="<?php echo $row->ID; ?>"><?php echo $row->project_name; ?></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">
                                                    <!-- dropdown menu links -->
                                                    <li><a target="_blank" href="<?php echo base_url() ?>project/ProjectSetup"  id="btnNewPro">
                                                            <i class="i-plus-3"></i><?php echo $this->lang->line('addnewproject') ?></a></li>
                                                    <li><a href="javascript:" onclick="refreshProject()">
                                                            <i class="i-ccw"></i><?php echo $this->lang->line('refreshlist') ?></a></li>
                                                </ul>
                                            </div><!-- btn group -->
                                        </div>
                                    </div> <!-- row control -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('amountreceive') ?></div>
                                        <div class="span8">
                                            <input ondblclick="copyAmntReceive()" onkeyup="updateTotalReceive()" id="amountreceive" name="amountreceive" type="text" 
                                                   placeholder="0.00" class="span10 amount validate[required]" readonly>            
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('refno') ?></div>
                                        <div class="span8">
                                            <input id="refno" name="refno" type="text" placeholder="Ref No" class="span10">            
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('paymentmethod') ?></div>
                                        <div class="span8">
                                            <select  id="paymentmethod" class="span10 validate[required]"><option></option>
                                                <?php
                                                if ($paymentmethod) {
                                                    foreach ($paymentmethod as $row) {
                                                        ?>
                                                        <option value="<?php echo $row->ID; ?>"> <?php echo $row->name; ?></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">
                                                    <!-- dropdown menu links -->
                                                    <li><a target="_blank" href="<?php echo base_url() ?>setting/masterCodeSetup"  id="btnLocation">
                                                            <i class="i-plus-3"></i><?php echo $this->lang->line('addpaymethod') ?></a></li>
                                                    <li><a href="#" onclick="refreshPayMethod()">
                                                            <i class="i-ccw"></i><?php echo $this->lang->line('refreshlist') ?></a></li>
                                                </ul>
                                            </div> <!-- btnn group -->
                                        </div><!-- span -->
                                    </div><!-- control row -->                           
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('currency') ?></div>
                                        <div class="span8">
                                            <input id="currency" class="span10 validate[required]" name="currency" type="text" disabled="disabled" placeholder="Currency" >            
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('exchangerate') ?></div>
                                        <div class="span8">
                                            <input id="exchange_rate" class="span10 validate[required] tar"  name="exchange_rate" type="text" placeholder="Example: 3.20000" />
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                </div><!-- grid block 2-->
                            </div><!-- span6 scCol -->
                        </div><!-- row-fluid scRow-->

                        <div class="row-fluid scRow">                            
                            <div class="span12 scCol">
                                <div class="block ns" id="grid_block_3">
                                    <div class="controls-row"><!-- Row 4-->
                                        <div class="span1"><?php echo form_label($this->lang->line('memo'), 'memo'); ?></div>
                                        <div class="span11">
<?php
$data = array(
    'name' => 'memo',
    'id' => 'memo',
    'class' => 'span12',);
echo form_input($data);
?>
                                        </div>
                                    </div><!-- End Row 4-->
                                </div><!--block_3 -->
                            </div><!--span12 scCol -->
                        </div><!--row-fluid scRow -->
                    </div><!-- content np -->
                  </div>
                    <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('listofinvoices') ?></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="listDetails" cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th><?php echo $this->lang->line('invoiceno') ?></th>
                                                <th><?php echo $this->lang->line('invoicedate') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('totalamount') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('arbalance') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('amountapplied') ?></th>
                                                <th><input type="checkbox" /></th>
                                            </tr>
                                        </thead>
                                        <tbody id="bodyListPendingInvoices">
                                        </tbody>
                                    </table>     
                                </div><!-- content np -->
                            </div><!-- grid block 4-->
                        </div><!-- scCol -->
                    </div><!-- row-fluid scRow-->

                    <div id="row_list_debitnote" class="row-fluid scRow hide">                            
                        <div class="span12 scCol">
                            <div class="block" >
                                <div class="head">
                                    <h2><?php echo $this->lang->line('list_debit_note') ?></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="liste_debit_note" cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th><?php echo $this->lang->line('formno') ?></th>
                                                <th><?php echo $this->lang->line('date') ?></th>
                                                <th><?php echo $this->lang->line('invno') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('total_amount') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('balance') ?></th>
                                                <th class="amount"><?php echo $this->lang->line('amountapplied') ?></th>
                                                <th><input  type="checkbox" /></th>
                                            </tr>
                                        </thead>
                                        <tbody id="liste_debit_note_body">
                                        </tbody>
                                    </table>     
                                </div><!-- content -->
                            </div><!-- grid block 4-->
                        </div><!-- scCol -->
                    </div><!-- row-fluid scRow-->
<?php //akmal20151105. remove list of credit note from ar payment
/*
                    <div id="row_list_creditnote" class="row-fluid scRow hide">                            
                        <div class="span12 scCol">
                            <div class="block" >
                                <div class="head">
                                    <h2>Lists Of Credit Note</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="liste_Credit_note" cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Form No.</th>
                                                <th>Date </th>
                                                <th>Invoice No</th>
                                                <th class="amount">Total Amount</th>
                                                <th class="amount">Balance</th>
                                                <th class="amount"><?php echo $this->lang->line('amountapplied') ?></th>
                                                <th><input  type="checkbox" /></th>
                                            </tr>
                                        </thead>
                                        <tbody id="liste_credit_note_body">
                                        </tbody>
                                    </table>     
                                </div><!-- content np -->
                            </div><!-- grid block 4-->
                        </div><!-- scCol -->
                    </div><!-- row-fluid scRow-->
 */ ?>                    
                    <div id="row_list_histo" class="row-fluid hide">
                    <div class="span12 scCol">
                        <div class="block" id="grid_block_4">
                            <div class="head">
                                <h2><?php echo $this->lang->line('pending_histo_inv') ?></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="list_histo_invoice" cellpadding="0" cellspacing="0" width="100%">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th><?php echo $this->lang->line('totalAmounts') ?></th>
                                            <th><?php echo $this->lang->line('date') ?></th>
                                            <th><?php echo $this->lang->line('invno') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('total_amount') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('balance') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('amount_aplied') ?></th>
                                            <th><input type="checkbox" readonly /></th>
                                        </tr>
                                    </thead>

                                    <tbody id="liste_histo_body">
                                    </tbody>
                                </table>          
                            </div>                            
                        </div><!-- content-->
                    </div><!-- grid block 3-->
                </div><!-- row-fluid scRow-->

                </div><!-- block -->
      
        <div class="content">    
            <div class="row-fluid scRow">  
                <div class="span12 scCol">
                    <div class="block">

                        <div class="head">
                            <h2><?php echo $this->lang->line('totalAmounts') ?></h2>
                            <ul class="buttons">
                                <li><a href="#" class="block_toggle"><span class="i-arrow-down-3"></span></a></li>
                            </ul>
                        </div>

                        <div class="content np">				
                            <div class="span6 scCol">
                                <div class="block" id="grid_block_4">							
                                    <div class="content np">
                                        <div class="controls-row">
                                            <div class="span5"><?php echo $this->lang->line('total_inv_applied') ?></div>
                                            <div class="span7">
                                                <input id="totalappliedInvoice" class="span12 amount validate[required min[1]]" type="text" disabled="disabled"  placeholder="0">
                                            </div>
                                        </div><!-- row control -->
                                         <div class="controls-row">
                                                    <div class="span5"><?php echo $this->lang->line('total_histo_applied') ?></div>
                                                    <div class="span7">
                                                        <input id="totalappliedHistoInvoice"  class="span12 amount validate[required min[1]]" type="text" readonly="readonly"  placeholder="0">
                                                    </div>
                                                </div><!-- row control -->
                                        <div class="controls-row">
                                            <div class="span5"><?php echo $this->lang->line('total_debitnote_applied') ?></div>
                                            <div class="span7">
                                                <input id="totalappliedDebit" class="span12 amount validate[required min[1]]" type="text" disabled="disabled"  placeholder="0">
                                            </div>
                                        </div><!-- row control -->
                                        <!--div class="controls-row">
                                            <div class="span5">Total Credit Note Applied</div>
                                            <div class="span7">
                                                <input id="totalappliedCredit" class="span12 amount validate[required min[1]]" type="text" disabled="disabled"  placeholder="0">
                                            </div>
                                        </div--><!-- row control -->
                                    </div>
                                </div><!-- grid block 1-->
                            </div><!-- span6 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('totalapplied') ?></div>
                                            <div class="span8">
                                                <input id="totalapplied" class="span12 amount validate[required min[1]]" type="text" disabled="disabled"  placeholder="0">
                                            </div>
                                        </div><!-- row control -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('bankcharges') ?></div>
                                            <div class="span8">
                                                <input id="bankcharges" class="span12 amount" type="text" onkeyup="updateOtherCharges()" placeholder="0" <?php echo $bankChargesReadOnly; ?>>
                                            </div>
                                        </div><!-- row control -->
                                        <div class="controls-row">
                                            <div class="span4"><?php echo $this->lang->line('totalreceived') ?></div>
                                            <div class="span8">
                                                <input onchange="updateTotalReceive()" id="totalreceived" class="span12 amount" type="text" placeholder="0" disabled="disabled" >
                                            </div>
                                        </div><!-- row control -->
                                    </div>    
                                </div><!-- grid block 1-->
                            </div><!-- span6 scCol -->					
                        </div><!-- content np-->
                        <div class="footer">
                            <div class="side fr">
                                <div class="btn-group">
<?php
$data = array(
    'name' => 'validat',
    'class' => 'btn-form btn-warning-form',
    'onClick' => "$('#validate').validationEngine('hide');");
echo form_button($data, 'Hide prompts');
?>
                                    <a id="btnSave" onclick="savePayment()" class="btn-form btn-success-form"><?php echo $this->lang->line('save') ?></a>
                                </div><!-- btn group -->      
                            </div><!-- side fr -->      
                        </div><!-- footer --> 
                    </div><!-- block-->
                </div><!-- span12-->	
            </div><!--row-fluid scRow -->
        </div> <!--content total -->	


        </form>
    </div><!-- content class -->		
</div><!--wrap -->
</div><!--content id -->



