<style >
    .amount{
        text-align: right !important;
    }

    .quantity {
        text-align: center !important;
    }
    .btn-group button {
        height:30px; }

    tbody td {
    font-size:11px;}


</style>
<?php 
if(!empty($taxmaster)){
    foreach($taxmaster as $k=>$v){
        $val = null;
        $val = array_search('OS',(array) $taxmaster[$k]);  
        if($val != null){
            $nonGstTaxID = $taxmaster[$k]->ID;
            break;
        }
    }
}else{
    $nonGstTaxID = 0;  
}
?>
<script type="application/javascript">
    var gstStatus = true;
   $(document).ready(function(){
                gstStatus = isGstRegistered(<?php echo element('compID', $this->session->userdata('logged_in')); ?>,'company');
                console.log(gstStatus);
                $('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;
                }
                $("#customer").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 getLatestItemPrice(){
          var qtyInvoice = parseFloat($("#itemInvoice").attr("data-qtyInvoice"))* $("#idUnitOfMeasure option:selected").attr("data-factor")/$("#idUnitOfMeasure option:selected").attr("data-unitm");
        $("#itemInvoice").val(accounting.formatNumber(qtyInvoice,0));
     /*$.ajax({
            type: "POST",
            data : {
                option :'sale',
                itemID : $("#itemComboList").val(),
                datePrice : $("#createdDate").val(),
                customerID : $("#customer").val()
            },
            url: "<?php echo base_url() ?>artransaction/getPrice",
            success: function(data) {
                $("#itemunitprice").val(accounting.formatNumber(data,2));
            }
      });*/
    }
  
      function displaysItemDefaultValue(){
        $("#itemdes").val($("#itemComboList option:selected").attr("data-desc"));
        $("#itemunitprice").val(accounting.formatNumber($("#itemComboList option:selected").attr("data-unitprice"),2));
        
        
     $("#itemInvoice").val($("#itemComboList option:selected").attr("data-exactQty"));
        $("#itemInvoice").attr("data-qtyInvoice", $("#itemComboList option:selected").attr("data-exactQty"));
        $("#itemqte").val("");
        
        if(gstStatus){
            $("#itemTax").val($("#itemComboList option:selected").attr("data-taxPercentage"));
            $("#itemTax").attr("data-taxid",$("#itemComboList option:selected").attr("data-taxid"));
            $("#displayTaxCode").text($("#itemComboList option:selected").attr("data-taxcode"));
        }
      //  getLatestItemPrice ();
      
       getItemListOfUM();
    }
     
function displaysCustomerInvoiceNo(){
    $("#cusinvoicenumber").val($('#CompInvNo option:selected').attr("data-cusinvno"));
    getSaleInoviceItemList();
}

function getCustomerInvoicelist(cusID){
    $.ajax({
        type: "POST",
        data : "customerID=" + cusID ,
        url: "<?php echo base_url() ?>arTransaction/getCompanyInvoiceList",
        success: function(data) {

        var resul = eval ("(" + data + ")"); 
        var n=resul.recordSet.length;
        var i=0;
        var opt='' +
        '<option></option>';
        for (i=0;i<n;i++)
            opt=opt + '<option data-cusinvno="' + resul.recordSet[i].customerPoNo + '" value="' + resul.recordSet[i].id + '">' + resul.recordSet[i].formNO + '</option>';
            $('#CompInvNo').empty();
            $('#CompInvNo').append(opt);
        }
      });
}
		
                                function refreshSupplier(){
                                    //<span style="color:#85c420;">'+modTxt+"</span>
                                  $.ajax({
                                    type: "POST",
                                    url: "<?php echo base_url() ?>supplier/refreshSupplier",
                                    success: function(data) {
                                    
                                       var resul = eval ("(" + data + ")"); 
                                               var n=resul.records.length;
                                               var i=0;
                                               var opt='' +
                                          '<option></option>';
                                                for (i=0;i<n;i++)
                                                  if(resul.records[i].gstRegNo != ''){
                                                    opt=opt + '<option value="' + resul.records[i].id + '">' + resul.records[i].supplierName + ' (GST)</option>';
                                                  }else{
                                                    opt=opt + '<option value="' + resul.records[i].id + '">' + resul.records[i].supplierName + '</option>';
                                                  }
                                      $('#supplier').empty();
                                              $('#supplier').append(opt);
                                    }
                                     });
                                   
                                }
				
				
                                function getItemCode(me){
                                        $.ajax({
                                                type: "POST",
                                                data: "itemCode="+$(me).val(),
                                                url: "<?php echo base_url() ?>item/getItemCodes",
                                                success: function(data) {
                                                   $("#itemcode").attr("data-source", data);
                                                }
                                         });
                                }
				
				
                                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 openModalAddSupplier(){
                                        $.ajax({
                                                type: "POST",
                                                url: "<?php echo base_url() ?>aptransaction/getSupplierNewForm",
                                                success: function(result) {
                                                        $("#_popupContent").empty();
                                                        $("#_popupContent").append(result);
                                                        $('#popupModal').modal('show');
                                                        $("#_popupTitle").html("New Supplier");
                                                        $("#popupModal").attr("style","width:900px;left:530px;");
                                                }
                                         });
                                }
				

    function saveSaleRowItem(me){
     if( $("#saleDetailsForm").validationEngine('validate') && finanEngine('financhk')){
            if ( $("#saleDebitNoteID").val()=="null"){
                    $(me).attr("disabled","disabled");
                    $.ajax({
                    type: "POST",
                    data: {

                          customerID : $("#customer").val(),
                          formNo : $("#formNo").val(),
                          debitNoteDate : $("#createdDate").val(),
                          salesInvoiceID : $("#CompInvNo").val(),
                          projectID: $("#project").val(),
                          exchangeRate : $("#exchange_rate").val(),
                          memo : $("#memo").val(),

                          lineNo:  $("#listDetails").attr("data-currentRow")*1+1,
                          
                           itemID : $("#itemComboList option:selected").attr("data-itemID"),
                               invoiceDetailID : $("#itemComboList").val(),
                               
                          itemdescription: $("#itemdes").val(),
                          quantity : $("#itemqte").val(),
                          umid : $("#idUnitOfMeasure").val(),
                          unitPrice: accounting.unformat($("#itemunitprice").val()),
                          amountExcludedTax: accounting.unformat($("#itemAmountET").val()),
                          taxID: $("#itemTax").attr("data-taxid"),
                          taxRate: $("#itemTax").val(),
                          taxAmount: accounting.unformat($("#itemTaxAmount").val()),
                          amountIncludedTax:accounting.unformat($("#itemAmountIT").val())

                            },
                     url: "<?php echo base_url() ?>artransaction/saveSaleDebitNoteItem",
                     success: function(data) {
                     var resul = eval ("(" + data + ")"); 
                      $("#saleDebitNoteID").val(resul.debitNoteID);
                      $(''+
                       '<tr>' +
                            '<td>' + ($("#listDetails").attr("data-currentRow")*1+1) + '</td>'+
                            '<td>' + $("#itemComboList option:selected").text() + '</td>'+
                            '<td>' + $("#itemdes").val() + '</td>'+
                             '<td class="tac">' +  $("#idUnitOfMeasure option:selected").text() + '</td>'+
                             '<td class="tac">' + $("#itemInvoice").val() + '</td>'+
                              '<td class="tac">' + $("#itemqte").val() + '</td>'+
                            '<td class="tar">' + accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                            '<td class="tar">' + $("#itemAmountET").val() + '</td>'+
                            '<td>' + $("#displayTaxCode").text() + " | " + $("#itemTax").val() + '</td>'+
                            '<td class="tar">' + $("#itemTaxAmount").val() + '</td>'+
                            '<td class="tar">' + $("#itemAmountIT").val() + '</td>'+
                            '<td>'+
                            '</td>'+
                          '</tr>'
                            ).insertBefore( "#trInfos" );
                            $("#listDetails").attr("data-currentRow", $("#listDetails").attr("data-currentRow")*1+1);
                            $("#btnCancel").trigger("click");
                            
                          msg (1,"alert alert-success","Details successfully saved");
                          getTotal();
                    } //end function
             });//end ajax
            }else{
            $(me).attr("disabled","disabled");
                    $.ajax({
                    type: "POST",
                    data: {
                              debitNoteID : $("#saleDebitNoteID").val(),
                            
                              lineNo:  $("#listDetails").attr("data-currentRow")*1+1,
                              
                               itemID : $("#itemComboList option:selected").attr("data-itemID"),
                               invoiceDetailID : $("#itemComboList").val(),
                              
                              itemdescription: $("#itemdes").val(),
                              quantity : $("#itemqte").val(),
                              umid : $("#idUnitOfMeasure").val(),
                              unitPrice: accounting.unformat($("#itemunitprice").val()),
                              amountExcludedTax: accounting.unformat($("#itemAmountET").val()),
                              taxID: $("#itemTax").attr("data-taxid"),
                              taxRate: $("#itemTax").val(),
                              taxAmount: accounting.unformat($("#itemTaxAmount").val()),
                              amountIncludedTax:accounting.unformat($("#itemAmountIT").val())

                            },
                    url: "<?php echo base_url() ?>artransaction/saveSaleDebitNoteItemDetailOnly",
                    success: function(data) {
                     msg (1,"alert alert-success","Details successfully saved");
                      var resul = eval ("(" + data + ")"); 
               $(''+
                     '<tr>' +
                            '<td>' + ($("#listDetails").attr("data-currentRow")*1+1) + '</td>'+
                            '<td>' + $("#itemComboList option:selected").text() + '</td>'+
                            '<td>' + $("#itemdes").val() + '</td>'+
                             '<td class="tac">' +  $("#idUnitOfMeasure option:selected").text() + '</td>'+
                             '<td class="tac">' + $("#itemInvoice").val() + '</td>'+
                              '<td class="tac">' + $("#itemqte").val() + '</td>'+
                            '<td class="tar">' + accounting.formatNumber($("#itemunitprice").val(),2) + '</td>'+
                            '<td class="tar">' + $("#itemAmountET").val() + '</td>'+
                            '<td>' + $("#displayTaxCode").text() + " | " + $("#itemTax").val() + '</td>'+
                            '<td class="tar">' + $("#itemTaxAmount").val() + '</td>'+
                            '<td class="tar">' + $("#itemAmountIT").val() + '</td>'+
                            '<td>'+
                            '</td>'+
                    '</tr>'
                ).insertBefore( "#trInfos" );
                $("#listDetails").attr("data-currentRow", $("#listDetails").attr("data-currentRow")*1+1);
                $("#btnCancel").trigger("click");
                getTotal();
               }
             }); //end ajax
            } //end if data valide
            }else {
                    msg (1,"alert alert-error", "Data incorrect or invalid ...");
            }

    }
				
                                function deleteCompanyDetail(me){
                                        $('#popupModal').modal('show');
                                        $("#_popupTitle").html("Confirm delete");
                                        $("#_popupContent").html("Your about to delete definively this row. <br/> Click on ok to confirm");
					
                                        $('#_popupFooter').empty();
                           $('#_popupFooter').append('<button class="btn-form btn-success-form" id="detButton">Ok</button>' +
                                        '<button class="btn-form btn-danger-form" id="canb">Cancel</button>');
                                        $("#_popupTitle").html("Confirm delete");
                                        $( "#canb" ).click(function() {
                                                $('#popupModal').modal('hide');
                                        });
                                        $( "#detButton" ).click(function() {
                                                $('#popupModal').modal('hide');
                                                $.ajax({
                                                type: "POST",
                                                data: "detailsId="+ $(me).attr("data-detailid"),
                                                url: "<?php echo base_url() ?>aptransaction/deleteDebitNoteDetail",
                                                success: function(data) {
                                                        msg (1,"alert alert-success","Data deleted succesfuly ...");
                                                        var td=me.parentNode;
                                                        var tr=td.parentNode;
                                                        var tBody=tr.parentNode;
                                                        tBody.removeChild(tr);
                                                        }
                                                });
                                        });
					
                                        $( "#calcul" ).trigger( "click" );
                                        }
				
                                function getItemDetails(me){
                                        $("#itemname").val("");
                                        $("#itemdes").val("");
                                        $.ajax({
                                                type: "POST",
                                                data: "code="+ me.value,
                                                url: "<?php echo base_url() ?>ItemSetup/getItemDetails",
                                                success: function(data) {
                                                        if(data!="item Not found"){
                                                                 var resul = eval ("(" + data + ")");
                                                                $("#itemname").val(resul.description);
                                                                $("#itemdes").val(resul.name);
                                                                $("#itemTax").val(resul.tax);
                                                                $("#itemTax").attr("data-taxid",resul.taxID);
                                                                $("#displayTaxCode").text(resul.taxcode); 
                                                        }else{
                                                                $("#itemdes").attr("placeholder",data);
                                                                $("#itemname").attr("placeholder",data);
                                                                $("#itemTax").val("");
                                                                $("#itemTaxAmount").val("");
                                                                $("#itemAmountIT").val("");
                                                                $("#itemTax").attr("data-taxid",""); 
                                                                $("#displayTaxCode").html("");
                                                                }
							
                                                }
                                         });
                                }
				 
                                function calculamountET(){
				
						
                                        $("#totalamount").val("");
					
                                        $("#impotpayable").val("");
					
                                        $("#totalpayable").val("");
                                        //if ($("#itemTax").attr("data-taxid")=="") {
                                        //	taxPopup ();
                                        //}
						
                                        var j_itemAmountET =accounting.unformat($("#itemunitprice").val())*accounting.unformat($("#itemqte").val());
					
					
                                        var j_itemTaxAmount=j_itemAmountET*accounting.unformat($("#itemTax").val())/100;
					
					
                                        if (!isNaN(j_itemAmountET))
                                                $("#itemAmountET").val(accounting.formatNumber(j_itemAmountET,2));
						
                                        if (!isNaN(j_itemTaxAmount))
                                                $("#itemTaxAmount").val(accounting.formatNumber(j_itemTaxAmount,2));
						
                                        $("#itemAmountIT").val(accounting.formatNumber(j_itemTaxAmount+j_itemAmountET,2));
					
                                        if (!isNaN(j_itemTaxAmount) && !isNaN(j_itemTaxAmount) )
                                                $("#itemAmountIT").val(accounting.formatNumber(j_itemTaxAmount+j_itemAmountET,2));	
					
                                }
				
                                function addRowInvoice(){                     
                                        if (!$("#itemdes").length) {
                                          if(gstStatus){
                                              var tax = '<td class="span1"><div  class="input-prepend"><input data-taxid="" id="itemTax" disabled onkeyup="calculamountET()" 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>';
                                          }else{
                                              var tax = '<td class="span1"><div  class="input-prepend"><input data-taxid="" id="itemTax" name="itemTax" disabled value="0" class="span6 validate[required, custom[number]]" type="text" placeholder="Tax(%)"><span style="margin-top:0;" id="displayTaxCode"  class="btn add-on">OS</span></div></td>';
                                          }
                                         $(''+
                                         '<tr><td>'+ ($("#listDetails").attr("data-currentRow")*1+1) +'</td>' +
                        '<td class="span2" >' +
                        '<select id="itemComboList" class="span12" onchange="displaysItemDefaultValue()">'+ $("#hiddentItemComboList").html() +'</select></td>'+
                        '<td class="span3"><input id="itemdes" name="itemdes" class="span12" type="text" placeholder="Description"></td>'+
                        '<td class="span1"><select onchange="getLatestItemPrice()" id="idUnitOfMeasure" class="span12 validate[required]"><option></option></select></td>'+
                         '<td class="span1"><input id="itemInvoice" disabled name="itemInvoice" class="span10 validate[required,custom[integer]]" type="text" placeholder="Qty Invoice"></td>'+
                         '<td class="span1"><input id="itemqte" onkeyup="calculamountET()"  name="itemqte" class="span12 validate[required,custom[integer]] tar" type="text" placeholder="Additional Qty"></td>'+
                        '<td class="span2"><input id="itemunitprice" onkeyup="calculamountET()" name="itemunitprice" class="span12 validate[required,custom[number]] tar" type="text" placeholder="Unit Priece"></td>'+
                        '<td class="span1"><input id="itemAmountET" disabled name="itemAmountET" onkeydown="return false;" class="span12 validate[required] tar" type="text" placeholder="Amount (Exclude Tax)"></td>'+
                        tax+
                        '<td class="span1"><input id="itemTaxAmount" disabled name="itemTaxAmount" onkeydown="return false;" class="span12 tar" type="text" placeholder="Tax Amount"></td>'+
                        '<td class="span2"><input id="itemAmountIT" disabled name="itemAmountIT" onkeydown="return false;" class="span12 tar" type="text" placeholder="Amount (Include Tax)"></td>'+
                        '<td class="span1">'+
                                                        '<button class="btn-icon btn-mini btn-success-form" onclick="saveSaleRowItem(this)" type="button"><i class="i-checkmark-3"></i></button>'+
                                                        ' <button id="btnCancel" class="btn-icon btn-mini btn-danger-form" onclick="delRow(this)" type="button"><i class="i-cross"></i></button>'+
                                                '</td>'+
                    '</tr>'
                                          ).insertBefore( "#trInfos" );
                                        $("#itemComboList").select2();
					
                                         $('#idUnitOfMeasure').select2();
    
    $.each($("#listDetails .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();
            });
        });

 
                                        }else{
                                                msg (1,"alert","Please, do save the current details before adding new one");
                                                }
                                }
 
  function getTotal (){
	  
         $("#totalamount").val("");
  
        $("#impotpayable").val("");
  
        $("#totalpayable").val("");
         var n =$("#listDetails > tbody > tr").length-1;
         var totalAmount =0;
         var impot = 0;
         var total = 0;
         for (i=0; i<=n; i++) {
                        totalAmount= totalAmount + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(7)').text())*1; 
                        impot= impot + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(9)').text())*1; 
                        total= total + accounting.unformat($('#listDetails > tbody > tr:eq(' + i + ') > td:eq(10)').text())*1; 
         }
	
	 
         var n =$("#listCharge > tbody > tr").length-1;
         var totalAmountCharge =0;
         var impotCharge = 0;
         var totalCharge = 0;
         for (i=0; i<n; i++) {
                        totalAmountCharge= totalAmountCharge + $('#listCharge > tbody > tr:eq(' + i + ') > td:eq(3)').text()*1; 
                        impotCharge= impotCharge + accounting.unformat($('#listCharge > tbody > tr:eq(' + i + ') > td:eq(5)').text()); 
                        totalCharge= totalCharge + accounting.unformat($('#listCharge > tbody > tr:eq(' + i + ') > td:eq(6)').text()); 
            console.log(impotCharge+"<->"+totalCharge);
         }
	 
      //   $("#totalamount").val(accounting.formatNumber(totalAmount + totalAmountCharge,2) );
  
        $("#impotpayable").val(accounting.formatNumber(impot +  impotCharge,2));
  
        $("#totalpayable").val(accounting.formatNumber(total + totalCharge,2));
	
  }
					
					
function msg(n,type, message){
        $("#msg_div"+n +" p").html(message);
        $("#msg_div"+n).attr("class","alert " + type);
}

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

function checkformNumber(me){
        var answer ="no";
        $.ajax({
          type: "POST",
          data: "code="+ me.value,
          url: "<?php echo base_url() ?>aptransaction/checkformNumber",
          success: function(data) {
                  if(data=="yes"){
                          $("#formNo").attr("placeholder","Error: Number exist ...");
                          $("#formNo").val("");
                          msg (1,"alert", "This form number is already used ");
                  }
          }
   });
   return answer;
}

function taxPopup () {
        $('#popupModal').modal('show');
        $("#_popupTitle").html("Purchase Invoice");
        $("#_popupContent").html('' +
          '<label>Select a tax</label>' +
          '<select style="width:100%;" onchange="calculamountET()" name="listTaxPopup" id="listTaxPopup" >' +
<?php
if ($taxmaster) {
    foreach ($taxmaster as $row2) {
        $temp = str_replace(array("\n", "\r", "'"), " ", $row2->name, $count);
        ?>
                    '<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 $temp; ?></option>'+
    <?php }
} ?>
            '</select>');
            $("#listTaxPopup").select2();
	
        $('#_popupFooter').empty();
           $('#_popupFooter').append('<button class="btn-form btn-success-form" id="confButton">Ok</button>' +
        '<button class="btn-form btn-danger-form" id="canb">Cancel</button>');
        $("#_popupTitle").html("Tax Master");
        $( "#canb" ).click(function() {
                $('#popupModal').modal('hide');
        });
        $( "#confButton" ).click(function() {
                $('#popupModal').modal('hide');
                
               
                
                 $("#listTax").attr("data-taxid",$("#listTaxPopup").val() );
                 // alert( $("#listTax").attr("data-taxid"));
                  $("#itemTax").attr("data-taxid",$("#listTaxPopup").val() );
                  
                 $("#itemTax,#listTax").val ($("#listTaxPopup option:selected").attr("data-tax"));
                 $("#displayTaxCode,#displayCode").html($("#listTaxPopup option:selected").attr("data-taxcode"));
                 calculChargeAmount();
                 calculamountET();
        });
}


function loadCustomerDefaultValue(){
        $('#currency').attr("value",'');
        $('#exchange_rate').attr("value",'');
        $.ajax({
                type: "POST",
                data: "customer="+ $("#customer").val(),
                url: "<?php echo base_url() ?>customerSetup/loadCustomerDefaultValue",
                success: function(data) {
                         var resul = eval ("(" + data + ")"); 
                        $('#currency').attr("value",resul.records[0].currency);
                        $('#exchange_rate').attr("value",accounting.formatNumber(resul.records[0].exchangeRate,5));
                }
         });
         getCustomerInvoicelist ($("#customer").val());
}

function refreshCustomer(){
         $.ajax({
        type: "POST",
        url: "<?php echo base_url() ?>CustomerSetup/refreshCustomer",
        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++)
                    if(resul.records[i].gstRegNo != '')
                        opt=opt + '<option value="' + resul.records[i].id +'">' + resul.records[i].customerName + ' (GST)</option>';
                    else
                        opt=opt + '<option value="' + resul.records[i].id +'">' + resul.records[i].customerName + '</option>';

                $('#customer').empty();
                $('#customer').append(opt);
        }
   });  
}

function addRowInvoiceCharge(){
        var tax = '';
        if(gstStatus){
            tax = '<td class="span1">\
                        <div class="input-prepend">\
                            <input disabled="disabled" data-taxid="" id="listTax" onkeyup="calculChargeAmount()" name="itemTax" class="span6 validate[required, custom[number]]" type="text" placeholder="Tax(%)" value="">\
                            <span onclick="taxPopup ()" style="margin-top:0;" id="displayCode" class="btn add-on"></span>\
                        </div>\
                  </td>';

        }else{
            tax = '<td class="span2">\
                        <div class="input-prepend">\
                            <input disabled="disabled" data-taxid="<?php echo $nonGstTaxID; ?>" value="0" id="listTax" onkeyup="calculChargeAmount()" name="itemTax" class="span6 validate[required, custom[number]]" type="text" placeholder="Tax(%)">\
                            <span style="margin-top:0;" id="displayCode" class="btn add-on">OS</span>\
                        </div>\
                  </td>';
        }

        if (!$("#chargeAccount").length) {
                                             $(''+
                                             '<tr><td>' + ($("#listCharge").attr("data-currentRow")*1 +1) +'</td>' +
                                                   '<td class="span3"> <select name="chargeAccount" id="chargeAccount" class="span12 validate[required]"><option></option>' +
<?php
if ($chargeAccount) {
    foreach ($chargeAccount as $row) {
        $temp = str_replace(array("\n", "\r", "'"), " ", $row->acctName, $count);
        ?>
                                     '<option value="<?php echo $row->ID; ?>"><?php echo substr($row->acctCode,0,4).'-'.substr($row->acctCode,4,3).'-'.substr($row->acctCode,7) . " | ";
        echo $temp;
        ?></option>'+
    <?php }
}
?>
                     '</select></td>'+
                        '<td class="span4"><input  id="chargedesc" name="chargedesc"  type="text" class="span12 validate[required]" placeholder="Description"></td>'+
                        '<td class="span2"><input id="chargeAmount" onkeyup="calculChargeAmount()"  onfocus="modAmount(this)" name="chargeAmount" class="span12 amount validate[required, custom[number]] tar" type="text" placeholder="Amount"></td>'+
                        tax+
                        '<td class="span1"><input disabled="disabled" id="chargetaxAmount"  name="chargetaxAmount" class="span12 amount tar" type="text" placeholder="Amount"></td>'+
                        '<td class="span2"><input disabled  id="chargeAmountIT" name="chargeAmountIT" class="span12 amount" type="text" placeholder="Amount (Exclude Tax)"></td>'+
                        '<td class="span1">'+
                        '<button onclick = "saveCharge(this)" class="btn-icon btn-mini btn-success-form" type="button"><i class="i-checkmark-3"></i></button>'+
                        '<button onclick="delRow(this)" id="btnCancelCharge" class="btn-icon btn-mini btn-danger-form" type="button"><i class="i-cross"></i></button>'+
                                                '</td>'+
                        '<td class="span1" style="text-align:center;"><input data-taxid="" id="inclusiveTax" onchange="modAmount(this)" name="incTax" class="tac" type="checkbox"></td>'+
                    '</tr>'
                                          ).insertBefore( "#trInfosCharge" );
					
                                            $('#chargeAccount').select2();
                                            if($('#listTax option').length){
                                              $('#listTax').select2();
                                            }
											
											$.each($("#listCharge .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();
												});
											});
											
 
                                        }else{
                                                msg (2,"alert","Please, do save the current details before adding new one");
                                                }
                                                
}

    function modAmount(me){
        console.log($(me).attr('type'));
        var $taxPer = accounting.unformat($("#listTax").val());
        var $chargeAmount = accounting.unformat($("#chargeAmount").val());
        if($(me).attr('type') != 'text'){
            if($('#inclusiveTax').attr("checked") == "checked"){
                $("#chargeAmount").attr('data-actual',accounting.unformat($("#chargeAmount").val()));
                var $taxAmount = ($chargeAmount*$taxPer)/(100+$taxPer);
                var $actualCharge = $chargeAmount - $taxAmount;
                $("#chargeAmount").val(accounting.formatNumber($actualCharge,2));
                calculChargeAmount();
            }else{
                $("#chargeAmount").val(accounting.formatNumber($("#chargeAmount").attr('data-actual'),2));
                calculChargeAmount();
            }
        }else{
            $("#chargeAmount").val(accounting.formatNumber($("#chargeAmount").attr('data-actual'),2));
            $('#inclusiveTax').attr("checked",false);
            calculChargeAmount();
        }
    }

function calculChargeAmount() { 
        if($('#inclusiveTax').attr("checked") == "checked"){          
          var t = (accounting.unformat($("#chargeAmount").attr('data-actual')) * accounting.unformat($("#listTax").val())) /(100+accounting.unformat($("#listTax").val()));  
        }else{
          var t = accounting.unformat($("#chargeAmount").val()) * accounting.unformat($("#listTax").val()) /100;
        }
        $("#chargetaxAmount").val(accounting.formatNumber(t,2));
        $("#chargeAmountIT").val(accounting.formatNumber(t+ accounting.unformat( $("#chargeAmount").val())*1,2));
}


function saveCharge(me){
      if( $("#saleDetailsForm").validationEngine('validate') && finanEngine('financhk')){
            if ( $("#saleDebitNoteID").val()=="null"){
                  getTotal();
                  $(me).attr("disabled","disabled");
                  $.ajax({
                  type: "POST",
                  data: {
                                 customerID : $("#customer").val(),
                                  formNo : $("#formNo").val(),
                                  debitNoteDate : $("#createdDate").val(),
                                  salesInvoiceID : $("#CompInvNo").val(),
                                  projectID: $("#project").val(),
                                  exchangeRate : $("#exchange_rate").val(),
                                  memo : $("#memo").val(),
				
                                accountNoID : $("#chargeAccount").val(),
                                lineNo : $("#listCharge").attr("data-currentRow")*1 +1,
                                chargeDescription : $("#chargedesc").val(),
                                taxAmount : accounting.unformat($("#chargetaxAmount").val()),
                                amountIncludedTax : accounting.unformat($("#chargeAmountIT").val()),
                                amountExcludedTax: accounting.unformat($("#chargeAmount").val()),
                                taxID: $("#listTax").attr('data-taxid'),
                                taxRate: $("#listTax").val()
				
                          },
                   url: "<?php echo base_url() ?>Artransaction/saveSaleDebitNoteCharge",
                   success: function(data) {
                   var resul = eval ("(" + data + ")"); 
                        $("#saleDebitNoteID").val(resul.debitNoteID);
                        var taxPercent = $("#listTax").val();
                        var taxID = $("#listTax").attr('data-taxid');
                        var taxText = '<td>' + $("#displayCode").text() + " | " + taxPercent + '</td>';
                        $(''+
                       '<tr> <td>' + ($("#listCharge").attr("data-currentRow")*1 +1) + '</td>' +
                          '<td>' + $("#chargeAccount option:selected").text() + '</td>'+
                          '<td>' + $("#chargedesc").val() + '</td>'+
                          '<td class="amount">' + $("#chargeAmount").val() + '</td>'+
                          taxText+  
                          '<td class="amount">' + $("#chargetaxAmount").val() + '</td>'+
                          '<td class="amount">' + $("#chargeAmountIT").val() + '</td>'+
                          '<td></td>'+
                  '</tr>'
                          ).insertBefore( "#trInfosCharge" );
                          $("#btnCancelCharge").trigger("click");
                          $("#listCharge").attr("data-currentRow",$("#listCharge").attr("data-currentRow")*1 +1)
                          getTotal();
                         msg (2,"alert alert-success","Details successfully saved");
                  } //end function
           });//end ajax
          }else{
                $(me).attr("disabled","disabled");
                  $.ajax({
                  type: "POST",
                  data: {
                        masterId : $("#saleDebitNoteID").val(),
                        lineNo : $("#listCharge").attr("data-currentRow")*1 +1,
                        accountNoID : $("#chargeAccount").val(), 
                        chargeDescription : $("#chargedesc").val(),
                        taxAmount : accounting.unformat($("#chargetaxAmount").val()),
                        currentTotalInvoice : accounting.unformat($("#totalpayable").val()),
                        amountIncludedTax : accounting.unformat($("#chargeAmountIT").val()),
                        amountExcludedTax: accounting.unformat($("#chargeAmount").val()),
                         taxID: $("#listTax").attr('data-taxid'),
                        taxRate: $("#listTax").val()

                          },
                   url: "<?php echo base_url() ?>Artransaction/saveSaleDebitNoteChargeDetailOnly",
                   success: function(data) {
                   msg (2,"alert alert-success","Details successfully saved");
                        var taxPercent = $("#listTax").val();
                        var taxID = $("#listTax").attr('data-taxid');
                        var resul = eval ("(" + data + ")"); 
                        $(''+
                           '<tr> <td>' + ($("#listCharge").attr("data-currentRow")*1 +1) + '</td>' +
                          '<td>' + $("#chargeAccount option:selected").text() + '</td>'+
                          '<td>' + $("#chargedesc").val() + '</td>'+
                          '<td class="amount">' + $("#chargeAmount").val() + '</td>'+
                          '<td>' + $("#displayCode").text() + " | " + taxPercent + '</td>'+
                          '<td class="amount">' + $("#chargetaxAmount").val() + '</td>'+
                          '<td class="amount">' + $("#chargeAmountIT").val() + '</td>'+
                          '<td></td>'+
                  '</tr>'
                   ).insertBefore( "#trInfosCharge" );
                $("#listCharge").attr("data-currentRow",$("#listCharge").attr("data-currentRow")*1 +1);
                   $("#btnCancelCharge").trigger("click");
                   getTotal();
                 }
           }); //end ajax
           }
          }else {
                  msg (1,"alert alert-error", "Data incorrect or invalid ...");
          }
  }
  
  
  function getSaleInoviceItemList(){
        $('#hiddentItemComboList').empty();
         $.ajax({
            type: "POST",
            data : "invoiceId=" + $("#CompInvNo").val() ,
            url: "<?php echo base_url() ?>arTransaction/getSaleInvoiceItemListDebit",
            success: function(data) {

            var resul = eval ("(" + data + ")"); 
            var n=resul.recordSet.length;
            var i=0;
            var opt='' +
            '<option></option>';
            for (i=0;i<n;i++)
                opt=opt + '<option data-itemID="' + resul.recordSet[i].itemID + '" ' + ' data-desc ="' + resul.recordSet[i].description + '" ' + 
                                   'data-umCode="' + resul.recordSet[i].unitOfMeasure + '" ' +
                                   'data-exactQty="' + resul.recordSet[i].exactQty + '" ' +
                                   'data-umid="' + resul.recordSet[i].umID + '" ' +
                                   'data-unitPrice="' + resul.recordSet[i].unitPrice + '" ' +
                                   'data-amountExcludedTax="' + resul.recordSet[i].amountExcludedTax + '" ' + 
                                   'data-taxid="' + resul.recordSet[i].taxID + '" ' +
                                   'data-taxPercentage="' + resul.recordSet[i].taxRate + '" ' +
                                   'data-taxAmount="' + resul.recordSet[i].taxAmount + '" ' +
                                   'data-taxcode="' + resul.recordSet[i].code + '" ' + 
                                   'data-amountIncludedTax="' + resul.recordSet[i].amountIncludedTax + '" ' + 
                       ' value="' + resul.recordSet[i].invoiceDetailID + '">' +  resul.recordSet[i].name + ' [ ' + resul.recordSet[i].itemCode + '] </option>';
                $('#hiddentItemComboList').empty();
                $('#hiddentItemComboList').append(opt);
            }
          });
      }
      
      function getItemListOfUM(){
        $("#idUnitOfMeasure").empty();
        if ($("#itemComboList option:selected").attr("data-umid") > 0 && $("#itemComboList option:selected").attr("data-umCode")!=null){
        //  $("#idUnitOfMeasure").select2('destroy'); 
            $("#idUnitOfMeasure").append("<option data-unitm='1' data-factor='1'  value="+ $("#itemComboList option:selected").attr("data-umid") +">"+ $("#itemComboList option:selected").attr("data-umCode") +"</option>");
           $("#idUnitOfMeasure").select2("val",$("#itemComboList option:selected").attr("data-umid"));

        }
        $.ajax({
            type: "POST",
            data : "unitFrom=" + $("#itemComboList option:selected").attr("data-umid") + "&itemID=" +  $("#itemComboList option:selected").attr("data-itemID") ,
            url: "<?php echo base_url() ?>apTransaction/getItemUnitList",
            success: function(data) {

            var resul = eval ("(" + data + ")"); 
            var n=resul.recordSet.length;
            var i=0;
            var opt='';
            for (i=0;i<n;i++){
                opt=opt + '<option  value="' + resul.recordSet[i].ID + '" data-unitm="' + resul.recordSet[i].unitm + '" data-factor="' + resul.recordSet[i].factor + '" data-desc ="' + resul.recordSet[i].desc + '">'+ resul.recordSet[i].code +'</option>';
                
            }
                $('#idUnitOfMeasure').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() . "gl/home" ?>'> <?php echo $this->lang->line('module') ?></a> <span class="divider">-</span></li>
                    <li class="active"><?php echo $this->lang->line('title2') ?></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="saleDetailsForm" action="#">    

                <div class="block">
                    <div class="head">
                        <h2><strong><?php echo $this->lang->line('addNewSaleDebitNote') ?></strong></h2>
                    </div><!-- head -->
                    <div class="content np">
                        <div class="row-fluid scRow">                            
                            <div class="span6 scCol">
                                <div class="block ns" id="grid_block_1">
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('customer') ?></div>
                                        <input type="hidden" value="null" id="saleDebitNoteID"/>
                                        <div class="span8">
                                            <select class="span11 validate[required]" id="customer" onchange="loadCustomerDefaultValue()">
                                                <option></option>
<?php
if ($customer) {
    foreach ($customer as $row) {
        ?>
                                                        <option value="<?php echo $row->ID; ?>"> <?php echo $row->customerName;
        echo ($row->gstRegNo != '' && $row->gstRegNo != '0') ? ' (GST)' : ''; ?></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() ?>CustomerSetup/CustomerNew"  id="newcustumer">
                                                            <i class="i-plus-2"></i> <?php echo $this->lang->line('addNewCustomer') ?></a></li>
                                                    <li><a href="#" onclick="refreshCustomer()">
                                                            <i class="i-ccw"></i><?php echo $this->lang->line('refreshlist') ?></a></li>
                                                </ul>
                                            </div>
                                        </div>

                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('formNo') ?></div>
                                        <div class="span5">
                                            <input class="span12 validate[required]" id="formNo" name="formNo" value='<?php echo "$formNo"; ?>' style="color:red;"   type="text" placeholder="Form number ...">
                                        </div>
                                        <div class="span3">
                                            <input  class="span12"   type="text" placeholder="Serial" disabled="disabled">
                                        </div>
                                    </div> <!-- row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('date') ?></div>
                                        <div class="span8">
                                            <div class="input-prepend span12"><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="span4"><?php echo $this->lang->line('project') ?></div>
                                        <div class="span8">
                                            <select id="project" class="span11">
                                                <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-2"></i><?php echo $this->lang->line('addNewProject') ?></a></li>
                                                    <li><a href="#" onclick="refreshProject()"><i class="i-ccw"></i><?php echo $this->lang->line('refreshlist') ?></a></li>
                                                </ul>
                                            </div><!-- btn group -->
                                        </div><!-- span -->
                                    </div> <!-- row control -->
                                </div><!-- grid block 1-->
                            </div><!-- scCol -->
                            <div class="span6 scCol">
                                <div class="block ns" id="grid_block_2">
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('invoiceNo') ?></div>
                                        <div class="span8">
                                            <select onchange="displaysCustomerInvoiceNo()" id="CompInvNo" class="span12 validate[required]">
                                                <option></option>
                                            </select>
                                        </div><!-- span -->
                                    </div><!-- control row -->

                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('customerPoNo') ?></div>
                                        <div class="span8">
                                            <input id="cusinvoicenumber" disabled="disabled" class="span12 validate[required]" type="text" placeholder="Customer Invoice Number">
                                        </div><!-- span -->
                                    </div> <!-- row -->

                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('currency') ?></div>
                                        <div class="span8">
                                            <input id="currency" name="currency" type="text" placeholder="Currency" disabled class="span12 validate[required,minSize[5],maxSize[10]]">            
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                    <div class="controls-row">
                                        <div class="span4"><?php echo $this->lang->line('exchangeRate') ?></div>
                                        <div class="span8">
                                            <input class="span12 validate[required] tar" id="exchange_rate" name="exchange_rate" type="text" placeholder="Example: 3.20000" >           
                                        </div><!-- span -->
                                    </div><!-- control row -->
                                </div><!-- grid block 1-->
                            </div><!-- scCol -->
                        </div>
                    </div>
                </div>
                
                 <div class="row-fluid scRow">                            
                    <div class="span12 scCol">
                        <textarea style="margin-top:10px;" id="memo" class="span12" placeholder="Memo"></textarea>
                        </div>
                </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('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>                                        
                            </div><!-- head -->
                            <div class="content np">
                                <table data-currentRow="0" 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('um') ?></th>
                                            <th class="tac"><?php echo $this->lang->line('qtyInvoice') ?></th>
                                            <th class="quantity" ><?php echo $this->lang->line('qtyReceive') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('unitPrice') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('amountExcludeTax') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('tax') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('taxAmount') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('amountIncludeTax') ?></th>
                                            <th><?php echo $this->lang->line('action') ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr id="trInfos">
                                            <td colspan="12">
                                                  <myselect style="display:none; display: none;" id="hiddentItemComboList">
                                                <option></option>
                                               </myselect>
                                                <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>
                                <div class="footer">
                                    <div class="side fr">
                                        <div class="btn-group">
                                            <button style="margin-right:6px;" onclick="$('#saleDetailsForm').validationEngine('hide');" class="btn-form btn-warning-form" type="button" name="validat">Hide prompts</button>
                                            <button id="addRow" onclick="addRowInvoice()" class="btn-icon btn-warning-form" type="button">
                                                <i class="i-plus-2"></i><?php echo $this->lang->line('addNewDetails') ?></button>
                                        </div>  
                                    </div><!-- side fr -->      
                                </div><!-- footer -->      
                            </div><!-- content -->
                        </div><!-- grid block 4-->
                    </div><!-- scCol -->
                </div><!-- row-fluid scRow-->

                <div class="row-fluid scRow">                            
                    <div class="span12 scCol">
                        <div class="block" id="grid_block_4">
                            <div class="head">
                                <h2><?php echo $this->lang->line('charges') ?></h2>
                                <ul class="buttons">
                                    <li><a class="block_toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">
                                            <span class="i-arrow-down-3"></span></a></li>
                                </ul>                                        
                            </div><!-- head -->
                            <div class="content np">
                                <table data-currentRow="0" id="listCharge" cellpadding="0" cellspacing="0" width="100%">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th><?php echo $this->lang->line('account') ?></th>
                                            <th><?php echo $this->lang->line('description') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('amount') ?></th>
                                            <th><?php echo $this->lang->line('tax') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('taxAmount') ?></th>
                                            <th class="amount"><?php echo $this->lang->line('amountIncludeTax') ?></th>
                                            <th><?php echo $this->lang->line('action') ?></th>
                                            <th><?php echo $this->lang->line('inclusiveTax') ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr id="trInfosCharge">
                                            <td colspan="9">
                                                <div id="msg_div2" class="alert alert-info">
                                                    <h4><?php echo $this->lang->line('lastMessage') ?></h4>
                                                    <p style="padding-top:10px;"><?php echo $this->lang->line('noMessage') ?></p>
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <div class="footer">
                                    <div class="side fr">
                                        <div class="btn-group">
                                            <button style="margin-right:6px;" onclick="$('#SaleDetailForm').validationEngine('hide');" class="btn-form btn-warning-form" type="button" name="validat">Hide prompts</button>
                                            <button id="addRowCharge" onclick="addRowInvoiceCharge()" class="btn-icon btn-warning-form" type="button">
                                                <i class="i-plus-2"></i><?php echo $this->lang->line('addNewCharge') ?></button>

                                        </div><!-- btn group -->      
                                    </div><!-- side fr -->      
                                </div><!-- footer -->      
                            </div><!-- content -->

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

                <div class="row-fluid scRow">
                    <div class="span7 scCol">
                        <div class="block" id="grid_block_4">
                          
                        </div>
                    </div>
                    <div class="span5 scCol">
                        <div class="block" id="grid_block_4">
                            <div class="content">

                                <div class="controls-row">
                                    <div class="span5"><?php echo $this->lang->line('totalTaxAmount') ?></div>
                                    <div class="span7">
                                        <input id="impotpayable" class="span12 amount" type="text" disabled="disabled"  placeholder="0">
                                    </div>
                                </div><!-- row control -->
                                <div class="controls-row">
                                    <div class="span5"><?php echo $this->lang->line('totalDebitNote') ?></div>
                                    <div class="span7">
                                        <input id="totalpayable" disabled="disabled"  class="span12 amount" type="text" placeholder="0">
                                    </div>
                                </div><!-- row control --> 
                            </div><!-- grid block 4-->
                        </div><!-- scCol -->
                    </div><!-- row-fluid scRow-->
            </form>
        </div><!-- grid 1 -->
    </div><!-- wrap -->
</div><!-- content -->
</div>


